From 607c0458b011da532c3a0170b36c6ae1dcc20049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lumi=C3=A8re=20=C3=89lev=C3=A9?= <88174309+PoneyClairDeLune@users.noreply.github.com> Date: Mon, 25 Sep 2023 09:02:29 +0000 Subject: [PATCH] `initOnReset` for every demo screen. --- dist/basic.mjs | 13 +++++++------ dist/cambiare.mjs | 42 ++++++++++++++++++++++-------------------- dist/state.mjs | 38 +++++++++++++++++++------------------- dist/state_skim.mjs | 16 ++++++++-------- dist/xp_basic.mjs | 41 +++++++++++++++++++++-------------------- dist/xp_state.mjs | 38 +++++++++++++++++++------------------- src/fakeMu/index.js | 4 ++++ src/fakeNs5r/index.js | 4 ++++ src/fakePsr/index.js | 4 ++++ src/fakeQy/index.js | 4 ++++ 10 files changed, 112 insertions(+), 92 deletions(-) diff --git a/dist/basic.mjs b/dist/basic.mjs index d7aa125e..58cdd1e8 100644 --- a/dist/basic.mjs +++ b/dist/basic.mjs @@ -1,7 +1,7 @@ -var _=Object.create;var O=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var z=(t,a)=>()=>(a||t((a={exports:{}}).exports,a),a.exports);var q=(t,a,c,e)=>{if(a&&typeof a=="object"||typeof a=="function")for(let s of F(a))!K.call(t,s)&&s!==c&&O(t,s,{get:()=>a[s],enumerable:!(e=X(a,s))||e.enumerable});return t};var Q=(t,a,c)=>(c=t!=null?_(V(t)):{},q(a||!t||!t.__esModule?O(c,"default",{value:t,enumerable:!0}):c,t));var N=z((ze,T)=>{(function(){"use strict";let t={fatal:!0},a=[new TextDecoder("iso-8859-15",t),new TextDecoder("sjis",t),new TextDecoder("euc-jp",t),new TextDecoder("utf-8",t),new TextDecoder("utf-16",t),new TextDecoder("ascii")],c={debug:!1,parse:function(e,s){if(e instanceof Uint8Array)return c.Uint8(e);if(typeof e=="string")return c.Base64(e);if(e instanceof HTMLElement&&e.type==="file")return c.addListener(e,s);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(e,s){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(e===void 0||!(e instanceof HTMLElement)||e.tagName!=="INPUT"||e.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;s=s||function(){},e.addEventListener("change",function(r){if(!r.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let o=new FileReader;o.readAsArrayBuffer(r.target.files[0]),o.onload=function(h){s(c.Uint8(new Uint8Array(h.target.result)))}})},Base64:function(e){let s=function(h){var g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(h=h.replace(/^.*?base64,/,""),h=String(h).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(h))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");h+="==".slice(2-(3&h.length));let u,p="",i,n,d=0;for(;d>16&255):n===64?String.fromCharCode(u>>16&255,u>>8&255):String.fromCharCode(u>>16&255,u>>8&255,255&u);return p}(e=String(e));var r=s.length;let o=new Uint8Array(new ArrayBuffer(r));for(let h=0;h{n[l]=this.readInt(1)});for(let b=0;b191||y>127&&y<160)throw new RangeError(`Invalid code point: ${y}`)}d=!0,console.debug(`String byte sequence in ${a[b].encoding}`)}catch(l){console.debug(`SMF string ${l}`)}return f||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let i=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)i=this.readInt(1);else{let d=[];for(;128<=this.data.getUint8(this.pointer);)d.push(this.readInt(1)-128);var n=this.readInt(1);for(let f=1;f<=d.length;f++)i+=d[d.length-f]*Math.pow(128,f);i+=n}return i}};if(s.data=new DataView(o.buffer,o.byteOffset,o.byteLength),s.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;s.readInt(4);let r={};r.formatType=s.readInt(2),r.tracks=s.readInt(2),r.track=[];var o=s.readInt(1),h=s.readInt(1);128<=o?(r.timeDivision=[],r.timeDivision[0]=o-128,r.timeDivision[1]=h):r.timeDivision=256*o+h;for(let i=1;i<=r.tracks;i++){r.track[i-1]={event:[]};var g,u=s.readInt(4);if(u===-1)break;if(u!==1297379947)return!1;s.readInt(4);let n=0,d=!1,f,b;for(;!d&&(n++,r.track[i-1].event[n-1]={},r.track[i-1].event[n-1].deltaTime=s.readIntVLV(),(f=s.readInt(1))!==-1);)if(128<=f?b=f:(f=b,s.movePointer(-1)),f===255){r.track[i-1].event[n-1].type=255,r.track[i-1].event[n-1].metaType=s.readInt(1);var p=s.readIntVLV();switch(r.track[i-1].event[n-1].metaType){case 47:case-1:d=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:r.track[i-1].event[n-1].data=s.readStr(p);break;case 33:case 89:case 81:r.track[i-1].event[n-1].data=s.readInt(p);break;case 84:r.track[i-1].event[n-1].data=[],r.track[i-1].event[n-1].data[0]=s.readInt(1),r.track[i-1].event[n-1].data[1]=s.readInt(1),r.track[i-1].event[n-1].data[2]=s.readInt(1),r.track[i-1].event[n-1].data[3]=s.readInt(1),r.track[i-1].event[n-1].data[4]=s.readInt(1);break;case 88:r.track[i-1].event[n-1].data=[],r.track[i-1].event[n-1].data[0]=s.readInt(1),r.track[i-1].event[n-1].data[1]=s.readInt(1),r.track[i-1].event[n-1].data[2]=s.readInt(1),r.track[i-1].event[n-1].data[3]=s.readInt(1);break;default:this.customInterpreter!==null&&(r.track[i-1].event[n-1].data=this.customInterpreter(r.track[i-1].event[n-1].metaType,s,p)),this.customInterpreter!==null&&r.track[i-1].event[n-1].data!==!1||(s.readInt(p),r.track[i-1].event[n-1].data=s.readInt(p),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((f=f.toString(16).split(""))[1]||f.unshift("0"),r.track[i-1].event[n-1].type=parseInt(f[0],16),r.track[i-1].event[n-1].channel=parseInt(f[1],16),r.track[i-1].event[n-1].type){case 15:this.customInterpreter!==null&&(r.track[i-1].event[n-1].data=this.customInterpreter(r.track[i-1].event[n-1].type,s,!1)),this.customInterpreter!==null&&r.track[i-1].event[n-1].data!==!1||(g=s.readIntVLV(),r.track[i-1].event[n-1].data=s.readInt(g),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:r.track[i-1].event[n-1].data=[],r.track[i-1].event[n-1].data[0]=s.readInt(1),r.track[i-1].event[n-1].data[1]=s.readInt(1);break;case 12:case 13:r.track[i-1].event[n-1].data=s.readInt(1);break;case-1:d=!0;break;default:if(this.customInterpreter!==null&&(r.track[i-1].event[n-1].data=this.customInterpreter(r.track[i-1].event[n-1].metaType,s,!1)),this.customInterpreter===null||r.track[i-1].event[n-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return r},customInterpreter:null};if(typeof T<"u")T.exports=c;else{let e=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;e.MidiParser=c}})()});var k=class{#e={};addEventListener(t,a){this.#e[t]||(this.#e[t]=[]),this.#e[t].unshift(a)}removeEventListener(t,a){if(this.#e[t]){let c=this.#e[t].indexOf(a);c>-1&&this.#e[t].splice(c,1),this.#e[t].length<1&&delete this.#e[t]}}dispatchEvent(t,a){let c=new Event(t),e=this;c.data=a,this.#e[t]?.length>0&&this.#e[t].forEach(function(s){try{s?.call(e,c)}catch(r){console.error(r)}}),this[`on${t}`]&&this[`on${t}`](c)}};var I=class{#e={};context;set(t,a){this.#e[t]=a}has(t){return!!this.#e[t]}async read(t,a){if(!this.has(t))throw new Error(`No decoder registered for "${t}"`);return await this.#e[t].call(this.context||this,a)}};var j=function(t,a){let c=!0;return a.forEach((e,s)=>{c=c&&t[s]==e}),c},P=function(t){let a=0;return t.forEach(c=>{a*=256,a+=c}),a},$=new TextDecoder,U=new I;U.set("s7e",async function(t){let a=new Uint8Array(await t.slice(0,65536).arrayBuffer()),c="MSB LSB PRG NME",e=[0,0,0,0],s=32,r=0,o=0,h=!0,g=[],u=0;for(;h;){let p=a.subarray(r);([()=>{$.decode(p.subarray(0,4))=="YSFC"?(r+=80,o=1):r++},()=>{if(j(p.subarray(0,4),e))g.forEach((i,n,d)=>{let f=P(a.subarray(i.start+4,i.start+8));i.length=f}),o=2;else{let i=$.decode(p.subarray(0,4)),n=P(p.subarray(4,8));g.push({type:i,start:n}),r+=8}},()=>{let i=g[u],n=a.subarray(i.start,i.start+i.length),d=32;switch(i.type){case"ENVC":{let f=s;for(;f=g.length&&(o=3,h=!1)}][o]||(()=>{h=!1}))()}return c});var Y=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]);var W=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),Z={};`hi*, +var _=Object.create;var O=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var z=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports);var q=(t,n,c,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of V(n))!K.call(t,s)&&s!==c&&O(t,s,{get:()=>n[s],enumerable:!(e=X(n,s))||e.enumerable});return t};var Q=(t,n,c)=>(c=t!=null?_(F(t)):{},q(n||!t||!t.__esModule?O(c,"default",{value:t,enumerable:!0}):c,t));var N=z((ze,T)=>{(function(){"use strict";let t={fatal:!0},n=[new TextDecoder("iso-8859-15",t),new TextDecoder("sjis",t),new TextDecoder("euc-jp",t),new TextDecoder("utf-8",t),new TextDecoder("utf-16",t),new TextDecoder("ascii")],c={debug:!1,parse:function(e,s){if(e instanceof Uint8Array)return c.Uint8(e);if(typeof e=="string")return c.Base64(e);if(e instanceof HTMLElement&&e.type==="file")return c.addListener(e,s);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(e,s){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(e===void 0||!(e instanceof HTMLElement)||e.tagName!=="INPUT"||e.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;s=s||function(){},e.addEventListener("change",function(r){if(!r.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let o=new FileReader;o.readAsArrayBuffer(r.target.files[0]),o.onload=function(h){s(c.Uint8(new Uint8Array(h.target.result)))}})},Base64:function(e){let s=function(h){var g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(h=h.replace(/^.*?base64,/,""),h=String(h).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(h))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");h+="==".slice(2-(3&h.length));let b,u="",a,i,l=0;for(;l>16&255):i===64?String.fromCharCode(b>>16&255,b>>8&255):String.fromCharCode(b>>16&255,b>>8&255,255&b);return u}(e=String(e));var r=s.length;let o=new Uint8Array(new ArrayBuffer(r));for(let h=0;h{i[d]=this.readInt(1)});for(let p=0;p191||y>127&&y<160)throw new RangeError(`Invalid code point: ${y}`)}l=!0,console.debug(`String byte sequence in ${n[p].encoding}`)}catch(d){console.debug(`SMF string ${d}`)}return f||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let a=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)a=this.readInt(1);else{let l=[];for(;128<=this.data.getUint8(this.pointer);)l.push(this.readInt(1)-128);var i=this.readInt(1);for(let f=1;f<=l.length;f++)a+=l[l.length-f]*Math.pow(128,f);a+=i}return a}};if(s.data=new DataView(o.buffer,o.byteOffset,o.byteLength),s.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;s.readInt(4);let r={};r.formatType=s.readInt(2),r.tracks=s.readInt(2),r.track=[];var o=s.readInt(1),h=s.readInt(1);128<=o?(r.timeDivision=[],r.timeDivision[0]=o-128,r.timeDivision[1]=h):r.timeDivision=256*o+h;for(let a=1;a<=r.tracks;a++){r.track[a-1]={event:[]};var g,b=s.readInt(4);if(b===-1)break;if(b!==1297379947)return!1;s.readInt(4);let i=0,l=!1,f,p;for(;!l&&(i++,r.track[a-1].event[i-1]={},r.track[a-1].event[i-1].deltaTime=s.readIntVLV(),(f=s.readInt(1))!==-1);)if(128<=f?p=f:(f=p,s.movePointer(-1)),f===255){r.track[a-1].event[i-1].type=255,r.track[a-1].event[i-1].metaType=s.readInt(1);var u=s.readIntVLV();switch(r.track[a-1].event[i-1].metaType){case 47:case-1:l=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:r.track[a-1].event[i-1].data=s.readStr(u);break;case 33:case 89:case 81:r.track[a-1].event[i-1].data=s.readInt(u);break;case 84:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=s.readInt(1),r.track[a-1].event[i-1].data[1]=s.readInt(1),r.track[a-1].event[i-1].data[2]=s.readInt(1),r.track[a-1].event[i-1].data[3]=s.readInt(1),r.track[a-1].event[i-1].data[4]=s.readInt(1);break;case 88:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=s.readInt(1),r.track[a-1].event[i-1].data[1]=s.readInt(1),r.track[a-1].event[i-1].data[2]=s.readInt(1),r.track[a-1].event[i-1].data[3]=s.readInt(1);break;default:this.customInterpreter!==null&&(r.track[a-1].event[i-1].data=this.customInterpreter(r.track[a-1].event[i-1].metaType,s,u)),this.customInterpreter!==null&&r.track[a-1].event[i-1].data!==!1||(s.readInt(u),r.track[a-1].event[i-1].data=s.readInt(u),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((f=f.toString(16).split(""))[1]||f.unshift("0"),r.track[a-1].event[i-1].type=parseInt(f[0],16),r.track[a-1].event[i-1].channel=parseInt(f[1],16),r.track[a-1].event[i-1].type){case 15:this.customInterpreter!==null&&(r.track[a-1].event[i-1].data=this.customInterpreter(r.track[a-1].event[i-1].type,s,!1)),this.customInterpreter!==null&&r.track[a-1].event[i-1].data!==!1||(g=s.readIntVLV(),r.track[a-1].event[i-1].data=s.readInt(g),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=s.readInt(1),r.track[a-1].event[i-1].data[1]=s.readInt(1);break;case 12:case 13:r.track[a-1].event[i-1].data=s.readInt(1);break;case-1:l=!0;break;default:if(this.customInterpreter!==null&&(r.track[a-1].event[i-1].data=this.customInterpreter(r.track[a-1].event[i-1].metaType,s,!1)),this.customInterpreter===null||r.track[a-1].event[i-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return r},customInterpreter:null};if(typeof T<"u")T.exports=c;else{let e=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;e.MidiParser=c}})()});var w=class{#e={};addEventListener(t,n){this.#e[t]||(this.#e[t]=[]),this.#e[t].unshift(n)}removeEventListener(t,n){if(this.#e[t]){let c=this.#e[t].indexOf(n);c>-1&&this.#e[t].splice(c,1),this.#e[t].length<1&&delete this.#e[t]}}dispatchEvent(t,n){let c=new Event(t),e=this;c.data=n,this.#e[t]?.length>0&&this.#e[t].forEach(function(s){try{s?.call(e,c)}catch(r){console.error(r)}}),this[`on${t}`]&&this[`on${t}`](c)}};var A=class{#e={};context;set(t,n){this.#e[t]=n}has(t){return!!this.#e[t]}async read(t,n){if(!this.has(t))throw new Error(`No decoder registered for "${t}"`);return await this.#e[t].call(this.context||this,n)}};var Y=function(t,n){let c=!0;return n.forEach((e,s)=>{c=c&&t[s]==e}),c},I=function(t){let n=0;return t.forEach(c=>{n*=256,n+=c}),n},v=new TextDecoder,U=new A;U.set("s7e",async function(t){let n=new Uint8Array(await t.slice(0,65536).arrayBuffer()),c="MSB LSB PRG NME",e=[0,0,0,0],s=32,r=0,o=0,h=!0,g=[],b=0;for(;h;){let u=n.subarray(r);([()=>{v.decode(u.subarray(0,4))=="YSFC"?(r+=80,o=1):r++},()=>{if(Y(u.subarray(0,4),e))g.forEach((a,i,l)=>{let f=I(n.subarray(a.start+4,a.start+8));a.length=f}),o=2;else{let a=v.decode(u.subarray(0,4)),i=I(u.subarray(4,8));g.push({type:a,start:i}),r+=8}},()=>{let a=g[b],i=n.subarray(a.start,a.start+a.length),l=32;switch(a.type){case"ENVC":{let f=s;for(;f=g.length&&(o=3,h=!1)}][o]||(()=>{h=!1}))()}return c});var j=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]);var W=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),Z={};`hi*, ka,か ki,き ku,く @@ -138,5 +138,6 @@ o,お ~, ^, _,`.split(` -`).forEach(t=>{let a=t.split(",");Z[a[0]]=a[1]});var A=function(t,a,c){let e=[],s=c==!1?a.readIntVLV():c;t==0||t==127;for(let r=0;r127)return console.debug(`Early termination: ${e}`),e.pop(),a.backOne(),a.backOne(),new Uint8Array(e)}}}return new Uint8Array(e)};var J=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"];var S=[20,21,22,23,24,25,26,28,29,30,31,36,37,64,65],x=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19];var ee={};J.forEach((t,a)=>{ee[t]=a});var v={length:x.length};x.forEach((t,a)=>{v[t]=a});var L={length:S.length};S.forEach((t,a)=>{L[t]=a});var Ve={ch:128,cc:x.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:S.length,dnc:128,efx:7};var R=Q(N(),1);var H=class{#e=!1;constructor(t,a,c,e){this.#e=t,this.start=a,this.end=c,this.data=e}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#e}},C=class extends H{constructor(t,a,c){super(!0,t,a,c)}},B=class extends H{constructor(t,a){super(!1,t,t,a)}},M=class extends Array{#e=-1;constructor(){super(...arguments)}resetIndex(t){this.#e=-1}fresh(){this.sort(function(t,a){return t.start==a.start?0:(+(t.start>a.start)<<1)-1}),this.forEach(function(t,a){t.index=a})}step(t,a=!1){let c=[];if(a)for(let e=0;et);e++){if(this[e].ends.#e&&(c.push(r),s.#e=r.index)})}return c}getRange(t,a){t>a&&([t,a]=[a,t]);let c=[],e=-1,s=Math.ceil(Math.sqrt(this.length)),r=!0;for(let o=0;o=t&&(e=o):e=e<0?o:e;for(;r;)this[e]?.end=t&&c.push(this[e]):r=!1,e++;return c}};var te=0xffffffffffff,G=function(t){let a=new M,c=this,e=t.timeDivision,s=120,r=new M,o=0,h=0;r.push(new C(0,te,[120,0])),t.track.forEach(function(i){o=0,i.event.forEach(function(n){o+=n.deltaTime,n.type==255&&n?.metaType==81&&(s=6e7/n.data,r[r.length-1]&&r.push(new C(o,0xffffffffffff,[s,0])))})}),r.fresh(),r.forEach(function(i,n,d){n>0&&(d[n-1].end=i.start)});let g=120;r.forEach(function(i,n,d){n>0&&(i.end==i.start?d.splice(d.indexOf(i),1):g==i.data[0]&&(d[n-1].end=i.end,d.splice(d.indexOf(i),1)),g=i.data[0])});let u=0,p=120;return r.forEach(function(i){let n=i.start,d=n/p/e*60+u;p=i.data[0],u=d-n/p/e*60,i.data[1]=u}),console.debug("All tempo changes: ",r),s=120,o=0,h=0,t.track.forEach(function(i,n){o=0,h=0;let d=n+1;i.event.forEach(function(f,b){o+=f.deltaTime;let l=r.step(o,!0)[0];l&&(s=l.data[0],h=l.data[1]);let y={type:f.type,data:f.data,track:d,part:0};f.type>14?y.meta=f.metaType:y.part=f.channel,a.push(new B(o/s/e*60+h,y))})}),a.fresh(),self.midiEvents=a,console.debug(`Parsed a type ${t.formatType} MIDI sequence.`),a};R.default.customInterpreter=A;var m=function(t,a,c){t.addEventListener(c,e=>{a.dispatchEvent(c,e.data)})},st=class extends k{device;#e;#h;#d=[];#a="";#n=[];#c=new Uint8ClampedArray(128);#f=new Uint8ClampedArray(128);#s=.5;#i=120;#t=4;#o=4;#r=0;#l=0;smoothingAtk=0;smoothingDcy=0;reset(){let t=this;t.dispatchEvent("reset"),t.#e?.resetIndex(),t.device.init(),t.#a="",t.#s=.5,t.#i=120,t.#t=4,t.#o=4,t.#r=0,t.#l=0,t.dispatchEvent("tempo",t.#i),t.dispatchEvent("title",t.#a)}async loadFile(t){this.#e=G(R.default.parse(new Uint8Array(await t.arrayBuffer())))}async loadMap(t){}async loadEfx(t){let a=this,c=0,e=0,s,r,o;t.split(` -`).forEach((h,g)=>{if(g){let u=0,p;h.split(" ").forEach((i,n)=>{switch(n){case s:{u|=parseInt(i,16)<<8;break}case r:{u|=parseInt(i,16);break}case o:{p=i;break}}}),a.#d[u]?console.debug(`EFX ID 0x${u.toString(16).padStart(4,"0")} (${p}) seems to be in conflict.`):(a.#d[u]=p,c++),e++}else h.split(" ").forEach((u,p)=>{switch(u){case"MSB":{s=p;break}case"LSB":{r=p;break}case"Name":{o=p;break}default:console.warn(`Unknown EFX field: ${u}`)}})}),console.debug(`EFX: ${e} total, ${c} loaded.`),a.dispatchEvent("efxreverb",a.device.getEffectType(0)),a.dispatchEvent("efxchorus",a.device.getEffectType(1)),a.dispatchEvent("efxdelay",a.device.getEffectType(2)),a.dispatchEvent("efxinsert0",a.device.getEffectType(3)),a.dispatchEvent("efxinsert1",a.device.getEffectType(4)),a.dispatchEvent("efxinsert2",a.device.getEffectType(5)),a.dispatchEvent("efxinsert3",a.device.getEffectType(6))}switchMode(t,a=!1){this.device.switchMode(t,a)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(t){return this.device.getChVoice(t)}getMapped(t){}getEfx([t,a]){let c=t<<8|a;return this.#d[c]||`0x${c.toString(16).padStart(4,"0")}`}get noteProgress(){return this.#l/this.#s}get noteOverall(){return this.noteProgress-this.#r}get noteBar(){return Math.floor(this.noteOverall/this.#t)}get noteBeat(){let t=this.noteOverall%this.#t;return t<0&&(t+=this.#t),t}getTimeSig(){return[this.#t,this.#o]}getTempo(){return this.#i}sendCmd(t){this.device.runJson(t)}render(t){t>this.#l&&(this.#l=t);let a=this.#e?.step(t)||[],c=0,e=new Set,s=this,r=[];this.device.getStrength().forEach((b,l)=>{this.#f[l]=b}),s.device.newStrength(),a.forEach(function(b){let l=b.data;l.type==9&&(l.data[1]>0?e.add(l.part*128+l.data[0]):e.has(l.part*128+l.data[0])&&c++),b.data.type==8&&e.has(l.part*128+l.data[0])&&c++;let y=s.device.runJson(l);switch(y?.reply){case"meta":{r.push(y);break}}y?.reply&&delete y.reply}),r?.length>0&&this.dispatchEvent("meta",r);let o=this.device.getActive(),h=[],g=s.device.getPitch(),u=s.device.getCcAll(),p=s.device.getProgram(),i=s.device.getChType(),n=this.device.getStrength();n.forEach(function(b,l,y){y[l]=Math.max(s.#f[l],b);let E=y[l]-s.#c[l],D=v.length*l;if(E>=0){let w=4*.25**(u[D+v[73]]/64);s.#c[l]+=Math.ceil(E-E*s.smoothingAtk**w)}else{let w=4*.25**(u[D+v[72]]/64);s.#c[l]+=Math.floor(E-E*s.smoothingDcy**w)}});let d=0;return o.forEach(function(b,l){b&&(h[l]=s.device.getVel(l),d+=h[l].size)}),{extraPoly:c,curPoly:d,chInUse:o,chKeyPr:h,chPitch:g,chProgr:p,chContr:u,chType:i,eventCount:a.length,title:this.#a,bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:this.#c.slice(),velo:n,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce(),efxSink:this.device.getEffectSink()}}constructor(t,a=.5,c=.5){super();let e=this;e.smoothingAtk=a,e.smoothingDcy=c,e.device=t,e.addEventListener("meta",function(s){s?.data?.forEach(function(r){(e.#n[r.meta]||console.debug).call(e,r.meta,r.data)})}),m(e.device,e,"mode"),m(e.device,e,"mastervolume"),m(e.device,e,"channelactive"),m(e.device,e,"channelmin"),m(e.device,e,"channelmax"),m(e.device,e,"channelreset"),m(e.device,e,"screen"),m(e.device,e,"metacommit"),m(e.device,e,"efxreverb"),m(e.device,e,"efxchorus"),m(e.device,e,"efxdelay"),m(e.device,e,"efxinsert0"),m(e.device,e,"efxinsert1"),m(e.device,e,"efxinsert2"),m(e.device,e,"efxinsert3"),e.#n[3]=function(s,r){e.#a?.length<1&&(e.#a=r,e.dispatchEvent("title",e.#a))},e.#n[81]=function(s,r){let o=e.noteProgress,h=e.#s||.5;e.#i=6e7/r,e.#s=r/1e6,e.#r+=o*(h/e.#s)-o,e.dispatchEvent("tempo",e.#i)},e.#n[88]=function(s,r){let o=e.noteProgress,h=e.noteOverall,g=e.noteBar,u=e.noteBeat,p=e.#t,i=e.#o;e.#t=r[0],e.#o=1<=p&&(p{let n=t.split(",");Z[n[0]]=n[1]});var P=function(t,n,c){let e=[],s=c==!1?n.readIntVLV():c;t==0||t==127;for(let r=0;r127)return console.debug(`Early termination: ${e}`),e.pop(),n.backOne(),n.backOne(),new Uint8Array(e)}}}return new Uint8Array(e)};var J=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"];var S=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var x=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19];var ee={};J.forEach((t,n)=>{ee[t]=n});var $={length:x.length};x.forEach((t,n)=>{$[t]=n});var L={length:S.length};S.forEach((t,n)=>{L[t]=n});var Fe={ch:128,cc:x.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:S.length,dnc:128,efx:7};var R=Q(N(),1);var B=class{#e=!1;constructor(t,n,c,e){this.#e=t,this.start=n,this.end=c,this.data=e}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#e}},C=class extends B{constructor(t,n,c){super(!0,t,n,c)}},H=class extends B{constructor(t,n){super(!1,t,t,n)}},M=class extends Array{#e=-1;constructor(){super(...arguments)}resetIndex(t){this.#e=-1}fresh(){this.sort(function(t,n){return t.start==n.start?0:(+(t.start>n.start)<<1)-1}),this.forEach(function(t,n){t.index=n})}step(t,n=!1){let c=[];if(n)for(let e=0;et);e++){if(this[e].ends.#e&&(c.push(r),s.#e=r.index)})}return c}getRange(t,n){t>n&&([t,n]=[n,t]);let c=[],e=-1,s=Math.ceil(Math.sqrt(this.length)),r=!0;for(let o=0;o=t&&(e=o):e=e<0?o:e;for(;r;)this[e]?.end=t&&c.push(this[e]):r=!1,e++;return c}};var te=0xffffffffffff,G=function(t){let n=new M,c=this,e=t.timeDivision,s=120,r=new M,o=0,h=0;r.push(new C(0,te,[120,0])),t.track.forEach(function(a){o=0,a.event.forEach(function(i){o+=i.deltaTime,i.type==255&&i?.metaType==81&&(s=6e7/i.data,r[r.length-1]&&r.push(new C(o,0xffffffffffff,[s,0])))})}),r.fresh(),r.forEach(function(a,i,l){i>0&&(l[i-1].end=a.start)});let g=120;r.forEach(function(a,i,l){i>0&&(a.end==a.start?l.splice(l.indexOf(a),1):g==a.data[0]&&(l[i-1].end=a.end,l.splice(l.indexOf(a),1)),g=a.data[0])});let b=0,u=120;return r.forEach(function(a){let i=a.start,l=i/u/e*60+b;u=a.data[0],b=l-i/u/e*60,a.data[1]=b}),console.debug("All tempo changes: ",r),s=120,o=0,h=0,t.track.forEach(function(a,i){o=0,h=0;let l=i+1;a.event.forEach(function(f,p){o+=f.deltaTime;let d=r.step(o,!0)[0];d&&(s=d.data[0],h=d.data[1]);let y={type:f.type,data:f.data,track:l,part:0};f.type>14?y.meta=f.metaType:y.part=f.channel,n.push(new H(o/s/e*60+h,y))})}),n.fresh(),self.midiEvents=n,console.debug(`Parsed a type ${t.formatType} MIDI sequence.`),n};R.default.customInterpreter=P;var m=function(t,n,c){t.addEventListener(c,e=>{n.dispatchEvent(c,e.data)})},st=class extends w{device;#e;#n={};#f=[];#a="";#c=[];#o=new Uint8ClampedArray(128);#h=new Uint8ClampedArray(128);#s=.5;#i=120;#t=4;#l=4;#r=0;#d=0;smoothingAtk=0;smoothingDcy=0;reset(){let t=this;t.dispatchEvent("reset"),t.#e?.resetIndex(),t.device.init(),t.#a="",t.#s=.5,t.#i=120,t.#t=4,t.#l=4,t.#r=0,t.#d=0,t.dispatchEvent("tempo",t.#i),t.dispatchEvent("title",t.#a)}async loadFile(t){this.#e=G(R.default.parse(new Uint8Array(await t.arrayBuffer())))}async loadMap(t,n){let c=this,e=0,s=0,r=0,o,h;t.split(` +`).forEach((g,b)=>{if(!g)return;let u=g.split(" ");if(b){if(!r)return;let a="",i="";u.forEach((l,f)=>{switch(f){case o:{a=l;break}case h:{i=l;break}}}),!c.#n[a]||n?(c.#n[a]=i,e++):self.debugMode&&console.debug(`Voice "${i}" (${a}) seems to be in conflict with (${c.#n[a]}).`),s++}else u.forEach((a,i)=>{switch(a){case"ID":{o=i,r++;break}case"Name":{h=i,r++;break}default:console.debug(`Unknown map field: ${a}`)}})}),console.debug(`Map: ${s} total, ${e} loaded.`),c?.device.forceVoiceRefresh()}async loadEfx(t,n){let c=this,e=0,s=0,r,o,h;t.split(` +`).forEach((g,b)=>{if(g)if(b){let u=0,a;g.split(" ").forEach((i,l)=>{switch(l){case r:{u|=parseInt(i,16)<<8;break}case o:{u|=parseInt(i,16);break}case h:{a=i;break}}}),!c.#f[u]||n?(c.#f[u]=a,e++):self.debugMode&&console.debug(`EFX ID 0x${u.toString(16).padStart(4,"0")} (${a}) seems to be in conflict.`),s++}else g.split(" ").forEach((u,a)=>{switch(u){case"MSB":{r=a;break}case"LSB":{o=a;break}case"Name":{h=a;break}default:console.debug(`Unknown EFX field: ${u}`)}})}),console.debug(`EFX: ${s} total, ${e} loaded.`),c.dispatchEvent("efxreverb",c.device.getEffectType(0)),c.dispatchEvent("efxchorus",c.device.getEffectType(1)),c.dispatchEvent("efxdelay",c.device.getEffectType(2)),c.dispatchEvent("efxinsert0",c.device.getEffectType(3)),c.dispatchEvent("efxinsert1",c.device.getEffectType(4)),c.dispatchEvent("efxinsert2",c.device.getEffectType(5)),c.dispatchEvent("efxinsert3",c.device.getEffectType(6))}switchMode(t,n=!1){this.device.switchMode(t,n)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(t){return this.device.getChVoice(t)}getMapped(t){return this.#n[t]||t}getEfx([t,n]){let c=t<<8|n;return this.#f[c]||`0x${c.toString(16).padStart(4,"0")}`}get noteProgress(){return this.#d/this.#s}get noteOverall(){return this.noteProgress-this.#r}get noteBar(){return Math.floor(this.noteOverall/this.#t)}get noteBeat(){let t=this.noteOverall%this.#t;return t<0&&(t+=this.#t),t}getTimeSig(){return[this.#t,this.#l]}getTempo(){return this.#i}sendCmd(t){this.device.runJson(t)}render(t){t>this.#d&&(this.#d=t);let n=this.#e?.step(t)||[],c=0,e=new Set,s=this,r=[];this.device.getStrength().forEach((p,d)=>{this.#h[d]=p}),s.device.newStrength(),n.forEach(function(p){let d=p.data;d.type==9&&(d.data[1]>0?e.add(d.part*128+d.data[0]):e.has(d.part*128+d.data[0])&&c++),p.data.type==8&&e.has(d.part*128+d.data[0])&&c++;let y=s.device.runJson(d);switch(y?.reply){case"meta":{r.push(y);break}}y?.reply&&delete y.reply}),r?.length>0&&this.dispatchEvent("meta",r);let o=this.device.getActive(),h=[],g=s.device.getPitch(),b=s.device.getCcAll(),u=s.device.getProgram(),a=s.device.getChType(),i=this.device.getStrength();i.forEach(function(p,d,y){y[d]=Math.max(s.#h[d],p);let E=y[d]-s.#o[d],D=$.length*d;if(E>=0){let k=4*.25**(b[D+$[73]]/64);s.#o[d]+=Math.ceil(E-E*s.smoothingAtk**k)}else{let k=4*.25**(b[D+$[72]]/64);s.#o[d]+=Math.floor(E-E*s.smoothingDcy**k)}});let l=0;return o.forEach(function(p,d){p&&(h[d]=s.device.getVel(d),l+=h[d].size)}),{extraPoly:c,curPoly:l,chInUse:o,chKeyPr:h,chPitch:g,chProgr:u,chContr:b,chType:a,eventCount:n.length,title:this.#a,bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:this.#o.slice(),velo:i,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce(),efxSink:this.device.getEffectSink()}}constructor(t,n=.5,c=.5){super();let e=this;e.smoothingAtk=n,e.smoothingDcy=c,e.device=t,e.addEventListener("meta",function(s){s?.data?.forEach(function(r){(e.#c[r.meta]||console.debug).call(e,r.meta,r.data)})}),m(e.device,e,"mode"),m(e.device,e,"mastervolume"),m(e.device,e,"channelactive"),m(e.device,e,"channelmin"),m(e.device,e,"channelmax"),m(e.device,e,"channelreset"),m(e.device,e,"channeltoggle"),m(e.device,e,"screen"),m(e.device,e,"metacommit"),m(e.device,e,"voice"),m(e.device,e,"pitch"),m(e.device,e,"note"),m(e.device,e,"reset"),m(e.device,e,"efxreverb"),m(e.device,e,"efxchorus"),m(e.device,e,"efxdelay"),m(e.device,e,"efxinsert0"),m(e.device,e,"efxinsert1"),m(e.device,e,"efxinsert2"),m(e.device,e,"efxinsert3"),m(e.device,e,"partefxtoggle"),e.#c[3]=function(s,r){e.#a?.length<1&&(e.#a=r,e.dispatchEvent("title",e.#a))},e.#c[81]=function(s,r){let o=e.noteProgress,h=e.#s||.5;e.#i=6e7/r,e.#s=r/1e6,e.#r+=o*(h/e.#s)-o,e.dispatchEvent("tempo",e.#i)},e.#c[88]=function(s,r){let o=e.noteProgress,h=e.noteOverall,g=e.noteBar,b=e.noteBeat,u=e.#t,a=e.#l;e.#t=r[0],e.#l=1<=u&&(u()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ue=(e,t,l,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Oe(t))!Ie.call(e,a)&&a!==l&&ie(e,a,{get:()=>t[a],enumerable:!(c=De(t,a))||c.enumerable});return e};var Ae=(e,t,l)=>(l=e!=null?Re(Pe(e)):{},Ue(t||!e||!e.__esModule?ie(l,"default",{value:e,enumerable:!0}):l,e));var Se=Le((wt,j)=>{(function(){"use strict";let e={fatal:!0},t=[new TextDecoder("iso-8859-15",e),new TextDecoder("sjis",e),new TextDecoder("euc-jp",e),new TextDecoder("utf-8",e),new TextDecoder("utf-16",e),new TextDecoder("ascii")],l={debug:!1,parse:function(c,a){if(c instanceof Uint8Array)return l.Uint8(c);if(typeof c=="string")return l.Base64(c);if(c instanceof HTMLElement&&c.type==="file")return l.addListener(c,a);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(c,a){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(c===void 0||!(c instanceof HTMLElement)||c.tagName!=="INPUT"||c.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;a=a||function(){},c.addEventListener("change",function(r){if(!r.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let s=new FileReader;s.readAsArrayBuffer(r.target.files[0]),s.onload=function(n){a(l.Uint8(new Uint8Array(n.target.result)))}})},Base64:function(c){let a=function(n){var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(n=n.replace(/^.*?base64,/,""),n=String(n).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(n))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");n+="==".slice(2-(3&n.length));let d,f="",o,h,p=0;for(;p>16&255):h===64?String.fromCharCode(d>>16&255,d>>8&255):String.fromCharCode(d>>16&255,d>>8&255,255&d);return f}(c=String(c));var r=a.length;let s=new Uint8Array(new ArrayBuffer(r));for(let n=0;n{h[m]=this.readInt(1)});for(let v=0;v191||$>127&&$<160)throw new RangeError(`Invalid code point: ${$}`)}p=!0,console.debug(`String byte sequence in ${t[v].encoding}`)}catch(m){console.debug(`SMF string ${m}`)}return g||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let o=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)o=this.readInt(1);else{let p=[];for(;128<=this.data.getUint8(this.pointer);)p.push(this.readInt(1)-128);var h=this.readInt(1);for(let g=1;g<=p.length;g++)o+=p[p.length-g]*Math.pow(128,g);o+=h}return o}};if(a.data=new DataView(s.buffer,s.byteOffset,s.byteLength),a.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;a.readInt(4);let r={};r.formatType=a.readInt(2),r.tracks=a.readInt(2),r.track=[];var s=a.readInt(1),n=a.readInt(1);128<=s?(r.timeDivision=[],r.timeDivision[0]=s-128,r.timeDivision[1]=n):r.timeDivision=256*s+n;for(let o=1;o<=r.tracks;o++){r.track[o-1]={event:[]};var i,d=a.readInt(4);if(d===-1)break;if(d!==1297379947)return!1;a.readInt(4);let h=0,p=!1,g,v;for(;!p&&(h++,r.track[o-1].event[h-1]={},r.track[o-1].event[h-1].deltaTime=a.readIntVLV(),(g=a.readInt(1))!==-1);)if(128<=g?v=g:(g=v,a.movePointer(-1)),g===255){r.track[o-1].event[h-1].type=255,r.track[o-1].event[h-1].metaType=a.readInt(1);var f=a.readIntVLV();switch(r.track[o-1].event[h-1].metaType){case 47:case-1:p=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:r.track[o-1].event[h-1].data=a.readStr(f);break;case 33:case 89:case 81:r.track[o-1].event[h-1].data=a.readInt(f);break;case 84:r.track[o-1].event[h-1].data=[],r.track[o-1].event[h-1].data[0]=a.readInt(1),r.track[o-1].event[h-1].data[1]=a.readInt(1),r.track[o-1].event[h-1].data[2]=a.readInt(1),r.track[o-1].event[h-1].data[3]=a.readInt(1),r.track[o-1].event[h-1].data[4]=a.readInt(1);break;case 88:r.track[o-1].event[h-1].data=[],r.track[o-1].event[h-1].data[0]=a.readInt(1),r.track[o-1].event[h-1].data[1]=a.readInt(1),r.track[o-1].event[h-1].data[2]=a.readInt(1),r.track[o-1].event[h-1].data[3]=a.readInt(1);break;default:this.customInterpreter!==null&&(r.track[o-1].event[h-1].data=this.customInterpreter(r.track[o-1].event[h-1].metaType,a,f)),this.customInterpreter!==null&&r.track[o-1].event[h-1].data!==!1||(a.readInt(f),r.track[o-1].event[h-1].data=a.readInt(f),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((g=g.toString(16).split(""))[1]||g.unshift("0"),r.track[o-1].event[h-1].type=parseInt(g[0],16),r.track[o-1].event[h-1].channel=parseInt(g[1],16),r.track[o-1].event[h-1].type){case 15:this.customInterpreter!==null&&(r.track[o-1].event[h-1].data=this.customInterpreter(r.track[o-1].event[h-1].type,a,!1)),this.customInterpreter!==null&&r.track[o-1].event[h-1].data!==!1||(i=a.readIntVLV(),r.track[o-1].event[h-1].data=a.readInt(i),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:r.track[o-1].event[h-1].data=[],r.track[o-1].event[h-1].data[0]=a.readInt(1),r.track[o-1].event[h-1].data[1]=a.readInt(1);break;case 12:case 13:r.track[o-1].event[h-1].data=a.readInt(1);break;case-1:p=!0;break;default:if(this.customInterpreter!==null&&(r.track[o-1].event[h-1].data=this.customInterpreter(r.track[o-1].event[h-1].metaType,a,!1)),this.customInterpreter===null||r.track[o-1].event[h-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return r},customInterpreter:null};if(typeof j<"u")j.exports=l;else{let c=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;c.MidiParser=l}})()});var se=function(e,t){let l=Math.min(e.length,t.length),c=e.slice(0,l),a=t.slice(0,l),r=0,s=0;for(;s0){let c=this.pool.length,a=1<=1&&s>=0;){if(s<=0)throw new Error("TTL reached.");if(r==c)r-=a;else{let i=se(t,this.pool[r]);switch(i){case 0:{s=0;break}case 1:{r+a<=c&&(r+=a);break}case-1:{r!=0&&(r-=a);break}default:console.warn(`Unexpected result ${i}.`)}}a=a>>1,s--}let n=!0;if(r>=this.pool.length)n=!1;else{let i=this;this.pool[r].forEach(function(d,f,o){n&&d!=t[f]&&(n=!1)}),!n&&se(t,this.pool[r])>0&&r++}return n||l?r:-1}else return l?0:-1},this.add=function(t,l){return t.data=l,this.pool.splice(this.point(t,!0),0,t),this},this.default=function(t){console.warn(`No match in "${this.name||"(unknown)"}" for "${t}". Default action not defined.`)},this.get=function(t){let l=this.point(t);if(l>-1)return this.pool[l].data;this.default(t)},this.run=function(t,...l){let c=this.point(t);c>-1?t.subarray?this.pool[c].data(t.subarray(this.pool[c].length),...l):this.pool[c].data(t.slice(this.pool[c].length),...l):this.default(t,...l)}};var N=class{#a={};addEventListener(e,t){this.#a[e]||(this.#a[e]=[]),this.#a[e].unshift(t)}removeEventListener(e,t){if(this.#a[e]){let l=this.#a[e].indexOf(t);l>-1&&this.#a[e].splice(l,1),this.#a[e].length<1&&delete this.#a[e]}}dispatchEvent(e,t){let l=new Event(e),c=this;l.data=t,this.#a[e]?.length>0&&this.#a[e].forEach(function(a){try{a?.call(c,l)}catch(r){console.error(r)}}),this[`on${e}`]&&this[`on${e}`](l)}};var Ne=["MSB","PRG","LSB"],_=function(e){let t=Math.floor(e/10),l=e%10;return`${t.toString(16)}${l}`},K=class{#a;strictMode=!1;get(e=0,t=0,l=0,c){let a=[e,t,l],r,s=Array.from(arguments);switch(c){case"xg":{switch(e){case 0:{l==126?s[2]=125:l==127&&(s[2]=0);break}case 32:{s[2]+=4;break}case 33:case 35:case 36:{s[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:s[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{l==126&&(s[2]=0);break}case 48:case 64:case 126:case 127:{l==126&&(s[2]=0);break}}break}case"gs":{e==0&&l<5?s[2]=0:e>125&&l<5&&l!=2&&(s[2]=e,s[0]=0);break}case"g2":case"sd":{(e>>1==40||e>95&&e<100)&&(s[2]|=16);break}case"sg":{e==8&&l==0&&(s[2]=5);break}case"s90es":{l<8?s[2]+=17:l<32?s[2]+=13:s[2]=(s[2]>>3)+19;break}case"motif":{l<8?s[2]+=28:l<32?s[2]+=13:s[2]=(s[2]>>3)+19;break}}let n=" ",i="M",d=0,f=0;switch(s[0]){case 0:{s[2]==127?i="MT-a":s[2]==126?i="MT-b":s[2]==7?i="GM-k":s[2]==5?i="SG-a":s[2]==4?i="SP-l":s[2]==0||c=="gs"&&s[2]<5?i="GM-a":(i="y",d=3);break}case 8:{c=="sg"?i="GM-s":i="r:";break}case 48:{i=`yM${(s[2]>>3).toString().padStart(2,"0")}`,d=1;break}case 56:{i="GM-b";break}case 61:case 120:{i="rDrm";break}case 62:{i="kDrm";break}case 63:{if(s[2]<17){let g=s[2];i=g<10?"kP:":"kC:",i+=g%10}else s[2]<34?i=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][s[2]-17]:i="Ds";break}case 64:{i="ySFX";break}case 67:{i="DX:S";break}case 80:case 81:case 82:case 83:{i=`Prg${"UABC"[s[0]-80]}`;break}case 88:case 89:case 90:case 91:{i=`Cmb${"UABC"[s[0]-88]}`;break}case 95:{i=`${["DR","PC"][s[2]]}-d`;break}case 96:{i=s[2]==106?"AP-a":s[2]>>4==1?"SDg":"PF",s[2]>63?f=63:s[2]>>4==1&&(f=16),d=3;break}case 97:{i=s[2]>>4==1?"SDa":"VL:",d=3,s[2]>>4==1?f=16:f=112;break}case 98:{i=s[2]>>4==1?"SDb":"SG-a",d=3,f=16;break}case 99:{i=s[2]>>4==1?"SDc":"DX",s[2]>63?f=63:s[2]>>4==1&&(f=16),d=3;break}case 100:{i="AN",s[2]>63?f=63:s[2]>>4==1&&(f=16),d=3;break}case 104:case 105:case 106:case 107:{i="SDd",f=104;break}case 121:{i=`GM-${s[2]?"":"a"}`,d=3;break}case 122:{i="lDrm";break}case 126:{i="yDrS";break}case 127:{s[2]==127?i="rDrm":i="yDrm";break}default:s[0]<48?i="r:":i="M"}i.length<4&&(i+=`${[e,l,s[0],s[2]][d]-f}`.padStart(4-i.length,"0")),c=="xg"&&e==16&&(r=`Voice${(l*128+t+1).toString().padStart(3,"0")}`,n=" ");let o=[s[0],s[1],s[2]];for(;!(r?.length>=0);)r=this.#a[s[1]||0][(s[0]<<7)+s[2]],r||(this.strictMode?(r="",n="?"):this.#a[s[1]||0][s[0]<<7]?s[0]==0?(s[2]=0,n="^"):s[2]<1?(s[0]=0,n="*"):(s[2]--,n="^"):e==48?(s[0]=0,s[2]=0,n="!"):e==62?(s[1]--,n=" ",s[1]<1&&!r?.length&&(s[0]=0,n="!")):e<63?s[0]==0?(s[2]=0,n="^"):s[2]<1?(s[0]=0,n="*"):s[2]--:e==80?(r=`PrgU:${t.toString().padStart(3,"0")}`,n="!"):e==88?(r=`CmbU:${t.toString().padStart(3,"0")}`,n="!"):e==121?(r=`GM2Vox0${l}`,n="#"):e==122?(s[1]==32?s[1]==0:s[1]%=7,r=this.#a[s[1]||0][(s[0]<<7)+s[2]],r?n=" ":(r="",n="*")):s[1]==0?(r=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${l.toString().padStart(3,"0")}`,n="!"):s[0]==0?(s[2]=0,n="^"):s[2]>0?s[2]--:s[1]>0?(s[1]=0,n="!"):(s[0]=0,n="?"));let h=[s[0],s[1],s[2]];(c=="gs"||c=="ns5r")&&n=="^"&&(n=" "),e==127&&n=="^"&&(n=" "),n!=" "&&self.debugMode&&(r="");let p="??";switch(s[0]){case 0:{s[2]==0?p="GM":s[2]==5||s[2]==7?p="KG":s[2]<126?p="XG":s[2]==127&&(p="MT");break}case 48:{p="MU";break}case 56:{p="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{p="AI";break}case 62:case 82:case 90:{p="XD";break}case 63:{s[2]<17?p="KR":s[2]<34?p="ES":p="DS";break}case 64:case 126:{p="XG";break}case 67:case 99:{p=s[2]>>4==1?"SD":"DX";break}case 81:{p="RW";break}case 95:{p=["DR","PC"][s[2]];break}case 96:{p=s[2]==106?"AP":s[2]>>4==1?"SD":"PF";break}case 97:{p=s[2]>>4==1?"SD":"VL";break}case 98:{p=s[2]>>4==1?"SD":"SG";break}case 100:{p="AN";break}case 104:case 105:case 106:case 107:{p="SD";break}case 120:{p="GS";break}case 121:{p=s[2]?"G2":"GM";break}case 122:{p="KG";break}case 127:{p=s[2]==127?"MT":t==0?"GM":"XG";break}default:s[0]<48&&(s[0]==16&&c=="xg"?p="XG":p="GS")}return{name:r||`${_(e||0)} ${_(t||0)} ${_(l||0)}`,iid:o,eid:h,sid:a,ending:n,sect:i,standard:p}}async load(e,t,l){let c=this,a=[],r=0,s=0;e.split(` -`).forEach(function(n,i){let d=n.split(" "),f=[];i==0?d.forEach(function(o,h){a[Ne.indexOf(o)]=h}):d.forEach(async function(o,h){h>2?(c.#a[f[a[1]]]=c.#a[f[a[1]]]||[],(!c.#a[f[a[1]]][(f[a[0]]<<7)+f[a[2]]]?.length||t)&&(c.#a[f[a[1]]][(f[a[0]]<<7)+f[a[2]]]=d[3],r++),s++):f.push(parseInt(d[h]))})}),t||console.debug(`Map "${l||"(internal)"}": ${s} total, ${r} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],l=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],c=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let a=l[0];a<=l[1];a++){let r=a<<7;for(let s=c[0];s<=c[1];s++){let n=r+s;for(let i=t[0];i<=t[1];i++)delete this.#a[i][n]}}}init(){this.#a=[];for(let e=0;e<128;e++)this.#a.push([""])}async loadFiles(...e){this.init();let t=this;e.forEach(async function(l,c){try{await fetch(`./data/bank/${l}.tsv`).then(function(a){return a.text()}).then(a=>{t.load(a,!1,l)})}catch{console.error(`Failed loading "${l}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var ne=class{#a={};context;set(e,t){this.#a[e]=t}has(e){return!!this.#a[e]}async read(e,t){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#a[e].call(this.context||this,t)}};var Be=function(e,t){let l=!0;return t.forEach((c,a)=>{l=l&&e[a]==c}),l},ce=function(e){let t=0;return e.forEach(l=>{t*=256,t+=l}),t},O=new TextDecoder,B=new ne;B.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),l="MSB LSB PRG NME",c=[0,0,0,0],a=32,r=0,s=0,n=!0,i=[],d=0;for(;n;){let f=t.subarray(r);([()=>{O.decode(f.subarray(0,4))=="YSFC"?(r+=80,s=1):r++},()=>{if(Be(f.subarray(0,4),c))i.forEach((o,h,p)=>{let g=ce(t.subarray(o.start+4,o.start+8));o.length=g}),s=2;else{let o=O.decode(f.subarray(0,4)),h=ce(f.subarray(4,8));i.push({type:o,start:h}),r+=8}},()=>{let o=i[d],h=t.subarray(o.start,o.start+o.length),p=32;switch(o.type){case"ENVC":{let g=a;for(;g=i.length&&(s=3,n=!1)}][s]||(()=>{n=!1}))()}return l});var P=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),I=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],He=[17.1,18.6,20.2,21.8,23.3,24.9,26.5,28,29.6,31.2,32.8,34.3,35.9,37.5,39,40.6,42.2,43.7,45.3,46.9,48.4,50],R=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],le=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],oe=function(e){let t=.1,l=-.3;return e>66?(t=5,l=315):e>56?(t=1,l=47):e>46&&(t=.5,l=18.5),t*e-l},de=function(e){return e>105?He[e-106]:e>100?e*1.1-100:e/10},fe=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),F={};`hi*, +var _e=Object.create;var fe=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var Ve=Object.getPrototypeOf,ze=Object.prototype.hasOwnProperty;var qe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var We=(e,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of Ke(t))!ze.call(e,u)&&u!==n&&fe(e,u,{get:()=>t[u],enumerable:!(l=Fe(t,u))||l.enumerable});return e};var Qe=(e,t,n)=>(n=e!=null?_e(Ve(e)):{},We(t||!e||!e.__esModule?fe(n,"default",{value:e,enumerable:!0}):n,e));var Pe=qe((Ht,ie)=>{(function(){"use strict";let e={fatal:!0},t=[new TextDecoder("iso-8859-15",e),new TextDecoder("sjis",e),new TextDecoder("euc-jp",e),new TextDecoder("utf-8",e),new TextDecoder("utf-16",e),new TextDecoder("ascii")],n={debug:!1,parse:function(l,u){if(l instanceof Uint8Array)return n.Uint8(l);if(typeof l=="string")return n.Base64(l);if(l instanceof HTMLElement&&l.type==="file")return n.addListener(l,u);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(l,u){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(l===void 0||!(l instanceof HTMLElement)||l.tagName!=="INPUT"||l.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;u=u||function(){},l.addEventListener("change",function(p){if(!p.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let h=new FileReader;h.readAsArrayBuffer(p.target.files[0]),h.onload=function(a){u(n.Uint8(new Uint8Array(a.target.result)))}})},Base64:function(l){let u=function(a){var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(a=a.replace(/^.*?base64,/,""),a=String(a).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(a))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");a+="==".slice(2-(3&a.length));let d,s="",r,c,f=0;for(;f>16&255):c===64?String.fromCharCode(d>>16&255,d>>8&255):String.fromCharCode(d>>16&255,d>>8&255,255&d);return s}(l=String(l));var p=u.length;let h=new Uint8Array(new ArrayBuffer(p));for(let a=0;a{c[m]=this.readInt(1)});for(let b=0;b191||E>127&&E<160)throw new RangeError(`Invalid code point: ${E}`)}f=!0,console.debug(`String byte sequence in ${t[b].encoding}`)}catch(m){console.debug(`SMF string ${m}`)}return o||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let r=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)r=this.readInt(1);else{let f=[];for(;128<=this.data.getUint8(this.pointer);)f.push(this.readInt(1)-128);var c=this.readInt(1);for(let o=1;o<=f.length;o++)r+=f[f.length-o]*Math.pow(128,o);r+=c}return r}};if(u.data=new DataView(h.buffer,h.byteOffset,h.byteLength),u.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;u.readInt(4);let p={};p.formatType=u.readInt(2),p.tracks=u.readInt(2),p.track=[];var h=u.readInt(1),a=u.readInt(1);128<=h?(p.timeDivision=[],p.timeDivision[0]=h-128,p.timeDivision[1]=a):p.timeDivision=256*h+a;for(let r=1;r<=p.tracks;r++){p.track[r-1]={event:[]};var i,d=u.readInt(4);if(d===-1)break;if(d!==1297379947)return!1;u.readInt(4);let c=0,f=!1,o,b;for(;!f&&(c++,p.track[r-1].event[c-1]={},p.track[r-1].event[c-1].deltaTime=u.readIntVLV(),(o=u.readInt(1))!==-1);)if(128<=o?b=o:(o=b,u.movePointer(-1)),o===255){p.track[r-1].event[c-1].type=255,p.track[r-1].event[c-1].metaType=u.readInt(1);var s=u.readIntVLV();switch(p.track[r-1].event[c-1].metaType){case 47:case-1:f=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:p.track[r-1].event[c-1].data=u.readStr(s);break;case 33:case 89:case 81:p.track[r-1].event[c-1].data=u.readInt(s);break;case 84:p.track[r-1].event[c-1].data=[],p.track[r-1].event[c-1].data[0]=u.readInt(1),p.track[r-1].event[c-1].data[1]=u.readInt(1),p.track[r-1].event[c-1].data[2]=u.readInt(1),p.track[r-1].event[c-1].data[3]=u.readInt(1),p.track[r-1].event[c-1].data[4]=u.readInt(1);break;case 88:p.track[r-1].event[c-1].data=[],p.track[r-1].event[c-1].data[0]=u.readInt(1),p.track[r-1].event[c-1].data[1]=u.readInt(1),p.track[r-1].event[c-1].data[2]=u.readInt(1),p.track[r-1].event[c-1].data[3]=u.readInt(1);break;default:this.customInterpreter!==null&&(p.track[r-1].event[c-1].data=this.customInterpreter(p.track[r-1].event[c-1].metaType,u,s)),this.customInterpreter!==null&&p.track[r-1].event[c-1].data!==!1||(u.readInt(s),p.track[r-1].event[c-1].data=u.readInt(s),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((o=o.toString(16).split(""))[1]||o.unshift("0"),p.track[r-1].event[c-1].type=parseInt(o[0],16),p.track[r-1].event[c-1].channel=parseInt(o[1],16),p.track[r-1].event[c-1].type){case 15:this.customInterpreter!==null&&(p.track[r-1].event[c-1].data=this.customInterpreter(p.track[r-1].event[c-1].type,u,!1)),this.customInterpreter!==null&&p.track[r-1].event[c-1].data!==!1||(i=u.readIntVLV(),p.track[r-1].event[c-1].data=u.readInt(i),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:p.track[r-1].event[c-1].data=[],p.track[r-1].event[c-1].data[0]=u.readInt(1),p.track[r-1].event[c-1].data[1]=u.readInt(1);break;case 12:case 13:p.track[r-1].event[c-1].data=u.readInt(1);break;case-1:f=!0;break;default:if(this.customInterpreter!==null&&(p.track[r-1].event[c-1].data=this.customInterpreter(p.track[r-1].event[c-1].metaType,u,!1)),this.customInterpreter===null||p.track[r-1].event[c-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return p},customInterpreter:null};if(typeof ie<"u")ie.exports=n;else{let l=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;l.MidiParser=n}})()});var he=function(e,t){let n=Math.min(e.length,t.length),l=e.slice(0,n),u=t.slice(0,n),p=0,h=0;for(;h0){let l=this.pool.length,u=1<=1&&h>=0;){if(h<=0)throw new Error("TTL reached.");if(p==l)p-=u;else{let i=he(t,this.pool[p]);switch(i){case 0:{h=0;break}case 1:{p+u<=l&&(p+=u);break}case-1:{p!=0&&(p-=u);break}default:console.warn(`Unexpected result ${i}.`)}}u=u>>1,h--}let a=!0;if(p>=this.pool.length)a=!1;else{let i=this;this.pool[p].forEach(function(d,s,r){a&&d!=t[s]&&(a=!1)}),!a&&he(t,this.pool[p])>0&&p++}return a||n?p:-1}else return n?0:-1},this.add=function(t,n){return t.data=n,this.pool.splice(this.point(t,!0),0,t),this},this.default=function(t){console.warn(`No match in "${this.name||"(unknown)"}" for "${t}". Default action not defined.`)},this.get=function(t){let n=this.point(t);if(n>-1)return this.pool[n].data;this.default(t)},this.run=function(t,...n){let l=this.point(t);l>-1?t.subarray?this.pool[l].data(t.subarray(this.pool[l].length),...n):this.pool[l].data(t.slice(this.pool[l].length),...n):this.default(t,...n)}};var V=class{#t={};addEventListener(e,t){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(t)}removeEventListener(e,t){if(this.#t[e]){let n=this.#t[e].indexOf(t);n>-1&&this.#t[e].splice(n,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,t){let n=new Event(e),l=this;n.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(u){try{u?.call(l,n)}catch(p){console.error(p)}}),this[`on${e}`]&&this[`on${e}`](n)}};var Ye=["MSB","PRG","LSB"],Y=function(e){let t=Math.floor(e/10),n=e%10;return`${t.toString(16)}${n}`},j=class{#t;strictMode=!1;get(e=0,t=0,n=0,l){let u=[e,t,n],p,h=Array.from(arguments);switch(l){case"xg":{switch(e){case 0:{n==126?h[2]=125:n==127&&(h[2]=0);break}case 16:{n==126&&(h[2]=0);break}case 32:{h[2]+=4;break}case 33:case 35:case 36:{h[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:h[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{n==126&&(h[2]=0);break}case 48:case 64:case 126:case 127:{n==126&&(h[2]=0);break}}break}case"gs":{e==0&&n<5?h[2]=0:e>125&&n<5&&n!=2&&(h[2]=e,h[0]=0);break}case"g2":case"sd":{(e>>1==40||e>95&&e<100)&&(h[2]|=16);break}case"sg":{e==8&&n==0&&(h[2]=5);break}case"s90es":{n<8?h[2]+=17:n<32?h[2]+=13:h[2]=(h[2]>>3)+19;break}case"motif":{n<8?h[2]+=28:n<32?h[2]+=13:h[2]=(h[2]>>3)+19;break}}let a=" ",i="M",d=0,s=0;switch(h[0]){case 0:{h[2]==127?i="MT-a":h[2]==126?i="MT-b":h[2]==7?i="GM-k":h[2]==5?i="SG-a":h[2]==4?i="SP-l":h[2]==0||l=="gs"&&h[2]<5?i="GM-a":(i="y",d=3);break}case 8:{l=="sg"?i="GM-s":i="r:";break}case 48:{i=`yM${(h[2]>>3).toString().padStart(2,"0")}`,d=1;break}case 56:{i="GM-b";break}case 61:case 120:{i="rDrm";break}case 62:{i="kDrm";break}case 63:{if(h[2]<17){let o=h[2];i=o<10?"kP:":"kC:",i+=o%10}else h[2]<34?i=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][h[2]-17]:i="Ds";break}case 64:{i="ySFX";break}case 67:{i="DX:S";break}case 80:case 81:case 82:case 83:{i=`Prg${"UABC"[h[0]-80]}`;break}case 88:case 89:case 90:case 91:{i=`Cmb${"UABC"[h[0]-88]}`;break}case 95:{i=`${["DR","PC"][h[2]]}-d`;break}case 96:{i=h[2]==106?"AP-a":h[2]>>4==1?"SDg":"PF",h[2]>63?s=63:h[2]>>4==1&&(s=16),d=3;break}case 97:{i=h[2]>>4==1?"SDa":"VL:",d=3,h[2]>>4==1?s=16:s=112;break}case 98:{i=h[2]>>4==1?"SDb":"SG-a",d=3,s=16;break}case 99:{i=h[2]>>4==1?"SDc":"DX",h[2]>63?s=63:h[2]>>4==1&&(s=16),d=3;break}case 100:{i="AN",h[2]>63?s=63:h[2]>>4==1&&(s=16),d=3;break}case 104:case 105:case 106:case 107:{i="SDd",s=104;break}case 121:{i=`GM-${h[2]?"":"a"}`,d=3;break}case 122:{i="lDrm";break}case 126:{i="yDrS";break}case 127:{h[2]==127?i="rDrm":i="yDrm";break}default:h[0]<48?i="r:":i="M"}i.length<4&&(i+=`${[e,n,h[0],h[2]][d]-s}`.padStart(4-i.length,"0")),l=="xg"&&(e==0?h[2]<100?i=i.replace("y0","y:"):h[2]==125&&(i="y126"):e==16&&(p=`Voice${(h[2]*128+h[1]+1).toString().padStart(3,"0")}`,a=" "));let r=[h[0],h[1],h[2]];for(;!(p?.length>=0);)p=this.#t[h[1]||0][(h[0]<<7)+h[2]],p||(this.strictMode?(p="",a="?"):this.#t[h[1]||0][h[0]<<7]?h[0]==0?(h[2]=0,a="^"):h[2]<1?(h[0]=0,a="*"):(h[2]--,a="^"):e==48?(h[0]=0,h[2]=0,a="!"):e==62?(h[1]--,a=" ",h[1]<1&&!p?.length&&(h[0]=0,a="!")):e<63?h[0]==0?(h[2]=0,a="^"):h[2]<1?(h[0]=0,a="*"):h[2]--:e==80?(p=`PrgU:${t.toString().padStart(3,"0")}`,a="!"):e==88?(p=`CmbU:${t.toString().padStart(3,"0")}`,a="!"):e==121?(p=`GM2Vox0${n}`,a="#"):e==122?(h[1]==32?h[1]==0:h[1]%=7,p=this.#t[h[1]||0][(h[0]<<7)+h[2]],p?a=" ":(p="",a="*")):h[1]==0?(p=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")}`,a="!"):h[0]==0?(h[2]=0,a="^"):h[2]>0?h[2]--:h[1]>0?(h[1]=0,a="!"):(h[0]=0,a="?"));let c=[h[0],h[1],h[2]];(l=="gs"||l=="ns5r")&&a=="^"&&(a=" "),e==127&&a=="^"&&(a=" "),a!=" "&&self.debugMode&&(p="");let f="??";switch(h[0]){case 0:{h[2]==0?f="GM":h[2]==5||h[2]==7?f="KG":h[2]<126?f="XG":h[2]==127&&(f="MT");break}case 48:{f="MU";break}case 56:{f="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{f="AI";break}case 62:case 82:case 90:{f="XD";break}case 63:{h[2]<17?f="KR":h[2]<34?f="ES":f="DS";break}case 64:case 126:{f="XG";break}case 67:case 99:{f=h[2]>>4==1?"SD":"DX";break}case 81:{f="RW";break}case 95:{f=["DR","PC"][h[2]];break}case 96:{f=h[2]==106?"AP":h[2]>>4==1?"SD":"PF";break}case 97:{f=h[2]>>4==1?"SD":"VL";break}case 98:{f=h[2]>>4==1?"SD":"SG";break}case 100:{f="AN";break}case 104:case 105:case 106:case 107:{f="SD";break}case 120:{f="GS";break}case 121:{f=h[2]?"G2":"GM";break}case 122:{f="KG";break}case 127:{f=h[2]==127?"MT":t==0?"GM":"XG";break}default:h[0]<48&&(h[0]==16&&l=="xg"?f="XG":f="GS")}return{name:p||`${Y(e||0)} ${Y(t||0)} ${Y(n||0)}`,iid:r,eid:c,sid:u,ending:a,sect:i,standard:f}}async load(e,t,n){let l=this,u=[],p=0,h=0;e.split(` +`).forEach(function(a,i){let d=a.split(" "),s=[];i==0?d.forEach(function(r,c){u[Ye.indexOf(r)]=c}):d.forEach(async function(r,c){c>2?(l.#t[s[u[1]]]=l.#t[s[u[1]]]||[],(!l.#t[s[u[1]]][(s[u[0]]<<7)+s[u[2]]]?.length||t)&&(l.#t[s[u[1]]][(s[u[0]]<<7)+s[u[2]]]=d[3],p++),h++):s.push(parseInt(d[c]))})}),t||console.debug(`Map "${n||"(internal)"}": ${h} total, ${p} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],n=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],l=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let u=n[0];u<=n[1];u++){let p=u<<7;for(let h=l[0];h<=l[1];h++){let a=p+h;for(let i=t[0];i<=t[1];i++)delete this.#t[i][a]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let t=this;e.forEach(async function(n,l){try{await fetch(`./data/bank/${n}.tsv`).then(function(u){return u.text()}).then(u=>{t.load(u,!1,n)})}catch{console.error(`Failed loading "${n}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var ue=class{#t={};context;set(e,t){this.#t[e]=t}has(e){return!!this.#t[e]}async read(e,t){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,t)}};var je=function(e,t){let n=!0;return t.forEach((l,u)=>{n=n&&e[u]==l}),n},pe=function(e){let t=0;return e.forEach(n=>{t*=256,t+=n}),t},H=new TextDecoder,z=new ue;z.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),n="MSB LSB PRG NME",l=[0,0,0,0],u=32,p=0,h=0,a=!0,i=[],d=0;for(;a;){let s=t.subarray(p);([()=>{H.decode(s.subarray(0,4))=="YSFC"?(p+=80,h=1):p++},()=>{if(je(s.subarray(0,4),l))i.forEach((r,c,f)=>{let o=pe(t.subarray(r.start+4,r.start+8));r.length=o}),h=2;else{let r=H.decode(s.subarray(0,4)),c=pe(s.subarray(4,8));i.push({type:r,start:c}),p+=8}},()=>{let r=i[d],c=t.subarray(r.start,r.start+r.length),f=32;switch(r.type){case"ENVC":{let o=u;for(;o=i.length&&(h=3,a=!1)}][h]||(()=>{a=!1}))()}return n});var G=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),X=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],Ze=[17.1,18.6,20.2,21.8,23.3,24.9,26.5,28,29.6,31.2,32.8,34.3,35.9,37.5,39,40.6,42.2,43.7,45.3,46.9,48.4,50],U=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],be=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],ge=function(e){let t=.1,n=-.3;return e>66?(t=5,n=315):e>56?(t=1,n=47):e>46&&(t=.5,n=18.5),t*e-n},me=function(e){return e>105?Ze[e-106]:e>100?e*1.1-100:e/10},ye=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),Z={};`hi*, ka,か ki,き ku,く @@ -139,8 +139,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let t=e.split(",");F[t[0]]=t[1]});var he=function(e){let t=e;e[0]=="*"&&(t=t.slice(1)),["aa","ii","uu","ee","oo"].forEach(c=>{for(;t.indexOf(c)>-1;)t=t.replace(c,c[0])});for(let c in F)t=t.replaceAll(c,F[c]);t.indexOf("ん")==0&&t.length>1&&(t=t.slice(1));let l=t.indexOf("!");return l>-1&&t.length>1&&(t=t.slice(l+1)),t},ue=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var V=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],pe=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],be=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var Ge={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},Xe={66307:["drive"],66309:["vowel",e=>"aiueo"[e]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",e=>["off","LPF","HPF"][e]],94984:["noise type",e=>["white","pink"][e]],94987:["disc type",e=>["LP","SP","EP","RND"]],94990:["hum type",e=>`${e+5}0Hz`],94993:["M/S",e=>["mono","stereo"][e]]},z=function(e){return Ge[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ge=function(e,t,l){let c=(e[0]-32<<16)+(e[1]<<8)+t,a=Xe[c]||{},r=a[0];if(r?.length)return r+=`: ${(a[1]||function(){})(l)||l}`,r},q=[68,48,95,78,41,3,110,122,0];var k=function(e=64){return Math.round(2e3*Math.log10(e/64))/100},me=function(e,t,l){let c=[],a=l==!1?t.readIntVLV():l;e==0||e==127;for(let r=0;r127)return console.debug(`Early termination: ${c}`),c.pop(),t.backOne(),t.backOne(),new Uint8Array(c)}}}return new Uint8Array(c)},Q=function(e){let t=0;return e.forEach(l=>{t+=l,t=t&127}),~t+1&127},T=function(e,t){let l=0,c=0;for(let a=0;a>r&1)<<7,n=e[a];n+=s,a%8!=0?(t(n,l,e),l++):c=e[a]}},L=function(e){let t=Math.floor(e*14.2);return t<128?t:0};var C=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],ye=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],M=[120,127,120,127,120,127,61,62,62,105,120,122,122,127],_e=[0,3,81,84,88],Ee={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},W={0:0,1:1,2:3,5:4},ve=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],$e=[36,37],H=[20,21,22,23,24,25,26,28,29,30,31,36,37,64,65],U=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19],Ke=[12,13,16,17,18,19],Fe=[33,99,100,32,102,8,9,10],we=[0,16,25,40,32,64,26,48],E={};C.forEach((e,t)=>{E[e]=t});var u={length:U.length};U.forEach((e,t)=>{u[e]=t});var Y={length:H.length};H.forEach((e,t)=>{Y[e]=t});var S=function(){return!!self.Bun||self.debugMode||!1},Ve=function(e){let t=[],l=0;return e?.forEach(function(c,a){c==247?t.push(e.subarray(l,a)):c==240&&(l=a+1)}),t.length||t.push(e.subarray(0)),S()&&console.debug(t),t};var b={ch:128,cc:U.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:H.length,dnc:128,efx:7},ke=class extends N{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#a=0;#g=0;#m=0;#h=new Array(11);get#o(){return this.#h[this.#g]}set#o(e){this.#h[this.#g]=e}#c=new Uint8Array(b.ch);#d=new Uint8Array(b.ch);#r=new Uint8Array(b.ch);#e=new Uint8Array(b.ch*b.cc);#t=new Uint8Array(b.ace);#i=new Uint8Array(b.ch);#n=new Uint8Array(b.ch*b.nn);#l=new Uint8Array(b.ch);#b=new Uint16Array(b.pl);#p=new Uint8Array(b.pl);#M=new Int16Array(b.ch);#v=new Uint8Array(b.ch);#R=0;#s=new Uint8Array(b.ch*b.rpn);#z=new Int8Array(b.ch*$e.length);#Z=new Uint8Array(b.drm*b.dpn*b.dnc);#D=new Uint8Array(b.ch);#L=new Uint8Array(128);#T=new Uint8Array(b.cmt*8);#q=new Uint8Array(1024);#U=new Uint8Array(b.cmt*64);#$=new Uint8Array(b.efx*3);#Q=new Uint8Array(b.ch);#A=0;#k=0;#f=100;#H=0;#W=500;#Y=0;#O="";#N=0;#j=0;#C=!0;#u=!1;#J;#ae=new Uint8Array(2);#w=[];#P=new Uint8Array(b.ch);#B=new Uint8Array(b.tr);baseBank=new K("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es");userBank=new K("gm");initOnReset=!1;aiEfxName="";chRedir(e,t,l){if(this.#B[t])return(this.#B[t]-1)*16+e;if([2,3].indexOf(this.#k)>-1){if(l==1)return e;let c=0,a=!0;for(;a;)this.#P[e+c]==0?(this.#P[e+c]=t,console.debug(`Assign track ${t} to channel ${e+c+1}.`),a=!1):this.#P[e+c]==t?a=!1:(c+=16,c>=128&&(c=0,a=!1));return e+c}else return e}#E=[];#G;#y={nOff:(e,t)=>{let l=e*128+t,c=this.#b.lastIndexOf(l);c>-1&&(this.#e[b.cc*e+u[64]]>63?(this.#p[c]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#n[l],state:this.NOTE_HELD})):this.#e[b.cc*e+u[66]]>63&&this.#p[c]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#p[c]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#n[l],state:this.NOTE_SOSTENUTO_HELD})):(this.#b[c]=0,this.#n[l]=0,this.#p[c]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:t,velo:0,state:this.NOTE_IDLE})))},nOn:(e,t,l)=>{let c=e*128+t,a=0;for(this.#l[e]&&this.#y.ano(e);this.#p[a]>0&&this.#b[a]!=c;)a++;a{},cAt:(e,t)=>{},hoOf:e=>{this.#p.forEach((t,l)=>{if(t==this.NOTE_HELD){let c=this.#b[l],a=c>>7;e==a&&(this.#p[l]=this.NOTE_IDLE,this.#b[l]=0,this.#n[c]=0,this.dispatchEvent("note",{part:e,note:c&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#p.forEach((t,l)=>{let c;switch(t){case this.NOTE_ATTACK:{c=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{c=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{c=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(c){this.#p[l]=c;let a=this.#b[l];this.dispatchEvent("note",{part:e,note:a&127,velo:this.#n[a],state:c})}})},soOf:e=>{this.#p.forEach((t,l)=>{if(t==this.NOTE_SOSTENUTO_HELD){let c=this.#b[l],a=c>>7;e==a&&(this.#p[l]=this.NOTE_IDLE,this.#b[l]=0,this.#n[c]=0,this.dispatchEvent("note",{part:e,note:c&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#b.forEach((t,l,c)=>{let a=t>>7,r=t&127;t==0&&this.#n[0]==0||a==e&&this.#y.nOff(a,r)})}};#ee={8:function(e){let t=e.channel,l=e.data[0];this.#y.nOff(t,l)},9:function(e){let t=e.channel;this.#c[t]=1;let l=e.data[0],c=e.data[1];c>0?this.#y.nOn(t,l,c):this.#y.nOff(t,l)},10:function(e){let t=e.channel,l=t*128+e.data[0];this.#b.indexOf(l)>-1&&(this.#n[l]=data[1],this.dispatchEvent("note",{part:t,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let t=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#a){case E.s90es:case E.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&(this.#c[t]=1);break}e.data[1]&&(this.#c[t]=1);break}default:{this.#c[t]=1;break}}})();let l=t*b.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#y.ano(t),this.#M[t]=0;let c=t*b.cc;this.#e[c+u[1]]=0,this.#e[c+u[5]]=0,this.#e[c+u[64]]=0,this.#e[c+u[65]]=0,this.#e[c+u[66]]=0,this.#e[c+u[67]]=0,this.#e[c+u[11]]=127,this.#e[c+u[101]]=127,this.#e[c+u[100]]=127,this.#e[c+u[99]]=127,this.#e[c+u[98]]=127;return}case 123:{this.#y.ano(t);return}case 124:{this.#y.ano(t);return}case 125:{this.#y.ano(t);return}case 126:{this.#l[t]=1,this.#y.ano(t);return}case 127:{this.#l[t]=0,this.#y.ano(t);return}}if(u[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Ke.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(S()&&console.debug(`${C[this.#a]}, CH${t+1}: ${e.data[1]}`),this.#a==0?e.data[1]<48?(this.#r[t]>0&&(e.data[1]=this.#e[l],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#a==E.gs?e.data[1]<56&&this.#r[t]>0&&(e.data[1]=this.#e[l],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)):this.#a==E.gm?e.data[1]<48?this.#r[t]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${t+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):this.#a==E.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),this.#a){case E.xg:{[126,127].indexOf(e.data[1])>-1?this.#r[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#r[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case E["05rw"]:case E.x5d:case E.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#r[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#r[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case E.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#r[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#r[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case E.g2:{e.data[1]==120?this.#r[t]==0&&(this.setChType(t,this.CH_DRUMS),console.debug(`CH${t+1} set to drums by MSB.`)):this.#r[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:t});break}case 6:{if(this.#R){[E.xg,E.gs,E.ns5r].indexOf(this.#a)<0&&console.warn(`NRPN commits are not available under "${C[this.#a]}" mode, even when they are supported in Octavia.`);let c=this.#e[l+u[99]],a=this.#e[l+u[98]];if(c==1){let r=Fe.indexOf(a);if(r>-1)this.#e[l+u[71+r]]=e.data[1],S()&&console.debug(`Redirected NRPN 1 ${a} to cc${71+r}.`),this.dispatchEvent("cc",{part:t,cc:71+r,data:e.data[1]});else{let s=$e.indexOf(a);s>-1?this.#z[t*10+s]=e.data[1]-64:console.warn(`NRPN 0x01${a.toString(16).padStart(2,"0")} is not supported.`),S()&&console.debug(`CH${t+1} voice NRPN ${a} commit`)}}else{if(H.indexOf(c)<0){let s=`NRPN 0x${c.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")} `;c==127?console.warn(`${s}is not necessary. Consider removing it.`):console.warn(`${s}is not supported.`)}else{let s=this.#r[t]-2;s<0?console.warn(`CH${t+1} cannot accept drum NRPN as type ${I[this.#r[t]]}.`):this.#Z[(s*b.dpn+Y[c])*b.dnc+a]=e.data[1]-64}S()&&console.debug(`CH${t+1} (${I[this.#r[t]]}) drum NRPN ${c} commit`)}}else{let c=W[this.#e[l+u[100]]];this.#e[l+u[101]]==0&&c!=null&&(S()&&console.debug(`CH${t+1} RPN 0 ${this.#e[l+u[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],ve[c][0]),ve[c][1]),this.#s[t*b.rpn+c]=e.data[1])}break}case 32:{switch(S()&&console.debug(`${C[this.#a]}, CH${t+1} LSB: ${e.data[1]}`),this.#a){case E.s90es:case E.motif:{this.setChType(t,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#a,!0);break}}this.dispatchEvent("voice",{part:t});break}case 38:{this.#R||this.#e[l+101]==0&&W[this.#e[l+100]]!=null&&(this.#s[t*b.rpn+W[this.#e[l+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#y.hoOf(t);break}case 66:{e.data[1]>>6?this.#y.soOn(t):this.#y.soOf(t);break}case 98:case 99:{this.#R=1;break}case 100:case 101:{this.#R=0;break}}this.#e[l+u[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:t,cc:e.data[0],data:e.data[1]})}},12:function(e){let t=e.channel;switch(this.#a){case E.s90es:case E.motif:{e.data&&(this.#c[t]=1);break}default:this.#c[t]=1}this.#i[t]=e.data,this.#D[t]=0,S()&&console.debug(`T:${e.track} C:${t} P:${e.data}`),this.dispatchEvent("voice",{part:t})},13:function(e){let t=this,l=e.channel;this.#b.forEach(function(c){let a=c>>7;l==a&&(t.#n[c]=e.data,t.dispatchEvent("note",{part:l,note:c&127,velo:e.data,state:t.NOTE_SUSTAIN}))})},14:function(e){let t=e.channel;this.#M[t]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)})},15:function(e){Ve(e.data).forEach(t=>{let l=t[0],c=t[1];(this.#te[l]||function(){console.debug(`Unknown manufacturer ${l}.`)})(c,t.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#E[e.meta]||function(l,c,a){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#H=0);let t=_e.indexOf(e.meta)>-1;if(S()&&console.debug(e),t)return e.reply="meta",e}};#te={64:(e,t,l)=>{this.#K.run(t,l,e)},65:(e,t,l)=>{if(t[0]<16)if(t[1]==72){let c=t[t.length-1],a=Q(t.subarray(3,t.length-1));c==a?this.#x.run(t.subarray(0,t.length-1),l,e):console.warn(`Bad SD checksum ${c}. Should be ${a}.`)}else this.#x.run(t,l,e);else{let c=t[t.length-1],a=Q(t.subarray(2,t.length-1));c==a?this.#x.run(t.subarray(0,t.length-1),l,e):console.warn(`Bad GS checksum ${c}. Should be ${a}.`)}},66:(e,t,l)=>{this.#I.run(t,l,e)},67:(e,t,l)=>{this.#S.run(t,l,e)},68:(e,t,l)=>{this.#V.run(t,l,e)},71:(e,t,l)=>{this.#F.run(t,l,e)},126:(e,t,l)=>{this.#X.run(t,l,e)},127:(e,t,l)=>{this.switchMode("gm"),this.#_.run(t,l,e)}};#X;#_;#S;#x;#I;#K;#F;#V;buildRchTree(){let e=[];this.#d.forEach((t,l)=>{e[t]?.constructor||(e[t]=[]),e[t].push(l)}),this.#J=e}getActive(){let e=this.#c.slice();return this.#a==E.mt32,e}getCc(e){let t=e*b.cc,l=this.#e.subarray(t,t+b.cc);return l[u[0]]=l[u[0]]||this.#A,l[u[32]]=l[u[32]]||this.#k,l}getCcCh(e,t){if(U.indexOf(t)<0)throw new Error("CC number not accepted");return this.#e[b.cc*e+u[t]]}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&!c&&(this.#e[e*b.cc+u[0]]=M[l])}getPitch(){return this.#M}getProgram(){return this.#i}getTexts(){return this.#w.slice()}getVel(e){let t=new Map,l=this;return l.#b.forEach(function(c,a){let r=Math.floor(c/128),s=c%128;e==r&&l.#n[c]>0&&t.set(s,{v:l.#n[c],s:l.#p[a]})}),t}getBitmap(){return{bitmap:this.#o,expire:this.#m}}getLetter(){return{text:this.#O,expire:this.#N}}getMode(){return C[this.#a]}getMaster(){return{volume:this.#f}}getRawStrength(){let e=this;return this.#b.forEach(function(t){let l=Math.floor(t/128);e.#n[t]>e.#v[l]&&(e.#v[l]=e.#n[t])}),this.#v}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(l,c){e[c]=Math.floor(l*t.#e[c*b.cc+u[7]]*t.#e[c*b.cc+u[11]]*t.#f/803288)}),e}getRpn(){return this.#s}getNrpn(){return this.#z}getVoice(e,t,l,c){let a=e||this.#A,r=t,s=l||this.#k;C[this.#a]=="ns5r"&&a>0&&a<56&&(s=3);let n=this.userBank.get(a,r,s,c);if(C[this.#a]=="mt32"&&n.name.indexOf("MT-m:")==0){let i=parseInt(n.name.slice(5)),d=i*b.cmt,f="";this.#U.subarray(d,d+10).forEach(o=>{o>31&&(f+=String.fromCharCode(o))}),this.userBank.load(`MSB LSB PRG -0 127 ${r} ${f}`,!0),n.name=f,n.ending=" "}return(n.ending!=" "||!n.name.length)&&(n=this.baseBank.get(a,r,s,c)),n}getChVoice(e){let t=this.getVoice(this.#e[e*b.cc+u[0]],this.#i[e],this.#e[e*b.cc+u[32]],C[this.#a]);if(this.#D[e])switch(this.#a){case E.mt32:t.ending="~",t.name="",this.#T.subarray(14*(e-1),14*(e-1)+10).forEach(l=>{l>31&&(t.name+=String.fromCharCode(l))})}return t}getPitchShift(e){let t=e*b.rpn;return this.#M[e]/8192*this.#s[t]+(this.#s[t+3]-64)+((this.#s[t+1]<<7)+this.#s[t+2]-8192)/8192}getEffectType(e=0){let t=3*e+1;return this.#$.subarray(t,t+2)}setEffectTypeRaw(e=0,t,l){let c=3*e;this.#$[c]=1,this.#$[c+1+ +t]=l}setEffectType(e=0,t,l){this.setEffectTypeRaw(e,!1,t),this.setEffectTypeRaw(e,!0,l)}getEffectSink(){return this.#Q}setLetterDisplay(e,t,l=0,c=3200){let a=this,r;a.#O=" ".repeat(l),e.forEach(s=>{a.#O+=String.fromCharCode(s>31?s:32),s<32&&(r=r||new Set,r.add(s))}),a.#N=Date.now()+3200,a.#O=a.#O.padEnd(32," "),r&&(r=Array.from(r),r.forEach((s,n,i)=>{i[n]=s.toString(16).padStart(2,"0")}),console.warn(`${t}${t?" ":""}invalid code point${r.length>1?"s":""}: 0x${r.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let t=!0,l=0;for(;t&&l=b.ace&&console.warn("ACE slots are full.")}getAce(){return this.#t}getChAce(e,t){if(t<0||t>=b.ace)throw new RangeError("No such ACE slot");let l=this.#t[t];if(l){if(U.indexOf(l)>=0)return this.#e[e*b.cc+u[l]];throw new Error(`Invalid ACE source: ${l}`)}else return 0}init(e=0){let t=this;t.dispatchEvent("mode","?"),t.#a=0,t.#A=0,t.#k=0,t.#H=0,t.#c.fill(0),t.#e.fill(0),t.#t.fill(0),t.#i.fill(0),t.#n.fill(0),t.#b.fill(0),t.#v.fill(0),t.#M.fill(0),t.#z.fill(0),t.#Z.fill(0),t.#f=100,t.#w=[],t.#W=500,t.#Y=0,t.#N=0,t.#O="",t.#m=0,t.#g=0,t.#o.fill(0),t.#u=!1,t.#j=0,t.#C=!0,t.#d.forEach(function(l,c,a){a[c]=c}),t.buildRchTree(),e==0&&(t.#P.fill(0),t.#B.fill(0)),t.#e[b.cc*9]=M[0],t.#e[b.cc*25]=M[0],t.#e[b.cc*41]=M[0],t.#e[b.cc*57]=M[0],t.#r.fill(t.CH_MELODIC),t.#r[9]=t.CH_DRUM1,t.#r[25]=t.CH_DRUM3,t.#r[41]=t.CH_DRUMS,t.#r[57]=t.CH_DRUMS,t.#r[73]=t.CH_DRUM5,t.#r[89]=t.CH_DRUM7,t.#r[105]=t.CH_DRUMS,t.#r[121]=t.CH_DRUMS,t.#q.fill(0),t.#U.fill(0),t.#L.fill(0),t.#T.fill(0),t.#D.fill(0),t.#$.fill(0),t.#Q.fill(0),t.aiEfxName="",t.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let l=0;l-1){if(l.#a==0||t){let a=l.#a;l.#a=c,l.#g=0,l.#A=ye[0][c],l.#k=ye[1][c];for(let s=0;s0&&l.#e[s*b.cc+u[0]]==M[a]&&(l.#e[s*b.cc]=M[c]);switch(l.initOnReset,c){case E.mt32:{q.forEach((s,n)=>{let i=n+1;l.#c[i]||(l.#i[i]=s,l.#e[i*b.cc+u[91]]=127)});break}}let r;switch(c){case E["?"]:case E.xg:{r=[1,0,65,0,5,0,0,0];break}case E.gm:case E.gs:case E.g2:case E.sd:{r=[40,4,40,18,40,32,32,0];break}case E["05rw"]:case E.x5d:case E.ns5r:{r=[44,1,44,19,44,0,44,0];break}case E.k11:case E.sg:{r=[24,0,0,0,0,0,0,0];break}case E.mt32:{r=[40,4,0,0,0,0,0,0];break}default:r=[0,0,0,0,0,0,0,0]}for(let s=0;s<4;s++)l.#$[3*s]||(l.#$[3*s+1]=r[2*s],l.#$[3*s+2]=r[2*s+1],l.dispatchEvent(`efx${["reverb","chorus","delay","insert"][s]}`,l.getEffectType(s)));l.dispatchEvent("mode",e)}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#v.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#ee[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),l=!1;this.#J[t]?.forEach(c=>{e.channel=c,l=!0,this.#ee[e.type].call(this,e)}),l||console.warn(`${Ee[e.type]?Ee[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${t+1} without any recipient.`)}this.#w.length>100&&this.#w.splice(100,this.#w.length-99)}runRaw(e){}async loadBank(e,t){switch(e=e.toLowerCase(),e){case"s7e":{this.userBank.clearRange({msb:63,lsb:[21,22]}),this.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{B.context=this,this.userBank.load(await B.read(e,t));break}}}constructor(){super();let e=this;this.#o=new Uint8Array(256),this.#h[10]=new Uint8Array(512),this.#G=new x,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let t=e.split(",");Z[t[0]]=t[1]});var ve=function(e){let t=e;e[0]=="*"&&(t=t.slice(1)),["aa","ii","uu","ee","oo"].forEach(l=>{for(;t.indexOf(l)>-1;)t=t.replace(l,l[0])});for(let l in Z)t=t.replaceAll(l,Z[l]);t.indexOf("ん")==0&&t.length>1&&(t=t.slice(1));let n=t.indexOf("!");return n>-1&&t.length>1&&(t=t.slice(n+1)),t},Ee=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var J=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],we=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],$e=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var Je={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},et={66307:["drive"],66309:["vowel",e=>"aiueo"[e]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",e=>["off","LPF","HPF"][e]],94984:["noise type",e=>["white","pink"][e]],94987:["disc type",e=>["LP","SP","EP","RND"]],94990:["hum type",e=>`${e+5}0Hz`],94993:["M/S",e=>["mono","stereo"][e]]},ee=function(e){return Je[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ke=function(e,t,n){let l=(e[0]-32<<16)+(e[1]<<8)+t,u=et[l]||{},p=u[0];if(p?.length)return p+=`: ${(u[1]||function(){})(n)||n}`,p},te=[68,48,95,78,41,3,110,122,0];var C=function(e=64){return Math.round(2e3*Math.log10(e/64))/100},xe=function(e,t,n){let l=[],u=n==!1?t.readIntVLV():n;e==0||e==127;for(let p=0;p127)return console.debug(`Early termination: ${l}`),l.pop(),t.backOne(),t.backOne(),new Uint8Array(l)}}}return new Uint8Array(l)},ae=function(e){let t=0;return e.forEach(n=>{t+=n,t=t&127}),~t+1&127},O=function(e,t){let n=0,l=0;for(let u=0;u>p&1)<<7,a=e[u];a+=h,u%8!=0?(t(a,n,e),n++):l=e[u]}},_=function(e){let t=Math.floor(e*14.2);return t<128?t:0};var A=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],Se=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],I=[120,127,120,127,120,127,61,62,62,105,120,122,122,127],tt=[0,3,81,84,88],Te={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},re={0:0,1:1,2:3,5:4},Ce=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Me=[36,37,48,49,52,53],q=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Re={26:127,29:0,30:0,31:0,52:12,53:54},F=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19],at=[12,13,16,17,18,19],rt=[33,99,100,32,102,8,9,10],De=[0,16,25,40,32,64,26,48],w={};A.forEach((e,t)=>{w[e]=t});var g={length:F.length};F.forEach((e,t)=>{g[e]=t});var R={length:q.length};q.forEach((e,t)=>{R[e]=t});var k=function(){return!!self.Bun||self.debugMode||!1},it=function(e){let t=[],n=0;return e?.forEach(function(l,u){l==247?t.push(e.subarray(n,u)):l==240&&(n=u+1)}),t.length||t.push(e.subarray(0)),k()&&console.debug(t),t};var y={ch:128,cc:F.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:q.length,dnc:128,efx:7},Oe=class extends V{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#f=0;#v=0;#l=new Array(11);get#b(){return this.#l[this.#f]}set#b(e){this.#l[this.#f]=e}#E=new Uint8Array(y.ch);#h=new Uint8Array(y.ch);#i=new Uint8Array(y.ch);#e=new Uint8Array(y.ch*y.cc);#o=new Uint8Array(y.ace);#s=new Uint8Array(y.ch);#c=new Uint8Array(y.ch*y.nn);#g=new Uint8Array(y.ch);#u=new Uint16Array(y.pl);#y=new Uint8Array(y.pl);#D=new Int16Array(y.ch);#O=new Uint8Array(y.ch);#B=0;#r=new Uint8Array(y.ch*y.rpn);#k=new Int8Array(y.ch*Me.length);#x=new Uint8Array(y.drm*y.dpn*y.dnc);#a=new Uint8Array(y.ch);#w=new Uint8Array(128);#n=new Uint8Array(y.cmt*8);#m=new Uint8Array(1024);#S=new Uint8Array(y.cmt*64);#T=new Uint8Array(y.efx*3);#H=new Uint8Array(y.ch);#P=0;#C=0;#d=100;#G=0;#V=500;#U=0;#X="";#N=0;#_=0;#M=!0;#p=!1;#J;#ae=new Uint8Array(2);#A=[];#F=new Uint8Array(y.ch);#z=new Uint8Array(y.tr);baseBank=new j("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es");userBank=new j("gm");initOnReset=!1;aiEfxName="";chRedir(e,t,n){if(this.#z[t])return(this.#z[t]-1)*16+e;if([2,3].indexOf(this.#C)>-1){if(n==1)return e;let l=0,u=!0;for(;u;)this.#F[e+l]==0?(this.#F[e+l]=t,console.debug(`Assign track ${t} to channel ${e+l+1}.`),u=!1):this.#F[e+l]==t?u=!1:(l+=16,l>=128&&(l=0,u=!1));return e+l}else return e}forceVoiceRefresh(){for(let e=0;e{let n=e*128+t,l=this.#u.lastIndexOf(n);l>-1&&(this.#e[y.cc*e+g[64]]>63?(this.#y[l]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#c[n],state:this.NOTE_HELD})):this.#e[y.cc*e+g[66]]>63&&this.#y[l]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#y[l]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#c[n],state:this.NOTE_SOSTENUTO_HELD})):(this.#u[l]=0,this.#c[n]=0,this.#y[l]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:t,velo:0,state:this.NOTE_IDLE})))},nOn:(e,t,n)=>{let l=e*128+t,u=0;for(this.#g[e]&&this.#$.ano(e);this.#y[u]>0&&this.#u[u]!=l;)u++;u{},cAt:(e,t)=>{},hoOf:e=>{this.#y.forEach((t,n)=>{if(t==this.NOTE_HELD){let l=this.#u[n],u=l>>7;e==u&&(this.#y[n]=this.NOTE_IDLE,this.#u[n]=0,this.#c[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#y.forEach((t,n)=>{let l;switch(t){case this.NOTE_ATTACK:{l=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{l=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{l=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(l){this.#y[n]=l;let u=this.#u[n];this.dispatchEvent("note",{part:e,note:u&127,velo:this.#c[u],state:l})}})},soOf:e=>{this.#y.forEach((t,n)=>{if(t==this.NOTE_SOSTENUTO_HELD){let l=this.#u[n],u=l>>7;e==u&&(this.#y[n]=this.NOTE_IDLE,this.#u[n]=0,this.#c[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#u.forEach((t,n,l)=>{let u=t>>7,p=t&127;t==0&&this.#c[0]==0||u==e&&this.#$.nOff(u,p)})}};#ee={8:function(e){let t=e.channel,n=e.data[0];this.#$.nOff(t,n)},9:function(e){let t=e.channel;this.setChActive(t,1);let n=e.data[0],l=e.data[1];l>0?this.#$.nOn(t,n,l):this.#$.nOff(t,n)},10:function(e){let t=e.channel,n=t*128+e.data[0];this.#u.indexOf(n)>-1&&(this.#c[n]=data[1],this.dispatchEvent("note",{part:t,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let t=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case w.s90es:case w.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(t,1);break}e.data[1]&&this.setChActive(t,1);break}default:{this.setChActive(t,1);break}}})();let n=t*y.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#$.ano(t),this.#D[t]=0;let l=t*y.cc;this.#e[l+g[1]]=0,this.#e[l+g[5]]=0,this.#e[l+g[64]]=0,this.#e[l+g[65]]=0,this.#e[l+g[66]]=0,this.#e[l+g[67]]=0,this.#e[l+g[11]]=127,this.#e[l+g[101]]=127,this.#e[l+g[100]]=127,this.#e[l+g[99]]=127,this.#e[l+g[98]]=127;return}case 123:{this.#$.ano(t);return}case 124:{this.#$.ano(t);return}case 125:{this.#$.ano(t);return}case 126:{this.#g[t]=1,this.#$.ano(t);return}case 127:{this.#g[t]=0,this.#$.ano(t);return}}if(g[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(at.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(k()&&console.debug(`${A[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#i[t]>0&&(e.data[1]=this.#e[n],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==w.gs?e.data[1]<56&&this.#i[t]>0&&(e.data[1]=this.#e[n],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)):this.#t==w.gm?e.data[1]<48?this.#i[t]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${t+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):this.#t==w.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),this.#t){case w.xg:{[126,127].indexOf(e.data[1])>-1?this.#i[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case w["05rw"]:case w.x5d:case w.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#i[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case w.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#i[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case w.g2:{e.data[1]==120?this.#i[t]==0&&(this.setChType(t,this.CH_DRUMS),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:t});break}case 6:{if(this.#B){[w.xg,w.gs,w.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${A[this.#t]}" mode, even when they are supported in Octavia.`);let l=this.#e[n+g[99]],u=this.#e[n+g[98]];if(l==1){let p=rt.indexOf(u);if(p>-1)this.#e[n+g[71+p]]=e.data[1],k()&&console.debug(`Redirected NRPN 1 ${u} to cc${71+p}.`),this.dispatchEvent("cc",{part:t,cc:71+p,data:e.data[1]});else{let h=Me.indexOf(u);h>-1?this.#k[t*10+h]=e.data[1]-64:console.warn(`NRPN 0x01${u.toString(16).padStart(2,"0")} is not supported.`),k()&&console.debug(`CH${t+1} voice NRPN ${u} commit`)}}else{if(q.indexOf(l)<0){let h=`NRPN 0x${l.toString(16).padStart(2,"0")}${u.toString(16).padStart(2,"0")} `;l==127?console.warn(`${h}is not necessary. Consider removing it.`):console.warn(`${h}is not supported.`)}else{let h=this.#i[t]-2;h<0?console.warn(`CH${t+1} cannot accept drum NRPN as type ${X[this.#i[t]]}.`):this.#x[(h*y.dpn+R[l])*y.dnc+u]=e.data[1]}k()&&console.debug(`CH${t+1} (${X[this.#i[t]]}) drum NRPN ${l} commit`)}}else{let l=re[this.#e[n+g[100]]];this.#e[n+g[101]]==0&&l!=null&&(k()&&console.debug(`CH${t+1} RPN 0 ${this.#e[n+g[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Ce[l][0]),Ce[l][1]),this.#r[t*y.rpn+l]=e.data[1])}break}case 32:{switch(k()&&console.debug(`${A[this.#t]}, CH${t+1} LSB: ${e.data[1]}`),this.#t){case w.s90es:case w.motif:{this.setChType(t,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.dispatchEvent("voice",{part:t});break}case 38:{this.#B||this.#e[n+101]==0&&re[this.#e[n+100]]!=null&&(this.#r[t*y.rpn+re[this.#e[n+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#$.hoOf(t);break}case 66:{e.data[1]>>6?this.#$.soOn(t):this.#$.soOf(t);break}case 98:case 99:{this.#B=1;break}case 100:case 101:{this.#B=0;break}}this.#e[n+g[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:t,cc:e.data[0],data:e.data[1]})}},12:function(e){let t=e.channel;switch(this.#t){case w.s90es:case w.motif:{e.data&&this.setChActive(t,1);break}default:this.setChActive(t,1)}this.#s[t]=e.data,this.#a[t]=0,k()&&console.debug(`T:${e.track} C:${t} P:${e.data}`),this.dispatchEvent("voice",{part:t})},13:function(e){let t=this,n=e.channel;this.#u.forEach(function(l){let u=l>>7;n==u&&(t.#c[l]=e.data,t.dispatchEvent("note",{part:n,note:l&127,velo:e.data,state:t.NOTE_SUSTAIN}))})},14:function(e){let t=e.channel;this.#D[t]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)})},15:function(e){it(e.data).forEach(t=>{let n=t[0],l=t[1];(this.#te[n]||function(){console.debug(`Unknown manufacturer ${n}.`)})(l,t.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#R[e.meta]||function(n,l,u){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#G=0);let t=tt.indexOf(e.meta)>-1;if(k()&&console.debug(e),t)return e.reply="meta",e}};#te={64:(e,t,n)=>{this.#Y.run(t,n,e)},65:(e,t,n)=>{if(t[0]<16)if(t[1]==72){let l=t[t.length-1],u=ae(t.subarray(3,t.length-1));l==u?this.#I.run(t.subarray(0,t.length-1),n,e):console.warn(`Bad SD checksum ${l}. Should be ${u}.`)}else this.#I.run(t,n,e);else{let l=t[t.length-1],u=ae(t.subarray(2,t.length-1));l==u?this.#I.run(t.subarray(0,t.length-1),n,e):console.warn(`Bad GS checksum ${l}. Should be ${u}.`)}},66:(e,t,n)=>{this.#K.run(t,n,e)},67:(e,t,n)=>{this.#L.run(t,n,e)},68:(e,t,n)=>{this.#Z.run(t,n,e)},71:(e,t,n)=>{this.#j.run(t,n,e)},126:(e,t,n)=>{this.#W.run(t,n,e)},127:(e,t,n)=>{this.switchMode("gm"),this.#Q.run(t,n,e)}};#W;#Q;#L;#I;#K;#Y;#j;#Z;buildRchTree(){let e=[];this.#h.forEach((t,n)=>{e[t]?.constructor||(e[t]=[]),e[t].push(n)}),this.#J=e}getActive(){return this.#E}getCc(e){let t=e*y.cc,n=this.#e.subarray(t,t+y.cc);return n[g[0]]=n[g[0]]||this.#P,n[g[32]]=n[g[32]]||this.#C,n}getCcCh(e,t){if(F.indexOf(t)<0)throw new Error("CC number not accepted");return this.#e[y.cc*e+g[t]]}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&!l&&(this.#e[e*y.cc+g[0]]=I[n])}setChActive(e,t=0){this.#E[e]!=t&&this.dispatchEvent("channeltoggle",{part:e,active:t}),this.#E[e]=t}getPitch(){return this.#D}getProgram(){return this.#s}getTexts(){return this.#A.slice()}getVel(e){let t=new Map,n=this;return n.#u.forEach(function(l,u){let p=Math.floor(l/128),h=l%128;e==p&&n.#c[l]>0&&t.set(h,{v:n.#c[l],s:n.#y[u]})}),t}getBitmap(){return{bitmap:this.#b,expire:this.#v}}getLetter(){return{text:this.#X,expire:this.#N}}getMode(){return A[this.#t]}getMaster(){return{volume:this.#d}}getRawStrength(){let e=this;return this.#u.forEach(function(t){let n=Math.floor(t/128);e.#c[t]>e.#O[n]&&(e.#O[n]=e.#c[t])}),this.#O}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(n,l){e[l]=Math.floor(n*t.#e[l*y.cc+g[7]]*t.#e[l*y.cc+g[11]]*t.#d/803288)}),e}getRpn(){return this.#r}getNrpn(){return this.#k}getVoice(e,t,n,l){let u=e||this.#P,p=t,h=n||this.#C;A[this.#t]=="ns5r"&&u>0&&u<56&&(h=3);let a=this.userBank.get(u,p,h,l);if(A[this.#t]=="mt32"&&a.name.indexOf("MT-m:")==0){let i=parseInt(a.name.slice(5)),d=i*y.cmt,s="";this.#S.subarray(d,d+10).forEach(r=>{r>31&&(s+=String.fromCharCode(r))}),this.userBank.load(`MSB LSB PRG +0 127 ${p} ${s}`,!0),a.name=s,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(u,p,h,l)),a}getChVoice(e){let t=this.getVoice(this.#e[e*y.cc+g[0]],this.#s[e],this.#e[e*y.cc+g[32]],A[this.#t]);if(this.#a[e])switch(this.#t){case w.mt32:t.ending="~",t.name="",this.#n.subarray(14*(e-1),14*(e-1)+10).forEach(n=>{n>31&&(t.name+=String.fromCharCode(n))})}return t}getPitchShift(e){let t=e*y.rpn;return this.#D[e]/8192*this.#r[t]+(this.#r[t+3]-64)+((this.#r[t+1]<<7)+this.#r[t+2]-8192)/8192}getEffectType(e=0){let t=3*e+1;return this.#T.subarray(t,t+2)}setEffectTypeRaw(e=0,t,n){let l=3*e;this.#T[l]=1,this.#T[l+1+ +t]=n}setEffectType(e=0,t,n){this.setEffectTypeRaw(e,!1,t),this.setEffectTypeRaw(e,!0,n)}getEffectSink(){return this.#H}setLetterDisplay(e,t,n=0,l=3200){let u=this,p;u.#X=" ".repeat(n),e.forEach(h=>{u.#X+=String.fromCharCode(h>31?h:32),h<32&&(p=p||new Set,p.add(h))}),u.#N=Date.now()+l,p&&(p=Array.from(p),p.forEach((h,a,i)=>{i[a]=h.toString(16).padStart(2,"0")}),console.warn(`${t}${t?" ":""}invalid code point${p.length>1?"s":""}: 0x${p.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let t=!0,n=0;for(;t&&n=y.ace&&console.warn("ACE slots are full.")}getAce(){return this.#o}getChAce(e,t){if(t<0||t>=y.ace)throw new RangeError("No such ACE slot");let n=this.#o[t];if(n){if(F.indexOf(n)>=0)return this.#e[e*y.cc+g[n]];throw new Error(`Invalid ACE source: ${n}`)}else return 0}initDrums(){let e=this;e.#x.fill(64);for(let t=0;t-1){if(n.#t==0||t){let u=n.#t;n.initOnReset&&t&&this.init(1),n.#t=l,n.#f=0,n.#P=Se[0][l],n.#C=Se[1][l];for(let h=0;h0&&n.#e[h*y.cc+g[0]]==I[u]&&(n.#e[h*y.cc]=I[l]);switch(l){case w.mt32:{te.forEach((h,a)=>{let i=a+1;n.#E[i]||(n.#s[i]=h,n.#e[i*y.cc+g[91]]=127)});for(let h=1;h<10;h++)n.dispatchEvent("voice",{part:h});break}}let p;switch(l){case w["?"]:case w.xg:{p=[1,0,65,0,5,0,0,0];break}case w.gm:case w.gs:case w.g2:case w.sd:{p=[40,4,40,18,40,32,32,0];break}case w["05rw"]:case w.x5d:case w.ns5r:{p=[44,1,44,19,44,0,44,0];break}case w.k11:case w.sg:{p=[24,0,0,0,0,0,0,0];break}case w.mt32:{p=[40,4,0,0,0,0,0,0];break}default:p=[0,0,0,0,0,0,0,0]}for(let h=0;h<4;h++)n.#T[3*h]||(n.#T[3*h+1]=p[2*h],n.#T[3*h+2]=p[2*h+1],n.dispatchEvent(`efx${["reverb","chorus","delay","insert"][h]}`,n.getEffectType(h)));n.dispatchEvent("mode",e),n.forceVoiceRefresh()}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#O.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#ee[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),n=!1;this.#J[t]?.forEach(l=>{e.channel=l,n=!0,this.#ee[e.type].call(this,e)}),n||console.warn(`${Te[e.type]?Te[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${t+1} without any recipient.`)}this.#A.length>100&&this.#A.splice(100,this.#A.length-99)}runRaw(e){}async loadBank(e,t){let n=this;switch(e=e.toLowerCase(),e){case"s7e":{n.userBank.clearRange({msb:63,lsb:[21,22]}),n.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{z.context=this,n.userBank.load(await z.read(e,t));break}}n.forceVoiceRefresh()}constructor(){super();let e=this;this.#b=new Uint8Array(256),this.#l[10]=new Uint8Array(512),this.#q=new D,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -148,19 +148,21 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),this.addEventListener("metacommit",function(a){let{data:r}=a;e.#w[0]?.type==r.type&&e.#w[0]?.amend?(e.#w[0].amend=r.amend,e.#w[0].data+=r.data):e.#w.unshift(r)}),this.#E[1]=function(a){switch(a=a.replaceAll(`\r +122 006 000 `),this.addEventListener("metacommit",function(a){let{data:i}=a;e.#A[0]?.type==i.type&&e.#A[0]?.amend?(e.#A[0].amend=i.amend,e.#A[0].data+=i.data):e.#A.unshift(i)}),this.#R[1]=function(a){switch(a=a.replaceAll(`\r `,` `).replaceAll("\r",` -`),a.slice(0,2)){case"@I":{this.#u=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:a.slice(2)?.trimLeft()});break}case"@K":{this.#u=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:a.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{this.#u=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:a.slice(2)?.trimLeft()});break}case"@T":{this.#u=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:a.slice(2)?.trimLeft()});break}case"@V":{this.#u=!0,this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:a.slice(2)?.trimLeft()});break}case"XF":{let r=a.slice(2).split(":");switch(r[0]){case"hd":{r.slice(1).forEach((s,n)=>{s.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][n],data:s})});break}case"ln":{r.slice(1).forEach((s,n)=>{s.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][n],data:s})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:this.#u?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` -`).forEach((r,s)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:r,mask:s!=0})})}},this.#E[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},this.#E[3]=function(a,r){r<1&&this.#H<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},this.#E[4]=function(a,r){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},this.#E[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},this.#E[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},this.#E[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},this.#E[32]=function(a){this.#H=a[0]+1},this.#E[33]=function(a,r){e.#B[r]=a+1},this.#E[81]=function(a,r){e.#W=a/1e3},this.#E[127]=function(a,r){e.#G.run(a,r)},this.#G.default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},this.#G.add([67,0,1],function(a,r){e.#B[r]=a[0]+1}),this.#X=new x("universal non-realtime"),this.#_=new x("universal realtime"),this.#S=new x("Yamaha"),this.#x=new x("Roland"),this.#I=new x("Korg"),this.#K=new x("Kawai"),this.#F=new x("Akai"),this.#V=new x("Casio");let t=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,a)};this.#X.default=t,this.#_.default=t,this.#S.default=t,this.#x.default=t,this.#I.default=t,this.#K.default=t,this.#F.default=t,this.#V.default=t,this.#X.add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),e.#u=e.#u||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),this.#_.add([4,1],a=>{e.#f=((a[1]<<7)+a[0])/16383*100,e.dispatchEvent("mastervolume",e.#f)}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64),this.#S.add([76,0,0],a=>{switch(a[0]){case 125:{console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),e.#u=!1,console.info("MIDI reset: XG");break}default:{let r=[0,0,0,0],s=(n,i)=>{r[i]=n};if(a.subarray(1).forEach((n,i)=>{let d=i+a[0];([s,s,s,s,f=>{this.#f=f*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},f=>{},f=>{}][d]||(()=>{}))(n,i)}),a[0]<4){let n=0;r.forEach(i=>{n=n<<4,n+=i}),n-=1024}}}}).add([76,2,1],a=>{let r="XG ";a[0]<32?(r+="reverb ",a.subarray(1).forEach((s,n)=>{([i=>{e.setEffectTypeRaw(0,!1,i),console.info(`${r}main type: ${P[i]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},i=>{e.setEffectTypeRaw(0,!0,i),console.debug(`${r}sub type: ${i+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},i=>{console.debug(`${r}time: ${oe(i)}s`)},i=>{console.debug(`${r}diffusion: ${i}`)},i=>{console.debug(`${r}initial delay: ${i}`)},i=>{console.debug(`${r}HPF cutoff: ${R[i]}Hz`)},i=>{console.debug(`${r}LPF cutoff: ${R[i]}Hz`)},i=>{console.debug(`${r}width: ${i}`)},i=>{console.debug(`${r}height: ${i}`)},i=>{console.debug(`${r}depth: ${i}`)},i=>{console.debug(`${r}wall type: ${i}`)},i=>{console.debug(`${r}dry/wet: ${i}`)},i=>{console.debug(`${r}send: ${k(i)}dB`)},i=>{console.debug(`${r}pan: ${i-64}`)},!1,!1,i=>{console.debug(`${r}delay: ${i}`)},i=>{console.debug(`${r}density: ${i}`)},i=>{console.debug(`${r}balance: ${i}`)},i=>{},i=>{console.debug(`${r}feedback: ${i}`)},i=>{}][a[0]+n]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(s)})):a[0]<64?(r+="chorus ",a.subarray(1).forEach((s,n)=>{([i=>{e.setEffectTypeRaw(1,!1,i),console.info(`${r}main type: ${P[i]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},i=>{e.setEffectTypeRaw(1,!0,i),console.debug(`${r}sub type: ${i+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},i=>{console.debug(`${r}LFO: ${le[i]}Hz`)},i=>{},i=>{console.debug(`${r}feedback: ${i}`)},i=>{console.debug(`${r}delay offset: ${de(i)}ms`)},i=>{},i=>{console.debug(`${r}low: ${R[i]}Hz`)},i=>{console.debug(`${r}low: ${i-64}dB`)},i=>{console.debug(`${r}high: ${R[i]}Hz`)},i=>{console.debug(`${r}high: ${i-64}dB`)},i=>{console.debug(`${r}dry/wet: ${i}`)},i=>{console.debug(`${r}send: ${k(i)}dB`)},i=>{console.debug(`${r}pan: ${i-64}`)},i=>{console.debug(`${r}to reverb: ${k(i)}dB`)},!1,i=>{},i=>{},i=>{},i=>{console.debug(`${r}LFO phase diff: ${(i-64)*3}deg`)},i=>{console.debug(`${r}input mode: ${i?"stereo":"mono"}`)},i=>{}][a[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(s)})):a[0]<86?(r+="variation ",a.subarray(1).forEach((s,n)=>{([i=>{e.setEffectTypeRaw(2,!1,i),console.info(`${r}main type: ${P[i]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},i=>{e.setEffectTypeRaw(2,!0,i),console.debug(`${r}sub type: ${i+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+n]||function(){})(s)})):a[0]<97?(r+="variation ",a.subarray(1).forEach((s,n)=>{[i=>{console.debug(`${r}send: ${k(i)}dB`)},i=>{console.debug(`${r}pan: ${i-64}`)},i=>{console.debug(`${r}to reverb: ${k(i)}dB`)},i=>{console.debug(`${r}to chorus: ${k(i)}dB`)},i=>{console.debug(`${r}connection: ${i?"system":"insertion"}`)},i=>{console.debug(`${r}channel: CH${i+1}`)},i=>{console.debug(`${r}mod wheel: ${i-64}`)},i=>{console.debug(`${r}bend wheel: ${i-64}`)},i=>{console.debug(`${r}channel after touch: ${i-64}`)},i=>{console.debug(`${r}AC1: ${i-64}`)},i=>{console.debug(`${r}AC2: ${i-64}`)}][a[0]-86+n](s)})):a[0]>111&&a[0]<118?r+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((r,s)=>{let n=s+a[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][r]}`);else{let i=n-1>>2,d=n-1&3,f=`XG EQ ${i} ${["gain","freq","Q","shape"][d]}: `;[()=>{console.debug(`${f}${r-64}dB`)},()=>{console.debug(`${f}${r} (raw)`)},()=>{console.debug(`${f}${r/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!r]}`)}][d]()}})}).add([76,3],a=>{let r=a[0],s=a[1],n=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((i,d)=>{([f=>{e.setEffectTypeRaw(3+r,!1,f),console.info(`${n}main type: ${P[f]}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))},f=>{e.setEffectTypeRaw(3+r,!0,f),console.debug(`${n}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))}][s+d]||function(){})(i)})}).add([76,6,0],a=>{let r=a[0];r<64?e.setLetterDisplay(a.subarray(1),"XG letter display",r):e.#N=Date.now()}).add([76,7,0],a=>{let r=a[0];e.#g=0,e.#m=Date.now()+3200,e.#o.fill(0);let s=a.subarray(1);for(let n=0;n>6-p&1,p++})}).add([76,8],(a,r)=>{let s=e.chRedir(a[0],r,!0),n=a[1],i=b.cc*s,d=`XG CH${s+1} `,f=`Unknown XG part address ${n}.`;a.subarray(2).forEach((o,h)=>{n<1?console.debug(f):n<41?([()=>{e.#e[i+u[0]]=o},()=>{e.#e[i+u[32]]=o},()=>{e.#i[s]=o},()=>{let p=e.chRedir(o,r,!0);e.#d[s]=p,s!=p&&(e.buildRchTree(),console.info(`${d}receives from CH${p+1}`))},()=>{e.#l[s]=+!o},()=>{},()=>{e.setChType(s,o,E.xg),console.debug(`${d}type: ${I[o]||o}`)},()=>{e.#s[b.rpn*s+3]=o},!1,!1,()=>{e.#e[i+u[7]]=o},!1,!1,()=>{e.#e[i+u[10]]=o||128},!1,!1,()=>{e.#e[i+u[128]]=o},()=>{e.#e[i+u[93]]=o},()=>{e.#e[i+u[91]]=o},()=>{e.#e[i+u[94]]=o},()=>{e.#e[i+u[76]]=o},()=>{e.#e[i+u[77]]=o},()=>{e.#e[i+u[78]]=o},()=>{e.#e[i+u[74]]=o},()=>{e.#e[i+u[71]]=o},()=>{e.#e[i+u[73]]=o},()=>{e.#e[i+u[75]]=o},()=>{e.#e[i+u[72]]=o}][n+h-1]||(()=>{}))():n<48?console.debug(f):n<111?n>102&&n<105&&(e.#e[i+u[[5,65][n&1]]]=o):n<114?console.debug(f):n<116?console.debug(`${d}EQ ${["bass","treble"][n&1]} gain: ${o-64}dB`):n<118?console.debug(f):n<120?console.debug(`${d}EQ ${["bass","treble"][n&1]} freq: ${o}`):console.debug(f)})}).add([76,9],(a,r)=>{let s=e.chRedir(a[0],r,!0),n=a[1],i=`PLG-150VL CH${s+1} `;a.subarray(2).forEach((d,f)=>{let o=f+n;switch(o){case 1:{console.info(`${i}breath mode: ${["system","breath","velocity","touch EG"][d]}`);break}case 0:case 27:case 28:break;default:if(o<27){let h=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][o-3>>1];o&1?o<23?(console.debug(`${i}${h} control source: ${ue(d)}`),d&&d<96&&e.allocateAce(d)):console.debug(`${i}${h} scale break point: ${d}`):console.debug(`${i}${h} depth: ${d-64}`)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][a[0]]} for CH${a[2]+1}.`)}).add([73,0,0],(a,r)=>{let s=a[0],n="MU1000 System: ";a.subarray(1).forEach((i,d)=>{let f=s+d;f==8?console.debug(`${n}LCD contrast set to ${i}.`):f==18?(e.#k=i?126:0,console.debug(`${n}bank defaults to ${i?"MU100 Native":"MU Basic"}.`)):f>=64&&f<69&&[()=>{e.dispatchEvent("channelactive",i)},()=>{i<8?(e.dispatchEvent("channelmin",i<<4),console.debug(`Octavia System: Minimum CH${(i<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{i<8?(e.dispatchEvent("channelmax",(i<<4)+15),console.debug(`Octavia System: Maximum CH${(i<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#C=!!i,console.info(`Octavia System: RS receiving ${["dis","en"][i]}abled.`)}][f-64]()})}).add([73,10,0],(a,r)=>{let s=a[0],n=`MU1000 RS${e.#C?"":" (ignored)"}: `;if(s<16)switch(s){case 2:{let i=e.chRedir(0,r,!0);e.#C&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+63)),console.info(`${n}Show CH1~64`);break}case 3:{let i=e.chRedir(a[1]<<5,r,!0);e.#C&&e.dispatchEvent("channelmin",i),e.#C&&e.dispatchEvent("channelmax",i+31),console.info(`${n}Show CH${i+1}~CH${i+32}`);break}default:console.debug(`${n}unknown switch ${s} invoked.`)}else if(s<32){if(e.#C){let i=e.chRedir(s-16+(e.#j<<4),r,!0);e.dispatchEvent("channelactive",i)}}else if(s<36){let i=e.chRedir(s-32<<4,r,!0);e.#C&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+15),e.#j=s-32),console.info(`${n}Show CH${i+1}~CH${i+16}`)}}).add([93,3],(a,r)=>{let s=e.chRedir(a[0],r,!0),n=`PLG-100SG CH${s+1} `,i=Date.now();if(a[1]==0){let d="",f=0;a.subarray(2).forEach((o,h)=>{h%2==0?d+=fe[o]||o.toString().padStart("0"):f+=o*13}),i>=e.#Y&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${he(d)}`,amend:!0}),e.#Y=i+Math.ceil(f/2)+e.#W,S()&&console.debug(`${n}vocals: ${d}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)}),this.#S.add([76,48],a=>{}).add([76,49],a=>{}).add([76,50],a=>{}).add([76,51],a=>{}),this.#S.add([89,0],(a,r,s)=>{if(e.eprom){let n=a[0],i=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);S()&&console.debug(`MU1000 EPROM trail to 0x${i.toString(16).padStart(6,"0")}, ${n} bytes.`);let d=e.eprom.data;a.subarray(4).forEach((f,o)=>{let h=o>>3,p=o&7;if(p==7)for(let g=0;g<7;g++)d[i+7*h+g]+=(f>>6-g&1)<<7;else d[i+7*h+p]=f})}}).add([89,1],(a,r,s)=>{let n=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];S()&&console.debug(`MU1000 EPROM jump to 0x${n.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=n)}).add([89,2],(a,r,s)=>{if(e.eprom){let n=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);S()&&console.debug(`MU1000 EPROM write to 0x${n.toString(16).padStart(6,"0")}.`);let i=e.eprom.data;a.subarray(4).forEach((d,f)=>{let o=f>>3,h=f&7;if(h==7)for(let p=0;p<7;p++)i[n+7*o+p]+=(d>>6-p&1)<<7;else i[n+7*o+h]=d})}}).add([89,3],(a,r,s)=>{}),this.#S.add([39,48],(a,r,s)=>{}).add([43,0,0],(a,r,s)=>{let n=[0,0,0,0],i=(d,f)=>{n[f]=d};if(a.subarray(1).forEach((d,f)=>{let o=f+a[0];[i,i,i,i,()=>{this.#f=d*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},()=>d-64,()=>d||128,()=>d,()=>d,()=>{console.debug(`TG300 variation on cc${d}.`)}][o](d,o)}),a[0]<4){let d=0;n.forEach(f=>{d=d<<4,d+=f}),d-=1024}}).add([43,1,0],(a,r,s)=>{}).add([43,2],(a,r,s)=>{let n=e.chRedir(a[0],r,!0),i=a[1],d=b.cc*n,f=`TG300 CH${n+1} `;a.subarray(2).forEach((o,h)=>{h<5?([()=>{},()=>{e.#e[d+u[0]]=o},()=>{e.#e[d+u[32]]=o},()=>{e.#i[n]=o},()=>{let p=e.chRedir(o,r,!0);e.#d[n]=p,n!=p&&(e.buildRchTree(),console.info(`${f}receives from CH${p+1}`))}][h+i]||(()=>{}))(o,h+i):h<21||(h<47?([()=>{e.#l[n]=+!o},()=>{},()=>{},()=>{e.#s[b.rpn*n+3]=o},()=>{},()=>{e.#e[d+u[7]]=o},!1,!1,()=>{e.#e[d+u[10]]=o||128},!1,!1,()=>{console.debug(`${f} AC1 at cc${o}`)},()=>{console.debug(`${f} AC2 at cc${o}`)},()=>{e.#e[d+u[128]]=o},()=>{e.#e[d+u[93]]=o},()=>{e.#e[d+u[91]]=o},()=>{e.#e[d+u[94]]=o},()=>{e.#e[d+u[76]]=o},()=>{e.#e[d+u[77]]=o},()=>{e.#e[d+u[74]]=o},()=>{e.#e[d+u[71]]=o},()=>{e.#e[d+u[73]]=o},()=>{e.#e[d+u[75]]=o},()=>{e.#e[d+u[72]]=o},()=>{e.#e[d+u[78]]=o}][h+i-21]||(()=>{}))(o,h+i):h<95||([()=>{e.#e[d+u[65]]=o},()=>{e.#e[d+u[5]]=o}][h+i-95]||(()=>{}))(o,h+i))})}).add([43,7,0],(a,r,s)=>{let n=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",n)}).add([43,7,1],(a,r,s)=>{e.#g=0,e.#m=Date.now()+3200,e.#o.fill(0),a.forEach(function(n,i){let d=Math.floor(i/16),f=i%16,o=(f*3+d)*7,h=7,p=0;for(o-=f*5,d==2&&(h=2);p>6-p&1,p++})}),this.#x.add([66,18,0,0,127],(a,r,s)=>{e.switchMode("gs",!0),e.#e[b.cc*9]=120,e.#e[b.cc*25]=120,e.#e[b.cc*41]=120,e.#e[b.cc*57]=120,e.#k=3,e.#u=!1,e.#P.fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,r,s)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),e.#e[b.cc*9]=120,e.#e[b.cc*25]=120,e.#e[b.cc*41]=120,e.#e[b.cc*57]=120,e.#u=!1,e.#P.fill(0),console.info("MIDI reset: GS");break}default:{let n=[0,0,0,0],i=(d,f)=>{n[f]=d};if(a.subarray(1).forEach((d,f)=>{let o=f+a[0];[i,i,i,i,h=>{this.#f=h*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},h=>{},h=>{}][o](d,f)}),a[0]<4){let d=0;n.forEach(f=>{d=d<<4,d+=f}),d-=1024}}}}).add([66,18,64,1],a=>{let r=a[0];if(r<16){let s="".padStart(r," ");a.subarray(1).forEach((n,i)=>{s+=String.fromCharCode(Math.max(32,n))}),s=s.padEnd(16," "),console.debug(`GS patch name: ${s}`)}else r<48||(r<65?a.subarray(1).forEach((s,n)=>{let i=`GS ${r+n>55?"chorus":"reverb"} `;([()=>{console.info(`${i}type: ${V[s]}`),e.setEffectType(0,40,s),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${i}predelay: ${s}ms`)},()=>{console.info(`${i}type: ${pe[s]}`),e.setEffectType(1,40,16+s),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${i}to reverb: ${k(s)}`)},()=>{console.debug(`${i}to delay: ${k(s)}`)}][r+n-48]||(()=>{}))()}):r<80?console.debug(`Unknown GS patch address: ${r}`):r<91?a.subarray(1).forEach((s,n)=>{let i="GS delay ";([()=>{console.info(`${i}type: ${be[s]}`),e.setEffectType(2,40,32+s),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${i}to reverb: ${k(s)}`)}][r+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${r}`))}).add([66,18,64,2],a=>{let r="GS EQ ";a.subarray(1).forEach((s,n)=>{([()=>{console.debug(`${r}low freq: ${[200,400][s]}Hz`)},()=>{console.debug(`${r}low gain: ${s-64}dB`)},()=>{console.debug(`${r}high freq: ${[3e3,6e3][s]}Hz`)},()=>{console.debug(`${r}high gain: ${s-64}dB`)}][a[0]+n]||function(){console.warn(`Unknown GS EQ address: ${a[0]+n}`)})()})}).add([66,18,64,3],a=>{let r="GS EFX ",s=function(n,i){let d=ge(e.#$.subarray(10,12),i,n);d&&console.debug(`${r}${z(e.#$.subarray(10,12))} ${d}`)};a.subarray(1).forEach((n,i)=>{([()=>{e.setEffectTypeRaw(3,!1,32+n),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,n),console.info(`${r}type: ${z(e.#$.subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,()=>{console.debug(`${r}to reverb: ${k(n)}dB`)},()=>{console.debug(`${r}to chorus: ${k(n)}dB`)},()=>{console.debug(`${r}to delay: ${k(n)}dB`)},!1,()=>{console.debug(`${r}1 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${r}1 depth: ${n-64}`)},()=>{console.debug(`${r}2 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${r}2 depth: ${n-64}`)},()=>{console.debug(`${r}to EQ: ${n?"ON":"OFF"}`)}][a[0]+i]||function(d,f){console.warn(`Unknown GS EFX address: ${f}`)})(n,a[0]+i)})}).add([66,18,65],a=>{}).add([69,18,16],a=>{switch(a[0]){case 0:{let r=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",r);break}case 32:{e.#m=Date.now()+3200,a[1]==0&&(e.#g=Math.max(Math.min(a[2]-1,9),0));break}default:if(a[0]<11){e.#g>9&&(e.#g=0),e.#m=Date.now()+3200,e.#h[a[0]-1]?.length||(e.#h[a[0]-1]=new Uint8Array(256));let r=e.#h[a[0]-1],s=a[1];r.fill(0);let n=a.subarray(2);for(let i=0;i>4-g&1,g++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let l=function(a,r,s){let n=a[0],i=b.cc*r,d=b.rpn*r,f=`GS CH${r+1} `;n<3?a.subarray(1).forEach((o,h)=>{[()=>{e.#e[i+u[0]]=o},()=>{e.#i[r]=o},()=>{let p=e.chRedir(o,s,!0);e.#d[r]=p,r!=p&&(e.buildRchTree(),console.info(`${f}receives from CH${p+1}`))}][n+h]()}):n<19||(n<44?a.subarray(1).forEach((o,h)=>{([()=>{e.#l[r]=+!o},!1,()=>{e.setChType(r,o<<1,E.gs),console.debug(`${f}type: ${o?"drum ":"melodic"}${o||""}`)},()=>{e.#s[d+3]=o},!1,()=>{e.#e[i+u[7]]=o},!1,!1,()=>{e.#e[i+u[10]]=o||128},!1,!1,()=>{console.debug(`${f}CC 1: cc${o}`)},()=>{console.debug(`${f}CC 2: cc${o}`)},()=>{e.#e[i+u[93]]=o},()=>{e.#e[i+u[91]]=o},!1,!1,()=>{e.#s[d+1]=o},()=>{e.#s[d+2]=o},()=>{e.#e[i+u[94]]=o}][n+h-19]||(()=>{}))()}):n<76||console.debug(`Unknown GS part address: ${n}`))},c=function(a,r){let s=a[0],n=`GS CH${r+1} `;s<2?a.subarray(1).forEach((i,d)=>{[()=>{e.#e[b.cc*r+u[32]]=i},()=>{}][s+d]()}):s<32?console.warn(`Unknown GS misc address: ${s}`):s<35?a.subarray(1).forEach((i,d)=>{[()=>{console.debug(`${n}EQ: o${["ff","n"][i]}`)},()=>{},()=>{console.debug(`${n}EFX: o${["ff","n"][i]}`),e.#Q[r]=i}][s+d-32]()}):console.warn(`Unknown GS misc address: ${s}`)};this.#x.add([66,18,64,16],(a,r)=>{l(a,e.chRedir(9,r,!0),r)}).add([66,18,64,17],(a,r)=>{l(a,e.chRedir(0,r,!0),r)}).add([66,18,64,18],(a,r)=>{l(a,e.chRedir(1,r,!0),r)}).add([66,18,64,19],(a,r)=>{l(a,e.chRedir(2,r,!0),r)}).add([66,18,64,20],(a,r)=>{l(a,e.chRedir(3,r,!0),r)}).add([66,18,64,21],(a,r)=>{l(a,e.chRedir(4,r,!0),r)}).add([66,18,64,22],(a,r)=>{l(a,e.chRedir(5,r,!0),r)}).add([66,18,64,23],(a,r)=>{l(a,e.chRedir(6,r,!0),r)}).add([66,18,64,24],(a,r)=>{l(a,e.chRedir(7,r,!0),r)}).add([66,18,64,25],(a,r)=>{l(a,e.chRedir(8,r,!0),r)}).add([66,18,64,26],(a,r)=>{l(a,e.chRedir(10,r,!0),r)}).add([66,18,64,27],(a,r)=>{l(a,e.chRedir(11,r,!0),r)}).add([66,18,64,28],(a,r)=>{l(a,e.chRedir(12,r,!0),r)}).add([66,18,64,29],(a,r)=>{l(a,e.chRedir(13,r,!0),r)}).add([66,18,64,30],(a,r)=>{l(a,e.chRedir(14,r,!0),r)}).add([66,18,64,31],(a,r)=>{l(a,e.chRedir(15,r,!0),r)}).add([66,18,64,64],(a,r)=>{c(a,e.chRedir(9,r,!0))}).add([66,18,64,65],(a,r)=>{c(a,e.chRedir(0,r,!0))}).add([66,18,64,66],(a,r)=>{c(a,e.chRedir(1,r,!0))}).add([66,18,64,67],(a,r)=>{c(a,e.chRedir(2,r,!0))}).add([66,18,64,68],(a,r)=>{c(a,e.chRedir(3,r,!0))}).add([66,18,64,69],(a,r)=>{c(a,e.chRedir(4,r,!0))}).add([66,18,64,70],(a,r)=>{c(a,e.chRedir(5,r,!0))}).add([66,18,64,71],(a,r)=>{c(a,e.chRedir(6,r,!0))}).add([66,18,64,72],(a,r)=>{c(a,e.chRedir(7,r,!0))}).add([66,18,64,73],(a,r)=>{c(a,e.chRedir(8,r,!0))}).add([66,18,64,74],(a,r)=>{c(a,e.chRedir(10,r,!0))}).add([66,18,64,75],(a,r)=>{c(a,e.chRedir(11,r,!0))}).add([66,18,64,76],(a,r)=>{c(a,e.chRedir(12,r,!0))}).add([66,18,64,77],(a,r)=>{c(a,e.chRedir(13,r,!0))}).add([66,18,64,78],(a,r)=>{c(a,e.chRedir(14,r,!0))}).add([66,18,64,79],(a,r)=>{c(a,e.chRedir(15,r,!0))}),this.#I.add([54,65],(a,r)=>{e.switchMode("x5d");let s=(a[1]<<7)+a[0],n=(a[3]<<7)+a[2],i=e.chRedir(s&15,r,!0),d=b.cc*i;[()=>{n<1||(n<101?(e.setChType(i,e.CH_MELODIC,E.x5d),e.#i[i]=n-1,e.#e[d+u[0]]=82):n<229?(e.setChType(i,e.CH_MELODIC,E.x5d),e.#i[i]=n-101,e.#e[d+u[0]]=56):(e.setChType(i,e.CH_DRUMS,E.x5d),e.#i[i]=we[n-229]||0,e.#e[d+u[0]]=62))},()=>{e.#e[d+u[7]]=n},()=>{n<31&&(e.#e[d+u[10]]=Math.round((n-15)*4.2+64))},()=>{e.#e[d+u[93]]=L(n)},()=>{e.#e[d+u[91]]=L(n)},()=>{e.#s[i*b.rpn+3]=n>8191?n-16320:64+n},()=>{e.#s[i*b.rpn+1]=n>8191?n-16320:64+n},()=>{n>0&&(e.#s[i*b.rpn]=n)},()=>{}][s>>4]()}).add([54,76,0],(a,r)=>{e.switchMode("x5d",!0);let s="",n=82,i=0,d=0,f="MSB PRG LSB NME";T(a,function(o,h){if(h<16400){let p=h%164;switch(!0){case p<10:{o>31&&(s+=String.fromCharCode(o));break}case p==11:{f+=` -${n} ${i} ${d} ${s.trim().replace("Init Voice","")}`,i++,s="";break}}i>99&&(n=90,i=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(f)}).add([54,77,0],(a,r)=>{e.switchMode("x5d",!0);let s="",n=90,i=0,d=0,f="MSB PRG LSB NME";T(a,function(o,h){if(h<13600){let p=h%136;switch(!0){case p<10:{o>31&&(s+=String.fromCharCode(o));break}case p==11:{f+=` -${n} ${i} ${d} ${s.trim().replace("Init Combi","")}`,i++,s="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f)}).add([54,78],(a,r)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,r)=>{e.switchMode("x5d",!0),T(a,(s,n)=>{n>0&&n<3&&(e.setEffectType(n-1,44,s),e.dispatchEvent(`efx${["reverb","chorus"][n-1]}`,e.getEffectType(n-1)))})}).add([54,104],(a,r)=>{e.switchMode("x5d",!0),T(a,function(s,n,i,d){if(n<192){let f=e.chRedir(Math.floor(n/12),r,!0),o=f*b.cc;switch(n%12){case 0:{s<128?(e.setChType(f,e.CH_MELODIC,E.x5d),e.#e[o+u[0]]=82,e.#i[f]=s):(e.setChType(f,e.CH_DRUMS,E.x5d),e.#e[o+u[0]]=62,e.#i[f]=we[s-128]),s>0&&(e.#c[f]=1);break}case 1:{e.#e[o+u[7]]=s;break}case 2:{e.#s[f*b.rpn+3]=s>127?s-192:64+s;break}case 3:{e.#s[f*b.rpn+1]=s>127?s-192:64+s;break}case 4:{s<31&&(e.#e[o+u[10]]=Math.round((s-15)*4.2+64));break}case 5:{let h=s>>4,p=s&15;e.#e[o+u[91]]=L(p),e.#e[o+u[93]]=L(h);break}case 10:break;case 11:{let h=e.chRedir(s&15,r,!0),p=s>>4;e.#d[f]=s,(h!=f||p)&&(console.info(`X5D Part CH${f+1} receives from CH${h+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(n-192,r,!0)}})}),this.#x.add([22,18,127],a=>{e.switchMode("mt32",!0),e.#u=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,r,s)=>{e.switchMode("mt32");let n=e.chRedir(s,r,!0),i=a[1];a.subarray(2).forEach((d,f)=>{let o=f+i;e.#L[o+(n-1)*16]=d,([!1,()=>{let h=e.#L[n-1<<4];if(h<3)if(e.#D[n]=1,h==2)for(let p=0;p{e.#s[n*b.rpn+3]=d+40},()=>{e.#s[n*b.rpn+1]=d+14},()=>{e.#s[n*b.rpn]=d},!1,()=>{e.#e[b.cc*n+u[91]]=d?127:0},!1,()=>{e.#e[b.cc*n+u[7]]=d},()=>{e.#e[b.cc*n+u[10]]=Math.ceil(d*9.05)}][o]||(()=>{}))()})}).add([22,18,1],(a,r,s)=>{e.switchMode("mt32");let n=e.chRedir(s,r,!0)}).add([22,18,2],(a,r,s)=>{e.switchMode("mt32");let n=e.chRedir(s,r,!0),i=a[1]+(a[0]<<7);i<10&&(e.#D[n]=1),a.subarray(2).forEach((d,f)=>{let o=f+i;o<14&&(e.#T[(n-1)*b.cmt+o]=d)})}).add([22,18,3],(a,r,s)=>{if(e.switchMode("mt32"),a[0]){let n=a[1]-16}else{let n=a[1];a.subarray(2).forEach((i,d)=>{let f=d+n;e.#L[f]=i;let o=e.chRedir(1+f>>4,r,!0),h=f&15;([!1,()=>{let p=e.#L[o-1<<4];if(p<3)if(e.#D[o]=1,p==2)for(let g=0;g{e.#s[o*b.rpn+3]=i+40},()=>{e.#s[o*b.rpn+1]=i+14},()=>{e.#s[o*b.rpn]=i},!1,()=>{e.#e[b.cc*o+u[91]]=i?127:0},!1,()=>{e.#e[b.cc*o+u[7]]=i},()=>{e.#e[b.cc*o+u[10]]=Math.ceil(i*9.05)}][h]||(()=>{}))()})}}).add([22,18,4],(a,r,s)=>{e.switchMode("mt32");let n=a[1]+(a[0]<<7);a.subarray(2).forEach((i,d)=>{let f=d+n,o=e.chRedir(Math.floor(f/246+1),r,!0),h=f%246;h<14&&(e.#T[(o-1)*b.cmt+h]=i),h<10&&(e.#D[o]=1)})}).add([22,18,5],(a,r,s)=>{e.switchMode("mt32");let n=(a[0]<<7)+a[1];a.subarray(2).forEach((i,d)=>{let f=n+d,o=Math.floor(f/8),h=f&7,p=o*8;e.#q[f]=i,([!1,()=>{let g=e.#q[p];if(g<3){let v="";if(g==2){let m=b.cmt*o;v=`MT-m:${i.toString().padStart(3,"0")}`}else v=e.baseBank.get(0,i+(g<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:o}),e.userBank.load(`MSB LSB PRG NME -000 127 ${o} ${v}`,!0)}}][h]||(()=>{}))()})}).add([22,18,8],(a,r,s)=>{e.switchMode("mt32");let n=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((i,d)=>{let f=n+d;f>1)*b.cmt+f]=i)})}).add([22,18,16],(a,r,s)=>{e.switchMode("mt32");let n=a[1],i=!1,d=function(f,o){e.#d[o-12]=f,i=!0};a.subarray(2).forEach((f,o)=>{let h=o+n;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,d,d,d,d,d,d,d,d,d,()=>{e.#f=f,e.dispatchEvent("mastervolume",e.#f)}][h]||(()=>{}))(f,o)}),i&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let r=a[1],s=" ".repeat(r);a.subarray(2).forEach(n=>{n>31&&(s+=String.fromCharCode(n))}),e.#O=s.padStart(20," "),e.#N=Date.now()+3200}).add([22,18,82],(a,r)=>{let s=e.chRedir(0,r,!0);for(let n=0;n<16;n++)e.#y.ano(s+n),n&&n<10&&(e.#i[s+n]=q[n-1]);console.info("MT-32 alt reset complete.")}),this.#I.add([66,0],(a,r)=>{e.switchMode("ns5r",!0),e.#u=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,r)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),e.#u=!1}).add([66,18,0,0],(a,r)=>{let s=a[0];switch(s){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#u=!1;break}case 125:{console.info(`NS5R drum setup reset: ${a}`);break}default:if(s<10){let n=[0,0,0,0],i=(d,f)=>{n[f]=d};if(a.subarray(1).forEach((d,f)=>{[i,i,i,i,()=>{e.#f=d*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},()=>d-64,()=>d-64,()=>{},()=>{},()=>{}][s+f]()}),a[0]<4){let d=0;n.forEach(f=>{d=d<<4,d+=f}),d-=1024}}}}).add([66,18,0,1],(a,r)=>{}).add([66,18,0,2],(a,r)=>{}).add([66,18,1],(a,r)=>{let s=e.chRedir(a[0],r,!0),n=s*b.cc,i=a[1],d=`NS5R CH${s+1} `;a.subarray(2).forEach((f,o)=>{let h=i+o;h<3?[()=>{e.#e[n+u[0]]=f||121},()=>{e.#e[n+u[32]]=f},()=>{e.#i[s]=f}][h]():h<8||(h<14?[()=>{let p=e.chRedir(f,r,!0);e.#d[s]=p,s!=p&&(e.buildRchTree(),console.info(`${d}receives from CH${p+1}`))},()=>{e.#l[s]=+!f},()=>{e.setChType(s,f,E.ns5r),console.debug(`${d}type: ${I[f]}`)},()=>{e.#s[b.rpn*s+3]=f},()=>{},()=>{}][h-8]():h<16||(h<33?[()=>{e.#e[n+u[7]]=f},()=>{e.#e[n+u[11]]=f},()=>{},()=>{},()=>{e.#e[n+u[10]]=f||128},()=>{},()=>{},()=>{e.#e[n+u[93]]=f},()=>{e.#e[n+u[91]]=f},()=>{e.#e[n+u[76]]=f},()=>{e.#e[n+u[77]]=f},()=>{e.#e[n+u[78]]=f},()=>{e.#e[n+u[74]]=f},()=>{e.#e[n+u[71]]=f},()=>{e.#e[n+u[73]]=f},()=>{e.#e[n+u[75]]=f},()=>{e.#e[n+u[72]]=f}][h-16]():h<112||h<114&&[()=>{e.#e[n+u[5]]=f},()=>{e.#e[n+u[65]]=f}][h-112]()))})}).add([66,18,8,0],(a,r)=>{let s=a[0];if(s<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let n=s-32;e.#m=Date.now()+3200,e.#g=10,e.#o.fill(0);let i=a.subarray(1),d=4;i.forEach(function(f,o){let h=o+n,p=h>>4,g=h&15;if(h<80){let v=p>3,m=0,$=p0;)e.#o[g*32+p*7+($-m)]=v&1,v=v>>1,m++}})}}).add([66,52],(a,r)=>{e.switchMode("ns5r",!0),e.#u=!1;let s="";T(a,(n,i)=>{i<8?(n>31&&(s+=String.fromCharCode(n)),i==7&&(e.aiEfxName=s)):i<10&&(e.setEffectType(i-8,44,n),e.dispatchEvent(`efx${["reverb","chorus"][i-8]}`,e.getEffectType(i-8)))})}).add([66,53],(a,r)=>{e.switchMode("ns5r",!0),e.#u=!1,T(a,function(s,n){switch(!0){case n<2944:{let i=e.chRedir(Math.floor(n/92),r,!0),d=i*b.cc;switch(n%92){case 0:{e.#e[d+u[0]]=s||121;break}case 1:{e.#e[d+u[32]]=s;break}case 2:{e.#i[i]=s,s>0&&(e.#c[i]=1);break}case 3:{let f=e.chRedir(s,r,!0);e.#d[i]=f,i!=f&&(console.info(`NS5R CH${i+1} receives from CH${f+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#s[i*b.rpn+3]=s<40||s>88?s+(s>63?-192:64):s;break}case 9:case 10:{e.#e[d+u[7]]=s;break}case 11:{e.#e[d+u[11]]=s;break}case 14:{e.#e[d+u[10]]=s||128;break}case 19:{e.#e[d+u[93]]=s;break}case 20:{e.#e[d+u[91]]=s;break}case 84:{e.#e[d+u[65]]=s;break}case 85:{e.#e[d+u[5]]=s;break}}break}case n<3096:break;case n<3134:break;case n<8566:break}})}).add([66,54],(a,r)=>{e.switchMode("ns5r",!0);let s="",n=80,i=0,d=0,f="MSB PRG LSB NME";T(a,function(o,h){let p=h%158;switch(!0){case p<10:{o>31&&(s+=String.fromCharCode(o));break}case p==11:{n=o&127;break}case p==12:{d=o&127;break}case p==13:{f+=` -${n} ${i} ${d} ${s.trim().replace("Init Voice","")}`,i++,s="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(f)}).add([66,55],(a,r)=>{e.switchMode("ns5r",!0);let s="",n=88,i=0,d=0,f="MSB PRG LSB NME";T(a,function(o,h){let p=h%126;switch(!0){case p<10:{o>31&&(s+=String.fromCharCode(o));break}case p==11:break;case p==12:break;case p==13:{f+=` -${n} ${i} ${d} ${s.trim().replace("Init Combi","")}`,i++,s="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(f)}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let r=new Uint8Array(5760);T(a,(s,n,i)=>{if(n<720)for(let d=0;d<8;d++)r[n*8+d]=s>>7-d&1}),e.dispatchEvent("screen",{type:"ns5r",data:r})}).add([76],(a,r,s)=>{e.#I.run([66,...a],r,s)}),this.#K.add([16,0,8,0],(a,r,s)=>{let n=(a[2]<<4)+a[3],i="K11 ";([()=>{e.switchMode("k11",!0),e.#u=!1,e.#k=n?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,n),console.debug(`${i}reverb type: ${n}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${i}reverb time: ${n}`)},()=>{console.debug(`${i}reverb time: ${n}`)},()=>{console.debug(`${i}reverb predelay: ${n}`)},()=>{console.debug(`${i}reverb predelay: ${n}`)},()=>{console.debug(`${i}depth high: ${n}`)},()=>{console.debug(`${i}depth high: ${n}`)},()=>{console.debug(`${i}depth low: ${n}`)},()=>{console.debug(`${i}depth low: ${n}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,r,s)=>{let n=e.chRedir(a[1],r,!0),i=b.cc*n,d=b.rpn*n,f=(a[3]<<4)+a[4],o=`K11 CH${n+1} `;([()=>{f<128?(e.setChType(n,e.CH_MELODIC,E.k11),e.#e[i+u[0]]=0,e.#i[n]=f):(e.setChType(n,e.CH_DRUMS,E.k11),e.#i[n]=f-128)},()=>{let h=e.chRedir(f,r,!0);e.#d[n]=h,n!=h&&(e.buildRchTree(),console.info(`${o}receives from CH${h+1}`))},()=>{e.#e[i+u[7]]=f},()=>{e.#c[n]=f},()=>{e.#e[i+u[10]]=f},()=>{e.#s[d+3]=f+40},()=>{e.#s[d+1]=f>>1,e.#s[d+2]=f&1},()=>{e.#e[i+u[91]]=f?127:0},()=>{},()=>{e.#e[i+u[74]]=f},()=>{e.#e[i+u[73]]=f},()=>{e.#e[i+u[72]]=f}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,r,s)=>{let n=(a[2]<<4)+a[3],i="GMLX ";([()=>{console.debug(`${i}reverb type: ${n}`)},()=>{console.debug(`${i}reverb time: ${n}`)},()=>{console.debug(`${i}reverb predelay: ${n}`)},()=>{console.debug(`${i}depth high: ${n}`)},()=>{console.debug(`${i}depth low: ${n}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,r,s)=>{let n=(a[2]<<4)+a[3],i=e.chRedir(a[1],r,!0),d=i*b.cc;[()=>{n<128?(e.setChType(i,e.CH_MELODIC,E.k11),e.#e[d+u[0]]=0,e.#e[d+u[32]]=0,e.#i[i]=n):n<160?(e.setChType(i,e.CH_MELODIC,E.k11),e.#e[d+u[0]]=0,e.#e[d+u[32]]=7,e.#i[i]=n-100):(e.setChType(i,e.CH_DRUMS,E.k11),e.#e[d+u[0]]=122,e.#e[d+u[32]]=0,e.#i[i]=n-160)},()=>{let f=e.chRedir(n,r,!0);e.#d[i]=f,i!=f&&(e.buildRchTree(),console.info(`GMLX CH${i+1} receives from CH${f+1}`))}][a[0]]()}).add([16,0,9,4],(a,r,s)=>{let n=(a[2]<<4)+a[3],i=e.chRedir(a[1],r,!0),d=i*b.cc,f=i*b.rpn,o=`GMLX CH${i+1} `;[()=>{e.#c[i]=n},()=>{e.#e[d+u[7]]=n},()=>{e.#e[d+u[10]]=n},()=>{e.#e[d+u[91]]=n?127:0},()=>{e.#s[f+3]=n+40},()=>{e.#s[f+1]=n},()=>{e.#s[f]=n},()=>{}][a[0]]()}),this.#F.add([66,93,64],(a,r,s)=>{let n=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{e.#f=n*129/16383*100,e.dispatchEvent("mastervolume",e.#f);break}case 5:{n-64;break}case 6:{console.debug(`SG global reverb: ${n?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(a[1]){case 48:{console.debug(`SG reverb type: ${V[n]}`);break}}break}default:if(a[0]>>4==1){let i=e.chRedir(a[0]&15,r,!0);if(a[1]==2){let d=e.chRedir(n,r,!0);e.#d[i]=d,i!=d&&(e.buildRchTree(),console.info(`SG CH${i+1} receives from CH${d+1}`))}else a[1]==19&&(e.#e[b.cc*i+u[7]]=n)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),this.#V.add([9],(a,r,s)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),this.#S.add([127,0],(a,r,s)=>{e.switchMode("motif");let n=new Uint8Array([127,1,...a]);e.#S.run(n,r,s)}).add([127,1,0,0],(a,r,s)=>{e.switchMode("s90es");let n="S90/Motif ES system ",i=a[0];a.subarray(1).forEach((d,f)=>{([()=>{e.#f=d*12900/16383,e.dispatchEvent("mastervolume",e.#f)}][i+f]||(()=>{console.info(`Unrecognized ${n}ID: ${i+f}`)}))()})}).add([127,1,0,0,14],(a,r,s)=>{e.switchMode("s90es");let n="S90/Motif ES bulk header ",i=[];i[95]=(d,f,o)=>{console.debug(`${n}multi edit buffer: ${d[1]}`)},(i[a[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,r,s)=>{e.switchMode("s90es");let n="S90/Motif ES bulk footer ",i=[];i[95]=(d,f,o)=>{console.debug(`${n}multi edit buffer: ${d[1]}`)},(i[a[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,r,s)=>{e.switchMode("s90es");let n=e.chRedir(a[0],r,!0),i=b.cc*n,d=a[1],f=`S90/Motif ES bulk CH${n<16?n+1:"U"+(n-95)} `;console.debug(f,a),!(a[0]>15)&&a.subarray(2).forEach((o,h)=>{([()=>{e.#e[i+u[0]]=o},()=>{o&&(e.#c[n]=1),e.#e[i+u[32]]=o,e.setChType(n,[32,40].indexOf(o)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#a,!0)},()=>{o&&(e.#c[n]=1),e.#i[n]=o},()=>{let p=e.chRedir(o,r,!0);e.#d[n]=p,n!=p&&(e.buildRchTree(),console.info(`${f}receives from CH${p+1}`))},()=>{e.#l[n]=o?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{e.#e[i+u[7]]=o},()=>{e.#e[i+u[10]]=o},!1,!1,!1,()=>{e.#e[i+u[91]]=o},()=>{e.#e[i+u[93]]=o},()=>{e.#e[i+u[94]]=o},()=>{e.#e[i+u[128]]=o},()=>{},()=>{e.#e[i+u[74]]=o},()=>{e.#e[i+u[71]]=o},!1,()=>{e.#e[i+u[65]]=o},()=>{e.#e[i+u[5]]=o},()=>{}][d+h]||(()=>{}))()})}).add([127,1,54,16],(a,r,s)=>{e.switchMode("s90es");let n=a[0];a.subarray(1).forEach((i,d)=>{let o=`S90/Motif ES EQ${(d>>2)+1} `;([()=>{let h=i-64},()=>{let h=R[i]},()=>{let h=i/10},()=>{let h=i}][n+d&3]||(()=>{}))()})}),this.#x.add([0,72,18,0,0,0,0],(a,r,s)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,r,s)=>{let n=a[0]>>5,i=a[0]&31;switch(n){case 0:{console.debug(`Unknown SD-90 global effects message: -%o`,a);break}case 1:{let d=e.chRedir(i,r,!0),f=a[1],o=d*b.cc;a.subarray(2).forEach((h,p)=>{let g=f+p;g<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[o+u[0]]=h,h){case 104:case 105:case 106:case 107:case 120:{e.#r[d]||e.setChType(d,e.CH_DRUMS);break}default:e.#r[d]&&e.setChType(d,e.CH_MELODIC)}},()=>{e.#e[o+u[32]]=h},()=>{e.#i[d]=h},()=>{e.#e[o+u[7]]=h},()=>{e.#e[o+u[10]]=h},()=>{},()=>{},()=>{h<2&&(e.#l[d]=h)},()=>{h<2&&(e.#e[o+u[68]]=h?127:0)},()=>{},()=>{h<2&&(e.#e[o+u[65]]=h?127:0)},()=>{e.#e[o+u[5]]=h&15<<4|e.#e[o+u[5]]&15},()=>{e.#e[o+u[5]]=h&15|(e.#e[o+u[5]]&240)>>4},()=>{e.#e[o+u[74]]=h},()=>{e.#e[o+u[71]]=h},()=>{e.#e[o+u[73]]=h},()=>{e.#e[o+u[72]]=h},0,0,0,0,0,0,0,()=>{e.#e[o+u[128]]=h},()=>{e.#e[o+u[93]]=h},()=>{e.#e[o+u[91]]=h},0,0,()=>{e.#e[o+u[75]]=h},()=>{e.#e[o+u[76]]=h},()=>{e.#e[o+u[77]]=h},()=>{e.#e[o+u[78]]=h}][g]||(()=>{}))():g<63||(g<64?e.#r[d]?e.#e[o+u[0]]=104|h:e.#e[o+u[0]]=96|h:console.debug(`Unknown SD-90 global CH${d+1} param setup message: -%o`,a))});break}case 2:{let d=e.chRedir(i,r,!0),f=a[1];console.debug(`Unknown SD-90 global CH${d+1} MIDI setup message: +`),a.slice(0,2)){case"@I":{this.#p=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:a.slice(2)?.trimLeft()});break}case"@K":{this.#p=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:a.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{this.#p=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:a.slice(2)?.trimLeft()});break}case"@T":{this.#p=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:a.slice(2)?.trimLeft()});break}case"@V":{this.#p=!0,this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:a.slice(2)?.trimLeft()});break}case"XF":{let i=a.slice(2).split(":");switch(i[0]){case"hd":{i.slice(1).forEach((d,s)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][s],data:d})});break}case"ln":{i.slice(1).forEach((d,s)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][s],data:d})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:this.#p?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` +`).forEach((i,d)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:i,mask:d!=0})})}},this.#R[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},this.#R[3]=function(a,i){i<1&&this.#G<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},this.#R[4]=function(a,i){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},this.#R[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},this.#R[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},this.#R[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},this.#R[32]=function(a){this.#G=a[0]+1},this.#R[33]=function(a,i){e.#z[i]=a+1},this.#R[81]=function(a,i){e.#V=a/1e3},this.#R[127]=function(a,i){e.#q.run(a,i)},this.#q.default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},this.#q.add([67,0,1],function(a,i){e.#z[i]=a[0]+1}),this.#W=new D("universal non-realtime"),this.#Q=new D("universal realtime"),this.#L=new D("Yamaha"),this.#I=new D("Roland"),this.#K=new D("Korg"),this.#Y=new D("Kawai"),this.#j=new D("Akai"),this.#Z=new D("Casio");let t=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,a)};this.#W.default=t,this.#Q.default=t,this.#L.default=t,this.#I.default=t,this.#K.default=t,this.#Y.default=t,this.#j.default=t,this.#Z.default=t,this.#W.add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),e.#p=e.#p||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),this.#Q.add([4,1],a=>{e.#d=((a[1]<<7)+a[0])/16383*100,e.dispatchEvent("mastervolume",e.#d)}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64),this.#L.add([76,0,0],a=>{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),e.#p=!1,console.info("MIDI reset: XG");break}default:{let i=[0,0,0,0],d=(s,r)=>{i[r]=s};if(a.subarray(1).forEach((s,r)=>{let c=r+a[0];([d,d,d,d,f=>{this.#d=f*129/16383*100,e.dispatchEvent("mastervolume",e.#d)},f=>{},f=>{}][c]||(()=>{}))(s,r)}),a[0]<4){let s=0;i.forEach(r=>{s=s<<4,s+=r}),s-=1024}}}}).add([76,2,1],a=>{let i="XG ";a[0]<32?(i+="reverb ",a.subarray(1).forEach((d,s)=>{([r=>{e.setEffectTypeRaw(0,!1,r),console.info(`${i}main type: ${G[r]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},r=>{e.setEffectTypeRaw(0,!0,r),console.debug(`${i}sub type: ${r+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},r=>{console.debug(`${i}time: ${ge(r)}s`)},r=>{console.debug(`${i}diffusion: ${r}`)},r=>{console.debug(`${i}initial delay: ${r}`)},r=>{console.debug(`${i}HPF cutoff: ${U[r]}Hz`)},r=>{console.debug(`${i}LPF cutoff: ${U[r]}Hz`)},r=>{console.debug(`${i}width: ${r}`)},r=>{console.debug(`${i}height: ${r}`)},r=>{console.debug(`${i}depth: ${r}`)},r=>{console.debug(`${i}wall type: ${r}`)},r=>{console.debug(`${i}dry/wet: ${r}`)},r=>{console.debug(`${i}send: ${C(r)}dB`)},r=>{console.debug(`${i}pan: ${r-64}`)},!1,!1,r=>{console.debug(`${i}delay: ${r}`)},r=>{console.debug(`${i}density: ${r}`)},r=>{console.debug(`${i}balance: ${r}`)},r=>{},r=>{console.debug(`${i}feedback: ${r}`)},r=>{}][a[0]+s]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(d)})):a[0]<64?(i+="chorus ",a.subarray(1).forEach((d,s)=>{([r=>{e.setEffectTypeRaw(1,!1,r),console.info(`${i}main type: ${G[r]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},r=>{e.setEffectTypeRaw(1,!0,r),console.debug(`${i}sub type: ${r+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},r=>{console.debug(`${i}LFO: ${be[r]}Hz`)},r=>{},r=>{console.debug(`${i}feedback: ${r}`)},r=>{console.debug(`${i}delay offset: ${me(r)}ms`)},r=>{},r=>{console.debug(`${i}low: ${U[r]}Hz`)},r=>{console.debug(`${i}low: ${r-64}dB`)},r=>{console.debug(`${i}high: ${U[r]}Hz`)},r=>{console.debug(`${i}high: ${r-64}dB`)},r=>{console.debug(`${i}dry/wet: ${r}`)},r=>{console.debug(`${i}send: ${C(r)}dB`)},r=>{console.debug(`${i}pan: ${r-64}`)},r=>{console.debug(`${i}to reverb: ${C(r)}dB`)},!1,r=>{},r=>{},r=>{},r=>{console.debug(`${i}LFO phase diff: ${(r-64)*3}deg`)},r=>{console.debug(`${i}input mode: ${r?"stereo":"mono"}`)},r=>{}][a[0]-32+s]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(d)})):a[0]<86?(i+="variation ",a.subarray(1).forEach((d,s)=>{([r=>{e.setEffectTypeRaw(2,!1,r),console.info(`${i}main type: ${G[r]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},r=>{e.setEffectTypeRaw(2,!0,r),console.debug(`${i}sub type: ${r+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+s]||function(){})(d)})):a[0]<97?(i+="variation ",a.subarray(1).forEach((d,s)=>{[r=>{console.debug(`${i}send: ${C(r)}dB`)},r=>{console.debug(`${i}pan: ${r-64}`)},r=>{console.debug(`${i}to reverb: ${C(r)}dB`)},r=>{console.debug(`${i}to chorus: ${C(r)}dB`)},r=>{console.debug(`${i}connection: ${r?"system":"insertion"}`)},r=>{console.debug(`${i}channel: CH${r+1}`)},r=>{console.debug(`${i}mod wheel: ${r-64}`)},r=>{console.debug(`${i}bend wheel: ${r-64}`)},r=>{console.debug(`${i}channel after touch: ${r-64}`)},r=>{console.debug(`${i}AC1: ${r-64}`)},r=>{console.debug(`${i}AC2: ${r-64}`)}][a[0]-86+s](d)})):a[0]>111&&a[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((i,d)=>{let s=d+a[0];if(s==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let r=s-1>>2,c=s-1&3,f=`XG EQ ${r} ${["gain","freq","Q","shape"][c]}: `;[()=>{console.debug(`${f}${i-64}dB`)},()=>{console.debug(`${f}${i} (raw)`)},()=>{console.debug(`${f}${i/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!i]}`)}][c]()}})}).add([76,3],a=>{let i=a[0],d=a[1],s=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((r,c)=>{([f=>{e.setEffectTypeRaw(3+i,!1,f),console.info(`${s}main type: ${G[f]}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))},f=>{e.setEffectTypeRaw(3+i,!0,f),console.debug(`${s}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))}][d+c]||function(){})(r)})}).add([76,6,0],a=>{let i=a[0];i<64?e.setLetterDisplay(a.subarray(1),"XG letter display",i):e.#N=Date.now()}).add([76,7,0],a=>{let i=a[0];e.#f=0,e.#v=Date.now()+3200,e.#b.fill(0);let d=a.subarray(1);for(let s=0;s>6-m&1,m++})}).add([76,8],(a,i)=>{let d=e.chRedir(a[0],i,!0),s=a[1],r=y.cc*d,c=`XG CH${d+1} `,f=`Unknown XG part address ${s}.`;a.subarray(2).forEach((o,b)=>{s<1?console.debug(f):s<41?([()=>{e.#e[r+g[0]]=o,e.dispatchEvent("voice",{part:d})},()=>{e.#e[r+g[32]]=o,e.dispatchEvent("voice",{part:d})},()=>{e.#s[d]=o,e.dispatchEvent("voice",{part:d})},()=>{let m=e.chRedir(o,i,!0);e.#h[d]=m,d!=m&&(e.buildRchTree(),console.info(`${c}receives from CH${m+1}`))},()=>{e.#g[d]=+!o},()=>{},()=>{e.setChType(d,o,w.xg),console.debug(`${c}type: ${X[o]||o}`)},()=>{e.#r[y.rpn*d+3]=o},!1,!1,()=>{e.#e[r+g[7]]=o},!1,!1,()=>{e.#e[r+g[10]]=o||128},!1,!1,()=>{e.#e[r+g[128]]=o},()=>{e.#e[r+g[93]]=o},()=>{e.#e[r+g[91]]=o},()=>{e.#e[r+g[94]]=o},()=>{e.#e[r+g[76]]=o},()=>{e.#e[r+g[77]]=o},()=>{e.#e[r+g[78]]=o},()=>{e.#e[r+g[74]]=o},()=>{e.#e[r+g[71]]=o},()=>{e.#e[r+g[73]]=o},()=>{e.#e[r+g[75]]=o},()=>{e.#e[r+g[72]]=o}][s+b-1]||(()=>{}))():s<48?console.debug(f):s<111?s>102&&s<105&&(e.#e[r+g[[5,65][s&1]]]=o):s<114?console.debug(f):s<116?console.debug(`${c}EQ ${["bass","treble"][s&1]} gain: ${o-64}dB`):s<118?console.debug(f):s<120?console.debug(`${c}EQ ${["bass","treble"][s&1]} freq: ${o}`):console.debug(f)})}).add([76,9],(a,i)=>{let d=e.chRedir(a[0],i,!0),s=a[1],r=`PLG-150VL CH${d+1} `;a.subarray(2).forEach((c,f)=>{let o=f+s;switch(o){case 1:{console.info(`${r}breath mode: ${["system","breath","velocity","touch EG"][c]}`);break}case 0:case 27:case 28:break;default:if(o<27){let b=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][o-3>>1];o&1?o<23?(console.debug(`${r}${b} control source: ${Ee(c)}`),c&&c<96&&e.allocateAce(c)):console.debug(`${r}${b} scale break point: ${c}`):console.debug(`${r}${b} depth: ${c-64}`)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][a[0]]} for CH${a[2]+1}.`)}).add([73,0,0],(a,i)=>{let d=a[0],s="MU1000 System: ";a.subarray(1).forEach((r,c)=>{let f=d+c;f==8?console.debug(`${s}LCD contrast set to ${r}.`):f==18?(e.#C=r?126:0,console.debug(`${s}bank defaults to ${r?"MU100 Native":"MU Basic"}.`)):f>=64&&f<69&&[()=>{e.dispatchEvent("channelactive",r)},()=>{r<8?(e.dispatchEvent("channelmin",r<<4),console.debug(`Octavia System: Minimum CH${(r<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{r<8?(e.dispatchEvent("channelmax",(r<<4)+15),console.debug(`Octavia System: Maximum CH${(r<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#M=!!r,console.info(`Octavia System: RS receiving ${["dis","en"][r]}abled.`)}][f-64]()})}).add([73,10,0],(a,i)=>{let d=a[0],s=`MU1000 RS${e.#M?"":" (ignored)"}: `;if(d<16)switch(d){case 2:{let r=e.chRedir(0,i,!0);e.#M&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+63)),console.info(`${s}Show CH1~64`);break}case 3:{let r=e.chRedir(a[1]<<5,i,!0);e.#M&&e.dispatchEvent("channelmin",r),e.#M&&e.dispatchEvent("channelmax",r+31),console.info(`${s}Show CH${r+1}~CH${r+32}`);break}default:console.debug(`${s}unknown switch ${d} invoked.`)}else if(d<32){if(e.#M){let r=e.chRedir(d-16+(e.#_<<4),i,!0);e.dispatchEvent("channelactive",r)}}else if(d<36){let r=e.chRedir(d-32<<4,i,!0);e.#M&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+15),e.#_=d-32),console.info(`${s}Show CH${r+1}~CH${r+16}`)}}).add([93,3],(a,i)=>{let d=e.chRedir(a[0],i,!0),s=`PLG-100SG CH${d+1} `,r=Date.now();if(a[1]==0){let c="",f=0;a.subarray(2).forEach((o,b)=>{b%2==0?c+=ye[o]||o.toString().padStart("0"):f+=o*13}),r>=e.#U&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${ve(c)}`,amend:!0}),e.#U=r+Math.ceil(f/2)+e.#V,k()&&console.debug(`${s}vocals: ${c}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)});let n=function(a,i,d,s){},l=function(a,i){let d=a*y.dpn,s=i[0],r=i[1];i.subarray(2).forEach((c,f)=>{let o=f+r,b=-1;o<16?([()=>{b=24},()=>{b=25},()=>{b=26},()=>{},()=>{b=28},()=>{b=29},()=>{b=30},()=>{b=31},()=>{},()=>{},()=>{},()=>{b=20},()=>{b=21},()=>{b=22},()=>{b=23},()=>{}][o]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${a+1}.`)}))():o<32||(o<40?([()=>{b=48},()=>{b=49},!1,!1,()=>{b=52},()=>{b=53}][o-32]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${a+1}.`)}))():o<80||([()=>{b=36}][o-80]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${a+1}.`)}))()),b>=0?(k()&&console.debug(d,b,s,c),e.#x[(d+R[b])*y.dnc+s]=c):k()&&console.debug(`XG-style drum param ${o} has no writes.`)})},u=function(a,i,d){let s=a*y.dpn,r=(i<<7)+d[0];d.subarray(1).forEach((c,f)=>{let o=f+r,b=o&127,m=o>>7,E=-1;m>1&&([()=>{E=26},()=>{},()=>{E=28},()=>{E=29},()=>{E=30},()=>{},()=>{},()=>{E=31}][m-2]||(()=>{console.debug(`Unknown GS-style drum param ${m} on set ${a+1}.`)}))(),E>-1?(k()&&console.debug(s,E,b,c),e.#x[(s+R[E])*y.dnc+b]=c):k()&&console.debug(`GS-style drum param ${m} has no writes.`)})};this.#L.add([76,48],(a,i,d)=>{l(0,a)}).add([76,49],(a,i,d)=>{l(1,a)}).add([76,50],(a,i,d)=>{l(2,a)}).add([76,51],(a,i,d)=>{l(3,a)}).add([76,52],(a,i,d)=>{l(4,a)}).add([76,53],(a,i,d)=>{l(5,a)}).add([76,54],(a,i,d)=>{l(6,a)}).add([76,55],(a,i,d)=>{l(7,a)}),this.#L.add([89,0],(a,i,d)=>{if(e.eprom){let s=a[0],r=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);k()&&console.debug(`MU1000 EPROM trail to 0x${r.toString(16).padStart(6,"0")}, ${s} bytes.`);let c=e.eprom.data;a.subarray(4).forEach((f,o)=>{let b=o>>3,m=o&7;if(m==7)for(let E=0;E<7;E++)c[r+7*b+E]+=(f>>6-E&1)<<7;else c[r+7*b+m]=f})}}).add([89,1],(a,i,d)=>{let s=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];k()&&console.debug(`MU1000 EPROM jump to 0x${s.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=s)}).add([89,2],(a,i,d)=>{if(e.eprom){let s=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);k()&&console.debug(`MU1000 EPROM write to 0x${s.toString(16).padStart(6,"0")}.`);let r=e.eprom.data;a.subarray(4).forEach((c,f)=>{let o=f>>3,b=f&7;if(b==7)for(let m=0;m<7;m++)r[s+7*o+m]+=(c>>6-m&1)<<7;else r[s+7*o+b]=c})}}).add([89,3],(a,i,d)=>{}),this.#L.add([39,48],(a,i,d)=>{}).add([43,0,0],(a,i,d)=>{let s=[0,0,0,0],r=(c,f)=>{s[f]=c};if(a.subarray(1).forEach((c,f)=>{let o=f+a[0];[r,r,r,r,()=>{this.#d=c*129/16383*100,e.dispatchEvent("mastervolume",e.#d)},()=>c-64,()=>c||128,()=>c,()=>c,()=>{console.debug(`TG300 variation on cc${c}.`)}][o](c,o)}),a[0]<4){let c=0;s.forEach(f=>{c=c<<4,c+=f}),c-=1024}}).add([43,1,0],(a,i,d)=>{}).add([43,2],(a,i,d)=>{let s=e.chRedir(a[0],i,!0),r=a[1],c=y.cc*s,f=`TG300 CH${s+1} `;a.subarray(2).forEach((o,b)=>{b<5?([()=>{},()=>{e.#e[c+g[0]]=o,e.dispatchEvent("voice",{part:s})},()=>{e.#e[c+g[32]]=o,e.dispatchEvent("voice",{part:s})},()=>{e.#s[s]=o,e.dispatchEvent("voice",{part:s})},()=>{let m=e.chRedir(o,i,!0);e.#h[s]=m,s!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))}][b+r]||(()=>{}))(o,b+r):b<21||(b<47?([()=>{e.#g[s]=+!o},()=>{},()=>{},()=>{e.#r[y.rpn*s+3]=o},()=>{},()=>{e.#e[c+g[7]]=o},!1,!1,()=>{e.#e[c+g[10]]=o||128},!1,!1,()=>{console.debug(`${f} AC1 at cc${o}`)},()=>{console.debug(`${f} AC2 at cc${o}`)},()=>{e.#e[c+g[128]]=o},()=>{e.#e[c+g[93]]=o},()=>{e.#e[c+g[91]]=o},()=>{e.#e[c+g[94]]=o},()=>{e.#e[c+g[76]]=o},()=>{e.#e[c+g[77]]=o},()=>{e.#e[c+g[74]]=o},()=>{e.#e[c+g[71]]=o},()=>{e.#e[c+g[73]]=o},()=>{e.#e[c+g[75]]=o},()=>{e.#e[c+g[72]]=o},()=>{e.#e[c+g[78]]=o}][b+r-21]||(()=>{}))(o,b+r):b<95||([()=>{e.#e[c+g[65]]=o},()=>{e.#e[c+g[5]]=o}][b+r-95]||(()=>{}))(o,b+r))})}).add([43,7,0],(a,i,d)=>{let s=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",s)}).add([43,7,1],(a,i,d)=>{e.#f=0,e.#v=Date.now()+3200,e.#b.fill(0),a.forEach(function(s,r){let c=Math.floor(r/16),f=r%16,o=(f*3+c)*7,b=7,m=0;for(o-=f*5,c==2&&(b=2);m>6-m&1,m++})}),this.#I.add([66,18,0,0,127],(a,i,d)=>{e.switchMode("gs",!0),e.#e[y.cc*9]=120,e.#e[y.cc*25]=120,e.#e[y.cc*41]=120,e.#e[y.cc*57]=120,e.#C=3,e.#p=!1,e.#F.fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,i,d)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),e.#e[y.cc*9]=120,e.#e[y.cc*25]=120,e.#e[y.cc*41]=120,e.#e[y.cc*57]=120,e.#p=!1,e.#F.fill(0),console.info("MIDI reset: GS");break}default:{let s=[0,0,0,0],r=(c,f)=>{s[f]=c};if(a.subarray(1).forEach((c,f)=>{let o=f+a[0];[r,r,r,r,b=>{this.#d=b*129/16383*100,e.dispatchEvent("mastervolume",e.#d)},b=>{},b=>{}][o](c,f)}),a[0]<4){let c=0;s.forEach(f=>{c=c<<4,c+=f}),c-=1024}}}}).add([66,18,64,1],a=>{let i=a[0];if(i<16){let d="".padStart(i," ");a.subarray(1).forEach((s,r)=>{d+=String.fromCharCode(Math.max(32,s))}),d=d.padEnd(16," "),console.debug(`GS patch name: ${d}`)}else i<48||(i<65?a.subarray(1).forEach((d,s)=>{let r=`GS ${i+s>55?"chorus":"reverb"} `;([()=>{console.info(`${r}type: ${J[d]}`),e.setEffectType(0,40,d),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${r}predelay: ${d}ms`)},()=>{console.info(`${r}type: ${we[d]}`),e.setEffectType(1,40,16+d),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${C(d)}`)},()=>{console.debug(`${r}to delay: ${C(d)}`)}][i+s-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?a.subarray(1).forEach((d,s)=>{let r="GS delay ";([()=>{console.info(`${r}type: ${$e[d]}`),e.setEffectType(2,40,32+d),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${C(d)}`)}][i+s-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],a=>{let i="GS EQ ";a.subarray(1).forEach((d,s)=>{([()=>{console.debug(`${i}low freq: ${[200,400][d]}Hz`)},()=>{console.debug(`${i}low gain: ${d-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][d]}Hz`)},()=>{console.debug(`${i}high gain: ${d-64}dB`)}][a[0]+s]||function(){console.warn(`Unknown GS EQ address: ${a[0]+s}`)})()})}).add([66,18,64,3],a=>{let i="GS EFX ",d=function(s,r){let c=ke(e.#T.subarray(10,12),r,s);c&&console.debug(`${i}${ee(e.#T.subarray(10,12))} ${c}`)};a.subarray(1).forEach((s,r)=>{([()=>{e.setEffectTypeRaw(3,!1,32+s),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,s),console.info(`${i}type: ${ee(e.#T.subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,()=>{console.debug(`${i}to reverb: ${C(s)}dB`)},()=>{console.debug(`${i}to chorus: ${C(s)}dB`)},()=>{console.debug(`${i}to delay: ${C(s)}dB`)},!1,()=>{console.debug(`${i}1 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}1 depth: ${s-64}`)},()=>{console.debug(`${i}2 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}2 depth: ${s-64}`)},()=>{console.debug(`${i}to EQ: ${s?"ON":"OFF"}`)}][a[0]+r]||function(c,f){console.warn(`Unknown GS EFX address: ${f}`)})(s,a[0]+r)})}).add([66,18,65],a=>{u((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],a=>{switch(a[0]){case 0:{let i=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",i);break}case 32:{e.#v=Date.now()+3200,a[1]==0&&(e.#f=Math.max(Math.min(a[2]-1,9),0),k()&&console.debug(`GS switch display page ${a[2]-1}.`));break}default:if(a[0]<6){e.#f>9&&(e.#f=0);let i=a[0]-1<<1|a[1]>>6;e.#f==i&&(e.#v=Date.now()+3200),e.#l[i]?.length||(e.#l[i]=new Uint8Array(256));let d=e.#l[i];k()&&console.debug(`GS frame draw page ${i}.`);let s=a[1]&63;d.fill(0),a.subarray(2).forEach(function(c,f){let o=f+s,b=Math.floor(o/16),m=o%16,E=(m*4+b)*5,$=5,x=0;for(E-=m*4,b==3&&($=1);x<$;)d[E+x]=c>>4-x&1,x++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let p=function(a,i,d){let s=a[0],r=y.cc*i,c=y.rpn*i,f=`GS CH${i+1} `;s<3?(a.subarray(1).forEach((o,b)=>{[()=>{e.#e[r+g[0]]=o},()=>{e.#s[i]=o},()=>{let m=e.chRedir(o,d,!0);e.#h[i]=m,i!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))}][s+b]()}),e.dispatchEvent("voice",{part:i})):s<19||(s<44?a.subarray(1).forEach((o,b)=>{([()=>{e.#g[i]=+!o},!1,()=>{e.setChType(i,o<<1,w.gs),console.debug(`${f}type: ${o?"drum ":"melodic"}${o||""}`)},()=>{e.#r[c+3]=o},!1,()=>{e.#e[r+g[7]]=o},!1,!1,()=>{e.#e[r+g[10]]=o||128},!1,!1,()=>{console.debug(`${f}CC 1: cc${o}`)},()=>{console.debug(`${f}CC 2: cc${o}`)},()=>{e.#e[r+g[93]]=o},()=>{e.#e[r+g[91]]=o},!1,!1,()=>{e.#r[c+1]=o},()=>{e.#r[c+2]=o},()=>{e.#e[r+g[94]]=o}][s+b-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},h=function(a,i){let d=a[0],s=`GS CH${i+1} `;d<2?a.subarray(1).forEach((r,c)=>{[()=>{e.#e[y.cc*i+g[32]]=r},()=>{}][d+c]()}):d<32?console.warn(`Unknown GS misc address: ${d}`):d<35?a.subarray(1).forEach((r,c)=>{[()=>{console.debug(`${s}EQ: o${["ff","n"][r]}`)},()=>{},()=>{console.debug(`${s}EFX: o${["ff","n"][r]}`),e.#H[i]=r,e.dispatchEvent("partefxtoggle",{part:i,active:r})}][d+c-32]()}):console.warn(`Unknown GS misc address: ${d}`)};this.#I.add([66,18,64,16],(a,i)=>{p(a,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(a,i)=>{p(a,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(a,i)=>{p(a,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(a,i)=>{p(a,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(a,i)=>{p(a,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(a,i)=>{p(a,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(a,i)=>{p(a,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(a,i)=>{p(a,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(a,i)=>{p(a,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(a,i)=>{p(a,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(a,i)=>{p(a,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(a,i)=>{p(a,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(a,i)=>{p(a,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(a,i)=>{p(a,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(a,i)=>{p(a,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(a,i)=>{p(a,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(a,i)=>{h(a,e.chRedir(9,i,!0))}).add([66,18,64,65],(a,i)=>{h(a,e.chRedir(0,i,!0))}).add([66,18,64,66],(a,i)=>{h(a,e.chRedir(1,i,!0))}).add([66,18,64,67],(a,i)=>{h(a,e.chRedir(2,i,!0))}).add([66,18,64,68],(a,i)=>{h(a,e.chRedir(3,i,!0))}).add([66,18,64,69],(a,i)=>{h(a,e.chRedir(4,i,!0))}).add([66,18,64,70],(a,i)=>{h(a,e.chRedir(5,i,!0))}).add([66,18,64,71],(a,i)=>{h(a,e.chRedir(6,i,!0))}).add([66,18,64,72],(a,i)=>{h(a,e.chRedir(7,i,!0))}).add([66,18,64,73],(a,i)=>{h(a,e.chRedir(8,i,!0))}).add([66,18,64,74],(a,i)=>{h(a,e.chRedir(10,i,!0))}).add([66,18,64,75],(a,i)=>{h(a,e.chRedir(11,i,!0))}).add([66,18,64,76],(a,i)=>{h(a,e.chRedir(12,i,!0))}).add([66,18,64,77],(a,i)=>{h(a,e.chRedir(13,i,!0))}).add([66,18,64,78],(a,i)=>{h(a,e.chRedir(14,i,!0))}).add([66,18,64,79],(a,i)=>{h(a,e.chRedir(15,i,!0))}),this.#K.add([54,65],(a,i)=>{e.switchMode("x5d");let d=(a[1]<<7)+a[0],s=(a[3]<<7)+a[2],r=e.chRedir(d&15,i,!0),c=y.cc*r;[()=>{s<1||(s<101?(e.setChType(r,e.CH_MELODIC,w.x5d),e.#s[r]=s-1,e.#e[c+g[0]]=82):s<229?(e.setChType(r,e.CH_MELODIC,w.x5d),e.#s[r]=s-101,e.#e[c+g[0]]=56):(e.setChType(r,e.CH_DRUMS,w.x5d),e.#s[r]=De[s-229]||0,e.#e[c+g[0]]=62)),e.dispatchEvent("voice",{part:r})},()=>{e.#e[c+g[7]]=s},()=>{s<31&&(e.#e[c+g[10]]=Math.round((s-15)*4.2+64))},()=>{e.#e[c+g[93]]=_(s)},()=>{e.#e[c+g[91]]=_(s)},()=>{e.#r[r*y.rpn+3]=s>8191?s-16320:64+s},()=>{e.#r[r*y.rpn+1]=s>8191?s-16320:64+s},()=>{s>0&&(e.#r[r*y.rpn]=s)},()=>{}][d>>4]()}).add([54,76,0],(a,i)=>{e.switchMode("x5d",!0);let d="",s=82,r=0,c=0,f="MSB PRG LSB NME";O(a,function(o,b){if(b<16400){let m=b%164;switch(!0){case m<10:{o>31&&(d+=String.fromCharCode(o));break}case m==11:{f+=` +${s} ${r} ${c} ${d.trim().replace("Init Voice","")}`,r++,d="";break}}r>99&&(s=90,r=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([54,77,0],(a,i)=>{e.switchMode("x5d",!0);let d="",s=90,r=0,c=0,f="MSB PRG LSB NME";O(a,function(o,b){if(b<13600){let m=b%136;switch(!0){case m<10:{o>31&&(d+=String.fromCharCode(o));break}case m==11:{f+=` +${s} ${r} ${c} ${d.trim().replace("Init Combi","")}`,r++,d="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([54,78],(a,i)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,i)=>{e.switchMode("x5d",!0),O(a,(d,s)=>{s>0&&s<3&&(e.setEffectType(s-1,44,d),e.dispatchEvent(`efx${["reverb","chorus"][s-1]}`,e.getEffectType(s-1)))})}).add([54,104],(a,i)=>{e.switchMode("x5d",!0),O(a,function(d,s,r,c){if(s<192){let f=e.chRedir(Math.floor(s/12),i,!0),o=f*y.cc;switch(s%12){case 0:{d<128?(e.setChType(f,e.CH_MELODIC,w.x5d),e.#e[o+g[0]]=82,e.#s[f]=d):(e.setChType(f,e.CH_DRUMS,w.x5d),e.#e[o+g[0]]=62,e.#s[f]=De[d-128]),d>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{e.#e[o+g[7]]=d;break}case 2:{e.#r[f*y.rpn+3]=d>127?d-192:64+d;break}case 3:{e.#r[f*y.rpn+1]=d>127?d-192:64+d;break}case 4:{d<31&&(e.#e[o+g[10]]=Math.round((d-15)*4.2+64));break}case 5:{let b=d>>4,m=d&15;e.#e[o+g[91]]=_(m),e.#e[o+g[93]]=_(b);break}case 10:break;case 11:{let b=e.chRedir(d&15,i,!0),m=d>>4;e.#h[f]=d,(b!=f||m)&&(console.info(`X5D Part CH${f+1} receives from CH${b+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(s-192,i,!0)}})}),this.#I.add([22,18,127],a=>{e.switchMode("mt32",!0),e.#p=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,i,d)=>{e.switchMode("mt32");let s=e.chRedir(d,i,!0),r=a[1];a.subarray(2).forEach((c,f)=>{let o=f+r;e.#w[o+(s-1)*16]=c,([!1,()=>{let b=e.#w[s-1<<4];if(b<3){if(e.#a[s]=1,b==2)for(let m=0;m{e.#r[s*y.rpn+3]=c+40},()=>{e.#r[s*y.rpn+1]=c+14},()=>{e.#r[s*y.rpn]=c},!1,()=>{e.#e[y.cc*s+g[91]]=c?127:0},!1,()=>{e.#e[y.cc*s+g[7]]=c},()=>{e.#e[y.cc*s+g[10]]=Math.ceil(c*9.05)}][o]||(()=>{}))()})}).add([22,18,1],(a,i,d)=>{e.switchMode("mt32");let s=d&7;console.debug(`MT-32 slot #${d+1} Drum: ${a}`);let r=a[0]<<7|a[1];a.subarray(2).forEach((c,f)=>{let o=f+r,b=(o>>2)+24,m=o&3,E=s*y.dpn;if(k()&&console.debug(`MT-32 temp drum note ${b} param ${m}: ${c}`),b<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${b}`);return}[()=>{},()=>{e.#x[(E+R[26])*y.dnc+b]=Math.round(c*1.27)},()=>{e.#x[(E+R[26])*y.dnc+b]=c*9+1&127},()=>{e.#x[(E+R[26])*y.dnc+b]=c?127:0}][m]()})}).add([22,18,2],(a,i,d)=>{e.switchMode("mt32");let s=e.chRedir(d,i,!0),r=a[1]+(a[0]<<7);r<10&&(e.#a[s]=1),a.subarray(2).forEach((c,f)=>{let o=f+r;o<14&&(e.#n[(s-1)*y.cmt+o]=c)}),e.dispatchEvent("voice",{part:s})}).add([22,18,3],(a,i,d)=>{e.switchMode("mt32");let s=d&7;if(a[0]){let r=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((c,f)=>{let o=f+r,b=(o>>2)+24,m=o&3,E=s*y.dpn;if(k()&&console.debug(`MT-32 dev drum note ${b} param ${m}: ${c}`),b<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${b}`);return}[()=>{},()=>{e.#x[(E+R[26])*y.dnc+b]=Math.round(c*1.27)},()=>{e.#x[(E+R[26])*y.dnc+b]=c*9+1&127},()=>{e.#x[(E+R[26])*y.dnc+b]=c?127:0}][m]()})}else{let r=a[1];a.subarray(2).forEach((c,f)=>{let o=f+r;e.#w[o]=c;let b=e.chRedir(1+(o>>4),i,!0),m=o&15;([!1,()=>{let E=e.#w[b-1<<4];if(E<3)if(e.#a[b]=1,E==2)for(let $=0;${e.#r[b*y.rpn+3]=c+40},()=>{e.#r[b*y.rpn+1]=c+14},()=>{e.#r[b*y.rpn]=c},!1,()=>{e.#e[y.cc*b+g[91]]=c?127:0},!1,()=>{e.#e[y.cc*b+g[7]]=c},()=>{e.#e[y.cc*b+g[10]]=Math.ceil(c*9.05)}][m]||(()=>{}))()})}}).add([22,18,4],(a,i,d)=>{e.switchMode("mt32");let s=a[1]+(a[0]<<7),r=[];a.subarray(2).forEach((c,f)=>{let o=f+s,b=e.chRedir(Math.floor(o/246+1),i,!0),m=o%246;m<14&&(e.#n[(b-1)*y.cmt+m]=c),m<10&&(e.#a[b]=1),r.indexOf(b)<0&&r.push(b)}),r.forEach(c=>{e.dispatchEvent("voice",{part:c})})}).add([22,18,5],(a,i,d)=>{e.switchMode("mt32");let s=(a[0]<<7)+a[1];a.subarray(2).forEach((r,c)=>{let f=s+c,o=Math.floor(f/8),b=f&7,m=o*8;e.#m[f]=r,([!1,()=>{let E=e.#m[m];if(E<3){let $="";if(E==2){let x=y.cmt*o;$=`MT-m:${r.toString().padStart(3,"0")}`}else $=e.baseBank.get(0,r+(E<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:o}),e.userBank.load(`MSB LSB PRG NME +000 127 ${o} ${$}`,!0)}}][b]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,i,d)=>{e.switchMode("mt32");let s=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((r,c)=>{let f=s+c;f>1)*y.cmt+f]=r)}),e.forceVoiceRefresh()}).add([22,18,16],(a,i,d)=>{e.switchMode("mt32");let s=a[1],r=!1,c=function(f,o){e.#h[o-12]=f,r=!0};a.subarray(2).forEach((f,o)=>{let b=o+s;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,c,c,c,c,c,c,c,c,c,()=>{e.#d=f,e.dispatchEvent("mastervolume",e.#d)}][b]||(()=>{}))(f,o)}),r&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let i=a[1],d=" ".repeat(i);a.subarray(2).forEach(s=>{s>31?d+=String.fromCharCode(s):d+=" "}),e.#X=d.padStart(20," "),e.#N=Date.now()+3200}).add([22,18,82],(a,i)=>{let d=e.chRedir(0,i,!0);for(let s=0;s<16;s++)e.#$.ano(d+s),s&&s<10&&(e.#s[d+s]=te[s-1]);console.info("MT-32 alt reset complete.")}),this.#K.add([66,0],(a,i)=>{e.switchMode("ns5r",!0),e.#p=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,i)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),e.#p=!1}).add([66,18,0,0],(a,i)=>{let d=a[0];switch(d){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#p=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(d<10){let s=[0,0,0,0],r=(c,f)=>{s[f]=c};if(a.subarray(1).forEach((c,f)=>{[r,r,r,r,()=>{e.#d=c*129/16383*100,e.dispatchEvent("mastervolume",e.#d)},()=>c-64,()=>c-64,()=>{},()=>{},()=>{}][d+f]()}),a[0]<4){let c=0;s.forEach(f=>{c=c<<4,c+=f}),c-=1024}}}}).add([66,18,0,1],(a,i)=>{}).add([66,18,0,2],(a,i)=>{}).add([66,18,1],(a,i)=>{let d=e.chRedir(a[0],i,!0),s=d*y.cc,r=a[1],c=`NS5R CH${d+1} `;a.subarray(2).forEach((f,o)=>{let b=r+o;b<3?([()=>{e.#e[s+g[0]]=f||121},()=>{e.#e[s+g[32]]=f},()=>{e.#s[d]=f}][b](),e.dispatchEvent("voice",{part:d})):b<8||(b<14?[()=>{let m=e.chRedir(f,i,!0);e.#h[d]=m,d!=m&&(e.buildRchTree(),console.info(`${c}receives from CH${m+1}`))},()=>{e.#g[d]=+!f},()=>{e.setChType(d,f,w.ns5r),console.debug(`${c}type: ${X[f]}`)},()=>{e.#r[y.rpn*d+3]=f},()=>{},()=>{}][b-8]():b<16||(b<33?[()=>{e.#e[s+g[7]]=f},()=>{e.#e[s+g[11]]=f},()=>{},()=>{},()=>{e.#e[s+g[10]]=f||128},()=>{},()=>{},()=>{e.#e[s+g[93]]=f},()=>{e.#e[s+g[91]]=f},()=>{e.#e[s+g[76]]=f},()=>{e.#e[s+g[77]]=f},()=>{e.#e[s+g[78]]=f},()=>{e.#e[s+g[74]]=f},()=>{e.#e[s+g[71]]=f},()=>{e.#e[s+g[73]]=f},()=>{e.#e[s+g[75]]=f},()=>{e.#e[s+g[72]]=f}][b-16]():b<112||b<114&&[()=>{e.#e[s+g[5]]=f},()=>{e.#e[s+g[65]]=f}][b-112]()))})}).add([66,18,8,0],(a,i)=>{let d=a[0];if(d<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let s=d-32;e.#v=Date.now()+3200,e.#f=10,e.#b.fill(0);let r=a.subarray(1),c=4;r.forEach(function(f,o){let b=o+s,m=b>>4,E=b&15;if(b<80){let $=m>3,x=0,B=m0;)e.#b[E*32+m*7+(B-x)]=$&1,$=$>>1,x++}})}}).add([66,18,48],(a,i,d)=>{l(0,a)}).add([66,18,49],(a,i,d)=>{l(1,a)}).add([66,18,50],(a,i,d)=>{l(2,a)}).add([66,18,51],(a,i,d)=>{l(3,a)}).add([66,18,52],(a,i,d)=>{l(4,a)}).add([66,18,53],(a,i,d)=>{l(5,a)}).add([66,18,54],(a,i,d)=>{l(6,a)}).add([66,18,55],(a,i,d)=>{l(7,a)}).add([66,52],(a,i)=>{e.switchMode("ns5r",!0),e.#p=!1;let d="";O(a,(s,r)=>{r<8?(s>31&&(d+=String.fromCharCode(s)),r==7&&(e.aiEfxName=d)):r<10&&(e.setEffectType(r-8,44,s),e.dispatchEvent(`efx${["reverb","chorus"][r-8]}`,e.getEffectType(r-8)))})}).add([66,53],(a,i)=>{e.switchMode("ns5r",!0),e.#p=!1,O(a,function(d,s){switch(!0){case s<2944:{let r=e.chRedir(Math.floor(s/92),i,!0),c=r*y.cc;switch(s%92){case 0:{e.#e[c+g[0]]=d||121,e.dispatchEvent("voice",{part:r});break}case 1:{e.#e[c+g[32]]=d,e.dispatchEvent("voice",{part:r});break}case 2:{e.#s[r]=d,d>0&&e.setChActive(r,1),e.dispatchEvent("voice",{part:r});break}case 3:{let f=e.chRedir(d,i,!0);e.#h[r]=f,r!=f&&(console.info(`NS5R CH${r+1} receives from CH${f+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#r[r*y.rpn+3]=d<40||d>88?d+(d>63?-192:64):d;break}case 9:case 10:{e.#e[c+g[7]]=d;break}case 11:{e.#e[c+g[11]]=d;break}case 14:{e.#e[c+g[10]]=d||128;break}case 19:{e.#e[c+g[93]]=d;break}case 20:{e.#e[c+g[91]]=d;break}case 84:{e.#e[c+g[65]]=d;break}case 85:{e.#e[c+g[5]]=d;break}}break}case s<3096:break;case s<3134:break;case s<8566:break}})}).add([66,54],(a,i)=>{e.switchMode("ns5r",!0);let d="",s=80,r=0,c=0,f="MSB PRG LSB NME";O(a,function(o,b){let m=b%158;switch(!0){case m<10:{o>31&&(d+=String.fromCharCode(o));break}case m==11:{s=o&127;break}case m==12:{c=o&127;break}case m==13:{f+=` +${s} ${r} ${c} ${d.trim().replace("Init Voice","")}`,r++,d="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([66,55],(a,i)=>{e.switchMode("ns5r",!0);let d="",s=88,r=0,c=0,f="MSB PRG LSB NME";O(a,function(o,b){let m=b%126;switch(!0){case m<10:{o>31&&(d+=String.fromCharCode(o));break}case m==11:break;case m==12:break;case m==13:{f+=` +${s} ${r} ${c} ${d.trim().replace("Init Combi","")}`,r++,d="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let i=new Uint8Array(5760);O(a,(d,s,r)=>{if(s<720)for(let c=0;c<8;c++)i[s*8+c]=d>>7-c&1}),e.dispatchEvent("screen",{type:"ns5r",data:i})}).add([76],(a,i,d)=>{e.#K.run([66,...a],i,d)}),this.#Y.add([16,0,8,0],(a,i,d)=>{let s=(a[2]<<4)+a[3],r="K11 ";([()=>{e.switchMode("k11",!0),e.#p=!1,e.#C=s?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,s),console.debug(`${r}reverb type: ${s}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${r}reverb time: ${s}`)},()=>{console.debug(`${r}reverb time: ${s}`)},()=>{console.debug(`${r}reverb predelay: ${s}`)},()=>{console.debug(`${r}reverb predelay: ${s}`)},()=>{console.debug(`${r}depth high: ${s}`)},()=>{console.debug(`${r}depth high: ${s}`)},()=>{console.debug(`${r}depth low: ${s}`)},()=>{console.debug(`${r}depth low: ${s}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,i,d)=>{let s=e.chRedir(a[1],i,!0),r=y.cc*s,c=y.rpn*s,f=(a[3]<<4)+a[4],o=`K11 CH${s+1} `;([()=>{f<128?(e.setChType(s,e.CH_MELODIC,w.k11),e.#e[r+g[0]]=0,e.#s[s]=f):(e.setChType(s,e.CH_DRUMS,w.k11),e.#s[s]=f-128),e.dispatchEvent("voice",{part:s})},()=>{let b=e.chRedir(f,i,!0);e.#h[s]=b,s!=b&&(e.buildRchTree(),console.info(`${o}receives from CH${b+1}`))},()=>{e.#e[r+g[7]]=f},()=>{uupThis.setChActive(s,f)},()=>{e.#e[r+g[10]]=f},()=>{e.#r[c+3]=f+40},()=>{e.#r[c+1]=f>>1,e.#r[c+2]=f&1},()=>{e.#e[r+g[91]]=f?127:0},()=>{},()=>{e.#e[r+g[74]]=f},()=>{e.#e[r+g[73]]=f},()=>{e.#e[r+g[72]]=f}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,i,d)=>{let s=(a[2]<<4)+a[3],r="GMLX ";([()=>{console.debug(`${r}reverb type: ${s}`)},()=>{console.debug(`${r}reverb time: ${s}`)},()=>{console.debug(`${r}reverb predelay: ${s}`)},()=>{console.debug(`${r}depth high: ${s}`)},()=>{console.debug(`${r}depth low: ${s}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,i,d)=>{let s=(a[2]<<4)+a[3],r=e.chRedir(a[1],i,!0),c=r*y.cc;[()=>{s<128?(e.setChType(r,e.CH_MELODIC,w.k11),e.#e[c+g[0]]=0,e.#e[c+g[32]]=0,e.#s[r]=s):s<160?(e.setChType(r,e.CH_MELODIC,w.k11),e.#e[c+g[0]]=0,e.#e[c+g[32]]=7,e.#s[r]=s-100):(e.setChType(r,e.CH_DRUMS,w.k11),e.#e[c+g[0]]=122,e.#e[c+g[32]]=0,e.#s[r]=s-160),e.dispatchEvent("voice",{part:r})},()=>{let f=e.chRedir(s,i,!0);e.#h[r]=f,r!=f&&(e.buildRchTree(),console.info(`GMLX CH${r+1} receives from CH${f+1}`))}][a[0]]()}).add([16,0,9,4],(a,i,d)=>{let s=(a[2]<<4)+a[3],r=e.chRedir(a[1],i,!0),c=r*y.cc,f=r*y.rpn,o=`GMLX CH${r+1} `;[()=>{e.setChActive(r,s)},()=>{e.#e[c+g[7]]=s},()=>{e.#e[c+g[10]]=s},()=>{e.#e[c+g[91]]=s?127:0},()=>{e.#r[f+3]=s+40},()=>{e.#r[f+1]=s},()=>{e.#r[f]=s},()=>{}][a[0]]()}),this.#j.add([66,93,64],(a,i,d)=>{let s=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{e.#d=s*129/16383*100,e.dispatchEvent("mastervolume",e.#d);break}case 5:{s-64;break}case 6:{console.debug(`SG global reverb: ${s?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(a[1]){case 48:{console.debug(`SG reverb type: ${J[s]}`);break}}break}default:if(a[0]>>4==1){let r=e.chRedir(a[0]&15,i,!0);if(a[1]==2){let c=e.chRedir(s,i,!0);e.#h[r]=c,r!=c&&(e.buildRchTree(),console.info(`SG CH${r+1} receives from CH${c+1}`))}else a[1]==19&&(e.#e[y.cc*r+g[7]]=s)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),this.#Z.add([9],(a,i,d)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),this.#L.add([127,0],(a,i,d)=>{e.switchMode("motif");let s=new Uint8Array([127,1,...a]);e.#L.run(s,i,d)}).add([127,1,0,0],(a,i,d)=>{e.switchMode("s90es");let s="S90/Motif ES system ",r=a[0];a.subarray(1).forEach((c,f)=>{([()=>{e.#d=c*12900/16383,e.dispatchEvent("mastervolume",e.#d)}][r+f]||(()=>{console.info(`Unrecognized ${s}ID: ${r+f}`)}))()})}).add([127,1,0,0,14],(a,i,d)=>{e.switchMode("s90es");let s="S90/Motif ES bulk header ",r=[];r[95]=(c,f,o)=>{console.debug(`${s}multi edit buffer: ${c[1]}`)},(r[a[0]]||(()=>{console.info(`Unrecognized ${s}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,i,d)=>{e.switchMode("s90es");let s="S90/Motif ES bulk footer ",r=[];r[95]=(c,f,o)=>{console.debug(`${s}multi edit buffer: ${c[1]}`)},(r[a[0]]||(()=>{console.info(`Unrecognized ${s}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,i,d)=>{e.switchMode("s90es");let s=e.chRedir(a[0],i,!0),r=y.cc*s,c=a[1],f=`S90/Motif ES bulk CH${s<16?s+1:"U"+(s-95)} `;console.debug(f,a),!(a[0]>15)&&a.subarray(2).forEach((o,b)=>{([()=>{e.#e[r+g[0]]=o,e.dispatchEvent("voice",{part:s})},()=>{o&&e.setChActive(s,1),e.#e[r+g[32]]=o,e.setChType(s,[32,40].indexOf(o)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:s})},()=>{o&&e.setChActive(s,1),e.#s[s]=o,e.dispatchEvent("voice",{part:s})},()=>{let m=e.chRedir(o,i,!0);e.#h[s]=m,s!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))},()=>{e.#g[s]=o?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{e.#e[r+g[7]]=o},()=>{e.#e[r+g[10]]=o},!1,!1,!1,()=>{e.#e[r+g[91]]=o},()=>{e.#e[r+g[93]]=o},()=>{e.#e[r+g[94]]=o},()=>{e.#e[r+g[128]]=o},()=>{},()=>{e.#e[r+g[74]]=o},()=>{e.#e[r+g[71]]=o},!1,()=>{e.#e[r+g[65]]=o},()=>{e.#e[r+g[5]]=o},()=>{}][c+b]||(()=>{}))()})}).add([127,1,54,16],(a,i,d)=>{e.switchMode("s90es");let s=a[0];a.subarray(1).forEach((r,c)=>{let o=`S90/Motif ES EQ${(c>>2)+1} `;([()=>{let b=r-64},()=>{let b=U[r]},()=>{let b=r/10},()=>{let b=r}][s+c&3]||(()=>{}))()})}),this.#I.add([0,72,18,0,0,0,0],(a,i,d)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,i,d)=>{let s=a[0]>>5,r=a[0]&31;switch(s){case 0:{console.debug(`Unknown SD-90 global effects message: +%o`,a);break}case 1:{let c=e.chRedir(r,i,!0),f=a[1],o=c*y.cc;a.subarray(2).forEach((b,m)=>{let E=f+m;E<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[o+g[0]]=b,b){case 104:case 105:case 106:case 107:case 120:{e.#i[c]||e.setChType(c,e.CH_DRUMS);break}default:e.#i[c]&&e.setChType(c,e.CH_MELODIC)}e.dispatchEvent("voice",{part:c})},()=>{e.#e[o+g[32]]=b,e.dispatchEvent("voice",{part:c})},()=>{e.#s[c]=b,e.dispatchEvent("voice",{part:c})},()=>{e.#e[o+g[7]]=b},()=>{e.#e[o+g[10]]=b},()=>{},()=>{},()=>{b<2&&(e.#g[c]=b)},()=>{b<2&&(e.#e[o+g[68]]=b?127:0)},()=>{},()=>{b<2&&(e.#e[o+g[65]]=b?127:0)},()=>{e.#e[o+g[5]]=b&15<<4|e.#e[o+g[5]]&15},()=>{e.#e[o+g[5]]=b&15|(e.#e[o+g[5]]&240)>>4},()=>{e.#e[o+g[74]]=b},()=>{e.#e[o+g[71]]=b},()=>{e.#e[o+g[73]]=b},()=>{e.#e[o+g[72]]=b},0,0,0,0,0,0,0,()=>{e.#e[o+g[128]]=b},()=>{e.#e[o+g[93]]=b},()=>{e.#e[o+g[91]]=b},0,0,()=>{e.#e[o+g[75]]=b},()=>{e.#e[o+g[76]]=b},()=>{e.#e[o+g[77]]=b},()=>{e.#e[o+g[78]]=b}][E]||(()=>{}))():E<63||(E<64?e.#i[c]?e.#e[o+g[0]]=104|b:e.#e[o+g[0]]=96|b:console.debug(`Unknown SD-90 global CH${c+1} param setup message: +%o`,a))});break}case 2:{let c=e.chRedir(r,i,!0),f=a[1];console.debug(`Unknown SD-90 global CH${c+1} MIDI setup message: %o`,a.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,a)}})}};var ee=Ae(Se(),1);var xe=class{#a=!1;constructor(e,t,l,c){this.#a=e,this.start=t,this.end=l,this.data=c}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#a}},Z=class extends xe{constructor(e,t,l){super(!0,e,t,l)}},Te=class extends xe{constructor(e,t){super(!1,e,e,t)}},J=class extends Array{#a=-1;constructor(){super(...arguments)}resetIndex(e){this.#a=-1}fresh(){this.sort(function(e,t){return e.start==t.start?0:(+(e.start>t.start)<<1)-1}),this.forEach(function(e,t){e.index=t})}step(e,t=!1){let l=[];if(t)for(let c=0;ce);c++){if(this[c].enda.#a&&(l.push(r),a.#a=r.index)})}return l}getRange(e,t){e>t&&([e,t]=[t,e]);let l=[],c=-1,a=Math.ceil(Math.sqrt(this.length)),r=!0;for(let s=0;s=e&&(c=s):c=c<0?s:c;for(;r;)this[c]?.end=e&&l.push(this[c]):r=!1,c++;return l}};var ze=0xffffffffffff,Ce=function(e){let t=new J,l=this,c=e.timeDivision,a=120,r=new J,s=0,n=0;r.push(new Z(0,ze,[120,0])),e.track.forEach(function(o){s=0,o.event.forEach(function(h){s+=h.deltaTime,h.type==255&&h?.metaType==81&&(a=6e7/h.data,r[r.length-1]&&r.push(new Z(s,0xffffffffffff,[a,0])))})}),r.fresh(),r.forEach(function(o,h,p){h>0&&(p[h-1].end=o.start)});let i=120;r.forEach(function(o,h,p){h>0&&(o.end==o.start?p.splice(p.indexOf(o),1):i==o.data[0]&&(p[h-1].end=o.end,p.splice(p.indexOf(o),1)),i=o.data[0])});let d=0,f=120;return r.forEach(function(o){let h=o.start,p=h/f/c*60+d;f=o.data[0],d=p-h/f/c*60,o.data[1]=d}),console.debug("All tempo changes: ",r),a=120,s=0,n=0,e.track.forEach(function(o,h){s=0,n=0;let p=h+1;o.event.forEach(function(g,v){s+=g.deltaTime;let m=r.step(s,!0)[0];m&&(a=m.data[0],n=m.data[1]);let $={type:g.type,data:g.data,track:p,part:0};g.type>14?$.meta=g.metaType:$.part=g.channel,t.push(new Te(s/a/c*60+n,$))})}),t.fresh(),self.midiEvents=t,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),t};ee.default.customInterpreter=me;var w=function(e,t,l){e.addEventListener(l,c=>{t.dispatchEvent(l,c.data)})},Me=class extends N{device;#a;#g;#m=[];#h="";#o=[];#c=new Uint8ClampedArray(128);#d=new Uint8ClampedArray(128);#r=.5;#e=120;#t=4;#i=4;#n=0;#l=0;smoothingAtk=0;smoothingDcy=0;reset(){let e=this;e.dispatchEvent("reset"),e.#a?.resetIndex(),e.device.init(),e.#h="",e.#r=.5,e.#e=120,e.#t=4,e.#i=4,e.#n=0,e.#l=0,e.dispatchEvent("tempo",e.#e),e.dispatchEvent("title",e.#h)}async loadFile(e){this.#a=Ce(ee.default.parse(new Uint8Array(await e.arrayBuffer())))}async loadMap(e){}async loadEfx(e){let t=this,l=0,c=0,a,r,s;e.split(` -`).forEach((n,i)=>{if(i){let d=0,f;n.split(" ").forEach((o,h)=>{switch(h){case a:{d|=parseInt(o,16)<<8;break}case r:{d|=parseInt(o,16);break}case s:{f=o;break}}}),t.#m[d]?console.debug(`EFX ID 0x${d.toString(16).padStart(4,"0")} (${f}) seems to be in conflict.`):(t.#m[d]=f,l++),c++}else n.split(" ").forEach((d,f)=>{switch(d){case"MSB":{a=f;break}case"LSB":{r=f;break}case"Name":{s=f;break}default:console.warn(`Unknown EFX field: ${d}`)}})}),console.debug(`EFX: ${c} total, ${l} loaded.`),t.dispatchEvent("efxreverb",t.device.getEffectType(0)),t.dispatchEvent("efxchorus",t.device.getEffectType(1)),t.dispatchEvent("efxdelay",t.device.getEffectType(2)),t.dispatchEvent("efxinsert0",t.device.getEffectType(3)),t.dispatchEvent("efxinsert1",t.device.getEffectType(4)),t.dispatchEvent("efxinsert2",t.device.getEffectType(5)),t.dispatchEvent("efxinsert3",t.device.getEffectType(6))}switchMode(e,t=!1){this.device.switchMode(e,t)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}getMapped(e){}getEfx([e,t]){let l=e<<8|t;return this.#m[l]||`0x${l.toString(16).padStart(4,"0")}`}get noteProgress(){return this.#l/this.#r}get noteOverall(){return this.noteProgress-this.#n}get noteBar(){return Math.floor(this.noteOverall/this.#t)}get noteBeat(){let e=this.noteOverall%this.#t;return e<0&&(e+=this.#t),e}getTimeSig(){return[this.#t,this.#i]}getTempo(){return this.#e}sendCmd(e){this.device.runJson(e)}render(e){e>this.#l&&(this.#l=e);let t=this.#a?.step(e)||[],l=0,c=new Set,a=this,r=[];this.device.getStrength().forEach((v,m)=>{this.#d[m]=v}),a.device.newStrength(),t.forEach(function(v){let m=v.data;m.type==9&&(m.data[1]>0?c.add(m.part*128+m.data[0]):c.has(m.part*128+m.data[0])&&l++),v.data.type==8&&c.has(m.part*128+m.data[0])&&l++;let $=a.device.runJson(m);switch($?.reply){case"meta":{r.push($);break}}$?.reply&&delete $.reply}),r?.length>0&&this.dispatchEvent("meta",r);let s=this.device.getActive(),n=[],i=a.device.getPitch(),d=a.device.getCcAll(),f=a.device.getProgram(),o=a.device.getChType(),h=this.device.getStrength();h.forEach(function(v,m,$){$[m]=Math.max(a.#d[m],v);let D=$[m]-a.#c[m],re=u.length*m;if(D>=0){let X=4*.25**(d[re+u[73]]/64);a.#c[m]+=Math.ceil(D-D*a.smoothingAtk**X)}else{let X=4*.25**(d[re+u[72]]/64);a.#c[m]+=Math.floor(D-D*a.smoothingDcy**X)}});let p=0;return s.forEach(function(v,m){v&&(n[m]=a.device.getVel(m),p+=n[m].size)}),{extraPoly:l,curPoly:p,chInUse:s,chKeyPr:n,chPitch:i,chProgr:f,chContr:d,chType:o,eventCount:t.length,title:this.#h,bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:this.#c.slice(),velo:h,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce(),efxSink:this.device.getEffectSink()}}constructor(e,t=.5,l=.5){super();let c=this;c.smoothingAtk=t,c.smoothingDcy=l,c.device=e,c.addEventListener("meta",function(a){a?.data?.forEach(function(r){(c.#o[r.meta]||console.debug).call(c,r.meta,r.data)})}),w(c.device,c,"mode"),w(c.device,c,"mastervolume"),w(c.device,c,"channelactive"),w(c.device,c,"channelmin"),w(c.device,c,"channelmax"),w(c.device,c,"channelreset"),w(c.device,c,"screen"),w(c.device,c,"metacommit"),w(c.device,c,"efxreverb"),w(c.device,c,"efxchorus"),w(c.device,c,"efxdelay"),w(c.device,c,"efxinsert0"),w(c.device,c,"efxinsert1"),w(c.device,c,"efxinsert2"),w(c.device,c,"efxinsert3"),c.#o[3]=function(a,r){c.#h?.length<1&&(c.#h=r,c.dispatchEvent("title",c.#h))},c.#o[81]=function(a,r){let s=c.noteProgress,n=c.#r||.5;c.#e=6e7/r,c.#r=r/1e6,c.#n+=s*(n/c.#r)-s,c.dispatchEvent("tempo",c.#e)},c.#o[88]=function(a,r){let s=c.noteProgress,n=c.noteOverall,i=c.noteBar,d=c.noteBeat,f=c.#t,o=c.#i;c.#t=r[0],c.#i=1<=f&&(f{c.classList.add(f)});let{t:a,l:r,w:s,h:n,i,a:d}=l;return a?.constructor&&(c.style.top=`${a}px`),r?.constructor&&(c.style.left=`${r}px`),s?.constructor&&(c.style.width=`${s}px`),n?.constructor&&(c.style.height=`${n}px`),i?.constructor&&c.appendChild(document.createTextNode(i)),d?.constructor&&(c.style.textAlign=d),c},A=function(e,t){t?.forEach(l=>{e.appendChild(l)})},te=function(e,t){t.forEach(l=>{e.classList.contains(l)&&e.classList.remove(l)})},ae=function(e,t){t.forEach(l=>{e.classList.contains(l)||e.classList.add(l)})},Bt=class extends Me{#a=20;#g=!1;#m="";#h;#o=0;#c;#d;#r;#e;#t={};#i={};#n={};#l;#b(){let e=self.innerWidth/self.innerHeight,t=1,l=self.innerWidth,c=self.innerHeight;e>G?(t=Math.round(self.innerHeight/1080*1e4)/1e4,l=Math.ceil(self.innerHeight*G)):e{t.#t.mode.innerText=`${qe[a.data]}`,t.setMode(a.data)}),t.addEventListener("mastervolume",a=>{let r=Math.round(a.data*100)/100;t.#t.volume.innerText=`${Math.floor(r)}.${`${Math.floor(r%1*100)}`.padStart(2,"0")}`}),t.addEventListener("tempo",a=>{let r=Math.round(a.data*100);t.#t.tempo.innerText=`${Math.floor(r/100)}.${`${Math.floor(r%100)}`.padStart(2,"0")}`}),t.addEventListener("tsig",a=>{[t.#t.sigN.innerText,t.#t.sigD.innerText]=a.data}),t.addEventListener("title",a=>{t.#t.title.innerText=a.data||"No Title"}),t.addEventListener("efxreverb",a=>{t.#t.reverb.innerText=t.getEfx(a.data)}),t.addEventListener("efxchorus",a=>{t.#t.chorus.innerText=t.getEfx(a.data)}),t.addEventListener("efxdelay",a=>{t.#t.delay.innerText=t.getEfx(a.data)}),t.addEventListener("efxinsert0",a=>{t.#t.insert.innerText=t.getEfx(a.data)}),t.addEventListener("metacommit",a=>{let r=a.data;if(t.#g&&r.type==t.#m&&t.#h)t.#h.childNodes[0].data+=r.data;else if(r.data?.length&&We.indexOf(r.type)==-1){let s=y("div",["meta-line"]),n=y("span",["field","field-key","meta-type"],{i:Qe[r.type]||r.type});for(r.mask&&(n.style.display="none"),t.#h=y("span",["field","meta-data"],{i:r.data}),t.#l.appendChild(s),A(s,[n,t.#h]);t.#l.children.length>t.#a;)t.#l.children[0].remove()}t.#g=r.amend||!1,t.#m=r.type||"",t.#l.scrollTop=t.#l.scrollHeight-140}),t.dispatchEvent("mode","?"),t.dispatchEvent("mastervolume",100),t.dispatchEvent("tempo",120),t.dispatchEvent("tsig",[4,4]),t.dispatchEvent("title",""),t.dispatchEvent("efxreverb",t.device.getEffectType(0)),t.dispatchEvent("efxchorus",t.device.getEffectType(1)),t.dispatchEvent("efxdelay",t.device.getEffectType(2)),t.dispatchEvent("efxinsert0",t.device.getEffectType(3))}detach(e){let t=this;self.removeEventListener("resize",t.#p),t.#e.remove(),t.#e=void 0,t.#r.remove(),t.#r=void 0,t.#d=void 0,clearInterval(t.#R)}constructor(e,t){super(new ke,.1,.75);let l=this;l.#p=l.#b.bind(this),l.#v=l.#M.bind(this),e&&l.attach(e),t&&l.setClockSource(t),l.addEventListener("reset",()=>{l.#o=0,l.#g=!1,l.#m="",l.#h=null;let c=l.#l.children;for(let a=c.length-1;a>=0;a--)c[a].remove()})}};export{Bt as Cambiare}; +%o`,a)}})}};var ce=Qe(Pe(),1);var Ae=class{#t=!1;constructor(e,t,n,l){this.#t=e,this.start=t,this.end=n,this.data=l}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#t}},se=class extends Ae{constructor(e,t,n){super(!0,e,t,n)}},Le=class extends Ae{constructor(e,t){super(!1,e,e,t)}},ne=class extends Array{#t=-1;constructor(){super(...arguments)}resetIndex(e){this.#t=-1}fresh(){this.sort(function(e,t){return e.start==t.start?0:(+(e.start>t.start)<<1)-1}),this.forEach(function(e,t){e.index=t})}step(e,t=!1){let n=[];if(t)for(let l=0;le);l++){if(this[l].endu.#t&&(n.push(p),u.#t=p.index)})}return n}getRange(e,t){e>t&&([e,t]=[t,e]);let n=[],l=-1,u=Math.ceil(Math.sqrt(this.length)),p=!0;for(let h=0;h=e&&(l=h):l=l<0?h:l;for(;p;)this[l]?.end=e&&n.push(this[l]):p=!1,l++;return n}};var st=0xffffffffffff,Ie=function(e){let t=new ne,n=this,l=e.timeDivision,u=120,p=new ne,h=0,a=0;p.push(new se(0,st,[120,0])),e.track.forEach(function(r){h=0,r.event.forEach(function(c){h+=c.deltaTime,c.type==255&&c?.metaType==81&&(u=6e7/c.data,p[p.length-1]&&p.push(new se(h,0xffffffffffff,[u,0])))})}),p.fresh(),p.forEach(function(r,c,f){c>0&&(f[c-1].end=r.start)});let i=120;p.forEach(function(r,c,f){c>0&&(r.end==r.start?f.splice(f.indexOf(r),1):i==r.data[0]&&(f[c-1].end=r.end,f.splice(f.indexOf(r),1)),i=r.data[0])});let d=0,s=120;return p.forEach(function(r){let c=r.start,f=c/s/l*60+d;s=r.data[0],d=f-c/s/l*60,r.data[1]=d}),console.debug("All tempo changes: ",p),u=120,h=0,a=0,e.track.forEach(function(r,c){h=0,a=0;let f=c+1;r.event.forEach(function(o,b){h+=o.deltaTime;let m=p.step(h,!0)[0];m&&(u=m.data[0],a=m.data[1]);let E={type:o.type,data:o.data,track:f,part:0};o.type>14?E.meta=o.metaType:E.part=o.channel,t.push(new Le(h/u/l*60+a,E))})}),t.fresh(),self.midiEvents=t,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),t};ce.default.customInterpreter=xe;var S=function(e,t,n){e.addEventListener(n,l=>{t.dispatchEvent(n,l.data)})},Ue=class extends V{device;#t;#f={};#v=[];#l="";#b=[];#E=new Uint8ClampedArray(128);#h=new Uint8ClampedArray(128);#i=.5;#e=120;#o=4;#s=4;#c=0;#g=0;smoothingAtk=0;smoothingDcy=0;reset(){let e=this;e.dispatchEvent("reset"),e.#t?.resetIndex(),e.device.init(),e.#l="",e.#i=.5,e.#e=120,e.#o=4,e.#s=4,e.#c=0,e.#g=0,e.dispatchEvent("tempo",e.#e),e.dispatchEvent("title",e.#l)}async loadFile(e){this.#t=Ie(ce.default.parse(new Uint8Array(await e.arrayBuffer())))}async loadMap(e,t){let n=this,l=0,u=0,p=0,h,a;e.split(` +`).forEach((i,d)=>{if(!i)return;let s=i.split(" ");if(d){if(!p)return;let r="",c="";s.forEach((f,o)=>{switch(o){case h:{r=f;break}case a:{c=f;break}}}),!n.#f[r]||t?(n.#f[r]=c,l++):self.debugMode&&console.debug(`Voice "${c}" (${r}) seems to be in conflict with (${n.#f[r]}).`),u++}else s.forEach((r,c)=>{switch(r){case"ID":{h=c,p++;break}case"Name":{a=c,p++;break}default:console.debug(`Unknown map field: ${r}`)}})}),console.debug(`Map: ${u} total, ${l} loaded.`),n?.device.forceVoiceRefresh()}async loadEfx(e,t){let n=this,l=0,u=0,p,h,a;e.split(` +`).forEach((i,d)=>{if(i)if(d){let s=0,r;i.split(" ").forEach((c,f)=>{switch(f){case p:{s|=parseInt(c,16)<<8;break}case h:{s|=parseInt(c,16);break}case a:{r=c;break}}}),!n.#v[s]||t?(n.#v[s]=r,l++):self.debugMode&&console.debug(`EFX ID 0x${s.toString(16).padStart(4,"0")} (${r}) seems to be in conflict.`),u++}else i.split(" ").forEach((s,r)=>{switch(s){case"MSB":{p=r;break}case"LSB":{h=r;break}case"Name":{a=r;break}default:console.debug(`Unknown EFX field: ${s}`)}})}),console.debug(`EFX: ${u} total, ${l} loaded.`),n.dispatchEvent("efxreverb",n.device.getEffectType(0)),n.dispatchEvent("efxchorus",n.device.getEffectType(1)),n.dispatchEvent("efxdelay",n.device.getEffectType(2)),n.dispatchEvent("efxinsert0",n.device.getEffectType(3)),n.dispatchEvent("efxinsert1",n.device.getEffectType(4)),n.dispatchEvent("efxinsert2",n.device.getEffectType(5)),n.dispatchEvent("efxinsert3",n.device.getEffectType(6))}switchMode(e,t=!1){this.device.switchMode(e,t)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}getMapped(e){return this.#f[e]||e}getEfx([e,t]){let n=e<<8|t;return this.#v[n]||`0x${n.toString(16).padStart(4,"0")}`}get noteProgress(){return this.#g/this.#i}get noteOverall(){return this.noteProgress-this.#c}get noteBar(){return Math.floor(this.noteOverall/this.#o)}get noteBeat(){let e=this.noteOverall%this.#o;return e<0&&(e+=this.#o),e}getTimeSig(){return[this.#o,this.#s]}getTempo(){return this.#e}sendCmd(e){this.device.runJson(e)}render(e){e>this.#g&&(this.#g=e);let t=this.#t?.step(e)||[],n=0,l=new Set,u=this,p=[];this.device.getStrength().forEach((b,m)=>{this.#h[m]=b}),u.device.newStrength(),t.forEach(function(b){let m=b.data;m.type==9&&(m.data[1]>0?l.add(m.part*128+m.data[0]):l.has(m.part*128+m.data[0])&&n++),b.data.type==8&&l.has(m.part*128+m.data[0])&&n++;let E=u.device.runJson(m);switch(E?.reply){case"meta":{p.push(E);break}}E?.reply&&delete E.reply}),p?.length>0&&this.dispatchEvent("meta",p);let h=this.device.getActive(),a=[],i=u.device.getPitch(),d=u.device.getCcAll(),s=u.device.getProgram(),r=u.device.getChType(),c=this.device.getStrength();c.forEach(function(b,m,E){E[m]=Math.max(u.#h[m],b);let $=E[m]-u.#E[m],x=g.length*m;if($>=0){let B=4*.25**(d[x+g[73]]/64);u.#E[m]+=Math.ceil($-$*u.smoothingAtk**B)}else{let B=4*.25**(d[x+g[72]]/64);u.#E[m]+=Math.floor($-$*u.smoothingDcy**B)}});let f=0;return h.forEach(function(b,m){b&&(a[m]=u.device.getVel(m),f+=a[m].size)}),{extraPoly:n,curPoly:f,chInUse:h,chKeyPr:a,chPitch:i,chProgr:s,chContr:d,chType:r,eventCount:t.length,title:this.#l,bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:this.#E.slice(),velo:c,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce(),efxSink:this.device.getEffectSink()}}constructor(e,t=.5,n=.5){super();let l=this;l.smoothingAtk=t,l.smoothingDcy=n,l.device=e,l.addEventListener("meta",function(u){u?.data?.forEach(function(p){(l.#b[p.meta]||console.debug).call(l,p.meta,p.data)})}),S(l.device,l,"mode"),S(l.device,l,"mastervolume"),S(l.device,l,"channelactive"),S(l.device,l,"channelmin"),S(l.device,l,"channelmax"),S(l.device,l,"channelreset"),S(l.device,l,"channeltoggle"),S(l.device,l,"screen"),S(l.device,l,"metacommit"),S(l.device,l,"voice"),S(l.device,l,"pitch"),S(l.device,l,"note"),S(l.device,l,"reset"),S(l.device,l,"efxreverb"),S(l.device,l,"efxchorus"),S(l.device,l,"efxdelay"),S(l.device,l,"efxinsert0"),S(l.device,l,"efxinsert1"),S(l.device,l,"efxinsert2"),S(l.device,l,"efxinsert3"),S(l.device,l,"partefxtoggle"),l.#b[3]=function(u,p){l.#l?.length<1&&(l.#l=p,l.dispatchEvent("title",l.#l))},l.#b[81]=function(u,p){let h=l.noteProgress,a=l.#i||.5;l.#e=6e7/p,l.#i=p/1e6,l.#c+=h*(a/l.#i)-h,l.dispatchEvent("tempo",l.#e)},l.#b[88]=function(u,p){let h=l.noteProgress,a=l.noteOverall,i=l.noteBar,d=l.noteBeat,s=l.#o,r=l.#s;l.#o=p[0],l.#s=1<=s&&(s{oe&&(le[K]=!le[K],K++,K>34&&(K=0))},1e3/50);Uint8Array.prototype.render=function(e){let t=0,n=0,l=this.width||5,u=this.height||8;for(let p=0;p=l&&(t=0,n++)};var Ne=class{#t=[];async load(e,t=!1,n="(internal)"){let l=this,u=0,p=0;console.debug(`Font "${n||"(internal)"}": loading started.`),e.split(` +`).forEach(function(h,a){if(a>0&&h?.length>0){let i=h.split(" "),d=parseInt(i[0],16);if(p++,l.#t[d]&&!t)return;let s=new Uint8Array(40);Array.from(i[1]).forEach(async function(r,c){let f=c%2?4:0,o=Math.floor(c/2),b=parseInt(r,16),m=3;for(;b>0||m>=0;){let E=(f+m)*5+o;s[E]=b&1,b=b>>1,m--}}),l.#t[d]=s,u++}}),console.debug(`Font "${n||"(internal)"}": ${p} total, ${u} loaded.`)}async loadFile(e,t=!1){let n=this;console.debug(`Requested font file from "${e}".`),await n.load(await(await fetch(e)).text(),t,e),oe=!1}constructor(...e){oe=!0,(async()=>{for(let t=0;t{l.classList.add(s)});let{t:u,l:p,w:h,h:a,i,a:d}=n;return u?.constructor&&(l.style.top=u?.length?u:`${u}px`),p?.constructor&&(l.style.left=p?.length?p:`${p}px`),h?.constructor&&(l.style.width=h?.length?h:`${h}px`),a?.constructor&&(l.style.height=a?.length?a:`${a}px`),i?.constructor&&l.appendChild(document.createTextNode(i)),d?.constructor&&(l.style.textAlign=d),l},M=function(e,t){let n=document.createElementNS("http://www.w3.org/2000/svg",e);for(let l in t)n.setAttribute(l,t[l]);return n},T=function(e,t){t?.forEach(n=>{e.appendChild(n)})},L=function(e,t){t.forEach(n=>{e.classList.contains(n)&&e.classList.remove(n)})},N=function(e,t){t.forEach(n=>{e.classList.contains(n)||e.classList.add(n)})},Ge=new Array(128).fill(0);Ge.forEach((e,t,n)=>{n[t]=Math.floor(24*t/12.7)/10});var de=new Array(128).fill(0);de.forEach((e,t,n)=>{n[t]=Math.abs(Math.round(48*(t-64)/12.7)/10)});var Xe=new Array(11).fill(null);Xe.forEach((e,t,n)=>{n[t]=`${Math.round(t*12/.0128)/100}%`});var ht=new Array(128).fill(null);ht.forEach((e,t,n)=>{n[t]=`${Math.round(t/1.27)/100}`});var P=function(e,t){let n=Ge[t];e.setAttribute("height",n),e.setAttribute("y",24-n)},He=function(e,t){e.innerText=t,e.rNew=!0;let n=e.measureText(t);e.rWidth=n.width},sa=class extends Ue{#t=128;#f=!1;#v="";#l;#b=0;#E=0;#h=0;#i=0;#e=1;#o=0;#s=new Uint8Array(1280);#c=new Uint8Array(1280);#g=new Uint8Array(1280);#u=new Uint8Array(512);#y=new Uint8Array(512);#D=new Uint8Array(512);#O;#B;#r;#k;#x="fcdaff";#a={};#w={};#n=[];#m={};#S={};#T=[];#H=[];#P="block";glyphs=new Ne;#C(e,t,n,l=0,u=0){let p=this,{width:h,height:a}=e.canvas,i,d,s,r,c=p.#e,f=l>3,o=ct.indexOf(t%12)>-1;switch(p.#P){case"block":case"comb":{i=Math.round(t*h/128),d=Math.round((t+1)*h/128),s=d-i,r=c==1?2:1;break}case"piano":{i=Math.round((Math.floor(t/12)*7+Be[t%12])*h/75*1.0044642857142856),d=Math.round((Math.floor(t/12)*7+Be[t%12]+1)*h/75*1.0044642857142856)-1,s=d-i,r=c==1?3:1;break}default:}switch(e.fillStyle=`#${o?p.#x:"ffffff"}${(n<<1|n>>6).toString(16).padStart(2,"0")}`,e.strokeStyle=e.fillStyle,p.#P){case"block":{let b=e.canvas.height-1;e.fillRect(i,1,s,b),f&&e.clearRect(i+r,r+1,s-(r<<1),b-(r<<1));break}case"comb":{let b=(o?Math.round((e.canvas.height<<1)/3):e.canvas.height)-1;e.fillRect(i,1,s,b),f&&e.clearRect(i+r,r+1,s-(r<<1),b-(r<<1));break}case"piano":{let b=(o?0:e.canvas.height>>1)+1,m=(e.canvas.height>>1)-1;e.fillRect(i,b,s,m),f&&e.clearRect(i+r,b+r,s-(r<<1),m-(r<<1));break}default:}}#d(e,t){let n=this;(e?.chInUse||t).forEach((l,u)=>{if(l){let p=n.#n[u>>4][u&15].cxt;p.clearRect(0,0,p.canvas.width,p.canvas.height),e.chKeyPr[u].forEach(({v:h,s:a},i)=>{n.#C(p,i,h,a,n.device.getPitchShift(u))})}})}#G(e){let t=this;Date.now()-t.#b>4e3&&(t.#E=0,t.#h=142-t.#m.view.clientHeight,(t.#l?.clientWidth||0)>840&&(t.#E=840-t.#l.clientWidth),t.#m.view.style.transform=`translateX(${t.#E}px) translateY(${t.#h}px)`,e&&(t.#b=0))}#V(){let e=self.innerWidth/self.innerHeight,t=1,n=self.innerWidth,l=self.innerHeight;e>=W?(t=Math.round(self.innerHeight/1080*1e4)/1e4,n=Math.ceil(self.innerHeight*W)):e>4,f=r*y.cc,o=e.#n[c][r&15];if(n.chInUse[r]&&c>=e.#o&&co.metre.canvas.width){o.metre.rNew&&(o.metre.rNew=!1,o.metre.rOffset=t);let m=t-(o.metre.rOffset||0),E=32,$=o.metre.rWidth-o.metre.canvas.width+E,x=m*-25%(o.metre.rWidth+E+48)+48;x>0&&(x=0),o.metre.fillText(o.metre.innerText,x,3),Math.abs(x)>$&&o.metre.fillText(o.metre.innerText,x+o.metre.rWidth+E,3)}else o.metre.fillText(o.metre.innerText,0,3);o.metre.globalCompositeOperation="xor",o.metre.fillRect(0,0,n.strength[r]*121/255,25);let b=n.chContr[f+g[10]];o.pan.setAttribute("width",`${de[b]||0}`),b<64?o.pan.setAttribute("x",`${84-de[b]}`):b>127?(o.pan.setAttribute("x","60"),o.pan.setAttribute("width","48")):o.pan.setAttribute("x","84")}}let h=new Set,a=new Set,i=new Array(y.ch),d={};if(e.#n.forEach((r,c)=>{r.forEach((f,o)=>{f.refresh&&(f.refresh=!1,i[c<<7|o]=!0)})}),["line"].indexOf(e.#P)>-1)for(;e.#H.length>0;){let r=e.#H.shift();i[r.part]=!0}for(;e.#T.length>0;){let r=e.#T.shift(),{part:c,note:f,velo:o,state:b}=r,m=c<<7|f;i[c]=!0,b==0?h.has(m)&&(a.add(m),e.#n[c>>4][c&15].refresh=!0):(h.add(m),d[m]=r)}e.#d(n,i),a.forEach(r=>{let{part:c,note:f,velo:o,state:b}=d[r],m=e.#n[c>>7][c&15].cxt;e.#C(m,f,o,b,e.device.getPitchShift(c))});let s=e.#S.cxt;l>n.bitmap.expire?e.#D.fill(0):n.bitmap.bitmap.length>256?n.bitmap.bitmap.forEach((r,c)=>{e.#D[c]=r?255:0}):n.bitmap.bitmap.forEach((r,c)=>{e.#D[c<<1]=r?255:0,e.#D[c<<1|1]=r?255:0}),e.#g.fill(0),l<=n.letter.expire&&e.glyphs.getStr(n.letter.text).forEach((r,c)=>{let f=(c&15)*5,o=c>>4<<3;r.forEach((b,m)=>{let E=f+m%5,$=o+Math.floor(m/5);e.#g[$*80+E]=b?255:0})}),e.#u.forEach((r,c,f)=>{let o=e.#D[c];o>r?f[c]+=Math.min(o-r,Q):o{let o=e.#g[c];o>r?f[c]+=Math.min(o-r,Q):o{let f=c>>5,o=c&31;e.#y[c]!=r?(s.clearRect(252+(o<<2),f<<2,3,3),r&&(s.fillStyle=`#ffffff${r.toString(16).padStart(2,"0")}`,s.fillRect(252+(o<<2),f<<2,3,3))):self.debugMode&&(s.clearRect(252+(o<<2),f<<2,3,3),r&&(s.fillStyle=`#ff0000${r.toString(16).padStart(2,"0")}`,s.fillRect(252+(o<<2),f<<2,3,3)))}),e.#s.forEach((r,c)=>{let f=Math.floor(c/80),o=c%80;o+=Math.floor(o/5),e.#c[c]!=r?(s.clearRect(o<<2,(f|16)<<2,3,3),r&&(s.fillStyle=`#ffffff${r.toString(16).padStart(2,"0")}`,s.fillRect(o<<2,(f|16)<<2,3,3))):self.debugMode&&(s.clearRect(o<<2,(f|16)<<2,3,3),r&&(s.fillStyle=`#ff0000${r.toString(16).padStart(2,"0")}`,s.fillRect(o<<2,(f|16)<<2,3,3)))}),e.#y.forEach((r,c,f)=>{f[c]=e.#u[c]}),e.#c.forEach((r,c,f)=>{f[c]=e.#s[c]})}#N;#_;get style(){return this.#P}set style(e){let t=this;t.#P=e,t.#d(t.render(t.#O?.currentTime||0))}setClockSource(e){this.#O=e}setMode(e){let t=this;L(t.#k,["cambiare-mode-gm","cambiare-mode-xg","cambiare-mode-gs","cambiare-mode-ns5r","cambiare-mode-05rw","cambiare-mode-x5d","cambiare-mode-k11","cambiare-mode-sg","cambiare-mode-g2","cambiare-mode-mt32","cambiare-mode-sd","cambiare-mode-krs","cambiare-mode-s90es","cambiare-mode-motif"]),e!="?"&&N(t.#k,[`cambiare-mode-${e}`]),t.#x={xg:"9efaa0",ns5r:"9efaa0",x5d:"9efaa0","05rw":"9efaa0",k11:"9efaa0",s90es:"9efaa0",motif:"9efaa0",gm:"a1f3ff",g2:"a1f3ff",krs:"a1f3ff",gs:"ffe1a5",mt32:"ffe1a5",sd:"ffe1a5",sg:"ffdddd"}[e]||"fcdaff"}#M(e){let t=this,n=t.#e,l=t.#o;t.#n.forEach((u,p)=>{if(p>=l&&p{d.root.style.top=`${s*(n>2?26:52)}px`})}else L(u.root,["port-active"]),u.root.style.top="",u.root.style.left="",u.forEach((h,a)=>{h.root.style.top=""});e&&u.forEach((h,a)=>{h.cxt.canvas.width=t.#e==1?1193:495,h.cxt.canvas.height=t.#e==4?26:52})})}setPort(e){let t=this;L(t.#k,["cambiare-start0","cambiare-start1","cambiare-start2","cambiare-start3","cambiare-start4","cambiare-start5","cambiare-start6","cambiare-start7"]),N(t.#k,[`cambiare-start${e}`]),t.#o=e,t.#M(!1)}setRange(e){let t=this;L(t.#k,["cambiare-port1","cambiare-port2","cambiare-port4","cambiare-compact"]),N(t.#k,[`cambiare-${e}`]),t.#e=parseInt(e.slice(4))||1,t.#M(!0)}attach(e){let t=this;t.#B=e;let n=v("div",["cambiare-container"]);e.appendChild(n),t.#r=n;let l=v("div",["cambiare-canvas","cambiare-port1","cambiare-start0"]);n.appendChild(l),t.#k=l,self.addEventListener("resize",t.#U),t.#U(),t.#_=setInterval(t.#N,20),t.#a.root=v("div",["sect-info"]),t.#a.events=v("span",["field"],{t:1,l:0,w:35,h:33}),t.#a.curPoly=v("span",["field"],{t:1,l:52,w:35,h:33}),t.#a.maxPoly=v("span",["field"],{t:1,l:98,w:35,h:33}),t.#a.sigN=v("span",["field"],{t:1,l:194,w:23,h:33,a:"right"}),t.#a.sigD=v("span",["field"],{t:1,l:232,w:23,h:33}),t.#a.barCount=v("span",["field"],{t:1,l:304,w:35,h:33,a:"right"}),t.#a.barNote=v("span",["field"],{t:1,l:354,w:23,h:33}),t.#a.tempo=v("span",["field"],{t:1,l:454,w:64,h:33,a:"right"}),t.#a.volume=v("span",["field"],{t:1,l:562,w:63,h:33,a:"right"}),t.#a.mode=v("span",["field"],{t:1,l:708,w:152,h:33}),t.#a.reverb=v("span",["field"],{t:1,l:1e3,w:190,h:33}),t.#a.chorus=v("span",["field"],{t:1,l:1240,w:190,h:33}),t.#a.delay=v("span",["field"],{t:1,l:1475,w:190,h:33}),t.#a.insert=v("span",["field"],{t:1,l:1706,w:190,h:33}),t.#a.title=v("span",["field"],{t:35,l:50,w:810,h:33}),l.appendChild(t.#a.root),T(t.#a.root,[t.#a.events,t.#a.curPoly,v("span",["field","field-label"],{t:1,l:89,w:5,h:33,i:":"}),t.#a.maxPoly,v("span",["field","field-key"],{t:1,l:148,w:41,h:33,i:"TSig"}),t.#a.sigN,v("span",["field","field-label"],{t:0,l:221,w:8,h:33,i:"/"}),t.#a.sigD,v("span",["field","field-key"],{t:1,l:268,w:30,h:33,i:"Bar"}),t.#a.barCount,v("span",["field","field-label"],{t:0,l:343,w:8,h:33,i:"/"}),t.#a.barNote,v("span",["field","field-key"],{t:1,l:390,w:61,h:33,i:"Tempo",a:"right"}),t.#a.tempo,v("span",["field","field-key"],{t:1,l:528,w:29,h:33,i:"Vol"}),t.#a.volume,v("span",["field","field-label"],{t:1,l:626,w:17,h:33,i:"%"}),v("span",["field","field-key"],{t:1,l:652,w:52,h:33,i:"Mode"}),t.#a.mode,v("span",["field","field-key"],{t:1,l:960,w:34,h:33,i:"Rev"}),t.#a.reverb,v("span",["field","field-key"],{t:1,l:1198,w:36,h:33,i:"Cho"}),t.#a.chorus,v("span",["field","field-key"],{t:1,l:1438,w:31,h:33,i:"Var"}),t.#a.delay,v("span",["field","field-key"],{t:1,l:1673,w:27,h:33,i:"Ins"}),t.#a.insert,v("span",["field","field-key"],{t:35,l:0,w:44,h:33,i:"Title"}),t.#a.title]),t.#w.root=v("div",["sect-mark"]),t.#w.left=v("div",["sect-mark-left","boundary"],{t:0,l:0}),t.#w.right=v("div",["sect-mark-right","boundary"],{t:0,l:960}),l.appendChild(t.#w.root),T(t.#w.root,[t.#w.left,t.#w.right]),T(t.#w.left,[v("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),v("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),v("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),v("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),v("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),v("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),T(t.#w.right,[v("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),v("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),v("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),v("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),v("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),v("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),t.#n.root=v("div",["sect-part"]);for(let u=0;u>4;u++){let p=u<<4;t.#n[u]=[],t.#n[u].root=v("div",["boundary",`part-port-${u}`]);for(let h=0;h<16;h++){let a=(p|h)+1;a>=100?a=`${Math.floor(a/10).toString(16)}${a%10}`:a=`${a}`.padStart(2,"0"),t.#n[u][h]={root:v("div",["boundary","part-channel"]),major:v("div",["boundary","part-info-major"]),minor:v("div",["boundary","part-info-minor"],{t:26}),keys:v("div",["boundary","part-keys"]),notes:v("div",["boundary","part-keyboard"]),cxt:v("canvas",["field"]).getContext("2d"),number:v("span",["field","field-label"],{t:1,w:18,h:25,i:a}),voice:v("span",["field"],{l:22,t:1,w:121,h:25}),metre:v("canvas",["field"]).getContext("2d"),type:v("span",["field","field-label"],{t:1,w:18,h:25}),std:v("span",["field"],{l:22,t:1,w:20,h:25,a:"center"}),msb:v("span",["field"],{l:48,t:1,w:27,h:25}),prg:v("span",["field"],{l:81,t:1,w:27,h:25}),lsb:v("span",["field"],{l:114,t:1,w:27,h:25}),cc:M("svg",{viewBox:"0 0 108 24",width:108,style:"left: 146px; top: 1px; position: absolute;"}),vol:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:0}),exp:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:6}),mod:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:12}),rev:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:18}),cho:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:24}),var:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:30}),brt:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:36}),por:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:42}),cea:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:48}),ceb:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:54}),pan:M("rect",{fill:"var(--accent-color)",width:0,height:24,x:84})};let i=t.#n[u][h];Xe.forEach(d=>{i.notes.appendChild(v("span",["field","part-csplit"],{l:d}))}),i.notes.appendChild(v("span",["field","part-csplit","part-cdive"],{l:0,w:"100%",h:1})),i.metre.canvas.width=121,i.metre.canvas.height=25,i.metre.fillStyle="#fff",i.metre.textBaseline="top",i.metre.font="20px 'PT Sans Narrow'",T(i.notes,[i.cxt.canvas]),T(i.keys,[i.notes]),T(i.voice,[i.metre.canvas]),T(i.cc,[i.vol,i.exp,i.mod,i.rev,i.cho,i.var,i.brt,i.por,i.cea,i.ceb,i.pan,M("rect",{x:83,y:0,width:1,height:24,fill:"var(--foreground-color)"})]),T(i.major,[i.number,i.voice,i.cc]),T(i.minor,[i.type,i.std,i.msb,i.prg,i.lsb]),T(i.root,[i.major,i.minor,i.keys]),T(t.#n[u].root,[i.root])}t.#n.root.appendChild(t.#n[u].root)}l.appendChild(t.#n.root),t.#m.root=v("div",["sect-meta"]),t.#m.view=v("div",["boundary"]),l.appendChild(t.#m.root),T(t.#m.root,[t.#m.view]),t.#S.root=v("div",["sect-pix","boundary"],{l:1529,t:950,w:379,h:127}),t.#S.cxt=v("canvas",["field"]).getContext("2d"),t.#S.cxt.canvas.width=379,t.#S.cxt.canvas.height=127,T(t.#S.root,[t.#S.cxt.canvas]),l.appendChild(t.#S.root),t.addEventListener("mode",u=>{t.#a.mode.innerText=`${lt[u.data]}`,t.setMode(u.data)}),t.addEventListener("mastervolume",u=>{let p=Math.round(u.data*100)/100;t.#a.volume.innerText=`${Math.floor(p)}.${`${Math.floor(p%1*100)}`.padStart(2,"0")}`}),t.addEventListener("tempo",u=>{let p=Math.round(u.data*100);t.#a.tempo.innerText=`${Math.floor(p/100)}.${`${Math.floor(p%100)}`.padStart(2,"0")}`}),t.addEventListener("tsig",u=>{[t.#a.sigN.innerText,t.#a.sigD.innerText]=u.data}),t.addEventListener("title",u=>{t.#a.title.innerText=u.data||"No Title"}),t.addEventListener("voice",({data:u})=>{let p=t.getChVoice(u.part),h=t.#n[u.part>>4][u.part&15];He(h.metre,t.getMapped(p.name)),h.type.innerText=nt[t.device.getChType()[u.part]],h.std.innerText=p.standard,h.msb.innerText=`${p.sid[0]}`.padStart(3,"0"),h.prg.innerText=`${p.sid[1]}`.padStart(3,"0"),h.lsb.innerText=`${p.sid[2]}`.padStart(3,"0")}),t.addEventListener("pitch",u=>{let{part:p,pitch:h}=u.data;t.#n[p>>4][p&15].notes.style.transform=`translateX(${h/1.28}%)`}),t.addEventListener("efxreverb",u=>{t.#a.reverb.innerText=t.getEfx(u.data)}),t.addEventListener("efxchorus",u=>{t.#a.chorus.innerText=t.getEfx(u.data)}),t.addEventListener("efxdelay",u=>{t.#a.delay.innerText=t.getEfx(u.data)}),t.addEventListener("efxinsert0",u=>{t.#a.insert.innerText=t.getEfx(u.data)}),t.addEventListener("partefxtoggle",u=>{let{part:p,active:h}=u.data;[L,N][h](t.#n[p>>4][p&15].number,["part-efx"])}),t.addEventListener("channeltoggle",u=>{let{part:p,active:h}=u.data;[L,N][h](t.#n[p>>4][p&15].root,["part-active"])}),t.addEventListener("metacommit",u=>{let p=u.data;if(t.#f&&p.type==t.#v&&t.#l)switch(p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{T(t.#l,[v("span",["meta-slice"],{i:p.data})]);break}default:t.#l.childNodes[0].data+=p.data}else if(p.data?.length&&dt.indexOf(p.type)==-1){let h=v("div",["meta-line"]),a=v("span",["field","field-key","meta-type"],{i:ot[p.type]||p.type});switch(p.mask&&(a.style.display="none"),p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{t.#l=v("span",["field","meta-data"]),T(t.#l,[v("span",["meta-slice"],{i:p.data})]);break}default:t.#l=v("span",["field","meta-data"],{i:p.data})}for(t.#m.view.appendChild(h),T(h,[a,t.#l]);t.#m.view.children.length>t.#t;)t.#m.view.children[0].remove()}t.#f=p.amend||!1,t.#v=p.type||"",t.#G()}),t.#m.view.style.transform="translateX(0px) translateY(140px)",t.dispatchEvent("mode","?"),t.dispatchEvent("mastervolume",100),t.dispatchEvent("tempo",120),t.dispatchEvent("tsig",[4,4]),t.dispatchEvent("title",""),t.dispatchEvent("efxreverb",t.device.getEffectType(0)),t.dispatchEvent("efxchorus",t.device.getEffectType(1)),t.dispatchEvent("efxdelay",t.device.getEffectType(2)),t.dispatchEvent("efxinsert0",t.device.getEffectType(3)),t.#M(!0)}detach(e){let t=this;self.removeEventListener("resize",t.#U),t.#k.remove(),t.#k=void 0,t.#r.remove(),t.#r=void 0,t.#B=void 0,clearInterval(t.#_)}constructor(e,t){super(new Oe,.1,.75);let n=this;n.#U=n.#V.bind(this),n.#N=n.#X.bind(this),e&&n.attach(e),t&&n.setClockSource(t),n.addEventListener("reset",()=>{n.#i=0,n.#f=!1,n.#v="",n.#l=null;try{let l=n.#m.view.children;for(let u=l.length-1;u>=0;u--)l[u].remove();n.#m.view.style.transform="translateX(0px) translateY(140px)";for(let u=0;u>4][u&15];L(p.root,["part-active"]),L(p.number,["part-efx"]),He(p.metre,""),p.type.innerText="",p.std.innerText="",p.msb.innerText="",p.prg.innerText="",p.lsb.innerText="",p.notes.style.transform=""}}catch{}}),n.addEventListener("note",({data:l})=>{n.#T.push(l)}),n.addEventListener("pitch",({data:l})=>{n.#H.push(l)})}};export{sa as Cambiare}; diff --git a/dist/state.mjs b/dist/state.mjs index e25836fc..93e16f8f 100644 --- a/dist/state.mjs +++ b/dist/state.mjs @@ -1,8 +1,8 @@ -var K=function(e,s){let c=Math.min(e.length,s.length),d=e.slice(0,c),t=s.slice(0,c),i=0,r=0;for(;r0){let d=this.pool.length,t=1<=1&&r>=0;){if(r<=0)throw new Error("TTL reached.");if(i==d)i-=t;else{let a=K(s,this.pool[i]);switch(a){case 0:{r=0;break}case 1:{i+t<=d&&(i+=t);break}case-1:{i!=0&&(i-=t);break}default:console.warn(`Unexpected result ${a}.`)}}t=t>>1,r--}let n=!0;if(i>=this.pool.length)n=!1;else{let a=this;this.pool[i].forEach(function(l,f,o){n&&l!=s[f]&&(n=!1)}),!n&&K(s,this.pool[i])>0&&i++}return n||c?i:-1}else return c?0:-1},this.add=function(s,c){return s.data=c,this.pool.splice(this.point(s,!0),0,s),this},this.default=function(s){console.warn(`No match in "${this.name||"(unknown)"}" for "${s}". Default action not defined.`)},this.get=function(s){let c=this.point(s);if(c>-1)return this.pool[c].data;this.default(s)},this.run=function(s,...c){let d=this.point(s);d>-1?s.subarray?this.pool[d].data(s.subarray(this.pool[d].length),...c):this.pool[d].data(s.slice(this.pool[d].length),...c):this.default(s,...c)}};var F=class{#t={};addEventListener(e,s){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(s)}removeEventListener(e,s){if(this.#t[e]){let c=this.#t[e].indexOf(s);c>-1&&this.#t[e].splice(c,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,s){let c=new Event(e),d=this;c.data=s,this.#t[e]?.length>0&&this.#t[e].forEach(function(t){try{t?.call(d,c)}catch(i){console.error(i)}}),this[`on${e}`]&&this[`on${e}`](c)}};var le=["MSB","PRG","LSB"],H=function(e){let s=Math.floor(e/10),c=e%10;return`${s.toString(16)}${c}`},N=class{#t;strictMode=!1;get(e=0,s=0,c=0,d){let t=[e,s,c],i,r=Array.from(arguments);switch(d){case"xg":{switch(e){case 0:{c==126?r[2]=125:c==127&&(r[2]=0);break}case 32:{r[2]+=4;break}case 33:case 35:case 36:{r[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:r[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{c==126&&(r[2]=0);break}case 48:case 64:case 126:case 127:{c==126&&(r[2]=0);break}}break}case"gs":{e==0&&c<5?r[2]=0:e>125&&c<5&&c!=2&&(r[2]=e,r[0]=0);break}case"g2":case"sd":{(e>>1==40||e>95&&e<100)&&(r[2]|=16);break}case"sg":{e==8&&c==0&&(r[2]=5);break}case"s90es":{c<8?r[2]+=17:c<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}case"motif":{c<8?r[2]+=28:c<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}}let n=" ",a="M",l=0,f=0;switch(r[0]){case 0:{r[2]==127?a="MT-a":r[2]==126?a="MT-b":r[2]==7?a="GM-k":r[2]==5?a="SG-a":r[2]==4?a="SP-l":r[2]==0||d=="gs"&&r[2]<5?a="GM-a":(a="y",l=3);break}case 8:{d=="sg"?a="GM-s":a="r:";break}case 48:{a=`yM${(r[2]>>3).toString().padStart(2,"0")}`,l=1;break}case 56:{a="GM-b";break}case 61:case 120:{a="rDrm";break}case 62:{a="kDrm";break}case 63:{if(r[2]<17){let g=r[2];a=g<10?"kP:":"kC:",a+=g%10}else r[2]<34?a=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][r[2]-17]:a="Ds";break}case 64:{a="ySFX";break}case 67:{a="DX:S";break}case 80:case 81:case 82:case 83:{a=`Prg${"UABC"[r[0]-80]}`;break}case 88:case 89:case 90:case 91:{a=`Cmb${"UABC"[r[0]-88]}`;break}case 95:{a=`${["DR","PC"][r[2]]}-d`;break}case 96:{a=r[2]==106?"AP-a":r[2]>>4==1?"SDg":"PF",r[2]>63?f=63:r[2]>>4==1&&(f=16),l=3;break}case 97:{a=r[2]>>4==1?"SDa":"VL:",l=3,r[2]>>4==1?f=16:f=112;break}case 98:{a=r[2]>>4==1?"SDb":"SG-a",l=3,f=16;break}case 99:{a=r[2]>>4==1?"SDc":"DX",r[2]>63?f=63:r[2]>>4==1&&(f=16),l=3;break}case 100:{a="AN",r[2]>63?f=63:r[2]>>4==1&&(f=16),l=3;break}case 104:case 105:case 106:case 107:{a="SDd",f=104;break}case 121:{a=`GM-${r[2]?"":"a"}`,l=3;break}case 122:{a="lDrm";break}case 126:{a="yDrS";break}case 127:{r[2]==127?a="rDrm":a="yDrm";break}default:r[0]<48?a="r:":a="M"}a.length<4&&(a+=`${[e,c,r[0],r[2]][l]-f}`.padStart(4-a.length,"0")),d=="xg"&&e==16&&(i=`Voice${(c*128+s+1).toString().padStart(3,"0")}`,n=" ");let o=[r[0],r[1],r[2]];for(;!(i?.length>=0);)i=this.#t[r[1]||0][(r[0]<<7)+r[2]],i||(this.strictMode?(i="",n="?"):this.#t[r[1]||0][r[0]<<7]?r[0]==0?(r[2]=0,n="^"):r[2]<1?(r[0]=0,n="*"):(r[2]--,n="^"):e==48?(r[0]=0,r[2]=0,n="!"):e==62?(r[1]--,n=" ",r[1]<1&&!i?.length&&(r[0]=0,n="!")):e<63?r[0]==0?(r[2]=0,n="^"):r[2]<1?(r[0]=0,n="*"):r[2]--:e==80?(i=`PrgU:${s.toString().padStart(3,"0")}`,n="!"):e==88?(i=`CmbU:${s.toString().padStart(3,"0")}`,n="!"):e==121?(i=`GM2Vox0${c}`,n="#"):e==122?(r[1]==32?r[1]==0:r[1]%=7,i=this.#t[r[1]||0][(r[0]<<7)+r[2]],i?n=" ":(i="",n="*")):r[1]==0?(i=`${e.toString().padStart(3,"0")} ${s.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")}`,n="!"):r[0]==0?(r[2]=0,n="^"):r[2]>0?r[2]--:r[1]>0?(r[1]=0,n="!"):(r[0]=0,n="?"));let u=[r[0],r[1],r[2]];(d=="gs"||d=="ns5r")&&n=="^"&&(n=" "),e==127&&n=="^"&&(n=" "),n!=" "&&self.debugMode&&(i="");let p="??";switch(r[0]){case 0:{r[2]==0?p="GM":r[2]==5||r[2]==7?p="KG":r[2]<126?p="XG":r[2]==127&&(p="MT");break}case 48:{p="MU";break}case 56:{p="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{p="AI";break}case 62:case 82:case 90:{p="XD";break}case 63:{r[2]<17?p="KR":r[2]<34?p="ES":p="DS";break}case 64:case 126:{p="XG";break}case 67:case 99:{p=r[2]>>4==1?"SD":"DX";break}case 81:{p="RW";break}case 95:{p=["DR","PC"][r[2]];break}case 96:{p=r[2]==106?"AP":r[2]>>4==1?"SD":"PF";break}case 97:{p=r[2]>>4==1?"SD":"VL";break}case 98:{p=r[2]>>4==1?"SD":"SG";break}case 100:{p="AN";break}case 104:case 105:case 106:case 107:{p="SD";break}case 120:{p="GS";break}case 121:{p=r[2]?"G2":"GM";break}case 122:{p="KG";break}case 127:{p=r[2]==127?"MT":s==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&d=="xg"?p="XG":p="GS")}return{name:i||`${H(e||0)} ${H(s||0)} ${H(c||0)}`,iid:o,eid:u,sid:t,ending:n,sect:a,standard:p}}async load(e,s,c){let d=this,t=[],i=0,r=0;e.split(` -`).forEach(function(n,a){let l=n.split(" "),f=[];a==0?l.forEach(function(o,u){t[le.indexOf(o)]=u}):l.forEach(async function(o,u){u>2?(d.#t[f[t[1]]]=d.#t[f[t[1]]]||[],(!d.#t[f[t[1]]][(f[t[0]]<<7)+f[t[2]]]?.length||s)&&(d.#t[f[t[1]]][(f[t[0]]<<7)+f[t[2]]]=l[3],i++),r++):f.push(parseInt(l[u]))})}),s||console.debug(`Map "${c||"(internal)"}": ${r} total, ${i} loaded.`)}clearRange(e){let s=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],c=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],d=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let t=c[0];t<=c[1];t++){let i=t<<7;for(let r=d[0];r<=d[1];r++){let n=i+r;for(let a=s[0];a<=s[1];a++)delete this.#t[a][n]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let s=this;e.forEach(async function(c,d){try{await fetch(`./data/bank/${c}.tsv`).then(function(t){return t.text()}).then(t=>{s.load(t,!1,c)})}catch{console.error(`Failed loading "${c}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var V=class{#t={};context;set(e,s){this.#t[e]=s}has(e){return!!this.#t[e]}async read(e,s){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,s)}};var oe=function(e,s){let c=!0;return s.forEach((d,t)=>{c=c&&e[t]==d}),c},z=function(e){let s=0;return e.forEach(c=>{s*=256,s+=c}),s},T=new TextDecoder,A=new V;A.set("s7e",async function(e){let s=new Uint8Array(await e.slice(0,65536).arrayBuffer()),c="MSB LSB PRG NME",d=[0,0,0,0],t=32,i=0,r=0,n=!0,a=[],l=0;for(;n;){let f=s.subarray(i);([()=>{T.decode(f.subarray(0,4))=="YSFC"?(i+=80,r=1):i++},()=>{if(oe(f.subarray(0,4),d))a.forEach((o,u,p)=>{let g=z(s.subarray(o.start+4,o.start+8));o.length=g}),r=2;else{let o=T.decode(f.subarray(0,4)),u=z(f.subarray(4,8));a.push({type:o,start:u}),i+=8}},()=>{let o=a[l],u=s.subarray(o.start,o.start+o.length),p=32;switch(o.type){case"ENVC":{let g=t;for(;g=a.length&&(r=3,n=!1)}][r]||(()=>{n=!1}))()}return c});var R=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),D=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],fe=[17.1,18.6,20.2,21.8,23.3,24.9,26.5,28,29.6,31.2,32.8,34.3,35.9,37.5,39,40.6,42.2,43.7,45.3,46.9,48.4,50],M=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],q=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],Q=function(e){let s=.1,c=-.3;return e>66?(s=5,c=315):e>56?(s=1,c=47):e>46&&(s=.5,c=18.5),s*e-c},Y=function(e){return e>105?fe[e-106]:e>100?e*1.1-100:e/10},W=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),L={};`hi*, +var z=function(e,a){let o=Math.min(e.length,a.length),h=e.slice(0,o),y=a.slice(0,o),g=0,f=0;for(;f0){let h=this.pool.length,y=1<=1&&f>=0;){if(f<=0)throw new Error("TTL reached.");if(g==h)g-=y;else{let s=z(a,this.pool[g]);switch(s){case 0:{f=0;break}case 1:{g+y<=h&&(g+=y);break}case-1:{g!=0&&(g-=y);break}default:console.warn(`Unexpected result ${s}.`)}}y=y>>1,f--}let t=!0;if(g>=this.pool.length)t=!1;else{let s=this;this.pool[g].forEach(function(c,i,r){t&&c!=a[i]&&(t=!1)}),!t&&z(a,this.pool[g])>0&&g++}return t||o?g:-1}else return o?0:-1},this.add=function(a,o){return a.data=o,this.pool.splice(this.point(a,!0),0,a),this},this.default=function(a){console.warn(`No match in "${this.name||"(unknown)"}" for "${a}". Default action not defined.`)},this.get=function(a){let o=this.point(a);if(o>-1)return this.pool[o].data;this.default(a)},this.run=function(a,...o){let h=this.point(a);h>-1?a.subarray?this.pool[h].data(a.subarray(this.pool[h].length),...o):this.pool[h].data(a.slice(this.pool[h].length),...o):this.default(a,...o)}};var q=class{#t={};addEventListener(e,a){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(a)}removeEventListener(e,a){if(this.#t[e]){let o=this.#t[e].indexOf(a);o>-1&&this.#t[e].splice(o,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,a){let o=new Event(e),h=this;o.data=a,this.#t[e]?.length>0&&this.#t[e].forEach(function(y){try{y?.call(h,o)}catch(g){console.error(g)}}),this[`on${e}`]&&this[`on${e}`](o)}};var he=["MSB","PRG","LSB"],G=function(e){let a=Math.floor(e/10),o=e%10;return`${a.toString(16)}${o}`},B=class{#t;strictMode=!1;get(e=0,a=0,o=0,h){let y=[e,a,o],g,f=Array.from(arguments);switch(h){case"xg":{switch(e){case 0:{o==126?f[2]=125:o==127&&(f[2]=0);break}case 16:{o==126&&(f[2]=0);break}case 32:{f[2]+=4;break}case 33:case 35:case 36:{f[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:f[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{o==126&&(f[2]=0);break}case 48:case 64:case 126:case 127:{o==126&&(f[2]=0);break}}break}case"gs":{e==0&&o<5?f[2]=0:e>125&&o<5&&o!=2&&(f[2]=e,f[0]=0);break}case"g2":case"sd":{(e>>1==40||e>95&&e<100)&&(f[2]|=16);break}case"sg":{e==8&&o==0&&(f[2]=5);break}case"s90es":{o<8?f[2]+=17:o<32?f[2]+=13:f[2]=(f[2]>>3)+19;break}case"motif":{o<8?f[2]+=28:o<32?f[2]+=13:f[2]=(f[2]>>3)+19;break}}let t=" ",s="M",c=0,i=0;switch(f[0]){case 0:{f[2]==127?s="MT-a":f[2]==126?s="MT-b":f[2]==7?s="GM-k":f[2]==5?s="SG-a":f[2]==4?s="SP-l":f[2]==0||h=="gs"&&f[2]<5?s="GM-a":(s="y",c=3);break}case 8:{h=="sg"?s="GM-s":s="r:";break}case 48:{s=`yM${(f[2]>>3).toString().padStart(2,"0")}`,c=1;break}case 56:{s="GM-b";break}case 61:case 120:{s="rDrm";break}case 62:{s="kDrm";break}case 63:{if(f[2]<17){let l=f[2];s=l<10?"kP:":"kC:",s+=l%10}else f[2]<34?s=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][f[2]-17]:s="Ds";break}case 64:{s="ySFX";break}case 67:{s="DX:S";break}case 80:case 81:case 82:case 83:{s=`Prg${"UABC"[f[0]-80]}`;break}case 88:case 89:case 90:case 91:{s=`Cmb${"UABC"[f[0]-88]}`;break}case 95:{s=`${["DR","PC"][f[2]]}-d`;break}case 96:{s=f[2]==106?"AP-a":f[2]>>4==1?"SDg":"PF",f[2]>63?i=63:f[2]>>4==1&&(i=16),c=3;break}case 97:{s=f[2]>>4==1?"SDa":"VL:",c=3,f[2]>>4==1?i=16:i=112;break}case 98:{s=f[2]>>4==1?"SDb":"SG-a",c=3,i=16;break}case 99:{s=f[2]>>4==1?"SDc":"DX",f[2]>63?i=63:f[2]>>4==1&&(i=16),c=3;break}case 100:{s="AN",f[2]>63?i=63:f[2]>>4==1&&(i=16),c=3;break}case 104:case 105:case 106:case 107:{s="SDd",i=104;break}case 121:{s=`GM-${f[2]?"":"a"}`,c=3;break}case 122:{s="lDrm";break}case 126:{s="yDrS";break}case 127:{f[2]==127?s="rDrm":s="yDrm";break}default:f[0]<48?s="r:":s="M"}s.length<4&&(s+=`${[e,o,f[0],f[2]][c]-i}`.padStart(4-s.length,"0")),h=="xg"&&(e==0?f[2]<100?s=s.replace("y0","y:"):f[2]==125&&(s="y126"):e==16&&(g=`Voice${(f[2]*128+f[1]+1).toString().padStart(3,"0")}`,t=" "));let r=[f[0],f[1],f[2]];for(;!(g?.length>=0);)g=this.#t[f[1]||0][(f[0]<<7)+f[2]],g||(this.strictMode?(g="",t="?"):this.#t[f[1]||0][f[0]<<7]?f[0]==0?(f[2]=0,t="^"):f[2]<1?(f[0]=0,t="*"):(f[2]--,t="^"):e==48?(f[0]=0,f[2]=0,t="!"):e==62?(f[1]--,t=" ",f[1]<1&&!g?.length&&(f[0]=0,t="!")):e<63?f[0]==0?(f[2]=0,t="^"):f[2]<1?(f[0]=0,t="*"):f[2]--:e==80?(g=`PrgU:${a.toString().padStart(3,"0")}`,t="!"):e==88?(g=`CmbU:${a.toString().padStart(3,"0")}`,t="!"):e==121?(g=`GM2Vox0${o}`,t="#"):e==122?(f[1]==32?f[1]==0:f[1]%=7,g=this.#t[f[1]||0][(f[0]<<7)+f[2]],g?t=" ":(g="",t="*")):f[1]==0?(g=`${e.toString().padStart(3,"0")} ${a.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")}`,t="!"):f[0]==0?(f[2]=0,t="^"):f[2]>0?f[2]--:f[1]>0?(f[1]=0,t="!"):(f[0]=0,t="?"));let n=[f[0],f[1],f[2]];(h=="gs"||h=="ns5r")&&t=="^"&&(t=" "),e==127&&t=="^"&&(t=" "),t!=" "&&self.debugMode&&(g="");let d="??";switch(f[0]){case 0:{f[2]==0?d="GM":f[2]==5||f[2]==7?d="KG":f[2]<126?d="XG":f[2]==127&&(d="MT");break}case 48:{d="MU";break}case 56:{d="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{d="AI";break}case 62:case 82:case 90:{d="XD";break}case 63:{f[2]<17?d="KR":f[2]<34?d="ES":d="DS";break}case 64:case 126:{d="XG";break}case 67:case 99:{d=f[2]>>4==1?"SD":"DX";break}case 81:{d="RW";break}case 95:{d=["DR","PC"][f[2]];break}case 96:{d=f[2]==106?"AP":f[2]>>4==1?"SD":"PF";break}case 97:{d=f[2]>>4==1?"SD":"VL";break}case 98:{d=f[2]>>4==1?"SD":"SG";break}case 100:{d="AN";break}case 104:case 105:case 106:case 107:{d="SD";break}case 120:{d="GS";break}case 121:{d=f[2]?"G2":"GM";break}case 122:{d="KG";break}case 127:{d=f[2]==127?"MT":a==0?"GM":"XG";break}default:f[0]<48&&(f[0]==16&&h=="xg"?d="XG":d="GS")}return{name:g||`${G(e||0)} ${G(a||0)} ${G(o||0)}`,iid:r,eid:n,sid:y,ending:t,sect:s,standard:d}}async load(e,a,o){let h=this,y=[],g=0,f=0;e.split(` +`).forEach(function(t,s){let c=t.split(" "),i=[];s==0?c.forEach(function(r,n){y[he.indexOf(r)]=n}):c.forEach(async function(r,n){n>2?(h.#t[i[y[1]]]=h.#t[i[y[1]]]||[],(!h.#t[i[y[1]]][(i[y[0]]<<7)+i[y[2]]]?.length||a)&&(h.#t[i[y[1]]][(i[y[0]]<<7)+i[y[2]]]=c[3],g++),f++):i.push(parseInt(c[n]))})}),a||console.debug(`Map "${o||"(internal)"}": ${f} total, ${g} loaded.`)}clearRange(e){let a=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],o=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],h=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let y=o[0];y<=o[1];y++){let g=y<<7;for(let f=h[0];f<=h[1];f++){let t=g+f;for(let s=a[0];s<=a[1];s++)delete this.#t[s][t]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let a=this;e.forEach(async function(o,h){try{await fetch(`./data/bank/${o}.tsv`).then(function(y){return y.text()}).then(y=>{a.load(y,!1,o)})}catch{console.error(`Failed loading "${o}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var Q=class{#t={};context;set(e,a){this.#t[e]=a}has(e){return!!this.#t[e]}async read(e,a){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,a)}};var ue=function(e,a){let o=!0;return a.forEach((h,y)=>{o=o&&e[y]==h}),o},Y=function(e){let a=0;return e.forEach(o=>{a*=256,a+=o}),a},O=new TextDecoder,N=new Q;N.set("s7e",async function(e){let a=new Uint8Array(await e.slice(0,65536).arrayBuffer()),o="MSB LSB PRG NME",h=[0,0,0,0],y=32,g=0,f=0,t=!0,s=[],c=0;for(;t;){let i=a.subarray(g);([()=>{O.decode(i.subarray(0,4))=="YSFC"?(g+=80,f=1):g++},()=>{if(ue(i.subarray(0,4),h))s.forEach((r,n,d)=>{let l=Y(a.subarray(r.start+4,r.start+8));r.length=l}),f=2;else{let r=O.decode(i.subarray(0,4)),n=Y(i.subarray(4,8));s.push({type:r,start:n}),g+=8}},()=>{let r=s[c],n=a.subarray(r.start,r.start+r.length),d=32;switch(r.type){case"ENVC":{let l=y;for(;l=s.length&&(f=3,t=!1)}][f]||(()=>{t=!1}))()}return o});var U=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),A=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],pe=[17.1,18.6,20.2,21.8,23.3,24.9,26.5,28,29.6,31.2,32.8,34.3,35.9,37.5,39,40.6,42.2,43.7,45.3,46.9,48.4,50],D=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],W=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],J=function(e){let a=.1,o=-.3;return e>66?(a=5,o=315):e>56?(a=1,o=47):e>46&&(a=.5,o=18.5),a*e-o},Z=function(e){return e>105?pe[e-106]:e>100?e*1.1-100:e/10},j=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),_={};`hi*, ka,か ki,き ku,く @@ -139,8 +139,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let s=e.split(",");L[s[0]]=s[1]});var J=function(e){let s=e;e[0]=="*"&&(s=s.slice(1)),["aa","ii","uu","ee","oo"].forEach(d=>{for(;s.indexOf(d)>-1;)s=s.replace(d,d[0])});for(let d in L)s=s.replaceAll(d,L[d]);s.indexOf("ん")==0&&s.length>1&&(s=s.slice(1));let c=s.indexOf("!");return c>-1&&s.length>1&&(s=s.slice(c+1)),s},Z=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var G=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],j=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ee=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var he={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},de={66307:["drive"],66309:["vowel",e=>"aiueo"[e]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",e=>["off","LPF","HPF"][e]],94984:["noise type",e=>["white","pink"][e]],94987:["disc type",e=>["LP","SP","EP","RND"]],94990:["hum type",e=>`${e+5}0Hz`],94993:["M/S",e=>["mono","stereo"][e]]},B=function(e){return he[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},te=function(e,s,c){let d=(e[0]-32<<16)+(e[1]<<8)+s,t=de[d]||{},i=t[0];if(i?.length)return i+=`: ${(t[1]||function(){})(c)||c}`,i},_=[68,48,95,78,41,3,110,122,0];var m=function(e=64){return Math.round(2e3*Math.log10(e/64))/100};var I=function(e){let s=0;return e.forEach(c=>{s+=c,s=s&127}),~s+1&127},S=function(e,s){let c=0,d=0;for(let t=0;t>i&1)<<7,n=e[t];n+=r,t%8!=0?(s(n,c,e),c++):d=e[t]}},O=function(e){let s=Math.floor(e*14.2);return s<128?s:0};var v=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],ae=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],C=[120,127,120,127,120,127,61,62,62,105,120,122,122,127],ue=[0,3,81,84,88],se={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},X={0:0,1:1,2:3,5:4},re=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],ie=[36,37],P=[20,21,22,23,24,25,26,28,29,30,31,36,37,64,65],U=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19],be=[12,13,16,17,18,19],pe=[33,99,100,32,102,8,9,10],ne=[0,16,25,40,32,64,26,48],y={};v.forEach((e,s)=>{y[e]=s});var h={length:U.length};U.forEach((e,s)=>{h[e]=s});var ce={length:P.length};P.forEach((e,s)=>{ce[e]=s});var w=function(){return!!self.Bun||self.debugMode||!1},ge=function(e){let s=[],c=0;return e?.forEach(function(d,t){d==247?s.push(e.subarray(c,t)):d==240&&(c=t+1)}),s.length||s.push(e.subarray(0)),w()&&console.debug(s),s};var b={ch:128,cc:U.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:P.length,dnc:128,efx:7},_e=class extends F{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#b=0;#v=0;#T=new Array(11);get#p(){return this.#T[this.#b]}set#p(e){this.#T[this.#b]=e}#c=new Uint8Array(b.ch);#h=new Uint8Array(b.ch);#s=new Uint8Array(b.ch);#e=new Uint8Array(b.ch*b.cc);#R=new Uint8Array(b.ace);#r=new Uint8Array(b.ch);#l=new Uint8Array(b.ch*b.nn);#$=new Uint8Array(b.ch);#o=new Uint16Array(b.pl);#d=new Uint8Array(b.pl);#U=new Int16Array(b.ch);#C=new Uint8Array(b.ch);#G=0;#a=new Uint8Array(b.ch*b.rpn);#z=new Int8Array(b.ch*ie.length);#Z=new Uint8Array(b.drm*b.dpn*b.dnc);#x=new Uint8Array(b.ch);#A=new Uint8Array(128);#k=new Uint8Array(b.cmt*8);#q=new Uint8Array(1024);#P=new Uint8Array(b.cmt*64);#g=new Uint8Array(b.efx*3);#Q=new Uint8Array(b.ch);#H=0;#E=0;#i=100;#B=0;#Y=500;#W=0;#M="";#N=0;#J=0;#S=!0;#n=!1;#j;#ae=new Uint8Array(2);#y=[];#D=new Uint8Array(b.ch);#L=new Uint8Array(b.tr);baseBank=new N("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es");userBank=new N("gm");initOnReset=!1;aiEfxName="";chRedir(e,s,c){if(this.#L[s])return(this.#L[s]-1)*16+e;if([2,3].indexOf(this.#E)>-1){if(c==1)return e;let d=0,t=!0;for(;t;)this.#D[e+d]==0?(this.#D[e+d]=s,console.debug(`Assign track ${s} to channel ${e+d+1}.`),t=!1):this.#D[e+d]==s?t=!1:(d+=16,d>=128&&(d=0,t=!1));return e+d}else return e}#u=[];#_;#f={nOff:(e,s)=>{let c=e*128+s,d=this.#o.lastIndexOf(c);d>-1&&(this.#e[b.cc*e+h[64]]>63?(this.#d[d]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:s,velo:this.#l[c],state:this.NOTE_HELD})):this.#e[b.cc*e+h[66]]>63&&this.#d[d]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#d[d]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:s,velo:this.#l[c],state:this.NOTE_SOSTENUTO_HELD})):(this.#o[d]=0,this.#l[c]=0,this.#d[d]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:s,velo:0,state:this.NOTE_IDLE})))},nOn:(e,s,c)=>{let d=e*128+s,t=0;for(this.#$[e]&&this.#f.ano(e);this.#d[t]>0&&this.#o[t]!=d;)t++;t{},cAt:(e,s)=>{},hoOf:e=>{this.#d.forEach((s,c)=>{if(s==this.NOTE_HELD){let d=this.#o[c],t=d>>7;e==t&&(this.#d[c]=this.NOTE_IDLE,this.#o[c]=0,this.#l[d]=0,this.dispatchEvent("note",{part:e,note:d&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#d.forEach((s,c)=>{let d;switch(s){case this.NOTE_ATTACK:{d=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{d=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{d=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(d){this.#d[c]=d;let t=this.#o[c];this.dispatchEvent("note",{part:e,note:t&127,velo:this.#l[t],state:d})}})},soOf:e=>{this.#d.forEach((s,c)=>{if(s==this.NOTE_SOSTENUTO_HELD){let d=this.#o[c],t=d>>7;e==t&&(this.#d[c]=this.NOTE_IDLE,this.#o[c]=0,this.#l[d]=0,this.dispatchEvent("note",{part:e,note:d&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#o.forEach((s,c,d)=>{let t=s>>7,i=s&127;s==0&&this.#l[0]==0||t==e&&this.#f.nOff(t,i)})}};#ee={8:function(e){let s=e.channel,c=e.data[0];this.#f.nOff(s,c)},9:function(e){let s=e.channel;this.#c[s]=1;let c=e.data[0],d=e.data[1];d>0?this.#f.nOn(s,c,d):this.#f.nOff(s,c)},10:function(e){let s=e.channel,c=s*128+e.data[0];this.#o.indexOf(c)>-1&&(this.#l[c]=data[1],this.dispatchEvent("note",{part:s,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let s=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case y.s90es:case y.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&(this.#c[s]=1);break}e.data[1]&&(this.#c[s]=1);break}default:{this.#c[s]=1;break}}})();let c=s*b.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#f.ano(s),this.#U[s]=0;let d=s*b.cc;this.#e[d+h[1]]=0,this.#e[d+h[5]]=0,this.#e[d+h[64]]=0,this.#e[d+h[65]]=0,this.#e[d+h[66]]=0,this.#e[d+h[67]]=0,this.#e[d+h[11]]=127,this.#e[d+h[101]]=127,this.#e[d+h[100]]=127,this.#e[d+h[99]]=127,this.#e[d+h[98]]=127;return}case 123:{this.#f.ano(s);return}case 124:{this.#f.ano(s);return}case 125:{this.#f.ano(s);return}case 126:{this.#$[s]=1,this.#f.ano(s);return}case 127:{this.#$[s]=0,this.#f.ano(s);return}}if(h[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(be.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(w()&&console.debug(`${v[this.#t]}, CH${s+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#s[s]>0&&(e.data[1]=this.#e[c],e.data[1]=120,console.debug(`Forced channel ${s+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==y.gs?e.data[1]<56&&this.#s[s]>0&&(e.data[1]=this.#e[c],e.data[1]=120,console.debug(`Forced channel ${s+1} to stay drums.`)):this.#t==y.gm?e.data[1]<48?this.#s[s]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${s+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):this.#t==y.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),this.#t){case y.xg:{[126,127].indexOf(e.data[1])>-1?this.#s[s]==0&&(this.setChType(s,this.CH_DRUM2),console.debug(`CH${s+1} set to drums by MSB.`)):this.#s[s]>0&&(this.setChType(s,this.CH_MELODIC),console.debug(`CH${s+1} set to melodic by MSB.`));break}case y["05rw"]:case y.x5d:case y.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#s[s]==0&&(this.setChType(s,this.CH_DRUM2),console.debug(`CH${s+1} set to drums by MSB.`)):this.#s[s]>0&&(this.setChType(s,this.CH_MELODIC),console.debug(`CH${s+1} set to melodic by MSB.`));break}case y.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#s[s]==0&&(this.setChType(s,this.CH_DRUM2),console.debug(`CH${s+1} set to drums by MSB.`)):this.#s[s]>0&&(this.setChType(s,this.CH_MELODIC),console.debug(`CH${s+1} set to melodic by MSB.`));break}case y.g2:{e.data[1]==120?this.#s[s]==0&&(this.setChType(s,this.CH_DRUMS),console.debug(`CH${s+1} set to drums by MSB.`)):this.#s[s]>0&&(this.setChType(s,this.CH_MELODIC),console.debug(`CH${s+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:s});break}case 6:{if(this.#G){[y.xg,y.gs,y.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${v[this.#t]}" mode, even when they are supported in Octavia.`);let d=this.#e[c+h[99]],t=this.#e[c+h[98]];if(d==1){let i=pe.indexOf(t);if(i>-1)this.#e[c+h[71+i]]=e.data[1],w()&&console.debug(`Redirected NRPN 1 ${t} to cc${71+i}.`),this.dispatchEvent("cc",{part:s,cc:71+i,data:e.data[1]});else{let r=ie.indexOf(t);r>-1?this.#z[s*10+r]=e.data[1]-64:console.warn(`NRPN 0x01${t.toString(16).padStart(2,"0")} is not supported.`),w()&&console.debug(`CH${s+1} voice NRPN ${t} commit`)}}else{if(P.indexOf(d)<0){let r=`NRPN 0x${d.toString(16).padStart(2,"0")}${t.toString(16).padStart(2,"0")} `;d==127?console.warn(`${r}is not necessary. Consider removing it.`):console.warn(`${r}is not supported.`)}else{let r=this.#s[s]-2;r<0?console.warn(`CH${s+1} cannot accept drum NRPN as type ${D[this.#s[s]]}.`):this.#Z[(r*b.dpn+ce[d])*b.dnc+t]=e.data[1]-64}w()&&console.debug(`CH${s+1} (${D[this.#s[s]]}) drum NRPN ${d} commit`)}}else{let d=X[this.#e[c+h[100]]];this.#e[c+h[101]]==0&&d!=null&&(w()&&console.debug(`CH${s+1} RPN 0 ${this.#e[c+h[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],re[d][0]),re[d][1]),this.#a[s*b.rpn+d]=e.data[1])}break}case 32:{switch(w()&&console.debug(`${v[this.#t]}, CH${s+1} LSB: ${e.data[1]}`),this.#t){case y.s90es:case y.motif:{this.setChType(s,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.dispatchEvent("voice",{part:s});break}case 38:{this.#G||this.#e[c+101]==0&&X[this.#e[c+100]]!=null&&(this.#a[s*b.rpn+X[this.#e[c+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#f.hoOf(s);break}case 66:{e.data[1]>>6?this.#f.soOn(s):this.#f.soOf(s);break}case 98:case 99:{this.#G=1;break}case 100:case 101:{this.#G=0;break}}this.#e[c+h[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:s,cc:e.data[0],data:e.data[1]})}},12:function(e){let s=e.channel;switch(this.#t){case y.s90es:case y.motif:{e.data&&(this.#c[s]=1);break}default:this.#c[s]=1}this.#r[s]=e.data,this.#x[s]=0,w()&&console.debug(`T:${e.track} C:${s} P:${e.data}`),this.dispatchEvent("voice",{part:s})},13:function(e){let s=this,c=e.channel;this.#o.forEach(function(d){let t=d>>7;c==t&&(s.#l[d]=e.data,s.dispatchEvent("note",{part:c,note:d&127,velo:e.data,state:s.NOTE_SUSTAIN}))})},14:function(e){let s=e.channel;this.#U[s]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:s,pitch:this.getPitchShift(s)})},15:function(e){ge(e.data).forEach(s=>{let c=s[0],d=s[1];(this.#te[c]||function(){console.debug(`Unknown manufacturer ${c}.`)})(d,s.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#u[e.meta]||function(c,d,t){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#B=0);let s=ue.indexOf(e.meta)>-1;if(w()&&console.debug(e),s)return e.reply="meta",e}};#te={64:(e,s,c)=>{this.#K.run(s,c,e)},65:(e,s,c)=>{if(s[0]<16)if(s[1]==72){let d=s[s.length-1],t=I(s.subarray(3,s.length-1));d==t?this.#w.run(s.subarray(0,s.length-1),c,e):console.warn(`Bad SD checksum ${d}. Should be ${t}.`)}else this.#w.run(s,c,e);else{let d=s[s.length-1],t=I(s.subarray(2,s.length-1));d==t?this.#w.run(s.subarray(0,s.length-1),c,e):console.warn(`Bad GS checksum ${d}. Should be ${t}.`)}},66:(e,s,c)=>{this.#O.run(s,c,e)},67:(e,s,c)=>{this.#m.run(s,c,e)},68:(e,s,c)=>{this.#V.run(s,c,e)},71:(e,s,c)=>{this.#F.run(s,c,e)},126:(e,s,c)=>{this.#I.run(s,c,e)},127:(e,s,c)=>{this.switchMode("gm"),this.#X.run(s,c,e)}};#I;#X;#m;#w;#O;#K;#F;#V;buildRchTree(){let e=[];this.#h.forEach((s,c)=>{e[s]?.constructor||(e[s]=[]),e[s].push(c)}),this.#j=e}getActive(){let e=this.#c.slice();return this.#t==y.mt32,e}getCc(e){let s=e*b.cc,c=this.#e.subarray(s,s+b.cc);return c[h[0]]=c[h[0]]||this.#H,c[h[32]]=c[h[32]]||this.#E,c}getCcCh(e,s){if(U.indexOf(s)<0)throw new Error("CC number not accepted");return this.#e[b.cc*e+h[s]]}getCcAll(){let e=this.#e.slice();for(let s=0;s0&&!d&&(this.#e[e*b.cc+h[0]]=C[c])}getPitch(){return this.#U}getProgram(){return this.#r}getTexts(){return this.#y.slice()}getVel(e){let s=new Map,c=this;return c.#o.forEach(function(d,t){let i=Math.floor(d/128),r=d%128;e==i&&c.#l[d]>0&&s.set(r,{v:c.#l[d],s:c.#d[t]})}),s}getBitmap(){return{bitmap:this.#p,expire:this.#v}}getLetter(){return{text:this.#M,expire:this.#N}}getMode(){return v[this.#t]}getMaster(){return{volume:this.#i}}getRawStrength(){let e=this;return this.#o.forEach(function(s){let c=Math.floor(s/128);e.#l[s]>e.#C[c]&&(e.#C[c]=e.#l[s])}),this.#C}getStrength(){let e=[],s=this;return this.getRawStrength().forEach(function(c,d){e[d]=Math.floor(c*s.#e[d*b.cc+h[7]]*s.#e[d*b.cc+h[11]]*s.#i/803288)}),e}getRpn(){return this.#a}getNrpn(){return this.#z}getVoice(e,s,c,d){let t=e||this.#H,i=s,r=c||this.#E;v[this.#t]=="ns5r"&&t>0&&t<56&&(r=3);let n=this.userBank.get(t,i,r,d);if(v[this.#t]=="mt32"&&n.name.indexOf("MT-m:")==0){let a=parseInt(n.name.slice(5)),l=a*b.cmt,f="";this.#P.subarray(l,l+10).forEach(o=>{o>31&&(f+=String.fromCharCode(o))}),this.userBank.load(`MSB LSB PRG -0 127 ${i} ${f}`,!0),n.name=f,n.ending=" "}return(n.ending!=" "||!n.name.length)&&(n=this.baseBank.get(t,i,r,d)),n}getChVoice(e){let s=this.getVoice(this.#e[e*b.cc+h[0]],this.#r[e],this.#e[e*b.cc+h[32]],v[this.#t]);if(this.#x[e])switch(this.#t){case y.mt32:s.ending="~",s.name="",this.#k.subarray(14*(e-1),14*(e-1)+10).forEach(c=>{c>31&&(s.name+=String.fromCharCode(c))})}return s}getPitchShift(e){let s=e*b.rpn;return this.#U[e]/8192*this.#a[s]+(this.#a[s+3]-64)+((this.#a[s+1]<<7)+this.#a[s+2]-8192)/8192}getEffectType(e=0){let s=3*e+1;return this.#g.subarray(s,s+2)}setEffectTypeRaw(e=0,s,c){let d=3*e;this.#g[d]=1,this.#g[d+1+ +s]=c}setEffectType(e=0,s,c){this.setEffectTypeRaw(e,!1,s),this.setEffectTypeRaw(e,!0,c)}getEffectSink(){return this.#Q}setLetterDisplay(e,s,c=0,d=3200){let t=this,i;t.#M=" ".repeat(c),e.forEach(r=>{t.#M+=String.fromCharCode(r>31?r:32),r<32&&(i=i||new Set,i.add(r))}),t.#N=Date.now()+3200,t.#M=t.#M.padEnd(32," "),i&&(i=Array.from(i),i.forEach((r,n,a)=>{a[n]=r.toString(16).padStart(2,"0")}),console.warn(`${s}${s?" ":""}invalid code point${i.length>1?"s":""}: 0x${i.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let s=!0,c=0;for(;s&&c=b.ace&&console.warn("ACE slots are full.")}getAce(){return this.#R}getChAce(e,s){if(s<0||s>=b.ace)throw new RangeError("No such ACE slot");let c=this.#R[s];if(c){if(U.indexOf(c)>=0)return this.#e[e*b.cc+h[c]];throw new Error(`Invalid ACE source: ${c}`)}else return 0}init(e=0){let s=this;s.dispatchEvent("mode","?"),s.#t=0,s.#H=0,s.#E=0,s.#B=0,s.#c.fill(0),s.#e.fill(0),s.#R.fill(0),s.#r.fill(0),s.#l.fill(0),s.#o.fill(0),s.#C.fill(0),s.#U.fill(0),s.#z.fill(0),s.#Z.fill(0),s.#i=100,s.#y=[],s.#Y=500,s.#W=0,s.#N=0,s.#M="",s.#v=0,s.#b=0,s.#p.fill(0),s.#n=!1,s.#J=0,s.#S=!0,s.#h.forEach(function(c,d,t){t[d]=d}),s.buildRchTree(),e==0&&(s.#D.fill(0),s.#L.fill(0)),s.#e[b.cc*9]=C[0],s.#e[b.cc*25]=C[0],s.#e[b.cc*41]=C[0],s.#e[b.cc*57]=C[0],s.#s.fill(s.CH_MELODIC),s.#s[9]=s.CH_DRUM1,s.#s[25]=s.CH_DRUM3,s.#s[41]=s.CH_DRUMS,s.#s[57]=s.CH_DRUMS,s.#s[73]=s.CH_DRUM5,s.#s[89]=s.CH_DRUM7,s.#s[105]=s.CH_DRUMS,s.#s[121]=s.CH_DRUMS,s.#q.fill(0),s.#P.fill(0),s.#A.fill(0),s.#k.fill(0),s.#x.fill(0),s.#g.fill(0),s.#Q.fill(0),s.aiEfxName="",s.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let c=0;c-1){if(c.#t==0||s){let t=c.#t;c.#t=d,c.#b=0,c.#H=ae[0][d],c.#E=ae[1][d];for(let r=0;r0&&c.#e[r*b.cc+h[0]]==C[t]&&(c.#e[r*b.cc]=C[d]);switch(c.initOnReset,d){case y.mt32:{_.forEach((r,n)=>{let a=n+1;c.#c[a]||(c.#r[a]=r,c.#e[a*b.cc+h[91]]=127)});break}}let i;switch(d){case y["?"]:case y.xg:{i=[1,0,65,0,5,0,0,0];break}case y.gm:case y.gs:case y.g2:case y.sd:{i=[40,4,40,18,40,32,32,0];break}case y["05rw"]:case y.x5d:case y.ns5r:{i=[44,1,44,19,44,0,44,0];break}case y.k11:case y.sg:{i=[24,0,0,0,0,0,0,0];break}case y.mt32:{i=[40,4,0,0,0,0,0,0];break}default:i=[0,0,0,0,0,0,0,0]}for(let r=0;r<4;r++)c.#g[3*r]||(c.#g[3*r+1]=i[2*r],c.#g[3*r+2]=i[2*r+1],c.dispatchEvent(`efx${["reverb","chorus","delay","insert"][r]}`,c.getEffectType(r)));c.dispatchEvent("mode",e)}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#C.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#ee[e.type].call(this,e);{let s=this.chRedir(e.part,e.track),c=!1;this.#j[s]?.forEach(d=>{e.channel=d,c=!0,this.#ee[e.type].call(this,e)}),c||console.warn(`${se[e.type]?se[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${s+1} without any recipient.`)}this.#y.length>100&&this.#y.splice(100,this.#y.length-99)}runRaw(e){}async loadBank(e,s){switch(e=e.toLowerCase(),e){case"s7e":{this.userBank.clearRange({msb:63,lsb:[21,22]}),this.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{A.context=this,this.userBank.load(await A.read(e,s));break}}}constructor(){super();let e=this;this.#p=new Uint8Array(256),this.#T[10]=new Uint8Array(512),this.#_=new k,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let a=e.split(",");_[a[0]]=a[1]});var ee=function(e){let a=e;e[0]=="*"&&(a=a.slice(1)),["aa","ii","uu","ee","oo"].forEach(h=>{for(;a.indexOf(h)>-1;)a=a.replace(h,h[0])});for(let h in _)a=a.replaceAll(h,_[h]);a.indexOf("ん")==0&&a.length>1&&(a=a.slice(1));let o=a.indexOf("!");return o>-1&&a.length>1&&(a=a.slice(o+1)),a},te=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var I=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],ae=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],se=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var be={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},ye={66307:["drive"],66309:["vowel",e=>"aiueo"[e]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",e=>["off","LPF","HPF"][e]],94984:["noise type",e=>["white","pink"][e]],94987:["disc type",e=>["LP","SP","EP","RND"]],94990:["hum type",e=>`${e+5}0Hz`],94993:["M/S",e=>["mono","stereo"][e]]},X=function(e){return be[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},re=function(e,a,o){let h=(e[0]-32<<16)+(e[1]<<8)+a,y=ye[h]||{},g=y[0];if(g?.length)return g+=`: ${(y[1]||function(){})(o)||o}`,g},V=[68,48,95,78,41,3,110,122,0];var S=function(e=64){return Math.round(2e3*Math.log10(e/64))/100};var K=function(e){let a=0;return e.forEach(o=>{a+=o,a=a&127}),~a+1&127},M=function(e,a){let o=0,h=0;for(let y=0;y>g&1)<<7,t=e[y];t+=f,y%8!=0?(a(t,o,e),o++):h=e[y]}},P=function(e){let a=Math.floor(e*14.2);return a<128?a:0};var T=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],ie=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],R=[120,127,120,127,120,127,61,62,62,105,120,122,122,127],$e=[0,3,81,84,88],ce={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},F={0:0,1:1,2:3,5:4},ne=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],oe=[36,37,48,49,52,53],L=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],le={26:127,29:0,30:0,31:0,52:12,53:54},H=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19],ge=[12,13,16,17,18,19],Ee=[33,99,100,32,102,8,9,10],de=[0,16,25,40,32,64,26,48],m={};T.forEach((e,a)=>{m[e]=a});var u={length:H.length};H.forEach((e,a)=>{u[e]=a});var C={length:L.length};L.forEach((e,a)=>{C[e]=a});var k=function(){return!!self.Bun||self.debugMode||!1},me=function(e){let a=[],o=0;return e?.forEach(function(h,y){h==247?a.push(e.subarray(o,y)):h==240&&(o=y+1)}),a.length||a.push(e.subarray(0)),k()&&console.debug(a),a};var b={ch:128,cc:H.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:L.length,dnc:128,efx:7},Ke=class extends q{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#u=0;#S=0;#M=new Array(11);get#b(){return this.#M[this.#u]}set#b(e){this.#M[this.#u]=e}#T=new Uint8Array(b.ch);#d=new Uint8Array(b.ch);#s=new Uint8Array(b.ch);#e=new Uint8Array(b.ch*b.cc);#R=new Uint8Array(b.ace);#r=new Uint8Array(b.ch);#n=new Uint8Array(b.ch*b.nn);#g=new Uint8Array(b.ch);#o=new Uint16Array(b.pl);#f=new Uint8Array(b.pl);#U=new Int16Array(b.ch);#C=new Uint8Array(b.ch);#B=0;#a=new Uint8Array(b.ch*b.rpn);#q=new Int8Array(b.ch*oe.length);#p=new Uint8Array(b.drm*b.dpn*b.dnc);#x=new Uint8Array(b.ch);#A=new Uint8Array(128);#v=new Uint8Array(b.cmt*8);#Q=new Uint8Array(1024);#P=new Uint8Array(b.cmt*64);#y=new Uint8Array(b.efx*3);#Y=new Uint8Array(b.ch);#H=0;#E=0;#i=100;#_=0;#W=500;#J=0;#N="";#L=0;#Z=0;#w=!0;#c=!1;#j;#ae=new Uint8Array(2);#$=[];#D=new Uint8Array(b.ch);#G=new Uint8Array(b.tr);baseBank=new B("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es");userBank=new B("gm");initOnReset=!1;aiEfxName="";chRedir(e,a,o){if(this.#G[a])return(this.#G[a]-1)*16+e;if([2,3].indexOf(this.#E)>-1){if(o==1)return e;let h=0,y=!0;for(;y;)this.#D[e+h]==0?(this.#D[e+h]=a,console.debug(`Assign track ${a} to channel ${e+h+1}.`),y=!1):this.#D[e+h]==a?y=!1:(h+=16,h>=128&&(h=0,y=!1));return e+h}else return e}forceVoiceRefresh(){for(let e=0;e{let o=e*128+a,h=this.#o.lastIndexOf(o);h>-1&&(this.#e[b.cc*e+u[64]]>63?(this.#f[h]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:a,velo:this.#n[o],state:this.NOTE_HELD})):this.#e[b.cc*e+u[66]]>63&&this.#f[h]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#f[h]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:a,velo:this.#n[o],state:this.NOTE_SOSTENUTO_HELD})):(this.#o[h]=0,this.#n[o]=0,this.#f[h]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:a,velo:0,state:this.NOTE_IDLE})))},nOn:(e,a,o)=>{let h=e*128+a,y=0;for(this.#g[e]&&this.#l.ano(e);this.#f[y]>0&&this.#o[y]!=h;)y++;y{},cAt:(e,a)=>{},hoOf:e=>{this.#f.forEach((a,o)=>{if(a==this.NOTE_HELD){let h=this.#o[o],y=h>>7;e==y&&(this.#f[o]=this.NOTE_IDLE,this.#o[o]=0,this.#n[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#f.forEach((a,o)=>{let h;switch(a){case this.NOTE_ATTACK:{h=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{h=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{h=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(h){this.#f[o]=h;let y=this.#o[o];this.dispatchEvent("note",{part:e,note:y&127,velo:this.#n[y],state:h})}})},soOf:e=>{this.#f.forEach((a,o)=>{if(a==this.NOTE_SOSTENUTO_HELD){let h=this.#o[o],y=h>>7;e==y&&(this.#f[o]=this.NOTE_IDLE,this.#o[o]=0,this.#n[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#o.forEach((a,o,h)=>{let y=a>>7,g=a&127;a==0&&this.#n[0]==0||y==e&&this.#l.nOff(y,g)})}};#ee={8:function(e){let a=e.channel,o=e.data[0];this.#l.nOff(a,o)},9:function(e){let a=e.channel;this.setChActive(a,1);let o=e.data[0],h=e.data[1];h>0?this.#l.nOn(a,o,h):this.#l.nOff(a,o)},10:function(e){let a=e.channel,o=a*128+e.data[0];this.#o.indexOf(o)>-1&&(this.#n[o]=data[1],this.dispatchEvent("note",{part:a,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let a=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case m.s90es:case m.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(a,1);break}e.data[1]&&this.setChActive(a,1);break}default:{this.setChActive(a,1);break}}})();let o=a*b.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#l.ano(a),this.#U[a]=0;let h=a*b.cc;this.#e[h+u[1]]=0,this.#e[h+u[5]]=0,this.#e[h+u[64]]=0,this.#e[h+u[65]]=0,this.#e[h+u[66]]=0,this.#e[h+u[67]]=0,this.#e[h+u[11]]=127,this.#e[h+u[101]]=127,this.#e[h+u[100]]=127,this.#e[h+u[99]]=127,this.#e[h+u[98]]=127;return}case 123:{this.#l.ano(a);return}case 124:{this.#l.ano(a);return}case 125:{this.#l.ano(a);return}case 126:{this.#g[a]=1,this.#l.ano(a);return}case 127:{this.#g[a]=0,this.#l.ano(a);return}}if(u[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(ge.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(k()&&console.debug(`${T[this.#t]}, CH${a+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#s[a]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==m.gs?e.data[1]<56&&this.#s[a]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)):this.#t==m.gm?e.data[1]<48?this.#s[a]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${a+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):this.#t==m.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),this.#t){case m.xg:{[126,127].indexOf(e.data[1])>-1?this.#s[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#s[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m["05rw"]:case m.x5d:case m.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#s[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#s[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#s[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#s[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m.g2:{e.data[1]==120?this.#s[a]==0&&(this.setChType(a,this.CH_DRUMS),console.debug(`CH${a+1} set to drums by MSB.`)):this.#s[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:a});break}case 6:{if(this.#B){[m.xg,m.gs,m.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${T[this.#t]}" mode, even when they are supported in Octavia.`);let h=this.#e[o+u[99]],y=this.#e[o+u[98]];if(h==1){let g=Ee.indexOf(y);if(g>-1)this.#e[o+u[71+g]]=e.data[1],k()&&console.debug(`Redirected NRPN 1 ${y} to cc${71+g}.`),this.dispatchEvent("cc",{part:a,cc:71+g,data:e.data[1]});else{let f=oe.indexOf(y);f>-1?this.#q[a*10+f]=e.data[1]-64:console.warn(`NRPN 0x01${y.toString(16).padStart(2,"0")} is not supported.`),k()&&console.debug(`CH${a+1} voice NRPN ${y} commit`)}}else{if(L.indexOf(h)<0){let f=`NRPN 0x${h.toString(16).padStart(2,"0")}${y.toString(16).padStart(2,"0")} `;h==127?console.warn(`${f}is not necessary. Consider removing it.`):console.warn(`${f}is not supported.`)}else{let f=this.#s[a]-2;f<0?console.warn(`CH${a+1} cannot accept drum NRPN as type ${A[this.#s[a]]}.`):this.#p[(f*b.dpn+C[h])*b.dnc+y]=e.data[1]}k()&&console.debug(`CH${a+1} (${A[this.#s[a]]}) drum NRPN ${h} commit`)}}else{let h=F[this.#e[o+u[100]]];this.#e[o+u[101]]==0&&h!=null&&(k()&&console.debug(`CH${a+1} RPN 0 ${this.#e[o+u[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],ne[h][0]),ne[h][1]),this.#a[a*b.rpn+h]=e.data[1])}break}case 32:{switch(k()&&console.debug(`${T[this.#t]}, CH${a+1} LSB: ${e.data[1]}`),this.#t){case m.s90es:case m.motif:{this.setChType(a,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.dispatchEvent("voice",{part:a});break}case 38:{this.#B||this.#e[o+101]==0&&F[this.#e[o+100]]!=null&&(this.#a[a*b.rpn+F[this.#e[o+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#l.hoOf(a);break}case 66:{e.data[1]>>6?this.#l.soOn(a):this.#l.soOf(a);break}case 98:case 99:{this.#B=1;break}case 100:case 101:{this.#B=0;break}}this.#e[o+u[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:a,cc:e.data[0],data:e.data[1]})}},12:function(e){let a=e.channel;switch(this.#t){case m.s90es:case m.motif:{e.data&&this.setChActive(a,1);break}default:this.setChActive(a,1)}this.#r[a]=e.data,this.#x[a]=0,k()&&console.debug(`T:${e.track} C:${a} P:${e.data}`),this.dispatchEvent("voice",{part:a})},13:function(e){let a=this,o=e.channel;this.#o.forEach(function(h){let y=h>>7;o==y&&(a.#n[h]=e.data,a.dispatchEvent("note",{part:o,note:h&127,velo:e.data,state:a.NOTE_SUSTAIN}))})},14:function(e){let a=e.channel;this.#U[a]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)})},15:function(e){me(e.data).forEach(a=>{let o=a[0],h=a[1];(this.#te[o]||function(){console.debug(`Unknown manufacturer ${o}.`)})(h,a.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#h[e.meta]||function(o,h,y){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#_=0);let a=$e.indexOf(e.meta)>-1;if(k()&&console.debug(e),a)return e.reply="meta",e}};#te={64:(e,a,o)=>{this.#K.run(a,o,e)},65:(e,a,o)=>{if(a[0]<16)if(a[1]==72){let h=a[a.length-1],y=K(a.subarray(3,a.length-1));h==y?this.#k.run(a.subarray(0,a.length-1),o,e):console.warn(`Bad SD checksum ${h}. Should be ${y}.`)}else this.#k.run(a,o,e);else{let h=a[a.length-1],y=K(a.subarray(2,a.length-1));h==y?this.#k.run(a.subarray(0,a.length-1),o,e):console.warn(`Bad GS checksum ${h}. Should be ${y}.`)}},66:(e,a,o)=>{this.#O.run(a,o,e)},67:(e,a,o)=>{this.#m.run(a,o,e)},68:(e,a,o)=>{this.#z.run(a,o,e)},71:(e,a,o)=>{this.#F.run(a,o,e)},126:(e,a,o)=>{this.#X.run(a,o,e)},127:(e,a,o)=>{this.switchMode("gm"),this.#V.run(a,o,e)}};#X;#V;#m;#k;#O;#K;#F;#z;buildRchTree(){let e=[];this.#d.forEach((a,o)=>{e[a]?.constructor||(e[a]=[]),e[a].push(o)}),this.#j=e}getActive(){return this.#T}getCc(e){let a=e*b.cc,o=this.#e.subarray(a,a+b.cc);return o[u[0]]=o[u[0]]||this.#H,o[u[32]]=o[u[32]]||this.#E,o}getCcCh(e,a){if(H.indexOf(a)<0)throw new Error("CC number not accepted");return this.#e[b.cc*e+u[a]]}getCcAll(){let e=this.#e.slice();for(let a=0;a0&&!h&&(this.#e[e*b.cc+u[0]]=R[o])}setChActive(e,a=0){this.#T[e]!=a&&this.dispatchEvent("channeltoggle",{part:e,active:a}),this.#T[e]=a}getPitch(){return this.#U}getProgram(){return this.#r}getTexts(){return this.#$.slice()}getVel(e){let a=new Map,o=this;return o.#o.forEach(function(h,y){let g=Math.floor(h/128),f=h%128;e==g&&o.#n[h]>0&&a.set(f,{v:o.#n[h],s:o.#f[y]})}),a}getBitmap(){return{bitmap:this.#b,expire:this.#S}}getLetter(){return{text:this.#N,expire:this.#L}}getMode(){return T[this.#t]}getMaster(){return{volume:this.#i}}getRawStrength(){let e=this;return this.#o.forEach(function(a){let o=Math.floor(a/128);e.#n[a]>e.#C[o]&&(e.#C[o]=e.#n[a])}),this.#C}getStrength(){let e=[],a=this;return this.getRawStrength().forEach(function(o,h){e[h]=Math.floor(o*a.#e[h*b.cc+u[7]]*a.#e[h*b.cc+u[11]]*a.#i/803288)}),e}getRpn(){return this.#a}getNrpn(){return this.#q}getVoice(e,a,o,h){let y=e||this.#H,g=a,f=o||this.#E;T[this.#t]=="ns5r"&&y>0&&y<56&&(f=3);let t=this.userBank.get(y,g,f,h);if(T[this.#t]=="mt32"&&t.name.indexOf("MT-m:")==0){let s=parseInt(t.name.slice(5)),c=s*b.cmt,i="";this.#P.subarray(c,c+10).forEach(r=>{r>31&&(i+=String.fromCharCode(r))}),this.userBank.load(`MSB LSB PRG +0 127 ${g} ${i}`,!0),t.name=i,t.ending=" "}return(t.ending!=" "||!t.name.length)&&(t=this.baseBank.get(y,g,f,h)),t}getChVoice(e){let a=this.getVoice(this.#e[e*b.cc+u[0]],this.#r[e],this.#e[e*b.cc+u[32]],T[this.#t]);if(this.#x[e])switch(this.#t){case m.mt32:a.ending="~",a.name="",this.#v.subarray(14*(e-1),14*(e-1)+10).forEach(o=>{o>31&&(a.name+=String.fromCharCode(o))})}return a}getPitchShift(e){let a=e*b.rpn;return this.#U[e]/8192*this.#a[a]+(this.#a[a+3]-64)+((this.#a[a+1]<<7)+this.#a[a+2]-8192)/8192}getEffectType(e=0){let a=3*e+1;return this.#y.subarray(a,a+2)}setEffectTypeRaw(e=0,a,o){let h=3*e;this.#y[h]=1,this.#y[h+1+ +a]=o}setEffectType(e=0,a,o){this.setEffectTypeRaw(e,!1,a),this.setEffectTypeRaw(e,!0,o)}getEffectSink(){return this.#Y}setLetterDisplay(e,a,o=0,h=3200){let y=this,g;y.#N=" ".repeat(o),e.forEach(f=>{y.#N+=String.fromCharCode(f>31?f:32),f<32&&(g=g||new Set,g.add(f))}),y.#L=Date.now()+h,g&&(g=Array.from(g),g.forEach((f,t,s)=>{s[t]=f.toString(16).padStart(2,"0")}),console.warn(`${a}${a?" ":""}invalid code point${g.length>1?"s":""}: 0x${g.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let a=!0,o=0;for(;a&&o=b.ace&&console.warn("ACE slots are full.")}getAce(){return this.#R}getChAce(e,a){if(a<0||a>=b.ace)throw new RangeError("No such ACE slot");let o=this.#R[a];if(o){if(H.indexOf(o)>=0)return this.#e[e*b.cc+u[o]];throw new Error(`Invalid ACE source: ${o}`)}else return 0}initDrums(){let e=this;e.#p.fill(64);for(let a=0;a-1){if(o.#t==0||a){let y=o.#t;o.initOnReset&&a&&this.init(1),o.#t=h,o.#u=0,o.#H=ie[0][h],o.#E=ie[1][h];for(let f=0;f0&&o.#e[f*b.cc+u[0]]==R[y]&&(o.#e[f*b.cc]=R[h]);switch(h){case m.mt32:{V.forEach((f,t)=>{let s=t+1;o.#T[s]||(o.#r[s]=f,o.#e[s*b.cc+u[91]]=127)});for(let f=1;f<10;f++)o.dispatchEvent("voice",{part:f});break}}let g;switch(h){case m["?"]:case m.xg:{g=[1,0,65,0,5,0,0,0];break}case m.gm:case m.gs:case m.g2:case m.sd:{g=[40,4,40,18,40,32,32,0];break}case m["05rw"]:case m.x5d:case m.ns5r:{g=[44,1,44,19,44,0,44,0];break}case m.k11:case m.sg:{g=[24,0,0,0,0,0,0,0];break}case m.mt32:{g=[40,4,0,0,0,0,0,0];break}default:g=[0,0,0,0,0,0,0,0]}for(let f=0;f<4;f++)o.#y[3*f]||(o.#y[3*f+1]=g[2*f],o.#y[3*f+2]=g[2*f+1],o.dispatchEvent(`efx${["reverb","chorus","delay","insert"][f]}`,o.getEffectType(f)));o.dispatchEvent("mode",e),o.forceVoiceRefresh()}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#C.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#ee[e.type].call(this,e);{let a=this.chRedir(e.part,e.track),o=!1;this.#j[a]?.forEach(h=>{e.channel=h,o=!0,this.#ee[e.type].call(this,e)}),o||console.warn(`${ce[e.type]?ce[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${a+1} without any recipient.`)}this.#$.length>100&&this.#$.splice(100,this.#$.length-99)}runRaw(e){}async loadBank(e,a){let o=this;switch(e=e.toLowerCase(),e){case"s7e":{o.userBank.clearRange({msb:63,lsb:[21,22]}),o.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{N.context=this,o.userBank.load(await N.read(e,a));break}}o.forceVoiceRefresh()}constructor(){super();let e=this;this.#b=new Uint8Array(256),this.#M[10]=new Uint8Array(512),this.#I=new x,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -148,18 +148,18 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),this.addEventListener("metacommit",function(t){let{data:i}=t;e.#y[0]?.type==i.type&&e.#y[0]?.amend?(e.#y[0].amend=i.amend,e.#y[0].data+=i.data):e.#y.unshift(i)}),this.#u[1]=function(t){switch(t=t.replaceAll(`\r +122 006 000 `),this.addEventListener("metacommit",function(t){let{data:s}=t;e.#$[0]?.type==s.type&&e.#$[0]?.amend?(e.#$[0].amend=s.amend,e.#$[0].data+=s.data):e.#$.unshift(s)}),this.#h[1]=function(t){switch(t=t.replaceAll(`\r `,` `).replaceAll("\r",` -`),t.slice(0,2)){case"@I":{this.#n=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:t.slice(2)?.trimLeft()});break}case"@K":{this.#n=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:t.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#n=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:t.slice(2)?.trimLeft()});break}case"@T":{this.#n=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:t.slice(2)?.trimLeft()});break}case"@V":{this.#n=!0,this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:t.slice(2)?.trimLeft()});break}case"XF":{let i=t.slice(2).split(":");switch(i[0]){case"hd":{i.slice(1).forEach((r,n)=>{r.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][n],data:r})});break}case"ln":{i.slice(1).forEach((r,n)=>{r.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][n],data:r})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:t})}break}default:this.#n?t[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:t.slice(1),amend:!0})):t[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:t.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:t,amend:!0}):t.split(` -`).forEach((i,r)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:i,mask:r!=0})})}},this.#u[2]=function(t){this.dispatchEvent("metacommit",{type:"Copyrite",data:t})},this.#u[3]=function(t,i){i<1&&this.#B<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:t})},this.#u[4]=function(t,i){this.dispatchEvent("metacommit",{type:"Instrmnt",data:t})},this.#u[5]=function(t){t.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:t,amend:!0})},this.#u[6]=function(t){this.dispatchEvent("metacommit",{type:"C.Marker",data:t})},this.#u[7]=function(t){this.dispatchEvent("metacommit",{type:"CuePoint",data:t})},this.#u[32]=function(t){this.#B=t[0]+1},this.#u[33]=function(t,i){e.#L[i]=t+1},this.#u[81]=function(t,i){e.#Y=t/1e3},this.#u[127]=function(t,i){e.#_.run(t,i)},this.#_.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#_.add([67,0,1],function(t,i){e.#L[i]=t[0]+1}),this.#I=new k("universal non-realtime"),this.#X=new k("universal realtime"),this.#m=new k("Yamaha"),this.#w=new k("Roland"),this.#O=new k("Korg"),this.#K=new k("Kawai"),this.#F=new k("Akai"),this.#V=new k("Casio");let s=function(t){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,t)};this.#I.default=s,this.#X.default=s,this.#m.default=s,this.#w.default=s,this.#O.default=s,this.#K.default=s,this.#F.default=s,this.#V.default=s,this.#I.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#n=e.#n||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#X.add([4,1],t=>{e.#i=((t[1]<<7)+t[0])/16383*100,e.dispatchEvent("mastervolume",e.#i)}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#m.add([76,0,0],t=>{switch(t[0]){case 125:{console.info(`XG drum setup reset: ${t}`);break}case 126:{e.switchMode("xg",!0),e.#n=!1,console.info("MIDI reset: XG");break}default:{let i=[0,0,0,0],r=(n,a)=>{i[a]=n};if(t.subarray(1).forEach((n,a)=>{let l=a+t[0];([r,r,r,r,f=>{this.#i=f*129/16383*100,e.dispatchEvent("mastervolume",e.#i)},f=>{},f=>{}][l]||(()=>{}))(n,a)}),t[0]<4){let n=0;i.forEach(a=>{n=n<<4,n+=a}),n-=1024}}}}).add([76,2,1],t=>{let i="XG ";t[0]<32?(i+="reverb ",t.subarray(1).forEach((r,n)=>{([a=>{e.setEffectTypeRaw(0,!1,a),console.info(`${i}main type: ${R[a]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},a=>{e.setEffectTypeRaw(0,!0,a),console.debug(`${i}sub type: ${a+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},a=>{console.debug(`${i}time: ${Q(a)}s`)},a=>{console.debug(`${i}diffusion: ${a}`)},a=>{console.debug(`${i}initial delay: ${a}`)},a=>{console.debug(`${i}HPF cutoff: ${M[a]}Hz`)},a=>{console.debug(`${i}LPF cutoff: ${M[a]}Hz`)},a=>{console.debug(`${i}width: ${a}`)},a=>{console.debug(`${i}height: ${a}`)},a=>{console.debug(`${i}depth: ${a}`)},a=>{console.debug(`${i}wall type: ${a}`)},a=>{console.debug(`${i}dry/wet: ${a}`)},a=>{console.debug(`${i}send: ${m(a)}dB`)},a=>{console.debug(`${i}pan: ${a-64}`)},!1,!1,a=>{console.debug(`${i}delay: ${a}`)},a=>{console.debug(`${i}density: ${a}`)},a=>{console.debug(`${i}balance: ${a}`)},a=>{},a=>{console.debug(`${i}feedback: ${a}`)},a=>{}][t[0]+n]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(r)})):t[0]<64?(i+="chorus ",t.subarray(1).forEach((r,n)=>{([a=>{e.setEffectTypeRaw(1,!1,a),console.info(`${i}main type: ${R[a]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},a=>{e.setEffectTypeRaw(1,!0,a),console.debug(`${i}sub type: ${a+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},a=>{console.debug(`${i}LFO: ${q[a]}Hz`)},a=>{},a=>{console.debug(`${i}feedback: ${a}`)},a=>{console.debug(`${i}delay offset: ${Y(a)}ms`)},a=>{},a=>{console.debug(`${i}low: ${M[a]}Hz`)},a=>{console.debug(`${i}low: ${a-64}dB`)},a=>{console.debug(`${i}high: ${M[a]}Hz`)},a=>{console.debug(`${i}high: ${a-64}dB`)},a=>{console.debug(`${i}dry/wet: ${a}`)},a=>{console.debug(`${i}send: ${m(a)}dB`)},a=>{console.debug(`${i}pan: ${a-64}`)},a=>{console.debug(`${i}to reverb: ${m(a)}dB`)},!1,a=>{},a=>{},a=>{},a=>{console.debug(`${i}LFO phase diff: ${(a-64)*3}deg`)},a=>{console.debug(`${i}input mode: ${a?"stereo":"mono"}`)},a=>{}][t[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(r)})):t[0]<86?(i+="variation ",t.subarray(1).forEach((r,n)=>{([a=>{e.setEffectTypeRaw(2,!1,a),console.info(`${i}main type: ${R[a]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},a=>{e.setEffectTypeRaw(2,!0,a),console.debug(`${i}sub type: ${a+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][t[0]-64+n]||function(){})(r)})):t[0]<97?(i+="variation ",t.subarray(1).forEach((r,n)=>{[a=>{console.debug(`${i}send: ${m(a)}dB`)},a=>{console.debug(`${i}pan: ${a-64}`)},a=>{console.debug(`${i}to reverb: ${m(a)}dB`)},a=>{console.debug(`${i}to chorus: ${m(a)}dB`)},a=>{console.debug(`${i}connection: ${a?"system":"insertion"}`)},a=>{console.debug(`${i}channel: CH${a+1}`)},a=>{console.debug(`${i}mod wheel: ${a-64}`)},a=>{console.debug(`${i}bend wheel: ${a-64}`)},a=>{console.debug(`${i}channel after touch: ${a-64}`)},a=>{console.debug(`${i}AC1: ${a-64}`)},a=>{console.debug(`${i}AC2: ${a-64}`)}][t[0]-86+n](r)})):t[0]>111&&t[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${t[0]}`)}).add([76,2,64],t=>{t.subarray(1).forEach((i,r)=>{let n=r+t[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let a=n-1>>2,l=n-1&3,f=`XG EQ ${a} ${["gain","freq","Q","shape"][l]}: `;[()=>{console.debug(`${f}${i-64}dB`)},()=>{console.debug(`${f}${i} (raw)`)},()=>{console.debug(`${f}${i/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!i]}`)}][l]()}})}).add([76,3],t=>{let i=t[0],r=t[1],n=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((a,l)=>{([f=>{e.setEffectTypeRaw(3+i,!1,f),console.info(`${n}main type: ${R[f]}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))},f=>{e.setEffectTypeRaw(3+i,!0,f),console.debug(`${n}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))}][r+l]||function(){})(a)})}).add([76,6,0],t=>{let i=t[0];i<64?e.setLetterDisplay(t.subarray(1),"XG letter display",i):e.#N=Date.now()}).add([76,7,0],t=>{let i=t[0];e.#b=0,e.#v=Date.now()+3200,e.#p.fill(0);let r=t.subarray(1);for(let n=0;n>6-p&1,p++})}).add([76,8],(t,i)=>{let r=e.chRedir(t[0],i,!0),n=t[1],a=b.cc*r,l=`XG CH${r+1} `,f=`Unknown XG part address ${n}.`;t.subarray(2).forEach((o,u)=>{n<1?console.debug(f):n<41?([()=>{e.#e[a+h[0]]=o},()=>{e.#e[a+h[32]]=o},()=>{e.#r[r]=o},()=>{let p=e.chRedir(o,i,!0);e.#h[r]=p,r!=p&&(e.buildRchTree(),console.info(`${l}receives from CH${p+1}`))},()=>{e.#$[r]=+!o},()=>{},()=>{e.setChType(r,o,y.xg),console.debug(`${l}type: ${D[o]||o}`)},()=>{e.#a[b.rpn*r+3]=o},!1,!1,()=>{e.#e[a+h[7]]=o},!1,!1,()=>{e.#e[a+h[10]]=o||128},!1,!1,()=>{e.#e[a+h[128]]=o},()=>{e.#e[a+h[93]]=o},()=>{e.#e[a+h[91]]=o},()=>{e.#e[a+h[94]]=o},()=>{e.#e[a+h[76]]=o},()=>{e.#e[a+h[77]]=o},()=>{e.#e[a+h[78]]=o},()=>{e.#e[a+h[74]]=o},()=>{e.#e[a+h[71]]=o},()=>{e.#e[a+h[73]]=o},()=>{e.#e[a+h[75]]=o},()=>{e.#e[a+h[72]]=o}][n+u-1]||(()=>{}))():n<48?console.debug(f):n<111?n>102&&n<105&&(e.#e[a+h[[5,65][n&1]]]=o):n<114?console.debug(f):n<116?console.debug(`${l}EQ ${["bass","treble"][n&1]} gain: ${o-64}dB`):n<118?console.debug(f):n<120?console.debug(`${l}EQ ${["bass","treble"][n&1]} freq: ${o}`):console.debug(f)})}).add([76,9],(t,i)=>{let r=e.chRedir(t[0],i,!0),n=t[1],a=`PLG-150VL CH${r+1} `;t.subarray(2).forEach((l,f)=>{let o=f+n;switch(o){case 1:{console.info(`${a}breath mode: ${["system","breath","velocity","touch EG"][l]}`);break}case 0:case 27:case 28:break;default:if(o<27){let u=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][o-3>>1];o&1?o<23?(console.debug(`${a}${u} control source: ${Z(l)}`),l&&l<96&&e.allocateAce(l)):console.debug(`${a}${u} scale break point: ${l}`):console.debug(`${a}${u} depth: ${l-64}`)}}})}).add([76,10],t=>{}).add([76,16],t=>{}).add([76,17,0,0],t=>{}).add([76,112],t=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][t[0]]} for CH${t[2]+1}.`)}).add([73,0,0],(t,i)=>{let r=t[0],n="MU1000 System: ";t.subarray(1).forEach((a,l)=>{let f=r+l;f==8?console.debug(`${n}LCD contrast set to ${a}.`):f==18?(e.#E=a?126:0,console.debug(`${n}bank defaults to ${a?"MU100 Native":"MU Basic"}.`)):f>=64&&f<69&&[()=>{e.dispatchEvent("channelactive",a)},()=>{a<8?(e.dispatchEvent("channelmin",a<<4),console.debug(`Octavia System: Minimum CH${(a<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{a<8?(e.dispatchEvent("channelmax",(a<<4)+15),console.debug(`Octavia System: Maximum CH${(a<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#S=!!a,console.info(`Octavia System: RS receiving ${["dis","en"][a]}abled.`)}][f-64]()})}).add([73,10,0],(t,i)=>{let r=t[0],n=`MU1000 RS${e.#S?"":" (ignored)"}: `;if(r<16)switch(r){case 2:{let a=e.chRedir(0,i,!0);e.#S&&(e.dispatchEvent("channelmin",a),e.dispatchEvent("channelmax",a+63)),console.info(`${n}Show CH1~64`);break}case 3:{let a=e.chRedir(t[1]<<5,i,!0);e.#S&&e.dispatchEvent("channelmin",a),e.#S&&e.dispatchEvent("channelmax",a+31),console.info(`${n}Show CH${a+1}~CH${a+32}`);break}default:console.debug(`${n}unknown switch ${r} invoked.`)}else if(r<32){if(e.#S){let a=e.chRedir(r-16+(e.#J<<4),i,!0);e.dispatchEvent("channelactive",a)}}else if(r<36){let a=e.chRedir(r-32<<4,i,!0);e.#S&&(e.dispatchEvent("channelmin",a),e.dispatchEvent("channelmax",a+15),e.#J=r-32),console.info(`${n}Show CH${a+1}~CH${a+16}`)}}).add([93,3],(t,i)=>{let r=e.chRedir(t[0],i,!0),n=`PLG-100SG CH${r+1} `,a=Date.now();if(t[1]==0){let l="",f=0;t.subarray(2).forEach((o,u)=>{u%2==0?l+=W[o]||o.toString().padStart("0"):f+=o*13}),a>=e.#W&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${J(l)}`,amend:!0}),e.#W=a+Math.ceil(f/2)+e.#Y,w()&&console.debug(`${n}vocals: ${l}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}),this.#m.add([76,48],t=>{}).add([76,49],t=>{}).add([76,50],t=>{}).add([76,51],t=>{}),this.#m.add([89,0],(t,i,r)=>{if(e.eprom){let n=t[0],a=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);w()&&console.debug(`MU1000 EPROM trail to 0x${a.toString(16).padStart(6,"0")}, ${n} bytes.`);let l=e.eprom.data;t.subarray(4).forEach((f,o)=>{let u=o>>3,p=o&7;if(p==7)for(let g=0;g<7;g++)l[a+7*u+g]+=(f>>6-g&1)<<7;else l[a+7*u+p]=f})}}).add([89,1],(t,i,r)=>{let n=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];w()&&console.debug(`MU1000 EPROM jump to 0x${n.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=n)}).add([89,2],(t,i,r)=>{if(e.eprom){let n=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);w()&&console.debug(`MU1000 EPROM write to 0x${n.toString(16).padStart(6,"0")}.`);let a=e.eprom.data;t.subarray(4).forEach((l,f)=>{let o=f>>3,u=f&7;if(u==7)for(let p=0;p<7;p++)a[n+7*o+p]+=(l>>6-p&1)<<7;else a[n+7*o+u]=l})}}).add([89,3],(t,i,r)=>{}),this.#m.add([39,48],(t,i,r)=>{}).add([43,0,0],(t,i,r)=>{let n=[0,0,0,0],a=(l,f)=>{n[f]=l};if(t.subarray(1).forEach((l,f)=>{let o=f+t[0];[a,a,a,a,()=>{this.#i=l*129/16383*100,e.dispatchEvent("mastervolume",e.#i)},()=>l-64,()=>l||128,()=>l,()=>l,()=>{console.debug(`TG300 variation on cc${l}.`)}][o](l,o)}),t[0]<4){let l=0;n.forEach(f=>{l=l<<4,l+=f}),l-=1024}}).add([43,1,0],(t,i,r)=>{}).add([43,2],(t,i,r)=>{let n=e.chRedir(t[0],i,!0),a=t[1],l=b.cc*n,f=`TG300 CH${n+1} `;t.subarray(2).forEach((o,u)=>{u<5?([()=>{},()=>{e.#e[l+h[0]]=o},()=>{e.#e[l+h[32]]=o},()=>{e.#r[n]=o},()=>{let p=e.chRedir(o,i,!0);e.#h[n]=p,n!=p&&(e.buildRchTree(),console.info(`${f}receives from CH${p+1}`))}][u+a]||(()=>{}))(o,u+a):u<21||(u<47?([()=>{e.#$[n]=+!o},()=>{},()=>{},()=>{e.#a[b.rpn*n+3]=o},()=>{},()=>{e.#e[l+h[7]]=o},!1,!1,()=>{e.#e[l+h[10]]=o||128},!1,!1,()=>{console.debug(`${f} AC1 at cc${o}`)},()=>{console.debug(`${f} AC2 at cc${o}`)},()=>{e.#e[l+h[128]]=o},()=>{e.#e[l+h[93]]=o},()=>{e.#e[l+h[91]]=o},()=>{e.#e[l+h[94]]=o},()=>{e.#e[l+h[76]]=o},()=>{e.#e[l+h[77]]=o},()=>{e.#e[l+h[74]]=o},()=>{e.#e[l+h[71]]=o},()=>{e.#e[l+h[73]]=o},()=>{e.#e[l+h[75]]=o},()=>{e.#e[l+h[72]]=o},()=>{e.#e[l+h[78]]=o}][u+a-21]||(()=>{}))(o,u+a):u<95||([()=>{e.#e[l+h[65]]=o},()=>{e.#e[l+h[5]]=o}][u+a-95]||(()=>{}))(o,u+a))})}).add([43,7,0],(t,i,r)=>{let n=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",n)}).add([43,7,1],(t,i,r)=>{e.#b=0,e.#v=Date.now()+3200,e.#p.fill(0),t.forEach(function(n,a){let l=Math.floor(a/16),f=a%16,o=(f*3+l)*7,u=7,p=0;for(o-=f*5,l==2&&(u=2);p>6-p&1,p++})}),this.#w.add([66,18,0,0,127],(t,i,r)=>{e.switchMode("gs",!0),e.#e[b.cc*9]=120,e.#e[b.cc*25]=120,e.#e[b.cc*41]=120,e.#e[b.cc*57]=120,e.#E=3,e.#n=!1,e.#D.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,i,r)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[b.cc*9]=120,e.#e[b.cc*25]=120,e.#e[b.cc*41]=120,e.#e[b.cc*57]=120,e.#n=!1,e.#D.fill(0),console.info("MIDI reset: GS");break}default:{let n=[0,0,0,0],a=(l,f)=>{n[f]=l};if(t.subarray(1).forEach((l,f)=>{let o=f+t[0];[a,a,a,a,u=>{this.#i=u*129/16383*100,e.dispatchEvent("mastervolume",e.#i)},u=>{},u=>{}][o](l,f)}),t[0]<4){let l=0;n.forEach(f=>{l=l<<4,l+=f}),l-=1024}}}}).add([66,18,64,1],t=>{let i=t[0];if(i<16){let r="".padStart(i," ");t.subarray(1).forEach((n,a)=>{r+=String.fromCharCode(Math.max(32,n))}),r=r.padEnd(16," "),console.debug(`GS patch name: ${r}`)}else i<48||(i<65?t.subarray(1).forEach((r,n)=>{let a=`GS ${i+n>55?"chorus":"reverb"} `;([()=>{console.info(`${a}type: ${G[r]}`),e.setEffectType(0,40,r),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${a}predelay: ${r}ms`)},()=>{console.info(`${a}type: ${j[r]}`),e.setEffectType(1,40,16+r),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${a}to reverb: ${m(r)}`)},()=>{console.debug(`${a}to delay: ${m(r)}`)}][i+n-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?t.subarray(1).forEach((r,n)=>{let a="GS delay ";([()=>{console.info(`${a}type: ${ee[r]}`),e.setEffectType(2,40,32+r),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${a}to reverb: ${m(r)}`)}][i+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],t=>{let i="GS EQ ";t.subarray(1).forEach((r,n)=>{([()=>{console.debug(`${i}low freq: ${[200,400][r]}Hz`)},()=>{console.debug(`${i}low gain: ${r-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][r]}Hz`)},()=>{console.debug(`${i}high gain: ${r-64}dB`)}][t[0]+n]||function(){console.warn(`Unknown GS EQ address: ${t[0]+n}`)})()})}).add([66,18,64,3],t=>{let i="GS EFX ",r=function(n,a){let l=te(e.#g.subarray(10,12),a,n);l&&console.debug(`${i}${B(e.#g.subarray(10,12))} ${l}`)};t.subarray(1).forEach((n,a)=>{([()=>{e.setEffectTypeRaw(3,!1,32+n),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,n),console.info(`${i}type: ${B(e.#g.subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,()=>{console.debug(`${i}to reverb: ${m(n)}dB`)},()=>{console.debug(`${i}to chorus: ${m(n)}dB`)},()=>{console.debug(`${i}to delay: ${m(n)}dB`)},!1,()=>{console.debug(`${i}1 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${i}1 depth: ${n-64}`)},()=>{console.debug(`${i}2 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${i}2 depth: ${n-64}`)},()=>{console.debug(`${i}to EQ: ${n?"ON":"OFF"}`)}][t[0]+a]||function(l,f){console.warn(`Unknown GS EFX address: ${f}`)})(n,t[0]+a)})}).add([66,18,65],t=>{}).add([69,18,16],t=>{switch(t[0]){case 0:{let i=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",i);break}case 32:{e.#v=Date.now()+3200,t[1]==0&&(e.#b=Math.max(Math.min(t[2]-1,9),0));break}default:if(t[0]<11){e.#b>9&&(e.#b=0),e.#v=Date.now()+3200,e.#T[t[0]-1]?.length||(e.#T[t[0]-1]=new Uint8Array(256));let i=e.#T[t[0]-1],r=t[1];i.fill(0);let n=t.subarray(2);for(let a=0;a>4-g&1,g++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let c=function(t,i,r){let n=t[0],a=b.cc*i,l=b.rpn*i,f=`GS CH${i+1} `;n<3?t.subarray(1).forEach((o,u)=>{[()=>{e.#e[a+h[0]]=o},()=>{e.#r[i]=o},()=>{let p=e.chRedir(o,r,!0);e.#h[i]=p,i!=p&&(e.buildRchTree(),console.info(`${f}receives from CH${p+1}`))}][n+u]()}):n<19||(n<44?t.subarray(1).forEach((o,u)=>{([()=>{e.#$[i]=+!o},!1,()=>{e.setChType(i,o<<1,y.gs),console.debug(`${f}type: ${o?"drum ":"melodic"}${o||""}`)},()=>{e.#a[l+3]=o},!1,()=>{e.#e[a+h[7]]=o},!1,!1,()=>{e.#e[a+h[10]]=o||128},!1,!1,()=>{console.debug(`${f}CC 1: cc${o}`)},()=>{console.debug(`${f}CC 2: cc${o}`)},()=>{e.#e[a+h[93]]=o},()=>{e.#e[a+h[91]]=o},!1,!1,()=>{e.#a[l+1]=o},()=>{e.#a[l+2]=o},()=>{e.#e[a+h[94]]=o}][n+u-19]||(()=>{}))()}):n<76||console.debug(`Unknown GS part address: ${n}`))},d=function(t,i){let r=t[0],n=`GS CH${i+1} `;r<2?t.subarray(1).forEach((a,l)=>{[()=>{e.#e[b.cc*i+h[32]]=a},()=>{}][r+l]()}):r<32?console.warn(`Unknown GS misc address: ${r}`):r<35?t.subarray(1).forEach((a,l)=>{[()=>{console.debug(`${n}EQ: o${["ff","n"][a]}`)},()=>{},()=>{console.debug(`${n}EFX: o${["ff","n"][a]}`),e.#Q[i]=a}][r+l-32]()}):console.warn(`Unknown GS misc address: ${r}`)};this.#w.add([66,18,64,16],(t,i)=>{c(t,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(t,i)=>{c(t,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(t,i)=>{c(t,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(t,i)=>{c(t,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(t,i)=>{c(t,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(t,i)=>{c(t,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(t,i)=>{c(t,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(t,i)=>{c(t,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(t,i)=>{c(t,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(t,i)=>{c(t,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(t,i)=>{c(t,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(t,i)=>{c(t,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(t,i)=>{c(t,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(t,i)=>{c(t,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(t,i)=>{c(t,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(t,i)=>{c(t,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(t,i)=>{d(t,e.chRedir(9,i,!0))}).add([66,18,64,65],(t,i)=>{d(t,e.chRedir(0,i,!0))}).add([66,18,64,66],(t,i)=>{d(t,e.chRedir(1,i,!0))}).add([66,18,64,67],(t,i)=>{d(t,e.chRedir(2,i,!0))}).add([66,18,64,68],(t,i)=>{d(t,e.chRedir(3,i,!0))}).add([66,18,64,69],(t,i)=>{d(t,e.chRedir(4,i,!0))}).add([66,18,64,70],(t,i)=>{d(t,e.chRedir(5,i,!0))}).add([66,18,64,71],(t,i)=>{d(t,e.chRedir(6,i,!0))}).add([66,18,64,72],(t,i)=>{d(t,e.chRedir(7,i,!0))}).add([66,18,64,73],(t,i)=>{d(t,e.chRedir(8,i,!0))}).add([66,18,64,74],(t,i)=>{d(t,e.chRedir(10,i,!0))}).add([66,18,64,75],(t,i)=>{d(t,e.chRedir(11,i,!0))}).add([66,18,64,76],(t,i)=>{d(t,e.chRedir(12,i,!0))}).add([66,18,64,77],(t,i)=>{d(t,e.chRedir(13,i,!0))}).add([66,18,64,78],(t,i)=>{d(t,e.chRedir(14,i,!0))}).add([66,18,64,79],(t,i)=>{d(t,e.chRedir(15,i,!0))}),this.#O.add([54,65],(t,i)=>{e.switchMode("x5d");let r=(t[1]<<7)+t[0],n=(t[3]<<7)+t[2],a=e.chRedir(r&15,i,!0),l=b.cc*a;[()=>{n<1||(n<101?(e.setChType(a,e.CH_MELODIC,y.x5d),e.#r[a]=n-1,e.#e[l+h[0]]=82):n<229?(e.setChType(a,e.CH_MELODIC,y.x5d),e.#r[a]=n-101,e.#e[l+h[0]]=56):(e.setChType(a,e.CH_DRUMS,y.x5d),e.#r[a]=ne[n-229]||0,e.#e[l+h[0]]=62))},()=>{e.#e[l+h[7]]=n},()=>{n<31&&(e.#e[l+h[10]]=Math.round((n-15)*4.2+64))},()=>{e.#e[l+h[93]]=O(n)},()=>{e.#e[l+h[91]]=O(n)},()=>{e.#a[a*b.rpn+3]=n>8191?n-16320:64+n},()=>{e.#a[a*b.rpn+1]=n>8191?n-16320:64+n},()=>{n>0&&(e.#a[a*b.rpn]=n)},()=>{}][r>>4]()}).add([54,76,0],(t,i)=>{e.switchMode("x5d",!0);let r="",n=82,a=0,l=0,f="MSB PRG LSB NME";S(t,function(o,u){if(u<16400){let p=u%164;switch(!0){case p<10:{o>31&&(r+=String.fromCharCode(o));break}case p==11:{f+=` -${n} ${a} ${l} ${r.trim().replace("Init Voice","")}`,a++,r="";break}}a>99&&(n=90,a=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(f)}).add([54,77,0],(t,i)=>{e.switchMode("x5d",!0);let r="",n=90,a=0,l=0,f="MSB PRG LSB NME";S(t,function(o,u){if(u<13600){let p=u%136;switch(!0){case p<10:{o>31&&(r+=String.fromCharCode(o));break}case p==11:{f+=` -${n} ${a} ${l} ${r.trim().replace("Init Combi","")}`,a++,r="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f)}).add([54,78],(t,i)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][t[0]]} mode.`)}).add([54,85],(t,i)=>{e.switchMode("x5d",!0),S(t,(r,n)=>{n>0&&n<3&&(e.setEffectType(n-1,44,r),e.dispatchEvent(`efx${["reverb","chorus"][n-1]}`,e.getEffectType(n-1)))})}).add([54,104],(t,i)=>{e.switchMode("x5d",!0),S(t,function(r,n,a,l){if(n<192){let f=e.chRedir(Math.floor(n/12),i,!0),o=f*b.cc;switch(n%12){case 0:{r<128?(e.setChType(f,e.CH_MELODIC,y.x5d),e.#e[o+h[0]]=82,e.#r[f]=r):(e.setChType(f,e.CH_DRUMS,y.x5d),e.#e[o+h[0]]=62,e.#r[f]=ne[r-128]),r>0&&(e.#c[f]=1);break}case 1:{e.#e[o+h[7]]=r;break}case 2:{e.#a[f*b.rpn+3]=r>127?r-192:64+r;break}case 3:{e.#a[f*b.rpn+1]=r>127?r-192:64+r;break}case 4:{r<31&&(e.#e[o+h[10]]=Math.round((r-15)*4.2+64));break}case 5:{let u=r>>4,p=r&15;e.#e[o+h[91]]=O(p),e.#e[o+h[93]]=O(u);break}case 10:break;case 11:{let u=e.chRedir(r&15,i,!0),p=r>>4;e.#h[f]=r,(u!=f||p)&&(console.info(`X5D Part CH${f+1} receives from CH${u+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(n-192,i,!0)}})}),this.#w.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#n=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(t,i,r)=>{e.switchMode("mt32");let n=e.chRedir(r,i,!0),a=t[1];t.subarray(2).forEach((l,f)=>{let o=f+a;e.#A[o+(n-1)*16]=l,([!1,()=>{let u=e.#A[n-1<<4];if(u<3)if(e.#x[n]=1,u==2)for(let p=0;p{e.#a[n*b.rpn+3]=l+40},()=>{e.#a[n*b.rpn+1]=l+14},()=>{e.#a[n*b.rpn]=l},!1,()=>{e.#e[b.cc*n+h[91]]=l?127:0},!1,()=>{e.#e[b.cc*n+h[7]]=l},()=>{e.#e[b.cc*n+h[10]]=Math.ceil(l*9.05)}][o]||(()=>{}))()})}).add([22,18,1],(t,i,r)=>{e.switchMode("mt32");let n=e.chRedir(r,i,!0)}).add([22,18,2],(t,i,r)=>{e.switchMode("mt32");let n=e.chRedir(r,i,!0),a=t[1]+(t[0]<<7);a<10&&(e.#x[n]=1),t.subarray(2).forEach((l,f)=>{let o=f+a;o<14&&(e.#k[(n-1)*b.cmt+o]=l)})}).add([22,18,3],(t,i,r)=>{if(e.switchMode("mt32"),t[0]){let n=t[1]-16}else{let n=t[1];t.subarray(2).forEach((a,l)=>{let f=l+n;e.#A[f]=a;let o=e.chRedir(1+f>>4,i,!0),u=f&15;([!1,()=>{let p=e.#A[o-1<<4];if(p<3)if(e.#x[o]=1,p==2)for(let g=0;g{e.#a[o*b.rpn+3]=a+40},()=>{e.#a[o*b.rpn+1]=a+14},()=>{e.#a[o*b.rpn]=a},!1,()=>{e.#e[b.cc*o+h[91]]=a?127:0},!1,()=>{e.#e[b.cc*o+h[7]]=a},()=>{e.#e[b.cc*o+h[10]]=Math.ceil(a*9.05)}][u]||(()=>{}))()})}}).add([22,18,4],(t,i,r)=>{e.switchMode("mt32");let n=t[1]+(t[0]<<7);t.subarray(2).forEach((a,l)=>{let f=l+n,o=e.chRedir(Math.floor(f/246+1),i,!0),u=f%246;u<14&&(e.#k[(o-1)*b.cmt+u]=a),u<10&&(e.#x[o]=1)})}).add([22,18,5],(t,i,r)=>{e.switchMode("mt32");let n=(t[0]<<7)+t[1];t.subarray(2).forEach((a,l)=>{let f=n+l,o=Math.floor(f/8),u=f&7,p=o*8;e.#q[f]=a,([!1,()=>{let g=e.#q[p];if(g<3){let $="";if(g==2){let E=b.cmt*o;$=`MT-m:${a.toString().padStart(3,"0")}`}else $=e.baseBank.get(0,a+(g<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:o}),e.userBank.load(`MSB LSB PRG NME -000 127 ${o} ${$}`,!0)}}][u]||(()=>{}))()})}).add([22,18,8],(t,i,r)=>{e.switchMode("mt32");let n=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((a,l)=>{let f=n+l;f>1)*b.cmt+f]=a)})}).add([22,18,16],(t,i,r)=>{e.switchMode("mt32");let n=t[1],a=!1,l=function(f,o){e.#h[o-12]=f,a=!0};t.subarray(2).forEach((f,o)=>{let u=o+n;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,l,l,l,l,l,l,l,l,l,()=>{e.#i=f,e.dispatchEvent("mastervolume",e.#i)}][u]||(()=>{}))(f,o)}),a&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let i=t[1],r=" ".repeat(i);t.subarray(2).forEach(n=>{n>31&&(r+=String.fromCharCode(n))}),e.#M=r.padStart(20," "),e.#N=Date.now()+3200}).add([22,18,82],(t,i)=>{let r=e.chRedir(0,i,!0);for(let n=0;n<16;n++)e.#f.ano(r+n),n&&n<10&&(e.#r[r+n]=_[n-1]);console.info("MT-32 alt reset complete.")}),this.#O.add([66,0],(t,i)=>{e.switchMode("ns5r",!0),e.#n=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,i)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#n=!1}).add([66,18,0,0],(t,i)=>{let r=t[0];switch(r){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#n=!1;break}case 125:{console.info(`NS5R drum setup reset: ${t}`);break}default:if(r<10){let n=[0,0,0,0],a=(l,f)=>{n[f]=l};if(t.subarray(1).forEach((l,f)=>{[a,a,a,a,()=>{e.#i=l*129/16383*100,e.dispatchEvent("mastervolume",e.#i)},()=>l-64,()=>l-64,()=>{},()=>{},()=>{}][r+f]()}),t[0]<4){let l=0;n.forEach(f=>{l=l<<4,l+=f}),l-=1024}}}}).add([66,18,0,1],(t,i)=>{}).add([66,18,0,2],(t,i)=>{}).add([66,18,1],(t,i)=>{let r=e.chRedir(t[0],i,!0),n=r*b.cc,a=t[1],l=`NS5R CH${r+1} `;t.subarray(2).forEach((f,o)=>{let u=a+o;u<3?[()=>{e.#e[n+h[0]]=f||121},()=>{e.#e[n+h[32]]=f},()=>{e.#r[r]=f}][u]():u<8||(u<14?[()=>{let p=e.chRedir(f,i,!0);e.#h[r]=p,r!=p&&(e.buildRchTree(),console.info(`${l}receives from CH${p+1}`))},()=>{e.#$[r]=+!f},()=>{e.setChType(r,f,y.ns5r),console.debug(`${l}type: ${D[f]}`)},()=>{e.#a[b.rpn*r+3]=f},()=>{},()=>{}][u-8]():u<16||(u<33?[()=>{e.#e[n+h[7]]=f},()=>{e.#e[n+h[11]]=f},()=>{},()=>{},()=>{e.#e[n+h[10]]=f||128},()=>{},()=>{},()=>{e.#e[n+h[93]]=f},()=>{e.#e[n+h[91]]=f},()=>{e.#e[n+h[76]]=f},()=>{e.#e[n+h[77]]=f},()=>{e.#e[n+h[78]]=f},()=>{e.#e[n+h[74]]=f},()=>{e.#e[n+h[71]]=f},()=>{e.#e[n+h[73]]=f},()=>{e.#e[n+h[75]]=f},()=>{e.#e[n+h[72]]=f}][u-16]():u<112||u<114&&[()=>{e.#e[n+h[5]]=f},()=>{e.#e[n+h[65]]=f}][u-112]()))})}).add([66,18,8,0],(t,i)=>{let r=t[0];if(r<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let n=r-32;e.#v=Date.now()+3200,e.#b=10,e.#p.fill(0);let a=t.subarray(1),l=4;a.forEach(function(f,o){let u=o+n,p=u>>4,g=u&15;if(u<80){let $=p>3,E=0,x=p0;)e.#p[g*32+p*7+(x-E)]=$&1,$=$>>1,E++}})}}).add([66,52],(t,i)=>{e.switchMode("ns5r",!0),e.#n=!1;let r="";S(t,(n,a)=>{a<8?(n>31&&(r+=String.fromCharCode(n)),a==7&&(e.aiEfxName=r)):a<10&&(e.setEffectType(a-8,44,n),e.dispatchEvent(`efx${["reverb","chorus"][a-8]}`,e.getEffectType(a-8)))})}).add([66,53],(t,i)=>{e.switchMode("ns5r",!0),e.#n=!1,S(t,function(r,n){switch(!0){case n<2944:{let a=e.chRedir(Math.floor(n/92),i,!0),l=a*b.cc;switch(n%92){case 0:{e.#e[l+h[0]]=r||121;break}case 1:{e.#e[l+h[32]]=r;break}case 2:{e.#r[a]=r,r>0&&(e.#c[a]=1);break}case 3:{let f=e.chRedir(r,i,!0);e.#h[a]=f,a!=f&&(console.info(`NS5R CH${a+1} receives from CH${f+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#a[a*b.rpn+3]=r<40||r>88?r+(r>63?-192:64):r;break}case 9:case 10:{e.#e[l+h[7]]=r;break}case 11:{e.#e[l+h[11]]=r;break}case 14:{e.#e[l+h[10]]=r||128;break}case 19:{e.#e[l+h[93]]=r;break}case 20:{e.#e[l+h[91]]=r;break}case 84:{e.#e[l+h[65]]=r;break}case 85:{e.#e[l+h[5]]=r;break}}break}case n<3096:break;case n<3134:break;case n<8566:break}})}).add([66,54],(t,i)=>{e.switchMode("ns5r",!0);let r="",n=80,a=0,l=0,f="MSB PRG LSB NME";S(t,function(o,u){let p=u%158;switch(!0){case p<10:{o>31&&(r+=String.fromCharCode(o));break}case p==11:{n=o&127;break}case p==12:{l=o&127;break}case p==13:{f+=` -${n} ${a} ${l} ${r.trim().replace("Init Voice","")}`,a++,r="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(f)}).add([66,55],(t,i)=>{e.switchMode("ns5r",!0);let r="",n=88,a=0,l=0,f="MSB PRG LSB NME";S(t,function(o,u){let p=u%126;switch(!0){case p<10:{o>31&&(r+=String.fromCharCode(o));break}case p==11:break;case p==12:break;case p==13:{f+=` -${n} ${a} ${l} ${r.trim().replace("Init Combi","")}`,a++,r="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(f)}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let i=new Uint8Array(5760);S(t,(r,n,a)=>{if(n<720)for(let l=0;l<8;l++)i[n*8+l]=r>>7-l&1}),e.dispatchEvent("screen",{type:"ns5r",data:i})}).add([76],(t,i,r)=>{e.#O.run([66,...t],i,r)}),this.#K.add([16,0,8,0],(t,i,r)=>{let n=(t[2]<<4)+t[3],a="K11 ";([()=>{e.switchMode("k11",!0),e.#n=!1,e.#E=n?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,n),console.debug(`${a}reverb type: ${n}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${a}reverb time: ${n}`)},()=>{console.debug(`${a}reverb time: ${n}`)},()=>{console.debug(`${a}reverb predelay: ${n}`)},()=>{console.debug(`${a}reverb predelay: ${n}`)},()=>{console.debug(`${a}depth high: ${n}`)},()=>{console.debug(`${a}depth high: ${n}`)},()=>{console.debug(`${a}depth low: ${n}`)},()=>{console.debug(`${a}depth low: ${n}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,i,r)=>{let n=e.chRedir(t[1],i,!0),a=b.cc*n,l=b.rpn*n,f=(t[3]<<4)+t[4],o=`K11 CH${n+1} `;([()=>{f<128?(e.setChType(n,e.CH_MELODIC,y.k11),e.#e[a+h[0]]=0,e.#r[n]=f):(e.setChType(n,e.CH_DRUMS,y.k11),e.#r[n]=f-128)},()=>{let u=e.chRedir(f,i,!0);e.#h[n]=u,n!=u&&(e.buildRchTree(),console.info(`${o}receives from CH${u+1}`))},()=>{e.#e[a+h[7]]=f},()=>{e.#c[n]=f},()=>{e.#e[a+h[10]]=f},()=>{e.#a[l+3]=f+40},()=>{e.#a[l+1]=f>>1,e.#a[l+2]=f&1},()=>{e.#e[a+h[91]]=f?127:0},()=>{},()=>{e.#e[a+h[74]]=f},()=>{e.#e[a+h[73]]=f},()=>{e.#e[a+h[72]]=f}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,i,r)=>{let n=(t[2]<<4)+t[3],a="GMLX ";([()=>{console.debug(`${a}reverb type: ${n}`)},()=>{console.debug(`${a}reverb time: ${n}`)},()=>{console.debug(`${a}reverb predelay: ${n}`)},()=>{console.debug(`${a}depth high: ${n}`)},()=>{console.debug(`${a}depth low: ${n}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,i,r)=>{let n=(t[2]<<4)+t[3],a=e.chRedir(t[1],i,!0),l=a*b.cc;[()=>{n<128?(e.setChType(a,e.CH_MELODIC,y.k11),e.#e[l+h[0]]=0,e.#e[l+h[32]]=0,e.#r[a]=n):n<160?(e.setChType(a,e.CH_MELODIC,y.k11),e.#e[l+h[0]]=0,e.#e[l+h[32]]=7,e.#r[a]=n-100):(e.setChType(a,e.CH_DRUMS,y.k11),e.#e[l+h[0]]=122,e.#e[l+h[32]]=0,e.#r[a]=n-160)},()=>{let f=e.chRedir(n,i,!0);e.#h[a]=f,a!=f&&(e.buildRchTree(),console.info(`GMLX CH${a+1} receives from CH${f+1}`))}][t[0]]()}).add([16,0,9,4],(t,i,r)=>{let n=(t[2]<<4)+t[3],a=e.chRedir(t[1],i,!0),l=a*b.cc,f=a*b.rpn,o=`GMLX CH${a+1} `;[()=>{e.#c[a]=n},()=>{e.#e[l+h[7]]=n},()=>{e.#e[l+h[10]]=n},()=>{e.#e[l+h[91]]=n?127:0},()=>{e.#a[f+3]=n+40},()=>{e.#a[f+1]=n},()=>{e.#a[f]=n},()=>{}][t[0]]()}),this.#F.add([66,93,64],(t,i,r)=>{let n=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{e.#i=n*129/16383*100,e.dispatchEvent("mastervolume",e.#i);break}case 5:{n-64;break}case 6:{console.debug(`SG global reverb: ${n?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(t[1]){case 48:{console.debug(`SG reverb type: ${G[n]}`);break}}break}default:if(t[0]>>4==1){let a=e.chRedir(t[0]&15,i,!0);if(t[1]==2){let l=e.chRedir(n,i,!0);e.#h[a]=l,a!=l&&(e.buildRchTree(),console.info(`SG CH${a+1} receives from CH${l+1}`))}else t[1]==19&&(e.#e[b.cc*a+h[7]]=n)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),this.#V.add([9],(t,i,r)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)}),this.#m.add([127,0],(t,i,r)=>{e.switchMode("motif");let n=new Uint8Array([127,1,...t]);e.#m.run(n,i,r)}).add([127,1,0,0],(t,i,r)=>{e.switchMode("s90es");let n="S90/Motif ES system ",a=t[0];t.subarray(1).forEach((l,f)=>{([()=>{e.#i=l*12900/16383,e.dispatchEvent("mastervolume",e.#i)}][a+f]||(()=>{console.info(`Unrecognized ${n}ID: ${a+f}`)}))()})}).add([127,1,0,0,14],(t,i,r)=>{e.switchMode("s90es");let n="S90/Motif ES bulk header ",a=[];a[95]=(l,f,o)=>{console.debug(`${n}multi edit buffer: ${l[1]}`)},(a[t[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,0,15],(t,i,r)=>{e.switchMode("s90es");let n="S90/Motif ES bulk footer ",a=[];a[95]=(l,f,o)=>{console.debug(`${n}multi edit buffer: ${l[1]}`)},(a[t[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,58,55],(t,i,r)=>{e.switchMode("s90es");let n=e.chRedir(t[0],i,!0),a=b.cc*n,l=t[1],f=`S90/Motif ES bulk CH${n<16?n+1:"U"+(n-95)} `;console.debug(f,t),!(t[0]>15)&&t.subarray(2).forEach((o,u)=>{([()=>{e.#e[a+h[0]]=o},()=>{o&&(e.#c[n]=1),e.#e[a+h[32]]=o,e.setChType(n,[32,40].indexOf(o)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0)},()=>{o&&(e.#c[n]=1),e.#r[n]=o},()=>{let p=e.chRedir(o,i,!0);e.#h[n]=p,n!=p&&(e.buildRchTree(),console.info(`${f}receives from CH${p+1}`))},()=>{e.#$[n]=o?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{e.#e[a+h[7]]=o},()=>{e.#e[a+h[10]]=o},!1,!1,!1,()=>{e.#e[a+h[91]]=o},()=>{e.#e[a+h[93]]=o},()=>{e.#e[a+h[94]]=o},()=>{e.#e[a+h[128]]=o},()=>{},()=>{e.#e[a+h[74]]=o},()=>{e.#e[a+h[71]]=o},!1,()=>{e.#e[a+h[65]]=o},()=>{e.#e[a+h[5]]=o},()=>{}][l+u]||(()=>{}))()})}).add([127,1,54,16],(t,i,r)=>{e.switchMode("s90es");let n=t[0];t.subarray(1).forEach((a,l)=>{let o=`S90/Motif ES EQ${(l>>2)+1} `;([()=>{let u=a-64},()=>{let u=M[a]},()=>{let u=a/10},()=>{let u=a}][n+l&3]||(()=>{}))()})}),this.#w.add([0,72,18,0,0,0,0],(t,i,r)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(t,i,r)=>{let n=t[0]>>5,a=t[0]&31;switch(n){case 0:{console.debug(`Unknown SD-90 global effects message: -%o`,t);break}case 1:{let l=e.chRedir(a,i,!0),f=t[1],o=l*b.cc;t.subarray(2).forEach((u,p)=>{let g=f+p;g<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[o+h[0]]=u,u){case 104:case 105:case 106:case 107:case 120:{e.#s[l]||e.setChType(l,e.CH_DRUMS);break}default:e.#s[l]&&e.setChType(l,e.CH_MELODIC)}},()=>{e.#e[o+h[32]]=u},()=>{e.#r[l]=u},()=>{e.#e[o+h[7]]=u},()=>{e.#e[o+h[10]]=u},()=>{},()=>{},()=>{u<2&&(e.#$[l]=u)},()=>{u<2&&(e.#e[o+h[68]]=u?127:0)},()=>{},()=>{u<2&&(e.#e[o+h[65]]=u?127:0)},()=>{e.#e[o+h[5]]=u&15<<4|e.#e[o+h[5]]&15},()=>{e.#e[o+h[5]]=u&15|(e.#e[o+h[5]]&240)>>4},()=>{e.#e[o+h[74]]=u},()=>{e.#e[o+h[71]]=u},()=>{e.#e[o+h[73]]=u},()=>{e.#e[o+h[72]]=u},0,0,0,0,0,0,0,()=>{e.#e[o+h[128]]=u},()=>{e.#e[o+h[93]]=u},()=>{e.#e[o+h[91]]=u},0,0,()=>{e.#e[o+h[75]]=u},()=>{e.#e[o+h[76]]=u},()=>{e.#e[o+h[77]]=u},()=>{e.#e[o+h[78]]=u}][g]||(()=>{}))():g<63||(g<64?e.#s[l]?e.#e[o+h[0]]=104|u:e.#e[o+h[0]]=96|u:console.debug(`Unknown SD-90 global CH${l+1} param setup message: -%o`,t))});break}case 2:{let l=e.chRedir(a,i,!0),f=t[1];console.debug(`Unknown SD-90 global CH${l+1} MIDI setup message: +`),t.slice(0,2)){case"@I":{this.#c=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:t.slice(2)?.trimLeft()});break}case"@K":{this.#c=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:t.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#c=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:t.slice(2)?.trimLeft()});break}case"@T":{this.#c=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:t.slice(2)?.trimLeft()});break}case"@V":{this.#c=!0,this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:t.slice(2)?.trimLeft()});break}case"XF":{let s=t.slice(2).split(":");switch(s[0]){case"hd":{s.slice(1).forEach((c,i)=>{c.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][i],data:c})});break}case"ln":{s.slice(1).forEach((c,i)=>{c.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][i],data:c})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:t})}break}default:this.#c?t[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:t.slice(1),amend:!0})):t[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:t.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:t,amend:!0}):t.split(` +`).forEach((s,c)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:s,mask:c!=0})})}},this.#h[2]=function(t){this.dispatchEvent("metacommit",{type:"Copyrite",data:t})},this.#h[3]=function(t,s){s<1&&this.#_<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:t})},this.#h[4]=function(t,s){this.dispatchEvent("metacommit",{type:"Instrmnt",data:t})},this.#h[5]=function(t){t.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:t,amend:!0})},this.#h[6]=function(t){this.dispatchEvent("metacommit",{type:"C.Marker",data:t})},this.#h[7]=function(t){this.dispatchEvent("metacommit",{type:"CuePoint",data:t})},this.#h[32]=function(t){this.#_=t[0]+1},this.#h[33]=function(t,s){e.#G[s]=t+1},this.#h[81]=function(t,s){e.#W=t/1e3},this.#h[127]=function(t,s){e.#I.run(t,s)},this.#I.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#I.add([67,0,1],function(t,s){e.#G[s]=t[0]+1}),this.#X=new x("universal non-realtime"),this.#V=new x("universal realtime"),this.#m=new x("Yamaha"),this.#k=new x("Roland"),this.#O=new x("Korg"),this.#K=new x("Kawai"),this.#F=new x("Akai"),this.#z=new x("Casio");let a=function(t){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,t)};this.#X.default=a,this.#V.default=a,this.#m.default=a,this.#k.default=a,this.#O.default=a,this.#K.default=a,this.#F.default=a,this.#z.default=a,this.#X.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#c=e.#c||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#V.add([4,1],t=>{e.#i=((t[1]<<7)+t[0])/16383*100,e.dispatchEvent("mastervolume",e.#i)}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#m.add([76,0,0],t=>{switch(t[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${t}`);break}case 126:{e.switchMode("xg",!0),e.#c=!1,console.info("MIDI reset: XG");break}default:{let s=[0,0,0,0],c=(i,r)=>{s[r]=i};if(t.subarray(1).forEach((i,r)=>{let n=r+t[0];([c,c,c,c,d=>{this.#i=d*129/16383*100,e.dispatchEvent("mastervolume",e.#i)},d=>{},d=>{}][n]||(()=>{}))(i,r)}),t[0]<4){let i=0;s.forEach(r=>{i=i<<4,i+=r}),i-=1024}}}}).add([76,2,1],t=>{let s="XG ";t[0]<32?(s+="reverb ",t.subarray(1).forEach((c,i)=>{([r=>{e.setEffectTypeRaw(0,!1,r),console.info(`${s}main type: ${U[r]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},r=>{e.setEffectTypeRaw(0,!0,r),console.debug(`${s}sub type: ${r+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},r=>{console.debug(`${s}time: ${J(r)}s`)},r=>{console.debug(`${s}diffusion: ${r}`)},r=>{console.debug(`${s}initial delay: ${r}`)},r=>{console.debug(`${s}HPF cutoff: ${D[r]}Hz`)},r=>{console.debug(`${s}LPF cutoff: ${D[r]}Hz`)},r=>{console.debug(`${s}width: ${r}`)},r=>{console.debug(`${s}height: ${r}`)},r=>{console.debug(`${s}depth: ${r}`)},r=>{console.debug(`${s}wall type: ${r}`)},r=>{console.debug(`${s}dry/wet: ${r}`)},r=>{console.debug(`${s}send: ${S(r)}dB`)},r=>{console.debug(`${s}pan: ${r-64}`)},!1,!1,r=>{console.debug(`${s}delay: ${r}`)},r=>{console.debug(`${s}density: ${r}`)},r=>{console.debug(`${s}balance: ${r}`)},r=>{},r=>{console.debug(`${s}feedback: ${r}`)},r=>{}][t[0]+i]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(c)})):t[0]<64?(s+="chorus ",t.subarray(1).forEach((c,i)=>{([r=>{e.setEffectTypeRaw(1,!1,r),console.info(`${s}main type: ${U[r]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},r=>{e.setEffectTypeRaw(1,!0,r),console.debug(`${s}sub type: ${r+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},r=>{console.debug(`${s}LFO: ${W[r]}Hz`)},r=>{},r=>{console.debug(`${s}feedback: ${r}`)},r=>{console.debug(`${s}delay offset: ${Z(r)}ms`)},r=>{},r=>{console.debug(`${s}low: ${D[r]}Hz`)},r=>{console.debug(`${s}low: ${r-64}dB`)},r=>{console.debug(`${s}high: ${D[r]}Hz`)},r=>{console.debug(`${s}high: ${r-64}dB`)},r=>{console.debug(`${s}dry/wet: ${r}`)},r=>{console.debug(`${s}send: ${S(r)}dB`)},r=>{console.debug(`${s}pan: ${r-64}`)},r=>{console.debug(`${s}to reverb: ${S(r)}dB`)},!1,r=>{},r=>{},r=>{},r=>{console.debug(`${s}LFO phase diff: ${(r-64)*3}deg`)},r=>{console.debug(`${s}input mode: ${r?"stereo":"mono"}`)},r=>{}][t[0]-32+i]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(c)})):t[0]<86?(s+="variation ",t.subarray(1).forEach((c,i)=>{([r=>{e.setEffectTypeRaw(2,!1,r),console.info(`${s}main type: ${U[r]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},r=>{e.setEffectTypeRaw(2,!0,r),console.debug(`${s}sub type: ${r+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][t[0]-64+i]||function(){})(c)})):t[0]<97?(s+="variation ",t.subarray(1).forEach((c,i)=>{[r=>{console.debug(`${s}send: ${S(r)}dB`)},r=>{console.debug(`${s}pan: ${r-64}`)},r=>{console.debug(`${s}to reverb: ${S(r)}dB`)},r=>{console.debug(`${s}to chorus: ${S(r)}dB`)},r=>{console.debug(`${s}connection: ${r?"system":"insertion"}`)},r=>{console.debug(`${s}channel: CH${r+1}`)},r=>{console.debug(`${s}mod wheel: ${r-64}`)},r=>{console.debug(`${s}bend wheel: ${r-64}`)},r=>{console.debug(`${s}channel after touch: ${r-64}`)},r=>{console.debug(`${s}AC1: ${r-64}`)},r=>{console.debug(`${s}AC2: ${r-64}`)}][t[0]-86+i](c)})):t[0]>111&&t[0]<118?s+="variation ":console.warn(`Unknown XG variation address: ${t[0]}`)}).add([76,2,64],t=>{t.subarray(1).forEach((s,c)=>{let i=c+t[0];if(i==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][s]}`);else{let r=i-1>>2,n=i-1&3,d=`XG EQ ${r} ${["gain","freq","Q","shape"][n]}: `;[()=>{console.debug(`${d}${s-64}dB`)},()=>{console.debug(`${d}${s} (raw)`)},()=>{console.debug(`${d}${s/10}`)},()=>{console.debug(`${d}${["shelf","peak"][+!!s]}`)}][n]()}})}).add([76,3],t=>{let s=t[0],c=t[1],i=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((r,n)=>{([d=>{e.setEffectTypeRaw(3+s,!1,d),console.info(`${i}main type: ${U[d]}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))},d=>{e.setEffectTypeRaw(3+s,!0,d),console.debug(`${i}sub type: ${d+1}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))}][c+n]||function(){})(r)})}).add([76,6,0],t=>{let s=t[0];s<64?e.setLetterDisplay(t.subarray(1),"XG letter display",s):e.#L=Date.now()}).add([76,7,0],t=>{let s=t[0];e.#u=0,e.#S=Date.now()+3200,e.#b.fill(0);let c=t.subarray(1);for(let i=0;i>6-$&1,$++})}).add([76,8],(t,s)=>{let c=e.chRedir(t[0],s,!0),i=t[1],r=b.cc*c,n=`XG CH${c+1} `,d=`Unknown XG part address ${i}.`;t.subarray(2).forEach((l,p)=>{i<1?console.debug(d):i<41?([()=>{e.#e[r+u[0]]=l,e.dispatchEvent("voice",{part:c})},()=>{e.#e[r+u[32]]=l,e.dispatchEvent("voice",{part:c})},()=>{e.#r[c]=l,e.dispatchEvent("voice",{part:c})},()=>{let $=e.chRedir(l,s,!0);e.#d[c]=$,c!=$&&(e.buildRchTree(),console.info(`${n}receives from CH${$+1}`))},()=>{e.#g[c]=+!l},()=>{},()=>{e.setChType(c,l,m.xg),console.debug(`${n}type: ${A[l]||l}`)},()=>{e.#a[b.rpn*c+3]=l},!1,!1,()=>{e.#e[r+u[7]]=l},!1,!1,()=>{e.#e[r+u[10]]=l||128},!1,!1,()=>{e.#e[r+u[128]]=l},()=>{e.#e[r+u[93]]=l},()=>{e.#e[r+u[91]]=l},()=>{e.#e[r+u[94]]=l},()=>{e.#e[r+u[76]]=l},()=>{e.#e[r+u[77]]=l},()=>{e.#e[r+u[78]]=l},()=>{e.#e[r+u[74]]=l},()=>{e.#e[r+u[71]]=l},()=>{e.#e[r+u[73]]=l},()=>{e.#e[r+u[75]]=l},()=>{e.#e[r+u[72]]=l}][i+p-1]||(()=>{}))():i<48?console.debug(d):i<111?i>102&&i<105&&(e.#e[r+u[[5,65][i&1]]]=l):i<114?console.debug(d):i<116?console.debug(`${n}EQ ${["bass","treble"][i&1]} gain: ${l-64}dB`):i<118?console.debug(d):i<120?console.debug(`${n}EQ ${["bass","treble"][i&1]} freq: ${l}`):console.debug(d)})}).add([76,9],(t,s)=>{let c=e.chRedir(t[0],s,!0),i=t[1],r=`PLG-150VL CH${c+1} `;t.subarray(2).forEach((n,d)=>{let l=d+i;switch(l){case 1:{console.info(`${r}breath mode: ${["system","breath","velocity","touch EG"][n]}`);break}case 0:case 27:case 28:break;default:if(l<27){let p=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${r}${p} control source: ${te(n)}`),n&&n<96&&e.allocateAce(n)):console.debug(`${r}${p} scale break point: ${n}`):console.debug(`${r}${p} depth: ${n-64}`)}}})}).add([76,10],t=>{}).add([76,16],t=>{}).add([76,17,0,0],t=>{}).add([76,112],t=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][t[0]]} for CH${t[2]+1}.`)}).add([73,0,0],(t,s)=>{let c=t[0],i="MU1000 System: ";t.subarray(1).forEach((r,n)=>{let d=c+n;d==8?console.debug(`${i}LCD contrast set to ${r}.`):d==18?(e.#E=r?126:0,console.debug(`${i}bank defaults to ${r?"MU100 Native":"MU Basic"}.`)):d>=64&&d<69&&[()=>{e.dispatchEvent("channelactive",r)},()=>{r<8?(e.dispatchEvent("channelmin",r<<4),console.debug(`Octavia System: Minimum CH${(r<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{r<8?(e.dispatchEvent("channelmax",(r<<4)+15),console.debug(`Octavia System: Maximum CH${(r<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#w=!!r,console.info(`Octavia System: RS receiving ${["dis","en"][r]}abled.`)}][d-64]()})}).add([73,10,0],(t,s)=>{let c=t[0],i=`MU1000 RS${e.#w?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let r=e.chRedir(0,s,!0);e.#w&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+63)),console.info(`${i}Show CH1~64`);break}case 3:{let r=e.chRedir(t[1]<<5,s,!0);e.#w&&e.dispatchEvent("channelmin",r),e.#w&&e.dispatchEvent("channelmax",r+31),console.info(`${i}Show CH${r+1}~CH${r+32}`);break}default:console.debug(`${i}unknown switch ${c} invoked.`)}else if(c<32){if(e.#w){let r=e.chRedir(c-16+(e.#Z<<4),s,!0);e.dispatchEvent("channelactive",r)}}else if(c<36){let r=e.chRedir(c-32<<4,s,!0);e.#w&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+15),e.#Z=c-32),console.info(`${i}Show CH${r+1}~CH${r+16}`)}}).add([93,3],(t,s)=>{let c=e.chRedir(t[0],s,!0),i=`PLG-100SG CH${c+1} `,r=Date.now();if(t[1]==0){let n="",d=0;t.subarray(2).forEach((l,p)=>{p%2==0?n+=j[l]||l.toString().padStart("0"):d+=l*13}),r>=e.#J&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${ee(n)}`,amend:!0}),e.#J=r+Math.ceil(d/2)+e.#W,k()&&console.debug(`${i}vocals: ${n}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)});let o=function(t,s,c,i){},h=function(t,s){let c=t*b.dpn,i=s[0],r=s[1];s.subarray(2).forEach((n,d)=>{let l=d+r,p=-1;l<16?([()=>{p=24},()=>{p=25},()=>{p=26},()=>{},()=>{p=28},()=>{p=29},()=>{p=30},()=>{p=31},()=>{},()=>{},()=>{},()=>{p=20},()=>{p=21},()=>{p=22},()=>{p=23},()=>{}][l]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${t+1}.`)}))():l<32||(l<40?([()=>{p=48},()=>{p=49},!1,!1,()=>{p=52},()=>{p=53}][l-32]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${t+1}.`)}))():l<80||([()=>{p=36}][l-80]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${t+1}.`)}))()),p>=0?(k()&&console.debug(c,p,i,n),e.#p[(c+C[p])*b.dnc+i]=n):k()&&console.debug(`XG-style drum param ${l} has no writes.`)})},y=function(t,s,c){let i=t*b.dpn,r=(s<<7)+c[0];c.subarray(1).forEach((n,d)=>{let l=d+r,p=l&127,$=l>>7,E=-1;$>1&&([()=>{E=26},()=>{},()=>{E=28},()=>{E=29},()=>{E=30},()=>{},()=>{},()=>{E=31}][$-2]||(()=>{console.debug(`Unknown GS-style drum param ${$} on set ${t+1}.`)}))(),E>-1?(k()&&console.debug(i,E,p,n),e.#p[(i+C[E])*b.dnc+p]=n):k()&&console.debug(`GS-style drum param ${$} has no writes.`)})};this.#m.add([76,48],(t,s,c)=>{h(0,t)}).add([76,49],(t,s,c)=>{h(1,t)}).add([76,50],(t,s,c)=>{h(2,t)}).add([76,51],(t,s,c)=>{h(3,t)}).add([76,52],(t,s,c)=>{h(4,t)}).add([76,53],(t,s,c)=>{h(5,t)}).add([76,54],(t,s,c)=>{h(6,t)}).add([76,55],(t,s,c)=>{h(7,t)}),this.#m.add([89,0],(t,s,c)=>{if(e.eprom){let i=t[0],r=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);k()&&console.debug(`MU1000 EPROM trail to 0x${r.toString(16).padStart(6,"0")}, ${i} bytes.`);let n=e.eprom.data;t.subarray(4).forEach((d,l)=>{let p=l>>3,$=l&7;if($==7)for(let E=0;E<7;E++)n[r+7*p+E]+=(d>>6-E&1)<<7;else n[r+7*p+$]=d})}}).add([89,1],(t,s,c)=>{let i=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];k()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(t,s,c)=>{if(e.eprom){let i=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);k()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let r=e.eprom.data;t.subarray(4).forEach((n,d)=>{let l=d>>3,p=d&7;if(p==7)for(let $=0;$<7;$++)r[i+7*l+$]+=(n>>6-$&1)<<7;else r[i+7*l+p]=n})}}).add([89,3],(t,s,c)=>{}),this.#m.add([39,48],(t,s,c)=>{}).add([43,0,0],(t,s,c)=>{let i=[0,0,0,0],r=(n,d)=>{i[d]=n};if(t.subarray(1).forEach((n,d)=>{let l=d+t[0];[r,r,r,r,()=>{this.#i=n*129/16383*100,e.dispatchEvent("mastervolume",e.#i)},()=>n-64,()=>n||128,()=>n,()=>n,()=>{console.debug(`TG300 variation on cc${n}.`)}][l](n,l)}),t[0]<4){let n=0;i.forEach(d=>{n=n<<4,n+=d}),n-=1024}}).add([43,1,0],(t,s,c)=>{}).add([43,2],(t,s,c)=>{let i=e.chRedir(t[0],s,!0),r=t[1],n=b.cc*i,d=`TG300 CH${i+1} `;t.subarray(2).forEach((l,p)=>{p<5?([()=>{},()=>{e.#e[n+u[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{e.#e[n+u[32]]=l,e.dispatchEvent("voice",{part:i})},()=>{e.#r[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(l,s,!0);e.#d[i]=$,i!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))}][p+r]||(()=>{}))(l,p+r):p<21||(p<47?([()=>{e.#g[i]=+!l},()=>{},()=>{},()=>{e.#a[b.rpn*i+3]=l},()=>{},()=>{e.#e[n+u[7]]=l},!1,!1,()=>{e.#e[n+u[10]]=l||128},!1,!1,()=>{console.debug(`${d} AC1 at cc${l}`)},()=>{console.debug(`${d} AC2 at cc${l}`)},()=>{e.#e[n+u[128]]=l},()=>{e.#e[n+u[93]]=l},()=>{e.#e[n+u[91]]=l},()=>{e.#e[n+u[94]]=l},()=>{e.#e[n+u[76]]=l},()=>{e.#e[n+u[77]]=l},()=>{e.#e[n+u[74]]=l},()=>{e.#e[n+u[71]]=l},()=>{e.#e[n+u[73]]=l},()=>{e.#e[n+u[75]]=l},()=>{e.#e[n+u[72]]=l},()=>{e.#e[n+u[78]]=l}][p+r-21]||(()=>{}))(l,p+r):p<95||([()=>{e.#e[n+u[65]]=l},()=>{e.#e[n+u[5]]=l}][p+r-95]||(()=>{}))(l,p+r))})}).add([43,7,0],(t,s,c)=>{let i=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",i)}).add([43,7,1],(t,s,c)=>{e.#u=0,e.#S=Date.now()+3200,e.#b.fill(0),t.forEach(function(i,r){let n=Math.floor(r/16),d=r%16,l=(d*3+n)*7,p=7,$=0;for(l-=d*5,n==2&&(p=2);$>6-$&1,$++})}),this.#k.add([66,18,0,0,127],(t,s,c)=>{e.switchMode("gs",!0),e.#e[b.cc*9]=120,e.#e[b.cc*25]=120,e.#e[b.cc*41]=120,e.#e[b.cc*57]=120,e.#E=3,e.#c=!1,e.#D.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,s,c)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[b.cc*9]=120,e.#e[b.cc*25]=120,e.#e[b.cc*41]=120,e.#e[b.cc*57]=120,e.#c=!1,e.#D.fill(0),console.info("MIDI reset: GS");break}default:{let i=[0,0,0,0],r=(n,d)=>{i[d]=n};if(t.subarray(1).forEach((n,d)=>{let l=d+t[0];[r,r,r,r,p=>{this.#i=p*129/16383*100,e.dispatchEvent("mastervolume",e.#i)},p=>{},p=>{}][l](n,d)}),t[0]<4){let n=0;i.forEach(d=>{n=n<<4,n+=d}),n-=1024}}}}).add([66,18,64,1],t=>{let s=t[0];if(s<16){let c="".padStart(s," ");t.subarray(1).forEach((i,r)=>{c+=String.fromCharCode(Math.max(32,i))}),c=c.padEnd(16," "),console.debug(`GS patch name: ${c}`)}else s<48||(s<65?t.subarray(1).forEach((c,i)=>{let r=`GS ${s+i>55?"chorus":"reverb"} `;([()=>{console.info(`${r}type: ${I[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${r}predelay: ${c}ms`)},()=>{console.info(`${r}type: ${ae[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${S(c)}`)},()=>{console.debug(`${r}to delay: ${S(c)}`)}][s+i-48]||(()=>{}))()}):s<80?console.debug(`Unknown GS patch address: ${s}`):s<91?t.subarray(1).forEach((c,i)=>{let r="GS delay ";([()=>{console.info(`${r}type: ${se[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${S(c)}`)}][s+i-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${s}`))}).add([66,18,64,2],t=>{let s="GS EQ ";t.subarray(1).forEach((c,i)=>{([()=>{console.debug(`${s}low freq: ${[200,400][c]}Hz`)},()=>{console.debug(`${s}low gain: ${c-64}dB`)},()=>{console.debug(`${s}high freq: ${[3e3,6e3][c]}Hz`)},()=>{console.debug(`${s}high gain: ${c-64}dB`)}][t[0]+i]||function(){console.warn(`Unknown GS EQ address: ${t[0]+i}`)})()})}).add([66,18,64,3],t=>{let s="GS EFX ",c=function(i,r){let n=re(e.#y.subarray(10,12),r,i);n&&console.debug(`${s}${X(e.#y.subarray(10,12))} ${n}`)};t.subarray(1).forEach((i,r)=>{([()=>{e.setEffectTypeRaw(3,!1,32+i),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,i),console.info(`${s}type: ${X(e.#y.subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,()=>{console.debug(`${s}to reverb: ${S(i)}dB`)},()=>{console.debug(`${s}to chorus: ${S(i)}dB`)},()=>{console.debug(`${s}to delay: ${S(i)}dB`)},!1,()=>{console.debug(`${s}1 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${s}1 depth: ${i-64}`)},()=>{console.debug(`${s}2 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${s}2 depth: ${i-64}`)},()=>{console.debug(`${s}to EQ: ${i?"ON":"OFF"}`)}][t[0]+r]||function(n,d){console.warn(`Unknown GS EFX address: ${d}`)})(i,t[0]+r)})}).add([66,18,65],t=>{y((t[0]>>4)+1<<1,t[0]&15,t.subarray(1))}).add([69,18,16],t=>{switch(t[0]){case 0:{let s=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",s);break}case 32:{e.#S=Date.now()+3200,t[1]==0&&(e.#u=Math.max(Math.min(t[2]-1,9),0),k()&&console.debug(`GS switch display page ${t[2]-1}.`));break}default:if(t[0]<6){e.#u>9&&(e.#u=0);let s=t[0]-1<<1|t[1]>>6;e.#u==s&&(e.#S=Date.now()+3200),e.#M[s]?.length||(e.#M[s]=new Uint8Array(256));let c=e.#M[s];k()&&console.debug(`GS frame draw page ${s}.`);let i=t[1]&63;c.fill(0),t.subarray(2).forEach(function(n,d){let l=d+i,p=Math.floor(l/16),$=l%16,E=($*4+p)*5,v=5,w=0;for(E-=$*4,p==3&&(v=1);w>4-w&1,w++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let g=function(t,s,c){let i=t[0],r=b.cc*s,n=b.rpn*s,d=`GS CH${s+1} `;i<3?(t.subarray(1).forEach((l,p)=>{[()=>{e.#e[r+u[0]]=l},()=>{e.#r[s]=l},()=>{let $=e.chRedir(l,c,!0);e.#d[s]=$,s!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))}][i+p]()}),e.dispatchEvent("voice",{part:s})):i<19||(i<44?t.subarray(1).forEach((l,p)=>{([()=>{e.#g[s]=+!l},!1,()=>{e.setChType(s,l<<1,m.gs),console.debug(`${d}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{e.#a[n+3]=l},!1,()=>{e.#e[r+u[7]]=l},!1,!1,()=>{e.#e[r+u[10]]=l||128},!1,!1,()=>{console.debug(`${d}CC 1: cc${l}`)},()=>{console.debug(`${d}CC 2: cc${l}`)},()=>{e.#e[r+u[93]]=l},()=>{e.#e[r+u[91]]=l},!1,!1,()=>{e.#a[n+1]=l},()=>{e.#a[n+2]=l},()=>{e.#e[r+u[94]]=l}][i+p-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},f=function(t,s){let c=t[0],i=`GS CH${s+1} `;c<2?t.subarray(1).forEach((r,n)=>{[()=>{e.#e[b.cc*s+u[32]]=r},()=>{}][c+n]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?t.subarray(1).forEach((r,n)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][r]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][r]}`),e.#Y[s]=r,e.dispatchEvent("partefxtoggle",{part:s,active:r})}][c+n-32]()}):console.warn(`Unknown GS misc address: ${c}`)};this.#k.add([66,18,64,16],(t,s)=>{g(t,e.chRedir(9,s,!0),s)}).add([66,18,64,17],(t,s)=>{g(t,e.chRedir(0,s,!0),s)}).add([66,18,64,18],(t,s)=>{g(t,e.chRedir(1,s,!0),s)}).add([66,18,64,19],(t,s)=>{g(t,e.chRedir(2,s,!0),s)}).add([66,18,64,20],(t,s)=>{g(t,e.chRedir(3,s,!0),s)}).add([66,18,64,21],(t,s)=>{g(t,e.chRedir(4,s,!0),s)}).add([66,18,64,22],(t,s)=>{g(t,e.chRedir(5,s,!0),s)}).add([66,18,64,23],(t,s)=>{g(t,e.chRedir(6,s,!0),s)}).add([66,18,64,24],(t,s)=>{g(t,e.chRedir(7,s,!0),s)}).add([66,18,64,25],(t,s)=>{g(t,e.chRedir(8,s,!0),s)}).add([66,18,64,26],(t,s)=>{g(t,e.chRedir(10,s,!0),s)}).add([66,18,64,27],(t,s)=>{g(t,e.chRedir(11,s,!0),s)}).add([66,18,64,28],(t,s)=>{g(t,e.chRedir(12,s,!0),s)}).add([66,18,64,29],(t,s)=>{g(t,e.chRedir(13,s,!0),s)}).add([66,18,64,30],(t,s)=>{g(t,e.chRedir(14,s,!0),s)}).add([66,18,64,31],(t,s)=>{g(t,e.chRedir(15,s,!0),s)}).add([66,18,64,64],(t,s)=>{f(t,e.chRedir(9,s,!0))}).add([66,18,64,65],(t,s)=>{f(t,e.chRedir(0,s,!0))}).add([66,18,64,66],(t,s)=>{f(t,e.chRedir(1,s,!0))}).add([66,18,64,67],(t,s)=>{f(t,e.chRedir(2,s,!0))}).add([66,18,64,68],(t,s)=>{f(t,e.chRedir(3,s,!0))}).add([66,18,64,69],(t,s)=>{f(t,e.chRedir(4,s,!0))}).add([66,18,64,70],(t,s)=>{f(t,e.chRedir(5,s,!0))}).add([66,18,64,71],(t,s)=>{f(t,e.chRedir(6,s,!0))}).add([66,18,64,72],(t,s)=>{f(t,e.chRedir(7,s,!0))}).add([66,18,64,73],(t,s)=>{f(t,e.chRedir(8,s,!0))}).add([66,18,64,74],(t,s)=>{f(t,e.chRedir(10,s,!0))}).add([66,18,64,75],(t,s)=>{f(t,e.chRedir(11,s,!0))}).add([66,18,64,76],(t,s)=>{f(t,e.chRedir(12,s,!0))}).add([66,18,64,77],(t,s)=>{f(t,e.chRedir(13,s,!0))}).add([66,18,64,78],(t,s)=>{f(t,e.chRedir(14,s,!0))}).add([66,18,64,79],(t,s)=>{f(t,e.chRedir(15,s,!0))}),this.#O.add([54,65],(t,s)=>{e.switchMode("x5d");let c=(t[1]<<7)+t[0],i=(t[3]<<7)+t[2],r=e.chRedir(c&15,s,!0),n=b.cc*r;[()=>{i<1||(i<101?(e.setChType(r,e.CH_MELODIC,m.x5d),e.#r[r]=i-1,e.#e[n+u[0]]=82):i<229?(e.setChType(r,e.CH_MELODIC,m.x5d),e.#r[r]=i-101,e.#e[n+u[0]]=56):(e.setChType(r,e.CH_DRUMS,m.x5d),e.#r[r]=de[i-229]||0,e.#e[n+u[0]]=62)),e.dispatchEvent("voice",{part:r})},()=>{e.#e[n+u[7]]=i},()=>{i<31&&(e.#e[n+u[10]]=Math.round((i-15)*4.2+64))},()=>{e.#e[n+u[93]]=P(i)},()=>{e.#e[n+u[91]]=P(i)},()=>{e.#a[r*b.rpn+3]=i>8191?i-16320:64+i},()=>{e.#a[r*b.rpn+1]=i>8191?i-16320:64+i},()=>{i>0&&(e.#a[r*b.rpn]=i)},()=>{}][c>>4]()}).add([54,76,0],(t,s)=>{e.switchMode("x5d",!0);let c="",i=82,r=0,n=0,d="MSB PRG LSB NME";M(t,function(l,p){if(p<16400){let $=p%164;switch(!0){case $<10:{l>31&&(c+=String.fromCharCode(l));break}case $==11:{d+=` +${i} ${r} ${n} ${c.trim().replace("Init Voice","")}`,r++,c="";break}}r>99&&(i=90,r=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(d),k()&&console.debug(d),e.forceVoiceRefresh()}).add([54,77,0],(t,s)=>{e.switchMode("x5d",!0);let c="",i=90,r=0,n=0,d="MSB PRG LSB NME";M(t,function(l,p){if(p<13600){let $=p%136;switch(!0){case $<10:{l>31&&(c+=String.fromCharCode(l));break}case $==11:{d+=` +${i} ${r} ${n} ${c.trim().replace("Init Combi","")}`,r++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(d),k()&&console.debug(d),e.forceVoiceRefresh()}).add([54,78],(t,s)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][t[0]]} mode.`)}).add([54,85],(t,s)=>{e.switchMode("x5d",!0),M(t,(c,i)=>{i>0&&i<3&&(e.setEffectType(i-1,44,c),e.dispatchEvent(`efx${["reverb","chorus"][i-1]}`,e.getEffectType(i-1)))})}).add([54,104],(t,s)=>{e.switchMode("x5d",!0),M(t,function(c,i,r,n){if(i<192){let d=e.chRedir(Math.floor(i/12),s,!0),l=d*b.cc;switch(i%12){case 0:{c<128?(e.setChType(d,e.CH_MELODIC,m.x5d),e.#e[l+u[0]]=82,e.#r[d]=c):(e.setChType(d,e.CH_DRUMS,m.x5d),e.#e[l+u[0]]=62,e.#r[d]=de[c-128]),c>0&&e.setChActive(d,1),e.dispatchEvent("voice",{part:d});break}case 1:{e.#e[l+u[7]]=c;break}case 2:{e.#a[d*b.rpn+3]=c>127?c-192:64+c;break}case 3:{e.#a[d*b.rpn+1]=c>127?c-192:64+c;break}case 4:{c<31&&(e.#e[l+u[10]]=Math.round((c-15)*4.2+64));break}case 5:{let p=c>>4,$=c&15;e.#e[l+u[91]]=P($),e.#e[l+u[93]]=P(p);break}case 10:break;case 11:{let p=e.chRedir(c&15,s,!0),$=c>>4;e.#d[d]=c,(p!=d||$)&&(console.info(`X5D Part CH${d+1} receives from CH${p+1}.`),e.buildRchTree())}}}else{let d=e.chRedir(i-192,s,!0)}})}),this.#k.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#c=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(t,s,c)=>{e.switchMode("mt32");let i=e.chRedir(c,s,!0),r=t[1];t.subarray(2).forEach((n,d)=>{let l=d+r;e.#A[l+(i-1)*16]=n,([!1,()=>{let p=e.#A[i-1<<4];if(p<3){if(e.#x[i]=1,p==2)for(let $=0;${e.#a[i*b.rpn+3]=n+40},()=>{e.#a[i*b.rpn+1]=n+14},()=>{e.#a[i*b.rpn]=n},!1,()=>{e.#e[b.cc*i+u[91]]=n?127:0},!1,()=>{e.#e[b.cc*i+u[7]]=n},()=>{e.#e[b.cc*i+u[10]]=Math.ceil(n*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(t,s,c)=>{e.switchMode("mt32");let i=c&7;console.debug(`MT-32 slot #${c+1} Drum: ${t}`);let r=t[0]<<7|t[1];t.subarray(2).forEach((n,d)=>{let l=d+r,p=(l>>2)+24,$=l&3,E=i*b.dpn;if(k()&&console.debug(`MT-32 temp drum note ${p} param ${$}: ${n}`),p<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${p}`);return}[()=>{},()=>{e.#p[(E+C[26])*b.dnc+p]=Math.round(n*1.27)},()=>{e.#p[(E+C[26])*b.dnc+p]=n*9+1&127},()=>{e.#p[(E+C[26])*b.dnc+p]=n?127:0}][$]()})}).add([22,18,2],(t,s,c)=>{e.switchMode("mt32");let i=e.chRedir(c,s,!0),r=t[1]+(t[0]<<7);r<10&&(e.#x[i]=1),t.subarray(2).forEach((n,d)=>{let l=d+r;l<14&&(e.#v[(i-1)*b.cmt+l]=n)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(t,s,c)=>{e.switchMode("mt32");let i=c&7;if(t[0]){let r=(t[0]-1<<7)+t[1]-16;t.subarray(2).forEach((n,d)=>{let l=d+r,p=(l>>2)+24,$=l&3,E=i*b.dpn;if(k()&&console.debug(`MT-32 dev drum note ${p} param ${$}: ${n}`),p<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${p}`);return}[()=>{},()=>{e.#p[(E+C[26])*b.dnc+p]=Math.round(n*1.27)},()=>{e.#p[(E+C[26])*b.dnc+p]=n*9+1&127},()=>{e.#p[(E+C[26])*b.dnc+p]=n?127:0}][$]()})}else{let r=t[1];t.subarray(2).forEach((n,d)=>{let l=d+r;e.#A[l]=n;let p=e.chRedir(1+(l>>4),s,!0),$=l&15;([!1,()=>{let E=e.#A[p-1<<4];if(E<3)if(e.#x[p]=1,E==2)for(let v=0;v{e.#a[p*b.rpn+3]=n+40},()=>{e.#a[p*b.rpn+1]=n+14},()=>{e.#a[p*b.rpn]=n},!1,()=>{e.#e[b.cc*p+u[91]]=n?127:0},!1,()=>{e.#e[b.cc*p+u[7]]=n},()=>{e.#e[b.cc*p+u[10]]=Math.ceil(n*9.05)}][$]||(()=>{}))()})}}).add([22,18,4],(t,s,c)=>{e.switchMode("mt32");let i=t[1]+(t[0]<<7),r=[];t.subarray(2).forEach((n,d)=>{let l=d+i,p=e.chRedir(Math.floor(l/246+1),s,!0),$=l%246;$<14&&(e.#v[(p-1)*b.cmt+$]=n),$<10&&(e.#x[p]=1),r.indexOf(p)<0&&r.push(p)}),r.forEach(n=>{e.dispatchEvent("voice",{part:n})})}).add([22,18,5],(t,s,c)=>{e.switchMode("mt32");let i=(t[0]<<7)+t[1];t.subarray(2).forEach((r,n)=>{let d=i+n,l=Math.floor(d/8),p=d&7,$=l*8;e.#Q[d]=r,([!1,()=>{let E=e.#Q[$];if(E<3){let v="";if(E==2){let w=b.cmt*l;v=`MT-m:${r.toString().padStart(3,"0")}`}else v=e.baseBank.get(0,r+(E<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l}),e.userBank.load(`MSB LSB PRG NME +000 127 ${l} ${v}`,!0)}}][p]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(t,s,c)=>{e.switchMode("mt32");let i=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((r,n)=>{let d=i+n;d>1)*b.cmt+d]=r)}),e.forceVoiceRefresh()}).add([22,18,16],(t,s,c)=>{e.switchMode("mt32");let i=t[1],r=!1,n=function(d,l){e.#d[l-12]=d,r=!0};t.subarray(2).forEach((d,l)=>{let p=l+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,n,n,n,n,n,n,n,n,n,()=>{e.#i=d,e.dispatchEvent("mastervolume",e.#i)}][p]||(()=>{}))(d,l)}),r&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let s=t[1],c=" ".repeat(s);t.subarray(2).forEach(i=>{i>31?c+=String.fromCharCode(i):c+=" "}),e.#N=c.padStart(20," "),e.#L=Date.now()+3200}).add([22,18,82],(t,s)=>{let c=e.chRedir(0,s,!0);for(let i=0;i<16;i++)e.#l.ano(c+i),i&&i<10&&(e.#r[c+i]=V[i-1]);console.info("MT-32 alt reset complete.")}),this.#O.add([66,0],(t,s)=>{e.switchMode("ns5r",!0),e.#c=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,s)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#c=!1}).add([66,18,0,0],(t,s)=>{let c=t[0];switch(c){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#c=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${t}`);break}default:if(c<10){let i=[0,0,0,0],r=(n,d)=>{i[d]=n};if(t.subarray(1).forEach((n,d)=>{[r,r,r,r,()=>{e.#i=n*129/16383*100,e.dispatchEvent("mastervolume",e.#i)},()=>n-64,()=>n-64,()=>{},()=>{},()=>{}][c+d]()}),t[0]<4){let n=0;i.forEach(d=>{n=n<<4,n+=d}),n-=1024}}}}).add([66,18,0,1],(t,s)=>{}).add([66,18,0,2],(t,s)=>{}).add([66,18,1],(t,s)=>{let c=e.chRedir(t[0],s,!0),i=c*b.cc,r=t[1],n=`NS5R CH${c+1} `;t.subarray(2).forEach((d,l)=>{let p=r+l;p<3?([()=>{e.#e[i+u[0]]=d||121},()=>{e.#e[i+u[32]]=d},()=>{e.#r[c]=d}][p](),e.dispatchEvent("voice",{part:c})):p<8||(p<14?[()=>{let $=e.chRedir(d,s,!0);e.#d[c]=$,c!=$&&(e.buildRchTree(),console.info(`${n}receives from CH${$+1}`))},()=>{e.#g[c]=+!d},()=>{e.setChType(c,d,m.ns5r),console.debug(`${n}type: ${A[d]}`)},()=>{e.#a[b.rpn*c+3]=d},()=>{},()=>{}][p-8]():p<16||(p<33?[()=>{e.#e[i+u[7]]=d},()=>{e.#e[i+u[11]]=d},()=>{},()=>{},()=>{e.#e[i+u[10]]=d||128},()=>{},()=>{},()=>{e.#e[i+u[93]]=d},()=>{e.#e[i+u[91]]=d},()=>{e.#e[i+u[76]]=d},()=>{e.#e[i+u[77]]=d},()=>{e.#e[i+u[78]]=d},()=>{e.#e[i+u[74]]=d},()=>{e.#e[i+u[71]]=d},()=>{e.#e[i+u[73]]=d},()=>{e.#e[i+u[75]]=d},()=>{e.#e[i+u[72]]=d}][p-16]():p<112||p<114&&[()=>{e.#e[i+u[5]]=d},()=>{e.#e[i+u[65]]=d}][p-112]()))})}).add([66,18,8,0],(t,s)=>{let c=t[0];if(c<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let i=c-32;e.#S=Date.now()+3200,e.#u=10,e.#b.fill(0);let r=t.subarray(1),n=4;r.forEach(function(d,l){let p=l+i,$=p>>4,E=p&15;if(p<80){let v=$>3,w=0,fe=$0;)e.#b[E*32+$*7+(fe-w)]=v&1,v=v>>1,w++}})}}).add([66,18,48],(t,s,c)=>{h(0,t)}).add([66,18,49],(t,s,c)=>{h(1,t)}).add([66,18,50],(t,s,c)=>{h(2,t)}).add([66,18,51],(t,s,c)=>{h(3,t)}).add([66,18,52],(t,s,c)=>{h(4,t)}).add([66,18,53],(t,s,c)=>{h(5,t)}).add([66,18,54],(t,s,c)=>{h(6,t)}).add([66,18,55],(t,s,c)=>{h(7,t)}).add([66,52],(t,s)=>{e.switchMode("ns5r",!0),e.#c=!1;let c="";M(t,(i,r)=>{r<8?(i>31&&(c+=String.fromCharCode(i)),r==7&&(e.aiEfxName=c)):r<10&&(e.setEffectType(r-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][r-8]}`,e.getEffectType(r-8)))})}).add([66,53],(t,s)=>{e.switchMode("ns5r",!0),e.#c=!1,M(t,function(c,i){switch(!0){case i<2944:{let r=e.chRedir(Math.floor(i/92),s,!0),n=r*b.cc;switch(i%92){case 0:{e.#e[n+u[0]]=c||121,e.dispatchEvent("voice",{part:r});break}case 1:{e.#e[n+u[32]]=c,e.dispatchEvent("voice",{part:r});break}case 2:{e.#r[r]=c,c>0&&e.setChActive(r,1),e.dispatchEvent("voice",{part:r});break}case 3:{let d=e.chRedir(c,s,!0);e.#d[r]=d,r!=d&&(console.info(`NS5R CH${r+1} receives from CH${d+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#a[r*b.rpn+3]=c<40||c>88?c+(c>63?-192:64):c;break}case 9:case 10:{e.#e[n+u[7]]=c;break}case 11:{e.#e[n+u[11]]=c;break}case 14:{e.#e[n+u[10]]=c||128;break}case 19:{e.#e[n+u[93]]=c;break}case 20:{e.#e[n+u[91]]=c;break}case 84:{e.#e[n+u[65]]=c;break}case 85:{e.#e[n+u[5]]=c;break}}break}case i<3096:break;case i<3134:break;case i<8566:break}})}).add([66,54],(t,s)=>{e.switchMode("ns5r",!0);let c="",i=80,r=0,n=0,d="MSB PRG LSB NME";M(t,function(l,p){let $=p%158;switch(!0){case $<10:{l>31&&(c+=String.fromCharCode(l));break}case $==11:{i=l&127;break}case $==12:{n=l&127;break}case $==13:{d+=` +${i} ${r} ${n} ${c.trim().replace("Init Voice","")}`,r++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(d),k()&&console.debug(d),e.forceVoiceRefresh()}).add([66,55],(t,s)=>{e.switchMode("ns5r",!0);let c="",i=88,r=0,n=0,d="MSB PRG LSB NME";M(t,function(l,p){let $=p%126;switch(!0){case $<10:{l>31&&(c+=String.fromCharCode(l));break}case $==11:break;case $==12:break;case $==13:{d+=` +${i} ${r} ${n} ${c.trim().replace("Init Combi","")}`,r++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(d),k()&&console.debug(d),e.forceVoiceRefresh()}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let s=new Uint8Array(5760);M(t,(c,i,r)=>{if(i<720)for(let n=0;n<8;n++)s[i*8+n]=c>>7-n&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(t,s,c)=>{e.#O.run([66,...t],s,c)}),this.#K.add([16,0,8,0],(t,s,c)=>{let i=(t[2]<<4)+t[3],r="K11 ";([()=>{e.switchMode("k11",!0),e.#c=!1,e.#E=i?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,i),console.debug(`${r}reverb type: ${i}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${r}reverb time: ${i}`)},()=>{console.debug(`${r}reverb time: ${i}`)},()=>{console.debug(`${r}reverb predelay: ${i}`)},()=>{console.debug(`${r}reverb predelay: ${i}`)},()=>{console.debug(`${r}depth high: ${i}`)},()=>{console.debug(`${r}depth high: ${i}`)},()=>{console.debug(`${r}depth low: ${i}`)},()=>{console.debug(`${r}depth low: ${i}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,s,c)=>{let i=e.chRedir(t[1],s,!0),r=b.cc*i,n=b.rpn*i,d=(t[3]<<4)+t[4],l=`K11 CH${i+1} `;([()=>{d<128?(e.setChType(i,e.CH_MELODIC,m.k11),e.#e[r+u[0]]=0,e.#r[i]=d):(e.setChType(i,e.CH_DRUMS,m.k11),e.#r[i]=d-128),e.dispatchEvent("voice",{part:i})},()=>{let p=e.chRedir(d,s,!0);e.#d[i]=p,i!=p&&(e.buildRchTree(),console.info(`${l}receives from CH${p+1}`))},()=>{e.#e[r+u[7]]=d},()=>{uupThis.setChActive(i,d)},()=>{e.#e[r+u[10]]=d},()=>{e.#a[n+3]=d+40},()=>{e.#a[n+1]=d>>1,e.#a[n+2]=d&1},()=>{e.#e[r+u[91]]=d?127:0},()=>{},()=>{e.#e[r+u[74]]=d},()=>{e.#e[r+u[73]]=d},()=>{e.#e[r+u[72]]=d}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,s,c)=>{let i=(t[2]<<4)+t[3],r="GMLX ";([()=>{console.debug(`${r}reverb type: ${i}`)},()=>{console.debug(`${r}reverb time: ${i}`)},()=>{console.debug(`${r}reverb predelay: ${i}`)},()=>{console.debug(`${r}depth high: ${i}`)},()=>{console.debug(`${r}depth low: ${i}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,s,c)=>{let i=(t[2]<<4)+t[3],r=e.chRedir(t[1],s,!0),n=r*b.cc;[()=>{i<128?(e.setChType(r,e.CH_MELODIC,m.k11),e.#e[n+u[0]]=0,e.#e[n+u[32]]=0,e.#r[r]=i):i<160?(e.setChType(r,e.CH_MELODIC,m.k11),e.#e[n+u[0]]=0,e.#e[n+u[32]]=7,e.#r[r]=i-100):(e.setChType(r,e.CH_DRUMS,m.k11),e.#e[n+u[0]]=122,e.#e[n+u[32]]=0,e.#r[r]=i-160),e.dispatchEvent("voice",{part:r})},()=>{let d=e.chRedir(i,s,!0);e.#d[r]=d,r!=d&&(e.buildRchTree(),console.info(`GMLX CH${r+1} receives from CH${d+1}`))}][t[0]]()}).add([16,0,9,4],(t,s,c)=>{let i=(t[2]<<4)+t[3],r=e.chRedir(t[1],s,!0),n=r*b.cc,d=r*b.rpn,l=`GMLX CH${r+1} `;[()=>{e.setChActive(r,i)},()=>{e.#e[n+u[7]]=i},()=>{e.#e[n+u[10]]=i},()=>{e.#e[n+u[91]]=i?127:0},()=>{e.#a[d+3]=i+40},()=>{e.#a[d+1]=i},()=>{e.#a[d]=i},()=>{}][t[0]]()}),this.#F.add([66,93,64],(t,s,c)=>{let i=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{e.#i=i*129/16383*100,e.dispatchEvent("mastervolume",e.#i);break}case 5:{i-64;break}case 6:{console.debug(`SG global reverb: ${i?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(t[1]){case 48:{console.debug(`SG reverb type: ${I[i]}`);break}}break}default:if(t[0]>>4==1){let r=e.chRedir(t[0]&15,s,!0);if(t[1]==2){let n=e.chRedir(i,s,!0);e.#d[r]=n,r!=n&&(e.buildRchTree(),console.info(`SG CH${r+1} receives from CH${n+1}`))}else t[1]==19&&(e.#e[b.cc*r+u[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),this.#z.add([9],(t,s,c)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)}),this.#m.add([127,0],(t,s,c)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...t]);e.#m.run(i,s,c)}).add([127,1,0,0],(t,s,c)=>{e.switchMode("s90es");let i="S90/Motif ES system ",r=t[0];t.subarray(1).forEach((n,d)=>{([()=>{e.#i=n*12900/16383,e.dispatchEvent("mastervolume",e.#i)}][r+d]||(()=>{console.info(`Unrecognized ${i}ID: ${r+d}`)}))()})}).add([127,1,0,0,14],(t,s,c)=>{e.switchMode("s90es");let i="S90/Motif ES bulk header ",r=[];r[95]=(n,d,l)=>{console.debug(`${i}multi edit buffer: ${n[1]}`)},(r[t[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,0,15],(t,s,c)=>{e.switchMode("s90es");let i="S90/Motif ES bulk footer ",r=[];r[95]=(n,d,l)=>{console.debug(`${i}multi edit buffer: ${n[1]}`)},(r[t[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,58,55],(t,s,c)=>{e.switchMode("s90es");let i=e.chRedir(t[0],s,!0),r=b.cc*i,n=t[1],d=`S90/Motif ES bulk CH${i<16?i+1:"U"+(i-95)} `;console.debug(d,t),!(t[0]>15)&&t.subarray(2).forEach((l,p)=>{([()=>{e.#e[r+u[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),e.#e[r+u[32]]=l,e.setChType(i,[32,40].indexOf(l)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),e.#r[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(l,s,!0);e.#d[i]=$,i!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))},()=>{e.#g[i]=l?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{e.#e[r+u[7]]=l},()=>{e.#e[r+u[10]]=l},!1,!1,!1,()=>{e.#e[r+u[91]]=l},()=>{e.#e[r+u[93]]=l},()=>{e.#e[r+u[94]]=l},()=>{e.#e[r+u[128]]=l},()=>{},()=>{e.#e[r+u[74]]=l},()=>{e.#e[r+u[71]]=l},!1,()=>{e.#e[r+u[65]]=l},()=>{e.#e[r+u[5]]=l},()=>{}][n+p]||(()=>{}))()})}).add([127,1,54,16],(t,s,c)=>{e.switchMode("s90es");let i=t[0];t.subarray(1).forEach((r,n)=>{let l=`S90/Motif ES EQ${(n>>2)+1} `;([()=>{let p=r-64},()=>{let p=D[r]},()=>{let p=r/10},()=>{let p=r}][i+n&3]||(()=>{}))()})}),this.#k.add([0,72,18,0,0,0,0],(t,s,c)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(t,s,c)=>{let i=t[0]>>5,r=t[0]&31;switch(i){case 0:{console.debug(`Unknown SD-90 global effects message: +%o`,t);break}case 1:{let n=e.chRedir(r,s,!0),d=t[1],l=n*b.cc;t.subarray(2).forEach((p,$)=>{let E=d+$;E<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[l+u[0]]=p,p){case 104:case 105:case 106:case 107:case 120:{e.#s[n]||e.setChType(n,e.CH_DRUMS);break}default:e.#s[n]&&e.setChType(n,e.CH_MELODIC)}e.dispatchEvent("voice",{part:n})},()=>{e.#e[l+u[32]]=p,e.dispatchEvent("voice",{part:n})},()=>{e.#r[n]=p,e.dispatchEvent("voice",{part:n})},()=>{e.#e[l+u[7]]=p},()=>{e.#e[l+u[10]]=p},()=>{},()=>{},()=>{p<2&&(e.#g[n]=p)},()=>{p<2&&(e.#e[l+u[68]]=p?127:0)},()=>{},()=>{p<2&&(e.#e[l+u[65]]=p?127:0)},()=>{e.#e[l+u[5]]=p&15<<4|e.#e[l+u[5]]&15},()=>{e.#e[l+u[5]]=p&15|(e.#e[l+u[5]]&240)>>4},()=>{e.#e[l+u[74]]=p},()=>{e.#e[l+u[71]]=p},()=>{e.#e[l+u[73]]=p},()=>{e.#e[l+u[72]]=p},0,0,0,0,0,0,0,()=>{e.#e[l+u[128]]=p},()=>{e.#e[l+u[93]]=p},()=>{e.#e[l+u[91]]=p},0,0,()=>{e.#e[l+u[75]]=p},()=>{e.#e[l+u[76]]=p},()=>{e.#e[l+u[77]]=p},()=>{e.#e[l+u[78]]=p}][E]||(()=>{}))():E<63||(E<64?e.#s[n]?e.#e[l+u[0]]=104|p:e.#e[l+u[0]]=96|p:console.debug(`Unknown SD-90 global CH${n+1} param setup message: +%o`,t))});break}case 2:{let n=e.chRedir(r,s,!0),d=t[1];console.debug(`Unknown SD-90 global CH${n+1} MIDI setup message: %o`,t.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,t)}})}};export{_e as OctaviaDevice,b as allocated,h as ccToPos,ce as dnToPos}; +%o`,t)}})}};export{Ke as OctaviaDevice,b as allocated,u as ccToPos,C as dnToPos}; diff --git a/dist/state_skim.mjs b/dist/state_skim.mjs index 32f943cd..82898998 100644 --- a/dist/state_skim.mjs +++ b/dist/state_skim.mjs @@ -1,7 +1,7 @@ -var U=function(e,t){let s=Math.min(e.length,t.length),a=e.slice(0,s),r=t.slice(0,s),n=0,i=0;for(;i0){let a=this.pool.length,r=1<=1&&i>=0;){if(i<=0)throw new Error("TTL reached.");if(n==a)n-=r;else{let c=U(t,this.pool[n]);switch(c){case 0:{i=0;break}case 1:{n+r<=a&&(n+=r);break}case-1:{n!=0&&(n-=r);break}default:console.warn(`Unexpected result ${c}.`)}}r=r>>1,i--}let l=!0;if(n>=this.pool.length)l=!1;else{let c=this;this.pool[n].forEach(function(u,f,p){l&&u!=t[f]&&(l=!1)}),!l&&U(t,this.pool[n])>0&&n++}return l||s?n:-1}else return s?0:-1},this.add=function(t,s){return t.data=s,this.pool.splice(this.point(t,!0),0,t),this},this.default=function(t){console.warn(`No match in "${this.name||"(unknown)"}" for "${t}". Default action not defined.`)},this.get=function(t){let s=this.point(t);if(s>-1)return this.pool[s].data;this.default(t)},this.run=function(t,...s){let a=this.point(t);a>-1?t.subarray?this.pool[a].data(t.subarray(this.pool[a].length),...s):this.pool[a].data(t.slice(this.pool[a].length),...s):this.default(t,...s)}};var v=class{#t={};addEventListener(e,t){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(t)}removeEventListener(e,t){if(this.#t[e]){let s=this.#t[e].indexOf(t);s>-1&&this.#t[e].splice(s,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,t){let s=new Event(e),a=this;s.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(r){try{r?.call(a,s)}catch(n){console.error(n)}}),this[`on${e}`]&&this[`on${e}`](s)}};var P=class{#t={};context;set(e,t){this.#t[e]=t}has(e){return!!this.#t[e]}async read(e,t){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,t)}};var X=function(e,t){let s=!0;return t.forEach((a,r)=>{s=s&&e[r]==a}),s},N=function(e){let t=0;return e.forEach(s=>{t*=256,t+=s}),t},C=new TextDecoder,L=new P;L.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),s="MSB LSB PRG NME",a=[0,0,0,0],r=32,n=0,i=0,l=!0,c=[],u=0;for(;l;){let f=t.subarray(n);([()=>{C.decode(f.subarray(0,4))=="YSFC"?(n+=80,i=1):n++},()=>{if(X(f.subarray(0,4),a))c.forEach((p,g,d)=>{let b=N(t.subarray(p.start+4,p.start+8));p.length=b}),i=2;else{let p=C.decode(f.subarray(0,4)),g=N(f.subarray(4,8));c.push({type:p,start:g}),n+=8}},()=>{let p=c[u],g=t.subarray(p.start,p.start+p.length),d=32;switch(p.type){case"ENVC":{let b=r;for(;b=c.length&&(i=3,l=!1)}][i]||(()=>{l=!1}))()}return s});var K=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]);var F=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),V={};`hi*, +var U=function(e,t){let s=Math.min(e.length,t.length),i=e.slice(0,s),r=t.slice(0,s),n=0,a=0;for(;a0){let i=this.pool.length,r=1<=1&&a>=0;){if(a<=0)throw new Error("TTL reached.");if(n==i)n-=r;else{let c=U(t,this.pool[n]);switch(c){case 0:{a=0;break}case 1:{n+r<=i&&(n+=r);break}case-1:{n!=0&&(n-=r);break}default:console.warn(`Unexpected result ${c}.`)}}r=r>>1,a--}let o=!0;if(n>=this.pool.length)o=!1;else{let c=this;this.pool[n].forEach(function(u,f,p){o&&u!=t[f]&&(o=!1)}),!o&&U(t,this.pool[n])>0&&n++}return o||s?n:-1}else return s?0:-1},this.add=function(t,s){return t.data=s,this.pool.splice(this.point(t,!0),0,t),this},this.default=function(t){console.warn(`No match in "${this.name||"(unknown)"}" for "${t}". Default action not defined.`)},this.get=function(t){let s=this.point(t);if(s>-1)return this.pool[s].data;this.default(t)},this.run=function(t,...s){let i=this.point(t);i>-1?t.subarray?this.pool[i].data(t.subarray(this.pool[i].length),...s):this.pool[i].data(t.slice(this.pool[i].length),...s):this.default(t,...s)}};var x=class{#t={};addEventListener(e,t){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(t)}removeEventListener(e,t){if(this.#t[e]){let s=this.#t[e].indexOf(t);s>-1&&this.#t[e].splice(s,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,t){let s=new Event(e),i=this;s.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(r){try{r?.call(i,s)}catch(n){console.error(n)}}),this[`on${e}`]&&this[`on${e}`](s)}};var P=class{#t={};context;set(e,t){this.#t[e]=t}has(e){return!!this.#t[e]}async read(e,t){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,t)}};var X=function(e,t){let s=!0;return t.forEach((i,r)=>{s=s&&e[r]==i}),s},N=function(e){let t=0;return e.forEach(s=>{t*=256,t+=s}),t},S=new TextDecoder,L=new P;L.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),s="MSB LSB PRG NME",i=[0,0,0,0],r=32,n=0,a=0,o=!0,c=[],u=0;for(;o;){let f=t.subarray(n);([()=>{S.decode(f.subarray(0,4))=="YSFC"?(n+=80,a=1):n++},()=>{if(X(f.subarray(0,4),i))c.forEach((p,g,d)=>{let b=N(t.subarray(p.start+4,p.start+8));p.length=b}),a=2;else{let p=S.decode(f.subarray(0,4)),g=N(f.subarray(4,8));c.push({type:p,start:g}),n+=8}},()=>{let p=c[u],g=t.subarray(p.start,p.start+p.length),d=32;switch(p.type){case"ENVC":{let b=r;for(;b=c.length&&(a=3,o=!1)}][a]||(()=>{o=!1}))()}return s});var K=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]);var V=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),F={};`hi*, ka,か ki,き ku,く @@ -138,9 +138,9 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let t=e.split(",");V[t[0]]=t[1]});var z=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"];var T=[20,21,22,23,24,25,26,28,29,30,31,36,37,64,65],R=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19];var q={};z.forEach((e,t)=>{q[e]=t});var Q={length:R.length};R.forEach((e,t)=>{Q[e]=t});var Y={length:T.length};T.forEach((e,t)=>{Y[e]=t});var Le={ch:128,cc:R.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:T.length,dnc:128,efx:7};var W=["MSB","PRG","LSB"],O=function(e){let t=Math.floor(e/10),s=e%10;return`${t.toString(16)}${s}`},M=class{#t;strictMode=!1;get(e=0,t=0,s=0,a){let r=[e,t,s],n,i=Array.from(arguments);switch(a){case"xg":{switch(e){case 0:{s==126?i[2]=125:s==127&&(i[2]=0);break}case 32:{i[2]+=4;break}case 33:case 35:case 36:{i[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:i[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{s==126&&(i[2]=0);break}case 48:case 64:case 126:case 127:{s==126&&(i[2]=0);break}}break}case"gs":{e==0&&s<5?i[2]=0:e>125&&s<5&&s!=2&&(i[2]=e,i[0]=0);break}case"g2":case"sd":{(e>>1==40||e>95&&e<100)&&(i[2]|=16);break}case"sg":{e==8&&s==0&&(i[2]=5);break}case"s90es":{s<8?i[2]+=17:s<32?i[2]+=13:i[2]=(i[2]>>3)+19;break}case"motif":{s<8?i[2]+=28:s<32?i[2]+=13:i[2]=(i[2]>>3)+19;break}}let l=" ",c="M",u=0,f=0;switch(i[0]){case 0:{i[2]==127?c="MT-a":i[2]==126?c="MT-b":i[2]==7?c="GM-k":i[2]==5?c="SG-a":i[2]==4?c="SP-l":i[2]==0||a=="gs"&&i[2]<5?c="GM-a":(c="y",u=3);break}case 8:{a=="sg"?c="GM-s":c="r:";break}case 48:{c=`yM${(i[2]>>3).toString().padStart(2,"0")}`,u=1;break}case 56:{c="GM-b";break}case 61:case 120:{c="rDrm";break}case 62:{c="kDrm";break}case 63:{if(i[2]<17){let b=i[2];c=b<10?"kP:":"kC:",c+=b%10}else i[2]<34?c=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][i[2]-17]:c="Ds";break}case 64:{c="ySFX";break}case 67:{c="DX:S";break}case 80:case 81:case 82:case 83:{c=`Prg${"UABC"[i[0]-80]}`;break}case 88:case 89:case 90:case 91:{c=`Cmb${"UABC"[i[0]-88]}`;break}case 95:{c=`${["DR","PC"][i[2]]}-d`;break}case 96:{c=i[2]==106?"AP-a":i[2]>>4==1?"SDg":"PF",i[2]>63?f=63:i[2]>>4==1&&(f=16),u=3;break}case 97:{c=i[2]>>4==1?"SDa":"VL:",u=3,i[2]>>4==1?f=16:f=112;break}case 98:{c=i[2]>>4==1?"SDb":"SG-a",u=3,f=16;break}case 99:{c=i[2]>>4==1?"SDc":"DX",i[2]>63?f=63:i[2]>>4==1&&(f=16),u=3;break}case 100:{c="AN",i[2]>63?f=63:i[2]>>4==1&&(f=16),u=3;break}case 104:case 105:case 106:case 107:{c="SDd",f=104;break}case 121:{c=`GM-${i[2]?"":"a"}`,u=3;break}case 122:{c="lDrm";break}case 126:{c="yDrS";break}case 127:{i[2]==127?c="rDrm":c="yDrm";break}default:i[0]<48?c="r:":c="M"}c.length<4&&(c+=`${[e,s,i[0],i[2]][u]-f}`.padStart(4-c.length,"0")),a=="xg"&&e==16&&(n=`Voice${(s*128+t+1).toString().padStart(3,"0")}`,l=" ");let p=[i[0],i[1],i[2]];for(;!(n?.length>=0);)n=this.#t[i[1]||0][(i[0]<<7)+i[2]],n||(this.strictMode?(n="",l="?"):this.#t[i[1]||0][i[0]<<7]?i[0]==0?(i[2]=0,l="^"):i[2]<1?(i[0]=0,l="*"):(i[2]--,l="^"):e==48?(i[0]=0,i[2]=0,l="!"):e==62?(i[1]--,l=" ",i[1]<1&&!n?.length&&(i[0]=0,l="!")):e<63?i[0]==0?(i[2]=0,l="^"):i[2]<1?(i[0]=0,l="*"):i[2]--:e==80?(n=`PrgU:${t.toString().padStart(3,"0")}`,l="!"):e==88?(n=`CmbU:${t.toString().padStart(3,"0")}`,l="!"):e==121?(n=`GM2Vox0${s}`,l="#"):e==122?(i[1]==32?i[1]==0:i[1]%=7,n=this.#t[i[1]||0][(i[0]<<7)+i[2]],n?l=" ":(n="",l="*")):i[1]==0?(n=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${s.toString().padStart(3,"0")}`,l="!"):i[0]==0?(i[2]=0,l="^"):i[2]>0?i[2]--:i[1]>0?(i[1]=0,l="!"):(i[0]=0,l="?"));let g=[i[0],i[1],i[2]];(a=="gs"||a=="ns5r")&&l=="^"&&(l=" "),e==127&&l=="^"&&(l=" "),l!=" "&&self.debugMode&&(n="");let d="??";switch(i[0]){case 0:{i[2]==0?d="GM":i[2]==5||i[2]==7?d="KG":i[2]<126?d="XG":i[2]==127&&(d="MT");break}case 48:{d="MU";break}case 56:{d="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{d="AI";break}case 62:case 82:case 90:{d="XD";break}case 63:{i[2]<17?d="KR":i[2]<34?d="ES":d="DS";break}case 64:case 126:{d="XG";break}case 67:case 99:{d=i[2]>>4==1?"SD":"DX";break}case 81:{d="RW";break}case 95:{d=["DR","PC"][i[2]];break}case 96:{d=i[2]==106?"AP":i[2]>>4==1?"SD":"PF";break}case 97:{d=i[2]>>4==1?"SD":"VL";break}case 98:{d=i[2]>>4==1?"SD":"SG";break}case 100:{d="AN";break}case 104:case 105:case 106:case 107:{d="SD";break}case 120:{d="GS";break}case 121:{d=i[2]?"G2":"GM";break}case 122:{d="KG";break}case 127:{d=i[2]==127?"MT":t==0?"GM":"XG";break}default:i[0]<48&&(i[0]==16&&a=="xg"?d="XG":d="GS")}return{name:n||`${O(e||0)} ${O(t||0)} ${O(s||0)}`,iid:p,eid:g,sid:r,ending:l,sect:c,standard:d}}async load(e,t,s){let a=this,r=[],n=0,i=0;e.split(` -`).forEach(function(l,c){let u=l.split(" "),f=[];c==0?u.forEach(function(p,g){r[W.indexOf(p)]=g}):u.forEach(async function(p,g){g>2?(a.#t[f[r[1]]]=a.#t[f[r[1]]]||[],(!a.#t[f[r[1]]][(f[r[0]]<<7)+f[r[2]]]?.length||t)&&(a.#t[f[r[1]]][(f[r[0]]<<7)+f[r[2]]]=u[3],n++),i++):f.push(parseInt(u[g]))})}),t||console.debug(`Map "${s||"(internal)"}": ${i} total, ${n} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],s=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],a=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let r=s[0];r<=s[1];r++){let n=r<<7;for(let i=a[0];i<=a[1];i++){let l=n+i;for(let c=t[0];c<=t[1];c++)delete this.#t[c][l]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let t=this;e.forEach(async function(s,a){try{await fetch(`./data/bank/${s}.tsv`).then(function(r){return r.text()}).then(r=>{t.load(r,!1,s)})}catch{console.error(`Failed loading "${s}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var E=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],H=[[0,0,0,0,121,0,0,56,82,81,63,0,0],[0,0,4,0,0,127,0,0,0,0,0,0,0]],S=[120,127,120,127,120,127,61,62,62,62,120,122,122],J=[0,3,81,84,88],I={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},D={0:0,1:1,2:3,5:4},B=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],G=[36,37];var A=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,12,13,16,17,18,19],Z=[33,99,100,32,102,8,9,10];var w={};E.forEach((e,t)=>{w[e]=t});var h={length:A.length};A.forEach((e,t)=>{h[e]=t});var k=function(){return!!self.Bun||self.debugMode||!1},j=function(e){let t=[],s=0;return e?.forEach(function(a,r){a==247?t.push(e.subarray(s,r)):a==240&&(s=r+1)}),t.length||t.push(e.subarray(0)),k(),t},_=function(e,t="",s="",a=2){return e?`${t}${e.toString().padStart(a,"0")}${s}`:""},o={ch:128,cc:A.length,nn:128,pl:512,tr:256,cmt:14,rpn:6},Ve=class extends v{#t=0;#E=0;#b=0;#g=new Array(11);get#h(){return this.#g[this.#E]}set#h(e){this.#g[this.#E]=e}#y=new Uint8Array(o.ch);#I=new Uint8Array(o.ch);#e=new Uint8ClampedArray(o.ch*o.cc);#$=new Uint8ClampedArray(o.ch);#l=new Uint8ClampedArray(o.ch*o.nn);#D=new Uint8Array(o.ch);#n=new Uint16Array(o.pl);#f=new Uint8Array(o.pl);#x=new Int16Array(o.ch);#d=new Uint8Array(o.ch);#M=0;#o=new Uint8Array(o.ch*o.rpn);#A=new Int8Array(o.ch*G.length);#U=new Uint8Array(o.ch);#F=new Uint8Array(128);#B=new Uint8Array(o.cmt*8);#V=new Uint8Array(1024);#G=new Uint8Array(o.cmt*64);#k=0;#u=0;#v=100;#m=0;#_=500;#z=0;#i="";#p=0;#q=0;#Q=!0;#a=!1;#X;#Y=new Uint8Array(2);#s=[];#w=new Uint8Array(o.ch);#S=new Uint8Array(o.tr);baseBank=new M("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new M("gm");initOnReset=!1;chRedir(e,t,s){if(this.#S[t])return(this.#S[t]-1)*16+e;if([w.gs,w.ns5r].indexOf(this.#t)>-1){if(s==1)return e;let a=0,r=!0;for(;r;)this.#w[e+a]==0?(this.#w[e+a]=t,console.debug(`Assign track ${t} to channel ${e+a+1}.`),r=!1):this.#w[e+a]==t?r=!1:(a+=16,a>=128&&(a=0,r=!1));return e+a}else return e}#c=[];#T;#r={nOff:(e,t)=>{let s=e*128+t,a=this.#n.lastIndexOf(s);a>-1&&(this.#e[o.cc*e+h[64]]>63&&!this.config?.disableCc64?this.#f[a]=4:(this.#n[a]=0,this.#l[s]=0,this.#f[a]=0))},nOn:(e,t,s)=>{let a=e*128+t,r=0;for(this.#D[e]&&this.#r.ano(e);this.#f[r]>0&&this.#n[r]!=a;)r++;r{},cAt:(e,t)=>{},hoOf:e=>{this.#f.forEach((t,s)=>{if(t==4){let a=this.#n[s],r=a>>7;e==r&&(this.#f[s]=0,this.#n[s]=0,this.#l[a]=0)}})},soOf:e=>{},ano:e=>{this.#n.forEach((t,s,a)=>{let r=t>>7,n=t&127;t==0&&this.#l[0]==0||r==e&&this.#r.nOff(r,n)})}};#K={8:function(e){let t=e.channel,s=e.data[0];this.#r.nOff(t,s)},9:function(e){let t=e.channel;this.#y[t]=1;let s=e.data[0],a=e.data[1];a>0?this.#r.nOn(t,s,a):this.#r.nOff(t,s)},10:function(e){let s=e.channel*128+e.data[0];this.#n.indexOf(s)>-1&&(this.#l[s]=data[1])},11:function(e){let t=e.channel;this.#y[t]=1;let s=t*o.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#r.ano(t),this.#x[t]=0;let a=t*o.cc;this.#e[a+h[1]]=0,this.#e[a+h[5]]=0,this.#e[a+h[64]]=0,this.#e[a+h[65]]=0,this.#e[a+h[66]]=0,this.#e[a+h[67]]=0,this.#e[a+h[11]]=127,this.#e[a+h[101]]=127,this.#e[a+h[100]]=127,this.#e[a+h[99]]=127,this.#e[a+h[98]]=127;return}case 123:{this.#r.ano(t);return}case 124:{this.#r.ano(t);return}case 125:{this.#r.ano(t);return}case 126:{this.#D[t]=1,this.#r.ano(t);return}case 127:{this.#D[t]=0,this.#r.ano(t);return}}if(h[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(e.data[0]){case 0:{if(k()&&console.debug(`${E[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#e[s]>119&&(e.data[1]=this.#e[s],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg");else if(this.#t==w.gs)e.data[1]<56&&this.#e[s]>119&&(e.data[1]=this.#e[s],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`));else if(this.#t==w.gm)e.data[1]<48?this.#e[s]>119&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${t+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0);else if(this.#t==w.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let a=0;for(let r=0;r<16;r++){let n=this.#e[o.cc*r];(n==56||n==62)&&a++}a>14&&this.switchMode("ag10",!0)}}break}case 6:{if(this.#M){let a=this.#e[s+h[99]],r=this.#e[s+h[98]];if(a==1){let n=Z.indexOf(r);if(n>-1)this.#e[s+h[71+n]]=e.data[1],k()&&console.debug(`Redirected NRPN 1 ${r} to cc${71+n}.`);else{let i=G.indexOf(r);i>-1&&(this.#A[t*10+i]=e.data[1]-64),k()&&console.debug(`CH${t+1} voice NRPN ${r} commit`)}}}else{let a=D[this.#e[s+h[100]]];this.#e[s+h[101]]==0&&a!=null&&(k()&&console.debug(`CH${t+1} RPN 0 ${this.#e[s+h[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],B[a][0]),B[a][1]),this.#o[t*o.rpn+a]=e.data[1])}break}case 38:{this.#M||this.#e[s+101]==0&&D[this.#e[s+100]]!=null&&(this.#o[t*o.rpn+D[this.#e[s+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#r.hoOf(t);break}case 66:{console.debug(`Sostenuto pedal: ${e.data[1]}`);break}case 98:case 99:{this.#M=1;break}case 100:case 101:{this.#M=0;break}}this.#e[s+h[e.data[0]]]=e.data[1]}},12:function(e){let t=e.channel;this.#y[t]=1,this.#$[t]=e.data,this.#U[t]=0,k()&&console.debug(`T:${e.track} C:${t} P:${e.data}`)},13:function(e){let t=this,s=e.channel;this.#n.forEach(function(a){let r=a>>7;s==r&&(t.#l[a]=e.data)})},14:function(e){let t=e.channel;this.#x[t]=e.data[1]*128+e.data[0]-8192},15:function(e){j(e.data).forEach(t=>{let s=t[0],a=t[1];(this.#W[s]||function(){console.debug(`Unknown manufacturer ${s}.`)})(a,t.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){if((this.#c[e.meta]||function(s,a,r){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#m=0),J.indexOf(e.meta)>-1)return e.reply="meta",e;k()&&console.debug(e)}};#W={64:(e,t,s)=>{this.#L.run(t,s,e)},65:(e,t,s)=>{if(t[0]<16)this.#C.run(t,s,e),console.warn("Unknown device SysEx!");else{let a=t[t.length-1],r=gsChecksum(t.subarray(2,t.length-1));a==r?this.#C.run(t.subarray(0,t.length-1),s,e):console.warn(`Bad GS checksum ${a}. Should be ${r}.`)}},66:(e,t,s)=>{this.#O.run(t,s,e)},67:(e,t,s)=>{this.#R.run(t,s,e)},68:(e,t,s)=>{this.#J.run(t,s,e)},71:(e,t,s)=>{this.#H.run(t,s,e)},126:(e,t,s)=>{this.#P.run(t,s,e)},127:(e,t,s)=>{this.switchMode("gm"),this.#N.run(t,s,e)}};#P;#N;#R;#C;#O;#L;#H;#J;buildRchTree(){let e=[];this.#I.forEach((t,s)=>{e[t]?.constructor||(e[t]=[]),e[t].push(s)}),this.#X=e}getActive(){let e=this.#y.slice();return this.#t==w.mt32,e}getCc(e){let t=e*o.cc,s=this.#e.slice(t,t+o.cc);return s[h[0]]=s[h[0]]||this.#k,s[h[32]]=s[h[32]]||this.#u,s}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&t.set(i,{v:s.#l[a],s:s.#f[r]})}),t}getBitmap(){return{bitmap:this.#h,expire:this.#b}}getLetter(){return{text:this.#i,expire:this.#p}}getMode(){return E[this.#t]}getMaster(){return{volume:this.#v}}getRawStrength(){let e=this;return this.#n.forEach(function(t){let s=Math.floor(t/128);e.#l[t]>e.#d[s]&&(e.#d[s]=e.#l[t])}),this.#d}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(s,a){e[a]=Math.floor(s*t.#e[a*o.cc+h[7]]*t.#e[a*o.cc+h[11]]*t.#v/803288)}),e}getRpn(){return this.#o}getNrpn(){return this.#A}getVoice(e,t,s,a){let r=e||this.#k,n=t,i=s||this.#u;E[this.#t]=="ns5r"&&r>0&&r<56&&(i=3);let l=this.userBank.get(r,n,i,a);if(E[this.#t]=="mt32"&&l.name.indexOf("MT-m:")==0){let c=parseInt(l.name.slice(5)),u=c*o.cmt,f="";this.#G.subarray(u,u+10).forEach(p=>{p>31&&(f+=String.fromCharCode(p))}),this.userBank.load(`MSB LSB PRG -0 127 ${n} ${f}`,!0),l.name=f,l.ending=" "}return(l.ending!=" "||!l.name.length)&&(l=this.baseBank.get(r,n,i,a)),l}getChVoice(e){let t=this.getVoice(this.#e[e*o.cc+h[0]],this.#$[e],this.#e[e*o.cc+h[32]],E[this.#t]);if(this.#U[e])switch(this.#t){case w.mt32:t.ending="~",t.name="",this.#B.subarray(14*(e-1),14*(e-1)+10).forEach(s=>{s>31&&(t.name+=String.fromCharCode(s))})}return t}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#k=0,this.#u=0,this.#m=0,this.#y.fill(0),this.#e.fill(0),this.#$.fill(0),this.#l.fill(0),this.#n.fill(0),this.#d.fill(0),this.#x.fill(0),this.#A.fill(0),this.#v=100,this.#s=[],this.#_=500,this.#z=0,this.#p=0,this.#i="",this.#b=0,this.#E=0,this.#h.fill(0),this.#a=!1,this.#q=0,this.#Q=!0,this.#I.forEach(function(t,s,a){a[s]=s}),this.buildRchTree(),e==0&&(this.#w.fill(0),this.#S.fill(0)),this.#e[o.cc*9]=S[0],this.#e[o.cc*25]=S[0],this.#e[o.cc*41]=S[0],this.#e[o.cc*57]=S[0],this.#Y.fill(0),this.#V.fill(0),this.#G.fill(0),this.#F.fill(0),this.#B.fill(0),this.#U.fill(0),this.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let t=0;t-1){if(this.#t==0||t){this.#t=s,this.#E=0,this.#k=H[0][s],this.#u=H[1][s];for(let a=0;a-1&&(this.#e[a*o.cc]=S[s]);switch(this.initOnReset,s){case w.mt32:{mt32DefProg.forEach((a,r)=>{let n=r+1;this.#y[n]||(this.#$[n]=a,this.#e[n*o.cc+h[91]]=127)});break}}this.dispatchEvent("mode",e)}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#d.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#K[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),s=!1;this.#X[t]?.forEach(a=>{e.channel=a,s=!0,this.#K[e.type].call(this,e)}),s||console.warn(`${I[e.type]?I[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${t+1} without any recipient.`)}this.#s.length>100&&this.#s.splice(100,this.#s.length-99)}runRaw(e){}constructor(){super();let e=this;this.#h=new Uint8Array(256),this.#g[10]=new Uint8Array(512),this.#T=new m,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let t=e.split(",");F[t[0]]=t[1]});var z=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"];var T=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var R=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19];var q={};z.forEach((e,t)=>{q[e]=t});var Q={length:R.length};R.forEach((e,t)=>{Q[e]=t});var Y={length:T.length};T.forEach((e,t)=>{Y[e]=t});var Le={ch:128,cc:R.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:T.length,dnc:128,efx:7};var W=["MSB","PRG","LSB"],O=function(e){let t=Math.floor(e/10),s=e%10;return`${t.toString(16)}${s}`},M=class{#t;strictMode=!1;get(e=0,t=0,s=0,i){let r=[e,t,s],n,a=Array.from(arguments);switch(i){case"xg":{switch(e){case 0:{s==126?a[2]=125:s==127&&(a[2]=0);break}case 16:{s==126&&(a[2]=0);break}case 32:{a[2]+=4;break}case 33:case 35:case 36:{a[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:a[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{s==126&&(a[2]=0);break}case 48:case 64:case 126:case 127:{s==126&&(a[2]=0);break}}break}case"gs":{e==0&&s<5?a[2]=0:e>125&&s<5&&s!=2&&(a[2]=e,a[0]=0);break}case"g2":case"sd":{(e>>1==40||e>95&&e<100)&&(a[2]|=16);break}case"sg":{e==8&&s==0&&(a[2]=5);break}case"s90es":{s<8?a[2]+=17:s<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}case"motif":{s<8?a[2]+=28:s<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}}let o=" ",c="M",u=0,f=0;switch(a[0]){case 0:{a[2]==127?c="MT-a":a[2]==126?c="MT-b":a[2]==7?c="GM-k":a[2]==5?c="SG-a":a[2]==4?c="SP-l":a[2]==0||i=="gs"&&a[2]<5?c="GM-a":(c="y",u=3);break}case 8:{i=="sg"?c="GM-s":c="r:";break}case 48:{c=`yM${(a[2]>>3).toString().padStart(2,"0")}`,u=1;break}case 56:{c="GM-b";break}case 61:case 120:{c="rDrm";break}case 62:{c="kDrm";break}case 63:{if(a[2]<17){let b=a[2];c=b<10?"kP:":"kC:",c+=b%10}else a[2]<34?c=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][a[2]-17]:c="Ds";break}case 64:{c="ySFX";break}case 67:{c="DX:S";break}case 80:case 81:case 82:case 83:{c=`Prg${"UABC"[a[0]-80]}`;break}case 88:case 89:case 90:case 91:{c=`Cmb${"UABC"[a[0]-88]}`;break}case 95:{c=`${["DR","PC"][a[2]]}-d`;break}case 96:{c=a[2]==106?"AP-a":a[2]>>4==1?"SDg":"PF",a[2]>63?f=63:a[2]>>4==1&&(f=16),u=3;break}case 97:{c=a[2]>>4==1?"SDa":"VL:",u=3,a[2]>>4==1?f=16:f=112;break}case 98:{c=a[2]>>4==1?"SDb":"SG-a",u=3,f=16;break}case 99:{c=a[2]>>4==1?"SDc":"DX",a[2]>63?f=63:a[2]>>4==1&&(f=16),u=3;break}case 100:{c="AN",a[2]>63?f=63:a[2]>>4==1&&(f=16),u=3;break}case 104:case 105:case 106:case 107:{c="SDd",f=104;break}case 121:{c=`GM-${a[2]?"":"a"}`,u=3;break}case 122:{c="lDrm";break}case 126:{c="yDrS";break}case 127:{a[2]==127?c="rDrm":c="yDrm";break}default:a[0]<48?c="r:":c="M"}c.length<4&&(c+=`${[e,s,a[0],a[2]][u]-f}`.padStart(4-c.length,"0")),i=="xg"&&(e==0?a[2]<100?c=c.replace("y0","y:"):a[2]==125&&(c="y126"):e==16&&(n=`Voice${(a[2]*128+a[1]+1).toString().padStart(3,"0")}`,o=" "));let p=[a[0],a[1],a[2]];for(;!(n?.length>=0);)n=this.#t[a[1]||0][(a[0]<<7)+a[2]],n||(this.strictMode?(n="",o="?"):this.#t[a[1]||0][a[0]<<7]?a[0]==0?(a[2]=0,o="^"):a[2]<1?(a[0]=0,o="*"):(a[2]--,o="^"):e==48?(a[0]=0,a[2]=0,o="!"):e==62?(a[1]--,o=" ",a[1]<1&&!n?.length&&(a[0]=0,o="!")):e<63?a[0]==0?(a[2]=0,o="^"):a[2]<1?(a[0]=0,o="*"):a[2]--:e==80?(n=`PrgU:${t.toString().padStart(3,"0")}`,o="!"):e==88?(n=`CmbU:${t.toString().padStart(3,"0")}`,o="!"):e==121?(n=`GM2Vox0${s}`,o="#"):e==122?(a[1]==32?a[1]==0:a[1]%=7,n=this.#t[a[1]||0][(a[0]<<7)+a[2]],n?o=" ":(n="",o="*")):a[1]==0?(n=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${s.toString().padStart(3,"0")}`,o="!"):a[0]==0?(a[2]=0,o="^"):a[2]>0?a[2]--:a[1]>0?(a[1]=0,o="!"):(a[0]=0,o="?"));let g=[a[0],a[1],a[2]];(i=="gs"||i=="ns5r")&&o=="^"&&(o=" "),e==127&&o=="^"&&(o=" "),o!=" "&&self.debugMode&&(n="");let d="??";switch(a[0]){case 0:{a[2]==0?d="GM":a[2]==5||a[2]==7?d="KG":a[2]<126?d="XG":a[2]==127&&(d="MT");break}case 48:{d="MU";break}case 56:{d="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{d="AI";break}case 62:case 82:case 90:{d="XD";break}case 63:{a[2]<17?d="KR":a[2]<34?d="ES":d="DS";break}case 64:case 126:{d="XG";break}case 67:case 99:{d=a[2]>>4==1?"SD":"DX";break}case 81:{d="RW";break}case 95:{d=["DR","PC"][a[2]];break}case 96:{d=a[2]==106?"AP":a[2]>>4==1?"SD":"PF";break}case 97:{d=a[2]>>4==1?"SD":"VL";break}case 98:{d=a[2]>>4==1?"SD":"SG";break}case 100:{d="AN";break}case 104:case 105:case 106:case 107:{d="SD";break}case 120:{d="GS";break}case 121:{d=a[2]?"G2":"GM";break}case 122:{d="KG";break}case 127:{d=a[2]==127?"MT":t==0?"GM":"XG";break}default:a[0]<48&&(a[0]==16&&i=="xg"?d="XG":d="GS")}return{name:n||`${O(e||0)} ${O(t||0)} ${O(s||0)}`,iid:p,eid:g,sid:r,ending:o,sect:c,standard:d}}async load(e,t,s){let i=this,r=[],n=0,a=0;e.split(` +`).forEach(function(o,c){let u=o.split(" "),f=[];c==0?u.forEach(function(p,g){r[W.indexOf(p)]=g}):u.forEach(async function(p,g){g>2?(i.#t[f[r[1]]]=i.#t[f[r[1]]]||[],(!i.#t[f[r[1]]][(f[r[0]]<<7)+f[r[2]]]?.length||t)&&(i.#t[f[r[1]]][(f[r[0]]<<7)+f[r[2]]]=u[3],n++),a++):f.push(parseInt(u[g]))})}),t||console.debug(`Map "${s||"(internal)"}": ${a} total, ${n} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],s=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],i=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let r=s[0];r<=s[1];r++){let n=r<<7;for(let a=i[0];a<=i[1];a++){let o=n+a;for(let c=t[0];c<=t[1];c++)delete this.#t[c][o]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let t=this;e.forEach(async function(s,i){try{await fetch(`./data/bank/${s}.tsv`).then(function(r){return r.text()}).then(r=>{t.load(r,!1,s)})}catch{console.error(`Failed loading "${s}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var w=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],G=[[0,0,0,0,121,0,0,56,82,81,63,0,0],[0,0,4,0,0,127,0,0,0,0,0,0,0]],v=[120,127,120,127,120,127,61,62,62,62,120,122,122],J=[0,3,81,84,88],H={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},D={0:0,1:1,2:3,5:4},B=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],I=[36,37];var A=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,12,13,16,17,18,19],Z=[33,99,100,32,102,8,9,10];var E={};w.forEach((e,t)=>{E[e]=t});var h={length:A.length};A.forEach((e,t)=>{h[e]=t});var k=function(){return!!self.Bun||self.debugMode||!1},j=function(e){let t=[],s=0;return e?.forEach(function(i,r){i==247?t.push(e.subarray(s,r)):i==240&&(s=r+1)}),t.length||t.push(e.subarray(0)),k(),t},_=function(e,t="",s="",i=2){return e?`${t}${e.toString().padStart(i,"0")}${s}`:""},l={ch:128,cc:A.length,nn:128,pl:512,tr:256,cmt:14,rpn:6},Fe=class extends x{#t=0;#w=0;#b=0;#g=new Array(11);get#h(){return this.#g[this.#w]}set#h(e){this.#g[this.#w]=e}#y=new Uint8Array(l.ch);#H=new Uint8Array(l.ch);#e=new Uint8ClampedArray(l.ch*l.cc);#$=new Uint8ClampedArray(l.ch);#o=new Uint8ClampedArray(l.ch*l.nn);#D=new Uint8Array(l.ch);#n=new Uint16Array(l.pl);#f=new Uint8Array(l.pl);#C=new Int16Array(l.ch);#d=new Uint8Array(l.ch);#M=0;#l=new Uint8Array(l.ch*l.rpn);#A=new Int8Array(l.ch*I.length);#U=new Uint8Array(l.ch);#V=new Uint8Array(128);#B=new Uint8Array(l.cmt*8);#F=new Uint8Array(1024);#I=new Uint8Array(l.cmt*64);#k=0;#u=0;#x=100;#m=0;#_=500;#z=0;#i="";#p=0;#q=0;#Q=!0;#a=!1;#X;#Y=new Uint8Array(2);#s=[];#E=new Uint8Array(l.ch);#v=new Uint8Array(l.tr);baseBank=new M("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new M("gm");initOnReset=!1;chRedir(e,t,s){if(this.#v[t])return(this.#v[t]-1)*16+e;if([E.gs,E.ns5r].indexOf(this.#t)>-1){if(s==1)return e;let i=0,r=!0;for(;r;)this.#E[e+i]==0?(this.#E[e+i]=t,console.debug(`Assign track ${t} to channel ${e+i+1}.`),r=!1):this.#E[e+i]==t?r=!1:(i+=16,i>=128&&(i=0,r=!1));return e+i}else return e}#c=[];#T;#r={nOff:(e,t)=>{let s=e*128+t,i=this.#n.lastIndexOf(s);i>-1&&(this.#e[l.cc*e+h[64]]>63&&!this.config?.disableCc64?this.#f[i]=4:(this.#n[i]=0,this.#o[s]=0,this.#f[i]=0))},nOn:(e,t,s)=>{let i=e*128+t,r=0;for(this.#D[e]&&this.#r.ano(e);this.#f[r]>0&&this.#n[r]!=i;)r++;r{},cAt:(e,t)=>{},hoOf:e=>{this.#f.forEach((t,s)=>{if(t==4){let i=this.#n[s],r=i>>7;e==r&&(this.#f[s]=0,this.#n[s]=0,this.#o[i]=0)}})},soOf:e=>{},ano:e=>{this.#n.forEach((t,s,i)=>{let r=t>>7,n=t&127;t==0&&this.#o[0]==0||r==e&&this.#r.nOff(r,n)})}};#K={8:function(e){let t=e.channel,s=e.data[0];this.#r.nOff(t,s)},9:function(e){let t=e.channel;this.#y[t]=1;let s=e.data[0],i=e.data[1];i>0?this.#r.nOn(t,s,i):this.#r.nOff(t,s)},10:function(e){let s=e.channel*128+e.data[0];this.#n.indexOf(s)>-1&&(this.#o[s]=data[1])},11:function(e){let t=e.channel;this.#y[t]=1;let s=t*l.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#r.ano(t),this.#C[t]=0;let i=t*l.cc;this.#e[i+h[1]]=0,this.#e[i+h[5]]=0,this.#e[i+h[64]]=0,this.#e[i+h[65]]=0,this.#e[i+h[66]]=0,this.#e[i+h[67]]=0,this.#e[i+h[11]]=127,this.#e[i+h[101]]=127,this.#e[i+h[100]]=127,this.#e[i+h[99]]=127,this.#e[i+h[98]]=127;return}case 123:{this.#r.ano(t);return}case 124:{this.#r.ano(t);return}case 125:{this.#r.ano(t);return}case 126:{this.#D[t]=1,this.#r.ano(t);return}case 127:{this.#D[t]=0,this.#r.ano(t);return}}if(h[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(e.data[0]){case 0:{if(k()&&console.debug(`${w[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#e[s]>119&&(e.data[1]=this.#e[s],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg");else if(this.#t==E.gs)e.data[1]<56&&this.#e[s]>119&&(e.data[1]=this.#e[s],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`));else if(this.#t==E.gm)e.data[1]<48?this.#e[s]>119&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${t+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0);else if(this.#t==E.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let i=0;for(let r=0;r<16;r++){let n=this.#e[l.cc*r];(n==56||n==62)&&i++}i>14&&this.switchMode("ag10",!0)}}break}case 6:{if(this.#M){let i=this.#e[s+h[99]],r=this.#e[s+h[98]];if(i==1){let n=Z.indexOf(r);if(n>-1)this.#e[s+h[71+n]]=e.data[1],k()&&console.debug(`Redirected NRPN 1 ${r} to cc${71+n}.`);else{let a=I.indexOf(r);a>-1&&(this.#A[t*10+a]=e.data[1]-64),k()&&console.debug(`CH${t+1} voice NRPN ${r} commit`)}}}else{let i=D[this.#e[s+h[100]]];this.#e[s+h[101]]==0&&i!=null&&(k()&&console.debug(`CH${t+1} RPN 0 ${this.#e[s+h[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],B[i][0]),B[i][1]),this.#l[t*l.rpn+i]=e.data[1])}break}case 38:{this.#M||this.#e[s+101]==0&&D[this.#e[s+100]]!=null&&(this.#l[t*l.rpn+D[this.#e[s+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#r.hoOf(t);break}case 66:{console.debug(`Sostenuto pedal: ${e.data[1]}`);break}case 98:case 99:{this.#M=1;break}case 100:case 101:{this.#M=0;break}}this.#e[s+h[e.data[0]]]=e.data[1]}},12:function(e){let t=e.channel;this.#y[t]=1,this.#$[t]=e.data,this.#U[t]=0,k()&&console.debug(`T:${e.track} C:${t} P:${e.data}`)},13:function(e){let t=this,s=e.channel;this.#n.forEach(function(i){let r=i>>7;s==r&&(t.#o[i]=e.data)})},14:function(e){let t=e.channel;this.#C[t]=e.data[1]*128+e.data[0]-8192},15:function(e){j(e.data).forEach(t=>{let s=t[0],i=t[1];(this.#W[s]||function(){console.debug(`Unknown manufacturer ${s}.`)})(i,t.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){if((this.#c[e.meta]||function(s,i,r){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#m=0),J.indexOf(e.meta)>-1)return e.reply="meta",e;k()&&console.debug(e)}};#W={64:(e,t,s)=>{this.#L.run(t,s,e)},65:(e,t,s)=>{if(t[0]<16)this.#S.run(t,s,e),console.warn("Unknown device SysEx!");else{let i=t[t.length-1],r=gsChecksum(t.subarray(2,t.length-1));i==r?this.#S.run(t.subarray(0,t.length-1),s,e):console.warn(`Bad GS checksum ${i}. Should be ${r}.`)}},66:(e,t,s)=>{this.#O.run(t,s,e)},67:(e,t,s)=>{this.#R.run(t,s,e)},68:(e,t,s)=>{this.#J.run(t,s,e)},71:(e,t,s)=>{this.#G.run(t,s,e)},126:(e,t,s)=>{this.#P.run(t,s,e)},127:(e,t,s)=>{this.switchMode("gm"),this.#N.run(t,s,e)}};#P;#N;#R;#S;#O;#L;#G;#J;buildRchTree(){let e=[];this.#H.forEach((t,s)=>{e[t]?.constructor||(e[t]=[]),e[t].push(s)}),this.#X=e}getActive(){let e=this.#y.slice();return this.#t==E.mt32,e}getCc(e){let t=e*l.cc,s=this.#e.slice(t,t+l.cc);return s[h[0]]=s[h[0]]||this.#k,s[h[32]]=s[h[32]]||this.#u,s}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&t.set(a,{v:s.#o[i],s:s.#f[r]})}),t}getBitmap(){return{bitmap:this.#h,expire:this.#b}}getLetter(){return{text:this.#i,expire:this.#p}}getMode(){return w[this.#t]}getMaster(){return{volume:this.#x}}getRawStrength(){let e=this;return this.#n.forEach(function(t){let s=Math.floor(t/128);e.#o[t]>e.#d[s]&&(e.#d[s]=e.#o[t])}),this.#d}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(s,i){e[i]=Math.floor(s*t.#e[i*l.cc+h[7]]*t.#e[i*l.cc+h[11]]*t.#x/803288)}),e}getRpn(){return this.#l}getNrpn(){return this.#A}getVoice(e,t,s,i){let r=e||this.#k,n=t,a=s||this.#u;w[this.#t]=="ns5r"&&r>0&&r<56&&(a=3);let o=this.userBank.get(r,n,a,i);if(w[this.#t]=="mt32"&&o.name.indexOf("MT-m:")==0){let c=parseInt(o.name.slice(5)),u=c*l.cmt,f="";this.#I.subarray(u,u+10).forEach(p=>{p>31&&(f+=String.fromCharCode(p))}),this.userBank.load(`MSB LSB PRG +0 127 ${n} ${f}`,!0),o.name=f,o.ending=" "}return(o.ending!=" "||!o.name.length)&&(o=this.baseBank.get(r,n,a,i)),o}getChVoice(e){let t=this.getVoice(this.#e[e*l.cc+h[0]],this.#$[e],this.#e[e*l.cc+h[32]],w[this.#t]);if(this.#U[e])switch(this.#t){case E.mt32:t.ending="~",t.name="",this.#B.subarray(14*(e-1),14*(e-1)+10).forEach(s=>{s>31&&(t.name+=String.fromCharCode(s))})}return t}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#k=0,this.#u=0,this.#m=0,this.#y.fill(0),this.#e.fill(0),this.#$.fill(0),this.#o.fill(0),this.#n.fill(0),this.#d.fill(0),this.#C.fill(0),this.#A.fill(0),this.#x=100,this.#s=[],this.#_=500,this.#z=0,this.#p=0,this.#i="",this.#b=0,this.#w=0,this.#h.fill(0),this.#a=!1,this.#q=0,this.#Q=!0,this.#H.forEach(function(t,s,i){i[s]=s}),this.buildRchTree(),e==0&&(this.#E.fill(0),this.#v.fill(0)),this.#e[l.cc*9]=v[0],this.#e[l.cc*25]=v[0],this.#e[l.cc*41]=v[0],this.#e[l.cc*57]=v[0],this.#Y.fill(0),this.#F.fill(0),this.#I.fill(0),this.#V.fill(0),this.#B.fill(0),this.#U.fill(0),this.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let t=0;t-1){if(this.#t==0||t){this.#t=s,this.#w=0,this.#k=G[0][s],this.#u=G[1][s];for(let i=0;i-1&&(this.#e[i*l.cc]=v[s]);switch(this.initOnReset,s){case E.mt32:{mt32DefProg.forEach((i,r)=>{let n=r+1;this.#y[n]||(this.#$[n]=i,this.#e[n*l.cc+h[91]]=127)});break}}this.dispatchEvent("mode",e)}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#d.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#K[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),s=!1;this.#X[t]?.forEach(i=>{e.channel=i,s=!0,this.#K[e.type].call(this,e)}),s||console.warn(`${H[e.type]?H[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${t+1} without any recipient.`)}this.#s.length>100&&this.#s.splice(100,this.#s.length-99)}runRaw(e){}constructor(){super();let e=this;this.#h=new Uint8Array(256),this.#g[10]=new Uint8Array(512),this.#T=new m,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -148,4 +148,4 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),this.#c[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#a=!0,this.#s.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#a=!0,this.#s.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#a=!0,this.#s.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#a=!0,this.#s.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#a=!0,this.#s.unshift(`Kara.Ver: ${t.slice(2)}`);break}case"XF":{let s=t.slice(2).split(":");switch(s[0]){case"hd":{s.slice(1).forEach((a,r)=>{a.length&&this.#s.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][r]}: ${a}`)});break}case"ln":{s.slice(1).forEach((a,r)=>{a.length&&this.#s.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][r]}: ${a}`)});break}default:this.#s.unshift(`XGF_Data: ${t}`)}break}default:this.#a?t[0]=="\\"?this.#s.unshift(`@ ${t.slice(1)}`):t[0]=="/"?this.#s.unshift(t.slice(1)):this.#s[0]+=t:(this.#s[0]=t,this.#s.unshift(""))}},this.#c[2]=function(t){this.#s.unshift(`Copyrite: ${t}`)},this.#c[3]=function(t,s){s<1&&this.#m<1&&this.#s.unshift(`TrkTitle: ${t}`)},this.#c[4]=function(t,s){this.#s.unshift(`${_(this.#m,""," ")}Instrmnt: ${t}`)},this.#c[5]=function(t){t.trim()==""?this.#s.unshift(""):this.#s[0]+=`${t}`},this.#c[6]=function(t){this.#s.unshift(`${_(this.#m,""," ")}C.Marker: ${t}`)},this.#c[7]=function(t){this.#s.unshift(`CuePoint: ${t}`)},this.#c[32]=function(t){this.#m=t[0]+1},this.#c[33]=function(t,s){console.debug(`Track ${s} requests to get assigned to output ${t}.`),e.#S[s]=t+1},this.#c[81]=function(t,s){e.#_=t/1e3},this.#c[127]=function(t,s){e.#T.run(t,s)},this.#T.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#T.add([67,0,1],function(t,s){e.#S[s]=t[0]+1}),this.#P=new m,this.#N=new m,this.#R=new m,this.#C=new m,this.#O=new m,this.#L=new m,this.#H=new m,this.#P.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#a=e.#a||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#N.add([4,1],t=>{e.#v=((t[1]<<7)+t[0])/16383*100}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#R.add([76,0,0],t=>{switch(t[0]){case 126:{e.switchMode("xg",!0),e.#a=!1,console.info("MIDI reset: XG");break}}}).add([76,6,0],t=>{let s=t[0];s<64?(e.#i=" ".repeat(s),e.#p=Date.now()+3200,t.subarray(1).forEach(function(a){e.#i+=String.fromCharCode(a)}),e.#i=e.#i.padEnd(32," ")):e.#p=Date.now()}).add([76,7,0],t=>{let s=t[0];e.#b=Date.now()+3200,e.#h.fill(0);let a=t.subarray(1);for(let r=0;r>6-f&1,f++})}),this.#R.add([43,7,0],(t,s,a)=>{e.#i=" ".repeat(offset),e.#p=Date.now()+3200,t.subarray(1).forEach(function(r){e.#i+=String.fromCharCode(r)}),e.#i=e.#i.padEnd(32," ")}).add([43,7,1],(t,s,a)=>{e.#b=Date.now()+3200,e.#h.fill(0),t.forEach(function(r,n){let i=Math.floor(n/16),l=n%16,c=(l*3+i)*7,u=7,f=0;for(c-=l*5,i==2&&(u=2);f>6-f&1,f++})}),this.#C.add([66,18,0,0,127],(t,s,a)=>{e.switchMode("gs",!0),e.#e[o.cc*9]=120,e.#e[o.cc*25]=120,e.#e[o.cc*41]=120,e.#e[o.cc*57]=120,e.#u=3,e.#a=!1,e.#w.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,s,a)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[o.cc*9]=120,e.#e[o.cc*25]=120,e.#e[o.cc*41]=120,e.#e[o.cc*57]=120,e.#a=!1,e.#w.fill(0),console.info("MIDI reset: GS");break}}}).add([69,18,16],t=>{switch(t[0]){case 0:{e.#p=Date.now()+3200;let s=t[1];e.#i=" ".repeat(s),t.subarray(2).forEach(function(a){a<128&&(e.#i+=String.fromCharCode(a))});break}case 32:{e.#b=Date.now()+3200,t[1]==0&&(e.#E=Math.max(Math.min(t[2]-1,9),0));break}default:if(t[0]<11){e.#b=Date.now()+3200,e.#g[t[0]-1]?.length||(e.#g[t[0]-1]=new Uint8Array(256));let s=e.#g[t[0]-1],a=t[1];s.fill(0);let r=t.subarray(2);for(let n=0;n>4-p&1,p++})}else console.warn(`Unknown GS display section: ${t[0]}`)}}),this.#C.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#a=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,32],t=>{e.switchMode("mt32");let s=t[1],a=" ".repeat(s);t.subarray(2).forEach(r=>{r>31&&(a+=String.fromCharCode(r))}),e.#i=a.padStart(20," "),e.#p=Date.now()+3200}).add([22,18,82],(t,s)=>{let a=e.chRedir(0,s,!0);for(let r=0;r<16;r++)e.#r.ano(a+r),r&&r<10&&(e.#$[a+r]=mt32DefProg[r-1]);console.info("MT-32 alt reset complete.")}),this.#O.add([66,0],(t,s)=>{e.switchMode("ns5r",!0),e.#a=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,s)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#a=!1}).add([66,18,0,0],(t,s)=>{switch(t[0]){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#a=!1;break}}}).add([66,18,8,0],(t,s)=>{}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let s=new Uint8Array(5760);korgFilter(t,(a,r,n)=>{if(r<720)for(let i=0;i<8;i++)s[r*8+i]=a>>7-i&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(t,s,a)=>{e.#O.run([66,...t],s,a)}),this.#L.add([16,0,8,0],(t,s,a)=>{let r=(t[2]<<4)+t[3],n="K11 ";([()=>{e.switchMode("k11",!0),e.#a=!1,e.#u=r?4:0,console.info("MIDI reset: GMega/K11")}][t[0]]||(()=>{}))()}),this.#H.add([66,93,64],(t,s,a)=>{let r=t[2];switch(t[0]){case 0:{switch(t[1]){case 127:{e.switchMode("sg",!0);break}}break}}})}};export{Ve as OctaviaDevice,o as allocated,h as ccToPos}; +122 006 000 `),this.#c[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#a=!0,this.#s.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#a=!0,this.#s.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#a=!0,this.#s.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#a=!0,this.#s.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#a=!0,this.#s.unshift(`Kara.Ver: ${t.slice(2)}`);break}case"XF":{let s=t.slice(2).split(":");switch(s[0]){case"hd":{s.slice(1).forEach((i,r)=>{i.length&&this.#s.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][r]}: ${i}`)});break}case"ln":{s.slice(1).forEach((i,r)=>{i.length&&this.#s.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][r]}: ${i}`)});break}default:this.#s.unshift(`XGF_Data: ${t}`)}break}default:this.#a?t[0]=="\\"?this.#s.unshift(`@ ${t.slice(1)}`):t[0]=="/"?this.#s.unshift(t.slice(1)):this.#s[0]+=t:(this.#s[0]=t,this.#s.unshift(""))}},this.#c[2]=function(t){this.#s.unshift(`Copyrite: ${t}`)},this.#c[3]=function(t,s){s<1&&this.#m<1&&this.#s.unshift(`TrkTitle: ${t}`)},this.#c[4]=function(t,s){this.#s.unshift(`${_(this.#m,""," ")}Instrmnt: ${t}`)},this.#c[5]=function(t){t.trim()==""?this.#s.unshift(""):this.#s[0]+=`${t}`},this.#c[6]=function(t){this.#s.unshift(`${_(this.#m,""," ")}C.Marker: ${t}`)},this.#c[7]=function(t){this.#s.unshift(`CuePoint: ${t}`)},this.#c[32]=function(t){this.#m=t[0]+1},this.#c[33]=function(t,s){console.debug(`Track ${s} requests to get assigned to output ${t}.`),e.#v[s]=t+1},this.#c[81]=function(t,s){e.#_=t/1e3},this.#c[127]=function(t,s){e.#T.run(t,s)},this.#T.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#T.add([67,0,1],function(t,s){e.#v[s]=t[0]+1}),this.#P=new m,this.#N=new m,this.#R=new m,this.#S=new m,this.#O=new m,this.#L=new m,this.#G=new m,this.#P.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#a=e.#a||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#N.add([4,1],t=>{e.#x=((t[1]<<7)+t[0])/16383*100}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#R.add([76,0,0],t=>{switch(t[0]){case 126:{e.switchMode("xg",!0),e.#a=!1,console.info("MIDI reset: XG");break}}}).add([76,6,0],t=>{let s=t[0];s<64?(e.#i=" ".repeat(s),e.#p=Date.now()+3200,t.subarray(1).forEach(function(i){e.#i+=String.fromCharCode(i)}),e.#i=e.#i.padEnd(32," ")):e.#p=Date.now()}).add([76,7,0],t=>{let s=t[0];e.#b=Date.now()+3200,e.#h.fill(0);let i=t.subarray(1);for(let r=0;r>6-f&1,f++})}),this.#R.add([43,7,0],(t,s,i)=>{e.#i=" ".repeat(offset),e.#p=Date.now()+3200,t.subarray(1).forEach(function(r){e.#i+=String.fromCharCode(r)}),e.#i=e.#i.padEnd(32," ")}).add([43,7,1],(t,s,i)=>{e.#b=Date.now()+3200,e.#h.fill(0),t.forEach(function(r,n){let a=Math.floor(n/16),o=n%16,c=(o*3+a)*7,u=7,f=0;for(c-=o*5,a==2&&(u=2);f>6-f&1,f++})}),this.#S.add([66,18,0,0,127],(t,s,i)=>{e.switchMode("gs",!0),e.#e[l.cc*9]=120,e.#e[l.cc*25]=120,e.#e[l.cc*41]=120,e.#e[l.cc*57]=120,e.#u=3,e.#a=!1,e.#E.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,s,i)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[l.cc*9]=120,e.#e[l.cc*25]=120,e.#e[l.cc*41]=120,e.#e[l.cc*57]=120,e.#a=!1,e.#E.fill(0),console.info("MIDI reset: GS");break}}}).add([69,18,16],t=>{switch(t[0]){case 0:{e.#p=Date.now()+3200;let s=t[1];e.#i=" ".repeat(s),t.subarray(2).forEach(function(i){i<128&&(e.#i+=String.fromCharCode(i))});break}case 32:{e.#b=Date.now()+3200,t[1]==0&&(e.#w=Math.max(Math.min(t[2]-1,9),0));break}default:if(t[0]<11){e.#b=Date.now()+3200,e.#g[t[0]-1]?.length||(e.#g[t[0]-1]=new Uint8Array(256));let s=e.#g[t[0]-1],i=t[1];s.fill(0);let r=t.subarray(2);for(let n=0;n>4-p&1,p++})}else console.warn(`Unknown GS display section: ${t[0]}`)}}),this.#S.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#a=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,32],t=>{e.switchMode("mt32");let s=t[1],i=" ".repeat(s);t.subarray(2).forEach(r=>{r>31&&(i+=String.fromCharCode(r))}),e.#i=i.padStart(20," "),e.#p=Date.now()+3200}).add([22,18,82],(t,s)=>{let i=e.chRedir(0,s,!0);for(let r=0;r<16;r++)e.#r.ano(i+r),r&&r<10&&(e.#$[i+r]=mt32DefProg[r-1]);console.info("MT-32 alt reset complete.")}),this.#O.add([66,0],(t,s)=>{e.switchMode("ns5r",!0),e.#a=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,s)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#a=!1}).add([66,18,0,0],(t,s)=>{switch(t[0]){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#a=!1;break}}}).add([66,18,8,0],(t,s)=>{}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let s=new Uint8Array(5760);korgFilter(t,(i,r,n)=>{if(r<720)for(let a=0;a<8;a++)s[r*8+a]=i>>7-a&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(t,s,i)=>{e.#O.run([66,...t],s,i)}),this.#L.add([16,0,8,0],(t,s,i)=>{let r=(t[2]<<4)+t[3],n="K11 ";([()=>{e.switchMode("k11",!0),e.#a=!1,e.#u=r?4:0,console.info("MIDI reset: GMega/K11")}][t[0]]||(()=>{}))()}),this.#G.add([66,93,64],(t,s,i)=>{let r=t[2];switch(t[0]){case 0:{switch(t[1]){case 127:{e.switchMode("sg",!0);break}}break}}})}};export{Fe as OctaviaDevice,l as allocated,h as ccToPos}; diff --git a/dist/xp_basic.mjs b/dist/xp_basic.mjs index af7a6218..e26b9ca2 100644 --- a/dist/xp_basic.mjs +++ b/dist/xp_basic.mjs @@ -1,8 +1,8 @@ -var oa=Object.create;var ut=Object.defineProperty;var la=Object.getOwnPropertyDescriptor;var da=Object.getOwnPropertyNames;var fa=Object.getPrototypeOf,ha=Object.prototype.hasOwnProperty;var ua=(u,e,s)=>e in u?ut(u,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):u[e]=s;var Rt=(u,e)=>()=>(u&&(e=u(u=0)),e);var pa=(u,e)=>()=>(e||u((e={exports:{}}).exports,e),e.exports);var ba=(u,e,s,h)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of da(e))!ha.call(u,o)&&o!==s&&ut(u,o,{get:()=>e[o],enumerable:!(h=la(e,o))||h.enumerable});return u};var ga=(u,e,s)=>(s=u!=null?oa(fa(u)):{},ba(e||!u||!u.__esModule?ut(s,"default",{value:u,enumerable:!0}):s,u));var C=(u,e,s)=>(ua(u,typeof e!="symbol"?e+"":e,s),s),Ot=(u,e,s)=>{if(!e.has(u))throw TypeError("Cannot "+s)};var t=(u,e,s)=>(Ot(u,e,"read from private field"),s?s.call(u):e.get(u)),v=(u,e,s)=>{if(e.has(u))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(u):e.set(u,s)},E=(u,e,s,h)=>(Ot(u,e,"write to private field"),h?h.call(u,s):e.set(u,s),s);var Dt=Rt(()=>{"use strict";R();(function(){var u=function(c,n,i){var f,l;if(self.MessageEvent)switch(c){case"message":{l=new MessageEvent(c,{data:n,ports:i==null?void 0:i.ports}),Object.defineProperty(l,"source",{value:i==null?void 0:i.source});break}default:l=new Event(c)}else l=document.createEvent("Event"),l.initEvent(c,!1,!1),i&&c=="message"&&(l.data=n,i.source&&Object.defineProperty(l,"source",{value:i.source}),(f=i.ports)!=null&&f.length&&Object.defineProperty(l,"ports",{value:i.ports}));return l};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),s=[],h={},o=function(c){var n,i=this;if((this==null?void 0:this.constructor)!=o)throw new TypeError("Illegal constructor");s.push(this),(n=h[c])!=null&&n.constructor||(h[c]=[]),h[c].push(this);var f=Math.floor(Math.random()*281474976710656),l=[],d=0,p=[],y=!0,$=!1;Object.defineProperty(this,"id",{get:function(){return f}}),Object.defineProperty(this,"name",{value:c}),this.close=function(){var w,T=s.indexOf(i);T>-1?(e.postMessage({t:"d",c,i:f}),s.splice(T,1),(w=h[c])!=null&&w.constructor&&(T=h[c].indexOf(i),T>-1&&h[c].splice(T,1)),h[c].length||delete h[c],console.debug("[Snowy] BroadcastChannel closed."),$=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(w){if(e){if($)throw new Error("Channel already closed");e.postMessage({t:"m",c,i:f,m:d,d:w}),d++,d>4294967295&&(d=0)}else p.push(w),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(y){for(e.postMessage({t:"r",c,i:f}),console.debug("[Snowy] ".concat(p.length," message(s) in cache."));p.length;){var w=p.shift();i.postMessage(w)}y=!1,console.debug("[Snowy] All cached messages are flushed away.")}}else throw new Error("Tried to flush when the ports are not ready")},this.receiveMessage=function(w){w.c==c?w.i!=f&&i.dispatchEvent(u("message",w.d,{source:i})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(f," receives from ").concat(c,", not ").concat(w.c,"."))};var k={};this.dispatchEvent=function(w){var T,A;if(Object.defineProperty(w,"target",{value:i}),Object.defineProperty(w,"currentTarget",{value:i}),(T=k[w.type])!=null&&T.length)for(var V=k[w.type],ie=0;ie-1&&k[w].splice(ie,1)}!((V=k[w])!=null&&V.length)&&k[w].constructor&&delete k[w]}},self.BroadcastChannel=o,a=function(){if(e){e.addEventListener("message",function(n){var i=n.data,f=!1;switch(i.t){case"k":{f=!1,e.postMessage({t:"k"});break}case"m":{var l=h[i.c];if(l!=null&&l.length)for(var d=0;d{"use strict";Dt();{let u=function(e,s){let h=new FileReader;return new Promise((o,a)=>{switch(h.addEventListener("abort",()=>{a(new Error("Blob read aborted"))}),h.addEventListener("error",r=>{a(h.error||r.data||new Error("Blob read error"))}),h.addEventListener("load",()=>{o(h.result)}),s.toLowerCase()){case"arraybuffer":case"buffer":{h.readAsArrayBuffer(e);break}case"string":case"text":{h.readAsText(e);break}default:a(new Error(`Unknown target ${s}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return u(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return u(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(u,e){let s=0,h=16,o=this,a=[];for(;s-1;){let r=o.lastIndexOf(u);a.unshift(o.slice(r+u.length)),o=o.slice(0,r),r==0&&a.unshift(""),s++}return o.length&&a.unshift(o),a.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(u,e){if(e){let s=this;for(;s.length{R();(function(){"use strict";let u={fatal:!0},e=[new TextDecoder("iso-8859-15",u),new TextDecoder("sjis",u),new TextDecoder("euc-jp",u),new TextDecoder("utf-8",u),new TextDecoder("utf-16",u),new TextDecoder("ascii")],s={debug:!1,parse:function(h,o){if(h instanceof Uint8Array)return s.Uint8(h);if(typeof h=="string")return s.Base64(h);if(h instanceof HTMLElement&&h.type==="file")return s.addListener(h,o);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(h,o){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(h===void 0||!(h instanceof HTMLElement)||h.tagName!=="INPUT"||h.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;o=o||function(){},h.addEventListener("change",function(a){if(!a.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let r=new FileReader;r.readAsArrayBuffer(a.target.files[0]),r.onload=function(c){o(s.Uint8(new Uint8Array(c.target.result)))}})},Base64:function(h){let o=function(c){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(c=c.replace(/^.*?base64,/,""),c=String(c).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(c))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");c+="==".slice(2-(3&c.length));let i,f="",l,d,p=0;for(;p>16&255):d===64?String.fromCharCode(i>>16&255,i>>8&255):String.fromCharCode(i>>16&255,i>>8&255,255&i);return f}(h=String(h));var a=o.length;let r=new Uint8Array(new ArrayBuffer(a));for(let c=0;c{d[k]=this.readInt(1)});for(let $=0;$191||w>127&&w<160)throw new RangeError(`Invalid code point: ${w}`)}p=!0,console.debug(`String byte sequence in ${e[$].encoding}`)}catch(k){console.debug(`SMF string ${k}`)}return y||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let l=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)l=this.readInt(1);else{let p=[];for(;128<=this.data.getUint8(this.pointer);)p.push(this.readInt(1)-128);var d=this.readInt(1);for(let y=1;y<=p.length;y++)l+=p[p.length-y]*Math.pow(128,y);l+=d}return l}};if(o.data=new DataView(r.buffer,r.byteOffset,r.byteLength),o.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;o.readInt(4);let a={};a.formatType=o.readInt(2),a.tracks=o.readInt(2),a.track=[];var r=o.readInt(1),c=o.readInt(1);128<=r?(a.timeDivision=[],a.timeDivision[0]=r-128,a.timeDivision[1]=c):a.timeDivision=256*r+c;for(let l=1;l<=a.tracks;l++){a.track[l-1]={event:[]};var n,i=o.readInt(4);if(i===-1)break;if(i!==1297379947)return!1;o.readInt(4);let d=0,p=!1,y,$;for(;!p&&(d++,a.track[l-1].event[d-1]={},a.track[l-1].event[d-1].deltaTime=o.readIntVLV(),(y=o.readInt(1))!==-1);)if(128<=y?$=y:(y=$,o.movePointer(-1)),y===255){a.track[l-1].event[d-1].type=255,a.track[l-1].event[d-1].metaType=o.readInt(1);var f=o.readIntVLV();switch(a.track[l-1].event[d-1].metaType){case 47:case-1:p=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:a.track[l-1].event[d-1].data=o.readStr(f);break;case 33:case 89:case 81:a.track[l-1].event[d-1].data=o.readInt(f);break;case 84:a.track[l-1].event[d-1].data=[],a.track[l-1].event[d-1].data[0]=o.readInt(1),a.track[l-1].event[d-1].data[1]=o.readInt(1),a.track[l-1].event[d-1].data[2]=o.readInt(1),a.track[l-1].event[d-1].data[3]=o.readInt(1),a.track[l-1].event[d-1].data[4]=o.readInt(1);break;case 88:a.track[l-1].event[d-1].data=[],a.track[l-1].event[d-1].data[0]=o.readInt(1),a.track[l-1].event[d-1].data[1]=o.readInt(1),a.track[l-1].event[d-1].data[2]=o.readInt(1),a.track[l-1].event[d-1].data[3]=o.readInt(1);break;default:this.customInterpreter!==null&&(a.track[l-1].event[d-1].data=this.customInterpreter(a.track[l-1].event[d-1].metaType,o,f)),this.customInterpreter!==null&&a.track[l-1].event[d-1].data!==!1||(o.readInt(f),a.track[l-1].event[d-1].data=o.readInt(f),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((y=y.toString(16).split(""))[1]||y.unshift("0"),a.track[l-1].event[d-1].type=parseInt(y[0],16),a.track[l-1].event[d-1].channel=parseInt(y[1],16),a.track[l-1].event[d-1].type){case 15:this.customInterpreter!==null&&(a.track[l-1].event[d-1].data=this.customInterpreter(a.track[l-1].event[d-1].type,o,!1)),this.customInterpreter!==null&&a.track[l-1].event[d-1].data!==!1||(n=o.readIntVLV(),a.track[l-1].event[d-1].data=o.readInt(n),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:a.track[l-1].event[d-1].data=[],a.track[l-1].event[d-1].data[0]=o.readInt(1),a.track[l-1].event[d-1].data[1]=o.readInt(1);break;case 12:case 13:a.track[l-1].event[d-1].data=o.readInt(1);break;case-1:p=!0;break;default:if(this.customInterpreter!==null&&(a.track[l-1].event[d-1].data=this.customInterpreter(a.track[l-1].event[d-1].metaType,o,!1)),this.customInterpreter===null||a.track[l-1].event[d-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return a},customInterpreter:null};if(typeof St<"u")St.exports=s;else{let h=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;h.MidiParser=s}})()});R();R();var K,Pt,ot=(Pt=class{constructor(){v(this,K,{})}addEventListener(u,e){t(this,K)[u]||(t(this,K)[u]=[]),t(this,K)[u].unshift(e)}removeEventListener(u,e){if(t(this,K)[u]){let s=t(this,K)[u].indexOf(e);s>-1&&t(this,K)[u].splice(s,1),t(this,K)[u].length<1&&delete t(this,K)[u]}}dispatchEvent(u,e){var o;let s=new Event(u),h=this;s.data=e,((o=t(this,K)[u])==null?void 0:o.length)>0&&t(this,K)[u].forEach(function(a){try{a==null||a.call(h,s)}catch(r){console.error(r)}}),this[`on${u}`]&&this[`on${u}`](s)}},K=new WeakMap,Pt);R();R();var It=function(u,e){let s=Math.min(u.length,e.length),h=u.slice(0,s),o=e.slice(0,s),a=0,r=0;for(;r0){let h=this.pool.length,o=1<=1&&r>=0;){if(r<=0)throw new Error("TTL reached.");if(a==h)a-=o;else{let n=It(e,this.pool[a]);switch(n){case 0:{r=0;break}case 1:{a+o<=h&&(a+=o);break}case-1:{a!=0&&(a-=o);break}default:console.warn(`Unexpected result ${n}.`)}}o=o>>1,r--}let c=!0;if(a>=this.pool.length)c=!1;else{let n=this;this.pool[a].forEach(function(i,f,l){c&&i!=e[f]&&(c=!1)}),!c&&It(e,this.pool[a])>0&&a++}return c||s?a:-1}else return s?0:-1},this.add=function(e,s){return e.data=s,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match in "${this.name||"(unknown)"}" for "${e}". Default action not defined.`)},this.get=function(e){let s=this.point(e);if(s>-1)return this.pool[s].data;this.default(e)},this.run=function(e,...s){let h=this.point(e);h>-1?e.subarray?this.pool[h].data(e.subarray(this.pool[h].length),...s):this.pool[h].data(e.slice(this.pool[h].length),...s):this.default(e,...s)}};R();var ya=["MSB","PRG","LSB"],pt=function(u){let e=Math.floor(u/10),s=u%10;return`${e.toString(16)}${s}`},z,At,bt=(At=class{constructor(...u){v(this,z,void 0);C(this,"strictMode",!1);this.loadFiles(...u)}get(u=0,e=0,s=0,h){let o=[u,e,s],a,r=Array.from(arguments);switch(h){case"xg":{switch(u){case 0:{s==126?r[2]=125:s==127&&(r[2]=0);break}case 32:{r[2]+=4;break}case 33:case 35:case 36:{r[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:r[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{s==126&&(r[2]=0);break}case 48:case 64:case 126:case 127:{s==126&&(r[2]=0);break}}break}case"gs":{u==0&&s<5?r[2]=0:u>125&&s<5&&s!=2&&(r[2]=u,r[0]=0);break}case"g2":case"sd":{(u>>1==40||u>95&&u<100)&&(r[2]|=16);break}case"sg":{u==8&&s==0&&(r[2]=5);break}case"s90es":{s<8?r[2]+=17:s<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}case"motif":{s<8?r[2]+=28:s<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}}let c=" ",n="M",i=0,f=0;switch(r[0]){case 0:{r[2]==127?n="MT-a":r[2]==126?n="MT-b":r[2]==7?n="GM-k":r[2]==5?n="SG-a":r[2]==4?n="SP-l":r[2]==0||h=="gs"&&r[2]<5?n="GM-a":(n="y",i=3);break}case 8:{h=="sg"?n="GM-s":n="r:";break}case 48:{n=`yM${(r[2]>>3).toString().padStart(2,"0")}`,i=1;break}case 56:{n="GM-b";break}case 61:case 120:{n="rDrm";break}case 62:{n="kDrm";break}case 63:{if(r[2]<17){let y=r[2];n=y<10?"kP:":"kC:",n+=y%10}else r[2]<34?n=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][r[2]-17]:n="Ds";break}case 64:{n="ySFX";break}case 67:{n="DX:S";break}case 80:case 81:case 82:case 83:{n=`Prg${"UABC"[r[0]-80]}`;break}case 88:case 89:case 90:case 91:{n=`Cmb${"UABC"[r[0]-88]}`;break}case 95:{n=`${["DR","PC"][r[2]]}-d`;break}case 96:{n=r[2]==106?"AP-a":r[2]>>4==1?"SDg":"PF",r[2]>63?f=63:r[2]>>4==1&&(f=16),i=3;break}case 97:{n=r[2]>>4==1?"SDa":"VL:",i=3,r[2]>>4==1?f=16:f=112;break}case 98:{n=r[2]>>4==1?"SDb":"SG-a",i=3,f=16;break}case 99:{n=r[2]>>4==1?"SDc":"DX",r[2]>63?f=63:r[2]>>4==1&&(f=16),i=3;break}case 100:{n="AN",r[2]>63?f=63:r[2]>>4==1&&(f=16),i=3;break}case 104:case 105:case 106:case 107:{n="SDd",f=104;break}case 121:{n=`GM-${r[2]?"":"a"}`,i=3;break}case 122:{n="lDrm";break}case 126:{n="yDrS";break}case 127:{r[2]==127?n="rDrm":n="yDrm";break}default:r[0]<48?n="r:":n="M"}n.length<4&&(n+=`${[u,s,r[0],r[2]][i]-f}`.padStart(4-n.length,"0")),h=="xg"&&u==16&&(a=`Voice${(s*128+e+1).toString().padStart(3,"0")}`,c=" ");let l=[r[0],r[1],r[2]];for(;!((a==null?void 0:a.length)>=0);)a=t(this,z)[r[1]||0][(r[0]<<7)+r[2]],a||(this.strictMode?(a="",c="?"):t(this,z)[r[1]||0][r[0]<<7]?r[0]==0?(r[2]=0,c="^"):r[2]<1?(r[0]=0,c="*"):(r[2]--,c="^"):u==48?(r[0]=0,r[2]=0,c="!"):u==62?(r[1]--,c=" ",r[1]<1&&!(a!=null&&a.length)&&(r[0]=0,c="!")):u<63?r[0]==0?(r[2]=0,c="^"):r[2]<1?(r[0]=0,c="*"):r[2]--:u==80?(a=`PrgU:${e.toString().padStart(3,"0")}`,c="!"):u==88?(a=`CmbU:${e.toString().padStart(3,"0")}`,c="!"):u==121?(a=`GM2Vox0${s}`,c="#"):u==122?(r[1]==32?r[1]==0:r[1]%=7,a=t(this,z)[r[1]||0][(r[0]<<7)+r[2]],a?c=" ":(a="",c="*")):r[1]==0?(a=`${u.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${s.toString().padStart(3,"0")}`,c="!"):r[0]==0?(r[2]=0,c="^"):r[2]>0?r[2]--:r[1]>0?(r[1]=0,c="!"):(r[0]=0,c="?"));let d=[r[0],r[1],r[2]];(h=="gs"||h=="ns5r")&&c=="^"&&(c=" "),u==127&&c=="^"&&(c=" "),c!=" "&&self.debugMode&&(a="");let p="??";switch(r[0]){case 0:{r[2]==0?p="GM":r[2]==5||r[2]==7?p="KG":r[2]<126?p="XG":r[2]==127&&(p="MT");break}case 48:{p="MU";break}case 56:{p="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{p="AI";break}case 62:case 82:case 90:{p="XD";break}case 63:{r[2]<17?p="KR":r[2]<34?p="ES":p="DS";break}case 64:case 126:{p="XG";break}case 67:case 99:{p=r[2]>>4==1?"SD":"DX";break}case 81:{p="RW";break}case 95:{p=["DR","PC"][r[2]];break}case 96:{p=r[2]==106?"AP":r[2]>>4==1?"SD":"PF";break}case 97:{p=r[2]>>4==1?"SD":"VL";break}case 98:{p=r[2]>>4==1?"SD":"SG";break}case 100:{p="AN";break}case 104:case 105:case 106:case 107:{p="SD";break}case 120:{p="GS";break}case 121:{p=r[2]?"G2":"GM";break}case 122:{p="KG";break}case 127:{p=r[2]==127?"MT":e==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&h=="xg"?p="XG":p="GS")}return{name:a||`${pt(u||0)} ${pt(e||0)} ${pt(s||0)}`,iid:l,eid:d,sid:o,ending:c,sect:n,standard:p}}async load(u,e,s){let h=this,o=[],a=0,r=0;u.split(` -`).forEach(function(c,n){let i=c.split(" "),f=[];n==0?i.forEach(function(l,d){o[ya.indexOf(l)]=d}):i.forEach(async function(l,d){var p;d>2?(t(h,z)[f[o[1]]]=t(h,z)[f[o[1]]]||[],(!((p=t(h,z)[f[o[1]]][(f[o[0]]<<7)+f[o[2]]])!=null&&p.length)||e)&&(t(h,z)[f[o[1]]][(f[o[0]]<<7)+f[o[2]]]=i[3],a++),r++):f.push(parseInt(i[d]))})}),e||console.debug(`Map "${s||"(internal)"}": ${r} total, ${a} loaded.`)}clearRange(u){let e=u.prg!=null?u.prg.constructor==Array?u.prg:[u.prg,u.prg]:[0,127],s=u.msb!=null?u.msb.constructor==Array?u.msb:[u.msb,u.msb]:[0,127],h=u.lsb!=null?u.lsb.constructor==Array?u.lsb:[u.lsb,u.lsb]:[0,127];for(let o=s[0];o<=s[1];o++){let a=o<<7;for(let r=h[0];r<=h[1];r++){let c=a+r;for(let n=e[0];n<=e[1];n++)delete t(this,z)[n][c]}}}init(){E(this,z,[]);for(let u=0;u<128;u++)t(this,z).push([""])}async loadFiles(...u){this.init();let e=this;u.forEach(async function(s,h){try{await fetch(`./data/bank/${s}.tsv`).then(function(o){return o.text()}).then(o=>{e.load(o,!1,s)})}catch(o){console.error(`Failed loading "${s}.tsv".`)}})}},z=new WeakMap,At);R();R();var Xe,Ut,Lt=(Ut=class{constructor(){v(this,Xe,{});C(this,"context")}set(u,e){t(this,Xe)[u]=e}has(u){return!!t(this,Xe)[u]}async read(u,e){if(!this.has(u))throw new Error(`No decoder registered for "${u}"`);return await t(this,Xe)[u].call(this.context||this,e)}},Xe=new WeakMap,Ut);var ma=function(u,e){let s=!0;return e.forEach((h,o)=>{s=s&&u[o]==h}),s},Bt=function(u){let e=0;return u.forEach(s=>{e*=256,e+=s}),e},Ze=new TextDecoder,lt=new Lt;lt.set("s7e",async function(u){let e=new Uint8Array(await u.slice(0,65536).arrayBuffer()),s="MSB LSB PRG NME",h=[0,0,0,0],o=32,a=0,r=0,c=!0,n=[],i=0;for(;c;){let f=e.subarray(a);([()=>{Ze.decode(f.subarray(0,4))=="YSFC"?(a+=80,r=1):a++},()=>{if(ma(f.subarray(0,4),h))n.forEach((l,d,p)=>{let y=Bt(e.subarray(l.start+4,l.start+8));l.length=y}),r=2;else{let l=Ze.decode(f.subarray(0,4)),d=Bt(f.subarray(4,8));n.push({type:l,start:d}),a+=8}},()=>{let l=n[i],d=e.subarray(l.start,l.start+l.length),p=32;switch(l.type){case"ENVC":{let y=o;for(;y=n.length&&(r=3,c=!1)}][r]||(()=>{c=!1}))()}return s});R();var Je=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),et=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],Ea=[17.1,18.6,20.2,21.8,23.3,24.9,26.5,28,29.6,31.2,32.8,34.3,35.9,37.5,39,40.6,42.2,43.7,45.3,46.9,48.4,50],Fe=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],Nt=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],Ht=function(u){let e=.1,s=-.3;return u>66?(e=5,s=315):u>56?(e=1,s=47):u>46&&(e=.5,s=18.5),e*u-s},Gt=function(u){return u>105?Ea[u-106]:u>100?u*1.1-100:u/10},_t=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),gt={};`hi*, +var la=Object.create;var bt=Object.defineProperty;var da=Object.getOwnPropertyDescriptor;var fa=Object.getOwnPropertyNames;var ha=Object.getPrototypeOf,ua=Object.prototype.hasOwnProperty;var pa=(b,e,r)=>e in b?bt(b,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):b[e]=r;var Rt=(b,e)=>()=>(b&&(e=b(b=0)),e);var ba=(b,e)=>()=>(e||b((e={exports:{}}).exports,e),e.exports);var ga=(b,e,r,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of fa(e))!ua.call(b,c)&&c!==r&&bt(b,c,{get:()=>e[c],enumerable:!(d=da(e,c))||d.enumerable});return b};var ya=(b,e,r)=>(r=b!=null?la(ha(b)):{},ga(e||!b||!b.__esModule?bt(r,"default",{value:b,enumerable:!0}):r,b));var M=(b,e,r)=>(pa(b,typeof e!="symbol"?e+"":e,r),r),Ot=(b,e,r)=>{if(!e.has(b))throw TypeError("Cannot "+r)};var t=(b,e,r)=>(Ot(b,e,"read from private field"),r?r.call(b):e.get(b)),S=(b,e,r)=>{if(e.has(b))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(b):e.set(b,r)},w=(b,e,r,d)=>(Ot(b,e,"write to private field"),d?d.call(b,r):e.set(b,r),r);var Dt=Rt(()=>{"use strict";O();(function(){var b=function(m,a,n){var l,i;if(self.MessageEvent)switch(m){case"message":{i=new MessageEvent(m,{data:a,ports:n==null?void 0:n.ports}),Object.defineProperty(i,"source",{value:n==null?void 0:n.source});break}default:i=new Event(m)}else i=document.createEvent("Event"),i.initEvent(m,!1,!1),n&&m=="message"&&(i.data=a,n.source&&Object.defineProperty(i,"source",{value:n.source}),(l=n.ports)!=null&&l.length&&Object.defineProperty(i,"ports",{value:n.ports}));return i};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),r=[],d={},c=function(m){var a,n=this;if((this==null?void 0:this.constructor)!=c)throw new TypeError("Illegal constructor");r.push(this),(a=d[m])!=null&&a.constructor||(d[m]=[]),d[m].push(this);var l=Math.floor(Math.random()*281474976710656),i=[],s=0,o=[],f=!0,u=!1;Object.defineProperty(this,"id",{get:function(){return l}}),Object.defineProperty(this,"name",{value:m}),this.close=function(){var E,k=r.indexOf(n);k>-1?(e.postMessage({t:"d",c:m,i:l}),r.splice(k,1),(E=d[m])!=null&&E.constructor&&(k=d[m].indexOf(n),k>-1&&d[m].splice(k,1)),d[m].length||delete d[m],console.debug("[Snowy] BroadcastChannel closed."),u=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(E){if(e){if(u)throw new Error("Channel already closed");e.postMessage({t:"m",c:m,i:l,m:s,d:E}),s++,s>4294967295&&(s=0)}else o.push(E),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(f){for(e.postMessage({t:"r",c:m,i:l}),console.debug("[Snowy] ".concat(o.length," message(s) in cache."));o.length;){var E=o.shift();n.postMessage(E)}f=!1,console.debug("[Snowy] All cached messages are flushed away.")}}else throw new Error("Tried to flush when the ports are not ready")},this.receiveMessage=function(E){E.c==m?E.i!=l&&n.dispatchEvent(b("message",E.d,{source:n})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(l," receives from ").concat(m,", not ").concat(E.c,"."))};var g={};this.dispatchEvent=function(E){var k,C;if(Object.defineProperty(E,"target",{value:n}),Object.defineProperty(E,"currentTarget",{value:n}),(k=g[E.type])!=null&&k.length)for(var A=g[E.type],_=0;_-1&&g[E].splice(_,1)}!((A=g[E])!=null&&A.length)&&g[E].constructor&&delete g[E]}},self.BroadcastChannel=c,p=function(){if(e){e.addEventListener("message",function(a){var n=a.data,l=!1;switch(n.t){case"k":{l=!1,e.postMessage({t:"k"});break}case"m":{var i=d[n.c];if(i!=null&&i.length)for(var s=0;s{"use strict";Dt();{let b=function(e,r){let d=new FileReader;return new Promise((c,p)=>{switch(d.addEventListener("abort",()=>{p(new Error("Blob read aborted"))}),d.addEventListener("error",h=>{p(d.error||h.data||new Error("Blob read error"))}),d.addEventListener("load",()=>{c(d.result)}),r.toLowerCase()){case"arraybuffer":case"buffer":{d.readAsArrayBuffer(e);break}case"string":case"text":{d.readAsText(e);break}default:p(new Error(`Unknown target ${r}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return b(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return b(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(b,e){let r=0,d=16,c=this,p=[];for(;r-1;){let h=c.lastIndexOf(b);p.unshift(c.slice(h+b.length)),c=c.slice(0,h),h==0&&p.unshift(""),r++}return c.length&&p.unshift(c),p.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(b,e){if(e){let r=this;for(;r.length{O();(function(){"use strict";let b={fatal:!0},e=[new TextDecoder("iso-8859-15",b),new TextDecoder("sjis",b),new TextDecoder("euc-jp",b),new TextDecoder("utf-8",b),new TextDecoder("utf-16",b),new TextDecoder("ascii")],r={debug:!1,parse:function(d,c){if(d instanceof Uint8Array)return r.Uint8(d);if(typeof d=="string")return r.Base64(d);if(d instanceof HTMLElement&&d.type==="file")return r.addListener(d,c);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(d,c){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(d===void 0||!(d instanceof HTMLElement)||d.tagName!=="INPUT"||d.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;c=c||function(){},d.addEventListener("change",function(p){if(!p.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let h=new FileReader;h.readAsArrayBuffer(p.target.files[0]),h.onload=function(m){c(r.Uint8(new Uint8Array(m.target.result)))}})},Base64:function(d){let c=function(m){var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(m=m.replace(/^.*?base64,/,""),m=String(m).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(m))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");m+="==".slice(2-(3&m.length));let n,l="",i,s,o=0;for(;o>16&255):s===64?String.fromCharCode(n>>16&255,n>>8&255):String.fromCharCode(n>>16&255,n>>8&255,255&n);return l}(d=String(d));var p=c.length;let h=new Uint8Array(new ArrayBuffer(p));for(let m=0;m{s[g]=this.readInt(1)});for(let u=0;u191||E>127&&E<160)throw new RangeError(`Invalid code point: ${E}`)}o=!0,console.debug(`String byte sequence in ${e[u].encoding}`)}catch(g){console.debug(`SMF string ${g}`)}return f||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let i=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)i=this.readInt(1);else{let o=[];for(;128<=this.data.getUint8(this.pointer);)o.push(this.readInt(1)-128);var s=this.readInt(1);for(let f=1;f<=o.length;f++)i+=o[o.length-f]*Math.pow(128,f);i+=s}return i}};if(c.data=new DataView(h.buffer,h.byteOffset,h.byteLength),c.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;c.readInt(4);let p={};p.formatType=c.readInt(2),p.tracks=c.readInt(2),p.track=[];var h=c.readInt(1),m=c.readInt(1);128<=h?(p.timeDivision=[],p.timeDivision[0]=h-128,p.timeDivision[1]=m):p.timeDivision=256*h+m;for(let i=1;i<=p.tracks;i++){p.track[i-1]={event:[]};var a,n=c.readInt(4);if(n===-1)break;if(n!==1297379947)return!1;c.readInt(4);let s=0,o=!1,f,u;for(;!o&&(s++,p.track[i-1].event[s-1]={},p.track[i-1].event[s-1].deltaTime=c.readIntVLV(),(f=c.readInt(1))!==-1);)if(128<=f?u=f:(f=u,c.movePointer(-1)),f===255){p.track[i-1].event[s-1].type=255,p.track[i-1].event[s-1].metaType=c.readInt(1);var l=c.readIntVLV();switch(p.track[i-1].event[s-1].metaType){case 47:case-1:o=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:p.track[i-1].event[s-1].data=c.readStr(l);break;case 33:case 89:case 81:p.track[i-1].event[s-1].data=c.readInt(l);break;case 84:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=c.readInt(1),p.track[i-1].event[s-1].data[1]=c.readInt(1),p.track[i-1].event[s-1].data[2]=c.readInt(1),p.track[i-1].event[s-1].data[3]=c.readInt(1),p.track[i-1].event[s-1].data[4]=c.readInt(1);break;case 88:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=c.readInt(1),p.track[i-1].event[s-1].data[1]=c.readInt(1),p.track[i-1].event[s-1].data[2]=c.readInt(1),p.track[i-1].event[s-1].data[3]=c.readInt(1);break;default:this.customInterpreter!==null&&(p.track[i-1].event[s-1].data=this.customInterpreter(p.track[i-1].event[s-1].metaType,c,l)),this.customInterpreter!==null&&p.track[i-1].event[s-1].data!==!1||(c.readInt(l),p.track[i-1].event[s-1].data=c.readInt(l),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((f=f.toString(16).split(""))[1]||f.unshift("0"),p.track[i-1].event[s-1].type=parseInt(f[0],16),p.track[i-1].event[s-1].channel=parseInt(f[1],16),p.track[i-1].event[s-1].type){case 15:this.customInterpreter!==null&&(p.track[i-1].event[s-1].data=this.customInterpreter(p.track[i-1].event[s-1].type,c,!1)),this.customInterpreter!==null&&p.track[i-1].event[s-1].data!==!1||(a=c.readIntVLV(),p.track[i-1].event[s-1].data=c.readInt(a),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=c.readInt(1),p.track[i-1].event[s-1].data[1]=c.readInt(1);break;case 12:case 13:p.track[i-1].event[s-1].data=c.readInt(1);break;case-1:o=!0;break;default:if(this.customInterpreter!==null&&(p.track[i-1].event[s-1].data=this.customInterpreter(p.track[i-1].event[s-1].metaType,c,!1)),this.customInterpreter===null||p.track[i-1].event[s-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return p},customInterpreter:null};if(typeof xt<"u")xt.exports=r;else{let d=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;d.MidiParser=r}})()});O();O();var j,At,dt=(At=class{constructor(){S(this,j,{})}addEventListener(b,e){t(this,j)[b]||(t(this,j)[b]=[]),t(this,j)[b].unshift(e)}removeEventListener(b,e){if(t(this,j)[b]){let r=t(this,j)[b].indexOf(e);r>-1&&t(this,j)[b].splice(r,1),t(this,j)[b].length<1&&delete t(this,j)[b]}}dispatchEvent(b,e){var c;let r=new Event(b),d=this;r.data=e,((c=t(this,j)[b])==null?void 0:c.length)>0&&t(this,j)[b].forEach(function(p){try{p==null||p.call(d,r)}catch(h){console.error(h)}}),this[`on${b}`]&&this[`on${b}`](r)}},j=new WeakMap,At);O();O();var Pt=function(b,e){let r=Math.min(b.length,e.length),d=b.slice(0,r),c=e.slice(0,r),p=0,h=0;for(;h0){let d=this.pool.length,c=1<=1&&h>=0;){if(h<=0)throw new Error("TTL reached.");if(p==d)p-=c;else{let a=Pt(e,this.pool[p]);switch(a){case 0:{h=0;break}case 1:{p+c<=d&&(p+=c);break}case-1:{p!=0&&(p-=c);break}default:console.warn(`Unexpected result ${a}.`)}}c=c>>1,h--}let m=!0;if(p>=this.pool.length)m=!1;else{let a=this;this.pool[p].forEach(function(n,l,i){m&&n!=e[l]&&(m=!1)}),!m&&Pt(e,this.pool[p])>0&&p++}return m||r?p:-1}else return r?0:-1},this.add=function(e,r){return e.data=r,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match in "${this.name||"(unknown)"}" for "${e}". Default action not defined.`)},this.get=function(e){let r=this.point(e);if(r>-1)return this.pool[r].data;this.default(e)},this.run=function(e,...r){let d=this.point(e);d>-1?e.subarray?this.pool[d].data(e.subarray(this.pool[d].length),...r):this.pool[d].data(e.slice(this.pool[d].length),...r):this.default(e,...r)}};O();var va=["MSB","PRG","LSB"],gt=function(b){let e=Math.floor(b/10),r=b%10;return`${e.toString(16)}${r}`},Q,It,yt=(It=class{constructor(...b){S(this,Q,void 0);M(this,"strictMode",!1);this.loadFiles(...b)}get(b=0,e=0,r=0,d){let c=[b,e,r],p,h=Array.from(arguments);switch(d){case"xg":{switch(b){case 0:{r==126?h[2]=125:r==127&&(h[2]=0);break}case 16:{r==126&&(h[2]=0);break}case 32:{h[2]+=4;break}case 33:case 35:case 36:{h[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:h[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{r==126&&(h[2]=0);break}case 48:case 64:case 126:case 127:{r==126&&(h[2]=0);break}}break}case"gs":{b==0&&r<5?h[2]=0:b>125&&r<5&&r!=2&&(h[2]=b,h[0]=0);break}case"g2":case"sd":{(b>>1==40||b>95&&b<100)&&(h[2]|=16);break}case"sg":{b==8&&r==0&&(h[2]=5);break}case"s90es":{r<8?h[2]+=17:r<32?h[2]+=13:h[2]=(h[2]>>3)+19;break}case"motif":{r<8?h[2]+=28:r<32?h[2]+=13:h[2]=(h[2]>>3)+19;break}}let m=" ",a="M",n=0,l=0;switch(h[0]){case 0:{h[2]==127?a="MT-a":h[2]==126?a="MT-b":h[2]==7?a="GM-k":h[2]==5?a="SG-a":h[2]==4?a="SP-l":h[2]==0||d=="gs"&&h[2]<5?a="GM-a":(a="y",n=3);break}case 8:{d=="sg"?a="GM-s":a="r:";break}case 48:{a=`yM${(h[2]>>3).toString().padStart(2,"0")}`,n=1;break}case 56:{a="GM-b";break}case 61:case 120:{a="rDrm";break}case 62:{a="kDrm";break}case 63:{if(h[2]<17){let f=h[2];a=f<10?"kP:":"kC:",a+=f%10}else h[2]<34?a=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][h[2]-17]:a="Ds";break}case 64:{a="ySFX";break}case 67:{a="DX:S";break}case 80:case 81:case 82:case 83:{a=`Prg${"UABC"[h[0]-80]}`;break}case 88:case 89:case 90:case 91:{a=`Cmb${"UABC"[h[0]-88]}`;break}case 95:{a=`${["DR","PC"][h[2]]}-d`;break}case 96:{a=h[2]==106?"AP-a":h[2]>>4==1?"SDg":"PF",h[2]>63?l=63:h[2]>>4==1&&(l=16),n=3;break}case 97:{a=h[2]>>4==1?"SDa":"VL:",n=3,h[2]>>4==1?l=16:l=112;break}case 98:{a=h[2]>>4==1?"SDb":"SG-a",n=3,l=16;break}case 99:{a=h[2]>>4==1?"SDc":"DX",h[2]>63?l=63:h[2]>>4==1&&(l=16),n=3;break}case 100:{a="AN",h[2]>63?l=63:h[2]>>4==1&&(l=16),n=3;break}case 104:case 105:case 106:case 107:{a="SDd",l=104;break}case 121:{a=`GM-${h[2]?"":"a"}`,n=3;break}case 122:{a="lDrm";break}case 126:{a="yDrS";break}case 127:{h[2]==127?a="rDrm":a="yDrm";break}default:h[0]<48?a="r:":a="M"}a.length<4&&(a+=`${[b,r,h[0],h[2]][n]-l}`.padStart(4-a.length,"0")),d=="xg"&&(b==0?h[2]<100?a=a.replace("y0","y:"):h[2]==125&&(a="y126"):b==16&&(p=`Voice${(h[2]*128+h[1]+1).toString().padStart(3,"0")}`,m=" "));let i=[h[0],h[1],h[2]];for(;!((p==null?void 0:p.length)>=0);)p=t(this,Q)[h[1]||0][(h[0]<<7)+h[2]],p||(this.strictMode?(p="",m="?"):t(this,Q)[h[1]||0][h[0]<<7]?h[0]==0?(h[2]=0,m="^"):h[2]<1?(h[0]=0,m="*"):(h[2]--,m="^"):b==48?(h[0]=0,h[2]=0,m="!"):b==62?(h[1]--,m=" ",h[1]<1&&!(p!=null&&p.length)&&(h[0]=0,m="!")):b<63?h[0]==0?(h[2]=0,m="^"):h[2]<1?(h[0]=0,m="*"):h[2]--:b==80?(p=`PrgU:${e.toString().padStart(3,"0")}`,m="!"):b==88?(p=`CmbU:${e.toString().padStart(3,"0")}`,m="!"):b==121?(p=`GM2Vox0${r}`,m="#"):b==122?(h[1]==32?h[1]==0:h[1]%=7,p=t(this,Q)[h[1]||0][(h[0]<<7)+h[2]],p?m=" ":(p="",m="*")):h[1]==0?(p=`${b.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${r.toString().padStart(3,"0")}`,m="!"):h[0]==0?(h[2]=0,m="^"):h[2]>0?h[2]--:h[1]>0?(h[1]=0,m="!"):(h[0]=0,m="?"));let s=[h[0],h[1],h[2]];(d=="gs"||d=="ns5r")&&m=="^"&&(m=" "),b==127&&m=="^"&&(m=" "),m!=" "&&self.debugMode&&(p="");let o="??";switch(h[0]){case 0:{h[2]==0?o="GM":h[2]==5||h[2]==7?o="KG":h[2]<126?o="XG":h[2]==127&&(o="MT");break}case 48:{o="MU";break}case 56:{o="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{o="AI";break}case 62:case 82:case 90:{o="XD";break}case 63:{h[2]<17?o="KR":h[2]<34?o="ES":o="DS";break}case 64:case 126:{o="XG";break}case 67:case 99:{o=h[2]>>4==1?"SD":"DX";break}case 81:{o="RW";break}case 95:{o=["DR","PC"][h[2]];break}case 96:{o=h[2]==106?"AP":h[2]>>4==1?"SD":"PF";break}case 97:{o=h[2]>>4==1?"SD":"VL";break}case 98:{o=h[2]>>4==1?"SD":"SG";break}case 100:{o="AN";break}case 104:case 105:case 106:case 107:{o="SD";break}case 120:{o="GS";break}case 121:{o=h[2]?"G2":"GM";break}case 122:{o="KG";break}case 127:{o=h[2]==127?"MT":e==0?"GM":"XG";break}default:h[0]<48&&(h[0]==16&&d=="xg"?o="XG":o="GS")}return{name:p||`${gt(b||0)} ${gt(e||0)} ${gt(r||0)}`,iid:i,eid:s,sid:c,ending:m,sect:a,standard:o}}async load(b,e,r){let d=this,c=[],p=0,h=0;b.split(` +`).forEach(function(m,a){let n=m.split(" "),l=[];a==0?n.forEach(function(i,s){c[va.indexOf(i)]=s}):n.forEach(async function(i,s){var o;s>2?(t(d,Q)[l[c[1]]]=t(d,Q)[l[c[1]]]||[],(!((o=t(d,Q)[l[c[1]]][(l[c[0]]<<7)+l[c[2]]])!=null&&o.length)||e)&&(t(d,Q)[l[c[1]]][(l[c[0]]<<7)+l[c[2]]]=n[3],p++),h++):l.push(parseInt(n[s]))})}),e||console.debug(`Map "${r||"(internal)"}": ${h} total, ${p} loaded.`)}clearRange(b){let e=b.prg!=null?b.prg.constructor==Array?b.prg:[b.prg,b.prg]:[0,127],r=b.msb!=null?b.msb.constructor==Array?b.msb:[b.msb,b.msb]:[0,127],d=b.lsb!=null?b.lsb.constructor==Array?b.lsb:[b.lsb,b.lsb]:[0,127];for(let c=r[0];c<=r[1];c++){let p=c<<7;for(let h=d[0];h<=d[1];h++){let m=p+h;for(let a=e[0];a<=e[1];a++)delete t(this,Q)[a][m]}}}init(){w(this,Q,[]);for(let b=0;b<128;b++)t(this,Q).push([""])}async loadFiles(...b){this.init();let e=this;b.forEach(async function(r,d){try{await fetch(`./data/bank/${r}.tsv`).then(function(c){return c.text()}).then(c=>{e.load(c,!1,r)})}catch(c){console.error(`Failed loading "${r}.tsv".`)}})}},Q=new WeakMap,It);O();O();var Ke,Ut,Lt=(Ut=class{constructor(){S(this,Ke,{});M(this,"context")}set(b,e){t(this,Ke)[b]=e}has(b){return!!t(this,Ke)[b]}async read(b,e){if(!this.has(b))throw new Error(`No decoder registered for "${b}"`);return await t(this,Ke)[b].call(this.context||this,e)}},Ke=new WeakMap,Ut);var ma=function(b,e){let r=!0;return e.forEach((d,c)=>{r=r&&b[c]==d}),r},Bt=function(b){let e=0;return b.forEach(r=>{e*=256,e+=r}),e},tt=new TextDecoder,ft=new Lt;ft.set("s7e",async function(b){let e=new Uint8Array(await b.slice(0,65536).arrayBuffer()),r="MSB LSB PRG NME",d=[0,0,0,0],c=32,p=0,h=0,m=!0,a=[],n=0;for(;m;){let l=e.subarray(p);([()=>{tt.decode(l.subarray(0,4))=="YSFC"?(p+=80,h=1):p++},()=>{if(ma(l.subarray(0,4),d))a.forEach((i,s,o)=>{let f=Bt(e.subarray(i.start+4,i.start+8));i.length=f}),h=2;else{let i=tt.decode(l.subarray(0,4)),s=Bt(l.subarray(4,8));a.push({type:i,start:s}),p+=8}},()=>{let i=a[n],s=e.subarray(i.start,i.start+i.length),o=32;switch(i.type){case"ENVC":{let f=c;for(;f=a.length&&(h=3,m=!1)}][h]||(()=>{m=!1}))()}return r});O();var at=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),rt=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],Ea=[17.1,18.6,20.2,21.8,23.3,24.9,26.5,28,29.6,31.2,32.8,34.3,35.9,37.5,39,40.6,42.2,43.7,45.3,46.9,48.4,50],ze=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],Nt=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],Ht=function(b){let e=.1,r=-.3;return b>66?(e=5,r=315):b>56?(e=1,r=47):b>46&&(e=.5,r=18.5),e*b-r},Gt=function(b){return b>105?Ea[b-106]:b>100?b*1.1-100:b/10},_t=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),vt={};`hi*, ka,か ki,き ku,く @@ -139,7 +139,7 @@ o,お ~, ^, _,`.split(` -`).forEach(u=>{let e=u.split(",");gt[e[0]]=e[1]});var Xt=function(u){let e=u;u[0]=="*"&&(e=e.slice(1)),["aa","ii","uu","ee","oo"].forEach(h=>{for(;e.indexOf(h)>-1;)e=e.replace(h,h[0])});for(let h in gt)e=e.replaceAll(h,gt[h]);e.indexOf("ん")==0&&e.length>1&&(e=e.slice(1));let s=e.indexOf("!");return s>-1&&e.length>1&&(e=e.slice(s+1)),e},Ft=function(u){return u?u<96?`cc${u}`:["aftertouch","velocity","pitch bend"][u-96]:"off"};R();var yt=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],Vt=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],Kt=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var va={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},$a={66307:["drive"],66309:["vowel",u=>"aiueo"[u]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",u=>["off","LPF","HPF"][u]],94984:["noise type",u=>["white","pink"][u]],94987:["disc type",u=>["LP","SP","EP","RND"]],94990:["hum type",u=>`${u+5}0Hz`],94993:["M/S",u=>["mono","stereo"][u]]},mt=function(u){return va[(u[0]-32<<8)+u[1]]||`0x${u[0].toString(16).padStart(2,"0")}${u[1].toString(16).padStart(2,"0")}`},zt=function(u,e,s){let h=(u[0]-32<<16)+(u[1]<<8)+e,o=$a[h]||{},a=o[0];if(a!=null&&a.length)return a+=`: ${(o[1]||function(){})(s)||s}`,a},Et=[68,48,95,78,41,3,110,122,0];R();var q=function(u=64){return Math.round(2e3*Math.log10(u/64))/100},qt=function(u,e,s){let h=[],o=s==!1?e.readIntVLV():s;u==0||u==127;for(let a=0;a127)return console.debug(`Early termination: ${h}`),h.pop(),e.backOne(),e.backOne(),new Uint8Array(h)}}}return new Uint8Array(h)},vt=function(u){let e=0;return u.forEach(s=>{e+=s,e=e&127}),~e+1&127},ce=function(u,e){let s=0,h=0;for(let o=0;o>a&1)<<7,c=u[o];c+=r,o%8!=0?(e(c,s,u),s++):h=u[o]}},tt=function(u){let e=Math.floor(u*14.2);return e<128?e:0};var he=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],jt=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],Me=[120,127,120,127,120,127,61,62,62,105,120,122,122,127],wa=[0,3,81,84,88],Qt={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},$t={0:0,1:1,2:3,5:4},Wt=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Yt=[36,37],ft=[20,21,22,23,24,25,26,28,29,30,31,36,37,64,65],at=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19],ka=[12,13,16,17,18,19],Sa=[33,99,100,32,102,8,9,10],Zt=[0,16,25,40,32,64,26,48],S={};he.forEach((u,e)=>{S[u]=e});var g={length:at.length};at.forEach((u,e)=>{g[u]=e});var kt={length:ft.length};ft.forEach((u,e)=>{kt[u]=e});var j=function(){return!!self.Bun||self.debugMode||!1},xa=function(u){let e=[],s=0;return u==null||u.forEach(function(h,o){h==247?e.push(u.subarray(s,o)):h==240&&(s=o+1)}),e.length||e.push(u.subarray(0)),j()&&console.debug(e),e};var m={ch:128,cc:at.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:ft.length,dnc:128,efx:7},O,Q,oe,pe,Z,ue,ea,U,H,M,b,be,D,L,J,B,G,ve,le,Re,x,Ve,rt,de,$e,re,Ke,we,W,ze,ke,ee,P,Oe,qe,je,fe,Se,Qe,se,I,st,wt,Y,ge,xe,_,De,N,it,dt,Pe,Ie,te,ae,ye,Ae,Ue,Le,Jt,dr=(Jt=class extends ot{constructor(){super();v(this,Z);C(this,"NOTE_IDLE",0);C(this,"NOTE_ATTACK",1);C(this,"NOTE_DECAY",2);C(this,"NOTE_SUSTAIN",3);C(this,"NOTE_HELD",4);C(this,"NOTE_RELEASE",5);C(this,"NOTE_SOSTENUTO_ATTACK",8);C(this,"NOTE_SOSTENUTO_DECAY",9);C(this,"NOTE_SOSTENUTO_SUSTAIN",10);C(this,"NOTE_SOSTENUTO_HELD",11);C(this,"CH_MELODIC",0);C(this,"CH_DRUMS",1);C(this,"CH_DRUM1",2);C(this,"CH_DRUM2",3);C(this,"CH_DRUM3",4);C(this,"CH_DRUM4",5);C(this,"CH_DRUM5",6);C(this,"CH_DRUM6",7);C(this,"CH_DRUM7",8);C(this,"CH_DRUM8",9);v(this,O,0);v(this,Q,0);v(this,oe,0);v(this,pe,new Array(11));v(this,U,new Uint8Array(m.ch));v(this,H,new Uint8Array(m.ch));v(this,M,new Uint8Array(m.ch));v(this,b,new Uint8Array(m.ch*m.cc));v(this,be,new Uint8Array(m.ace));v(this,D,new Uint8Array(m.ch));v(this,L,new Uint8Array(m.ch*m.nn));v(this,J,new Uint8Array(m.ch));v(this,B,new Uint16Array(m.pl));v(this,G,new Uint8Array(m.pl));v(this,ve,new Int16Array(m.ch));v(this,le,new Uint8Array(m.ch));v(this,Re,0);v(this,x,new Uint8Array(m.ch*m.rpn));v(this,Ve,new Int8Array(m.ch*Yt.length));v(this,rt,new Uint8Array(m.drm*m.dpn*m.dnc));v(this,de,new Uint8Array(m.ch));v(this,$e,new Uint8Array(128));v(this,re,new Uint8Array(m.cmt*8));v(this,Ke,new Uint8Array(1024));v(this,we,new Uint8Array(m.cmt*64));v(this,W,new Uint8Array(m.efx*3));v(this,ze,new Uint8Array(m.ch));v(this,ke,0);v(this,ee,0);v(this,P,100);v(this,Oe,0);v(this,qe,500);v(this,je,0);v(this,fe,"");v(this,Se,0);v(this,Qe,0);v(this,se,!0);v(this,I,!1);v(this,st,void 0);v(this,wt,new Uint8Array(2));v(this,Y,[]);v(this,ge,new Uint8Array(m.ch));v(this,xe,new Uint8Array(m.tr));C(this,"baseBank",new bt("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es"));C(this,"userBank",new bt("gm"));C(this,"initOnReset",!1);C(this,"aiEfxName","");v(this,_,[]);v(this,De,void 0);v(this,N,{nOff:(e,s)=>{let h=e*128+s,o=t(this,B).lastIndexOf(h);o>-1&&(t(this,b)[m.cc*e+g[64]]>63?(t(this,G)[o]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:s,velo:t(this,L)[h],state:this.NOTE_HELD})):t(this,b)[m.cc*e+g[66]]>63&&t(this,G)[o]==this.NOTE_SOSTENUTO_SUSTAIN?(t(this,G)[o]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:s,velo:t(this,L)[h],state:this.NOTE_SOSTENUTO_HELD})):(t(this,B)[o]=0,t(this,L)[h]=0,t(this,G)[o]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:s,velo:0,state:this.NOTE_IDLE})))},nOn:(e,s,h)=>{let o=e*128+s,a=0;for(t(this,J)[e]&&t(this,N).ano(e);t(this,G)[a]>0&&t(this,B)[a]!=o;)a++;a{},cAt:(e,s)=>{},hoOf:e=>{t(this,G).forEach((s,h)=>{if(s==this.NOTE_HELD){let o=t(this,B)[h],a=o>>7;e==a&&(t(this,G)[h]=this.NOTE_IDLE,t(this,B)[h]=0,t(this,L)[o]=0,this.dispatchEvent("note",{part:e,note:o&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,G).forEach((s,h)=>{let o;switch(s){case this.NOTE_ATTACK:{o=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{o=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{o=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(o){t(this,G)[h]=o;let a=t(this,B)[h];this.dispatchEvent("note",{part:e,note:a&127,velo:t(this,L)[a],state:o})}})},soOf:e=>{t(this,G).forEach((s,h)=>{if(s==this.NOTE_SOSTENUTO_HELD){let o=t(this,B)[h],a=o>>7;e==a&&(t(this,G)[h]=this.NOTE_IDLE,t(this,B)[h]=0,t(this,L)[o]=0,this.dispatchEvent("note",{part:e,note:o&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,B).forEach((s,h,o)=>{let a=s>>7,r=s&127;s==0&&t(this,L)[0]==0||a==e&&t(this,N).nOff(a,r)})}});v(this,it,{8:function(e){let s=e.channel,h=e.data[0];t(this,N).nOff(s,h)},9:function(e){let s=e.channel;t(this,U)[s]=1;let h=e.data[0],o=e.data[1];o>0?t(this,N).nOn(s,h,o):t(this,N).nOff(s,h)},10:function(e){let s=e.channel,h=s*128+e.data[0];t(this,B).indexOf(h)>-1&&(t(this,L)[h]=data[1],this.dispatchEvent("note",{part:s,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let s=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,O)){case S.s90es:case S.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&(t(this,U)[s]=1);break}e.data[1]&&(t(this,U)[s]=1);break}default:{t(this,U)[s]=1;break}}})();let h=s*m.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,N).ano(s),t(this,ve)[s]=0;let o=s*m.cc;t(this,b)[o+g[1]]=0,t(this,b)[o+g[5]]=0,t(this,b)[o+g[64]]=0,t(this,b)[o+g[65]]=0,t(this,b)[o+g[66]]=0,t(this,b)[o+g[67]]=0,t(this,b)[o+g[11]]=127,t(this,b)[o+g[101]]=127,t(this,b)[o+g[100]]=127,t(this,b)[o+g[99]]=127,t(this,b)[o+g[98]]=127;return}case 123:{t(this,N).ano(s);return}case 124:{t(this,N).ano(s);return}case 125:{t(this,N).ano(s);return}case 126:{t(this,J)[s]=1,t(this,N).ano(s);return}case 127:{t(this,J)[s]=0,t(this,N).ano(s);return}}if(g[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(ka.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(j()&&console.debug(`${he[t(this,O)]}, CH${s+1}: ${e.data[1]}`),t(this,O)==0?e.data[1]<48?(t(this,M)[s]>0&&(e.data[1]=t(this,b)[h],e.data[1]=120,console.debug(`Forced channel ${s+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,O)==S.gs?e.data[1]<56&&t(this,M)[s]>0&&(e.data[1]=t(this,b)[h],e.data[1]=120,console.debug(`Forced channel ${s+1} to stay drums.`)):t(this,O)==S.gm?e.data[1]<48?t(this,M)[s]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${s+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):t(this,O)==S.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),t(this,O)){case S.xg:{[126,127].indexOf(e.data[1])>-1?t(this,M)[s]==0&&(this.setChType(s,this.CH_DRUM2),console.debug(`CH${s+1} set to drums by MSB.`)):t(this,M)[s]>0&&(this.setChType(s,this.CH_MELODIC),console.debug(`CH${s+1} set to melodic by MSB.`));break}case S["05rw"]:case S.x5d:case S.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(this,M)[s]==0&&(this.setChType(s,this.CH_DRUM2),console.debug(`CH${s+1} set to drums by MSB.`)):t(this,M)[s]>0&&(this.setChType(s,this.CH_MELODIC),console.debug(`CH${s+1} set to melodic by MSB.`));break}case S.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,M)[s]==0&&(this.setChType(s,this.CH_DRUM2),console.debug(`CH${s+1} set to drums by MSB.`)):t(this,M)[s]>0&&(this.setChType(s,this.CH_MELODIC),console.debug(`CH${s+1} set to melodic by MSB.`));break}case S.g2:{e.data[1]==120?t(this,M)[s]==0&&(this.setChType(s,this.CH_DRUMS),console.debug(`CH${s+1} set to drums by MSB.`)):t(this,M)[s]>0&&(this.setChType(s,this.CH_MELODIC),console.debug(`CH${s+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:s});break}case 6:{if(t(this,Re)){[S.xg,S.gs,S.ns5r].indexOf(t(this,O))<0&&console.warn(`NRPN commits are not available under "${he[t(this,O)]}" mode, even when they are supported in Octavia.`);let o=t(this,b)[h+g[99]],a=t(this,b)[h+g[98]];if(o==1){let r=Sa.indexOf(a);if(r>-1)t(this,b)[h+g[71+r]]=e.data[1],j()&&console.debug(`Redirected NRPN 1 ${a} to cc${71+r}.`),this.dispatchEvent("cc",{part:s,cc:71+r,data:e.data[1]});else{let c=Yt.indexOf(a);c>-1?t(this,Ve)[s*10+c]=e.data[1]-64:console.warn(`NRPN 0x01${a.toString(16).padStart(2,"0")} is not supported.`),j()&&console.debug(`CH${s+1} voice NRPN ${a} commit`)}}else{if(ft.indexOf(o)<0){let c=`NRPN 0x${o.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")} `;o==127?console.warn(`${c}is not necessary. Consider removing it.`):console.warn(`${c}is not supported.`)}else{let c=t(this,M)[s]-2;c<0?console.warn(`CH${s+1} cannot accept drum NRPN as type ${et[t(this,M)[s]]}.`):t(this,rt)[(c*m.dpn+kt[o])*m.dnc+a]=e.data[1]-64}j()&&console.debug(`CH${s+1} (${et[t(this,M)[s]]}) drum NRPN ${o} commit`)}}else{let o=$t[t(this,b)[h+g[100]]];t(this,b)[h+g[101]]==0&&o!=null&&(j()&&console.debug(`CH${s+1} RPN 0 ${t(this,b)[h+g[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Wt[o][0]),Wt[o][1]),t(this,x)[s*m.rpn+o]=e.data[1])}break}case 32:{switch(j()&&console.debug(`${he[t(this,O)]}, CH${s+1} LSB: ${e.data[1]}`),t(this,O)){case S.s90es:case S.motif:{this.setChType(s,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,O),!0);break}}this.dispatchEvent("voice",{part:s});break}case 38:{t(this,Re)||t(this,b)[h+101]==0&&$t[t(this,b)[h+100]]!=null&&(t(this,x)[s*m.rpn+$t[t(this,b)[h+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&t(this,N).hoOf(s);break}case 66:{e.data[1]>>6?t(this,N).soOn(s):t(this,N).soOf(s);break}case 98:case 99:{E(this,Re,1);break}case 100:case 101:{E(this,Re,0);break}}t(this,b)[h+g[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:s,cc:e.data[0],data:e.data[1]})}},12:function(e){let s=e.channel;switch(t(this,O)){case S.s90es:case S.motif:{e.data&&(t(this,U)[s]=1);break}default:t(this,U)[s]=1}t(this,D)[s]=e.data,t(this,de)[s]=0,j()&&console.debug(`T:${e.track} C:${s} P:${e.data}`),this.dispatchEvent("voice",{part:s})},13:function(e){let s=this,h=e.channel;t(this,B).forEach(function(o){let a=o>>7;h==a&&(t(s,L)[o]=e.data,s.dispatchEvent("note",{part:h,note:o&127,velo:e.data,state:s.NOTE_SUSTAIN}))})},14:function(e){let s=e.channel;t(this,ve)[s]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:s,pitch:this.getPitchShift(s)})},15:function(e){xa(e.data).forEach(s=>{let h=s[0],o=s[1];(t(this,dt)[h]||function(){console.debug(`Unknown manufacturer ${h}.`)})(o,s.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(t(this,_)[e.meta]||function(h,o,a){}).call(this,e.data,e.track,e.meta),e.meta!=32&&E(this,Oe,0);let s=wa.indexOf(e.meta)>-1;if(j()&&console.debug(e),s)return e.reply="meta",e}});v(this,dt,{64:(e,s,h)=>{t(this,Ae).run(s,h,e)},65:(e,s,h)=>{if(s[0]<16)if(s[1]==72){let o=s[s.length-1],a=vt(s.subarray(3,s.length-1));o==a?t(this,ae).run(s.subarray(0,s.length-1),h,e):console.warn(`Bad SD checksum ${o}. Should be ${a}.`)}else t(this,ae).run(s,h,e);else{let o=s[s.length-1],a=vt(s.subarray(2,s.length-1));o==a?t(this,ae).run(s.subarray(0,s.length-1),h,e):console.warn(`Bad GS checksum ${o}. Should be ${a}.`)}},66:(e,s,h)=>{t(this,ye).run(s,h,e)},67:(e,s,h)=>{t(this,te).run(s,h,e)},68:(e,s,h)=>{t(this,Le).run(s,h,e)},71:(e,s,h)=>{t(this,Ue).run(s,h,e)},126:(e,s,h)=>{t(this,Pe).run(s,h,e)},127:(e,s,h)=>{this.switchMode("gm"),t(this,Ie).run(s,h,e)}});v(this,Pe,void 0);v(this,Ie,void 0);v(this,te,void 0);v(this,ae,void 0);v(this,ye,void 0);v(this,Ae,void 0);v(this,Ue,void 0);v(this,Le,void 0);let e=this;E(this,Z,new Uint8Array(256),ea),t(this,pe)[10]=new Uint8Array(512),E(this,De,new ne),this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(b=>{let e=b.split(",");vt[e[0]]=e[1]});var Xt=function(b){let e=b;b[0]=="*"&&(e=e.slice(1)),["aa","ii","uu","ee","oo"].forEach(d=>{for(;e.indexOf(d)>-1;)e=e.replace(d,d[0])});for(let d in vt)e=e.replaceAll(d,vt[d]);e.indexOf("ん")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},Ft=function(b){return b?b<96?`cc${b}`:["aftertouch","velocity","pitch bend"][b-96]:"off"};O();var mt=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],Vt=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],Kt=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var $a={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},wa={66307:["drive"],66309:["vowel",b=>"aiueo"[b]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",b=>["off","LPF","HPF"][b]],94984:["noise type",b=>["white","pink"][b]],94987:["disc type",b=>["LP","SP","EP","RND"]],94990:["hum type",b=>`${b+5}0Hz`],94993:["M/S",b=>["mono","stereo"][b]]},Et=function(b){return $a[(b[0]-32<<8)+b[1]]||`0x${b[0].toString(16).padStart(2,"0")}${b[1].toString(16).padStart(2,"0")}`},zt=function(b,e,r){let d=(b[0]-32<<16)+(b[1]<<8)+e,c=wa[d]||{},p=c[0];if(p!=null&&p.length)return p+=`: ${(c[1]||function(){})(r)||r}`,p},$t=[68,48,95,78,41,3,110,122,0];O();var W=function(b=64){return Math.round(2e3*Math.log10(b/64))/100},qt=function(b,e,r){let d=[],c=r==!1?e.readIntVLV():r;b==0||b==127;for(let p=0;p127)return console.debug(`Early termination: ${d}`),d.pop(),e.backOne(),e.backOne(),new Uint8Array(d)}}}return new Uint8Array(d)},wt=function(b){let e=0;return b.forEach(r=>{e+=r,e=e&127}),~e+1&127},oe=function(b,e){let r=0,d=0;for(let c=0;c>p&1)<<7,m=b[c];m+=h,c%8!=0?(e(m,r,b),r++):d=b[c]}},st=function(b){let e=Math.floor(b*14.2);return e<128?e:0};var he=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],jt=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],Oe=[120,127,120,127,120,127,61,62,62,105,120,122,122,127],ka=[0,3,81,84,88],Qt={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},kt={0:0,1:1,2:3,5:4},Wt=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Yt=[36,37,48,49,52,53],ut=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Zt={26:127,29:0,30:0,31:0,52:12,53:54},it=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19],Sa=[12,13,16,17,18,19],xa=[33,99,100,32,102,8,9,10],Jt=[0,16,25,40,32,64,26,48],x={};he.forEach((b,e)=>{x[b]=e});var v={length:it.length};it.forEach((b,e)=>{v[b]=e});var ee={length:ut.length};ut.forEach((b,e)=>{ee[b]=e});var I=function(){return!!self.Bun||self.debugMode||!1},Ca=function(b){let e=[],r=0;return b==null||b.forEach(function(d,c){d==247?e.push(b.subarray(r,c)):d==240&&(r=c+1)}),e.length||e.push(b.subarray(0)),I()&&console.debug(e),e};var $={ch:128,cc:it.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:ut.length,dnc:128,efx:7},D,z,le,pe,J,ue,ta,be,X,R,y,ge,P,N,te,H,F,$e,de,De,T,qe,q,fe,we,ie,je,ke,Y,Qe,Se,ae,U,Ae,We,Ye,xe,Ce,Ze,ne,L,nt,St,Z,ye,Te,V,Pe,G,ct,ht,Ie,Ue,re,se,ve,Le,Be,Ne,ea,fr=(ea=class extends dt{constructor(){super();S(this,J);M(this,"NOTE_IDLE",0);M(this,"NOTE_ATTACK",1);M(this,"NOTE_DECAY",2);M(this,"NOTE_SUSTAIN",3);M(this,"NOTE_HELD",4);M(this,"NOTE_RELEASE",5);M(this,"NOTE_SOSTENUTO_ATTACK",8);M(this,"NOTE_SOSTENUTO_DECAY",9);M(this,"NOTE_SOSTENUTO_SUSTAIN",10);M(this,"NOTE_SOSTENUTO_HELD",11);M(this,"CH_MELODIC",0);M(this,"CH_DRUMS",1);M(this,"CH_DRUM1",2);M(this,"CH_DRUM2",3);M(this,"CH_DRUM3",4);M(this,"CH_DRUM4",5);M(this,"CH_DRUM5",6);M(this,"CH_DRUM6",7);M(this,"CH_DRUM7",8);M(this,"CH_DRUM8",9);S(this,D,0);S(this,z,0);S(this,le,0);S(this,pe,new Array(11));S(this,be,new Uint8Array($.ch));S(this,X,new Uint8Array($.ch));S(this,R,new Uint8Array($.ch));S(this,y,new Uint8Array($.ch*$.cc));S(this,ge,new Uint8Array($.ace));S(this,P,new Uint8Array($.ch));S(this,N,new Uint8Array($.ch*$.nn));S(this,te,new Uint8Array($.ch));S(this,H,new Uint16Array($.pl));S(this,F,new Uint8Array($.pl));S(this,$e,new Int16Array($.ch));S(this,de,new Uint8Array($.ch));S(this,De,0);S(this,T,new Uint8Array($.ch*$.rpn));S(this,qe,new Int8Array($.ch*Yt.length));S(this,q,new Uint8Array($.drm*$.dpn*$.dnc));S(this,fe,new Uint8Array($.ch));S(this,we,new Uint8Array(128));S(this,ie,new Uint8Array($.cmt*8));S(this,je,new Uint8Array(1024));S(this,ke,new Uint8Array($.cmt*64));S(this,Y,new Uint8Array($.efx*3));S(this,Qe,new Uint8Array($.ch));S(this,Se,0);S(this,ae,0);S(this,U,100);S(this,Ae,0);S(this,We,500);S(this,Ye,0);S(this,xe,"");S(this,Ce,0);S(this,Ze,0);S(this,ne,!0);S(this,L,!1);S(this,nt,void 0);S(this,St,new Uint8Array(2));S(this,Z,[]);S(this,ye,new Uint8Array($.ch));S(this,Te,new Uint8Array($.tr));M(this,"baseBank",new yt("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es"));M(this,"userBank",new yt("gm"));M(this,"initOnReset",!1);M(this,"aiEfxName","");S(this,V,[]);S(this,Pe,void 0);S(this,G,{nOff:(e,r)=>{let d=e*128+r,c=t(this,H).lastIndexOf(d);c>-1&&(t(this,y)[$.cc*e+v[64]]>63?(t(this,F)[c]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,N)[d],state:this.NOTE_HELD})):t(this,y)[$.cc*e+v[66]]>63&&t(this,F)[c]==this.NOTE_SOSTENUTO_SUSTAIN?(t(this,F)[c]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,N)[d],state:this.NOTE_SOSTENUTO_HELD})):(t(this,H)[c]=0,t(this,N)[d]=0,t(this,F)[c]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})))},nOn:(e,r,d)=>{let c=e*128+r,p=0;for(t(this,te)[e]&&t(this,G).ano(e);t(this,F)[p]>0&&t(this,H)[p]!=c;)p++;p<$.pl?(t(this,H)[p]=c,t(this,N)[c]=d,t(this,F)[p]=this.NOTE_SUSTAIN,t(this,de)[e]{},cAt:(e,r)=>{},hoOf:e=>{t(this,F).forEach((r,d)=>{if(r==this.NOTE_HELD){let c=t(this,H)[d],p=c>>7;e==p&&(t(this,F)[d]=this.NOTE_IDLE,t(this,H)[d]=0,t(this,N)[c]=0,this.dispatchEvent("note",{part:e,note:c&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,F).forEach((r,d)=>{let c;switch(r){case this.NOTE_ATTACK:{c=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{c=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{c=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(c){t(this,F)[d]=c;let p=t(this,H)[d];this.dispatchEvent("note",{part:e,note:p&127,velo:t(this,N)[p],state:c})}})},soOf:e=>{t(this,F).forEach((r,d)=>{if(r==this.NOTE_SOSTENUTO_HELD){let c=t(this,H)[d],p=c>>7;e==p&&(t(this,F)[d]=this.NOTE_IDLE,t(this,H)[d]=0,t(this,N)[c]=0,this.dispatchEvent("note",{part:e,note:c&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,H).forEach((r,d,c)=>{let p=r>>7,h=r&127;r==0&&t(this,N)[0]==0||p==e&&t(this,G).nOff(p,h)})}});S(this,ct,{8:function(e){let r=e.channel,d=e.data[0];t(this,G).nOff(r,d)},9:function(e){let r=e.channel;this.setChActive(r,1);let d=e.data[0],c=e.data[1];c>0?t(this,G).nOn(r,d,c):t(this,G).nOff(r,d)},10:function(e){let r=e.channel,d=r*128+e.data[0];t(this,H).indexOf(d)>-1&&(t(this,N)[d]=data[1],this.dispatchEvent("note",{part:r,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let r=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,D)){case x.s90es:case x.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(r,1);break}e.data[1]&&this.setChActive(r,1);break}default:{this.setChActive(r,1);break}}})();let d=r*$.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,G).ano(r),t(this,$e)[r]=0;let c=r*$.cc;t(this,y)[c+v[1]]=0,t(this,y)[c+v[5]]=0,t(this,y)[c+v[64]]=0,t(this,y)[c+v[65]]=0,t(this,y)[c+v[66]]=0,t(this,y)[c+v[67]]=0,t(this,y)[c+v[11]]=127,t(this,y)[c+v[101]]=127,t(this,y)[c+v[100]]=127,t(this,y)[c+v[99]]=127,t(this,y)[c+v[98]]=127;return}case 123:{t(this,G).ano(r);return}case 124:{t(this,G).ano(r);return}case 125:{t(this,G).ano(r);return}case 126:{t(this,te)[r]=1,t(this,G).ano(r);return}case 127:{t(this,te)[r]=0,t(this,G).ano(r);return}}if(v[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Sa.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(I()&&console.debug(`${he[t(this,D)]}, CH${r+1}: ${e.data[1]}`),t(this,D)==0?e.data[1]<48?(t(this,R)[r]>0&&(e.data[1]=t(this,y)[d],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,D)==x.gs?e.data[1]<56&&t(this,R)[r]>0&&(e.data[1]=t(this,y)[d],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):t(this,D)==x.gm?e.data[1]<48?t(this,R)[r]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${r+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):t(this,D)==x.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),t(this,D)){case x.xg:{[126,127].indexOf(e.data[1])>-1?t(this,R)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,R)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x["05rw"]:case x.x5d:case x.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(this,R)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,R)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,R)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,R)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x.g2:{e.data[1]==120?t(this,R)[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,R)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:r});break}case 6:{if(t(this,De)){[x.xg,x.gs,x.ns5r].indexOf(t(this,D))<0&&console.warn(`NRPN commits are not available under "${he[t(this,D)]}" mode, even when they are supported in Octavia.`);let c=t(this,y)[d+v[99]],p=t(this,y)[d+v[98]];if(c==1){let h=xa.indexOf(p);if(h>-1)t(this,y)[d+v[71+h]]=e.data[1],I()&&console.debug(`Redirected NRPN 1 ${p} to cc${71+h}.`),this.dispatchEvent("cc",{part:r,cc:71+h,data:e.data[1]});else{let m=Yt.indexOf(p);m>-1?t(this,qe)[r*10+m]=e.data[1]-64:console.warn(`NRPN 0x01${p.toString(16).padStart(2,"0")} is not supported.`),I()&&console.debug(`CH${r+1} voice NRPN ${p} commit`)}}else{if(ut.indexOf(c)<0){let m=`NRPN 0x${c.toString(16).padStart(2,"0")}${p.toString(16).padStart(2,"0")} `;c==127?console.warn(`${m}is not necessary. Consider removing it.`):console.warn(`${m}is not supported.`)}else{let m=t(this,R)[r]-2;m<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${rt[t(this,R)[r]]}.`):t(this,q)[(m*$.dpn+ee[c])*$.dnc+p]=e.data[1]}I()&&console.debug(`CH${r+1} (${rt[t(this,R)[r]]}) drum NRPN ${c} commit`)}}else{let c=kt[t(this,y)[d+v[100]]];t(this,y)[d+v[101]]==0&&c!=null&&(I()&&console.debug(`CH${r+1} RPN 0 ${t(this,y)[d+v[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Wt[c][0]),Wt[c][1]),t(this,T)[r*$.rpn+c]=e.data[1])}break}case 32:{switch(I()&&console.debug(`${he[t(this,D)]}, CH${r+1} LSB: ${e.data[1]}`),t(this,D)){case x.s90es:case x.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,D),!0);break}}this.dispatchEvent("voice",{part:r});break}case 38:{t(this,De)||t(this,y)[d+101]==0&&kt[t(this,y)[d+100]]!=null&&(t(this,T)[r*$.rpn+kt[t(this,y)[d+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&t(this,G).hoOf(r);break}case 66:{e.data[1]>>6?t(this,G).soOn(r):t(this,G).soOf(r);break}case 98:case 99:{w(this,De,1);break}case 100:case 101:{w(this,De,0);break}}t(this,y)[d+v[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:r,cc:e.data[0],data:e.data[1]})}},12:function(e){let r=e.channel;switch(t(this,D)){case x.s90es:case x.motif:{e.data&&this.setChActive(r,1);break}default:this.setChActive(r,1)}t(this,P)[r]=e.data,t(this,fe)[r]=0,I()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),this.dispatchEvent("voice",{part:r})},13:function(e){let r=this,d=e.channel;t(this,H).forEach(function(c){let p=c>>7;d==p&&(t(r,N)[c]=e.data,r.dispatchEvent("note",{part:d,note:c&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;t(this,$e)[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){Ca(e.data).forEach(r=>{let d=r[0],c=r[1];(t(this,ht)[d]||function(){console.debug(`Unknown manufacturer ${d}.`)})(c,r.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(t(this,V)[e.meta]||function(d,c,p){}).call(this,e.data,e.track,e.meta),e.meta!=32&&w(this,Ae,0);let r=ka.indexOf(e.meta)>-1;if(I()&&console.debug(e),r)return e.reply="meta",e}});S(this,ht,{64:(e,r,d)=>{t(this,Le).run(r,d,e)},65:(e,r,d)=>{if(r[0]<16)if(r[1]==72){let c=r[r.length-1],p=wt(r.subarray(3,r.length-1));c==p?t(this,se).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad SD checksum ${c}. Should be ${p}.`)}else t(this,se).run(r,d,e);else{let c=r[r.length-1],p=wt(r.subarray(2,r.length-1));c==p?t(this,se).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad GS checksum ${c}. Should be ${p}.`)}},66:(e,r,d)=>{t(this,ve).run(r,d,e)},67:(e,r,d)=>{t(this,re).run(r,d,e)},68:(e,r,d)=>{t(this,Ne).run(r,d,e)},71:(e,r,d)=>{t(this,Be).run(r,d,e)},126:(e,r,d)=>{t(this,Ie).run(r,d,e)},127:(e,r,d)=>{this.switchMode("gm"),t(this,Ue).run(r,d,e)}});S(this,Ie,void 0);S(this,Ue,void 0);S(this,re,void 0);S(this,se,void 0);S(this,ve,void 0);S(this,Le,void 0);S(this,Be,void 0);S(this,Ne,void 0);let e=this;w(this,J,new Uint8Array(256),ta),t(this,pe)[10]=new Uint8Array(512),w(this,Pe,new ce),this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -147,20 +147,21 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),this.addEventListener("metacommit",function(a){var c,n;let{data:r}=a;((c=t(e,Y)[0])==null?void 0:c.type)==r.type&&((n=t(e,Y)[0])!=null&&n.amend)?(t(e,Y)[0].amend=r.amend,t(e,Y)[0].data+=r.data):t(e,Y).unshift(r)}),t(this,_)[1]=function(a){var r,c,n,i,f;switch(a=a.replaceAll(`\r +122 006 000 `),this.addEventListener("metacommit",function(a){var l,i;let{data:n}=a;((l=t(e,Z)[0])==null?void 0:l.type)==n.type&&((i=t(e,Z)[0])!=null&&i.amend)?(t(e,Z)[0].amend=n.amend,t(e,Z)[0].data+=n.data):t(e,Z).unshift(n)}),t(this,V)[1]=function(a){var n,l,i,s,o;switch(a=a.replaceAll(`\r `,` `).replaceAll("\r",` -`),a.slice(0,2)){case"@I":{E(this,I,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(r=a.slice(2))==null?void 0:r.trimLeft()});break}case"@K":{E(this,I,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(c=a.slice(2))==null?void 0:c.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{E(this,I,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(n=a.slice(2))==null?void 0:n.trimLeft()});break}case"@T":{E(this,I,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(i=a.slice(2))==null?void 0:i.trimLeft()});break}case"@V":{E(this,I,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(f=a.slice(2))==null?void 0:f.trimLeft()});break}case"XF":{let l=a.slice(2).split(":");switch(l[0]){case"hd":{l.slice(1).forEach((d,p)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][p],data:d})});break}case"ln":{l.slice(1).forEach((d,p)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][p],data:d})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:t(this,I)?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` -`).forEach((l,d)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:l,mask:d!=0})})}},t(this,_)[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},t(this,_)[3]=function(a,r){r<1&&t(this,Oe)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},t(this,_)[4]=function(a,r){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},t(this,_)[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},t(this,_)[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},t(this,_)[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},t(this,_)[32]=function(a){E(this,Oe,a[0]+1)},t(this,_)[33]=function(a,r){t(e,xe)[r]=a+1},t(this,_)[81]=function(a,r){E(e,qe,a/1e3)},t(this,_)[127]=function(a,r){t(e,De).run(a,r)},t(this,De).default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},t(this,De).add([67,0,1],function(a,r){t(e,xe)[r]=a[0]+1}),E(this,Pe,new ne("universal non-realtime")),E(this,Ie,new ne("universal realtime")),E(this,te,new ne("Yamaha")),E(this,ae,new ne("Roland")),E(this,ye,new ne("Korg")),E(this,Ae,new ne("Kawai")),E(this,Ue,new ne("Akai")),E(this,Le,new ne("Casio"));let s=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,a)};t(this,Pe).default=s,t(this,Ie).default=s,t(this,te).default=s,t(this,ae).default=s,t(this,ye).default=s,t(this,Ae).default=s,t(this,Ue).default=s,t(this,Le).default=s,t(this,Pe).add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),E(e,I,t(e,I)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),t(this,Ie).add([4,1],a=>{E(e,P,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,P))}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64),t(this,te).add([76,0,0],a=>{switch(a[0]){case 125:{console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),E(e,I,!1),console.info("MIDI reset: XG");break}default:{let r=[0,0,0,0],c=(n,i)=>{r[i]=n};if(a.subarray(1).forEach((n,i)=>{let f=i+a[0];([c,c,c,c,l=>{E(this,P,l*129/16383*100),e.dispatchEvent("mastervolume",t(e,P))},l=>{},l=>{}][f]||(()=>{}))(n,i)}),a[0]<4){let n=0;r.forEach(i=>{n=n<<4,n+=i}),n-=1024}}}}).add([76,2,1],a=>{let r="XG ";a[0]<32?(r+="reverb ",a.subarray(1).forEach((c,n)=>{([i=>{e.setEffectTypeRaw(0,!1,i),console.info(`${r}main type: ${Je[i]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},i=>{e.setEffectTypeRaw(0,!0,i),console.debug(`${r}sub type: ${i+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},i=>{console.debug(`${r}time: ${Ht(i)}s`)},i=>{console.debug(`${r}diffusion: ${i}`)},i=>{console.debug(`${r}initial delay: ${i}`)},i=>{console.debug(`${r}HPF cutoff: ${Fe[i]}Hz`)},i=>{console.debug(`${r}LPF cutoff: ${Fe[i]}Hz`)},i=>{console.debug(`${r}width: ${i}`)},i=>{console.debug(`${r}height: ${i}`)},i=>{console.debug(`${r}depth: ${i}`)},i=>{console.debug(`${r}wall type: ${i}`)},i=>{console.debug(`${r}dry/wet: ${i}`)},i=>{console.debug(`${r}send: ${q(i)}dB`)},i=>{console.debug(`${r}pan: ${i-64}`)},!1,!1,i=>{console.debug(`${r}delay: ${i}`)},i=>{console.debug(`${r}density: ${i}`)},i=>{console.debug(`${r}balance: ${i}`)},i=>{},i=>{console.debug(`${r}feedback: ${i}`)},i=>{}][a[0]+n]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(c)})):a[0]<64?(r+="chorus ",a.subarray(1).forEach((c,n)=>{([i=>{e.setEffectTypeRaw(1,!1,i),console.info(`${r}main type: ${Je[i]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},i=>{e.setEffectTypeRaw(1,!0,i),console.debug(`${r}sub type: ${i+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},i=>{console.debug(`${r}LFO: ${Nt[i]}Hz`)},i=>{},i=>{console.debug(`${r}feedback: ${i}`)},i=>{console.debug(`${r}delay offset: ${Gt(i)}ms`)},i=>{},i=>{console.debug(`${r}low: ${Fe[i]}Hz`)},i=>{console.debug(`${r}low: ${i-64}dB`)},i=>{console.debug(`${r}high: ${Fe[i]}Hz`)},i=>{console.debug(`${r}high: ${i-64}dB`)},i=>{console.debug(`${r}dry/wet: ${i}`)},i=>{console.debug(`${r}send: ${q(i)}dB`)},i=>{console.debug(`${r}pan: ${i-64}`)},i=>{console.debug(`${r}to reverb: ${q(i)}dB`)},!1,i=>{},i=>{},i=>{},i=>{console.debug(`${r}LFO phase diff: ${(i-64)*3}deg`)},i=>{console.debug(`${r}input mode: ${i?"stereo":"mono"}`)},i=>{}][a[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(c)})):a[0]<86?(r+="variation ",a.subarray(1).forEach((c,n)=>{([i=>{e.setEffectTypeRaw(2,!1,i),console.info(`${r}main type: ${Je[i]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},i=>{e.setEffectTypeRaw(2,!0,i),console.debug(`${r}sub type: ${i+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+n]||function(){})(c)})):a[0]<97?(r+="variation ",a.subarray(1).forEach((c,n)=>{[i=>{console.debug(`${r}send: ${q(i)}dB`)},i=>{console.debug(`${r}pan: ${i-64}`)},i=>{console.debug(`${r}to reverb: ${q(i)}dB`)},i=>{console.debug(`${r}to chorus: ${q(i)}dB`)},i=>{console.debug(`${r}connection: ${i?"system":"insertion"}`)},i=>{console.debug(`${r}channel: CH${i+1}`)},i=>{console.debug(`${r}mod wheel: ${i-64}`)},i=>{console.debug(`${r}bend wheel: ${i-64}`)},i=>{console.debug(`${r}channel after touch: ${i-64}`)},i=>{console.debug(`${r}AC1: ${i-64}`)},i=>{console.debug(`${r}AC2: ${i-64}`)}][a[0]-86+n](c)})):a[0]>111&&a[0]<118?r+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((r,c)=>{let n=c+a[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][r]}`);else{let i=n-1>>2,f=n-1&3,l=`XG EQ ${i} ${["gain","freq","Q","shape"][f]}: `;[()=>{console.debug(`${l}${r-64}dB`)},()=>{console.debug(`${l}${r} (raw)`)},()=>{console.debug(`${l}${r/10}`)},()=>{console.debug(`${l}${["shelf","peak"][+!!r]}`)}][f]()}})}).add([76,3],a=>{let r=a[0],c=a[1],n=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((i,f)=>{([l=>{e.setEffectTypeRaw(3+r,!1,l),console.info(`${n}main type: ${Je[l]}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))},l=>{e.setEffectTypeRaw(3+r,!0,l),console.debug(`${n}sub type: ${l+1}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))}][c+f]||function(){})(i)})}).add([76,6,0],a=>{let r=a[0];r<64?e.setLetterDisplay(a.subarray(1),"XG letter display",r):E(e,Se,Date.now())}).add([76,7,0],a=>{let r=a[0];E(e,Q,0),E(e,oe,Date.now()+3200),t(e,Z,ue).fill(0);let c=a.subarray(1);for(let n=0;n>6-y&1,y++})}).add([76,8],(a,r)=>{let c=e.chRedir(a[0],r,!0),n=a[1],i=m.cc*c,f=`XG CH${c+1} `,l=`Unknown XG part address ${n}.`;a.subarray(2).forEach((d,p)=>{n<1?console.debug(l):n<41?([()=>{t(e,b)[i+g[0]]=d},()=>{t(e,b)[i+g[32]]=d},()=>{t(e,D)[c]=d},()=>{let y=e.chRedir(d,r,!0);t(e,H)[c]=y,c!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))},()=>{t(e,J)[c]=+!d},()=>{},()=>{e.setChType(c,d,S.xg),console.debug(`${f}type: ${et[d]||d}`)},()=>{t(e,x)[m.rpn*c+3]=d},!1,!1,()=>{t(e,b)[i+g[7]]=d},!1,!1,()=>{t(e,b)[i+g[10]]=d||128},!1,!1,()=>{t(e,b)[i+g[128]]=d},()=>{t(e,b)[i+g[93]]=d},()=>{t(e,b)[i+g[91]]=d},()=>{t(e,b)[i+g[94]]=d},()=>{t(e,b)[i+g[76]]=d},()=>{t(e,b)[i+g[77]]=d},()=>{t(e,b)[i+g[78]]=d},()=>{t(e,b)[i+g[74]]=d},()=>{t(e,b)[i+g[71]]=d},()=>{t(e,b)[i+g[73]]=d},()=>{t(e,b)[i+g[75]]=d},()=>{t(e,b)[i+g[72]]=d}][n+p-1]||(()=>{}))():n<48?console.debug(l):n<111?n>102&&n<105&&(t(e,b)[i+g[[5,65][n&1]]]=d):n<114?console.debug(l):n<116?console.debug(`${f}EQ ${["bass","treble"][n&1]} gain: ${d-64}dB`):n<118?console.debug(l):n<120?console.debug(`${f}EQ ${["bass","treble"][n&1]} freq: ${d}`):console.debug(l)})}).add([76,9],(a,r)=>{let c=e.chRedir(a[0],r,!0),n=a[1],i=`PLG-150VL CH${c+1} `;a.subarray(2).forEach((f,l)=>{let d=l+n;switch(d){case 1:{console.info(`${i}breath mode: ${["system","breath","velocity","touch EG"][f]}`);break}case 0:case 27:case 28:break;default:if(d<27){let p=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][d-3>>1];d&1?d<23?(console.debug(`${i}${p} control source: ${Ft(f)}`),f&&f<96&&e.allocateAce(f)):console.debug(`${i}${p} scale break point: ${f}`):console.debug(`${i}${p} depth: ${f-64}`)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][a[0]]} for CH${a[2]+1}.`)}).add([73,0,0],(a,r)=>{let c=a[0],n="MU1000 System: ";a.subarray(1).forEach((i,f)=>{let l=c+f;l==8?console.debug(`${n}LCD contrast set to ${i}.`):l==18?(E(e,ee,i?126:0),console.debug(`${n}bank defaults to ${i?"MU100 Native":"MU Basic"}.`)):l>=64&&l<69&&[()=>{e.dispatchEvent("channelactive",i)},()=>{i<8?(e.dispatchEvent("channelmin",i<<4),console.debug(`Octavia System: Minimum CH${(i<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{i<8?(e.dispatchEvent("channelmax",(i<<4)+15),console.debug(`Octavia System: Maximum CH${(i<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{E(e,se,!!i),console.info(`Octavia System: RS receiving ${["dis","en"][i]}abled.`)}][l-64]()})}).add([73,10,0],(a,r)=>{let c=a[0],n=`MU1000 RS${t(e,se)?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let i=e.chRedir(0,r,!0);t(e,se)&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+63)),console.info(`${n}Show CH1~64`);break}case 3:{let i=e.chRedir(a[1]<<5,r,!0);t(e,se)&&e.dispatchEvent("channelmin",i),t(e,se)&&e.dispatchEvent("channelmax",i+31),console.info(`${n}Show CH${i+1}~CH${i+32}`);break}default:console.debug(`${n}unknown switch ${c} invoked.`)}else if(c<32){if(t(e,se)){let i=e.chRedir(c-16+(t(e,Qe)<<4),r,!0);e.dispatchEvent("channelactive",i)}}else if(c<36){let i=e.chRedir(c-32<<4,r,!0);t(e,se)&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+15),E(e,Qe,c-32)),console.info(`${n}Show CH${i+1}~CH${i+16}`)}}).add([93,3],(a,r)=>{let c=e.chRedir(a[0],r,!0),n=`PLG-100SG CH${c+1} `,i=Date.now();if(a[1]==0){let f="",l=0;a.subarray(2).forEach((d,p)=>{p%2==0?f+=_t[d]||d.toString().padStart("0"):l+=d*13}),i>=t(e,je)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${Xt(f)}`,amend:!0}),E(e,je,i+Math.ceil(l/2)+t(e,qe)),j()&&console.debug(`${n}vocals: ${f}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)}),t(this,te).add([76,48],a=>{}).add([76,49],a=>{}).add([76,50],a=>{}).add([76,51],a=>{}),t(this,te).add([89,0],(a,r,c)=>{if(e.eprom){let n=a[0],i=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);j()&&console.debug(`MU1000 EPROM trail to 0x${i.toString(16).padStart(6,"0")}, ${n} bytes.`);let f=e.eprom.data;a.subarray(4).forEach((l,d)=>{let p=d>>3,y=d&7;if(y==7)for(let $=0;$<7;$++)f[i+7*p+$]+=(l>>6-$&1)<<7;else f[i+7*p+y]=l})}}).add([89,1],(a,r,c)=>{let n=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];j()&&console.debug(`MU1000 EPROM jump to 0x${n.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=n)}).add([89,2],(a,r,c)=>{if(e.eprom){let n=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);j()&&console.debug(`MU1000 EPROM write to 0x${n.toString(16).padStart(6,"0")}.`);let i=e.eprom.data;a.subarray(4).forEach((f,l)=>{let d=l>>3,p=l&7;if(p==7)for(let y=0;y<7;y++)i[n+7*d+y]+=(f>>6-y&1)<<7;else i[n+7*d+p]=f})}}).add([89,3],(a,r,c)=>{}),t(this,te).add([39,48],(a,r,c)=>{}).add([43,0,0],(a,r,c)=>{let n=[0,0,0,0],i=(f,l)=>{n[l]=f};if(a.subarray(1).forEach((f,l)=>{let d=l+a[0];[i,i,i,i,()=>{E(this,P,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,P))},()=>f-64,()=>f||128,()=>f,()=>f,()=>{console.debug(`TG300 variation on cc${f}.`)}][d](f,d)}),a[0]<4){let f=0;n.forEach(l=>{f=f<<4,f+=l}),f-=1024}}).add([43,1,0],(a,r,c)=>{}).add([43,2],(a,r,c)=>{let n=e.chRedir(a[0],r,!0),i=a[1],f=m.cc*n,l=`TG300 CH${n+1} `;a.subarray(2).forEach((d,p)=>{p<5?([()=>{},()=>{t(e,b)[f+g[0]]=d},()=>{t(e,b)[f+g[32]]=d},()=>{t(e,D)[n]=d},()=>{let y=e.chRedir(d,r,!0);t(e,H)[n]=y,n!=y&&(e.buildRchTree(),console.info(`${l}receives from CH${y+1}`))}][p+i]||(()=>{}))(d,p+i):p<21||(p<47?([()=>{t(e,J)[n]=+!d},()=>{},()=>{},()=>{t(e,x)[m.rpn*n+3]=d},()=>{},()=>{t(e,b)[f+g[7]]=d},!1,!1,()=>{t(e,b)[f+g[10]]=d||128},!1,!1,()=>{console.debug(`${l} AC1 at cc${d}`)},()=>{console.debug(`${l} AC2 at cc${d}`)},()=>{t(e,b)[f+g[128]]=d},()=>{t(e,b)[f+g[93]]=d},()=>{t(e,b)[f+g[91]]=d},()=>{t(e,b)[f+g[94]]=d},()=>{t(e,b)[f+g[76]]=d},()=>{t(e,b)[f+g[77]]=d},()=>{t(e,b)[f+g[74]]=d},()=>{t(e,b)[f+g[71]]=d},()=>{t(e,b)[f+g[73]]=d},()=>{t(e,b)[f+g[75]]=d},()=>{t(e,b)[f+g[72]]=d},()=>{t(e,b)[f+g[78]]=d}][p+i-21]||(()=>{}))(d,p+i):p<95||([()=>{t(e,b)[f+g[65]]=d},()=>{t(e,b)[f+g[5]]=d}][p+i-95]||(()=>{}))(d,p+i))})}).add([43,7,0],(a,r,c)=>{let n=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",n)}).add([43,7,1],(a,r,c)=>{E(e,Q,0),E(e,oe,Date.now()+3200),t(e,Z,ue).fill(0),a.forEach(function(n,i){let f=Math.floor(i/16),l=i%16,d=(l*3+f)*7,p=7,y=0;for(d-=l*5,f==2&&(p=2);y>6-y&1,y++})}),t(this,ae).add([66,18,0,0,127],(a,r,c)=>{e.switchMode("gs",!0),t(e,b)[m.cc*9]=120,t(e,b)[m.cc*25]=120,t(e,b)[m.cc*41]=120,t(e,b)[m.cc*57]=120,E(e,ee,3),E(e,I,!1),t(e,ge).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,r,c)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),t(e,b)[m.cc*9]=120,t(e,b)[m.cc*25]=120,t(e,b)[m.cc*41]=120,t(e,b)[m.cc*57]=120,E(e,I,!1),t(e,ge).fill(0),console.info("MIDI reset: GS");break}default:{let n=[0,0,0,0],i=(f,l)=>{n[l]=f};if(a.subarray(1).forEach((f,l)=>{let d=l+a[0];[i,i,i,i,p=>{E(this,P,p*129/16383*100),e.dispatchEvent("mastervolume",t(e,P))},p=>{},p=>{}][d](f,l)}),a[0]<4){let f=0;n.forEach(l=>{f=f<<4,f+=l}),f-=1024}}}}).add([66,18,64,1],a=>{let r=a[0];if(r<16){let c="".padStart(r," ");a.subarray(1).forEach((n,i)=>{c+=String.fromCharCode(Math.max(32,n))}),c=c.padEnd(16," "),console.debug(`GS patch name: ${c}`)}else r<48||(r<65?a.subarray(1).forEach((c,n)=>{let i=`GS ${r+n>55?"chorus":"reverb"} `;([()=>{console.info(`${i}type: ${yt[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${i}predelay: ${c}ms`)},()=>{console.info(`${i}type: ${Vt[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${i}to reverb: ${q(c)}`)},()=>{console.debug(`${i}to delay: ${q(c)}`)}][r+n-48]||(()=>{}))()}):r<80?console.debug(`Unknown GS patch address: ${r}`):r<91?a.subarray(1).forEach((c,n)=>{let i="GS delay ";([()=>{console.info(`${i}type: ${Kt[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${i}to reverb: ${q(c)}`)}][r+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${r}`))}).add([66,18,64,2],a=>{let r="GS EQ ";a.subarray(1).forEach((c,n)=>{([()=>{console.debug(`${r}low freq: ${[200,400][c]}Hz`)},()=>{console.debug(`${r}low gain: ${c-64}dB`)},()=>{console.debug(`${r}high freq: ${[3e3,6e3][c]}Hz`)},()=>{console.debug(`${r}high gain: ${c-64}dB`)}][a[0]+n]||function(){console.warn(`Unknown GS EQ address: ${a[0]+n}`)})()})}).add([66,18,64,3],a=>{let r="GS EFX ",c=function(n,i){let f=zt(t(e,W).subarray(10,12),i,n);f&&console.debug(`${r}${mt(t(e,W).subarray(10,12))} ${f}`)};a.subarray(1).forEach((n,i)=>{([()=>{e.setEffectTypeRaw(3,!1,32+n),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,n),console.info(`${r}type: ${mt(t(e,W).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,()=>{console.debug(`${r}to reverb: ${q(n)}dB`)},()=>{console.debug(`${r}to chorus: ${q(n)}dB`)},()=>{console.debug(`${r}to delay: ${q(n)}dB`)},!1,()=>{console.debug(`${r}1 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${r}1 depth: ${n-64}`)},()=>{console.debug(`${r}2 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${r}2 depth: ${n-64}`)},()=>{console.debug(`${r}to EQ: ${n?"ON":"OFF"}`)}][a[0]+i]||function(f,l){console.warn(`Unknown GS EFX address: ${l}`)})(n,a[0]+i)})}).add([66,18,65],a=>{}).add([69,18,16],a=>{var r;switch(a[0]){case 0:{let c=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",c);break}case 32:{E(e,oe,Date.now()+3200),a[1]==0&&E(e,Q,Math.max(Math.min(a[2]-1,9),0));break}default:if(a[0]<11){t(e,Q)>9&&E(e,Q,0),E(e,oe,Date.now()+3200),(r=t(e,pe)[a[0]-1])!=null&&r.length||(t(e,pe)[a[0]-1]=new Uint8Array(256));let c=t(e,pe)[a[0]-1],n=a[1];c.fill(0);let i=a.subarray(2);for(let f=0;f>4-k&1,k++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let h=function(a,r,c){let n=a[0],i=m.cc*r,f=m.rpn*r,l=`GS CH${r+1} `;n<3?a.subarray(1).forEach((d,p)=>{[()=>{t(e,b)[i+g[0]]=d},()=>{t(e,D)[r]=d},()=>{let y=e.chRedir(d,c,!0);t(e,H)[r]=y,r!=y&&(e.buildRchTree(),console.info(`${l}receives from CH${y+1}`))}][n+p]()}):n<19||(n<44?a.subarray(1).forEach((d,p)=>{([()=>{t(e,J)[r]=+!d},!1,()=>{e.setChType(r,d<<1,S.gs),console.debug(`${l}type: ${d?"drum ":"melodic"}${d||""}`)},()=>{t(e,x)[f+3]=d},!1,()=>{t(e,b)[i+g[7]]=d},!1,!1,()=>{t(e,b)[i+g[10]]=d||128},!1,!1,()=>{console.debug(`${l}CC 1: cc${d}`)},()=>{console.debug(`${l}CC 2: cc${d}`)},()=>{t(e,b)[i+g[93]]=d},()=>{t(e,b)[i+g[91]]=d},!1,!1,()=>{t(e,x)[f+1]=d},()=>{t(e,x)[f+2]=d},()=>{t(e,b)[i+g[94]]=d}][n+p-19]||(()=>{}))()}):n<76||console.debug(`Unknown GS part address: ${n}`))},o=function(a,r){let c=a[0],n=`GS CH${r+1} `;c<2?a.subarray(1).forEach((i,f)=>{[()=>{t(e,b)[m.cc*r+g[32]]=i},()=>{}][c+f]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?a.subarray(1).forEach((i,f)=>{[()=>{console.debug(`${n}EQ: o${["ff","n"][i]}`)},()=>{},()=>{console.debug(`${n}EFX: o${["ff","n"][i]}`),t(e,ze)[r]=i}][c+f-32]()}):console.warn(`Unknown GS misc address: ${c}`)};t(this,ae).add([66,18,64,16],(a,r)=>{h(a,e.chRedir(9,r,!0),r)}).add([66,18,64,17],(a,r)=>{h(a,e.chRedir(0,r,!0),r)}).add([66,18,64,18],(a,r)=>{h(a,e.chRedir(1,r,!0),r)}).add([66,18,64,19],(a,r)=>{h(a,e.chRedir(2,r,!0),r)}).add([66,18,64,20],(a,r)=>{h(a,e.chRedir(3,r,!0),r)}).add([66,18,64,21],(a,r)=>{h(a,e.chRedir(4,r,!0),r)}).add([66,18,64,22],(a,r)=>{h(a,e.chRedir(5,r,!0),r)}).add([66,18,64,23],(a,r)=>{h(a,e.chRedir(6,r,!0),r)}).add([66,18,64,24],(a,r)=>{h(a,e.chRedir(7,r,!0),r)}).add([66,18,64,25],(a,r)=>{h(a,e.chRedir(8,r,!0),r)}).add([66,18,64,26],(a,r)=>{h(a,e.chRedir(10,r,!0),r)}).add([66,18,64,27],(a,r)=>{h(a,e.chRedir(11,r,!0),r)}).add([66,18,64,28],(a,r)=>{h(a,e.chRedir(12,r,!0),r)}).add([66,18,64,29],(a,r)=>{h(a,e.chRedir(13,r,!0),r)}).add([66,18,64,30],(a,r)=>{h(a,e.chRedir(14,r,!0),r)}).add([66,18,64,31],(a,r)=>{h(a,e.chRedir(15,r,!0),r)}).add([66,18,64,64],(a,r)=>{o(a,e.chRedir(9,r,!0))}).add([66,18,64,65],(a,r)=>{o(a,e.chRedir(0,r,!0))}).add([66,18,64,66],(a,r)=>{o(a,e.chRedir(1,r,!0))}).add([66,18,64,67],(a,r)=>{o(a,e.chRedir(2,r,!0))}).add([66,18,64,68],(a,r)=>{o(a,e.chRedir(3,r,!0))}).add([66,18,64,69],(a,r)=>{o(a,e.chRedir(4,r,!0))}).add([66,18,64,70],(a,r)=>{o(a,e.chRedir(5,r,!0))}).add([66,18,64,71],(a,r)=>{o(a,e.chRedir(6,r,!0))}).add([66,18,64,72],(a,r)=>{o(a,e.chRedir(7,r,!0))}).add([66,18,64,73],(a,r)=>{o(a,e.chRedir(8,r,!0))}).add([66,18,64,74],(a,r)=>{o(a,e.chRedir(10,r,!0))}).add([66,18,64,75],(a,r)=>{o(a,e.chRedir(11,r,!0))}).add([66,18,64,76],(a,r)=>{o(a,e.chRedir(12,r,!0))}).add([66,18,64,77],(a,r)=>{o(a,e.chRedir(13,r,!0))}).add([66,18,64,78],(a,r)=>{o(a,e.chRedir(14,r,!0))}).add([66,18,64,79],(a,r)=>{o(a,e.chRedir(15,r,!0))}),t(this,ye).add([54,65],(a,r)=>{e.switchMode("x5d");let c=(a[1]<<7)+a[0],n=(a[3]<<7)+a[2],i=e.chRedir(c&15,r,!0),f=m.cc*i;[()=>{n<1||(n<101?(e.setChType(i,e.CH_MELODIC,S.x5d),t(e,D)[i]=n-1,t(e,b)[f+g[0]]=82):n<229?(e.setChType(i,e.CH_MELODIC,S.x5d),t(e,D)[i]=n-101,t(e,b)[f+g[0]]=56):(e.setChType(i,e.CH_DRUMS,S.x5d),t(e,D)[i]=Zt[n-229]||0,t(e,b)[f+g[0]]=62))},()=>{t(e,b)[f+g[7]]=n},()=>{n<31&&(t(e,b)[f+g[10]]=Math.round((n-15)*4.2+64))},()=>{t(e,b)[f+g[93]]=tt(n)},()=>{t(e,b)[f+g[91]]=tt(n)},()=>{t(e,x)[i*m.rpn+3]=n>8191?n-16320:64+n},()=>{t(e,x)[i*m.rpn+1]=n>8191?n-16320:64+n},()=>{n>0&&(t(e,x)[i*m.rpn]=n)},()=>{}][c>>4]()}).add([54,76,0],(a,r)=>{e.switchMode("x5d",!0);let c="",n=82,i=0,f=0,l="MSB PRG LSB NME";ce(a,function(d,p){if(p<16400){let y=p%164;switch(!0){case y<10:{d>31&&(c+=String.fromCharCode(d));break}case y==11:{l+=` -${n} ${i} ${f} ${c.trim().replace("Init Voice","")}`,i++,c="";break}}i>99&&(n=90,i=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(l)}).add([54,77,0],(a,r)=>{e.switchMode("x5d",!0);let c="",n=90,i=0,f=0,l="MSB PRG LSB NME";ce(a,function(d,p){if(p<13600){let y=p%136;switch(!0){case y<10:{d>31&&(c+=String.fromCharCode(d));break}case y==11:{l+=` -${n} ${i} ${f} ${c.trim().replace("Init Combi","")}`,i++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(l)}).add([54,78],(a,r)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,r)=>{e.switchMode("x5d",!0),ce(a,(c,n)=>{n>0&&n<3&&(e.setEffectType(n-1,44,c),e.dispatchEvent(`efx${["reverb","chorus"][n-1]}`,e.getEffectType(n-1)))})}).add([54,104],(a,r)=>{e.switchMode("x5d",!0),ce(a,function(c,n,i,f){if(n<192){let l=e.chRedir(Math.floor(n/12),r,!0),d=l*m.cc;switch(n%12){case 0:{c<128?(e.setChType(l,e.CH_MELODIC,S.x5d),t(e,b)[d+g[0]]=82,t(e,D)[l]=c):(e.setChType(l,e.CH_DRUMS,S.x5d),t(e,b)[d+g[0]]=62,t(e,D)[l]=Zt[c-128]),c>0&&(t(e,U)[l]=1);break}case 1:{t(e,b)[d+g[7]]=c;break}case 2:{t(e,x)[l*m.rpn+3]=c>127?c-192:64+c;break}case 3:{t(e,x)[l*m.rpn+1]=c>127?c-192:64+c;break}case 4:{c<31&&(t(e,b)[d+g[10]]=Math.round((c-15)*4.2+64));break}case 5:{let p=c>>4,y=c&15;t(e,b)[d+g[91]]=tt(y),t(e,b)[d+g[93]]=tt(p);break}case 10:break;case 11:{let p=e.chRedir(c&15,r,!0),y=c>>4;t(e,H)[l]=c,(p!=l||y)&&(console.info(`X5D Part CH${l+1} receives from CH${p+1}.`),e.buildRchTree())}}}else{let l=e.chRedir(n-192,r,!0)}})}),t(this,ae).add([22,18,127],a=>{e.switchMode("mt32",!0),E(e,I,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,r,c)=>{e.switchMode("mt32");let n=e.chRedir(c,r,!0),i=a[1];a.subarray(2).forEach((f,l)=>{let d=l+i;t(e,$e)[d+(n-1)*16]=f,([!1,()=>{let p=t(e,$e)[n-1<<4];if(p<3)if(t(e,de)[n]=1,p==2)for(let y=0;y{t(e,x)[n*m.rpn+3]=f+40},()=>{t(e,x)[n*m.rpn+1]=f+14},()=>{t(e,x)[n*m.rpn]=f},!1,()=>{t(e,b)[m.cc*n+g[91]]=f?127:0},!1,()=>{t(e,b)[m.cc*n+g[7]]=f},()=>{t(e,b)[m.cc*n+g[10]]=Math.ceil(f*9.05)}][d]||(()=>{}))()})}).add([22,18,1],(a,r,c)=>{e.switchMode("mt32");let n=e.chRedir(c,r,!0)}).add([22,18,2],(a,r,c)=>{e.switchMode("mt32");let n=e.chRedir(c,r,!0),i=a[1]+(a[0]<<7);i<10&&(t(e,de)[n]=1),a.subarray(2).forEach((f,l)=>{let d=l+i;d<14&&(t(e,re)[(n-1)*m.cmt+d]=f)})}).add([22,18,3],(a,r,c)=>{if(e.switchMode("mt32"),a[0]){let n=a[1]-16}else{let n=a[1];a.subarray(2).forEach((i,f)=>{let l=f+n;t(e,$e)[l]=i;let d=e.chRedir(1+l>>4,r,!0),p=l&15;([!1,()=>{let y=t(e,$e)[d-1<<4];if(y<3)if(t(e,de)[d]=1,y==2)for(let $=0;${t(e,x)[d*m.rpn+3]=i+40},()=>{t(e,x)[d*m.rpn+1]=i+14},()=>{t(e,x)[d*m.rpn]=i},!1,()=>{t(e,b)[m.cc*d+g[91]]=i?127:0},!1,()=>{t(e,b)[m.cc*d+g[7]]=i},()=>{t(e,b)[m.cc*d+g[10]]=Math.ceil(i*9.05)}][p]||(()=>{}))()})}}).add([22,18,4],(a,r,c)=>{e.switchMode("mt32");let n=a[1]+(a[0]<<7);a.subarray(2).forEach((i,f)=>{let l=f+n,d=e.chRedir(Math.floor(l/246+1),r,!0),p=l%246;p<14&&(t(e,re)[(d-1)*m.cmt+p]=i),p<10&&(t(e,de)[d]=1)})}).add([22,18,5],(a,r,c)=>{e.switchMode("mt32");let n=(a[0]<<7)+a[1];a.subarray(2).forEach((i,f)=>{let l=n+f,d=Math.floor(l/8),p=l&7,y=d*8;t(e,Ke)[l]=i,([!1,()=>{let $=t(e,Ke)[y];if($<3){let k="";if($==2){let w=m.cmt*d;k=`MT-m:${i.toString().padStart(3,"0")}`}else k=e.baseBank.get(0,i+($<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:d}),e.userBank.load(`MSB LSB PRG NME -000 127 ${d} ${k}`,!0)}}][p]||(()=>{}))()})}).add([22,18,8],(a,r,c)=>{e.switchMode("mt32");let n=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((i,f)=>{let l=n+f;l>1)*m.cmt+l]=i)})}).add([22,18,16],(a,r,c)=>{e.switchMode("mt32");let n=a[1],i=!1,f=function(l,d){t(e,H)[d-12]=l,i=!0};a.subarray(2).forEach((l,d)=>{let p=d+n;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,f,f,f,f,f,f,f,f,f,()=>{E(e,P,l),e.dispatchEvent("mastervolume",t(e,P))}][p]||(()=>{}))(l,d)}),i&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let r=a[1],c=" ".repeat(r);a.subarray(2).forEach(n=>{n>31&&(c+=String.fromCharCode(n))}),E(e,fe,c.padStart(20," ")),E(e,Se,Date.now()+3200)}).add([22,18,82],(a,r)=>{let c=e.chRedir(0,r,!0);for(let n=0;n<16;n++)t(e,N).ano(c+n),n&&n<10&&(t(e,D)[c+n]=Et[n-1]);console.info("MT-32 alt reset complete.")}),t(this,ye).add([66,0],(a,r)=>{e.switchMode("ns5r",!0),E(e,I,!1),console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,r)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),E(e,I,!1)}).add([66,18,0,0],(a,r)=>{let c=a[0];switch(c){case 124:case 126:case 127:{e.switchMode("ns5r",!0),E(e,I,!1);break}case 125:{console.info(`NS5R drum setup reset: ${a}`);break}default:if(c<10){let n=[0,0,0,0],i=(f,l)=>{n[l]=f};if(a.subarray(1).forEach((f,l)=>{[i,i,i,i,()=>{E(e,P,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,P))},()=>f-64,()=>f-64,()=>{},()=>{},()=>{}][c+l]()}),a[0]<4){let f=0;n.forEach(l=>{f=f<<4,f+=l}),f-=1024}}}}).add([66,18,0,1],(a,r)=>{}).add([66,18,0,2],(a,r)=>{}).add([66,18,1],(a,r)=>{let c=e.chRedir(a[0],r,!0),n=c*m.cc,i=a[1],f=`NS5R CH${c+1} `;a.subarray(2).forEach((l,d)=>{let p=i+d;p<3?[()=>{t(e,b)[n+g[0]]=l||121},()=>{t(e,b)[n+g[32]]=l},()=>{t(e,D)[c]=l}][p]():p<8||(p<14?[()=>{let y=e.chRedir(l,r,!0);t(e,H)[c]=y,c!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))},()=>{t(e,J)[c]=+!l},()=>{e.setChType(c,l,S.ns5r),console.debug(`${f}type: ${et[l]}`)},()=>{t(e,x)[m.rpn*c+3]=l},()=>{},()=>{}][p-8]():p<16||(p<33?[()=>{t(e,b)[n+g[7]]=l},()=>{t(e,b)[n+g[11]]=l},()=>{},()=>{},()=>{t(e,b)[n+g[10]]=l||128},()=>{},()=>{},()=>{t(e,b)[n+g[93]]=l},()=>{t(e,b)[n+g[91]]=l},()=>{t(e,b)[n+g[76]]=l},()=>{t(e,b)[n+g[77]]=l},()=>{t(e,b)[n+g[78]]=l},()=>{t(e,b)[n+g[74]]=l},()=>{t(e,b)[n+g[71]]=l},()=>{t(e,b)[n+g[73]]=l},()=>{t(e,b)[n+g[75]]=l},()=>{t(e,b)[n+g[72]]=l}][p-16]():p<112||p<114&&[()=>{t(e,b)[n+g[5]]=l},()=>{t(e,b)[n+g[65]]=l}][p-112]()))})}).add([66,18,8,0],(a,r)=>{let c=a[0];if(c<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let n=c-32;E(e,oe,Date.now()+3200),E(e,Q,10),t(e,Z,ue).fill(0);let i=a.subarray(1),f=4;i.forEach(function(l,d){let p=d+n,y=p>>4,$=p&15;if(p<80){let k=y>3,w=0,T=y0;)t(e,Z,ue)[$*32+y*7+(T-w)]=k&1,k=k>>1,w++}})}}).add([66,52],(a,r)=>{e.switchMode("ns5r",!0),E(e,I,!1);let c="";ce(a,(n,i)=>{i<8?(n>31&&(c+=String.fromCharCode(n)),i==7&&(e.aiEfxName=c)):i<10&&(e.setEffectType(i-8,44,n),e.dispatchEvent(`efx${["reverb","chorus"][i-8]}`,e.getEffectType(i-8)))})}).add([66,53],(a,r)=>{e.switchMode("ns5r",!0),E(e,I,!1),ce(a,function(c,n){switch(!0){case n<2944:{let i=e.chRedir(Math.floor(n/92),r,!0),f=i*m.cc;switch(n%92){case 0:{t(e,b)[f+g[0]]=c||121;break}case 1:{t(e,b)[f+g[32]]=c;break}case 2:{t(e,D)[i]=c,c>0&&(t(e,U)[i]=1);break}case 3:{let l=e.chRedir(c,r,!0);t(e,H)[i]=l,i!=l&&(console.info(`NS5R CH${i+1} receives from CH${l+1}.`),e.buildRchTree())}case 7:break;case 8:{t(e,x)[i*m.rpn+3]=c<40||c>88?c+(c>63?-192:64):c;break}case 9:case 10:{t(e,b)[f+g[7]]=c;break}case 11:{t(e,b)[f+g[11]]=c;break}case 14:{t(e,b)[f+g[10]]=c||128;break}case 19:{t(e,b)[f+g[93]]=c;break}case 20:{t(e,b)[f+g[91]]=c;break}case 84:{t(e,b)[f+g[65]]=c;break}case 85:{t(e,b)[f+g[5]]=c;break}}break}case n<3096:break;case n<3134:break;case n<8566:break}})}).add([66,54],(a,r)=>{e.switchMode("ns5r",!0);let c="",n=80,i=0,f=0,l="MSB PRG LSB NME";ce(a,function(d,p){let y=p%158;switch(!0){case y<10:{d>31&&(c+=String.fromCharCode(d));break}case y==11:{n=d&127;break}case y==12:{f=d&127;break}case y==13:{l+=` -${n} ${i} ${f} ${c.trim().replace("Init Voice","")}`,i++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(l)}).add([66,55],(a,r)=>{e.switchMode("ns5r",!0);let c="",n=88,i=0,f=0,l="MSB PRG LSB NME";ce(a,function(d,p){let y=p%126;switch(!0){case y<10:{d>31&&(c+=String.fromCharCode(d));break}case y==11:break;case y==12:break;case y==13:{l+=` -${n} ${i} ${f} ${c.trim().replace("Init Combi","")}`,i++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(l)}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let r=new Uint8Array(5760);ce(a,(c,n,i)=>{if(n<720)for(let f=0;f<8;f++)r[n*8+f]=c>>7-f&1}),e.dispatchEvent("screen",{type:"ns5r",data:r})}).add([76],(a,r,c)=>{t(e,ye).run([66,...a],r,c)}),t(this,Ae).add([16,0,8,0],(a,r,c)=>{let n=(a[2]<<4)+a[3],i="K11 ";([()=>{e.switchMode("k11",!0),E(e,I,!1),E(e,ee,n?4:0),console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,n),console.debug(`${i}reverb type: ${n}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${i}reverb time: ${n}`)},()=>{console.debug(`${i}reverb time: ${n}`)},()=>{console.debug(`${i}reverb predelay: ${n}`)},()=>{console.debug(`${i}reverb predelay: ${n}`)},()=>{console.debug(`${i}depth high: ${n}`)},()=>{console.debug(`${i}depth high: ${n}`)},()=>{console.debug(`${i}depth low: ${n}`)},()=>{console.debug(`${i}depth low: ${n}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,r,c)=>{let n=e.chRedir(a[1],r,!0),i=m.cc*n,f=m.rpn*n,l=(a[3]<<4)+a[4],d=`K11 CH${n+1} `;([()=>{l<128?(e.setChType(n,e.CH_MELODIC,S.k11),t(e,b)[i+g[0]]=0,t(e,D)[n]=l):(e.setChType(n,e.CH_DRUMS,S.k11),t(e,D)[n]=l-128)},()=>{let p=e.chRedir(l,r,!0);t(e,H)[n]=p,n!=p&&(e.buildRchTree(),console.info(`${d}receives from CH${p+1}`))},()=>{t(e,b)[i+g[7]]=l},()=>{t(e,U)[n]=l},()=>{t(e,b)[i+g[10]]=l},()=>{t(e,x)[f+3]=l+40},()=>{t(e,x)[f+1]=l>>1,t(e,x)[f+2]=l&1},()=>{t(e,b)[i+g[91]]=l?127:0},()=>{},()=>{t(e,b)[i+g[74]]=l},()=>{t(e,b)[i+g[73]]=l},()=>{t(e,b)[i+g[72]]=l}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,r,c)=>{let n=(a[2]<<4)+a[3],i="GMLX ";([()=>{console.debug(`${i}reverb type: ${n}`)},()=>{console.debug(`${i}reverb time: ${n}`)},()=>{console.debug(`${i}reverb predelay: ${n}`)},()=>{console.debug(`${i}depth high: ${n}`)},()=>{console.debug(`${i}depth low: ${n}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,r,c)=>{let n=(a[2]<<4)+a[3],i=e.chRedir(a[1],r,!0),f=i*m.cc;[()=>{n<128?(e.setChType(i,e.CH_MELODIC,S.k11),t(e,b)[f+g[0]]=0,t(e,b)[f+g[32]]=0,t(e,D)[i]=n):n<160?(e.setChType(i,e.CH_MELODIC,S.k11),t(e,b)[f+g[0]]=0,t(e,b)[f+g[32]]=7,t(e,D)[i]=n-100):(e.setChType(i,e.CH_DRUMS,S.k11),t(e,b)[f+g[0]]=122,t(e,b)[f+g[32]]=0,t(e,D)[i]=n-160)},()=>{let l=e.chRedir(n,r,!0);t(e,H)[i]=l,i!=l&&(e.buildRchTree(),console.info(`GMLX CH${i+1} receives from CH${l+1}`))}][a[0]]()}).add([16,0,9,4],(a,r,c)=>{let n=(a[2]<<4)+a[3],i=e.chRedir(a[1],r,!0),f=i*m.cc,l=i*m.rpn,d=`GMLX CH${i+1} `;[()=>{t(e,U)[i]=n},()=>{t(e,b)[f+g[7]]=n},()=>{t(e,b)[f+g[10]]=n},()=>{t(e,b)[f+g[91]]=n?127:0},()=>{t(e,x)[l+3]=n+40},()=>{t(e,x)[l+1]=n},()=>{t(e,x)[l]=n},()=>{}][a[0]]()}),t(this,Ue).add([66,93,64],(a,r,c)=>{let n=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{E(e,P,n*129/16383*100),e.dispatchEvent("mastervolume",t(e,P));break}case 5:{n-64;break}case 6:{console.debug(`SG global reverb: ${n?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(a[1]){case 48:{console.debug(`SG reverb type: ${yt[n]}`);break}}break}default:if(a[0]>>4==1){let i=e.chRedir(a[0]&15,r,!0);if(a[1]==2){let f=e.chRedir(n,r,!0);t(e,H)[i]=f,i!=f&&(e.buildRchTree(),console.info(`SG CH${i+1} receives from CH${f+1}`))}else a[1]==19&&(t(e,b)[m.cc*i+g[7]]=n)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,Le).add([9],(a,r,c)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),t(this,te).add([127,0],(a,r,c)=>{e.switchMode("motif");let n=new Uint8Array([127,1,...a]);t(e,te).run(n,r,c)}).add([127,1,0,0],(a,r,c)=>{e.switchMode("s90es");let n="S90/Motif ES system ",i=a[0];a.subarray(1).forEach((f,l)=>{([()=>{E(e,P,f*12900/16383),e.dispatchEvent("mastervolume",t(e,P))}][i+l]||(()=>{console.info(`Unrecognized ${n}ID: ${i+l}`)}))()})}).add([127,1,0,0,14],(a,r,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk header ",i=[];i[95]=(f,l,d)=>{console.debug(`${n}multi edit buffer: ${f[1]}`)},(i[a[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,r,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk footer ",i=[];i[95]=(f,l,d)=>{console.debug(`${n}multi edit buffer: ${f[1]}`)},(i[a[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,r,c)=>{e.switchMode("s90es");let n=e.chRedir(a[0],r,!0),i=m.cc*n,f=a[1],l=`S90/Motif ES bulk CH${n<16?n+1:"U"+(n-95)} `;console.debug(l,a),!(a[0]>15)&&a.subarray(2).forEach((d,p)=>{([()=>{t(e,b)[i+g[0]]=d},()=>{d&&(t(e,U)[n]=1),t(e,b)[i+g[32]]=d,e.setChType(n,[32,40].indexOf(d)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,O),!0)},()=>{d&&(t(e,U)[n]=1),t(e,D)[n]=d},()=>{let y=e.chRedir(d,r,!0);t(e,H)[n]=y,n!=y&&(e.buildRchTree(),console.info(`${l}receives from CH${y+1}`))},()=>{t(e,J)[n]=d?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{t(e,b)[i+g[7]]=d},()=>{t(e,b)[i+g[10]]=d},!1,!1,!1,()=>{t(e,b)[i+g[91]]=d},()=>{t(e,b)[i+g[93]]=d},()=>{t(e,b)[i+g[94]]=d},()=>{t(e,b)[i+g[128]]=d},()=>{},()=>{t(e,b)[i+g[74]]=d},()=>{t(e,b)[i+g[71]]=d},!1,()=>{t(e,b)[i+g[65]]=d},()=>{t(e,b)[i+g[5]]=d},()=>{}][f+p]||(()=>{}))()})}).add([127,1,54,16],(a,r,c)=>{e.switchMode("s90es");let n=a[0];a.subarray(1).forEach((i,f)=>{let d=`S90/Motif ES EQ${(f>>2)+1} `;([()=>{let p=i-64},()=>{let p=Fe[i]},()=>{let p=i/10},()=>{let p=i}][n+f&3]||(()=>{}))()})}),t(this,ae).add([0,72,18,0,0,0,0],(a,r,c)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,r,c)=>{let n=a[0]>>5,i=a[0]&31;switch(n){case 0:{console.debug(`Unknown SD-90 global effects message: -%o`,a);break}case 1:{let f=e.chRedir(i,r,!0),l=a[1],d=f*m.cc;a.subarray(2).forEach((p,y)=>{let $=l+y;$<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,b)[d+g[0]]=p,p){case 104:case 105:case 106:case 107:case 120:{t(e,M)[f]||e.setChType(f,e.CH_DRUMS);break}default:t(e,M)[f]&&e.setChType(f,e.CH_MELODIC)}},()=>{t(e,b)[d+g[32]]=p},()=>{t(e,D)[f]=p},()=>{t(e,b)[d+g[7]]=p},()=>{t(e,b)[d+g[10]]=p},()=>{},()=>{},()=>{p<2&&(t(e,J)[f]=p)},()=>{p<2&&(t(e,b)[d+g[68]]=p?127:0)},()=>{},()=>{p<2&&(t(e,b)[d+g[65]]=p?127:0)},()=>{t(e,b)[d+g[5]]=p&15<<4|t(e,b)[d+g[5]]&15},()=>{t(e,b)[d+g[5]]=p&15|(t(e,b)[d+g[5]]&240)>>4},()=>{t(e,b)[d+g[74]]=p},()=>{t(e,b)[d+g[71]]=p},()=>{t(e,b)[d+g[73]]=p},()=>{t(e,b)[d+g[72]]=p},0,0,0,0,0,0,0,()=>{t(e,b)[d+g[128]]=p},()=>{t(e,b)[d+g[93]]=p},()=>{t(e,b)[d+g[91]]=p},0,0,()=>{t(e,b)[d+g[75]]=p},()=>{t(e,b)[d+g[76]]=p},()=>{t(e,b)[d+g[77]]=p},()=>{t(e,b)[d+g[78]]=p}][$]||(()=>{}))():$<63||($<64?t(e,M)[f]?t(e,b)[d+g[0]]=104|p:t(e,b)[d+g[0]]=96|p:console.debug(`Unknown SD-90 global CH${f+1} param setup message: -%o`,a))});break}case 2:{let f=e.chRedir(i,r,!0),l=a[1];console.debug(`Unknown SD-90 global CH${f+1} MIDI setup message: +`),a.slice(0,2)){case"@I":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(n=a.slice(2))==null?void 0:n.trimLeft()});break}case"@K":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(l=a.slice(2))==null?void 0:l.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(i=a.slice(2))==null?void 0:i.trimLeft()});break}case"@T":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(s=a.slice(2))==null?void 0:s.trimLeft()});break}case"@V":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(o=a.slice(2))==null?void 0:o.trimLeft()});break}case"XF":{let f=a.slice(2).split(":");switch(f[0]){case"hd":{f.slice(1).forEach((u,g)=>{u.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][g],data:u})});break}case"ln":{f.slice(1).forEach((u,g)=>{u.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][g],data:u})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:t(this,L)?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` +`).forEach((f,u)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:f,mask:u!=0})})}},t(this,V)[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},t(this,V)[3]=function(a,n){n<1&&t(this,Ae)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},t(this,V)[4]=function(a,n){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},t(this,V)[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},t(this,V)[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},t(this,V)[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},t(this,V)[32]=function(a){w(this,Ae,a[0]+1)},t(this,V)[33]=function(a,n){t(e,Te)[n]=a+1},t(this,V)[81]=function(a,n){w(e,We,a/1e3)},t(this,V)[127]=function(a,n){t(e,Pe).run(a,n)},t(this,Pe).default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},t(this,Pe).add([67,0,1],function(a,n){t(e,Te)[n]=a[0]+1}),w(this,Ie,new ce("universal non-realtime")),w(this,Ue,new ce("universal realtime")),w(this,re,new ce("Yamaha")),w(this,se,new ce("Roland")),w(this,ve,new ce("Korg")),w(this,Le,new ce("Kawai")),w(this,Be,new ce("Akai")),w(this,Ne,new ce("Casio"));let r=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,a)};t(this,Ie).default=r,t(this,Ue).default=r,t(this,re).default=r,t(this,se).default=r,t(this,ve).default=r,t(this,Le).default=r,t(this,Be).default=r,t(this,Ne).default=r,t(this,Ie).add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),w(e,L,t(e,L)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),t(this,Ue).add([4,1],a=>{w(e,U,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,U))}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64),t(this,re).add([76,0,0],a=>{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),w(e,L,!1),console.info("MIDI reset: XG");break}default:{let n=[0,0,0,0],l=(i,s)=>{n[s]=i};if(a.subarray(1).forEach((i,s)=>{let o=s+a[0];([l,l,l,l,f=>{w(this,U,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,U))},f=>{},f=>{}][o]||(()=>{}))(i,s)}),a[0]<4){let i=0;n.forEach(s=>{i=i<<4,i+=s}),i-=1024}}}}).add([76,2,1],a=>{let n="XG ";a[0]<32?(n+="reverb ",a.subarray(1).forEach((l,i)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${n}main type: ${at[s]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{e.setEffectTypeRaw(0,!0,s),console.debug(`${n}sub type: ${s+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{console.debug(`${n}time: ${Ht(s)}s`)},s=>{console.debug(`${n}diffusion: ${s}`)},s=>{console.debug(`${n}initial delay: ${s}`)},s=>{console.debug(`${n}HPF cutoff: ${ze[s]}Hz`)},s=>{console.debug(`${n}LPF cutoff: ${ze[s]}Hz`)},s=>{console.debug(`${n}width: ${s}`)},s=>{console.debug(`${n}height: ${s}`)},s=>{console.debug(`${n}depth: ${s}`)},s=>{console.debug(`${n}wall type: ${s}`)},s=>{console.debug(`${n}dry/wet: ${s}`)},s=>{console.debug(`${n}send: ${W(s)}dB`)},s=>{console.debug(`${n}pan: ${s-64}`)},!1,!1,s=>{console.debug(`${n}delay: ${s}`)},s=>{console.debug(`${n}density: ${s}`)},s=>{console.debug(`${n}balance: ${s}`)},s=>{},s=>{console.debug(`${n}feedback: ${s}`)},s=>{}][a[0]+i]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(l)})):a[0]<64?(n+="chorus ",a.subarray(1).forEach((l,i)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${n}main type: ${at[s]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{e.setEffectTypeRaw(1,!0,s),console.debug(`${n}sub type: ${s+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{console.debug(`${n}LFO: ${Nt[s]}Hz`)},s=>{},s=>{console.debug(`${n}feedback: ${s}`)},s=>{console.debug(`${n}delay offset: ${Gt(s)}ms`)},s=>{},s=>{console.debug(`${n}low: ${ze[s]}Hz`)},s=>{console.debug(`${n}low: ${s-64}dB`)},s=>{console.debug(`${n}high: ${ze[s]}Hz`)},s=>{console.debug(`${n}high: ${s-64}dB`)},s=>{console.debug(`${n}dry/wet: ${s}`)},s=>{console.debug(`${n}send: ${W(s)}dB`)},s=>{console.debug(`${n}pan: ${s-64}`)},s=>{console.debug(`${n}to reverb: ${W(s)}dB`)},!1,s=>{},s=>{},s=>{},s=>{console.debug(`${n}LFO phase diff: ${(s-64)*3}deg`)},s=>{console.debug(`${n}input mode: ${s?"stereo":"mono"}`)},s=>{}][a[0]-32+i]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(l)})):a[0]<86?(n+="variation ",a.subarray(1).forEach((l,i)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${n}main type: ${at[s]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},s=>{e.setEffectTypeRaw(2,!0,s),console.debug(`${n}sub type: ${s+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+i]||function(){})(l)})):a[0]<97?(n+="variation ",a.subarray(1).forEach((l,i)=>{[s=>{console.debug(`${n}send: ${W(s)}dB`)},s=>{console.debug(`${n}pan: ${s-64}`)},s=>{console.debug(`${n}to reverb: ${W(s)}dB`)},s=>{console.debug(`${n}to chorus: ${W(s)}dB`)},s=>{console.debug(`${n}connection: ${s?"system":"insertion"}`)},s=>{console.debug(`${n}channel: CH${s+1}`)},s=>{console.debug(`${n}mod wheel: ${s-64}`)},s=>{console.debug(`${n}bend wheel: ${s-64}`)},s=>{console.debug(`${n}channel after touch: ${s-64}`)},s=>{console.debug(`${n}AC1: ${s-64}`)},s=>{console.debug(`${n}AC2: ${s-64}`)}][a[0]-86+i](l)})):a[0]>111&&a[0]<118?n+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((n,l)=>{let i=l+a[0];if(i==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][n]}`);else{let s=i-1>>2,o=i-1&3,f=`XG EQ ${s} ${["gain","freq","Q","shape"][o]}: `;[()=>{console.debug(`${f}${n-64}dB`)},()=>{console.debug(`${f}${n} (raw)`)},()=>{console.debug(`${f}${n/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!n]}`)}][o]()}})}).add([76,3],a=>{let n=a[0],l=a[1],i=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((s,o)=>{([f=>{e.setEffectTypeRaw(3+n,!1,f),console.info(`${i}main type: ${at[f]}`),e.dispatchEvent(`efxinsert${n}`,e.getEffectType(3+n))},f=>{e.setEffectTypeRaw(3+n,!0,f),console.debug(`${i}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${n}`,e.getEffectType(3+n))}][l+o]||function(){})(s)})}).add([76,6,0],a=>{let n=a[0];n<64?e.setLetterDisplay(a.subarray(1),"XG letter display",n):w(e,Ce,Date.now())}).add([76,7,0],a=>{let n=a[0];w(e,z,0),w(e,le,Date.now()+3200),t(e,J,ue).fill(0);let l=a.subarray(1);for(let i=0;i>6-E&1,E++})}).add([76,8],(a,n)=>{let l=e.chRedir(a[0],n,!0),i=a[1],s=$.cc*l,o=`XG CH${l+1} `,f=`Unknown XG part address ${i}.`;a.subarray(2).forEach((u,g)=>{i<1?console.debug(f):i<41?([()=>{t(e,y)[s+v[0]]=u,e.dispatchEvent("voice",{part:l})},()=>{t(e,y)[s+v[32]]=u,e.dispatchEvent("voice",{part:l})},()=>{t(e,P)[l]=u,e.dispatchEvent("voice",{part:l})},()=>{let E=e.chRedir(u,n,!0);t(e,X)[l]=E,l!=E&&(e.buildRchTree(),console.info(`${o}receives from CH${E+1}`))},()=>{t(e,te)[l]=+!u},()=>{},()=>{e.setChType(l,u,x.xg),console.debug(`${o}type: ${rt[u]||u}`)},()=>{t(e,T)[$.rpn*l+3]=u},!1,!1,()=>{t(e,y)[s+v[7]]=u},!1,!1,()=>{t(e,y)[s+v[10]]=u||128},!1,!1,()=>{t(e,y)[s+v[128]]=u},()=>{t(e,y)[s+v[93]]=u},()=>{t(e,y)[s+v[91]]=u},()=>{t(e,y)[s+v[94]]=u},()=>{t(e,y)[s+v[76]]=u},()=>{t(e,y)[s+v[77]]=u},()=>{t(e,y)[s+v[78]]=u},()=>{t(e,y)[s+v[74]]=u},()=>{t(e,y)[s+v[71]]=u},()=>{t(e,y)[s+v[73]]=u},()=>{t(e,y)[s+v[75]]=u},()=>{t(e,y)[s+v[72]]=u}][i+g-1]||(()=>{}))():i<48?console.debug(f):i<111?i>102&&i<105&&(t(e,y)[s+v[[5,65][i&1]]]=u):i<114?console.debug(f):i<116?console.debug(`${o}EQ ${["bass","treble"][i&1]} gain: ${u-64}dB`):i<118?console.debug(f):i<120?console.debug(`${o}EQ ${["bass","treble"][i&1]} freq: ${u}`):console.debug(f)})}).add([76,9],(a,n)=>{let l=e.chRedir(a[0],n,!0),i=a[1],s=`PLG-150VL CH${l+1} `;a.subarray(2).forEach((o,f)=>{let u=f+i;switch(u){case 1:{console.info(`${s}breath mode: ${["system","breath","velocity","touch EG"][o]}`);break}case 0:case 27:case 28:break;default:if(u<27){let g=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][u-3>>1];u&1?u<23?(console.debug(`${s}${g} control source: ${Ft(o)}`),o&&o<96&&e.allocateAce(o)):console.debug(`${s}${g} scale break point: ${o}`):console.debug(`${s}${g} depth: ${o-64}`)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][a[0]]} for CH${a[2]+1}.`)}).add([73,0,0],(a,n)=>{let l=a[0],i="MU1000 System: ";a.subarray(1).forEach((s,o)=>{let f=l+o;f==8?console.debug(`${i}LCD contrast set to ${s}.`):f==18?(w(e,ae,s?126:0),console.debug(`${i}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):f>=64&&f<69&&[()=>{e.dispatchEvent("channelactive",s)},()=>{s<8?(e.dispatchEvent("channelmin",s<<4),console.debug(`Octavia System: Minimum CH${(s<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{s<8?(e.dispatchEvent("channelmax",(s<<4)+15),console.debug(`Octavia System: Maximum CH${(s<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{w(e,ne,!!s),console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][f-64]()})}).add([73,10,0],(a,n)=>{let l=a[0],i=`MU1000 RS${t(e,ne)?"":" (ignored)"}: `;if(l<16)switch(l){case 2:{let s=e.chRedir(0,n,!0);t(e,ne)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${i}Show CH1~64`);break}case 3:{let s=e.chRedir(a[1]<<5,n,!0);t(e,ne)&&e.dispatchEvent("channelmin",s),t(e,ne)&&e.dispatchEvent("channelmax",s+31),console.info(`${i}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${i}unknown switch ${l} invoked.`)}else if(l<32){if(t(e,ne)){let s=e.chRedir(l-16+(t(e,Ze)<<4),n,!0);e.dispatchEvent("channelactive",s)}}else if(l<36){let s=e.chRedir(l-32<<4,n,!0);t(e,ne)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),w(e,Ze,l-32)),console.info(`${i}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(a,n)=>{let l=e.chRedir(a[0],n,!0),i=`PLG-100SG CH${l+1} `,s=Date.now();if(a[1]==0){let o="",f=0;a.subarray(2).forEach((u,g)=>{g%2==0?o+=_t[u]||u.toString().padStart("0"):f+=u*13}),s>=t(e,Ye)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${Xt(o)}`,amend:!0}),w(e,Ye,s+Math.ceil(f/2)+t(e,We)),I()&&console.debug(`${i}vocals: ${o}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)});let d=function(a,n,l,i){},c=function(a,n){let l=a*$.dpn,i=n[0],s=n[1];n.subarray(2).forEach((o,f)=>{let u=f+s,g=-1;u<16?([()=>{g=24},()=>{g=25},()=>{g=26},()=>{},()=>{g=28},()=>{g=29},()=>{g=30},()=>{g=31},()=>{},()=>{},()=>{},()=>{g=20},()=>{g=21},()=>{g=22},()=>{g=23},()=>{}][u]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))():u<32||(u<40?([()=>{g=48},()=>{g=49},!1,!1,()=>{g=52},()=>{g=53}][u-32]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))():u<80||([()=>{g=36}][u-80]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))()),g>=0?(I()&&console.debug(l,g,i,o),t(e,q)[(l+ee[g])*$.dnc+i]=o):I()&&console.debug(`XG-style drum param ${u} has no writes.`)})},p=function(a,n,l){let i=a*$.dpn,s=(n<<7)+l[0];l.subarray(1).forEach((o,f)=>{let u=f+s,g=u&127,E=u>>7,k=-1;E>1&&([()=>{k=26},()=>{},()=>{k=28},()=>{k=29},()=>{k=30},()=>{},()=>{},()=>{k=31}][E-2]||(()=>{console.debug(`Unknown GS-style drum param ${E} on set ${a+1}.`)}))(),k>-1?(I()&&console.debug(i,k,g,o),t(e,q)[(i+ee[k])*$.dnc+g]=o):I()&&console.debug(`GS-style drum param ${E} has no writes.`)})};t(this,re).add([76,48],(a,n,l)=>{c(0,a)}).add([76,49],(a,n,l)=>{c(1,a)}).add([76,50],(a,n,l)=>{c(2,a)}).add([76,51],(a,n,l)=>{c(3,a)}).add([76,52],(a,n,l)=>{c(4,a)}).add([76,53],(a,n,l)=>{c(5,a)}).add([76,54],(a,n,l)=>{c(6,a)}).add([76,55],(a,n,l)=>{c(7,a)}),t(this,re).add([89,0],(a,n,l)=>{if(e.eprom){let i=a[0],s=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);I()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${i} bytes.`);let o=e.eprom.data;a.subarray(4).forEach((f,u)=>{let g=u>>3,E=u&7;if(E==7)for(let k=0;k<7;k++)o[s+7*g+k]+=(f>>6-k&1)<<7;else o[s+7*g+E]=f})}}).add([89,1],(a,n,l)=>{let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];I()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(a,n,l)=>{if(e.eprom){let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);I()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;a.subarray(4).forEach((o,f)=>{let u=f>>3,g=f&7;if(g==7)for(let E=0;E<7;E++)s[i+7*u+E]+=(o>>6-E&1)<<7;else s[i+7*u+g]=o})}}).add([89,3],(a,n,l)=>{}),t(this,re).add([39,48],(a,n,l)=>{}).add([43,0,0],(a,n,l)=>{let i=[0,0,0,0],s=(o,f)=>{i[f]=o};if(a.subarray(1).forEach((o,f)=>{let u=f+a[0];[s,s,s,s,()=>{w(this,U,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,U))},()=>o-64,()=>o||128,()=>o,()=>o,()=>{console.debug(`TG300 variation on cc${o}.`)}][u](o,u)}),a[0]<4){let o=0;i.forEach(f=>{o=o<<4,o+=f}),o-=1024}}).add([43,1,0],(a,n,l)=>{}).add([43,2],(a,n,l)=>{let i=e.chRedir(a[0],n,!0),s=a[1],o=$.cc*i,f=`TG300 CH${i+1} `;a.subarray(2).forEach((u,g)=>{g<5?([()=>{},()=>{t(e,y)[o+v[0]]=u,e.dispatchEvent("voice",{part:i})},()=>{t(e,y)[o+v[32]]=u,e.dispatchEvent("voice",{part:i})},()=>{t(e,P)[i]=u,e.dispatchEvent("voice",{part:i})},()=>{let E=e.chRedir(u,n,!0);t(e,X)[i]=E,i!=E&&(e.buildRchTree(),console.info(`${f}receives from CH${E+1}`))}][g+s]||(()=>{}))(u,g+s):g<21||(g<47?([()=>{t(e,te)[i]=+!u},()=>{},()=>{},()=>{t(e,T)[$.rpn*i+3]=u},()=>{},()=>{t(e,y)[o+v[7]]=u},!1,!1,()=>{t(e,y)[o+v[10]]=u||128},!1,!1,()=>{console.debug(`${f} AC1 at cc${u}`)},()=>{console.debug(`${f} AC2 at cc${u}`)},()=>{t(e,y)[o+v[128]]=u},()=>{t(e,y)[o+v[93]]=u},()=>{t(e,y)[o+v[91]]=u},()=>{t(e,y)[o+v[94]]=u},()=>{t(e,y)[o+v[76]]=u},()=>{t(e,y)[o+v[77]]=u},()=>{t(e,y)[o+v[74]]=u},()=>{t(e,y)[o+v[71]]=u},()=>{t(e,y)[o+v[73]]=u},()=>{t(e,y)[o+v[75]]=u},()=>{t(e,y)[o+v[72]]=u},()=>{t(e,y)[o+v[78]]=u}][g+s-21]||(()=>{}))(u,g+s):g<95||([()=>{t(e,y)[o+v[65]]=u},()=>{t(e,y)[o+v[5]]=u}][g+s-95]||(()=>{}))(u,g+s))})}).add([43,7,0],(a,n,l)=>{let i=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",i)}).add([43,7,1],(a,n,l)=>{w(e,z,0),w(e,le,Date.now()+3200),t(e,J,ue).fill(0),a.forEach(function(i,s){let o=Math.floor(s/16),f=s%16,u=(f*3+o)*7,g=7,E=0;for(u-=f*5,o==2&&(g=2);E>6-E&1,E++})}),t(this,se).add([66,18,0,0,127],(a,n,l)=>{e.switchMode("gs",!0),t(e,y)[$.cc*9]=120,t(e,y)[$.cc*25]=120,t(e,y)[$.cc*41]=120,t(e,y)[$.cc*57]=120,w(e,ae,3),w(e,L,!1),t(e,ye).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,n,l)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),t(e,y)[$.cc*9]=120,t(e,y)[$.cc*25]=120,t(e,y)[$.cc*41]=120,t(e,y)[$.cc*57]=120,w(e,L,!1),t(e,ye).fill(0),console.info("MIDI reset: GS");break}default:{let i=[0,0,0,0],s=(o,f)=>{i[f]=o};if(a.subarray(1).forEach((o,f)=>{let u=f+a[0];[s,s,s,s,g=>{w(this,U,g*129/16383*100),e.dispatchEvent("mastervolume",t(e,U))},g=>{},g=>{}][u](o,f)}),a[0]<4){let o=0;i.forEach(f=>{o=o<<4,o+=f}),o-=1024}}}}).add([66,18,64,1],a=>{let n=a[0];if(n<16){let l="".padStart(n," ");a.subarray(1).forEach((i,s)=>{l+=String.fromCharCode(Math.max(32,i))}),l=l.padEnd(16," "),console.debug(`GS patch name: ${l}`)}else n<48||(n<65?a.subarray(1).forEach((l,i)=>{let s=`GS ${n+i>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${mt[l]}`),e.setEffectType(0,40,l),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${l}ms`)},()=>{console.info(`${s}type: ${Vt[l]}`),e.setEffectType(1,40,16+l),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${W(l)}`)},()=>{console.debug(`${s}to delay: ${W(l)}`)}][n+i-48]||(()=>{}))()}):n<80?console.debug(`Unknown GS patch address: ${n}`):n<91?a.subarray(1).forEach((l,i)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${Kt[l]}`),e.setEffectType(2,40,32+l),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${W(l)}`)}][n+i-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${n}`))}).add([66,18,64,2],a=>{let n="GS EQ ";a.subarray(1).forEach((l,i)=>{([()=>{console.debug(`${n}low freq: ${[200,400][l]}Hz`)},()=>{console.debug(`${n}low gain: ${l-64}dB`)},()=>{console.debug(`${n}high freq: ${[3e3,6e3][l]}Hz`)},()=>{console.debug(`${n}high gain: ${l-64}dB`)}][a[0]+i]||function(){console.warn(`Unknown GS EQ address: ${a[0]+i}`)})()})}).add([66,18,64,3],a=>{let n="GS EFX ",l=function(i,s){let o=zt(t(e,Y).subarray(10,12),s,i);o&&console.debug(`${n}${Et(t(e,Y).subarray(10,12))} ${o}`)};a.subarray(1).forEach((i,s)=>{([()=>{e.setEffectTypeRaw(3,!1,32+i),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,i),console.info(`${n}type: ${Et(t(e,Y).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,()=>{console.debug(`${n}to reverb: ${W(i)}dB`)},()=>{console.debug(`${n}to chorus: ${W(i)}dB`)},()=>{console.debug(`${n}to delay: ${W(i)}dB`)},!1,()=>{console.debug(`${n}1 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${n}1 depth: ${i-64}`)},()=>{console.debug(`${n}2 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${n}2 depth: ${i-64}`)},()=>{console.debug(`${n}to EQ: ${i?"ON":"OFF"}`)}][a[0]+s]||function(o,f){console.warn(`Unknown GS EFX address: ${f}`)})(i,a[0]+s)})}).add([66,18,65],a=>{p((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],a=>{var n;switch(a[0]){case 0:{let l=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",l);break}case 32:{w(e,le,Date.now()+3200),a[1]==0&&(w(e,z,Math.max(Math.min(a[2]-1,9),0)),I()&&console.debug(`GS switch display page ${a[2]-1}.`));break}default:if(a[0]<6){t(e,z)>9&&w(e,z,0);let l=a[0]-1<<1|a[1]>>6;t(e,z)==l&&w(e,le,Date.now()+3200),(n=t(e,pe)[l])!=null&&n.length||(t(e,pe)[l]=new Uint8Array(256));let i=t(e,pe)[l];I()&&console.debug(`GS frame draw page ${l}.`);let s=a[1]&63;i.fill(0),a.subarray(2).forEach(function(f,u){let g=u+s,E=Math.floor(g/16),k=g%16,C=(k*4+E)*5,A=5,_=0;for(C-=k*4,E==3&&(A=1);_>4-_&1,_++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let h=function(a,n,l){let i=a[0],s=$.cc*n,o=$.rpn*n,f=`GS CH${n+1} `;i<3?(a.subarray(1).forEach((u,g)=>{[()=>{t(e,y)[s+v[0]]=u},()=>{t(e,P)[n]=u},()=>{let E=e.chRedir(u,l,!0);t(e,X)[n]=E,n!=E&&(e.buildRchTree(),console.info(`${f}receives from CH${E+1}`))}][i+g]()}),e.dispatchEvent("voice",{part:n})):i<19||(i<44?a.subarray(1).forEach((u,g)=>{([()=>{t(e,te)[n]=+!u},!1,()=>{e.setChType(n,u<<1,x.gs),console.debug(`${f}type: ${u?"drum ":"melodic"}${u||""}`)},()=>{t(e,T)[o+3]=u},!1,()=>{t(e,y)[s+v[7]]=u},!1,!1,()=>{t(e,y)[s+v[10]]=u||128},!1,!1,()=>{console.debug(`${f}CC 1: cc${u}`)},()=>{console.debug(`${f}CC 2: cc${u}`)},()=>{t(e,y)[s+v[93]]=u},()=>{t(e,y)[s+v[91]]=u},!1,!1,()=>{t(e,T)[o+1]=u},()=>{t(e,T)[o+2]=u},()=>{t(e,y)[s+v[94]]=u}][i+g-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},m=function(a,n){let l=a[0],i=`GS CH${n+1} `;l<2?a.subarray(1).forEach((s,o)=>{[()=>{t(e,y)[$.cc*n+v[32]]=s},()=>{}][l+o]()}):l<32?console.warn(`Unknown GS misc address: ${l}`):l<35?a.subarray(1).forEach((s,o)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][s]}`),t(e,Qe)[n]=s,e.dispatchEvent("partefxtoggle",{part:n,active:s})}][l+o-32]()}):console.warn(`Unknown GS misc address: ${l}`)};t(this,se).add([66,18,64,16],(a,n)=>{h(a,e.chRedir(9,n,!0),n)}).add([66,18,64,17],(a,n)=>{h(a,e.chRedir(0,n,!0),n)}).add([66,18,64,18],(a,n)=>{h(a,e.chRedir(1,n,!0),n)}).add([66,18,64,19],(a,n)=>{h(a,e.chRedir(2,n,!0),n)}).add([66,18,64,20],(a,n)=>{h(a,e.chRedir(3,n,!0),n)}).add([66,18,64,21],(a,n)=>{h(a,e.chRedir(4,n,!0),n)}).add([66,18,64,22],(a,n)=>{h(a,e.chRedir(5,n,!0),n)}).add([66,18,64,23],(a,n)=>{h(a,e.chRedir(6,n,!0),n)}).add([66,18,64,24],(a,n)=>{h(a,e.chRedir(7,n,!0),n)}).add([66,18,64,25],(a,n)=>{h(a,e.chRedir(8,n,!0),n)}).add([66,18,64,26],(a,n)=>{h(a,e.chRedir(10,n,!0),n)}).add([66,18,64,27],(a,n)=>{h(a,e.chRedir(11,n,!0),n)}).add([66,18,64,28],(a,n)=>{h(a,e.chRedir(12,n,!0),n)}).add([66,18,64,29],(a,n)=>{h(a,e.chRedir(13,n,!0),n)}).add([66,18,64,30],(a,n)=>{h(a,e.chRedir(14,n,!0),n)}).add([66,18,64,31],(a,n)=>{h(a,e.chRedir(15,n,!0),n)}).add([66,18,64,64],(a,n)=>{m(a,e.chRedir(9,n,!0))}).add([66,18,64,65],(a,n)=>{m(a,e.chRedir(0,n,!0))}).add([66,18,64,66],(a,n)=>{m(a,e.chRedir(1,n,!0))}).add([66,18,64,67],(a,n)=>{m(a,e.chRedir(2,n,!0))}).add([66,18,64,68],(a,n)=>{m(a,e.chRedir(3,n,!0))}).add([66,18,64,69],(a,n)=>{m(a,e.chRedir(4,n,!0))}).add([66,18,64,70],(a,n)=>{m(a,e.chRedir(5,n,!0))}).add([66,18,64,71],(a,n)=>{m(a,e.chRedir(6,n,!0))}).add([66,18,64,72],(a,n)=>{m(a,e.chRedir(7,n,!0))}).add([66,18,64,73],(a,n)=>{m(a,e.chRedir(8,n,!0))}).add([66,18,64,74],(a,n)=>{m(a,e.chRedir(10,n,!0))}).add([66,18,64,75],(a,n)=>{m(a,e.chRedir(11,n,!0))}).add([66,18,64,76],(a,n)=>{m(a,e.chRedir(12,n,!0))}).add([66,18,64,77],(a,n)=>{m(a,e.chRedir(13,n,!0))}).add([66,18,64,78],(a,n)=>{m(a,e.chRedir(14,n,!0))}).add([66,18,64,79],(a,n)=>{m(a,e.chRedir(15,n,!0))}),t(this,ve).add([54,65],(a,n)=>{e.switchMode("x5d");let l=(a[1]<<7)+a[0],i=(a[3]<<7)+a[2],s=e.chRedir(l&15,n,!0),o=$.cc*s;[()=>{i<1||(i<101?(e.setChType(s,e.CH_MELODIC,x.x5d),t(e,P)[s]=i-1,t(e,y)[o+v[0]]=82):i<229?(e.setChType(s,e.CH_MELODIC,x.x5d),t(e,P)[s]=i-101,t(e,y)[o+v[0]]=56):(e.setChType(s,e.CH_DRUMS,x.x5d),t(e,P)[s]=Jt[i-229]||0,t(e,y)[o+v[0]]=62)),e.dispatchEvent("voice",{part:s})},()=>{t(e,y)[o+v[7]]=i},()=>{i<31&&(t(e,y)[o+v[10]]=Math.round((i-15)*4.2+64))},()=>{t(e,y)[o+v[93]]=st(i)},()=>{t(e,y)[o+v[91]]=st(i)},()=>{t(e,T)[s*$.rpn+3]=i>8191?i-16320:64+i},()=>{t(e,T)[s*$.rpn+1]=i>8191?i-16320:64+i},()=>{i>0&&(t(e,T)[s*$.rpn]=i)},()=>{}][l>>4]()}).add([54,76,0],(a,n)=>{e.switchMode("x5d",!0);let l="",i=82,s=0,o=0,f="MSB PRG LSB NME";oe(a,function(u,g){if(g<16400){let E=g%164;switch(!0){case E<10:{u>31&&(l+=String.fromCharCode(u));break}case E==11:{f+=` +${i} ${s} ${o} ${l.trim().replace("Init Voice","")}`,s++,l="";break}}s>99&&(i=90,s=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(f),I()&&console.debug(f),e.forceVoiceRefresh()}).add([54,77,0],(a,n)=>{e.switchMode("x5d",!0);let l="",i=90,s=0,o=0,f="MSB PRG LSB NME";oe(a,function(u,g){if(g<13600){let E=g%136;switch(!0){case E<10:{u>31&&(l+=String.fromCharCode(u));break}case E==11:{f+=` +${i} ${s} ${o} ${l.trim().replace("Init Combi","")}`,s++,l="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f),I()&&console.debug(f),e.forceVoiceRefresh()}).add([54,78],(a,n)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,n)=>{e.switchMode("x5d",!0),oe(a,(l,i)=>{i>0&&i<3&&(e.setEffectType(i-1,44,l),e.dispatchEvent(`efx${["reverb","chorus"][i-1]}`,e.getEffectType(i-1)))})}).add([54,104],(a,n)=>{e.switchMode("x5d",!0),oe(a,function(l,i,s,o){if(i<192){let f=e.chRedir(Math.floor(i/12),n,!0),u=f*$.cc;switch(i%12){case 0:{l<128?(e.setChType(f,e.CH_MELODIC,x.x5d),t(e,y)[u+v[0]]=82,t(e,P)[f]=l):(e.setChType(f,e.CH_DRUMS,x.x5d),t(e,y)[u+v[0]]=62,t(e,P)[f]=Jt[l-128]),l>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{t(e,y)[u+v[7]]=l;break}case 2:{t(e,T)[f*$.rpn+3]=l>127?l-192:64+l;break}case 3:{t(e,T)[f*$.rpn+1]=l>127?l-192:64+l;break}case 4:{l<31&&(t(e,y)[u+v[10]]=Math.round((l-15)*4.2+64));break}case 5:{let g=l>>4,E=l&15;t(e,y)[u+v[91]]=st(E),t(e,y)[u+v[93]]=st(g);break}case 10:break;case 11:{let g=e.chRedir(l&15,n,!0),E=l>>4;t(e,X)[f]=l,(g!=f||E)&&(console.info(`X5D Part CH${f+1} receives from CH${g+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(i-192,n,!0)}})}),t(this,se).add([22,18,127],a=>{e.switchMode("mt32",!0),w(e,L,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,n,l)=>{e.switchMode("mt32");let i=e.chRedir(l,n,!0),s=a[1];a.subarray(2).forEach((o,f)=>{let u=f+s;t(e,we)[u+(i-1)*16]=o,([!1,()=>{let g=t(e,we)[i-1<<4];if(g<3){if(t(e,fe)[i]=1,g==2)for(let E=0;E{t(e,T)[i*$.rpn+3]=o+40},()=>{t(e,T)[i*$.rpn+1]=o+14},()=>{t(e,T)[i*$.rpn]=o},!1,()=>{t(e,y)[$.cc*i+v[91]]=o?127:0},!1,()=>{t(e,y)[$.cc*i+v[7]]=o},()=>{t(e,y)[$.cc*i+v[10]]=Math.ceil(o*9.05)}][u]||(()=>{}))()})}).add([22,18,1],(a,n,l)=>{e.switchMode("mt32");let i=l&7;console.debug(`MT-32 slot #${l+1} Drum: ${a}`);let s=a[0]<<7|a[1];a.subarray(2).forEach((o,f)=>{let u=f+s,g=(u>>2)+24,E=u&3,k=i*$.dpn;if(I()&&console.debug(`MT-32 temp drum note ${g} param ${E}: ${o}`),g<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${g}`);return}[()=>{},()=>{t(e,q)[(k+ee[26])*$.dnc+g]=Math.round(o*1.27)},()=>{t(e,q)[(k+ee[26])*$.dnc+g]=o*9+1&127},()=>{t(e,q)[(k+ee[26])*$.dnc+g]=o?127:0}][E]()})}).add([22,18,2],(a,n,l)=>{e.switchMode("mt32");let i=e.chRedir(l,n,!0),s=a[1]+(a[0]<<7);s<10&&(t(e,fe)[i]=1),a.subarray(2).forEach((o,f)=>{let u=f+s;u<14&&(t(e,ie)[(i-1)*$.cmt+u]=o)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(a,n,l)=>{e.switchMode("mt32");let i=l&7;if(a[0]){let s=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((o,f)=>{let u=f+s,g=(u>>2)+24,E=u&3,k=i*$.dpn;if(I()&&console.debug(`MT-32 dev drum note ${g} param ${E}: ${o}`),g<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${g}`);return}[()=>{},()=>{t(e,q)[(k+ee[26])*$.dnc+g]=Math.round(o*1.27)},()=>{t(e,q)[(k+ee[26])*$.dnc+g]=o*9+1&127},()=>{t(e,q)[(k+ee[26])*$.dnc+g]=o?127:0}][E]()})}else{let s=a[1];a.subarray(2).forEach((o,f)=>{let u=f+s;t(e,we)[u]=o;let g=e.chRedir(1+(u>>4),n,!0),E=u&15;([!1,()=>{let k=t(e,we)[g-1<<4];if(k<3)if(t(e,fe)[g]=1,k==2)for(let C=0;C{t(e,T)[g*$.rpn+3]=o+40},()=>{t(e,T)[g*$.rpn+1]=o+14},()=>{t(e,T)[g*$.rpn]=o},!1,()=>{t(e,y)[$.cc*g+v[91]]=o?127:0},!1,()=>{t(e,y)[$.cc*g+v[7]]=o},()=>{t(e,y)[$.cc*g+v[10]]=Math.ceil(o*9.05)}][E]||(()=>{}))()})}}).add([22,18,4],(a,n,l)=>{e.switchMode("mt32");let i=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((o,f)=>{let u=f+i,g=e.chRedir(Math.floor(u/246+1),n,!0),E=u%246;E<14&&(t(e,ie)[(g-1)*$.cmt+E]=o),E<10&&(t(e,fe)[g]=1),s.indexOf(g)<0&&s.push(g)}),s.forEach(o=>{e.dispatchEvent("voice",{part:o})})}).add([22,18,5],(a,n,l)=>{e.switchMode("mt32");let i=(a[0]<<7)+a[1];a.subarray(2).forEach((s,o)=>{let f=i+o,u=Math.floor(f/8),g=f&7,E=u*8;t(e,je)[f]=s,([!1,()=>{let k=t(e,je)[E];if(k<3){let C="";if(k==2){let A=$.cmt*u;C=`MT-m:${s.toString().padStart(3,"0")}`}else C=e.baseBank.get(0,s+(k<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:u}),e.userBank.load(`MSB LSB PRG NME +000 127 ${u} ${C}`,!0)}}][g]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,n,l)=>{e.switchMode("mt32");let i=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((s,o)=>{let f=i+o;f<$.cmt&&(t(e,ke)[(a[0]>>1)*$.cmt+f]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(a,n,l)=>{e.switchMode("mt32");let i=a[1],s=!1,o=function(f,u){t(e,X)[u-12]=f,s=!0};a.subarray(2).forEach((f,u)=>{let g=u+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,o,o,o,o,o,o,o,o,o,()=>{w(e,U,f),e.dispatchEvent("mastervolume",t(e,U))}][g]||(()=>{}))(f,u)}),s&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let n=a[1],l=" ".repeat(n);a.subarray(2).forEach(i=>{i>31?l+=String.fromCharCode(i):l+=" "}),w(e,xe,l.padStart(20," ")),w(e,Ce,Date.now()+3200)}).add([22,18,82],(a,n)=>{let l=e.chRedir(0,n,!0);for(let i=0;i<16;i++)t(e,G).ano(l+i),i&&i<10&&(t(e,P)[l+i]=$t[i-1]);console.info("MT-32 alt reset complete.")}),t(this,ve).add([66,0],(a,n)=>{e.switchMode("ns5r",!0),w(e,L,!1),console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,n)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),w(e,L,!1)}).add([66,18,0,0],(a,n)=>{let l=a[0];switch(l){case 124:case 126:case 127:{e.switchMode("ns5r",!0),w(e,L,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(l<10){let i=[0,0,0,0],s=(o,f)=>{i[f]=o};if(a.subarray(1).forEach((o,f)=>{[s,s,s,s,()=>{w(e,U,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,U))},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][l+f]()}),a[0]<4){let o=0;i.forEach(f=>{o=o<<4,o+=f}),o-=1024}}}}).add([66,18,0,1],(a,n)=>{}).add([66,18,0,2],(a,n)=>{}).add([66,18,1],(a,n)=>{let l=e.chRedir(a[0],n,!0),i=l*$.cc,s=a[1],o=`NS5R CH${l+1} `;a.subarray(2).forEach((f,u)=>{let g=s+u;g<3?([()=>{t(e,y)[i+v[0]]=f||121},()=>{t(e,y)[i+v[32]]=f},()=>{t(e,P)[l]=f}][g](),e.dispatchEvent("voice",{part:l})):g<8||(g<14?[()=>{let E=e.chRedir(f,n,!0);t(e,X)[l]=E,l!=E&&(e.buildRchTree(),console.info(`${o}receives from CH${E+1}`))},()=>{t(e,te)[l]=+!f},()=>{e.setChType(l,f,x.ns5r),console.debug(`${o}type: ${rt[f]}`)},()=>{t(e,T)[$.rpn*l+3]=f},()=>{},()=>{}][g-8]():g<16||(g<33?[()=>{t(e,y)[i+v[7]]=f},()=>{t(e,y)[i+v[11]]=f},()=>{},()=>{},()=>{t(e,y)[i+v[10]]=f||128},()=>{},()=>{},()=>{t(e,y)[i+v[93]]=f},()=>{t(e,y)[i+v[91]]=f},()=>{t(e,y)[i+v[76]]=f},()=>{t(e,y)[i+v[77]]=f},()=>{t(e,y)[i+v[78]]=f},()=>{t(e,y)[i+v[74]]=f},()=>{t(e,y)[i+v[71]]=f},()=>{t(e,y)[i+v[73]]=f},()=>{t(e,y)[i+v[75]]=f},()=>{t(e,y)[i+v[72]]=f}][g-16]():g<112||g<114&&[()=>{t(e,y)[i+v[5]]=f},()=>{t(e,y)[i+v[65]]=f}][g-112]()))})}).add([66,18,8,0],(a,n)=>{let l=a[0];if(l<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let i=l-32;w(e,le,Date.now()+3200),w(e,z,10),t(e,J,ue).fill(0);let s=a.subarray(1),o=4;s.forEach(function(f,u){let g=u+i,E=g>>4,k=g&15;if(g<80){let C=E>3,A=0,_=E0;)t(e,J,ue)[k*32+E*7+(_-A)]=C&1,C=C>>1,A++}})}}).add([66,18,48],(a,n,l)=>{c(0,a)}).add([66,18,49],(a,n,l)=>{c(1,a)}).add([66,18,50],(a,n,l)=>{c(2,a)}).add([66,18,51],(a,n,l)=>{c(3,a)}).add([66,18,52],(a,n,l)=>{c(4,a)}).add([66,18,53],(a,n,l)=>{c(5,a)}).add([66,18,54],(a,n,l)=>{c(6,a)}).add([66,18,55],(a,n,l)=>{c(7,a)}).add([66,52],(a,n)=>{e.switchMode("ns5r",!0),w(e,L,!1);let l="";oe(a,(i,s)=>{s<8?(i>31&&(l+=String.fromCharCode(i)),s==7&&(e.aiEfxName=l)):s<10&&(e.setEffectType(s-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(a,n)=>{e.switchMode("ns5r",!0),w(e,L,!1),oe(a,function(l,i){switch(!0){case i<2944:{let s=e.chRedir(Math.floor(i/92),n,!0),o=s*$.cc;switch(i%92){case 0:{t(e,y)[o+v[0]]=l||121,e.dispatchEvent("voice",{part:s});break}case 1:{t(e,y)[o+v[32]]=l,e.dispatchEvent("voice",{part:s});break}case 2:{t(e,P)[s]=l,l>0&&e.setChActive(s,1),e.dispatchEvent("voice",{part:s});break}case 3:{let f=e.chRedir(l,n,!0);t(e,X)[s]=f,s!=f&&(console.info(`NS5R CH${s+1} receives from CH${f+1}.`),e.buildRchTree())}case 7:break;case 8:{t(e,T)[s*$.rpn+3]=l<40||l>88?l+(l>63?-192:64):l;break}case 9:case 10:{t(e,y)[o+v[7]]=l;break}case 11:{t(e,y)[o+v[11]]=l;break}case 14:{t(e,y)[o+v[10]]=l||128;break}case 19:{t(e,y)[o+v[93]]=l;break}case 20:{t(e,y)[o+v[91]]=l;break}case 84:{t(e,y)[o+v[65]]=l;break}case 85:{t(e,y)[o+v[5]]=l;break}}break}case i<3096:break;case i<3134:break;case i<8566:break}})}).add([66,54],(a,n)=>{e.switchMode("ns5r",!0);let l="",i=80,s=0,o=0,f="MSB PRG LSB NME";oe(a,function(u,g){let E=g%158;switch(!0){case E<10:{u>31&&(l+=String.fromCharCode(u));break}case E==11:{i=u&127;break}case E==12:{o=u&127;break}case E==13:{f+=` +${i} ${s} ${o} ${l.trim().replace("Init Voice","")}`,s++,l="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(f),I()&&console.debug(f),e.forceVoiceRefresh()}).add([66,55],(a,n)=>{e.switchMode("ns5r",!0);let l="",i=88,s=0,o=0,f="MSB PRG LSB NME";oe(a,function(u,g){let E=g%126;switch(!0){case E<10:{u>31&&(l+=String.fromCharCode(u));break}case E==11:break;case E==12:break;case E==13:{f+=` +${i} ${s} ${o} ${l.trim().replace("Init Combi","")}`,s++,l="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(f),I()&&console.debug(f),e.forceVoiceRefresh()}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let n=new Uint8Array(5760);oe(a,(l,i,s)=>{if(i<720)for(let o=0;o<8;o++)n[i*8+o]=l>>7-o&1}),e.dispatchEvent("screen",{type:"ns5r",data:n})}).add([76],(a,n,l)=>{t(e,ve).run([66,...a],n,l)}),t(this,Le).add([16,0,8,0],(a,n,l)=>{let i=(a[2]<<4)+a[3],s="K11 ";([()=>{e.switchMode("k11",!0),w(e,L,!1),w(e,ae,i?4:0),console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,i),console.debug(`${s}reverb type: ${i}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${s}reverb time: ${i}`)},()=>{console.debug(`${s}reverb time: ${i}`)},()=>{console.debug(`${s}reverb predelay: ${i}`)},()=>{console.debug(`${s}reverb predelay: ${i}`)},()=>{console.debug(`${s}depth high: ${i}`)},()=>{console.debug(`${s}depth high: ${i}`)},()=>{console.debug(`${s}depth low: ${i}`)},()=>{console.debug(`${s}depth low: ${i}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,n,l)=>{let i=e.chRedir(a[1],n,!0),s=$.cc*i,o=$.rpn*i,f=(a[3]<<4)+a[4],u=`K11 CH${i+1} `;([()=>{f<128?(e.setChType(i,e.CH_MELODIC,x.k11),t(e,y)[s+v[0]]=0,t(e,P)[i]=f):(e.setChType(i,e.CH_DRUMS,x.k11),t(e,P)[i]=f-128),e.dispatchEvent("voice",{part:i})},()=>{let g=e.chRedir(f,n,!0);t(e,X)[i]=g,i!=g&&(e.buildRchTree(),console.info(`${u}receives from CH${g+1}`))},()=>{t(e,y)[s+v[7]]=f},()=>{uupThis.setChActive(i,f)},()=>{t(e,y)[s+v[10]]=f},()=>{t(e,T)[o+3]=f+40},()=>{t(e,T)[o+1]=f>>1,t(e,T)[o+2]=f&1},()=>{t(e,y)[s+v[91]]=f?127:0},()=>{},()=>{t(e,y)[s+v[74]]=f},()=>{t(e,y)[s+v[73]]=f},()=>{t(e,y)[s+v[72]]=f}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,n,l)=>{let i=(a[2]<<4)+a[3],s="GMLX ";([()=>{console.debug(`${s}reverb type: ${i}`)},()=>{console.debug(`${s}reverb time: ${i}`)},()=>{console.debug(`${s}reverb predelay: ${i}`)},()=>{console.debug(`${s}depth high: ${i}`)},()=>{console.debug(`${s}depth low: ${i}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,n,l)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],n,!0),o=s*$.cc;[()=>{i<128?(e.setChType(s,e.CH_MELODIC,x.k11),t(e,y)[o+v[0]]=0,t(e,y)[o+v[32]]=0,t(e,P)[s]=i):i<160?(e.setChType(s,e.CH_MELODIC,x.k11),t(e,y)[o+v[0]]=0,t(e,y)[o+v[32]]=7,t(e,P)[s]=i-100):(e.setChType(s,e.CH_DRUMS,x.k11),t(e,y)[o+v[0]]=122,t(e,y)[o+v[32]]=0,t(e,P)[s]=i-160),e.dispatchEvent("voice",{part:s})},()=>{let f=e.chRedir(i,n,!0);t(e,X)[s]=f,s!=f&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${f+1}`))}][a[0]]()}).add([16,0,9,4],(a,n,l)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],n,!0),o=s*$.cc,f=s*$.rpn,u=`GMLX CH${s+1} `;[()=>{e.setChActive(s,i)},()=>{t(e,y)[o+v[7]]=i},()=>{t(e,y)[o+v[10]]=i},()=>{t(e,y)[o+v[91]]=i?127:0},()=>{t(e,T)[f+3]=i+40},()=>{t(e,T)[f+1]=i},()=>{t(e,T)[f]=i},()=>{}][a[0]]()}),t(this,Be).add([66,93,64],(a,n,l)=>{let i=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{w(e,U,i*129/16383*100),e.dispatchEvent("mastervolume",t(e,U));break}case 5:{i-64;break}case 6:{console.debug(`SG global reverb: ${i?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(a[1]){case 48:{console.debug(`SG reverb type: ${mt[i]}`);break}}break}default:if(a[0]>>4==1){let s=e.chRedir(a[0]&15,n,!0);if(a[1]==2){let o=e.chRedir(i,n,!0);t(e,X)[s]=o,s!=o&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${o+1}`))}else a[1]==19&&(t(e,y)[$.cc*s+v[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,Ne).add([9],(a,n,l)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),t(this,re).add([127,0],(a,n,l)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...a]);t(e,re).run(i,n,l)}).add([127,1,0,0],(a,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES system ",s=a[0];a.subarray(1).forEach((o,f)=>{([()=>{w(e,U,o*12900/16383),e.dispatchEvent("mastervolume",t(e,U))}][s+f]||(()=>{console.info(`Unrecognized ${i}ID: ${s+f}`)}))()})}).add([127,1,0,0,14],(a,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES bulk header ",s=[];s[95]=(o,f,u)=>{console.debug(`${i}multi edit buffer: ${o[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES bulk footer ",s=[];s[95]=(o,f,u)=>{console.debug(`${i}multi edit buffer: ${o[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,n,l)=>{e.switchMode("s90es");let i=e.chRedir(a[0],n,!0),s=$.cc*i,o=a[1],f=`S90/Motif ES bulk CH${i<16?i+1:"U"+(i-95)} `;console.debug(f,a),!(a[0]>15)&&a.subarray(2).forEach((u,g)=>{([()=>{t(e,y)[s+v[0]]=u,e.dispatchEvent("voice",{part:i})},()=>{u&&e.setChActive(i,1),t(e,y)[s+v[32]]=u,e.setChType(i,[32,40].indexOf(u)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,D),!0),e.dispatchEvent("voice",{part:i})},()=>{u&&e.setChActive(i,1),t(e,P)[i]=u,e.dispatchEvent("voice",{part:i})},()=>{let E=e.chRedir(u,n,!0);t(e,X)[i]=E,i!=E&&(e.buildRchTree(),console.info(`${f}receives from CH${E+1}`))},()=>{t(e,te)[i]=u?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{t(e,y)[s+v[7]]=u},()=>{t(e,y)[s+v[10]]=u},!1,!1,!1,()=>{t(e,y)[s+v[91]]=u},()=>{t(e,y)[s+v[93]]=u},()=>{t(e,y)[s+v[94]]=u},()=>{t(e,y)[s+v[128]]=u},()=>{},()=>{t(e,y)[s+v[74]]=u},()=>{t(e,y)[s+v[71]]=u},!1,()=>{t(e,y)[s+v[65]]=u},()=>{t(e,y)[s+v[5]]=u},()=>{}][o+g]||(()=>{}))()})}).add([127,1,54,16],(a,n,l)=>{e.switchMode("s90es");let i=a[0];a.subarray(1).forEach((s,o)=>{let u=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let g=s-64},()=>{let g=ze[s]},()=>{let g=s/10},()=>{let g=s}][i+o&3]||(()=>{}))()})}),t(this,se).add([0,72,18,0,0,0,0],(a,n,l)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,n,l)=>{let i=a[0]>>5,s=a[0]&31;switch(i){case 0:{console.debug(`Unknown SD-90 global effects message: +%o`,a);break}case 1:{let o=e.chRedir(s,n,!0),f=a[1],u=o*$.cc;a.subarray(2).forEach((g,E)=>{let k=f+E;k<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,y)[u+v[0]]=g,g){case 104:case 105:case 106:case 107:case 120:{t(e,R)[o]||e.setChType(o,e.CH_DRUMS);break}default:t(e,R)[o]&&e.setChType(o,e.CH_MELODIC)}e.dispatchEvent("voice",{part:o})},()=>{t(e,y)[u+v[32]]=g,e.dispatchEvent("voice",{part:o})},()=>{t(e,P)[o]=g,e.dispatchEvent("voice",{part:o})},()=>{t(e,y)[u+v[7]]=g},()=>{t(e,y)[u+v[10]]=g},()=>{},()=>{},()=>{g<2&&(t(e,te)[o]=g)},()=>{g<2&&(t(e,y)[u+v[68]]=g?127:0)},()=>{},()=>{g<2&&(t(e,y)[u+v[65]]=g?127:0)},()=>{t(e,y)[u+v[5]]=g&15<<4|t(e,y)[u+v[5]]&15},()=>{t(e,y)[u+v[5]]=g&15|(t(e,y)[u+v[5]]&240)>>4},()=>{t(e,y)[u+v[74]]=g},()=>{t(e,y)[u+v[71]]=g},()=>{t(e,y)[u+v[73]]=g},()=>{t(e,y)[u+v[72]]=g},0,0,0,0,0,0,0,()=>{t(e,y)[u+v[128]]=g},()=>{t(e,y)[u+v[93]]=g},()=>{t(e,y)[u+v[91]]=g},0,0,()=>{t(e,y)[u+v[75]]=g},()=>{t(e,y)[u+v[76]]=g},()=>{t(e,y)[u+v[77]]=g},()=>{t(e,y)[u+v[78]]=g}][k]||(()=>{}))():k<63||(k<64?t(e,R)[o]?t(e,y)[u+v[0]]=104|g:t(e,y)[u+v[0]]=96|g:console.debug(`Unknown SD-90 global CH${o+1} param setup message: +%o`,a))});break}case 2:{let o=e.chRedir(s,n,!0),f=a[1];console.debug(`Unknown SD-90 global CH${o+1} MIDI setup message: %o`,a.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,a)}})}chRedir(e,s,h){if(t(this,xe)[s])return(t(this,xe)[s]-1)*16+e;if([2,3].indexOf(t(this,ee))>-1){if(h==1)return e;let o=0,a=!0;for(;a;)t(this,ge)[e+o]==0?(t(this,ge)[e+o]=s,console.debug(`Assign track ${s} to channel ${e+o+1}.`),a=!1):t(this,ge)[e+o]==s?a=!1:(o+=16,o>=128&&(o=0,a=!1));return e+o}else return e}buildRchTree(){let e=[];t(this,H).forEach((s,h)=>{var o;(o=e[s])!=null&&o.constructor||(e[s]=[]),e[s].push(h)}),E(this,st,e)}getActive(){let e=t(this,U).slice();return t(this,O)==S.mt32,e}getCc(e){let s=e*m.cc,h=t(this,b).subarray(s,s+m.cc);return h[g[0]]=h[g[0]]||t(this,ke),h[g[32]]=h[g[32]]||t(this,ee),h}getCcCh(e,s){if(at.indexOf(s)<0)throw new Error("CC number not accepted");return t(this,b)[m.cc*e+g[s]]}getCcAll(){let e=t(this,b).slice();for(let s=0;s0&&!o&&(t(this,b)[e*m.cc+g[0]]=Me[h])}getPitch(){return t(this,ve)}getProgram(){return t(this,D)}getTexts(){return t(this,Y).slice()}getVel(e){let s=new Map,h=this;return t(h,B).forEach(function(o,a){let r=Math.floor(o/128),c=o%128;e==r&&t(h,L)[o]>0&&s.set(c,{v:t(h,L)[o],s:t(h,G)[a]})}),s}getBitmap(){return{bitmap:t(this,Z,ue),expire:t(this,oe)}}getLetter(){return{text:t(this,fe),expire:t(this,Se)}}getMode(){return he[t(this,O)]}getMaster(){return{volume:t(this,P)}}getRawStrength(){let e=this;return t(this,B).forEach(function(s){let h=Math.floor(s/128);t(e,L)[s]>t(e,le)[h]&&(t(e,le)[h]=t(e,L)[s])}),t(this,le)}getStrength(){let e=[],s=this;return this.getRawStrength().forEach(function(h,o){e[o]=Math.floor(h*t(s,b)[o*m.cc+g[7]]*t(s,b)[o*m.cc+g[11]]*t(s,P)/803288)}),e}getRpn(){return t(this,x)}getNrpn(){return t(this,Ve)}getVoice(e,s,h,o){let a=e||t(this,ke),r=s,c=h||t(this,ee);he[t(this,O)]=="ns5r"&&a>0&&a<56&&(c=3);let n=this.userBank.get(a,r,c,o);if(he[t(this,O)]=="mt32"&&n.name.indexOf("MT-m:")==0){let i=parseInt(n.name.slice(5)),f=i*m.cmt,l="";t(this,we).subarray(f,f+10).forEach(d=>{d>31&&(l+=String.fromCharCode(d))}),this.userBank.load(`MSB LSB PRG -0 127 ${r} ${l}`,!0),n.name=l,n.ending=" "}return(n.ending!=" "||!n.name.length)&&(n=this.baseBank.get(a,r,c,o)),n}getChVoice(e){let s=this.getVoice(t(this,b)[e*m.cc+g[0]],t(this,D)[e],t(this,b)[e*m.cc+g[32]],he[t(this,O)]);if(t(this,de)[e])switch(t(this,O)){case S.mt32:s.ending="~",s.name="",t(this,re).subarray(14*(e-1),14*(e-1)+10).forEach(h=>{h>31&&(s.name+=String.fromCharCode(h))})}return s}getPitchShift(e){let s=e*m.rpn;return t(this,ve)[e]/8192*t(this,x)[s]+(t(this,x)[s+3]-64)+((t(this,x)[s+1]<<7)+t(this,x)[s+2]-8192)/8192}getEffectType(e=0){let s=3*e+1;return t(this,W).subarray(s,s+2)}setEffectTypeRaw(e=0,s,h){let o=3*e;t(this,W)[o]=1,t(this,W)[o+1+ +s]=h}setEffectType(e=0,s,h){this.setEffectTypeRaw(e,!1,s),this.setEffectTypeRaw(e,!0,h)}getEffectSink(){return t(this,ze)}setLetterDisplay(e,s,h=0,o=3200){let a=this,r;E(a,fe," ".repeat(h)),e.forEach(c=>{E(a,fe,t(a,fe)+String.fromCharCode(c>31?c:32)),c<32&&(r=r||new Set,r.add(c))}),E(a,Se,Date.now()+3200),E(a,fe,t(a,fe).padEnd(32," ")),r&&(r=Array.from(r),r.forEach((c,n,i)=>{i[n]=c.toString(16).padStart(2,"0")}),console.warn(`${s}${s?" ":""}invalid code point${r.length>1?"s":""}: 0x${r.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let s=!0,h=0;for(;s&&h=m.ace&&console.warn("ACE slots are full.")}getAce(){return t(this,be)}getChAce(e,s){if(s<0||s>=m.ace)throw new RangeError("No such ACE slot");let h=t(this,be)[s];if(h){if(at.indexOf(h)>=0)return t(this,b)[e*m.cc+g[h]];throw new Error(`Invalid ACE source: ${h}`)}else return 0}init(e=0){let s=this;s.dispatchEvent("mode","?"),E(s,O,0),E(s,ke,0),E(s,ee,0),E(s,Oe,0),t(s,U).fill(0),t(s,b).fill(0),t(s,be).fill(0),t(s,D).fill(0),t(s,L).fill(0),t(s,B).fill(0),t(s,le).fill(0),t(s,ve).fill(0),t(s,Ve).fill(0),t(s,rt).fill(0),E(s,P,100),E(s,Y,[]),E(s,qe,500),E(s,je,0),E(s,Se,0),E(s,fe,""),E(s,oe,0),E(s,Q,0),t(s,Z,ue).fill(0),E(s,I,!1),E(s,Qe,0),E(s,se,!0),t(s,H).forEach(function(h,o,a){a[o]=o}),s.buildRchTree(),e==0&&(t(s,ge).fill(0),t(s,xe).fill(0)),t(s,b)[m.cc*9]=Me[0],t(s,b)[m.cc*25]=Me[0],t(s,b)[m.cc*41]=Me[0],t(s,b)[m.cc*57]=Me[0],t(s,M).fill(s.CH_MELODIC),t(s,M)[9]=s.CH_DRUM1,t(s,M)[25]=s.CH_DRUM3,t(s,M)[41]=s.CH_DRUMS,t(s,M)[57]=s.CH_DRUMS,t(s,M)[73]=s.CH_DRUM5,t(s,M)[89]=s.CH_DRUM7,t(s,M)[105]=s.CH_DRUMS,t(s,M)[121]=s.CH_DRUMS,t(s,Ke).fill(0),t(s,we).fill(0),t(s,$e).fill(0),t(s,re).fill(0),t(s,de).fill(0),t(s,W).fill(0),t(s,ze).fill(0),s.aiEfxName="",s.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let h=0;h-1){if(t(h,O)==0||s){let a=t(h,O);E(h,O,o),E(h,Q,0),E(h,ke,jt[0][o]),E(h,ee,jt[1][o]);for(let c=0;c0&&t(h,b)[c*m.cc+g[0]]==Me[a]&&(t(h,b)[c*m.cc]=Me[o]);switch(h.initOnReset,o){case S.mt32:{Et.forEach((c,n)=>{let i=n+1;t(h,U)[i]||(t(h,D)[i]=c,t(h,b)[i*m.cc+g[91]]=127)});break}}let r;switch(o){case S["?"]:case S.xg:{r=[1,0,65,0,5,0,0,0];break}case S.gm:case S.gs:case S.g2:case S.sd:{r=[40,4,40,18,40,32,32,0];break}case S["05rw"]:case S.x5d:case S.ns5r:{r=[44,1,44,19,44,0,44,0];break}case S.k11:case S.sg:{r=[24,0,0,0,0,0,0,0];break}case S.mt32:{r=[40,4,0,0,0,0,0,0];break}default:r=[0,0,0,0,0,0,0,0]}for(let c=0;c<4;c++)t(h,W)[3*c]||(t(h,W)[3*c+1]=r[2*c],t(h,W)[3*c+2]=r[2*c+1],h.dispatchEvent(`efx${["reverb","chorus","delay","insert"][c]}`,h.getEffectType(c)));h.dispatchEvent("mode",e)}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,le).fill(0)}runJson(e){var s;if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,it)[e.type].call(this,e);{let h=this.chRedir(e.part,e.track),o=!1;(s=t(this,st)[h])==null||s.forEach(a=>{e.channel=a,o=!0,t(this,it)[e.type].call(this,e)}),o||console.warn(`${Qt[e.type]?Qt[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${h+1} without any recipient.`)}t(this,Y).length>100&&t(this,Y).splice(100,t(this,Y).length-99)}runRaw(e){}async loadBank(e,s){switch(e=e.toLowerCase(),e){case"s7e":{this.userBank.clearRange({msb:63,lsb:[21,22]}),this.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{lt.context=this,this.userBank.load(await lt.read(e,s));break}}}},O=new WeakMap,Q=new WeakMap,oe=new WeakMap,pe=new WeakMap,Z=new WeakSet,ue=function(){return t(this,pe)[t(this,Q)]},ea=function(e){t(this,pe)[t(this,Q)]=e},U=new WeakMap,H=new WeakMap,M=new WeakMap,b=new WeakMap,be=new WeakMap,D=new WeakMap,L=new WeakMap,J=new WeakMap,B=new WeakMap,G=new WeakMap,ve=new WeakMap,le=new WeakMap,Re=new WeakMap,x=new WeakMap,Ve=new WeakMap,rt=new WeakMap,de=new WeakMap,$e=new WeakMap,re=new WeakMap,Ke=new WeakMap,we=new WeakMap,W=new WeakMap,ze=new WeakMap,ke=new WeakMap,ee=new WeakMap,P=new WeakMap,Oe=new WeakMap,qe=new WeakMap,je=new WeakMap,fe=new WeakMap,Se=new WeakMap,Qe=new WeakMap,se=new WeakMap,I=new WeakMap,st=new WeakMap,wt=new WeakMap,Y=new WeakMap,ge=new WeakMap,xe=new WeakMap,_=new WeakMap,De=new WeakMap,N=new WeakMap,it=new WeakMap,dt=new WeakMap,Pe=new WeakMap,Ie=new WeakMap,te=new WeakMap,ae=new WeakMap,ye=new WeakMap,Ae=new WeakMap,Ue=new WeakMap,Le=new WeakMap,Jt);var Mt=ga(ta(),1);R();R();var nt,aa,sa=(aa=class{constructor(u,e,s,h){v(this,nt,!1);E(this,nt,u),this.start=e,this.end=s,this.data=h}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return t(this,nt)}},nt=new WeakMap,aa),xt=class extends sa{constructor(u,e,s){super(!0,u,e,s)}},ia=class extends sa{constructor(u,e){super(!1,u,u,e)}},Be,ra,Tt=(ra=class extends Array{constructor(){super(...arguments);v(this,Be,-1)}resetIndex(e){E(this,Be,-1)}fresh(){this.sort(function(e,s){return e.start==s.start?0:(+(e.start>s.start)<<1)-1}),this.forEach(function(e,s){e.index=s})}step(e,s=!1){let h=[];if(s)for(let o=0;oe);o++){if(this[o].endt(a,Be)&&(h.push(r),E(a,Be,r.index))})}return h}getRange(e,s){var c;e>s&&([e,s]=[s,e]);let h=[],o=-1,a=Math.ceil(Math.sqrt(this.length)),r=!0;for(let n=0;n=e&&(o=n):o=o<0?n:o;for(;r;)((c=this[o])==null?void 0:c.end)=e&&h.push(this[o]):r=!1,o++;return h}},Be=new WeakMap,ra);var Ta=0xffffffffffff,na=function(u){let e=new Tt,s=this,h=u.timeDivision,o=120,a=new Tt,r=0,c=0;a.push(new xt(0,Ta,[120,0])),u.track.forEach(function(l){r=0,l.event.forEach(function(d){r+=d.deltaTime,d.type==255&&(d==null?void 0:d.metaType)==81&&(o=6e7/d.data,a[a.length-1]&&a.push(new xt(r,0xffffffffffff,[o,0])))})}),a.fresh(),a.forEach(function(l,d,p){d>0&&(p[d-1].end=l.start)});let n=120;a.forEach(function(l,d,p){d>0&&(l.end==l.start?p.splice(p.indexOf(l),1):n==l.data[0]&&(p[d-1].end=l.end,p.splice(p.indexOf(l),1)),n=l.data[0])});let i=0,f=120;return a.forEach(function(l){let d=l.start,p=d/f/h*60+i;f=l.data[0],i=p-d/f/h*60,l.data[1]=i}),console.debug("All tempo changes: ",a),o=120,r=0,c=0,u.track.forEach(function(l,d){r=0,c=0;let p=d+1;l.event.forEach(function(y,$){r+=y.deltaTime;let k=a.step(r,!0)[0];k&&(o=k.data[0],c=k.data[1]);let w={type:y.type,data:y.data,track:p,part:0};y.type>14?w.meta=y.metaType:w.part=y.channel,e.push(new ia(r/o/h*60+c,w))})}),e.fresh(),self.midiEvents=e,console.debug(`Parsed a type ${u.formatType} MIDI sequence.`),e};Mt.default.customInterpreter=qt;var X=function(u,e,s){u.addEventListener(s,h=>{e.dispatchEvent(s,h.data)})},We,Ct,Ye,me,Ne,He,ct,Te,Ce,F,Ge,Ee,_e,ca,Dr=(ca=class extends ot{constructor(e,s=.5,h=.5){super();C(this,"device");v(this,We,void 0);v(this,Ct,void 0);v(this,Ye,[]);v(this,me,"");v(this,Ne,[]);v(this,He,new Uint8ClampedArray(128));v(this,ct,new Uint8ClampedArray(128));v(this,Te,.5);v(this,Ce,120);v(this,F,4);v(this,Ge,4);v(this,Ee,0);v(this,_e,0);C(this,"smoothingAtk",0);C(this,"smoothingDcy",0);let o=this;o.smoothingAtk=s,o.smoothingDcy=h,o.device=e,o.addEventListener("meta",function(a){var r;(r=a==null?void 0:a.data)==null||r.forEach(function(c){(t(o,Ne)[c.meta]||console.debug).call(o,c.meta,c.data)})}),X(o.device,o,"mode"),X(o.device,o,"mastervolume"),X(o.device,o,"channelactive"),X(o.device,o,"channelmin"),X(o.device,o,"channelmax"),X(o.device,o,"channelreset"),X(o.device,o,"screen"),X(o.device,o,"metacommit"),X(o.device,o,"efxreverb"),X(o.device,o,"efxchorus"),X(o.device,o,"efxdelay"),X(o.device,o,"efxinsert0"),X(o.device,o,"efxinsert1"),X(o.device,o,"efxinsert2"),X(o.device,o,"efxinsert3"),t(o,Ne)[3]=function(a,r){var c;((c=t(o,me))==null?void 0:c.length)<1&&(E(o,me,r),o.dispatchEvent("title",t(o,me)))},t(o,Ne)[81]=function(a,r){let c=o.noteProgress,n=t(o,Te)||.5;E(o,Ce,6e7/r),E(o,Te,r/1e6),E(o,Ee,t(o,Ee)+(c*(n/t(o,Te))-c)),o.dispatchEvent("tempo",t(o,Ce))},t(o,Ne)[88]=function(a,r){let c=o.noteProgress,n=o.noteOverall,i=o.noteBar,f=o.noteBeat,l=t(o,F),d=t(o,Ge);E(o,F,r[0]),E(o,Ge,1<=l&&(l{if(i){let f=0,l;n.split(" ").forEach((d,p)=>{switch(p){case a:{f|=parseInt(d,16)<<8;break}case r:{f|=parseInt(d,16);break}case c:{l=d;break}}}),t(s,Ye)[f]?console.debug(`EFX ID 0x${f.toString(16).padStart(4,"0")} (${l}) seems to be in conflict.`):(t(s,Ye)[f]=l,h++),o++}else n.split(" ").forEach((f,l)=>{switch(f){case"MSB":{a=l;break}case"LSB":{r=l;break}case"Name":{c=l;break}default:console.warn(`Unknown EFX field: ${f}`)}})}),console.debug(`EFX: ${o} total, ${h} loaded.`),s.dispatchEvent("efxreverb",s.device.getEffectType(0)),s.dispatchEvent("efxchorus",s.device.getEffectType(1)),s.dispatchEvent("efxdelay",s.device.getEffectType(2)),s.dispatchEvent("efxinsert0",s.device.getEffectType(3)),s.dispatchEvent("efxinsert1",s.device.getEffectType(4)),s.dispatchEvent("efxinsert2",s.device.getEffectType(5)),s.dispatchEvent("efxinsert3",s.device.getEffectType(6))}switchMode(e,s=!1){this.device.switchMode(e,s)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}getMapped(e){}getEfx([e,s]){let h=e<<8|s;return t(this,Ye)[h]||`0x${h.toString(16).padStart(4,"0")}`}get noteProgress(){return t(this,_e)/t(this,Te)}get noteOverall(){return this.noteProgress-t(this,Ee)}get noteBar(){return Math.floor(this.noteOverall/t(this,F))}get noteBeat(){let e=this.noteOverall%t(this,F);return e<0&&(e+=t(this,F)),e}getTimeSig(){return[t(this,F),t(this,Ge)]}getTempo(){return t(this,Ce)}sendCmd(e){this.device.runJson(e)}render(e){var k;e>t(this,_e)&&E(this,_e,e);let s=((k=t(this,We))==null?void 0:k.step(e))||[],h=0,o=new Set,a=this,r=[];this.device.getStrength().forEach((w,T)=>{t(this,ct)[T]=w}),a.device.newStrength(),s.forEach(function(w){let T=w.data;T.type==9&&(T.data[1]>0?o.add(T.part*128+T.data[0]):o.has(T.part*128+T.data[0])&&h++),w.data.type==8&&o.has(T.part*128+T.data[0])&&h++;let A=a.device.runJson(T);switch(A==null?void 0:A.reply){case"meta":{r.push(A);break}}A!=null&&A.reply&&delete A.reply}),(r==null?void 0:r.length)>0&&this.dispatchEvent("meta",r);let c=this.device.getActive(),n=[],i=a.device.getPitch(),f=a.device.getCcAll(),l=a.device.getProgram(),d=a.device.getChType(),p=this.device.getStrength();p.forEach(function(w,T,A){A[T]=Math.max(t(a,ct)[T],w);let V=A[T]-t(a,He)[T],ie=g.length*T;if(V>=0){let ht=4*.25**(f[ie+g[73]]/64);t(a,He)[T]+=Math.ceil(V-V*a.smoothingAtk**ht)}else{let ht=4*.25**(f[ie+g[72]]/64);t(a,He)[T]+=Math.floor(V-V*a.smoothingDcy**ht)}});let y=0;return c.forEach(function(w,T){w&&(n[T]=a.device.getVel(T),y+=n[T].size)}),{extraPoly:h,curPoly:y,chInUse:c,chKeyPr:n,chPitch:i,chProgr:l,chContr:f,chType:d,eventCount:s.length,title:t(this,me),bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:t(this,He).slice(),velo:p,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce(),efxSink:this.device.getEffectSink()}}},We=new WeakMap,Ct=new WeakMap,Ye=new WeakMap,me=new WeakMap,Ne=new WeakMap,He=new WeakMap,ct=new WeakMap,Te=new WeakMap,Ce=new WeakMap,F=new WeakMap,Ge=new WeakMap,Ee=new WeakMap,_e=new WeakMap,ca);export{Dr as RootDisplay,g as ccToPos,kt as dnToPos}; +%o`,a)}})}chRedir(e,r,d){if(t(this,Te)[r])return(t(this,Te)[r]-1)*16+e;if([2,3].indexOf(t(this,ae))>-1){if(d==1)return e;let c=0,p=!0;for(;p;)t(this,ye)[e+c]==0?(t(this,ye)[e+c]=r,console.debug(`Assign track ${r} to channel ${e+c+1}.`),p=!1):t(this,ye)[e+c]==r?p=!1:(c+=16,c>=128&&(c=0,p=!1));return e+c}else return e}forceVoiceRefresh(){for(let e=0;e<$.ch;e++)t(this,be)[e]&&this.dispatchEvent("voice",{part:e})}buildRchTree(){let e=[];t(this,X).forEach((r,d)=>{var c;(c=e[r])!=null&&c.constructor||(e[r]=[]),e[r].push(d)}),w(this,nt,e)}getActive(){return t(this,be)}getCc(e){let r=e*$.cc,d=t(this,y).subarray(r,r+$.cc);return d[v[0]]=d[v[0]]||t(this,Se),d[v[32]]=d[v[32]]||t(this,ae),d}getCcCh(e,r){if(it.indexOf(r)<0)throw new Error("CC number not accepted");return t(this,y)[$.cc*e+v[r]]}getCcAll(){let e=t(this,y).slice();for(let r=0;r<$.ch;r++){let d=r*$.cc;e[d+v[0]]=e[d+v[0]]||t(this,Se),e[d+v[32]]=e[d+v[32]]||t(this,ae)}return e}getChSource(){return t(this,X)}getChType(){return t(this,R)}setChType(e,r,d=t(this,D),c=!1){r&=15,t(this,R)[e]=r,r>0&&!c&&(t(this,y)[e*$.cc+v[0]]=Oe[d])}setChActive(e,r=0){t(this,be)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),t(this,be)[e]=r}getPitch(){return t(this,$e)}getProgram(){return t(this,P)}getTexts(){return t(this,Z).slice()}getVel(e){let r=new Map,d=this;return t(d,H).forEach(function(c,p){let h=Math.floor(c/128),m=c%128;e==h&&t(d,N)[c]>0&&r.set(m,{v:t(d,N)[c],s:t(d,F)[p]})}),r}getBitmap(){return{bitmap:t(this,J,ue),expire:t(this,le)}}getLetter(){return{text:t(this,xe),expire:t(this,Ce)}}getMode(){return he[t(this,D)]}getMaster(){return{volume:t(this,U)}}getRawStrength(){let e=this;return t(this,H).forEach(function(r){let d=Math.floor(r/128);t(e,N)[r]>t(e,de)[d]&&(t(e,de)[d]=t(e,N)[r])}),t(this,de)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(d,c){e[c]=Math.floor(d*t(r,y)[c*$.cc+v[7]]*t(r,y)[c*$.cc+v[11]]*t(r,U)/803288)}),e}getRpn(){return t(this,T)}getNrpn(){return t(this,qe)}getVoice(e,r,d,c){let p=e||t(this,Se),h=r,m=d||t(this,ae);he[t(this,D)]=="ns5r"&&p>0&&p<56&&(m=3);let a=this.userBank.get(p,h,m,c);if(he[t(this,D)]=="mt32"&&a.name.indexOf("MT-m:")==0){let n=parseInt(a.name.slice(5)),l=n*$.cmt,i="";t(this,ke).subarray(l,l+10).forEach(s=>{s>31&&(i+=String.fromCharCode(s))}),this.userBank.load(`MSB LSB PRG +0 127 ${h} ${i}`,!0),a.name=i,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(p,h,m,c)),a}getChVoice(e){let r=this.getVoice(t(this,y)[e*$.cc+v[0]],t(this,P)[e],t(this,y)[e*$.cc+v[32]],he[t(this,D)]);if(t(this,fe)[e])switch(t(this,D)){case x.mt32:r.ending="~",r.name="",t(this,ie).subarray(14*(e-1),14*(e-1)+10).forEach(d=>{d>31&&(r.name+=String.fromCharCode(d))})}return r}getPitchShift(e){let r=e*$.rpn;return t(this,$e)[e]/8192*t(this,T)[r]+(t(this,T)[r+3]-64)+((t(this,T)[r+1]<<7)+t(this,T)[r+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return t(this,Y).subarray(r,r+2)}setEffectTypeRaw(e=0,r,d){let c=3*e;t(this,Y)[c]=1,t(this,Y)[c+1+ +r]=d}setEffectType(e=0,r,d){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,d)}getEffectSink(){return t(this,Qe)}setLetterDisplay(e,r,d=0,c=3200){let p=this,h;w(p,xe," ".repeat(d)),e.forEach(m=>{w(p,xe,t(p,xe)+String.fromCharCode(m>31?m:32)),m<32&&(h=h||new Set,h.add(m))}),w(p,Ce,Date.now()+c),h&&(h=Array.from(h),h.forEach((m,a,n)=>{n[a]=m.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${h.length>1?"s":""}: 0x${h.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let r=!0,d=0;for(;r&&d<$.ace;)t(this,ge)[d]==e?r=!1:t(this,ge)[d]||(r=!1,t(this,ge)[d]=e,console.info(`Allocated cc${e} to ACE slot ${d}.`)),d++;d>=$.ace&&console.warn("ACE slots are full.")}getAce(){return t(this,ge)}getChAce(e,r){if(r<0||r>=$.ace)throw new RangeError("No such ACE slot");let d=t(this,ge)[r];if(d){if(it.indexOf(d)>=0)return t(this,y)[e*$.cc+v[d]];throw new Error(`Invalid ACE source: ${d}`)}else return 0}initDrums(){let e=this;t(e,q).fill(64);for(let r=0;r<$.drm;r++){let d=r*$.dpn;for(let c in Zt){let p=Zt[c],h=(d+ee[c])*$.dnc;t(e,q).subarray(h,h+$.dnc).fill(p)}}}init(e=0){let r=this;w(r,Se,0),w(r,ae,0),w(r,Ae,0),t(r,be).fill(0),t(r,y).fill(0),t(r,ge).fill(0),t(r,P).fill(0),t(r,N).fill(0),t(r,H).fill(0),t(r,de).fill(0),t(r,$e).fill(0),t(r,qe).fill(0),w(r,U,100),w(r,Z,[]),w(r,We,500),w(r,Ye,0),w(r,le,0),w(r,z,0),t(r,J,ue).fill(0),w(r,L,!1),w(r,Ze,0),w(r,ne,!0),r.initDrums(),t(r,X).forEach(function(d,c,p){p[c]=c}),r.buildRchTree(),e==0&&(r.dispatchEvent("mode","?"),w(r,D,0),t(r,ye).fill(0),t(r,Te).fill(0),w(r,Ce,0),w(r,xe,"")),t(r,y)[$.cc*9]=Oe[0],t(r,y)[$.cc*25]=Oe[0],t(r,y)[$.cc*41]=Oe[0],t(r,y)[$.cc*57]=Oe[0],t(r,R).fill(r.CH_MELODIC),t(r,R)[9]=r.CH_DRUM1,t(r,R)[25]=r.CH_DRUM3,t(r,R)[41]=r.CH_DRUMS,t(r,R)[57]=r.CH_DRUMS,t(r,R)[73]=r.CH_DRUM5,t(r,R)[89]=r.CH_DRUM7,t(r,R)[105]=r.CH_DRUMS,t(r,R)[121]=r.CH_DRUMS,t(r,je).fill(0),t(r,ke).fill(0),t(r,we).fill(0),t(r,ie).fill(0),t(r,fe).fill(0),t(r,Y).fill(0),t(r,Qe).fill(0),r.aiEfxName="",r.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let d=0;d<$.ch;d++){let c=d*$.cc;t(r,y)[c+v[7]]=100,t(r,y)[c+v[11]]=127,t(r,y)[c+v[10]]=64,t(r,y)[c+v[71]]=64,t(r,y)[c+v[72]]=64,t(r,y)[c+v[73]]=64,t(r,y)[c+v[74]]=64,t(r,y)[c+v[75]]=64,t(r,y)[c+v[76]]=64,t(r,y)[c+v[77]]=64,t(r,y)[c+v[78]]=64,t(r,y)[c+v[91]]=40,t(r,y)[c+v[101]]=127,t(r,y)[c+v[100]]=127,t(r,y)[c+v[99]]=127,t(r,y)[c+v[98]]=127;let p=d*$.rpn;t(r,T)[p]=2,t(r,T)[p+1]=64,t(r,T)[p+2]=0,t(r,T)[p+3]=64,t(r,T)[p+4]=0,t(r,T)[p+5]=0}r.dispatchEvent("mastervolume",t(r,U)),r.dispatchEvent("efxreverb",r.getEffectType(0)),r.dispatchEvent("efxchorus",r.getEffectType(1)),r.dispatchEvent("efxdelay",r.getEffectType(2)),r.dispatchEvent("efxinsert0",r.getEffectType(3)),r.dispatchEvent("efxinsert1",r.getEffectType(4)),r.dispatchEvent("efxinsert2",r.getEffectType(5)),r.dispatchEvent("efxinsert3",r.getEffectType(6)),r.dispatchEvent("reset"),r.switchMode("?")}switchMode(e,r=!1){let d=this,c=he.indexOf(e);if(c>-1){if(t(d,D)==0||r){let p=t(d,D);d.initOnReset&&r&&this.init(1),w(d,D,c),w(d,z,0),w(d,Se,jt[0][c]),w(d,ae,jt[1][c]);for(let m=0;m<$.ch;m++)t(d,R)[m]>0&&t(d,y)[m*$.cc+v[0]]==Oe[p]&&(t(d,y)[m*$.cc]=Oe[c]);switch(c){case x.mt32:{$t.forEach((m,a)=>{let n=a+1;t(d,be)[n]||(t(d,P)[n]=m,t(d,y)[n*$.cc+v[91]]=127)});for(let m=1;m<10;m++)d.dispatchEvent("voice",{part:m});break}}let h;switch(c){case x["?"]:case x.xg:{h=[1,0,65,0,5,0,0,0];break}case x.gm:case x.gs:case x.g2:case x.sd:{h=[40,4,40,18,40,32,32,0];break}case x["05rw"]:case x.x5d:case x.ns5r:{h=[44,1,44,19,44,0,44,0];break}case x.k11:case x.sg:{h=[24,0,0,0,0,0,0,0];break}case x.mt32:{h=[40,4,0,0,0,0,0,0];break}default:h=[0,0,0,0,0,0,0,0]}for(let m=0;m<4;m++)t(d,Y)[3*m]||(t(d,Y)[3*m+1]=h[2*m],t(d,Y)[3*m+2]=h[2*m+1],d.dispatchEvent(`efx${["reverb","chorus","delay","insert"][m]}`,d.getEffectType(m)));d.dispatchEvent("mode",e),d.forceVoiceRefresh()}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,de).fill(0)}runJson(e){var r;if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,ct)[e.type].call(this,e);{let d=this.chRedir(e.part,e.track),c=!1;(r=t(this,nt)[d])==null||r.forEach(p=>{e.channel=p,c=!0,t(this,ct)[e.type].call(this,e)}),c||console.warn(`${Qt[e.type]?Qt[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${d+1} without any recipient.`)}t(this,Z).length>100&&t(this,Z).splice(100,t(this,Z).length-99)}runRaw(e){}async loadBank(e,r){let d=this;switch(e=e.toLowerCase(),e){case"s7e":{d.userBank.clearRange({msb:63,lsb:[21,22]}),d.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{ft.context=this,d.userBank.load(await ft.read(e,r));break}}d.forceVoiceRefresh()}},D=new WeakMap,z=new WeakMap,le=new WeakMap,pe=new WeakMap,J=new WeakSet,ue=function(){return t(this,pe)[t(this,z)]},ta=function(e){t(this,pe)[t(this,z)]=e},be=new WeakMap,X=new WeakMap,R=new WeakMap,y=new WeakMap,ge=new WeakMap,P=new WeakMap,N=new WeakMap,te=new WeakMap,H=new WeakMap,F=new WeakMap,$e=new WeakMap,de=new WeakMap,De=new WeakMap,T=new WeakMap,qe=new WeakMap,q=new WeakMap,fe=new WeakMap,we=new WeakMap,ie=new WeakMap,je=new WeakMap,ke=new WeakMap,Y=new WeakMap,Qe=new WeakMap,Se=new WeakMap,ae=new WeakMap,U=new WeakMap,Ae=new WeakMap,We=new WeakMap,Ye=new WeakMap,xe=new WeakMap,Ce=new WeakMap,Ze=new WeakMap,ne=new WeakMap,L=new WeakMap,nt=new WeakMap,St=new WeakMap,Z=new WeakMap,ye=new WeakMap,Te=new WeakMap,V=new WeakMap,Pe=new WeakMap,G=new WeakMap,ct=new WeakMap,ht=new WeakMap,Ie=new WeakMap,Ue=new WeakMap,re=new WeakMap,se=new WeakMap,ve=new WeakMap,Le=new WeakMap,Be=new WeakMap,Ne=new WeakMap,ea);var Mt=ya(aa(),1);O();O();var ot,ra,ia=(ra=class{constructor(b,e,r,d){S(this,ot,!1);w(this,ot,b),this.start=e,this.end=r,this.data=d}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return t(this,ot)}},ot=new WeakMap,ra),Ct=class extends ia{constructor(b,e,r){super(!0,b,e,r)}},na=class extends ia{constructor(b,e){super(!1,b,b,e)}},He,sa,Tt=(sa=class extends Array{constructor(){super(...arguments);S(this,He,-1)}resetIndex(e){w(this,He,-1)}fresh(){this.sort(function(e,r){return e.start==r.start?0:(+(e.start>r.start)<<1)-1}),this.forEach(function(e,r){e.index=r})}step(e,r=!1){let d=[];if(r)for(let c=0;ce);c++){if(this[c].endt(p,He)&&(d.push(h),w(p,He,h.index))})}return d}getRange(e,r){var m;e>r&&([e,r]=[r,e]);let d=[],c=-1,p=Math.ceil(Math.sqrt(this.length)),h=!0;for(let a=0;a=e&&(c=a):c=c<0?a:c;for(;h;)((m=this[c])==null?void 0:m.end)=e&&d.push(this[c]):h=!1,c++;return d}},He=new WeakMap,sa);var Ta=0xffffffffffff,ca=function(b){let e=new Tt,r=this,d=b.timeDivision,c=120,p=new Tt,h=0,m=0;p.push(new Ct(0,Ta,[120,0])),b.track.forEach(function(i){h=0,i.event.forEach(function(s){h+=s.deltaTime,s.type==255&&(s==null?void 0:s.metaType)==81&&(c=6e7/s.data,p[p.length-1]&&p.push(new Ct(h,0xffffffffffff,[c,0])))})}),p.fresh(),p.forEach(function(i,s,o){s>0&&(o[s-1].end=i.start)});let a=120;p.forEach(function(i,s,o){s>0&&(i.end==i.start?o.splice(o.indexOf(i),1):a==i.data[0]&&(o[s-1].end=i.end,o.splice(o.indexOf(i),1)),a=i.data[0])});let n=0,l=120;return p.forEach(function(i){let s=i.start,o=s/l/d*60+n;l=i.data[0],n=o-s/l/d*60,i.data[1]=n}),console.debug("All tempo changes: ",p),c=120,h=0,m=0,b.track.forEach(function(i,s){h=0,m=0;let o=s+1;i.event.forEach(function(f,u){h+=f.deltaTime;let g=p.step(h,!0)[0];g&&(c=g.data[0],m=g.data[1]);let E={type:f.type,data:f.data,track:o,part:0};f.type>14?E.meta=f.metaType:E.part=f.channel,e.push(new na(h/c/d*60+m,E))})}),e.fresh(),self.midiEvents=e,console.debug(`Parsed a type ${b.formatType} MIDI sequence.`),e};Mt.default.customInterpreter=qt;var B=function(b,e,r){b.addEventListener(r,d=>{e.dispatchEvent(r,d.data)})},Je,Ge,et,me,_e,Xe,lt,Me,Re,K,Fe,Ee,Ve,oa,Ar=(oa=class extends dt{constructor(e,r=.5,d=.5){super();M(this,"device");S(this,Je,void 0);S(this,Ge,{});S(this,et,[]);S(this,me,"");S(this,_e,[]);S(this,Xe,new Uint8ClampedArray(128));S(this,lt,new Uint8ClampedArray(128));S(this,Me,.5);S(this,Re,120);S(this,K,4);S(this,Fe,4);S(this,Ee,0);S(this,Ve,0);M(this,"smoothingAtk",0);M(this,"smoothingDcy",0);let c=this;c.smoothingAtk=r,c.smoothingDcy=d,c.device=e,c.addEventListener("meta",function(p){var h;(h=p==null?void 0:p.data)==null||h.forEach(function(m){(t(c,_e)[m.meta]||console.debug).call(c,m.meta,m.data)})}),B(c.device,c,"mode"),B(c.device,c,"mastervolume"),B(c.device,c,"channelactive"),B(c.device,c,"channelmin"),B(c.device,c,"channelmax"),B(c.device,c,"channelreset"),B(c.device,c,"channeltoggle"),B(c.device,c,"screen"),B(c.device,c,"metacommit"),B(c.device,c,"voice"),B(c.device,c,"pitch"),B(c.device,c,"note"),B(c.device,c,"reset"),B(c.device,c,"efxreverb"),B(c.device,c,"efxchorus"),B(c.device,c,"efxdelay"),B(c.device,c,"efxinsert0"),B(c.device,c,"efxinsert1"),B(c.device,c,"efxinsert2"),B(c.device,c,"efxinsert3"),B(c.device,c,"partefxtoggle"),t(c,_e)[3]=function(p,h){var m;((m=t(c,me))==null?void 0:m.length)<1&&(w(c,me,h),c.dispatchEvent("title",t(c,me)))},t(c,_e)[81]=function(p,h){let m=c.noteProgress,a=t(c,Me)||.5;w(c,Re,6e7/h),w(c,Me,h/1e6),w(c,Ee,t(c,Ee)+(m*(a/t(c,Me))-m)),c.dispatchEvent("tempo",t(c,Re))},t(c,_e)[88]=function(p,h){let m=c.noteProgress,a=c.noteOverall,n=c.noteBar,l=c.noteBeat,i=t(c,K),s=t(c,Fe);w(c,K,h[0]),w(c,Fe,1<=i&&(i{if(!n)return;let i=n.split(" ");if(l){if(!h)return;let s="",o="";i.forEach((f,u)=>{switch(u){case m:{s=f;break}case a:{o=f;break}}}),!t(d,Ge)[s]||r?(t(d,Ge)[s]=o,c++):self.debugMode&&console.debug(`Voice "${o}" (${s}) seems to be in conflict with (${t(d,Ge)[s]}).`),p++}else i.forEach((s,o)=>{switch(s){case"ID":{m=o,h++;break}case"Name":{a=o,h++;break}default:console.debug(`Unknown map field: ${s}`)}})}),console.debug(`Map: ${p} total, ${c} loaded.`),d==null||d.device.forceVoiceRefresh()}async loadEfx(e,r){let d=this,c=0,p=0,h,m,a;e.split(` +`).forEach((n,l)=>{if(n)if(l){let i=0,s;n.split(" ").forEach((o,f)=>{switch(f){case h:{i|=parseInt(o,16)<<8;break}case m:{i|=parseInt(o,16);break}case a:{s=o;break}}}),!t(d,et)[i]||r?(t(d,et)[i]=s,c++):self.debugMode&&console.debug(`EFX ID 0x${i.toString(16).padStart(4,"0")} (${s}) seems to be in conflict.`),p++}else n.split(" ").forEach((i,s)=>{switch(i){case"MSB":{h=s;break}case"LSB":{m=s;break}case"Name":{a=s;break}default:console.debug(`Unknown EFX field: ${i}`)}})}),console.debug(`EFX: ${p} total, ${c} loaded.`),d.dispatchEvent("efxreverb",d.device.getEffectType(0)),d.dispatchEvent("efxchorus",d.device.getEffectType(1)),d.dispatchEvent("efxdelay",d.device.getEffectType(2)),d.dispatchEvent("efxinsert0",d.device.getEffectType(3)),d.dispatchEvent("efxinsert1",d.device.getEffectType(4)),d.dispatchEvent("efxinsert2",d.device.getEffectType(5)),d.dispatchEvent("efxinsert3",d.device.getEffectType(6))}switchMode(e,r=!1){this.device.switchMode(e,r)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}getMapped(e){return t(this,Ge)[e]||e}getEfx([e,r]){let d=e<<8|r;return t(this,et)[d]||`0x${d.toString(16).padStart(4,"0")}`}get noteProgress(){return t(this,Ve)/t(this,Me)}get noteOverall(){return this.noteProgress-t(this,Ee)}get noteBar(){return Math.floor(this.noteOverall/t(this,K))}get noteBeat(){let e=this.noteOverall%t(this,K);return e<0&&(e+=t(this,K)),e}getTimeSig(){return[t(this,K),t(this,Fe)]}getTempo(){return t(this,Re)}sendCmd(e){this.device.runJson(e)}render(e){var g;e>t(this,Ve)&&w(this,Ve,e);let r=((g=t(this,Je))==null?void 0:g.step(e))||[],d=0,c=new Set,p=this,h=[];this.device.getStrength().forEach((E,k)=>{t(this,lt)[k]=E}),p.device.newStrength(),r.forEach(function(E){let k=E.data;k.type==9&&(k.data[1]>0?c.add(k.part*128+k.data[0]):c.has(k.part*128+k.data[0])&&d++),E.data.type==8&&c.has(k.part*128+k.data[0])&&d++;let C=p.device.runJson(k);switch(C==null?void 0:C.reply){case"meta":{h.push(C);break}}C!=null&&C.reply&&delete C.reply}),(h==null?void 0:h.length)>0&&this.dispatchEvent("meta",h);let m=this.device.getActive(),a=[],n=p.device.getPitch(),l=p.device.getCcAll(),i=p.device.getProgram(),s=p.device.getChType(),o=this.device.getStrength();o.forEach(function(E,k,C){C[k]=Math.max(t(p,lt)[k],E);let A=C[k]-t(p,Xe)[k],_=v.length*k;if(A>=0){let pt=4*.25**(l[_+v[73]]/64);t(p,Xe)[k]+=Math.ceil(A-A*p.smoothingAtk**pt)}else{let pt=4*.25**(l[_+v[72]]/64);t(p,Xe)[k]+=Math.floor(A-A*p.smoothingDcy**pt)}});let f=0;return m.forEach(function(E,k){E&&(a[k]=p.device.getVel(k),f+=a[k].size)}),{extraPoly:d,curPoly:f,chInUse:m,chKeyPr:a,chPitch:n,chProgr:i,chContr:l,chType:s,eventCount:r.length,title:t(this,me),bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:t(this,Xe).slice(),velo:o,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce(),efxSink:this.device.getEffectSink()}}},Je=new WeakMap,Ge=new WeakMap,et=new WeakMap,me=new WeakMap,_e=new WeakMap,Xe=new WeakMap,lt=new WeakMap,Me=new WeakMap,Re=new WeakMap,K=new WeakMap,Fe=new WeakMap,Ee=new WeakMap,Ve=new WeakMap,oa);export{Ar as RootDisplay,v as ccToPos,ee as dnToPos}; diff --git a/dist/xp_state.mjs b/dist/xp_state.mjs index c96cafcf..486ac783 100644 --- a/dist/xp_state.mjs +++ b/dist/xp_state.mjs @@ -1,8 +1,8 @@ -var Rt=Object.defineProperty;var Ot=(b,e,s)=>e in b?Rt(b,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):b[e]=s;var M=(b,e,s)=>(Ot(b,typeof e!="symbol"?e+"":e,s),s),st=(b,e,s)=>{if(!e.has(b))throw TypeError("Cannot "+s)};var t=(b,e,s)=>(st(b,e,"read from private field"),s?s.call(b):e.get(b)),m=(b,e,s)=>{if(e.has(b))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(b):e.set(b,s)},E=(b,e,s,f)=>(st(b,e,"write to private field"),f?f.call(b,s):e.set(b,s),s);(function(){var b=function(c,n,i){var o,h;if(self.MessageEvent)switch(c){case"message":{h=new MessageEvent(c,{data:n,ports:i==null?void 0:i.ports}),Object.defineProperty(h,"source",{value:i==null?void 0:i.source});break}default:h=new Event(c)}else h=document.createEvent("Event"),h.initEvent(c,!1,!1),i&&c=="message"&&(h.data=n,i.source&&Object.defineProperty(h,"source",{value:i.source}),(o=i.ports)!=null&&o.length&&Object.defineProperty(h,"ports",{value:i.ports}));return h};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),s=[],f={},d=function(c){var n,i=this;if((this==null?void 0:this.constructor)!=d)throw new TypeError("Illegal constructor");s.push(this),(n=f[c])!=null&&n.constructor||(f[c]=[]),f[c].push(this);var o=Math.floor(Math.random()*281474976710656),h=[],l=0,g=[],$=!0,w=!1;Object.defineProperty(this,"id",{get:function(){return o}}),Object.defineProperty(this,"name",{value:c}),this.close=function(){var S,B=s.indexOf(i);B>-1?(e.postMessage({t:"d",c,i:o}),s.splice(B,1),(S=f[c])!=null&&S.constructor&&(B=f[c].indexOf(i),B>-1&&f[c].splice(B,1)),f[c].length||delete f[c],console.debug("[Snowy] BroadcastChannel closed."),w=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(S){if(e){if(w)throw new Error("Channel already closed");e.postMessage({t:"m",c,i:o,m:l,d:S}),l++,l>4294967295&&(l=0)}else g.push(S),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if($){for(e.postMessage({t:"r",c,i:o}),console.debug("[Snowy] ".concat(g.length," message(s) in cache."));g.length;){var S=g.shift();i.postMessage(S)}$=!1,console.debug("[Snowy] All cached messages are flushed away.")}}else throw new Error("Tried to flush when the ports are not ready")},this.receiveMessage=function(S){S.c==c?S.i!=o&&i.dispatchEvent(b("message",S.d,{source:i})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(o," receives from ").concat(c,", not ").concat(S.c,"."))};var k={};this.dispatchEvent=function(S){var B,de;if(Object.defineProperty(S,"target",{value:i}),Object.defineProperty(S,"currentTarget",{value:i}),(B=k[S.type])!=null&&B.length)for(var ue=k[S.type],me=0;me-1&&k[S].splice(me,1)}!((ue=k[S])!=null&&ue.length)&&k[S].constructor&&delete k[S]}},self.BroadcastChannel=d,a=function(){if(e){e.addEventListener("message",function(n){var i=n.data,o=!1;switch(i.t){case"k":{o=!1,e.postMessage({t:"k"});break}case"m":{var h=f[i.c];if(h!=null&&h.length)for(var l=0;l{switch(f.addEventListener("abort",()=>{a(new Error("Blob read aborted"))}),f.addEventListener("error",r=>{a(f.error||r.data||new Error("Blob read error"))}),f.addEventListener("load",()=>{d(f.result)}),s.toLowerCase()){case"arraybuffer":case"buffer":{f.readAsArrayBuffer(e);break}case"string":case"text":{f.readAsText(e);break}default:a(new Error(`Unknown target ${s}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return b(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return b(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(b,e){let s=0,f=16,d=this,a=[];for(;s-1;){let r=d.lastIndexOf(b);a.unshift(d.slice(r+b.length)),d=d.slice(0,r),r==0&&a.unshift(""),s++}return d.length&&a.unshift(d),a.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(b,e){if(e){let s=this;for(;s.length0){let f=this.pool.length,d=1<=1&&r>=0;){if(r<=0)throw new Error("TTL reached.");if(a==f)a-=d;else{let n=it(e,this.pool[a]);switch(n){case 0:{r=0;break}case 1:{a+d<=f&&(a+=d);break}case-1:{a!=0&&(a-=d);break}default:console.warn(`Unexpected result ${n}.`)}}d=d>>1,r--}let c=!0;if(a>=this.pool.length)c=!1;else{let n=this;this.pool[a].forEach(function(i,o,h){c&&i!=e[o]&&(c=!1)}),!c&&it(e,this.pool[a])>0&&a++}return c||s?a:-1}else return s?0:-1},this.add=function(e,s){return e.data=s,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match in "${this.name||"(unknown)"}" for "${e}". Default action not defined.`)},this.get=function(e){let s=this.point(e);if(s>-1)return this.pool[s].data;this.default(e)},this.run=function(e,...s){let f=this.point(e);f>-1?e.subarray?this.pool[f].data(e.subarray(this.pool[f].length),...s):this.pool[f].data(e.slice(this.pool[f].length),...s):this.default(e,...s)}};var I,nt,ct=(nt=class{constructor(){m(this,I,{})}addEventListener(b,e){t(this,I)[b]||(t(this,I)[b]=[]),t(this,I)[b].unshift(e)}removeEventListener(b,e){if(t(this,I)[b]){let s=t(this,I)[b].indexOf(e);s>-1&&t(this,I)[b].splice(s,1),t(this,I)[b].length<1&&delete t(this,I)[b]}}dispatchEvent(b,e){var d;let s=new Event(b),f=this;s.data=e,((d=t(this,I)[b])==null?void 0:d.length)>0&&t(this,I)[b].forEach(function(a){try{a==null||a.call(f,s)}catch(r){console.error(r)}}),this[`on${b}`]&&this[`on${b}`](s)}},I=new WeakMap,nt);var Dt=["MSB","PRG","LSB"],je=function(b){let e=Math.floor(b/10),s=b%10;return`${e.toString(16)}${s}`},_,ot,We=(ot=class{constructor(...b){m(this,_,void 0);M(this,"strictMode",!1);this.loadFiles(...b)}get(b=0,e=0,s=0,f){let d=[b,e,s],a,r=Array.from(arguments);switch(f){case"xg":{switch(b){case 0:{s==126?r[2]=125:s==127&&(r[2]=0);break}case 32:{r[2]+=4;break}case 33:case 35:case 36:{r[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:r[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{s==126&&(r[2]=0);break}case 48:case 64:case 126:case 127:{s==126&&(r[2]=0);break}}break}case"gs":{b==0&&s<5?r[2]=0:b>125&&s<5&&s!=2&&(r[2]=b,r[0]=0);break}case"g2":case"sd":{(b>>1==40||b>95&&b<100)&&(r[2]|=16);break}case"sg":{b==8&&s==0&&(r[2]=5);break}case"s90es":{s<8?r[2]+=17:s<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}case"motif":{s<8?r[2]+=28:s<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}}let c=" ",n="M",i=0,o=0;switch(r[0]){case 0:{r[2]==127?n="MT-a":r[2]==126?n="MT-b":r[2]==7?n="GM-k":r[2]==5?n="SG-a":r[2]==4?n="SP-l":r[2]==0||f=="gs"&&r[2]<5?n="GM-a":(n="y",i=3);break}case 8:{f=="sg"?n="GM-s":n="r:";break}case 48:{n=`yM${(r[2]>>3).toString().padStart(2,"0")}`,i=1;break}case 56:{n="GM-b";break}case 61:case 120:{n="rDrm";break}case 62:{n="kDrm";break}case 63:{if(r[2]<17){let $=r[2];n=$<10?"kP:":"kC:",n+=$%10}else r[2]<34?n=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][r[2]-17]:n="Ds";break}case 64:{n="ySFX";break}case 67:{n="DX:S";break}case 80:case 81:case 82:case 83:{n=`Prg${"UABC"[r[0]-80]}`;break}case 88:case 89:case 90:case 91:{n=`Cmb${"UABC"[r[0]-88]}`;break}case 95:{n=`${["DR","PC"][r[2]]}-d`;break}case 96:{n=r[2]==106?"AP-a":r[2]>>4==1?"SDg":"PF",r[2]>63?o=63:r[2]>>4==1&&(o=16),i=3;break}case 97:{n=r[2]>>4==1?"SDa":"VL:",i=3,r[2]>>4==1?o=16:o=112;break}case 98:{n=r[2]>>4==1?"SDb":"SG-a",i=3,o=16;break}case 99:{n=r[2]>>4==1?"SDc":"DX",r[2]>63?o=63:r[2]>>4==1&&(o=16),i=3;break}case 100:{n="AN",r[2]>63?o=63:r[2]>>4==1&&(o=16),i=3;break}case 104:case 105:case 106:case 107:{n="SDd",o=104;break}case 121:{n=`GM-${r[2]?"":"a"}`,i=3;break}case 122:{n="lDrm";break}case 126:{n="yDrS";break}case 127:{r[2]==127?n="rDrm":n="yDrm";break}default:r[0]<48?n="r:":n="M"}n.length<4&&(n+=`${[b,s,r[0],r[2]][i]-o}`.padStart(4-n.length,"0")),f=="xg"&&b==16&&(a=`Voice${(s*128+e+1).toString().padStart(3,"0")}`,c=" ");let h=[r[0],r[1],r[2]];for(;!((a==null?void 0:a.length)>=0);)a=t(this,_)[r[1]||0][(r[0]<<7)+r[2]],a||(this.strictMode?(a="",c="?"):t(this,_)[r[1]||0][r[0]<<7]?r[0]==0?(r[2]=0,c="^"):r[2]<1?(r[0]=0,c="*"):(r[2]--,c="^"):b==48?(r[0]=0,r[2]=0,c="!"):b==62?(r[1]--,c=" ",r[1]<1&&!(a!=null&&a.length)&&(r[0]=0,c="!")):b<63?r[0]==0?(r[2]=0,c="^"):r[2]<1?(r[0]=0,c="*"):r[2]--:b==80?(a=`PrgU:${e.toString().padStart(3,"0")}`,c="!"):b==88?(a=`CmbU:${e.toString().padStart(3,"0")}`,c="!"):b==121?(a=`GM2Vox0${s}`,c="#"):b==122?(r[1]==32?r[1]==0:r[1]%=7,a=t(this,_)[r[1]||0][(r[0]<<7)+r[2]],a?c=" ":(a="",c="*")):r[1]==0?(a=`${b.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${s.toString().padStart(3,"0")}`,c="!"):r[0]==0?(r[2]=0,c="^"):r[2]>0?r[2]--:r[1]>0?(r[1]=0,c="!"):(r[0]=0,c="?"));let l=[r[0],r[1],r[2]];(f=="gs"||f=="ns5r")&&c=="^"&&(c=" "),b==127&&c=="^"&&(c=" "),c!=" "&&self.debugMode&&(a="");let g="??";switch(r[0]){case 0:{r[2]==0?g="GM":r[2]==5||r[2]==7?g="KG":r[2]<126?g="XG":r[2]==127&&(g="MT");break}case 48:{g="MU";break}case 56:{g="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{g="AI";break}case 62:case 82:case 90:{g="XD";break}case 63:{r[2]<17?g="KR":r[2]<34?g="ES":g="DS";break}case 64:case 126:{g="XG";break}case 67:case 99:{g=r[2]>>4==1?"SD":"DX";break}case 81:{g="RW";break}case 95:{g=["DR","PC"][r[2]];break}case 96:{g=r[2]==106?"AP":r[2]>>4==1?"SD":"PF";break}case 97:{g=r[2]>>4==1?"SD":"VL";break}case 98:{g=r[2]>>4==1?"SD":"SG";break}case 100:{g="AN";break}case 104:case 105:case 106:case 107:{g="SD";break}case 120:{g="GS";break}case 121:{g=r[2]?"G2":"GM";break}case 122:{g="KG";break}case 127:{g=r[2]==127?"MT":e==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&f=="xg"?g="XG":g="GS")}return{name:a||`${je(b||0)} ${je(e||0)} ${je(s||0)}`,iid:h,eid:l,sid:d,ending:c,sect:n,standard:g}}async load(b,e,s){let f=this,d=[],a=0,r=0;b.split(` -`).forEach(function(c,n){let i=c.split(" "),o=[];n==0?i.forEach(function(h,l){d[Dt.indexOf(h)]=l}):i.forEach(async function(h,l){var g;l>2?(t(f,_)[o[d[1]]]=t(f,_)[o[d[1]]]||[],(!((g=t(f,_)[o[d[1]]][(o[d[0]]<<7)+o[d[2]]])!=null&&g.length)||e)&&(t(f,_)[o[d[1]]][(o[d[0]]<<7)+o[d[2]]]=i[3],a++),r++):o.push(parseInt(i[l]))})}),e||console.debug(`Map "${s||"(internal)"}": ${r} total, ${a} loaded.`)}clearRange(b){let e=b.prg!=null?b.prg.constructor==Array?b.prg:[b.prg,b.prg]:[0,127],s=b.msb!=null?b.msb.constructor==Array?b.msb:[b.msb,b.msb]:[0,127],f=b.lsb!=null?b.lsb.constructor==Array?b.lsb:[b.lsb,b.lsb]:[0,127];for(let d=s[0];d<=s[1];d++){let a=d<<7;for(let r=f[0];r<=f[1];r++){let c=a+r;for(let n=e[0];n<=e[1];n++)delete t(this,_)[n][c]}}}init(){E(this,_,[]);for(let b=0;b<128;b++)t(this,_).push([""])}async loadFiles(...b){this.init();let e=this;b.forEach(async function(s,f){try{await fetch(`./data/bank/${s}.tsv`).then(function(d){return d.text()}).then(d=>{e.load(d,!1,s)})}catch(d){console.error(`Failed loading "${s}.tsv".`)}})}},_=new WeakMap,ot);var Oe,lt,ft=(lt=class{constructor(){m(this,Oe,{});M(this,"context")}set(b,e){t(this,Oe)[b]=e}has(b){return!!t(this,Oe)[b]}async read(b,e){if(!this.has(b))throw new Error(`No decoder registered for "${b}"`);return await t(this,Oe)[b].call(this.context||this,e)}},Oe=new WeakMap,lt);var Ut=function(b,e){let s=!0;return e.forEach((f,d)=>{s=s&&b[d]==f}),s},ht=function(b){let e=0;return b.forEach(s=>{e*=256,e+=s}),e},Be=new TextDecoder,ze=new ft;ze.set("s7e",async function(b){let e=new Uint8Array(await b.slice(0,65536).arrayBuffer()),s="MSB LSB PRG NME",f=[0,0,0,0],d=32,a=0,r=0,c=!0,n=[],i=0;for(;c;){let o=e.subarray(a);([()=>{Be.decode(o.subarray(0,4))=="YSFC"?(a+=80,r=1):a++},()=>{if(Ut(o.subarray(0,4),f))n.forEach((h,l,g)=>{let $=ht(e.subarray(h.start+4,h.start+8));h.length=$}),r=2;else{let h=Be.decode(o.subarray(0,4)),l=ht(o.subarray(4,8));n.push({type:h,start:l}),a+=8}},()=>{let h=n[i],l=e.subarray(h.start,h.start+h.length),g=32;switch(h.type){case"ENVC":{let $=d;for(;$=n.length&&(r=3,c=!1)}][r]||(()=>{c=!1}))()}return s});var Ge=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),Ie=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],Pt=[17.1,18.6,20.2,21.8,23.3,24.9,26.5,28,29.6,31.2,32.8,34.3,35.9,37.5,39,40.6,42.2,43.7,45.3,46.9,48.4,50],De=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],dt=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],ut=function(b){let e=.1,s=-.3;return b>66?(e=5,s=315):b>56?(e=1,s=47):b>46&&(e=.5,s=18.5),e*b-s},pt=function(b){return b>105?Pt[b-106]:b>100?b*1.1-100:b/10},bt=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),Ye={};`hi*, +var Ot=Object.defineProperty;var Dt=(g,e,r)=>e in g?Ot(g,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):g[e]=r;var T=(g,e,r)=>(Dt(g,typeof e!="symbol"?e+"":e,r),r),it=(g,e,r)=>{if(!e.has(g))throw TypeError("Cannot "+r)};var t=(g,e,r)=>(it(g,e,"read from private field"),r?r.call(g):e.get(g)),k=(g,e,r)=>{if(e.has(g))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(g):e.set(g,r)},w=(g,e,r,d)=>(it(g,e,"write to private field"),d?d.call(g,r):e.set(g,r),r);(function(){var g=function(m,a,i){var c,n;if(self.MessageEvent)switch(m){case"message":{n=new MessageEvent(m,{data:a,ports:i==null?void 0:i.ports}),Object.defineProperty(n,"source",{value:i==null?void 0:i.source});break}default:n=new Event(m)}else n=document.createEvent("Event"),n.initEvent(m,!1,!1),i&&m=="message"&&(n.data=a,i.source&&Object.defineProperty(n,"source",{value:i.source}),(c=i.ports)!=null&&c.length&&Object.defineProperty(n,"ports",{value:i.ports}));return n};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),r=[],d={},h=function(m){var a,i=this;if((this==null?void 0:this.constructor)!=h)throw new TypeError("Illegal constructor");r.push(this),(a=d[m])!=null&&a.constructor||(d[m]=[]),d[m].push(this);var c=Math.floor(Math.random()*281474976710656),n=[],s=0,o=[],f=!0,l=!1;Object.defineProperty(this,"id",{get:function(){return c}}),Object.defineProperty(this,"name",{value:m}),this.close=function(){var v,S=r.indexOf(i);S>-1?(e.postMessage({t:"d",c:m,i:c}),r.splice(S,1),(v=d[m])!=null&&v.constructor&&(S=d[m].indexOf(i),S>-1&&d[m].splice(S,1)),d[m].length||delete d[m],console.debug("[Snowy] BroadcastChannel closed."),l=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(v){if(e){if(l)throw new Error("Channel already closed");e.postMessage({t:"m",c:m,i:c,m:s,d:v}),s++,s>4294967295&&(s=0)}else o.push(v),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(f){for(e.postMessage({t:"r",c:m,i:c}),console.debug("[Snowy] ".concat(o.length," message(s) in cache."));o.length;){var v=o.shift();i.postMessage(v)}f=!1,console.debug("[Snowy] All cached messages are flushed away.")}}else throw new Error("Tried to flush when the ports are not ready")},this.receiveMessage=function(v){v.c==m?v.i!=c&&i.dispatchEvent(g("message",v.d,{source:i})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(c," receives from ").concat(m,", not ").concat(v.c,"."))};var b={};this.dispatchEvent=function(v){var S,R;if(Object.defineProperty(v,"target",{value:i}),Object.defineProperty(v,"currentTarget",{value:i}),(S=b[v.type])!=null&&S.length)for(var L=b[v.type],X=0;X-1&&b[v].splice(X,1)}!((L=b[v])!=null&&L.length)&&b[v].constructor&&delete b[v]}},self.BroadcastChannel=h,$=function(){if(e){e.addEventListener("message",function(a){var i=a.data,c=!1;switch(i.t){case"k":{c=!1,e.postMessage({t:"k"});break}case"m":{var n=d[i.c];if(n!=null&&n.length)for(var s=0;s{switch(d.addEventListener("abort",()=>{$(new Error("Blob read aborted"))}),d.addEventListener("error",p=>{$(d.error||p.data||new Error("Blob read error"))}),d.addEventListener("load",()=>{h(d.result)}),r.toLowerCase()){case"arraybuffer":case"buffer":{d.readAsArrayBuffer(e);break}case"string":case"text":{d.readAsText(e);break}default:$(new Error(`Unknown target ${r}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return g(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return g(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(g,e){let r=0,d=16,h=this,$=[];for(;r-1;){let p=h.lastIndexOf(g);$.unshift(h.slice(p+g.length)),h=h.slice(0,p),p==0&&$.unshift(""),r++}return h.length&&$.unshift(h),$.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(g,e){if(e){let r=this;for(;r.length0){let d=this.pool.length,h=1<=1&&p>=0;){if(p<=0)throw new Error("TTL reached.");if($==d)$-=h;else{let a=nt(e,this.pool[$]);switch(a){case 0:{p=0;break}case 1:{$+h<=d&&($+=h);break}case-1:{$!=0&&($-=h);break}default:console.warn(`Unexpected result ${a}.`)}}h=h>>1,p--}let m=!0;if($>=this.pool.length)m=!1;else{let a=this;this.pool[$].forEach(function(i,c,n){m&&i!=e[c]&&(m=!1)}),!m&&nt(e,this.pool[$])>0&&$++}return m||r?$:-1}else return r?0:-1},this.add=function(e,r){return e.data=r,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match in "${this.name||"(unknown)"}" for "${e}". Default action not defined.`)},this.get=function(e){let r=this.point(e);if(r>-1)return this.pool[r].data;this.default(e)},this.run=function(e,...r){let d=this.point(e);d>-1?e.subarray?this.pool[d].data(e.subarray(this.pool[d].length),...r):this.pool[d].data(e.slice(this.pool[d].length),...r):this.default(e,...r)}};var K,ct,ot=(ct=class{constructor(){k(this,K,{})}addEventListener(g,e){t(this,K)[g]||(t(this,K)[g]=[]),t(this,K)[g].unshift(e)}removeEventListener(g,e){if(t(this,K)[g]){let r=t(this,K)[g].indexOf(e);r>-1&&t(this,K)[g].splice(r,1),t(this,K)[g].length<1&&delete t(this,K)[g]}}dispatchEvent(g,e){var h;let r=new Event(g),d=this;r.data=e,((h=t(this,K)[g])==null?void 0:h.length)>0&&t(this,K)[g].forEach(function($){try{$==null||$.call(d,r)}catch(p){console.error(p)}}),this[`on${g}`]&&this[`on${g}`](r)}},K=new WeakMap,ct);var At=["MSB","PRG","LSB"],Ye=function(g){let e=Math.floor(g/10),r=g%10;return`${e.toString(16)}${r}`},z,lt,je=(lt=class{constructor(...g){k(this,z,void 0);T(this,"strictMode",!1);this.loadFiles(...g)}get(g=0,e=0,r=0,d){let h=[g,e,r],$,p=Array.from(arguments);switch(d){case"xg":{switch(g){case 0:{r==126?p[2]=125:r==127&&(p[2]=0);break}case 16:{r==126&&(p[2]=0);break}case 32:{p[2]+=4;break}case 33:case 35:case 36:{p[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:p[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{r==126&&(p[2]=0);break}case 48:case 64:case 126:case 127:{r==126&&(p[2]=0);break}}break}case"gs":{g==0&&r<5?p[2]=0:g>125&&r<5&&r!=2&&(p[2]=g,p[0]=0);break}case"g2":case"sd":{(g>>1==40||g>95&&g<100)&&(p[2]|=16);break}case"sg":{g==8&&r==0&&(p[2]=5);break}case"s90es":{r<8?p[2]+=17:r<32?p[2]+=13:p[2]=(p[2]>>3)+19;break}case"motif":{r<8?p[2]+=28:r<32?p[2]+=13:p[2]=(p[2]>>3)+19;break}}let m=" ",a="M",i=0,c=0;switch(p[0]){case 0:{p[2]==127?a="MT-a":p[2]==126?a="MT-b":p[2]==7?a="GM-k":p[2]==5?a="SG-a":p[2]==4?a="SP-l":p[2]==0||d=="gs"&&p[2]<5?a="GM-a":(a="y",i=3);break}case 8:{d=="sg"?a="GM-s":a="r:";break}case 48:{a=`yM${(p[2]>>3).toString().padStart(2,"0")}`,i=1;break}case 56:{a="GM-b";break}case 61:case 120:{a="rDrm";break}case 62:{a="kDrm";break}case 63:{if(p[2]<17){let f=p[2];a=f<10?"kP:":"kC:",a+=f%10}else p[2]<34?a=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][p[2]-17]:a="Ds";break}case 64:{a="ySFX";break}case 67:{a="DX:S";break}case 80:case 81:case 82:case 83:{a=`Prg${"UABC"[p[0]-80]}`;break}case 88:case 89:case 90:case 91:{a=`Cmb${"UABC"[p[0]-88]}`;break}case 95:{a=`${["DR","PC"][p[2]]}-d`;break}case 96:{a=p[2]==106?"AP-a":p[2]>>4==1?"SDg":"PF",p[2]>63?c=63:p[2]>>4==1&&(c=16),i=3;break}case 97:{a=p[2]>>4==1?"SDa":"VL:",i=3,p[2]>>4==1?c=16:c=112;break}case 98:{a=p[2]>>4==1?"SDb":"SG-a",i=3,c=16;break}case 99:{a=p[2]>>4==1?"SDc":"DX",p[2]>63?c=63:p[2]>>4==1&&(c=16),i=3;break}case 100:{a="AN",p[2]>63?c=63:p[2]>>4==1&&(c=16),i=3;break}case 104:case 105:case 106:case 107:{a="SDd",c=104;break}case 121:{a=`GM-${p[2]?"":"a"}`,i=3;break}case 122:{a="lDrm";break}case 126:{a="yDrS";break}case 127:{p[2]==127?a="rDrm":a="yDrm";break}default:p[0]<48?a="r:":a="M"}a.length<4&&(a+=`${[g,r,p[0],p[2]][i]-c}`.padStart(4-a.length,"0")),d=="xg"&&(g==0?p[2]<100?a=a.replace("y0","y:"):p[2]==125&&(a="y126"):g==16&&($=`Voice${(p[2]*128+p[1]+1).toString().padStart(3,"0")}`,m=" "));let n=[p[0],p[1],p[2]];for(;!(($==null?void 0:$.length)>=0);)$=t(this,z)[p[1]||0][(p[0]<<7)+p[2]],$||(this.strictMode?($="",m="?"):t(this,z)[p[1]||0][p[0]<<7]?p[0]==0?(p[2]=0,m="^"):p[2]<1?(p[0]=0,m="*"):(p[2]--,m="^"):g==48?(p[0]=0,p[2]=0,m="!"):g==62?(p[1]--,m=" ",p[1]<1&&!($!=null&&$.length)&&(p[0]=0,m="!")):g<63?p[0]==0?(p[2]=0,m="^"):p[2]<1?(p[0]=0,m="*"):p[2]--:g==80?($=`PrgU:${e.toString().padStart(3,"0")}`,m="!"):g==88?($=`CmbU:${e.toString().padStart(3,"0")}`,m="!"):g==121?($=`GM2Vox0${r}`,m="#"):g==122?(p[1]==32?p[1]==0:p[1]%=7,$=t(this,z)[p[1]||0][(p[0]<<7)+p[2]],$?m=" ":($="",m="*")):p[1]==0?($=`${g.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${r.toString().padStart(3,"0")}`,m="!"):p[0]==0?(p[2]=0,m="^"):p[2]>0?p[2]--:p[1]>0?(p[1]=0,m="!"):(p[0]=0,m="?"));let s=[p[0],p[1],p[2]];(d=="gs"||d=="ns5r")&&m=="^"&&(m=" "),g==127&&m=="^"&&(m=" "),m!=" "&&self.debugMode&&($="");let o="??";switch(p[0]){case 0:{p[2]==0?o="GM":p[2]==5||p[2]==7?o="KG":p[2]<126?o="XG":p[2]==127&&(o="MT");break}case 48:{o="MU";break}case 56:{o="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{o="AI";break}case 62:case 82:case 90:{o="XD";break}case 63:{p[2]<17?o="KR":p[2]<34?o="ES":o="DS";break}case 64:case 126:{o="XG";break}case 67:case 99:{o=p[2]>>4==1?"SD":"DX";break}case 81:{o="RW";break}case 95:{o=["DR","PC"][p[2]];break}case 96:{o=p[2]==106?"AP":p[2]>>4==1?"SD":"PF";break}case 97:{o=p[2]>>4==1?"SD":"VL";break}case 98:{o=p[2]>>4==1?"SD":"SG";break}case 100:{o="AN";break}case 104:case 105:case 106:case 107:{o="SD";break}case 120:{o="GS";break}case 121:{o=p[2]?"G2":"GM";break}case 122:{o="KG";break}case 127:{o=p[2]==127?"MT":e==0?"GM":"XG";break}default:p[0]<48&&(p[0]==16&&d=="xg"?o="XG":o="GS")}return{name:$||`${Ye(g||0)} ${Ye(e||0)} ${Ye(r||0)}`,iid:n,eid:s,sid:h,ending:m,sect:a,standard:o}}async load(g,e,r){let d=this,h=[],$=0,p=0;g.split(` +`).forEach(function(m,a){let i=m.split(" "),c=[];a==0?i.forEach(function(n,s){h[At.indexOf(n)]=s}):i.forEach(async function(n,s){var o;s>2?(t(d,z)[c[h[1]]]=t(d,z)[c[h[1]]]||[],(!((o=t(d,z)[c[h[1]]][(c[h[0]]<<7)+c[h[2]]])!=null&&o.length)||e)&&(t(d,z)[c[h[1]]][(c[h[0]]<<7)+c[h[2]]]=i[3],$++),p++):c.push(parseInt(i[s]))})}),e||console.debug(`Map "${r||"(internal)"}": ${p} total, ${$} loaded.`)}clearRange(g){let e=g.prg!=null?g.prg.constructor==Array?g.prg:[g.prg,g.prg]:[0,127],r=g.msb!=null?g.msb.constructor==Array?g.msb:[g.msb,g.msb]:[0,127],d=g.lsb!=null?g.lsb.constructor==Array?g.lsb:[g.lsb,g.lsb]:[0,127];for(let h=r[0];h<=r[1];h++){let $=h<<7;for(let p=d[0];p<=d[1];p++){let m=$+p;for(let a=e[0];a<=e[1];a++)delete t(this,z)[a][m]}}}init(){w(this,z,[]);for(let g=0;g<128;g++)t(this,z).push([""])}async loadFiles(...g){this.init();let e=this;g.forEach(async function(r,d){try{await fetch(`./data/bank/${r}.tsv`).then(function(h){return h.text()}).then(h=>{e.load(h,!1,r)})}catch(h){console.error(`Failed loading "${r}.tsv".`)}})}},z=new WeakMap,lt);var Ae,dt,ft=(dt=class{constructor(){k(this,Ae,{});T(this,"context")}set(g,e){t(this,Ae)[g]=e}has(g){return!!t(this,Ae)[g]}async read(g,e){if(!this.has(g))throw new Error(`No decoder registered for "${g}"`);return await t(this,Ae)[g].call(this.context||this,e)}},Ae=new WeakMap,dt);var Ut=function(g,e){let r=!0;return e.forEach((d,h)=>{r=r&&g[h]==d}),r},ht=function(g){let e=0;return g.forEach(r=>{e*=256,e+=r}),e},_e=new TextDecoder,Qe=new ft;Qe.set("s7e",async function(g){let e=new Uint8Array(await g.slice(0,65536).arrayBuffer()),r="MSB LSB PRG NME",d=[0,0,0,0],h=32,$=0,p=0,m=!0,a=[],i=0;for(;m;){let c=e.subarray($);([()=>{_e.decode(c.subarray(0,4))=="YSFC"?($+=80,p=1):$++},()=>{if(Ut(c.subarray(0,4),d))a.forEach((n,s,o)=>{let f=ht(e.subarray(n.start+4,n.start+8));n.length=f}),p=2;else{let n=_e.decode(c.subarray(0,4)),s=ht(c.subarray(4,8));a.push({type:n,start:s}),$+=8}},()=>{let n=a[i],s=e.subarray(n.start,n.start+n.length),o=32;switch(n.type){case"ENVC":{let f=h;for(;f=a.length&&(p=3,m=!1)}][p]||(()=>{m=!1}))()}return r});var Ie=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),Xe=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],Pt=[17.1,18.6,20.2,21.8,23.3,24.9,26.5,28,29.6,31.2,32.8,34.3,35.9,37.5,39,40.6,42.2,43.7,45.3,46.9,48.4,50],Ue=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],ut=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],pt=function(g){let e=.1,r=-.3;return g>66?(e=5,r=315):g>56?(e=1,r=47):g>46&&(e=.5,r=18.5),e*g-r},bt=function(g){return g>105?Pt[g-106]:g>100?g*1.1-100:g/10},yt=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),Je={};`hi*, ka,か ki,き ku,く @@ -139,7 +139,7 @@ o,お ~, ^, _,`.split(` -`).forEach(b=>{let e=b.split(",");Ye[e[0]]=e[1]});var gt=function(b){let e=b;b[0]=="*"&&(e=e.slice(1)),["aa","ii","uu","ee","oo"].forEach(f=>{for(;e.indexOf(f)>-1;)e=e.replace(f,f[0])});for(let f in Ye)e=e.replaceAll(f,Ye[f]);e.indexOf("ん")==0&&e.length>1&&(e=e.slice(1));let s=e.indexOf("!");return s>-1&&e.length>1&&(e=e.slice(s+1)),e},yt=function(b){return b?b<96?`cc${b}`:["aftertouch","velocity","pitch bend"][b-96]:"off"};var Je=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],$t=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],Et=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var At={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},Lt={66307:["drive"],66309:["vowel",b=>"aiueo"[b]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",b=>["off","LPF","HPF"][b]],94984:["noise type",b=>["white","pink"][b]],94987:["disc type",b=>["LP","SP","EP","RND"]],94990:["hum type",b=>`${b+5}0Hz`],94993:["M/S",b=>["mono","stereo"][b]]},Ze=function(b){return At[(b[0]-32<<8)+b[1]]||`0x${b[0].toString(16).padStart(2,"0")}${b[1].toString(16).padStart(2,"0")}`},mt=function(b,e,s){let f=(b[0]-32<<16)+(b[1]<<8)+e,d=Lt[f]||{},a=d[0];if(a!=null&&a.length)return a+=`: ${(d[1]||function(){})(s)||s}`,a},et=[68,48,95,78,41,3,110,122,0];var X=function(b=64){return Math.round(2e3*Math.log10(b/64))/100};var tt=function(b){let e=0;return b.forEach(s=>{e+=s,e=e&127}),~e+1&127},te=function(b,e){let s=0,f=0;for(let d=0;d>a&1)<<7,c=b[d];c+=r,d%8!=0?(e(c,s,b),s++):f=b[d]}},_e=function(b){let e=Math.floor(b*14.2);return e<128?e:0};var ne=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],wt=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],we=[120,127,120,127,120,127,61,62,62,105,120,122,122,127],Ht=[0,3,81,84,88],vt={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},at={0:0,1:1,2:3,5:4},kt=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],St=[36,37],qe=[20,21,22,23,24,25,26,28,29,30,31,36,37,64,65],Xe=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19],Nt=[12,13,16,17,18,19],Bt=[33,99,100,32,102,8,9,10],xt=[0,16,25,40,32,64,26,48],v={};ne.forEach((b,e)=>{v[b]=e});var p={length:Xe.length};Xe.forEach((b,e)=>{p[b]=e});var Mt={length:qe.length};qe.forEach((b,e)=>{Mt[b]=e});var F=function(){return!!self.Bun||self.debugMode||!1},Gt=function(b){let e=[],s=0;return b==null||b.forEach(function(f,d){f==247?e.push(b.subarray(s,d)):f==240&&(s=d+1)}),e.length||e.push(b.subarray(0)),F()&&console.debug(e),e};var y={ch:128,cc:Xe.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:qe.length,dnc:128,efx:7},T,K,ae,oe,Q,ce,Tt,U,H,C,u,le,R,P,q,A,N,pe,re,ve,x,Ue,Fe,se,be,J,Pe,ge,V,Ae,ye,j,O,ke,Le,He,ie,$e,Ne,Z,D,Ke,rt,z,fe,Ee,G,Se,L,Ve,Qe,xe,Ce,W,Y,he,Me,Te,Re,Ct,ka=(Ct=class extends ct{constructor(){super();m(this,Q);M(this,"NOTE_IDLE",0);M(this,"NOTE_ATTACK",1);M(this,"NOTE_DECAY",2);M(this,"NOTE_SUSTAIN",3);M(this,"NOTE_HELD",4);M(this,"NOTE_RELEASE",5);M(this,"NOTE_SOSTENUTO_ATTACK",8);M(this,"NOTE_SOSTENUTO_DECAY",9);M(this,"NOTE_SOSTENUTO_SUSTAIN",10);M(this,"NOTE_SOSTENUTO_HELD",11);M(this,"CH_MELODIC",0);M(this,"CH_DRUMS",1);M(this,"CH_DRUM1",2);M(this,"CH_DRUM2",3);M(this,"CH_DRUM3",4);M(this,"CH_DRUM4",5);M(this,"CH_DRUM5",6);M(this,"CH_DRUM6",7);M(this,"CH_DRUM7",8);M(this,"CH_DRUM8",9);m(this,T,0);m(this,K,0);m(this,ae,0);m(this,oe,new Array(11));m(this,U,new Uint8Array(y.ch));m(this,H,new Uint8Array(y.ch));m(this,C,new Uint8Array(y.ch));m(this,u,new Uint8Array(y.ch*y.cc));m(this,le,new Uint8Array(y.ace));m(this,R,new Uint8Array(y.ch));m(this,P,new Uint8Array(y.ch*y.nn));m(this,q,new Uint8Array(y.ch));m(this,A,new Uint16Array(y.pl));m(this,N,new Uint8Array(y.pl));m(this,pe,new Int16Array(y.ch));m(this,re,new Uint8Array(y.ch));m(this,ve,0);m(this,x,new Uint8Array(y.ch*y.rpn));m(this,Ue,new Int8Array(y.ch*St.length));m(this,Fe,new Uint8Array(y.drm*y.dpn*y.dnc));m(this,se,new Uint8Array(y.ch));m(this,be,new Uint8Array(128));m(this,J,new Uint8Array(y.cmt*8));m(this,Pe,new Uint8Array(1024));m(this,ge,new Uint8Array(y.cmt*64));m(this,V,new Uint8Array(y.efx*3));m(this,Ae,new Uint8Array(y.ch));m(this,ye,0);m(this,j,0);m(this,O,100);m(this,ke,0);m(this,Le,500);m(this,He,0);m(this,ie,"");m(this,$e,0);m(this,Ne,0);m(this,Z,!0);m(this,D,!1);m(this,Ke,void 0);m(this,rt,new Uint8Array(2));m(this,z,[]);m(this,fe,new Uint8Array(y.ch));m(this,Ee,new Uint8Array(y.tr));M(this,"baseBank",new We("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es"));M(this,"userBank",new We("gm"));M(this,"initOnReset",!1);M(this,"aiEfxName","");m(this,G,[]);m(this,Se,void 0);m(this,L,{nOff:(e,s)=>{let f=e*128+s,d=t(this,A).lastIndexOf(f);d>-1&&(t(this,u)[y.cc*e+p[64]]>63?(t(this,N)[d]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:s,velo:t(this,P)[f],state:this.NOTE_HELD})):t(this,u)[y.cc*e+p[66]]>63&&t(this,N)[d]==this.NOTE_SOSTENUTO_SUSTAIN?(t(this,N)[d]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:s,velo:t(this,P)[f],state:this.NOTE_SOSTENUTO_HELD})):(t(this,A)[d]=0,t(this,P)[f]=0,t(this,N)[d]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:s,velo:0,state:this.NOTE_IDLE})))},nOn:(e,s,f)=>{let d=e*128+s,a=0;for(t(this,q)[e]&&t(this,L).ano(e);t(this,N)[a]>0&&t(this,A)[a]!=d;)a++;a{},cAt:(e,s)=>{},hoOf:e=>{t(this,N).forEach((s,f)=>{if(s==this.NOTE_HELD){let d=t(this,A)[f],a=d>>7;e==a&&(t(this,N)[f]=this.NOTE_IDLE,t(this,A)[f]=0,t(this,P)[d]=0,this.dispatchEvent("note",{part:e,note:d&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,N).forEach((s,f)=>{let d;switch(s){case this.NOTE_ATTACK:{d=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{d=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{d=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(d){t(this,N)[f]=d;let a=t(this,A)[f];this.dispatchEvent("note",{part:e,note:a&127,velo:t(this,P)[a],state:d})}})},soOf:e=>{t(this,N).forEach((s,f)=>{if(s==this.NOTE_SOSTENUTO_HELD){let d=t(this,A)[f],a=d>>7;e==a&&(t(this,N)[f]=this.NOTE_IDLE,t(this,A)[f]=0,t(this,P)[d]=0,this.dispatchEvent("note",{part:e,note:d&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,A).forEach((s,f,d)=>{let a=s>>7,r=s&127;s==0&&t(this,P)[0]==0||a==e&&t(this,L).nOff(a,r)})}});m(this,Ve,{8:function(e){let s=e.channel,f=e.data[0];t(this,L).nOff(s,f)},9:function(e){let s=e.channel;t(this,U)[s]=1;let f=e.data[0],d=e.data[1];d>0?t(this,L).nOn(s,f,d):t(this,L).nOff(s,f)},10:function(e){let s=e.channel,f=s*128+e.data[0];t(this,A).indexOf(f)>-1&&(t(this,P)[f]=data[1],this.dispatchEvent("note",{part:s,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let s=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,T)){case v.s90es:case v.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&(t(this,U)[s]=1);break}e.data[1]&&(t(this,U)[s]=1);break}default:{t(this,U)[s]=1;break}}})();let f=s*y.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,L).ano(s),t(this,pe)[s]=0;let d=s*y.cc;t(this,u)[d+p[1]]=0,t(this,u)[d+p[5]]=0,t(this,u)[d+p[64]]=0,t(this,u)[d+p[65]]=0,t(this,u)[d+p[66]]=0,t(this,u)[d+p[67]]=0,t(this,u)[d+p[11]]=127,t(this,u)[d+p[101]]=127,t(this,u)[d+p[100]]=127,t(this,u)[d+p[99]]=127,t(this,u)[d+p[98]]=127;return}case 123:{t(this,L).ano(s);return}case 124:{t(this,L).ano(s);return}case 125:{t(this,L).ano(s);return}case 126:{t(this,q)[s]=1,t(this,L).ano(s);return}case 127:{t(this,q)[s]=0,t(this,L).ano(s);return}}if(p[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Nt.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(F()&&console.debug(`${ne[t(this,T)]}, CH${s+1}: ${e.data[1]}`),t(this,T)==0?e.data[1]<48?(t(this,C)[s]>0&&(e.data[1]=t(this,u)[f],e.data[1]=120,console.debug(`Forced channel ${s+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,T)==v.gs?e.data[1]<56&&t(this,C)[s]>0&&(e.data[1]=t(this,u)[f],e.data[1]=120,console.debug(`Forced channel ${s+1} to stay drums.`)):t(this,T)==v.gm?e.data[1]<48?t(this,C)[s]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${s+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):t(this,T)==v.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),t(this,T)){case v.xg:{[126,127].indexOf(e.data[1])>-1?t(this,C)[s]==0&&(this.setChType(s,this.CH_DRUM2),console.debug(`CH${s+1} set to drums by MSB.`)):t(this,C)[s]>0&&(this.setChType(s,this.CH_MELODIC),console.debug(`CH${s+1} set to melodic by MSB.`));break}case v["05rw"]:case v.x5d:case v.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(this,C)[s]==0&&(this.setChType(s,this.CH_DRUM2),console.debug(`CH${s+1} set to drums by MSB.`)):t(this,C)[s]>0&&(this.setChType(s,this.CH_MELODIC),console.debug(`CH${s+1} set to melodic by MSB.`));break}case v.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,C)[s]==0&&(this.setChType(s,this.CH_DRUM2),console.debug(`CH${s+1} set to drums by MSB.`)):t(this,C)[s]>0&&(this.setChType(s,this.CH_MELODIC),console.debug(`CH${s+1} set to melodic by MSB.`));break}case v.g2:{e.data[1]==120?t(this,C)[s]==0&&(this.setChType(s,this.CH_DRUMS),console.debug(`CH${s+1} set to drums by MSB.`)):t(this,C)[s]>0&&(this.setChType(s,this.CH_MELODIC),console.debug(`CH${s+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:s});break}case 6:{if(t(this,ve)){[v.xg,v.gs,v.ns5r].indexOf(t(this,T))<0&&console.warn(`NRPN commits are not available under "${ne[t(this,T)]}" mode, even when they are supported in Octavia.`);let d=t(this,u)[f+p[99]],a=t(this,u)[f+p[98]];if(d==1){let r=Bt.indexOf(a);if(r>-1)t(this,u)[f+p[71+r]]=e.data[1],F()&&console.debug(`Redirected NRPN 1 ${a} to cc${71+r}.`),this.dispatchEvent("cc",{part:s,cc:71+r,data:e.data[1]});else{let c=St.indexOf(a);c>-1?t(this,Ue)[s*10+c]=e.data[1]-64:console.warn(`NRPN 0x01${a.toString(16).padStart(2,"0")} is not supported.`),F()&&console.debug(`CH${s+1} voice NRPN ${a} commit`)}}else{if(qe.indexOf(d)<0){let c=`NRPN 0x${d.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")} `;d==127?console.warn(`${c}is not necessary. Consider removing it.`):console.warn(`${c}is not supported.`)}else{let c=t(this,C)[s]-2;c<0?console.warn(`CH${s+1} cannot accept drum NRPN as type ${Ie[t(this,C)[s]]}.`):t(this,Fe)[(c*y.dpn+Mt[d])*y.dnc+a]=e.data[1]-64}F()&&console.debug(`CH${s+1} (${Ie[t(this,C)[s]]}) drum NRPN ${d} commit`)}}else{let d=at[t(this,u)[f+p[100]]];t(this,u)[f+p[101]]==0&&d!=null&&(F()&&console.debug(`CH${s+1} RPN 0 ${t(this,u)[f+p[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],kt[d][0]),kt[d][1]),t(this,x)[s*y.rpn+d]=e.data[1])}break}case 32:{switch(F()&&console.debug(`${ne[t(this,T)]}, CH${s+1} LSB: ${e.data[1]}`),t(this,T)){case v.s90es:case v.motif:{this.setChType(s,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,T),!0);break}}this.dispatchEvent("voice",{part:s});break}case 38:{t(this,ve)||t(this,u)[f+101]==0&&at[t(this,u)[f+100]]!=null&&(t(this,x)[s*y.rpn+at[t(this,u)[f+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&t(this,L).hoOf(s);break}case 66:{e.data[1]>>6?t(this,L).soOn(s):t(this,L).soOf(s);break}case 98:case 99:{E(this,ve,1);break}case 100:case 101:{E(this,ve,0);break}}t(this,u)[f+p[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:s,cc:e.data[0],data:e.data[1]})}},12:function(e){let s=e.channel;switch(t(this,T)){case v.s90es:case v.motif:{e.data&&(t(this,U)[s]=1);break}default:t(this,U)[s]=1}t(this,R)[s]=e.data,t(this,se)[s]=0,F()&&console.debug(`T:${e.track} C:${s} P:${e.data}`),this.dispatchEvent("voice",{part:s})},13:function(e){let s=this,f=e.channel;t(this,A).forEach(function(d){let a=d>>7;f==a&&(t(s,P)[d]=e.data,s.dispatchEvent("note",{part:f,note:d&127,velo:e.data,state:s.NOTE_SUSTAIN}))})},14:function(e){let s=e.channel;t(this,pe)[s]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:s,pitch:this.getPitchShift(s)})},15:function(e){Gt(e.data).forEach(s=>{let f=s[0],d=s[1];(t(this,Qe)[f]||function(){console.debug(`Unknown manufacturer ${f}.`)})(d,s.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(t(this,G)[e.meta]||function(f,d,a){}).call(this,e.data,e.track,e.meta),e.meta!=32&&E(this,ke,0);let s=Ht.indexOf(e.meta)>-1;if(F()&&console.debug(e),s)return e.reply="meta",e}});m(this,Qe,{64:(e,s,f)=>{t(this,Me).run(s,f,e)},65:(e,s,f)=>{if(s[0]<16)if(s[1]==72){let d=s[s.length-1],a=tt(s.subarray(3,s.length-1));d==a?t(this,Y).run(s.subarray(0,s.length-1),f,e):console.warn(`Bad SD checksum ${d}. Should be ${a}.`)}else t(this,Y).run(s,f,e);else{let d=s[s.length-1],a=tt(s.subarray(2,s.length-1));d==a?t(this,Y).run(s.subarray(0,s.length-1),f,e):console.warn(`Bad GS checksum ${d}. Should be ${a}.`)}},66:(e,s,f)=>{t(this,he).run(s,f,e)},67:(e,s,f)=>{t(this,W).run(s,f,e)},68:(e,s,f)=>{t(this,Re).run(s,f,e)},71:(e,s,f)=>{t(this,Te).run(s,f,e)},126:(e,s,f)=>{t(this,xe).run(s,f,e)},127:(e,s,f)=>{this.switchMode("gm"),t(this,Ce).run(s,f,e)}});m(this,xe,void 0);m(this,Ce,void 0);m(this,W,void 0);m(this,Y,void 0);m(this,he,void 0);m(this,Me,void 0);m(this,Te,void 0);m(this,Re,void 0);let e=this;E(this,Q,new Uint8Array(256),Tt),t(this,oe)[10]=new Uint8Array(512),E(this,Se,new ee),this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(g=>{let e=g.split(",");Je[e[0]]=e[1]});var gt=function(g){let e=g;g[0]=="*"&&(e=e.slice(1)),["aa","ii","uu","ee","oo"].forEach(d=>{for(;e.indexOf(d)>-1;)e=e.replace(d,d[0])});for(let d in Je)e=e.replaceAll(d,Je[d]);e.indexOf("ん")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},$t=function(g){return g?g<96?`cc${g}`:["aftertouch","velocity","pitch bend"][g-96]:"off"};var Ze=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],Et=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],mt=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var Lt={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},Ht={66307:["drive"],66309:["vowel",g=>"aiueo"[g]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",g=>["off","LPF","HPF"][g]],94984:["noise type",g=>["white","pink"][g]],94987:["disc type",g=>["LP","SP","EP","RND"]],94990:["hum type",g=>`${g+5}0Hz`],94993:["M/S",g=>["mono","stereo"][g]]},et=function(g){return Lt[(g[0]-32<<8)+g[1]]||`0x${g[0].toString(16).padStart(2,"0")}${g[1].toString(16).padStart(2,"0")}`},vt=function(g,e,r){let d=(g[0]-32<<16)+(g[1]<<8)+e,h=Ht[d]||{},$=h[0];if($!=null&&$.length)return $+=`: ${(h[1]||function(){})(r)||r}`,$},tt=[68,48,95,78,41,3,110,122,0];var Q=function(g=64){return Math.round(2e3*Math.log10(g/64))/100};var at=function(g){let e=0;return g.forEach(r=>{e+=r,e=e&127}),~e+1&127},ie=function(g,e){let r=0,d=0;for(let h=0;h>$&1)<<7,m=g[h];m+=p,h%8!=0?(e(m,r,g),r++):d=g[h]}},Fe=function(g){let e=Math.floor(g*14.2);return e<128?e:0};var le=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],wt=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],ke=[120,127,120,127,120,127,61,62,62,105,120,122,122,127],Nt=[0,3,81,84,88],kt={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},rt={0:0,1:1,2:3,5:4},St=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Ct=[36,37,48,49,52,53],We=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],xt={26:127,29:0,30:0,31:0,52:12,53:54},Ve=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19],Bt=[12,13,16,17,18,19],Gt=[33,99,100,32,102,8,9,10],Mt=[0,16,25,40,32,64,26,48],C={};le.forEach((g,e)=>{C[g]=e});var y={length:Ve.length};Ve.forEach((g,e)=>{y[g]=e});var te={length:We.length};We.forEach((g,e)=>{te[g]=e});var A=function(){return!!self.Bun||self.debugMode||!1},_t=function(g){let e=[],r=0;return g==null||g.forEach(function(d,h){d==247?e.push(g.subarray(r,h)):d==240&&(r=h+1)}),e.length||e.push(g.subarray(0)),A()&&console.debug(e),e};var E={ch:128,cc:Ve.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:We.length,dnc:128,efx:7},O,F,ne,fe,Y,de,Rt,he,G,M,u,ue,D,H,j,N,_,ye,ce,Se,x,Pe,V,oe,ge,ae,Le,$e,q,He,Ee,J,U,Ce,Ne,Be,me,ve,Ge,re,P,Ke,st,W,pe,we,I,xe,B,ze,qe,Me,Te,Z,ee,be,Re,Oe,De,Tt,Sa=(Tt=class extends ot{constructor(){super();k(this,Y);T(this,"NOTE_IDLE",0);T(this,"NOTE_ATTACK",1);T(this,"NOTE_DECAY",2);T(this,"NOTE_SUSTAIN",3);T(this,"NOTE_HELD",4);T(this,"NOTE_RELEASE",5);T(this,"NOTE_SOSTENUTO_ATTACK",8);T(this,"NOTE_SOSTENUTO_DECAY",9);T(this,"NOTE_SOSTENUTO_SUSTAIN",10);T(this,"NOTE_SOSTENUTO_HELD",11);T(this,"CH_MELODIC",0);T(this,"CH_DRUMS",1);T(this,"CH_DRUM1",2);T(this,"CH_DRUM2",3);T(this,"CH_DRUM3",4);T(this,"CH_DRUM4",5);T(this,"CH_DRUM5",6);T(this,"CH_DRUM6",7);T(this,"CH_DRUM7",8);T(this,"CH_DRUM8",9);k(this,O,0);k(this,F,0);k(this,ne,0);k(this,fe,new Array(11));k(this,he,new Uint8Array(E.ch));k(this,G,new Uint8Array(E.ch));k(this,M,new Uint8Array(E.ch));k(this,u,new Uint8Array(E.ch*E.cc));k(this,ue,new Uint8Array(E.ace));k(this,D,new Uint8Array(E.ch));k(this,H,new Uint8Array(E.ch*E.nn));k(this,j,new Uint8Array(E.ch));k(this,N,new Uint16Array(E.pl));k(this,_,new Uint8Array(E.pl));k(this,ye,new Int16Array(E.ch));k(this,ce,new Uint8Array(E.ch));k(this,Se,0);k(this,x,new Uint8Array(E.ch*E.rpn));k(this,Pe,new Int8Array(E.ch*Ct.length));k(this,V,new Uint8Array(E.drm*E.dpn*E.dnc));k(this,oe,new Uint8Array(E.ch));k(this,ge,new Uint8Array(128));k(this,ae,new Uint8Array(E.cmt*8));k(this,Le,new Uint8Array(1024));k(this,$e,new Uint8Array(E.cmt*64));k(this,q,new Uint8Array(E.efx*3));k(this,He,new Uint8Array(E.ch));k(this,Ee,0);k(this,J,0);k(this,U,100);k(this,Ce,0);k(this,Ne,500);k(this,Be,0);k(this,me,"");k(this,ve,0);k(this,Ge,0);k(this,re,!0);k(this,P,!1);k(this,Ke,void 0);k(this,st,new Uint8Array(2));k(this,W,[]);k(this,pe,new Uint8Array(E.ch));k(this,we,new Uint8Array(E.tr));T(this,"baseBank",new je("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es"));T(this,"userBank",new je("gm"));T(this,"initOnReset",!1);T(this,"aiEfxName","");k(this,I,[]);k(this,xe,void 0);k(this,B,{nOff:(e,r)=>{let d=e*128+r,h=t(this,N).lastIndexOf(d);h>-1&&(t(this,u)[E.cc*e+y[64]]>63?(t(this,_)[h]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,H)[d],state:this.NOTE_HELD})):t(this,u)[E.cc*e+y[66]]>63&&t(this,_)[h]==this.NOTE_SOSTENUTO_SUSTAIN?(t(this,_)[h]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,H)[d],state:this.NOTE_SOSTENUTO_HELD})):(t(this,N)[h]=0,t(this,H)[d]=0,t(this,_)[h]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})))},nOn:(e,r,d)=>{let h=e*128+r,$=0;for(t(this,j)[e]&&t(this,B).ano(e);t(this,_)[$]>0&&t(this,N)[$]!=h;)$++;${},cAt:(e,r)=>{},hoOf:e=>{t(this,_).forEach((r,d)=>{if(r==this.NOTE_HELD){let h=t(this,N)[d],$=h>>7;e==$&&(t(this,_)[d]=this.NOTE_IDLE,t(this,N)[d]=0,t(this,H)[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,_).forEach((r,d)=>{let h;switch(r){case this.NOTE_ATTACK:{h=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{h=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{h=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(h){t(this,_)[d]=h;let $=t(this,N)[d];this.dispatchEvent("note",{part:e,note:$&127,velo:t(this,H)[$],state:h})}})},soOf:e=>{t(this,_).forEach((r,d)=>{if(r==this.NOTE_SOSTENUTO_HELD){let h=t(this,N)[d],$=h>>7;e==$&&(t(this,_)[d]=this.NOTE_IDLE,t(this,N)[d]=0,t(this,H)[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,N).forEach((r,d,h)=>{let $=r>>7,p=r&127;r==0&&t(this,H)[0]==0||$==e&&t(this,B).nOff($,p)})}});k(this,ze,{8:function(e){let r=e.channel,d=e.data[0];t(this,B).nOff(r,d)},9:function(e){let r=e.channel;this.setChActive(r,1);let d=e.data[0],h=e.data[1];h>0?t(this,B).nOn(r,d,h):t(this,B).nOff(r,d)},10:function(e){let r=e.channel,d=r*128+e.data[0];t(this,N).indexOf(d)>-1&&(t(this,H)[d]=data[1],this.dispatchEvent("note",{part:r,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let r=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,O)){case C.s90es:case C.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(r,1);break}e.data[1]&&this.setChActive(r,1);break}default:{this.setChActive(r,1);break}}})();let d=r*E.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,B).ano(r),t(this,ye)[r]=0;let h=r*E.cc;t(this,u)[h+y[1]]=0,t(this,u)[h+y[5]]=0,t(this,u)[h+y[64]]=0,t(this,u)[h+y[65]]=0,t(this,u)[h+y[66]]=0,t(this,u)[h+y[67]]=0,t(this,u)[h+y[11]]=127,t(this,u)[h+y[101]]=127,t(this,u)[h+y[100]]=127,t(this,u)[h+y[99]]=127,t(this,u)[h+y[98]]=127;return}case 123:{t(this,B).ano(r);return}case 124:{t(this,B).ano(r);return}case 125:{t(this,B).ano(r);return}case 126:{t(this,j)[r]=1,t(this,B).ano(r);return}case 127:{t(this,j)[r]=0,t(this,B).ano(r);return}}if(y[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Bt.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(A()&&console.debug(`${le[t(this,O)]}, CH${r+1}: ${e.data[1]}`),t(this,O)==0?e.data[1]<48?(t(this,M)[r]>0&&(e.data[1]=t(this,u)[d],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,O)==C.gs?e.data[1]<56&&t(this,M)[r]>0&&(e.data[1]=t(this,u)[d],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):t(this,O)==C.gm?e.data[1]<48?t(this,M)[r]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${r+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):t(this,O)==C.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),t(this,O)){case C.xg:{[126,127].indexOf(e.data[1])>-1?t(this,M)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,M)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case C["05rw"]:case C.x5d:case C.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(this,M)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,M)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case C.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,M)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,M)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case C.g2:{e.data[1]==120?t(this,M)[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,M)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:r});break}case 6:{if(t(this,Se)){[C.xg,C.gs,C.ns5r].indexOf(t(this,O))<0&&console.warn(`NRPN commits are not available under "${le[t(this,O)]}" mode, even when they are supported in Octavia.`);let h=t(this,u)[d+y[99]],$=t(this,u)[d+y[98]];if(h==1){let p=Gt.indexOf($);if(p>-1)t(this,u)[d+y[71+p]]=e.data[1],A()&&console.debug(`Redirected NRPN 1 ${$} to cc${71+p}.`),this.dispatchEvent("cc",{part:r,cc:71+p,data:e.data[1]});else{let m=Ct.indexOf($);m>-1?t(this,Pe)[r*10+m]=e.data[1]-64:console.warn(`NRPN 0x01${$.toString(16).padStart(2,"0")} is not supported.`),A()&&console.debug(`CH${r+1} voice NRPN ${$} commit`)}}else{if(We.indexOf(h)<0){let m=`NRPN 0x${h.toString(16).padStart(2,"0")}${$.toString(16).padStart(2,"0")} `;h==127?console.warn(`${m}is not necessary. Consider removing it.`):console.warn(`${m}is not supported.`)}else{let m=t(this,M)[r]-2;m<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${Xe[t(this,M)[r]]}.`):t(this,V)[(m*E.dpn+te[h])*E.dnc+$]=e.data[1]}A()&&console.debug(`CH${r+1} (${Xe[t(this,M)[r]]}) drum NRPN ${h} commit`)}}else{let h=rt[t(this,u)[d+y[100]]];t(this,u)[d+y[101]]==0&&h!=null&&(A()&&console.debug(`CH${r+1} RPN 0 ${t(this,u)[d+y[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],St[h][0]),St[h][1]),t(this,x)[r*E.rpn+h]=e.data[1])}break}case 32:{switch(A()&&console.debug(`${le[t(this,O)]}, CH${r+1} LSB: ${e.data[1]}`),t(this,O)){case C.s90es:case C.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,O),!0);break}}this.dispatchEvent("voice",{part:r});break}case 38:{t(this,Se)||t(this,u)[d+101]==0&&rt[t(this,u)[d+100]]!=null&&(t(this,x)[r*E.rpn+rt[t(this,u)[d+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&t(this,B).hoOf(r);break}case 66:{e.data[1]>>6?t(this,B).soOn(r):t(this,B).soOf(r);break}case 98:case 99:{w(this,Se,1);break}case 100:case 101:{w(this,Se,0);break}}t(this,u)[d+y[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:r,cc:e.data[0],data:e.data[1]})}},12:function(e){let r=e.channel;switch(t(this,O)){case C.s90es:case C.motif:{e.data&&this.setChActive(r,1);break}default:this.setChActive(r,1)}t(this,D)[r]=e.data,t(this,oe)[r]=0,A()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),this.dispatchEvent("voice",{part:r})},13:function(e){let r=this,d=e.channel;t(this,N).forEach(function(h){let $=h>>7;d==$&&(t(r,H)[h]=e.data,r.dispatchEvent("note",{part:d,note:h&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;t(this,ye)[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){_t(e.data).forEach(r=>{let d=r[0],h=r[1];(t(this,qe)[d]||function(){console.debug(`Unknown manufacturer ${d}.`)})(h,r.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(t(this,I)[e.meta]||function(d,h,$){}).call(this,e.data,e.track,e.meta),e.meta!=32&&w(this,Ce,0);let r=Nt.indexOf(e.meta)>-1;if(A()&&console.debug(e),r)return e.reply="meta",e}});k(this,qe,{64:(e,r,d)=>{t(this,Re).run(r,d,e)},65:(e,r,d)=>{if(r[0]<16)if(r[1]==72){let h=r[r.length-1],$=at(r.subarray(3,r.length-1));h==$?t(this,ee).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad SD checksum ${h}. Should be ${$}.`)}else t(this,ee).run(r,d,e);else{let h=r[r.length-1],$=at(r.subarray(2,r.length-1));h==$?t(this,ee).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad GS checksum ${h}. Should be ${$}.`)}},66:(e,r,d)=>{t(this,be).run(r,d,e)},67:(e,r,d)=>{t(this,Z).run(r,d,e)},68:(e,r,d)=>{t(this,De).run(r,d,e)},71:(e,r,d)=>{t(this,Oe).run(r,d,e)},126:(e,r,d)=>{t(this,Me).run(r,d,e)},127:(e,r,d)=>{this.switchMode("gm"),t(this,Te).run(r,d,e)}});k(this,Me,void 0);k(this,Te,void 0);k(this,Z,void 0);k(this,ee,void 0);k(this,be,void 0);k(this,Re,void 0);k(this,Oe,void 0);k(this,De,void 0);let e=this;w(this,Y,new Uint8Array(256),Rt),t(this,fe)[10]=new Uint8Array(512),w(this,xe,new se),this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -147,19 +147,19 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),this.addEventListener("metacommit",function(a){var c,n;let{data:r}=a;((c=t(e,z)[0])==null?void 0:c.type)==r.type&&((n=t(e,z)[0])!=null&&n.amend)?(t(e,z)[0].amend=r.amend,t(e,z)[0].data+=r.data):t(e,z).unshift(r)}),t(this,G)[1]=function(a){var r,c,n,i,o;switch(a=a.replaceAll(`\r +122 006 000 `),this.addEventListener("metacommit",function(a){var c,n;let{data:i}=a;((c=t(e,W)[0])==null?void 0:c.type)==i.type&&((n=t(e,W)[0])!=null&&n.amend)?(t(e,W)[0].amend=i.amend,t(e,W)[0].data+=i.data):t(e,W).unshift(i)}),t(this,I)[1]=function(a){var i,c,n,s,o;switch(a=a.replaceAll(`\r `,` `).replaceAll("\r",` -`),a.slice(0,2)){case"@I":{E(this,D,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(r=a.slice(2))==null?void 0:r.trimLeft()});break}case"@K":{E(this,D,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(c=a.slice(2))==null?void 0:c.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{E(this,D,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(n=a.slice(2))==null?void 0:n.trimLeft()});break}case"@T":{E(this,D,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(i=a.slice(2))==null?void 0:i.trimLeft()});break}case"@V":{E(this,D,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(o=a.slice(2))==null?void 0:o.trimLeft()});break}case"XF":{let h=a.slice(2).split(":");switch(h[0]){case"hd":{h.slice(1).forEach((l,g)=>{l.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][g],data:l})});break}case"ln":{h.slice(1).forEach((l,g)=>{l.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][g],data:l})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:t(this,D)?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` -`).forEach((h,l)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:h,mask:l!=0})})}},t(this,G)[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},t(this,G)[3]=function(a,r){r<1&&t(this,ke)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},t(this,G)[4]=function(a,r){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},t(this,G)[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},t(this,G)[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},t(this,G)[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},t(this,G)[32]=function(a){E(this,ke,a[0]+1)},t(this,G)[33]=function(a,r){t(e,Ee)[r]=a+1},t(this,G)[81]=function(a,r){E(e,Le,a/1e3)},t(this,G)[127]=function(a,r){t(e,Se).run(a,r)},t(this,Se).default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},t(this,Se).add([67,0,1],function(a,r){t(e,Ee)[r]=a[0]+1}),E(this,xe,new ee("universal non-realtime")),E(this,Ce,new ee("universal realtime")),E(this,W,new ee("Yamaha")),E(this,Y,new ee("Roland")),E(this,he,new ee("Korg")),E(this,Me,new ee("Kawai")),E(this,Te,new ee("Akai")),E(this,Re,new ee("Casio"));let s=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,a)};t(this,xe).default=s,t(this,Ce).default=s,t(this,W).default=s,t(this,Y).default=s,t(this,he).default=s,t(this,Me).default=s,t(this,Te).default=s,t(this,Re).default=s,t(this,xe).add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),E(e,D,t(e,D)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),t(this,Ce).add([4,1],a=>{E(e,O,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,O))}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64),t(this,W).add([76,0,0],a=>{switch(a[0]){case 125:{console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),E(e,D,!1),console.info("MIDI reset: XG");break}default:{let r=[0,0,0,0],c=(n,i)=>{r[i]=n};if(a.subarray(1).forEach((n,i)=>{let o=i+a[0];([c,c,c,c,h=>{E(this,O,h*129/16383*100),e.dispatchEvent("mastervolume",t(e,O))},h=>{},h=>{}][o]||(()=>{}))(n,i)}),a[0]<4){let n=0;r.forEach(i=>{n=n<<4,n+=i}),n-=1024}}}}).add([76,2,1],a=>{let r="XG ";a[0]<32?(r+="reverb ",a.subarray(1).forEach((c,n)=>{([i=>{e.setEffectTypeRaw(0,!1,i),console.info(`${r}main type: ${Ge[i]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},i=>{e.setEffectTypeRaw(0,!0,i),console.debug(`${r}sub type: ${i+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},i=>{console.debug(`${r}time: ${ut(i)}s`)},i=>{console.debug(`${r}diffusion: ${i}`)},i=>{console.debug(`${r}initial delay: ${i}`)},i=>{console.debug(`${r}HPF cutoff: ${De[i]}Hz`)},i=>{console.debug(`${r}LPF cutoff: ${De[i]}Hz`)},i=>{console.debug(`${r}width: ${i}`)},i=>{console.debug(`${r}height: ${i}`)},i=>{console.debug(`${r}depth: ${i}`)},i=>{console.debug(`${r}wall type: ${i}`)},i=>{console.debug(`${r}dry/wet: ${i}`)},i=>{console.debug(`${r}send: ${X(i)}dB`)},i=>{console.debug(`${r}pan: ${i-64}`)},!1,!1,i=>{console.debug(`${r}delay: ${i}`)},i=>{console.debug(`${r}density: ${i}`)},i=>{console.debug(`${r}balance: ${i}`)},i=>{},i=>{console.debug(`${r}feedback: ${i}`)},i=>{}][a[0]+n]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(c)})):a[0]<64?(r+="chorus ",a.subarray(1).forEach((c,n)=>{([i=>{e.setEffectTypeRaw(1,!1,i),console.info(`${r}main type: ${Ge[i]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},i=>{e.setEffectTypeRaw(1,!0,i),console.debug(`${r}sub type: ${i+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},i=>{console.debug(`${r}LFO: ${dt[i]}Hz`)},i=>{},i=>{console.debug(`${r}feedback: ${i}`)},i=>{console.debug(`${r}delay offset: ${pt(i)}ms`)},i=>{},i=>{console.debug(`${r}low: ${De[i]}Hz`)},i=>{console.debug(`${r}low: ${i-64}dB`)},i=>{console.debug(`${r}high: ${De[i]}Hz`)},i=>{console.debug(`${r}high: ${i-64}dB`)},i=>{console.debug(`${r}dry/wet: ${i}`)},i=>{console.debug(`${r}send: ${X(i)}dB`)},i=>{console.debug(`${r}pan: ${i-64}`)},i=>{console.debug(`${r}to reverb: ${X(i)}dB`)},!1,i=>{},i=>{},i=>{},i=>{console.debug(`${r}LFO phase diff: ${(i-64)*3}deg`)},i=>{console.debug(`${r}input mode: ${i?"stereo":"mono"}`)},i=>{}][a[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(c)})):a[0]<86?(r+="variation ",a.subarray(1).forEach((c,n)=>{([i=>{e.setEffectTypeRaw(2,!1,i),console.info(`${r}main type: ${Ge[i]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},i=>{e.setEffectTypeRaw(2,!0,i),console.debug(`${r}sub type: ${i+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+n]||function(){})(c)})):a[0]<97?(r+="variation ",a.subarray(1).forEach((c,n)=>{[i=>{console.debug(`${r}send: ${X(i)}dB`)},i=>{console.debug(`${r}pan: ${i-64}`)},i=>{console.debug(`${r}to reverb: ${X(i)}dB`)},i=>{console.debug(`${r}to chorus: ${X(i)}dB`)},i=>{console.debug(`${r}connection: ${i?"system":"insertion"}`)},i=>{console.debug(`${r}channel: CH${i+1}`)},i=>{console.debug(`${r}mod wheel: ${i-64}`)},i=>{console.debug(`${r}bend wheel: ${i-64}`)},i=>{console.debug(`${r}channel after touch: ${i-64}`)},i=>{console.debug(`${r}AC1: ${i-64}`)},i=>{console.debug(`${r}AC2: ${i-64}`)}][a[0]-86+n](c)})):a[0]>111&&a[0]<118?r+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((r,c)=>{let n=c+a[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][r]}`);else{let i=n-1>>2,o=n-1&3,h=`XG EQ ${i} ${["gain","freq","Q","shape"][o]}: `;[()=>{console.debug(`${h}${r-64}dB`)},()=>{console.debug(`${h}${r} (raw)`)},()=>{console.debug(`${h}${r/10}`)},()=>{console.debug(`${h}${["shelf","peak"][+!!r]}`)}][o]()}})}).add([76,3],a=>{let r=a[0],c=a[1],n=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((i,o)=>{([h=>{e.setEffectTypeRaw(3+r,!1,h),console.info(`${n}main type: ${Ge[h]}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))},h=>{e.setEffectTypeRaw(3+r,!0,h),console.debug(`${n}sub type: ${h+1}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))}][c+o]||function(){})(i)})}).add([76,6,0],a=>{let r=a[0];r<64?e.setLetterDisplay(a.subarray(1),"XG letter display",r):E(e,$e,Date.now())}).add([76,7,0],a=>{let r=a[0];E(e,K,0),E(e,ae,Date.now()+3200),t(e,Q,ce).fill(0);let c=a.subarray(1);for(let n=0;n>6-$&1,$++})}).add([76,8],(a,r)=>{let c=e.chRedir(a[0],r,!0),n=a[1],i=y.cc*c,o=`XG CH${c+1} `,h=`Unknown XG part address ${n}.`;a.subarray(2).forEach((l,g)=>{n<1?console.debug(h):n<41?([()=>{t(e,u)[i+p[0]]=l},()=>{t(e,u)[i+p[32]]=l},()=>{t(e,R)[c]=l},()=>{let $=e.chRedir(l,r,!0);t(e,H)[c]=$,c!=$&&(e.buildRchTree(),console.info(`${o}receives from CH${$+1}`))},()=>{t(e,q)[c]=+!l},()=>{},()=>{e.setChType(c,l,v.xg),console.debug(`${o}type: ${Ie[l]||l}`)},()=>{t(e,x)[y.rpn*c+3]=l},!1,!1,()=>{t(e,u)[i+p[7]]=l},!1,!1,()=>{t(e,u)[i+p[10]]=l||128},!1,!1,()=>{t(e,u)[i+p[128]]=l},()=>{t(e,u)[i+p[93]]=l},()=>{t(e,u)[i+p[91]]=l},()=>{t(e,u)[i+p[94]]=l},()=>{t(e,u)[i+p[76]]=l},()=>{t(e,u)[i+p[77]]=l},()=>{t(e,u)[i+p[78]]=l},()=>{t(e,u)[i+p[74]]=l},()=>{t(e,u)[i+p[71]]=l},()=>{t(e,u)[i+p[73]]=l},()=>{t(e,u)[i+p[75]]=l},()=>{t(e,u)[i+p[72]]=l}][n+g-1]||(()=>{}))():n<48?console.debug(h):n<111?n>102&&n<105&&(t(e,u)[i+p[[5,65][n&1]]]=l):n<114?console.debug(h):n<116?console.debug(`${o}EQ ${["bass","treble"][n&1]} gain: ${l-64}dB`):n<118?console.debug(h):n<120?console.debug(`${o}EQ ${["bass","treble"][n&1]} freq: ${l}`):console.debug(h)})}).add([76,9],(a,r)=>{let c=e.chRedir(a[0],r,!0),n=a[1],i=`PLG-150VL CH${c+1} `;a.subarray(2).forEach((o,h)=>{let l=h+n;switch(l){case 1:{console.info(`${i}breath mode: ${["system","breath","velocity","touch EG"][o]}`);break}case 0:case 27:case 28:break;default:if(l<27){let g=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${i}${g} control source: ${yt(o)}`),o&&o<96&&e.allocateAce(o)):console.debug(`${i}${g} scale break point: ${o}`):console.debug(`${i}${g} depth: ${o-64}`)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][a[0]]} for CH${a[2]+1}.`)}).add([73,0,0],(a,r)=>{let c=a[0],n="MU1000 System: ";a.subarray(1).forEach((i,o)=>{let h=c+o;h==8?console.debug(`${n}LCD contrast set to ${i}.`):h==18?(E(e,j,i?126:0),console.debug(`${n}bank defaults to ${i?"MU100 Native":"MU Basic"}.`)):h>=64&&h<69&&[()=>{e.dispatchEvent("channelactive",i)},()=>{i<8?(e.dispatchEvent("channelmin",i<<4),console.debug(`Octavia System: Minimum CH${(i<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{i<8?(e.dispatchEvent("channelmax",(i<<4)+15),console.debug(`Octavia System: Maximum CH${(i<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{E(e,Z,!!i),console.info(`Octavia System: RS receiving ${["dis","en"][i]}abled.`)}][h-64]()})}).add([73,10,0],(a,r)=>{let c=a[0],n=`MU1000 RS${t(e,Z)?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let i=e.chRedir(0,r,!0);t(e,Z)&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+63)),console.info(`${n}Show CH1~64`);break}case 3:{let i=e.chRedir(a[1]<<5,r,!0);t(e,Z)&&e.dispatchEvent("channelmin",i),t(e,Z)&&e.dispatchEvent("channelmax",i+31),console.info(`${n}Show CH${i+1}~CH${i+32}`);break}default:console.debug(`${n}unknown switch ${c} invoked.`)}else if(c<32){if(t(e,Z)){let i=e.chRedir(c-16+(t(e,Ne)<<4),r,!0);e.dispatchEvent("channelactive",i)}}else if(c<36){let i=e.chRedir(c-32<<4,r,!0);t(e,Z)&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+15),E(e,Ne,c-32)),console.info(`${n}Show CH${i+1}~CH${i+16}`)}}).add([93,3],(a,r)=>{let c=e.chRedir(a[0],r,!0),n=`PLG-100SG CH${c+1} `,i=Date.now();if(a[1]==0){let o="",h=0;a.subarray(2).forEach((l,g)=>{g%2==0?o+=bt[l]||l.toString().padStart("0"):h+=l*13}),i>=t(e,He)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${gt(o)}`,amend:!0}),E(e,He,i+Math.ceil(h/2)+t(e,Le)),F()&&console.debug(`${n}vocals: ${o}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)}),t(this,W).add([76,48],a=>{}).add([76,49],a=>{}).add([76,50],a=>{}).add([76,51],a=>{}),t(this,W).add([89,0],(a,r,c)=>{if(e.eprom){let n=a[0],i=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);F()&&console.debug(`MU1000 EPROM trail to 0x${i.toString(16).padStart(6,"0")}, ${n} bytes.`);let o=e.eprom.data;a.subarray(4).forEach((h,l)=>{let g=l>>3,$=l&7;if($==7)for(let w=0;w<7;w++)o[i+7*g+w]+=(h>>6-w&1)<<7;else o[i+7*g+$]=h})}}).add([89,1],(a,r,c)=>{let n=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];F()&&console.debug(`MU1000 EPROM jump to 0x${n.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=n)}).add([89,2],(a,r,c)=>{if(e.eprom){let n=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);F()&&console.debug(`MU1000 EPROM write to 0x${n.toString(16).padStart(6,"0")}.`);let i=e.eprom.data;a.subarray(4).forEach((o,h)=>{let l=h>>3,g=h&7;if(g==7)for(let $=0;$<7;$++)i[n+7*l+$]+=(o>>6-$&1)<<7;else i[n+7*l+g]=o})}}).add([89,3],(a,r,c)=>{}),t(this,W).add([39,48],(a,r,c)=>{}).add([43,0,0],(a,r,c)=>{let n=[0,0,0,0],i=(o,h)=>{n[h]=o};if(a.subarray(1).forEach((o,h)=>{let l=h+a[0];[i,i,i,i,()=>{E(this,O,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,O))},()=>o-64,()=>o||128,()=>o,()=>o,()=>{console.debug(`TG300 variation on cc${o}.`)}][l](o,l)}),a[0]<4){let o=0;n.forEach(h=>{o=o<<4,o+=h}),o-=1024}}).add([43,1,0],(a,r,c)=>{}).add([43,2],(a,r,c)=>{let n=e.chRedir(a[0],r,!0),i=a[1],o=y.cc*n,h=`TG300 CH${n+1} `;a.subarray(2).forEach((l,g)=>{g<5?([()=>{},()=>{t(e,u)[o+p[0]]=l},()=>{t(e,u)[o+p[32]]=l},()=>{t(e,R)[n]=l},()=>{let $=e.chRedir(l,r,!0);t(e,H)[n]=$,n!=$&&(e.buildRchTree(),console.info(`${h}receives from CH${$+1}`))}][g+i]||(()=>{}))(l,g+i):g<21||(g<47?([()=>{t(e,q)[n]=+!l},()=>{},()=>{},()=>{t(e,x)[y.rpn*n+3]=l},()=>{},()=>{t(e,u)[o+p[7]]=l},!1,!1,()=>{t(e,u)[o+p[10]]=l||128},!1,!1,()=>{console.debug(`${h} AC1 at cc${l}`)},()=>{console.debug(`${h} AC2 at cc${l}`)},()=>{t(e,u)[o+p[128]]=l},()=>{t(e,u)[o+p[93]]=l},()=>{t(e,u)[o+p[91]]=l},()=>{t(e,u)[o+p[94]]=l},()=>{t(e,u)[o+p[76]]=l},()=>{t(e,u)[o+p[77]]=l},()=>{t(e,u)[o+p[74]]=l},()=>{t(e,u)[o+p[71]]=l},()=>{t(e,u)[o+p[73]]=l},()=>{t(e,u)[o+p[75]]=l},()=>{t(e,u)[o+p[72]]=l},()=>{t(e,u)[o+p[78]]=l}][g+i-21]||(()=>{}))(l,g+i):g<95||([()=>{t(e,u)[o+p[65]]=l},()=>{t(e,u)[o+p[5]]=l}][g+i-95]||(()=>{}))(l,g+i))})}).add([43,7,0],(a,r,c)=>{let n=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",n)}).add([43,7,1],(a,r,c)=>{E(e,K,0),E(e,ae,Date.now()+3200),t(e,Q,ce).fill(0),a.forEach(function(n,i){let o=Math.floor(i/16),h=i%16,l=(h*3+o)*7,g=7,$=0;for(l-=h*5,o==2&&(g=2);$>6-$&1,$++})}),t(this,Y).add([66,18,0,0,127],(a,r,c)=>{e.switchMode("gs",!0),t(e,u)[y.cc*9]=120,t(e,u)[y.cc*25]=120,t(e,u)[y.cc*41]=120,t(e,u)[y.cc*57]=120,E(e,j,3),E(e,D,!1),t(e,fe).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,r,c)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),t(e,u)[y.cc*9]=120,t(e,u)[y.cc*25]=120,t(e,u)[y.cc*41]=120,t(e,u)[y.cc*57]=120,E(e,D,!1),t(e,fe).fill(0),console.info("MIDI reset: GS");break}default:{let n=[0,0,0,0],i=(o,h)=>{n[h]=o};if(a.subarray(1).forEach((o,h)=>{let l=h+a[0];[i,i,i,i,g=>{E(this,O,g*129/16383*100),e.dispatchEvent("mastervolume",t(e,O))},g=>{},g=>{}][l](o,h)}),a[0]<4){let o=0;n.forEach(h=>{o=o<<4,o+=h}),o-=1024}}}}).add([66,18,64,1],a=>{let r=a[0];if(r<16){let c="".padStart(r," ");a.subarray(1).forEach((n,i)=>{c+=String.fromCharCode(Math.max(32,n))}),c=c.padEnd(16," "),console.debug(`GS patch name: ${c}`)}else r<48||(r<65?a.subarray(1).forEach((c,n)=>{let i=`GS ${r+n>55?"chorus":"reverb"} `;([()=>{console.info(`${i}type: ${Je[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${i}predelay: ${c}ms`)},()=>{console.info(`${i}type: ${$t[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${i}to reverb: ${X(c)}`)},()=>{console.debug(`${i}to delay: ${X(c)}`)}][r+n-48]||(()=>{}))()}):r<80?console.debug(`Unknown GS patch address: ${r}`):r<91?a.subarray(1).forEach((c,n)=>{let i="GS delay ";([()=>{console.info(`${i}type: ${Et[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${i}to reverb: ${X(c)}`)}][r+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${r}`))}).add([66,18,64,2],a=>{let r="GS EQ ";a.subarray(1).forEach((c,n)=>{([()=>{console.debug(`${r}low freq: ${[200,400][c]}Hz`)},()=>{console.debug(`${r}low gain: ${c-64}dB`)},()=>{console.debug(`${r}high freq: ${[3e3,6e3][c]}Hz`)},()=>{console.debug(`${r}high gain: ${c-64}dB`)}][a[0]+n]||function(){console.warn(`Unknown GS EQ address: ${a[0]+n}`)})()})}).add([66,18,64,3],a=>{let r="GS EFX ",c=function(n,i){let o=mt(t(e,V).subarray(10,12),i,n);o&&console.debug(`${r}${Ze(t(e,V).subarray(10,12))} ${o}`)};a.subarray(1).forEach((n,i)=>{([()=>{e.setEffectTypeRaw(3,!1,32+n),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,n),console.info(`${r}type: ${Ze(t(e,V).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,()=>{console.debug(`${r}to reverb: ${X(n)}dB`)},()=>{console.debug(`${r}to chorus: ${X(n)}dB`)},()=>{console.debug(`${r}to delay: ${X(n)}dB`)},!1,()=>{console.debug(`${r}1 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${r}1 depth: ${n-64}`)},()=>{console.debug(`${r}2 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${r}2 depth: ${n-64}`)},()=>{console.debug(`${r}to EQ: ${n?"ON":"OFF"}`)}][a[0]+i]||function(o,h){console.warn(`Unknown GS EFX address: ${h}`)})(n,a[0]+i)})}).add([66,18,65],a=>{}).add([69,18,16],a=>{var r;switch(a[0]){case 0:{let c=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",c);break}case 32:{E(e,ae,Date.now()+3200),a[1]==0&&E(e,K,Math.max(Math.min(a[2]-1,9),0));break}default:if(a[0]<11){t(e,K)>9&&E(e,K,0),E(e,ae,Date.now()+3200),(r=t(e,oe)[a[0]-1])!=null&&r.length||(t(e,oe)[a[0]-1]=new Uint8Array(256));let c=t(e,oe)[a[0]-1],n=a[1];c.fill(0);let i=a.subarray(2);for(let o=0;o>4-k&1,k++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let f=function(a,r,c){let n=a[0],i=y.cc*r,o=y.rpn*r,h=`GS CH${r+1} `;n<3?a.subarray(1).forEach((l,g)=>{[()=>{t(e,u)[i+p[0]]=l},()=>{t(e,R)[r]=l},()=>{let $=e.chRedir(l,c,!0);t(e,H)[r]=$,r!=$&&(e.buildRchTree(),console.info(`${h}receives from CH${$+1}`))}][n+g]()}):n<19||(n<44?a.subarray(1).forEach((l,g)=>{([()=>{t(e,q)[r]=+!l},!1,()=>{e.setChType(r,l<<1,v.gs),console.debug(`${h}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{t(e,x)[o+3]=l},!1,()=>{t(e,u)[i+p[7]]=l},!1,!1,()=>{t(e,u)[i+p[10]]=l||128},!1,!1,()=>{console.debug(`${h}CC 1: cc${l}`)},()=>{console.debug(`${h}CC 2: cc${l}`)},()=>{t(e,u)[i+p[93]]=l},()=>{t(e,u)[i+p[91]]=l},!1,!1,()=>{t(e,x)[o+1]=l},()=>{t(e,x)[o+2]=l},()=>{t(e,u)[i+p[94]]=l}][n+g-19]||(()=>{}))()}):n<76||console.debug(`Unknown GS part address: ${n}`))},d=function(a,r){let c=a[0],n=`GS CH${r+1} `;c<2?a.subarray(1).forEach((i,o)=>{[()=>{t(e,u)[y.cc*r+p[32]]=i},()=>{}][c+o]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?a.subarray(1).forEach((i,o)=>{[()=>{console.debug(`${n}EQ: o${["ff","n"][i]}`)},()=>{},()=>{console.debug(`${n}EFX: o${["ff","n"][i]}`),t(e,Ae)[r]=i}][c+o-32]()}):console.warn(`Unknown GS misc address: ${c}`)};t(this,Y).add([66,18,64,16],(a,r)=>{f(a,e.chRedir(9,r,!0),r)}).add([66,18,64,17],(a,r)=>{f(a,e.chRedir(0,r,!0),r)}).add([66,18,64,18],(a,r)=>{f(a,e.chRedir(1,r,!0),r)}).add([66,18,64,19],(a,r)=>{f(a,e.chRedir(2,r,!0),r)}).add([66,18,64,20],(a,r)=>{f(a,e.chRedir(3,r,!0),r)}).add([66,18,64,21],(a,r)=>{f(a,e.chRedir(4,r,!0),r)}).add([66,18,64,22],(a,r)=>{f(a,e.chRedir(5,r,!0),r)}).add([66,18,64,23],(a,r)=>{f(a,e.chRedir(6,r,!0),r)}).add([66,18,64,24],(a,r)=>{f(a,e.chRedir(7,r,!0),r)}).add([66,18,64,25],(a,r)=>{f(a,e.chRedir(8,r,!0),r)}).add([66,18,64,26],(a,r)=>{f(a,e.chRedir(10,r,!0),r)}).add([66,18,64,27],(a,r)=>{f(a,e.chRedir(11,r,!0),r)}).add([66,18,64,28],(a,r)=>{f(a,e.chRedir(12,r,!0),r)}).add([66,18,64,29],(a,r)=>{f(a,e.chRedir(13,r,!0),r)}).add([66,18,64,30],(a,r)=>{f(a,e.chRedir(14,r,!0),r)}).add([66,18,64,31],(a,r)=>{f(a,e.chRedir(15,r,!0),r)}).add([66,18,64,64],(a,r)=>{d(a,e.chRedir(9,r,!0))}).add([66,18,64,65],(a,r)=>{d(a,e.chRedir(0,r,!0))}).add([66,18,64,66],(a,r)=>{d(a,e.chRedir(1,r,!0))}).add([66,18,64,67],(a,r)=>{d(a,e.chRedir(2,r,!0))}).add([66,18,64,68],(a,r)=>{d(a,e.chRedir(3,r,!0))}).add([66,18,64,69],(a,r)=>{d(a,e.chRedir(4,r,!0))}).add([66,18,64,70],(a,r)=>{d(a,e.chRedir(5,r,!0))}).add([66,18,64,71],(a,r)=>{d(a,e.chRedir(6,r,!0))}).add([66,18,64,72],(a,r)=>{d(a,e.chRedir(7,r,!0))}).add([66,18,64,73],(a,r)=>{d(a,e.chRedir(8,r,!0))}).add([66,18,64,74],(a,r)=>{d(a,e.chRedir(10,r,!0))}).add([66,18,64,75],(a,r)=>{d(a,e.chRedir(11,r,!0))}).add([66,18,64,76],(a,r)=>{d(a,e.chRedir(12,r,!0))}).add([66,18,64,77],(a,r)=>{d(a,e.chRedir(13,r,!0))}).add([66,18,64,78],(a,r)=>{d(a,e.chRedir(14,r,!0))}).add([66,18,64,79],(a,r)=>{d(a,e.chRedir(15,r,!0))}),t(this,he).add([54,65],(a,r)=>{e.switchMode("x5d");let c=(a[1]<<7)+a[0],n=(a[3]<<7)+a[2],i=e.chRedir(c&15,r,!0),o=y.cc*i;[()=>{n<1||(n<101?(e.setChType(i,e.CH_MELODIC,v.x5d),t(e,R)[i]=n-1,t(e,u)[o+p[0]]=82):n<229?(e.setChType(i,e.CH_MELODIC,v.x5d),t(e,R)[i]=n-101,t(e,u)[o+p[0]]=56):(e.setChType(i,e.CH_DRUMS,v.x5d),t(e,R)[i]=xt[n-229]||0,t(e,u)[o+p[0]]=62))},()=>{t(e,u)[o+p[7]]=n},()=>{n<31&&(t(e,u)[o+p[10]]=Math.round((n-15)*4.2+64))},()=>{t(e,u)[o+p[93]]=_e(n)},()=>{t(e,u)[o+p[91]]=_e(n)},()=>{t(e,x)[i*y.rpn+3]=n>8191?n-16320:64+n},()=>{t(e,x)[i*y.rpn+1]=n>8191?n-16320:64+n},()=>{n>0&&(t(e,x)[i*y.rpn]=n)},()=>{}][c>>4]()}).add([54,76,0],(a,r)=>{e.switchMode("x5d",!0);let c="",n=82,i=0,o=0,h="MSB PRG LSB NME";te(a,function(l,g){if(g<16400){let $=g%164;switch(!0){case $<10:{l>31&&(c+=String.fromCharCode(l));break}case $==11:{h+=` -${n} ${i} ${o} ${c.trim().replace("Init Voice","")}`,i++,c="";break}}i>99&&(n=90,i=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(h)}).add([54,77,0],(a,r)=>{e.switchMode("x5d",!0);let c="",n=90,i=0,o=0,h="MSB PRG LSB NME";te(a,function(l,g){if(g<13600){let $=g%136;switch(!0){case $<10:{l>31&&(c+=String.fromCharCode(l));break}case $==11:{h+=` -${n} ${i} ${o} ${c.trim().replace("Init Combi","")}`,i++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(h)}).add([54,78],(a,r)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,r)=>{e.switchMode("x5d",!0),te(a,(c,n)=>{n>0&&n<3&&(e.setEffectType(n-1,44,c),e.dispatchEvent(`efx${["reverb","chorus"][n-1]}`,e.getEffectType(n-1)))})}).add([54,104],(a,r)=>{e.switchMode("x5d",!0),te(a,function(c,n,i,o){if(n<192){let h=e.chRedir(Math.floor(n/12),r,!0),l=h*y.cc;switch(n%12){case 0:{c<128?(e.setChType(h,e.CH_MELODIC,v.x5d),t(e,u)[l+p[0]]=82,t(e,R)[h]=c):(e.setChType(h,e.CH_DRUMS,v.x5d),t(e,u)[l+p[0]]=62,t(e,R)[h]=xt[c-128]),c>0&&(t(e,U)[h]=1);break}case 1:{t(e,u)[l+p[7]]=c;break}case 2:{t(e,x)[h*y.rpn+3]=c>127?c-192:64+c;break}case 3:{t(e,x)[h*y.rpn+1]=c>127?c-192:64+c;break}case 4:{c<31&&(t(e,u)[l+p[10]]=Math.round((c-15)*4.2+64));break}case 5:{let g=c>>4,$=c&15;t(e,u)[l+p[91]]=_e($),t(e,u)[l+p[93]]=_e(g);break}case 10:break;case 11:{let g=e.chRedir(c&15,r,!0),$=c>>4;t(e,H)[h]=c,(g!=h||$)&&(console.info(`X5D Part CH${h+1} receives from CH${g+1}.`),e.buildRchTree())}}}else{let h=e.chRedir(n-192,r,!0)}})}),t(this,Y).add([22,18,127],a=>{e.switchMode("mt32",!0),E(e,D,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,r,c)=>{e.switchMode("mt32");let n=e.chRedir(c,r,!0),i=a[1];a.subarray(2).forEach((o,h)=>{let l=h+i;t(e,be)[l+(n-1)*16]=o,([!1,()=>{let g=t(e,be)[n-1<<4];if(g<3)if(t(e,se)[n]=1,g==2)for(let $=0;${t(e,x)[n*y.rpn+3]=o+40},()=>{t(e,x)[n*y.rpn+1]=o+14},()=>{t(e,x)[n*y.rpn]=o},!1,()=>{t(e,u)[y.cc*n+p[91]]=o?127:0},!1,()=>{t(e,u)[y.cc*n+p[7]]=o},()=>{t(e,u)[y.cc*n+p[10]]=Math.ceil(o*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(a,r,c)=>{e.switchMode("mt32");let n=e.chRedir(c,r,!0)}).add([22,18,2],(a,r,c)=>{e.switchMode("mt32");let n=e.chRedir(c,r,!0),i=a[1]+(a[0]<<7);i<10&&(t(e,se)[n]=1),a.subarray(2).forEach((o,h)=>{let l=h+i;l<14&&(t(e,J)[(n-1)*y.cmt+l]=o)})}).add([22,18,3],(a,r,c)=>{if(e.switchMode("mt32"),a[0]){let n=a[1]-16}else{let n=a[1];a.subarray(2).forEach((i,o)=>{let h=o+n;t(e,be)[h]=i;let l=e.chRedir(1+h>>4,r,!0),g=h&15;([!1,()=>{let $=t(e,be)[l-1<<4];if($<3)if(t(e,se)[l]=1,$==2)for(let w=0;w{t(e,x)[l*y.rpn+3]=i+40},()=>{t(e,x)[l*y.rpn+1]=i+14},()=>{t(e,x)[l*y.rpn]=i},!1,()=>{t(e,u)[y.cc*l+p[91]]=i?127:0},!1,()=>{t(e,u)[y.cc*l+p[7]]=i},()=>{t(e,u)[y.cc*l+p[10]]=Math.ceil(i*9.05)}][g]||(()=>{}))()})}}).add([22,18,4],(a,r,c)=>{e.switchMode("mt32");let n=a[1]+(a[0]<<7);a.subarray(2).forEach((i,o)=>{let h=o+n,l=e.chRedir(Math.floor(h/246+1),r,!0),g=h%246;g<14&&(t(e,J)[(l-1)*y.cmt+g]=i),g<10&&(t(e,se)[l]=1)})}).add([22,18,5],(a,r,c)=>{e.switchMode("mt32");let n=(a[0]<<7)+a[1];a.subarray(2).forEach((i,o)=>{let h=n+o,l=Math.floor(h/8),g=h&7,$=l*8;t(e,Pe)[h]=i,([!1,()=>{let w=t(e,Pe)[$];if(w<3){let k="";if(w==2){let S=y.cmt*l;k=`MT-m:${i.toString().padStart(3,"0")}`}else k=e.baseBank.get(0,i+(w<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l}),e.userBank.load(`MSB LSB PRG NME -000 127 ${l} ${k}`,!0)}}][g]||(()=>{}))()})}).add([22,18,8],(a,r,c)=>{e.switchMode("mt32");let n=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((i,o)=>{let h=n+o;h>1)*y.cmt+h]=i)})}).add([22,18,16],(a,r,c)=>{e.switchMode("mt32");let n=a[1],i=!1,o=function(h,l){t(e,H)[l-12]=h,i=!0};a.subarray(2).forEach((h,l)=>{let g=l+n;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,o,o,o,o,o,o,o,o,o,()=>{E(e,O,h),e.dispatchEvent("mastervolume",t(e,O))}][g]||(()=>{}))(h,l)}),i&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let r=a[1],c=" ".repeat(r);a.subarray(2).forEach(n=>{n>31&&(c+=String.fromCharCode(n))}),E(e,ie,c.padStart(20," ")),E(e,$e,Date.now()+3200)}).add([22,18,82],(a,r)=>{let c=e.chRedir(0,r,!0);for(let n=0;n<16;n++)t(e,L).ano(c+n),n&&n<10&&(t(e,R)[c+n]=et[n-1]);console.info("MT-32 alt reset complete.")}),t(this,he).add([66,0],(a,r)=>{e.switchMode("ns5r",!0),E(e,D,!1),console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,r)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),E(e,D,!1)}).add([66,18,0,0],(a,r)=>{let c=a[0];switch(c){case 124:case 126:case 127:{e.switchMode("ns5r",!0),E(e,D,!1);break}case 125:{console.info(`NS5R drum setup reset: ${a}`);break}default:if(c<10){let n=[0,0,0,0],i=(o,h)=>{n[h]=o};if(a.subarray(1).forEach((o,h)=>{[i,i,i,i,()=>{E(e,O,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,O))},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][c+h]()}),a[0]<4){let o=0;n.forEach(h=>{o=o<<4,o+=h}),o-=1024}}}}).add([66,18,0,1],(a,r)=>{}).add([66,18,0,2],(a,r)=>{}).add([66,18,1],(a,r)=>{let c=e.chRedir(a[0],r,!0),n=c*y.cc,i=a[1],o=`NS5R CH${c+1} `;a.subarray(2).forEach((h,l)=>{let g=i+l;g<3?[()=>{t(e,u)[n+p[0]]=h||121},()=>{t(e,u)[n+p[32]]=h},()=>{t(e,R)[c]=h}][g]():g<8||(g<14?[()=>{let $=e.chRedir(h,r,!0);t(e,H)[c]=$,c!=$&&(e.buildRchTree(),console.info(`${o}receives from CH${$+1}`))},()=>{t(e,q)[c]=+!h},()=>{e.setChType(c,h,v.ns5r),console.debug(`${o}type: ${Ie[h]}`)},()=>{t(e,x)[y.rpn*c+3]=h},()=>{},()=>{}][g-8]():g<16||(g<33?[()=>{t(e,u)[n+p[7]]=h},()=>{t(e,u)[n+p[11]]=h},()=>{},()=>{},()=>{t(e,u)[n+p[10]]=h||128},()=>{},()=>{},()=>{t(e,u)[n+p[93]]=h},()=>{t(e,u)[n+p[91]]=h},()=>{t(e,u)[n+p[76]]=h},()=>{t(e,u)[n+p[77]]=h},()=>{t(e,u)[n+p[78]]=h},()=>{t(e,u)[n+p[74]]=h},()=>{t(e,u)[n+p[71]]=h},()=>{t(e,u)[n+p[73]]=h},()=>{t(e,u)[n+p[75]]=h},()=>{t(e,u)[n+p[72]]=h}][g-16]():g<112||g<114&&[()=>{t(e,u)[n+p[5]]=h},()=>{t(e,u)[n+p[65]]=h}][g-112]()))})}).add([66,18,8,0],(a,r)=>{let c=a[0];if(c<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let n=c-32;E(e,ae,Date.now()+3200),E(e,K,10),t(e,Q,ce).fill(0);let i=a.subarray(1),o=4;i.forEach(function(h,l){let g=l+n,$=g>>4,w=g&15;if(g<80){let k=$>3,S=0,B=$0;)t(e,Q,ce)[w*32+$*7+(B-S)]=k&1,k=k>>1,S++}})}}).add([66,52],(a,r)=>{e.switchMode("ns5r",!0),E(e,D,!1);let c="";te(a,(n,i)=>{i<8?(n>31&&(c+=String.fromCharCode(n)),i==7&&(e.aiEfxName=c)):i<10&&(e.setEffectType(i-8,44,n),e.dispatchEvent(`efx${["reverb","chorus"][i-8]}`,e.getEffectType(i-8)))})}).add([66,53],(a,r)=>{e.switchMode("ns5r",!0),E(e,D,!1),te(a,function(c,n){switch(!0){case n<2944:{let i=e.chRedir(Math.floor(n/92),r,!0),o=i*y.cc;switch(n%92){case 0:{t(e,u)[o+p[0]]=c||121;break}case 1:{t(e,u)[o+p[32]]=c;break}case 2:{t(e,R)[i]=c,c>0&&(t(e,U)[i]=1);break}case 3:{let h=e.chRedir(c,r,!0);t(e,H)[i]=h,i!=h&&(console.info(`NS5R CH${i+1} receives from CH${h+1}.`),e.buildRchTree())}case 7:break;case 8:{t(e,x)[i*y.rpn+3]=c<40||c>88?c+(c>63?-192:64):c;break}case 9:case 10:{t(e,u)[o+p[7]]=c;break}case 11:{t(e,u)[o+p[11]]=c;break}case 14:{t(e,u)[o+p[10]]=c||128;break}case 19:{t(e,u)[o+p[93]]=c;break}case 20:{t(e,u)[o+p[91]]=c;break}case 84:{t(e,u)[o+p[65]]=c;break}case 85:{t(e,u)[o+p[5]]=c;break}}break}case n<3096:break;case n<3134:break;case n<8566:break}})}).add([66,54],(a,r)=>{e.switchMode("ns5r",!0);let c="",n=80,i=0,o=0,h="MSB PRG LSB NME";te(a,function(l,g){let $=g%158;switch(!0){case $<10:{l>31&&(c+=String.fromCharCode(l));break}case $==11:{n=l&127;break}case $==12:{o=l&127;break}case $==13:{h+=` -${n} ${i} ${o} ${c.trim().replace("Init Voice","")}`,i++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(h)}).add([66,55],(a,r)=>{e.switchMode("ns5r",!0);let c="",n=88,i=0,o=0,h="MSB PRG LSB NME";te(a,function(l,g){let $=g%126;switch(!0){case $<10:{l>31&&(c+=String.fromCharCode(l));break}case $==11:break;case $==12:break;case $==13:{h+=` -${n} ${i} ${o} ${c.trim().replace("Init Combi","")}`,i++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(h)}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let r=new Uint8Array(5760);te(a,(c,n,i)=>{if(n<720)for(let o=0;o<8;o++)r[n*8+o]=c>>7-o&1}),e.dispatchEvent("screen",{type:"ns5r",data:r})}).add([76],(a,r,c)=>{t(e,he).run([66,...a],r,c)}),t(this,Me).add([16,0,8,0],(a,r,c)=>{let n=(a[2]<<4)+a[3],i="K11 ";([()=>{e.switchMode("k11",!0),E(e,D,!1),E(e,j,n?4:0),console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,n),console.debug(`${i}reverb type: ${n}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${i}reverb time: ${n}`)},()=>{console.debug(`${i}reverb time: ${n}`)},()=>{console.debug(`${i}reverb predelay: ${n}`)},()=>{console.debug(`${i}reverb predelay: ${n}`)},()=>{console.debug(`${i}depth high: ${n}`)},()=>{console.debug(`${i}depth high: ${n}`)},()=>{console.debug(`${i}depth low: ${n}`)},()=>{console.debug(`${i}depth low: ${n}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,r,c)=>{let n=e.chRedir(a[1],r,!0),i=y.cc*n,o=y.rpn*n,h=(a[3]<<4)+a[4],l=`K11 CH${n+1} `;([()=>{h<128?(e.setChType(n,e.CH_MELODIC,v.k11),t(e,u)[i+p[0]]=0,t(e,R)[n]=h):(e.setChType(n,e.CH_DRUMS,v.k11),t(e,R)[n]=h-128)},()=>{let g=e.chRedir(h,r,!0);t(e,H)[n]=g,n!=g&&(e.buildRchTree(),console.info(`${l}receives from CH${g+1}`))},()=>{t(e,u)[i+p[7]]=h},()=>{t(e,U)[n]=h},()=>{t(e,u)[i+p[10]]=h},()=>{t(e,x)[o+3]=h+40},()=>{t(e,x)[o+1]=h>>1,t(e,x)[o+2]=h&1},()=>{t(e,u)[i+p[91]]=h?127:0},()=>{},()=>{t(e,u)[i+p[74]]=h},()=>{t(e,u)[i+p[73]]=h},()=>{t(e,u)[i+p[72]]=h}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,r,c)=>{let n=(a[2]<<4)+a[3],i="GMLX ";([()=>{console.debug(`${i}reverb type: ${n}`)},()=>{console.debug(`${i}reverb time: ${n}`)},()=>{console.debug(`${i}reverb predelay: ${n}`)},()=>{console.debug(`${i}depth high: ${n}`)},()=>{console.debug(`${i}depth low: ${n}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,r,c)=>{let n=(a[2]<<4)+a[3],i=e.chRedir(a[1],r,!0),o=i*y.cc;[()=>{n<128?(e.setChType(i,e.CH_MELODIC,v.k11),t(e,u)[o+p[0]]=0,t(e,u)[o+p[32]]=0,t(e,R)[i]=n):n<160?(e.setChType(i,e.CH_MELODIC,v.k11),t(e,u)[o+p[0]]=0,t(e,u)[o+p[32]]=7,t(e,R)[i]=n-100):(e.setChType(i,e.CH_DRUMS,v.k11),t(e,u)[o+p[0]]=122,t(e,u)[o+p[32]]=0,t(e,R)[i]=n-160)},()=>{let h=e.chRedir(n,r,!0);t(e,H)[i]=h,i!=h&&(e.buildRchTree(),console.info(`GMLX CH${i+1} receives from CH${h+1}`))}][a[0]]()}).add([16,0,9,4],(a,r,c)=>{let n=(a[2]<<4)+a[3],i=e.chRedir(a[1],r,!0),o=i*y.cc,h=i*y.rpn,l=`GMLX CH${i+1} `;[()=>{t(e,U)[i]=n},()=>{t(e,u)[o+p[7]]=n},()=>{t(e,u)[o+p[10]]=n},()=>{t(e,u)[o+p[91]]=n?127:0},()=>{t(e,x)[h+3]=n+40},()=>{t(e,x)[h+1]=n},()=>{t(e,x)[h]=n},()=>{}][a[0]]()}),t(this,Te).add([66,93,64],(a,r,c)=>{let n=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{E(e,O,n*129/16383*100),e.dispatchEvent("mastervolume",t(e,O));break}case 5:{n-64;break}case 6:{console.debug(`SG global reverb: ${n?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(a[1]){case 48:{console.debug(`SG reverb type: ${Je[n]}`);break}}break}default:if(a[0]>>4==1){let i=e.chRedir(a[0]&15,r,!0);if(a[1]==2){let o=e.chRedir(n,r,!0);t(e,H)[i]=o,i!=o&&(e.buildRchTree(),console.info(`SG CH${i+1} receives from CH${o+1}`))}else a[1]==19&&(t(e,u)[y.cc*i+p[7]]=n)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,Re).add([9],(a,r,c)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),t(this,W).add([127,0],(a,r,c)=>{e.switchMode("motif");let n=new Uint8Array([127,1,...a]);t(e,W).run(n,r,c)}).add([127,1,0,0],(a,r,c)=>{e.switchMode("s90es");let n="S90/Motif ES system ",i=a[0];a.subarray(1).forEach((o,h)=>{([()=>{E(e,O,o*12900/16383),e.dispatchEvent("mastervolume",t(e,O))}][i+h]||(()=>{console.info(`Unrecognized ${n}ID: ${i+h}`)}))()})}).add([127,1,0,0,14],(a,r,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk header ",i=[];i[95]=(o,h,l)=>{console.debug(`${n}multi edit buffer: ${o[1]}`)},(i[a[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,r,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk footer ",i=[];i[95]=(o,h,l)=>{console.debug(`${n}multi edit buffer: ${o[1]}`)},(i[a[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,r,c)=>{e.switchMode("s90es");let n=e.chRedir(a[0],r,!0),i=y.cc*n,o=a[1],h=`S90/Motif ES bulk CH${n<16?n+1:"U"+(n-95)} `;console.debug(h,a),!(a[0]>15)&&a.subarray(2).forEach((l,g)=>{([()=>{t(e,u)[i+p[0]]=l},()=>{l&&(t(e,U)[n]=1),t(e,u)[i+p[32]]=l,e.setChType(n,[32,40].indexOf(l)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,T),!0)},()=>{l&&(t(e,U)[n]=1),t(e,R)[n]=l},()=>{let $=e.chRedir(l,r,!0);t(e,H)[n]=$,n!=$&&(e.buildRchTree(),console.info(`${h}receives from CH${$+1}`))},()=>{t(e,q)[n]=l?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{t(e,u)[i+p[7]]=l},()=>{t(e,u)[i+p[10]]=l},!1,!1,!1,()=>{t(e,u)[i+p[91]]=l},()=>{t(e,u)[i+p[93]]=l},()=>{t(e,u)[i+p[94]]=l},()=>{t(e,u)[i+p[128]]=l},()=>{},()=>{t(e,u)[i+p[74]]=l},()=>{t(e,u)[i+p[71]]=l},!1,()=>{t(e,u)[i+p[65]]=l},()=>{t(e,u)[i+p[5]]=l},()=>{}][o+g]||(()=>{}))()})}).add([127,1,54,16],(a,r,c)=>{e.switchMode("s90es");let n=a[0];a.subarray(1).forEach((i,o)=>{let l=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let g=i-64},()=>{let g=De[i]},()=>{let g=i/10},()=>{let g=i}][n+o&3]||(()=>{}))()})}),t(this,Y).add([0,72,18,0,0,0,0],(a,r,c)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,r,c)=>{let n=a[0]>>5,i=a[0]&31;switch(n){case 0:{console.debug(`Unknown SD-90 global effects message: -%o`,a);break}case 1:{let o=e.chRedir(i,r,!0),h=a[1],l=o*y.cc;a.subarray(2).forEach((g,$)=>{let w=h+$;w<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,u)[l+p[0]]=g,g){case 104:case 105:case 106:case 107:case 120:{t(e,C)[o]||e.setChType(o,e.CH_DRUMS);break}default:t(e,C)[o]&&e.setChType(o,e.CH_MELODIC)}},()=>{t(e,u)[l+p[32]]=g},()=>{t(e,R)[o]=g},()=>{t(e,u)[l+p[7]]=g},()=>{t(e,u)[l+p[10]]=g},()=>{},()=>{},()=>{g<2&&(t(e,q)[o]=g)},()=>{g<2&&(t(e,u)[l+p[68]]=g?127:0)},()=>{},()=>{g<2&&(t(e,u)[l+p[65]]=g?127:0)},()=>{t(e,u)[l+p[5]]=g&15<<4|t(e,u)[l+p[5]]&15},()=>{t(e,u)[l+p[5]]=g&15|(t(e,u)[l+p[5]]&240)>>4},()=>{t(e,u)[l+p[74]]=g},()=>{t(e,u)[l+p[71]]=g},()=>{t(e,u)[l+p[73]]=g},()=>{t(e,u)[l+p[72]]=g},0,0,0,0,0,0,0,()=>{t(e,u)[l+p[128]]=g},()=>{t(e,u)[l+p[93]]=g},()=>{t(e,u)[l+p[91]]=g},0,0,()=>{t(e,u)[l+p[75]]=g},()=>{t(e,u)[l+p[76]]=g},()=>{t(e,u)[l+p[77]]=g},()=>{t(e,u)[l+p[78]]=g}][w]||(()=>{}))():w<63||(w<64?t(e,C)[o]?t(e,u)[l+p[0]]=104|g:t(e,u)[l+p[0]]=96|g:console.debug(`Unknown SD-90 global CH${o+1} param setup message: -%o`,a))});break}case 2:{let o=e.chRedir(i,r,!0),h=a[1];console.debug(`Unknown SD-90 global CH${o+1} MIDI setup message: +`),a.slice(0,2)){case"@I":{w(this,P,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(i=a.slice(2))==null?void 0:i.trimLeft()});break}case"@K":{w(this,P,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(c=a.slice(2))==null?void 0:c.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{w(this,P,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(n=a.slice(2))==null?void 0:n.trimLeft()});break}case"@T":{w(this,P,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(s=a.slice(2))==null?void 0:s.trimLeft()});break}case"@V":{w(this,P,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(o=a.slice(2))==null?void 0:o.trimLeft()});break}case"XF":{let f=a.slice(2).split(":");switch(f[0]){case"hd":{f.slice(1).forEach((l,b)=>{l.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][b],data:l})});break}case"ln":{f.slice(1).forEach((l,b)=>{l.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][b],data:l})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:t(this,P)?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` +`).forEach((f,l)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:f,mask:l!=0})})}},t(this,I)[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},t(this,I)[3]=function(a,i){i<1&&t(this,Ce)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},t(this,I)[4]=function(a,i){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},t(this,I)[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},t(this,I)[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},t(this,I)[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},t(this,I)[32]=function(a){w(this,Ce,a[0]+1)},t(this,I)[33]=function(a,i){t(e,we)[i]=a+1},t(this,I)[81]=function(a,i){w(e,Ne,a/1e3)},t(this,I)[127]=function(a,i){t(e,xe).run(a,i)},t(this,xe).default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},t(this,xe).add([67,0,1],function(a,i){t(e,we)[i]=a[0]+1}),w(this,Me,new se("universal non-realtime")),w(this,Te,new se("universal realtime")),w(this,Z,new se("Yamaha")),w(this,ee,new se("Roland")),w(this,be,new se("Korg")),w(this,Re,new se("Kawai")),w(this,Oe,new se("Akai")),w(this,De,new se("Casio"));let r=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,a)};t(this,Me).default=r,t(this,Te).default=r,t(this,Z).default=r,t(this,ee).default=r,t(this,be).default=r,t(this,Re).default=r,t(this,Oe).default=r,t(this,De).default=r,t(this,Me).add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),w(e,P,t(e,P)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),t(this,Te).add([4,1],a=>{w(e,U,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,U))}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64),t(this,Z).add([76,0,0],a=>{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),w(e,P,!1),console.info("MIDI reset: XG");break}default:{let i=[0,0,0,0],c=(n,s)=>{i[s]=n};if(a.subarray(1).forEach((n,s)=>{let o=s+a[0];([c,c,c,c,f=>{w(this,U,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,U))},f=>{},f=>{}][o]||(()=>{}))(n,s)}),a[0]<4){let n=0;i.forEach(s=>{n=n<<4,n+=s}),n-=1024}}}}).add([76,2,1],a=>{let i="XG ";a[0]<32?(i+="reverb ",a.subarray(1).forEach((c,n)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${i}main type: ${Ie[s]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{e.setEffectTypeRaw(0,!0,s),console.debug(`${i}sub type: ${s+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{console.debug(`${i}time: ${pt(s)}s`)},s=>{console.debug(`${i}diffusion: ${s}`)},s=>{console.debug(`${i}initial delay: ${s}`)},s=>{console.debug(`${i}HPF cutoff: ${Ue[s]}Hz`)},s=>{console.debug(`${i}LPF cutoff: ${Ue[s]}Hz`)},s=>{console.debug(`${i}width: ${s}`)},s=>{console.debug(`${i}height: ${s}`)},s=>{console.debug(`${i}depth: ${s}`)},s=>{console.debug(`${i}wall type: ${s}`)},s=>{console.debug(`${i}dry/wet: ${s}`)},s=>{console.debug(`${i}send: ${Q(s)}dB`)},s=>{console.debug(`${i}pan: ${s-64}`)},!1,!1,s=>{console.debug(`${i}delay: ${s}`)},s=>{console.debug(`${i}density: ${s}`)},s=>{console.debug(`${i}balance: ${s}`)},s=>{},s=>{console.debug(`${i}feedback: ${s}`)},s=>{}][a[0]+n]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(c)})):a[0]<64?(i+="chorus ",a.subarray(1).forEach((c,n)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${i}main type: ${Ie[s]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{e.setEffectTypeRaw(1,!0,s),console.debug(`${i}sub type: ${s+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{console.debug(`${i}LFO: ${ut[s]}Hz`)},s=>{},s=>{console.debug(`${i}feedback: ${s}`)},s=>{console.debug(`${i}delay offset: ${bt(s)}ms`)},s=>{},s=>{console.debug(`${i}low: ${Ue[s]}Hz`)},s=>{console.debug(`${i}low: ${s-64}dB`)},s=>{console.debug(`${i}high: ${Ue[s]}Hz`)},s=>{console.debug(`${i}high: ${s-64}dB`)},s=>{console.debug(`${i}dry/wet: ${s}`)},s=>{console.debug(`${i}send: ${Q(s)}dB`)},s=>{console.debug(`${i}pan: ${s-64}`)},s=>{console.debug(`${i}to reverb: ${Q(s)}dB`)},!1,s=>{},s=>{},s=>{},s=>{console.debug(`${i}LFO phase diff: ${(s-64)*3}deg`)},s=>{console.debug(`${i}input mode: ${s?"stereo":"mono"}`)},s=>{}][a[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(c)})):a[0]<86?(i+="variation ",a.subarray(1).forEach((c,n)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${i}main type: ${Ie[s]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},s=>{e.setEffectTypeRaw(2,!0,s),console.debug(`${i}sub type: ${s+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+n]||function(){})(c)})):a[0]<97?(i+="variation ",a.subarray(1).forEach((c,n)=>{[s=>{console.debug(`${i}send: ${Q(s)}dB`)},s=>{console.debug(`${i}pan: ${s-64}`)},s=>{console.debug(`${i}to reverb: ${Q(s)}dB`)},s=>{console.debug(`${i}to chorus: ${Q(s)}dB`)},s=>{console.debug(`${i}connection: ${s?"system":"insertion"}`)},s=>{console.debug(`${i}channel: CH${s+1}`)},s=>{console.debug(`${i}mod wheel: ${s-64}`)},s=>{console.debug(`${i}bend wheel: ${s-64}`)},s=>{console.debug(`${i}channel after touch: ${s-64}`)},s=>{console.debug(`${i}AC1: ${s-64}`)},s=>{console.debug(`${i}AC2: ${s-64}`)}][a[0]-86+n](c)})):a[0]>111&&a[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((i,c)=>{let n=c+a[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let s=n-1>>2,o=n-1&3,f=`XG EQ ${s} ${["gain","freq","Q","shape"][o]}: `;[()=>{console.debug(`${f}${i-64}dB`)},()=>{console.debug(`${f}${i} (raw)`)},()=>{console.debug(`${f}${i/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!i]}`)}][o]()}})}).add([76,3],a=>{let i=a[0],c=a[1],n=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((s,o)=>{([f=>{e.setEffectTypeRaw(3+i,!1,f),console.info(`${n}main type: ${Ie[f]}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))},f=>{e.setEffectTypeRaw(3+i,!0,f),console.debug(`${n}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))}][c+o]||function(){})(s)})}).add([76,6,0],a=>{let i=a[0];i<64?e.setLetterDisplay(a.subarray(1),"XG letter display",i):w(e,ve,Date.now())}).add([76,7,0],a=>{let i=a[0];w(e,F,0),w(e,ne,Date.now()+3200),t(e,Y,de).fill(0);let c=a.subarray(1);for(let n=0;n>6-v&1,v++})}).add([76,8],(a,i)=>{let c=e.chRedir(a[0],i,!0),n=a[1],s=E.cc*c,o=`XG CH${c+1} `,f=`Unknown XG part address ${n}.`;a.subarray(2).forEach((l,b)=>{n<1?console.debug(f):n<41?([()=>{t(e,u)[s+y[0]]=l,e.dispatchEvent("voice",{part:c})},()=>{t(e,u)[s+y[32]]=l,e.dispatchEvent("voice",{part:c})},()=>{t(e,D)[c]=l,e.dispatchEvent("voice",{part:c})},()=>{let v=e.chRedir(l,i,!0);t(e,G)[c]=v,c!=v&&(e.buildRchTree(),console.info(`${o}receives from CH${v+1}`))},()=>{t(e,j)[c]=+!l},()=>{},()=>{e.setChType(c,l,C.xg),console.debug(`${o}type: ${Xe[l]||l}`)},()=>{t(e,x)[E.rpn*c+3]=l},!1,!1,()=>{t(e,u)[s+y[7]]=l},!1,!1,()=>{t(e,u)[s+y[10]]=l||128},!1,!1,()=>{t(e,u)[s+y[128]]=l},()=>{t(e,u)[s+y[93]]=l},()=>{t(e,u)[s+y[91]]=l},()=>{t(e,u)[s+y[94]]=l},()=>{t(e,u)[s+y[76]]=l},()=>{t(e,u)[s+y[77]]=l},()=>{t(e,u)[s+y[78]]=l},()=>{t(e,u)[s+y[74]]=l},()=>{t(e,u)[s+y[71]]=l},()=>{t(e,u)[s+y[73]]=l},()=>{t(e,u)[s+y[75]]=l},()=>{t(e,u)[s+y[72]]=l}][n+b-1]||(()=>{}))():n<48?console.debug(f):n<111?n>102&&n<105&&(t(e,u)[s+y[[5,65][n&1]]]=l):n<114?console.debug(f):n<116?console.debug(`${o}EQ ${["bass","treble"][n&1]} gain: ${l-64}dB`):n<118?console.debug(f):n<120?console.debug(`${o}EQ ${["bass","treble"][n&1]} freq: ${l}`):console.debug(f)})}).add([76,9],(a,i)=>{let c=e.chRedir(a[0],i,!0),n=a[1],s=`PLG-150VL CH${c+1} `;a.subarray(2).forEach((o,f)=>{let l=f+n;switch(l){case 1:{console.info(`${s}breath mode: ${["system","breath","velocity","touch EG"][o]}`);break}case 0:case 27:case 28:break;default:if(l<27){let b=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${s}${b} control source: ${$t(o)}`),o&&o<96&&e.allocateAce(o)):console.debug(`${s}${b} scale break point: ${o}`):console.debug(`${s}${b} depth: ${o-64}`)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][a[0]]} for CH${a[2]+1}.`)}).add([73,0,0],(a,i)=>{let c=a[0],n="MU1000 System: ";a.subarray(1).forEach((s,o)=>{let f=c+o;f==8?console.debug(`${n}LCD contrast set to ${s}.`):f==18?(w(e,J,s?126:0),console.debug(`${n}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):f>=64&&f<69&&[()=>{e.dispatchEvent("channelactive",s)},()=>{s<8?(e.dispatchEvent("channelmin",s<<4),console.debug(`Octavia System: Minimum CH${(s<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{s<8?(e.dispatchEvent("channelmax",(s<<4)+15),console.debug(`Octavia System: Maximum CH${(s<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{w(e,re,!!s),console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][f-64]()})}).add([73,10,0],(a,i)=>{let c=a[0],n=`MU1000 RS${t(e,re)?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let s=e.chRedir(0,i,!0);t(e,re)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${n}Show CH1~64`);break}case 3:{let s=e.chRedir(a[1]<<5,i,!0);t(e,re)&&e.dispatchEvent("channelmin",s),t(e,re)&&e.dispatchEvent("channelmax",s+31),console.info(`${n}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${n}unknown switch ${c} invoked.`)}else if(c<32){if(t(e,re)){let s=e.chRedir(c-16+(t(e,Ge)<<4),i,!0);e.dispatchEvent("channelactive",s)}}else if(c<36){let s=e.chRedir(c-32<<4,i,!0);t(e,re)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),w(e,Ge,c-32)),console.info(`${n}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(a,i)=>{let c=e.chRedir(a[0],i,!0),n=`PLG-100SG CH${c+1} `,s=Date.now();if(a[1]==0){let o="",f=0;a.subarray(2).forEach((l,b)=>{b%2==0?o+=yt[l]||l.toString().padStart("0"):f+=l*13}),s>=t(e,Be)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${gt(o)}`,amend:!0}),w(e,Be,s+Math.ceil(f/2)+t(e,Ne)),A()&&console.debug(`${n}vocals: ${o}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)});let d=function(a,i,c,n){},h=function(a,i){let c=a*E.dpn,n=i[0],s=i[1];i.subarray(2).forEach((o,f)=>{let l=f+s,b=-1;l<16?([()=>{b=24},()=>{b=25},()=>{b=26},()=>{},()=>{b=28},()=>{b=29},()=>{b=30},()=>{b=31},()=>{},()=>{},()=>{},()=>{b=20},()=>{b=21},()=>{b=22},()=>{b=23},()=>{}][l]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))():l<32||(l<40?([()=>{b=48},()=>{b=49},!1,!1,()=>{b=52},()=>{b=53}][l-32]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))():l<80||([()=>{b=36}][l-80]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))()),b>=0?(A()&&console.debug(c,b,n,o),t(e,V)[(c+te[b])*E.dnc+n]=o):A()&&console.debug(`XG-style drum param ${l} has no writes.`)})},$=function(a,i,c){let n=a*E.dpn,s=(i<<7)+c[0];c.subarray(1).forEach((o,f)=>{let l=f+s,b=l&127,v=l>>7,S=-1;v>1&&([()=>{S=26},()=>{},()=>{S=28},()=>{S=29},()=>{S=30},()=>{},()=>{},()=>{S=31}][v-2]||(()=>{console.debug(`Unknown GS-style drum param ${v} on set ${a+1}.`)}))(),S>-1?(A()&&console.debug(n,S,b,o),t(e,V)[(n+te[S])*E.dnc+b]=o):A()&&console.debug(`GS-style drum param ${v} has no writes.`)})};t(this,Z).add([76,48],(a,i,c)=>{h(0,a)}).add([76,49],(a,i,c)=>{h(1,a)}).add([76,50],(a,i,c)=>{h(2,a)}).add([76,51],(a,i,c)=>{h(3,a)}).add([76,52],(a,i,c)=>{h(4,a)}).add([76,53],(a,i,c)=>{h(5,a)}).add([76,54],(a,i,c)=>{h(6,a)}).add([76,55],(a,i,c)=>{h(7,a)}),t(this,Z).add([89,0],(a,i,c)=>{if(e.eprom){let n=a[0],s=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);A()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${n} bytes.`);let o=e.eprom.data;a.subarray(4).forEach((f,l)=>{let b=l>>3,v=l&7;if(v==7)for(let S=0;S<7;S++)o[s+7*b+S]+=(f>>6-S&1)<<7;else o[s+7*b+v]=f})}}).add([89,1],(a,i,c)=>{let n=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];A()&&console.debug(`MU1000 EPROM jump to 0x${n.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=n)}).add([89,2],(a,i,c)=>{if(e.eprom){let n=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);A()&&console.debug(`MU1000 EPROM write to 0x${n.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;a.subarray(4).forEach((o,f)=>{let l=f>>3,b=f&7;if(b==7)for(let v=0;v<7;v++)s[n+7*l+v]+=(o>>6-v&1)<<7;else s[n+7*l+b]=o})}}).add([89,3],(a,i,c)=>{}),t(this,Z).add([39,48],(a,i,c)=>{}).add([43,0,0],(a,i,c)=>{let n=[0,0,0,0],s=(o,f)=>{n[f]=o};if(a.subarray(1).forEach((o,f)=>{let l=f+a[0];[s,s,s,s,()=>{w(this,U,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,U))},()=>o-64,()=>o||128,()=>o,()=>o,()=>{console.debug(`TG300 variation on cc${o}.`)}][l](o,l)}),a[0]<4){let o=0;n.forEach(f=>{o=o<<4,o+=f}),o-=1024}}).add([43,1,0],(a,i,c)=>{}).add([43,2],(a,i,c)=>{let n=e.chRedir(a[0],i,!0),s=a[1],o=E.cc*n,f=`TG300 CH${n+1} `;a.subarray(2).forEach((l,b)=>{b<5?([()=>{},()=>{t(e,u)[o+y[0]]=l,e.dispatchEvent("voice",{part:n})},()=>{t(e,u)[o+y[32]]=l,e.dispatchEvent("voice",{part:n})},()=>{t(e,D)[n]=l,e.dispatchEvent("voice",{part:n})},()=>{let v=e.chRedir(l,i,!0);t(e,G)[n]=v,n!=v&&(e.buildRchTree(),console.info(`${f}receives from CH${v+1}`))}][b+s]||(()=>{}))(l,b+s):b<21||(b<47?([()=>{t(e,j)[n]=+!l},()=>{},()=>{},()=>{t(e,x)[E.rpn*n+3]=l},()=>{},()=>{t(e,u)[o+y[7]]=l},!1,!1,()=>{t(e,u)[o+y[10]]=l||128},!1,!1,()=>{console.debug(`${f} AC1 at cc${l}`)},()=>{console.debug(`${f} AC2 at cc${l}`)},()=>{t(e,u)[o+y[128]]=l},()=>{t(e,u)[o+y[93]]=l},()=>{t(e,u)[o+y[91]]=l},()=>{t(e,u)[o+y[94]]=l},()=>{t(e,u)[o+y[76]]=l},()=>{t(e,u)[o+y[77]]=l},()=>{t(e,u)[o+y[74]]=l},()=>{t(e,u)[o+y[71]]=l},()=>{t(e,u)[o+y[73]]=l},()=>{t(e,u)[o+y[75]]=l},()=>{t(e,u)[o+y[72]]=l},()=>{t(e,u)[o+y[78]]=l}][b+s-21]||(()=>{}))(l,b+s):b<95||([()=>{t(e,u)[o+y[65]]=l},()=>{t(e,u)[o+y[5]]=l}][b+s-95]||(()=>{}))(l,b+s))})}).add([43,7,0],(a,i,c)=>{let n=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",n)}).add([43,7,1],(a,i,c)=>{w(e,F,0),w(e,ne,Date.now()+3200),t(e,Y,de).fill(0),a.forEach(function(n,s){let o=Math.floor(s/16),f=s%16,l=(f*3+o)*7,b=7,v=0;for(l-=f*5,o==2&&(b=2);v>6-v&1,v++})}),t(this,ee).add([66,18,0,0,127],(a,i,c)=>{e.switchMode("gs",!0),t(e,u)[E.cc*9]=120,t(e,u)[E.cc*25]=120,t(e,u)[E.cc*41]=120,t(e,u)[E.cc*57]=120,w(e,J,3),w(e,P,!1),t(e,pe).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,i,c)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),t(e,u)[E.cc*9]=120,t(e,u)[E.cc*25]=120,t(e,u)[E.cc*41]=120,t(e,u)[E.cc*57]=120,w(e,P,!1),t(e,pe).fill(0),console.info("MIDI reset: GS");break}default:{let n=[0,0,0,0],s=(o,f)=>{n[f]=o};if(a.subarray(1).forEach((o,f)=>{let l=f+a[0];[s,s,s,s,b=>{w(this,U,b*129/16383*100),e.dispatchEvent("mastervolume",t(e,U))},b=>{},b=>{}][l](o,f)}),a[0]<4){let o=0;n.forEach(f=>{o=o<<4,o+=f}),o-=1024}}}}).add([66,18,64,1],a=>{let i=a[0];if(i<16){let c="".padStart(i," ");a.subarray(1).forEach((n,s)=>{c+=String.fromCharCode(Math.max(32,n))}),c=c.padEnd(16," "),console.debug(`GS patch name: ${c}`)}else i<48||(i<65?a.subarray(1).forEach((c,n)=>{let s=`GS ${i+n>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${Ze[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${c}ms`)},()=>{console.info(`${s}type: ${Et[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${Q(c)}`)},()=>{console.debug(`${s}to delay: ${Q(c)}`)}][i+n-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?a.subarray(1).forEach((c,n)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${mt[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${Q(c)}`)}][i+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],a=>{let i="GS EQ ";a.subarray(1).forEach((c,n)=>{([()=>{console.debug(`${i}low freq: ${[200,400][c]}Hz`)},()=>{console.debug(`${i}low gain: ${c-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][c]}Hz`)},()=>{console.debug(`${i}high gain: ${c-64}dB`)}][a[0]+n]||function(){console.warn(`Unknown GS EQ address: ${a[0]+n}`)})()})}).add([66,18,64,3],a=>{let i="GS EFX ",c=function(n,s){let o=vt(t(e,q).subarray(10,12),s,n);o&&console.debug(`${i}${et(t(e,q).subarray(10,12))} ${o}`)};a.subarray(1).forEach((n,s)=>{([()=>{e.setEffectTypeRaw(3,!1,32+n),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,n),console.info(`${i}type: ${et(t(e,q).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,()=>{console.debug(`${i}to reverb: ${Q(n)}dB`)},()=>{console.debug(`${i}to chorus: ${Q(n)}dB`)},()=>{console.debug(`${i}to delay: ${Q(n)}dB`)},!1,()=>{console.debug(`${i}1 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${i}1 depth: ${n-64}`)},()=>{console.debug(`${i}2 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${i}2 depth: ${n-64}`)},()=>{console.debug(`${i}to EQ: ${n?"ON":"OFF"}`)}][a[0]+s]||function(o,f){console.warn(`Unknown GS EFX address: ${f}`)})(n,a[0]+s)})}).add([66,18,65],a=>{$((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],a=>{var i;switch(a[0]){case 0:{let c=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",c);break}case 32:{w(e,ne,Date.now()+3200),a[1]==0&&(w(e,F,Math.max(Math.min(a[2]-1,9),0)),A()&&console.debug(`GS switch display page ${a[2]-1}.`));break}default:if(a[0]<6){t(e,F)>9&&w(e,F,0);let c=a[0]-1<<1|a[1]>>6;t(e,F)==c&&w(e,ne,Date.now()+3200),(i=t(e,fe)[c])!=null&&i.length||(t(e,fe)[c]=new Uint8Array(256));let n=t(e,fe)[c];A()&&console.debug(`GS frame draw page ${c}.`);let s=a[1]&63;n.fill(0),a.subarray(2).forEach(function(f,l){let b=l+s,v=Math.floor(b/16),S=b%16,R=(S*4+v)*5,L=5,X=0;for(R-=S*4,v==3&&(L=1);X>4-X&1,X++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let p=function(a,i,c){let n=a[0],s=E.cc*i,o=E.rpn*i,f=`GS CH${i+1} `;n<3?(a.subarray(1).forEach((l,b)=>{[()=>{t(e,u)[s+y[0]]=l},()=>{t(e,D)[i]=l},()=>{let v=e.chRedir(l,c,!0);t(e,G)[i]=v,i!=v&&(e.buildRchTree(),console.info(`${f}receives from CH${v+1}`))}][n+b]()}),e.dispatchEvent("voice",{part:i})):n<19||(n<44?a.subarray(1).forEach((l,b)=>{([()=>{t(e,j)[i]=+!l},!1,()=>{e.setChType(i,l<<1,C.gs),console.debug(`${f}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{t(e,x)[o+3]=l},!1,()=>{t(e,u)[s+y[7]]=l},!1,!1,()=>{t(e,u)[s+y[10]]=l||128},!1,!1,()=>{console.debug(`${f}CC 1: cc${l}`)},()=>{console.debug(`${f}CC 2: cc${l}`)},()=>{t(e,u)[s+y[93]]=l},()=>{t(e,u)[s+y[91]]=l},!1,!1,()=>{t(e,x)[o+1]=l},()=>{t(e,x)[o+2]=l},()=>{t(e,u)[s+y[94]]=l}][n+b-19]||(()=>{}))()}):n<76||console.debug(`Unknown GS part address: ${n}`))},m=function(a,i){let c=a[0],n=`GS CH${i+1} `;c<2?a.subarray(1).forEach((s,o)=>{[()=>{t(e,u)[E.cc*i+y[32]]=s},()=>{}][c+o]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?a.subarray(1).forEach((s,o)=>{[()=>{console.debug(`${n}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${n}EFX: o${["ff","n"][s]}`),t(e,He)[i]=s,e.dispatchEvent("partefxtoggle",{part:i,active:s})}][c+o-32]()}):console.warn(`Unknown GS misc address: ${c}`)};t(this,ee).add([66,18,64,16],(a,i)=>{p(a,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(a,i)=>{p(a,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(a,i)=>{p(a,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(a,i)=>{p(a,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(a,i)=>{p(a,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(a,i)=>{p(a,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(a,i)=>{p(a,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(a,i)=>{p(a,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(a,i)=>{p(a,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(a,i)=>{p(a,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(a,i)=>{p(a,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(a,i)=>{p(a,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(a,i)=>{p(a,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(a,i)=>{p(a,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(a,i)=>{p(a,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(a,i)=>{p(a,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(a,i)=>{m(a,e.chRedir(9,i,!0))}).add([66,18,64,65],(a,i)=>{m(a,e.chRedir(0,i,!0))}).add([66,18,64,66],(a,i)=>{m(a,e.chRedir(1,i,!0))}).add([66,18,64,67],(a,i)=>{m(a,e.chRedir(2,i,!0))}).add([66,18,64,68],(a,i)=>{m(a,e.chRedir(3,i,!0))}).add([66,18,64,69],(a,i)=>{m(a,e.chRedir(4,i,!0))}).add([66,18,64,70],(a,i)=>{m(a,e.chRedir(5,i,!0))}).add([66,18,64,71],(a,i)=>{m(a,e.chRedir(6,i,!0))}).add([66,18,64,72],(a,i)=>{m(a,e.chRedir(7,i,!0))}).add([66,18,64,73],(a,i)=>{m(a,e.chRedir(8,i,!0))}).add([66,18,64,74],(a,i)=>{m(a,e.chRedir(10,i,!0))}).add([66,18,64,75],(a,i)=>{m(a,e.chRedir(11,i,!0))}).add([66,18,64,76],(a,i)=>{m(a,e.chRedir(12,i,!0))}).add([66,18,64,77],(a,i)=>{m(a,e.chRedir(13,i,!0))}).add([66,18,64,78],(a,i)=>{m(a,e.chRedir(14,i,!0))}).add([66,18,64,79],(a,i)=>{m(a,e.chRedir(15,i,!0))}),t(this,be).add([54,65],(a,i)=>{e.switchMode("x5d");let c=(a[1]<<7)+a[0],n=(a[3]<<7)+a[2],s=e.chRedir(c&15,i,!0),o=E.cc*s;[()=>{n<1||(n<101?(e.setChType(s,e.CH_MELODIC,C.x5d),t(e,D)[s]=n-1,t(e,u)[o+y[0]]=82):n<229?(e.setChType(s,e.CH_MELODIC,C.x5d),t(e,D)[s]=n-101,t(e,u)[o+y[0]]=56):(e.setChType(s,e.CH_DRUMS,C.x5d),t(e,D)[s]=Mt[n-229]||0,t(e,u)[o+y[0]]=62)),e.dispatchEvent("voice",{part:s})},()=>{t(e,u)[o+y[7]]=n},()=>{n<31&&(t(e,u)[o+y[10]]=Math.round((n-15)*4.2+64))},()=>{t(e,u)[o+y[93]]=Fe(n)},()=>{t(e,u)[o+y[91]]=Fe(n)},()=>{t(e,x)[s*E.rpn+3]=n>8191?n-16320:64+n},()=>{t(e,x)[s*E.rpn+1]=n>8191?n-16320:64+n},()=>{n>0&&(t(e,x)[s*E.rpn]=n)},()=>{}][c>>4]()}).add([54,76,0],(a,i)=>{e.switchMode("x5d",!0);let c="",n=82,s=0,o=0,f="MSB PRG LSB NME";ie(a,function(l,b){if(b<16400){let v=b%164;switch(!0){case v<10:{l>31&&(c+=String.fromCharCode(l));break}case v==11:{f+=` +${n} ${s} ${o} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}s>99&&(n=90,s=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(f),A()&&console.debug(f),e.forceVoiceRefresh()}).add([54,77,0],(a,i)=>{e.switchMode("x5d",!0);let c="",n=90,s=0,o=0,f="MSB PRG LSB NME";ie(a,function(l,b){if(b<13600){let v=b%136;switch(!0){case v<10:{l>31&&(c+=String.fromCharCode(l));break}case v==11:{f+=` +${n} ${s} ${o} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f),A()&&console.debug(f),e.forceVoiceRefresh()}).add([54,78],(a,i)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,i)=>{e.switchMode("x5d",!0),ie(a,(c,n)=>{n>0&&n<3&&(e.setEffectType(n-1,44,c),e.dispatchEvent(`efx${["reverb","chorus"][n-1]}`,e.getEffectType(n-1)))})}).add([54,104],(a,i)=>{e.switchMode("x5d",!0),ie(a,function(c,n,s,o){if(n<192){let f=e.chRedir(Math.floor(n/12),i,!0),l=f*E.cc;switch(n%12){case 0:{c<128?(e.setChType(f,e.CH_MELODIC,C.x5d),t(e,u)[l+y[0]]=82,t(e,D)[f]=c):(e.setChType(f,e.CH_DRUMS,C.x5d),t(e,u)[l+y[0]]=62,t(e,D)[f]=Mt[c-128]),c>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{t(e,u)[l+y[7]]=c;break}case 2:{t(e,x)[f*E.rpn+3]=c>127?c-192:64+c;break}case 3:{t(e,x)[f*E.rpn+1]=c>127?c-192:64+c;break}case 4:{c<31&&(t(e,u)[l+y[10]]=Math.round((c-15)*4.2+64));break}case 5:{let b=c>>4,v=c&15;t(e,u)[l+y[91]]=Fe(v),t(e,u)[l+y[93]]=Fe(b);break}case 10:break;case 11:{let b=e.chRedir(c&15,i,!0),v=c>>4;t(e,G)[f]=c,(b!=f||v)&&(console.info(`X5D Part CH${f+1} receives from CH${b+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(n-192,i,!0)}})}),t(this,ee).add([22,18,127],a=>{e.switchMode("mt32",!0),w(e,P,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,i,c)=>{e.switchMode("mt32");let n=e.chRedir(c,i,!0),s=a[1];a.subarray(2).forEach((o,f)=>{let l=f+s;t(e,ge)[l+(n-1)*16]=o,([!1,()=>{let b=t(e,ge)[n-1<<4];if(b<3){if(t(e,oe)[n]=1,b==2)for(let v=0;v{t(e,x)[n*E.rpn+3]=o+40},()=>{t(e,x)[n*E.rpn+1]=o+14},()=>{t(e,x)[n*E.rpn]=o},!1,()=>{t(e,u)[E.cc*n+y[91]]=o?127:0},!1,()=>{t(e,u)[E.cc*n+y[7]]=o},()=>{t(e,u)[E.cc*n+y[10]]=Math.ceil(o*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(a,i,c)=>{e.switchMode("mt32");let n=c&7;console.debug(`MT-32 slot #${c+1} Drum: ${a}`);let s=a[0]<<7|a[1];a.subarray(2).forEach((o,f)=>{let l=f+s,b=(l>>2)+24,v=l&3,S=n*E.dpn;if(A()&&console.debug(`MT-32 temp drum note ${b} param ${v}: ${o}`),b<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${b}`);return}[()=>{},()=>{t(e,V)[(S+te[26])*E.dnc+b]=Math.round(o*1.27)},()=>{t(e,V)[(S+te[26])*E.dnc+b]=o*9+1&127},()=>{t(e,V)[(S+te[26])*E.dnc+b]=o?127:0}][v]()})}).add([22,18,2],(a,i,c)=>{e.switchMode("mt32");let n=e.chRedir(c,i,!0),s=a[1]+(a[0]<<7);s<10&&(t(e,oe)[n]=1),a.subarray(2).forEach((o,f)=>{let l=f+s;l<14&&(t(e,ae)[(n-1)*E.cmt+l]=o)}),e.dispatchEvent("voice",{part:n})}).add([22,18,3],(a,i,c)=>{e.switchMode("mt32");let n=c&7;if(a[0]){let s=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((o,f)=>{let l=f+s,b=(l>>2)+24,v=l&3,S=n*E.dpn;if(A()&&console.debug(`MT-32 dev drum note ${b} param ${v}: ${o}`),b<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${b}`);return}[()=>{},()=>{t(e,V)[(S+te[26])*E.dnc+b]=Math.round(o*1.27)},()=>{t(e,V)[(S+te[26])*E.dnc+b]=o*9+1&127},()=>{t(e,V)[(S+te[26])*E.dnc+b]=o?127:0}][v]()})}else{let s=a[1];a.subarray(2).forEach((o,f)=>{let l=f+s;t(e,ge)[l]=o;let b=e.chRedir(1+(l>>4),i,!0),v=l&15;([!1,()=>{let S=t(e,ge)[b-1<<4];if(S<3)if(t(e,oe)[b]=1,S==2)for(let R=0;R{t(e,x)[b*E.rpn+3]=o+40},()=>{t(e,x)[b*E.rpn+1]=o+14},()=>{t(e,x)[b*E.rpn]=o},!1,()=>{t(e,u)[E.cc*b+y[91]]=o?127:0},!1,()=>{t(e,u)[E.cc*b+y[7]]=o},()=>{t(e,u)[E.cc*b+y[10]]=Math.ceil(o*9.05)}][v]||(()=>{}))()})}}).add([22,18,4],(a,i,c)=>{e.switchMode("mt32");let n=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((o,f)=>{let l=f+n,b=e.chRedir(Math.floor(l/246+1),i,!0),v=l%246;v<14&&(t(e,ae)[(b-1)*E.cmt+v]=o),v<10&&(t(e,oe)[b]=1),s.indexOf(b)<0&&s.push(b)}),s.forEach(o=>{e.dispatchEvent("voice",{part:o})})}).add([22,18,5],(a,i,c)=>{e.switchMode("mt32");let n=(a[0]<<7)+a[1];a.subarray(2).forEach((s,o)=>{let f=n+o,l=Math.floor(f/8),b=f&7,v=l*8;t(e,Le)[f]=s,([!1,()=>{let S=t(e,Le)[v];if(S<3){let R="";if(S==2){let L=E.cmt*l;R=`MT-m:${s.toString().padStart(3,"0")}`}else R=e.baseBank.get(0,s+(S<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l}),e.userBank.load(`MSB LSB PRG NME +000 127 ${l} ${R}`,!0)}}][b]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,i,c)=>{e.switchMode("mt32");let n=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((s,o)=>{let f=n+o;f>1)*E.cmt+f]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(a,i,c)=>{e.switchMode("mt32");let n=a[1],s=!1,o=function(f,l){t(e,G)[l-12]=f,s=!0};a.subarray(2).forEach((f,l)=>{let b=l+n;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,o,o,o,o,o,o,o,o,o,()=>{w(e,U,f),e.dispatchEvent("mastervolume",t(e,U))}][b]||(()=>{}))(f,l)}),s&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let i=a[1],c=" ".repeat(i);a.subarray(2).forEach(n=>{n>31?c+=String.fromCharCode(n):c+=" "}),w(e,me,c.padStart(20," ")),w(e,ve,Date.now()+3200)}).add([22,18,82],(a,i)=>{let c=e.chRedir(0,i,!0);for(let n=0;n<16;n++)t(e,B).ano(c+n),n&&n<10&&(t(e,D)[c+n]=tt[n-1]);console.info("MT-32 alt reset complete.")}),t(this,be).add([66,0],(a,i)=>{e.switchMode("ns5r",!0),w(e,P,!1),console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,i)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),w(e,P,!1)}).add([66,18,0,0],(a,i)=>{let c=a[0];switch(c){case 124:case 126:case 127:{e.switchMode("ns5r",!0),w(e,P,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(c<10){let n=[0,0,0,0],s=(o,f)=>{n[f]=o};if(a.subarray(1).forEach((o,f)=>{[s,s,s,s,()=>{w(e,U,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,U))},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][c+f]()}),a[0]<4){let o=0;n.forEach(f=>{o=o<<4,o+=f}),o-=1024}}}}).add([66,18,0,1],(a,i)=>{}).add([66,18,0,2],(a,i)=>{}).add([66,18,1],(a,i)=>{let c=e.chRedir(a[0],i,!0),n=c*E.cc,s=a[1],o=`NS5R CH${c+1} `;a.subarray(2).forEach((f,l)=>{let b=s+l;b<3?([()=>{t(e,u)[n+y[0]]=f||121},()=>{t(e,u)[n+y[32]]=f},()=>{t(e,D)[c]=f}][b](),e.dispatchEvent("voice",{part:c})):b<8||(b<14?[()=>{let v=e.chRedir(f,i,!0);t(e,G)[c]=v,c!=v&&(e.buildRchTree(),console.info(`${o}receives from CH${v+1}`))},()=>{t(e,j)[c]=+!f},()=>{e.setChType(c,f,C.ns5r),console.debug(`${o}type: ${Xe[f]}`)},()=>{t(e,x)[E.rpn*c+3]=f},()=>{},()=>{}][b-8]():b<16||(b<33?[()=>{t(e,u)[n+y[7]]=f},()=>{t(e,u)[n+y[11]]=f},()=>{},()=>{},()=>{t(e,u)[n+y[10]]=f||128},()=>{},()=>{},()=>{t(e,u)[n+y[93]]=f},()=>{t(e,u)[n+y[91]]=f},()=>{t(e,u)[n+y[76]]=f},()=>{t(e,u)[n+y[77]]=f},()=>{t(e,u)[n+y[78]]=f},()=>{t(e,u)[n+y[74]]=f},()=>{t(e,u)[n+y[71]]=f},()=>{t(e,u)[n+y[73]]=f},()=>{t(e,u)[n+y[75]]=f},()=>{t(e,u)[n+y[72]]=f}][b-16]():b<112||b<114&&[()=>{t(e,u)[n+y[5]]=f},()=>{t(e,u)[n+y[65]]=f}][b-112]()))})}).add([66,18,8,0],(a,i)=>{let c=a[0];if(c<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let n=c-32;w(e,ne,Date.now()+3200),w(e,F,10),t(e,Y,de).fill(0);let s=a.subarray(1),o=4;s.forEach(function(f,l){let b=l+n,v=b>>4,S=b&15;if(b<80){let R=v>3,L=0,X=v0;)t(e,Y,de)[S*32+v*7+(X-L)]=R&1,R=R>>1,L++}})}}).add([66,18,48],(a,i,c)=>{h(0,a)}).add([66,18,49],(a,i,c)=>{h(1,a)}).add([66,18,50],(a,i,c)=>{h(2,a)}).add([66,18,51],(a,i,c)=>{h(3,a)}).add([66,18,52],(a,i,c)=>{h(4,a)}).add([66,18,53],(a,i,c)=>{h(5,a)}).add([66,18,54],(a,i,c)=>{h(6,a)}).add([66,18,55],(a,i,c)=>{h(7,a)}).add([66,52],(a,i)=>{e.switchMode("ns5r",!0),w(e,P,!1);let c="";ie(a,(n,s)=>{s<8?(n>31&&(c+=String.fromCharCode(n)),s==7&&(e.aiEfxName=c)):s<10&&(e.setEffectType(s-8,44,n),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(a,i)=>{e.switchMode("ns5r",!0),w(e,P,!1),ie(a,function(c,n){switch(!0){case n<2944:{let s=e.chRedir(Math.floor(n/92),i,!0),o=s*E.cc;switch(n%92){case 0:{t(e,u)[o+y[0]]=c||121,e.dispatchEvent("voice",{part:s});break}case 1:{t(e,u)[o+y[32]]=c,e.dispatchEvent("voice",{part:s});break}case 2:{t(e,D)[s]=c,c>0&&e.setChActive(s,1),e.dispatchEvent("voice",{part:s});break}case 3:{let f=e.chRedir(c,i,!0);t(e,G)[s]=f,s!=f&&(console.info(`NS5R CH${s+1} receives from CH${f+1}.`),e.buildRchTree())}case 7:break;case 8:{t(e,x)[s*E.rpn+3]=c<40||c>88?c+(c>63?-192:64):c;break}case 9:case 10:{t(e,u)[o+y[7]]=c;break}case 11:{t(e,u)[o+y[11]]=c;break}case 14:{t(e,u)[o+y[10]]=c||128;break}case 19:{t(e,u)[o+y[93]]=c;break}case 20:{t(e,u)[o+y[91]]=c;break}case 84:{t(e,u)[o+y[65]]=c;break}case 85:{t(e,u)[o+y[5]]=c;break}}break}case n<3096:break;case n<3134:break;case n<8566:break}})}).add([66,54],(a,i)=>{e.switchMode("ns5r",!0);let c="",n=80,s=0,o=0,f="MSB PRG LSB NME";ie(a,function(l,b){let v=b%158;switch(!0){case v<10:{l>31&&(c+=String.fromCharCode(l));break}case v==11:{n=l&127;break}case v==12:{o=l&127;break}case v==13:{f+=` +${n} ${s} ${o} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(f),A()&&console.debug(f),e.forceVoiceRefresh()}).add([66,55],(a,i)=>{e.switchMode("ns5r",!0);let c="",n=88,s=0,o=0,f="MSB PRG LSB NME";ie(a,function(l,b){let v=b%126;switch(!0){case v<10:{l>31&&(c+=String.fromCharCode(l));break}case v==11:break;case v==12:break;case v==13:{f+=` +${n} ${s} ${o} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(f),A()&&console.debug(f),e.forceVoiceRefresh()}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let i=new Uint8Array(5760);ie(a,(c,n,s)=>{if(n<720)for(let o=0;o<8;o++)i[n*8+o]=c>>7-o&1}),e.dispatchEvent("screen",{type:"ns5r",data:i})}).add([76],(a,i,c)=>{t(e,be).run([66,...a],i,c)}),t(this,Re).add([16,0,8,0],(a,i,c)=>{let n=(a[2]<<4)+a[3],s="K11 ";([()=>{e.switchMode("k11",!0),w(e,P,!1),w(e,J,n?4:0),console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,n),console.debug(`${s}reverb type: ${n}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${s}reverb time: ${n}`)},()=>{console.debug(`${s}reverb time: ${n}`)},()=>{console.debug(`${s}reverb predelay: ${n}`)},()=>{console.debug(`${s}reverb predelay: ${n}`)},()=>{console.debug(`${s}depth high: ${n}`)},()=>{console.debug(`${s}depth high: ${n}`)},()=>{console.debug(`${s}depth low: ${n}`)},()=>{console.debug(`${s}depth low: ${n}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,i,c)=>{let n=e.chRedir(a[1],i,!0),s=E.cc*n,o=E.rpn*n,f=(a[3]<<4)+a[4],l=`K11 CH${n+1} `;([()=>{f<128?(e.setChType(n,e.CH_MELODIC,C.k11),t(e,u)[s+y[0]]=0,t(e,D)[n]=f):(e.setChType(n,e.CH_DRUMS,C.k11),t(e,D)[n]=f-128),e.dispatchEvent("voice",{part:n})},()=>{let b=e.chRedir(f,i,!0);t(e,G)[n]=b,n!=b&&(e.buildRchTree(),console.info(`${l}receives from CH${b+1}`))},()=>{t(e,u)[s+y[7]]=f},()=>{uupThis.setChActive(n,f)},()=>{t(e,u)[s+y[10]]=f},()=>{t(e,x)[o+3]=f+40},()=>{t(e,x)[o+1]=f>>1,t(e,x)[o+2]=f&1},()=>{t(e,u)[s+y[91]]=f?127:0},()=>{},()=>{t(e,u)[s+y[74]]=f},()=>{t(e,u)[s+y[73]]=f},()=>{t(e,u)[s+y[72]]=f}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,i,c)=>{let n=(a[2]<<4)+a[3],s="GMLX ";([()=>{console.debug(`${s}reverb type: ${n}`)},()=>{console.debug(`${s}reverb time: ${n}`)},()=>{console.debug(`${s}reverb predelay: ${n}`)},()=>{console.debug(`${s}depth high: ${n}`)},()=>{console.debug(`${s}depth low: ${n}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,i,c)=>{let n=(a[2]<<4)+a[3],s=e.chRedir(a[1],i,!0),o=s*E.cc;[()=>{n<128?(e.setChType(s,e.CH_MELODIC,C.k11),t(e,u)[o+y[0]]=0,t(e,u)[o+y[32]]=0,t(e,D)[s]=n):n<160?(e.setChType(s,e.CH_MELODIC,C.k11),t(e,u)[o+y[0]]=0,t(e,u)[o+y[32]]=7,t(e,D)[s]=n-100):(e.setChType(s,e.CH_DRUMS,C.k11),t(e,u)[o+y[0]]=122,t(e,u)[o+y[32]]=0,t(e,D)[s]=n-160),e.dispatchEvent("voice",{part:s})},()=>{let f=e.chRedir(n,i,!0);t(e,G)[s]=f,s!=f&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${f+1}`))}][a[0]]()}).add([16,0,9,4],(a,i,c)=>{let n=(a[2]<<4)+a[3],s=e.chRedir(a[1],i,!0),o=s*E.cc,f=s*E.rpn,l=`GMLX CH${s+1} `;[()=>{e.setChActive(s,n)},()=>{t(e,u)[o+y[7]]=n},()=>{t(e,u)[o+y[10]]=n},()=>{t(e,u)[o+y[91]]=n?127:0},()=>{t(e,x)[f+3]=n+40},()=>{t(e,x)[f+1]=n},()=>{t(e,x)[f]=n},()=>{}][a[0]]()}),t(this,Oe).add([66,93,64],(a,i,c)=>{let n=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{w(e,U,n*129/16383*100),e.dispatchEvent("mastervolume",t(e,U));break}case 5:{n-64;break}case 6:{console.debug(`SG global reverb: ${n?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(a[1]){case 48:{console.debug(`SG reverb type: ${Ze[n]}`);break}}break}default:if(a[0]>>4==1){let s=e.chRedir(a[0]&15,i,!0);if(a[1]==2){let o=e.chRedir(n,i,!0);t(e,G)[s]=o,s!=o&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${o+1}`))}else a[1]==19&&(t(e,u)[E.cc*s+y[7]]=n)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,De).add([9],(a,i,c)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),t(this,Z).add([127,0],(a,i,c)=>{e.switchMode("motif");let n=new Uint8Array([127,1,...a]);t(e,Z).run(n,i,c)}).add([127,1,0,0],(a,i,c)=>{e.switchMode("s90es");let n="S90/Motif ES system ",s=a[0];a.subarray(1).forEach((o,f)=>{([()=>{w(e,U,o*12900/16383),e.dispatchEvent("mastervolume",t(e,U))}][s+f]||(()=>{console.info(`Unrecognized ${n}ID: ${s+f}`)}))()})}).add([127,1,0,0,14],(a,i,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk header ",s=[];s[95]=(o,f,l)=>{console.debug(`${n}multi edit buffer: ${o[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,i,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk footer ",s=[];s[95]=(o,f,l)=>{console.debug(`${n}multi edit buffer: ${o[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,i,c)=>{e.switchMode("s90es");let n=e.chRedir(a[0],i,!0),s=E.cc*n,o=a[1],f=`S90/Motif ES bulk CH${n<16?n+1:"U"+(n-95)} `;console.debug(f,a),!(a[0]>15)&&a.subarray(2).forEach((l,b)=>{([()=>{t(e,u)[s+y[0]]=l,e.dispatchEvent("voice",{part:n})},()=>{l&&e.setChActive(n,1),t(e,u)[s+y[32]]=l,e.setChType(n,[32,40].indexOf(l)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,O),!0),e.dispatchEvent("voice",{part:n})},()=>{l&&e.setChActive(n,1),t(e,D)[n]=l,e.dispatchEvent("voice",{part:n})},()=>{let v=e.chRedir(l,i,!0);t(e,G)[n]=v,n!=v&&(e.buildRchTree(),console.info(`${f}receives from CH${v+1}`))},()=>{t(e,j)[n]=l?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{t(e,u)[s+y[7]]=l},()=>{t(e,u)[s+y[10]]=l},!1,!1,!1,()=>{t(e,u)[s+y[91]]=l},()=>{t(e,u)[s+y[93]]=l},()=>{t(e,u)[s+y[94]]=l},()=>{t(e,u)[s+y[128]]=l},()=>{},()=>{t(e,u)[s+y[74]]=l},()=>{t(e,u)[s+y[71]]=l},!1,()=>{t(e,u)[s+y[65]]=l},()=>{t(e,u)[s+y[5]]=l},()=>{}][o+b]||(()=>{}))()})}).add([127,1,54,16],(a,i,c)=>{e.switchMode("s90es");let n=a[0];a.subarray(1).forEach((s,o)=>{let l=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let b=s-64},()=>{let b=Ue[s]},()=>{let b=s/10},()=>{let b=s}][n+o&3]||(()=>{}))()})}),t(this,ee).add([0,72,18,0,0,0,0],(a,i,c)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,i,c)=>{let n=a[0]>>5,s=a[0]&31;switch(n){case 0:{console.debug(`Unknown SD-90 global effects message: +%o`,a);break}case 1:{let o=e.chRedir(s,i,!0),f=a[1],l=o*E.cc;a.subarray(2).forEach((b,v)=>{let S=f+v;S<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,u)[l+y[0]]=b,b){case 104:case 105:case 106:case 107:case 120:{t(e,M)[o]||e.setChType(o,e.CH_DRUMS);break}default:t(e,M)[o]&&e.setChType(o,e.CH_MELODIC)}e.dispatchEvent("voice",{part:o})},()=>{t(e,u)[l+y[32]]=b,e.dispatchEvent("voice",{part:o})},()=>{t(e,D)[o]=b,e.dispatchEvent("voice",{part:o})},()=>{t(e,u)[l+y[7]]=b},()=>{t(e,u)[l+y[10]]=b},()=>{},()=>{},()=>{b<2&&(t(e,j)[o]=b)},()=>{b<2&&(t(e,u)[l+y[68]]=b?127:0)},()=>{},()=>{b<2&&(t(e,u)[l+y[65]]=b?127:0)},()=>{t(e,u)[l+y[5]]=b&15<<4|t(e,u)[l+y[5]]&15},()=>{t(e,u)[l+y[5]]=b&15|(t(e,u)[l+y[5]]&240)>>4},()=>{t(e,u)[l+y[74]]=b},()=>{t(e,u)[l+y[71]]=b},()=>{t(e,u)[l+y[73]]=b},()=>{t(e,u)[l+y[72]]=b},0,0,0,0,0,0,0,()=>{t(e,u)[l+y[128]]=b},()=>{t(e,u)[l+y[93]]=b},()=>{t(e,u)[l+y[91]]=b},0,0,()=>{t(e,u)[l+y[75]]=b},()=>{t(e,u)[l+y[76]]=b},()=>{t(e,u)[l+y[77]]=b},()=>{t(e,u)[l+y[78]]=b}][S]||(()=>{}))():S<63||(S<64?t(e,M)[o]?t(e,u)[l+y[0]]=104|b:t(e,u)[l+y[0]]=96|b:console.debug(`Unknown SD-90 global CH${o+1} param setup message: +%o`,a))});break}case 2:{let o=e.chRedir(s,i,!0),f=a[1];console.debug(`Unknown SD-90 global CH${o+1} MIDI setup message: %o`,a.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,a)}})}chRedir(e,s,f){if(t(this,Ee)[s])return(t(this,Ee)[s]-1)*16+e;if([2,3].indexOf(t(this,j))>-1){if(f==1)return e;let d=0,a=!0;for(;a;)t(this,fe)[e+d]==0?(t(this,fe)[e+d]=s,console.debug(`Assign track ${s} to channel ${e+d+1}.`),a=!1):t(this,fe)[e+d]==s?a=!1:(d+=16,d>=128&&(d=0,a=!1));return e+d}else return e}buildRchTree(){let e=[];t(this,H).forEach((s,f)=>{var d;(d=e[s])!=null&&d.constructor||(e[s]=[]),e[s].push(f)}),E(this,Ke,e)}getActive(){let e=t(this,U).slice();return t(this,T)==v.mt32,e}getCc(e){let s=e*y.cc,f=t(this,u).subarray(s,s+y.cc);return f[p[0]]=f[p[0]]||t(this,ye),f[p[32]]=f[p[32]]||t(this,j),f}getCcCh(e,s){if(Xe.indexOf(s)<0)throw new Error("CC number not accepted");return t(this,u)[y.cc*e+p[s]]}getCcAll(){let e=t(this,u).slice();for(let s=0;s0&&!d&&(t(this,u)[e*y.cc+p[0]]=we[f])}getPitch(){return t(this,pe)}getProgram(){return t(this,R)}getTexts(){return t(this,z).slice()}getVel(e){let s=new Map,f=this;return t(f,A).forEach(function(d,a){let r=Math.floor(d/128),c=d%128;e==r&&t(f,P)[d]>0&&s.set(c,{v:t(f,P)[d],s:t(f,N)[a]})}),s}getBitmap(){return{bitmap:t(this,Q,ce),expire:t(this,ae)}}getLetter(){return{text:t(this,ie),expire:t(this,$e)}}getMode(){return ne[t(this,T)]}getMaster(){return{volume:t(this,O)}}getRawStrength(){let e=this;return t(this,A).forEach(function(s){let f=Math.floor(s/128);t(e,P)[s]>t(e,re)[f]&&(t(e,re)[f]=t(e,P)[s])}),t(this,re)}getStrength(){let e=[],s=this;return this.getRawStrength().forEach(function(f,d){e[d]=Math.floor(f*t(s,u)[d*y.cc+p[7]]*t(s,u)[d*y.cc+p[11]]*t(s,O)/803288)}),e}getRpn(){return t(this,x)}getNrpn(){return t(this,Ue)}getVoice(e,s,f,d){let a=e||t(this,ye),r=s,c=f||t(this,j);ne[t(this,T)]=="ns5r"&&a>0&&a<56&&(c=3);let n=this.userBank.get(a,r,c,d);if(ne[t(this,T)]=="mt32"&&n.name.indexOf("MT-m:")==0){let i=parseInt(n.name.slice(5)),o=i*y.cmt,h="";t(this,ge).subarray(o,o+10).forEach(l=>{l>31&&(h+=String.fromCharCode(l))}),this.userBank.load(`MSB LSB PRG -0 127 ${r} ${h}`,!0),n.name=h,n.ending=" "}return(n.ending!=" "||!n.name.length)&&(n=this.baseBank.get(a,r,c,d)),n}getChVoice(e){let s=this.getVoice(t(this,u)[e*y.cc+p[0]],t(this,R)[e],t(this,u)[e*y.cc+p[32]],ne[t(this,T)]);if(t(this,se)[e])switch(t(this,T)){case v.mt32:s.ending="~",s.name="",t(this,J).subarray(14*(e-1),14*(e-1)+10).forEach(f=>{f>31&&(s.name+=String.fromCharCode(f))})}return s}getPitchShift(e){let s=e*y.rpn;return t(this,pe)[e]/8192*t(this,x)[s]+(t(this,x)[s+3]-64)+((t(this,x)[s+1]<<7)+t(this,x)[s+2]-8192)/8192}getEffectType(e=0){let s=3*e+1;return t(this,V).subarray(s,s+2)}setEffectTypeRaw(e=0,s,f){let d=3*e;t(this,V)[d]=1,t(this,V)[d+1+ +s]=f}setEffectType(e=0,s,f){this.setEffectTypeRaw(e,!1,s),this.setEffectTypeRaw(e,!0,f)}getEffectSink(){return t(this,Ae)}setLetterDisplay(e,s,f=0,d=3200){let a=this,r;E(a,ie," ".repeat(f)),e.forEach(c=>{E(a,ie,t(a,ie)+String.fromCharCode(c>31?c:32)),c<32&&(r=r||new Set,r.add(c))}),E(a,$e,Date.now()+3200),E(a,ie,t(a,ie).padEnd(32," ")),r&&(r=Array.from(r),r.forEach((c,n,i)=>{i[n]=c.toString(16).padStart(2,"0")}),console.warn(`${s}${s?" ":""}invalid code point${r.length>1?"s":""}: 0x${r.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let s=!0,f=0;for(;s&&f=y.ace&&console.warn("ACE slots are full.")}getAce(){return t(this,le)}getChAce(e,s){if(s<0||s>=y.ace)throw new RangeError("No such ACE slot");let f=t(this,le)[s];if(f){if(Xe.indexOf(f)>=0)return t(this,u)[e*y.cc+p[f]];throw new Error(`Invalid ACE source: ${f}`)}else return 0}init(e=0){let s=this;s.dispatchEvent("mode","?"),E(s,T,0),E(s,ye,0),E(s,j,0),E(s,ke,0),t(s,U).fill(0),t(s,u).fill(0),t(s,le).fill(0),t(s,R).fill(0),t(s,P).fill(0),t(s,A).fill(0),t(s,re).fill(0),t(s,pe).fill(0),t(s,Ue).fill(0),t(s,Fe).fill(0),E(s,O,100),E(s,z,[]),E(s,Le,500),E(s,He,0),E(s,$e,0),E(s,ie,""),E(s,ae,0),E(s,K,0),t(s,Q,ce).fill(0),E(s,D,!1),E(s,Ne,0),E(s,Z,!0),t(s,H).forEach(function(f,d,a){a[d]=d}),s.buildRchTree(),e==0&&(t(s,fe).fill(0),t(s,Ee).fill(0)),t(s,u)[y.cc*9]=we[0],t(s,u)[y.cc*25]=we[0],t(s,u)[y.cc*41]=we[0],t(s,u)[y.cc*57]=we[0],t(s,C).fill(s.CH_MELODIC),t(s,C)[9]=s.CH_DRUM1,t(s,C)[25]=s.CH_DRUM3,t(s,C)[41]=s.CH_DRUMS,t(s,C)[57]=s.CH_DRUMS,t(s,C)[73]=s.CH_DRUM5,t(s,C)[89]=s.CH_DRUM7,t(s,C)[105]=s.CH_DRUMS,t(s,C)[121]=s.CH_DRUMS,t(s,Pe).fill(0),t(s,ge).fill(0),t(s,be).fill(0),t(s,J).fill(0),t(s,se).fill(0),t(s,V).fill(0),t(s,Ae).fill(0),s.aiEfxName="",s.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let f=0;f-1){if(t(f,T)==0||s){let a=t(f,T);E(f,T,d),E(f,K,0),E(f,ye,wt[0][d]),E(f,j,wt[1][d]);for(let c=0;c0&&t(f,u)[c*y.cc+p[0]]==we[a]&&(t(f,u)[c*y.cc]=we[d]);switch(f.initOnReset,d){case v.mt32:{et.forEach((c,n)=>{let i=n+1;t(f,U)[i]||(t(f,R)[i]=c,t(f,u)[i*y.cc+p[91]]=127)});break}}let r;switch(d){case v["?"]:case v.xg:{r=[1,0,65,0,5,0,0,0];break}case v.gm:case v.gs:case v.g2:case v.sd:{r=[40,4,40,18,40,32,32,0];break}case v["05rw"]:case v.x5d:case v.ns5r:{r=[44,1,44,19,44,0,44,0];break}case v.k11:case v.sg:{r=[24,0,0,0,0,0,0,0];break}case v.mt32:{r=[40,4,0,0,0,0,0,0];break}default:r=[0,0,0,0,0,0,0,0]}for(let c=0;c<4;c++)t(f,V)[3*c]||(t(f,V)[3*c+1]=r[2*c],t(f,V)[3*c+2]=r[2*c+1],f.dispatchEvent(`efx${["reverb","chorus","delay","insert"][c]}`,f.getEffectType(c)));f.dispatchEvent("mode",e)}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,re).fill(0)}runJson(e){var s;if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,Ve)[e.type].call(this,e);{let f=this.chRedir(e.part,e.track),d=!1;(s=t(this,Ke)[f])==null||s.forEach(a=>{e.channel=a,d=!0,t(this,Ve)[e.type].call(this,e)}),d||console.warn(`${vt[e.type]?vt[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${f+1} without any recipient.`)}t(this,z).length>100&&t(this,z).splice(100,t(this,z).length-99)}runRaw(e){}async loadBank(e,s){switch(e=e.toLowerCase(),e){case"s7e":{this.userBank.clearRange({msb:63,lsb:[21,22]}),this.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{ze.context=this,this.userBank.load(await ze.read(e,s));break}}}},T=new WeakMap,K=new WeakMap,ae=new WeakMap,oe=new WeakMap,Q=new WeakSet,ce=function(){return t(this,oe)[t(this,K)]},Tt=function(e){t(this,oe)[t(this,K)]=e},U=new WeakMap,H=new WeakMap,C=new WeakMap,u=new WeakMap,le=new WeakMap,R=new WeakMap,P=new WeakMap,q=new WeakMap,A=new WeakMap,N=new WeakMap,pe=new WeakMap,re=new WeakMap,ve=new WeakMap,x=new WeakMap,Ue=new WeakMap,Fe=new WeakMap,se=new WeakMap,be=new WeakMap,J=new WeakMap,Pe=new WeakMap,ge=new WeakMap,V=new WeakMap,Ae=new WeakMap,ye=new WeakMap,j=new WeakMap,O=new WeakMap,ke=new WeakMap,Le=new WeakMap,He=new WeakMap,ie=new WeakMap,$e=new WeakMap,Ne=new WeakMap,Z=new WeakMap,D=new WeakMap,Ke=new WeakMap,rt=new WeakMap,z=new WeakMap,fe=new WeakMap,Ee=new WeakMap,G=new WeakMap,Se=new WeakMap,L=new WeakMap,Ve=new WeakMap,Qe=new WeakMap,xe=new WeakMap,Ce=new WeakMap,W=new WeakMap,Y=new WeakMap,he=new WeakMap,Me=new WeakMap,Te=new WeakMap,Re=new WeakMap,Ct);export{ka as OctaviaDevice,y as allocated,p as ccToPos,Mt as dnToPos}; +%o`,a)}})}chRedir(e,r,d){if(t(this,we)[r])return(t(this,we)[r]-1)*16+e;if([2,3].indexOf(t(this,J))>-1){if(d==1)return e;let h=0,$=!0;for(;$;)t(this,pe)[e+h]==0?(t(this,pe)[e+h]=r,console.debug(`Assign track ${r} to channel ${e+h+1}.`),$=!1):t(this,pe)[e+h]==r?$=!1:(h+=16,h>=128&&(h=0,$=!1));return e+h}else return e}forceVoiceRefresh(){for(let e=0;e{var h;(h=e[r])!=null&&h.constructor||(e[r]=[]),e[r].push(d)}),w(this,Ke,e)}getActive(){return t(this,he)}getCc(e){let r=e*E.cc,d=t(this,u).subarray(r,r+E.cc);return d[y[0]]=d[y[0]]||t(this,Ee),d[y[32]]=d[y[32]]||t(this,J),d}getCcCh(e,r){if(Ve.indexOf(r)<0)throw new Error("CC number not accepted");return t(this,u)[E.cc*e+y[r]]}getCcAll(){let e=t(this,u).slice();for(let r=0;r0&&!h&&(t(this,u)[e*E.cc+y[0]]=ke[d])}setChActive(e,r=0){t(this,he)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),t(this,he)[e]=r}getPitch(){return t(this,ye)}getProgram(){return t(this,D)}getTexts(){return t(this,W).slice()}getVel(e){let r=new Map,d=this;return t(d,N).forEach(function(h,$){let p=Math.floor(h/128),m=h%128;e==p&&t(d,H)[h]>0&&r.set(m,{v:t(d,H)[h],s:t(d,_)[$]})}),r}getBitmap(){return{bitmap:t(this,Y,de),expire:t(this,ne)}}getLetter(){return{text:t(this,me),expire:t(this,ve)}}getMode(){return le[t(this,O)]}getMaster(){return{volume:t(this,U)}}getRawStrength(){let e=this;return t(this,N).forEach(function(r){let d=Math.floor(r/128);t(e,H)[r]>t(e,ce)[d]&&(t(e,ce)[d]=t(e,H)[r])}),t(this,ce)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(d,h){e[h]=Math.floor(d*t(r,u)[h*E.cc+y[7]]*t(r,u)[h*E.cc+y[11]]*t(r,U)/803288)}),e}getRpn(){return t(this,x)}getNrpn(){return t(this,Pe)}getVoice(e,r,d,h){let $=e||t(this,Ee),p=r,m=d||t(this,J);le[t(this,O)]=="ns5r"&&$>0&&$<56&&(m=3);let a=this.userBank.get($,p,m,h);if(le[t(this,O)]=="mt32"&&a.name.indexOf("MT-m:")==0){let i=parseInt(a.name.slice(5)),c=i*E.cmt,n="";t(this,$e).subarray(c,c+10).forEach(s=>{s>31&&(n+=String.fromCharCode(s))}),this.userBank.load(`MSB LSB PRG +0 127 ${p} ${n}`,!0),a.name=n,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get($,p,m,h)),a}getChVoice(e){let r=this.getVoice(t(this,u)[e*E.cc+y[0]],t(this,D)[e],t(this,u)[e*E.cc+y[32]],le[t(this,O)]);if(t(this,oe)[e])switch(t(this,O)){case C.mt32:r.ending="~",r.name="",t(this,ae).subarray(14*(e-1),14*(e-1)+10).forEach(d=>{d>31&&(r.name+=String.fromCharCode(d))})}return r}getPitchShift(e){let r=e*E.rpn;return t(this,ye)[e]/8192*t(this,x)[r]+(t(this,x)[r+3]-64)+((t(this,x)[r+1]<<7)+t(this,x)[r+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return t(this,q).subarray(r,r+2)}setEffectTypeRaw(e=0,r,d){let h=3*e;t(this,q)[h]=1,t(this,q)[h+1+ +r]=d}setEffectType(e=0,r,d){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,d)}getEffectSink(){return t(this,He)}setLetterDisplay(e,r,d=0,h=3200){let $=this,p;w($,me," ".repeat(d)),e.forEach(m=>{w($,me,t($,me)+String.fromCharCode(m>31?m:32)),m<32&&(p=p||new Set,p.add(m))}),w($,ve,Date.now()+h),p&&(p=Array.from(p),p.forEach((m,a,i)=>{i[a]=m.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${p.length>1?"s":""}: 0x${p.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let r=!0,d=0;for(;r&&d=E.ace&&console.warn("ACE slots are full.")}getAce(){return t(this,ue)}getChAce(e,r){if(r<0||r>=E.ace)throw new RangeError("No such ACE slot");let d=t(this,ue)[r];if(d){if(Ve.indexOf(d)>=0)return t(this,u)[e*E.cc+y[d]];throw new Error(`Invalid ACE source: ${d}`)}else return 0}initDrums(){let e=this;t(e,V).fill(64);for(let r=0;r-1){if(t(d,O)==0||r){let $=t(d,O);d.initOnReset&&r&&this.init(1),w(d,O,h),w(d,F,0),w(d,Ee,wt[0][h]),w(d,J,wt[1][h]);for(let m=0;m0&&t(d,u)[m*E.cc+y[0]]==ke[$]&&(t(d,u)[m*E.cc]=ke[h]);switch(h){case C.mt32:{tt.forEach((m,a)=>{let i=a+1;t(d,he)[i]||(t(d,D)[i]=m,t(d,u)[i*E.cc+y[91]]=127)});for(let m=1;m<10;m++)d.dispatchEvent("voice",{part:m});break}}let p;switch(h){case C["?"]:case C.xg:{p=[1,0,65,0,5,0,0,0];break}case C.gm:case C.gs:case C.g2:case C.sd:{p=[40,4,40,18,40,32,32,0];break}case C["05rw"]:case C.x5d:case C.ns5r:{p=[44,1,44,19,44,0,44,0];break}case C.k11:case C.sg:{p=[24,0,0,0,0,0,0,0];break}case C.mt32:{p=[40,4,0,0,0,0,0,0];break}default:p=[0,0,0,0,0,0,0,0]}for(let m=0;m<4;m++)t(d,q)[3*m]||(t(d,q)[3*m+1]=p[2*m],t(d,q)[3*m+2]=p[2*m+1],d.dispatchEvent(`efx${["reverb","chorus","delay","insert"][m]}`,d.getEffectType(m)));d.dispatchEvent("mode",e),d.forceVoiceRefresh()}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,ce).fill(0)}runJson(e){var r;if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,ze)[e.type].call(this,e);{let d=this.chRedir(e.part,e.track),h=!1;(r=t(this,Ke)[d])==null||r.forEach($=>{e.channel=$,h=!0,t(this,ze)[e.type].call(this,e)}),h||console.warn(`${kt[e.type]?kt[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${d+1} without any recipient.`)}t(this,W).length>100&&t(this,W).splice(100,t(this,W).length-99)}runRaw(e){}async loadBank(e,r){let d=this;switch(e=e.toLowerCase(),e){case"s7e":{d.userBank.clearRange({msb:63,lsb:[21,22]}),d.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{Qe.context=this,d.userBank.load(await Qe.read(e,r));break}}d.forceVoiceRefresh()}},O=new WeakMap,F=new WeakMap,ne=new WeakMap,fe=new WeakMap,Y=new WeakSet,de=function(){return t(this,fe)[t(this,F)]},Rt=function(e){t(this,fe)[t(this,F)]=e},he=new WeakMap,G=new WeakMap,M=new WeakMap,u=new WeakMap,ue=new WeakMap,D=new WeakMap,H=new WeakMap,j=new WeakMap,N=new WeakMap,_=new WeakMap,ye=new WeakMap,ce=new WeakMap,Se=new WeakMap,x=new WeakMap,Pe=new WeakMap,V=new WeakMap,oe=new WeakMap,ge=new WeakMap,ae=new WeakMap,Le=new WeakMap,$e=new WeakMap,q=new WeakMap,He=new WeakMap,Ee=new WeakMap,J=new WeakMap,U=new WeakMap,Ce=new WeakMap,Ne=new WeakMap,Be=new WeakMap,me=new WeakMap,ve=new WeakMap,Ge=new WeakMap,re=new WeakMap,P=new WeakMap,Ke=new WeakMap,st=new WeakMap,W=new WeakMap,pe=new WeakMap,we=new WeakMap,I=new WeakMap,xe=new WeakMap,B=new WeakMap,ze=new WeakMap,qe=new WeakMap,Me=new WeakMap,Te=new WeakMap,Z=new WeakMap,ee=new WeakMap,be=new WeakMap,Re=new WeakMap,Oe=new WeakMap,De=new WeakMap,Tt);export{Sa as OctaviaDevice,E as allocated,y as ccToPos,te as dnToPos}; diff --git a/src/fakeMu/index.js b/src/fakeMu/index.js index e2c1cc4c..80d82d93 100644 --- a/src/fakeMu/index.js +++ b/src/fakeMu/index.js @@ -115,6 +115,7 @@ getBlobFrom(`list.tsv`).then(async (response) => { stDemo.forEach(function (e, i, a) { e.addEventListener("click", async function () { audioPlayer.pause(); + visualizer.device.initOnReset = false; if (!demoBlobs[e.title]?.midi) { demoBlobs[e.title] = {}; audioPlayer.src = "about:blank"; @@ -159,6 +160,7 @@ propsAud = JSON.parse('{"mimeTypes":["audio/*"],"startIn":"music","id":"audioOpe $e("#openMidi").addEventListener("click", async function () { useMidiBus = false; midwIndicator.classList.off("active"); + visualizer.device.initOnReset = false; let file = await fileOpen(propsMid); let fileSplit = file.name.lastIndexOf("."), ext = ""; if (fileSplit > -1) { @@ -187,6 +189,7 @@ $e("#openMidi").addEventListener("click", async function () { $e("#openAudio").addEventListener("click", async function () { useMidiBus = false; midwIndicator.classList.off("active"); + visualizer.device.initOnReset = false; if (audioBlob) { URL.revokeObjectURL(audioBlob); }; @@ -195,6 +198,7 @@ $e("#openAudio").addEventListener("click", async function () { }); midwIndicator.addEventListener("click", function () { stDemo.to(-1); + visualizer.device.initOnReset = true; if (audioBlob) { URL.revokeObjectURL(audioBlob); }; diff --git a/src/fakeNs5r/index.js b/src/fakeNs5r/index.js index d97e431a..bc84549c 100644 --- a/src/fakeNs5r/index.js +++ b/src/fakeNs5r/index.js @@ -86,6 +86,7 @@ getBlobFrom(`list.tsv`).then(async (response) => { stDemo.forEach(function (e, i, a) { e.addEventListener("click", async function () { audioPlayer.pause(); + visualizer.device.initOnReset = false; visualizer.device.setLetterDisplay(codepointArray(`\x8a${demoPool.data[i].artist.slice(0, 15).padEnd(15, " ")}\x8b${demoPool.data[i].title.slice(0, 15)}`)); if (!demoBlobs[e.title]?.midi) { demoBlobs[e.title] = {}; @@ -130,6 +131,7 @@ propsAud = JSON.parse('{"mimeTypes":["audio/*"],"startIn":"music","id":"audioOpe $e("#openMidi").addEventListener("click", async function () { useMidiBus = false; midwIndicator.classList.off("active"); + visualizer.device.initOnReset = false; let file = await fileOpen(propsMid); let fileSplit = file.name.lastIndexOf("."), ext = ""; if (fileSplit > -1) { @@ -158,6 +160,7 @@ $e("#openMidi").addEventListener("click", async function () { $e("#openAudio").addEventListener("click", async function () { useMidiBus = false; midwIndicator.classList.off("active"); + visualizer.device.initOnReset = false; if (audioBlob) { URL.revokeObjectURL(audioBlob); }; @@ -169,6 +172,7 @@ midwIndicator.addEventListener("click", function () { if (audioBlob) { URL.revokeObjectURL(audioBlob); }; + visualizer.device.initOnReset = true; audioBlob = null; audioPlayer.src = ""; visualizer.reset(); diff --git a/src/fakePsr/index.js b/src/fakePsr/index.js index c186c7c1..f6769f4a 100644 --- a/src/fakePsr/index.js +++ b/src/fakePsr/index.js @@ -116,6 +116,7 @@ getBlobFrom(`list.tsv`).then(async (response) => { stDemo.forEach(function (e, i, a) { e.addEventListener("click", async function () { audioPlayer.pause(); + visualizer.device.initOnReset = false; if (!demoBlobs[e.title]?.midi) { demoBlobs[e.title] = {}; audioPlayer.src = "about:blank"; @@ -217,6 +218,7 @@ propsAud = JSON.parse('{"mimeTypes":["audio/*"],"startIn":"music","id":"audioOpe $e("#openMidi").addEventListener("click", async function () { useMidiBus = false; midwIndicator.classList.off("active"); + visualizer.device.initOnReset = false; let file = await fileOpen(propsMid); let fileSplit = file.name.lastIndexOf("."), ext = ""; if (fileSplit > -1) { @@ -245,6 +247,7 @@ $e("#openMidi").addEventListener("click", async function () { $e("#openAudio").addEventListener("click", async function () { useMidiBus = false; midwIndicator.classList.off("active"); + visualizer.device.initOnReset = false; if (audioBlob) { URL.revokeObjectURL(audioBlob); }; @@ -253,6 +256,7 @@ $e("#openAudio").addEventListener("click", async function () { }); midwIndicator.addEventListener("click", function () { stDemo.to(-1); + visualizer.device.initOnReset = true; if (audioBlob) { URL.revokeObjectURL(audioBlob); }; diff --git a/src/fakeQy/index.js b/src/fakeQy/index.js index b8f5f267..cecaac48 100644 --- a/src/fakeQy/index.js +++ b/src/fakeQy/index.js @@ -86,6 +86,7 @@ getBlobFrom(`list.tsv`).then(async (response) => { stDemo.forEach(function (e, i, a) { e.addEventListener("click", async function () { audioPlayer.pause(); + visualizer.device.initOnReset = false; visualizer.device.setLetterDisplay(codepointArray(`\x8a${demoPool.data[i].artist.slice(0, 15).padEnd(15, " ")}\x8b${demoPool.data[i].title.slice(0, 15)}`)); if (!demoBlobs[e.title]?.midi) { demoBlobs[e.title] = {}; @@ -131,6 +132,7 @@ propsAud = JSON.parse('{"mimeTypes":["audio/*"],"startIn":"music","id":"audioOpe $e("#openMidi").addEventListener("click", async function () { useMidiBus = false; midwIndicator.classList.off("active"); + visualizer.device.initOnReset = false; let file = await fileOpen(propsMid); let fileSplit = file.name.lastIndexOf("."), ext = ""; if (fileSplit > -1) { @@ -159,6 +161,7 @@ $e("#openMidi").addEventListener("click", async function () { $e("#openAudio").addEventListener("click", async function () { useMidiBus = false; midwIndicator.classList.off("active"); + visualizer.device.initOnReset = false; if (audioBlob) { URL.revokeObjectURL(audioBlob); }; @@ -167,6 +170,7 @@ $e("#openAudio").addEventListener("click", async function () { }); midwIndicator.addEventListener("click", function () { stDemo.to(-1); + visualizer.device.initOnReset = true; if (audioBlob) { URL.revokeObjectURL(audioBlob); };