diff --git a/dist/README.md b/dist/README.md index 185f726e..076ab3eb 100644 --- a/dist/README.md +++ b/dist/README.md @@ -6,7 +6,7 @@ Made with ❤️ by Lightingale Community. Visit our repo on [Codeberg](https://codeberg.org/ltgc/octavia/), [GitHub](https://github.com/ltgcgo/octavia/) or [GitLab](https://gitlab.com/ltgc/oss/octavia/) for more info, or see the [demos in action](https://ltgcgo.github.io/octavia/test/). ## Files -Only files ending in `.mjs` are meant to be used as a library. +Only files ending in `.mjs` are meant to be used as a library. Files prefixed with `xp_` are tested to work on Windows XP (Chrome 49 and Firefox 52 ESR). * `state.mjs`: MIDI processing core. * `basic.mjs`: The bare minimum to get you started on writing visualizers. Requires `state.mjs`. diff --git a/dist/basic.mjs b/dist/basic.mjs index f555b185..a44a5ab3 100644 --- a/dist/basic.mjs +++ b/dist/basic.mjs @@ -1,7 +1,7 @@ -var F=Object.create;var L=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var j=(t,s)=>()=>(s||t((s={exports:{}}).exports,s),s.exports);var Y=(t,s,o,e)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of z(s))!Q.call(t,n)&&n!==o&&L(t,n,{get:()=>s[n],enumerable:!(e=K(s,n))||e.enumerable});return t};var W=(t,s,o)=>(o=t!=null?F(q(t)):{},Y(s||!t||!t.__esModule?L(o,"default",{value:t,enumerable:!0}):o,t));var G=j((Je,R)=>{(function(){"use strict";let t={fatal:!0},s=[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")],o={debug:!1,parse:function(e,n){if(e instanceof Uint8Array)return o.Uint8(e);if(typeof e=="string")return o.Base64(e);if(e instanceof HTMLElement&&e.type==="file")return o.addListener(e,n);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(e,n){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;n=n||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 c=new FileReader;c.readAsArrayBuffer(r.target.files[0]),c.onload=function(f){n(o.Uint8(new Uint8Array(f.target.result)))}})},Base64:function(e){let n=function(f){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(f=f.replace(/^.*?base64,/,""),f=String(f).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(f))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");f+="==".slice(2-(3&f.length));let u,h="",a,i,l=0;for(;l>16&255):i===64?String.fromCharCode(u>>16&255,u>>8&255):String.fromCharCode(u>>16&255,u>>8&255,255&u);return h}(e=String(e));var r=n.length;let c=new Uint8Array(new ArrayBuffer(r));for(let f=0;f{i[p]=this.readInt(1)});for(let g=0;g191||m>127&&m<160)throw new RangeError(`Invalid code point: ${m}`)}l=!0,console.debug(`String byte sequence in ${s[g].encoding}`)}catch(p){console.debug(`SMF string ${p}`)}return d||"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 d=1;d<=l.length;d++)a+=l[l.length-d]*Math.pow(128,d);a+=i}return a}};if(n.data=new DataView(c.buffer,c.byteOffset,c.byteLength),n.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;n.readInt(4);let r={};r.formatType=n.readInt(2),r.tracks=n.readInt(2),r.track=[];var c=n.readInt(1),f=n.readInt(1);128<=c?(r.timeDivision=[],r.timeDivision[0]=c-128,r.timeDivision[1]=f):r.timeDivision=256*c+f;for(let a=1;a<=r.tracks;a++){r.track[a-1]={event:[]};var b,u=n.readInt(4);if(u===-1)break;if(u!==1297379947)return!1;n.readInt(4);let i=0,l=!1,d,g;for(;!l&&(i++,r.track[a-1].event[i-1]={},r.track[a-1].event[i-1].deltaTime=n.readIntVLV(),(d=n.readInt(1))!==-1);)if(128<=d?g=d:(d=g,n.movePointer(-1)),d===255){r.track[a-1].event[i-1].type=255,r.track[a-1].event[i-1].metaType=n.readInt(1);var h=n.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=n.readStr(h);break;case 33:case 89:case 81:r.track[a-1].event[i-1].data=n.readInt(h);break;case 84:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=n.readInt(1),r.track[a-1].event[i-1].data[1]=n.readInt(1),r.track[a-1].event[i-1].data[2]=n.readInt(1),r.track[a-1].event[i-1].data[3]=n.readInt(1),r.track[a-1].event[i-1].data[4]=n.readInt(1);break;case 88:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=n.readInt(1),r.track[a-1].event[i-1].data[1]=n.readInt(1),r.track[a-1].event[i-1].data[2]=n.readInt(1),r.track[a-1].event[i-1].data[3]=n.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,n,h)),this.customInterpreter!==null&&r.track[a-1].event[i-1].data!==!1||(n.readInt(h),r.track[a-1].event[i-1].data=n.readInt(h),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((d=d.toString(16).split(""))[1]||d.unshift("0"),r.track[a-1].event[i-1].type=parseInt(d[0],16),r.track[a-1].event[i-1].channel=parseInt(d[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,n,!1)),this.customInterpreter!==null&&r.track[a-1].event[i-1].data!==!1||(b=n.readIntVLV(),r.track[a-1].event[i-1].data=n.readInt(b),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]=n.readInt(1),r.track[a-1].event[i-1].data[1]=n.readInt(1);break;case 12:case 13:r.track[a-1].event[i-1].data=n.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,n,!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 R<"u")R.exports=o;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=o}})()});var T=class{#e={};addEventListener(t,s){this.#e[t]||(this.#e[t]=[]),this.#e[t].unshift(s)}removeEventListener(t,s){if(this.#e[t]){let o=this.#e[t].indexOf(s);o>-1&&this.#e[t].splice(o,1),this.#e[t].length<1&&delete this.#e[t]}}dispatchEvent(t,s){let o=new Event(t),e=this;o.data=s,this.#e[t]?.length>0&&this.#e[t].forEach(function(n){try{n?.call(e,o)}catch(r){console.error(r)}}),this[`on${t}`]&&this[`on${t}`](o)}};var P=class{#e={};context;set(t,s){this.#e[t]=s}has(t){return!!this.#e[t]}async read(t,s){if(!this.has(t))throw new Error(`No decoder registered for "${t}"`);return await this.#e[t].call(this.context||this,s)}};var Z=function(t,s){let o=!0;return s.forEach((e,n)=>{o=o&&t[n]==e}),o},U=function(t){let s=0;return t.forEach(o=>{s*=256,s+=o}),s},w=new TextDecoder,N=new P;N.set("s7e",async function(t){let s=new Uint8Array(await t.slice(0,65536).arrayBuffer()),o="MSB LSB PRG NME",e=[0,0,0,0],n=32,r=0,c=0,f=!0,b=[],u=0;for(;f;){let h=s.subarray(r);([()=>{w.decode(h.subarray(0,4))=="YSFC"?(r+=80,c=1):r++},()=>{if(Z(h.subarray(0,4),e))b.forEach((a,i,l)=>{let d=U(s.subarray(a.start+4,a.start+8));a.length=d}),c=2;else{let a=w.decode(h.subarray(0,4)),i=U(h.subarray(4,8));b.push({type:a,start:i}),r+=8}},()=>{let a=b[u],i=s.subarray(a.start,a.start+a.length),l=32;switch(a.type){case"ENVC":{let d=n;for(;d()=>(s||t((s={exports:{}}).exports,s),s.exports);var j=(t,s,o,e)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of z(s))!Q.call(t,n)&&n!==o&&L(t,n,{get:()=>s[n],enumerable:!(e=K(s,n))||e.enumerable});return t};var W=(t,s,o)=>(o=t!=null?F(q(t)):{},j(s||!t||!t.__esModule?L(o,"default",{value:t,enumerable:!0}):o,t));var _=Y((Je,R)=>{(function(){"use strict";let t={fatal:!0},s=[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")],o={debug:!1,parse:function(e,n){if(e instanceof Uint8Array)return o.Uint8(e);if(typeof e=="string")return o.Base64(e);if(e instanceof HTMLElement&&e.type==="file")return o.addListener(e,n);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(e,n){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;n=n||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 c=new FileReader;c.readAsArrayBuffer(r.target.files[0]),c.onload=function(f){n(o.Uint8(new Uint8Array(f.target.result)))}})},Base64:function(e){let n=function(f){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(f=f.replace(/^.*?base64,/,""),f=String(f).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(f))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");f+="==".slice(2-(3&f.length));let u,h="",a,i,l=0;for(;l>16&255):i===64?String.fromCharCode(u>>16&255,u>>8&255):String.fromCharCode(u>>16&255,u>>8&255,255&u);return h}(e=String(e));var r=n.length;let c=new Uint8Array(new ArrayBuffer(r));for(let f=0;f{i[p]=this.readInt(1)});for(let g=0;g191||v>127&&v<160)throw new RangeError(`Invalid code point: ${v}`)}l=!0,console.debug(`String byte sequence in ${s[g].encoding}`)}catch(p){console.debug(`SMF string ${p}`)}return d||"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 d=1;d<=l.length;d++)a+=l[l.length-d]*Math.pow(128,d);a+=i}return a}};if(n.data=new DataView(c.buffer,c.byteOffset,c.byteLength),n.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;n.readInt(4);let r={};r.formatType=n.readInt(2),r.tracks=n.readInt(2),r.track=[];var c=n.readInt(1),f=n.readInt(1);128<=c?(r.timeDivision=[],r.timeDivision[0]=c-128,r.timeDivision[1]=f):r.timeDivision=256*c+f;for(let a=1;a<=r.tracks;a++){r.track[a-1]={event:[]};var b,u=n.readInt(4);if(u===-1)break;if(u!==1297379947)return!1;n.readInt(4);let i=0,l=!1,d,g;for(;!l&&(i++,r.track[a-1].event[i-1]={},r.track[a-1].event[i-1].deltaTime=n.readIntVLV(),(d=n.readInt(1))!==-1);)if(128<=d?g=d:(d=g,n.movePointer(-1)),d===255){r.track[a-1].event[i-1].type=255,r.track[a-1].event[i-1].metaType=n.readInt(1);var h=n.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=n.readStr(h);break;case 33:case 89:case 81:r.track[a-1].event[i-1].data=n.readInt(h);break;case 84:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=n.readInt(1),r.track[a-1].event[i-1].data[1]=n.readInt(1),r.track[a-1].event[i-1].data[2]=n.readInt(1),r.track[a-1].event[i-1].data[3]=n.readInt(1),r.track[a-1].event[i-1].data[4]=n.readInt(1);break;case 88:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=n.readInt(1),r.track[a-1].event[i-1].data[1]=n.readInt(1),r.track[a-1].event[i-1].data[2]=n.readInt(1),r.track[a-1].event[i-1].data[3]=n.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,n,h)),this.customInterpreter!==null&&r.track[a-1].event[i-1].data!==!1||(n.readInt(h),r.track[a-1].event[i-1].data=n.readInt(h),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((d=d.toString(16).split(""))[1]||d.unshift("0"),r.track[a-1].event[i-1].type=parseInt(d[0],16),r.track[a-1].event[i-1].channel=parseInt(d[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,n,!1)),this.customInterpreter!==null&&r.track[a-1].event[i-1].data!==!1||(b=n.readIntVLV(),r.track[a-1].event[i-1].data=n.readInt(b),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]=n.readInt(1),r.track[a-1].event[i-1].data[1]=n.readInt(1);break;case 12:case 13:r.track[a-1].event[i-1].data=n.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,n,!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 R<"u")R.exports=o;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=o}})()});var T=class{#e={};addEventListener(t,s){this.#e[t]||(this.#e[t]=[]),this.#e[t].unshift(s)}removeEventListener(t,s){if(this.#e[t]){let o=this.#e[t].indexOf(s);o>-1&&this.#e[t].splice(o,1),this.#e[t].length<1&&delete this.#e[t]}}dispatchEvent(t,s){let o=new Event(t),e=this;o.data=s,this.#e[t]?.length>0&&this.#e[t].forEach(function(n){try{n?.call(e,o)}catch(r){console.error(r)}}),this[`on${t}`]&&this[`on${t}`](o)}};var P=class{#e={};context;set(t,s){this.#e[t]=s}has(t){return!!this.#e[t]}async read(t,s){if(!this.has(t))throw new Error(`No decoder registered for "${t}"`);return await this.#e[t].call(this.context||this,s)}};var Z=function(t,s){let o=!0;return s.forEach((e,n)=>{o=o&&t[n]==e}),o},U=function(t){let s=0;return t.forEach(o=>{s*=256,s+=o}),s},w=new TextDecoder,N=new P;N.set("s7e",async function(t){let s=new Uint8Array(await t.slice(0,65536).arrayBuffer()),o="MSB LSB PRG NME",e=[0,0,0,0],n=32,r=0,c=0,f=!0,b=[],u=0;for(;f;){let h=s.subarray(r);([()=>{w.decode(h.subarray(0,4))=="YSFC"?(r+=80,c=1):r++},()=>{if(Z(h.subarray(0,4),e))b.forEach((a,i,l)=>{let d=U(s.subarray(a.start+4,a.start+8));a.length=d}),c=2;else{let a=w.decode(h.subarray(0,4)),i=U(h.subarray(4,8));b.push({type:a,start:i}),r+=8}},()=>{let a=b[u],i=s.subarray(a.start,a.start+a.length),l=32;switch(a.type){case"ENVC":{let d=n;for(;d=b.length&&(c=3,f=!1)}][c]||(()=>{f=!1}))()}return o});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 ee=",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(","),te={};`hi*, +063 024 ${g[19].toString().padStart(3,"0")} ${p}`),d+=l}break}case"EPVC":{let d=32,g=n;for(;g=b.length&&(c=3,f=!1)}][c]||(()=>{f=!1}))()}return o});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 ee=",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(","),te={};`hi*, ka,か ki,き ku,く @@ -138,6 +138,6 @@ o,お ~, ^, _,`.split(` -`).forEach(t=>{let s=t.split(",");te[s[0]]=s[1]});var B=function(t,s,o){let e=[],n=o==!1?s.readIntVLV():o;t==0||t==127;for(let r=0;r127)return console.debug(`Early termination: ${e}`),e.pop(),s.backOne(),s.backOne(),new Uint8Array(e)}}}return new Uint8Array(e)};var ae=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"];var re=["melodic","drum","menu"];var C=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var M=[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,14,15,20,21,26,28,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157];var se={};ae.forEach((t,s)=>{se[t]=s});var x={length:M.length};M.forEach((t,s)=>{x[t]=s});var H={length:C.length};C.forEach((t,s)=>{H[t]=s});var ie={};re.forEach((t,s)=>{ie[t]=s});var We={ch:128,cc:M.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:C.length,dnc:128,ext:2,efx:7,redir:32};var I=W(G(),1);var _=class{#e=!1;constructor(t,s,o,e){this.#e=t,this.start=s,this.end=o,this.data=e}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#e}},D=class extends _{constructor(t,s,o){super(!0,t,s,o)}},X=class extends _{constructor(t,s){super(!1,t,t,s)}},O=class extends Array{#e=-1;constructor(){super(...arguments)}resetIndex(t){this.#e=-1}fresh(){this.sort(function(t,s){return t.start==s.start?0:(+(t.start>s.start)<<1)-1}),this.forEach(function(t,s){t.index=s})}step(t,s=!1){let o=[];if(s)for(let e=0;et);e++){if(this[e].endn.#e&&(o.push(r),n.#e=r.index)})}return o}getRange(t,s){t>s&&([t,s]=[s,t]);let o=[],e=-1,n=Math.ceil(Math.sqrt(this.length)),r=!0;for(let c=0;c=t&&(e=c):e=e<0?c:e;for(;r;)this[e]?.end=t&&o.push(this[e]):r=!1,e++;return o}};var ne=0xffffffffffff,V=function(t){let s=new O,o=this,e=t.timeDivision,n=120,r=new O,c=0,f=0;r.push(new D(0,ne,[120,0])),t.track.forEach(function(a){c=0,a.event.forEach(function(i){c+=i.deltaTime,i.type==255&&i?.metaType==81&&(n=6e7/i.data,r[r.length-1]&&r.push(new D(c,0xffffffffffff,[n,0])))})}),r.fresh(),r.forEach(function(a,i,l){i>0&&(l[i-1].end=a.start)});let b=120;r.forEach(function(a,i,l){i>0&&(a.end==a.start?l.splice(l.indexOf(a),1):b==a.data[0]&&(l[i-1].end=a.end,l.splice(l.indexOf(a),1)),b=a.data[0])});let u=0,h=120;return r.forEach(function(a){let i=a.start,l=i/h/e*60+u;h=a.data[0],u=l-i/h/e*60,a.data[1]=u}),console.debug("All tempo changes: ",r),n=120,c=0,f=0,t.track.forEach(function(a,i){c=0,f=0;let l=i+1;a.event.forEach(function(d,g){c+=d.deltaTime;let p=r.step(c,!0)[0];p&&(n=p.data[0],f=p.data[1]);let m={type:d.type,data:d.data,track:l,part:0};d.type>14?m.meta=d.metaType:m.part=d.channel,s.push(new X(c/n/e*60+f,m))})}),s.fresh(),self.midiEvents=s,console.debug(`Parsed a type ${t.formatType} MIDI sequence.`),s};I.default.customInterpreter=B;var E=function(t,s,o){t.addEventListener(o,e=>{s.dispatchEvent(o,e.data)})},ft=class extends T{device;#e;#n={};#f=[];#a="";#c=[];#h=[];#o=new Uint8ClampedArray(128);#u=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)}init(){this.reset(),this.#e=void 0}async loadFile(t){this.#e=V(I.default.parse(new Uint8Array(await t.arrayBuffer())))}async loadMap(t,s){let o=this,e=0,n=0,r=0,c,f;t.split(` +`).forEach(t=>{let s=t.split(",");te[s[0]]=s[1]});var B=function(t,s,o){let e=[],n=o==!1?s.readIntVLV():o;t==0||t==127;for(let r=0;r127)return console.debug(`Early termination: ${e}`),e.pop(),s.backOne(),s.backOne(),new Uint8Array(e)}}}return new Uint8Array(e)};var ae=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"];var re=["melodic","drum","menu"];var C=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var M=[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,14,15,20,21,26,28,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157];var se={};ae.forEach((t,s)=>{se[t]=s});var x={length:M.length};M.forEach((t,s)=>{x[t]=s});var H={length:C.length};C.forEach((t,s)=>{H[t]=s});var ie={};re.forEach((t,s)=>{ie[t]=s});var We={ch:128,cc:M.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:C.length,dnc:128,ext:2,efx:7,cvn:12,redir:32};var A=W(_(),1);var G=class{#e=!1;constructor(t,s,o,e){this.#e=t,this.start=s,this.end=o,this.data=e}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#e}},D=class extends G{constructor(t,s,o){super(!0,t,s,o)}},X=class extends G{constructor(t,s){super(!1,t,t,s)}},O=class extends Array{#e=-1;constructor(){super(...arguments)}resetIndex(t){this.#e=-1}fresh(){this.sort(function(t,s){return t.start==s.start?0:(+(t.start>s.start)<<1)-1}),this.forEach(function(t,s){t.index=s})}step(t,s=!1){let o=[];if(s)for(let e=0;et);e++){if(this[e].endn.#e&&(o.push(r),n.#e=r.index)})}return o}getRange(t,s){t>s&&([t,s]=[s,t]);let o=[],e=-1,n=Math.ceil(Math.sqrt(this.length)),r=!0;for(let c=0;c=t&&(e=c):e=e<0?c:e;for(;r;)this[e]?.end=t&&o.push(this[e]):r=!1,e++;return o}};var ne=0xffffffffffff,V=function(t){let s=new O,o=this,e=t.timeDivision,n=120,r=new O,c=0,f=0;r.push(new D(0,ne,[120,0])),t.track.forEach(function(a){c=0,a.event.forEach(function(i){c+=i.deltaTime,i.type==255&&i?.metaType==81&&(n=6e7/i.data,r[r.length-1]&&r.push(new D(c,0xffffffffffff,[n,0])))})}),r.fresh(),r.forEach(function(a,i,l){i>0&&(l[i-1].end=a.start)});let b=120;r.forEach(function(a,i,l){i>0&&(a.end==a.start?l.splice(l.indexOf(a),1):b==a.data[0]&&(l[i-1].end=a.end,l.splice(l.indexOf(a),1)),b=a.data[0])});let u=0,h=120;return r.forEach(function(a){let i=a.start,l=i/h/e*60+u;h=a.data[0],u=l-i/h/e*60,a.data[1]=u}),console.debug("All tempo changes: ",r),n=120,c=0,f=0,t.track.forEach(function(a,i){c=0,f=0;let l=i+1;a.event.forEach(function(d,g){c+=d.deltaTime;let p=r.step(c,!0)[0];p&&(n=p.data[0],f=p.data[1]);let v={type:d.type,data:d.data,track:l,part:0};d.type>14?v.meta=d.metaType:v.part=d.channel,s.push(new X(c/n/e*60+f,v))})}),s.fresh(),self.midiEvents=s,console.debug(`Parsed a type ${t.formatType} MIDI sequence.`),s};A.default.customInterpreter=B;var E=function(t,s,o){t.addEventListener(o,e=>{s.dispatchEvent(o,e.data)})},ft=class extends T{device;#e;#n={};#f=[];#a="";#c=[];#h=[];#o=new Uint8ClampedArray(128);#u=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)}init(){this.reset(),this.#e=void 0}async loadFile(t){this.#e=V(A.default.parse(new Uint8Array(await t.arrayBuffer())))}async loadMap(t,s){let o=this,e=0,n=0,r=0,c,f;t.split(` `).forEach((b,u)=>{if(!b)return;let h=b.split(" ");if(u){if(!r)return;let a="",i="";h.forEach((l,d)=>{switch(d){case c:{a=l;break}case f:{i=l;break}}}),!o.#n[a]||s?(o.#n[a]=i,e++):self.debugMode&&console.debug(`Voice "${i}" (${a}) seems to be in conflict with (${o.#n[a]}).`),n++}else h.forEach((a,i)=>{switch(a){case"ID":{c=i,r++;break}case"Name":{f=i,r++;break}default:console.debug(`Unknown map field: ${a}`)}})}),console.debug(`Voice names: ${n} total, ${e} loaded.`),o?.device.forceVoiceRefresh()}async loadEfx(t,s){let o=this,e=0,n=0,r,c,f;t.split(` -`).forEach((b,u)=>{if(b)if(u){let h=0,a;b.split(" ").forEach((i,l)=>{switch(l){case r:{h|=parseInt(i,16)<<8;break}case c:{h|=parseInt(i,16);break}case f:{a=i;break}}}),!o.#f[h]||s?(o.#f[h]=a,e++):self.debugMode&&console.debug(`EFX ID 0x${h.toString(16).padStart(4,"0")} (${a}) seems to be in conflict.`),n++}else b.split(" ").forEach((h,a)=>{switch(h){case"MSB":{r=a;break}case"LSB":{c=a;break}case"Name":{f=a;break}default:console.debug(`Unknown EFX field: ${h}`)}})}),console.debug(`EFX: ${n} total, ${e} loaded.`),o.dispatchEvent("efxreverb",o.device.getEffectType(0)),o.dispatchEvent("efxchorus",o.device.getEffectType(1)),o.dispatchEvent("efxdelay",o.device.getEffectType(2)),o.dispatchEvent("efxinsert0",o.device.getEffectType(3)),o.dispatchEvent("efxinsert1",o.device.getEffectType(4)),o.dispatchEvent("efxinsert2",o.device.getEffectType(5)),o.dispatchEvent("efxinsert3",o.device.getEffectType(6))}switchMode(t,s=!1){this.device.switchMode(t,s)}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,s]){let o=t<<8|s;return this.#f[o]||`0x${o.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 s=this.#e?.step(t)||[],o=0,e=new Set,n={},r=[],c=this,f=[];for(c.device.getStrength().forEach((v,y)=>{c.#u[y]=v}),c.device.newStrength(),s.forEach(function(v){let y=v.data,$=c.device.runJson(y);switch($?.reply){case"meta":{f.push($);break}}$?.reply&&delete $.reply});c.#h.length>0;){let v=c.#h.shift(),y=v.part<<7|v.note;v.state?(e.add(y),n[y]=v.velo):e.has(y)&&(r.push({part:v.part,note:v.note,velo:n[y],state:c.device.NOTE_SUSTAIN}),o++)}f?.length>0&&c.dispatchEvent("meta",f);let b=c.device.getActive(),u=[],h=c.device.getPitch(),a=c.device.getCcAll(),i=c.device.getProgram(),l=c.device.getChType(),d=[],g=c.device.getStrength();g.forEach(function(v,y,$){$[y]=Math.max(c.#u[y],v);let k=$[y]-c.#o[y],A=x.length*y;if(k>=0){let S=4*.25**(a[A+x[73]]/64);c.#o[y]+=Math.ceil(k-k*c.smoothingAtk**S)}else{let S=4*.25**(a[A+x[72]]/64);c.#o[y]+=Math.floor(k-k*c.smoothingDcy**S)}});let p=0;return b.forEach(function(v,y){v&&(u[y]=c.device.getVel(y),d[y]=c.device.getExt(y),p+=u[y].size)}),{extraPoly:o,extraNotes:r,curPoly:p,chInUse:b,chKeyPr:u,chPitch:h,chProgr:i,chContr:a,chType:l,chExt:d,eventCount:s.length,title:c.#a,bitmap:c.device.getBitmap(),letter:c.device.getLetter(),texts:c.device.getTexts(),master:c.device.getMaster(),mode:c.device.getMode(),strength:c.#o.slice(),velo:g,rpn:c.device.getRpn(),tSig:c.getTimeSig(),tempo:c.getTempo(),noteBar:c.noteBar,noteBeat:c.noteBeat,ace:c.device.getAce(),rawVelo:c.device.getStrength(),rawPitch:c.device.getRawPitch(),efxSink:c.device.getEffectSink()}}constructor(t,s=.5,o=.5){super();let e=this;e.smoothingAtk=s,e.smoothingDcy=o,e.device=t,e.addEventListener("meta",function(n){n?.data?.forEach(function(r){(e.#c[r.meta]||console.debug).call(e,r.meta,r.data)})}),E(e.device,e,"mode"),E(e.device,e,"mastervolume"),E(e.device,e,"channelactive"),E(e.device,e,"channelmin"),E(e.device,e,"channelmax"),E(e.device,e,"channelreset"),E(e.device,e,"channeltoggle"),E(e.device,e,"screen"),E(e.device,e,"metacommit"),E(e.device,e,"voice"),E(e.device,e,"pitch"),E(e.device,e,"note"),E(e.device,e,"reset"),E(e.device,e,"efxreverb"),E(e.device,e,"efxchorus"),E(e.device,e,"efxdelay"),E(e.device,e,"efxinsert0"),E(e.device,e,"efxinsert1"),E(e.device,e,"efxinsert2"),E(e.device,e,"efxinsert3"),E(e.device,e,"partefxtoggle"),e.addEventListener("note",function({data:n}){e.#h.push(n)}),e.#c[3]=function(n,r){e.#a?.length<1&&(e.#a=r,e.dispatchEvent("title",e.#a))},e.#c[81]=function(n,r){let c=e.noteProgress,f=e.#s||.5;e.#i=6e7/r,e.#s=r/1e6,e.#r+=c*(f/e.#s)-c,e.dispatchEvent("tempo",e.#i)},e.#c[88]=function(n,r){let c=e.noteProgress,f=e.noteOverall,b=e.noteBar,u=e.noteBeat,h=e.#t,a=e.#l;e.#t=r[0],e.#l=1<=h&&(h{if(b)if(u){let h=0,a;b.split(" ").forEach((i,l)=>{switch(l){case r:{h|=parseInt(i,16)<<8;break}case c:{h|=parseInt(i,16);break}case f:{a=i;break}}}),!o.#f[h]||s?(o.#f[h]=a,e++):self.debugMode&&console.debug(`EFX ID 0x${h.toString(16).padStart(4,"0")} (${a}) seems to be in conflict.`),n++}else b.split(" ").forEach((h,a)=>{switch(h){case"MSB":{r=a;break}case"LSB":{c=a;break}case"Name":{f=a;break}default:console.debug(`Unknown EFX field: ${h}`)}})}),console.debug(`EFX: ${n} total, ${e} loaded.`),o.dispatchEvent("efxreverb",o.device.getEffectType(0)),o.dispatchEvent("efxchorus",o.device.getEffectType(1)),o.dispatchEvent("efxdelay",o.device.getEffectType(2)),o.dispatchEvent("efxinsert0",o.device.getEffectType(3)),o.dispatchEvent("efxinsert1",o.device.getEffectType(4)),o.dispatchEvent("efxinsert2",o.device.getEffectType(5)),o.dispatchEvent("efxinsert3",o.device.getEffectType(6))}switchMode(t,s=!1){this.device.switchMode(t,s)}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,s]){let o=t<<8|s;return this.#f[o]||`0x${o.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 s=this.#e?.step(t)||[],o=0,e=new Set,n={},r=[],c=this,f=[];for(c.device.getStrength().forEach((m,y)=>{c.#u[y]=m}),c.device.newStrength(),s.forEach(function(m){let y=m.data,$=c.device.runJson(y);switch($?.reply){case"meta":{f.push($);break}}$?.reply&&delete $.reply});c.#h.length>0;){let m=c.#h.shift(),y=m.part<<7|m.note;m.state?(e.add(y),n[y]=m.velo):e.has(y)&&(r.push({part:m.part,note:m.note,velo:n[y],state:c.device.NOTE_SUSTAIN}),o++)}f?.length>0&&c.dispatchEvent("meta",f);let b=c.device.getActive(),u=[],h=c.device.getPitch(),a=c.device.getCcAll(),i=c.device.getProgram(),l=c.device.getChType(),d=[],g=c.device.getStrength();g.forEach(function(m,y,$){$[y]=Math.max(c.#u[y],m);let k=$[y]-c.#o[y],I=x.length*y;if(k>=0){let S=4*.25**(a[I+x[73]]/64);c.#o[y]+=Math.ceil(k-k*c.smoothingAtk**S)}else{let S=4*.25**(a[I+x[72]]/64);c.#o[y]+=Math.floor(k-k*c.smoothingDcy**S)}});let p=0;return b.forEach(function(m,y){m&&(u[y]=c.device.getVel(y),d[y]=c.device.getExt(y),p+=u[y].size)}),{extraPoly:o,extraNotes:r,curPoly:p,chInUse:b,chKeyPr:u,chPitch:h,chProgr:i,chContr:a,chType:l,chExt:d,eventCount:s.length,title:c.#a,bitmap:c.device.getBitmap(),letter:c.device.getLetter(),texts:c.device.getTexts(),master:c.device.getMaster(),mode:c.device.getMode(),strength:c.#o.slice(),velo:g,rpn:c.device.getRpn(),tSig:c.getTimeSig(),tempo:c.getTempo(),noteBar:c.noteBar,noteBeat:c.noteBeat,ace:c.device.getAce(),rawVelo:c.device.getStrength(),rawPitch:c.device.getRawPitch(),efxSink:c.device.getEffectSink()}}constructor(t,s=.5,o=.5){super();let e=this;e.smoothingAtk=s,e.smoothingDcy=o,e.device=t,e.addEventListener("meta",function(n){n?.data?.forEach(function(r){(e.#c[r.meta]||console.debug).call(e,r.meta,r.data)})}),E(e.device,e,"mode"),E(e.device,e,"mastervolume"),E(e.device,e,"channelactive"),E(e.device,e,"channelmin"),E(e.device,e,"channelmax"),E(e.device,e,"channelreset"),E(e.device,e,"channeltoggle"),E(e.device,e,"screen"),E(e.device,e,"metacommit"),E(e.device,e,"voice"),E(e.device,e,"pitch"),E(e.device,e,"note"),E(e.device,e,"reset"),E(e.device,e,"efxreverb"),E(e.device,e,"efxchorus"),E(e.device,e,"efxdelay"),E(e.device,e,"efxinsert0"),E(e.device,e,"efxinsert1"),E(e.device,e,"efxinsert2"),E(e.device,e,"efxinsert3"),E(e.device,e,"partefxtoggle"),e.addEventListener("note",function({data:n}){e.#h.push(n)}),e.#c[3]=function(n,r){e.#a?.length<1&&(e.#a=r,e.dispatchEvent("title",e.#a))},e.#c[81]=function(n,r){let c=e.noteProgress,f=e.#s||.5;e.#i=6e7/r,e.#s=r/1e6,e.#r+=c*(f/e.#s)-c,e.dispatchEvent("tempo",e.#i)},e.#c[88]=function(n,r){let c=e.noteProgress,f=e.noteOverall,b=e.noteBar,u=e.noteBeat,h=e.#t,a=e.#l;e.#t=r[0],e.#l=1<=h&&(h()=>(t||e((t={exports:{}}).exports,t),t.exports);var tt=(e,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of je(t))!Je.call(e,o)&&o!==n&&be(e,o,{get:()=>t[o],enumerable:!(l=Qe(t,o))||l.enumerable});return e};var at=(e,t,n)=>(n=e!=null?Ye(Ze(e)):{},tt(t||!e||!e.__esModule?be(n,"default",{value:e,enumerable:!0}):n,e));var Be=et((jt,ne)=>{(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,o){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,o);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(l,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(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;o=o||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 g=new FileReader;g.readAsArrayBuffer(p.target.files[0]),g.onload=function(y){o(n.Uint8(new Uint8Array(y.target.result)))}})},Base64:function(l){let o=function(y){var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(y=y.replace(/^.*?base64,/,""),y=String(y).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(y))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");y+="==".slice(2-(3&y.length));let r,c="",i,s,f=0;for(;f>16&255):s===64?String.fromCharCode(r>>16&255,r>>8&255):String.fromCharCode(r>>16&255,r>>8&255,255&r);return c}(l=String(l));var p=o.length;let g=new Uint8Array(new ArrayBuffer(p));for(let y=0;y{s[u]=this.readInt(1)});for(let h=0;h191||v>127&&v<160)throw new RangeError(`Invalid code point: ${v}`)}f=!0,console.debug(`String byte sequence in ${t[h].encoding}`)}catch(u){console.debug(`SMF string ${u}`)}return d||"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 f=[];for(;128<=this.data.getUint8(this.pointer);)f.push(this.readInt(1)-128);var s=this.readInt(1);for(let d=1;d<=f.length;d++)i+=f[f.length-d]*Math.pow(128,d);i+=s}return i}};if(o.data=new DataView(g.buffer,g.byteOffset,g.byteLength),o.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;o.readInt(4);let p={};p.formatType=o.readInt(2),p.tracks=o.readInt(2),p.track=[];var g=o.readInt(1),y=o.readInt(1);128<=g?(p.timeDivision=[],p.timeDivision[0]=g-128,p.timeDivision[1]=y):p.timeDivision=256*g+y;for(let i=1;i<=p.tracks;i++){p.track[i-1]={event:[]};var a,r=o.readInt(4);if(r===-1)break;if(r!==1297379947)return!1;o.readInt(4);let s=0,f=!1,d,h;for(;!f&&(s++,p.track[i-1].event[s-1]={},p.track[i-1].event[s-1].deltaTime=o.readIntVLV(),(d=o.readInt(1))!==-1);)if(128<=d?h=d:(d=h,o.movePointer(-1)),d===255){p.track[i-1].event[s-1].type=255,p.track[i-1].event[s-1].metaType=o.readInt(1);var c=o.readIntVLV();switch(p.track[i-1].event[s-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[i-1].event[s-1].data=o.readStr(c);break;case 33:case 89:case 81:p.track[i-1].event[s-1].data=o.readInt(c);break;case 84:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=o.readInt(1),p.track[i-1].event[s-1].data[1]=o.readInt(1),p.track[i-1].event[s-1].data[2]=o.readInt(1),p.track[i-1].event[s-1].data[3]=o.readInt(1),p.track[i-1].event[s-1].data[4]=o.readInt(1);break;case 88:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=o.readInt(1),p.track[i-1].event[s-1].data[1]=o.readInt(1),p.track[i-1].event[s-1].data[2]=o.readInt(1),p.track[i-1].event[s-1].data[3]=o.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,o,c)),this.customInterpreter!==null&&p.track[i-1].event[s-1].data!==!1||(o.readInt(c),p.track[i-1].event[s-1].data=o.readInt(c),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((d=d.toString(16).split(""))[1]||d.unshift("0"),p.track[i-1].event[s-1].type=parseInt(d[0],16),p.track[i-1].event[s-1].channel=parseInt(d[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,o,!1)),this.customInterpreter!==null&&p.track[i-1].event[s-1].data!==!1||(a=o.readIntVLV(),p.track[i-1].event[s-1].data=o.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]=o.readInt(1),p.track[i-1].event[s-1].data[1]=o.readInt(1);break;case 12:case 13:p.track[i-1].event[s-1].data=o.readInt(1);break;case-1:f=!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,o,!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 ne<"u")ne.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 ge=function(e,t){let n=Math.min(e.length,t.length),l=e.slice(0,n),o=t.slice(0,n),p=0,g=0;for(;g0){let l=this.pool.length,o=1<=1&&g>=0;){if(g<=0)throw new Error("TTL reached.");if(p==l)p-=o;else{let a=ge(t,this.pool[p]);switch(a){case 0:{g=0;break}case 1:{p+o<=l&&(p+=o);break}case-1:{p!=0&&(p-=o);break}default:console.warn(`Unexpected result ${a}.`)}}o=o>>1,g--}let y=!0;if(p>=this.pool.length)y=!1;else{let a=this;this.pool[p].forEach(function(r,c,i){y&&r!=t[c]&&(y=!1)}),!y&&ge(t,this.pool[p])>0&&p++}return y||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 W=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(o){try{o?.call(l,n)}catch(p){console.error(p)}}),this[`on${e}`]&&this[`on${e}`](n)}};var rt=["MSB","PRG","LSB","NME","ELC","DRM"],ee=function(e){let t=Math.floor(e/10),n=e%10;return`${t.toString(16)}${n}`},te=class{#t;strictMode=!1;get(e=0,t=0,n=0,l){let o=[e,t,n],p,g=1,y=0,a,r=Array.from(arguments);switch(l){case"xg":{switch(e){case 0:{n==126?r[2]=125:n==127&&(r[2]=0);break}case 16:{n==126&&(r[2]=0);break}case 32:{n>125&&(r[2]=0),r[2]+=4;break}case 33:case 34:case 35:case 36:{n>125&&(r[2]=0),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:{n==126&&(r[2]=0);break}case 48:case 64:case 126:case 127:{n==126&&(r[2]=0);break}}break}case"gs":{e==0&&n<5?r[2]=0:e>125&&n<5&&n!=2&&(r[2]=e,r[0]=0);break}case"g2":case"sd":{e>>1==40?r[2]|=16:e>95&&e<100&&(r[2]|=16,t>>3==15&&(r[0]=96));break}case"sg":{e==8&&n==0&&(r[2]=5);break}case"s90es":{n<8?r[2]+=17:n<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}case"motif":{n<8?r[2]+=28:n<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}}let c=" ",i="M",s=0,f=0;switch(r[0]){case 0:{r[2]==127?i="MT-a":r[2]==126?i="MT-b":r[2]==7?i="GM-k":r[2]==5?i="SG-a":r[2]==4?i="SP-l":r[2]==0||l=="gs"&&r[2]<5?i="GM-a":(i="y",s=3);break}case 8:{l=="sg"?i="GM-s":i="r:";break}case 32:case 33:case 34:case 35:case 36:{l=="xg"&&(i=`${["AP","VL","PF","DX","AN"][e&7]}-${"abcdefgh"[n]}`);break}case 48:{i=`yM${(r[2]>>3).toString().padStart(2,"0")}`,s=1;break}case 56:{i="GM-b";break}case 61:case 120:{i="rDrm";break}case 62:{i="kDrm";break}case 63:{if(r[2]<17){let v=r[2];i=v<10?"kP:":"kC:",i+=v%10}else r[2]<34?i=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][r[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"[r[0]-80]}`;break}case 88:case 89:case 90:case 91:{i=`Cmb${"UABC"[r[0]-88]}`;break}case 95:{i=`${["DR","PC"][r[2]]}-d`;break}case 96:{i=r[2]==106?"AP-a":r[2]>>4==1?"SDg":"PF",r[2]>63?f=63:r[2]>>4==1&&(f=16),s=3;break}case 97:{i=r[2]>>4==1?"SDa":"VL:",s=3,r[2]>>4==1?f=16:f=112;break}case 98:{i=r[2]>>4==1?"SDb":"SG-a",s=3,f=16;break}case 99:{i=r[2]>>4==1?"SDc":"DX",r[2]>63?f=63:r[2]>>4==1&&(f=16),s=3;break}case 100:{i="AN",r[2]>63?f=63:r[2]>>4==1&&(f=16),s=3;break}case 104:case 105:case 106:case 107:{i="SDd",f=104;break}case 121:{i=`GM-${r[2]?"":"a"}`,s=3;break}case 122:{i="lDrm";break}case 126:{i="yDrS";break}case 127:{r[2]==127?i="rDrm":i="yDrm";break}default:r[0]<48?i="r:":i="M"}i.length<4&&(i+=`${[e,n,r[0],r[2]][s]-f}`.padStart(4-i.length,"0")),l=="xg"&&(e==0?r[2]<100?i=i.replace("y0","y:"):r[2]==125&&(i="y126"):e==16&&(p=`Voice${(r[2]*128+r[1]+1).toString().padStart(3,"0")}`,c=" "));let d=[r[0],r[1],r[2]];for(;!(p?.length>=0);)if(p=this.#t[r[1]||0][(r[0]<<7)+r[2]]?.name,p){let v=this.#t[r[1]||0][(r[0]<<7)+r[2]];g=v?.poly||g,y=v?.type||y,a=v?.drum}else if(this.strictMode)p="",c="?";else if(r[0]==0&&r[1]==0&&r[2]==0)p="Unloaded";else if(this.#t[r[1]||0][r[0]<<7])r[0]==0?(r[2]=0,c="^"):r[2]<1?(r[0]=0,c="*"):(r[2]--,c="^");else if(e==48)r[0]=0,r[2]=0,c="!";else if(e==62)r[1]--,c=" ",r[1]<1&&!p?.length&&(r[0]=0,c="!");else if(e<63)r[0]==0?(r[2]=0,c="^"):r[2]<1?(r[0]=0,c="*"):r[2]--;else if(e==80)p=`PrgU:${t.toString().padStart(3,"0")}`,c="!";else if(e==88)p=`CmbU:${t.toString().padStart(3,"0")}`,c="!";else if(e==121)p=`GM2Vox0${n}`,c="#";else if(e==122)if(r[1]==32?r[1]==0:r[1]%=7,p=this.#t[r[1]||0][(r[0]<<7)+r[2]]?.name,p){c=" ";let v=this.#t[r[1]||0][(r[0]<<7)+r[2]];g=v?.poly||g,y=v?.type||y,a=v?.drum}else p="",c="*";else r[1]==0?(p=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${n.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 h=[r[0],r[1],r[2]];(l=="gs"||l=="ns5r")&&c=="^"&&(c=" "),e==127&&c=="^"&&(c=" "),c!=" "&&self.debugMode&&(p="");let u="??";switch(r[0]){case 0:{r[2]==0?u="GM":r[2]==5||r[2]==7?u="KG":r[2]<126?u="XG":r[2]==127&&(u="MT");break}case 32:case 33:case 35:case 36:{r[2]>4?u=["AP","VL","PF","DX","AN"][r[0]-32]:u="GS";break}case 48:{u="MU";break}case 56:{u="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{u="AI";break}case 62:case 82:case 90:{u="XD";break}case 63:{r[2]<17?u="KR":r[2]<34?u="ES":u="DS";break}case 64:case 126:{u="XG";break}case 67:case 99:{u=r[2]>>4==1?"SD":"DX";break}case 81:{u="RW";break}case 95:{u=["DR","PC"][r[2]];break}case 96:{u=r[2]==106?"AP":r[2]>>4==1?"SD":"PF";break}case 97:{u=r[2]>>4==1?"SD":"VL";break}case 98:{u=r[2]>>4==1?"SD":"SG";break}case 100:{u="AN";break}case 104:case 105:case 106:case 107:{u="SD";break}case 120:{u="GS";break}case 121:{u=r[2]?"G2":"GM";break}case 122:{u="KG";break}case 127:{u=r[2]==127?"MT":t==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&l=="xg"?u="XG":u="GS")}return{name:p||`${ee(e||0)} ${ee(t||0)} ${ee(n||0)}`,poly:g,type:y,drum:a,iid:d,eid:h,sid:o,ending:c,sect:i,standard:u}}async load(e,t,n="(internal)"){let l=this,o=[],p=0,g=0;e.split(` -`).forEach(function(y,a){let r=y.split(" "),c=[];if(a==0){if(r.forEach(function(i,s){o[rt.indexOf(i)]=s}),o.length<4){console.debug("Debugger launched.");debugger}}else{let i=0,s=0,f=0,d,h=1,u=0,v;r.forEach(async function($,T){switch(T){case o[0]:{i=parseInt($);break}case o[1]:{s=parseInt($);break}case o[2]:{f=parseInt($);break}case o[3]:{d=$;break}case o[4]:{$=parseInt($),$<16?h=$+1:u=($&15)+1;break}case o[5]:{v=$;break}}}),l.#t[s]=l.#t[s]||[];let E=l.#t[s];if(!E[i<<7|f]||t){let $={msb:i,prg:s,lsb:f,name:d,poly:h,type:u,drum:v};E[i<<7|f]=$,p++}g++}}),t||console.debug(`Map "${n}": ${g} 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 o=n[0];o<=n[1];o++){let p=o<<7;for(let g=l[0];g<=l[1];g++){let y=p+g;for(let a=t[0];a<=t[1];a++)delete this.#t[a][y]}}}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){try{await fetch(`./data/bank/${n}.tsv`).then(function(l){return l.text()}).then(l=>{t.load(l,!1,n)})}catch{console.error(`Failed loading "${n}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var me=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 it=function(e,t){let n=!0;return t.forEach((l,o)=>{n=n&&e[o]==l}),n},ye=function(e){let t=0;return e.forEach(n=>{t*=256,t+=n}),t},G=new TextDecoder,Y=new me;Y.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],o=32,p=0,g=0,y=!0,a=[],r=0;for(;y;){let c=t.subarray(p);([()=>{G.decode(c.subarray(0,4))=="YSFC"?(p+=80,g=1):p++},()=>{if(it(c.subarray(0,4),l))a.forEach((i,s,f)=>{let d=ye(t.subarray(i.start+4,i.start+8));i.length=d}),g=2;else{let i=G.decode(c.subarray(0,4)),s=ye(c.subarray(4,8));a.push({type:i,start:s}),p+=8}},()=>{let i=a[r],s=t.subarray(i.start,i.start+i.length),f=32;switch(i.type){case"ENVC":{let d=o;for(;d=a.length&&(g=3,y=!1)}][g]||(()=>{y=!1}))()}return n});var V=["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"]),_=["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"],st=[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],H=[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],ve=[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],Ee=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},we=function(e){return e>105?st[e-106]:e>100?e*1.1-100:e/10},$e=",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(","),ae={};`hi*, +var Ye=Object.create;var be=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var je=Object.getOwnPropertyNames;var Ze=Object.getPrototypeOf,Je=Object.prototype.hasOwnProperty;var et=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var tt=(e,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of je(t))!Je.call(e,d)&&d!==n&&be(e,d,{get:()=>t[d],enumerable:!(l=Qe(t,d))||l.enumerable});return e};var at=(e,t,n)=>(n=e!=null?Ye(Ze(e)):{},tt(t||!e||!e.__esModule?be(n,"default",{value:e,enumerable:!0}):n,e));var Be=et((jt,ne)=>{(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,d){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,d);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(l,d){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;d=d||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 g=new FileReader;g.readAsArrayBuffer(p.target.files[0]),g.onload=function(v){d(n.Uint8(new Uint8Array(v.target.result)))}})},Base64:function(l){let d=function(v){var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(v=v.replace(/^.*?base64,/,""),v=String(v).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(v))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");v+="==".slice(2-(3&v.length));let r,c="",i,s,f=0;for(;f>16&255):s===64?String.fromCharCode(r>>16&255,r>>8&255):String.fromCharCode(r>>16&255,r>>8&255,255&r);return c}(l=String(l));var p=d.length;let g=new Uint8Array(new ArrayBuffer(p));for(let v=0;v{s[u]=this.readInt(1)});for(let h=0;h191||y>127&&y<160)throw new RangeError(`Invalid code point: ${y}`)}f=!0,console.debug(`String byte sequence in ${t[h].encoding}`)}catch(u){console.debug(`SMF string ${u}`)}return o||"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 f=[];for(;128<=this.data.getUint8(this.pointer);)f.push(this.readInt(1)-128);var s=this.readInt(1);for(let o=1;o<=f.length;o++)i+=f[f.length-o]*Math.pow(128,o);i+=s}return i}};if(d.data=new DataView(g.buffer,g.byteOffset,g.byteLength),d.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;d.readInt(4);let p={};p.formatType=d.readInt(2),p.tracks=d.readInt(2),p.track=[];var g=d.readInt(1),v=d.readInt(1);128<=g?(p.timeDivision=[],p.timeDivision[0]=g-128,p.timeDivision[1]=v):p.timeDivision=256*g+v;for(let i=1;i<=p.tracks;i++){p.track[i-1]={event:[]};var a,r=d.readInt(4);if(r===-1)break;if(r!==1297379947)return!1;d.readInt(4);let s=0,f=!1,o,h;for(;!f&&(s++,p.track[i-1].event[s-1]={},p.track[i-1].event[s-1].deltaTime=d.readIntVLV(),(o=d.readInt(1))!==-1);)if(128<=o?h=o:(o=h,d.movePointer(-1)),o===255){p.track[i-1].event[s-1].type=255,p.track[i-1].event[s-1].metaType=d.readInt(1);var c=d.readIntVLV();switch(p.track[i-1].event[s-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[i-1].event[s-1].data=d.readStr(c);break;case 33:case 89:case 81:p.track[i-1].event[s-1].data=d.readInt(c);break;case 84:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=d.readInt(1),p.track[i-1].event[s-1].data[1]=d.readInt(1),p.track[i-1].event[s-1].data[2]=d.readInt(1),p.track[i-1].event[s-1].data[3]=d.readInt(1),p.track[i-1].event[s-1].data[4]=d.readInt(1);break;case 88:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=d.readInt(1),p.track[i-1].event[s-1].data[1]=d.readInt(1),p.track[i-1].event[s-1].data[2]=d.readInt(1),p.track[i-1].event[s-1].data[3]=d.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,d,c)),this.customInterpreter!==null&&p.track[i-1].event[s-1].data!==!1||(d.readInt(c),p.track[i-1].event[s-1].data=d.readInt(c),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[i-1].event[s-1].type=parseInt(o[0],16),p.track[i-1].event[s-1].channel=parseInt(o[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,d,!1)),this.customInterpreter!==null&&p.track[i-1].event[s-1].data!==!1||(a=d.readIntVLV(),p.track[i-1].event[s-1].data=d.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]=d.readInt(1),p.track[i-1].event[s-1].data[1]=d.readInt(1);break;case 12:case 13:p.track[i-1].event[s-1].data=d.readInt(1);break;case-1:f=!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,d,!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 ne<"u")ne.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 ge=function(e,t){let n=Math.min(e.length,t.length),l=e.slice(0,n),d=t.slice(0,n),p=0,g=0;for(;g0){let l=this.pool.length,d=1<=1&&g>=0;){if(g<=0)throw new Error("TTL reached.");if(p==l)p-=d;else{let a=ge(t,this.pool[p]);switch(a){case 0:{g=0;break}case 1:{p+d<=l&&(p+=d);break}case-1:{p!=0&&(p-=d);break}default:console.warn(`Unexpected result ${a}.`)}}d=d>>1,g--}let v=!0;if(p>=this.pool.length)v=!1;else{let a=this;this.pool[p].forEach(function(r,c,i){v&&r!=t[c]&&(v=!1)}),!v&&ge(t,this.pool[p])>0&&p++}return v||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 W=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(d){try{d?.call(l,n)}catch(p){console.error(p)}}),this[`on${e}`]&&this[`on${e}`](n)}};var rt=["MSB","PRG","LSB","NME","ELC","DRM"],ee=function(e){let t=Math.floor(e/10),n=e%10;return`${t.toString(16)}${n}`},te=class{#t;strictMode=!1;get(e=0,t=0,n=0,l){let d=[e,t,n],p,g=1,v=0,a,r=Array.from(arguments);switch(l){case"xg":{switch(e){case 0:{n==126?r[2]=125:n==127&&(r[2]=0);break}case 16:{n==126&&(r[2]=0);break}case 32:{n>125&&(r[2]=0),r[2]+=4;break}case 33:case 34:case 35:case 36:{n>125&&(r[2]=0),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:{n==126&&(r[2]=0);break}case 48:case 64:case 126:case 127:{n==126&&(r[2]=0);break}}break}case"gs":{e==0&&n<5?r[2]=0:e>125&&n<5&&n!=2&&(r[2]=e,r[0]=0);break}case"g2":case"sd":{e>>1==40?r[2]|=16:e>95&&e<100&&(r[2]|=16,t>>3==15&&(r[0]=96));break}case"sg":{e==8&&n==0&&(r[2]=5);break}case"s90es":{n<8?r[2]+=17:n<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}case"motif":{n<8?r[2]+=28:n<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}}let c=" ",i="M",s=0,f=0;switch(r[0]){case 0:{r[2]==127?i="MT-a":r[2]==126?i="MT-b":r[2]==7?i="GM-k":r[2]==5?i="SG-a":r[2]==4?i="SP-l":r[2]==0||l=="gs"&&r[2]<5?i="GM-a":(i="y",s=3);break}case 8:{l=="sg"?i="GM-s":i="r:";break}case 32:case 33:case 34:case 35:case 36:{l=="xg"&&(i=`${["AP","VL","PF","DX","AN"][e&7]}-${"abcdefgh"[n]}`);break}case 48:{i=`yM${(r[2]>>3).toString().padStart(2,"0")}`,s=1;break}case 56:{i="GM-b";break}case 61:case 120:{i="rDrm";break}case 62:{i="kDrm";break}case 63:{if(r[2]<17){let y=r[2];i=y<10?"kP:":"kC:",i+=y%10}else r[2]<34?i=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][r[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"[r[0]-80]}`;break}case 88:case 89:case 90:case 91:{i=`Cmb${"UABC"[r[0]-88]}`;break}case 95:{i=`${["DR","PC"][r[2]]}-d`;break}case 96:{i=r[2]==106?"AP-a":r[2]>>4==1?"SDg":"PF",r[2]>63?f=63:r[2]>>4==1&&(f=16),s=3;break}case 97:{i=r[2]>>4==1?"SDa":"VL:",s=3,r[2]>>4==1?f=16:f=112;break}case 98:{i=r[2]>>4==1?"SDb":"SG-a",s=3,f=16;break}case 99:{i=r[2]>>4==1?"SDc":"DX",r[2]>63?f=63:r[2]>>4==1&&(f=16),s=3;break}case 100:{i="AN",r[2]>63?f=63:r[2]>>4==1&&(f=16),s=3;break}case 104:case 105:case 106:case 107:{i="SDd",f=104;break}case 121:{i=`GM-${r[2]?"":"a"}`,s=3;break}case 122:{i="lDrm";break}case 126:{i="yDrS";break}case 127:{r[2]==127?i="rDrm":i="yDrm";break}default:r[0]<48?i="r:":i="M"}i.length<4&&(i+=`${[e,n,r[0],r[2]][s]-f}`.padStart(4-i.length,"0")),l=="xg"&&(e==0?r[2]<100?i=i.replace("y0","y:"):r[2]==125&&(i="y126"):e==16?(p=`Voice${((r[2]<<7)+r[1]+1).toString().padStart(3,"0")}`,c=" "):e==35&&n>>1==2&&(p=`DXCH_${(((r[2]&1)<<7)+t+1).toString().padStart(3,"0")}`,c=" "));let o=[r[0],r[1],r[2]];for(;!(p?.length>=0);)if(p=this.#t[r[1]||0][(r[0]<<7)+r[2]]?.name,p){let y=this.#t[r[1]||0][(r[0]<<7)+r[2]];g=y?.poly||g,v=y?.type||v,a=y?.drum}else if(this.strictMode)p="",c="?";else if(r[0]==0&&r[1]==0&&r[2]==0)p="Unloaded";else if(this.#t[r[1]||0][r[0]<<7])r[0]==0?(r[2]=0,c="^"):r[2]<1?(r[0]=0,c="*"):(r[2]--,c="^");else if(e==48)r[0]=0,r[2]=0,c="!";else if(e==62)r[1]--,c=" ",r[1]<1&&!p?.length&&(r[0]=0,c="!");else if(e<63)r[0]==0?(r[2]=0,c="^"):r[2]<1?(r[0]=0,c="*"):r[2]--;else if(e==80)p=`PrgU:${t.toString().padStart(3,"0")}`,c="!";else if(e==88)p=`CmbU:${t.toString().padStart(3,"0")}`,c="!";else if(e==121)p=`GM2Vox0${n}`,c="#";else if(e==122)if(r[1]==32?r[1]==0:r[1]%=7,p=this.#t[r[1]||0][(r[0]<<7)+r[2]]?.name,p){c=" ";let y=this.#t[r[1]||0][(r[0]<<7)+r[2]];g=y?.poly||g,v=y?.type||v,a=y?.drum}else p="",c="*";else r[1]==0?(p=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${n.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 h=[r[0],r[1],r[2]];(l=="gs"||l=="ns5r")&&c=="^"&&(c=" "),e==127&&c=="^"&&(c=" "),c!=" "&&self.debugMode&&(p="");let u="??";switch(r[0]){case 0:{r[2]==0?u="GM":r[2]==5||r[2]==7?u="KG":r[2]<126?u="XG":r[2]==127&&(u="MT");break}case 32:case 33:case 35:case 36:{r[2]>4?u=["AP","VL","PF","DX","AN"][r[0]-32]:u="GS";break}case 48:{u="MU";break}case 56:{u="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{u="AI";break}case 62:case 82:case 90:{u="XD";break}case 63:{r[2]<17?u="KR":r[2]<34?u="ES":u="DS";break}case 64:case 126:{u="XG";break}case 67:case 99:{u=r[2]>>4==1?"SD":"DX";break}case 81:{u="RW";break}case 95:{u=["DR","PC"][r[2]];break}case 96:{u=r[2]==106?"AP":r[2]>>4==1?"SD":"PF";break}case 97:{u=r[2]>>4==1?"SD":"VL";break}case 98:{u=r[2]>>4==1?"SD":"SG";break}case 100:{u="AN";break}case 104:case 105:case 106:case 107:{u="SD";break}case 120:{u="GS";break}case 121:{u=r[2]?"G2":"GM";break}case 122:{u="KG";break}case 127:{u=r[2]==127?"MT":t==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&l=="xg"?u="XG":u="GS")}return{name:p||`${ee(e||0)} ${ee(t||0)} ${ee(n||0)}`,poly:g,type:v,drum:a,iid:o,eid:h,sid:d,ending:c,sect:i,standard:u}}async load(e,t,n="(internal)"){let l=this,d=[],p=0,g=0;e.split(` +`).forEach(function(v,a){let r=v.split(" "),c=[];if(a==0){if(r.forEach(function(i,s){d[rt.indexOf(i)]=s}),d.length<4){console.debug("Debugger launched.");debugger}}else{let i=0,s=0,f=0,o,h=1,u=0,y;r.forEach(async function($,T){switch(T){case d[0]:{i=parseInt($);break}case d[1]:{s=parseInt($);break}case d[2]:{f=parseInt($);break}case d[3]:{o=$;break}case d[4]:{$=parseInt($),$<16?h=$+1:u=($&15)+1;break}case d[5]:{y=$;break}}}),l.#t[s]=l.#t[s]||[];let E=l.#t[s];if(!E[i<<7|f]||t){let $={msb:i,prg:s,lsb:f,name:o,poly:h,type:u,drum:y};E[i<<7|f]=$,p++}g++}}),t||console.debug(`Map "${n}": ${g} 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 d=n[0];d<=n[1];d++){let p=d<<7;for(let g=l[0];g<=l[1];g++){let v=p+g;for(let a=t[0];a<=t[1];a++)delete this.#t[a][v]}}}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){try{await fetch(`./data/bank/${n}.tsv`).then(function(l){return l.text()}).then(l=>{t.load(l,!1,n)})}catch{console.error(`Failed loading "${n}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var me=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 it=function(e,t){let n=!0;return t.forEach((l,d)=>{n=n&&e[d]==l}),n},ye=function(e){let t=0;return e.forEach(n=>{t*=256,t+=n}),t},G=new TextDecoder,Y=new me;Y.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],d=32,p=0,g=0,v=!0,a=[],r=0;for(;v;){let c=t.subarray(p);([()=>{G.decode(c.subarray(0,4))=="YSFC"?(p+=80,g=1):p++},()=>{if(it(c.subarray(0,4),l))a.forEach((i,s,f)=>{let o=ye(t.subarray(i.start+4,i.start+8));i.length=o}),g=2;else{let i=G.decode(c.subarray(0,4)),s=ye(c.subarray(4,8));a.push({type:i,start:s}),p+=8}},()=>{let i=a[r],s=t.subarray(i.start,i.start+i.length),f=32;switch(i.type){case"ENVC":{let o=d;for(;o=a.length&&(g=3,v=!1)}][g]||(()=>{v=!1}))()}return n});var V=["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"]),_=["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"],st=[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],H=[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],ve=[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],Ee=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},we=function(e){return e>105?st[e-106]:e>100?e*1.1-100:e/10},$e=",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(","),ae={};`hi*, ka,か ki,き ku,く @@ -139,8 +139,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let t=e.split(",");ae[t[0]]=t[1]});var ke=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 ae)t=t.replaceAll(l,ae[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},xe=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var re=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],Te=["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 nt={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"},ct={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]]},ie=function(e){return nt[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},Ce=function(e,t,n){let l=(e[0]-32<<16)+(e[1]<<8)+t,o=ct[l]||{},p=o[0];if(p?.length)return p+=`: ${(o[1]||function(){})(n)||n}`,p},se=[68,48,95,78,41,3,110,122,0];var M=function(e=64){return Math.round(2e3*Math.log10(e/64))/100},Me=function(e,t,n){let l=[],o=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)},N=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 o=0;o>p&1)<<7,y=e[o];y+=g,o%8!=0?(t(y,n,e),n++):l=e[o]}};var F=function(e){let t=Math.floor(e*14.2);return t<128?t:0};var P=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],lt={gm2:"g2","mt-32":"mt32","c/m":"mt32",ag10:"05rw","ag-10":"05rw","05r/w":"05rw",x5:"05rw",x5dr:"x5d",gmega:"k11","kross 2":"krs","motif es":"motif","s90 es":"s90es"},ot=["melodic","drum","menu"],Re=[[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]],B=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],dt=[0,3,81,84,88],De={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Le={0:0,1:1,2:3,5:4},Oe={0:0,1:1,2:2,5:3},Pe=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Ae=[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],Ie={26:127,29:0,30:0,31:0,52:12,53:54},z=[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,14,15,20,21,26,28,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157],ft=[2,12,13,14,15,16,17,18,19,20,21,136,130,131,132,133,134,135,137,138,139],ht=[33,99,100,32,102,8,9,10],Ue=[0,16,25,40,32,64,26,48],k={};P.forEach((e,t)=>{k[e]=t});var b={length:z.length};z.forEach((e,t)=>{b[e]=t});var D={length:Q.length};Q.forEach((e,t)=>{D[e]=t});var ut={};ot.forEach((e,t)=>{ut[e]=t});var x=function(){return!!self.Bun||self.debugMode||!1},pt=function(e){let t=[],n=0;return e?.forEach(function(l,o){l==247?t.push(e.subarray(n,o)):l==240&&(n=o+1)}),t.length||t.push(e.subarray(0)),x()&&console.debug(t),t};var m={ch:128,cc:z.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:Q.length,dnc:128,ext:2,efx:7,redir:32},K={bank0:128},Ne=class extends W{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;EXT_NONE=0;EXT_VL=1;VLBC_BRTHEXPR=1;VLBC_VELOINIT=2;VLBC_VELOALL=3;#t=0;#b=0;#x=0;#c=new Array(11);get#y(){return this.#c[this.#b]}set#y(e){this.#c[this.#b]=e}#T=new Uint8Array(m.ch);#f=new Uint8Array(m.ch);#s=new Uint8Array(m.ch);#e=new Uint8Array(m.ch*m.cc);#E=new Uint8Array(m.ace);#i=new Uint8Array(m.ch);#o=new Uint8Array(m.ch*m.nn);#p=new Uint8Array(m.ch);#l=new Uint16Array(m.pl);#w=new Uint8Array(m.pl);#M=new Int16Array(m.ch);#R=new Uint8Array(m.ch);#X=0;#C=new Uint8Array(m.ch*m.ext);#r=new Uint8Array(m.ch*m.rpn);#n=new Uint8Array(m.ch*m.rpnt);#V=new Int8Array(m.ch*Ae.length);#a=new Uint8Array(m.drm*m.dpn*m.dnc);#g=new Uint8Array(m.efx*3);#d=new Uint8Array(m.ch);#v=new Uint8Array(m.ch*m.redir);#$=new Uint8Array(m.ch);#P=new Uint8Array(128);#S=new Uint8Array(m.cmt*8);#_=new Uint8Array(1024);#U=new Uint8Array(m.cmt*64);#N=0;#L=0;#h;#u=100;#H=0;#F=500;#G=0;#q="";#W=0;#ie=0;#re=0;#B=!0;#m=!1;#ce=1;#se;#Q=new Array(m.ch);#oe=new Uint8Array(2);#O=[];#K=new Uint8Array(m.ch);#Y=new Uint8Array(m.tr);baseBank=new te("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","krs","s90es");userBank=new te("gm");initOnReset=!1;aiEfxName="";chRedir(e,t,n){if(this.#Y[t])return(this.#Y[t]-1)*16+e;if([2,3].indexOf(this.#L)>-1){if(n==1)return e;let l=0,o=!0;for(;o;)this.#K[e+l]==0?(this.#K[e+l]=t,console.debug(`Assign track ${t} to channel ${e+l+1}.`),o=!1):this.#K[e+l]==t?o=!1:(l+=16,l>=128&&(l=0,o=!1));return e+l}else return e}forceVoiceRefresh(){for(let e=0;e{let n=e*128+t,l=this.#l.lastIndexOf(n);if(l>-1)if(this.#e[m.cc*e+b[64]]>63)this.#w[l]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#o[n],state:this.NOTE_HELD});else if(this.#e[m.cc*e+b[66]]>63&&this.#w[l]==this.NOTE_SOSTENUTO_SUSTAIN)this.#w[l]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#o[n],state:this.NOTE_SOSTENUTO_HELD});else{this.#l[l]=0,this.#o[n]=0,this.#w[l]=this.NOTE_IDLE;let o=this.getExt(e)[1];(o==this.VLBC_VELOINIT||o==this.VLBC_VELOALL)&&(this.#e[m.cc*e+b[129]]=0),this.dispatchEvent("note",{part:e,note:t,velo:0,state:this.NOTE_IDLE})}},nOn:(e,t,n)=>{let l=e*128+t,o=0;for(this.#p[e]&&this.#k.ano(e);this.#w[o]>0&&this.#l[o]!=l;)o++;if(o{},cAt:(e,t)=>{},hoOf:e=>{this.#w.forEach((t,n)=>{if(t==this.NOTE_HELD){let l=this.#l[n],o=l>>7;e==o&&(this.#w[n]=this.NOTE_IDLE,this.#l[n]=0,this.#o[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#w.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.#w[n]=l;let o=this.#l[n];this.dispatchEvent("note",{part:e,note:o&127,velo:this.#o[o],state:l})}})},soOf:e=>{this.#w.forEach((t,n)=>{if(t==this.NOTE_SOSTENUTO_HELD){let l=this.#l[n],o=l>>7;e==o&&(this.#w[n]=this.NOTE_IDLE,this.#l[n]=0,this.#o[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#l.forEach((t,n,l)=>{let o=t>>7,p=t&127;t==0&&this.#o[0]==0||o==e&&this.#k.nOff(o,p)})}};#ne={8:function(e){let t=e.channel,n=e.data[0];this.#k.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.#k.nOn(t,n,l):this.#k.nOff(t,n)},10:function(e){let t=e.channel,n=t*128+e.data[0];this.#l.indexOf(n)>-1&&(this.#o[n]=data[1],this.getExt(t)[1]==this.VLBC_VELOALL&&(this.#e[m.cc*t+b[129]]=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,n=this.#Q[t],l=n[e.data[0]];l&&(e.data[0]=l),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case k.s90es:case k.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 o=t*m.cc,p=t*m.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#k.ano(t),this.#M[t]=0,this.#e[o+b[1]]=0,this.#e[o+b[5]]=0,this.#e[o+b[64]]=0,this.#e[o+b[65]]=0,this.#e[o+b[66]]=0,this.#e[o+b[67]]=0,this.#e[o+b[11]]=127,this.#e[o+b[101]]=127,this.#e[o+b[100]]=127,this.#e[o+b[99]]=127,this.#e[o+b[98]]=127;return}case 123:{this.#k.ano(t);return}case 124:{this.#k.ano(t);return}case 125:{this.#k.ano(t);return}case 126:{this.#p[t]=1,this.#k.ano(t);return}case 127:{this.#p[t]=0,this.#k.ano(t);return}}if(b[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(ft.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(x()&&console.debug(`${P[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#s[t]>0&&(e.data[1]=this.#e[o],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(this.#h.x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(this.modeIdx[this.#h.ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==k.gs?e.data[1]<56&&this.#s[t]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)):this.#t==k.gm&&(e.data[1]<48?this.#s[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){case k.xg:{[79,95,126,127].indexOf(e.data[1])>-1?this.#s[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#s[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?this.#C[p]=this.EXT_VL:this.#C[p]=this.EXT_NONE;break}case k["05rw"]:case k.x5d:case k.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#s[t]==this.CH_MELODIC&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):[80,81,82,83].indexOf(e.data[1])>-1||this.#s[t]!=this.CH_MELODIC&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case k.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#s[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#s[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case k.g2:{e.data[1]==120?this.#s[t]==0&&(this.setChType(t,this.CH_DRUMS),console.debug(`CH${t+1} set to drums by MSB.`)):this.#s[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 2:{this.getExt(t)[1]==this.VLBC_BRTHEXPR&&(this.#e[o+b[129]]=e.data[1]);break}case 6:{if(this.#X){[k.xg,k.gs,k.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${P[this.#t]}" mode, even when they are supported in Octavia.`);let g=this.#e[o+b[99]],y=this.#e[o+b[98]];if(g==1){let a=ht.indexOf(y);if(a>-1)this.#e[o+b[71+a]]=e.data[1],x()&&console.debug(`Redirected NRPN 1 ${y} to cc${71+a}.`),this.dispatchEvent("cc",{part:t,cc:71+a,data:e.data[1]});else{let r=Ae.indexOf(y);r>-1?this.#V[t*10+r]=e.data[1]-64:console.warn(`NRPN 0x01${y.toString(16).padStart(2,"0")} is not supported.`),x()&&console.debug(`CH${t+1} voice NRPN ${y} commit`)}}else{if(Q.indexOf(g)<0){let r=`NRPN 0x${g.toString(16).padStart(2,"0")}${y.toString(16).padStart(2,"0")} `;g==127?console.warn(`${r}is not necessary. Consider removing it.`):console.warn(`${r}is not supported.`)}else{let r=this.#s[t]-2;r<0?console.warn(`CH${t+1} cannot accept drum NRPN as type ${_[this.#s[t]]}.`):this.#a[(r*m.dpn+D[g])*m.dnc+y]=e.data[1]}x()&&console.debug(`CH${t+1} (${_[this.#s[t]]}) drum NRPN ${g} commit`)}}else{let g=Le[this.#e[o+b[100]]],y=Oe[this.#e[o+b[100]]];this.#e[o+b[101]]==0&&g!=null&&(x()&&console.debug(`CH${t+1} RPN 0 ${this.#e[o+b[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Pe[g][0]),Pe[g][1]),this.#r[t*m.rpn+g]=e.data[1],this.#n[t*m.rpnt+y]=1)}break}case 32:{switch(x()&&console.debug(`${P[this.#t]}, CH${t+1} LSB: ${e.data[1]}`),this.#t){case k.s90es:case k.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:{if(!this.#X){let g=Le[this.#e[o+100]],y=Oe[this.#e[o+100]];this.#e[o+101]==0&&g!=null&&(this.#r[t*m.rpn+g+1]=e.data[1],this.#n[t*m.rpnt+y]=1)}break}case 64:{e.data[1]<64&&this.#k.hoOf(t);break}case 66:{e.data[1]>>6?this.#k.soOn(t):this.#k.soOf(t);break}case 98:case 99:{this.#X=1;break}case 100:case 101:{this.#X=0;break}}this.#e[o+b[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 k.s90es:case k.motif:{e.data&&this.setChActive(t,1);break}default:this.setChActive(t,1)}this.#i[t]=e.data,this.#$[t]=0,x()&&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.#l.forEach(function(l){let o=l>>7;n==o&&(t.#o[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.#M[t]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)})},15:function(e){pt(e.data).forEach(t=>{let n=t[0],l=t[1];(this.#le[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.#D[e.meta]||function(n,l,o){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#H=0);let t=dt.indexOf(e.meta)>-1;if(x()&&console.debug(e),t)return e.reply="meta",e}};#le={64:(e,t,n)=>{this.#ee.run(t,n,e)},65:(e,t,n)=>{if(t[0]<16)if(t[1]==72){let l=t[t.length-1],o=N(t.subarray(3,t.length-1));l==o?this.#I.run(t.subarray(0,t.length-1),n,e):console.warn(`Bad SD checksum ${l}. Should be ${o}.`)}else this.#I.run(t,n,e);else{let l=t[t.length-1],o=N(t.subarray(2,t.length-1));l==o?this.#I.run(t.subarray(0,t.length-1),n,e):console.warn(`Bad GS checksum ${l}. Should be ${o}.`)}},66:(e,t,n)=>{this.#z.run(t,n,e)},67:(e,t,n)=>{this.#A.run(t,n,e)},68:(e,t,n)=>{this.#ae.run(t,n,e)},71:(e,t,n)=>{this.#te.run(t,n,e)},126:(e,t,n)=>{this.#Z.run(t,n,e)},127:(e,t,n)=>{this.switchMode("gm"),this.#J.run(t,n,e)}};#Z;#J;#A;#I;#z;#ee;#te;#ae;buildRchTree(){let e=[];this.#f.forEach((t,n)=>{t{t&&(e.#Q[Math.floor(n/m.redir)][t]=n%m.redir|128)}),x()&&console.debug(e.#Q)}getActive(){return this.#T}getCc(e){let t=e*m.cc,n=this.#e.subarray(t,t+m.cc);return n[b[0]]=n[b[0]]||this.#N,n[b[32]]=n[b[32]]||this.#L,n[b[0]]==K.bank0&&(n[b[0]]=0),n}getCcCh(e,t){if(z.indexOf(t)<0)throw new Error("CC number not accepted");return this.#e[m.cc*e+b[t]]}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&!l&&(this.#e[e*m.cc+b[0]]=B[n])}setChActive(e,t=0){this.#T[e]!=t&&this.dispatchEvent("channeltoggle",{part:e,active:t}),this.#T[e]=t}getExt(e){let t=m.ext*e,n=this.#C.subarray(t,t+m.ext),l=new Uint8Array(n.length);return l.set(n),l[1]=l[1]||this.#ce,l}getPitch(){return this.#M}getProgram(){return this.#i}getTexts(){return this.#O.slice()}getVel(e){let t=new Map,n=this;return n.#l.forEach(function(l,o){let p=Math.floor(l/128),g=l%128;e==p&&n.#o[l]>0&&t.set(g,{v:n.#o[l],s:n.#w[o]})}),t}getBitmap(){return{bitmap:this.#y,expire:this.#x}}getLetter(){return{text:this.#q,set:this.#ie,expire:this.#W}}getMode(){return P[this.#t]}getMaster(){return{volume:this.#u}}getRawStrength(){let e=this;return this.#l.forEach(function(t){let n=Math.floor(t/128);e.#o[t]>e.#R[n]&&(e.#R[n]=e.#o[t])}),this.#R}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(n,l){e[l]=Math.floor(n*t.#e[l*m.cc+b[7]]*t.#e[l*m.cc+b[11]]*t.#u/803288)}),e}getRpn(){return this.#r}getNrpn(){return this.#V}getVoice(e,t,n,l){let o=e||this.#N,p=t,g=n||this.#L;o==K.bank0&&(o=0),P[this.#t]=="ns5r"&&o>0&&o<56&&(g=3);let y=this.userBank.get(o,p,g,l);if(P[this.#t]=="mt32"&&y.name.indexOf("MT-m:")==0){let a=parseInt(y.name.slice(5)),r=a*m.cmt,c="";this.#U.subarray(r,r+10).forEach(s=>{s>31&&(c+=String.fromCharCode(s))});let i=`MSB LSB PRG NME -0 127 ${p} ${c}`;this.userBank.load(i,!0),y.name=c,y.ending=" "}return(y.ending!=" "||!y.name.length)&&(y=this.baseBank.get(o,p,g,l)),y}getChVoice(e){let t=this.getVoice(this.#e[e*m.cc+b[0]],this.#i[e],this.#e[e*m.cc+b[32]],P[this.#t]);if(this.#$[e])switch(this.#t){case k.mt32:t.ending="~",t.name="",this.#S.subarray(14*(e-1),14*(e-1)+10).forEach(n=>{t.name+=String.fromCharCode(Math.max(n,32))}),t.name=t.name.trimRight()}return t}getRawPitch(){return this.#M}getPitchShift(e){let t=this,n=e*m.rpn,l=t.#r[n];return t.#n[e*m.rpnt]||t.#t==k.mt32&&(l=12),t.#M[e]/8192*l+(t.#r[n+3]-64)+((t.#r[n+1]<<7)+t.#r[n+2]-8192)/8192}getEffectType(e=0){let t=3*e+1;return this.#g.subarray(t,t+2)}setEffectTypeRaw(e=0,t,n){let l=3*e;this.#g[l]=1,this.#g[l+1+ +t]=n}setEffectType(e=0,t,n){this.setEffectTypeRaw(e,!1,t),this.setEffectTypeRaw(e,!0,n)}getEffectSink(){return this.#d}setLetterDisplay(e,t,n=0,l=3200){let o=this,p;o.#q=" ".repeat(n),e.forEach(g=>{o.#q+=String.fromCharCode(g>31?g:32),g<32&&(p=p||new Set,p.add(g))}),o.#ie=Date.now(),o.#W=Date.now()+l,p&&(p=Array.from(p),p.forEach((g,y,a)=>{a[y]=g.toString(16).padStart(2,"0")}),console.warn(`${t}${t?" ":""}invalid code point${p.length>1?"s":""}: 0x${p.join(", 0x")}`))}setDetectionTargets(e="?",t=0){let n=this,l=-1;switch(e.replaceAll(", ",",").split(",").forEach(o=>{o=o.toLowerCase();let p=P.indexOf(lt[o]||o);x()&&console.debug(`Mapped mode "${o}" to ID "${p}".`),p>-1&&(l=p)}),x()&&console.debug(`Set detection target to ID "${l}".`),l>0&&(n.#h.x5=82,n.#h.ds=k.krs),l){case k["05rw"]:{n.#h.x5=81;break}case k.s90es:n.#h.ds=k.s90es;case k.motif:n.#h.ds=k.motif}}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let t=!0,n=0;for(;t&&n=m.ace&&console.warn("ACE slots are full.")}getAce(){return this.#E}getChAce(e,t){if(t<0||t>=m.ace)throw new RangeError("No such ACE slot");let n=this.#E[t];if(n){if(z.indexOf(n)>=0)return this.#e[e*m.cc+b[n]];throw new Error(`Invalid ACE source: ${n}`)}else return 0}initDrums(){let e=this;e.#a.fill(64);for(let t=0;t-1){if(l.#t==0||t){let p=l.#t;l.initOnReset&&t&&(this.init(1),p=k["?"]),l.#t=o,l.#b=0,l.#N=Re[0][o],l.#L=Re[1][o];for(let y=0;y0&&l.#e[y*m.cc+b[0]]==B[p]&&(l.#e[y*m.cc]=B[o]);switch(o){case k.mt32:{se.forEach((y,a)=>{let r=a+1;l.#T[r]||(l.#i[r]=y,l.#e[r*m.cc+b[91]]=127)});for(let y=1;y<10;y++)l.dispatchEvent("voice",{part:y});break}}let g;switch(o){case k["?"]:case k.g2:{g=[52,4,52,18,0,0,0,0];break}case k.xg:{g=[1,0,65,0,5,0,0,0];break}case k.gm:case k.gs:{g=[40,4,40,18,40,32,32,0];break}case k.sd:{g=[58,0,60,0,61,0,61,0];break}case k["05rw"]:case k.x5d:case k.ns5r:{g=[44,1,44,19,44,0,44,0];break}case k.k11:case k.sg:{g=[24,0,0,0,0,0,0,0];break}case k.mt32:{g=[40,4,0,0,0,0,0,0];break}default:g=[0,0,0,0,0,0,0,0]}for(let y=0;y14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#ne[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),n=!1;this.#se[t]?.forEach(l=>{e.channel=l,n=!0,this.#ne[e.type].call(this,e)}),n||console.warn(`${De[e.type]?De[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.#O.length>100&&this.#O.splice(100,this.#O.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":{Y.context=this,n.userBank.load(await Y.read(e,t));break}}n.forceVoiceRefresh()}constructor(){super();let e=this;e.#y=new Uint8Array(256),e.#c[10]=new Uint8Array(512),e.#j=new L,e.#h={x5:82,ds:k.krs},e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let t=e.split(",");ae[t[0]]=t[1]});var ke=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 ae)t=t.replaceAll(l,ae[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},xe=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var re=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],Te=["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 nt={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"},ct={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]]},ie=function(e){return nt[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},Ce=function(e,t,n){let l=(e[0]-32<<16)+(e[1]<<8)+t,d=ct[l]||{},p=d[0];if(p?.length)return p+=`: ${(d[1]||function(){})(n)||n}`,p},se=[68,48,95,78,41,3,110,122,0];var M=function(e=64){return Math.round(2e3*Math.log10(e/64))/100},Me=function(e,t,n){let l=[],d=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)},N=function(e){let t=0;return e.forEach(n=>{t+=n,t=t&127}),~t+1&127},L=function(e,t){let n=0,l=0;for(let d=0;d>p&1)<<7,v=e[d];v+=g,d%8!=0?(t(v,n,e),n++):l=e[d]}};var F=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"],lt={gm2:"g2","mt-32":"mt32","c/m":"mt32",ag10:"05rw","ag-10":"05rw","05r/w":"05rw",x5:"05rw",x5dr:"x5d",gmega:"k11","kross 2":"krs","motif es":"motif","s90 es":"s90es"},ot=["melodic","drum","menu"],Re=[[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]],B=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],ft=[0,3,81,84,88],De={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Oe={0:0,1:1,2:3,5:4},Le={0:0,1:1,2:2,5:3},Ae=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Pe=[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],Ie={26:127,29:0,30:0,31:0,52:12,53:54},z=[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,14,15,20,21,26,28,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157],dt=[2,12,13,14,15,16,17,18,19,20,21,136,130,131,132,133,134,135,137,138,139,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157],ht=[33,99,100,32,102,8,9,10],Ue=[0,16,25,40,32,64,26,48],k={};A.forEach((e,t)=>{k[e]=t});var b={length:z.length};z.forEach((e,t)=>{b[e]=t});var D={length:Q.length};Q.forEach((e,t)=>{D[e]=t});var ut={};ot.forEach((e,t)=>{ut[e]=t});var x=function(){return!!self.Bun||self.debugMode||!1},pt=function(e){let t=[],n=0;return e?.forEach(function(l,d){l==247?t.push(e.subarray(n,d)):l==240&&(n=d+1)}),t.length||t.push(e.subarray(0)),x()&&console.debug(t),t};var m={ch:128,cc:z.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:Q.length,dnc:128,ext:2,efx:7,cvn:12,redir:32},K={bank0:128},Ne=class extends W{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;EXT_NONE=0;EXT_VL=1;EXT_DX=3;VLBC_BRTHEXPR=1;VLBC_VELOINIT=2;VLBC_VELOALL=3;#t=0;#p=0;#T=0;#c=new Array(11);get#v(){return this.#c[this.#p]}set#v(e){this.#c[this.#p]=e}#S=new Uint8Array(m.ch);#h=new Uint8Array(m.ch);#s=new Uint8Array(m.ch);#e=new Uint8Array(m.ch*m.cc);#b=new Uint8Array(m.ace);#i=new Uint8Array(m.ch);#o=new Uint8Array(m.ch*m.nn);#u=new Uint8Array(m.ch);#l=new Uint16Array(m.pl);#$=new Uint8Array(m.pl);#M=new Int16Array(m.ch);#R=new Uint8Array(m.ch);#B=0;#k=new Uint8Array(m.ch*m.ext);#r=new Uint8Array(m.ch*m.rpn);#n=new Uint8Array(m.ch*m.rpnt);#X=new Int8Array(m.ch*Pe.length);#a=new Uint8Array(m.drm*m.dpn*m.dnc);#g=new Uint8Array(m.efx*3);#f=new Uint8Array(m.ch);#E=new Uint8Array(m.ch*m.redir);#w=new Uint8Array(m.ch);#_=new Uint8Array(m.ch*m.cvn);#O=new Uint8Array(128);#L=new Uint8Array(m.cmt*8);#F=new Uint8Array(1024);#U=new Uint8Array(m.cmt*64);#H=0;#C=0;#m;#d=100;#G=0;#V=500;#re=0;#q="";#W=0;#se=0;#ie=0;#N=!0;#y=!1;#le=1;#ne;#Q=new Array(m.ch);#fe=new Uint8Array(2);#A=[];#K=new Uint8Array(m.ch);#Y=new Uint8Array(m.tr);baseBank=new te("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","krs","s90es");userBank=new te("gm");initOnReset=!1;aiEfxName="";chRedir(e,t,n){if(this.#Y[t])return(this.#Y[t]-1)*16+e;if([2,3].indexOf(this.#C)>-1){if(n==1)return e;let l=0,d=!0;for(;d;)this.#K[e+l]==0?(this.#K[e+l]=t,console.debug(`Assign track ${t} to channel ${e+l+1}.`),d=!1):this.#K[e+l]==t?d=!1:(l+=16,l>=128&&(l=0,d=!1));return e+l}else return e}forceVoiceRefresh(){for(let e=0;e{let n=e*128+t,l=this.#l.lastIndexOf(n);if(l>-1)if(this.#e[m.cc*e+b[64]]>63)this.#$[l]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#o[n],state:this.NOTE_HELD});else if(this.#e[m.cc*e+b[66]]>63&&this.#$[l]==this.NOTE_SOSTENUTO_SUSTAIN)this.#$[l]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#o[n],state:this.NOTE_SOSTENUTO_HELD});else{this.#l[l]=0,this.#o[n]=0,this.#$[l]=this.NOTE_IDLE;let d=this.getExt(e)[1];(d==this.VLBC_VELOINIT||d==this.VLBC_VELOALL)&&(this.#e[m.cc*e+b[129]]=0),this.dispatchEvent("note",{part:e,note:t,velo:0,state:this.NOTE_IDLE})}},nOn:(e,t,n)=>{let l=e*128+t,d=0;for(this.#u[e]&&this.#x.ano(e);this.#$[d]>0&&this.#l[d]!=l;)d++;if(d{},cAt:(e,t)=>{},hoOf:e=>{this.#$.forEach((t,n)=>{if(t==this.NOTE_HELD){let l=this.#l[n],d=l>>7;e==d&&(this.#$[n]=this.NOTE_IDLE,this.#l[n]=0,this.#o[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#$.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.#$[n]=l;let d=this.#l[n];this.dispatchEvent("note",{part:e,note:d&127,velo:this.#o[d],state:l})}})},soOf:e=>{this.#$.forEach((t,n)=>{if(t==this.NOTE_SOSTENUTO_HELD){let l=this.#l[n],d=l>>7;e==d&&(this.#$[n]=this.NOTE_IDLE,this.#l[n]=0,this.#o[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#l.forEach((t,n,l)=>{let d=t>>7,p=t&127;t==0&&this.#o[0]==0||d==e&&this.#x.nOff(d,p)})}};#ce={8:function(e){let t=e.channel,n=e.data[0];this.#x.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.#x.nOn(t,n,l):this.#x.nOff(t,n)},10:function(e){let t=e.channel,n=t*128+e.data[0];this.#l.indexOf(n)>-1&&(this.#o[n]=data[1],this.getExt(t)[1]==this.VLBC_VELOALL&&(this.#e[m.cc*t+b[129]]=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,n=this.#Q[t],l=n[e.data[0]];l&&(e.data[0]=l),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case k.s90es:case k.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 d=t*m.cc,p=t*m.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#x.ano(t),this.#M[t]=0,this.#e[d+b[1]]=0,this.#e[d+b[5]]=0,this.#e[d+b[64]]=0,this.#e[d+b[65]]=0,this.#e[d+b[66]]=0,this.#e[d+b[67]]=0,this.#e[d+b[11]]=127,this.#e[d+b[101]]=127,this.#e[d+b[100]]=127,this.#e[d+b[99]]=127,this.#e[d+b[98]]=127;return}case 123:{this.#x.ano(t);return}case 124:{this.#x.ano(t);return}case 125:{this.#x.ano(t);return}case 126:{this.#u[t]=1,this.#x.ano(t);return}case 127:{this.#u[t]=0,this.#x.ano(t);return}}if(b[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(dt.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(x()&&console.debug(`${A[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#s[t]>0&&(e.data[1]=this.#e[d],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(this.#m.x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(this.modeIdx[this.#m.ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==k.gs?e.data[1]<56&&this.#s[t]>0&&(e.data[1]=this.#e[d],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)):this.#t==k.gm&&(e.data[1]<48?this.#s[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){case k.xg:{[79,95,126,127].indexOf(e.data[1])>-1?this.#s[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#s[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?this.#k[p]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?this.#k[p]=this.EXT_DX:this.#k[p]=this.EXT_NONE;break}case k["05rw"]:case k.x5d:case k.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#s[t]==this.CH_MELODIC&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):[80,81,82,83].indexOf(e.data[1])>-1||this.#s[t]!=this.CH_MELODIC&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case k.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#s[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#s[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case k.g2:{e.data[1]==120?this.#s[t]==0&&(this.setChType(t,this.CH_DRUMS),console.debug(`CH${t+1} set to drums by MSB.`)):this.#s[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 2:{this.getExt(t)[1]==this.VLBC_BRTHEXPR&&(this.#e[d+b[129]]=e.data[1]);break}case 6:{if(this.#B){[k.xg,k.gs,k.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 g=this.#e[d+b[99]],v=this.#e[d+b[98]];if(g==1){let a=ht.indexOf(v);if(a>-1)this.#e[d+b[71+a]]=e.data[1],x()&&console.debug(`Redirected NRPN 1 ${v} to cc${71+a}.`),this.dispatchEvent("cc",{part:t,cc:71+a,data:e.data[1]});else{let r=Pe.indexOf(v);r>-1?this.#X[t*10+r]=e.data[1]-64:console.warn(`NRPN 0x01${v.toString(16).padStart(2,"0")} is not supported.`),x()&&console.debug(`CH${t+1} voice NRPN ${v} commit`)}}else{if(Q.indexOf(g)<0){let r=`NRPN 0x${g.toString(16).padStart(2,"0")}${v.toString(16).padStart(2,"0")} `;g==127?console.warn(`${r}is not necessary. Consider removing it.`):console.warn(`${r}is not supported.`)}else{let r=this.#s[t]-2;r<0?console.warn(`CH${t+1} cannot accept drum NRPN as type ${_[this.#s[t]]}.`):this.#a[(r*m.dpn+D[g])*m.dnc+v]=e.data[1]}x()&&console.debug(`CH${t+1} (${_[this.#s[t]]}) drum NRPN ${g} commit`)}}else{let g=Oe[this.#e[d+b[100]]],v=Le[this.#e[d+b[100]]];this.#e[d+b[101]]==0&&g!=null&&(x()&&console.debug(`CH${t+1} RPN 0 ${this.#e[d+b[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Ae[g][0]),Ae[g][1]),this.#r[t*m.rpn+g]=e.data[1],this.#n[t*m.rpnt+v]=1)}break}case 32:{switch(x()&&console.debug(`${A[this.#t]}, CH${t+1} LSB: ${e.data[1]}`),this.#t){case k.s90es:case k.motif:{this.setChType(t,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.getExt(t)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:t});break}case 38:{if(!this.#B){let g=Oe[this.#e[d+100]],v=Le[this.#e[d+100]];this.#e[d+101]==0&&g!=null&&(this.#r[t*m.rpn+g+1]=e.data[1],this.#n[t*m.rpnt+v]=1)}break}case 64:{e.data[1]<64&&this.#x.hoOf(t);break}case 66:{e.data[1]>>6?this.#x.soOn(t):this.#x.soOf(t);break}case 98:case 99:{this.#B=1;break}case 100:case 101:{this.#B=0;break}}this.#e[d+b[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 k.s90es:case k.motif:{e.data&&this.setChActive(t,1);break}default:this.setChActive(t,1)}if(this.getExt(t)[0]==this.EXT_DX){let n=m.cc*t}this.#i[t]=e.data,this.#w[t]=0,x()&&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.#l.forEach(function(l){let d=l>>7;n==d&&(t.#o[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.#M[t]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)})},15:function(e){pt(e.data).forEach(t=>{let n=t[0],l=t[1];(this.#oe[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.#D[e.meta]||function(n,l,d){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#G=0);let t=ft.indexOf(e.meta)>-1;if(x()&&console.debug(e),t)return e.reply="meta",e}};#oe={64:(e,t,n)=>{this.#ee.run(t,n,e)},65:(e,t,n)=>{if(t[0]<16)if(t[1]==72){let l=t[t.length-1],d=N(t.subarray(3,t.length-1));l==d?this.#I.run(t.subarray(0,t.length-1),n,e):console.warn(`Bad SD checksum ${l} - should be ${d}.`)}else this.#I.run(t,n,e);else{let l=t[t.length-1],d=N(t.subarray(2,t.length-1));l==d?this.#I.run(t.subarray(0,t.length-1),n,e):console.warn(`Bad GS checksum ${l} - should be ${d}.`)}},66:(e,t,n)=>{this.#z.run(t,n,e)},67:(e,t,n)=>{this.#P.run(t,n,e)},68:(e,t,n)=>{this.#ae.run(t,n,e)},71:(e,t,n)=>{this.#te.run(t,n,e)},126:(e,t,n)=>{this.#Z.run(t,n,e)},127:(e,t,n)=>{this.switchMode("gm"),this.#J.run(t,n,e)}};#Z;#J;#P;#I;#z;#ee;#te;#ae;buildRchTree(){let e=[];this.#h.forEach((t,n)=>{t{t&&(e.#Q[Math.floor(n/m.redir)][t]=n%m.redir|128)}),x()&&console.debug(e.#Q)}getActive(){return this.#S}getCc(e){let t=e*m.cc,n=this.#e.subarray(t,t+m.cc);return n[b[0]]=n[b[0]]||this.#H,n[b[32]]=n[b[32]]||this.#C,n[b[0]]==K.bank0&&(n[b[0]]=0),n}getCcCh(e,t){if(z.indexOf(t)<0)throw new Error("CC number not accepted");return this.#e[m.cc*e+b[t]]}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&!l&&(this.#e[e*m.cc+b[0]]=B[n])}setChActive(e,t=0){this.#S[e]!=t&&this.dispatchEvent("channeltoggle",{part:e,active:t}),this.#S[e]=t}getExt(e){let t=m.ext*e,n=this.#k.subarray(t,t+m.ext),l=new Uint8Array(n.length);return l.set(n),l[1]=l[1]||this.#le,l}getPitch(){return this.#M}getProgram(){return this.#i}getTexts(){return this.#A.slice()}getVel(e){let t=new Map,n=this;return n.#l.forEach(function(l,d){let p=Math.floor(l/128),g=l%128;e==p&&n.#o[l]>0&&t.set(g,{v:n.#o[l],s:n.#$[d]})}),t}getBitmap(){return{bitmap:this.#v,expire:this.#T}}getLetter(){return{text:this.#q,set:this.#se,expire:this.#W}}getMode(){return A[this.#t]}getMaster(){return{volume:this.#d}}getRawStrength(){let e=this;return this.#l.forEach(function(t){let n=Math.floor(t/128);e.#o[t]>e.#R[n]&&(e.#R[n]=e.#o[t])}),this.#R}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(n,l){e[l]=Math.floor(n*t.#e[l*m.cc+b[7]]*t.#e[l*m.cc+b[11]]*t.#d/803288)}),e}getRpn(){return this.#r}getNrpn(){return this.#X}getVoice(e,t,n,l){let d=e||this.#H,p=t,g=n||this.#C;d==K.bank0&&(d=0),A[this.#t]=="ns5r"&&d>0&&d<56&&(g=3);let v=this.userBank.get(d,p,g,l);if(A[this.#t]=="mt32"&&v.name.indexOf("MT-m:")==0){let a=parseInt(v.name.slice(5)),r=a*m.cmt,c="";this.#U.subarray(r,r+10).forEach(s=>{s>31&&(c+=String.fromCharCode(s))});let i=`MSB LSB PRG NME +0 127 ${p} ${c}`;this.userBank.load(i,!0),v.name=c,v.ending=" "}return(v.ending!=" "||!v.name.length)&&(v=this.baseBank.get(d,p,g,l)),v}getChVoice(e){let t=this.getVoice(this.#e[e*m.cc+b[0]],this.#i[e],this.#e[e*m.cc+b[32]],A[this.#t]);if(this.#w[e]){let n="";switch(this.#t){case k.mt32:{this.#L.subarray(m.cmt*(e-1),m.cmt*(e-1)+10).forEach(l=>{n+=String.fromCharCode(Math.max(l,32))}),n=n.trimRight();break}default:{let l=m.cvn*e;this.#_.subarray(l,l+m.cvn).forEach(d=>{n+=String.fromCharCode(Math.max(d,32))}),n=n.trimRight()}}n.length&&(t.ending="~",t.name=n)}return t}getRawPitch(){return this.#M}getPitchShift(e){let t=this,n=e*m.rpn,l=t.#r[n];return t.#n[e*m.rpnt]||t.#t==k.mt32&&(l=12),t.#M[e]/8192*l+(t.#r[n+3]-64)+((t.#r[n+1]<<7)+t.#r[n+2]-8192)/8192}getEffectType(e=0){let t=3*e+1;return this.#g.subarray(t,t+2)}setEffectTypeRaw(e=0,t,n){let l=3*e;this.#g[l]=1,this.#g[l+1+ +t]=n}setEffectType(e=0,t,n){this.setEffectTypeRaw(e,!1,t),this.setEffectTypeRaw(e,!0,n)}getEffectSink(){return this.#f}setLetterDisplay(e,t,n=0,l=3200){let d=this,p;d.#q=" ".repeat(n),e.forEach(g=>{d.#q+=String.fromCharCode(g>31?g:32),g<32&&(p=p||new Set,p.add(g))}),d.#se=Date.now(),d.#W=Date.now()+l,p&&(p=Array.from(p),p.forEach((g,v,a)=>{a[v]=g.toString(16).padStart(2,"0")}),console.warn(`${t}${t?" ":""}invalid code point${p.length>1?"s":""}: 0x${p.join(", 0x")}`))}setDetectionTargets(e="?",t=0){let n=this,l=-1;switch(e.replaceAll(", ",",").split(",").forEach(d=>{d=d.toLowerCase();let p=A.indexOf(lt[d]||d);x()&&console.debug(`Mapped mode "${d}" to ID "${p}".`),p>-1&&(l=p)}),x()&&console.debug(`Set detection target to ID "${l}".`),l>0&&(n.#m.x5=82,n.#m.ds=k.krs),l){case k["05rw"]:{n.#m.x5=81;break}case k.s90es:n.#m.ds=k.s90es;case k.motif:n.#m.ds=k.motif}}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let t=!0,n=0;for(;t&&n=m.ace&&console.warn("ACE slots are full.")}releaseAce(e){let t=!0,n=0;for(;t&&n=m.ace)throw new RangeError("No such ACE slot");let n=this.#b[t];if(n){if(z.indexOf(n)>=0)return this.#e[e*m.cc+b[n]];throw new Error(`Invalid ACE source: ${n}`)}else return 0}initDrums(){let e=this;e.#a.fill(64);for(let t=0;t-1){if(l.#t==0||t){let p=l.#t;l.initOnReset&&t&&(this.init(1),p=k["?"]),l.#t=d,l.#p=0,l.#H=Re[0][d],l.#C=Re[1][d];for(let v=0;v0&&l.#e[v*m.cc+b[0]]==B[p]&&(l.#e[v*m.cc]=B[d]);switch(d){case k.mt32:{se.forEach((v,a)=>{let r=a+1;l.#S[r]||(l.#i[r]=v,l.#e[r*m.cc+b[91]]=127)});for(let v=1;v<10;v++)l.dispatchEvent("voice",{part:v});break}}let g;switch(d){case k["?"]:case k.g2:{g=[52,4,52,18,0,0,0,0];break}case k.xg:{g=[1,0,65,0,5,0,0,0];break}case k.gm:case k.gs:{g=[40,4,40,18,40,32,32,0];break}case k.sd:{g=[58,0,60,0,61,0,61,0];break}case k["05rw"]:case k.x5d:case k.ns5r:{g=[44,1,44,19,44,0,44,0];break}case k.k11:case k.sg:{g=[24,0,0,0,0,0,0,0];break}case k.mt32:{g=[40,4,0,0,0,0,0,0];break}default:g=[0,0,0,0,0,0,0,0]}for(let v=0;v14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#ce[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),n=!1;this.#ne[t]?.forEach(l=>{e.channel=l,n=!0,this.#ce[e.type].call(this,e)}),n||console.warn(`${De[e.type]?De[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":{Y.context=this,n.userBank.load(await Y.read(e,t));break}}n.forceVoiceRefresh()}constructor(){super();let e=this;e.#v=new Uint8Array(256),e.#c[10]=new Uint8Array(512),e.#j=new O,e.#m={x5:82,ds:k.krs},e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -148,24 +148,25 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),e.addEventListener("metacommit",function(a){let{data:r}=a;e.#O[0]?.type==r.type&&e.#O[0]?.amend?(e.#O[0].amend=r.amend,e.#O[0].data+=r.data):e.#O.unshift(r)}),e.#D[1]=function(a){switch(a=a.replaceAll(`\r +122 006 000 `),e.addEventListener("metacommit",function(a){let{data:r}=a;e.#A[0]?.type==r.type&&e.#A[0]?.amend?(e.#A[0].amend=r.amend,e.#A[0].data+=r.data):e.#A.unshift(r)}),e.#D[1]=function(a){switch(a=a.replaceAll(`\r `,` `).replaceAll("\r",` -`),a.slice(0,2)){case"@I":{this.#m=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:a.slice(2)?.trimLeft()});break}case"@K":{this.#m=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:a.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{this.#m=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:a.slice(2)?.trimLeft()});break}case"@T":{this.#m=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:a.slice(2)?.trimLeft()});break}case"@V":{this.#m=!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((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":{r.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:a})}break}default:this.#m?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,c)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:r,mask:c!=0})})}},e.#D[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},e.#D[3]=function(a,r){r<1&&this.#H<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},e.#D[4]=function(a,r){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},e.#D[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},e.#D[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},e.#D[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},e.#D[32]=function(a){this.#H=a[0]+1},e.#D[33]=function(a,r){e.#Y[r]=a+1},e.#D[81]=function(a,r){e.#F=a/1e3},e.#D[127]=function(a,r){e.#j.run(a,r)},e.#j.default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},e.#j.add([67,0,1],function(a,r){e.#Y[r]=a[0]+1}),e.#Z=new L("universal non-realtime"),e.#J=new L("universal realtime"),e.#A=new L("Yamaha"),e.#I=new L("Roland"),e.#z=new L("Korg"),e.#ee=new L("Kawai"),e.#te=new L("Akai"),e.#ae=new L("Casio");let t=new L("DX7+ Dump"),n=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,a)};e.#Z.default=n,e.#J.default=n,e.#A.default=n,e.#I.default=n,e.#z.default=n,e.#ee.default=n,e.#te.default=n,e.#ae.default=n,t.default=n,e.#Z.add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),e.#m=e.#m||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),e.#J.add([4,1],a=>{e.#u=((a[1]<<7)+a[0])/16383*100,e.dispatchEvent("mastervolume",e.#u)}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64).add([4,5],a=>{let r=a[0],c=a[1],i=a[2],s=3,f=s+(r<<1),d=f+c;if(r!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${r})! -`,a);return}let h=0,u=0,v=0;switch(a.subarray(s,f).forEach(E=>{h=h<<7,h|=E}),a.subarray(f,d).forEach((E,$)=>{u|=E<<$*7}),a.subarray(d).forEach((E,$)=>{v|=E<<$*7}),x()&&console.debug(`GM2 global parameter: (${a.subarray(3,f)}; p: ${u}, v: ${v})`),h){case 129:{u==0&&(e.setEffectType(0,52,v),e.dispatchEvent("efxreverb",e.getEffectType(0)));break}case 130:{u==0&&(e.setEffectType(1,52,v|16),e.dispatchEvent("efxchorus",e.getEffectType(1)));break}default:x()&&console.debug("GM2 global paramater slot path unknown.")}}),this.#A.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.#m=!1,console.info("MIDI reset: XG");break}default:{let r=[0,0,0,0],c=(i,s)=>{r[s]=i};if(a.subarray(1).forEach((i,s)=>{let f=s+a[0];([c,c,c,c,d=>{this.#u=d*129/16383*100,e.dispatchEvent("mastervolume",e.#u)},d=>{},d=>{}][f]||(()=>{}))(i,s)}),a[0]<4){let i=0;r.forEach(s=>{i=i<<4,i+=s}),i-=1024}}}}).add([76,2,1],a=>{let r="XG ";a[0]<32?(r+="reverb ",a.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${r}main type: ${V[s]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{e.setEffectTypeRaw(0,!0,s),console.debug(`${r}sub type: ${s+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{console.debug(`${r}time: ${Ee(s)}s`)},s=>{console.debug(`${r}diffusion: ${s}`)},s=>{console.debug(`${r}initial delay: ${s}`)},s=>{console.debug(`${r}HPF cutoff: ${H[s]}Hz`)},s=>{console.debug(`${r}LPF cutoff: ${H[s]}Hz`)},s=>{console.debug(`${r}width: ${s}`)},s=>{console.debug(`${r}height: ${s}`)},s=>{console.debug(`${r}depth: ${s}`)},s=>{console.debug(`${r}wall type: ${s}`)},s=>{console.debug(`${r}dry/wet: ${s}`)},s=>{console.debug(`${r}send: ${M(s)}dB`)},s=>{console.debug(`${r}pan: ${s-64}`)},!1,!1,s=>{console.debug(`${r}delay: ${s}`)},s=>{console.debug(`${r}density: ${s}`)},s=>{console.debug(`${r}balance: ${s}`)},s=>{},s=>{console.debug(`${r}feedback: ${s}`)},s=>{}][a[0]+i]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(c)})):a[0]<64?(r+="chorus ",a.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${r}main type: ${V[s]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{e.setEffectTypeRaw(1,!0,s),console.debug(`${r}sub type: ${s+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{console.debug(`${r}LFO: ${ve[s]}Hz`)},s=>{},s=>{console.debug(`${r}feedback: ${s}`)},s=>{console.debug(`${r}delay offset: ${we(s)}ms`)},s=>{},s=>{console.debug(`${r}low: ${H[s]}Hz`)},s=>{console.debug(`${r}low: ${s-64}dB`)},s=>{console.debug(`${r}high: ${H[s]}Hz`)},s=>{console.debug(`${r}high: ${s-64}dB`)},s=>{console.debug(`${r}dry/wet: ${s}`)},s=>{console.debug(`${r}send: ${M(s)}dB`)},s=>{console.debug(`${r}pan: ${s-64}`)},s=>{console.debug(`${r}to reverb: ${M(s)}dB`)},!1,s=>{},s=>{},s=>{},s=>{console.debug(`${r}LFO phase diff: ${(s-64)*3}deg`)},s=>{console.debug(`${r}input mode: ${s?"stereo":"mono"}`)},s=>{}][a[0]-32+i]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(c)})):a[0]<86?(r+="variation ",a.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${r}main type: ${V[s]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},s=>{e.setEffectTypeRaw(2,!0,s),console.debug(`${r}sub type: ${s+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+i]||function(){})(c)})):a[0]<97?(r+="variation ",a.subarray(1).forEach((c,i)=>{[s=>{console.debug(`${r}send: ${M(s)}dB`)},s=>{console.debug(`${r}pan: ${s-64}`)},s=>{console.debug(`${r}to reverb: ${M(s)}dB`)},s=>{console.debug(`${r}to chorus: ${M(s)}dB`)},s=>{console.debug(`${r}connection: ${s?"system":"insertion"}`)},s=>{console.debug(`${r}channel: CH${s+1}`)},s=>{console.debug(`${r}mod wheel: ${s-64}`)},s=>{console.debug(`${r}bend wheel: ${s-64}`)},s=>{console.debug(`${r}channel after touch: ${s-64}`)},s=>{console.debug(`${r}AC1: ${s-64}`)},s=>{console.debug(`${r}AC2: ${s-64}`)}][a[0]-86+i](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 i=c+a[0];if(i==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][r]}`);else{let s=i-1>>2,f=i-1&3,d=`XG EQ ${s} ${["gain","freq","Q","shape"][f]}: `;[()=>{console.debug(`${d}${r-64}dB`)},()=>{console.debug(`${d}${r} (raw)`)},()=>{console.debug(`${d}${r/10}`)},()=>{console.debug(`${d}${["shelf","peak"][+!!r]}`)}][f]()}})}).add([76,3],a=>{let r=a[0],c=a[1],i=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((s,f)=>{([d=>{e.setEffectTypeRaw(3+r,!1,d),console.info(`${i}main type: ${V[d]}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))},d=>{e.setEffectTypeRaw(3+r,!0,d),console.debug(`${i}sub type: ${d+1}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))}][c+f]||function(){})(s)})}).add([76,6,0],a=>{let r=a[0];r<64?e.setLetterDisplay(a.subarray(1),"XG letter display",r):e.#W=Date.now()}).add([76,7,0],a=>{let r=a[0];e.#b=0,e.#x=Date.now()+3200,e.#y.fill(0);let c=a.subarray(1);for(let i=0;i>6-v&1,v++})}).add([76,8],(a,r)=>{let c=e.chRedir(a[0],r,!0),i=a[1],s=m.cc*c,f=`XG CH${c+1} `,d=`Unknown XG part address ${i}.`;a.subarray(2).forEach((h,u)=>{i<1?console.debug(d):i<41?([()=>{e.#e[s+b[0]]=h,e.dispatchEvent("voice",{part:c})},()=>{e.#e[s+b[32]]=h,e.dispatchEvent("voice",{part:c})},()=>{e.#i[c]=h,e.dispatchEvent("voice",{part:c})},()=>{let v=e.chRedir(h,r,!0);e.#f[c]=v,c!=v&&(e.buildRchTree(),console.info(`${f}receives from CH${v+1}`))},()=>{e.#p[c]=+!h},()=>{},()=>{e.setChType(c,h,k.xg),console.debug(`${f}type: ${_[h]||h}`)},()=>{e.#r[m.rpn*c+3]=h,e.#n[m.rpnt*c+2]=1},!1,!1,()=>{e.#e[s+b[7]]=h},!1,!1,()=>{e.#e[s+b[10]]=h||128},!1,!1,()=>{e.#e[s+b[128]]=h},()=>{e.#e[s+b[93]]=h},()=>{e.#e[s+b[91]]=h},()=>{e.#e[s+b[94]]=h},()=>{e.#e[s+b[76]]=h},()=>{e.#e[s+b[77]]=h},()=>{e.#e[s+b[78]]=h},()=>{e.#e[s+b[74]]=h},()=>{e.#e[s+b[71]]=h},()=>{e.#e[s+b[73]]=h},()=>{e.#e[s+b[75]]=h},()=>{e.#e[s+b[72]]=h}][i+u-1]||(()=>{}))():i<48?console.debug(d):i<111?i>102&&i<105&&(e.#e[s+b[[5,65][i&1]]]=h):i<114?console.debug(d):i<116?console.debug(`${f}EQ ${["bass","treble"][i&1]} gain: ${h-64}dB`):i<118?console.debug(d):i<120?console.debug(`${f}EQ ${["bass","treble"][i&1]} freq: ${h}`):console.debug(d)})}).add([76,9],(a,r)=>{let c=e.chRedir(a[0],r,!0),i=a[1],s=m.cc*c,f=`PLG-VL CH${c+1} `;a.subarray(2).forEach((d,h)=>{let u=h+i;switch(u){case 1:{console.info(`${f}breath mode: ${["system","breath","velocity","touch EG"][d]}`);break}case 0:case 27:case 28:break;default:if(u<27){let v=u-3>>1,E=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][v];u&1?u<23?(console.debug(`${f}${E} control source: ${xe(d)}`),d&&d<96&&e.allocateAce(130+v),e.#v[m.redir*c+v+2]=d,e.buildRccMap()):console.debug(`${f}${E} scale break point: ${d}`):(console.debug(`${f}${E} depth: ${d-64}`),e.#e[s+b[130+v]]=d)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{switch(console.debug(`XG enable PLG-${["VL","SG","DX","AN","PF","DR","PC","AP"][a[0]]} for CH${a[2]+1}.`),a[0]){case 0:{e.#C[m.ext*a[2]]=e.EXT_VL;break}default:e.#C[m.ext*a[2]]=e.EXT_NONE}}).add([73,0,0],(a,r)=>{let c=a[0],i="MU1000 System: ";a.subarray(1).forEach((s,f)=>{let d=c+f;d==8?console.debug(`${i}LCD contrast set to ${s}.`):d==18?(e.#L=s?126:0,console.debug(`${i}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):d>=64&&d<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")},()=>{e.#B=!!s,console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][d-64]()})}).add([73,10,0],(a,r)=>{let c=a[0],i=`MU1000 RS${e.#B?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let s=e.chRedir(0,r,!0);e.#B&&(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,r,!0);e.#B&&e.dispatchEvent("channelmin",s),e.#B&&e.dispatchEvent("channelmax",s+31),console.info(`${i}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${i}unknown switch ${c} invoked.`)}else if(c<32){if(e.#B){let s=e.chRedir(c-16+(e.#re<<4),r,!0);e.dispatchEvent("channelactive",s)}}else if(c<36){let s=e.chRedir(c-32<<4,r,!0);e.#B&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),e.#re=c-32),console.info(`${i}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(a,r)=>{let c=e.chRedir(a[0],r,!0),i=`PLG-100SG CH${c+1} `,s=Date.now();if(a[1]==0){let f="",d=0;a.subarray(2).forEach((h,u)=>{u%2==0?f+=$e[h]||h.toString().padStart("0"):d+=h*13}),s>=e.#G&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${ke(f)}`,amend:!0}),e.#G=s+Math.ceil(d/2)+e.#F,x()&&console.debug(`${i}vocals: ${f}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)}).add([100,0],(a,r,c)=>{let i=a.subarray(0,a.length-1),s=N(i),f=a[a.length-1];if(s!=f){console.warn(`Yamaha DX7 dump SysEx checksum mismatch! Expected ${s}, but got ${f}: -`,a);return}else t.run(i)}),t.add([0,14,31],a=>{e.#e[m.cc*a[0]+b[64]]=0,e.#k.ano(a[0]),e.switchMode("xg"),console.debug(`Yamaha DX7+ reset CH${a[0]+1}.`)}).add([56,76,112],async a=>{let r=a[0],c="";a.subarray(1).forEach((i,s)=>{s<10&&(c+=String.fromCharCode(Math.max(i,32)))}),e.#i[r]=r&127,e.#e[m.cc*r+b[0]]=35,e.#e[m.cc*r+b[32]]=r>>7|2,e.dispatchEvent("voice",{part:r}),c.length>0&&(c=c.trimRight(),console.debug(`DX7+ CH${r+1} dumped voice name: "${c}"`))});let l=function(a,r,c,i){},o=function(a,r){let c=a*m.dpn,i=r[0],s=r[1];r.subarray(2).forEach((f,d)=>{let h=d+s,u=-1;h<16?([()=>{u=24},()=>{u=25},()=>{u=26},()=>{},()=>{u=28},()=>{u=29},()=>{u=30},()=>{u=31},()=>{},()=>{},()=>{},()=>{u=20},()=>{u=21},()=>{u=22},()=>{u=23},()=>{}][h]||(()=>{console.debug(`Unknown XG-style drum param ${h} on set ${a+1}.`)}))():h<32||(h<40?([()=>{u=48},()=>{u=49},!1,!1,()=>{u=52},()=>{u=53}][h-32]||(()=>{console.debug(`Unknown XG-style drum param ${h} on set ${a+1}.`)}))():h<80||([()=>{u=36}][h-80]||(()=>{console.debug(`Unknown XG-style drum param ${h} on set ${a+1}.`)}))()),u>=0?(x()&&console.debug(c,u,i,f),e.#a[(c+D[u])*m.dnc+i]=f):x()&&console.debug(`XG-style drum param ${h} has no writes.`)})},p=function(a,r,c){let i=a*m.dpn,s=(r<<7)+c[0];c.subarray(1).forEach((f,d)=>{let h=d+s,u=h&127,v=h>>7,E=-1;v>1&&([()=>{E=26},()=>{},()=>{E=28},()=>{E=29},()=>{E=30},()=>{},()=>{},()=>{E=31}][v-2]||(()=>{console.debug(`Unknown GS-style drum param ${v} on set ${a+1}.`)}))(),E>-1?(x()&&console.debug(i,E,u,f),e.#a[(i+D[E])*m.dnc+u]=f):x()&&console.debug(`GS-style drum param ${v} has no writes.`)})};this.#A.add([76,48],(a,r,c)=>{o(0,a)}).add([76,49],(a,r,c)=>{o(1,a)}).add([76,50],(a,r,c)=>{o(2,a)}).add([76,51],(a,r,c)=>{o(3,a)}).add([76,52],(a,r,c)=>{o(4,a)}).add([76,53],(a,r,c)=>{o(5,a)}).add([76,54],(a,r,c)=>{o(6,a)}).add([76,55],(a,r,c)=>{o(7,a)}),this.#A.add([89,0],(a,r,c)=>{if(e.eprom){let i=a[0],s=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);x()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${i} bytes.`);let f=e.eprom.data;a.subarray(4).forEach((d,h)=>{let u=h>>3,v=h&7;if(v==7)for(let E=0;E<7;E++)f[s+7*u+E]+=(d>>6-E&1)<<7;else f[s+7*u+v]=d})}}).add([89,1],(a,r,c)=>{let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];x()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(a,r,c)=>{if(e.eprom){let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);x()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;a.subarray(4).forEach((f,d)=>{let h=d>>3,u=d&7;if(u==7)for(let v=0;v<7;v++)s[i+7*h+v]+=(f>>6-v&1)<<7;else s[i+7*h+u]=f})}}).add([89,3],(a,r,c)=>{}),this.#A.add([39,48],(a,r,c)=>{}).add([43,0,0],(a,r,c)=>{let i=[0,0,0,0],s=(f,d)=>{i[d]=f};if(a.subarray(1).forEach((f,d)=>{let h=d+a[0];[s,s,s,s,()=>{this.#u=f*129/16383*100,e.dispatchEvent("mastervolume",e.#u)},()=>f-64,()=>f||128,()=>f,()=>f,()=>{console.debug(`TG300 variation on cc${f}.`)}][h](f,h)}),a[0]<4){let f=0;i.forEach(d=>{f=f<<4,f+=d}),f-=1024}}).add([43,1,0],(a,r,c)=>{}).add([43,2],(a,r,c)=>{let i=e.chRedir(a[0],r,!0),s=a[1],f=m.cc*i,d=`TG300 CH${i+1} `;a.subarray(2).forEach((h,u)=>{u<5?([()=>{},()=>{e.#e[f+b[0]]=h,e.dispatchEvent("voice",{part:i})},()=>{e.#e[f+b[32]]=h,e.dispatchEvent("voice",{part:i})},()=>{e.#i[i]=h,e.dispatchEvent("voice",{part:i})},()=>{let v=e.chRedir(h,r,!0);e.#f[i]=v,i!=v&&(e.buildRchTree(),console.info(`${d}receives from CH${v+1}`))}][u+s]||(()=>{}))(h,u+s):u<21||(u<47?([()=>{e.#p[i]=+!h},()=>{},()=>{},()=>{e.#r[m.rpn*i+3]=h,e.#n[m.rpnt*i+2]=1},()=>{},()=>{e.#e[f+b[7]]=h},!1,!1,()=>{e.#e[f+b[10]]=h||128},!1,!1,()=>{console.debug(`${d} AC1 at cc${h}`)},()=>{console.debug(`${d} AC2 at cc${h}`)},()=>{e.#e[f+b[128]]=h},()=>{e.#e[f+b[93]]=h},()=>{e.#e[f+b[91]]=h},()=>{e.#e[f+b[94]]=h},()=>{e.#e[f+b[76]]=h},()=>{e.#e[f+b[77]]=h},()=>{e.#e[f+b[74]]=h},()=>{e.#e[f+b[71]]=h},()=>{e.#e[f+b[73]]=h},()=>{e.#e[f+b[75]]=h},()=>{e.#e[f+b[72]]=h},()=>{e.#e[f+b[78]]=h}][u+s-21]||(()=>{}))(h,u+s):u<95||([()=>{e.#e[f+b[65]]=h},()=>{e.#e[f+b[5]]=h}][u+s-95]||(()=>{}))(h,u+s))})}).add([43,7,0],(a,r,c)=>{let i=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",i)}).add([43,7,1],(a,r,c)=>{e.#b=0,e.#x=Date.now()+3200,e.#y.fill(0),a.forEach(function(i,s){let f=Math.floor(s/16),d=s%16,h=(d*3+f)*7,u=7,v=0;for(h-=d*5,f==2&&(u=2);v>6-v&1,v++})}),this.#I.add([66,18,0,0,127],(a,r,c)=>{e.switchMode("gs",!0),e.#e[m.cc*9]=120,e.#e[m.cc*25]=120,e.#e[m.cc*41]=120,e.#e[m.cc*57]=120,e.#L=3,e.#m=!1,e.#K.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),e.#e[m.cc*9]=120,e.#e[m.cc*25]=120,e.#e[m.cc*41]=120,e.#e[m.cc*57]=120,e.#m=!1,e.#K.fill(0),console.info("MIDI reset: GS");break}default:{let i=[0,0,0,0],s=(f,d)=>{i[d]=f};if(a.subarray(1).forEach((f,d)=>{let h=d+a[0];[s,s,s,s,u=>{this.#u=u*129/16383*100,e.dispatchEvent("mastervolume",e.#u)},u=>{},u=>{}][h](f,d)}),a[0]<4){let f=0;i.forEach(d=>{f=f<<4,f+=d}),f-=1024}}}}).add([66,18,64,1],a=>{let r=a[0];if(r<16){let c="".padStart(r," ");a.subarray(1).forEach((i,s)=>{c+=String.fromCharCode(Math.max(32,i))}),c=c.padEnd(16," "),console.debug(`GS patch name: ${c}`)}else r<48||(r<65?a.subarray(1).forEach((c,i)=>{let s=`GS ${r+i>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${re[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${c}ms`)},()=>{console.info(`${s}type: ${Te[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${M(c)}`)},()=>{console.debug(`${s}to delay: ${M(c)}`)}][r+i-48]||(()=>{}))()}):r<80?console.debug(`Unknown GS patch address: ${r}`):r<91?a.subarray(1).forEach((c,i)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${Se[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${M(c)}`)}][r+i-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${r}`))}).add([66,18,64,2],a=>{let r="GS EQ ";a.subarray(1).forEach((c,i)=>{([()=>{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]+i]||function(){console.warn(`Unknown GS EQ address: ${a[0]+i}`)})()})}).add([66,18,64,3],a=>{let r="GS EFX ",c=function(i,s){let f=Ce(e.#g.subarray(10,12),s,i);f&&console.debug(`${r}${ie(e.#g.subarray(10,12))} ${f}`)};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(`${r}type: ${ie(e.#g.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: ${M(i)}dB`)},()=>{console.debug(`${r}to chorus: ${M(i)}dB`)},()=>{console.debug(`${r}to delay: ${M(i)}dB`)},!1,()=>{console.debug(`${r}1 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${r}1 depth: ${i-64}`)},()=>{console.debug(`${r}2 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${r}2 depth: ${i-64}`)},()=>{console.debug(`${r}to EQ: ${i?"ON":"OFF"}`)}][a[0]+s]||function(f,d){console.warn(`Unknown GS EFX address: ${d}`)})(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=>{switch(a[0]){case 0:{let r=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",r);break}case 32:{e.#x=Date.now()+3200,a[1]==0&&(e.#b=Math.max(Math.min(a[2]-1,9),0),x()&&console.debug(`GS switch display page ${a[2]-1}.`));break}default:if(a[0]<6){e.#b>9&&(e.#b=0);let r=a[0]-1<<1|a[1]>>6;e.#b==r&&(e.#x=Date.now()+3200),e.#c[r]?.length||(e.#c[r]=new Uint8Array(256));let c=e.#c[r];x()&&console.debug(`GS frame draw page ${r}.`);let i=a[1]&63;c.fill(0),a.subarray(2).forEach(function(f,d){let h=d+i,u=Math.floor(h/16),v=h%16,E=(v*4+u)*5,$=5,T=0;for(E-=v*4,u==3&&($=1);T<$;)c[E+T]=f>>4-T&1,T++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let g=function(a,r,c){let i=a[0],s=m.cc*r,f=m.rpn*r,d=`GS CH${r+1} `;i<3?(a.subarray(1).forEach((h,u)=>{[()=>{e.#e[s+b[0]]=h},()=>{e.#i[r]=h},()=>{let v=0;h<16?v=e.chRedir(h,c,!0):v=m.ch,e.#f[r]=v,r!=v&&(e.buildRchTree(),console.info(`${d}receives from CH${v+1}`))}][i+u]()}),e.dispatchEvent("voice",{part:r})):i<19||(i<44?a.subarray(1).forEach((h,u)=>{([()=>{e.#p[r]=+!h},!1,()=>{e.setChType(r,h<<1,k.gs),console.debug(`${d}type: ${h?"drum ":"melodic"}${h||""}`)},()=>{e.#r[f+3]=h,e.#n[m.rpnt*r+2]=1},!1,()=>{e.#e[s+b[7]]=h},!1,!1,()=>{e.#e[s+b[10]]=h||128},!1,!1,()=>{console.debug(`${d}CC 1: cc${h}`)},()=>{console.debug(`${d}CC 2: cc${h}`)},()=>{e.#e[s+b[93]]=h},()=>{e.#e[s+b[91]]=h},!1,!1,()=>{e.#r[f+1]=h,e.#n[m.rpnt*r+1]=1},()=>{e.#r[f+2]=h,e.#n[m.rpnt*r+1]=1},()=>{e.#e[s+b[94]]=h}][i+u-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},y=function(a,r){let c=a[0],i=`GS CH${r+1} `;c<2?a.subarray(1).forEach((s,f)=>{[()=>{e.#e[m.cc*r+b[32]]=s},()=>{}][c+f]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?a.subarray(1).forEach((s,f)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][s]}`),e.#d[r]=s,e.dispatchEvent("partefxtoggle",{part:r,active:s})}][c+f-32]()}):console.warn(`Unknown GS misc address: ${c}`)};this.#I.add([66,18,64,16],(a,r)=>{g(a,e.chRedir(9,r,!0),r)}).add([66,18,64,17],(a,r)=>{g(a,e.chRedir(0,r,!0),r)}).add([66,18,64,18],(a,r)=>{g(a,e.chRedir(1,r,!0),r)}).add([66,18,64,19],(a,r)=>{g(a,e.chRedir(2,r,!0),r)}).add([66,18,64,20],(a,r)=>{g(a,e.chRedir(3,r,!0),r)}).add([66,18,64,21],(a,r)=>{g(a,e.chRedir(4,r,!0),r)}).add([66,18,64,22],(a,r)=>{g(a,e.chRedir(5,r,!0),r)}).add([66,18,64,23],(a,r)=>{g(a,e.chRedir(6,r,!0),r)}).add([66,18,64,24],(a,r)=>{g(a,e.chRedir(7,r,!0),r)}).add([66,18,64,25],(a,r)=>{g(a,e.chRedir(8,r,!0),r)}).add([66,18,64,26],(a,r)=>{g(a,e.chRedir(10,r,!0),r)}).add([66,18,64,27],(a,r)=>{g(a,e.chRedir(11,r,!0),r)}).add([66,18,64,28],(a,r)=>{g(a,e.chRedir(12,r,!0),r)}).add([66,18,64,29],(a,r)=>{g(a,e.chRedir(13,r,!0),r)}).add([66,18,64,30],(a,r)=>{g(a,e.chRedir(14,r,!0),r)}).add([66,18,64,31],(a,r)=>{g(a,e.chRedir(15,r,!0),r)}).add([66,18,64,64],(a,r)=>{y(a,e.chRedir(9,r,!0))}).add([66,18,64,65],(a,r)=>{y(a,e.chRedir(0,r,!0))}).add([66,18,64,66],(a,r)=>{y(a,e.chRedir(1,r,!0))}).add([66,18,64,67],(a,r)=>{y(a,e.chRedir(2,r,!0))}).add([66,18,64,68],(a,r)=>{y(a,e.chRedir(3,r,!0))}).add([66,18,64,69],(a,r)=>{y(a,e.chRedir(4,r,!0))}).add([66,18,64,70],(a,r)=>{y(a,e.chRedir(5,r,!0))}).add([66,18,64,71],(a,r)=>{y(a,e.chRedir(6,r,!0))}).add([66,18,64,72],(a,r)=>{y(a,e.chRedir(7,r,!0))}).add([66,18,64,73],(a,r)=>{y(a,e.chRedir(8,r,!0))}).add([66,18,64,74],(a,r)=>{y(a,e.chRedir(10,r,!0))}).add([66,18,64,75],(a,r)=>{y(a,e.chRedir(11,r,!0))}).add([66,18,64,76],(a,r)=>{y(a,e.chRedir(12,r,!0))}).add([66,18,64,77],(a,r)=>{y(a,e.chRedir(13,r,!0))}).add([66,18,64,78],(a,r)=>{y(a,e.chRedir(14,r,!0))}).add([66,18,64,79],(a,r)=>{y(a,e.chRedir(15,r,!0))}),this.#z.add([54,65],(a,r)=>{e.switchMode("x5d");let c=a[a.length-1],i=a.subarray(0,a.length-1),s=N(i);s!=c&&(console.info(`X5D multi parameters checksum mismatch! Expected ${s}, got ${c}.`),console.debug(a));let f=(a[1]<<7)+a[0],d=(a[3]<<7)+a[2],h=e.chRedir(f&15,r,!0),u=m.cc*h;[()=>{d<1||(d<101?(e.setChType(h,e.CH_MELODIC,k.x5d),e.#i[h]=d-1,e.#e[u+b[0]]=e.#h.x5):d<229?(e.setChType(h,e.CH_MELODIC,k.x5d),e.#i[h]=d-101,e.#e[u+b[0]]=56):(e.setChType(h,e.CH_DRUMS,k.x5d),e.#i[h]=Ue[d-229]||0,e.#e[u+b[0]]=62)),e.dispatchEvent("voice",{part:h})},()=>{e.#e[u+b[7]]=d},()=>{d<31&&(e.#e[u+b[10]]=Math.round((d-15)*4.2+64))},()=>{e.#e[u+b[93]]=F(d)},()=>{e.#e[u+b[91]]=F(d)},()=>{e.#r[h*m.rpn+3]=d>8191?d-16320:64+d,e.#n[m.rpnt*h+2]=1},()=>{e.#r[h*m.rpn+1]=d>8191?d-16320:64+d,e.#n[m.rpnt*h+1]=1},()=>{d>0&&(e.#r[h*m.rpn]=d,e.#n[m.rpnt*h]=1)},()=>{}][f>>4]()}).add([54,76,0],(a,r)=>{e.switchMode(e.#h.x5=="81"?"05rw":"x5d",!0);let c="",i=e.#h.x5,s=0,f=0,d="MSB PRG LSB NME";O(a,function(h,u){if(u<16400){let v=u%164;switch(!0){case v<10:{h>31&&(c+=String.fromCharCode(h));break}case v==10:break;case v==11:{d+=` -${i} ${s} ${f} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}s>99&&(i=90,s=0)}}),e.userBank.clearRange({msb:e.#h.x5,prg:[0,99],lsb:0}),e.userBank.load(d),x()&&console.debug(d),e.forceVoiceRefresh()}).add([54,77,0],(a,r)=>{e.switchMode(e.#h.x5=="81"?"05rw":"x5d",!0);let c="",i=90,s=0,f=0,d="MSB PRG LSB NME";O(a,function(h,u){if(u<13600){let v=u%136;switch(!0){case v<10:{h>31&&(c+=String.fromCharCode(h));break}case v==11:{d+=` -${i} ${s} ${f} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(d),x()&&console.debug(d),e.forceVoiceRefresh()}).add([54,78],(a,r)=>{e.switchMode(e.#h.x5=="81"?"05rw":"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(e.#h.x5=="81"?"05rw":"x5d",!0),O(a,(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],(a,r)=>{e.switchMode(e.#h.x5=="81"?"05rw":"x5d",!0),O(a,function(c,i,s,f){if(i<192){let d=e.chRedir(Math.floor(i/12),r,!0),h=d*m.cc;switch(i%12){case 0:{c<128?(e.setChType(d,e.CH_MELODIC,k.x5d),e.#e[h+b[0]]=e.#h.x5,e.#i[d]=c):(e.setChType(d,e.CH_DRUMS,k.x5d),e.#e[h+b[0]]=62,e.#i[d]=Ue[c-128]),c>0&&e.setChActive(d,1),e.dispatchEvent("voice",{part:d});break}case 1:{e.#e[h+b[7]]=c;break}case 2:{e.#r[d*m.rpn+3]=c>127?c-192:64+c,e.#n[m.rpnt*d+2]=1;break}case 3:{e.#r[d*m.rpn+1]=c>127?c-192:64+c,e.#n[m.rpnt*d+1]=1;break}case 4:{c<31&&(e.#e[h+b[10]]=Math.round((c-15)*4.2+64));break}case 5:{let u=c>>4,v=c&15;e.#e[h+b[91]]=F(v),e.#e[h+b[93]]=F(u);break}case 10:break;case 11:{let u=e.chRedir(c&15,r,!0),v=c>>4;e.#f[d]=c,(u!=d||v)&&(console.info(`X5D Part CH${d+1} receives from CH${u+1}.`),e.buildRchTree())}}}else{let d=e.chRedir(i-192,r,!0)}})}),this.#I.add([22,18,127],a=>{e.switchMode("mt32",!0),e.#m=!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 i=e.chRedir(c,r,!0),s=a[1];a.subarray(2).forEach((f,d)=>{let h=d+s;e.#P[h+(i-1)*16]=f,([!1,()=>{let u=e.#P[i-1<<4];if(u<3){if(e.#$[i]=1,u==2)for(let v=0;v{e.#r[i*m.rpn+3]=f+40,e.#n[m.rpnt*i+2]=1},()=>{e.#r[i*m.rpn+1]=f+14,e.#n[m.rpnt*i+1]=1},()=>{e.#r[i*m.rpn]=f,e.#n[m.rpnt*i]=1},!1,()=>{e.#e[m.cc*i+b[91]]=f?127:0},!1,()=>{e.#e[m.cc*i+b[7]]=f},()=>{e.#e[m.cc*i+b[10]]=Math.ceil(f*9.05)}][h]||(()=>{}))()})}).add([22,18,1],(a,r,c)=>{e.switchMode("mt32");let i=c&7;console.debug(`MT-32 slot #${c+1} Drum: ${a}`);let s=a[0]<<7|a[1];a.subarray(2).forEach((f,d)=>{let h=d+s,u=(h>>2)+24,v=h&3,E=i*m.dpn;if(x()&&console.debug(`MT-32 temp drum note ${u} param ${v}: ${f}`),u<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${u}`);return}[()=>{},()=>{e.#a[(E+D[26])*m.dnc+u]=Math.round(f*1.27)},()=>{e.#a[(E+D[26])*m.dnc+u]=f*9+1&127},()=>{e.#a[(E+D[26])*m.dnc+u]=f?127:0}][v]()})}).add([22,18,2],(a,r,c)=>{e.switchMode("mt32");let i=e.chRedir(c,r,!0),s=a[1]+(a[0]<<7);s<10&&(e.#$[i]=1),a.subarray(2).forEach((f,d)=>{let h=d+s;h<14&&(e.#S[(i-1)*m.cmt+h]=f)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(a,r,c)=>{e.switchMode("mt32");let i=c&7;if(a[0]){let s=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((f,d)=>{let h=d+s,u=(h>>2)+24,v=h&3,E=i*m.dpn;if(x()&&console.debug(`MT-32 dev drum note ${u} param ${v}: ${f}`),u<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${u}`);return}[()=>{},()=>{e.#a[(E+D[26])*m.dnc+u]=Math.round(f*1.27)},()=>{e.#a[(E+D[26])*m.dnc+u]=f*9+1&127},()=>{e.#a[(E+D[26])*m.dnc+u]=f?127:0}][v]()})}else{let s=a[1];a.subarray(2).forEach((f,d)=>{let h=d+s;e.#P[h]=f;let u=e.chRedir(1+(h>>4),r,!0),v=h&15;([!1,()=>{let E=e.#P[u-1<<4];if(E<3)if(e.#$[u]=1,E==2)for(let $=0;${e.#r[u*m.rpn+3]=f+40,e.#n[m.rpnt*u+2]=1},()=>{e.#r[u*m.rpn+1]=f+14,e.#n[m.rpnt*u+1]=1},()=>{e.#r[u*m.rpn]=f,e.#n[m.rpnt*u]=1},!1,()=>{e.#e[m.cc*u+b[91]]=f?127:0},!1,()=>{e.#e[m.cc*u+b[7]]=f},()=>{e.#e[m.cc*u+b[10]]=Math.ceil(f*9.05)}][v]||(()=>{}))()})}}).add([22,18,4],(a,r,c)=>{e.switchMode("mt32");let i=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((f,d)=>{let h=d+i,u=e.chRedir(Math.floor(h/246+1),r,!0),v=h%246;v<14&&(e.#S[(u-1)*m.cmt+v]=f),v<10&&(e.#$[u]=1),s.indexOf(u)<0&&s.push(u)}),s.forEach(f=>{e.dispatchEvent("voice",{part:f})})}).add([22,18,5],(a,r,c)=>{e.switchMode("mt32");let i=(a[0]<<7)+a[1];a.subarray(2).forEach((s,f)=>{let d=i+f,h=Math.floor(d/8),u=d&7,v=h*8;e.#_[d]=s,([!1,()=>{let E=e.#_[v];if(E<3){let $="";if(E==2){let U=m.cmt*h;$=`MT-m:${s.toString().padStart(3,"0")}`}else $=e.baseBank.get(0,s+(E<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:h});let T=`MSB LSB PRG NME -000 127 ${h} ${$}`;e.userBank.load(T,!0)}}][u]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,r,c)=>{e.switchMode("mt32");let i=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((s,f)=>{let d=i+f;d>1)*m.cmt+d]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(a,r,c)=>{e.switchMode("mt32");let i=a[1],s=!1,f=function(d,h){e.#f[h-12]=d,s=!0};a.subarray(2).forEach((d,h)=>{let u=h+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,f,f,f,f,f,f,f,f,f,()=>{e.#u=d,e.dispatchEvent("mastervolume",e.#u)}][u]||(()=>{}))(d,h)}),s&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let r=a[1],c=" ".repeat(r);a.subarray(2).forEach(i=>{i>31?c+=String.fromCharCode(i):c+=" "}),e.#q=c.padStart(20," "),e.#W=Date.now()+3200}).add([22,18,82],(a,r)=>{let c=e.chRedir(0,r,!0);for(let i=0;i<16;i++)e.#k.ano(c+i),i&&i<10&&(e.#i[c+i]=se[i-1]);console.info("MT-32 alt reset complete.")}),this.#z.add([66,0],(a,r)=>{e.switchMode("ns5r",!0),e.#m=!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.#m=!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.#m=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(c<10){let i=[0,0,0,0],s=(f,d)=>{i[d]=f};if(a.subarray(1).forEach((f,d)=>{[s,s,s,s,()=>{e.#u=f*129/16383*100,e.dispatchEvent("mastervolume",e.#u)},()=>f-64,()=>f-64,()=>{},()=>{},()=>{}][c+d]()}),a[0]<4){let f=0;i.forEach(d=>{f=f<<4,f+=d}),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),i=c*m.cc,s=a[1],f=`NS5R CH${c+1} `;a.subarray(2).forEach((d,h)=>{let u=s+h;u<3?([()=>{e.#e[i+b[0]]=d||K.bank0},()=>{e.#e[i+b[32]]=d},()=>{e.#i[c]=d}][u](),e.dispatchEvent("voice",{part:c})):u<8||(u<14?[()=>{let v=e.chRedir(d,r,!0);e.#f[c]=v,c!=v&&(e.buildRchTree(),console.info(`${f}receives from CH${v+1}`))},()=>{e.#p[c]=+!d},()=>{e.setChType(c,d,k.ns5r),console.debug(`${f}type: ${_[d]}`)},()=>{e.#r[m.rpn*c+3]=d,e.#n[m.rpnt*c+2]=1},()=>{},()=>{}][u-8]():u<16||(u<33?[()=>{e.#e[i+b[7]]=d},()=>{e.#e[i+b[11]]=d},()=>{},()=>{},()=>{e.#e[i+b[10]]=d||128},()=>{},()=>{},()=>{e.#e[i+b[93]]=d},()=>{e.#e[i+b[91]]=d},()=>{e.#e[i+b[76]]=d},()=>{e.#e[i+b[77]]=d},()=>{e.#e[i+b[78]]=d},()=>{e.#e[i+b[74]]=d},()=>{e.#e[i+b[71]]=d},()=>{e.#e[i+b[73]]=d},()=>{e.#e[i+b[75]]=d},()=>{e.#e[i+b[72]]=d}][u-16]():u<112||u<114&&[()=>{e.#e[i+b[5]]=d},()=>{e.#e[i+b[65]]=d}][u-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 i=c-32;e.#x=Date.now()+3200,e.#b=10,e.#y.fill(0);let s=a.subarray(1),f=4;s.forEach(function(d,h){let u=h+i,v=u>>4,E=u&15;if(u<80){let $=v>3,T=0,U=v0;)e.#y[E*32+v*7+(U-T)]=$&1,$=$>>1,T++}})}}).add([66,18,48],(a,r,c)=>{o(0,a)}).add([66,18,49],(a,r,c)=>{o(1,a)}).add([66,18,50],(a,r,c)=>{o(2,a)}).add([66,18,51],(a,r,c)=>{o(3,a)}).add([66,18,52],(a,r,c)=>{o(4,a)}).add([66,18,53],(a,r,c)=>{o(5,a)}).add([66,18,54],(a,r,c)=>{o(6,a)}).add([66,18,55],(a,r,c)=>{o(7,a)}).add([66,52],(a,r)=>{e.switchMode("ns5r",!0),e.#m=!1;let c="";O(a,(i,s)=>{s<8?(i>31&&(c+=String.fromCharCode(i)),s==7&&(e.aiEfxName=c)):s<10&&(e.setEffectType(s-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(a,r)=>{e.switchMode("ns5r",!0),e.#m=!1;let c="",i=a[a.length-1],s=a.subarray(0,a.length-1),f=N(s);f!=i&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${f}, got ${i}.`),console.debug(a)),O(s,function(d,h){switch(!0){case h<2944:{let u=e.chRedir(Math.floor(h/92),r,!0),v=u*m.cc;switch(h%92){case 0:{e.#e[v+b[0]]=d,e.dispatchEvent("voice",{part:u});break}case 1:{e.#e[v+b[32]]=d,!d&&!e.#e[v+b[0]]&&(e.#e[v+b[0]]=K.bank0),e.dispatchEvent("voice",{part:u});break}case 2:{e.#i[u]=d,d>0&&e.setChActive(u,1),e.dispatchEvent("voice",{part:u});break}case 3:{let E=e.chRedir(d,r,!0);e.#f[u]=E,u!=E&&(console.info(`NS5R CH${u+1} receives from CH${E+1}.`),e.buildRchTree());break}case 7:{e.#s[u]=d,e.dispatchEvent("voice",{part:u});break}case 8:{e.#r[u*m.rpn+3]=d<40||d>88?d+(d>63?-192:64):d,e.#n[m.rpnt*u+2]=1;break}case 9:case 10:{e.#e[v+b[7]]=d;break}case 11:{e.#e[v+b[11]]=d;break}case 14:{e.#e[v+b[10]]=d||128;break}case 19:{e.#e[v+b[93]]=d;break}case 20:{e.#e[v+b[91]]=d;break}case 84:{e.#e[v+b[65]]=d;break}case 85:{e.#e[v+b[5]]=d;break}}break}case h<3096:break;case h<3134:{let u=h-3096;u<8?(d>31&&(c+=String.fromCharCode(d)),u==7&&(e.aiEfxName=c)):u<10&&(e.setEffectType(u-8,44,d),e.dispatchEvent(`efx${["reverb","chorus"][u-8]}`,e.getEffectType(u-8)));break}case h<8566:break}})}).add([66,54],(a,r)=>{e.switchMode("ns5r",!0);let c="",i=80,s=0,f=0,d="MSB PRG LSB NME";O(a,function(h,u){let v=u%158;switch(!0){case v<10:{h>31&&(c+=String.fromCharCode(h));break}case v==10:break;case v==11:{i=h&127;break}case v==12:{f=h&127;break}case v==13:{d+=` -${i} ${s} ${f} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(d),x()&&console.debug(d),e.forceVoiceRefresh()}).add([66,55],(a,r)=>{e.switchMode("ns5r",!0);let c="",i=88,s=0,f=0,d="MSB PRG LSB NME";O(a,function(h,u){let v=u%126;switch(!0){case v<10:{h>31&&(c+=String.fromCharCode(h));break}case v==11:break;case v==12:break;case v==13:{d+=` -${i} ${s} ${f} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(d),x()&&console.debug(d),e.forceVoiceRefresh()}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let r=a[a.length-1],c=a.subarray(0,a.length-1),i=N(c);i!=r&&(console.info(`NS5R screen dump checksum mismatch! Expected ${i}, got ${r}.`),console.debug(a));let s=new Uint8Array(5760);O(a,(f,d,h)=>{if(d<720)for(let u=0;u<8;u++)s[d*8+u]=f>>7-u&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(a,r,c)=>{e.#z.run([66,...a],r,c)}),this.#ee.add([16,0,8,0],(a,r,c)=>{let i=(a[2]<<4)+a[3],s="K11 ";([()=>{e.switchMode("k11",!0),e.#m=!1,e.#L=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,r,c)=>{let i=e.chRedir(a[1],r,!0),s=m.cc*i,f=m.rpn*i,d=(a[3]<<4)+a[4],h=`K11 CH${i+1} `;([()=>{d<128?(e.setChType(i,e.CH_MELODIC,k.k11),e.#e[s+b[0]]=0,e.#i[i]=d):(e.setChType(i,e.CH_DRUMS,k.k11),e.#i[i]=d-128),e.dispatchEvent("voice",{part:i})},()=>{let u=e.chRedir(d,r,!0);e.#f[i]=u,i!=u&&(e.buildRchTree(),console.info(`${h}receives from CH${u+1}`))},()=>{e.#e[s+b[7]]=d},()=>{uupThis.setChActive(i,d)},()=>{e.#e[s+b[10]]=d},()=>{e.#r[f+3]=d+40,e.#n[m.rpnt*i+2]=1},()=>{e.#r[f+1]=d>>1,e.#r[f+2]=d&1,e.#n[m.rpnt*i+1]=1},()=>{e.#e[s+b[91]]=d?127:0},()=>{},()=>{e.#e[s+b[74]]=d},()=>{e.#e[s+b[73]]=d},()=>{e.#e[s+b[72]]=d}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,r,c)=>{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,r,c)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],r,!0),f=s*m.cc;[()=>{i<128?(e.setChType(s,e.CH_MELODIC,k.k11),e.#e[f+b[0]]=0,e.#e[f+b[32]]=0,e.#i[s]=i):i<160?(e.setChType(s,e.CH_MELODIC,k.k11),e.#e[f+b[0]]=0,e.#e[f+b[32]]=7,e.#i[s]=i-100):(e.setChType(s,e.CH_DRUMS,k.k11),e.#e[f+b[0]]=122,e.#e[f+b[32]]=0,e.#i[s]=i-160),e.dispatchEvent("voice",{part:s})},()=>{let d=e.chRedir(i,r,!0);e.#f[s]=d,s!=d&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${d+1}`))}][a[0]]()}).add([16,0,9,4],(a,r,c)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],r,!0),f=s*m.cc,d=s*m.rpn,h=`GMLX CH${s+1} `;[()=>{e.setChActive(s,i)},()=>{e.#e[f+b[7]]=i},()=>{e.#e[f+b[10]]=i},()=>{e.#e[f+b[91]]=i?127:0},()=>{e.#r[d+3]=i+40,e.#n[m.rpnt*s+2]=1},()=>{e.#r[d+1]=i,e.#n[m.rpnt*s+1]=1},()=>{e.#r[d]=i,e.#n[m.rpnt*s]=1},()=>{}][a[0]]()}),this.#te.add([66,93,64],(a,r,c)=>{let i=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{e.#u=i*129/16383*100,e.dispatchEvent("mastervolume",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: ${re[i]}`);break}}break}default:if(a[0]>>4==1){let s=e.chRedir(a[0]&15,r,!0);if(a[1]==2){let f=e.chRedir(i,r,!0);e.#f[s]=f,s!=f&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${f+1}`))}else a[1]==19&&(e.#e[m.cc*s+b[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),this.#ae.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"}`)}),this.#A.add([127,0],(a,r,c)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...a]);e.#A.run(i,r,c)}).add([127,1,0,0],(a,r,c)=>{e.switchMode("s90es");let i="S90/Motif ES system ",s=a[0];a.subarray(1).forEach((f,d)=>{([()=>{e.#u=f*12900/16383,e.dispatchEvent("mastervolume",e.#u)}][s+d]||(()=>{console.info(`Unrecognized ${i}ID: ${s+d}`)}))()})}).add([127,1,0,0,14],(a,r,c)=>{e.switchMode("s90es");let i="S90/Motif ES bulk header ",s=[];s[95]=(f,d,h)=>{console.debug(`${i}multi edit buffer: ${f[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,r,c)=>{e.switchMode("s90es");let i="S90/Motif ES bulk footer ",s=[];s[95]=(f,d,h)=>{console.debug(`${i}multi edit buffer: ${f[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,r,c)=>{e.switchMode("s90es");let i=e.chRedir(a[0],r,!0),s=m.cc*i,f=a[1],d=`S90/Motif ES bulk CH${i<16?i+1:"U"+(i-95)} `;console.debug(d,a),!(a[0]>15)&&a.subarray(2).forEach((h,u)=>{([()=>{e.#e[s+b[0]]=h,e.dispatchEvent("voice",{part:i})},()=>{h&&e.setChActive(i,1),e.#e[s+b[32]]=h,e.setChType(i,[32,40].indexOf(h)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:i})},()=>{h&&e.setChActive(i,1),e.#i[i]=h,e.dispatchEvent("voice",{part:i})},()=>{let v=e.chRedir(h,r,!0);e.#f[i]=v,i!=v&&(e.buildRchTree(),console.info(`${d}receives from CH${v+1}`))},()=>{e.#p[i]=h?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{e.#e[s+b[7]]=h},()=>{e.#e[s+b[10]]=h},!1,!1,!1,()=>{e.#e[s+b[91]]=h},()=>{e.#e[s+b[93]]=h},()=>{e.#e[s+b[94]]=h},()=>{e.#e[s+b[128]]=h},()=>{},()=>{e.#e[s+b[74]]=h},()=>{e.#e[s+b[71]]=h},!1,()=>{e.#e[s+b[65]]=h},()=>{e.#e[s+b[5]]=h},()=>{}][f+u]||(()=>{}))()})}).add([127,1,54,16],(a,r,c)=>{e.switchMode("s90es");let i=a[0];a.subarray(1).forEach((s,f)=>{let h=`S90/Motif ES EQ${(f>>2)+1} `;([()=>{let u=s-64},()=>{let u=H[s]},()=>{let u=s/10},()=>{let u=s}][i+f&3]||(()=>{}))()})}),this.#I.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 i=a[0]>>5,s=a[0]&31;switch(i){case 0:{let f=a[0]>>1,d=a[1];switch(f){case 1:{a.subarray(2).forEach((h,u,v)=>{let E=u+d;switch(E){case 0:{h&&(e.setEffectType(1,60,h-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${E} - ${h}`));break}}});break}case 2:{a.subarray(2).forEach((h,u)=>{let v=u+d;switch(v){case 0:{h&&(e.setEffectType(0,55+h,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${v} - ${h}`));break}}});break}case 3:case 4:case 5:{let h=f-1;a.subarray(2).forEach((u,v)=>{let E=v+d;switch(console.debug(`SD MFX ${h-2}: ${E} - ${u}`),E){case 0:{e.setEffectTypeRaw(h,62,u),e.dispatchEvent(`efx${h>2?"delay":"insert"+(h-4)}`,e.getEffectType(h));break}}}),console.debug(`SD MFX message: +`),a.slice(0,2)){case"@I":{this.#y=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:a.slice(2)?.trimLeft()});break}case"@K":{this.#y=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:a.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{this.#y=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:a.slice(2)?.trimLeft()});break}case"@T":{this.#y=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:a.slice(2)?.trimLeft()});break}case"@V":{this.#y=!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((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":{r.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:a})}break}default:this.#y?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,c)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:r,mask:c!=0})})}},e.#D[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},e.#D[3]=function(a,r){r<1&&this.#G<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},e.#D[4]=function(a,r){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},e.#D[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},e.#D[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},e.#D[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},e.#D[32]=function(a){this.#G=a[0]+1},e.#D[33]=function(a,r){e.#Y[r]=a+1},e.#D[81]=function(a,r){e.#V=a/1e3},e.#D[127]=function(a,r){e.#j.run(a,r)},e.#j.default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},e.#j.add([67,0,1],function(a,r){e.#Y[r]=a[0]+1}),e.#Z=new O("universal non-realtime"),e.#J=new O("universal realtime"),e.#P=new O("Yamaha"),e.#I=new O("Roland"),e.#z=new O("Korg"),e.#ee=new O("Kawai"),e.#te=new O("Akai"),e.#ae=new O("Casio");let t=new O("DX7+ Dump"),n=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,a)};e.#Z.default=n,e.#J.default=n,e.#P.default=n,e.#I.default=n,e.#z.default=n,e.#ee.default=n,e.#te.default=n,e.#ae.default=n,t.default=n,e.#Z.add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),e.#y=e.#y||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),e.#J.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).add([4,5],a=>{let r=a[0],c=a[1],i=a[2],s=3,f=s+(r<<1),o=f+c;if(r!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${r})! +`,a);return}let h=0,u=0,y=0;switch(a.subarray(s,f).forEach(E=>{h=h<<7,h|=E}),a.subarray(f,o).forEach((E,$)=>{u|=E<<$*7}),a.subarray(o).forEach((E,$)=>{y|=E<<$*7}),x()&&console.debug(`GM2 global parameter: (${a.subarray(3,f)}; p: ${u}, v: ${y})`),h){case 129:{u==0&&(e.setEffectType(0,52,y),e.dispatchEvent("efxreverb",e.getEffectType(0)));break}case 130:{u==0&&(e.setEffectType(1,52,y|16),e.dispatchEvent("efxchorus",e.getEffectType(1)));break}default:x()&&console.debug("GM2 global paramater slot path unknown.")}}),this.#P.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.#y=!1,console.info("MIDI reset: XG");break}default:{let r=[0,0,0,0],c=(i,s)=>{r[s]=i};if(a.subarray(1).forEach((i,s)=>{let f=s+a[0];([c,c,c,c,o=>{this.#d=o*129/16383*100,e.dispatchEvent("mastervolume",e.#d)},o=>{},o=>{}][f]||(()=>{}))(i,s)}),a[0]<4){let i=0;r.forEach(s=>{i=i<<4,i+=s}),i-=1024}}}}).add([76,2,1],a=>{let r="XG ";a[0]<32?(r+="reverb ",a.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${r}main type: ${V[s]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{e.setEffectTypeRaw(0,!0,s),console.debug(`${r}sub type: ${s+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{console.debug(`${r}time: ${Ee(s)}s`)},s=>{console.debug(`${r}diffusion: ${s}`)},s=>{console.debug(`${r}initial delay: ${s}`)},s=>{console.debug(`${r}HPF cutoff: ${H[s]}Hz`)},s=>{console.debug(`${r}LPF cutoff: ${H[s]}Hz`)},s=>{console.debug(`${r}width: ${s}`)},s=>{console.debug(`${r}height: ${s}`)},s=>{console.debug(`${r}depth: ${s}`)},s=>{console.debug(`${r}wall type: ${s}`)},s=>{console.debug(`${r}dry/wet: ${s}`)},s=>{console.debug(`${r}send: ${M(s)}dB`)},s=>{console.debug(`${r}pan: ${s-64}`)},!1,!1,s=>{console.debug(`${r}delay: ${s}`)},s=>{console.debug(`${r}density: ${s}`)},s=>{console.debug(`${r}balance: ${s}`)},s=>{},s=>{console.debug(`${r}feedback: ${s}`)},s=>{}][a[0]+i]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(c)})):a[0]<64?(r+="chorus ",a.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${r}main type: ${V[s]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{e.setEffectTypeRaw(1,!0,s),console.debug(`${r}sub type: ${s+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{console.debug(`${r}LFO: ${ve[s]}Hz`)},s=>{},s=>{console.debug(`${r}feedback: ${s}`)},s=>{console.debug(`${r}delay offset: ${we(s)}ms`)},s=>{},s=>{console.debug(`${r}low: ${H[s]}Hz`)},s=>{console.debug(`${r}low: ${s-64}dB`)},s=>{console.debug(`${r}high: ${H[s]}Hz`)},s=>{console.debug(`${r}high: ${s-64}dB`)},s=>{console.debug(`${r}dry/wet: ${s}`)},s=>{console.debug(`${r}send: ${M(s)}dB`)},s=>{console.debug(`${r}pan: ${s-64}`)},s=>{console.debug(`${r}to reverb: ${M(s)}dB`)},!1,s=>{},s=>{},s=>{},s=>{console.debug(`${r}LFO phase diff: ${(s-64)*3}deg`)},s=>{console.debug(`${r}input mode: ${s?"stereo":"mono"}`)},s=>{}][a[0]-32+i]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(c)})):a[0]<86?(r+="variation ",a.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${r}main type: ${V[s]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},s=>{e.setEffectTypeRaw(2,!0,s),console.debug(`${r}sub type: ${s+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+i]||function(){})(c)})):a[0]<97?(r+="variation ",a.subarray(1).forEach((c,i)=>{[s=>{console.debug(`${r}send: ${M(s)}dB`)},s=>{console.debug(`${r}pan: ${s-64}`)},s=>{console.debug(`${r}to reverb: ${M(s)}dB`)},s=>{console.debug(`${r}to chorus: ${M(s)}dB`)},s=>{console.debug(`${r}connection: ${s?"system":"insertion"}`)},s=>{console.debug(`${r}channel: CH${s+1}`)},s=>{console.debug(`${r}mod wheel: ${s-64}`)},s=>{console.debug(`${r}bend wheel: ${s-64}`)},s=>{console.debug(`${r}channel after touch: ${s-64}`)},s=>{console.debug(`${r}AC1: ${s-64}`)},s=>{console.debug(`${r}AC2: ${s-64}`)}][a[0]-86+i](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 i=c+a[0];if(i==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][r]}`);else{let s=i-1>>2,f=i-1&3,o=`XG EQ ${s} ${["gain","freq","Q","shape"][f]}: `;[()=>{console.debug(`${o}${r-64}dB`)},()=>{console.debug(`${o}${r} (raw)`)},()=>{console.debug(`${o}${r/10}`)},()=>{console.debug(`${o}${["shelf","peak"][+!!r]}`)}][f]()}})}).add([76,3],a=>{let r=a[0],c=a[1],i=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((s,f)=>{([o=>{e.setEffectTypeRaw(3+r,!1,o),console.info(`${i}main type: ${V[o]}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))},o=>{e.setEffectTypeRaw(3+r,!0,o),console.debug(`${i}sub type: ${o+1}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))}][c+f]||function(){})(s)})}).add([76,6,0],a=>{let r=a[0];r<64?e.setLetterDisplay(a.subarray(1),"XG letter display",r):e.#W=Date.now()}).add([76,7,0],a=>{let r=a[0];e.#p=0,e.#T=Date.now()+3200,e.#v.fill(0);let c=a.subarray(1);for(let i=0;i>6-y&1,y++})}).add([76,8],(a,r)=>{let c=e.chRedir(a[0],r,!0),i=a[1],s=m.cc*c,f=`XG CH${c+1} `,o=`Unknown XG part address ${i}.`;a.subarray(2).forEach((h,u)=>{i<1?console.debug(o):i<41?([()=>{e.#e[s+b[0]]=h,e.dispatchEvent("voice",{part:c})},()=>{e.#e[s+b[32]]=h,e.dispatchEvent("voice",{part:c})},()=>{e.#i[c]=h,e.dispatchEvent("voice",{part:c})},()=>{let y=e.chRedir(h,r,!0);e.#h[c]=y,c!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))},()=>{e.#u[c]=+!h},()=>{},()=>{e.setChType(c,h,k.xg),console.debug(`${f}type: ${_[h]||h}`)},()=>{e.#r[m.rpn*c+3]=h,e.#n[m.rpnt*c+2]=1},!1,!1,()=>{e.#e[s+b[7]]=h},!1,!1,()=>{e.#e[s+b[10]]=h||128},!1,!1,()=>{e.#e[s+b[128]]=h},()=>{e.#e[s+b[93]]=h},()=>{e.#e[s+b[91]]=h},()=>{e.#e[s+b[94]]=h},()=>{e.#e[s+b[76]]=h},()=>{e.#e[s+b[77]]=h},()=>{e.#e[s+b[78]]=h},()=>{e.#e[s+b[74]]=h},()=>{e.#e[s+b[71]]=h},()=>{e.#e[s+b[73]]=h},()=>{e.#e[s+b[75]]=h},()=>{e.#e[s+b[72]]=h}][i+u-1]||(()=>{}))():i<48?console.debug(o):i<111?i>102&&i<105&&(e.#e[s+b[[5,65][i&1]]]=h):i<114?console.debug(o):i<116?console.debug(`${f}EQ ${["bass","treble"][i&1]} gain: ${h-64}dB`):i<118?console.debug(o):i<120?console.debug(`${f}EQ ${["bass","treble"][i&1]} freq: ${h}`):console.debug(o)})}).add([76,9],(a,r)=>{let c=e.chRedir(a[0],r,!0),i=a[1],s=m.cc*c,f=`PLG-VL CH${c+1} `;a.subarray(2).forEach((o,h)=>{let u=h+i;switch(u){case 1:{console.info(`${f}breath mode: ${["system","breath","velocity","touch EG"][o]}`);break}case 0:case 27:case 28:break;default:if(u<27){let y=u-3>>1,E=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][y];u&1?u<23?(console.debug(`${f}${E} control source: ${xe(o)}`),o&&o<96&&e.allocateAce(130+y),e.#E[m.redir*c+y+2]=o,e.buildRccMap()):console.debug(`${f}${E} scale break point: ${o}`):(console.debug(`${f}${E} depth: ${o-64}`),e.#e[s+b[130+y]]=o)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{switch(console.debug(`XG enable PLG-${["VL","SG","DX","AN","PF","DR","PC","AP"][a[0]]} for CH${a[2]+1}.`),a[0]){case 0:{e.#k[m.ext*a[2]]=e.EXT_VL;break}case 2:{e.#k[m.ext*a[2]]=e.EXT_DX;break}default:e.#k[m.ext*a[2]]=e.EXT_NONE}}).add([73,0,0],(a,r)=>{let c=a[0],i="MU1000 System: ";a.subarray(1).forEach((s,f)=>{let o=c+f;o==8?console.debug(`${i}LCD contrast set to ${s}.`):o==18?(e.#C=s?126:0,console.debug(`${i}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):o>=64&&o<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")},()=>{e.#N=!!s,console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][o-64]()})}).add([73,10,0],(a,r)=>{let c=a[0],i=`MU1000 RS${e.#N?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let s=e.chRedir(0,r,!0);e.#N&&(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,r,!0);e.#N&&e.dispatchEvent("channelmin",s),e.#N&&e.dispatchEvent("channelmax",s+31),console.info(`${i}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${i}unknown switch ${c} invoked.`)}else if(c<32){if(e.#N){let s=e.chRedir(c-16+(e.#ie<<4),r,!0);e.dispatchEvent("channelactive",s)}}else if(c<36){let s=e.chRedir(c-32<<4,r,!0);e.#N&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),e.#ie=c-32),console.info(`${i}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(a,r)=>{let c=e.chRedir(a[0],r,!0),i=`PLG-100SG CH${c+1} `,s=Date.now();if(a[1]==0){let f="",o=0;a.subarray(2).forEach((h,u)=>{u%2==0?f+=$e[h]||h.toString().padStart("0"):o+=h*13}),s>=e.#re&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${ke(f)}`,amend:!0}),e.#re=s+Math.ceil(o/2)+e.#V,x()&&console.debug(`${i}vocals: ${f}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)}).add([98,0],(a,r,c)=>{let i=a[0],s=a.length-5,f=a.length-1;if(i!=s){console.info(`PLG-DX native dump size mismatch! Gave ${i} instead of ${a.length-5}.`);return}let o=N(a.subarray(4,f));if(o!=a[f]){console.info(`Bad PLG-DX checksum ${a[f]} - should be ${o}.`);return}a[0]=98,e.#P.run(a.subarray(0,f),r,c,{noAce:!0})}).add([98,96],(a,r,c,i)=>{let s=e.chRedir(a[0],r,!0),f=m.cc*s,o=a[1];a.subarray(2).forEach((h,u)=>{let y=o+u;if(!(y<10)){if(y==10)e.resetAce();else if(y<27){let E=y+131;i?.noAce||e.allocateAce(E),e.#e[f+b[E]]=h,e.dispatchEvent("cc",{part:s,cc:E,data:h})}}})}).add([100,0],(a,r,c)=>{let i=a.subarray(0,a.length-1);if(a[0]+5!=a.length){console.warn(`Yamaha DX7+ dump SysEx size mismatch! Expected ${a.length}, but got ${a[0]}: +`,a);return}let s=N(i),f=a[a.length-1];if(s!=f){console.warn(`Yamaha DX7+ dump SysEx checksum mismatch! Expected ${s}, but got ${f}: +`,a);return}t.run(i.subarray(1))}).add([100,76],(a,r,c)=>{let i=a[0]>>4,s=a[0]&15,f=a[1];switch(i){case 2:{let o=e.chRedir(s,r,!0),h=m.cc*o;a.subarray(2).forEach((u,y)=>{let E=y+f;if(!(E<7)){if(E<23){let $=E+135;e.allocateAce($),e.#e[h+b[$]]=u,e.dispatchEvent("cc",{part:o,cc:$,data:u})}}});break}default:console.info("Unknown DX7+ multipart: %o",a)}}),t.add([14,31],a=>{e.#e[m.cc*a[0]+b[64]]=0,e.#x.ano(a[0]),e.switchMode("xg"),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${a[0]+1}.`)}).add([76,112],async a=>{let r=a[0],c=m.cc*r,i=m.ext*r,s=m.cvn*r;e.#k[i]=e.EXT_DX,e.#w[r]=1;let f=e.#_.subarray(s,s+m.cvn);f.fill(32),a.subarray(1).forEach((o,h)=>{if(h<10)f[h]=Math.max(o,32);else if(!(h<40)){if(h<56){let u=h+102;e.#e[c+b[u]]=o,e.dispatchEvent("cc",{part:r,cc:u,data:o})}}}),e.#i[r]=r&127,e.#e[m.cc*r+b[0]]=35,e.#e[m.cc*r+b[32]]=r>>7|4,e.dispatchEvent("voice",{part:r}),console.debug(`DX7+ CH${r+1} dump: %o`,a)});let l=function(a,r,c,i){},d=function(a,r){let c=a*m.dpn,i=r[0],s=r[1];r.subarray(2).forEach((f,o)=>{let h=o+s,u=-1;h<16?([()=>{u=24},()=>{u=25},()=>{u=26},()=>{},()=>{u=28},()=>{u=29},()=>{u=30},()=>{u=31},()=>{},()=>{},()=>{},()=>{u=20},()=>{u=21},()=>{u=22},()=>{u=23},()=>{}][h]||(()=>{console.debug(`Unknown XG-style drum param ${h} on set ${a+1}.`)}))():h<32||(h<40?([()=>{u=48},()=>{u=49},!1,!1,()=>{u=52},()=>{u=53}][h-32]||(()=>{console.debug(`Unknown XG-style drum param ${h} on set ${a+1}.`)}))():h<80||([()=>{u=36}][h-80]||(()=>{console.debug(`Unknown XG-style drum param ${h} on set ${a+1}.`)}))()),u>=0?(x()&&console.debug(c,u,i,f),e.#a[(c+D[u])*m.dnc+i]=f):x()&&console.debug(`XG-style drum param ${h} has no writes.`)})},p=function(a,r,c){let i=a*m.dpn,s=(r<<7)+c[0];c.subarray(1).forEach((f,o)=>{let h=o+s,u=h&127,y=h>>7,E=-1;y>1&&([()=>{E=26},()=>{},()=>{E=28},()=>{E=29},()=>{E=30},()=>{},()=>{},()=>{E=31}][y-2]||(()=>{console.debug(`Unknown GS-style drum param ${y} on set ${a+1}.`)}))(),E>-1?(x()&&console.debug(i,E,u,f),e.#a[(i+D[E])*m.dnc+u]=f):x()&&console.debug(`GS-style drum param ${y} has no writes.`)})};this.#P.add([76,48],(a,r,c)=>{d(0,a)}).add([76,49],(a,r,c)=>{d(1,a)}).add([76,50],(a,r,c)=>{d(2,a)}).add([76,51],(a,r,c)=>{d(3,a)}).add([76,52],(a,r,c)=>{d(4,a)}).add([76,53],(a,r,c)=>{d(5,a)}).add([76,54],(a,r,c)=>{d(6,a)}).add([76,55],(a,r,c)=>{d(7,a)}),this.#P.add([89,0],(a,r,c)=>{if(e.eprom){let i=a[0],s=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);x()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${i} bytes.`);let f=e.eprom.data;a.subarray(4).forEach((o,h)=>{let u=h>>3,y=h&7;if(y==7)for(let E=0;E<7;E++)f[s+7*u+E]+=(o>>6-E&1)<<7;else f[s+7*u+y]=o})}}).add([89,1],(a,r,c)=>{let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];x()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(a,r,c)=>{if(e.eprom){let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);x()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;a.subarray(4).forEach((f,o)=>{let h=o>>3,u=o&7;if(u==7)for(let y=0;y<7;y++)s[i+7*h+y]+=(f>>6-y&1)<<7;else s[i+7*h+u]=f})}}).add([89,3],(a,r,c)=>{}),this.#P.add([39,48],(a,r,c)=>{}).add([43,0,0],(a,r,c)=>{let i=[0,0,0,0],s=(f,o)=>{i[o]=f};if(a.subarray(1).forEach((f,o)=>{let h=o+a[0];[s,s,s,s,()=>{this.#d=f*129/16383*100,e.dispatchEvent("mastervolume",e.#d)},()=>f-64,()=>f||128,()=>f,()=>f,()=>{console.debug(`TG300 variation on cc${f}.`)}][h](f,h)}),a[0]<4){let f=0;i.forEach(o=>{f=f<<4,f+=o}),f-=1024}}).add([43,1,0],(a,r,c)=>{}).add([43,2],(a,r,c)=>{let i=e.chRedir(a[0],r,!0),s=a[1],f=m.cc*i,o=`TG300 CH${i+1} `;a.subarray(2).forEach((h,u)=>{u<5?([()=>{},()=>{e.#e[f+b[0]]=h,e.dispatchEvent("voice",{part:i})},()=>{e.#e[f+b[32]]=h,e.dispatchEvent("voice",{part:i})},()=>{e.#i[i]=h,e.dispatchEvent("voice",{part:i})},()=>{let y=e.chRedir(h,r,!0);e.#h[i]=y,i!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))}][u+s]||(()=>{}))(h,u+s):u<21||(u<47?([()=>{e.#u[i]=+!h},()=>{},()=>{},()=>{e.#r[m.rpn*i+3]=h,e.#n[m.rpnt*i+2]=1},()=>{},()=>{e.#e[f+b[7]]=h},!1,!1,()=>{e.#e[f+b[10]]=h||128},!1,!1,()=>{console.debug(`${o} AC1 at cc${h}`)},()=>{console.debug(`${o} AC2 at cc${h}`)},()=>{e.#e[f+b[128]]=h},()=>{e.#e[f+b[93]]=h},()=>{e.#e[f+b[91]]=h},()=>{e.#e[f+b[94]]=h},()=>{e.#e[f+b[76]]=h},()=>{e.#e[f+b[77]]=h},()=>{e.#e[f+b[74]]=h},()=>{e.#e[f+b[71]]=h},()=>{e.#e[f+b[73]]=h},()=>{e.#e[f+b[75]]=h},()=>{e.#e[f+b[72]]=h},()=>{e.#e[f+b[78]]=h}][u+s-21]||(()=>{}))(h,u+s):u<95||([()=>{e.#e[f+b[65]]=h},()=>{e.#e[f+b[5]]=h}][u+s-95]||(()=>{}))(h,u+s))})}).add([43,7,0],(a,r,c)=>{let i=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",i)}).add([43,7,1],(a,r,c)=>{e.#p=0,e.#T=Date.now()+3200,e.#v.fill(0),a.forEach(function(i,s){let f=Math.floor(s/16),o=s%16,h=(o*3+f)*7,u=7,y=0;for(h-=o*5,f==2&&(u=2);y>6-y&1,y++})}),this.#I.add([66,18,0,0,127],(a,r,c)=>{e.switchMode("gs",!0),e.#e[m.cc*9]=120,e.#e[m.cc*25]=120,e.#e[m.cc*41]=120,e.#e[m.cc*57]=120,e.#C=3,e.#y=!1,e.#K.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),e.#e[m.cc*9]=120,e.#e[m.cc*25]=120,e.#e[m.cc*41]=120,e.#e[m.cc*57]=120,e.#y=!1,e.#K.fill(0),console.info("MIDI reset: GS");break}default:{let i=[0,0,0,0],s=(f,o)=>{i[o]=f};if(a.subarray(1).forEach((f,o)=>{let h=o+a[0];[s,s,s,s,u=>{this.#d=u*129/16383*100,e.dispatchEvent("mastervolume",e.#d)},u=>{},u=>{}][h](f,o)}),a[0]<4){let f=0;i.forEach(o=>{f=f<<4,f+=o}),f-=1024}}}}).add([66,18,64,1],a=>{let r=a[0];if(r<16){let c="".padStart(r," ");a.subarray(1).forEach((i,s)=>{c+=String.fromCharCode(Math.max(32,i))}),c=c.padEnd(16," "),console.debug(`GS patch name: ${c}`)}else r<48||(r<65?a.subarray(1).forEach((c,i)=>{let s=`GS ${r+i>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${re[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${c}ms`)},()=>{console.info(`${s}type: ${Te[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${M(c)}`)},()=>{console.debug(`${s}to delay: ${M(c)}`)}][r+i-48]||(()=>{}))()}):r<80?console.debug(`Unknown GS patch address: ${r}`):r<91?a.subarray(1).forEach((c,i)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${Se[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${M(c)}`)}][r+i-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${r}`))}).add([66,18,64,2],a=>{let r="GS EQ ";a.subarray(1).forEach((c,i)=>{([()=>{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]+i]||function(){console.warn(`Unknown GS EQ address: ${a[0]+i}`)})()})}).add([66,18,64,3],a=>{let r="GS EFX ",c=function(i,s){let f=Ce(e.#g.subarray(10,12),s,i);f&&console.debug(`${r}${ie(e.#g.subarray(10,12))} ${f}`)};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(`${r}type: ${ie(e.#g.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: ${M(i)}dB`)},()=>{console.debug(`${r}to chorus: ${M(i)}dB`)},()=>{console.debug(`${r}to delay: ${M(i)}dB`)},!1,()=>{console.debug(`${r}1 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${r}1 depth: ${i-64}`)},()=>{console.debug(`${r}2 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${r}2 depth: ${i-64}`)},()=>{console.debug(`${r}to EQ: ${i?"ON":"OFF"}`)}][a[0]+s]||function(f,o){console.warn(`Unknown GS EFX address: ${o}`)})(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=>{switch(a[0]){case 0:{let r=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",r);break}case 32:{e.#T=Date.now()+3200,a[1]==0&&(e.#p=Math.max(Math.min(a[2]-1,9),0),x()&&console.debug(`GS switch display page ${a[2]-1}.`));break}default:if(a[0]<6){e.#p>9&&(e.#p=0);let r=a[0]-1<<1|a[1]>>6;e.#p==r&&(e.#T=Date.now()+3200),e.#c[r]?.length||(e.#c[r]=new Uint8Array(256));let c=e.#c[r];x()&&console.debug(`GS frame draw page ${r}.`);let i=a[1]&63;c.fill(0),a.subarray(2).forEach(function(f,o){let h=o+i,u=Math.floor(h/16),y=h%16,E=(y*4+u)*5,$=5,T=0;for(E-=y*4,u==3&&($=1);T<$;)c[E+T]=f>>4-T&1,T++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let g=function(a,r,c){let i=a[0],s=m.cc*r,f=m.rpn*r,o=`GS CH${r+1} `;i<3?(a.subarray(1).forEach((h,u)=>{[()=>{e.#e[s+b[0]]=h},()=>{e.#i[r]=h},()=>{let y=0;h<16?y=e.chRedir(h,c,!0):y=m.ch,e.#h[r]=y,r!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))}][i+u]()}),e.dispatchEvent("voice",{part:r})):i<19||(i<44?a.subarray(1).forEach((h,u)=>{([()=>{e.#u[r]=+!h},!1,()=>{e.setChType(r,h<<1,k.gs),console.debug(`${o}type: ${h?"drum ":"melodic"}${h||""}`)},()=>{e.#r[f+3]=h,e.#n[m.rpnt*r+2]=1},!1,()=>{e.#e[s+b[7]]=h},!1,!1,()=>{e.#e[s+b[10]]=h||128},!1,!1,()=>{console.debug(`${o}CC 1: cc${h}`)},()=>{console.debug(`${o}CC 2: cc${h}`)},()=>{e.#e[s+b[93]]=h},()=>{e.#e[s+b[91]]=h},!1,!1,()=>{e.#r[f+1]=h,e.#n[m.rpnt*r+1]=1},()=>{e.#r[f+2]=h,e.#n[m.rpnt*r+1]=1},()=>{e.#e[s+b[94]]=h}][i+u-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},v=function(a,r){let c=a[0],i=`GS CH${r+1} `;c<2?a.subarray(1).forEach((s,f)=>{[()=>{e.#e[m.cc*r+b[32]]=s},()=>{}][c+f]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?a.subarray(1).forEach((s,f)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][s]}`),e.#f[r]=s,e.dispatchEvent("partefxtoggle",{part:r,active:s})}][c+f-32]()}):console.warn(`Unknown GS misc address: ${c}`)};this.#I.add([66,18,64,16],(a,r)=>{g(a,e.chRedir(9,r,!0),r)}).add([66,18,64,17],(a,r)=>{g(a,e.chRedir(0,r,!0),r)}).add([66,18,64,18],(a,r)=>{g(a,e.chRedir(1,r,!0),r)}).add([66,18,64,19],(a,r)=>{g(a,e.chRedir(2,r,!0),r)}).add([66,18,64,20],(a,r)=>{g(a,e.chRedir(3,r,!0),r)}).add([66,18,64,21],(a,r)=>{g(a,e.chRedir(4,r,!0),r)}).add([66,18,64,22],(a,r)=>{g(a,e.chRedir(5,r,!0),r)}).add([66,18,64,23],(a,r)=>{g(a,e.chRedir(6,r,!0),r)}).add([66,18,64,24],(a,r)=>{g(a,e.chRedir(7,r,!0),r)}).add([66,18,64,25],(a,r)=>{g(a,e.chRedir(8,r,!0),r)}).add([66,18,64,26],(a,r)=>{g(a,e.chRedir(10,r,!0),r)}).add([66,18,64,27],(a,r)=>{g(a,e.chRedir(11,r,!0),r)}).add([66,18,64,28],(a,r)=>{g(a,e.chRedir(12,r,!0),r)}).add([66,18,64,29],(a,r)=>{g(a,e.chRedir(13,r,!0),r)}).add([66,18,64,30],(a,r)=>{g(a,e.chRedir(14,r,!0),r)}).add([66,18,64,31],(a,r)=>{g(a,e.chRedir(15,r,!0),r)}).add([66,18,64,64],(a,r)=>{v(a,e.chRedir(9,r,!0))}).add([66,18,64,65],(a,r)=>{v(a,e.chRedir(0,r,!0))}).add([66,18,64,66],(a,r)=>{v(a,e.chRedir(1,r,!0))}).add([66,18,64,67],(a,r)=>{v(a,e.chRedir(2,r,!0))}).add([66,18,64,68],(a,r)=>{v(a,e.chRedir(3,r,!0))}).add([66,18,64,69],(a,r)=>{v(a,e.chRedir(4,r,!0))}).add([66,18,64,70],(a,r)=>{v(a,e.chRedir(5,r,!0))}).add([66,18,64,71],(a,r)=>{v(a,e.chRedir(6,r,!0))}).add([66,18,64,72],(a,r)=>{v(a,e.chRedir(7,r,!0))}).add([66,18,64,73],(a,r)=>{v(a,e.chRedir(8,r,!0))}).add([66,18,64,74],(a,r)=>{v(a,e.chRedir(10,r,!0))}).add([66,18,64,75],(a,r)=>{v(a,e.chRedir(11,r,!0))}).add([66,18,64,76],(a,r)=>{v(a,e.chRedir(12,r,!0))}).add([66,18,64,77],(a,r)=>{v(a,e.chRedir(13,r,!0))}).add([66,18,64,78],(a,r)=>{v(a,e.chRedir(14,r,!0))}).add([66,18,64,79],(a,r)=>{v(a,e.chRedir(15,r,!0))}),this.#z.add([54,65],(a,r)=>{e.switchMode("x5d");let c=a[a.length-1],i=a.subarray(0,a.length-1),s=N(i);s!=c&&(console.info(`X5D multi parameters checksum mismatch! Expected ${s}, got ${c}.`),console.debug(a));let f=(a[1]<<7)+a[0],o=(a[3]<<7)+a[2],h=e.chRedir(f&15,r,!0),u=m.cc*h;[()=>{o<1||(o<101?(e.setChType(h,e.CH_MELODIC,k.x5d),e.#i[h]=o-1,e.#e[u+b[0]]=e.#m.x5):o<229?(e.setChType(h,e.CH_MELODIC,k.x5d),e.#i[h]=o-101,e.#e[u+b[0]]=56):(e.setChType(h,e.CH_DRUMS,k.x5d),e.#i[h]=Ue[o-229]||0,e.#e[u+b[0]]=62)),e.dispatchEvent("voice",{part:h})},()=>{e.#e[u+b[7]]=o},()=>{o<31&&(e.#e[u+b[10]]=Math.round((o-15)*4.2+64))},()=>{e.#e[u+b[93]]=F(o)},()=>{e.#e[u+b[91]]=F(o)},()=>{e.#r[h*m.rpn+3]=o>8191?o-16320:64+o,e.#n[m.rpnt*h+2]=1},()=>{e.#r[h*m.rpn+1]=o>8191?o-16320:64+o,e.#n[m.rpnt*h+1]=1},()=>{o>0&&(e.#r[h*m.rpn]=o,e.#n[m.rpnt*h]=1)},()=>{}][f>>4]()}).add([54,76,0],(a,r)=>{e.switchMode(e.#m.x5=="81"?"05rw":"x5d",!0);let c="",i=e.#m.x5,s=0,f=0,o="MSB PRG LSB NME";L(a,function(h,u){if(u<16400){let y=u%164;switch(!0){case y<10:{h>31&&(c+=String.fromCharCode(h));break}case y==10:break;case y==11:{o+=` +${i} ${s} ${f} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}s>99&&(i=90,s=0)}}),e.userBank.clearRange({msb:e.#m.x5,prg:[0,99],lsb:0}),e.userBank.load(o),x()&&console.debug(o),e.forceVoiceRefresh()}).add([54,77,0],(a,r)=>{e.switchMode(e.#m.x5=="81"?"05rw":"x5d",!0);let c="",i=90,s=0,f=0,o="MSB PRG LSB NME";L(a,function(h,u){if(u<13600){let y=u%136;switch(!0){case y<10:{h>31&&(c+=String.fromCharCode(h));break}case y==11:{o+=` +${i} ${s} ${f} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(o),x()&&console.debug(o),e.forceVoiceRefresh()}).add([54,78],(a,r)=>{e.switchMode(e.#m.x5=="81"?"05rw":"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(e.#m.x5=="81"?"05rw":"x5d",!0),L(a,(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],(a,r)=>{e.switchMode(e.#m.x5=="81"?"05rw":"x5d",!0),L(a,function(c,i,s,f){if(i<192){let o=e.chRedir(Math.floor(i/12),r,!0),h=o*m.cc;switch(i%12){case 0:{c<128?(e.setChType(o,e.CH_MELODIC,k.x5d),e.#e[h+b[0]]=e.#m.x5,e.#i[o]=c):(e.setChType(o,e.CH_DRUMS,k.x5d),e.#e[h+b[0]]=62,e.#i[o]=Ue[c-128]),c>0&&e.setChActive(o,1),e.dispatchEvent("voice",{part:o});break}case 1:{e.#e[h+b[7]]=c;break}case 2:{e.#r[o*m.rpn+3]=c>127?c-192:64+c,e.#n[m.rpnt*o+2]=1;break}case 3:{e.#r[o*m.rpn+1]=c>127?c-192:64+c,e.#n[m.rpnt*o+1]=1;break}case 4:{c<31&&(e.#e[h+b[10]]=Math.round((c-15)*4.2+64));break}case 5:{let u=c>>4,y=c&15;e.#e[h+b[91]]=F(y),e.#e[h+b[93]]=F(u);break}case 10:break;case 11:{let u=e.chRedir(c&15,r,!0),y=c>>4;e.#h[o]=c,(u!=o||y)&&(console.info(`X5D Part CH${o+1} receives from CH${u+1}.`),e.buildRchTree())}}}else{let o=e.chRedir(i-192,r,!0)}})}),this.#I.add([22,18,127],a=>{e.switchMode("mt32",!0),e.#y=!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 i=e.chRedir(c,r,!0),s=a[1];a.subarray(2).forEach((f,o)=>{let h=o+s;e.#O[h+(i-1)*16]=f,([!1,()=>{let u=e.#O[i-1<<4];if(u<3){if(e.#w[i]=1,u==2)for(let y=0;y{e.#r[i*m.rpn+3]=f+40,e.#n[m.rpnt*i+2]=1},()=>{e.#r[i*m.rpn+1]=f+14,e.#n[m.rpnt*i+1]=1},()=>{e.#r[i*m.rpn]=f,e.#n[m.rpnt*i]=1},!1,()=>{e.#e[m.cc*i+b[91]]=f?127:0},!1,()=>{e.#e[m.cc*i+b[7]]=f},()=>{e.#e[m.cc*i+b[10]]=Math.ceil(f*9.05)}][h]||(()=>{}))()})}).add([22,18,1],(a,r,c)=>{e.switchMode("mt32");let i=c&7;console.debug(`MT-32 slot #${c+1} Drum: ${a}`);let s=a[0]<<7|a[1];a.subarray(2).forEach((f,o)=>{let h=o+s,u=(h>>2)+24,y=h&3,E=i*m.dpn;if(x()&&console.debug(`MT-32 temp drum note ${u} param ${y}: ${f}`),u<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${u}`);return}[()=>{},()=>{e.#a[(E+D[26])*m.dnc+u]=Math.round(f*1.27)},()=>{e.#a[(E+D[26])*m.dnc+u]=f*9+1&127},()=>{e.#a[(E+D[26])*m.dnc+u]=f?127:0}][y]()})}).add([22,18,2],(a,r,c)=>{e.switchMode("mt32");let i=e.chRedir(c,r,!0),s=a[1]+(a[0]<<7);s<10&&(e.#w[i]=1),a.subarray(2).forEach((f,o)=>{let h=o+s;h<14&&(e.#L[(i-1)*m.cmt+h]=f)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(a,r,c)=>{e.switchMode("mt32");let i=c&7;if(a[0]){let s=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((f,o)=>{let h=o+s,u=(h>>2)+24,y=h&3,E=i*m.dpn;if(x()&&console.debug(`MT-32 dev drum note ${u} param ${y}: ${f}`),u<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${u}`);return}[()=>{},()=>{e.#a[(E+D[26])*m.dnc+u]=Math.round(f*1.27)},()=>{e.#a[(E+D[26])*m.dnc+u]=f*9+1&127},()=>{e.#a[(E+D[26])*m.dnc+u]=f?127:0}][y]()})}else{let s=a[1];a.subarray(2).forEach((f,o)=>{let h=o+s;e.#O[h]=f;let u=e.chRedir(1+(h>>4),r,!0),y=h&15;([!1,()=>{let E=e.#O[u-1<<4];if(E<3)if(e.#w[u]=1,E==2)for(let $=0;${e.#r[u*m.rpn+3]=f+40,e.#n[m.rpnt*u+2]=1},()=>{e.#r[u*m.rpn+1]=f+14,e.#n[m.rpnt*u+1]=1},()=>{e.#r[u*m.rpn]=f,e.#n[m.rpnt*u]=1},!1,()=>{e.#e[m.cc*u+b[91]]=f?127:0},!1,()=>{e.#e[m.cc*u+b[7]]=f},()=>{e.#e[m.cc*u+b[10]]=Math.ceil(f*9.05)}][y]||(()=>{}))()})}}).add([22,18,4],(a,r,c)=>{e.switchMode("mt32");let i=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((f,o)=>{let h=o+i,u=e.chRedir(Math.floor(h/246+1),r,!0),y=h%246;y<14&&(e.#L[(u-1)*m.cmt+y]=f),y<10&&(e.#w[u]=1),s.indexOf(u)<0&&s.push(u)}),s.forEach(f=>{e.dispatchEvent("voice",{part:f})})}).add([22,18,5],(a,r,c)=>{e.switchMode("mt32");let i=(a[0]<<7)+a[1];a.subarray(2).forEach((s,f)=>{let o=i+f,h=Math.floor(o/8),u=o&7,y=h*8;e.#F[o]=s,([!1,()=>{let E=e.#F[y];if(E<3){let $="";if(E==2){let U=m.cmt*h;$=`MT-m:${s.toString().padStart(3,"0")}`}else $=e.baseBank.get(0,s+(E<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:h});let T=`MSB LSB PRG NME +000 127 ${h} ${$}`;e.userBank.load(T,!0)}}][u]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,r,c)=>{e.switchMode("mt32");let i=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((s,f)=>{let o=i+f;o>1)*m.cmt+o]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(a,r,c)=>{e.switchMode("mt32");let i=a[1],s=!1,f=function(o,h){e.#h[h-12]=o,s=!0};a.subarray(2).forEach((o,h)=>{let u=h+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,f,f,f,f,f,f,f,f,f,()=>{e.#d=o,e.dispatchEvent("mastervolume",e.#d)}][u]||(()=>{}))(o,h)}),s&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let r=a[1],c=" ".repeat(r);a.subarray(2).forEach(i=>{i>31?c+=String.fromCharCode(i):c+=" "}),e.#q=c.padStart(20," "),e.#W=Date.now()+3200}).add([22,18,82],(a,r)=>{let c=e.chRedir(0,r,!0);for(let i=0;i<16;i++)e.#x.ano(c+i),i&&i<10&&(e.#i[c+i]=se[i-1]);console.info("MT-32 alt reset complete.")}),this.#z.add([66,0],(a,r)=>{e.switchMode("ns5r",!0),e.#y=!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.#y=!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.#y=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(c<10){let i=[0,0,0,0],s=(f,o)=>{i[o]=f};if(a.subarray(1).forEach((f,o)=>{[s,s,s,s,()=>{e.#d=f*129/16383*100,e.dispatchEvent("mastervolume",e.#d)},()=>f-64,()=>f-64,()=>{},()=>{},()=>{}][c+o]()}),a[0]<4){let f=0;i.forEach(o=>{f=f<<4,f+=o}),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),i=c*m.cc,s=a[1],f=`NS5R CH${c+1} `;a.subarray(2).forEach((o,h)=>{let u=s+h;u<3?([()=>{e.#e[i+b[0]]=o||K.bank0},()=>{e.#e[i+b[32]]=o},()=>{e.#i[c]=o}][u](),e.dispatchEvent("voice",{part:c})):u<8||(u<14?[()=>{let y=e.chRedir(o,r,!0);e.#h[c]=y,c!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))},()=>{e.#u[c]=+!o},()=>{e.setChType(c,o,k.ns5r),console.debug(`${f}type: ${_[o]}`)},()=>{e.#r[m.rpn*c+3]=o,e.#n[m.rpnt*c+2]=1},()=>{},()=>{}][u-8]():u<16||(u<33?[()=>{e.#e[i+b[7]]=o},()=>{e.#e[i+b[11]]=o},()=>{},()=>{},()=>{e.#e[i+b[10]]=o||128},()=>{},()=>{},()=>{e.#e[i+b[93]]=o},()=>{e.#e[i+b[91]]=o},()=>{e.#e[i+b[76]]=o},()=>{e.#e[i+b[77]]=o},()=>{e.#e[i+b[78]]=o},()=>{e.#e[i+b[74]]=o},()=>{e.#e[i+b[71]]=o},()=>{e.#e[i+b[73]]=o},()=>{e.#e[i+b[75]]=o},()=>{e.#e[i+b[72]]=o}][u-16]():u<112||u<114&&[()=>{e.#e[i+b[5]]=o},()=>{e.#e[i+b[65]]=o}][u-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 i=c-32;e.#T=Date.now()+3200,e.#p=10,e.#v.fill(0);let s=a.subarray(1),f=4;s.forEach(function(o,h){let u=h+i,y=u>>4,E=u&15;if(u<80){let $=y>3,T=0,U=y0;)e.#v[E*32+y*7+(U-T)]=$&1,$=$>>1,T++}})}}).add([66,18,48],(a,r,c)=>{d(0,a)}).add([66,18,49],(a,r,c)=>{d(1,a)}).add([66,18,50],(a,r,c)=>{d(2,a)}).add([66,18,51],(a,r,c)=>{d(3,a)}).add([66,18,52],(a,r,c)=>{d(4,a)}).add([66,18,53],(a,r,c)=>{d(5,a)}).add([66,18,54],(a,r,c)=>{d(6,a)}).add([66,18,55],(a,r,c)=>{d(7,a)}).add([66,52],(a,r)=>{e.switchMode("ns5r",!0),e.#y=!1;let c="";L(a,(i,s)=>{s<8?(i>31&&(c+=String.fromCharCode(i)),s==7&&(e.aiEfxName=c)):s<10&&(e.setEffectType(s-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(a,r)=>{e.switchMode("ns5r",!0),e.#y=!1;let c="",i=a[a.length-1],s=a.subarray(0,a.length-1),f=N(s);f!=i&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${f}, got ${i}.`),console.debug(a)),L(s,function(o,h){switch(!0){case h<2944:{let u=e.chRedir(Math.floor(h/92),r,!0),y=u*m.cc;switch(h%92){case 0:{e.#e[y+b[0]]=o,e.dispatchEvent("voice",{part:u});break}case 1:{e.#e[y+b[32]]=o,!o&&!e.#e[y+b[0]]&&(e.#e[y+b[0]]=K.bank0),e.dispatchEvent("voice",{part:u});break}case 2:{e.#i[u]=o,o>0&&e.setChActive(u,1),e.dispatchEvent("voice",{part:u});break}case 3:{let E=e.chRedir(o,r,!0);e.#h[u]=E,u!=E&&(console.info(`NS5R CH${u+1} receives from CH${E+1}.`),e.buildRchTree());break}case 7:{e.#s[u]=o,e.dispatchEvent("voice",{part:u});break}case 8:{e.#r[u*m.rpn+3]=o<40||o>88?o+(o>63?-192:64):o,e.#n[m.rpnt*u+2]=1;break}case 9:case 10:{e.#e[y+b[7]]=o;break}case 11:{e.#e[y+b[11]]=o;break}case 14:{e.#e[y+b[10]]=o||128;break}case 19:{e.#e[y+b[93]]=o;break}case 20:{e.#e[y+b[91]]=o;break}case 84:{e.#e[y+b[65]]=o;break}case 85:{e.#e[y+b[5]]=o;break}}break}case h<3096:break;case h<3134:{let u=h-3096;u<8?(o>31&&(c+=String.fromCharCode(o)),u==7&&(e.aiEfxName=c)):u<10&&(e.setEffectType(u-8,44,o),e.dispatchEvent(`efx${["reverb","chorus"][u-8]}`,e.getEffectType(u-8)));break}case h<8566:break}})}).add([66,54],(a,r)=>{e.switchMode("ns5r",!0);let c="",i=80,s=0,f=0,o="MSB PRG LSB NME";L(a,function(h,u){let y=u%158;switch(!0){case y<10:{h>31&&(c+=String.fromCharCode(h));break}case y==10:break;case y==11:{i=h&127;break}case y==12:{f=h&127;break}case y==13:{o+=` +${i} ${s} ${f} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(o),x()&&console.debug(o),e.forceVoiceRefresh()}).add([66,55],(a,r)=>{e.switchMode("ns5r",!0);let c="",i=88,s=0,f=0,o="MSB PRG LSB NME";L(a,function(h,u){let y=u%126;switch(!0){case y<10:{h>31&&(c+=String.fromCharCode(h));break}case y==11:break;case y==12:break;case y==13:{o+=` +${i} ${s} ${f} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(o),x()&&console.debug(o),e.forceVoiceRefresh()}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let r=a[a.length-1],c=a.subarray(0,a.length-1),i=N(c);i!=r&&(console.info(`NS5R screen dump checksum mismatch! Expected ${i}, got ${r}.`),console.debug(a));let s=new Uint8Array(5760);L(a,(f,o,h)=>{if(o<720)for(let u=0;u<8;u++)s[o*8+u]=f>>7-u&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(a,r,c)=>{e.#z.run([66,...a],r,c)}),this.#ee.add([16,0,8,0],(a,r,c)=>{let i=(a[2]<<4)+a[3],s="K11 ";([()=>{e.switchMode("k11",!0),e.#y=!1,e.#C=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,r,c)=>{let i=e.chRedir(a[1],r,!0),s=m.cc*i,f=m.rpn*i,o=(a[3]<<4)+a[4],h=`K11 CH${i+1} `;([()=>{o<128?(e.setChType(i,e.CH_MELODIC,k.k11),e.#e[s+b[0]]=0,e.#i[i]=o):(e.setChType(i,e.CH_DRUMS,k.k11),e.#i[i]=o-128),e.dispatchEvent("voice",{part:i})},()=>{let u=e.chRedir(o,r,!0);e.#h[i]=u,i!=u&&(e.buildRchTree(),console.info(`${h}receives from CH${u+1}`))},()=>{e.#e[s+b[7]]=o},()=>{uupThis.setChActive(i,o)},()=>{e.#e[s+b[10]]=o},()=>{e.#r[f+3]=o+40,e.#n[m.rpnt*i+2]=1},()=>{e.#r[f+1]=o>>1,e.#r[f+2]=o&1,e.#n[m.rpnt*i+1]=1},()=>{e.#e[s+b[91]]=o?127:0},()=>{},()=>{e.#e[s+b[74]]=o},()=>{e.#e[s+b[73]]=o},()=>{e.#e[s+b[72]]=o}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,r,c)=>{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,r,c)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],r,!0),f=s*m.cc;[()=>{i<128?(e.setChType(s,e.CH_MELODIC,k.k11),e.#e[f+b[0]]=0,e.#e[f+b[32]]=0,e.#i[s]=i):i<160?(e.setChType(s,e.CH_MELODIC,k.k11),e.#e[f+b[0]]=0,e.#e[f+b[32]]=7,e.#i[s]=i-100):(e.setChType(s,e.CH_DRUMS,k.k11),e.#e[f+b[0]]=122,e.#e[f+b[32]]=0,e.#i[s]=i-160),e.dispatchEvent("voice",{part:s})},()=>{let o=e.chRedir(i,r,!0);e.#h[s]=o,s!=o&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${o+1}`))}][a[0]]()}).add([16,0,9,4],(a,r,c)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],r,!0),f=s*m.cc,o=s*m.rpn,h=`GMLX CH${s+1} `;[()=>{e.setChActive(s,i)},()=>{e.#e[f+b[7]]=i},()=>{e.#e[f+b[10]]=i},()=>{e.#e[f+b[91]]=i?127:0},()=>{e.#r[o+3]=i+40,e.#n[m.rpnt*s+2]=1},()=>{e.#r[o+1]=i,e.#n[m.rpnt*s+1]=1},()=>{e.#r[o]=i,e.#n[m.rpnt*s]=1},()=>{}][a[0]]()}),this.#te.add([66,93,64],(a,r,c)=>{let i=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{e.#d=i*129/16383*100,e.dispatchEvent("mastervolume",e.#d);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: ${re[i]}`);break}}break}default:if(a[0]>>4==1){let s=e.chRedir(a[0]&15,r,!0);if(a[1]==2){let f=e.chRedir(i,r,!0);e.#h[s]=f,s!=f&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${f+1}`))}else a[1]==19&&(e.#e[m.cc*s+b[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),this.#ae.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"}`)}),this.#P.add([127,0],(a,r,c)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...a]);e.#P.run(i,r,c)}).add([127,1,0,0],(a,r,c)=>{e.switchMode("s90es");let i="S90/Motif ES system ",s=a[0];a.subarray(1).forEach((f,o)=>{([()=>{e.#d=f*12900/16383,e.dispatchEvent("mastervolume",e.#d)}][s+o]||(()=>{console.info(`Unrecognized ${i}ID: ${s+o}`)}))()})}).add([127,1,0,0,14],(a,r,c)=>{e.switchMode("s90es");let i="S90/Motif ES bulk header ",s=[];s[95]=(f,o,h)=>{console.debug(`${i}multi edit buffer: ${f[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,r,c)=>{e.switchMode("s90es");let i="S90/Motif ES bulk footer ",s=[];s[95]=(f,o,h)=>{console.debug(`${i}multi edit buffer: ${f[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,r,c)=>{e.switchMode("s90es");let i=e.chRedir(a[0],r,!0),s=m.cc*i,f=a[1],o=`S90/Motif ES bulk CH${i<16?i+1:"U"+(i-95)} `;console.debug(o,a),!(a[0]>15)&&a.subarray(2).forEach((h,u)=>{([()=>{e.#e[s+b[0]]=h,e.dispatchEvent("voice",{part:i})},()=>{h&&e.setChActive(i,1),e.#e[s+b[32]]=h,e.setChType(i,[32,40].indexOf(h)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:i})},()=>{h&&e.setChActive(i,1),e.#i[i]=h,e.dispatchEvent("voice",{part:i})},()=>{let y=e.chRedir(h,r,!0);e.#h[i]=y,i!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))},()=>{e.#u[i]=h?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{e.#e[s+b[7]]=h},()=>{e.#e[s+b[10]]=h},!1,!1,!1,()=>{e.#e[s+b[91]]=h},()=>{e.#e[s+b[93]]=h},()=>{e.#e[s+b[94]]=h},()=>{e.#e[s+b[128]]=h},()=>{},()=>{e.#e[s+b[74]]=h},()=>{e.#e[s+b[71]]=h},!1,()=>{e.#e[s+b[65]]=h},()=>{e.#e[s+b[5]]=h},()=>{}][f+u]||(()=>{}))()})}).add([127,1,54,16],(a,r,c)=>{e.switchMode("s90es");let i=a[0];a.subarray(1).forEach((s,f)=>{let h=`S90/Motif ES EQ${(f>>2)+1} `;([()=>{let u=s-64},()=>{let u=H[s]},()=>{let u=s/10},()=>{let u=s}][i+f&3]||(()=>{}))()})}),this.#I.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 i=a[0]>>5,s=a[0]&31;switch(i){case 0:{let f=a[0]>>1,o=a[1];switch(f){case 1:{a.subarray(2).forEach((h,u,y)=>{let E=u+o;switch(E){case 0:{h&&(e.setEffectType(1,60,h-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${E} - ${h}`));break}}});break}case 2:{a.subarray(2).forEach((h,u)=>{let y=u+o;switch(y){case 0:{h&&(e.setEffectType(0,55+h,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${y} - ${h}`));break}}});break}case 3:case 4:case 5:{let h=f-1;a.subarray(2).forEach((u,y)=>{let E=y+o;switch(console.debug(`SD MFX ${h-2}: ${E} - ${u}`),E){case 0:{e.setEffectTypeRaw(h,62,u),e.dispatchEvent(`efx${h>2?"delay":"insert"+(h-4)}`,e.getEffectType(h));break}}}),console.debug(`SD MFX message: %o`,a);break}default:console.debug(`Unknown SD-90 global effects message: -%o`,a)}break}case 1:{let f=e.chRedir(s,r,!0),d=a[1],h=f*m.cc;a.subarray(2).forEach((u,v)=>{let E=d+v;E<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[h+b[0]]=u,u){case 104:case 105:case 106:case 107:case 120:{e.#s[f]||e.setChType(f,e.CH_DRUMS);break}default:e.#s[f]&&e.setChType(f,e.CH_MELODIC)}e.dispatchEvent("voice",{part:f})},()=>{e.#e[h+b[32]]=u,e.dispatchEvent("voice",{part:f})},()=>{e.#i[f]=u,e.dispatchEvent("voice",{part:f})},()=>{e.#e[h+b[7]]=u},()=>{e.#e[h+b[10]]=u},()=>{},()=>{},()=>{u<2&&(e.#p[f]=u)},()=>{u<2&&(e.#e[h+b[68]]=u?127:0)},()=>{},()=>{u<2&&(e.#e[h+b[65]]=u?127:0)},()=>{e.#e[h+b[5]]=u&15<<4|e.#e[h+b[5]]&15},()=>{e.#e[h+b[5]]=u&15|(e.#e[h+b[5]]&240)>>4},()=>{e.#e[h+b[74]]=u},()=>{e.#e[h+b[71]]=u},()=>{e.#e[h+b[73]]=u},()=>{e.#e[h+b[72]]=u},0,0,0,0,0,0,0,()=>{e.#e[h+b[128]]=u},()=>{e.#e[h+b[93]]=u},()=>{e.#e[h+b[91]]=u},0,0,()=>{e.#e[h+b[75]]=u},()=>{e.#e[h+b[76]]=u},()=>{e.#e[h+b[77]]=u},()=>{e.#e[h+b[78]]=u}][E]||(()=>{}))():E<63||(E<64?(e.#s[f]?e.#e[h+b[0]]=104|u:e.#e[h+b[0]]=96|u,e.dispatchEvent("voice",{part:f})):console.debug(`Unknown SD-90 global CH${f+1} param setup message: -%o`,a))});break}case 2:{let f=e.chRedir(s,r,!0),d=a[1];console.debug(`Unknown SD-90 global CH${f+1} MIDI setup message: +%o`,a)}break}case 1:{let f=e.chRedir(s,r,!0),o=a[1],h=f*m.cc;a.subarray(2).forEach((u,y)=>{let E=o+y;E<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[h+b[0]]=u,u){case 104:case 105:case 106:case 107:case 120:{e.#s[f]||e.setChType(f,e.CH_DRUMS);break}default:e.#s[f]&&e.setChType(f,e.CH_MELODIC)}e.dispatchEvent("voice",{part:f})},()=>{e.#e[h+b[32]]=u,e.dispatchEvent("voice",{part:f})},()=>{e.#i[f]=u,e.dispatchEvent("voice",{part:f})},()=>{e.#e[h+b[7]]=u},()=>{e.#e[h+b[10]]=u},()=>{},()=>{},()=>{u<2&&(e.#u[f]=u)},()=>{u<2&&(e.#e[h+b[68]]=u?127:0)},()=>{},()=>{u<2&&(e.#e[h+b[65]]=u?127:0)},()=>{e.#e[h+b[5]]=u&15<<4|e.#e[h+b[5]]&15},()=>{e.#e[h+b[5]]=u&15|(e.#e[h+b[5]]&240)>>4},()=>{e.#e[h+b[74]]=u},()=>{e.#e[h+b[71]]=u},()=>{e.#e[h+b[73]]=u},()=>{e.#e[h+b[72]]=u},0,0,0,0,0,0,0,()=>{e.#e[h+b[128]]=u},()=>{e.#e[h+b[93]]=u},()=>{e.#e[h+b[91]]=u},0,0,()=>{e.#e[h+b[75]]=u},()=>{e.#e[h+b[76]]=u},()=>{e.#e[h+b[77]]=u},()=>{e.#e[h+b[78]]=u}][E]||(()=>{}))():E<63||(E<64?(e.#s[f]?e.#e[h+b[0]]=104|u:e.#e[h+b[0]]=96|u,e.dispatchEvent("voice",{part:f})):console.debug(`Unknown SD-90 global CH${f+1} param setup message: +%o`,a))});break}case 2:{let f=e.chRedir(s,r,!0),o=a[1];console.debug(`Unknown SD-90 global CH${f+1} MIDI setup message: %o`,a.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,a)}})}};var oe=at(Be(),1);var Xe=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}},ce=class extends Xe{constructor(e,t,n){super(!0,e,t,n)}},He=class extends Xe{constructor(e,t){super(!1,e,e,t)}},le=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].endo.#t&&(n.push(p),o.#t=p.index)})}return n}getRange(e,t){e>t&&([e,t]=[t,e]);let n=[],l=-1,o=Math.ceil(Math.sqrt(this.length)),p=!0;for(let g=0;g=e&&(l=g):l=l<0?g:l;for(;p;)this[l]?.end=e&&n.push(this[l]):p=!1,l++;return n}};var bt=0xffffffffffff,Ge=function(e){let t=new le,n=this,l=e.timeDivision,o=120,p=new le,g=0,y=0;p.push(new ce(0,bt,[120,0])),e.track.forEach(function(i){g=0,i.event.forEach(function(s){g+=s.deltaTime,s.type==255&&s?.metaType==81&&(o=6e7/s.data,p[p.length-1]&&p.push(new ce(g,0xffffffffffff,[o,0])))})}),p.fresh(),p.forEach(function(i,s,f){s>0&&(f[s-1].end=i.start)});let a=120;p.forEach(function(i,s,f){s>0&&(i.end==i.start?f.splice(f.indexOf(i),1):a==i.data[0]&&(f[s-1].end=i.end,f.splice(f.indexOf(i),1)),a=i.data[0])});let r=0,c=120;return p.forEach(function(i){let s=i.start,f=s/c/l*60+r;c=i.data[0],r=f-s/c/l*60,i.data[1]=r}),console.debug("All tempo changes: ",p),o=120,g=0,y=0,e.track.forEach(function(i,s){g=0,y=0;let f=s+1;i.event.forEach(function(d,h){g+=d.deltaTime;let u=p.step(g,!0)[0];u&&(o=u.data[0],y=u.data[1]);let v={type:d.type,data:d.data,track:f,part:0};d.type>14?v.meta=d.metaType:v.part=d.channel,t.push(new He(g/o/l*60+y,v))})}),t.fresh(),self.midiEvents=t,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),t};oe.default.customInterpreter=Me;var S=function(e,t,n){e.addEventListener(n,l=>{t.dispatchEvent(n,l.data)})},Ve=class extends W{device;#t;#b={};#x=[];#c="";#y=[];#T=[];#f=new Uint8ClampedArray(128);#s=new Uint8ClampedArray(128);#e=.5;#E=120;#i=4;#o=4;#p=0;#l=0;smoothingAtk=0;smoothingDcy=0;reset(){let e=this;e.dispatchEvent("reset"),e.#t?.resetIndex(),e.device.init(),e.#c="",e.#e=.5,e.#E=120,e.#i=4,e.#o=4,e.#p=0,e.#l=0,e.dispatchEvent("tempo",e.#E),e.dispatchEvent("title",e.#c)}init(){this.reset(),this.#t=void 0}async loadFile(e){this.#t=Ge(oe.default.parse(new Uint8Array(await e.arrayBuffer())))}async loadMap(e,t){let n=this,l=0,o=0,p=0,g,y;e.split(` -`).forEach((a,r)=>{if(!a)return;let c=a.split(" ");if(r){if(!p)return;let i="",s="";c.forEach((f,d)=>{switch(d){case g:{i=f;break}case y:{s=f;break}}}),!n.#b[i]||t?(n.#b[i]=s,l++):self.debugMode&&console.debug(`Voice "${s}" (${i}) seems to be in conflict with (${n.#b[i]}).`),o++}else c.forEach((i,s)=>{switch(i){case"ID":{g=s,p++;break}case"Name":{y=s,p++;break}default:console.debug(`Unknown map field: ${i}`)}})}),console.debug(`Voice names: ${o} total, ${l} loaded.`),n?.device.forceVoiceRefresh()}async loadEfx(e,t){let n=this,l=0,o=0,p,g,y;e.split(` -`).forEach((a,r)=>{if(a)if(r){let c=0,i;a.split(" ").forEach((s,f)=>{switch(f){case p:{c|=parseInt(s,16)<<8;break}case g:{c|=parseInt(s,16);break}case y:{i=s;break}}}),!n.#x[c]||t?(n.#x[c]=i,l++):self.debugMode&&console.debug(`EFX ID 0x${c.toString(16).padStart(4,"0")} (${i}) seems to be in conflict.`),o++}else a.split(" ").forEach((c,i)=>{switch(c){case"MSB":{p=i;break}case"LSB":{g=i;break}case"Name":{y=i;break}default:console.debug(`Unknown EFX field: ${c}`)}})}),console.debug(`EFX: ${o} 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.#b[e]||e}getEfx([e,t]){let n=e<<8|t;return this.#x[n]||`0x${n.toString(16).padStart(4,"0")}`}get noteProgress(){return this.#l/this.#e}get noteOverall(){return this.noteProgress-this.#p}get noteBar(){return Math.floor(this.noteOverall/this.#i)}get noteBeat(){let e=this.noteOverall%this.#i;return e<0&&(e+=this.#i),e}getTimeSig(){return[this.#i,this.#o]}getTempo(){return this.#E}sendCmd(e){this.device.runJson(e)}render(e){e>this.#l&&(this.#l=e);let t=this.#t?.step(e)||[],n=0,l=new Set,o={},p=[],g=this,y=[];for(g.device.getStrength().forEach((E,$)=>{g.#s[$]=E}),g.device.newStrength(),t.forEach(function(E){let $=E.data,T=g.device.runJson($);switch(T?.reply){case"meta":{y.push(T);break}}T?.reply&&delete T.reply});g.#T.length>0;){let E=g.#T.shift(),$=E.part<<7|E.note;E.state?(l.add($),o[$]=E.velo):l.has($)&&(p.push({part:E.part,note:E.note,velo:o[$],state:g.device.NOTE_SUSTAIN}),n++)}y?.length>0&&g.dispatchEvent("meta",y);let a=g.device.getActive(),r=[],c=g.device.getPitch(),i=g.device.getCcAll(),s=g.device.getProgram(),f=g.device.getChType(),d=[],h=g.device.getStrength();h.forEach(function(E,$,T){T[$]=Math.max(g.#s[$],E);let U=T[$]-g.#f[$],pe=b.length*$;if(U>=0){let J=4*.25**(i[pe+b[73]]/64);g.#f[$]+=Math.ceil(U-U*g.smoothingAtk**J)}else{let J=4*.25**(i[pe+b[72]]/64);g.#f[$]+=Math.floor(U-U*g.smoothingDcy**J)}});let u=0;return a.forEach(function(E,$){E&&(r[$]=g.device.getVel($),d[$]=g.device.getExt($),u+=r[$].size)}),{extraPoly:n,extraNotes:p,curPoly:u,chInUse:a,chKeyPr:r,chPitch:c,chProgr:s,chContr:i,chType:f,chExt:d,eventCount:t.length,title:g.#c,bitmap:g.device.getBitmap(),letter:g.device.getLetter(),texts:g.device.getTexts(),master:g.device.getMaster(),mode:g.device.getMode(),strength:g.#f.slice(),velo:h,rpn:g.device.getRpn(),tSig:g.getTimeSig(),tempo:g.getTempo(),noteBar:g.noteBar,noteBeat:g.noteBeat,ace:g.device.getAce(),rawVelo:g.device.getStrength(),rawPitch:g.device.getRawPitch(),efxSink:g.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(o){o?.data?.forEach(function(p){(l.#y[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.addEventListener("note",function({data:o}){l.#T.push(o)}),l.#y[3]=function(o,p){l.#c?.length<1&&(l.#c=p,l.dispatchEvent("title",l.#c))},l.#y[81]=function(o,p){let g=l.noteProgress,y=l.#e||.5;l.#E=6e7/p,l.#e=p/1e6,l.#p+=g*(y/l.#e)-g,l.dispatchEvent("tempo",l.#E)},l.#y[88]=function(o,p){let g=l.noteProgress,y=l.noteOverall,a=l.noteBar,r=l.noteBeat,c=l.#i,i=l.#o;l.#i=p[0],l.#o=1<=c&&(c{fe&&(de[q]=!de[q],q++,q>34&&(q=0))},1e3/50);Uint8Array.prototype.render=function(e){let t=0,n=0,l=this.width||5,o=this.height||8;for(let p=0;p=l&&(t=0,n++)};var _e=class{#t=[];async load(e,t=!1,n="(internal)"){let l=this,o=0,p=0;console.debug(`Font "${n||"(internal)"}": loading started.`),e.split(` -`).forEach(function(g,y){if(y>0&&g?.length>0){let a=g.split(" "),r=parseInt(a[0],16);if(p++,l.#t[r]&&!t)return;let c=new Uint8Array(40);Array.from(a[1]).forEach(async function(i,s){let f=s%2?4:0,d=Math.floor(s/2),h=parseInt(i,16),u=3;for(;h>0||u>=0;){let v=(f+u)*5+d;c[v]=h&1,h=h>>1,u--}}),l.#t[r]=c,o++}}),console.debug(`Font "${n||"(internal)"}": ${p} total, ${o} 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),fe=!1}constructor(...e){fe=!0,(async()=>{for(let t=0;t{l.classList.add(c)});let{t:o,l:p,w:g,h:y,i:a,a:r}=n;return o?.constructor&&(l.style.top=o?.length?o:`${o}px`),p?.constructor&&(l.style.left=p?.length?p:`${p}px`),g?.constructor&&(l.style.width=g?.length?g:`${g}px`),y?.constructor&&(l.style.height=y?.length?y:`${y}px`),a?.constructor&&l.appendChild(document.createTextNode(a)),r?.constructor&&(l.style.textAlign=r),l},R=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},C=function(e,t){t?.forEach(n=>{e.appendChild(n)})},I=function(e,t){t.forEach(n=>{e.classList.contains(n)&&e.classList.remove(n)})},X=function(e,t){t.forEach(n=>{e.classList.contains(n)||e.classList.add(n)})},qe=new Array(128).fill(0);qe.forEach((e,t,n)=>{n[t]=Math.floor(24*t/12.7)/10});var ue=new Array(128).fill(0);ue.forEach((e,t,n)=>{n[t]=Math.abs(Math.round(48*(t-64)/12.7)/10)});var We=new Array(11).fill(null);We.forEach((e,t,n)=>{n[t]=`${Math.round(t*12/.0128)/100}%`});var $t=new Array(128).fill(null);$t.forEach((e,t,n)=>{n[t]=`${Math.round(t/1.27)/100}`});var A=function(e,t){let n=qe[t];e.setAttribute("height",n),e.setAttribute("y",24-n)},ze=function(e,t){e.innerText=t,e.rNew=!0;let n=e.measureText(t);e.rWidth=n.width},ma=class extends Ve{#t=128;#b=!1;#x="";#c;#y=0;#T=0;#f=0;#s=0;#e=1;#E=0;#i=new Uint8Array(1280);#o=new Uint8Array(1280);#p=new Uint8Array(1280);#l=new Uint8Array(512);#w=new Uint8Array(512);#M=new Uint8Array(512);#R;#X;#C;#r;#n;#V="fcdaff";#a={};#g={};#d=[];#v={};#$={};#P=[];#S="block";glyphs=new _e;#_(e,t,n,l=0,o=0){let p=this,{width:g,height:y}=e.canvas,a,r,c,i,s=p.#e,f=l>3,d=mt.indexOf(t%12)>-1;switch(p.#S){case"block":case"comb":{a=Math.round(t*g/128),r=Math.round((t+1)*g/128),c=r-a,i=s==1?2:1;break}case"piano":{a=Math.round((Math.floor(t/12)*7+Fe[t%12])*g/75*1.0044642857142856),r=Math.round((Math.floor(t/12)*7+Fe[t%12]+1)*g/75*1.0044642857142856)-1,c=r-a,i=s==1?3:1;break}case"line":{let h=t-o;Math.abs(o)>2&&(h=t-Math.sign(o)*2),r=Math.round((t+.5)*g/128),a=Math.round((h+.5)*g/128)}default:}switch(e.fillStyle=`#${d?p.#V:"ffffff"}${(n<<1|n>>6).toString(16).padStart(2,"0")}`,e.strokeStyle=e.fillStyle,e.lineWidth=s==1?4:2,e.lineDashOffset=0,p.#S){case"block":{let h=e.canvas.height-1;e.fillRect(a,1,c,h),f&&e.clearRect(a+i,i+1,c-(i<<1),h-(i<<1));break}case"comb":{let h=(d?Math.round((e.canvas.height<<1)/3):e.canvas.height)-1;e.fillRect(a,1,c,h),f&&e.clearRect(a+i,i+1,c-(i<<1),h-(i<<1));break}case"piano":{let h=(d?0:e.canvas.height>>1)+1,u=(e.canvas.height>>1)-1;e.fillRect(a,h,c,u),f&&e.clearRect(a+i,h+i,c-(i<<1),u-(i<<1));break}case"line":{if(f)switch(s){case 4:{e.setLineDash(he[2]);break}default:e.setLineDash(he[1])}else e.setLineDash(he[0]),s!=4&&self?.document?.mozFullScreen&&(a+=.5,r+=.5);e.beginPath(),e.moveTo(a,(s==4||!f)&&self?.document?.mozFullScreen?2:1),e.lineTo(r,(y>>1)+2),e.lineTo(a,y+2),e.stroke();break}default:}}#U(e,t){let n=this;(e?.chInUse||t).forEach((l,o)=>{if(l){let p=n.#d[o>>4][o&15].cxt;p.clearRect(0,0,p.canvas.width,p.canvas.height),e.chKeyPr[o].forEach(({v:g,s:y},a)=>{n.#_(p,a,g,y,n.device.getPitchShift(o))})}})}#N(e){let t=this;Date.now()-t.#y>4e3&&(t.#T=0,t.#f=142-t.#v.view.clientHeight,(t.#c?.clientWidth||0)>840&&(t.#T=840-t.#c.clientWidth),t.#v.view.style.transform=`translateX(${t.#T}px) translateY(${t.#f}px)`,e&&(t.#y=0))}#L(){let e=self.innerWidth/self.innerHeight,t=1,n=self.innerWidth,l=self.innerHeight;e>=j?(t=Math.round(self.innerHeight/1080*1e4)/1e4,n=Math.ceil(self.innerHeight*j)):e>4,c=a*m.cc,i=e.#d[r][a&15];if(n.chInUse[a]&&r>=e.#E&&ri.metre.canvas.width){i.metre.rNew&&(i.metre.rNew=!1,i.metre.rOffset=t);let f=t-(i.metre.rOffset||0),d=32,h=i.metre.rWidth-i.metre.canvas.width+d,u=f*-25%(i.metre.rWidth+d+48)+48;u>0&&(u=0),i.metre.fillText(i.metre.innerText,u,3+e.#n.font4[0]),Math.abs(u)>h&&i.metre.fillText(i.metre.innerText,u+i.metre.rWidth+d,3+e.#n.font4[0])}else i.metre.fillText(i.metre.innerText,0,3+e.#n.font4[0]);i.metre.globalCompositeOperation="xor",i.metre.fillRect(0,0,n.strength[a]*121/255,25);let s=n.chContr[c+b[10]];switch(i.pan.setAttribute("width",`${ue[s]||0}`),s<64?i.pan.setAttribute("x",`${84-ue[s]}`):s>127?(i.pan.setAttribute("x","60"),i.pan.setAttribute("width","48")):i.pan.setAttribute("x","84"),i.extVis.clearRect(0,0,44,25),n.chExt[a][0]){case e.device.EXT_VL:{let f=(n.chContr[c+b[136]]-64)/64||n.rawPitch[a]/8192;f=f*-4+4;let d=+!!n.rawVelo[a]*(n.chContr[c+b[129]]*n.chContr[c+b[11]]/16129);!d&&n.rawVelo[a]&&(d=n.rawVelo[a]/255),d*=36,i.extVis.beginPath(),i.extVis.moveTo(0,12-f-3),i.extVis.lineTo(8+d,12),i.extVis.lineTo(0,12+f+3),i.extVis.fill();break}}}}let g=new Array(m.ch);if(e.#d.forEach((a,r)=>{a.forEach((c,i)=>{c.refresh&&(c.refresh=!1,g[r<<7|i]=!0)})}),["line"].indexOf(e.#S)>-1)for(;e.#P.length>0;){let a=e.#P.shift();g[a.part]=!0}e.#U(n,g),n.extraNotes.forEach(a=>{let{part:r,note:c,velo:i,state:s}=a,f=e.#d[r>>4][r&15].cxt;e.#_(f,c,i,s,e.device.getPitchShift(r))});let y=e.#$.cxt;l>n.bitmap.expire?e.#M.fill(0):n.bitmap.bitmap.length>256?n.bitmap.bitmap.forEach((a,r)=>{e.#M[r]=a?255:0}):n.bitmap.bitmap.forEach((a,r)=>{e.#M[r<<1]=a?255:0,e.#M[r<<1|1]=a?255:0}),e.#p.fill(0),l<=n.letter.expire&&e.glyphs.getStr(n.letter.text).forEach((a,r)=>{let c=(r&15)*5,i=r>>4<<3;a.forEach((s,f)=>{let d=c+f%5,h=i+Math.floor(f/5);e.#p[h*80+d]=s?255:0})}),e.#l.forEach((a,r,c)=>{let i=e.#M[r];i>a?c[r]+=Math.min(i-a,Z):i{let i=e.#p[r];i>a?c[r]+=Math.min(i-a,Z):i{let c=r>>5,i=r&31;e.#w[r]!=a?(y.clearRect(252+(i<<2),c<<2,3,3),a&&(y.fillStyle=`#ffffff${a.toString(16).padStart(2,"0")}`,y.fillRect(252+(i<<2),c<<2,3,3))):self.debugMode&&(y.clearRect(252+(i<<2),c<<2,3,3),a&&(y.fillStyle=`#ff0000${a.toString(16).padStart(2,"0")}`,y.fillRect(252+(i<<2),c<<2,3,3)))}),e.#i.forEach((a,r)=>{let c=Math.floor(r/80),i=r%80;i+=Math.floor(i/5),e.#o[r]!=a?(y.clearRect(i<<2,(c|16)<<2,3,3),a&&(y.fillStyle=`#ffffff${a.toString(16).padStart(2,"0")}`,y.fillRect(i<<2,(c|16)<<2,3,3))):self.debugMode&&(y.clearRect(i<<2,(c|16)<<2,3,3),a&&(y.fillStyle=`#ff0000${a.toString(16).padStart(2,"0")}`,y.fillRect(i<<2,(c|16)<<2,3,3)))}),e.#w.forEach((a,r,c)=>{c[r]=e.#l[r]}),e.#o.forEach((a,r,c)=>{c[r]=e.#i[r]})}#H;#F;get style(){return this.#S}set style(e){let t=this;t.#S=e,t.#U(t.render(t.#R?.currentTime||0)),I(t.#r,["cambiare-style-block","cambiare-style-comb","cambiare-style-piano","cambiare-style-line"]),X(t.#r,[`cambiare-style-${e}`])}setClockSource(e){this.#R=e}setPixelProfile(e){let t=this;if(Ke[e]){let n=Ke[e];t.#n=n,t.#r&&(t.#r.style.setProperty("--pcp-font4",`translate(${n.font4[1]}px, ${n.font4[0]}px)`),t.#r.style.setProperty("--pcp-font7",`translate(${n.font7[1]}px, ${n.font7[0]}px)`))}else throw new Error(`"${e}" is not a valid pixel correction profile`)}setMode(e){let t=this;I(t.#r,["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!="?"&&X(t.#r,[`cambiare-mode-${e}`]),t.#V={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"}#G(e){let t=this,n=t.#e,l=t.#E;t.#d.forEach((o,p)=>{if(p>=l&&p{r.root.style.top=`${c*(n>2?26:52)}px`})}else I(o.root,["port-active"]),o.root.style.top="",o.root.style.left="",o.forEach((g,y)=>{g.root.style.top=""});e&&o.forEach((g,y)=>{g.cxt.canvas.width=t.#e==1?1193:495,g.cxt.canvas.height=t.#e==4?26:52})})}setPort(e){let t=this;I(t.#r,["cambiare-start0","cambiare-start1","cambiare-start2","cambiare-start3","cambiare-start4","cambiare-start5","cambiare-start6","cambiare-start7"]),X(t.#r,[`cambiare-start${e}`]),t.#E=e,t.#G(!1)}setRange(e){let t=this;I(t.#r,["cambiare-port1","cambiare-port2","cambiare-port4","cambiare-compact"]),X(t.#r,[`cambiare-${e}`]),t.#e=parseInt(e.slice(4))||1,t.#G(!0)}attach(e){let t=this;t.#X=e;let n=w("div",["cambiare-container"]);e.appendChild(n),t.#C=n;let l=w("div",["cambiare-canvas","cambiare-port1","cambiare-start0","cambiare-style-block"]);n.appendChild(l),t.#r=l,self.addEventListener("resize",t.#h),t.#h(),t.#F=setInterval(t.#H,20),t.#a.root=w("div",["sect-info"]),t.#a.events=w("span",["field","pcp-font4"],{t:1,l:0,w:35,h:33}),t.#a.curPoly=w("span",["field","pcp-font4"],{t:1,l:52,w:35,h:33}),t.#a.maxPoly=w("span",["field","pcp-font4"],{t:1,l:98,w:35,h:33}),t.#a.sigN=w("span",["field","pcp-font4"],{t:1,l:194,w:23,h:33,a:"right"}),t.#a.sigD=w("span",["field","pcp-font4"],{t:1,l:232,w:23,h:33}),t.#a.barCount=w("span",["field","pcp-font4"],{t:1,l:304,w:35,h:33,a:"right"}),t.#a.barDelim=w("span",["field","field-label","pcp-font4"],{t:0,l:343,w:8,h:33,i:"/"}),t.#a.barNote=w("span",["field","pcp-font4"],{t:1,l:354,w:23,h:33}),t.#a.tempo=w("span",["field","pcp-font4"],{t:1,l:454,w:64,h:33,a:"right"}),t.#a.volume=w("span",["field","pcp-font4"],{t:1,l:562,w:63,h:33,a:"right"}),t.#a.mode=w("span",["field","pcp-font4"],{t:1,l:708,w:152,h:33}),t.#a.reverb=w("span",["field","pcp-font4"],{t:1,l:1e3,w:190,h:33}),t.#a.chorus=w("span",["field","pcp-font4"],{t:1,l:1240,w:190,h:33}),t.#a.delay=w("span",["field","pcp-font4"],{t:1,l:1475,w:190,h:33}),t.#a.insert=w("span",["field","pcp-font4"],{t:1,l:1706,w:190,h:33}),t.#a.title=w("span",["field","pcp-font4"],{t:35,l:50,w:810,h:33}),l.appendChild(t.#a.root),C(t.#a.root,[t.#a.events,t.#a.curPoly,w("span",["field","field-label","pcp-font4"],{t:1,l:89,w:5,h:33,i:":"}),t.#a.maxPoly,w("span",["field","field-key","pcp-font7"],{t:1,l:148,w:41,h:33,i:"TSig"}),t.#a.sigN,w("span",["field","field-label","pcp-font4"],{t:0,l:221,w:8,h:33,i:"/"}),t.#a.sigD,w("span",["field","field-key","pcp-font7"],{t:1,l:268,w:30,h:33,i:"Bar"}),t.#a.barCount,t.#a.barDelim,t.#a.barNote,w("span",["field","field-key","pcp-font7"],{t:1,l:390,w:61,h:33,i:"Tempo",a:"right"}),t.#a.tempo,w("span",["field","field-key","pcp-font7"],{t:1,l:528,w:29,h:33,i:"Vol"}),t.#a.volume,w("span",["field","field-label","pcp-font4"],{t:1,l:626,w:17,h:33,i:"%"}),w("span",["field","field-key","pcp-font7"],{t:1,l:652,w:52,h:33,i:"Mode"}),t.#a.mode,w("span",["field","field-key","pcp-font7"],{t:1,l:960,w:34,h:33,i:"Rev"}),t.#a.reverb,w("span",["field","field-key","pcp-font7"],{t:1,l:1198,w:36,h:33,i:"Cho"}),t.#a.chorus,w("span",["field","field-key","pcp-font7"],{t:1,l:1438,w:31,h:33,i:"Var"}),t.#a.delay,w("span",["field","field-key","pcp-font7"],{t:1,l:1673,w:27,h:33,i:"Ins"}),t.#a.insert,w("span",["field","field-key","pcp-font7"],{t:35,l:0,w:44,h:33,i:"Title"}),t.#a.title]),t.#g.root=w("div",["sect-mark"]),t.#g.left=w("div",["sect-mark-left","boundary"],{t:0,l:0}),t.#g.right=w("div",["sect-mark-right","boundary"],{t:0,l:960}),l.appendChild(t.#g.root),C(t.#g.root,[t.#g.left,t.#g.right]),C(t.#g.left,[w("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),w("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),w("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),w("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),w("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),w("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),C(t.#g.right,[w("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),w("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),w("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),w("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),w("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),w("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),t.#d.root=w("div",["sect-part"]);for(let o=0;o>4;o++){let p=o<<4;t.#d[o]=[],t.#d[o].root=w("div",["boundary",`part-port-${o}`]);for(let g=0;g<16;g++){let y=(p|g)+1;y>=100?y=`${Math.floor(y/10).toString(16)}${y%10}`:y=`${y}`.padStart(2,"0"),t.#d[o][g]={root:w("div",["boundary","part-channel"]),major:w("div",["boundary","part-info-major"]),minor:w("div",["boundary","part-info-minor"],{t:26}),keys:w("div",["boundary","part-keys"]),notes:w("div",["boundary","part-keyboard"]),cxt:w("canvas",["field"]).getContext("2d"),number:w("span",["field","field-label","pcp-font4"],{t:1,w:18,h:25,i:y}),voice:w("span",["field"],{l:22,t:1,w:121,h:25}),metre:w("canvas",["field"]).getContext("2d"),type:w("span",["field","field-label","pcp-font4"],{t:1,w:18,h:25}),std:w("span",["field","pcp-font4"],{l:22,t:1,w:20,h:25,a:"center"}),msb:w("span",["field","pcp-font4"],{l:48,t:1,w:27,h:25}),prg:w("span",["field","pcp-font4"],{l:81,t:1,w:27,h:25}),lsb:w("span",["field","pcp-font4"],{l:114,t:1,w:27,h:25}),cc:R("svg",{viewBox:"0 0 108 24",width:108,style:"left: 146px; top: 1px; position: absolute;"}),vol:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:0}),exp:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:6}),mod:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:12}),rev:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:18}),cho:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:24}),var:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:30}),brt:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:36}),por:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:42}),cea:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:48}),ceb:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:54}),pan:R("rect",{fill:"var(--accent-color)",width:0,height:24,x:84}),extVis:w("canvas",["field"],{l:210,t:1}).getContext("2d")};let a=t.#d[o][g];We.forEach(r=>{a.notes.appendChild(w("span",["field","part-csplit"],{l:r}))}),a.notes.appendChild(w("span",["field","part-csplit","part-cdive"],{l:0,w:"100%",h:1})),a.metre.canvas.width=121,a.metre.canvas.height=25,a.metre.fillStyle="#fff",a.metre.textBaseline="top",a.metre.font="20px 'PT Sans Narrow'",a.extVis.canvas.width=44,a.extVis.canvas.height=25,a.extVis.fillStyle="#fff",C(a.notes,[a.cxt.canvas]),C(a.keys,[a.notes]),C(a.voice,[a.metre.canvas]),C(a.cc,[a.vol,a.exp,a.mod,a.rev,a.cho,a.var,a.brt,a.por,a.cea,a.ceb,a.pan,R("rect",{x:83,y:0,width:1,height:24,fill:"var(--foreground-color)"})]),C(a.major,[a.number,a.voice,a.cc]),C(a.minor,[a.type,a.std,a.msb,a.prg,a.lsb,a.extVis.canvas]),C(a.root,[a.major,a.minor,a.keys]),C(t.#d[o].root,[a.root])}t.#d.root.appendChild(t.#d[o].root)}l.appendChild(t.#d.root),t.#v.root=w("div",["sect-meta"]),t.#v.view=w("div",["boundary"]),l.appendChild(t.#v.root),C(t.#v.root,[t.#v.view]),t.#$.root=w("div",["sect-pix","boundary"],{l:1529,t:950,w:379,h:127}),t.#$.cxt=w("canvas",["field"]).getContext("2d"),t.#$.cxt.canvas.width=379,t.#$.cxt.canvas.height=127,C(t.#$.root,[t.#$.cxt.canvas]),l.appendChild(t.#$.root),t.addEventListener("mode",o=>{t.#a.mode.innerText=`${yt[o.data]}`,t.setMode(o.data)}),t.addEventListener("mastervolume",o=>{let p=Math.round(o.data*100)/100;t.#a.volume.innerText=`${Math.floor(p)}.${`${Math.floor(p%1*100)}`.padStart(2,"0")}`}),t.addEventListener("tempo",o=>{let p=Math.round(o.data*100);t.#a.tempo.innerText=`${Math.floor(p/100)}.${`${Math.floor(p%100)}`.padStart(2,"0")}`}),t.addEventListener("tsig",o=>{[t.#a.sigN.innerText,t.#a.sigD.innerText]=o.data}),t.addEventListener("title",o=>{t.#a.title.innerText=o.data||"No Title"}),t.addEventListener("voice",({data:o})=>{let p=t.getChVoice(o.part),g=t.#d[o.part>>4][o.part&15];ze(g.metre,t.getMapped(p.name)),g.type.innerText=gt[t.device.getChType()[o.part]],g.std.innerText=p.standard,g.msb.innerText=`${p.sid[0]}`.padStart(3,"0"),g.prg.innerText=`${p.sid[1]}`.padStart(3,"0"),g.lsb.innerText=`${p.sid[2]}`.padStart(3,"0")}),t.addEventListener("pitch",o=>{let{part:p,pitch:g}=o.data;t.#d[p>>4][p&15].notes.style.transform=`translateX(${g/1.28}%)`}),t.addEventListener("efxreverb",o=>{t.#a.reverb.innerText=t.getEfx(o.data)}),t.addEventListener("efxchorus",o=>{t.#a.chorus.innerText=t.getEfx(o.data)}),t.addEventListener("efxdelay",o=>{t.#a.delay.innerText=t.getEfx(o.data)}),t.addEventListener("efxinsert0",o=>{t.#a.insert.innerText=t.getEfx(o.data)}),t.addEventListener("partefxtoggle",o=>{let{part:p,active:g}=o.data;[I,X][g](t.#d[p>>4][p&15].number,["part-efx"])}),t.addEventListener("channeltoggle",o=>{let{part:p,active:g}=o.data;[I,X][g](t.#d[p>>4][p&15].root,["part-active"])}),t.addEventListener("metacommit",o=>{let p=o.data;if(t.#b&&p.type==t.#x&&t.#c)switch(p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{C(t.#c,[w("span",["meta-slice"],{i:p.data})]);break}default:t.#c.childNodes[0].data+=p.data}else if(p.data?.length&&Et.indexOf(p.type)==-1){let g=w("div",["meta-line"]),y=w("span",["field","field-key","meta-type"],{i:vt[p.type]||p.type});switch(p.mask&&(y.style.display="none"),p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{t.#c=w("span",["field","meta-data"]),C(t.#c,[w("span",["meta-slice"],{i:p.data})]);break}default:t.#c=w("span",["field","meta-data"],{i:p.data})}for(t.#v.view.appendChild(g),C(g,[y,t.#c]);t.#v.view.children.length>t.#t;)t.#v.view.children[0].remove()}t.#b=p.amend||!1,t.#x=p.type||"",t.#N()}),t.#v.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.#G(!0)}detach(e){let t=this;self.removeEventListener("resize",t.#h),t.#r.remove(),t.#r=void 0,t.#C.remove(),t.#C=void 0,t.#X=void 0,clearInterval(t.#F)}constructor(e,t){super(new Ne,.1,.75);let n=this;n.#h=n.#L.bind(this),n.#H=n.#u.bind(this),e&&n.attach(e),t&&n.setClockSource(t),n.setPixelProfile("none"),n.addEventListener("reset",()=>{n.#s=0,n.#b=!1,n.#x="",n.#c=null;try{let l=n.#v.view.children;for(let o=l.length-1;o>=0;o--)l[o].remove();n.#v.view.style.transform="translateX(0px) translateY(140px)";for(let o=0;o>4][o&15];I(p.root,["part-active"]),I(p.number,["part-efx"]),ze(p.metre,""),p.type.innerText="",p.std.innerText="",p.msb.innerText="",p.prg.innerText="",p.lsb.innerText="",p.notes.style.transform=""}}catch{}}),n.addEventListener("pitch",({data:l})=>{n.#P.push(l)})}};export{ma as Cambiare}; +%o`,a)}})}};var oe=at(Be(),1);var Xe=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}},ce=class extends Xe{constructor(e,t,n){super(!0,e,t,n)}},He=class extends Xe{constructor(e,t){super(!1,e,e,t)}},le=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].endd.#t&&(n.push(p),d.#t=p.index)})}return n}getRange(e,t){e>t&&([e,t]=[t,e]);let n=[],l=-1,d=Math.ceil(Math.sqrt(this.length)),p=!0;for(let g=0;g=e&&(l=g):l=l<0?g:l;for(;p;)this[l]?.end=e&&n.push(this[l]):p=!1,l++;return n}};var bt=0xffffffffffff,Ge=function(e){let t=new le,n=this,l=e.timeDivision,d=120,p=new le,g=0,v=0;p.push(new ce(0,bt,[120,0])),e.track.forEach(function(i){g=0,i.event.forEach(function(s){g+=s.deltaTime,s.type==255&&s?.metaType==81&&(d=6e7/s.data,p[p.length-1]&&p.push(new ce(g,0xffffffffffff,[d,0])))})}),p.fresh(),p.forEach(function(i,s,f){s>0&&(f[s-1].end=i.start)});let a=120;p.forEach(function(i,s,f){s>0&&(i.end==i.start?f.splice(f.indexOf(i),1):a==i.data[0]&&(f[s-1].end=i.end,f.splice(f.indexOf(i),1)),a=i.data[0])});let r=0,c=120;return p.forEach(function(i){let s=i.start,f=s/c/l*60+r;c=i.data[0],r=f-s/c/l*60,i.data[1]=r}),console.debug("All tempo changes: ",p),d=120,g=0,v=0,e.track.forEach(function(i,s){g=0,v=0;let f=s+1;i.event.forEach(function(o,h){g+=o.deltaTime;let u=p.step(g,!0)[0];u&&(d=u.data[0],v=u.data[1]);let y={type:o.type,data:o.data,track:f,part:0};o.type>14?y.meta=o.metaType:y.part=o.channel,t.push(new He(g/d/l*60+v,y))})}),t.fresh(),self.midiEvents=t,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),t};oe.default.customInterpreter=Me;var S=function(e,t,n){e.addEventListener(n,l=>{t.dispatchEvent(n,l.data)})},Ve=class extends W{device;#t;#p={};#T=[];#c="";#v=[];#S=[];#h=new Uint8ClampedArray(128);#s=new Uint8ClampedArray(128);#e=.5;#b=120;#i=4;#o=4;#u=0;#l=0;smoothingAtk=0;smoothingDcy=0;reset(){let e=this;e.dispatchEvent("reset"),e.#t?.resetIndex(),e.device.init(),e.#c="",e.#e=.5,e.#b=120,e.#i=4,e.#o=4,e.#u=0,e.#l=0,e.dispatchEvent("tempo",e.#b),e.dispatchEvent("title",e.#c)}init(){this.reset(),this.#t=void 0}async loadFile(e){this.#t=Ge(oe.default.parse(new Uint8Array(await e.arrayBuffer())))}async loadMap(e,t){let n=this,l=0,d=0,p=0,g,v;e.split(` +`).forEach((a,r)=>{if(!a)return;let c=a.split(" ");if(r){if(!p)return;let i="",s="";c.forEach((f,o)=>{switch(o){case g:{i=f;break}case v:{s=f;break}}}),!n.#p[i]||t?(n.#p[i]=s,l++):self.debugMode&&console.debug(`Voice "${s}" (${i}) seems to be in conflict with (${n.#p[i]}).`),d++}else c.forEach((i,s)=>{switch(i){case"ID":{g=s,p++;break}case"Name":{v=s,p++;break}default:console.debug(`Unknown map field: ${i}`)}})}),console.debug(`Voice names: ${d} total, ${l} loaded.`),n?.device.forceVoiceRefresh()}async loadEfx(e,t){let n=this,l=0,d=0,p,g,v;e.split(` +`).forEach((a,r)=>{if(a)if(r){let c=0,i;a.split(" ").forEach((s,f)=>{switch(f){case p:{c|=parseInt(s,16)<<8;break}case g:{c|=parseInt(s,16);break}case v:{i=s;break}}}),!n.#T[c]||t?(n.#T[c]=i,l++):self.debugMode&&console.debug(`EFX ID 0x${c.toString(16).padStart(4,"0")} (${i}) seems to be in conflict.`),d++}else a.split(" ").forEach((c,i)=>{switch(c){case"MSB":{p=i;break}case"LSB":{g=i;break}case"Name":{v=i;break}default:console.debug(`Unknown EFX field: ${c}`)}})}),console.debug(`EFX: ${d} 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.#p[e]||e}getEfx([e,t]){let n=e<<8|t;return this.#T[n]||`0x${n.toString(16).padStart(4,"0")}`}get noteProgress(){return this.#l/this.#e}get noteOverall(){return this.noteProgress-this.#u}get noteBar(){return Math.floor(this.noteOverall/this.#i)}get noteBeat(){let e=this.noteOverall%this.#i;return e<0&&(e+=this.#i),e}getTimeSig(){return[this.#i,this.#o]}getTempo(){return this.#b}sendCmd(e){this.device.runJson(e)}render(e){e>this.#l&&(this.#l=e);let t=this.#t?.step(e)||[],n=0,l=new Set,d={},p=[],g=this,v=[];for(g.device.getStrength().forEach((E,$)=>{g.#s[$]=E}),g.device.newStrength(),t.forEach(function(E){let $=E.data,T=g.device.runJson($);switch(T?.reply){case"meta":{v.push(T);break}}T?.reply&&delete T.reply});g.#S.length>0;){let E=g.#S.shift(),$=E.part<<7|E.note;E.state?(l.add($),d[$]=E.velo):l.has($)&&(p.push({part:E.part,note:E.note,velo:d[$],state:g.device.NOTE_SUSTAIN}),n++)}v?.length>0&&g.dispatchEvent("meta",v);let a=g.device.getActive(),r=[],c=g.device.getPitch(),i=g.device.getCcAll(),s=g.device.getProgram(),f=g.device.getChType(),o=[],h=g.device.getStrength();h.forEach(function(E,$,T){T[$]=Math.max(g.#s[$],E);let U=T[$]-g.#h[$],pe=b.length*$;if(U>=0){let J=4*.25**(i[pe+b[73]]/64);g.#h[$]+=Math.ceil(U-U*g.smoothingAtk**J)}else{let J=4*.25**(i[pe+b[72]]/64);g.#h[$]+=Math.floor(U-U*g.smoothingDcy**J)}});let u=0;return a.forEach(function(E,$){E&&(r[$]=g.device.getVel($),o[$]=g.device.getExt($),u+=r[$].size)}),{extraPoly:n,extraNotes:p,curPoly:u,chInUse:a,chKeyPr:r,chPitch:c,chProgr:s,chContr:i,chType:f,chExt:o,eventCount:t.length,title:g.#c,bitmap:g.device.getBitmap(),letter:g.device.getLetter(),texts:g.device.getTexts(),master:g.device.getMaster(),mode:g.device.getMode(),strength:g.#h.slice(),velo:h,rpn:g.device.getRpn(),tSig:g.getTimeSig(),tempo:g.getTempo(),noteBar:g.noteBar,noteBeat:g.noteBeat,ace:g.device.getAce(),rawVelo:g.device.getStrength(),rawPitch:g.device.getRawPitch(),efxSink:g.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(d){d?.data?.forEach(function(p){(l.#v[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.addEventListener("note",function({data:d}){l.#S.push(d)}),l.#v[3]=function(d,p){l.#c?.length<1&&(l.#c=p,l.dispatchEvent("title",l.#c))},l.#v[81]=function(d,p){let g=l.noteProgress,v=l.#e||.5;l.#b=6e7/p,l.#e=p/1e6,l.#u+=g*(v/l.#e)-g,l.dispatchEvent("tempo",l.#b)},l.#v[88]=function(d,p){let g=l.noteProgress,v=l.noteOverall,a=l.noteBar,r=l.noteBeat,c=l.#i,i=l.#o;l.#i=p[0],l.#o=1<=c&&(c{de&&(fe[q]=!fe[q],q++,q>34&&(q=0))},1e3/50);Uint8Array.prototype.render=function(e){let t=0,n=0,l=this.width||5,d=this.height||8;for(let p=0;p=l&&(t=0,n++)};var _e=class{#t=[];async load(e,t=!1,n="(internal)"){let l=this,d=0,p=0;console.debug(`Font "${n||"(internal)"}": loading started.`),e.split(` +`).forEach(function(g,v){if(v>0&&g?.length>0){let a=g.split(" "),r=parseInt(a[0],16);if(p++,l.#t[r]&&!t)return;let c=new Uint8Array(40);Array.from(a[1]).forEach(async function(i,s){let f=s%2?4:0,o=Math.floor(s/2),h=parseInt(i,16),u=3;for(;h>0||u>=0;){let y=(f+u)*5+o;c[y]=h&1,h=h>>1,u--}}),l.#t[r]=c,d++}}),console.debug(`Font "${n||"(internal)"}": ${p} total, ${d} 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),de=!1}constructor(...e){de=!0,(async()=>{for(let t=0;t{l.classList.add(c)});let{t:d,l:p,w:g,h:v,i:a,a:r}=n;return d?.constructor&&(l.style.top=d?.length?d:`${d}px`),p?.constructor&&(l.style.left=p?.length?p:`${p}px`),g?.constructor&&(l.style.width=g?.length?g:`${g}px`),v?.constructor&&(l.style.height=v?.length?v:`${v}px`),a?.constructor&&l.appendChild(document.createTextNode(a)),r?.constructor&&(l.style.textAlign=r),l},R=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},C=function(e,t){t?.forEach(n=>{e.appendChild(n)})},I=function(e,t){t.forEach(n=>{e.classList.contains(n)&&e.classList.remove(n)})},X=function(e,t){t.forEach(n=>{e.classList.contains(n)||e.classList.add(n)})},qe=new Array(128).fill(0);qe.forEach((e,t,n)=>{n[t]=Math.floor(24*t/12.7)/10});var ue=new Array(128).fill(0);ue.forEach((e,t,n)=>{n[t]=Math.abs(Math.round(48*(t-64)/12.7)/10)});var We=new Array(11).fill(null);We.forEach((e,t,n)=>{n[t]=`${Math.round(t*12/.0128)/100}%`});var $t=new Array(128).fill(null);$t.forEach((e,t,n)=>{n[t]=`${Math.round(t/1.27)/100}`});var P=function(e,t){let n=qe[t];e.setAttribute("height",n),e.setAttribute("y",24-n)},ze=function(e,t){e.innerText=t,e.rNew=!0;let n=e.measureText(t);e.rWidth=n.width},ma=class extends Ve{#t=128;#p=!1;#T="";#c;#v=0;#S=0;#h=0;#s=0;#e=1;#b=0;#i=new Uint8Array(1280);#o=new Uint8Array(1280);#u=new Uint8Array(1280);#l=new Uint8Array(512);#$=new Uint8Array(512);#M=new Uint8Array(512);#R;#B;#k;#r;#n;#X="fcdaff";#a={};#g={};#f=[];#E={};#w={};#_=[];#O="block";glyphs=new _e;#L(e,t,n,l=0,d=0){let p=this,{width:g,height:v}=e.canvas,a,r,c,i,s=p.#e,f=l>3,o=mt.indexOf(t%12)>-1;switch(p.#O){case"block":case"comb":{a=Math.round(t*g/128),r=Math.round((t+1)*g/128),c=r-a,i=s==1?2:1;break}case"piano":{a=Math.round((Math.floor(t/12)*7+Fe[t%12])*g/75*1.0044642857142856),r=Math.round((Math.floor(t/12)*7+Fe[t%12]+1)*g/75*1.0044642857142856)-1,c=r-a,i=s==1?3:1;break}case"line":{let h=t-d;Math.abs(d)>2&&(h=t-Math.sign(d)*2),r=Math.round((t+.5)*g/128),a=Math.round((h+.5)*g/128)}default:}switch(e.fillStyle=`#${o?p.#X:"ffffff"}${(n<<1|n>>6).toString(16).padStart(2,"0")}`,e.strokeStyle=e.fillStyle,e.lineWidth=s==1?4:2,e.lineDashOffset=0,p.#O){case"block":{let h=e.canvas.height-1;e.fillRect(a,1,c,h),f&&e.clearRect(a+i,i+1,c-(i<<1),h-(i<<1));break}case"comb":{let h=(o?Math.round((e.canvas.height<<1)/3):e.canvas.height)-1;e.fillRect(a,1,c,h),f&&e.clearRect(a+i,i+1,c-(i<<1),h-(i<<1));break}case"piano":{let h=(o?0:e.canvas.height>>1)+1,u=(e.canvas.height>>1)-1;e.fillRect(a,h,c,u),f&&e.clearRect(a+i,h+i,c-(i<<1),u-(i<<1));break}case"line":{if(f)switch(s){case 4:{e.setLineDash(he[2]);break}default:e.setLineDash(he[1])}else e.setLineDash(he[0]),s!=4&&self?.document?.mozFullScreen&&(a+=.5,r+=.5);e.beginPath(),e.moveTo(a,(s==4||!f)&&self?.document?.mozFullScreen?2:1),e.lineTo(r,(v>>1)+2),e.lineTo(a,v+2),e.stroke();break}default:}}#F(e,t){let n=this;(e?.chInUse||t).forEach((l,d)=>{if(l){let p=n.#f[d>>4][d&15].cxt;p.clearRect(0,0,p.canvas.width,p.canvas.height),e.chKeyPr[d].forEach(({v:g,s:v},a)=>{n.#L(p,a,g,v,n.device.getPitchShift(d))})}})}#U(e){let t=this;Date.now()-t.#v>4e3&&(t.#S=0,t.#h=142-t.#E.view.clientHeight,(t.#c?.clientWidth||0)>840&&(t.#S=840-t.#c.clientWidth),t.#E.view.style.transform=`translateX(${t.#S}px) translateY(${t.#h}px)`,e&&(t.#v=0))}#H(){let e=self.innerWidth/self.innerHeight,t=1,n=self.innerWidth,l=self.innerHeight;e>=j?(t=Math.min(Math.round(self.innerHeight/1080*1e4)/1e4,100),n=Math.ceil(self.innerHeight*j)):e>4,c=a*m.cc,i=e.#f[r][a&15];if(n.chInUse[a]&&r>=e.#b&&ri.metre.canvas.width){i.metre.rNew&&(i.metre.rNew=!1,i.metre.rOffset=t);let f=t-(i.metre.rOffset||0),o=32,h=i.metre.rWidth-i.metre.canvas.width+o,u=f*-25%(i.metre.rWidth+o+48)+48;u>0&&(u=0),i.metre.fillText(i.metre.innerText,u,3+e.#n.font4[0]),Math.abs(u)>h&&i.metre.fillText(i.metre.innerText,u+i.metre.rWidth+o,3+e.#n.font4[0])}else i.metre.fillText(i.metre.innerText,0,3+e.#n.font4[0]);i.metre.globalCompositeOperation="xor",i.metre.fillRect(0,0,n.strength[a]*121/255,25);let s=n.chContr[c+b[10]];switch(i.pan.setAttribute("width",`${ue[s]||0}`),s<64?i.pan.setAttribute("x",`${84-ue[s]}`):s>127?(i.pan.setAttribute("x","60"),i.pan.setAttribute("width","48")):i.pan.setAttribute("x","84"),i.extVis.clearRect(0,0,44,25),i.extVis.fillStyle="#fff",n.chExt[a][0]){case e.device.EXT_VL:{let f=(n.chContr[c+b[136]]-64)/64||n.rawPitch[a]/8192;f=f*-4+4;let o=+!!n.rawVelo[a]*(n.chContr[c+b[129]]*n.chContr[c+b[11]]/16129);!o&&n.rawVelo[a]&&(o=n.rawVelo[a]/255),o*=36,i.extVis.beginPath(),i.extVis.moveTo(3,12-f-3),i.extVis.lineTo(11+o,12),i.extVis.lineTo(3,12+f+3),i.extVis.fill();break}case e.device.EXT_DX:{n.chContr.subarray(c+b[142],c+b[157]+1).forEach((o,h)=>{h>=8&&(i.extVis.fillStyle=`#${e.#X}`);let u=h*3,y=(o-64)/5.82;y>=0?i.extVis.fillRect(u,12-y,2,y+1):i.extVis.fillRect(u,12,2,1-y)});break}}}}let g=new Array(m.ch);if(e.#f.forEach((a,r)=>{a.forEach((c,i)=>{c.refresh&&(c.refresh=!1,g[r<<7|i]=!0)})}),["line"].indexOf(e.#O)>-1)for(;e.#_.length>0;){let a=e.#_.shift();g[a.part]=!0}e.#F(n,g),n.extraNotes.forEach(a=>{let{part:r,note:c,velo:i,state:s}=a,f=e.#f[r>>4][r&15].cxt;e.#L(f,c,i,s,e.device.getPitchShift(r))});let v=e.#w.cxt;l>n.bitmap.expire?e.#M.fill(0):n.bitmap.bitmap.length>256?n.bitmap.bitmap.forEach((a,r)=>{e.#M[r]=a?255:0}):n.bitmap.bitmap.forEach((a,r)=>{e.#M[r<<1]=a?255:0,e.#M[r<<1|1]=a?255:0}),e.#u.fill(0),l<=n.letter.expire&&e.glyphs.getStr(n.letter.text).forEach((a,r)=>{let c=(r&15)*5,i=r>>4<<3;a.forEach((s,f)=>{let o=c+f%5,h=i+Math.floor(f/5);e.#u[h*80+o]=s?255:0})}),e.#l.forEach((a,r,c)=>{let i=e.#M[r];i>a?c[r]+=Math.min(i-a,Z):i{let i=e.#u[r];i>a?c[r]+=Math.min(i-a,Z):i{let c=r>>5,i=r&31;e.#$[r]!=a?(v.clearRect(252+(i<<2),c<<2,3,3),a&&(v.fillStyle=`#ffffff${a.toString(16).padStart(2,"0")}`,v.fillRect(252+(i<<2),c<<2,3,3))):self.debugMode&&(v.clearRect(252+(i<<2),c<<2,3,3),a&&(v.fillStyle=`#ff0000${a.toString(16).padStart(2,"0")}`,v.fillRect(252+(i<<2),c<<2,3,3)))}),e.#i.forEach((a,r)=>{let c=Math.floor(r/80),i=r%80;i+=Math.floor(i/5),e.#o[r]!=a?(v.clearRect(i<<2,(c|16)<<2,3,3),a&&(v.fillStyle=`#ffffff${a.toString(16).padStart(2,"0")}`,v.fillRect(i<<2,(c|16)<<2,3,3))):self.debugMode&&(v.clearRect(i<<2,(c|16)<<2,3,3),a&&(v.fillStyle=`#ff0000${a.toString(16).padStart(2,"0")}`,v.fillRect(i<<2,(c|16)<<2,3,3)))}),e.#$.forEach((a,r,c)=>{c[r]=e.#l[r]}),e.#o.forEach((a,r,c)=>{c[r]=e.#i[r]})}#d;#G;get style(){return this.#O}set style(e){let t=this;t.#O=e,t.#F(t.render(t.#R?.currentTime||0)),I(t.#r,["cambiare-style-block","cambiare-style-comb","cambiare-style-piano","cambiare-style-line"]),X(t.#r,[`cambiare-style-${e}`])}setClockSource(e){this.#R=e}setPixelProfile(e){let t=this;if(Ke[e]){let n=Ke[e];t.#n=n,t.#r&&(t.#r.style.setProperty("--pcp-font4",`translate(${n.font4[1]}px, ${n.font4[0]}px)`),t.#r.style.setProperty("--pcp-font7",`translate(${n.font7[1]}px, ${n.font7[0]}px)`))}else throw new Error(`"${e}" is not a valid pixel correction profile`)}setMode(e){let t=this;I(t.#r,["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!="?"&&X(t.#r,[`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"}#V(e){let t=this,n=t.#e,l=t.#b;t.#f.forEach((d,p)=>{if(p>=l&&p{r.root.style.top=`${c*(n>2?26:52)}px`})}else I(d.root,["port-active"]),d.root.style.top="",d.root.style.left="",d.forEach((g,v)=>{g.root.style.top=""});e&&d.forEach((g,v)=>{g.cxt.canvas.width=t.#e==1?1193:495,g.cxt.canvas.height=t.#e==4?26:52})})}setPort(e){let t=this;I(t.#r,["cambiare-start0","cambiare-start1","cambiare-start2","cambiare-start3","cambiare-start4","cambiare-start5","cambiare-start6","cambiare-start7"]),X(t.#r,[`cambiare-start${e}`]),t.#b=e,t.#V(!1)}setRange(e){let t=this;I(t.#r,["cambiare-port1","cambiare-port2","cambiare-port4","cambiare-compact"]),X(t.#r,[`cambiare-${e}`]),t.#e=parseInt(e.slice(4))||1,t.#V(!0)}attach(e){let t=this;t.#B=e;let n=w("div",["cambiare-container"]);e.appendChild(n),t.#k=n;let l=w("div",["cambiare-canvas","cambiare-port1","cambiare-start0","cambiare-style-block"]);n.appendChild(l),t.#r=l,self.addEventListener("resize",t.#C),t.#C(),t.#G=setInterval(t.#d,20),t.#a.root=w("div",["sect-info"]),t.#a.events=w("span",["field","pcp-font4"],{t:1,l:0,w:35,h:33}),t.#a.curPoly=w("span",["field","pcp-font4"],{t:1,l:52,w:35,h:33}),t.#a.maxPoly=w("span",["field","pcp-font4"],{t:1,l:98,w:35,h:33}),t.#a.sigN=w("span",["field","pcp-font4"],{t:1,l:194,w:23,h:33,a:"right"}),t.#a.sigD=w("span",["field","pcp-font4"],{t:1,l:232,w:23,h:33}),t.#a.barCount=w("span",["field","pcp-font4"],{t:1,l:304,w:35,h:33,a:"right"}),t.#a.barDelim=w("span",["field","field-label","pcp-font4"],{t:0,l:343,w:8,h:33,i:"/"}),t.#a.barNote=w("span",["field","pcp-font4"],{t:1,l:354,w:23,h:33}),t.#a.tempo=w("span",["field","pcp-font4"],{t:1,l:454,w:64,h:33,a:"right"}),t.#a.volume=w("span",["field","pcp-font4"],{t:1,l:562,w:63,h:33,a:"right"}),t.#a.mode=w("span",["field","pcp-font4"],{t:1,l:708,w:152,h:33}),t.#a.reverb=w("span",["field","pcp-font4"],{t:1,l:1e3,w:190,h:33}),t.#a.chorus=w("span",["field","pcp-font4"],{t:1,l:1240,w:190,h:33}),t.#a.delay=w("span",["field","pcp-font4"],{t:1,l:1475,w:190,h:33}),t.#a.insert=w("span",["field","pcp-font4"],{t:1,l:1706,w:190,h:33}),t.#a.title=w("span",["field","pcp-font4"],{t:35,l:50,w:810,h:33}),l.appendChild(t.#a.root),C(t.#a.root,[t.#a.events,t.#a.curPoly,w("span",["field","field-label","pcp-font4"],{t:1,l:89,w:5,h:33,i:":"}),t.#a.maxPoly,w("span",["field","field-key","pcp-font7"],{t:1,l:148,w:41,h:33,i:"TSig"}),t.#a.sigN,w("span",["field","field-label","pcp-font4"],{t:0,l:221,w:8,h:33,i:"/"}),t.#a.sigD,w("span",["field","field-key","pcp-font7"],{t:1,l:268,w:30,h:33,i:"Bar"}),t.#a.barCount,t.#a.barDelim,t.#a.barNote,w("span",["field","field-key","pcp-font7"],{t:1,l:390,w:61,h:33,i:"Tempo",a:"right"}),t.#a.tempo,w("span",["field","field-key","pcp-font7"],{t:1,l:528,w:29,h:33,i:"Vol"}),t.#a.volume,w("span",["field","field-label","pcp-font4"],{t:1,l:626,w:17,h:33,i:"%"}),w("span",["field","field-key","pcp-font7"],{t:1,l:652,w:52,h:33,i:"Mode"}),t.#a.mode,w("span",["field","field-key","pcp-font7"],{t:1,l:960,w:34,h:33,i:"Rev"}),t.#a.reverb,w("span",["field","field-key","pcp-font7"],{t:1,l:1198,w:36,h:33,i:"Cho"}),t.#a.chorus,w("span",["field","field-key","pcp-font7"],{t:1,l:1438,w:31,h:33,i:"Var"}),t.#a.delay,w("span",["field","field-key","pcp-font7"],{t:1,l:1673,w:27,h:33,i:"Ins"}),t.#a.insert,w("span",["field","field-key","pcp-font7"],{t:35,l:0,w:44,h:33,i:"Title"}),t.#a.title]),t.#g.root=w("div",["sect-mark"]),t.#g.left=w("div",["sect-mark-left","boundary"],{t:0,l:0}),t.#g.right=w("div",["sect-mark-right","boundary"],{t:0,l:960}),l.appendChild(t.#g.root),C(t.#g.root,[t.#g.left,t.#g.right]),C(t.#g.left,[w("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),w("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),w("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),w("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),w("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),w("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),C(t.#g.right,[w("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),w("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),w("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),w("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),w("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),w("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),t.#f.root=w("div",["sect-part"]);for(let d=0;d>4;d++){let p=d<<4;t.#f[d]=[],t.#f[d].root=w("div",["boundary",`part-port-${d}`]);for(let g=0;g<16;g++){let v=(p|g)+1;v>=100?v=`${Math.floor(v/10).toString(16)}${v%10}`:v=`${v}`.padStart(2,"0"),t.#f[d][g]={root:w("div",["boundary","part-channel"]),major:w("div",["boundary","part-info-major"]),minor:w("div",["boundary","part-info-minor"],{t:26}),keys:w("div",["boundary","part-keys"]),notes:w("div",["boundary","part-keyboard"]),cxt:w("canvas",["field"]).getContext("2d"),number:w("span",["field","field-label","pcp-font4"],{t:1,w:18,h:25,i:v}),voice:w("span",["field"],{l:22,t:1,w:121,h:25}),metre:w("canvas",["field"]).getContext("2d"),type:w("span",["field","field-label","pcp-font4"],{t:1,w:18,h:25}),std:w("span",["field","pcp-font4"],{l:22,t:1,w:20,h:25,a:"center"}),msb:w("span",["field","pcp-font4"],{l:48,t:1,w:27,h:25}),prg:w("span",["field","pcp-font4"],{l:81,t:1,w:27,h:25}),lsb:w("span",["field","pcp-font4"],{l:114,t:1,w:27,h:25}),cc:R("svg",{viewBox:"0 0 108 24",width:108,style:"left: 146px; top: 1px; position: absolute;"}),vol:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:0}),exp:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:6}),mod:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:12}),rev:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:18}),cho:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:24}),var:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:30}),brt:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:36}),por:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:42}),cea:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:48}),ceb:R("rect",{fill:"var(--accent-color)",width:4,height:24,x:54}),pan:R("rect",{fill:"var(--accent-color)",width:0,height:24,x:84}),extVis:w("canvas",["field"],{l:207,t:1}).getContext("2d")};let a=t.#f[d][g];We.forEach(r=>{a.notes.appendChild(w("span",["field","part-csplit"],{l:r}))}),a.notes.appendChild(w("span",["field","part-csplit","part-cdive"],{l:0,w:"100%",h:1})),a.metre.canvas.width=121,a.metre.canvas.height=25,a.metre.fillStyle="#fff",a.metre.textBaseline="top",a.metre.font="20px 'PT Sans Narrow'",a.extVis.canvas.width=47,a.extVis.canvas.height=25,a.extVis.fillStyle="#fff",C(a.notes,[a.cxt.canvas]),C(a.keys,[a.notes]),C(a.voice,[a.metre.canvas]),C(a.cc,[a.vol,a.exp,a.mod,a.rev,a.cho,a.var,a.brt,a.por,a.cea,a.ceb,a.pan,R("rect",{x:83,y:0,width:1,height:24,fill:"var(--foreground-color)"})]),C(a.major,[a.number,a.voice,a.cc]),C(a.minor,[a.type,a.std,a.msb,a.prg,a.lsb,a.extVis.canvas]),C(a.root,[a.major,a.minor,a.keys]),C(t.#f[d].root,[a.root])}t.#f.root.appendChild(t.#f[d].root)}l.appendChild(t.#f.root),t.#E.root=w("div",["sect-meta"]),t.#E.view=w("div",["boundary"]),l.appendChild(t.#E.root),C(t.#E.root,[t.#E.view]),t.#w.root=w("div",["sect-pix","boundary"],{l:1529,t:950,w:379,h:127}),t.#w.cxt=w("canvas",["field"]).getContext("2d"),t.#w.cxt.canvas.width=379,t.#w.cxt.canvas.height=127,C(t.#w.root,[t.#w.cxt.canvas]),l.appendChild(t.#w.root),t.addEventListener("mode",d=>{t.#a.mode.innerText=`${yt[d.data]}`,t.setMode(d.data)}),t.addEventListener("mastervolume",d=>{let p=Math.round(d.data*100)/100;t.#a.volume.innerText=`${Math.floor(p)}.${`${Math.floor(p%1*100)}`.padStart(2,"0")}`}),t.addEventListener("tempo",d=>{let p=Math.round(d.data*100);t.#a.tempo.innerText=`${Math.floor(p/100)}.${`${Math.floor(p%100)}`.padStart(2,"0")}`}),t.addEventListener("tsig",d=>{[t.#a.sigN.innerText,t.#a.sigD.innerText]=d.data}),t.addEventListener("title",d=>{t.#a.title.innerText=d.data||"No Title"}),t.addEventListener("voice",({data:d})=>{let p=t.getChVoice(d.part),g=t.#f[d.part>>4][d.part&15];ze(g.metre,t.getMapped(p.name)),g.type.innerText=gt[t.device.getChType()[d.part]],g.std.innerText=p.standard,g.msb.innerText=`${p.sid[0]}`.padStart(3,"0"),g.prg.innerText=`${p.sid[1]}`.padStart(3,"0"),g.lsb.innerText=`${p.sid[2]}`.padStart(3,"0")}),t.addEventListener("pitch",d=>{let{part:p,pitch:g}=d.data;t.#f[p>>4][p&15].notes.style.transform=`translateX(${g/1.28}%)`}),t.addEventListener("efxreverb",d=>{t.#a.reverb.innerText=t.getEfx(d.data)}),t.addEventListener("efxchorus",d=>{t.#a.chorus.innerText=t.getEfx(d.data)}),t.addEventListener("efxdelay",d=>{t.#a.delay.innerText=t.getEfx(d.data)}),t.addEventListener("efxinsert0",d=>{t.#a.insert.innerText=t.getEfx(d.data)}),t.addEventListener("partefxtoggle",d=>{let{part:p,active:g}=d.data;[I,X][g](t.#f[p>>4][p&15].number,["part-efx"])}),t.addEventListener("channeltoggle",d=>{let{part:p,active:g}=d.data;[I,X][g](t.#f[p>>4][p&15].root,["part-active"])}),t.addEventListener("metacommit",d=>{let p=d.data;if(t.#p&&p.type==t.#T&&t.#c)switch(p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{C(t.#c,[w("span",["meta-slice"],{i:p.data})]);break}default:t.#c.childNodes[0].data+=p.data}else if(p.data?.length&&Et.indexOf(p.type)==-1){let g=w("div",["meta-line"]),v=w("span",["field","field-key","meta-type"],{i:vt[p.type]||p.type});switch(p.mask&&(v.style.display="none"),p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{t.#c=w("span",["field","meta-data"]),C(t.#c,[w("span",["meta-slice"],{i:p.data})]);break}default:t.#c=w("span",["field","meta-data"],{i:p.data})}for(t.#E.view.appendChild(g),C(g,[v,t.#c]);t.#E.view.children.length>t.#t;)t.#E.view.children[0].remove()}t.#p=p.amend||!1,t.#T=p.type||"",t.#U()}),t.#E.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.#V(!0)}detach(e){let t=this;self.removeEventListener("resize",t.#C),t.#r.remove(),t.#r=void 0,t.#k.remove(),t.#k=void 0,t.#B=void 0,clearInterval(t.#G)}constructor(e,t){super(new Ne,.1,.75);let n=this;n.#C=n.#H.bind(this),n.#d=n.#m.bind(this),e&&n.attach(e),t&&n.setClockSource(t),n.setPixelProfile("none"),n.addEventListener("reset",()=>{n.#s=0,n.#p=!1,n.#T="",n.#c=null;try{let l=n.#E.view.children;for(let d=l.length-1;d>=0;d--)l[d].remove();n.#E.view.style.transform="translateX(0px) translateY(140px)";for(let d=0;d>4][d&15];I(p.root,["part-active"]),I(p.number,["part-efx"]),ze(p.metre,""),p.type.innerText="",p.std.innerText="",p.msb.innerText="",p.prg.innerText="",p.lsb.innerText="",p.notes.style.transform=""}}catch{}}),n.addEventListener("pitch",({data:l})=>{n.#_.push(l)})}};export{ma as Cambiare}; diff --git a/dist/state.mjs b/dist/state.mjs index 823c74c3..e4ceaf22 100644 --- a/dist/state.mjs +++ b/dist/state.mjs @@ -1,8 +1,8 @@ -var Q=function(e,r){let d=Math.min(e.length,r.length),p=e.slice(0,d),b=r.slice(0,d),E=0,g=0;for(;g0){let p=this.pool.length,b=1<=1&&g>=0;){if(g<=0)throw new Error("TTL reached.");if(E==p)E-=b;else{let t=Q(r,this.pool[E]);switch(t){case 0:{g=0;break}case 1:{E+b<=p&&(E+=b);break}case-1:{E!=0&&(E-=b);break}default:console.warn(`Unexpected result ${t}.`)}}b=b>>1,g--}let $=!0;if(E>=this.pool.length)$=!1;else{let t=this;this.pool[E].forEach(function(a,c,i){$&&a!=r[c]&&($=!1)}),!$&&Q(r,this.pool[E])>0&&E++}return $||d?E:-1}else return d?0:-1},this.add=function(r,d){return r.data=d,this.pool.splice(this.point(r,!0),0,r),this},this.default=function(r){console.warn(`No match in "${this.name||"(unknown)"}" for "${r}". Default action not defined.`)},this.get=function(r){let d=this.point(r);if(d>-1)return this.pool[d].data;this.default(r)},this.run=function(r,...d){let p=this.point(r);p>-1?r.subarray?this.pool[p].data(r.subarray(this.pool[p].length),...d):this.pool[p].data(r.slice(this.pool[p].length),...d):this.default(r,...d)}};var Y=class{#t={};addEventListener(e,r){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(r)}removeEventListener(e,r){if(this.#t[e]){let d=this.#t[e].indexOf(r);d>-1&&this.#t[e].splice(d,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,r){let d=new Event(e),p=this;d.data=r,this.#t[e]?.length>0&&this.#t[e].forEach(function(b){try{b?.call(p,d)}catch(E){console.error(E)}}),this[`on${e}`]&&this[`on${e}`](d)}};var be=["MSB","PRG","LSB","NME","ELC","DRM"],I=function(e){let r=Math.floor(e/10),d=e%10;return`${r.toString(16)}${d}`},X=class{#t;strictMode=!1;get(e=0,r=0,d=0,p){let b=[e,r,d],E,g=1,$=0,t,a=Array.from(arguments);switch(p){case"xg":{switch(e){case 0:{d==126?a[2]=125:d==127&&(a[2]=0);break}case 16:{d==126&&(a[2]=0);break}case 32:{d>125&&(a[2]=0),a[2]+=4;break}case 33:case 34:case 35:case 36:{d>125&&(a[2]=0),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:{d==126&&(a[2]=0);break}case 48:case 64:case 126:case 127:{d==126&&(a[2]=0);break}}break}case"gs":{e==0&&d<5?a[2]=0:e>125&&d<5&&d!=2&&(a[2]=e,a[0]=0);break}case"g2":case"sd":{e>>1==40?a[2]|=16:e>95&&e<100&&(a[2]|=16,r>>3==15&&(a[0]=96));break}case"sg":{e==8&&d==0&&(a[2]=5);break}case"s90es":{d<8?a[2]+=17:d<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}case"motif":{d<8?a[2]+=28:d<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}}let c=" ",i="M",s=0,f=0;switch(a[0]){case 0:{a[2]==127?i="MT-a":a[2]==126?i="MT-b":a[2]==7?i="GM-k":a[2]==5?i="SG-a":a[2]==4?i="SP-l":a[2]==0||p=="gs"&&a[2]<5?i="GM-a":(i="y",s=3);break}case 8:{p=="sg"?i="GM-s":i="r:";break}case 32:case 33:case 34:case 35:case 36:{p=="xg"&&(i=`${["AP","VL","PF","DX","AN"][e&7]}-${"abcdefgh"[d]}`);break}case 48:{i=`yM${(a[2]>>3).toString().padStart(2,"0")}`,s=1;break}case 56:{i="GM-b";break}case 61:case 120:{i="rDrm";break}case 62:{i="kDrm";break}case 63:{if(a[2]<17){let y=a[2];i=y<10?"kP:":"kC:",i+=y%10}else a[2]<34?i=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][a[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"[a[0]-80]}`;break}case 88:case 89:case 90:case 91:{i=`Cmb${"UABC"[a[0]-88]}`;break}case 95:{i=`${["DR","PC"][a[2]]}-d`;break}case 96:{i=a[2]==106?"AP-a":a[2]>>4==1?"SDg":"PF",a[2]>63?f=63:a[2]>>4==1&&(f=16),s=3;break}case 97:{i=a[2]>>4==1?"SDa":"VL:",s=3,a[2]>>4==1?f=16:f=112;break}case 98:{i=a[2]>>4==1?"SDb":"SG-a",s=3,f=16;break}case 99:{i=a[2]>>4==1?"SDc":"DX",a[2]>63?f=63:a[2]>>4==1&&(f=16),s=3;break}case 100:{i="AN",a[2]>63?f=63:a[2]>>4==1&&(f=16),s=3;break}case 104:case 105:case 106:case 107:{i="SDd",f=104;break}case 121:{i=`GM-${a[2]?"":"a"}`,s=3;break}case 122:{i="lDrm";break}case 126:{i="yDrS";break}case 127:{a[2]==127?i="rDrm":i="yDrm";break}default:a[0]<48?i="r:":i="M"}i.length<4&&(i+=`${[e,d,a[0],a[2]][s]-f}`.padStart(4-i.length,"0")),p=="xg"&&(e==0?a[2]<100?i=i.replace("y0","y:"):a[2]==125&&(i="y126"):e==16&&(E=`Voice${(a[2]*128+a[1]+1).toString().padStart(3,"0")}`,c=" "));let o=[a[0],a[1],a[2]];for(;!(E?.length>=0);)if(E=this.#t[a[1]||0][(a[0]<<7)+a[2]]?.name,E){let y=this.#t[a[1]||0][(a[0]<<7)+a[2]];g=y?.poly||g,$=y?.type||$,t=y?.drum}else if(this.strictMode)E="",c="?";else if(a[0]==0&&a[1]==0&&a[2]==0)E="Unloaded";else if(this.#t[a[1]||0][a[0]<<7])a[0]==0?(a[2]=0,c="^"):a[2]<1?(a[0]=0,c="*"):(a[2]--,c="^");else if(e==48)a[0]=0,a[2]=0,c="!";else if(e==62)a[1]--,c=" ",a[1]<1&&!E?.length&&(a[0]=0,c="!");else if(e<63)a[0]==0?(a[2]=0,c="^"):a[2]<1?(a[0]=0,c="*"):a[2]--;else if(e==80)E=`PrgU:${r.toString().padStart(3,"0")}`,c="!";else if(e==88)E=`CmbU:${r.toString().padStart(3,"0")}`,c="!";else if(e==121)E=`GM2Vox0${d}`,c="#";else if(e==122)if(a[1]==32?a[1]==0:a[1]%=7,E=this.#t[a[1]||0][(a[0]<<7)+a[2]]?.name,E){c=" ";let y=this.#t[a[1]||0][(a[0]<<7)+a[2]];g=y?.poly||g,$=y?.type||$,t=y?.drum}else E="",c="*";else a[1]==0?(E=`${e.toString().padStart(3,"0")} ${r.toString().padStart(3,"0")} ${d.toString().padStart(3,"0")}`,c="!"):a[0]==0?(a[2]=0,c="^"):a[2]>0?a[2]--:a[1]>0?(a[1]=0,c="!"):(a[0]=0,c="?");let n=[a[0],a[1],a[2]];(p=="gs"||p=="ns5r")&&c=="^"&&(c=" "),e==127&&c=="^"&&(c=" "),c!=" "&&self.debugMode&&(E="");let l="??";switch(a[0]){case 0:{a[2]==0?l="GM":a[2]==5||a[2]==7?l="KG":a[2]<126?l="XG":a[2]==127&&(l="MT");break}case 32:case 33:case 35:case 36:{a[2]>4?l=["AP","VL","PF","DX","AN"][a[0]-32]:l="GS";break}case 48:{l="MU";break}case 56:{l="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{l="AI";break}case 62:case 82:case 90:{l="XD";break}case 63:{a[2]<17?l="KR":a[2]<34?l="ES":l="DS";break}case 64:case 126:{l="XG";break}case 67:case 99:{l=a[2]>>4==1?"SD":"DX";break}case 81:{l="RW";break}case 95:{l=["DR","PC"][a[2]];break}case 96:{l=a[2]==106?"AP":a[2]>>4==1?"SD":"PF";break}case 97:{l=a[2]>>4==1?"SD":"VL";break}case 98:{l=a[2]>>4==1?"SD":"SG";break}case 100:{l="AN";break}case 104:case 105:case 106:case 107:{l="SD";break}case 120:{l="GS";break}case 121:{l=a[2]?"G2":"GM";break}case 122:{l="KG";break}case 127:{l=a[2]==127?"MT":r==0?"GM":"XG";break}default:a[0]<48&&(a[0]==16&&p=="xg"?l="XG":l="GS")}return{name:E||`${I(e||0)} ${I(r||0)} ${I(d||0)}`,poly:g,type:$,drum:t,iid:o,eid:n,sid:b,ending:c,sect:i,standard:l}}async load(e,r,d="(internal)"){let p=this,b=[],E=0,g=0;e.split(` -`).forEach(function($,t){let a=$.split(" "),c=[];if(t==0){if(a.forEach(function(i,s){b[be.indexOf(i)]=s}),b.length<4){console.debug("Debugger launched.");debugger}}else{let i=0,s=0,f=0,o,n=1,l=0,y;a.forEach(async function(w,S){switch(S){case b[0]:{i=parseInt(w);break}case b[1]:{s=parseInt(w);break}case b[2]:{f=parseInt(w);break}case b[3]:{o=w;break}case b[4]:{w=parseInt(w),w<16?n=w+1:l=(w&15)+1;break}case b[5]:{y=w;break}}}),p.#t[s]=p.#t[s]||[];let m=p.#t[s];if(!m[i<<7|f]||r){let w={msb:i,prg:s,lsb:f,name:o,poly:n,type:l,drum:y};m[i<<7|f]=w,E++}g++}}),r||console.debug(`Map "${d}": ${g} total, ${E} loaded.`)}clearRange(e){let r=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],d=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],p=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let b=d[0];b<=d[1];b++){let E=b<<7;for(let g=p[0];g<=p[1];g++){let $=E+g;for(let t=r[0];t<=r[1];t++)delete this.#t[t][$]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let r=this;e.forEach(async function(d){try{await fetch(`./data/bank/${d}.tsv`).then(function(p){return p.text()}).then(p=>{r.load(p,!1,d)})}catch{console.error(`Failed loading "${d}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var W=class{#t={};context;set(e,r){this.#t[e]=r}has(e){return!!this.#t[e]}async read(e,r){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,r)}};var ye=function(e,r){let d=!0;return r.forEach((p,b)=>{d=d&&e[b]==p}),d},j=function(e){let r=0;return e.forEach(d=>{r*=256,r+=d}),r},A=new TextDecoder,B=new W;B.set("s7e",async function(e){let r=new Uint8Array(await e.slice(0,65536).arrayBuffer()),d="MSB LSB PRG NME",p=[0,0,0,0],b=32,E=0,g=0,$=!0,t=[],a=0;for(;$;){let c=r.subarray(E);([()=>{A.decode(c.subarray(0,4))=="YSFC"?(E+=80,g=1):E++},()=>{if(ye(c.subarray(0,4),p))t.forEach((i,s,f)=>{let o=j(r.subarray(i.start+4,i.start+8));i.length=o}),g=2;else{let i=A.decode(c.subarray(0,4)),s=j(c.subarray(4,8));t.push({type:i,start:s}),E+=8}},()=>{let i=t[a],s=r.subarray(i.start,i.start+i.length),f=32;switch(i.type){case"ENVC":{let o=b;for(;o=t.length&&(g=3,$=!1)}][g]||(()=>{$=!1}))()}return d});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"]),N=["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"],ge=[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],L=[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],J=[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],Z=function(e){let r=.1,d=-.3;return e>66?(r=5,d=315):e>56?(r=1,d=47):e>46&&(r=.5,d=18.5),r*e-d},ee=function(e){return e>105?ge[e-106]:e>100?e*1.1-100:e/10},te=",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 Q=function(e,r){let d=Math.min(e.length,r.length),p=e.slice(0,d),b=r.slice(0,d),E=0,$=0;for(;$0){let p=this.pool.length,b=1<=1&&$>=0;){if($<=0)throw new Error("TTL reached.");if(E==p)E-=b;else{let t=Q(r,this.pool[E]);switch(t){case 0:{$=0;break}case 1:{E+b<=p&&(E+=b);break}case-1:{E!=0&&(E-=b);break}default:console.warn(`Unexpected result ${t}.`)}}b=b>>1,$--}let g=!0;if(E>=this.pool.length)g=!1;else{let t=this;this.pool[E].forEach(function(a,c,i){g&&a!=r[c]&&(g=!1)}),!g&&Q(r,this.pool[E])>0&&E++}return g||d?E:-1}else return d?0:-1},this.add=function(r,d){return r.data=d,this.pool.splice(this.point(r,!0),0,r),this},this.default=function(r){console.warn(`No match in "${this.name||"(unknown)"}" for "${r}". Default action not defined.`)},this.get=function(r){let d=this.point(r);if(d>-1)return this.pool[d].data;this.default(r)},this.run=function(r,...d){let p=this.point(r);p>-1?r.subarray?this.pool[p].data(r.subarray(this.pool[p].length),...d):this.pool[p].data(r.slice(this.pool[p].length),...d):this.default(r,...d)}};var Y=class{#t={};addEventListener(e,r){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(r)}removeEventListener(e,r){if(this.#t[e]){let d=this.#t[e].indexOf(r);d>-1&&this.#t[e].splice(d,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,r){let d=new Event(e),p=this;d.data=r,this.#t[e]?.length>0&&this.#t[e].forEach(function(b){try{b?.call(p,d)}catch(E){console.error(E)}}),this[`on${e}`]&&this[`on${e}`](d)}};var be=["MSB","PRG","LSB","NME","ELC","DRM"],I=function(e){let r=Math.floor(e/10),d=e%10;return`${r.toString(16)}${d}`},X=class{#t;strictMode=!1;get(e=0,r=0,d=0,p){let b=[e,r,d],E,$=1,g=0,t,a=Array.from(arguments);switch(p){case"xg":{switch(e){case 0:{d==126?a[2]=125:d==127&&(a[2]=0);break}case 16:{d==126&&(a[2]=0);break}case 32:{d>125&&(a[2]=0),a[2]+=4;break}case 33:case 34:case 35:case 36:{d>125&&(a[2]=0),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:{d==126&&(a[2]=0);break}case 48:case 64:case 126:case 127:{d==126&&(a[2]=0);break}}break}case"gs":{e==0&&d<5?a[2]=0:e>125&&d<5&&d!=2&&(a[2]=e,a[0]=0);break}case"g2":case"sd":{e>>1==40?a[2]|=16:e>95&&e<100&&(a[2]|=16,r>>3==15&&(a[0]=96));break}case"sg":{e==8&&d==0&&(a[2]=5);break}case"s90es":{d<8?a[2]+=17:d<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}case"motif":{d<8?a[2]+=28:d<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}}let c=" ",i="M",s=0,f=0;switch(a[0]){case 0:{a[2]==127?i="MT-a":a[2]==126?i="MT-b":a[2]==7?i="GM-k":a[2]==5?i="SG-a":a[2]==4?i="SP-l":a[2]==0||p=="gs"&&a[2]<5?i="GM-a":(i="y",s=3);break}case 8:{p=="sg"?i="GM-s":i="r:";break}case 32:case 33:case 34:case 35:case 36:{p=="xg"&&(i=`${["AP","VL","PF","DX","AN"][e&7]}-${"abcdefgh"[d]}`);break}case 48:{i=`yM${(a[2]>>3).toString().padStart(2,"0")}`,s=1;break}case 56:{i="GM-b";break}case 61:case 120:{i="rDrm";break}case 62:{i="kDrm";break}case 63:{if(a[2]<17){let y=a[2];i=y<10?"kP:":"kC:",i+=y%10}else a[2]<34?i=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][a[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"[a[0]-80]}`;break}case 88:case 89:case 90:case 91:{i=`Cmb${"UABC"[a[0]-88]}`;break}case 95:{i=`${["DR","PC"][a[2]]}-d`;break}case 96:{i=a[2]==106?"AP-a":a[2]>>4==1?"SDg":"PF",a[2]>63?f=63:a[2]>>4==1&&(f=16),s=3;break}case 97:{i=a[2]>>4==1?"SDa":"VL:",s=3,a[2]>>4==1?f=16:f=112;break}case 98:{i=a[2]>>4==1?"SDb":"SG-a",s=3,f=16;break}case 99:{i=a[2]>>4==1?"SDc":"DX",a[2]>63?f=63:a[2]>>4==1&&(f=16),s=3;break}case 100:{i="AN",a[2]>63?f=63:a[2]>>4==1&&(f=16),s=3;break}case 104:case 105:case 106:case 107:{i="SDd",f=104;break}case 121:{i=`GM-${a[2]?"":"a"}`,s=3;break}case 122:{i="lDrm";break}case 126:{i="yDrS";break}case 127:{a[2]==127?i="rDrm":i="yDrm";break}default:a[0]<48?i="r:":i="M"}i.length<4&&(i+=`${[e,d,a[0],a[2]][s]-f}`.padStart(4-i.length,"0")),p=="xg"&&(e==0?a[2]<100?i=i.replace("y0","y:"):a[2]==125&&(i="y126"):e==16?(E=`Voice${((a[2]<<7)+a[1]+1).toString().padStart(3,"0")}`,c=" "):e==35&&d>>1==2&&(E=`DXCH_${(((a[2]&1)<<7)+r+1).toString().padStart(3,"0")}`,c=" "));let o=[a[0],a[1],a[2]];for(;!(E?.length>=0);)if(E=this.#t[a[1]||0][(a[0]<<7)+a[2]]?.name,E){let y=this.#t[a[1]||0][(a[0]<<7)+a[2]];$=y?.poly||$,g=y?.type||g,t=y?.drum}else if(this.strictMode)E="",c="?";else if(a[0]==0&&a[1]==0&&a[2]==0)E="Unloaded";else if(this.#t[a[1]||0][a[0]<<7])a[0]==0?(a[2]=0,c="^"):a[2]<1?(a[0]=0,c="*"):(a[2]--,c="^");else if(e==48)a[0]=0,a[2]=0,c="!";else if(e==62)a[1]--,c=" ",a[1]<1&&!E?.length&&(a[0]=0,c="!");else if(e<63)a[0]==0?(a[2]=0,c="^"):a[2]<1?(a[0]=0,c="*"):a[2]--;else if(e==80)E=`PrgU:${r.toString().padStart(3,"0")}`,c="!";else if(e==88)E=`CmbU:${r.toString().padStart(3,"0")}`,c="!";else if(e==121)E=`GM2Vox0${d}`,c="#";else if(e==122)if(a[1]==32?a[1]==0:a[1]%=7,E=this.#t[a[1]||0][(a[0]<<7)+a[2]]?.name,E){c=" ";let y=this.#t[a[1]||0][(a[0]<<7)+a[2]];$=y?.poly||$,g=y?.type||g,t=y?.drum}else E="",c="*";else a[1]==0?(E=`${e.toString().padStart(3,"0")} ${r.toString().padStart(3,"0")} ${d.toString().padStart(3,"0")}`,c="!"):a[0]==0?(a[2]=0,c="^"):a[2]>0?a[2]--:a[1]>0?(a[1]=0,c="!"):(a[0]=0,c="?");let n=[a[0],a[1],a[2]];(p=="gs"||p=="ns5r")&&c=="^"&&(c=" "),e==127&&c=="^"&&(c=" "),c!=" "&&self.debugMode&&(E="");let l="??";switch(a[0]){case 0:{a[2]==0?l="GM":a[2]==5||a[2]==7?l="KG":a[2]<126?l="XG":a[2]==127&&(l="MT");break}case 32:case 33:case 35:case 36:{a[2]>4?l=["AP","VL","PF","DX","AN"][a[0]-32]:l="GS";break}case 48:{l="MU";break}case 56:{l="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{l="AI";break}case 62:case 82:case 90:{l="XD";break}case 63:{a[2]<17?l="KR":a[2]<34?l="ES":l="DS";break}case 64:case 126:{l="XG";break}case 67:case 99:{l=a[2]>>4==1?"SD":"DX";break}case 81:{l="RW";break}case 95:{l=["DR","PC"][a[2]];break}case 96:{l=a[2]==106?"AP":a[2]>>4==1?"SD":"PF";break}case 97:{l=a[2]>>4==1?"SD":"VL";break}case 98:{l=a[2]>>4==1?"SD":"SG";break}case 100:{l="AN";break}case 104:case 105:case 106:case 107:{l="SD";break}case 120:{l="GS";break}case 121:{l=a[2]?"G2":"GM";break}case 122:{l="KG";break}case 127:{l=a[2]==127?"MT":r==0?"GM":"XG";break}default:a[0]<48&&(a[0]==16&&p=="xg"?l="XG":l="GS")}return{name:E||`${I(e||0)} ${I(r||0)} ${I(d||0)}`,poly:$,type:g,drum:t,iid:o,eid:n,sid:b,ending:c,sect:i,standard:l}}async load(e,r,d="(internal)"){let p=this,b=[],E=0,$=0;e.split(` +`).forEach(function(g,t){let a=g.split(" "),c=[];if(t==0){if(a.forEach(function(i,s){b[be.indexOf(i)]=s}),b.length<4){console.debug("Debugger launched.");debugger}}else{let i=0,s=0,f=0,o,n=1,l=0,y;a.forEach(async function(v,x){switch(x){case b[0]:{i=parseInt(v);break}case b[1]:{s=parseInt(v);break}case b[2]:{f=parseInt(v);break}case b[3]:{o=v;break}case b[4]:{v=parseInt(v),v<16?n=v+1:l=(v&15)+1;break}case b[5]:{y=v;break}}}),p.#t[s]=p.#t[s]||[];let m=p.#t[s];if(!m[i<<7|f]||r){let v={msb:i,prg:s,lsb:f,name:o,poly:n,type:l,drum:y};m[i<<7|f]=v,E++}$++}}),r||console.debug(`Map "${d}": ${$} total, ${E} loaded.`)}clearRange(e){let r=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],d=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],p=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let b=d[0];b<=d[1];b++){let E=b<<7;for(let $=p[0];$<=p[1];$++){let g=E+$;for(let t=r[0];t<=r[1];t++)delete this.#t[t][g]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let r=this;e.forEach(async function(d){try{await fetch(`./data/bank/${d}.tsv`).then(function(p){return p.text()}).then(p=>{r.load(p,!1,d)})}catch{console.error(`Failed loading "${d}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var W=class{#t={};context;set(e,r){this.#t[e]=r}has(e){return!!this.#t[e]}async read(e,r){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,r)}};var ye=function(e,r){let d=!0;return r.forEach((p,b)=>{d=d&&e[b]==p}),d},j=function(e){let r=0;return e.forEach(d=>{r*=256,r+=d}),r},L=new TextDecoder,G=new W;G.set("s7e",async function(e){let r=new Uint8Array(await e.slice(0,65536).arrayBuffer()),d="MSB LSB PRG NME",p=[0,0,0,0],b=32,E=0,$=0,g=!0,t=[],a=0;for(;g;){let c=r.subarray(E);([()=>{L.decode(c.subarray(0,4))=="YSFC"?(E+=80,$=1):E++},()=>{if(ye(c.subarray(0,4),p))t.forEach((i,s,f)=>{let o=j(r.subarray(i.start+4,i.start+8));i.length=o}),$=2;else{let i=L.decode(c.subarray(0,4)),s=j(c.subarray(4,8));t.push({type:i,start:s}),E+=8}},()=>{let i=t[a],s=r.subarray(i.start,i.start+i.length),f=32;switch(i.type){case"ENVC":{let o=b;for(;o=t.length&&($=3,g=!1)}][$]||(()=>{g=!1}))()}return d});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"]),N=["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"],Ee=[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],A=[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],J=[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],Z=function(e){let r=.1,d=-.3;return e>66?(r=5,d=315):e>56?(r=1,d=47):e>46&&(r=.5,d=18.5),r*e-d},ee=function(e){return e>105?Ee[e-106]:e>100?e*1.1-100:e/10},te=",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*, ka,か ki,き ku,く @@ -139,8 +139,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let r=e.split(",");V[r[0]]=r[1]});var ae=function(e){let r=e;e[0]=="*"&&(r=r.slice(1)),["aa","ii","uu","ee","oo"].forEach(p=>{for(;r.indexOf(p)>-1;)r=r.replace(p,p[0])});for(let p in V)r=r.replaceAll(p,V[p]);r.indexOf("ん")==0&&r.length>1&&(r=r.slice(1));let d=r.indexOf("!");return d>-1&&r.length>1&&(r=r.slice(d+1)),r},re=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var F=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],se=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ie=["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 Ee={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"},$e={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]]},K=function(e){return Ee[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ce=function(e,r,d){let p=(e[0]-32<<16)+(e[1]<<8)+r,b=$e[p]||{},E=b[0];if(E?.length)return E+=`: ${(b[1]||function(){})(d)||d}`,E},z=[68,48,95,78,41,3,110,122,0];var x=function(e=64){return Math.round(2e3*Math.log10(e/64))/100};var D=function(e){let r=0;return e.forEach(d=>{r+=d,r=r&127}),~r+1&127},M=function(e,r){let d=0,p=0;for(let b=0;b>E&1)<<7,$=e[b];$+=g,b%8!=0?(r($,d,e),d++):p=e[b]}};var P=function(e){let r=Math.floor(e*14.2);return r<128?r:0};var R=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],me={gm2:"g2","mt-32":"mt32","c/m":"mt32",ag10:"05rw","ag-10":"05rw","05r/w":"05rw",x5:"05rw",x5dr:"x5d",gmega:"k11","kross 2":"krs","motif es":"motif","s90 es":"s90es"},ke=["melodic","drum","menu"],ne=[[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]],O=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],we=[0,3,81,84,88],oe={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},le={0:0,1:1,2:3,5:4},fe={0:0,1:1,2:2,5:3},de=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],he=[36,37,48,49,52,53],_=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],ue={26:127,29:0,30:0,31:0,52:12,53:54},G=[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,14,15,20,21,26,28,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157],ve=[2,12,13,14,15,16,17,18,19,20,21,136,130,131,132,133,134,135,137,138,139],Se=[33,99,100,32,102,8,9,10],pe=[0,16,25,40,32,64,26,48],k={};R.forEach((e,r)=>{k[e]=r});var h={length:G.length};G.forEach((e,r)=>{h[e]=r});var T={length:_.length};_.forEach((e,r)=>{T[e]=r});var xe={};ke.forEach((e,r)=>{xe[e]=r});var v=function(){return!!self.Bun||self.debugMode||!1},Ce=function(e){let r=[],d=0;return e?.forEach(function(p,b){p==247?r.push(e.subarray(d,b)):p==240&&(d=b+1)}),r.length||r.push(e.subarray(0)),v()&&console.debug(r),r};var u={ch:128,cc:G.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:_.length,dnc:128,ext:2,efx:7,redir:32},H={bank0:128},Je=class extends Y{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;EXT_NONE=0;EXT_VL=1;VLBC_BRTHEXPR=1;VLBC_VELOINIT=2;VLBC_VELOALL=3;#t=0;#b=0;#C=0;#D=new Array(11);get#g(){return this.#D[this.#b]}set#g(e){this.#D[this.#b]=e}#O=new Uint8Array(u.ch);#h=new Uint8Array(u.ch);#r=new Uint8Array(u.ch);#e=new Uint8Array(u.ch*u.cc);#L=new Uint8Array(u.ace);#i=new Uint8Array(u.ch);#f=new Uint8Array(u.ch*u.nn);#E=new Uint8Array(u.ch);#d=new Uint16Array(u.pl);#u=new Uint8Array(u.pl);#A=new Int16Array(u.ch);#T=new Uint8Array(u.ch);#X=0;#M=new Uint8Array(u.ch*u.ext);#a=new Uint8Array(u.ch*u.rpn);#s=new Uint8Array(u.ch*u.rpnt);#J=new Int8Array(u.ch*he.length);#y=new Uint8Array(u.drm*u.dpn*u.dnc);#$=new Uint8Array(u.efx*3);#Z=new Uint8Array(u.ch);#V=new Uint8Array(u.ch*u.redir);#R=new Uint8Array(u.ch);#P=new Uint8Array(128);#S=new Uint8Array(u.cmt*8);#ee=new Uint8Array(1024);#H=new Uint8Array(u.cmt*64);#G=0;#k=0;#o;#c=100;#F=0;#te=500;#ae=0;#B="";#_=0;#se=0;#re=0;#x=!0;#n=!1;#ne=1;#ie;#K=new Array(u.ch);#le=new Uint8Array(2);#m=[];#U=new Uint8Array(u.ch);#I=new Uint8Array(u.tr);baseBank=new X("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","krs","s90es");userBank=new X("gm");initOnReset=!1;aiEfxName="";chRedir(e,r,d){if(this.#I[r])return(this.#I[r]-1)*16+e;if([2,3].indexOf(this.#k)>-1){if(d==1)return e;let p=0,b=!0;for(;b;)this.#U[e+p]==0?(this.#U[e+p]=r,console.debug(`Assign track ${r} to channel ${e+p+1}.`),b=!1):this.#U[e+p]==r?b=!1:(p+=16,p>=128&&(p=0,b=!1));return e+p}else return e}forceVoiceRefresh(){for(let e=0;e{let d=e*128+r,p=this.#d.lastIndexOf(d);if(p>-1)if(this.#e[u.cc*e+h[64]]>63)this.#u[p]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:this.#f[d],state:this.NOTE_HELD});else if(this.#e[u.cc*e+h[66]]>63&&this.#u[p]==this.NOTE_SOSTENUTO_SUSTAIN)this.#u[p]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:this.#f[d],state:this.NOTE_SOSTENUTO_HELD});else{this.#d[p]=0,this.#f[d]=0,this.#u[p]=this.NOTE_IDLE;let b=this.getExt(e)[1];(b==this.VLBC_VELOINIT||b==this.VLBC_VELOALL)&&(this.#e[u.cc*e+h[129]]=0),this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})}},nOn:(e,r,d)=>{let p=e*128+r,b=0;for(this.#E[e]&&this.#l.ano(e);this.#u[b]>0&&this.#d[b]!=p;)b++;if(b{},cAt:(e,r)=>{},hoOf:e=>{this.#u.forEach((r,d)=>{if(r==this.NOTE_HELD){let p=this.#d[d],b=p>>7;e==b&&(this.#u[d]=this.NOTE_IDLE,this.#d[d]=0,this.#f[p]=0,this.dispatchEvent("note",{part:e,note:p&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#u.forEach((r,d)=>{let p;switch(r){case this.NOTE_ATTACK:{p=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{p=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{p=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(p){this.#u[d]=p;let b=this.#d[d];this.dispatchEvent("note",{part:e,note:b&127,velo:this.#f[b],state:p})}})},soOf:e=>{this.#u.forEach((r,d)=>{if(r==this.NOTE_SOSTENUTO_HELD){let p=this.#d[d],b=p>>7;e==b&&(this.#u[d]=this.NOTE_IDLE,this.#d[d]=0,this.#f[p]=0,this.dispatchEvent("note",{part:e,note:p&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#d.forEach((r,d,p)=>{let b=r>>7,E=r&127;r==0&&this.#f[0]==0||b==e&&this.#l.nOff(b,E)})}};#ce={8:function(e){let r=e.channel,d=e.data[0];this.#l.nOff(r,d)},9:function(e){let r=e.channel;this.setChActive(r,1);let d=e.data[0],p=e.data[1];p>0?this.#l.nOn(r,d,p):this.#l.nOff(r,d)},10:function(e){let r=e.channel,d=r*128+e.data[0];this.#d.indexOf(d)>-1&&(this.#f[d]=data[1],this.getExt(r)[1]==this.VLBC_VELOALL&&(this.#e[u.cc*r+h[129]]=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,d=this.#K[r],p=d[e.data[0]];p&&(e.data[0]=p),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case k.s90es:case k.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 b=r*u.cc,E=r*u.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#l.ano(r),this.#A[r]=0,this.#e[b+h[1]]=0,this.#e[b+h[5]]=0,this.#e[b+h[64]]=0,this.#e[b+h[65]]=0,this.#e[b+h[66]]=0,this.#e[b+h[67]]=0,this.#e[b+h[11]]=127,this.#e[b+h[101]]=127,this.#e[b+h[100]]=127,this.#e[b+h[99]]=127,this.#e[b+h[98]]=127;return}case 123:{this.#l.ano(r);return}case 124:{this.#l.ano(r);return}case 125:{this.#l.ano(r);return}case 126:{this.#E[r]=1,this.#l.ano(r);return}case 127:{this.#E[r]=0,this.#l.ano(r);return}}if(h[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(ve.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(v()&&console.debug(`${R[this.#t]}, CH${r+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#r[r]>0&&(e.data[1]=this.#e[b],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(this.#o.x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(this.modeIdx[this.#o.ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==k.gs?e.data[1]<56&&this.#r[r]>0&&(e.data[1]=this.#e[b],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):this.#t==k.gm&&(e.data[1]<48?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)),this.#t){case k.xg:{[79,95,126,127].indexOf(e.data[1])>-1?this.#r[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):this.#r[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?this.#M[E]=this.EXT_VL:this.#M[E]=this.EXT_NONE;break}case k["05rw"]:case k.x5d:case k.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#r[r]==this.CH_MELODIC&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):[80,81,82,83].indexOf(e.data[1])>-1||this.#r[r]!=this.CH_MELODIC&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case k.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#r[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):this.#r[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case k.g2:{e.data[1]==120?this.#r[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):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 2:{this.getExt(r)[1]==this.VLBC_BRTHEXPR&&(this.#e[b+h[129]]=e.data[1]);break}case 6:{if(this.#X){[k.xg,k.gs,k.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${R[this.#t]}" mode, even when they are supported in Octavia.`);let g=this.#e[b+h[99]],$=this.#e[b+h[98]];if(g==1){let t=Se.indexOf($);if(t>-1)this.#e[b+h[71+t]]=e.data[1],v()&&console.debug(`Redirected NRPN 1 ${$} to cc${71+t}.`),this.dispatchEvent("cc",{part:r,cc:71+t,data:e.data[1]});else{let a=he.indexOf($);a>-1?this.#J[r*10+a]=e.data[1]-64:console.warn(`NRPN 0x01${$.toString(16).padStart(2,"0")} is not supported.`),v()&&console.debug(`CH${r+1} voice NRPN ${$} commit`)}}else{if(_.indexOf(g)<0){let a=`NRPN 0x${g.toString(16).padStart(2,"0")}${$.toString(16).padStart(2,"0")} `;g==127?console.warn(`${a}is not necessary. Consider removing it.`):console.warn(`${a}is not supported.`)}else{let a=this.#r[r]-2;a<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${N[this.#r[r]]}.`):this.#y[(a*u.dpn+T[g])*u.dnc+$]=e.data[1]}v()&&console.debug(`CH${r+1} (${N[this.#r[r]]}) drum NRPN ${g} commit`)}}else{let g=le[this.#e[b+h[100]]],$=fe[this.#e[b+h[100]]];this.#e[b+h[101]]==0&&g!=null&&(v()&&console.debug(`CH${r+1} RPN 0 ${this.#e[b+h[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],de[g][0]),de[g][1]),this.#a[r*u.rpn+g]=e.data[1],this.#s[r*u.rpnt+$]=1)}break}case 32:{switch(v()&&console.debug(`${R[this.#t]}, CH${r+1} LSB: ${e.data[1]}`),this.#t){case k.s90es:case k.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.dispatchEvent("voice",{part:r});break}case 38:{if(!this.#X){let g=le[this.#e[b+100]],$=fe[this.#e[b+100]];this.#e[b+101]==0&&g!=null&&(this.#a[r*u.rpn+g+1]=e.data[1],this.#s[r*u.rpnt+$]=1)}break}case 64:{e.data[1]<64&&this.#l.hoOf(r);break}case 66:{e.data[1]>>6?this.#l.soOn(r):this.#l.soOf(r);break}case 98:case 99:{this.#X=1;break}case 100:case 101:{this.#X=0;break}}this.#e[b+h[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(this.#t){case k.s90es:case k.motif:{e.data&&this.setChActive(r,1);break}default:this.setChActive(r,1)}this.#i[r]=e.data,this.#R[r]=0,v()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),this.dispatchEvent("voice",{part:r})},13:function(e){let r=this,d=e.channel;this.#d.forEach(function(p){let b=p>>7;d==b&&(r.#f[p]=e.data,r.dispatchEvent("note",{part:d,note:p&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;this.#A[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){Ce(e.data).forEach(r=>{let d=r[0],p=r[1];(this.#oe[d]||function(){console.debug(`Unknown manufacturer ${d}.`)})(p,r.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#p[e.meta]||function(d,p,b){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#F=0);let r=we.indexOf(e.meta)>-1;if(v()&&console.debug(e),r)return e.reply="meta",e}};#oe={64:(e,r,d)=>{this.#Y.run(r,d,e)},65:(e,r,d)=>{if(r[0]<16)if(r[1]==72){let p=r[r.length-1],b=D(r.subarray(3,r.length-1));p==b?this.#v.run(r.subarray(0,r.length-1),d,e):console.warn(`Bad SD checksum ${p}. Should be ${b}.`)}else this.#v.run(r,d,e);else{let p=r[r.length-1],b=D(r.subarray(2,r.length-1));p==b?this.#v.run(r.subarray(0,r.length-1),d,e):console.warn(`Bad GS checksum ${p}. Should be ${b}.`)}},66:(e,r,d)=>{this.#N.run(r,d,e)},67:(e,r,d)=>{this.#w.run(r,d,e)},68:(e,r,d)=>{this.#j.run(r,d,e)},71:(e,r,d)=>{this.#W.run(r,d,e)},126:(e,r,d)=>{this.#q.run(r,d,e)},127:(e,r,d)=>{this.switchMode("gm"),this.#Q.run(r,d,e)}};#q;#Q;#w;#v;#N;#Y;#W;#j;buildRchTree(){let e=[];this.#h.forEach((r,d)=>{r{r&&(e.#K[Math.floor(d/u.redir)][r]=d%u.redir|128)}),v()&&console.debug(e.#K)}getActive(){return this.#O}getCc(e){let r=e*u.cc,d=this.#e.subarray(r,r+u.cc);return d[h[0]]=d[h[0]]||this.#G,d[h[32]]=d[h[32]]||this.#k,d[h[0]]==H.bank0&&(d[h[0]]=0),d}getCcCh(e,r){if(G.indexOf(r)<0)throw new Error("CC number not accepted");return this.#e[u.cc*e+h[r]]}getCcAll(){let e=this.#e.slice();for(let r=0;r0&&!p&&(this.#e[e*u.cc+h[0]]=O[d])}setChActive(e,r=0){this.#O[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),this.#O[e]=r}getExt(e){let r=u.ext*e,d=this.#M.subarray(r,r+u.ext),p=new Uint8Array(d.length);return p.set(d),p[1]=p[1]||this.#ne,p}getPitch(){return this.#A}getProgram(){return this.#i}getTexts(){return this.#m.slice()}getVel(e){let r=new Map,d=this;return d.#d.forEach(function(p,b){let E=Math.floor(p/128),g=p%128;e==E&&d.#f[p]>0&&r.set(g,{v:d.#f[p],s:d.#u[b]})}),r}getBitmap(){return{bitmap:this.#g,expire:this.#C}}getLetter(){return{text:this.#B,set:this.#se,expire:this.#_}}getMode(){return R[this.#t]}getMaster(){return{volume:this.#c}}getRawStrength(){let e=this;return this.#d.forEach(function(r){let d=Math.floor(r/128);e.#f[r]>e.#T[d]&&(e.#T[d]=e.#f[r])}),this.#T}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(d,p){e[p]=Math.floor(d*r.#e[p*u.cc+h[7]]*r.#e[p*u.cc+h[11]]*r.#c/803288)}),e}getRpn(){return this.#a}getNrpn(){return this.#J}getVoice(e,r,d,p){let b=e||this.#G,E=r,g=d||this.#k;b==H.bank0&&(b=0),R[this.#t]=="ns5r"&&b>0&&b<56&&(g=3);let $=this.userBank.get(b,E,g,p);if(R[this.#t]=="mt32"&&$.name.indexOf("MT-m:")==0){let t=parseInt($.name.slice(5)),a=t*u.cmt,c="";this.#H.subarray(a,a+10).forEach(s=>{s>31&&(c+=String.fromCharCode(s))});let i=`MSB LSB PRG NME -0 127 ${E} ${c}`;this.userBank.load(i,!0),$.name=c,$.ending=" "}return($.ending!=" "||!$.name.length)&&($=this.baseBank.get(b,E,g,p)),$}getChVoice(e){let r=this.getVoice(this.#e[e*u.cc+h[0]],this.#i[e],this.#e[e*u.cc+h[32]],R[this.#t]);if(this.#R[e])switch(this.#t){case k.mt32:r.ending="~",r.name="",this.#S.subarray(14*(e-1),14*(e-1)+10).forEach(d=>{r.name+=String.fromCharCode(Math.max(d,32))}),r.name=r.name.trimRight()}return r}getRawPitch(){return this.#A}getPitchShift(e){let r=this,d=e*u.rpn,p=r.#a[d];return r.#s[e*u.rpnt]||r.#t==k.mt32&&(p=12),r.#A[e]/8192*p+(r.#a[d+3]-64)+((r.#a[d+1]<<7)+r.#a[d+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return this.#$.subarray(r,r+2)}setEffectTypeRaw(e=0,r,d){let p=3*e;this.#$[p]=1,this.#$[p+1+ +r]=d}setEffectType(e=0,r,d){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,d)}getEffectSink(){return this.#Z}setLetterDisplay(e,r,d=0,p=3200){let b=this,E;b.#B=" ".repeat(d),e.forEach(g=>{b.#B+=String.fromCharCode(g>31?g:32),g<32&&(E=E||new Set,E.add(g))}),b.#se=Date.now(),b.#_=Date.now()+p,E&&(E=Array.from(E),E.forEach((g,$,t)=>{t[$]=g.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${E.length>1?"s":""}: 0x${E.join(", 0x")}`))}setDetectionTargets(e="?",r=0){let d=this,p=-1;switch(e.replaceAll(", ",",").split(",").forEach(b=>{b=b.toLowerCase();let E=R.indexOf(me[b]||b);v()&&console.debug(`Mapped mode "${b}" to ID "${E}".`),E>-1&&(p=E)}),v()&&console.debug(`Set detection target to ID "${p}".`),p>0&&(d.#o.x5=82,d.#o.ds=k.krs),p){case k["05rw"]:{d.#o.x5=81;break}case k.s90es:d.#o.ds=k.s90es;case k.motif:d.#o.ds=k.motif}}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let r=!0,d=0;for(;r&&d=u.ace&&console.warn("ACE slots are full.")}getAce(){return this.#L}getChAce(e,r){if(r<0||r>=u.ace)throw new RangeError("No such ACE slot");let d=this.#L[r];if(d){if(G.indexOf(d)>=0)return this.#e[e*u.cc+h[d]];throw new Error(`Invalid ACE source: ${d}`)}else return 0}initDrums(){let e=this;e.#y.fill(64);for(let r=0;r-1){if(p.#t==0||r){let E=p.#t;p.initOnReset&&r&&(this.init(1),E=k["?"]),p.#t=b,p.#b=0,p.#G=ne[0][b],p.#k=ne[1][b];for(let $=0;$0&&p.#e[$*u.cc+h[0]]==O[E]&&(p.#e[$*u.cc]=O[b]);switch(b){case k.mt32:{z.forEach(($,t)=>{let a=t+1;p.#O[a]||(p.#i[a]=$,p.#e[a*u.cc+h[91]]=127)});for(let $=1;$<10;$++)p.dispatchEvent("voice",{part:$});break}}let g;switch(b){case k["?"]:case k.g2:{g=[52,4,52,18,0,0,0,0];break}case k.xg:{g=[1,0,65,0,5,0,0,0];break}case k.gm:case k.gs:{g=[40,4,40,18,40,32,32,0];break}case k.sd:{g=[58,0,60,0,61,0,61,0];break}case k["05rw"]:case k.x5d:case k.ns5r:{g=[44,1,44,19,44,0,44,0];break}case k.k11:case k.sg:{g=[24,0,0,0,0,0,0,0];break}case k.mt32:{g=[40,4,0,0,0,0,0,0];break}default:g=[0,0,0,0,0,0,0,0]}for(let $=0;$14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#ce[e.type].call(this,e);{let r=this.chRedir(e.part,e.track),d=!1;this.#ie[r]?.forEach(p=>{e.channel=p,d=!0,this.#ce[e.type].call(this,e)}),d||console.warn(`${oe[e.type]?oe[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${r+1} without any recipient.`)}this.#m.length>100&&this.#m.splice(100,this.#m.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":{B.context=this,d.userBank.load(await B.read(e,r));break}}d.forceVoiceRefresh()}constructor(){super();let e=this;e.#g=new Uint8Array(256),e.#D[10]=new Uint8Array(512),e.#z=new C,e.#o={x5:82,ds:k.krs},e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let r=e.split(",");V[r[0]]=r[1]});var ae=function(e){let r=e;e[0]=="*"&&(r=r.slice(1)),["aa","ii","uu","ee","oo"].forEach(p=>{for(;r.indexOf(p)>-1;)r=r.replace(p,p[0])});for(let p in V)r=r.replaceAll(p,V[p]);r.indexOf("ん")==0&&r.length>1&&(r=r.slice(1));let d=r.indexOf("!");return d>-1&&r.length>1&&(r=r.slice(d+1)),r},re=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var F=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],se=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ie=["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 $e={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"},ge={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]]},K=function(e){return $e[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ce=function(e,r,d){let p=(e[0]-32<<16)+(e[1]<<8)+r,b=ge[p]||{},E=b[0];if(E?.length)return E+=`: ${(b[1]||function(){})(d)||d}`,E},z=[68,48,95,78,41,3,110,122,0];var S=function(e=64){return Math.round(2e3*Math.log10(e/64))/100};var D=function(e){let r=0;return e.forEach(d=>{r+=d,r=r&127}),~r+1&127},M=function(e,r){let d=0,p=0;for(let b=0;b>E&1)<<7,g=e[b];g+=$,b%8!=0?(r(g,d,e),d++):p=e[b]}};var P=function(e){let r=Math.floor(e*14.2);return r<128?r:0};var R=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],me={gm2:"g2","mt-32":"mt32","c/m":"mt32",ag10:"05rw","ag-10":"05rw","05r/w":"05rw",x5:"05rw",x5dr:"x5d",gmega:"k11","kross 2":"krs","motif es":"motif","s90 es":"s90es"},ke=["melodic","drum","menu"],ne=[[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]],O=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],ve=[0,3,81,84,88],oe={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},le={0:0,1:1,2:3,5:4},fe={0:0,1:1,2:2,5:3},de=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],he=[36,37,48,49,52,53],B=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],ue={26:127,29:0,30:0,31:0,52:12,53:54},_=[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,14,15,20,21,26,28,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157],we=[2,12,13,14,15,16,17,18,19,20,21,136,130,131,132,133,134,135,137,138,139,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157],xe=[33,99,100,32,102,8,9,10],pe=[0,16,25,40,32,64,26,48],k={};R.forEach((e,r)=>{k[e]=r});var h={length:_.length};_.forEach((e,r)=>{h[e]=r});var T={length:B.length};B.forEach((e,r)=>{T[e]=r});var Se={};ke.forEach((e,r)=>{Se[e]=r});var w=function(){return!!self.Bun||self.debugMode||!1},Ce=function(e){let r=[],d=0;return e?.forEach(function(p,b){p==247?r.push(e.subarray(d,b)):p==240&&(d=b+1)}),r.length||r.push(e.subarray(0)),w()&&console.debug(r),r};var u={ch:128,cc:_.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:B.length,dnc:128,ext:2,efx:7,cvn:12,redir:32},H={bank0:128},Je=class extends Y{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;EXT_NONE=0;EXT_VL=1;EXT_DX=3;VLBC_BRTHEXPR=1;VLBC_VELOINIT=2;VLBC_VELOALL=3;#t=0;#b=0;#R=0;#O=new Array(11);get#E(){return this.#O[this.#b]}set#E(e){this.#O[this.#b]=e}#A=new Uint8Array(u.ch);#h=new Uint8Array(u.ch);#r=new Uint8Array(u.ch);#e=new Uint8Array(u.ch*u.cc);#w=new Uint8Array(u.ace);#i=new Uint8Array(u.ch);#f=new Uint8Array(u.ch*u.nn);#$=new Uint8Array(u.ch);#d=new Uint16Array(u.pl);#u=new Uint8Array(u.pl);#L=new Int16Array(u.ch);#D=new Uint8Array(u.ch);#X=0;#g=new Uint8Array(u.ch*u.ext);#a=new Uint8Array(u.ch*u.rpn);#s=new Uint8Array(u.ch*u.rpnt);#J=new Int8Array(u.ch*he.length);#y=new Uint8Array(u.drm*u.dpn*u.dnc);#m=new Uint8Array(u.efx*3);#Z=new Uint8Array(u.ch);#V=new Uint8Array(u.ch*u.redir);#C=new Uint8Array(u.ch);#se=new Uint8Array(u.ch*u.cvn);#P=new Uint8Array(128);#T=new Uint8Array(u.cmt*8);#ee=new Uint8Array(1024);#H=new Uint8Array(u.cmt*64);#_=0;#x=0;#o;#c=100;#F=0;#te=500;#ae=0;#G="";#B=0;#ie=0;#re=0;#M=!0;#n=!1;#oe=1;#ce;#K=new Array(u.ch);#fe=new Uint8Array(2);#k=[];#U=new Uint8Array(u.ch);#I=new Uint8Array(u.tr);baseBank=new X("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","krs","s90es");userBank=new X("gm");initOnReset=!1;aiEfxName="";chRedir(e,r,d){if(this.#I[r])return(this.#I[r]-1)*16+e;if([2,3].indexOf(this.#x)>-1){if(d==1)return e;let p=0,b=!0;for(;b;)this.#U[e+p]==0?(this.#U[e+p]=r,console.debug(`Assign track ${r} to channel ${e+p+1}.`),b=!1):this.#U[e+p]==r?b=!1:(p+=16,p>=128&&(p=0,b=!1));return e+p}else return e}forceVoiceRefresh(){for(let e=0;e{let d=e*128+r,p=this.#d.lastIndexOf(d);if(p>-1)if(this.#e[u.cc*e+h[64]]>63)this.#u[p]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:this.#f[d],state:this.NOTE_HELD});else if(this.#e[u.cc*e+h[66]]>63&&this.#u[p]==this.NOTE_SOSTENUTO_SUSTAIN)this.#u[p]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:this.#f[d],state:this.NOTE_SOSTENUTO_HELD});else{this.#d[p]=0,this.#f[d]=0,this.#u[p]=this.NOTE_IDLE;let b=this.getExt(e)[1];(b==this.VLBC_VELOINIT||b==this.VLBC_VELOALL)&&(this.#e[u.cc*e+h[129]]=0),this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})}},nOn:(e,r,d)=>{let p=e*128+r,b=0;for(this.#$[e]&&this.#l.ano(e);this.#u[b]>0&&this.#d[b]!=p;)b++;if(b{},cAt:(e,r)=>{},hoOf:e=>{this.#u.forEach((r,d)=>{if(r==this.NOTE_HELD){let p=this.#d[d],b=p>>7;e==b&&(this.#u[d]=this.NOTE_IDLE,this.#d[d]=0,this.#f[p]=0,this.dispatchEvent("note",{part:e,note:p&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#u.forEach((r,d)=>{let p;switch(r){case this.NOTE_ATTACK:{p=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{p=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{p=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(p){this.#u[d]=p;let b=this.#d[d];this.dispatchEvent("note",{part:e,note:b&127,velo:this.#f[b],state:p})}})},soOf:e=>{this.#u.forEach((r,d)=>{if(r==this.NOTE_SOSTENUTO_HELD){let p=this.#d[d],b=p>>7;e==b&&(this.#u[d]=this.NOTE_IDLE,this.#d[d]=0,this.#f[p]=0,this.dispatchEvent("note",{part:e,note:p&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#d.forEach((r,d,p)=>{let b=r>>7,E=r&127;r==0&&this.#f[0]==0||b==e&&this.#l.nOff(b,E)})}};#ne={8:function(e){let r=e.channel,d=e.data[0];this.#l.nOff(r,d)},9:function(e){let r=e.channel;this.setChActive(r,1);let d=e.data[0],p=e.data[1];p>0?this.#l.nOn(r,d,p):this.#l.nOff(r,d)},10:function(e){let r=e.channel,d=r*128+e.data[0];this.#d.indexOf(d)>-1&&(this.#f[d]=data[1],this.getExt(r)[1]==this.VLBC_VELOALL&&(this.#e[u.cc*r+h[129]]=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,d=this.#K[r],p=d[e.data[0]];p&&(e.data[0]=p),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case k.s90es:case k.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 b=r*u.cc,E=r*u.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#l.ano(r),this.#L[r]=0,this.#e[b+h[1]]=0,this.#e[b+h[5]]=0,this.#e[b+h[64]]=0,this.#e[b+h[65]]=0,this.#e[b+h[66]]=0,this.#e[b+h[67]]=0,this.#e[b+h[11]]=127,this.#e[b+h[101]]=127,this.#e[b+h[100]]=127,this.#e[b+h[99]]=127,this.#e[b+h[98]]=127;return}case 123:{this.#l.ano(r);return}case 124:{this.#l.ano(r);return}case 125:{this.#l.ano(r);return}case 126:{this.#$[r]=1,this.#l.ano(r);return}case 127:{this.#$[r]=0,this.#l.ano(r);return}}if(h[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(we.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(w()&&console.debug(`${R[this.#t]}, CH${r+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#r[r]>0&&(e.data[1]=this.#e[b],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(this.#o.x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(this.modeIdx[this.#o.ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==k.gs?e.data[1]<56&&this.#r[r]>0&&(e.data[1]=this.#e[b],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):this.#t==k.gm&&(e.data[1]<48?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)),this.#t){case k.xg:{[79,95,126,127].indexOf(e.data[1])>-1?this.#r[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):this.#r[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?this.#g[E]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?this.#g[E]=this.EXT_DX:this.#g[E]=this.EXT_NONE;break}case k["05rw"]:case k.x5d:case k.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#r[r]==this.CH_MELODIC&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):[80,81,82,83].indexOf(e.data[1])>-1||this.#r[r]!=this.CH_MELODIC&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case k.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#r[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):this.#r[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case k.g2:{e.data[1]==120?this.#r[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):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 2:{this.getExt(r)[1]==this.VLBC_BRTHEXPR&&(this.#e[b+h[129]]=e.data[1]);break}case 6:{if(this.#X){[k.xg,k.gs,k.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${R[this.#t]}" mode, even when they are supported in Octavia.`);let $=this.#e[b+h[99]],g=this.#e[b+h[98]];if($==1){let t=xe.indexOf(g);if(t>-1)this.#e[b+h[71+t]]=e.data[1],w()&&console.debug(`Redirected NRPN 1 ${g} to cc${71+t}.`),this.dispatchEvent("cc",{part:r,cc:71+t,data:e.data[1]});else{let a=he.indexOf(g);a>-1?this.#J[r*10+a]=e.data[1]-64:console.warn(`NRPN 0x01${g.toString(16).padStart(2,"0")} is not supported.`),w()&&console.debug(`CH${r+1} voice NRPN ${g} commit`)}}else{if(B.indexOf($)<0){let a=`NRPN 0x${$.toString(16).padStart(2,"0")}${g.toString(16).padStart(2,"0")} `;$==127?console.warn(`${a}is not necessary. Consider removing it.`):console.warn(`${a}is not supported.`)}else{let a=this.#r[r]-2;a<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${N[this.#r[r]]}.`):this.#y[(a*u.dpn+T[$])*u.dnc+g]=e.data[1]}w()&&console.debug(`CH${r+1} (${N[this.#r[r]]}) drum NRPN ${$} commit`)}}else{let $=le[this.#e[b+h[100]]],g=fe[this.#e[b+h[100]]];this.#e[b+h[101]]==0&&$!=null&&(w()&&console.debug(`CH${r+1} RPN 0 ${this.#e[b+h[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],de[$][0]),de[$][1]),this.#a[r*u.rpn+$]=e.data[1],this.#s[r*u.rpnt+g]=1)}break}case 32:{switch(w()&&console.debug(`${R[this.#t]}, CH${r+1} LSB: ${e.data[1]}`),this.#t){case k.s90es:case k.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.getExt(r)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:r});break}case 38:{if(!this.#X){let $=le[this.#e[b+100]],g=fe[this.#e[b+100]];this.#e[b+101]==0&&$!=null&&(this.#a[r*u.rpn+$+1]=e.data[1],this.#s[r*u.rpnt+g]=1)}break}case 64:{e.data[1]<64&&this.#l.hoOf(r);break}case 66:{e.data[1]>>6?this.#l.soOn(r):this.#l.soOf(r);break}case 98:case 99:{this.#X=1;break}case 100:case 101:{this.#X=0;break}}this.#e[b+h[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(this.#t){case k.s90es:case k.motif:{e.data&&this.setChActive(r,1);break}default:this.setChActive(r,1)}if(this.getExt(r)[0]==this.EXT_DX){let d=u.cc*r}this.#i[r]=e.data,this.#C[r]=0,w()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),this.dispatchEvent("voice",{part:r})},13:function(e){let r=this,d=e.channel;this.#d.forEach(function(p){let b=p>>7;d==b&&(r.#f[p]=e.data,r.dispatchEvent("note",{part:d,note:p&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;this.#L[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){Ce(e.data).forEach(r=>{let d=r[0],p=r[1];(this.#le[d]||function(){console.debug(`Unknown manufacturer ${d}.`)})(p,r.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#p[e.meta]||function(d,p,b){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#F=0);let r=ve.indexOf(e.meta)>-1;if(w()&&console.debug(e),r)return e.reply="meta",e}};#le={64:(e,r,d)=>{this.#Y.run(r,d,e)},65:(e,r,d)=>{if(r[0]<16)if(r[1]==72){let p=r[r.length-1],b=D(r.subarray(3,r.length-1));p==b?this.#S.run(r.subarray(0,r.length-1),d,e):console.warn(`Bad SD checksum ${p} - should be ${b}.`)}else this.#S.run(r,d,e);else{let p=r[r.length-1],b=D(r.subarray(2,r.length-1));p==b?this.#S.run(r.subarray(0,r.length-1),d,e):console.warn(`Bad GS checksum ${p} - should be ${b}.`)}},66:(e,r,d)=>{this.#N.run(r,d,e)},67:(e,r,d)=>{this.#v.run(r,d,e)},68:(e,r,d)=>{this.#j.run(r,d,e)},71:(e,r,d)=>{this.#W.run(r,d,e)},126:(e,r,d)=>{this.#q.run(r,d,e)},127:(e,r,d)=>{this.switchMode("gm"),this.#Q.run(r,d,e)}};#q;#Q;#v;#S;#N;#Y;#W;#j;buildRchTree(){let e=[];this.#h.forEach((r,d)=>{r{r&&(e.#K[Math.floor(d/u.redir)][r]=d%u.redir|128)}),w()&&console.debug(e.#K)}getActive(){return this.#A}getCc(e){let r=e*u.cc,d=this.#e.subarray(r,r+u.cc);return d[h[0]]=d[h[0]]||this.#_,d[h[32]]=d[h[32]]||this.#x,d[h[0]]==H.bank0&&(d[h[0]]=0),d}getCcCh(e,r){if(_.indexOf(r)<0)throw new Error("CC number not accepted");return this.#e[u.cc*e+h[r]]}getCcAll(){let e=this.#e.slice();for(let r=0;r0&&!p&&(this.#e[e*u.cc+h[0]]=O[d])}setChActive(e,r=0){this.#A[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),this.#A[e]=r}getExt(e){let r=u.ext*e,d=this.#g.subarray(r,r+u.ext),p=new Uint8Array(d.length);return p.set(d),p[1]=p[1]||this.#oe,p}getPitch(){return this.#L}getProgram(){return this.#i}getTexts(){return this.#k.slice()}getVel(e){let r=new Map,d=this;return d.#d.forEach(function(p,b){let E=Math.floor(p/128),$=p%128;e==E&&d.#f[p]>0&&r.set($,{v:d.#f[p],s:d.#u[b]})}),r}getBitmap(){return{bitmap:this.#E,expire:this.#R}}getLetter(){return{text:this.#G,set:this.#ie,expire:this.#B}}getMode(){return R[this.#t]}getMaster(){return{volume:this.#c}}getRawStrength(){let e=this;return this.#d.forEach(function(r){let d=Math.floor(r/128);e.#f[r]>e.#D[d]&&(e.#D[d]=e.#f[r])}),this.#D}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(d,p){e[p]=Math.floor(d*r.#e[p*u.cc+h[7]]*r.#e[p*u.cc+h[11]]*r.#c/803288)}),e}getRpn(){return this.#a}getNrpn(){return this.#J}getVoice(e,r,d,p){let b=e||this.#_,E=r,$=d||this.#x;b==H.bank0&&(b=0),R[this.#t]=="ns5r"&&b>0&&b<56&&($=3);let g=this.userBank.get(b,E,$,p);if(R[this.#t]=="mt32"&&g.name.indexOf("MT-m:")==0){let t=parseInt(g.name.slice(5)),a=t*u.cmt,c="";this.#H.subarray(a,a+10).forEach(s=>{s>31&&(c+=String.fromCharCode(s))});let i=`MSB LSB PRG NME +0 127 ${E} ${c}`;this.userBank.load(i,!0),g.name=c,g.ending=" "}return(g.ending!=" "||!g.name.length)&&(g=this.baseBank.get(b,E,$,p)),g}getChVoice(e){let r=this.getVoice(this.#e[e*u.cc+h[0]],this.#i[e],this.#e[e*u.cc+h[32]],R[this.#t]);if(this.#C[e]){let d="";switch(this.#t){case k.mt32:{this.#T.subarray(u.cmt*(e-1),u.cmt*(e-1)+10).forEach(p=>{d+=String.fromCharCode(Math.max(p,32))}),d=d.trimRight();break}default:{let p=u.cvn*e;this.#se.subarray(p,p+u.cvn).forEach(b=>{d+=String.fromCharCode(Math.max(b,32))}),d=d.trimRight()}}d.length&&(r.ending="~",r.name=d)}return r}getRawPitch(){return this.#L}getPitchShift(e){let r=this,d=e*u.rpn,p=r.#a[d];return r.#s[e*u.rpnt]||r.#t==k.mt32&&(p=12),r.#L[e]/8192*p+(r.#a[d+3]-64)+((r.#a[d+1]<<7)+r.#a[d+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return this.#m.subarray(r,r+2)}setEffectTypeRaw(e=0,r,d){let p=3*e;this.#m[p]=1,this.#m[p+1+ +r]=d}setEffectType(e=0,r,d){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,d)}getEffectSink(){return this.#Z}setLetterDisplay(e,r,d=0,p=3200){let b=this,E;b.#G=" ".repeat(d),e.forEach($=>{b.#G+=String.fromCharCode($>31?$:32),$<32&&(E=E||new Set,E.add($))}),b.#ie=Date.now(),b.#B=Date.now()+p,E&&(E=Array.from(E),E.forEach(($,g,t)=>{t[g]=$.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${E.length>1?"s":""}: 0x${E.join(", 0x")}`))}setDetectionTargets(e="?",r=0){let d=this,p=-1;switch(e.replaceAll(", ",",").split(",").forEach(b=>{b=b.toLowerCase();let E=R.indexOf(me[b]||b);w()&&console.debug(`Mapped mode "${b}" to ID "${E}".`),E>-1&&(p=E)}),w()&&console.debug(`Set detection target to ID "${p}".`),p>0&&(d.#o.x5=82,d.#o.ds=k.krs),p){case k["05rw"]:{d.#o.x5=81;break}case k.s90es:d.#o.ds=k.s90es;case k.motif:d.#o.ds=k.motif}}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let r=!0,d=0;for(;r&&d=u.ace&&console.warn("ACE slots are full.")}releaseAce(e){let r=!0,d=0;for(;r&&d=u.ace)throw new RangeError("No such ACE slot");let d=this.#w[r];if(d){if(_.indexOf(d)>=0)return this.#e[e*u.cc+h[d]];throw new Error(`Invalid ACE source: ${d}`)}else return 0}initDrums(){let e=this;e.#y.fill(64);for(let r=0;r-1){if(p.#t==0||r){let E=p.#t;p.initOnReset&&r&&(this.init(1),E=k["?"]),p.#t=b,p.#b=0,p.#_=ne[0][b],p.#x=ne[1][b];for(let g=0;g0&&p.#e[g*u.cc+h[0]]==O[E]&&(p.#e[g*u.cc]=O[b]);switch(b){case k.mt32:{z.forEach((g,t)=>{let a=t+1;p.#A[a]||(p.#i[a]=g,p.#e[a*u.cc+h[91]]=127)});for(let g=1;g<10;g++)p.dispatchEvent("voice",{part:g});break}}let $;switch(b){case k["?"]:case k.g2:{$=[52,4,52,18,0,0,0,0];break}case k.xg:{$=[1,0,65,0,5,0,0,0];break}case k.gm:case k.gs:{$=[40,4,40,18,40,32,32,0];break}case k.sd:{$=[58,0,60,0,61,0,61,0];break}case k["05rw"]:case k.x5d:case k.ns5r:{$=[44,1,44,19,44,0,44,0];break}case k.k11:case k.sg:{$=[24,0,0,0,0,0,0,0];break}case k.mt32:{$=[40,4,0,0,0,0,0,0];break}default:$=[0,0,0,0,0,0,0,0]}for(let g=0;g14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#ne[e.type].call(this,e);{let r=this.chRedir(e.part,e.track),d=!1;this.#ce[r]?.forEach(p=>{e.channel=p,d=!0,this.#ne[e.type].call(this,e)}),d||console.warn(`${oe[e.type]?oe[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${r+1} without any recipient.`)}this.#k.length>100&&this.#k.splice(100,this.#k.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":{G.context=this,d.userBank.load(await G.read(e,r));break}}d.forceVoiceRefresh()}constructor(){super();let e=this;e.#E=new Uint8Array(256),e.#O[10]=new Uint8Array(512),e.#z=new C,e.#o={x5:82,ds:k.krs},e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -148,21 +148,22 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),e.addEventListener("metacommit",function(t){let{data:a}=t;e.#m[0]?.type==a.type&&e.#m[0]?.amend?(e.#m[0].amend=a.amend,e.#m[0].data+=a.data):e.#m.unshift(a)}),e.#p[1]=function(t){switch(t=t.replaceAll(`\r +122 006 000 `),e.addEventListener("metacommit",function(t){let{data:a}=t;e.#k[0]?.type==a.type&&e.#k[0]?.amend?(e.#k[0].amend=a.amend,e.#k[0].data+=a.data):e.#k.unshift(a)}),e.#p[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 a=t.slice(2).split(":");switch(a[0]){case"hd":{a.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":{a.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.#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((a,c)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:a,mask:c!=0})})}},e.#p[2]=function(t){this.dispatchEvent("metacommit",{type:"Copyrite",data:t})},e.#p[3]=function(t,a){a<1&&this.#F<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:t})},e.#p[4]=function(t,a){this.dispatchEvent("metacommit",{type:"Instrmnt",data:t})},e.#p[5]=function(t){t.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:t,amend:!0})},e.#p[6]=function(t){this.dispatchEvent("metacommit",{type:"C.Marker",data:t})},e.#p[7]=function(t){this.dispatchEvent("metacommit",{type:"CuePoint",data:t})},e.#p[32]=function(t){this.#F=t[0]+1},e.#p[33]=function(t,a){e.#I[a]=t+1},e.#p[81]=function(t,a){e.#te=t/1e3},e.#p[127]=function(t,a){e.#z.run(t,a)},e.#z.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},e.#z.add([67,0,1],function(t,a){e.#I[a]=t[0]+1}),e.#q=new C("universal non-realtime"),e.#Q=new C("universal realtime"),e.#w=new C("Yamaha"),e.#v=new C("Roland"),e.#N=new C("Korg"),e.#Y=new C("Kawai"),e.#W=new C("Akai"),e.#j=new C("Casio");let r=new C("DX7+ Dump"),d=function(t){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,t)};e.#q.default=d,e.#Q.default=d,e.#w.default=d,e.#v.default=d,e.#N.default=d,e.#Y.default=d,e.#W.default=d,e.#j.default=d,r.default=d,e.#q.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()}),e.#Q.add([4,1],t=>{e.#c=((t[1]<<7)+t[0])/16383*100,e.dispatchEvent("mastervolume",e.#c)}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64).add([4,5],t=>{let a=t[0],c=t[1],i=t[2],s=3,f=s+(a<<1),o=f+c;if(a!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${a})! -`,t);return}let n=0,l=0,y=0;switch(t.subarray(s,f).forEach(m=>{n=n<<7,n|=m}),t.subarray(f,o).forEach((m,w)=>{l|=m<{y|=m<{switch(t[0]){case 125:{e.initDrums(),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 a=[0,0,0,0],c=(i,s)=>{a[s]=i};if(t.subarray(1).forEach((i,s)=>{let f=s+t[0];([c,c,c,c,o=>{this.#c=o*129/16383*100,e.dispatchEvent("mastervolume",e.#c)},o=>{},o=>{}][f]||(()=>{}))(i,s)}),t[0]<4){let i=0;a.forEach(s=>{i=i<<4,i+=s}),i-=1024}}}}).add([76,2,1],t=>{let a="XG ";t[0]<32?(a+="reverb ",t.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${a}main type: ${U[s]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{e.setEffectTypeRaw(0,!0,s),console.debug(`${a}sub type: ${s+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{console.debug(`${a}time: ${Z(s)}s`)},s=>{console.debug(`${a}diffusion: ${s}`)},s=>{console.debug(`${a}initial delay: ${s}`)},s=>{console.debug(`${a}HPF cutoff: ${L[s]}Hz`)},s=>{console.debug(`${a}LPF cutoff: ${L[s]}Hz`)},s=>{console.debug(`${a}width: ${s}`)},s=>{console.debug(`${a}height: ${s}`)},s=>{console.debug(`${a}depth: ${s}`)},s=>{console.debug(`${a}wall type: ${s}`)},s=>{console.debug(`${a}dry/wet: ${s}`)},s=>{console.debug(`${a}send: ${x(s)}dB`)},s=>{console.debug(`${a}pan: ${s-64}`)},!1,!1,s=>{console.debug(`${a}delay: ${s}`)},s=>{console.debug(`${a}density: ${s}`)},s=>{console.debug(`${a}balance: ${s}`)},s=>{},s=>{console.debug(`${a}feedback: ${s}`)},s=>{}][t[0]+i]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(c)})):t[0]<64?(a+="chorus ",t.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${a}main type: ${U[s]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{e.setEffectTypeRaw(1,!0,s),console.debug(`${a}sub type: ${s+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{console.debug(`${a}LFO: ${J[s]}Hz`)},s=>{},s=>{console.debug(`${a}feedback: ${s}`)},s=>{console.debug(`${a}delay offset: ${ee(s)}ms`)},s=>{},s=>{console.debug(`${a}low: ${L[s]}Hz`)},s=>{console.debug(`${a}low: ${s-64}dB`)},s=>{console.debug(`${a}high: ${L[s]}Hz`)},s=>{console.debug(`${a}high: ${s-64}dB`)},s=>{console.debug(`${a}dry/wet: ${s}`)},s=>{console.debug(`${a}send: ${x(s)}dB`)},s=>{console.debug(`${a}pan: ${s-64}`)},s=>{console.debug(`${a}to reverb: ${x(s)}dB`)},!1,s=>{},s=>{},s=>{},s=>{console.debug(`${a}LFO phase diff: ${(s-64)*3}deg`)},s=>{console.debug(`${a}input mode: ${s?"stereo":"mono"}`)},s=>{}][t[0]-32+i]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(c)})):t[0]<86?(a+="variation ",t.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${a}main type: ${U[s]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},s=>{e.setEffectTypeRaw(2,!0,s),console.debug(`${a}sub type: ${s+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][t[0]-64+i]||function(){})(c)})):t[0]<97?(a+="variation ",t.subarray(1).forEach((c,i)=>{[s=>{console.debug(`${a}send: ${x(s)}dB`)},s=>{console.debug(`${a}pan: ${s-64}`)},s=>{console.debug(`${a}to reverb: ${x(s)}dB`)},s=>{console.debug(`${a}to chorus: ${x(s)}dB`)},s=>{console.debug(`${a}connection: ${s?"system":"insertion"}`)},s=>{console.debug(`${a}channel: CH${s+1}`)},s=>{console.debug(`${a}mod wheel: ${s-64}`)},s=>{console.debug(`${a}bend wheel: ${s-64}`)},s=>{console.debug(`${a}channel after touch: ${s-64}`)},s=>{console.debug(`${a}AC1: ${s-64}`)},s=>{console.debug(`${a}AC2: ${s-64}`)}][t[0]-86+i](c)})):t[0]>111&&t[0]<118?a+="variation ":console.warn(`Unknown XG variation address: ${t[0]}`)}).add([76,2,64],t=>{t.subarray(1).forEach((a,c)=>{let i=c+t[0];if(i==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][a]}`);else{let s=i-1>>2,f=i-1&3,o=`XG EQ ${s} ${["gain","freq","Q","shape"][f]}: `;[()=>{console.debug(`${o}${a-64}dB`)},()=>{console.debug(`${o}${a} (raw)`)},()=>{console.debug(`${o}${a/10}`)},()=>{console.debug(`${o}${["shelf","peak"][+!!a]}`)}][f]()}})}).add([76,3],t=>{let a=t[0],c=t[1],i=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((s,f)=>{([o=>{e.setEffectTypeRaw(3+a,!1,o),console.info(`${i}main type: ${U[o]}`),e.dispatchEvent(`efxinsert${a}`,e.getEffectType(3+a))},o=>{e.setEffectTypeRaw(3+a,!0,o),console.debug(`${i}sub type: ${o+1}`),e.dispatchEvent(`efxinsert${a}`,e.getEffectType(3+a))}][c+f]||function(){})(s)})}).add([76,6,0],t=>{let a=t[0];a<64?e.setLetterDisplay(t.subarray(1),"XG letter display",a):e.#_=Date.now()}).add([76,7,0],t=>{let a=t[0];e.#b=0,e.#C=Date.now()+3200,e.#g.fill(0);let c=t.subarray(1);for(let i=0;i>6-y&1,y++})}).add([76,8],(t,a)=>{let c=e.chRedir(t[0],a,!0),i=t[1],s=u.cc*c,f=`XG CH${c+1} `,o=`Unknown XG part address ${i}.`;t.subarray(2).forEach((n,l)=>{i<1?console.debug(o):i<41?([()=>{e.#e[s+h[0]]=n,e.dispatchEvent("voice",{part:c})},()=>{e.#e[s+h[32]]=n,e.dispatchEvent("voice",{part:c})},()=>{e.#i[c]=n,e.dispatchEvent("voice",{part:c})},()=>{let y=e.chRedir(n,a,!0);e.#h[c]=y,c!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))},()=>{e.#E[c]=+!n},()=>{},()=>{e.setChType(c,n,k.xg),console.debug(`${f}type: ${N[n]||n}`)},()=>{e.#a[u.rpn*c+3]=n,e.#s[u.rpnt*c+2]=1},!1,!1,()=>{e.#e[s+h[7]]=n},!1,!1,()=>{e.#e[s+h[10]]=n||128},!1,!1,()=>{e.#e[s+h[128]]=n},()=>{e.#e[s+h[93]]=n},()=>{e.#e[s+h[91]]=n},()=>{e.#e[s+h[94]]=n},()=>{e.#e[s+h[76]]=n},()=>{e.#e[s+h[77]]=n},()=>{e.#e[s+h[78]]=n},()=>{e.#e[s+h[74]]=n},()=>{e.#e[s+h[71]]=n},()=>{e.#e[s+h[73]]=n},()=>{e.#e[s+h[75]]=n},()=>{e.#e[s+h[72]]=n}][i+l-1]||(()=>{}))():i<48?console.debug(o):i<111?i>102&&i<105&&(e.#e[s+h[[5,65][i&1]]]=n):i<114?console.debug(o):i<116?console.debug(`${f}EQ ${["bass","treble"][i&1]} gain: ${n-64}dB`):i<118?console.debug(o):i<120?console.debug(`${f}EQ ${["bass","treble"][i&1]} freq: ${n}`):console.debug(o)})}).add([76,9],(t,a)=>{let c=e.chRedir(t[0],a,!0),i=t[1],s=u.cc*c,f=`PLG-VL CH${c+1} `;t.subarray(2).forEach((o,n)=>{let l=n+i;switch(l){case 1:{console.info(`${f}breath mode: ${["system","breath","velocity","touch EG"][o]}`);break}case 0:case 27:case 28:break;default:if(l<27){let y=l-3>>1,m=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][y];l&1?l<23?(console.debug(`${f}${m} control source: ${re(o)}`),o&&o<96&&e.allocateAce(130+y),e.#V[u.redir*c+y+2]=o,e.buildRccMap()):console.debug(`${f}${m} scale break point: ${o}`):(console.debug(`${f}${m} depth: ${o-64}`),e.#e[s+h[130+y]]=o)}}})}).add([76,10],t=>{}).add([76,16],t=>{}).add([76,17,0,0],t=>{}).add([76,112],t=>{switch(console.debug(`XG enable PLG-${["VL","SG","DX","AN","PF","DR","PC","AP"][t[0]]} for CH${t[2]+1}.`),t[0]){case 0:{e.#M[u.ext*t[2]]=e.EXT_VL;break}default:e.#M[u.ext*t[2]]=e.EXT_NONE}}).add([73,0,0],(t,a)=>{let c=t[0],i="MU1000 System: ";t.subarray(1).forEach((s,f)=>{let o=c+f;o==8?console.debug(`${i}LCD contrast set to ${s}.`):o==18?(e.#k=s?126:0,console.debug(`${i}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):o>=64&&o<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")},()=>{e.#x=!!s,console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][o-64]()})}).add([73,10,0],(t,a)=>{let c=t[0],i=`MU1000 RS${e.#x?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let s=e.chRedir(0,a,!0);e.#x&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${i}Show CH1~64`);break}case 3:{let s=e.chRedir(t[1]<<5,a,!0);e.#x&&e.dispatchEvent("channelmin",s),e.#x&&e.dispatchEvent("channelmax",s+31),console.info(`${i}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${i}unknown switch ${c} invoked.`)}else if(c<32){if(e.#x){let s=e.chRedir(c-16+(e.#re<<4),a,!0);e.dispatchEvent("channelactive",s)}}else if(c<36){let s=e.chRedir(c-32<<4,a,!0);e.#x&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),e.#re=c-32),console.info(`${i}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(t,a)=>{let c=e.chRedir(t[0],a,!0),i=`PLG-100SG CH${c+1} `,s=Date.now();if(t[1]==0){let f="",o=0;t.subarray(2).forEach((n,l)=>{l%2==0?f+=te[n]||n.toString().padStart("0"):o+=n*13}),s>=e.#ae&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${ae(f)}`,amend:!0}),e.#ae=s+Math.ceil(o/2)+e.#te,v()&&console.debug(`${i}vocals: ${f}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}).add([100,0],(t,a,c)=>{let i=t.subarray(0,t.length-1),s=D(i),f=t[t.length-1];if(s!=f){console.warn(`Yamaha DX7 dump SysEx checksum mismatch! Expected ${s}, but got ${f}: -`,t);return}else r.run(i)}),r.add([0,14,31],t=>{e.#e[u.cc*t[0]+h[64]]=0,e.#l.ano(t[0]),e.switchMode("xg"),console.debug(`Yamaha DX7+ reset CH${t[0]+1}.`)}).add([56,76,112],async t=>{let a=t[0],c="";t.subarray(1).forEach((i,s)=>{s<10&&(c+=String.fromCharCode(Math.max(i,32)))}),e.#i[a]=a&127,e.#e[u.cc*a+h[0]]=35,e.#e[u.cc*a+h[32]]=a>>7|2,e.dispatchEvent("voice",{part:a}),c.length>0&&(c=c.trimRight(),console.debug(`DX7+ CH${a+1} dumped voice name: "${c}"`))});let p=function(t,a,c,i){},b=function(t,a){let c=t*u.dpn,i=a[0],s=a[1];a.subarray(2).forEach((f,o)=>{let n=o+s,l=-1;n<16?([()=>{l=24},()=>{l=25},()=>{l=26},()=>{},()=>{l=28},()=>{l=29},()=>{l=30},()=>{l=31},()=>{},()=>{},()=>{},()=>{l=20},()=>{l=21},()=>{l=22},()=>{l=23},()=>{}][n]||(()=>{console.debug(`Unknown XG-style drum param ${n} on set ${t+1}.`)}))():n<32||(n<40?([()=>{l=48},()=>{l=49},!1,!1,()=>{l=52},()=>{l=53}][n-32]||(()=>{console.debug(`Unknown XG-style drum param ${n} on set ${t+1}.`)}))():n<80||([()=>{l=36}][n-80]||(()=>{console.debug(`Unknown XG-style drum param ${n} on set ${t+1}.`)}))()),l>=0?(v()&&console.debug(c,l,i,f),e.#y[(c+T[l])*u.dnc+i]=f):v()&&console.debug(`XG-style drum param ${n} has no writes.`)})},E=function(t,a,c){let i=t*u.dpn,s=(a<<7)+c[0];c.subarray(1).forEach((f,o)=>{let n=o+s,l=n&127,y=n>>7,m=-1;y>1&&([()=>{m=26},()=>{},()=>{m=28},()=>{m=29},()=>{m=30},()=>{},()=>{},()=>{m=31}][y-2]||(()=>{console.debug(`Unknown GS-style drum param ${y} on set ${t+1}.`)}))(),m>-1?(v()&&console.debug(i,m,l,f),e.#y[(i+T[m])*u.dnc+l]=f):v()&&console.debug(`GS-style drum param ${y} has no writes.`)})};this.#w.add([76,48],(t,a,c)=>{b(0,t)}).add([76,49],(t,a,c)=>{b(1,t)}).add([76,50],(t,a,c)=>{b(2,t)}).add([76,51],(t,a,c)=>{b(3,t)}).add([76,52],(t,a,c)=>{b(4,t)}).add([76,53],(t,a,c)=>{b(5,t)}).add([76,54],(t,a,c)=>{b(6,t)}).add([76,55],(t,a,c)=>{b(7,t)}),this.#w.add([89,0],(t,a,c)=>{if(e.eprom){let i=t[0],s=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);v()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${i} bytes.`);let f=e.eprom.data;t.subarray(4).forEach((o,n)=>{let l=n>>3,y=n&7;if(y==7)for(let m=0;m<7;m++)f[s+7*l+m]+=(o>>6-m&1)<<7;else f[s+7*l+y]=o})}}).add([89,1],(t,a,c)=>{let i=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];v()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(t,a,c)=>{if(e.eprom){let i=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);v()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;t.subarray(4).forEach((f,o)=>{let n=o>>3,l=o&7;if(l==7)for(let y=0;y<7;y++)s[i+7*n+y]+=(f>>6-y&1)<<7;else s[i+7*n+l]=f})}}).add([89,3],(t,a,c)=>{}),this.#w.add([39,48],(t,a,c)=>{}).add([43,0,0],(t,a,c)=>{let i=[0,0,0,0],s=(f,o)=>{i[o]=f};if(t.subarray(1).forEach((f,o)=>{let n=o+t[0];[s,s,s,s,()=>{this.#c=f*129/16383*100,e.dispatchEvent("mastervolume",e.#c)},()=>f-64,()=>f||128,()=>f,()=>f,()=>{console.debug(`TG300 variation on cc${f}.`)}][n](f,n)}),t[0]<4){let f=0;i.forEach(o=>{f=f<<4,f+=o}),f-=1024}}).add([43,1,0],(t,a,c)=>{}).add([43,2],(t,a,c)=>{let i=e.chRedir(t[0],a,!0),s=t[1],f=u.cc*i,o=`TG300 CH${i+1} `;t.subarray(2).forEach((n,l)=>{l<5?([()=>{},()=>{e.#e[f+h[0]]=n,e.dispatchEvent("voice",{part:i})},()=>{e.#e[f+h[32]]=n,e.dispatchEvent("voice",{part:i})},()=>{e.#i[i]=n,e.dispatchEvent("voice",{part:i})},()=>{let y=e.chRedir(n,a,!0);e.#h[i]=y,i!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))}][l+s]||(()=>{}))(n,l+s):l<21||(l<47?([()=>{e.#E[i]=+!n},()=>{},()=>{},()=>{e.#a[u.rpn*i+3]=n,e.#s[u.rpnt*i+2]=1},()=>{},()=>{e.#e[f+h[7]]=n},!1,!1,()=>{e.#e[f+h[10]]=n||128},!1,!1,()=>{console.debug(`${o} AC1 at cc${n}`)},()=>{console.debug(`${o} AC2 at cc${n}`)},()=>{e.#e[f+h[128]]=n},()=>{e.#e[f+h[93]]=n},()=>{e.#e[f+h[91]]=n},()=>{e.#e[f+h[94]]=n},()=>{e.#e[f+h[76]]=n},()=>{e.#e[f+h[77]]=n},()=>{e.#e[f+h[74]]=n},()=>{e.#e[f+h[71]]=n},()=>{e.#e[f+h[73]]=n},()=>{e.#e[f+h[75]]=n},()=>{e.#e[f+h[72]]=n},()=>{e.#e[f+h[78]]=n}][l+s-21]||(()=>{}))(n,l+s):l<95||([()=>{e.#e[f+h[65]]=n},()=>{e.#e[f+h[5]]=n}][l+s-95]||(()=>{}))(n,l+s))})}).add([43,7,0],(t,a,c)=>{let i=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",i)}).add([43,7,1],(t,a,c)=>{e.#b=0,e.#C=Date.now()+3200,e.#g.fill(0),t.forEach(function(i,s){let f=Math.floor(s/16),o=s%16,n=(o*3+f)*7,l=7,y=0;for(n-=o*5,f==2&&(l=2);y>6-y&1,y++})}),this.#v.add([66,18,0,0,127],(t,a,c)=>{e.switchMode("gs",!0),e.#e[u.cc*9]=120,e.#e[u.cc*25]=120,e.#e[u.cc*41]=120,e.#e[u.cc*57]=120,e.#k=3,e.#n=!1,e.#U.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,a,c)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[u.cc*9]=120,e.#e[u.cc*25]=120,e.#e[u.cc*41]=120,e.#e[u.cc*57]=120,e.#n=!1,e.#U.fill(0),console.info("MIDI reset: GS");break}default:{let i=[0,0,0,0],s=(f,o)=>{i[o]=f};if(t.subarray(1).forEach((f,o)=>{let n=o+t[0];[s,s,s,s,l=>{this.#c=l*129/16383*100,e.dispatchEvent("mastervolume",e.#c)},l=>{},l=>{}][n](f,o)}),t[0]<4){let f=0;i.forEach(o=>{f=f<<4,f+=o}),f-=1024}}}}).add([66,18,64,1],t=>{let a=t[0];if(a<16){let c="".padStart(a," ");t.subarray(1).forEach((i,s)=>{c+=String.fromCharCode(Math.max(32,i))}),c=c.padEnd(16," "),console.debug(`GS patch name: ${c}`)}else a<48||(a<65?t.subarray(1).forEach((c,i)=>{let s=`GS ${a+i>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${F[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${c}ms`)},()=>{console.info(`${s}type: ${se[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${x(c)}`)},()=>{console.debug(`${s}to delay: ${x(c)}`)}][a+i-48]||(()=>{}))()}):a<80?console.debug(`Unknown GS patch address: ${a}`):a<91?t.subarray(1).forEach((c,i)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${ie[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${x(c)}`)}][a+i-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${a}`))}).add([66,18,64,2],t=>{let a="GS EQ ";t.subarray(1).forEach((c,i)=>{([()=>{console.debug(`${a}low freq: ${[200,400][c]}Hz`)},()=>{console.debug(`${a}low gain: ${c-64}dB`)},()=>{console.debug(`${a}high freq: ${[3e3,6e3][c]}Hz`)},()=>{console.debug(`${a}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 a="GS EFX ",c=function(i,s){let f=ce(e.#$.subarray(10,12),s,i);f&&console.debug(`${a}${K(e.#$.subarray(10,12))} ${f}`)};t.subarray(1).forEach((i,s)=>{([()=>{e.setEffectTypeRaw(3,!1,32+i),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,i),console.info(`${a}type: ${K(e.#$.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(`${a}to reverb: ${x(i)}dB`)},()=>{console.debug(`${a}to chorus: ${x(i)}dB`)},()=>{console.debug(`${a}to delay: ${x(i)}dB`)},!1,()=>{console.debug(`${a}1 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${a}1 depth: ${i-64}`)},()=>{console.debug(`${a}2 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${a}2 depth: ${i-64}`)},()=>{console.debug(`${a}to EQ: ${i?"ON":"OFF"}`)}][t[0]+s]||function(f,o){console.warn(`Unknown GS EFX address: ${o}`)})(i,t[0]+s)})}).add([66,18,65],t=>{E((t[0]>>4)+1<<1,t[0]&15,t.subarray(1))}).add([69,18,16],t=>{switch(t[0]){case 0:{let a=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",a);break}case 32:{e.#C=Date.now()+3200,t[1]==0&&(e.#b=Math.max(Math.min(t[2]-1,9),0),v()&&console.debug(`GS switch display page ${t[2]-1}.`));break}default:if(t[0]<6){e.#b>9&&(e.#b=0);let a=t[0]-1<<1|t[1]>>6;e.#b==a&&(e.#C=Date.now()+3200),e.#D[a]?.length||(e.#D[a]=new Uint8Array(256));let c=e.#D[a];v()&&console.debug(`GS frame draw page ${a}.`);let i=t[1]&63;c.fill(0),t.subarray(2).forEach(function(f,o){let n=o+i,l=Math.floor(n/16),y=n%16,m=(y*4+l)*5,w=5,S=0;for(m-=y*4,l==3&&(w=1);S>4-S&1,S++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let g=function(t,a,c){let i=t[0],s=u.cc*a,f=u.rpn*a,o=`GS CH${a+1} `;i<3?(t.subarray(1).forEach((n,l)=>{[()=>{e.#e[s+h[0]]=n},()=>{e.#i[a]=n},()=>{let y=0;n<16?y=e.chRedir(n,c,!0):y=u.ch,e.#h[a]=y,a!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))}][i+l]()}),e.dispatchEvent("voice",{part:a})):i<19||(i<44?t.subarray(1).forEach((n,l)=>{([()=>{e.#E[a]=+!n},!1,()=>{e.setChType(a,n<<1,k.gs),console.debug(`${o}type: ${n?"drum ":"melodic"}${n||""}`)},()=>{e.#a[f+3]=n,e.#s[u.rpnt*a+2]=1},!1,()=>{e.#e[s+h[7]]=n},!1,!1,()=>{e.#e[s+h[10]]=n||128},!1,!1,()=>{console.debug(`${o}CC 1: cc${n}`)},()=>{console.debug(`${o}CC 2: cc${n}`)},()=>{e.#e[s+h[93]]=n},()=>{e.#e[s+h[91]]=n},!1,!1,()=>{e.#a[f+1]=n,e.#s[u.rpnt*a+1]=1},()=>{e.#a[f+2]=n,e.#s[u.rpnt*a+1]=1},()=>{e.#e[s+h[94]]=n}][i+l-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},$=function(t,a){let c=t[0],i=`GS CH${a+1} `;c<2?t.subarray(1).forEach((s,f)=>{[()=>{e.#e[u.cc*a+h[32]]=s},()=>{}][c+f]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?t.subarray(1).forEach((s,f)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][s]}`),e.#Z[a]=s,e.dispatchEvent("partefxtoggle",{part:a,active:s})}][c+f-32]()}):console.warn(`Unknown GS misc address: ${c}`)};this.#v.add([66,18,64,16],(t,a)=>{g(t,e.chRedir(9,a,!0),a)}).add([66,18,64,17],(t,a)=>{g(t,e.chRedir(0,a,!0),a)}).add([66,18,64,18],(t,a)=>{g(t,e.chRedir(1,a,!0),a)}).add([66,18,64,19],(t,a)=>{g(t,e.chRedir(2,a,!0),a)}).add([66,18,64,20],(t,a)=>{g(t,e.chRedir(3,a,!0),a)}).add([66,18,64,21],(t,a)=>{g(t,e.chRedir(4,a,!0),a)}).add([66,18,64,22],(t,a)=>{g(t,e.chRedir(5,a,!0),a)}).add([66,18,64,23],(t,a)=>{g(t,e.chRedir(6,a,!0),a)}).add([66,18,64,24],(t,a)=>{g(t,e.chRedir(7,a,!0),a)}).add([66,18,64,25],(t,a)=>{g(t,e.chRedir(8,a,!0),a)}).add([66,18,64,26],(t,a)=>{g(t,e.chRedir(10,a,!0),a)}).add([66,18,64,27],(t,a)=>{g(t,e.chRedir(11,a,!0),a)}).add([66,18,64,28],(t,a)=>{g(t,e.chRedir(12,a,!0),a)}).add([66,18,64,29],(t,a)=>{g(t,e.chRedir(13,a,!0),a)}).add([66,18,64,30],(t,a)=>{g(t,e.chRedir(14,a,!0),a)}).add([66,18,64,31],(t,a)=>{g(t,e.chRedir(15,a,!0),a)}).add([66,18,64,64],(t,a)=>{$(t,e.chRedir(9,a,!0))}).add([66,18,64,65],(t,a)=>{$(t,e.chRedir(0,a,!0))}).add([66,18,64,66],(t,a)=>{$(t,e.chRedir(1,a,!0))}).add([66,18,64,67],(t,a)=>{$(t,e.chRedir(2,a,!0))}).add([66,18,64,68],(t,a)=>{$(t,e.chRedir(3,a,!0))}).add([66,18,64,69],(t,a)=>{$(t,e.chRedir(4,a,!0))}).add([66,18,64,70],(t,a)=>{$(t,e.chRedir(5,a,!0))}).add([66,18,64,71],(t,a)=>{$(t,e.chRedir(6,a,!0))}).add([66,18,64,72],(t,a)=>{$(t,e.chRedir(7,a,!0))}).add([66,18,64,73],(t,a)=>{$(t,e.chRedir(8,a,!0))}).add([66,18,64,74],(t,a)=>{$(t,e.chRedir(10,a,!0))}).add([66,18,64,75],(t,a)=>{$(t,e.chRedir(11,a,!0))}).add([66,18,64,76],(t,a)=>{$(t,e.chRedir(12,a,!0))}).add([66,18,64,77],(t,a)=>{$(t,e.chRedir(13,a,!0))}).add([66,18,64,78],(t,a)=>{$(t,e.chRedir(14,a,!0))}).add([66,18,64,79],(t,a)=>{$(t,e.chRedir(15,a,!0))}),this.#N.add([54,65],(t,a)=>{e.switchMode("x5d");let c=t[t.length-1],i=t.subarray(0,t.length-1),s=D(i);s!=c&&(console.info(`X5D multi parameters checksum mismatch! Expected ${s}, got ${c}.`),console.debug(t));let f=(t[1]<<7)+t[0],o=(t[3]<<7)+t[2],n=e.chRedir(f&15,a,!0),l=u.cc*n;[()=>{o<1||(o<101?(e.setChType(n,e.CH_MELODIC,k.x5d),e.#i[n]=o-1,e.#e[l+h[0]]=e.#o.x5):o<229?(e.setChType(n,e.CH_MELODIC,k.x5d),e.#i[n]=o-101,e.#e[l+h[0]]=56):(e.setChType(n,e.CH_DRUMS,k.x5d),e.#i[n]=pe[o-229]||0,e.#e[l+h[0]]=62)),e.dispatchEvent("voice",{part:n})},()=>{e.#e[l+h[7]]=o},()=>{o<31&&(e.#e[l+h[10]]=Math.round((o-15)*4.2+64))},()=>{e.#e[l+h[93]]=P(o)},()=>{e.#e[l+h[91]]=P(o)},()=>{e.#a[n*u.rpn+3]=o>8191?o-16320:64+o,e.#s[u.rpnt*n+2]=1},()=>{e.#a[n*u.rpn+1]=o>8191?o-16320:64+o,e.#s[u.rpnt*n+1]=1},()=>{o>0&&(e.#a[n*u.rpn]=o,e.#s[u.rpnt*n]=1)},()=>{}][f>>4]()}).add([54,76,0],(t,a)=>{e.switchMode(e.#o.x5=="81"?"05rw":"x5d",!0);let c="",i=e.#o.x5,s=0,f=0,o="MSB PRG LSB NME";M(t,function(n,l){if(l<16400){let y=l%164;switch(!0){case y<10:{n>31&&(c+=String.fromCharCode(n));break}case y==10:break;case y==11:{o+=` -${i} ${s} ${f} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}s>99&&(i=90,s=0)}}),e.userBank.clearRange({msb:e.#o.x5,prg:[0,99],lsb:0}),e.userBank.load(o),v()&&console.debug(o),e.forceVoiceRefresh()}).add([54,77,0],(t,a)=>{e.switchMode(e.#o.x5=="81"?"05rw":"x5d",!0);let c="",i=90,s=0,f=0,o="MSB PRG LSB NME";M(t,function(n,l){if(l<13600){let y=l%136;switch(!0){case y<10:{n>31&&(c+=String.fromCharCode(n));break}case y==11:{o+=` -${i} ${s} ${f} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(o),v()&&console.debug(o),e.forceVoiceRefresh()}).add([54,78],(t,a)=>{e.switchMode(e.#o.x5=="81"?"05rw":"x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][t[0]]} mode.`)}).add([54,85],(t,a)=>{e.switchMode(e.#o.x5=="81"?"05rw":"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,a)=>{e.switchMode(e.#o.x5=="81"?"05rw":"x5d",!0),M(t,function(c,i,s,f){if(i<192){let o=e.chRedir(Math.floor(i/12),a,!0),n=o*u.cc;switch(i%12){case 0:{c<128?(e.setChType(o,e.CH_MELODIC,k.x5d),e.#e[n+h[0]]=e.#o.x5,e.#i[o]=c):(e.setChType(o,e.CH_DRUMS,k.x5d),e.#e[n+h[0]]=62,e.#i[o]=pe[c-128]),c>0&&e.setChActive(o,1),e.dispatchEvent("voice",{part:o});break}case 1:{e.#e[n+h[7]]=c;break}case 2:{e.#a[o*u.rpn+3]=c>127?c-192:64+c,e.#s[u.rpnt*o+2]=1;break}case 3:{e.#a[o*u.rpn+1]=c>127?c-192:64+c,e.#s[u.rpnt*o+1]=1;break}case 4:{c<31&&(e.#e[n+h[10]]=Math.round((c-15)*4.2+64));break}case 5:{let l=c>>4,y=c&15;e.#e[n+h[91]]=P(y),e.#e[n+h[93]]=P(l);break}case 10:break;case 11:{let l=e.chRedir(c&15,a,!0),y=c>>4;e.#h[o]=c,(l!=o||y)&&(console.info(`X5D Part CH${o+1} receives from CH${l+1}.`),e.buildRchTree())}}}else{let o=e.chRedir(i-192,a,!0)}})}),this.#v.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,a,c)=>{e.switchMode("mt32");let i=e.chRedir(c,a,!0),s=t[1];t.subarray(2).forEach((f,o)=>{let n=o+s;e.#P[n+(i-1)*16]=f,([!1,()=>{let l=e.#P[i-1<<4];if(l<3){if(e.#R[i]=1,l==2)for(let y=0;y{e.#a[i*u.rpn+3]=f+40,e.#s[u.rpnt*i+2]=1},()=>{e.#a[i*u.rpn+1]=f+14,e.#s[u.rpnt*i+1]=1},()=>{e.#a[i*u.rpn]=f,e.#s[u.rpnt*i]=1},!1,()=>{e.#e[u.cc*i+h[91]]=f?127:0},!1,()=>{e.#e[u.cc*i+h[7]]=f},()=>{e.#e[u.cc*i+h[10]]=Math.ceil(f*9.05)}][n]||(()=>{}))()})}).add([22,18,1],(t,a,c)=>{e.switchMode("mt32");let i=c&7;console.debug(`MT-32 slot #${c+1} Drum: ${t}`);let s=t[0]<<7|t[1];t.subarray(2).forEach((f,o)=>{let n=o+s,l=(n>>2)+24,y=n&3,m=i*u.dpn;if(v()&&console.debug(`MT-32 temp drum note ${l} param ${y}: ${f}`),l<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${l}`);return}[()=>{},()=>{e.#y[(m+T[26])*u.dnc+l]=Math.round(f*1.27)},()=>{e.#y[(m+T[26])*u.dnc+l]=f*9+1&127},()=>{e.#y[(m+T[26])*u.dnc+l]=f?127:0}][y]()})}).add([22,18,2],(t,a,c)=>{e.switchMode("mt32");let i=e.chRedir(c,a,!0),s=t[1]+(t[0]<<7);s<10&&(e.#R[i]=1),t.subarray(2).forEach((f,o)=>{let n=o+s;n<14&&(e.#S[(i-1)*u.cmt+n]=f)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(t,a,c)=>{e.switchMode("mt32");let i=c&7;if(t[0]){let s=(t[0]-1<<7)+t[1]-16;t.subarray(2).forEach((f,o)=>{let n=o+s,l=(n>>2)+24,y=n&3,m=i*u.dpn;if(v()&&console.debug(`MT-32 dev drum note ${l} param ${y}: ${f}`),l<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${l}`);return}[()=>{},()=>{e.#y[(m+T[26])*u.dnc+l]=Math.round(f*1.27)},()=>{e.#y[(m+T[26])*u.dnc+l]=f*9+1&127},()=>{e.#y[(m+T[26])*u.dnc+l]=f?127:0}][y]()})}else{let s=t[1];t.subarray(2).forEach((f,o)=>{let n=o+s;e.#P[n]=f;let l=e.chRedir(1+(n>>4),a,!0),y=n&15;([!1,()=>{let m=e.#P[l-1<<4];if(m<3)if(e.#R[l]=1,m==2)for(let w=0;w{e.#a[l*u.rpn+3]=f+40,e.#s[u.rpnt*l+2]=1},()=>{e.#a[l*u.rpn+1]=f+14,e.#s[u.rpnt*l+1]=1},()=>{e.#a[l*u.rpn]=f,e.#s[u.rpnt*l]=1},!1,()=>{e.#e[u.cc*l+h[91]]=f?127:0},!1,()=>{e.#e[u.cc*l+h[7]]=f},()=>{e.#e[u.cc*l+h[10]]=Math.ceil(f*9.05)}][y]||(()=>{}))()})}}).add([22,18,4],(t,a,c)=>{e.switchMode("mt32");let i=t[1]+(t[0]<<7),s=[];t.subarray(2).forEach((f,o)=>{let n=o+i,l=e.chRedir(Math.floor(n/246+1),a,!0),y=n%246;y<14&&(e.#S[(l-1)*u.cmt+y]=f),y<10&&(e.#R[l]=1),s.indexOf(l)<0&&s.push(l)}),s.forEach(f=>{e.dispatchEvent("voice",{part:f})})}).add([22,18,5],(t,a,c)=>{e.switchMode("mt32");let i=(t[0]<<7)+t[1];t.subarray(2).forEach((s,f)=>{let o=i+f,n=Math.floor(o/8),l=o&7,y=n*8;e.#ee[o]=s,([!1,()=>{let m=e.#ee[y];if(m<3){let w="";if(m==2){let q=u.cmt*n;w=`MT-m:${s.toString().padStart(3,"0")}`}else w=e.baseBank.get(0,s+(m<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:n});let S=`MSB LSB PRG NME -000 127 ${n} ${w}`;e.userBank.load(S,!0)}}][l]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(t,a,c)=>{e.switchMode("mt32");let i=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((s,f)=>{let o=i+f;o>1)*u.cmt+o]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(t,a,c)=>{e.switchMode("mt32");let i=t[1],s=!1,f=function(o,n){e.#h[n-12]=o,s=!0};t.subarray(2).forEach((o,n)=>{let l=n+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,f,f,f,f,f,f,f,f,f,()=>{e.#c=o,e.dispatchEvent("mastervolume",e.#c)}][l]||(()=>{}))(o,n)}),s&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let a=t[1],c=" ".repeat(a);t.subarray(2).forEach(i=>{i>31?c+=String.fromCharCode(i):c+=" "}),e.#B=c.padStart(20," "),e.#_=Date.now()+3200}).add([22,18,82],(t,a)=>{let c=e.chRedir(0,a,!0);for(let i=0;i<16;i++)e.#l.ano(c+i),i&&i<10&&(e.#i[c+i]=z[i-1]);console.info("MT-32 alt reset complete.")}),this.#N.add([66,0],(t,a)=>{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,a)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#n=!1}).add([66,18,0,0],(t,a)=>{let c=t[0];switch(c){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#n=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${t}`);break}default:if(c<10){let i=[0,0,0,0],s=(f,o)=>{i[o]=f};if(t.subarray(1).forEach((f,o)=>{[s,s,s,s,()=>{e.#c=f*129/16383*100,e.dispatchEvent("mastervolume",e.#c)},()=>f-64,()=>f-64,()=>{},()=>{},()=>{}][c+o]()}),t[0]<4){let f=0;i.forEach(o=>{f=f<<4,f+=o}),f-=1024}}}}).add([66,18,0,1],(t,a)=>{}).add([66,18,0,2],(t,a)=>{}).add([66,18,1],(t,a)=>{let c=e.chRedir(t[0],a,!0),i=c*u.cc,s=t[1],f=`NS5R CH${c+1} `;t.subarray(2).forEach((o,n)=>{let l=s+n;l<3?([()=>{e.#e[i+h[0]]=o||H.bank0},()=>{e.#e[i+h[32]]=o},()=>{e.#i[c]=o}][l](),e.dispatchEvent("voice",{part:c})):l<8||(l<14?[()=>{let y=e.chRedir(o,a,!0);e.#h[c]=y,c!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))},()=>{e.#E[c]=+!o},()=>{e.setChType(c,o,k.ns5r),console.debug(`${f}type: ${N[o]}`)},()=>{e.#a[u.rpn*c+3]=o,e.#s[u.rpnt*c+2]=1},()=>{},()=>{}][l-8]():l<16||(l<33?[()=>{e.#e[i+h[7]]=o},()=>{e.#e[i+h[11]]=o},()=>{},()=>{},()=>{e.#e[i+h[10]]=o||128},()=>{},()=>{},()=>{e.#e[i+h[93]]=o},()=>{e.#e[i+h[91]]=o},()=>{e.#e[i+h[76]]=o},()=>{e.#e[i+h[77]]=o},()=>{e.#e[i+h[78]]=o},()=>{e.#e[i+h[74]]=o},()=>{e.#e[i+h[71]]=o},()=>{e.#e[i+h[73]]=o},()=>{e.#e[i+h[75]]=o},()=>{e.#e[i+h[72]]=o}][l-16]():l<112||l<114&&[()=>{e.#e[i+h[5]]=o},()=>{e.#e[i+h[65]]=o}][l-112]()))})}).add([66,18,8,0],(t,a)=>{let c=t[0];if(c<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let i=c-32;e.#C=Date.now()+3200,e.#b=10,e.#g.fill(0);let s=t.subarray(1),f=4;s.forEach(function(o,n){let l=n+i,y=l>>4,m=l&15;if(l<80){let w=y>3,S=0,q=y0;)e.#g[m*32+y*7+(q-S)]=w&1,w=w>>1,S++}})}}).add([66,18,48],(t,a,c)=>{b(0,t)}).add([66,18,49],(t,a,c)=>{b(1,t)}).add([66,18,50],(t,a,c)=>{b(2,t)}).add([66,18,51],(t,a,c)=>{b(3,t)}).add([66,18,52],(t,a,c)=>{b(4,t)}).add([66,18,53],(t,a,c)=>{b(5,t)}).add([66,18,54],(t,a,c)=>{b(6,t)}).add([66,18,55],(t,a,c)=>{b(7,t)}).add([66,52],(t,a)=>{e.switchMode("ns5r",!0),e.#n=!1;let c="";M(t,(i,s)=>{s<8?(i>31&&(c+=String.fromCharCode(i)),s==7&&(e.aiEfxName=c)):s<10&&(e.setEffectType(s-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(t,a)=>{e.switchMode("ns5r",!0),e.#n=!1;let c="",i=t[t.length-1],s=t.subarray(0,t.length-1),f=D(s);f!=i&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${f}, got ${i}.`),console.debug(t)),M(s,function(o,n){switch(!0){case n<2944:{let l=e.chRedir(Math.floor(n/92),a,!0),y=l*u.cc;switch(n%92){case 0:{e.#e[y+h[0]]=o,e.dispatchEvent("voice",{part:l});break}case 1:{e.#e[y+h[32]]=o,!o&&!e.#e[y+h[0]]&&(e.#e[y+h[0]]=H.bank0),e.dispatchEvent("voice",{part:l});break}case 2:{e.#i[l]=o,o>0&&e.setChActive(l,1),e.dispatchEvent("voice",{part:l});break}case 3:{let m=e.chRedir(o,a,!0);e.#h[l]=m,l!=m&&(console.info(`NS5R CH${l+1} receives from CH${m+1}.`),e.buildRchTree());break}case 7:{e.#r[l]=o,e.dispatchEvent("voice",{part:l});break}case 8:{e.#a[l*u.rpn+3]=o<40||o>88?o+(o>63?-192:64):o,e.#s[u.rpnt*l+2]=1;break}case 9:case 10:{e.#e[y+h[7]]=o;break}case 11:{e.#e[y+h[11]]=o;break}case 14:{e.#e[y+h[10]]=o||128;break}case 19:{e.#e[y+h[93]]=o;break}case 20:{e.#e[y+h[91]]=o;break}case 84:{e.#e[y+h[65]]=o;break}case 85:{e.#e[y+h[5]]=o;break}}break}case n<3096:break;case n<3134:{let l=n-3096;l<8?(o>31&&(c+=String.fromCharCode(o)),l==7&&(e.aiEfxName=c)):l<10&&(e.setEffectType(l-8,44,o),e.dispatchEvent(`efx${["reverb","chorus"][l-8]}`,e.getEffectType(l-8)));break}case n<8566:break}})}).add([66,54],(t,a)=>{e.switchMode("ns5r",!0);let c="",i=80,s=0,f=0,o="MSB PRG LSB NME";M(t,function(n,l){let y=l%158;switch(!0){case y<10:{n>31&&(c+=String.fromCharCode(n));break}case y==10:break;case y==11:{i=n&127;break}case y==12:{f=n&127;break}case y==13:{o+=` -${i} ${s} ${f} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(o),v()&&console.debug(o),e.forceVoiceRefresh()}).add([66,55],(t,a)=>{e.switchMode("ns5r",!0);let c="",i=88,s=0,f=0,o="MSB PRG LSB NME";M(t,function(n,l){let y=l%126;switch(!0){case y<10:{n>31&&(c+=String.fromCharCode(n));break}case y==11:break;case y==12:break;case y==13:{o+=` -${i} ${s} ${f} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(o),v()&&console.debug(o),e.forceVoiceRefresh()}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let a=t[t.length-1],c=t.subarray(0,t.length-1),i=D(c);i!=a&&(console.info(`NS5R screen dump checksum mismatch! Expected ${i}, got ${a}.`),console.debug(t));let s=new Uint8Array(5760);M(t,(f,o,n)=>{if(o<720)for(let l=0;l<8;l++)s[o*8+l]=f>>7-l&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(t,a,c)=>{e.#N.run([66,...t],a,c)}),this.#Y.add([16,0,8,0],(t,a,c)=>{let i=(t[2]<<4)+t[3],s="K11 ";([()=>{e.switchMode("k11",!0),e.#n=!1,e.#k=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}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,a,c)=>{let i=e.chRedir(t[1],a,!0),s=u.cc*i,f=u.rpn*i,o=(t[3]<<4)+t[4],n=`K11 CH${i+1} `;([()=>{o<128?(e.setChType(i,e.CH_MELODIC,k.k11),e.#e[s+h[0]]=0,e.#i[i]=o):(e.setChType(i,e.CH_DRUMS,k.k11),e.#i[i]=o-128),e.dispatchEvent("voice",{part:i})},()=>{let l=e.chRedir(o,a,!0);e.#h[i]=l,i!=l&&(e.buildRchTree(),console.info(`${n}receives from CH${l+1}`))},()=>{e.#e[s+h[7]]=o},()=>{uupThis.setChActive(i,o)},()=>{e.#e[s+h[10]]=o},()=>{e.#a[f+3]=o+40,e.#s[u.rpnt*i+2]=1},()=>{e.#a[f+1]=o>>1,e.#a[f+2]=o&1,e.#s[u.rpnt*i+1]=1},()=>{e.#e[s+h[91]]=o?127:0},()=>{},()=>{e.#e[s+h[74]]=o},()=>{e.#e[s+h[73]]=o},()=>{e.#e[s+h[72]]=o}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,a,c)=>{let i=(t[2]<<4)+t[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}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,a,c)=>{let i=(t[2]<<4)+t[3],s=e.chRedir(t[1],a,!0),f=s*u.cc;[()=>{i<128?(e.setChType(s,e.CH_MELODIC,k.k11),e.#e[f+h[0]]=0,e.#e[f+h[32]]=0,e.#i[s]=i):i<160?(e.setChType(s,e.CH_MELODIC,k.k11),e.#e[f+h[0]]=0,e.#e[f+h[32]]=7,e.#i[s]=i-100):(e.setChType(s,e.CH_DRUMS,k.k11),e.#e[f+h[0]]=122,e.#e[f+h[32]]=0,e.#i[s]=i-160),e.dispatchEvent("voice",{part:s})},()=>{let o=e.chRedir(i,a,!0);e.#h[s]=o,s!=o&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${o+1}`))}][t[0]]()}).add([16,0,9,4],(t,a,c)=>{let i=(t[2]<<4)+t[3],s=e.chRedir(t[1],a,!0),f=s*u.cc,o=s*u.rpn,n=`GMLX CH${s+1} `;[()=>{e.setChActive(s,i)},()=>{e.#e[f+h[7]]=i},()=>{e.#e[f+h[10]]=i},()=>{e.#e[f+h[91]]=i?127:0},()=>{e.#a[o+3]=i+40,e.#s[u.rpnt*s+2]=1},()=>{e.#a[o+1]=i,e.#s[u.rpnt*s+1]=1},()=>{e.#a[o]=i,e.#s[u.rpnt*s]=1},()=>{}][t[0]]()}),this.#W.add([66,93,64],(t,a,c)=>{let i=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{e.#c=i*129/16383*100,e.dispatchEvent("mastervolume",e.#c);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: ${F[i]}`);break}}break}default:if(t[0]>>4==1){let s=e.chRedir(t[0]&15,a,!0);if(t[1]==2){let f=e.chRedir(i,a,!0);e.#h[s]=f,s!=f&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${f+1}`))}else t[1]==19&&(e.#e[u.cc*s+h[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),this.#j.add([9],(t,a,c)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)}),this.#w.add([127,0],(t,a,c)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...t]);e.#w.run(i,a,c)}).add([127,1,0,0],(t,a,c)=>{e.switchMode("s90es");let i="S90/Motif ES system ",s=t[0];t.subarray(1).forEach((f,o)=>{([()=>{e.#c=f*12900/16383,e.dispatchEvent("mastervolume",e.#c)}][s+o]||(()=>{console.info(`Unrecognized ${i}ID: ${s+o}`)}))()})}).add([127,1,0,0,14],(t,a,c)=>{e.switchMode("s90es");let i="S90/Motif ES bulk header ",s=[];s[95]=(f,o,n)=>{console.debug(`${i}multi edit buffer: ${f[1]}`)},(s[t[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,0,15],(t,a,c)=>{e.switchMode("s90es");let i="S90/Motif ES bulk footer ",s=[];s[95]=(f,o,n)=>{console.debug(`${i}multi edit buffer: ${f[1]}`)},(s[t[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,58,55],(t,a,c)=>{e.switchMode("s90es");let i=e.chRedir(t[0],a,!0),s=u.cc*i,f=t[1],o=`S90/Motif ES bulk CH${i<16?i+1:"U"+(i-95)} `;console.debug(o,t),!(t[0]>15)&&t.subarray(2).forEach((n,l)=>{([()=>{e.#e[s+h[0]]=n,e.dispatchEvent("voice",{part:i})},()=>{n&&e.setChActive(i,1),e.#e[s+h[32]]=n,e.setChType(i,[32,40].indexOf(n)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:i})},()=>{n&&e.setChActive(i,1),e.#i[i]=n,e.dispatchEvent("voice",{part:i})},()=>{let y=e.chRedir(n,a,!0);e.#h[i]=y,i!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))},()=>{e.#E[i]=n?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{e.#e[s+h[7]]=n},()=>{e.#e[s+h[10]]=n},!1,!1,!1,()=>{e.#e[s+h[91]]=n},()=>{e.#e[s+h[93]]=n},()=>{e.#e[s+h[94]]=n},()=>{e.#e[s+h[128]]=n},()=>{},()=>{e.#e[s+h[74]]=n},()=>{e.#e[s+h[71]]=n},!1,()=>{e.#e[s+h[65]]=n},()=>{e.#e[s+h[5]]=n},()=>{}][f+l]||(()=>{}))()})}).add([127,1,54,16],(t,a,c)=>{e.switchMode("s90es");let i=t[0];t.subarray(1).forEach((s,f)=>{let n=`S90/Motif ES EQ${(f>>2)+1} `;([()=>{let l=s-64},()=>{let l=L[s]},()=>{let l=s/10},()=>{let l=s}][i+f&3]||(()=>{}))()})}),this.#v.add([0,72,18,0,0,0,0],(t,a,c)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(t,a,c)=>{let i=t[0]>>5,s=t[0]&31;switch(i){case 0:{let f=t[0]>>1,o=t[1];switch(f){case 1:{t.subarray(2).forEach((n,l,y)=>{let m=l+o;switch(m){case 0:{n&&(e.setEffectType(1,60,n-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${m} - ${n}`));break}}});break}case 2:{t.subarray(2).forEach((n,l)=>{let y=l+o;switch(y){case 0:{n&&(e.setEffectType(0,55+n,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${y} - ${n}`));break}}});break}case 3:case 4:case 5:{let n=f-1;t.subarray(2).forEach((l,y)=>{let m=y+o;switch(console.debug(`SD MFX ${n-2}: ${m} - ${l}`),m){case 0:{e.setEffectTypeRaw(n,62,l),e.dispatchEvent(`efx${n>2?"delay":"insert"+(n-4)}`,e.getEffectType(n));break}}}),console.debug(`SD MFX message: +`).forEach((a,c)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:a,mask:c!=0})})}},e.#p[2]=function(t){this.dispatchEvent("metacommit",{type:"Copyrite",data:t})},e.#p[3]=function(t,a){a<1&&this.#F<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:t})},e.#p[4]=function(t,a){this.dispatchEvent("metacommit",{type:"Instrmnt",data:t})},e.#p[5]=function(t){t.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:t,amend:!0})},e.#p[6]=function(t){this.dispatchEvent("metacommit",{type:"C.Marker",data:t})},e.#p[7]=function(t){this.dispatchEvent("metacommit",{type:"CuePoint",data:t})},e.#p[32]=function(t){this.#F=t[0]+1},e.#p[33]=function(t,a){e.#I[a]=t+1},e.#p[81]=function(t,a){e.#te=t/1e3},e.#p[127]=function(t,a){e.#z.run(t,a)},e.#z.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},e.#z.add([67,0,1],function(t,a){e.#I[a]=t[0]+1}),e.#q=new C("universal non-realtime"),e.#Q=new C("universal realtime"),e.#v=new C("Yamaha"),e.#S=new C("Roland"),e.#N=new C("Korg"),e.#Y=new C("Kawai"),e.#W=new C("Akai"),e.#j=new C("Casio");let r=new C("DX7+ Dump"),d=function(t){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,t)};e.#q.default=d,e.#Q.default=d,e.#v.default=d,e.#S.default=d,e.#N.default=d,e.#Y.default=d,e.#W.default=d,e.#j.default=d,r.default=d,e.#q.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()}),e.#Q.add([4,1],t=>{e.#c=((t[1]<<7)+t[0])/16383*100,e.dispatchEvent("mastervolume",e.#c)}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64).add([4,5],t=>{let a=t[0],c=t[1],i=t[2],s=3,f=s+(a<<1),o=f+c;if(a!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${a})! +`,t);return}let n=0,l=0,y=0;switch(t.subarray(s,f).forEach(m=>{n=n<<7,n|=m}),t.subarray(f,o).forEach((m,v)=>{l|=m<{y|=m<{switch(t[0]){case 125:{e.initDrums(),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 a=[0,0,0,0],c=(i,s)=>{a[s]=i};if(t.subarray(1).forEach((i,s)=>{let f=s+t[0];([c,c,c,c,o=>{this.#c=o*129/16383*100,e.dispatchEvent("mastervolume",e.#c)},o=>{},o=>{}][f]||(()=>{}))(i,s)}),t[0]<4){let i=0;a.forEach(s=>{i=i<<4,i+=s}),i-=1024}}}}).add([76,2,1],t=>{let a="XG ";t[0]<32?(a+="reverb ",t.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${a}main type: ${U[s]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{e.setEffectTypeRaw(0,!0,s),console.debug(`${a}sub type: ${s+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{console.debug(`${a}time: ${Z(s)}s`)},s=>{console.debug(`${a}diffusion: ${s}`)},s=>{console.debug(`${a}initial delay: ${s}`)},s=>{console.debug(`${a}HPF cutoff: ${A[s]}Hz`)},s=>{console.debug(`${a}LPF cutoff: ${A[s]}Hz`)},s=>{console.debug(`${a}width: ${s}`)},s=>{console.debug(`${a}height: ${s}`)},s=>{console.debug(`${a}depth: ${s}`)},s=>{console.debug(`${a}wall type: ${s}`)},s=>{console.debug(`${a}dry/wet: ${s}`)},s=>{console.debug(`${a}send: ${S(s)}dB`)},s=>{console.debug(`${a}pan: ${s-64}`)},!1,!1,s=>{console.debug(`${a}delay: ${s}`)},s=>{console.debug(`${a}density: ${s}`)},s=>{console.debug(`${a}balance: ${s}`)},s=>{},s=>{console.debug(`${a}feedback: ${s}`)},s=>{}][t[0]+i]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(c)})):t[0]<64?(a+="chorus ",t.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${a}main type: ${U[s]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{e.setEffectTypeRaw(1,!0,s),console.debug(`${a}sub type: ${s+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{console.debug(`${a}LFO: ${J[s]}Hz`)},s=>{},s=>{console.debug(`${a}feedback: ${s}`)},s=>{console.debug(`${a}delay offset: ${ee(s)}ms`)},s=>{},s=>{console.debug(`${a}low: ${A[s]}Hz`)},s=>{console.debug(`${a}low: ${s-64}dB`)},s=>{console.debug(`${a}high: ${A[s]}Hz`)},s=>{console.debug(`${a}high: ${s-64}dB`)},s=>{console.debug(`${a}dry/wet: ${s}`)},s=>{console.debug(`${a}send: ${S(s)}dB`)},s=>{console.debug(`${a}pan: ${s-64}`)},s=>{console.debug(`${a}to reverb: ${S(s)}dB`)},!1,s=>{},s=>{},s=>{},s=>{console.debug(`${a}LFO phase diff: ${(s-64)*3}deg`)},s=>{console.debug(`${a}input mode: ${s?"stereo":"mono"}`)},s=>{}][t[0]-32+i]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(c)})):t[0]<86?(a+="variation ",t.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${a}main type: ${U[s]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},s=>{e.setEffectTypeRaw(2,!0,s),console.debug(`${a}sub type: ${s+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][t[0]-64+i]||function(){})(c)})):t[0]<97?(a+="variation ",t.subarray(1).forEach((c,i)=>{[s=>{console.debug(`${a}send: ${S(s)}dB`)},s=>{console.debug(`${a}pan: ${s-64}`)},s=>{console.debug(`${a}to reverb: ${S(s)}dB`)},s=>{console.debug(`${a}to chorus: ${S(s)}dB`)},s=>{console.debug(`${a}connection: ${s?"system":"insertion"}`)},s=>{console.debug(`${a}channel: CH${s+1}`)},s=>{console.debug(`${a}mod wheel: ${s-64}`)},s=>{console.debug(`${a}bend wheel: ${s-64}`)},s=>{console.debug(`${a}channel after touch: ${s-64}`)},s=>{console.debug(`${a}AC1: ${s-64}`)},s=>{console.debug(`${a}AC2: ${s-64}`)}][t[0]-86+i](c)})):t[0]>111&&t[0]<118?a+="variation ":console.warn(`Unknown XG variation address: ${t[0]}`)}).add([76,2,64],t=>{t.subarray(1).forEach((a,c)=>{let i=c+t[0];if(i==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][a]}`);else{let s=i-1>>2,f=i-1&3,o=`XG EQ ${s} ${["gain","freq","Q","shape"][f]}: `;[()=>{console.debug(`${o}${a-64}dB`)},()=>{console.debug(`${o}${a} (raw)`)},()=>{console.debug(`${o}${a/10}`)},()=>{console.debug(`${o}${["shelf","peak"][+!!a]}`)}][f]()}})}).add([76,3],t=>{let a=t[0],c=t[1],i=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((s,f)=>{([o=>{e.setEffectTypeRaw(3+a,!1,o),console.info(`${i}main type: ${U[o]}`),e.dispatchEvent(`efxinsert${a}`,e.getEffectType(3+a))},o=>{e.setEffectTypeRaw(3+a,!0,o),console.debug(`${i}sub type: ${o+1}`),e.dispatchEvent(`efxinsert${a}`,e.getEffectType(3+a))}][c+f]||function(){})(s)})}).add([76,6,0],t=>{let a=t[0];a<64?e.setLetterDisplay(t.subarray(1),"XG letter display",a):e.#B=Date.now()}).add([76,7,0],t=>{let a=t[0];e.#b=0,e.#R=Date.now()+3200,e.#E.fill(0);let c=t.subarray(1);for(let i=0;i>6-y&1,y++})}).add([76,8],(t,a)=>{let c=e.chRedir(t[0],a,!0),i=t[1],s=u.cc*c,f=`XG CH${c+1} `,o=`Unknown XG part address ${i}.`;t.subarray(2).forEach((n,l)=>{i<1?console.debug(o):i<41?([()=>{e.#e[s+h[0]]=n,e.dispatchEvent("voice",{part:c})},()=>{e.#e[s+h[32]]=n,e.dispatchEvent("voice",{part:c})},()=>{e.#i[c]=n,e.dispatchEvent("voice",{part:c})},()=>{let y=e.chRedir(n,a,!0);e.#h[c]=y,c!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))},()=>{e.#$[c]=+!n},()=>{},()=>{e.setChType(c,n,k.xg),console.debug(`${f}type: ${N[n]||n}`)},()=>{e.#a[u.rpn*c+3]=n,e.#s[u.rpnt*c+2]=1},!1,!1,()=>{e.#e[s+h[7]]=n},!1,!1,()=>{e.#e[s+h[10]]=n||128},!1,!1,()=>{e.#e[s+h[128]]=n},()=>{e.#e[s+h[93]]=n},()=>{e.#e[s+h[91]]=n},()=>{e.#e[s+h[94]]=n},()=>{e.#e[s+h[76]]=n},()=>{e.#e[s+h[77]]=n},()=>{e.#e[s+h[78]]=n},()=>{e.#e[s+h[74]]=n},()=>{e.#e[s+h[71]]=n},()=>{e.#e[s+h[73]]=n},()=>{e.#e[s+h[75]]=n},()=>{e.#e[s+h[72]]=n}][i+l-1]||(()=>{}))():i<48?console.debug(o):i<111?i>102&&i<105&&(e.#e[s+h[[5,65][i&1]]]=n):i<114?console.debug(o):i<116?console.debug(`${f}EQ ${["bass","treble"][i&1]} gain: ${n-64}dB`):i<118?console.debug(o):i<120?console.debug(`${f}EQ ${["bass","treble"][i&1]} freq: ${n}`):console.debug(o)})}).add([76,9],(t,a)=>{let c=e.chRedir(t[0],a,!0),i=t[1],s=u.cc*c,f=`PLG-VL CH${c+1} `;t.subarray(2).forEach((o,n)=>{let l=n+i;switch(l){case 1:{console.info(`${f}breath mode: ${["system","breath","velocity","touch EG"][o]}`);break}case 0:case 27:case 28:break;default:if(l<27){let y=l-3>>1,m=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][y];l&1?l<23?(console.debug(`${f}${m} control source: ${re(o)}`),o&&o<96&&e.allocateAce(130+y),e.#V[u.redir*c+y+2]=o,e.buildRccMap()):console.debug(`${f}${m} scale break point: ${o}`):(console.debug(`${f}${m} depth: ${o-64}`),e.#e[s+h[130+y]]=o)}}})}).add([76,10],t=>{}).add([76,16],t=>{}).add([76,17,0,0],t=>{}).add([76,112],t=>{switch(console.debug(`XG enable PLG-${["VL","SG","DX","AN","PF","DR","PC","AP"][t[0]]} for CH${t[2]+1}.`),t[0]){case 0:{e.#g[u.ext*t[2]]=e.EXT_VL;break}case 2:{e.#g[u.ext*t[2]]=e.EXT_DX;break}default:e.#g[u.ext*t[2]]=e.EXT_NONE}}).add([73,0,0],(t,a)=>{let c=t[0],i="MU1000 System: ";t.subarray(1).forEach((s,f)=>{let o=c+f;o==8?console.debug(`${i}LCD contrast set to ${s}.`):o==18?(e.#x=s?126:0,console.debug(`${i}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):o>=64&&o<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")},()=>{e.#M=!!s,console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][o-64]()})}).add([73,10,0],(t,a)=>{let c=t[0],i=`MU1000 RS${e.#M?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let s=e.chRedir(0,a,!0);e.#M&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${i}Show CH1~64`);break}case 3:{let s=e.chRedir(t[1]<<5,a,!0);e.#M&&e.dispatchEvent("channelmin",s),e.#M&&e.dispatchEvent("channelmax",s+31),console.info(`${i}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${i}unknown switch ${c} invoked.`)}else if(c<32){if(e.#M){let s=e.chRedir(c-16+(e.#re<<4),a,!0);e.dispatchEvent("channelactive",s)}}else if(c<36){let s=e.chRedir(c-32<<4,a,!0);e.#M&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),e.#re=c-32),console.info(`${i}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(t,a)=>{let c=e.chRedir(t[0],a,!0),i=`PLG-100SG CH${c+1} `,s=Date.now();if(t[1]==0){let f="",o=0;t.subarray(2).forEach((n,l)=>{l%2==0?f+=te[n]||n.toString().padStart("0"):o+=n*13}),s>=e.#ae&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${ae(f)}`,amend:!0}),e.#ae=s+Math.ceil(o/2)+e.#te,w()&&console.debug(`${i}vocals: ${f}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}).add([98,0],(t,a,c)=>{let i=t[0],s=t.length-5,f=t.length-1;if(i!=s){console.info(`PLG-DX native dump size mismatch! Gave ${i} instead of ${t.length-5}.`);return}let o=D(t.subarray(4,f));if(o!=t[f]){console.info(`Bad PLG-DX checksum ${t[f]} - should be ${o}.`);return}t[0]=98,e.#v.run(t.subarray(0,f),a,c,{noAce:!0})}).add([98,96],(t,a,c,i)=>{let s=e.chRedir(t[0],a,!0),f=u.cc*s,o=t[1];t.subarray(2).forEach((n,l)=>{let y=o+l;if(!(y<10)){if(y==10)e.resetAce();else if(y<27){let m=y+131;i?.noAce||e.allocateAce(m),e.#e[f+h[m]]=n,e.dispatchEvent("cc",{part:s,cc:m,data:n})}}})}).add([100,0],(t,a,c)=>{let i=t.subarray(0,t.length-1);if(t[0]+5!=t.length){console.warn(`Yamaha DX7+ dump SysEx size mismatch! Expected ${t.length}, but got ${t[0]}: +`,t);return}let s=D(i),f=t[t.length-1];if(s!=f){console.warn(`Yamaha DX7+ dump SysEx checksum mismatch! Expected ${s}, but got ${f}: +`,t);return}r.run(i.subarray(1))}).add([100,76],(t,a,c)=>{let i=t[0]>>4,s=t[0]&15,f=t[1];switch(i){case 2:{let o=e.chRedir(s,a,!0),n=u.cc*o;t.subarray(2).forEach((l,y)=>{let m=y+f;if(!(m<7)){if(m<23){let v=m+135;e.allocateAce(v),e.#e[n+h[v]]=l,e.dispatchEvent("cc",{part:o,cc:v,data:l})}}});break}default:console.info("Unknown DX7+ multipart: %o",t)}}),r.add([14,31],t=>{e.#e[u.cc*t[0]+h[64]]=0,e.#l.ano(t[0]),e.switchMode("xg"),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${t[0]+1}.`)}).add([76,112],async t=>{let a=t[0],c=u.cc*a,i=u.ext*a,s=u.cvn*a;e.#g[i]=e.EXT_DX,e.#C[a]=1;let f=e.#se.subarray(s,s+u.cvn);f.fill(32),t.subarray(1).forEach((o,n)=>{if(n<10)f[n]=Math.max(o,32);else if(!(n<40)){if(n<56){let l=n+102;e.#e[c+h[l]]=o,e.dispatchEvent("cc",{part:a,cc:l,data:o})}}}),e.#i[a]=a&127,e.#e[u.cc*a+h[0]]=35,e.#e[u.cc*a+h[32]]=a>>7|4,e.dispatchEvent("voice",{part:a}),console.debug(`DX7+ CH${a+1} dump: %o`,t)});let p=function(t,a,c,i){},b=function(t,a){let c=t*u.dpn,i=a[0],s=a[1];a.subarray(2).forEach((f,o)=>{let n=o+s,l=-1;n<16?([()=>{l=24},()=>{l=25},()=>{l=26},()=>{},()=>{l=28},()=>{l=29},()=>{l=30},()=>{l=31},()=>{},()=>{},()=>{},()=>{l=20},()=>{l=21},()=>{l=22},()=>{l=23},()=>{}][n]||(()=>{console.debug(`Unknown XG-style drum param ${n} on set ${t+1}.`)}))():n<32||(n<40?([()=>{l=48},()=>{l=49},!1,!1,()=>{l=52},()=>{l=53}][n-32]||(()=>{console.debug(`Unknown XG-style drum param ${n} on set ${t+1}.`)}))():n<80||([()=>{l=36}][n-80]||(()=>{console.debug(`Unknown XG-style drum param ${n} on set ${t+1}.`)}))()),l>=0?(w()&&console.debug(c,l,i,f),e.#y[(c+T[l])*u.dnc+i]=f):w()&&console.debug(`XG-style drum param ${n} has no writes.`)})},E=function(t,a,c){let i=t*u.dpn,s=(a<<7)+c[0];c.subarray(1).forEach((f,o)=>{let n=o+s,l=n&127,y=n>>7,m=-1;y>1&&([()=>{m=26},()=>{},()=>{m=28},()=>{m=29},()=>{m=30},()=>{},()=>{},()=>{m=31}][y-2]||(()=>{console.debug(`Unknown GS-style drum param ${y} on set ${t+1}.`)}))(),m>-1?(w()&&console.debug(i,m,l,f),e.#y[(i+T[m])*u.dnc+l]=f):w()&&console.debug(`GS-style drum param ${y} has no writes.`)})};this.#v.add([76,48],(t,a,c)=>{b(0,t)}).add([76,49],(t,a,c)=>{b(1,t)}).add([76,50],(t,a,c)=>{b(2,t)}).add([76,51],(t,a,c)=>{b(3,t)}).add([76,52],(t,a,c)=>{b(4,t)}).add([76,53],(t,a,c)=>{b(5,t)}).add([76,54],(t,a,c)=>{b(6,t)}).add([76,55],(t,a,c)=>{b(7,t)}),this.#v.add([89,0],(t,a,c)=>{if(e.eprom){let i=t[0],s=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);w()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${i} bytes.`);let f=e.eprom.data;t.subarray(4).forEach((o,n)=>{let l=n>>3,y=n&7;if(y==7)for(let m=0;m<7;m++)f[s+7*l+m]+=(o>>6-m&1)<<7;else f[s+7*l+y]=o})}}).add([89,1],(t,a,c)=>{let i=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];w()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(t,a,c)=>{if(e.eprom){let i=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);w()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;t.subarray(4).forEach((f,o)=>{let n=o>>3,l=o&7;if(l==7)for(let y=0;y<7;y++)s[i+7*n+y]+=(f>>6-y&1)<<7;else s[i+7*n+l]=f})}}).add([89,3],(t,a,c)=>{}),this.#v.add([39,48],(t,a,c)=>{}).add([43,0,0],(t,a,c)=>{let i=[0,0,0,0],s=(f,o)=>{i[o]=f};if(t.subarray(1).forEach((f,o)=>{let n=o+t[0];[s,s,s,s,()=>{this.#c=f*129/16383*100,e.dispatchEvent("mastervolume",e.#c)},()=>f-64,()=>f||128,()=>f,()=>f,()=>{console.debug(`TG300 variation on cc${f}.`)}][n](f,n)}),t[0]<4){let f=0;i.forEach(o=>{f=f<<4,f+=o}),f-=1024}}).add([43,1,0],(t,a,c)=>{}).add([43,2],(t,a,c)=>{let i=e.chRedir(t[0],a,!0),s=t[1],f=u.cc*i,o=`TG300 CH${i+1} `;t.subarray(2).forEach((n,l)=>{l<5?([()=>{},()=>{e.#e[f+h[0]]=n,e.dispatchEvent("voice",{part:i})},()=>{e.#e[f+h[32]]=n,e.dispatchEvent("voice",{part:i})},()=>{e.#i[i]=n,e.dispatchEvent("voice",{part:i})},()=>{let y=e.chRedir(n,a,!0);e.#h[i]=y,i!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))}][l+s]||(()=>{}))(n,l+s):l<21||(l<47?([()=>{e.#$[i]=+!n},()=>{},()=>{},()=>{e.#a[u.rpn*i+3]=n,e.#s[u.rpnt*i+2]=1},()=>{},()=>{e.#e[f+h[7]]=n},!1,!1,()=>{e.#e[f+h[10]]=n||128},!1,!1,()=>{console.debug(`${o} AC1 at cc${n}`)},()=>{console.debug(`${o} AC2 at cc${n}`)},()=>{e.#e[f+h[128]]=n},()=>{e.#e[f+h[93]]=n},()=>{e.#e[f+h[91]]=n},()=>{e.#e[f+h[94]]=n},()=>{e.#e[f+h[76]]=n},()=>{e.#e[f+h[77]]=n},()=>{e.#e[f+h[74]]=n},()=>{e.#e[f+h[71]]=n},()=>{e.#e[f+h[73]]=n},()=>{e.#e[f+h[75]]=n},()=>{e.#e[f+h[72]]=n},()=>{e.#e[f+h[78]]=n}][l+s-21]||(()=>{}))(n,l+s):l<95||([()=>{e.#e[f+h[65]]=n},()=>{e.#e[f+h[5]]=n}][l+s-95]||(()=>{}))(n,l+s))})}).add([43,7,0],(t,a,c)=>{let i=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",i)}).add([43,7,1],(t,a,c)=>{e.#b=0,e.#R=Date.now()+3200,e.#E.fill(0),t.forEach(function(i,s){let f=Math.floor(s/16),o=s%16,n=(o*3+f)*7,l=7,y=0;for(n-=o*5,f==2&&(l=2);y>6-y&1,y++})}),this.#S.add([66,18,0,0,127],(t,a,c)=>{e.switchMode("gs",!0),e.#e[u.cc*9]=120,e.#e[u.cc*25]=120,e.#e[u.cc*41]=120,e.#e[u.cc*57]=120,e.#x=3,e.#n=!1,e.#U.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,a,c)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[u.cc*9]=120,e.#e[u.cc*25]=120,e.#e[u.cc*41]=120,e.#e[u.cc*57]=120,e.#n=!1,e.#U.fill(0),console.info("MIDI reset: GS");break}default:{let i=[0,0,0,0],s=(f,o)=>{i[o]=f};if(t.subarray(1).forEach((f,o)=>{let n=o+t[0];[s,s,s,s,l=>{this.#c=l*129/16383*100,e.dispatchEvent("mastervolume",e.#c)},l=>{},l=>{}][n](f,o)}),t[0]<4){let f=0;i.forEach(o=>{f=f<<4,f+=o}),f-=1024}}}}).add([66,18,64,1],t=>{let a=t[0];if(a<16){let c="".padStart(a," ");t.subarray(1).forEach((i,s)=>{c+=String.fromCharCode(Math.max(32,i))}),c=c.padEnd(16," "),console.debug(`GS patch name: ${c}`)}else a<48||(a<65?t.subarray(1).forEach((c,i)=>{let s=`GS ${a+i>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${F[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${c}ms`)},()=>{console.info(`${s}type: ${se[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${S(c)}`)},()=>{console.debug(`${s}to delay: ${S(c)}`)}][a+i-48]||(()=>{}))()}):a<80?console.debug(`Unknown GS patch address: ${a}`):a<91?t.subarray(1).forEach((c,i)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${ie[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${S(c)}`)}][a+i-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${a}`))}).add([66,18,64,2],t=>{let a="GS EQ ";t.subarray(1).forEach((c,i)=>{([()=>{console.debug(`${a}low freq: ${[200,400][c]}Hz`)},()=>{console.debug(`${a}low gain: ${c-64}dB`)},()=>{console.debug(`${a}high freq: ${[3e3,6e3][c]}Hz`)},()=>{console.debug(`${a}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 a="GS EFX ",c=function(i,s){let f=ce(e.#m.subarray(10,12),s,i);f&&console.debug(`${a}${K(e.#m.subarray(10,12))} ${f}`)};t.subarray(1).forEach((i,s)=>{([()=>{e.setEffectTypeRaw(3,!1,32+i),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,i),console.info(`${a}type: ${K(e.#m.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(`${a}to reverb: ${S(i)}dB`)},()=>{console.debug(`${a}to chorus: ${S(i)}dB`)},()=>{console.debug(`${a}to delay: ${S(i)}dB`)},!1,()=>{console.debug(`${a}1 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${a}1 depth: ${i-64}`)},()=>{console.debug(`${a}2 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${a}2 depth: ${i-64}`)},()=>{console.debug(`${a}to EQ: ${i?"ON":"OFF"}`)}][t[0]+s]||function(f,o){console.warn(`Unknown GS EFX address: ${o}`)})(i,t[0]+s)})}).add([66,18,65],t=>{E((t[0]>>4)+1<<1,t[0]&15,t.subarray(1))}).add([69,18,16],t=>{switch(t[0]){case 0:{let a=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",a);break}case 32:{e.#R=Date.now()+3200,t[1]==0&&(e.#b=Math.max(Math.min(t[2]-1,9),0),w()&&console.debug(`GS switch display page ${t[2]-1}.`));break}default:if(t[0]<6){e.#b>9&&(e.#b=0);let a=t[0]-1<<1|t[1]>>6;e.#b==a&&(e.#R=Date.now()+3200),e.#O[a]?.length||(e.#O[a]=new Uint8Array(256));let c=e.#O[a];w()&&console.debug(`GS frame draw page ${a}.`);let i=t[1]&63;c.fill(0),t.subarray(2).forEach(function(f,o){let n=o+i,l=Math.floor(n/16),y=n%16,m=(y*4+l)*5,v=5,x=0;for(m-=y*4,l==3&&(v=1);x>4-x&1,x++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let $=function(t,a,c){let i=t[0],s=u.cc*a,f=u.rpn*a,o=`GS CH${a+1} `;i<3?(t.subarray(1).forEach((n,l)=>{[()=>{e.#e[s+h[0]]=n},()=>{e.#i[a]=n},()=>{let y=0;n<16?y=e.chRedir(n,c,!0):y=u.ch,e.#h[a]=y,a!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))}][i+l]()}),e.dispatchEvent("voice",{part:a})):i<19||(i<44?t.subarray(1).forEach((n,l)=>{([()=>{e.#$[a]=+!n},!1,()=>{e.setChType(a,n<<1,k.gs),console.debug(`${o}type: ${n?"drum ":"melodic"}${n||""}`)},()=>{e.#a[f+3]=n,e.#s[u.rpnt*a+2]=1},!1,()=>{e.#e[s+h[7]]=n},!1,!1,()=>{e.#e[s+h[10]]=n||128},!1,!1,()=>{console.debug(`${o}CC 1: cc${n}`)},()=>{console.debug(`${o}CC 2: cc${n}`)},()=>{e.#e[s+h[93]]=n},()=>{e.#e[s+h[91]]=n},!1,!1,()=>{e.#a[f+1]=n,e.#s[u.rpnt*a+1]=1},()=>{e.#a[f+2]=n,e.#s[u.rpnt*a+1]=1},()=>{e.#e[s+h[94]]=n}][i+l-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},g=function(t,a){let c=t[0],i=`GS CH${a+1} `;c<2?t.subarray(1).forEach((s,f)=>{[()=>{e.#e[u.cc*a+h[32]]=s},()=>{}][c+f]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?t.subarray(1).forEach((s,f)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][s]}`),e.#Z[a]=s,e.dispatchEvent("partefxtoggle",{part:a,active:s})}][c+f-32]()}):console.warn(`Unknown GS misc address: ${c}`)};this.#S.add([66,18,64,16],(t,a)=>{$(t,e.chRedir(9,a,!0),a)}).add([66,18,64,17],(t,a)=>{$(t,e.chRedir(0,a,!0),a)}).add([66,18,64,18],(t,a)=>{$(t,e.chRedir(1,a,!0),a)}).add([66,18,64,19],(t,a)=>{$(t,e.chRedir(2,a,!0),a)}).add([66,18,64,20],(t,a)=>{$(t,e.chRedir(3,a,!0),a)}).add([66,18,64,21],(t,a)=>{$(t,e.chRedir(4,a,!0),a)}).add([66,18,64,22],(t,a)=>{$(t,e.chRedir(5,a,!0),a)}).add([66,18,64,23],(t,a)=>{$(t,e.chRedir(6,a,!0),a)}).add([66,18,64,24],(t,a)=>{$(t,e.chRedir(7,a,!0),a)}).add([66,18,64,25],(t,a)=>{$(t,e.chRedir(8,a,!0),a)}).add([66,18,64,26],(t,a)=>{$(t,e.chRedir(10,a,!0),a)}).add([66,18,64,27],(t,a)=>{$(t,e.chRedir(11,a,!0),a)}).add([66,18,64,28],(t,a)=>{$(t,e.chRedir(12,a,!0),a)}).add([66,18,64,29],(t,a)=>{$(t,e.chRedir(13,a,!0),a)}).add([66,18,64,30],(t,a)=>{$(t,e.chRedir(14,a,!0),a)}).add([66,18,64,31],(t,a)=>{$(t,e.chRedir(15,a,!0),a)}).add([66,18,64,64],(t,a)=>{g(t,e.chRedir(9,a,!0))}).add([66,18,64,65],(t,a)=>{g(t,e.chRedir(0,a,!0))}).add([66,18,64,66],(t,a)=>{g(t,e.chRedir(1,a,!0))}).add([66,18,64,67],(t,a)=>{g(t,e.chRedir(2,a,!0))}).add([66,18,64,68],(t,a)=>{g(t,e.chRedir(3,a,!0))}).add([66,18,64,69],(t,a)=>{g(t,e.chRedir(4,a,!0))}).add([66,18,64,70],(t,a)=>{g(t,e.chRedir(5,a,!0))}).add([66,18,64,71],(t,a)=>{g(t,e.chRedir(6,a,!0))}).add([66,18,64,72],(t,a)=>{g(t,e.chRedir(7,a,!0))}).add([66,18,64,73],(t,a)=>{g(t,e.chRedir(8,a,!0))}).add([66,18,64,74],(t,a)=>{g(t,e.chRedir(10,a,!0))}).add([66,18,64,75],(t,a)=>{g(t,e.chRedir(11,a,!0))}).add([66,18,64,76],(t,a)=>{g(t,e.chRedir(12,a,!0))}).add([66,18,64,77],(t,a)=>{g(t,e.chRedir(13,a,!0))}).add([66,18,64,78],(t,a)=>{g(t,e.chRedir(14,a,!0))}).add([66,18,64,79],(t,a)=>{g(t,e.chRedir(15,a,!0))}),this.#N.add([54,65],(t,a)=>{e.switchMode("x5d");let c=t[t.length-1],i=t.subarray(0,t.length-1),s=D(i);s!=c&&(console.info(`X5D multi parameters checksum mismatch! Expected ${s}, got ${c}.`),console.debug(t));let f=(t[1]<<7)+t[0],o=(t[3]<<7)+t[2],n=e.chRedir(f&15,a,!0),l=u.cc*n;[()=>{o<1||(o<101?(e.setChType(n,e.CH_MELODIC,k.x5d),e.#i[n]=o-1,e.#e[l+h[0]]=e.#o.x5):o<229?(e.setChType(n,e.CH_MELODIC,k.x5d),e.#i[n]=o-101,e.#e[l+h[0]]=56):(e.setChType(n,e.CH_DRUMS,k.x5d),e.#i[n]=pe[o-229]||0,e.#e[l+h[0]]=62)),e.dispatchEvent("voice",{part:n})},()=>{e.#e[l+h[7]]=o},()=>{o<31&&(e.#e[l+h[10]]=Math.round((o-15)*4.2+64))},()=>{e.#e[l+h[93]]=P(o)},()=>{e.#e[l+h[91]]=P(o)},()=>{e.#a[n*u.rpn+3]=o>8191?o-16320:64+o,e.#s[u.rpnt*n+2]=1},()=>{e.#a[n*u.rpn+1]=o>8191?o-16320:64+o,e.#s[u.rpnt*n+1]=1},()=>{o>0&&(e.#a[n*u.rpn]=o,e.#s[u.rpnt*n]=1)},()=>{}][f>>4]()}).add([54,76,0],(t,a)=>{e.switchMode(e.#o.x5=="81"?"05rw":"x5d",!0);let c="",i=e.#o.x5,s=0,f=0,o="MSB PRG LSB NME";M(t,function(n,l){if(l<16400){let y=l%164;switch(!0){case y<10:{n>31&&(c+=String.fromCharCode(n));break}case y==10:break;case y==11:{o+=` +${i} ${s} ${f} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}s>99&&(i=90,s=0)}}),e.userBank.clearRange({msb:e.#o.x5,prg:[0,99],lsb:0}),e.userBank.load(o),w()&&console.debug(o),e.forceVoiceRefresh()}).add([54,77,0],(t,a)=>{e.switchMode(e.#o.x5=="81"?"05rw":"x5d",!0);let c="",i=90,s=0,f=0,o="MSB PRG LSB NME";M(t,function(n,l){if(l<13600){let y=l%136;switch(!0){case y<10:{n>31&&(c+=String.fromCharCode(n));break}case y==11:{o+=` +${i} ${s} ${f} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(o),w()&&console.debug(o),e.forceVoiceRefresh()}).add([54,78],(t,a)=>{e.switchMode(e.#o.x5=="81"?"05rw":"x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][t[0]]} mode.`)}).add([54,85],(t,a)=>{e.switchMode(e.#o.x5=="81"?"05rw":"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,a)=>{e.switchMode(e.#o.x5=="81"?"05rw":"x5d",!0),M(t,function(c,i,s,f){if(i<192){let o=e.chRedir(Math.floor(i/12),a,!0),n=o*u.cc;switch(i%12){case 0:{c<128?(e.setChType(o,e.CH_MELODIC,k.x5d),e.#e[n+h[0]]=e.#o.x5,e.#i[o]=c):(e.setChType(o,e.CH_DRUMS,k.x5d),e.#e[n+h[0]]=62,e.#i[o]=pe[c-128]),c>0&&e.setChActive(o,1),e.dispatchEvent("voice",{part:o});break}case 1:{e.#e[n+h[7]]=c;break}case 2:{e.#a[o*u.rpn+3]=c>127?c-192:64+c,e.#s[u.rpnt*o+2]=1;break}case 3:{e.#a[o*u.rpn+1]=c>127?c-192:64+c,e.#s[u.rpnt*o+1]=1;break}case 4:{c<31&&(e.#e[n+h[10]]=Math.round((c-15)*4.2+64));break}case 5:{let l=c>>4,y=c&15;e.#e[n+h[91]]=P(y),e.#e[n+h[93]]=P(l);break}case 10:break;case 11:{let l=e.chRedir(c&15,a,!0),y=c>>4;e.#h[o]=c,(l!=o||y)&&(console.info(`X5D Part CH${o+1} receives from CH${l+1}.`),e.buildRchTree())}}}else{let o=e.chRedir(i-192,a,!0)}})}),this.#S.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,a,c)=>{e.switchMode("mt32");let i=e.chRedir(c,a,!0),s=t[1];t.subarray(2).forEach((f,o)=>{let n=o+s;e.#P[n+(i-1)*16]=f,([!1,()=>{let l=e.#P[i-1<<4];if(l<3){if(e.#C[i]=1,l==2)for(let y=0;y{e.#a[i*u.rpn+3]=f+40,e.#s[u.rpnt*i+2]=1},()=>{e.#a[i*u.rpn+1]=f+14,e.#s[u.rpnt*i+1]=1},()=>{e.#a[i*u.rpn]=f,e.#s[u.rpnt*i]=1},!1,()=>{e.#e[u.cc*i+h[91]]=f?127:0},!1,()=>{e.#e[u.cc*i+h[7]]=f},()=>{e.#e[u.cc*i+h[10]]=Math.ceil(f*9.05)}][n]||(()=>{}))()})}).add([22,18,1],(t,a,c)=>{e.switchMode("mt32");let i=c&7;console.debug(`MT-32 slot #${c+1} Drum: ${t}`);let s=t[0]<<7|t[1];t.subarray(2).forEach((f,o)=>{let n=o+s,l=(n>>2)+24,y=n&3,m=i*u.dpn;if(w()&&console.debug(`MT-32 temp drum note ${l} param ${y}: ${f}`),l<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${l}`);return}[()=>{},()=>{e.#y[(m+T[26])*u.dnc+l]=Math.round(f*1.27)},()=>{e.#y[(m+T[26])*u.dnc+l]=f*9+1&127},()=>{e.#y[(m+T[26])*u.dnc+l]=f?127:0}][y]()})}).add([22,18,2],(t,a,c)=>{e.switchMode("mt32");let i=e.chRedir(c,a,!0),s=t[1]+(t[0]<<7);s<10&&(e.#C[i]=1),t.subarray(2).forEach((f,o)=>{let n=o+s;n<14&&(e.#T[(i-1)*u.cmt+n]=f)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(t,a,c)=>{e.switchMode("mt32");let i=c&7;if(t[0]){let s=(t[0]-1<<7)+t[1]-16;t.subarray(2).forEach((f,o)=>{let n=o+s,l=(n>>2)+24,y=n&3,m=i*u.dpn;if(w()&&console.debug(`MT-32 dev drum note ${l} param ${y}: ${f}`),l<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${l}`);return}[()=>{},()=>{e.#y[(m+T[26])*u.dnc+l]=Math.round(f*1.27)},()=>{e.#y[(m+T[26])*u.dnc+l]=f*9+1&127},()=>{e.#y[(m+T[26])*u.dnc+l]=f?127:0}][y]()})}else{let s=t[1];t.subarray(2).forEach((f,o)=>{let n=o+s;e.#P[n]=f;let l=e.chRedir(1+(n>>4),a,!0),y=n&15;([!1,()=>{let m=e.#P[l-1<<4];if(m<3)if(e.#C[l]=1,m==2)for(let v=0;v{e.#a[l*u.rpn+3]=f+40,e.#s[u.rpnt*l+2]=1},()=>{e.#a[l*u.rpn+1]=f+14,e.#s[u.rpnt*l+1]=1},()=>{e.#a[l*u.rpn]=f,e.#s[u.rpnt*l]=1},!1,()=>{e.#e[u.cc*l+h[91]]=f?127:0},!1,()=>{e.#e[u.cc*l+h[7]]=f},()=>{e.#e[u.cc*l+h[10]]=Math.ceil(f*9.05)}][y]||(()=>{}))()})}}).add([22,18,4],(t,a,c)=>{e.switchMode("mt32");let i=t[1]+(t[0]<<7),s=[];t.subarray(2).forEach((f,o)=>{let n=o+i,l=e.chRedir(Math.floor(n/246+1),a,!0),y=n%246;y<14&&(e.#T[(l-1)*u.cmt+y]=f),y<10&&(e.#C[l]=1),s.indexOf(l)<0&&s.push(l)}),s.forEach(f=>{e.dispatchEvent("voice",{part:f})})}).add([22,18,5],(t,a,c)=>{e.switchMode("mt32");let i=(t[0]<<7)+t[1];t.subarray(2).forEach((s,f)=>{let o=i+f,n=Math.floor(o/8),l=o&7,y=n*8;e.#ee[o]=s,([!1,()=>{let m=e.#ee[y];if(m<3){let v="";if(m==2){let q=u.cmt*n;v=`MT-m:${s.toString().padStart(3,"0")}`}else v=e.baseBank.get(0,s+(m<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:n});let x=`MSB LSB PRG NME +000 127 ${n} ${v}`;e.userBank.load(x,!0)}}][l]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(t,a,c)=>{e.switchMode("mt32");let i=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((s,f)=>{let o=i+f;o>1)*u.cmt+o]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(t,a,c)=>{e.switchMode("mt32");let i=t[1],s=!1,f=function(o,n){e.#h[n-12]=o,s=!0};t.subarray(2).forEach((o,n)=>{let l=n+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,f,f,f,f,f,f,f,f,f,()=>{e.#c=o,e.dispatchEvent("mastervolume",e.#c)}][l]||(()=>{}))(o,n)}),s&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let a=t[1],c=" ".repeat(a);t.subarray(2).forEach(i=>{i>31?c+=String.fromCharCode(i):c+=" "}),e.#G=c.padStart(20," "),e.#B=Date.now()+3200}).add([22,18,82],(t,a)=>{let c=e.chRedir(0,a,!0);for(let i=0;i<16;i++)e.#l.ano(c+i),i&&i<10&&(e.#i[c+i]=z[i-1]);console.info("MT-32 alt reset complete.")}),this.#N.add([66,0],(t,a)=>{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,a)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#n=!1}).add([66,18,0,0],(t,a)=>{let c=t[0];switch(c){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#n=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${t}`);break}default:if(c<10){let i=[0,0,0,0],s=(f,o)=>{i[o]=f};if(t.subarray(1).forEach((f,o)=>{[s,s,s,s,()=>{e.#c=f*129/16383*100,e.dispatchEvent("mastervolume",e.#c)},()=>f-64,()=>f-64,()=>{},()=>{},()=>{}][c+o]()}),t[0]<4){let f=0;i.forEach(o=>{f=f<<4,f+=o}),f-=1024}}}}).add([66,18,0,1],(t,a)=>{}).add([66,18,0,2],(t,a)=>{}).add([66,18,1],(t,a)=>{let c=e.chRedir(t[0],a,!0),i=c*u.cc,s=t[1],f=`NS5R CH${c+1} `;t.subarray(2).forEach((o,n)=>{let l=s+n;l<3?([()=>{e.#e[i+h[0]]=o||H.bank0},()=>{e.#e[i+h[32]]=o},()=>{e.#i[c]=o}][l](),e.dispatchEvent("voice",{part:c})):l<8||(l<14?[()=>{let y=e.chRedir(o,a,!0);e.#h[c]=y,c!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))},()=>{e.#$[c]=+!o},()=>{e.setChType(c,o,k.ns5r),console.debug(`${f}type: ${N[o]}`)},()=>{e.#a[u.rpn*c+3]=o,e.#s[u.rpnt*c+2]=1},()=>{},()=>{}][l-8]():l<16||(l<33?[()=>{e.#e[i+h[7]]=o},()=>{e.#e[i+h[11]]=o},()=>{},()=>{},()=>{e.#e[i+h[10]]=o||128},()=>{},()=>{},()=>{e.#e[i+h[93]]=o},()=>{e.#e[i+h[91]]=o},()=>{e.#e[i+h[76]]=o},()=>{e.#e[i+h[77]]=o},()=>{e.#e[i+h[78]]=o},()=>{e.#e[i+h[74]]=o},()=>{e.#e[i+h[71]]=o},()=>{e.#e[i+h[73]]=o},()=>{e.#e[i+h[75]]=o},()=>{e.#e[i+h[72]]=o}][l-16]():l<112||l<114&&[()=>{e.#e[i+h[5]]=o},()=>{e.#e[i+h[65]]=o}][l-112]()))})}).add([66,18,8,0],(t,a)=>{let c=t[0];if(c<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let i=c-32;e.#R=Date.now()+3200,e.#b=10,e.#E.fill(0);let s=t.subarray(1),f=4;s.forEach(function(o,n){let l=n+i,y=l>>4,m=l&15;if(l<80){let v=y>3,x=0,q=y0;)e.#E[m*32+y*7+(q-x)]=v&1,v=v>>1,x++}})}}).add([66,18,48],(t,a,c)=>{b(0,t)}).add([66,18,49],(t,a,c)=>{b(1,t)}).add([66,18,50],(t,a,c)=>{b(2,t)}).add([66,18,51],(t,a,c)=>{b(3,t)}).add([66,18,52],(t,a,c)=>{b(4,t)}).add([66,18,53],(t,a,c)=>{b(5,t)}).add([66,18,54],(t,a,c)=>{b(6,t)}).add([66,18,55],(t,a,c)=>{b(7,t)}).add([66,52],(t,a)=>{e.switchMode("ns5r",!0),e.#n=!1;let c="";M(t,(i,s)=>{s<8?(i>31&&(c+=String.fromCharCode(i)),s==7&&(e.aiEfxName=c)):s<10&&(e.setEffectType(s-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(t,a)=>{e.switchMode("ns5r",!0),e.#n=!1;let c="",i=t[t.length-1],s=t.subarray(0,t.length-1),f=D(s);f!=i&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${f}, got ${i}.`),console.debug(t)),M(s,function(o,n){switch(!0){case n<2944:{let l=e.chRedir(Math.floor(n/92),a,!0),y=l*u.cc;switch(n%92){case 0:{e.#e[y+h[0]]=o,e.dispatchEvent("voice",{part:l});break}case 1:{e.#e[y+h[32]]=o,!o&&!e.#e[y+h[0]]&&(e.#e[y+h[0]]=H.bank0),e.dispatchEvent("voice",{part:l});break}case 2:{e.#i[l]=o,o>0&&e.setChActive(l,1),e.dispatchEvent("voice",{part:l});break}case 3:{let m=e.chRedir(o,a,!0);e.#h[l]=m,l!=m&&(console.info(`NS5R CH${l+1} receives from CH${m+1}.`),e.buildRchTree());break}case 7:{e.#r[l]=o,e.dispatchEvent("voice",{part:l});break}case 8:{e.#a[l*u.rpn+3]=o<40||o>88?o+(o>63?-192:64):o,e.#s[u.rpnt*l+2]=1;break}case 9:case 10:{e.#e[y+h[7]]=o;break}case 11:{e.#e[y+h[11]]=o;break}case 14:{e.#e[y+h[10]]=o||128;break}case 19:{e.#e[y+h[93]]=o;break}case 20:{e.#e[y+h[91]]=o;break}case 84:{e.#e[y+h[65]]=o;break}case 85:{e.#e[y+h[5]]=o;break}}break}case n<3096:break;case n<3134:{let l=n-3096;l<8?(o>31&&(c+=String.fromCharCode(o)),l==7&&(e.aiEfxName=c)):l<10&&(e.setEffectType(l-8,44,o),e.dispatchEvent(`efx${["reverb","chorus"][l-8]}`,e.getEffectType(l-8)));break}case n<8566:break}})}).add([66,54],(t,a)=>{e.switchMode("ns5r",!0);let c="",i=80,s=0,f=0,o="MSB PRG LSB NME";M(t,function(n,l){let y=l%158;switch(!0){case y<10:{n>31&&(c+=String.fromCharCode(n));break}case y==10:break;case y==11:{i=n&127;break}case y==12:{f=n&127;break}case y==13:{o+=` +${i} ${s} ${f} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(o),w()&&console.debug(o),e.forceVoiceRefresh()}).add([66,55],(t,a)=>{e.switchMode("ns5r",!0);let c="",i=88,s=0,f=0,o="MSB PRG LSB NME";M(t,function(n,l){let y=l%126;switch(!0){case y<10:{n>31&&(c+=String.fromCharCode(n));break}case y==11:break;case y==12:break;case y==13:{o+=` +${i} ${s} ${f} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(o),w()&&console.debug(o),e.forceVoiceRefresh()}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let a=t[t.length-1],c=t.subarray(0,t.length-1),i=D(c);i!=a&&(console.info(`NS5R screen dump checksum mismatch! Expected ${i}, got ${a}.`),console.debug(t));let s=new Uint8Array(5760);M(t,(f,o,n)=>{if(o<720)for(let l=0;l<8;l++)s[o*8+l]=f>>7-l&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(t,a,c)=>{e.#N.run([66,...t],a,c)}),this.#Y.add([16,0,8,0],(t,a,c)=>{let i=(t[2]<<4)+t[3],s="K11 ";([()=>{e.switchMode("k11",!0),e.#n=!1,e.#x=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}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,a,c)=>{let i=e.chRedir(t[1],a,!0),s=u.cc*i,f=u.rpn*i,o=(t[3]<<4)+t[4],n=`K11 CH${i+1} `;([()=>{o<128?(e.setChType(i,e.CH_MELODIC,k.k11),e.#e[s+h[0]]=0,e.#i[i]=o):(e.setChType(i,e.CH_DRUMS,k.k11),e.#i[i]=o-128),e.dispatchEvent("voice",{part:i})},()=>{let l=e.chRedir(o,a,!0);e.#h[i]=l,i!=l&&(e.buildRchTree(),console.info(`${n}receives from CH${l+1}`))},()=>{e.#e[s+h[7]]=o},()=>{uupThis.setChActive(i,o)},()=>{e.#e[s+h[10]]=o},()=>{e.#a[f+3]=o+40,e.#s[u.rpnt*i+2]=1},()=>{e.#a[f+1]=o>>1,e.#a[f+2]=o&1,e.#s[u.rpnt*i+1]=1},()=>{e.#e[s+h[91]]=o?127:0},()=>{},()=>{e.#e[s+h[74]]=o},()=>{e.#e[s+h[73]]=o},()=>{e.#e[s+h[72]]=o}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,a,c)=>{let i=(t[2]<<4)+t[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}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,a,c)=>{let i=(t[2]<<4)+t[3],s=e.chRedir(t[1],a,!0),f=s*u.cc;[()=>{i<128?(e.setChType(s,e.CH_MELODIC,k.k11),e.#e[f+h[0]]=0,e.#e[f+h[32]]=0,e.#i[s]=i):i<160?(e.setChType(s,e.CH_MELODIC,k.k11),e.#e[f+h[0]]=0,e.#e[f+h[32]]=7,e.#i[s]=i-100):(e.setChType(s,e.CH_DRUMS,k.k11),e.#e[f+h[0]]=122,e.#e[f+h[32]]=0,e.#i[s]=i-160),e.dispatchEvent("voice",{part:s})},()=>{let o=e.chRedir(i,a,!0);e.#h[s]=o,s!=o&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${o+1}`))}][t[0]]()}).add([16,0,9,4],(t,a,c)=>{let i=(t[2]<<4)+t[3],s=e.chRedir(t[1],a,!0),f=s*u.cc,o=s*u.rpn,n=`GMLX CH${s+1} `;[()=>{e.setChActive(s,i)},()=>{e.#e[f+h[7]]=i},()=>{e.#e[f+h[10]]=i},()=>{e.#e[f+h[91]]=i?127:0},()=>{e.#a[o+3]=i+40,e.#s[u.rpnt*s+2]=1},()=>{e.#a[o+1]=i,e.#s[u.rpnt*s+1]=1},()=>{e.#a[o]=i,e.#s[u.rpnt*s]=1},()=>{}][t[0]]()}),this.#W.add([66,93,64],(t,a,c)=>{let i=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{e.#c=i*129/16383*100,e.dispatchEvent("mastervolume",e.#c);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: ${F[i]}`);break}}break}default:if(t[0]>>4==1){let s=e.chRedir(t[0]&15,a,!0);if(t[1]==2){let f=e.chRedir(i,a,!0);e.#h[s]=f,s!=f&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${f+1}`))}else t[1]==19&&(e.#e[u.cc*s+h[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),this.#j.add([9],(t,a,c)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)}),this.#v.add([127,0],(t,a,c)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...t]);e.#v.run(i,a,c)}).add([127,1,0,0],(t,a,c)=>{e.switchMode("s90es");let i="S90/Motif ES system ",s=t[0];t.subarray(1).forEach((f,o)=>{([()=>{e.#c=f*12900/16383,e.dispatchEvent("mastervolume",e.#c)}][s+o]||(()=>{console.info(`Unrecognized ${i}ID: ${s+o}`)}))()})}).add([127,1,0,0,14],(t,a,c)=>{e.switchMode("s90es");let i="S90/Motif ES bulk header ",s=[];s[95]=(f,o,n)=>{console.debug(`${i}multi edit buffer: ${f[1]}`)},(s[t[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,0,15],(t,a,c)=>{e.switchMode("s90es");let i="S90/Motif ES bulk footer ",s=[];s[95]=(f,o,n)=>{console.debug(`${i}multi edit buffer: ${f[1]}`)},(s[t[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,58,55],(t,a,c)=>{e.switchMode("s90es");let i=e.chRedir(t[0],a,!0),s=u.cc*i,f=t[1],o=`S90/Motif ES bulk CH${i<16?i+1:"U"+(i-95)} `;console.debug(o,t),!(t[0]>15)&&t.subarray(2).forEach((n,l)=>{([()=>{e.#e[s+h[0]]=n,e.dispatchEvent("voice",{part:i})},()=>{n&&e.setChActive(i,1),e.#e[s+h[32]]=n,e.setChType(i,[32,40].indexOf(n)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:i})},()=>{n&&e.setChActive(i,1),e.#i[i]=n,e.dispatchEvent("voice",{part:i})},()=>{let y=e.chRedir(n,a,!0);e.#h[i]=y,i!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))},()=>{e.#$[i]=n?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{e.#e[s+h[7]]=n},()=>{e.#e[s+h[10]]=n},!1,!1,!1,()=>{e.#e[s+h[91]]=n},()=>{e.#e[s+h[93]]=n},()=>{e.#e[s+h[94]]=n},()=>{e.#e[s+h[128]]=n},()=>{},()=>{e.#e[s+h[74]]=n},()=>{e.#e[s+h[71]]=n},!1,()=>{e.#e[s+h[65]]=n},()=>{e.#e[s+h[5]]=n},()=>{}][f+l]||(()=>{}))()})}).add([127,1,54,16],(t,a,c)=>{e.switchMode("s90es");let i=t[0];t.subarray(1).forEach((s,f)=>{let n=`S90/Motif ES EQ${(f>>2)+1} `;([()=>{let l=s-64},()=>{let l=A[s]},()=>{let l=s/10},()=>{let l=s}][i+f&3]||(()=>{}))()})}),this.#S.add([0,72,18,0,0,0,0],(t,a,c)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(t,a,c)=>{let i=t[0]>>5,s=t[0]&31;switch(i){case 0:{let f=t[0]>>1,o=t[1];switch(f){case 1:{t.subarray(2).forEach((n,l,y)=>{let m=l+o;switch(m){case 0:{n&&(e.setEffectType(1,60,n-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${m} - ${n}`));break}}});break}case 2:{t.subarray(2).forEach((n,l)=>{let y=l+o;switch(y){case 0:{n&&(e.setEffectType(0,55+n,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${y} - ${n}`));break}}});break}case 3:case 4:case 5:{let n=f-1;t.subarray(2).forEach((l,y)=>{let m=y+o;switch(console.debug(`SD MFX ${n-2}: ${m} - ${l}`),m){case 0:{e.setEffectTypeRaw(n,62,l),e.dispatchEvent(`efx${n>2?"delay":"insert"+(n-4)}`,e.getEffectType(n));break}}}),console.debug(`SD MFX message: %o`,t);break}default:console.debug(`Unknown SD-90 global effects message: -%o`,t)}break}case 1:{let f=e.chRedir(s,a,!0),o=t[1],n=f*u.cc;t.subarray(2).forEach((l,y)=>{let m=o+y;m<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[n+h[0]]=l,l){case 104:case 105:case 106:case 107:case 120:{e.#r[f]||e.setChType(f,e.CH_DRUMS);break}default:e.#r[f]&&e.setChType(f,e.CH_MELODIC)}e.dispatchEvent("voice",{part:f})},()=>{e.#e[n+h[32]]=l,e.dispatchEvent("voice",{part:f})},()=>{e.#i[f]=l,e.dispatchEvent("voice",{part:f})},()=>{e.#e[n+h[7]]=l},()=>{e.#e[n+h[10]]=l},()=>{},()=>{},()=>{l<2&&(e.#E[f]=l)},()=>{l<2&&(e.#e[n+h[68]]=l?127:0)},()=>{},()=>{l<2&&(e.#e[n+h[65]]=l?127:0)},()=>{e.#e[n+h[5]]=l&15<<4|e.#e[n+h[5]]&15},()=>{e.#e[n+h[5]]=l&15|(e.#e[n+h[5]]&240)>>4},()=>{e.#e[n+h[74]]=l},()=>{e.#e[n+h[71]]=l},()=>{e.#e[n+h[73]]=l},()=>{e.#e[n+h[72]]=l},0,0,0,0,0,0,0,()=>{e.#e[n+h[128]]=l},()=>{e.#e[n+h[93]]=l},()=>{e.#e[n+h[91]]=l},0,0,()=>{e.#e[n+h[75]]=l},()=>{e.#e[n+h[76]]=l},()=>{e.#e[n+h[77]]=l},()=>{e.#e[n+h[78]]=l}][m]||(()=>{}))():m<63||(m<64?(e.#r[f]?e.#e[n+h[0]]=104|l:e.#e[n+h[0]]=96|l,e.dispatchEvent("voice",{part:f})):console.debug(`Unknown SD-90 global CH${f+1} param setup message: +%o`,t)}break}case 1:{let f=e.chRedir(s,a,!0),o=t[1],n=f*u.cc;t.subarray(2).forEach((l,y)=>{let m=o+y;m<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[n+h[0]]=l,l){case 104:case 105:case 106:case 107:case 120:{e.#r[f]||e.setChType(f,e.CH_DRUMS);break}default:e.#r[f]&&e.setChType(f,e.CH_MELODIC)}e.dispatchEvent("voice",{part:f})},()=>{e.#e[n+h[32]]=l,e.dispatchEvent("voice",{part:f})},()=>{e.#i[f]=l,e.dispatchEvent("voice",{part:f})},()=>{e.#e[n+h[7]]=l},()=>{e.#e[n+h[10]]=l},()=>{},()=>{},()=>{l<2&&(e.#$[f]=l)},()=>{l<2&&(e.#e[n+h[68]]=l?127:0)},()=>{},()=>{l<2&&(e.#e[n+h[65]]=l?127:0)},()=>{e.#e[n+h[5]]=l&15<<4|e.#e[n+h[5]]&15},()=>{e.#e[n+h[5]]=l&15|(e.#e[n+h[5]]&240)>>4},()=>{e.#e[n+h[74]]=l},()=>{e.#e[n+h[71]]=l},()=>{e.#e[n+h[73]]=l},()=>{e.#e[n+h[72]]=l},0,0,0,0,0,0,0,()=>{e.#e[n+h[128]]=l},()=>{e.#e[n+h[93]]=l},()=>{e.#e[n+h[91]]=l},0,0,()=>{e.#e[n+h[75]]=l},()=>{e.#e[n+h[76]]=l},()=>{e.#e[n+h[77]]=l},()=>{e.#e[n+h[78]]=l}][m]||(()=>{}))():m<63||(m<64?(e.#r[f]?e.#e[n+h[0]]=104|l:e.#e[n+h[0]]=96|l,e.dispatchEvent("voice",{part:f})):console.debug(`Unknown SD-90 global CH${f+1} param setup message: %o`,t))});break}case 2:{let f=e.chRedir(s,a,!0),o=t[1];console.debug(`Unknown SD-90 global CH${f+1} MIDI setup message: %o`,t.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: %o`,t)}})}};export{Je as OctaviaDevice,u as allocated,h as ccToPos,T as dnToPos}; diff --git a/dist/state_skim.mjs b/dist/state_skim.mjs index e45f554c..c7f6e8bc 100644 --- a/dist/state_skim.mjs +++ b/dist/state_skim.mjs @@ -1,7 +1,7 @@ -var P=function(e,t){let a=Math.min(e.length,t.length),s=e.slice(0,a),r=t.slice(0,a),n=0,l=0;for(;l0){let s=this.pool.length,r=1<=1&&l>=0;){if(l<=0)throw new Error("TTL reached.");if(n==s)n-=r;else{let p=P(t,this.pool[n]);switch(p){case 0:{l=0;break}case 1:{n+r<=s&&(n+=r);break}case-1:{n!=0&&(n-=r);break}default:console.warn(`Unexpected result ${p}.`)}}r=r>>1,l--}let u=!0;if(n>=this.pool.length)u=!1;else{let p=this;this.pool[n].forEach(function(i,h,c){u&&i!=t[h]&&(u=!1)}),!u&&P(t,this.pool[n])>0&&n++}return u||a?n:-1}else return a?0:-1},this.add=function(t,a){return t.data=a,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 a=this.point(t);if(a>-1)return this.pool[a].data;this.default(t)},this.run=function(t,...a){let s=this.point(t);s>-1?t.subarray?this.pool[s].data(t.subarray(this.pool[s].length),...a):this.pool[s].data(t.slice(this.pool[s].length),...a):this.default(t,...a)}};var T=class{#t={};addEventListener(e,t){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(t)}removeEventListener(e,t){if(this.#t[e]){let a=this.#t[e].indexOf(t);a>-1&&this.#t[e].splice(a,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,t){let a=new Event(e),s=this;a.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(r){try{r?.call(s,a)}catch(n){console.error(n)}}),this[`on${e}`]&&this[`on${e}`](a)}};var N=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 F=function(e,t){let a=!0;return t.forEach((s,r)=>{a=a&&e[r]==s}),a},I=function(e){let t=0;return e.forEach(a=>{t*=256,t+=a}),t},C=new TextDecoder,B=new N;B.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),a="MSB LSB PRG NME",s=[0,0,0,0],r=32,n=0,l=0,u=!0,p=[],i=0;for(;u;){let h=t.subarray(n);([()=>{C.decode(h.subarray(0,4))=="YSFC"?(n+=80,l=1):n++},()=>{if(F(h.subarray(0,4),s))p.forEach((c,b,g)=>{let y=I(t.subarray(c.start+4,c.start+8));c.length=y}),l=2;else{let c=C.decode(h.subarray(0,4)),b=I(h.subarray(4,8));p.push({type:c,start:b}),n+=8}},()=>{let c=p[i],b=t.subarray(c.start,c.start+c.length),g=32;switch(c.type){case"ENVC":{let y=r;for(;y0){let s=this.pool.length,r=1<=1&&h>=0;){if(h<=0)throw new Error("TTL reached.");if(n==s)n-=r;else{let p=P(t,this.pool[n]);switch(p){case 0:{h=0;break}case 1:{n+r<=s&&(n+=r);break}case-1:{n!=0&&(n-=r);break}default:console.warn(`Unexpected result ${p}.`)}}r=r>>1,h--}let u=!0;if(n>=this.pool.length)u=!1;else{let p=this;this.pool[n].forEach(function(i,o,c){u&&i!=t[o]&&(u=!1)}),!u&&P(t,this.pool[n])>0&&n++}return u||a?n:-1}else return a?0:-1},this.add=function(t,a){return t.data=a,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 a=this.point(t);if(a>-1)return this.pool[a].data;this.default(t)},this.run=function(t,...a){let s=this.point(t);s>-1?t.subarray?this.pool[s].data(t.subarray(this.pool[s].length),...a):this.pool[s].data(t.slice(this.pool[s].length),...a):this.default(t,...a)}};var T=class{#t={};addEventListener(e,t){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(t)}removeEventListener(e,t){if(this.#t[e]){let a=this.#t[e].indexOf(t);a>-1&&this.#t[e].splice(a,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,t){let a=new Event(e),s=this;a.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(r){try{r?.call(s,a)}catch(n){console.error(n)}}),this[`on${e}`]&&this[`on${e}`](a)}};var N=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 F=function(e,t){let a=!0;return t.forEach((s,r)=>{a=a&&e[r]==s}),a},I=function(e){let t=0;return e.forEach(a=>{t*=256,t+=a}),t},C=new TextDecoder,B=new N;B.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),a="MSB LSB PRG NME",s=[0,0,0,0],r=32,n=0,h=0,u=!0,p=[],i=0;for(;u;){let o=t.subarray(n);([()=>{C.decode(o.subarray(0,4))=="YSFC"?(n+=80,h=1):n++},()=>{if(F(o.subarray(0,4),s))p.forEach((c,b,g)=>{let y=I(t.subarray(c.start+4,c.start+8));c.length=y}),h=2;else{let c=C.decode(o.subarray(0,4)),b=I(o.subarray(4,8));p.push({type:c,start:b}),n+=8}},()=>{let c=p[i],b=t.subarray(c.start,c.start+c.length),g=32;switch(c.type){case"ENVC":{let y=r;for(;y=p.length&&(l=3,u=!1)}][l]||(()=>{u=!1}))()}return a});var z=["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 q=",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(","),Q={};`hi*, +063 ${(d[17]+1).toString().padStart(3,"0")} ${d[19].toString().padStart(3,"0")} ${$}`),E+=y}break}}i++,i>=p.length&&(h=3,u=!1)}][h]||(()=>{u=!1}))()}return a});var z=["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 q=",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(","),Q={};`hi*, ka,か ki,き ku,く @@ -138,9 +138,9 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let t=e.split(",");Q[t[0]]=t[1]});var Y=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"];var W=["melodic","drum","menu"];var R=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var O=[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,14,15,20,21,26,28,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157];var J={};Y.forEach((e,t)=>{J[e]=t});var Z={length:O.length};O.forEach((e,t)=>{Z[e]=t});var j={length:R.length};R.forEach((e,t)=>{j[e]=t});var ee={};W.forEach((e,t)=>{ee[e]=t});var Ve={ch:128,cc:O.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:R.length,dnc:128,ext:2,efx:7,redir:32};var te=["MSB","PRG","LSB","NME","ELC","DRM"],D=function(e){let t=Math.floor(e/10),a=e%10;return`${t.toString(16)}${a}`},M=class{#t;strictMode=!1;get(e=0,t=0,a=0,s){let r=[e,t,a],n,l=1,u=0,p,i=Array.from(arguments);switch(s){case"xg":{switch(e){case 0:{a==126?i[2]=125:a==127&&(i[2]=0);break}case 16:{a==126&&(i[2]=0);break}case 32:{a>125&&(i[2]=0),i[2]+=4;break}case 33:case 34:case 35:case 36:{a>125&&(i[2]=0),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:{a==126&&(i[2]=0);break}case 48:case 64:case 126:case 127:{a==126&&(i[2]=0);break}}break}case"gs":{e==0&&a<5?i[2]=0:e>125&&a<5&&a!=2&&(i[2]=e,i[0]=0);break}case"g2":case"sd":{e>>1==40?i[2]|=16:e>95&&e<100&&(i[2]|=16,t>>3==15&&(i[0]=96));break}case"sg":{e==8&&a==0&&(i[2]=5);break}case"s90es":{a<8?i[2]+=17:a<32?i[2]+=13:i[2]=(i[2]>>3)+19;break}case"motif":{a<8?i[2]+=28:a<32?i[2]+=13:i[2]=(i[2]>>3)+19;break}}let h=" ",c="M",b=0,g=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||s=="gs"&&i[2]<5?c="GM-a":(c="y",b=3);break}case 8:{s=="sg"?c="GM-s":c="r:";break}case 32:case 33:case 34:case 35:case 36:{s=="xg"&&(c=`${["AP","VL","PF","DX","AN"][e&7]}-${"abcdefgh"[a]}`);break}case 48:{c=`yM${(i[2]>>3).toString().padStart(2,"0")}`,b=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 $=i[2];c=$<10?"kP:":"kC:",c+=$%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?g=63:i[2]>>4==1&&(g=16),b=3;break}case 97:{c=i[2]>>4==1?"SDa":"VL:",b=3,i[2]>>4==1?g=16:g=112;break}case 98:{c=i[2]>>4==1?"SDb":"SG-a",b=3,g=16;break}case 99:{c=i[2]>>4==1?"SDc":"DX",i[2]>63?g=63:i[2]>>4==1&&(g=16),b=3;break}case 100:{c="AN",i[2]>63?g=63:i[2]>>4==1&&(g=16),b=3;break}case 104:case 105:case 106:case 107:{c="SDd",g=104;break}case 121:{c=`GM-${i[2]?"":"a"}`,b=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,a,i[0],i[2]][b]-g}`.padStart(4-c.length,"0")),s=="xg"&&(e==0?i[2]<100?c=c.replace("y0","y:"):i[2]==125&&(c="y126"):e==16&&(n=`Voice${(i[2]*128+i[1]+1).toString().padStart(3,"0")}`,h=" "));let y=[i[0],i[1],i[2]];for(;!(n?.length>=0);)if(n=this.#t[i[1]||0][(i[0]<<7)+i[2]]?.name,n){let $=this.#t[i[1]||0][(i[0]<<7)+i[2]];l=$?.poly||l,u=$?.type||u,p=$?.drum}else if(this.strictMode)n="",h="?";else if(i[0]==0&&i[1]==0&&i[2]==0)n="Unloaded";else if(this.#t[i[1]||0][i[0]<<7])i[0]==0?(i[2]=0,h="^"):i[2]<1?(i[0]=0,h="*"):(i[2]--,h="^");else if(e==48)i[0]=0,i[2]=0,h="!";else if(e==62)i[1]--,h=" ",i[1]<1&&!n?.length&&(i[0]=0,h="!");else if(e<63)i[0]==0?(i[2]=0,h="^"):i[2]<1?(i[0]=0,h="*"):i[2]--;else if(e==80)n=`PrgU:${t.toString().padStart(3,"0")}`,h="!";else if(e==88)n=`CmbU:${t.toString().padStart(3,"0")}`,h="!";else if(e==121)n=`GM2Vox0${a}`,h="#";else if(e==122)if(i[1]==32?i[1]==0:i[1]%=7,n=this.#t[i[1]||0][(i[0]<<7)+i[2]]?.name,n){h=" ";let $=this.#t[i[1]||0][(i[0]<<7)+i[2]];l=$?.poly||l,u=$?.type||u,p=$?.drum}else n="",h="*";else i[1]==0?(n=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${a.toString().padStart(3,"0")}`,h="!"):i[0]==0?(i[2]=0,h="^"):i[2]>0?i[2]--:i[1]>0?(i[1]=0,h="!"):(i[0]=0,h="?");let E=[i[0],i[1],i[2]];(s=="gs"||s=="ns5r")&&h=="^"&&(h=" "),e==127&&h=="^"&&(h=" "),h!=" "&&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 32:case 33:case 35:case 36:{i[2]>4?d=["AP","VL","PF","DX","AN"][i[0]-32]:d="GS";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&&s=="xg"?d="XG":d="GS")}return{name:n||`${D(e||0)} ${D(t||0)} ${D(a||0)}`,poly:l,type:u,drum:p,iid:y,eid:E,sid:r,ending:h,sect:c,standard:d}}async load(e,t,a="(internal)"){let s=this,r=[],n=0,l=0;e.split(` -`).forEach(function(u,p){let i=u.split(" "),h=[];if(p==0){if(i.forEach(function(c,b){r[te.indexOf(c)]=b}),r.length<4){console.debug("Debugger launched.");debugger}}else{let c=0,b=0,g=0,y,E=1,d=0,$;i.forEach(async function(m,K){switch(K){case r[0]:{c=parseInt(m);break}case r[1]:{b=parseInt(m);break}case r[2]:{g=parseInt(m);break}case r[3]:{y=m;break}case r[4]:{m=parseInt(m),m<16?E=m+1:d=(m&15)+1;break}case r[5]:{$=m;break}}}),s.#t[b]=s.#t[b]||[];let L=s.#t[b];if(!L[c<<7|g]||t){let m={msb:c,prg:b,lsb:g,name:y,poly:E,type:d,drum:$};L[c<<7|g]=m,n++}l++}}),t||console.debug(`Map "${a}": ${l} total, ${n} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],a=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],s=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let r=a[0];r<=a[1];r++){let n=r<<7;for(let l=s[0];l<=s[1];l++){let u=n+l;for(let p=t[0];p<=t[1];p++)delete this.#t[p][u]}}}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(a){try{await fetch(`./data/bank/${a}.tsv`).then(function(s){return s.text()}).then(s=>{t.load(s,!1,a)})}catch{console.error(`Failed loading "${a}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var v=["?","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]],x=[120,127,120,127,120,127,61,62,62,62,120,122,122],ae=[0,3,81,84,88],G={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},A={0:0,1:1,2:3,5:4},_=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],X=[36,37];var 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,12,13,16,17,18,19],se=[33,99,100,32,102,8,9,10];var k={};v.forEach((e,t)=>{k[e]=t});var f={length:U.length};U.forEach((e,t)=>{f[e]=t});var S=function(){return!!self.Bun||self.debugMode||!1},ie=function(e){let t=[],a=0;return e?.forEach(function(s,r){s==247?t.push(e.subarray(a,r)):s==240&&(a=r+1)}),t.length||t.push(e.subarray(0)),S(),t},V=function(e,t="",a="",s=2){return e?`${t}${e.toString().padStart(s,"0")}${a}`:""},o={ch:128,cc:U.length,nn:128,pl:512,tr:256,cmt:14,rpn:6},Ze=class extends T{#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(o.ch);#B=new Uint8Array(o.ch);#e=new Uint8ClampedArray(o.ch*o.cc);#$=new Uint8ClampedArray(o.ch);#o=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);#C=0;#l=new Uint8Array(o.ch*o.rpn);#A=new Int8Array(o.ch*X.length);#U=new Uint8Array(o.ch);#K=new Uint8Array(128);#H=new Uint8Array(o.cmt*8);#F=new Uint8Array(1024);#G=new Uint8Array(o.cmt*64);#k=0;#u=0;#M=100;#E=0;#_=500;#z=0;#i="";#p=0;#q=0;#Q=!0;#s=!1;#X;#Y=new Uint8Array(2);#a=[];#m=new Uint8Array(o.ch);#v=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,a){if(this.#v[t])return(this.#v[t]-1)*16+e;if([k.gs,k.ns5r].indexOf(this.#t)>-1){if(a==1)return e;let s=0,r=!0;for(;r;)this.#m[e+s]==0?(this.#m[e+s]=t,console.debug(`Assign track ${t} to channel ${e+s+1}.`),r=!1):this.#m[e+s]==t?r=!1:(s+=16,s>=128&&(s=0,r=!1));return e+s}else return e}#c=[];#T;#r={nOff:(e,t)=>{let a=e*128+t,s=this.#n.lastIndexOf(a);s>-1&&(this.#e[o.cc*e+f[64]]>63&&!this.config?.disableCc64?this.#f[s]=4:(this.#n[s]=0,this.#o[a]=0,this.#f[s]=0))},nOn:(e,t,a)=>{let s=e*128+t,r=0;for(this.#D[e]&&this.#r.ano(e);this.#f[r]>0&&this.#n[r]!=s;)r++;r{},cAt:(e,t)=>{},hoOf:e=>{this.#f.forEach((t,a)=>{if(t==4){let s=this.#n[a],r=s>>7;e==r&&(this.#f[a]=0,this.#n[a]=0,this.#o[s]=0)}})},soOf:e=>{},ano:e=>{this.#n.forEach((t,a,s)=>{let r=t>>7,n=t&127;t==0&&this.#o[0]==0||r==e&&this.#r.nOff(r,n)})}};#V={8:function(e){let t=e.channel,a=e.data[0];this.#r.nOff(t,a)},9:function(e){let t=e.channel;this.#y[t]=1;let a=e.data[0],s=e.data[1];s>0?this.#r.nOn(t,a,s):this.#r.nOff(t,a)},10:function(e){let a=e.channel*128+e.data[0];this.#n.indexOf(a)>-1&&(this.#o[a]=data[1])},11:function(e){let t=e.channel;this.#y[t]=1;let a=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 s=t*o.cc;this.#e[s+f[1]]=0,this.#e[s+f[5]]=0,this.#e[s+f[64]]=0,this.#e[s+f[65]]=0,this.#e[s+f[66]]=0,this.#e[s+f[67]]=0,this.#e[s+f[11]]=127,this.#e[s+f[101]]=127,this.#e[s+f[100]]=127,this.#e[s+f[99]]=127,this.#e[s+f[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(f[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(e.data[0]){case 0:{if(S()&&console.debug(`${v[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#e[a]>119&&(e.data[1]=this.#e[a],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==k.gs)e.data[1]<56&&this.#e[a]>119&&(e.data[1]=this.#e[a],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`));else if(this.#t==k.gm)e.data[1]<48?this.#e[a]>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==k.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let s=0;for(let r=0;r<16;r++){let n=this.#e[o.cc*r];(n==56||n==62)&&s++}s>14&&this.switchMode("ag10",!0)}}break}case 6:{if(this.#C){let s=this.#e[a+f[99]],r=this.#e[a+f[98]];if(s==1){let n=se.indexOf(r);if(n>-1)this.#e[a+f[71+n]]=e.data[1],S()&&console.debug(`Redirected NRPN 1 ${r} to cc${71+n}.`);else{let l=X.indexOf(r);l>-1&&(this.#A[t*10+l]=e.data[1]-64),S()&&console.debug(`CH${t+1} voice NRPN ${r} commit`)}}}else{let s=A[this.#e[a+f[100]]];this.#e[a+f[101]]==0&&s!=null&&(S()&&console.debug(`CH${t+1} RPN 0 ${this.#e[a+f[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],_[s][0]),_[s][1]),this.#l[t*o.rpn+s]=e.data[1])}break}case 38:{this.#C||this.#e[a+101]==0&&A[this.#e[a+100]]!=null&&(this.#l[t*o.rpn+A[this.#e[a+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.#C=1;break}case 100:case 101:{this.#C=0;break}}this.#e[a+f[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,S()&&console.debug(`T:${e.track} C:${t} P:${e.data}`)},13:function(e){let t=this,a=e.channel;this.#n.forEach(function(s){let r=s>>7;a==r&&(t.#o[s]=e.data)})},14:function(e){let t=e.channel;this.#x[t]=e.data[1]*128+e.data[0]-8192},15:function(e){ie(e.data).forEach(t=>{let a=t[0],s=t[1];(this.#W[a]||function(){console.debug(`Unknown manufacturer ${a}.`)})(s,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(a,s,r){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#E=0),ae.indexOf(e.meta)>-1)return e.reply="meta",e;S()&&console.debug(e)}};#W={64:(e,t,a)=>{this.#N.run(t,a,e)},65:(e,t,a)=>{if(t[0]<16)this.#S.run(t,a,e),console.warn("Unknown device SysEx!");else{let s=t[t.length-1],r=gsChecksum(t.subarray(2,t.length-1));s==r?this.#S.run(t.subarray(0,t.length-1),a,e):console.warn(`Bad GS checksum ${s}. Should be ${r}.`)}},66:(e,t,a)=>{this.#O.run(t,a,e)},67:(e,t,a)=>{this.#R.run(t,a,e)},68:(e,t,a)=>{this.#J.run(t,a,e)},71:(e,t,a)=>{this.#I.run(t,a,e)},126:(e,t,a)=>{this.#L.run(t,a,e)},127:(e,t,a)=>{this.switchMode("gm"),this.#P.run(t,a,e)}};#L;#P;#R;#S;#O;#N;#I;#J;buildRchTree(){let e=[];this.#B.forEach((t,a)=>{e[t]?.constructor||(e[t]=[]),e[t].push(a)}),this.#X=e}getActive(){let e=this.#y.slice();return this.#t==k.mt32,e}getCc(e){let t=e*o.cc,a=this.#e.slice(t,t+o.cc);return a[f[0]]=a[f[0]]||this.#k,a[f[32]]=a[f[32]]||this.#u,a}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&t.set(l,{v:a.#o[s],s:a.#f[r]})}),t}getBitmap(){return{bitmap:this.#h,expire:this.#b}}getLetter(){return{text:this.#i,expire:this.#p}}getMode(){return v[this.#t]}getMaster(){return{volume:this.#M}}getRawStrength(){let e=this;return this.#n.forEach(function(t){let a=Math.floor(t/128);e.#o[t]>e.#d[a]&&(e.#d[a]=e.#o[t])}),this.#d}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(a,s){e[s]=Math.floor(a*t.#e[s*o.cc+f[7]]*t.#e[s*o.cc+f[11]]*t.#M/803288)}),e}getRpn(){return this.#l}getNrpn(){return this.#A}getVoice(e,t,a,s){let r=e||this.#k,n=t,l=a||this.#u;v[this.#t]=="ns5r"&&r>0&&r<56&&(l=3);let u=this.userBank.get(r,n,l,s);if(v[this.#t]=="mt32"&&u.name.indexOf("MT-m:")==0){let p=parseInt(u.name.slice(5)),i=p*o.cmt,h="";this.#G.subarray(i,i+10).forEach(c=>{c>31&&(h+=String.fromCharCode(c))}),this.userBank.load(`MSB LSB PRG -0 127 ${n} ${h}`,!0),u.name=h,u.ending=" "}return(u.ending!=" "||!u.name.length)&&(u=this.baseBank.get(r,n,l,s)),u}getChVoice(e){let t=this.getVoice(this.#e[e*o.cc+f[0]],this.#$[e],this.#e[e*o.cc+f[32]],v[this.#t]);if(this.#U[e])switch(this.#t){case k.mt32:t.ending="~",t.name="",this.#H.subarray(14*(e-1),14*(e-1)+10).forEach(a=>{a>31&&(t.name+=String.fromCharCode(a))})}return t}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#k=0,this.#u=0,this.#E=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.#x.fill(0),this.#A.fill(0),this.#M=100,this.#a=[],this.#_=500,this.#z=0,this.#p=0,this.#i="",this.#b=0,this.#w=0,this.#h.fill(0),this.#s=!1,this.#q=0,this.#Q=!0,this.#B.forEach(function(t,a,s){s[a]=a}),this.buildRchTree(),e==0&&(this.#m.fill(0),this.#v.fill(0)),this.#e[o.cc*9]=x[0],this.#e[o.cc*25]=x[0],this.#e[o.cc*41]=x[0],this.#e[o.cc*57]=x[0],this.#Y.fill(0),this.#F.fill(0),this.#G.fill(0),this.#K.fill(0),this.#H.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=a,this.#w=0,this.#k=H[0][a],this.#u=H[1][a];for(let s=0;s-1&&(this.#e[s*o.cc]=x[a]);switch(this.initOnReset,a){case k.mt32:{mt32DefProg.forEach((s,r)=>{let n=r+1;this.#y[n]||(this.#$[n]=s,this.#e[n*o.cc+f[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.#V[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),a=!1;this.#X[t]?.forEach(s=>{e.channel=s,a=!0,this.#V[e.type].call(this,e)}),a||console.warn(`${G[e.type]?G[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){}constructor(){super();let e=this;this.#h=new Uint8Array(256),this.#g[10]=new Uint8Array(512),this.#T=new w,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let t=e.split(",");Q[t[0]]=t[1]});var Y=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"];var W=["melodic","drum","menu"];var R=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var D=[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,14,15,20,21,26,28,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157];var J={};Y.forEach((e,t)=>{J[e]=t});var Z={length:D.length};D.forEach((e,t)=>{Z[e]=t});var j={length:R.length};R.forEach((e,t)=>{j[e]=t});var ee={};W.forEach((e,t)=>{ee[e]=t});var Ve={ch:128,cc:D.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:R.length,dnc:128,ext:2,efx:7,cvn:12,redir:32};var te=["MSB","PRG","LSB","NME","ELC","DRM"],O=function(e){let t=Math.floor(e/10),a=e%10;return`${t.toString(16)}${a}`},M=class{#t;strictMode=!1;get(e=0,t=0,a=0,s){let r=[e,t,a],n,h=1,u=0,p,i=Array.from(arguments);switch(s){case"xg":{switch(e){case 0:{a==126?i[2]=125:a==127&&(i[2]=0);break}case 16:{a==126&&(i[2]=0);break}case 32:{a>125&&(i[2]=0),i[2]+=4;break}case 33:case 34:case 35:case 36:{a>125&&(i[2]=0),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:{a==126&&(i[2]=0);break}case 48:case 64:case 126:case 127:{a==126&&(i[2]=0);break}}break}case"gs":{e==0&&a<5?i[2]=0:e>125&&a<5&&a!=2&&(i[2]=e,i[0]=0);break}case"g2":case"sd":{e>>1==40?i[2]|=16:e>95&&e<100&&(i[2]|=16,t>>3==15&&(i[0]=96));break}case"sg":{e==8&&a==0&&(i[2]=5);break}case"s90es":{a<8?i[2]+=17:a<32?i[2]+=13:i[2]=(i[2]>>3)+19;break}case"motif":{a<8?i[2]+=28:a<32?i[2]+=13:i[2]=(i[2]>>3)+19;break}}let o=" ",c="M",b=0,g=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||s=="gs"&&i[2]<5?c="GM-a":(c="y",b=3);break}case 8:{s=="sg"?c="GM-s":c="r:";break}case 32:case 33:case 34:case 35:case 36:{s=="xg"&&(c=`${["AP","VL","PF","DX","AN"][e&7]}-${"abcdefgh"[a]}`);break}case 48:{c=`yM${(i[2]>>3).toString().padStart(2,"0")}`,b=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 $=i[2];c=$<10?"kP:":"kC:",c+=$%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?g=63:i[2]>>4==1&&(g=16),b=3;break}case 97:{c=i[2]>>4==1?"SDa":"VL:",b=3,i[2]>>4==1?g=16:g=112;break}case 98:{c=i[2]>>4==1?"SDb":"SG-a",b=3,g=16;break}case 99:{c=i[2]>>4==1?"SDc":"DX",i[2]>63?g=63:i[2]>>4==1&&(g=16),b=3;break}case 100:{c="AN",i[2]>63?g=63:i[2]>>4==1&&(g=16),b=3;break}case 104:case 105:case 106:case 107:{c="SDd",g=104;break}case 121:{c=`GM-${i[2]?"":"a"}`,b=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,a,i[0],i[2]][b]-g}`.padStart(4-c.length,"0")),s=="xg"&&(e==0?i[2]<100?c=c.replace("y0","y:"):i[2]==125&&(c="y126"):e==16?(n=`Voice${((i[2]<<7)+i[1]+1).toString().padStart(3,"0")}`,o=" "):e==35&&a>>1==2&&(n=`DXCH_${(((i[2]&1)<<7)+t+1).toString().padStart(3,"0")}`,o=" "));let y=[i[0],i[1],i[2]];for(;!(n?.length>=0);)if(n=this.#t[i[1]||0][(i[0]<<7)+i[2]]?.name,n){let $=this.#t[i[1]||0][(i[0]<<7)+i[2]];h=$?.poly||h,u=$?.type||u,p=$?.drum}else if(this.strictMode)n="",o="?";else if(i[0]==0&&i[1]==0&&i[2]==0)n="Unloaded";else if(this.#t[i[1]||0][i[0]<<7])i[0]==0?(i[2]=0,o="^"):i[2]<1?(i[0]=0,o="*"):(i[2]--,o="^");else if(e==48)i[0]=0,i[2]=0,o="!";else if(e==62)i[1]--,o=" ",i[1]<1&&!n?.length&&(i[0]=0,o="!");else if(e<63)i[0]==0?(i[2]=0,o="^"):i[2]<1?(i[0]=0,o="*"):i[2]--;else if(e==80)n=`PrgU:${t.toString().padStart(3,"0")}`,o="!";else if(e==88)n=`CmbU:${t.toString().padStart(3,"0")}`,o="!";else if(e==121)n=`GM2Vox0${a}`,o="#";else if(e==122)if(i[1]==32?i[1]==0:i[1]%=7,n=this.#t[i[1]||0][(i[0]<<7)+i[2]]?.name,n){o=" ";let $=this.#t[i[1]||0][(i[0]<<7)+i[2]];h=$?.poly||h,u=$?.type||u,p=$?.drum}else n="",o="*";else i[1]==0?(n=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${a.toString().padStart(3,"0")}`,o="!"):i[0]==0?(i[2]=0,o="^"):i[2]>0?i[2]--:i[1]>0?(i[1]=0,o="!"):(i[0]=0,o="?");let E=[i[0],i[1],i[2]];(s=="gs"||s=="ns5r")&&o=="^"&&(o=" "),e==127&&o=="^"&&(o=" "),o!=" "&&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 32:case 33:case 35:case 36:{i[2]>4?d=["AP","VL","PF","DX","AN"][i[0]-32]:d="GS";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&&s=="xg"?d="XG":d="GS")}return{name:n||`${O(e||0)} ${O(t||0)} ${O(a||0)}`,poly:h,type:u,drum:p,iid:y,eid:E,sid:r,ending:o,sect:c,standard:d}}async load(e,t,a="(internal)"){let s=this,r=[],n=0,h=0;e.split(` +`).forEach(function(u,p){let i=u.split(" "),o=[];if(p==0){if(i.forEach(function(c,b){r[te.indexOf(c)]=b}),r.length<4){console.debug("Debugger launched.");debugger}}else{let c=0,b=0,g=0,y,E=1,d=0,$;i.forEach(async function(m,K){switch(K){case r[0]:{c=parseInt(m);break}case r[1]:{b=parseInt(m);break}case r[2]:{g=parseInt(m);break}case r[3]:{y=m;break}case r[4]:{m=parseInt(m),m<16?E=m+1:d=(m&15)+1;break}case r[5]:{$=m;break}}}),s.#t[b]=s.#t[b]||[];let L=s.#t[b];if(!L[c<<7|g]||t){let m={msb:c,prg:b,lsb:g,name:y,poly:E,type:d,drum:$};L[c<<7|g]=m,n++}h++}}),t||console.debug(`Map "${a}": ${h} total, ${n} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],a=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],s=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let r=a[0];r<=a[1];r++){let n=r<<7;for(let h=s[0];h<=s[1];h++){let u=n+h;for(let p=t[0];p<=t[1];p++)delete this.#t[p][u]}}}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(a){try{await fetch(`./data/bank/${a}.tsv`).then(function(s){return s.text()}).then(s=>{t.load(s,!1,a)})}catch{console.error(`Failed loading "${a}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var v=["?","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]],x=[120,127,120,127,120,127,61,62,62,62,120,122,122],ae=[0,3,81,84,88],H={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},A={0:0,1:1,2:3,5:4},_=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],X=[36,37];var 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,12,13,16,17,18,19],se=[33,99,100,32,102,8,9,10];var k={};v.forEach((e,t)=>{k[e]=t});var f={length:U.length};U.forEach((e,t)=>{f[e]=t});var S=function(){return!!self.Bun||self.debugMode||!1},ie=function(e){let t=[],a=0;return e?.forEach(function(s,r){s==247?t.push(e.subarray(a,r)):s==240&&(a=r+1)}),t.length||t.push(e.subarray(0)),S(),t},V=function(e,t="",a="",s=2){return e?`${t}${e.toString().padStart(s,"0")}${a}`:""},l={ch:128,cc:U.length,nn:128,pl:512,tr:256,cmt:14,rpn:6},Ze=class extends T{#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);#B=new Uint8Array(l.ch);#e=new Uint8ClampedArray(l.ch*l.cc);#$=new Uint8ClampedArray(l.ch);#l=new Uint8ClampedArray(l.ch*l.nn);#O=new Uint8Array(l.ch);#n=new Uint16Array(l.pl);#f=new Uint8Array(l.pl);#x=new Int16Array(l.ch);#d=new Uint8Array(l.ch);#C=0;#o=new Uint8Array(l.ch*l.rpn);#A=new Int8Array(l.ch*X.length);#U=new Uint8Array(l.ch);#K=new Uint8Array(128);#G=new Uint8Array(l.cmt*8);#F=new Uint8Array(1024);#H=new Uint8Array(l.cmt*64);#k=0;#u=0;#M=100;#E=0;#_=500;#z=0;#i="";#p=0;#q=0;#Q=!0;#s=!1;#X;#Y=new Uint8Array(2);#a=[];#m=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,a){if(this.#v[t])return(this.#v[t]-1)*16+e;if([k.gs,k.ns5r].indexOf(this.#t)>-1){if(a==1)return e;let s=0,r=!0;for(;r;)this.#m[e+s]==0?(this.#m[e+s]=t,console.debug(`Assign track ${t} to channel ${e+s+1}.`),r=!1):this.#m[e+s]==t?r=!1:(s+=16,s>=128&&(s=0,r=!1));return e+s}else return e}#c=[];#T;#r={nOff:(e,t)=>{let a=e*128+t,s=this.#n.lastIndexOf(a);s>-1&&(this.#e[l.cc*e+f[64]]>63&&!this.config?.disableCc64?this.#f[s]=4:(this.#n[s]=0,this.#l[a]=0,this.#f[s]=0))},nOn:(e,t,a)=>{let s=e*128+t,r=0;for(this.#O[e]&&this.#r.ano(e);this.#f[r]>0&&this.#n[r]!=s;)r++;r{},cAt:(e,t)=>{},hoOf:e=>{this.#f.forEach((t,a)=>{if(t==4){let s=this.#n[a],r=s>>7;e==r&&(this.#f[a]=0,this.#n[a]=0,this.#l[s]=0)}})},soOf:e=>{},ano:e=>{this.#n.forEach((t,a,s)=>{let r=t>>7,n=t&127;t==0&&this.#l[0]==0||r==e&&this.#r.nOff(r,n)})}};#V={8:function(e){let t=e.channel,a=e.data[0];this.#r.nOff(t,a)},9:function(e){let t=e.channel;this.#y[t]=1;let a=e.data[0],s=e.data[1];s>0?this.#r.nOn(t,a,s):this.#r.nOff(t,a)},10:function(e){let a=e.channel*128+e.data[0];this.#n.indexOf(a)>-1&&(this.#l[a]=data[1])},11:function(e){let t=e.channel;this.#y[t]=1;let a=t*l.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 s=t*l.cc;this.#e[s+f[1]]=0,this.#e[s+f[5]]=0,this.#e[s+f[64]]=0,this.#e[s+f[65]]=0,this.#e[s+f[66]]=0,this.#e[s+f[67]]=0,this.#e[s+f[11]]=127,this.#e[s+f[101]]=127,this.#e[s+f[100]]=127,this.#e[s+f[99]]=127,this.#e[s+f[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.#O[t]=1,this.#r.ano(t);return}case 127:{this.#O[t]=0,this.#r.ano(t);return}}if(f[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(e.data[0]){case 0:{if(S()&&console.debug(`${v[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#e[a]>119&&(e.data[1]=this.#e[a],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==k.gs)e.data[1]<56&&this.#e[a]>119&&(e.data[1]=this.#e[a],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`));else if(this.#t==k.gm)e.data[1]<48?this.#e[a]>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==k.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let s=0;for(let r=0;r<16;r++){let n=this.#e[l.cc*r];(n==56||n==62)&&s++}s>14&&this.switchMode("ag10",!0)}}break}case 6:{if(this.#C){let s=this.#e[a+f[99]],r=this.#e[a+f[98]];if(s==1){let n=se.indexOf(r);if(n>-1)this.#e[a+f[71+n]]=e.data[1],S()&&console.debug(`Redirected NRPN 1 ${r} to cc${71+n}.`);else{let h=X.indexOf(r);h>-1&&(this.#A[t*10+h]=e.data[1]-64),S()&&console.debug(`CH${t+1} voice NRPN ${r} commit`)}}}else{let s=A[this.#e[a+f[100]]];this.#e[a+f[101]]==0&&s!=null&&(S()&&console.debug(`CH${t+1} RPN 0 ${this.#e[a+f[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],_[s][0]),_[s][1]),this.#o[t*l.rpn+s]=e.data[1])}break}case 38:{this.#C||this.#e[a+101]==0&&A[this.#e[a+100]]!=null&&(this.#o[t*l.rpn+A[this.#e[a+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.#C=1;break}case 100:case 101:{this.#C=0;break}}this.#e[a+f[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,S()&&console.debug(`T:${e.track} C:${t} P:${e.data}`)},13:function(e){let t=this,a=e.channel;this.#n.forEach(function(s){let r=s>>7;a==r&&(t.#l[s]=e.data)})},14:function(e){let t=e.channel;this.#x[t]=e.data[1]*128+e.data[0]-8192},15:function(e){ie(e.data).forEach(t=>{let a=t[0],s=t[1];(this.#W[a]||function(){console.debug(`Unknown manufacturer ${a}.`)})(s,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(a,s,r){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#E=0),ae.indexOf(e.meta)>-1)return e.reply="meta",e;S()&&console.debug(e)}};#W={64:(e,t,a)=>{this.#N.run(t,a,e)},65:(e,t,a)=>{if(t[0]<16)this.#S.run(t,a,e),console.warn("Unknown device SysEx!");else{let s=t[t.length-1],r=gsChecksum(t.subarray(2,t.length-1));s==r?this.#S.run(t.subarray(0,t.length-1),a,e):console.warn(`Bad GS checksum ${s}. Should be ${r}.`)}},66:(e,t,a)=>{this.#D.run(t,a,e)},67:(e,t,a)=>{this.#R.run(t,a,e)},68:(e,t,a)=>{this.#J.run(t,a,e)},71:(e,t,a)=>{this.#I.run(t,a,e)},126:(e,t,a)=>{this.#L.run(t,a,e)},127:(e,t,a)=>{this.switchMode("gm"),this.#P.run(t,a,e)}};#L;#P;#R;#S;#D;#N;#I;#J;buildRchTree(){let e=[];this.#B.forEach((t,a)=>{e[t]?.constructor||(e[t]=[]),e[t].push(a)}),this.#X=e}getActive(){let e=this.#y.slice();return this.#t==k.mt32,e}getCc(e){let t=e*l.cc,a=this.#e.slice(t,t+l.cc);return a[f[0]]=a[f[0]]||this.#k,a[f[32]]=a[f[32]]||this.#u,a}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&t.set(h,{v:a.#l[s],s:a.#f[r]})}),t}getBitmap(){return{bitmap:this.#h,expire:this.#b}}getLetter(){return{text:this.#i,expire:this.#p}}getMode(){return v[this.#t]}getMaster(){return{volume:this.#M}}getRawStrength(){let e=this;return this.#n.forEach(function(t){let a=Math.floor(t/128);e.#l[t]>e.#d[a]&&(e.#d[a]=e.#l[t])}),this.#d}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(a,s){e[s]=Math.floor(a*t.#e[s*l.cc+f[7]]*t.#e[s*l.cc+f[11]]*t.#M/803288)}),e}getRpn(){return this.#o}getNrpn(){return this.#A}getVoice(e,t,a,s){let r=e||this.#k,n=t,h=a||this.#u;v[this.#t]=="ns5r"&&r>0&&r<56&&(h=3);let u=this.userBank.get(r,n,h,s);if(v[this.#t]=="mt32"&&u.name.indexOf("MT-m:")==0){let p=parseInt(u.name.slice(5)),i=p*l.cmt,o="";this.#H.subarray(i,i+10).forEach(c=>{c>31&&(o+=String.fromCharCode(c))}),this.userBank.load(`MSB LSB PRG +0 127 ${n} ${o}`,!0),u.name=o,u.ending=" "}return(u.ending!=" "||!u.name.length)&&(u=this.baseBank.get(r,n,h,s)),u}getChVoice(e){let t=this.getVoice(this.#e[e*l.cc+f[0]],this.#$[e],this.#e[e*l.cc+f[32]],v[this.#t]);if(this.#U[e])switch(this.#t){case k.mt32:t.ending="~",t.name="",this.#G.subarray(14*(e-1),14*(e-1)+10).forEach(a=>{a>31&&(t.name+=String.fromCharCode(a))})}return t}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#k=0,this.#u=0,this.#E=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.#M=100,this.#a=[],this.#_=500,this.#z=0,this.#p=0,this.#i="",this.#b=0,this.#w=0,this.#h.fill(0),this.#s=!1,this.#q=0,this.#Q=!0,this.#B.forEach(function(t,a,s){s[a]=a}),this.buildRchTree(),e==0&&(this.#m.fill(0),this.#v.fill(0)),this.#e[l.cc*9]=x[0],this.#e[l.cc*25]=x[0],this.#e[l.cc*41]=x[0],this.#e[l.cc*57]=x[0],this.#Y.fill(0),this.#F.fill(0),this.#H.fill(0),this.#K.fill(0),this.#G.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=a,this.#w=0,this.#k=G[0][a],this.#u=G[1][a];for(let s=0;s-1&&(this.#e[s*l.cc]=x[a]);switch(this.initOnReset,a){case k.mt32:{mt32DefProg.forEach((s,r)=>{let n=r+1;this.#y[n]||(this.#$[n]=s,this.#e[n*l.cc+f[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.#V[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),a=!1;this.#X[t]?.forEach(s=>{e.channel=s,a=!0,this.#V[e.type].call(this,e)}),a||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.#a.length>100&&this.#a.splice(100,this.#a.length-99)}runRaw(e){}constructor(){super();let e=this;this.#h=new Uint8Array(256),this.#g[10]=new Uint8Array(512),this.#T=new w,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.#s=!0,this.#a.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#s=!0,this.#a.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#s=!0,this.#a.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#s=!0,this.#a.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#s=!0,this.#a.unshift(`Kara.Ver: ${t.slice(2)}`);break}case"XF":{let a=t.slice(2).split(":");switch(a[0]){case"hd":{a.slice(1).forEach((s,r)=>{s.length&&this.#a.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][r]}: ${s}`)});break}case"ln":{a.slice(1).forEach((s,r)=>{s.length&&this.#a.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][r]}: ${s}`)});break}default:this.#a.unshift(`XGF_Data: ${t}`)}break}default:this.#s?t[0]=="\\"?this.#a.unshift(`@ ${t.slice(1)}`):t[0]=="/"?this.#a.unshift(t.slice(1)):this.#a[0]+=t:(this.#a[0]=t,this.#a.unshift(""))}},this.#c[2]=function(t){this.#a.unshift(`Copyrite: ${t}`)},this.#c[3]=function(t,a){a<1&&this.#E<1&&this.#a.unshift(`TrkTitle: ${t}`)},this.#c[4]=function(t,a){this.#a.unshift(`${V(this.#E,""," ")}Instrmnt: ${t}`)},this.#c[5]=function(t){t.trim()==""?this.#a.unshift(""):this.#a[0]+=`${t}`},this.#c[6]=function(t){this.#a.unshift(`${V(this.#E,""," ")}C.Marker: ${t}`)},this.#c[7]=function(t){this.#a.unshift(`CuePoint: ${t}`)},this.#c[32]=function(t){this.#E=t[0]+1},this.#c[33]=function(t,a){console.debug(`Track ${a} requests to get assigned to output ${t}.`),e.#v[a]=t+1},this.#c[81]=function(t,a){e.#_=t/1e3},this.#c[127]=function(t,a){e.#T.run(t,a)},this.#T.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#T.add([67,0,1],function(t,a){e.#v[a]=t[0]+1}),this.#L=new w,this.#P=new w,this.#R=new w,this.#S=new w,this.#O=new w,this.#N=new w,this.#I=new w,this.#L.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#s=e.#s||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#P.add([4,1],t=>{e.#M=((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.#s=!1,console.info("MIDI reset: XG");break}}}).add([76,6,0],t=>{let a=t[0];a<64?(e.#i=" ".repeat(a),e.#p=Date.now()+3200,t.subarray(1).forEach(function(s){e.#i+=String.fromCharCode(s)}),e.#i=e.#i.padEnd(32," ")):e.#p=Date.now()}).add([76,7,0],t=>{let a=t[0];e.#b=Date.now()+3200,e.#h.fill(0);let s=t.subarray(1);for(let r=0;r>6-h&1,h++})}),this.#R.add([43,7,0],(t,a,s)=>{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,a,s)=>{e.#b=Date.now()+3200,e.#h.fill(0),t.forEach(function(r,n){let l=Math.floor(n/16),u=n%16,p=(u*3+l)*7,i=7,h=0;for(p-=u*5,l==2&&(i=2);h>6-h&1,h++})}),this.#S.add([66,18,0,0,127],(t,a,s)=>{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.#s=!1,e.#m.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,a,s)=>{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.#s=!1,e.#m.fill(0),console.info("MIDI reset: GS");break}}}).add([69,18,16],t=>{switch(t[0]){case 0:{e.#p=Date.now()+3200;let a=t[1];e.#i=" ".repeat(a),t.subarray(2).forEach(function(s){s<128&&(e.#i+=String.fromCharCode(s))});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 a=e.#g[t[0]-1],s=t[1];a.fill(0);let r=t.subarray(2);for(let n=0;n>4-c&1,c++})}else console.warn(`Unknown GS display section: ${t[0]}`)}}),this.#S.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#s=!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 a=t[1],s=" ".repeat(a);t.subarray(2).forEach(r=>{r>31&&(s+=String.fromCharCode(r))}),e.#i=s.padStart(20," "),e.#p=Date.now()+3200}).add([22,18,82],(t,a)=>{let s=e.chRedir(0,a,!0);for(let r=0;r<16;r++)e.#r.ano(s+r),r&&r<10&&(e.#$[s+r]=mt32DefProg[r-1]);console.info("MT-32 alt reset complete.")}),this.#O.add([66,0],(t,a)=>{e.switchMode("ns5r",!0),e.#s=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,a)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#s=!1}).add([66,18,0,0],(t,a)=>{switch(t[0]){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#s=!1;break}}}).add([66,18,8,0],(t,a)=>{}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let a=new Uint8Array(5760);korgFilter(t,(s,r,n)=>{if(r<720)for(let l=0;l<8;l++)a[r*8+l]=s>>7-l&1}),e.dispatchEvent("screen",{type:"ns5r",data:a})}).add([76],(t,a,s)=>{e.#O.run([66,...t],a,s)}),this.#N.add([16,0,8,0],(t,a,s)=>{let r=(t[2]<<4)+t[3],n="K11 ";([()=>{e.switchMode("k11",!0),e.#s=!1,e.#u=r?4:0,console.info("MIDI reset: GMega/K11")}][t[0]]||(()=>{}))()}),this.#I.add([66,93,64],(t,a,s)=>{let r=t[2];switch(t[0]){case 0:{switch(t[1]){case 127:{e.switchMode("sg",!0);break}}break}}})}};export{Ze as OctaviaDevice,o as allocated,f as ccToPos}; +122 006 000 `),this.#c[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#s=!0,this.#a.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#s=!0,this.#a.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#s=!0,this.#a.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#s=!0,this.#a.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#s=!0,this.#a.unshift(`Kara.Ver: ${t.slice(2)}`);break}case"XF":{let a=t.slice(2).split(":");switch(a[0]){case"hd":{a.slice(1).forEach((s,r)=>{s.length&&this.#a.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][r]}: ${s}`)});break}case"ln":{a.slice(1).forEach((s,r)=>{s.length&&this.#a.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][r]}: ${s}`)});break}default:this.#a.unshift(`XGF_Data: ${t}`)}break}default:this.#s?t[0]=="\\"?this.#a.unshift(`@ ${t.slice(1)}`):t[0]=="/"?this.#a.unshift(t.slice(1)):this.#a[0]+=t:(this.#a[0]=t,this.#a.unshift(""))}},this.#c[2]=function(t){this.#a.unshift(`Copyrite: ${t}`)},this.#c[3]=function(t,a){a<1&&this.#E<1&&this.#a.unshift(`TrkTitle: ${t}`)},this.#c[4]=function(t,a){this.#a.unshift(`${V(this.#E,""," ")}Instrmnt: ${t}`)},this.#c[5]=function(t){t.trim()==""?this.#a.unshift(""):this.#a[0]+=`${t}`},this.#c[6]=function(t){this.#a.unshift(`${V(this.#E,""," ")}C.Marker: ${t}`)},this.#c[7]=function(t){this.#a.unshift(`CuePoint: ${t}`)},this.#c[32]=function(t){this.#E=t[0]+1},this.#c[33]=function(t,a){console.debug(`Track ${a} requests to get assigned to output ${t}.`),e.#v[a]=t+1},this.#c[81]=function(t,a){e.#_=t/1e3},this.#c[127]=function(t,a){e.#T.run(t,a)},this.#T.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#T.add([67,0,1],function(t,a){e.#v[a]=t[0]+1}),this.#L=new w,this.#P=new w,this.#R=new w,this.#S=new w,this.#D=new w,this.#N=new w,this.#I=new w,this.#L.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#s=e.#s||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#P.add([4,1],t=>{e.#M=((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.#s=!1,console.info("MIDI reset: XG");break}}}).add([76,6,0],t=>{let a=t[0];a<64?(e.#i=" ".repeat(a),e.#p=Date.now()+3200,t.subarray(1).forEach(function(s){e.#i+=String.fromCharCode(s)}),e.#i=e.#i.padEnd(32," ")):e.#p=Date.now()}).add([76,7,0],t=>{let a=t[0];e.#b=Date.now()+3200,e.#h.fill(0);let s=t.subarray(1);for(let r=0;r>6-o&1,o++})}),this.#R.add([43,7,0],(t,a,s)=>{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,a,s)=>{e.#b=Date.now()+3200,e.#h.fill(0),t.forEach(function(r,n){let h=Math.floor(n/16),u=n%16,p=(u*3+h)*7,i=7,o=0;for(p-=u*5,h==2&&(i=2);o>6-o&1,o++})}),this.#S.add([66,18,0,0,127],(t,a,s)=>{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.#s=!1,e.#m.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,a,s)=>{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.#s=!1,e.#m.fill(0),console.info("MIDI reset: GS");break}}}).add([69,18,16],t=>{switch(t[0]){case 0:{e.#p=Date.now()+3200;let a=t[1];e.#i=" ".repeat(a),t.subarray(2).forEach(function(s){s<128&&(e.#i+=String.fromCharCode(s))});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 a=e.#g[t[0]-1],s=t[1];a.fill(0);let r=t.subarray(2);for(let n=0;n>4-c&1,c++})}else console.warn(`Unknown GS display section: ${t[0]}`)}}),this.#S.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#s=!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 a=t[1],s=" ".repeat(a);t.subarray(2).forEach(r=>{r>31&&(s+=String.fromCharCode(r))}),e.#i=s.padStart(20," "),e.#p=Date.now()+3200}).add([22,18,82],(t,a)=>{let s=e.chRedir(0,a,!0);for(let r=0;r<16;r++)e.#r.ano(s+r),r&&r<10&&(e.#$[s+r]=mt32DefProg[r-1]);console.info("MT-32 alt reset complete.")}),this.#D.add([66,0],(t,a)=>{e.switchMode("ns5r",!0),e.#s=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,a)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#s=!1}).add([66,18,0,0],(t,a)=>{switch(t[0]){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#s=!1;break}}}).add([66,18,8,0],(t,a)=>{}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let a=new Uint8Array(5760);korgFilter(t,(s,r,n)=>{if(r<720)for(let h=0;h<8;h++)a[r*8+h]=s>>7-h&1}),e.dispatchEvent("screen",{type:"ns5r",data:a})}).add([76],(t,a,s)=>{e.#D.run([66,...t],a,s)}),this.#N.add([16,0,8,0],(t,a,s)=>{let r=(t[2]<<4)+t[3],n="K11 ";([()=>{e.switchMode("k11",!0),e.#s=!1,e.#u=r?4:0,console.info("MIDI reset: GMega/K11")}][t[0]]||(()=>{}))()}),this.#I.add([66,93,64],(t,a,s)=>{let r=t[2];switch(t[0]){case 0:{switch(t[1]){case 127:{e.switchMode("sg",!0);break}}break}}})}};export{Ze as OctaviaDevice,l as allocated,f as ccToPos}; diff --git a/dist/xp_basic.mjs b/dist/xp_basic.mjs index d7e9fa93..aefbe55d 100644 --- a/dist/xp_basic.mjs +++ b/dist/xp_basic.mjs @@ -1,8 +1,8 @@ -var wa=Object.create;var Ct=Object.defineProperty;var ka=Object.getOwnPropertyDescriptor;var xa=Object.getOwnPropertyNames;var Sa=Object.getPrototypeOf,Ta=Object.prototype.hasOwnProperty;var Ca=(b,e,r)=>e in b?Ct(b,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):b[e]=r;var Gt=(b,e)=>()=>(b&&(e=b(b=0)),e);var Ma=(b,e)=>()=>(e||b((e={exports:{}}).exports,e),e.exports);var Ra=(b,e,r,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of xa(e))!Ta.call(b,o)&&o!==r&&Ct(b,o,{get:()=>e[o],enumerable:!(d=ka(e,o))||d.enumerable});return b};var Da=(b,e,r)=>(r=b!=null?wa(Sa(b)):{},Ra(e||!b||!b.__esModule?Ct(r,"default",{value:b,enumerable:!0}):r,b));var D=(b,e,r)=>(Ca(b,typeof e!="symbol"?e+"":e,r),r),_t=(b,e,r)=>{if(!e.has(b))throw TypeError("Cannot "+r)};var t=(b,e,r)=>(_t(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)},x=(b,e,r,d)=>(_t(b,e,"write to private field"),d?d.call(b,r):e.set(b,r),r);var Xt=Gt(()=>{"use strict";I();(function(){var b=function(E,w,a){var c,n;if(self.MessageEvent)switch(E){case"message":{n=new MessageEvent(E,{data:w,ports:a==null?void 0:a.ports}),Object.defineProperty(n,"source",{value:a==null?void 0:a.source});break}default:n=new Event(E)}else n=document.createEvent("Event"),n.initEvent(E,!1,!1),a&&E=="message"&&(n.data=w,a.source&&Object.defineProperty(n,"source",{value:a.source}),(c=a.ports)!=null&&c.length&&Object.defineProperty(n,"ports",{value:a.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={},o=function(E){var w,a=this;if((this==null?void 0:this.constructor)!=o)throw new TypeError("Illegal constructor");r.push(this),(w=d[E])!=null&&w.constructor||(d[E]=[]),d[E].push(this);var c=Math.floor(Math.random()*281474976710656),n=[],i=0,s=[],f=!0,h=!1;Object.defineProperty(this,"id",{get:function(){return c}}),Object.defineProperty(this,"name",{value:E}),this.close=function(){var u,m=r.indexOf(a);m>-1?(e.postMessage({t:"d",c:E,i:c}),r.splice(m,1),(u=d[E])!=null&&u.constructor&&(m=d[E].indexOf(a),m>-1&&d[E].splice(m,1)),d[E].length||delete d[E],console.debug("[Snowy] BroadcastChannel closed."),h=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(u){if(e){if(h)throw new Error("Channel already closed");e.postMessage({t:"m",c:E,i:c,m:i,d:u}),i++,i>4294967295&&(i=0)}else s.push(u),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(f){for(e.postMessage({t:"r",c:E,i:c}),console.debug("[Snowy] ".concat(s.length," message(s) in cache."));s.length;){var u=s.shift();a.postMessage(u)}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(u){u.c==E?u.i!=c&&a.dispatchEvent(b("message",u.d,{source:a})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(c," receives from ").concat(E,", not ").concat(u.c,"."))};var l={};this.dispatchEvent=function(u){var m,k;if(Object.defineProperty(u,"target",{value:a}),Object.defineProperty(u,"currentTarget",{value:a}),(m=l[u.type])!=null&&m.length)for(var C=l[u.type],M=0;M-1&&l[u].splice(M,1)}!((C=l[u])!=null&&C.length)&&l[u].constructor&&delete l[u]}},self.BroadcastChannel=o,p=function(){if(e){e.addEventListener("message",function(w){var a=w.data,c=!1;switch(a.t){case"k":{c=!1,e.postMessage({t:"k"});break}case"m":{var n=d[a.c];if(n!=null&&n.length)for(var i=0;i{"use strict";Xt();{let b=function(e,r){let d=new FileReader;return new Promise((o,p)=>{switch(d.addEventListener("abort",()=>{p(new Error("Blob read aborted"))}),d.addEventListener("error",$=>{p(d.error||$.data||new Error("Blob read error"))}),d.addEventListener("load",()=>{o(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,o=this,p=[];for(;r-1;){let $=o.lastIndexOf(b);p.unshift(o.slice($+b.length)),o=o.slice(0,$),$==0&&p.unshift(""),r++}return o.length&&p.unshift(o),p.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(b,e){if(e){let r=this;for(;r.length{I();(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,o){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,o);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(d,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(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;o=o||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 $=new FileReader;$.readAsArrayBuffer(p.target.files[0]),$.onload=function(E){o(r.Uint8(new Uint8Array(E.target.result)))}})},Base64:function(d){let o=function(E){var w="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(E=E.replace(/^.*?base64,/,""),E=String(E).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(E))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");E+="==".slice(2-(3&E.length));let a,c="",n,i,s=0;for(;s>16&255):i===64?String.fromCharCode(a>>16&255,a>>8&255):String.fromCharCode(a>>16&255,a>>8&255,255&a);return c}(d=String(d));var p=o.length;let $=new Uint8Array(new ArrayBuffer(p));for(let E=0;E{i[l]=this.readInt(1)});for(let h=0;h191||u>127&&u<160)throw new RangeError(`Invalid code point: ${u}`)}s=!0,console.debug(`String byte sequence in ${e[h].encoding}`)}catch(l){console.debug(`SMF string ${l}`)}return f||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let n=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)n=this.readInt(1);else{let s=[];for(;128<=this.data.getUint8(this.pointer);)s.push(this.readInt(1)-128);var i=this.readInt(1);for(let f=1;f<=s.length;f++)n+=s[s.length-f]*Math.pow(128,f);n+=i}return n}};if(o.data=new DataView($.buffer,$.byteOffset,$.byteLength),o.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;o.readInt(4);let p={};p.formatType=o.readInt(2),p.tracks=o.readInt(2),p.track=[];var $=o.readInt(1),E=o.readInt(1);128<=$?(p.timeDivision=[],p.timeDivision[0]=$-128,p.timeDivision[1]=E):p.timeDivision=256*$+E;for(let n=1;n<=p.tracks;n++){p.track[n-1]={event:[]};var w,a=o.readInt(4);if(a===-1)break;if(a!==1297379947)return!1;o.readInt(4);let i=0,s=!1,f,h;for(;!s&&(i++,p.track[n-1].event[i-1]={},p.track[n-1].event[i-1].deltaTime=o.readIntVLV(),(f=o.readInt(1))!==-1);)if(128<=f?h=f:(f=h,o.movePointer(-1)),f===255){p.track[n-1].event[i-1].type=255,p.track[n-1].event[i-1].metaType=o.readInt(1);var c=o.readIntVLV();switch(p.track[n-1].event[i-1].metaType){case 47:case-1:s=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:p.track[n-1].event[i-1].data=o.readStr(c);break;case 33:case 89:case 81:p.track[n-1].event[i-1].data=o.readInt(c);break;case 84:p.track[n-1].event[i-1].data=[],p.track[n-1].event[i-1].data[0]=o.readInt(1),p.track[n-1].event[i-1].data[1]=o.readInt(1),p.track[n-1].event[i-1].data[2]=o.readInt(1),p.track[n-1].event[i-1].data[3]=o.readInt(1),p.track[n-1].event[i-1].data[4]=o.readInt(1);break;case 88:p.track[n-1].event[i-1].data=[],p.track[n-1].event[i-1].data[0]=o.readInt(1),p.track[n-1].event[i-1].data[1]=o.readInt(1),p.track[n-1].event[i-1].data[2]=o.readInt(1),p.track[n-1].event[i-1].data[3]=o.readInt(1);break;default:this.customInterpreter!==null&&(p.track[n-1].event[i-1].data=this.customInterpreter(p.track[n-1].event[i-1].metaType,o,c)),this.customInterpreter!==null&&p.track[n-1].event[i-1].data!==!1||(o.readInt(c),p.track[n-1].event[i-1].data=o.readInt(c),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[n-1].event[i-1].type=parseInt(f[0],16),p.track[n-1].event[i-1].channel=parseInt(f[1],16),p.track[n-1].event[i-1].type){case 15:this.customInterpreter!==null&&(p.track[n-1].event[i-1].data=this.customInterpreter(p.track[n-1].event[i-1].type,o,!1)),this.customInterpreter!==null&&p.track[n-1].event[i-1].data!==!1||(w=o.readIntVLV(),p.track[n-1].event[i-1].data=o.readInt(w),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[n-1].event[i-1].data=[],p.track[n-1].event[i-1].data[0]=o.readInt(1),p.track[n-1].event[i-1].data[1]=o.readInt(1);break;case 12:case 13:p.track[n-1].event[i-1].data=o.readInt(1);break;case-1:s=!0;break;default:if(this.customInterpreter!==null&&(p.track[n-1].event[i-1].data=this.customInterpreter(p.track[n-1].event[i-1].metaType,o,!1)),this.customInterpreter===null||p.track[n-1].event[i-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return p},customInterpreter:null};if(typeof Pt<"u")Pt.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}})()});I();I();var Z,Vt,$t=(Vt=class{constructor(){S(this,Z,{})}addEventListener(b,e){t(this,Z)[b]||(t(this,Z)[b]=[]),t(this,Z)[b].unshift(e)}removeEventListener(b,e){if(t(this,Z)[b]){let r=t(this,Z)[b].indexOf(e);r>-1&&t(this,Z)[b].splice(r,1),t(this,Z)[b].length<1&&delete t(this,Z)[b]}}dispatchEvent(b,e){var o;let r=new Event(b),d=this;r.data=e,((o=t(this,Z)[b])==null?void 0:o.length)>0&&t(this,Z)[b].forEach(function(p){try{p==null||p.call(d,r)}catch($){console.error($)}}),this[`on${b}`]&&this[`on${b}`](r)}},Z=new WeakMap,Vt);I();I();var Ft=function(b,e){let r=Math.min(b.length,e.length),d=b.slice(0,r),o=e.slice(0,r),p=0,$=0;for(;$0){let d=this.pool.length,o=1<=1&&$>=0;){if($<=0)throw new Error("TTL reached.");if(p==d)p-=o;else{let w=Ft(e,this.pool[p]);switch(w){case 0:{$=0;break}case 1:{p+o<=d&&(p+=o);break}case-1:{p!=0&&(p-=o);break}default:console.warn(`Unexpected result ${w}.`)}}o=o>>1,$--}let E=!0;if(p>=this.pool.length)E=!1;else{let w=this;this.pool[p].forEach(function(a,c,n){E&&a!=e[c]&&(E=!1)}),!E&&Ft(e,this.pool[p])>0&&p++}return E||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)}};I();var Oa=["MSB","PRG","LSB","NME","ELC","DRM"],Mt=function(b){let e=Math.floor(b/10),r=b%10;return`${e.toString(16)}${r}`},Y,Kt,Rt=(Kt=class{constructor(...b){S(this,Y,void 0);D(this,"strictMode",!1);this.loadFiles(...b)}get(b=0,e=0,r=0,d){var u,m;let o=[b,e,r],p,$=1,E=0,w,a=Array.from(arguments);switch(d){case"xg":{switch(b){case 0:{r==126?a[2]=125:r==127&&(a[2]=0);break}case 16:{r==126&&(a[2]=0);break}case 32:{r>125&&(a[2]=0),a[2]+=4;break}case 33:case 34:case 35:case 36:{r>125&&(a[2]=0),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:{r==126&&(a[2]=0);break}case 48:case 64:case 126:case 127:{r==126&&(a[2]=0);break}}break}case"gs":{b==0&&r<5?a[2]=0:b>125&&r<5&&r!=2&&(a[2]=b,a[0]=0);break}case"g2":case"sd":{b>>1==40?a[2]|=16:b>95&&b<100&&(a[2]|=16,e>>3==15&&(a[0]=96));break}case"sg":{b==8&&r==0&&(a[2]=5);break}case"s90es":{r<8?a[2]+=17:r<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}case"motif":{r<8?a[2]+=28:r<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}}let c=" ",n="M",i=0,s=0;switch(a[0]){case 0:{a[2]==127?n="MT-a":a[2]==126?n="MT-b":a[2]==7?n="GM-k":a[2]==5?n="SG-a":a[2]==4?n="SP-l":a[2]==0||d=="gs"&&a[2]<5?n="GM-a":(n="y",i=3);break}case 8:{d=="sg"?n="GM-s":n="r:";break}case 32:case 33:case 34:case 35:case 36:{d=="xg"&&(n=`${["AP","VL","PF","DX","AN"][b&7]}-${"abcdefgh"[r]}`);break}case 48:{n=`yM${(a[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(a[2]<17){let k=a[2];n=k<10?"kP:":"kC:",n+=k%10}else a[2]<34?n=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][a[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"[a[0]-80]}`;break}case 88:case 89:case 90:case 91:{n=`Cmb${"UABC"[a[0]-88]}`;break}case 95:{n=`${["DR","PC"][a[2]]}-d`;break}case 96:{n=a[2]==106?"AP-a":a[2]>>4==1?"SDg":"PF",a[2]>63?s=63:a[2]>>4==1&&(s=16),i=3;break}case 97:{n=a[2]>>4==1?"SDa":"VL:",i=3,a[2]>>4==1?s=16:s=112;break}case 98:{n=a[2]>>4==1?"SDb":"SG-a",i=3,s=16;break}case 99:{n=a[2]>>4==1?"SDc":"DX",a[2]>63?s=63:a[2]>>4==1&&(s=16),i=3;break}case 100:{n="AN",a[2]>63?s=63:a[2]>>4==1&&(s=16),i=3;break}case 104:case 105:case 106:case 107:{n="SDd",s=104;break}case 121:{n=`GM-${a[2]?"":"a"}`,i=3;break}case 122:{n="lDrm";break}case 126:{n="yDrS";break}case 127:{a[2]==127?n="rDrm":n="yDrm";break}default:a[0]<48?n="r:":n="M"}n.length<4&&(n+=`${[b,r,a[0],a[2]][i]-s}`.padStart(4-n.length,"0")),d=="xg"&&(b==0?a[2]<100?n=n.replace("y0","y:"):a[2]==125&&(n="y126"):b==16&&(p=`Voice${(a[2]*128+a[1]+1).toString().padStart(3,"0")}`,c=" "));let f=[a[0],a[1],a[2]];for(;!((p==null?void 0:p.length)>=0);)if(p=(u=t(this,Y)[a[1]||0][(a[0]<<7)+a[2]])==null?void 0:u.name,p){let k=t(this,Y)[a[1]||0][(a[0]<<7)+a[2]];$=(k==null?void 0:k.poly)||$,E=(k==null?void 0:k.type)||E,w=k==null?void 0:k.drum}else if(this.strictMode)p="",c="?";else if(a[0]==0&&a[1]==0&&a[2]==0)p="Unloaded";else if(t(this,Y)[a[1]||0][a[0]<<7])a[0]==0?(a[2]=0,c="^"):a[2]<1?(a[0]=0,c="*"):(a[2]--,c="^");else if(b==48)a[0]=0,a[2]=0,c="!";else if(b==62)a[1]--,c=" ",a[1]<1&&!(p!=null&&p.length)&&(a[0]=0,c="!");else if(b<63)a[0]==0?(a[2]=0,c="^"):a[2]<1?(a[0]=0,c="*"):a[2]--;else if(b==80)p=`PrgU:${e.toString().padStart(3,"0")}`,c="!";else if(b==88)p=`CmbU:${e.toString().padStart(3,"0")}`,c="!";else if(b==121)p=`GM2Vox0${r}`,c="#";else if(b==122){if(a[1]==32?a[1]==0:a[1]%=7,p=(m=t(this,Y)[a[1]||0][(a[0]<<7)+a[2]])==null?void 0:m.name,p){c=" ";let k=t(this,Y)[a[1]||0][(a[0]<<7)+a[2]];$=(k==null?void 0:k.poly)||$,E=(k==null?void 0:k.type)||E,w=k==null?void 0:k.drum}else p="",c="*"}else a[1]==0?(p=`${b.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${r.toString().padStart(3,"0")}`,c="!"):a[0]==0?(a[2]=0,c="^"):a[2]>0?a[2]--:a[1]>0?(a[1]=0,c="!"):(a[0]=0,c="?");let h=[a[0],a[1],a[2]];(d=="gs"||d=="ns5r")&&c=="^"&&(c=" "),b==127&&c=="^"&&(c=" "),c!=" "&&self.debugMode&&(p="");let l="??";switch(a[0]){case 0:{a[2]==0?l="GM":a[2]==5||a[2]==7?l="KG":a[2]<126?l="XG":a[2]==127&&(l="MT");break}case 32:case 33:case 35:case 36:{a[2]>4?l=["AP","VL","PF","DX","AN"][a[0]-32]:l="GS";break}case 48:{l="MU";break}case 56:{l="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{l="AI";break}case 62:case 82:case 90:{l="XD";break}case 63:{a[2]<17?l="KR":a[2]<34?l="ES":l="DS";break}case 64:case 126:{l="XG";break}case 67:case 99:{l=a[2]>>4==1?"SD":"DX";break}case 81:{l="RW";break}case 95:{l=["DR","PC"][a[2]];break}case 96:{l=a[2]==106?"AP":a[2]>>4==1?"SD":"PF";break}case 97:{l=a[2]>>4==1?"SD":"VL";break}case 98:{l=a[2]>>4==1?"SD":"SG";break}case 100:{l="AN";break}case 104:case 105:case 106:case 107:{l="SD";break}case 120:{l="GS";break}case 121:{l=a[2]?"G2":"GM";break}case 122:{l="KG";break}case 127:{l=a[2]==127?"MT":e==0?"GM":"XG";break}default:a[0]<48&&(a[0]==16&&d=="xg"?l="XG":l="GS")}return{name:p||`${Mt(b||0)} ${Mt(e||0)} ${Mt(r||0)}`,poly:$,type:E,drum:w,iid:f,eid:h,sid:o,ending:c,sect:n,standard:l}}async load(b,e,r="(internal)"){let d=this,o=[],p=0,$=0;b.split(` -`).forEach(function(E,w){let a=E.split("\t"),c=[];if(w==0){if(a.forEach(function(n,i){o[Oa.indexOf(n)]=i}),o.length<4){console.debug("Debugger launched.");debugger}}else{let n=0,i=0,s=0,f,h=1,l=0,u;a.forEach(async function(k,C){switch(C){case o[0]:{n=parseInt(k);break}case o[1]:{i=parseInt(k);break}case o[2]:{s=parseInt(k);break}case o[3]:{f=k;break}case o[4]:{k=parseInt(k),k<16?h=k+1:l=(k&15)+1;break}case o[5]:{u=k;break}}}),t(d,Y)[i]=t(d,Y)[i]||[];let m=t(d,Y)[i];if(!m[n<<7|s]||e){let k={msb:n,prg:i,lsb:s,name:f,poly:h,type:l,drum:u};m[n<<7|s]=k,p++}$++}}),e||console.debug(`Map "${r}": ${$} 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 o=r[0];o<=r[1];o++){let p=o<<7;for(let $=d[0];$<=d[1];$++){let E=p+$;for(let w=e[0];w<=e[1];w++)delete t(this,Y)[w][E]}}}init(){x(this,Y,[]);for(let b=0;b<128;b++)t(this,Y).push([""])}async loadFiles(...b){this.init();let e=this;b.forEach(async function(r){try{await fetch(`./data/bank/${r}.tsv`).then(function(d){return d.text()}).then(d=>{e.load(d,!1,r)})}catch(d){console.error(`Failed loading "${r}.tsv".`)}})}},Y=new WeakMap,Kt);I();I();var Je,zt,qt=(zt=class{constructor(){S(this,Je,{});D(this,"context")}set(b,e){t(this,Je)[b]=e}has(b){return!!t(this,Je)[b]}async read(b,e){if(!this.has(b))throw new Error(`No decoder registered for "${b}"`);return await t(this,Je)[b].call(this.context||this,e)}},Je=new WeakMap,zt);var Aa=function(b,e){let r=!0;return e.forEach((d,o)=>{r=r&&b[o]==d}),r},Qt=function(b){let e=0;return b.forEach(r=>{e*=256,e+=r}),e},dt=new TextDecoder,wt=new qt;wt.set("s7e",async function(b){let e=new Uint8Array(await b.slice(0,65536).arrayBuffer()),r="MSB\tLSB\tPRG\tNME",d=[0,0,0,0],o=32,p=0,$=0,E=!0,w=[],a=0;for(;E;){let c=e.subarray(p);([()=>{dt.decode(c.subarray(0,4))=="YSFC"?(p+=80,$=1):p++},()=>{if(Aa(c.subarray(0,4),d))w.forEach((n,i,s)=>{let f=Qt(e.subarray(n.start+4,n.start+8));n.length=f}),$=2;else{let n=dt.decode(c.subarray(0,4)),i=Qt(c.subarray(4,8));w.push({type:n,start:i}),p+=8}},()=>{let n=w[a],i=e.subarray(n.start,n.start+n.length),s=32;switch(n.type){case"ENVC":{let f=o;for(;fe in b?Mt(b,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):b[e]=r;var Gt=(b,e)=>()=>(b&&(e=b(b=0)),e);var Ra=(b,e)=>()=>(e||b((e={exports:{}}).exports,e),e.exports);var Da=(b,e,r,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Sa(e))!Ca.call(b,o)&&o!==r&&Mt(b,o,{get:()=>e[o],enumerable:!(d=xa(e,o))||d.enumerable});return b};var Oa=(b,e,r)=>(r=b!=null?ka(Ta(b)):{},Da(e||!b||!b.__esModule?Mt(r,"default",{value:b,enumerable:!0}):r,b));var D=(b,e,r)=>(Ma(b,typeof e!="symbol"?e+"":e,r),r),Xt=(b,e,r)=>{if(!e.has(b))throw TypeError("Cannot "+r)};var t=(b,e,r)=>(Xt(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)},x=(b,e,r,d)=>(Xt(b,e,"write to private field"),d?d.call(b,r):e.set(b,r),r);var Vt=Gt(()=>{"use strict";I();(function(){var b=function(v,k,a){var n,c;if(self.MessageEvent)switch(v){case"message":{c=new MessageEvent(v,{data:k,ports:a==null?void 0:a.ports}),Object.defineProperty(c,"source",{value:a==null?void 0:a.source});break}default:c=new Event(v)}else c=document.createEvent("Event"),c.initEvent(v,!1,!1),a&&v=="message"&&(c.data=k,a.source&&Object.defineProperty(c,"source",{value:a.source}),(n=a.ports)!=null&&n.length&&Object.defineProperty(c,"ports",{value:a.ports}));return c};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),r=[],d={},o=function(v){var k,a=this;if((this==null?void 0:this.constructor)!=o)throw new TypeError("Illegal constructor");r.push(this),(k=d[v])!=null&&k.constructor||(d[v]=[]),d[v].push(this);var n=Math.floor(Math.random()*281474976710656),c=[],i=0,s=[],f=!0,h=!1;Object.defineProperty(this,"id",{get:function(){return n}}),Object.defineProperty(this,"name",{value:v}),this.close=function(){var u,m=r.indexOf(a);m>-1?(e.postMessage({t:"d",c:v,i:n}),r.splice(m,1),(u=d[v])!=null&&u.constructor&&(m=d[v].indexOf(a),m>-1&&d[v].splice(m,1)),d[v].length||delete d[v],console.debug("[Snowy] BroadcastChannel closed."),h=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(u){if(e){if(h)throw new Error("Channel already closed");e.postMessage({t:"m",c:v,i:n,m:i,d:u}),i++,i>4294967295&&(i=0)}else s.push(u),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(f){for(e.postMessage({t:"r",c:v,i:n}),console.debug("[Snowy] ".concat(s.length," message(s) in cache."));s.length;){var u=s.shift();a.postMessage(u)}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(u){u.c==v?u.i!=n&&a.dispatchEvent(b("message",u.d,{source:a})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(n," receives from ").concat(v,", not ").concat(u.c,"."))};var l={};this.dispatchEvent=function(u){var m,w;if(Object.defineProperty(u,"target",{value:a}),Object.defineProperty(u,"currentTarget",{value:a}),(m=l[u.type])!=null&&m.length)for(var C=l[u.type],M=0;M-1&&l[u].splice(M,1)}!((C=l[u])!=null&&C.length)&&l[u].constructor&&delete l[u]}},self.BroadcastChannel=o,p=function(){if(e){e.addEventListener("message",function(k){var a=k.data,n=!1;switch(a.t){case"k":{n=!1,e.postMessage({t:"k"});break}case"m":{var c=d[a.c];if(c!=null&&c.length)for(var i=0;i{"use strict";Vt();{let b=function(e,r){let d=new FileReader;return new Promise((o,p)=>{switch(d.addEventListener("abort",()=>{p(new Error("Blob read aborted"))}),d.addEventListener("error",$=>{p(d.error||$.data||new Error("Blob read error"))}),d.addEventListener("load",()=>{o(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,o=this,p=[];for(;r-1;){let $=o.lastIndexOf(b);p.unshift(o.slice($+b.length)),o=o.slice(0,$),$==0&&p.unshift(""),r++}return o.length&&p.unshift(o),p.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(b,e){if(e){let r=this;for(;r.length{I();(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,o){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,o);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(d,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(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;o=o||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 $=new FileReader;$.readAsArrayBuffer(p.target.files[0]),$.onload=function(v){o(r.Uint8(new Uint8Array(v.target.result)))}})},Base64:function(d){let o=function(v){var k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(v=v.replace(/^.*?base64,/,""),v=String(v).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(v))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");v+="==".slice(2-(3&v.length));let a,n="",c,i,s=0;for(;s>16&255):i===64?String.fromCharCode(a>>16&255,a>>8&255):String.fromCharCode(a>>16&255,a>>8&255,255&a);return n}(d=String(d));var p=o.length;let $=new Uint8Array(new ArrayBuffer(p));for(let v=0;v{i[l]=this.readInt(1)});for(let h=0;h191||u>127&&u<160)throw new RangeError(`Invalid code point: ${u}`)}s=!0,console.debug(`String byte sequence in ${e[h].encoding}`)}catch(l){console.debug(`SMF string ${l}`)}return f||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let c=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)c=this.readInt(1);else{let s=[];for(;128<=this.data.getUint8(this.pointer);)s.push(this.readInt(1)-128);var i=this.readInt(1);for(let f=1;f<=s.length;f++)c+=s[s.length-f]*Math.pow(128,f);c+=i}return c}};if(o.data=new DataView($.buffer,$.byteOffset,$.byteLength),o.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;o.readInt(4);let p={};p.formatType=o.readInt(2),p.tracks=o.readInt(2),p.track=[];var $=o.readInt(1),v=o.readInt(1);128<=$?(p.timeDivision=[],p.timeDivision[0]=$-128,p.timeDivision[1]=v):p.timeDivision=256*$+v;for(let c=1;c<=p.tracks;c++){p.track[c-1]={event:[]};var k,a=o.readInt(4);if(a===-1)break;if(a!==1297379947)return!1;o.readInt(4);let i=0,s=!1,f,h;for(;!s&&(i++,p.track[c-1].event[i-1]={},p.track[c-1].event[i-1].deltaTime=o.readIntVLV(),(f=o.readInt(1))!==-1);)if(128<=f?h=f:(f=h,o.movePointer(-1)),f===255){p.track[c-1].event[i-1].type=255,p.track[c-1].event[i-1].metaType=o.readInt(1);var n=o.readIntVLV();switch(p.track[c-1].event[i-1].metaType){case 47:case-1:s=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:p.track[c-1].event[i-1].data=o.readStr(n);break;case 33:case 89:case 81:p.track[c-1].event[i-1].data=o.readInt(n);break;case 84:p.track[c-1].event[i-1].data=[],p.track[c-1].event[i-1].data[0]=o.readInt(1),p.track[c-1].event[i-1].data[1]=o.readInt(1),p.track[c-1].event[i-1].data[2]=o.readInt(1),p.track[c-1].event[i-1].data[3]=o.readInt(1),p.track[c-1].event[i-1].data[4]=o.readInt(1);break;case 88:p.track[c-1].event[i-1].data=[],p.track[c-1].event[i-1].data[0]=o.readInt(1),p.track[c-1].event[i-1].data[1]=o.readInt(1),p.track[c-1].event[i-1].data[2]=o.readInt(1),p.track[c-1].event[i-1].data[3]=o.readInt(1);break;default:this.customInterpreter!==null&&(p.track[c-1].event[i-1].data=this.customInterpreter(p.track[c-1].event[i-1].metaType,o,n)),this.customInterpreter!==null&&p.track[c-1].event[i-1].data!==!1||(o.readInt(n),p.track[c-1].event[i-1].data=o.readInt(n),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[c-1].event[i-1].type=parseInt(f[0],16),p.track[c-1].event[i-1].channel=parseInt(f[1],16),p.track[c-1].event[i-1].type){case 15:this.customInterpreter!==null&&(p.track[c-1].event[i-1].data=this.customInterpreter(p.track[c-1].event[i-1].type,o,!1)),this.customInterpreter!==null&&p.track[c-1].event[i-1].data!==!1||(k=o.readIntVLV(),p.track[c-1].event[i-1].data=o.readInt(k),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[c-1].event[i-1].data=[],p.track[c-1].event[i-1].data[0]=o.readInt(1),p.track[c-1].event[i-1].data[1]=o.readInt(1);break;case 12:case 13:p.track[c-1].event[i-1].data=o.readInt(1);break;case-1:s=!0;break;default:if(this.customInterpreter!==null&&(p.track[c-1].event[i-1].data=this.customInterpreter(p.track[c-1].event[i-1].metaType,o,!1)),this.customInterpreter===null||p.track[c-1].event[i-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return p},customInterpreter:null};if(typeof Ut<"u")Ut.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}})()});I();I();var Z,Ft,wt=(Ft=class{constructor(){S(this,Z,{})}addEventListener(b,e){t(this,Z)[b]||(t(this,Z)[b]=[]),t(this,Z)[b].unshift(e)}removeEventListener(b,e){if(t(this,Z)[b]){let r=t(this,Z)[b].indexOf(e);r>-1&&t(this,Z)[b].splice(r,1),t(this,Z)[b].length<1&&delete t(this,Z)[b]}}dispatchEvent(b,e){var o;let r=new Event(b),d=this;r.data=e,((o=t(this,Z)[b])==null?void 0:o.length)>0&&t(this,Z)[b].forEach(function(p){try{p==null||p.call(d,r)}catch($){console.error($)}}),this[`on${b}`]&&this[`on${b}`](r)}},Z=new WeakMap,Ft);I();I();var Kt=function(b,e){let r=Math.min(b.length,e.length),d=b.slice(0,r),o=e.slice(0,r),p=0,$=0;for(;$0){let d=this.pool.length,o=1<=1&&$>=0;){if($<=0)throw new Error("TTL reached.");if(p==d)p-=o;else{let k=Kt(e,this.pool[p]);switch(k){case 0:{$=0;break}case 1:{p+o<=d&&(p+=o);break}case-1:{p!=0&&(p-=o);break}default:console.warn(`Unexpected result ${k}.`)}}o=o>>1,$--}let v=!0;if(p>=this.pool.length)v=!1;else{let k=this;this.pool[p].forEach(function(a,n,c){v&&a!=e[n]&&(v=!1)}),!v&&Kt(e,this.pool[p])>0&&p++}return v||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)}};I();var Aa=["MSB","PRG","LSB","NME","ELC","DRM"],Rt=function(b){let e=Math.floor(b/10),r=b%10;return`${e.toString(16)}${r}`},Y,zt,Dt=(zt=class{constructor(...b){S(this,Y,void 0);D(this,"strictMode",!1);this.loadFiles(...b)}get(b=0,e=0,r=0,d){var u,m;let o=[b,e,r],p,$=1,v=0,k,a=Array.from(arguments);switch(d){case"xg":{switch(b){case 0:{r==126?a[2]=125:r==127&&(a[2]=0);break}case 16:{r==126&&(a[2]=0);break}case 32:{r>125&&(a[2]=0),a[2]+=4;break}case 33:case 34:case 35:case 36:{r>125&&(a[2]=0),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:{r==126&&(a[2]=0);break}case 48:case 64:case 126:case 127:{r==126&&(a[2]=0);break}}break}case"gs":{b==0&&r<5?a[2]=0:b>125&&r<5&&r!=2&&(a[2]=b,a[0]=0);break}case"g2":case"sd":{b>>1==40?a[2]|=16:b>95&&b<100&&(a[2]|=16,e>>3==15&&(a[0]=96));break}case"sg":{b==8&&r==0&&(a[2]=5);break}case"s90es":{r<8?a[2]+=17:r<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}case"motif":{r<8?a[2]+=28:r<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}}let n=" ",c="M",i=0,s=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||d=="gs"&&a[2]<5?c="GM-a":(c="y",i=3);break}case 8:{d=="sg"?c="GM-s":c="r:";break}case 32:case 33:case 34:case 35:case 36:{d=="xg"&&(c=`${["AP","VL","PF","DX","AN"][b&7]}-${"abcdefgh"[r]}`);break}case 48:{c=`yM${(a[2]>>3).toString().padStart(2,"0")}`,i=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 w=a[2];c=w<10?"kP:":"kC:",c+=w%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?s=63:a[2]>>4==1&&(s=16),i=3;break}case 97:{c=a[2]>>4==1?"SDa":"VL:",i=3,a[2]>>4==1?s=16:s=112;break}case 98:{c=a[2]>>4==1?"SDb":"SG-a",i=3,s=16;break}case 99:{c=a[2]>>4==1?"SDc":"DX",a[2]>63?s=63:a[2]>>4==1&&(s=16),i=3;break}case 100:{c="AN",a[2]>63?s=63:a[2]>>4==1&&(s=16),i=3;break}case 104:case 105:case 106:case 107:{c="SDd",s=104;break}case 121:{c=`GM-${a[2]?"":"a"}`,i=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+=`${[b,r,a[0],a[2]][i]-s}`.padStart(4-c.length,"0")),d=="xg"&&(b==0?a[2]<100?c=c.replace("y0","y:"):a[2]==125&&(c="y126"):b==16?(p=`Voice${((a[2]<<7)+a[1]+1).toString().padStart(3,"0")}`,n=" "):b==35&&r>>1==2&&(p=`DXCH_${(((a[2]&1)<<7)+e+1).toString().padStart(3,"0")}`,n=" "));let f=[a[0],a[1],a[2]];for(;!((p==null?void 0:p.length)>=0);)if(p=(u=t(this,Y)[a[1]||0][(a[0]<<7)+a[2]])==null?void 0:u.name,p){let w=t(this,Y)[a[1]||0][(a[0]<<7)+a[2]];$=(w==null?void 0:w.poly)||$,v=(w==null?void 0:w.type)||v,k=w==null?void 0:w.drum}else if(this.strictMode)p="",n="?";else if(a[0]==0&&a[1]==0&&a[2]==0)p="Unloaded";else if(t(this,Y)[a[1]||0][a[0]<<7])a[0]==0?(a[2]=0,n="^"):a[2]<1?(a[0]=0,n="*"):(a[2]--,n="^");else if(b==48)a[0]=0,a[2]=0,n="!";else if(b==62)a[1]--,n=" ",a[1]<1&&!(p!=null&&p.length)&&(a[0]=0,n="!");else if(b<63)a[0]==0?(a[2]=0,n="^"):a[2]<1?(a[0]=0,n="*"):a[2]--;else if(b==80)p=`PrgU:${e.toString().padStart(3,"0")}`,n="!";else if(b==88)p=`CmbU:${e.toString().padStart(3,"0")}`,n="!";else if(b==121)p=`GM2Vox0${r}`,n="#";else if(b==122){if(a[1]==32?a[1]==0:a[1]%=7,p=(m=t(this,Y)[a[1]||0][(a[0]<<7)+a[2]])==null?void 0:m.name,p){n=" ";let w=t(this,Y)[a[1]||0][(a[0]<<7)+a[2]];$=(w==null?void 0:w.poly)||$,v=(w==null?void 0:w.type)||v,k=w==null?void 0:w.drum}else p="",n="*";}else a[1]==0?(p=`${b.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${r.toString().padStart(3,"0")}`,n="!"):a[0]==0?(a[2]=0,n="^"):a[2]>0?a[2]--:a[1]>0?(a[1]=0,n="!"):(a[0]=0,n="?");let h=[a[0],a[1],a[2]];(d=="gs"||d=="ns5r")&&n=="^"&&(n=" "),b==127&&n=="^"&&(n=" "),n!=" "&&self.debugMode&&(p="");let l="??";switch(a[0]){case 0:{a[2]==0?l="GM":a[2]==5||a[2]==7?l="KG":a[2]<126?l="XG":a[2]==127&&(l="MT");break}case 32:case 33:case 35:case 36:{a[2]>4?l=["AP","VL","PF","DX","AN"][a[0]-32]:l="GS";break}case 48:{l="MU";break}case 56:{l="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{l="AI";break}case 62:case 82:case 90:{l="XD";break}case 63:{a[2]<17?l="KR":a[2]<34?l="ES":l="DS";break}case 64:case 126:{l="XG";break}case 67:case 99:{l=a[2]>>4==1?"SD":"DX";break}case 81:{l="RW";break}case 95:{l=["DR","PC"][a[2]];break}case 96:{l=a[2]==106?"AP":a[2]>>4==1?"SD":"PF";break}case 97:{l=a[2]>>4==1?"SD":"VL";break}case 98:{l=a[2]>>4==1?"SD":"SG";break}case 100:{l="AN";break}case 104:case 105:case 106:case 107:{l="SD";break}case 120:{l="GS";break}case 121:{l=a[2]?"G2":"GM";break}case 122:{l="KG";break}case 127:{l=a[2]==127?"MT":e==0?"GM":"XG";break}default:a[0]<48&&(a[0]==16&&d=="xg"?l="XG":l="GS")}return{name:p||`${Rt(b||0)} ${Rt(e||0)} ${Rt(r||0)}`,poly:$,type:v,drum:k,iid:f,eid:h,sid:o,ending:n,sect:c,standard:l}}async load(b,e,r="(internal)"){let d=this,o=[],p=0,$=0;b.split(` +`).forEach(function(v,k){let a=v.split("\t"),n=[];if(k==0){if(a.forEach(function(c,i){o[Aa.indexOf(c)]=i}),o.length<4){console.debug("Debugger launched.");debugger}}else{let c=0,i=0,s=0,f,h=1,l=0,u;a.forEach(async function(w,C){switch(C){case o[0]:{c=parseInt(w);break}case o[1]:{i=parseInt(w);break}case o[2]:{s=parseInt(w);break}case o[3]:{f=w;break}case o[4]:{w=parseInt(w),w<16?h=w+1:l=(w&15)+1;break}case o[5]:{u=w;break}}}),t(d,Y)[i]=t(d,Y)[i]||[];let m=t(d,Y)[i];if(!m[c<<7|s]||e){let w={msb:c,prg:i,lsb:s,name:f,poly:h,type:l,drum:u};m[c<<7|s]=w,p++}$++}}),e||console.debug(`Map "${r}": ${$} 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 o=r[0];o<=r[1];o++){let p=o<<7;for(let $=d[0];$<=d[1];$++){let v=p+$;for(let k=e[0];k<=e[1];k++)delete t(this,Y)[k][v]}}}init(){x(this,Y,[]);for(let b=0;b<128;b++)t(this,Y).push([""])}async loadFiles(...b){this.init();let e=this;b.forEach(async function(r){try{await fetch(`./data/bank/${r}.tsv`).then(function(d){return d.text()}).then(d=>{e.load(d,!1,r)})}catch(d){console.error(`Failed loading "${r}.tsv".`)}})}},Y=new WeakMap,zt);I();I();var Je,qt,Qt=(qt=class{constructor(){S(this,Je,{});D(this,"context")}set(b,e){t(this,Je)[b]=e}has(b){return!!t(this,Je)[b]}async read(b,e){if(!this.has(b))throw new Error(`No decoder registered for "${b}"`);return await t(this,Je)[b].call(this.context||this,e)}},Je=new WeakMap,qt);var La=function(b,e){let r=!0;return e.forEach((d,o)=>{r=r&&b[o]==d}),r},Yt=function(b){let e=0;return b.forEach(r=>{e*=256,e+=r}),e},dt=new TextDecoder,kt=new Qt;kt.set("s7e",async function(b){let e=new Uint8Array(await b.slice(0,65536).arrayBuffer()),r="MSB\tLSB\tPRG\tNME",d=[0,0,0,0],o=32,p=0,$=0,v=!0,k=[],a=0;for(;v;){let n=e.subarray(p);([()=>{dt.decode(n.subarray(0,4))=="YSFC"?(p+=80,$=1):p++},()=>{if(La(n.subarray(0,4),d))k.forEach((c,i,s)=>{let f=Yt(e.subarray(c.start+4,c.start+8));c.length=f}),$=2;else{let c=dt.decode(n.subarray(0,4)),i=Yt(n.subarray(4,8));k.push({type:c,start:i}),p+=8}},()=>{let c=k[a],i=e.subarray(c.start,c.start+c.length),s=32;switch(c.type){case"ENVC":{let f=o;for(;f=w.length&&($=3,E=!1)}][$]||(()=>{E=!1}))()}return r});I();var ft=["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"]),ht=["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"],La=[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],et=[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],Yt=[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],Wt=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},jt=function(b){return b>105?La[b-106]:b>100?b*1.1-100:b/10},Zt=",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(","),Dt={};`hi*, +063 ${(l[17]+1).toString().padStart(3,"0")} ${l[19].toString().padStart(3,"0")} ${u}`),h+=f}break}}a++,a>=k.length&&($=3,v=!1)}][$]||(()=>{v=!1}))()}return r});I();var ft=["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"]),ht=["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"],Ia=[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],et=[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],Wt=[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],jt=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},Zt=function(b){return b>105?Ia[b-106]:b>100?b*1.1-100:b/10},Jt=",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(","),Ot={};`hi*, ka,か ki,き ku,く @@ -139,7 +139,7 @@ o,お ~, ^, _,`.split(` -`).forEach(b=>{let e=b.split(",");Dt[e[0]]=e[1]});var Jt=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 Dt)e=e.replaceAll(d,Dt[d]);e.indexOf("\u3093")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},ea=function(b){return b?b<96?`cc${b}`:["aftertouch","velocity","pitch bend"][b-96]:"off"};I();var Ot=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],ta=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],aa=["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 Ia={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"},Pa={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]]},At=function(b){return Ia[(b[0]-32<<8)+b[1]]||`0x${b[0].toString(16).padStart(2,"0")}${b[1].toString(16).padStart(2,"0")}`},ra=function(b,e,r){let d=(b[0]-32<<16)+(b[1]<<8)+e,o=Pa[d]||{},p=o[0];if(p!=null&&p.length)return p+=`: ${(o[1]||function(){})(r)||r}`,p},Lt=[68,48,95,78,41,3,110,122,0];I();var J=function(b=64){return Math.round(2e3*Math.log10(b/64))/100},sa=function(b,e,r){let d=[],o=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)},Ie=function(b){let e=0;return b.forEach(r=>{e+=r,e=e&127}),~e+1&127},fe=function(b,e){let r=0,d=0;for(let o=0;o>p&1)<<7,E=b[o];E+=$,o%8!=0?(e(E,r,b),r++):d=b[o]}};var ut=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"],Ua={gm2:"g2","mt-32":"mt32","c/m":"mt32",ag10:"05rw","ag-10":"05rw","05r/w":"05rw",x5:"05rw",x5dr:"x5d",gmega:"k11","kross 2":"krs","motif es":"motif","s90 es":"s90es"},Ba=["melodic","drum","menu"],ia=[[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]],Pe=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],Na=[0,3,81,84,88],na={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},ca={0:0,1:1,2:3,5:4},oa={0:0,1:1,2:2,5:3},la=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],da=[36,37,48,49,52,53],St=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],fa={26:127,29:0,30:0,31:0,52:12,53:54},bt=[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,14,15,20,21,26,28,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157],Ha=[2,12,13,14,15,16,17,18,19,20,21,136,130,131,132,133,134,135,137,138,139],Ga=[33,99,100,32,102,8,9,10],ha=[0,16,25,40,32,64,26,48],T={};he.forEach((b,e)=>{T[b]=e});var y={length:bt.length};bt.forEach((b,e)=>{y[b]=e});var se={length:St.length};St.forEach((b,e)=>{se[b]=e});var _a={};Ba.forEach((b,e)=>{_a[b]=e});var A=function(){return!!self.Bun||self.debugMode||!1},Xa=function(b){let e=[],r=0;return b==null||b.forEach(function(d,o){d==247?e.push(b.subarray(r,o)):d==240&&(r=o+1)}),e.length||e.push(b.subarray(0)),A()&&console.debug(e),e};var v={ch:128,cc:bt.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:St.length,dnc:128,ext:2,efx:7,redir:32},pt={bank0:128},P,W,ue,Ee,re,ye,pa,ve,K,O,g,me,U,V,ee,F,z,$e,pe,Ue,be,R,L,tt,j,te,at,Be,ge,Te,le,rt,Ce,Me,ie,G,B,Ne,st,it,Re,De,gt,nt,de,N,kt,yt,He,It,ae,we,Oe,q,Ge,X,Et,xt,_e,Xe,ne,ce,ke,Ve,Fe,Ke,ua,Rr=(ua=class extends $t{constructor(){super();S(this,re);D(this,"NOTE_IDLE",0);D(this,"NOTE_ATTACK",1);D(this,"NOTE_DECAY",2);D(this,"NOTE_SUSTAIN",3);D(this,"NOTE_HELD",4);D(this,"NOTE_RELEASE",5);D(this,"NOTE_SOSTENUTO_ATTACK",8);D(this,"NOTE_SOSTENUTO_DECAY",9);D(this,"NOTE_SOSTENUTO_SUSTAIN",10);D(this,"NOTE_SOSTENUTO_HELD",11);D(this,"CH_MELODIC",0);D(this,"CH_DRUMS",1);D(this,"CH_DRUM1",2);D(this,"CH_DRUM2",3);D(this,"CH_DRUM3",4);D(this,"CH_DRUM4",5);D(this,"CH_DRUM5",6);D(this,"CH_DRUM6",7);D(this,"CH_DRUM7",8);D(this,"CH_DRUM8",9);D(this,"EXT_NONE",0);D(this,"EXT_VL",1);D(this,"VLBC_BRTHEXPR",1);D(this,"VLBC_VELOINIT",2);D(this,"VLBC_VELOALL",3);S(this,P,0);S(this,W,0);S(this,ue,0);S(this,Ee,new Array(11));S(this,ve,new Uint8Array(v.ch));S(this,K,new Uint8Array(v.ch));S(this,O,new Uint8Array(v.ch));S(this,g,new Uint8Array(v.ch*v.cc));S(this,me,new Uint8Array(v.ace));S(this,U,new Uint8Array(v.ch));S(this,V,new Uint8Array(v.ch*v.nn));S(this,ee,new Uint8Array(v.ch));S(this,F,new Uint16Array(v.pl));S(this,z,new Uint8Array(v.pl));S(this,$e,new Int16Array(v.ch));S(this,pe,new Uint8Array(v.ch));S(this,Ue,0);S(this,be,new Uint8Array(v.ch*v.ext));S(this,R,new Uint8Array(v.ch*v.rpn));S(this,L,new Uint8Array(v.ch*v.rpnt));S(this,tt,new Int8Array(v.ch*da.length));S(this,j,new Uint8Array(v.drm*v.dpn*v.dnc));S(this,te,new Uint8Array(v.efx*3));S(this,at,new Uint8Array(v.ch));S(this,Be,new Uint8Array(v.ch*v.redir));S(this,ge,new Uint8Array(v.ch));S(this,Te,new Uint8Array(128));S(this,le,new Uint8Array(v.cmt*8));S(this,rt,new Uint8Array(1024));S(this,Ce,new Uint8Array(v.cmt*64));S(this,Me,0);S(this,ie,0);S(this,G,void 0);S(this,B,100);S(this,Ne,0);S(this,st,500);S(this,it,0);S(this,Re,"");S(this,De,0);S(this,gt,0);S(this,nt,0);S(this,de,!0);S(this,N,!1);S(this,kt,1);S(this,yt,void 0);S(this,He,new Array(v.ch));S(this,It,new Uint8Array(2));S(this,ae,[]);S(this,we,new Uint8Array(v.ch));S(this,Oe,new Uint8Array(v.tr));D(this,"baseBank",new Rt("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","krs","s90es"));D(this,"userBank",new Rt("gm"));D(this,"initOnReset",!1);D(this,"aiEfxName","");S(this,q,[]);S(this,Ge,void 0);S(this,X,{nOff:(e,r)=>{let d=e*128+r,o=t(this,F).lastIndexOf(d);if(o>-1)if(t(this,g)[v.cc*e+y[64]]>63)t(this,z)[o]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,V)[d],state:this.NOTE_HELD});else if(t(this,g)[v.cc*e+y[66]]>63&&t(this,z)[o]==this.NOTE_SOSTENUTO_SUSTAIN)t(this,z)[o]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,V)[d],state:this.NOTE_SOSTENUTO_HELD});else{t(this,F)[o]=0,t(this,V)[d]=0,t(this,z)[o]=this.NOTE_IDLE;let p=this.getExt(e)[1];(p==this.VLBC_VELOINIT||p==this.VLBC_VELOALL)&&(t(this,g)[v.cc*e+y[129]]=0),this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})}},nOn:(e,r,d)=>{let o=e*128+r,p=0;for(t(this,ee)[e]&&t(this,X).ano(e);t(this,z)[p]>0&&t(this,F)[p]!=o;)p++;if(p{},cAt:(e,r)=>{},hoOf:e=>{t(this,z).forEach((r,d)=>{if(r==this.NOTE_HELD){let o=t(this,F)[d],p=o>>7;e==p&&(t(this,z)[d]=this.NOTE_IDLE,t(this,F)[d]=0,t(this,V)[o]=0,this.dispatchEvent("note",{part:e,note:o&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,z).forEach((r,d)=>{let o;switch(r){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,z)[d]=o;let p=t(this,F)[d];this.dispatchEvent("note",{part:e,note:p&127,velo:t(this,V)[p],state:o})}})},soOf:e=>{t(this,z).forEach((r,d)=>{if(r==this.NOTE_SOSTENUTO_HELD){let o=t(this,F)[d],p=o>>7;e==p&&(t(this,z)[d]=this.NOTE_IDLE,t(this,F)[d]=0,t(this,V)[o]=0,this.dispatchEvent("note",{part:e,note:o&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,F).forEach((r,d,o)=>{let p=r>>7,$=r&127;r==0&&t(this,V)[0]==0||p==e&&t(this,X).nOff(p,$)})}});S(this,Et,{8:function(e){let r=e.channel,d=e.data[0];t(this,X).nOff(r,d)},9:function(e){let r=e.channel;this.setChActive(r,1);let d=e.data[0],o=e.data[1];o>0?t(this,X).nOn(r,d,o):t(this,X).nOff(r,d)},10:function(e){let r=e.channel,d=r*128+e.data[0];t(this,F).indexOf(d)>-1&&(t(this,V)[d]=data[1],this.getExt(r)[1]==this.VLBC_VELOALL&&(t(this,g)[v.cc*r+y[129]]=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,d=t(this,He)[r],o=d[e.data[0]];o&&(e.data[0]=o),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,P)){case T.s90es:case T.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 p=r*v.cc,$=r*v.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,X).ano(r),t(this,$e)[r]=0,t(this,g)[p+y[1]]=0,t(this,g)[p+y[5]]=0,t(this,g)[p+y[64]]=0,t(this,g)[p+y[65]]=0,t(this,g)[p+y[66]]=0,t(this,g)[p+y[67]]=0,t(this,g)[p+y[11]]=127,t(this,g)[p+y[101]]=127,t(this,g)[p+y[100]]=127,t(this,g)[p+y[99]]=127,t(this,g)[p+y[98]]=127;return}case 123:{t(this,X).ano(r);return}case 124:{t(this,X).ano(r);return}case 125:{t(this,X).ano(r);return}case 126:{t(this,ee)[r]=1,t(this,X).ano(r);return}case 127:{t(this,ee)[r]=0,t(this,X).ano(r);return}}if(y[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Ha.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(A()&&console.debug(`${he[t(this,P)]}, CH${r+1}: ${e.data[1]}`),t(this,P)==0?e.data[1]<48?(t(this,O)[r]>0&&(e.data[1]=t(this,g)[p],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(t(this,G).x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(this.modeIdx[t(this,G).ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,P)==T.gs?e.data[1]<56&&t(this,O)[r]>0&&(e.data[1]=t(this,g)[p],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):t(this,P)==T.gm&&(e.data[1]<48?t(this,O)[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,P)){case T.xg:{[79,95,126,127].indexOf(e.data[1])>-1?t(this,O)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,O)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?t(this,be)[$]=this.EXT_VL:t(this,be)[$]=this.EXT_NONE;break}case T["05rw"]:case T.x5d:case T.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(this,O)[r]==this.CH_MELODIC&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):[80,81,82,83].indexOf(e.data[1])>-1||t(this,O)[r]!=this.CH_MELODIC&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case T.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,O)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,O)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case T.g2:{e.data[1]==120?t(this,O)[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,O)[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 2:{this.getExt(r)[1]==this.VLBC_BRTHEXPR&&(t(this,g)[p+y[129]]=e.data[1]);break}case 6:{if(t(this,Ue)){[T.xg,T.gs,T.ns5r].indexOf(t(this,P))<0&&console.warn(`NRPN commits are not available under "${he[t(this,P)]}" mode, even when they are supported in Octavia.`);let E=t(this,g)[p+y[99]],w=t(this,g)[p+y[98]];if(E==1){let a=Ga.indexOf(w);if(a>-1)t(this,g)[p+y[71+a]]=e.data[1],A()&&console.debug(`Redirected NRPN 1 ${w} to cc${71+a}.`),this.dispatchEvent("cc",{part:r,cc:71+a,data:e.data[1]});else{let c=da.indexOf(w);c>-1?t(this,tt)[r*10+c]=e.data[1]-64:console.warn(`NRPN 0x01${w.toString(16).padStart(2,"0")} is not supported.`),A()&&console.debug(`CH${r+1} voice NRPN ${w} commit`)}}else{if(St.indexOf(E)<0){let c=`NRPN 0x${E.toString(16).padStart(2,"0")}${w.toString(16).padStart(2,"0")} `;E==127?console.warn(`${c}is not necessary. Consider removing it.`):console.warn(`${c}is not supported.`)}else{let c=t(this,O)[r]-2;c<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${ht[t(this,O)[r]]}.`):t(this,j)[(c*v.dpn+se[E])*v.dnc+w]=e.data[1]}A()&&console.debug(`CH${r+1} (${ht[t(this,O)[r]]}) drum NRPN ${E} commit`)}}else{let E=ca[t(this,g)[p+y[100]]],w=oa[t(this,g)[p+y[100]]];t(this,g)[p+y[101]]==0&&E!=null&&(A()&&console.debug(`CH${r+1} RPN 0 ${t(this,g)[p+y[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],la[E][0]),la[E][1]),t(this,R)[r*v.rpn+E]=e.data[1],t(this,L)[r*v.rpnt+w]=1)}break}case 32:{switch(A()&&console.debug(`${he[t(this,P)]}, CH${r+1} LSB: ${e.data[1]}`),t(this,P)){case T.s90es:case T.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,P),!0);break}}this.dispatchEvent("voice",{part:r});break}case 38:{if(!t(this,Ue)){let E=ca[t(this,g)[p+100]],w=oa[t(this,g)[p+100]];t(this,g)[p+101]==0&&E!=null&&(t(this,R)[r*v.rpn+E+1]=e.data[1],t(this,L)[r*v.rpnt+w]=1)}break}case 64:{e.data[1]<64&&t(this,X).hoOf(r);break}case 66:{e.data[1]>>6?t(this,X).soOn(r):t(this,X).soOf(r);break}case 98:case 99:{x(this,Ue,1);break}case 100:case 101:{x(this,Ue,0);break}}t(this,g)[p+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,P)){case T.s90es:case T.motif:{e.data&&this.setChActive(r,1);break}default:this.setChActive(r,1)}t(this,U)[r]=e.data,t(this,ge)[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,F).forEach(function(o){let p=o>>7;d==p&&(t(r,V)[o]=e.data,r.dispatchEvent("note",{part:d,note:o&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){Xa(e.data).forEach(r=>{let d=r[0],o=r[1];(t(this,xt)[d]||function(){console.debug(`Unknown manufacturer ${d}.`)})(o,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,q)[e.meta]||function(d,o,p){}).call(this,e.data,e.track,e.meta),e.meta!=32&&x(this,Ne,0);let r=Na.indexOf(e.meta)>-1;if(A()&&console.debug(e),r)return e.reply="meta",e}});S(this,xt,{64:(e,r,d)=>{t(this,Ve).run(r,d,e)},65:(e,r,d)=>{if(r[0]<16){if(r[1]==72){let o=r[r.length-1],p=Ie(r.subarray(3,r.length-1));o==p?t(this,ce).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad SD checksum ${o}. Should be ${p}.`)}else t(this,ce).run(r,d,e)}else{let o=r[r.length-1],p=Ie(r.subarray(2,r.length-1));o==p?t(this,ce).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad GS checksum ${o}. Should be ${p}.`)}},66:(e,r,d)=>{t(this,ke).run(r,d,e)},67:(e,r,d)=>{t(this,ne).run(r,d,e)},68:(e,r,d)=>{t(this,Ke).run(r,d,e)},71:(e,r,d)=>{t(this,Fe).run(r,d,e)},126:(e,r,d)=>{t(this,_e).run(r,d,e)},127:(e,r,d)=>{this.switchMode("gm"),t(this,Xe).run(r,d,e)}});S(this,_e,void 0);S(this,Xe,void 0);S(this,ne,void 0);S(this,ce,void 0);S(this,ke,void 0);S(this,Ve,void 0);S(this,Fe,void 0);S(this,Ke,void 0);let e=this;x(e,re,new Uint8Array(256),pa),t(e,Ee)[10]=new Uint8Array(512),x(e,Ge,new oe),x(e,G,{x5:82,ds:T.krs}),e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME +`).forEach(b=>{let e=b.split(",");Ot[e[0]]=e[1]});var ea=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 Ot)e=e.replaceAll(d,Ot[d]);e.indexOf("\u3093")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},ta=function(b){return b?b<96?`cc${b}`:["aftertouch","velocity","pitch bend"][b-96]:"off"};I();var At=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],aa=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ra=["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 Pa={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"},Ua={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]]},Lt=function(b){return Pa[(b[0]-32<<8)+b[1]]||`0x${b[0].toString(16).padStart(2,"0")}${b[1].toString(16).padStart(2,"0")}`},sa=function(b,e,r){let d=(b[0]-32<<16)+(b[1]<<8)+e,o=Ua[d]||{},p=o[0];if(p!=null&&p.length)return p+=`: ${(o[1]||function(){})(r)||r}`,p},It=[68,48,95,78,41,3,110,122,0];I();var J=function(b=64){return Math.round(2e3*Math.log10(b/64))/100},ia=function(b,e,r){let d=[],o=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)},Te=function(b){let e=0;return b.forEach(r=>{e+=r,e=e&127}),~e+1&127},pe=function(b,e){let r=0,d=0;for(let o=0;o>p&1)<<7,v=b[o];v+=$,o%8!=0?(e(v,r,b),r++):d=b[o]}};var ut=function(b){let e=Math.floor(b*14.2);return e<128?e:0};var be=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],Ba={gm2:"g2","mt-32":"mt32","c/m":"mt32",ag10:"05rw","ag-10":"05rw","05r/w":"05rw",x5:"05rw",x5dr:"x5d",gmega:"k11","kross 2":"krs","motif es":"motif","s90 es":"s90es"},Na=["melodic","drum","menu"],na=[[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]],Pe=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],Ha=[0,3,81,84,88],ca={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},oa={0:0,1:1,2:3,5:4},la={0:0,1:1,2:2,5:3},da=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],fa=[36,37,48,49,52,53],Tt=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],ha={26:127,29:0,30:0,31:0,52:12,53:54},bt=[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,14,15,20,21,26,28,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157],_a=[2,12,13,14,15,16,17,18,19,20,21,136,130,131,132,133,134,135,137,138,139,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157],Ga=[33,99,100,32,102,8,9,10],ua=[0,16,25,40,32,64,26,48],T={};be.forEach((b,e)=>{T[b]=e});var y={length:bt.length};bt.forEach((b,e)=>{y[b]=e});var ne={length:Tt.length};Tt.forEach((b,e)=>{ne[b]=e});var Xa={};Na.forEach((b,e)=>{Xa[b]=e});var A=function(){return!!self.Bun||self.debugMode||!1},Va=function(b){let e=[],r=0;return b==null||b.forEach(function(d,o){d==247?e.push(b.subarray(r,o)):d==240&&(r=o+1)}),e.length||e.push(b.subarray(0)),A()&&console.debug(e),e};var E={ch:128,cc:bt.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:Tt.length,dnc:128,ext:2,efx:7,cvn:12,redir:32},pt={bank0:128},P,W,ge,ve,ie,Ee,ba,me,K,O,g,ce,U,V,ee,F,z,$e,ye,Ue,te,R,L,tt,j,ae,at,Be,fe,gt,Ce,he,rt,Me,Re,oe,_,B,Ne,st,it,De,Oe,yt,nt,ue,N,xt,Et,He,Pt,re,we,Ae,q,_e,X,vt,St,Ge,Xe,se,le,ke,Ve,Fe,Ke,pa,Dr=(pa=class extends wt{constructor(){super();S(this,ie);D(this,"NOTE_IDLE",0);D(this,"NOTE_ATTACK",1);D(this,"NOTE_DECAY",2);D(this,"NOTE_SUSTAIN",3);D(this,"NOTE_HELD",4);D(this,"NOTE_RELEASE",5);D(this,"NOTE_SOSTENUTO_ATTACK",8);D(this,"NOTE_SOSTENUTO_DECAY",9);D(this,"NOTE_SOSTENUTO_SUSTAIN",10);D(this,"NOTE_SOSTENUTO_HELD",11);D(this,"CH_MELODIC",0);D(this,"CH_DRUMS",1);D(this,"CH_DRUM1",2);D(this,"CH_DRUM2",3);D(this,"CH_DRUM3",4);D(this,"CH_DRUM4",5);D(this,"CH_DRUM5",6);D(this,"CH_DRUM6",7);D(this,"CH_DRUM7",8);D(this,"CH_DRUM8",9);D(this,"EXT_NONE",0);D(this,"EXT_VL",1);D(this,"EXT_DX",3);D(this,"VLBC_BRTHEXPR",1);D(this,"VLBC_VELOINIT",2);D(this,"VLBC_VELOALL",3);S(this,P,0);S(this,W,0);S(this,ge,0);S(this,ve,new Array(11));S(this,me,new Uint8Array(E.ch));S(this,K,new Uint8Array(E.ch));S(this,O,new Uint8Array(E.ch));S(this,g,new Uint8Array(E.ch*E.cc));S(this,ce,new Uint8Array(E.ace));S(this,U,new Uint8Array(E.ch));S(this,V,new Uint8Array(E.ch*E.nn));S(this,ee,new Uint8Array(E.ch));S(this,F,new Uint16Array(E.pl));S(this,z,new Uint8Array(E.pl));S(this,$e,new Int16Array(E.ch));S(this,ye,new Uint8Array(E.ch));S(this,Ue,0);S(this,te,new Uint8Array(E.ch*E.ext));S(this,R,new Uint8Array(E.ch*E.rpn));S(this,L,new Uint8Array(E.ch*E.rpnt));S(this,tt,new Int8Array(E.ch*fa.length));S(this,j,new Uint8Array(E.drm*E.dpn*E.dnc));S(this,ae,new Uint8Array(E.efx*3));S(this,at,new Uint8Array(E.ch));S(this,Be,new Uint8Array(E.ch*E.redir));S(this,fe,new Uint8Array(E.ch));S(this,gt,new Uint8Array(E.ch*E.cvn));S(this,Ce,new Uint8Array(128));S(this,he,new Uint8Array(E.cmt*8));S(this,rt,new Uint8Array(1024));S(this,Me,new Uint8Array(E.cmt*64));S(this,Re,0);S(this,oe,0);S(this,_,void 0);S(this,B,100);S(this,Ne,0);S(this,st,500);S(this,it,0);S(this,De,"");S(this,Oe,0);S(this,yt,0);S(this,nt,0);S(this,ue,!0);S(this,N,!1);S(this,xt,1);S(this,Et,void 0);S(this,He,new Array(E.ch));S(this,Pt,new Uint8Array(2));S(this,re,[]);S(this,we,new Uint8Array(E.ch));S(this,Ae,new Uint8Array(E.tr));D(this,"baseBank",new Dt("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","krs","s90es"));D(this,"userBank",new Dt("gm"));D(this,"initOnReset",!1);D(this,"aiEfxName","");S(this,q,[]);S(this,_e,void 0);S(this,X,{nOff:(e,r)=>{let d=e*128+r,o=t(this,F).lastIndexOf(d);if(o>-1)if(t(this,g)[E.cc*e+y[64]]>63)t(this,z)[o]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,V)[d],state:this.NOTE_HELD});else if(t(this,g)[E.cc*e+y[66]]>63&&t(this,z)[o]==this.NOTE_SOSTENUTO_SUSTAIN)t(this,z)[o]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,V)[d],state:this.NOTE_SOSTENUTO_HELD});else{t(this,F)[o]=0,t(this,V)[d]=0,t(this,z)[o]=this.NOTE_IDLE;let p=this.getExt(e)[1];(p==this.VLBC_VELOINIT||p==this.VLBC_VELOALL)&&(t(this,g)[E.cc*e+y[129]]=0),this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})}},nOn:(e,r,d)=>{let o=e*128+r,p=0;for(t(this,ee)[e]&&t(this,X).ano(e);t(this,z)[p]>0&&t(this,F)[p]!=o;)p++;if(p{},cAt:(e,r)=>{},hoOf:e=>{t(this,z).forEach((r,d)=>{if(r==this.NOTE_HELD){let o=t(this,F)[d],p=o>>7;e==p&&(t(this,z)[d]=this.NOTE_IDLE,t(this,F)[d]=0,t(this,V)[o]=0,this.dispatchEvent("note",{part:e,note:o&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,z).forEach((r,d)=>{let o;switch(r){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,z)[d]=o;let p=t(this,F)[d];this.dispatchEvent("note",{part:e,note:p&127,velo:t(this,V)[p],state:o})}})},soOf:e=>{t(this,z).forEach((r,d)=>{if(r==this.NOTE_SOSTENUTO_HELD){let o=t(this,F)[d],p=o>>7;e==p&&(t(this,z)[d]=this.NOTE_IDLE,t(this,F)[d]=0,t(this,V)[o]=0,this.dispatchEvent("note",{part:e,note:o&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,F).forEach((r,d,o)=>{let p=r>>7,$=r&127;r==0&&t(this,V)[0]==0||p==e&&t(this,X).nOff(p,$)})}});S(this,vt,{8:function(e){let r=e.channel,d=e.data[0];t(this,X).nOff(r,d)},9:function(e){let r=e.channel;this.setChActive(r,1);let d=e.data[0],o=e.data[1];o>0?t(this,X).nOn(r,d,o):t(this,X).nOff(r,d)},10:function(e){let r=e.channel,d=r*128+e.data[0];t(this,F).indexOf(d)>-1&&(t(this,V)[d]=data[1],this.getExt(r)[1]==this.VLBC_VELOALL&&(t(this,g)[E.cc*r+y[129]]=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,d=t(this,He)[r],o=d[e.data[0]];o&&(e.data[0]=o),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,P)){case T.s90es:case T.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 p=r*E.cc,$=r*E.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,X).ano(r),t(this,$e)[r]=0,t(this,g)[p+y[1]]=0,t(this,g)[p+y[5]]=0,t(this,g)[p+y[64]]=0,t(this,g)[p+y[65]]=0,t(this,g)[p+y[66]]=0,t(this,g)[p+y[67]]=0,t(this,g)[p+y[11]]=127,t(this,g)[p+y[101]]=127,t(this,g)[p+y[100]]=127,t(this,g)[p+y[99]]=127,t(this,g)[p+y[98]]=127;return}case 123:{t(this,X).ano(r);return}case 124:{t(this,X).ano(r);return}case 125:{t(this,X).ano(r);return}case 126:{t(this,ee)[r]=1,t(this,X).ano(r);return}case 127:{t(this,ee)[r]=0,t(this,X).ano(r);return}}if(y[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(_a.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(A()&&console.debug(`${be[t(this,P)]}, CH${r+1}: ${e.data[1]}`),t(this,P)==0?e.data[1]<48?(t(this,O)[r]>0&&(e.data[1]=t(this,g)[p],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(t(this,_).x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(this.modeIdx[t(this,_).ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,P)==T.gs?e.data[1]<56&&t(this,O)[r]>0&&(e.data[1]=t(this,g)[p],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):t(this,P)==T.gm&&(e.data[1]<48?t(this,O)[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,P)){case T.xg:{[79,95,126,127].indexOf(e.data[1])>-1?t(this,O)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,O)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?t(this,te)[$]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?t(this,te)[$]=this.EXT_DX:t(this,te)[$]=this.EXT_NONE;break}case T["05rw"]:case T.x5d:case T.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(this,O)[r]==this.CH_MELODIC&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):[80,81,82,83].indexOf(e.data[1])>-1||t(this,O)[r]!=this.CH_MELODIC&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case T.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,O)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,O)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case T.g2:{e.data[1]==120?t(this,O)[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,O)[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 2:{this.getExt(r)[1]==this.VLBC_BRTHEXPR&&(t(this,g)[p+y[129]]=e.data[1]);break}case 6:{if(t(this,Ue)){[T.xg,T.gs,T.ns5r].indexOf(t(this,P))<0&&console.warn(`NRPN commits are not available under "${be[t(this,P)]}" mode, even when they are supported in Octavia.`);let v=t(this,g)[p+y[99]],k=t(this,g)[p+y[98]];if(v==1){let a=Ga.indexOf(k);if(a>-1)t(this,g)[p+y[71+a]]=e.data[1],A()&&console.debug(`Redirected NRPN 1 ${k} to cc${71+a}.`),this.dispatchEvent("cc",{part:r,cc:71+a,data:e.data[1]});else{let n=fa.indexOf(k);n>-1?t(this,tt)[r*10+n]=e.data[1]-64:console.warn(`NRPN 0x01${k.toString(16).padStart(2,"0")} is not supported.`),A()&&console.debug(`CH${r+1} voice NRPN ${k} commit`)}}else{if(Tt.indexOf(v)<0){let n=`NRPN 0x${v.toString(16).padStart(2,"0")}${k.toString(16).padStart(2,"0")} `;v==127?console.warn(`${n}is not necessary. Consider removing it.`):console.warn(`${n}is not supported.`)}else{let n=t(this,O)[r]-2;n<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${ht[t(this,O)[r]]}.`):t(this,j)[(n*E.dpn+ne[v])*E.dnc+k]=e.data[1]}A()&&console.debug(`CH${r+1} (${ht[t(this,O)[r]]}) drum NRPN ${v} commit`)}}else{let v=oa[t(this,g)[p+y[100]]],k=la[t(this,g)[p+y[100]]];t(this,g)[p+y[101]]==0&&v!=null&&(A()&&console.debug(`CH${r+1} RPN 0 ${t(this,g)[p+y[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],da[v][0]),da[v][1]),t(this,R)[r*E.rpn+v]=e.data[1],t(this,L)[r*E.rpnt+k]=1)}break}case 32:{switch(A()&&console.debug(`${be[t(this,P)]}, CH${r+1} LSB: ${e.data[1]}`),t(this,P)){case T.s90es:case T.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,P),!0);break}}this.getExt(r)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:r});break}case 38:{if(!t(this,Ue)){let v=oa[t(this,g)[p+100]],k=la[t(this,g)[p+100]];t(this,g)[p+101]==0&&v!=null&&(t(this,R)[r*E.rpn+v+1]=e.data[1],t(this,L)[r*E.rpnt+k]=1)}break}case 64:{e.data[1]<64&&t(this,X).hoOf(r);break}case 66:{e.data[1]>>6?t(this,X).soOn(r):t(this,X).soOf(r);break}case 98:case 99:{x(this,Ue,1);break}case 100:case 101:{x(this,Ue,0);break}}t(this,g)[p+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,P)){case T.s90es:case T.motif:{e.data&&this.setChActive(r,1);break}default:this.setChActive(r,1)}if(this.getExt(r)[0]==this.EXT_DX){let d=E.cc*r}t(this,U)[r]=e.data,t(this,fe)[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,F).forEach(function(o){let p=o>>7;d==p&&(t(r,V)[o]=e.data,r.dispatchEvent("note",{part:d,note:o&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){Va(e.data).forEach(r=>{let d=r[0],o=r[1];(t(this,St)[d]||function(){console.debug(`Unknown manufacturer ${d}.`)})(o,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,q)[e.meta]||function(d,o,p){}).call(this,e.data,e.track,e.meta),e.meta!=32&&x(this,Ne,0);let r=Ha.indexOf(e.meta)>-1;if(A()&&console.debug(e),r)return e.reply="meta",e}});S(this,St,{64:(e,r,d)=>{t(this,Ve).run(r,d,e)},65:(e,r,d)=>{if(r[0]<16){if(r[1]==72){let o=r[r.length-1],p=Te(r.subarray(3,r.length-1));o==p?t(this,le).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad SD checksum ${o} - should be ${p}.`)}else t(this,le).run(r,d,e);}else{let o=r[r.length-1],p=Te(r.subarray(2,r.length-1));o==p?t(this,le).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad GS checksum ${o} - should be ${p}.`)}},66:(e,r,d)=>{t(this,ke).run(r,d,e)},67:(e,r,d)=>{t(this,se).run(r,d,e)},68:(e,r,d)=>{t(this,Ke).run(r,d,e)},71:(e,r,d)=>{t(this,Fe).run(r,d,e)},126:(e,r,d)=>{t(this,Ge).run(r,d,e)},127:(e,r,d)=>{this.switchMode("gm"),t(this,Xe).run(r,d,e)}});S(this,Ge,void 0);S(this,Xe,void 0);S(this,se,void 0);S(this,le,void 0);S(this,ke,void 0);S(this,Ve,void 0);S(this,Fe,void 0);S(this,Ke,void 0);let e=this;x(e,ie,new Uint8Array(256),ba),t(e,ve)[10]=new Uint8Array(512),x(e,_e,new de),x(e,_,{x5:82,ds:T.krs}),e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -147,24 +147,25 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),e.addEventListener("metacommit",function(a){var n,i;let{data:c}=a;((n=t(e,ae)[0])==null?void 0:n.type)==c.type&&(i=t(e,ae)[0])!=null&&i.amend?(t(e,ae)[0].amend=c.amend,t(e,ae)[0].data+=c.data):t(e,ae).unshift(c)}),t(e,q)[1]=function(a){var c,n,i,s,f;switch(a=a.replaceAll(`\r +122 006 000 `),e.addEventListener("metacommit",function(a){var c,i;let{data:n}=a;((c=t(e,re)[0])==null?void 0:c.type)==n.type&&(i=t(e,re)[0])!=null&&i.amend?(t(e,re)[0].amend=n.amend,t(e,re)[0].data+=n.data):t(e,re).unshift(n)}),t(e,q)[1]=function(a){var n,c,i,s,f;switch(a=a.replaceAll(`\r `,` `).replaceAll("\r",` -`),a.slice(0,2)){case"@I":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(c=a.slice(2))==null?void 0:c.trimLeft()});break}case"@K":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(n=a.slice(2))==null?void 0:n.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(i=a.slice(2))==null?void 0:i.trimLeft()});break}case"@T":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(s=a.slice(2))==null?void 0:s.trimLeft()});break}case"@V":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(f=a.slice(2))==null?void 0:f.trimLeft()});break}case"XF":{let h=a.slice(2).split(":");switch(h[0]){case"hd":{h.slice(1).forEach((l,u)=>{l.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][u],data:l})});break}case"ln":{h.slice(1).forEach((l,u)=>{l.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][u],data:l})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:t(this,N)?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(e,q)[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},t(e,q)[3]=function(a,c){c<1&&t(this,Ne)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},t(e,q)[4]=function(a,c){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},t(e,q)[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(e,q)[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},t(e,q)[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},t(e,q)[32]=function(a){x(this,Ne,a[0]+1)},t(e,q)[33]=function(a,c){t(e,Oe)[c]=a+1},t(e,q)[81]=function(a,c){x(e,st,a/1e3)},t(e,q)[127]=function(a,c){t(e,Ge).run(a,c)},t(e,Ge).default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},t(e,Ge).add([67,0,1],function(a,c){t(e,Oe)[c]=a[0]+1}),x(e,_e,new oe("universal non-realtime")),x(e,Xe,new oe("universal realtime")),x(e,ne,new oe("Yamaha")),x(e,ce,new oe("Roland")),x(e,ke,new oe("Korg")),x(e,Ve,new oe("Kawai")),x(e,Fe,new oe("Akai")),x(e,Ke,new oe("Casio"));let r=new oe("DX7+ Dump"),d=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,a)};t(e,_e).default=d,t(e,Xe).default=d,t(e,ne).default=d,t(e,ce).default=d,t(e,ke).default=d,t(e,Ve).default=d,t(e,Fe).default=d,t(e,Ke).default=d,r.default=d,t(e,_e).add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),x(e,N,t(e,N)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),t(e,Xe).add([4,1],a=>{x(e,B,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,B))}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64).add([4,5],a=>{let c=a[0],n=a[1],i=a[2],s=3,f=s+(c<<1),h=f+n;if(c!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${c})! -`,a);return}let l=0,u=0,m=0;switch(a.subarray(s,f).forEach(k=>{l=l<<7,l|=k}),a.subarray(f,h).forEach((k,C)=>{u|=k<{m|=k<{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),x(e,N,!1),console.info("MIDI reset: XG");break}default:{let c=[0,0,0,0],n=(i,s)=>{c[s]=i};if(a.subarray(1).forEach((i,s)=>{let f=s+a[0];([n,n,n,n,h=>{x(this,B,h*129/16383*100),e.dispatchEvent("mastervolume",t(e,B))},h=>{},h=>{}][f]||(()=>{}))(i,s)}),a[0]<4){let i=0;c.forEach(s=>{i=i<<4,i+=s}),i-=1024}}}}).add([76,2,1],a=>{let c="XG ";a[0]<32?(c+="reverb ",a.subarray(1).forEach((n,i)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${c}main type: ${ft[s]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{e.setEffectTypeRaw(0,!0,s),console.debug(`${c}sub type: ${s+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{console.debug(`${c}time: ${Wt(s)}s`)},s=>{console.debug(`${c}diffusion: ${s}`)},s=>{console.debug(`${c}initial delay: ${s}`)},s=>{console.debug(`${c}HPF cutoff: ${et[s]}Hz`)},s=>{console.debug(`${c}LPF cutoff: ${et[s]}Hz`)},s=>{console.debug(`${c}width: ${s}`)},s=>{console.debug(`${c}height: ${s}`)},s=>{console.debug(`${c}depth: ${s}`)},s=>{console.debug(`${c}wall type: ${s}`)},s=>{console.debug(`${c}dry/wet: ${s}`)},s=>{console.debug(`${c}send: ${J(s)}dB`)},s=>{console.debug(`${c}pan: ${s-64}`)},!1,!1,s=>{console.debug(`${c}delay: ${s}`)},s=>{console.debug(`${c}density: ${s}`)},s=>{console.debug(`${c}balance: ${s}`)},s=>{},s=>{console.debug(`${c}feedback: ${s}`)},s=>{}][a[0]+i]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(n)})):a[0]<64?(c+="chorus ",a.subarray(1).forEach((n,i)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${c}main type: ${ft[s]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{e.setEffectTypeRaw(1,!0,s),console.debug(`${c}sub type: ${s+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{console.debug(`${c}LFO: ${Yt[s]}Hz`)},s=>{},s=>{console.debug(`${c}feedback: ${s}`)},s=>{console.debug(`${c}delay offset: ${jt(s)}ms`)},s=>{},s=>{console.debug(`${c}low: ${et[s]}Hz`)},s=>{console.debug(`${c}low: ${s-64}dB`)},s=>{console.debug(`${c}high: ${et[s]}Hz`)},s=>{console.debug(`${c}high: ${s-64}dB`)},s=>{console.debug(`${c}dry/wet: ${s}`)},s=>{console.debug(`${c}send: ${J(s)}dB`)},s=>{console.debug(`${c}pan: ${s-64}`)},s=>{console.debug(`${c}to reverb: ${J(s)}dB`)},!1,s=>{},s=>{},s=>{},s=>{console.debug(`${c}LFO phase diff: ${(s-64)*3}deg`)},s=>{console.debug(`${c}input mode: ${s?"stereo":"mono"}`)},s=>{}][a[0]-32+i]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(n)})):a[0]<86?(c+="variation ",a.subarray(1).forEach((n,i)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${c}main type: ${ft[s]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},s=>{e.setEffectTypeRaw(2,!0,s),console.debug(`${c}sub type: ${s+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+i]||function(){})(n)})):a[0]<97?(c+="variation ",a.subarray(1).forEach((n,i)=>{[s=>{console.debug(`${c}send: ${J(s)}dB`)},s=>{console.debug(`${c}pan: ${s-64}`)},s=>{console.debug(`${c}to reverb: ${J(s)}dB`)},s=>{console.debug(`${c}to chorus: ${J(s)}dB`)},s=>{console.debug(`${c}connection: ${s?"system":"insertion"}`)},s=>{console.debug(`${c}channel: CH${s+1}`)},s=>{console.debug(`${c}mod wheel: ${s-64}`)},s=>{console.debug(`${c}bend wheel: ${s-64}`)},s=>{console.debug(`${c}channel after touch: ${s-64}`)},s=>{console.debug(`${c}AC1: ${s-64}`)},s=>{console.debug(`${c}AC2: ${s-64}`)}][a[0]-86+i](n)})):a[0]>111&&a[0]<118?c+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((c,n)=>{let i=n+a[0];if(i==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][c]}`);else{let s=i-1>>2,f=i-1&3,h=`XG EQ ${s} ${["gain","freq","Q","shape"][f]}: `;[()=>{console.debug(`${h}${c-64}dB`)},()=>{console.debug(`${h}${c} (raw)`)},()=>{console.debug(`${h}${c/10}`)},()=>{console.debug(`${h}${["shelf","peak"][+!!c]}`)}][f]()}})}).add([76,3],a=>{let c=a[0],n=a[1],i=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((s,f)=>{([h=>{e.setEffectTypeRaw(3+c,!1,h),console.info(`${i}main type: ${ft[h]}`),e.dispatchEvent(`efxinsert${c}`,e.getEffectType(3+c))},h=>{e.setEffectTypeRaw(3+c,!0,h),console.debug(`${i}sub type: ${h+1}`),e.dispatchEvent(`efxinsert${c}`,e.getEffectType(3+c))}][n+f]||function(){})(s)})}).add([76,6,0],a=>{let c=a[0];c<64?e.setLetterDisplay(a.subarray(1),"XG letter display",c):x(e,De,Date.now())}).add([76,7,0],a=>{let c=a[0];x(e,W,0),x(e,ue,Date.now()+3200),t(e,re,ye).fill(0);let n=a.subarray(1);for(let i=0;i>6-m&1,m++})}).add([76,8],(a,c)=>{let n=e.chRedir(a[0],c,!0),i=a[1],s=v.cc*n,f=`XG CH${n+1} `,h=`Unknown XG part address ${i}.`;a.subarray(2).forEach((l,u)=>{i<1?console.debug(h):i<41?([()=>{t(e,g)[s+y[0]]=l,e.dispatchEvent("voice",{part:n})},()=>{t(e,g)[s+y[32]]=l,e.dispatchEvent("voice",{part:n})},()=>{t(e,U)[n]=l,e.dispatchEvent("voice",{part:n})},()=>{let m=e.chRedir(l,c,!0);t(e,K)[n]=m,n!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))},()=>{t(e,ee)[n]=+!l},()=>{},()=>{e.setChType(n,l,T.xg),console.debug(`${f}type: ${ht[l]||l}`)},()=>{t(e,R)[v.rpn*n+3]=l,t(e,L)[v.rpnt*n+2]=1},!1,!1,()=>{t(e,g)[s+y[7]]=l},!1,!1,()=>{t(e,g)[s+y[10]]=l||128},!1,!1,()=>{t(e,g)[s+y[128]]=l},()=>{t(e,g)[s+y[93]]=l},()=>{t(e,g)[s+y[91]]=l},()=>{t(e,g)[s+y[94]]=l},()=>{t(e,g)[s+y[76]]=l},()=>{t(e,g)[s+y[77]]=l},()=>{t(e,g)[s+y[78]]=l},()=>{t(e,g)[s+y[74]]=l},()=>{t(e,g)[s+y[71]]=l},()=>{t(e,g)[s+y[73]]=l},()=>{t(e,g)[s+y[75]]=l},()=>{t(e,g)[s+y[72]]=l}][i+u-1]||(()=>{}))():i<48?console.debug(h):i<111?i>102&&i<105&&(t(e,g)[s+y[[5,65][i&1]]]=l):i<114?console.debug(h):i<116?console.debug(`${f}EQ ${["bass","treble"][i&1]} gain: ${l-64}dB`):i<118?console.debug(h):i<120?console.debug(`${f}EQ ${["bass","treble"][i&1]} freq: ${l}`):console.debug(h)})}).add([76,9],(a,c)=>{let n=e.chRedir(a[0],c,!0),i=a[1],s=v.cc*n,f=`PLG-VL CH${n+1} `;a.subarray(2).forEach((h,l)=>{let u=l+i;switch(u){case 1:{console.info(`${f}breath mode: ${["system","breath","velocity","touch EG"][h]}`);break}case 0:case 27:case 28:break;default:if(u<27){let m=u-3>>1,k=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][m];u&1?u<23?(console.debug(`${f}${k} control source: ${ea(h)}`),h&&h<96&&e.allocateAce(130+m),t(e,Be)[v.redir*n+m+2]=h,e.buildRccMap()):console.debug(`${f}${k} scale break point: ${h}`):(console.debug(`${f}${k} depth: ${h-64}`),t(e,g)[s+y[130+m]]=h)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{switch(console.debug(`XG enable PLG-${["VL","SG","DX","AN","PF","DR","PC","AP"][a[0]]} for CH${a[2]+1}.`),a[0]){case 0:{t(e,be)[v.ext*a[2]]=e.EXT_VL;break}default:t(e,be)[v.ext*a[2]]=e.EXT_NONE}}).add([73,0,0],(a,c)=>{let n=a[0],i="MU1000 System: ";a.subarray(1).forEach((s,f)=>{let h=n+f;h==8?console.debug(`${i}LCD contrast set to ${s}.`):h==18?(x(e,ie,s?126:0),console.debug(`${i}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):h>=64&&h<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")},()=>{x(e,de,!!s),console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][h-64]()})}).add([73,10,0],(a,c)=>{let n=a[0],i=`MU1000 RS${t(e,de)?"":" (ignored)"}: `;if(n<16)switch(n){case 2:{let s=e.chRedir(0,c,!0);t(e,de)&&(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,c,!0);t(e,de)&&e.dispatchEvent("channelmin",s),t(e,de)&&e.dispatchEvent("channelmax",s+31),console.info(`${i}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${i}unknown switch ${n} invoked.`)}else if(n<32){if(t(e,de)){let s=e.chRedir(n-16+(t(e,nt)<<4),c,!0);e.dispatchEvent("channelactive",s)}}else if(n<36){let s=e.chRedir(n-32<<4,c,!0);t(e,de)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),x(e,nt,n-32)),console.info(`${i}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(a,c)=>{let n=e.chRedir(a[0],c,!0),i=`PLG-100SG CH${n+1} `,s=Date.now();if(a[1]==0){let f="",h=0;a.subarray(2).forEach((l,u)=>{u%2==0?f+=Zt[l]||l.toString().padStart("0"):h+=l*13}),s>=t(e,it)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${Jt(f)}`,amend:!0}),x(e,it,s+Math.ceil(h/2)+t(e,st)),A()&&console.debug(`${i}vocals: ${f}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)}).add([100,0],(a,c,n)=>{let i=a.subarray(0,a.length-1),s=Ie(i),f=a[a.length-1];if(s!=f){console.warn(`Yamaha DX7 dump SysEx checksum mismatch! Expected ${s}, but got ${f}: -`,a);return}else r.run(i)}),r.add([0,14,31],a=>{t(e,g)[v.cc*a[0]+y[64]]=0,t(e,X).ano(a[0]),e.switchMode("xg"),console.debug(`Yamaha DX7+ reset CH${a[0]+1}.`)}).add([56,76,112],async a=>{let c=a[0],n="";a.subarray(1).forEach((i,s)=>{s<10&&(n+=String.fromCharCode(Math.max(i,32)))}),t(e,U)[c]=c&127,t(e,g)[v.cc*c+y[0]]=35,t(e,g)[v.cc*c+y[32]]=c>>7|2,e.dispatchEvent("voice",{part:c}),n.length>0&&(n=n.trimRight(),console.debug(`DX7+ CH${c+1} dumped voice name: "${n}"`))});let o=function(a,c,n,i){},p=function(a,c){let n=a*v.dpn,i=c[0],s=c[1];c.subarray(2).forEach((f,h)=>{let l=h+s,u=-1;l<16?([()=>{u=24},()=>{u=25},()=>{u=26},()=>{},()=>{u=28},()=>{u=29},()=>{u=30},()=>{u=31},()=>{},()=>{},()=>{},()=>{u=20},()=>{u=21},()=>{u=22},()=>{u=23},()=>{}][l]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))():l<32||(l<40?([()=>{u=48},()=>{u=49},!1,!1,()=>{u=52},()=>{u=53}][l-32]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))():l<80||([()=>{u=36}][l-80]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))()),u>=0?(A()&&console.debug(n,u,i,f),t(e,j)[(n+se[u])*v.dnc+i]=f):A()&&console.debug(`XG-style drum param ${l} has no writes.`)})},$=function(a,c,n){let i=a*v.dpn,s=(c<<7)+n[0];n.subarray(1).forEach((f,h)=>{let l=h+s,u=l&127,m=l>>7,k=-1;m>1&&([()=>{k=26},()=>{},()=>{k=28},()=>{k=29},()=>{k=30},()=>{},()=>{},()=>{k=31}][m-2]||(()=>{console.debug(`Unknown GS-style drum param ${m} on set ${a+1}.`)}))(),k>-1?(A()&&console.debug(i,k,u,f),t(e,j)[(i+se[k])*v.dnc+u]=f):A()&&console.debug(`GS-style drum param ${m} has no writes.`)})};t(this,ne).add([76,48],(a,c,n)=>{p(0,a)}).add([76,49],(a,c,n)=>{p(1,a)}).add([76,50],(a,c,n)=>{p(2,a)}).add([76,51],(a,c,n)=>{p(3,a)}).add([76,52],(a,c,n)=>{p(4,a)}).add([76,53],(a,c,n)=>{p(5,a)}).add([76,54],(a,c,n)=>{p(6,a)}).add([76,55],(a,c,n)=>{p(7,a)}),t(this,ne).add([89,0],(a,c,n)=>{if(e.eprom){let i=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")}, ${i} bytes.`);let f=e.eprom.data;a.subarray(4).forEach((h,l)=>{let u=l>>3,m=l&7;if(m==7)for(let k=0;k<7;k++)f[s+7*u+k]+=(h>>6-k&1)<<7;else f[s+7*u+m]=h})}}).add([89,1],(a,c,n)=>{let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];A()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(a,c,n)=>{if(e.eprom){let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);A()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;a.subarray(4).forEach((f,h)=>{let l=h>>3,u=h&7;if(u==7)for(let m=0;m<7;m++)s[i+7*l+m]+=(f>>6-m&1)<<7;else s[i+7*l+u]=f})}}).add([89,3],(a,c,n)=>{}),t(this,ne).add([39,48],(a,c,n)=>{}).add([43,0,0],(a,c,n)=>{let i=[0,0,0,0],s=(f,h)=>{i[h]=f};if(a.subarray(1).forEach((f,h)=>{let l=h+a[0];[s,s,s,s,()=>{x(this,B,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,B))},()=>f-64,()=>f||128,()=>f,()=>f,()=>{console.debug(`TG300 variation on cc${f}.`)}][l](f,l)}),a[0]<4){let f=0;i.forEach(h=>{f=f<<4,f+=h}),f-=1024}}).add([43,1,0],(a,c,n)=>{}).add([43,2],(a,c,n)=>{let i=e.chRedir(a[0],c,!0),s=a[1],f=v.cc*i,h=`TG300 CH${i+1} `;a.subarray(2).forEach((l,u)=>{u<5?([()=>{},()=>{t(e,g)[f+y[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{t(e,g)[f+y[32]]=l,e.dispatchEvent("voice",{part:i})},()=>{t(e,U)[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let m=e.chRedir(l,c,!0);t(e,K)[i]=m,i!=m&&(e.buildRchTree(),console.info(`${h}receives from CH${m+1}`))}][u+s]||(()=>{}))(l,u+s):u<21||(u<47?([()=>{t(e,ee)[i]=+!l},()=>{},()=>{},()=>{t(e,R)[v.rpn*i+3]=l,t(e,L)[v.rpnt*i+2]=1},()=>{},()=>{t(e,g)[f+y[7]]=l},!1,!1,()=>{t(e,g)[f+y[10]]=l||128},!1,!1,()=>{console.debug(`${h} AC1 at cc${l}`)},()=>{console.debug(`${h} AC2 at cc${l}`)},()=>{t(e,g)[f+y[128]]=l},()=>{t(e,g)[f+y[93]]=l},()=>{t(e,g)[f+y[91]]=l},()=>{t(e,g)[f+y[94]]=l},()=>{t(e,g)[f+y[76]]=l},()=>{t(e,g)[f+y[77]]=l},()=>{t(e,g)[f+y[74]]=l},()=>{t(e,g)[f+y[71]]=l},()=>{t(e,g)[f+y[73]]=l},()=>{t(e,g)[f+y[75]]=l},()=>{t(e,g)[f+y[72]]=l},()=>{t(e,g)[f+y[78]]=l}][u+s-21]||(()=>{}))(l,u+s):u<95||([()=>{t(e,g)[f+y[65]]=l},()=>{t(e,g)[f+y[5]]=l}][u+s-95]||(()=>{}))(l,u+s))})}).add([43,7,0],(a,c,n)=>{let i=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",i)}).add([43,7,1],(a,c,n)=>{x(e,W,0),x(e,ue,Date.now()+3200),t(e,re,ye).fill(0),a.forEach(function(i,s){let f=Math.floor(s/16),h=s%16,l=(h*3+f)*7,u=7,m=0;for(l-=h*5,f==2&&(u=2);m>6-m&1,m++})}),t(this,ce).add([66,18,0,0,127],(a,c,n)=>{e.switchMode("gs",!0),t(e,g)[v.cc*9]=120,t(e,g)[v.cc*25]=120,t(e,g)[v.cc*41]=120,t(e,g)[v.cc*57]=120,x(e,ie,3),x(e,N,!1),t(e,we).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,c,n)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),t(e,g)[v.cc*9]=120,t(e,g)[v.cc*25]=120,t(e,g)[v.cc*41]=120,t(e,g)[v.cc*57]=120,x(e,N,!1),t(e,we).fill(0),console.info("MIDI reset: GS");break}default:{let i=[0,0,0,0],s=(f,h)=>{i[h]=f};if(a.subarray(1).forEach((f,h)=>{let l=h+a[0];[s,s,s,s,u=>{x(this,B,u*129/16383*100),e.dispatchEvent("mastervolume",t(e,B))},u=>{},u=>{}][l](f,h)}),a[0]<4){let f=0;i.forEach(h=>{f=f<<4,f+=h}),f-=1024}}}}).add([66,18,64,1],a=>{let c=a[0];if(c<16){let n="".padStart(c," ");a.subarray(1).forEach((i,s)=>{n+=String.fromCharCode(Math.max(32,i))}),n=n.padEnd(16," "),console.debug(`GS patch name: ${n}`)}else c<48||(c<65?a.subarray(1).forEach((n,i)=>{let s=`GS ${c+i>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${Ot[n]}`),e.setEffectType(0,40,n),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${n}ms`)},()=>{console.info(`${s}type: ${ta[n]}`),e.setEffectType(1,40,16+n),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${J(n)}`)},()=>{console.debug(`${s}to delay: ${J(n)}`)}][c+i-48]||(()=>{}))()}):c<80?console.debug(`Unknown GS patch address: ${c}`):c<91?a.subarray(1).forEach((n,i)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${aa[n]}`),e.setEffectType(2,40,32+n),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${J(n)}`)}][c+i-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${c}`))}).add([66,18,64,2],a=>{let c="GS EQ ";a.subarray(1).forEach((n,i)=>{([()=>{console.debug(`${c}low freq: ${[200,400][n]}Hz`)},()=>{console.debug(`${c}low gain: ${n-64}dB`)},()=>{console.debug(`${c}high freq: ${[3e3,6e3][n]}Hz`)},()=>{console.debug(`${c}high gain: ${n-64}dB`)}][a[0]+i]||function(){console.warn(`Unknown GS EQ address: ${a[0]+i}`)})()})}).add([66,18,64,3],a=>{let c="GS EFX ",n=function(i,s){let f=ra(t(e,te).subarray(10,12),s,i);f&&console.debug(`${c}${At(t(e,te).subarray(10,12))} ${f}`)};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(`${c}type: ${At(t(e,te).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,()=>{console.debug(`${c}to reverb: ${J(i)}dB`)},()=>{console.debug(`${c}to chorus: ${J(i)}dB`)},()=>{console.debug(`${c}to delay: ${J(i)}dB`)},!1,()=>{console.debug(`${c}1 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${c}1 depth: ${i-64}`)},()=>{console.debug(`${c}2 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${c}2 depth: ${i-64}`)},()=>{console.debug(`${c}to EQ: ${i?"ON":"OFF"}`)}][a[0]+s]||function(f,h){console.warn(`Unknown GS EFX address: ${h}`)})(i,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 c;switch(a[0]){case 0:{let n=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",n);break}case 32:{x(e,ue,Date.now()+3200),a[1]==0&&(x(e,W,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,W)>9&&x(e,W,0);let n=a[0]-1<<1|a[1]>>6;t(e,W)==n&&x(e,ue,Date.now()+3200),(c=t(e,Ee)[n])!=null&&c.length||(t(e,Ee)[n]=new Uint8Array(256));let i=t(e,Ee)[n];A()&&console.debug(`GS frame draw page ${n}.`);let s=a[1]&63;i.fill(0),a.subarray(2).forEach(function(h,l){let u=l+s,m=Math.floor(u/16),k=u%16,C=(k*4+m)*5,M=5,_=0;for(C-=k*4,m==3&&(M=1);_>4-_&1,_++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let E=function(a,c,n){let i=a[0],s=v.cc*c,f=v.rpn*c,h=`GS CH${c+1} `;i<3?(a.subarray(1).forEach((l,u)=>{[()=>{t(e,g)[s+y[0]]=l},()=>{t(e,U)[c]=l},()=>{let m=0;l<16?m=e.chRedir(l,n,!0):m=v.ch,t(e,K)[c]=m,c!=m&&(e.buildRchTree(),console.info(`${h}receives from CH${m+1}`))}][i+u]()}),e.dispatchEvent("voice",{part:c})):i<19||(i<44?a.subarray(1).forEach((l,u)=>{([()=>{t(e,ee)[c]=+!l},!1,()=>{e.setChType(c,l<<1,T.gs),console.debug(`${h}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{t(e,R)[f+3]=l,t(e,L)[v.rpnt*c+2]=1},!1,()=>{t(e,g)[s+y[7]]=l},!1,!1,()=>{t(e,g)[s+y[10]]=l||128},!1,!1,()=>{console.debug(`${h}CC 1: cc${l}`)},()=>{console.debug(`${h}CC 2: cc${l}`)},()=>{t(e,g)[s+y[93]]=l},()=>{t(e,g)[s+y[91]]=l},!1,!1,()=>{t(e,R)[f+1]=l,t(e,L)[v.rpnt*c+1]=1},()=>{t(e,R)[f+2]=l,t(e,L)[v.rpnt*c+1]=1},()=>{t(e,g)[s+y[94]]=l}][i+u-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},w=function(a,c){let n=a[0],i=`GS CH${c+1} `;n<2?a.subarray(1).forEach((s,f)=>{[()=>{t(e,g)[v.cc*c+y[32]]=s},()=>{}][n+f]()}):n<32?console.warn(`Unknown GS misc address: ${n}`):n<35?a.subarray(1).forEach((s,f)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][s]}`),t(e,at)[c]=s,e.dispatchEvent("partefxtoggle",{part:c,active:s})}][n+f-32]()}):console.warn(`Unknown GS misc address: ${n}`)};t(this,ce).add([66,18,64,16],(a,c)=>{E(a,e.chRedir(9,c,!0),c)}).add([66,18,64,17],(a,c)=>{E(a,e.chRedir(0,c,!0),c)}).add([66,18,64,18],(a,c)=>{E(a,e.chRedir(1,c,!0),c)}).add([66,18,64,19],(a,c)=>{E(a,e.chRedir(2,c,!0),c)}).add([66,18,64,20],(a,c)=>{E(a,e.chRedir(3,c,!0),c)}).add([66,18,64,21],(a,c)=>{E(a,e.chRedir(4,c,!0),c)}).add([66,18,64,22],(a,c)=>{E(a,e.chRedir(5,c,!0),c)}).add([66,18,64,23],(a,c)=>{E(a,e.chRedir(6,c,!0),c)}).add([66,18,64,24],(a,c)=>{E(a,e.chRedir(7,c,!0),c)}).add([66,18,64,25],(a,c)=>{E(a,e.chRedir(8,c,!0),c)}).add([66,18,64,26],(a,c)=>{E(a,e.chRedir(10,c,!0),c)}).add([66,18,64,27],(a,c)=>{E(a,e.chRedir(11,c,!0),c)}).add([66,18,64,28],(a,c)=>{E(a,e.chRedir(12,c,!0),c)}).add([66,18,64,29],(a,c)=>{E(a,e.chRedir(13,c,!0),c)}).add([66,18,64,30],(a,c)=>{E(a,e.chRedir(14,c,!0),c)}).add([66,18,64,31],(a,c)=>{E(a,e.chRedir(15,c,!0),c)}).add([66,18,64,64],(a,c)=>{w(a,e.chRedir(9,c,!0))}).add([66,18,64,65],(a,c)=>{w(a,e.chRedir(0,c,!0))}).add([66,18,64,66],(a,c)=>{w(a,e.chRedir(1,c,!0))}).add([66,18,64,67],(a,c)=>{w(a,e.chRedir(2,c,!0))}).add([66,18,64,68],(a,c)=>{w(a,e.chRedir(3,c,!0))}).add([66,18,64,69],(a,c)=>{w(a,e.chRedir(4,c,!0))}).add([66,18,64,70],(a,c)=>{w(a,e.chRedir(5,c,!0))}).add([66,18,64,71],(a,c)=>{w(a,e.chRedir(6,c,!0))}).add([66,18,64,72],(a,c)=>{w(a,e.chRedir(7,c,!0))}).add([66,18,64,73],(a,c)=>{w(a,e.chRedir(8,c,!0))}).add([66,18,64,74],(a,c)=>{w(a,e.chRedir(10,c,!0))}).add([66,18,64,75],(a,c)=>{w(a,e.chRedir(11,c,!0))}).add([66,18,64,76],(a,c)=>{w(a,e.chRedir(12,c,!0))}).add([66,18,64,77],(a,c)=>{w(a,e.chRedir(13,c,!0))}).add([66,18,64,78],(a,c)=>{w(a,e.chRedir(14,c,!0))}).add([66,18,64,79],(a,c)=>{w(a,e.chRedir(15,c,!0))}),t(this,ke).add([54,65],(a,c)=>{e.switchMode("x5d");let n=a[a.length-1],i=a.subarray(0,a.length-1),s=Ie(i);s!=n&&(console.info(`X5D multi parameters checksum mismatch! Expected ${s}, got ${n}.`),console.debug(a));let f=(a[1]<<7)+a[0],h=(a[3]<<7)+a[2],l=e.chRedir(f&15,c,!0),u=v.cc*l;[()=>{h<1||(h<101?(e.setChType(l,e.CH_MELODIC,T.x5d),t(e,U)[l]=h-1,t(e,g)[u+y[0]]=t(e,G).x5):h<229?(e.setChType(l,e.CH_MELODIC,T.x5d),t(e,U)[l]=h-101,t(e,g)[u+y[0]]=56):(e.setChType(l,e.CH_DRUMS,T.x5d),t(e,U)[l]=ha[h-229]||0,t(e,g)[u+y[0]]=62)),e.dispatchEvent("voice",{part:l})},()=>{t(e,g)[u+y[7]]=h},()=>{h<31&&(t(e,g)[u+y[10]]=Math.round((h-15)*4.2+64))},()=>{t(e,g)[u+y[93]]=ut(h)},()=>{t(e,g)[u+y[91]]=ut(h)},()=>{t(e,R)[l*v.rpn+3]=h>8191?h-16320:64+h,t(e,L)[v.rpnt*l+2]=1},()=>{t(e,R)[l*v.rpn+1]=h>8191?h-16320:64+h,t(e,L)[v.rpnt*l+1]=1},()=>{h>0&&(t(e,R)[l*v.rpn]=h,t(e,L)[v.rpnt*l]=1)},()=>{}][f>>4]()}).add([54,76,0],(a,c)=>{e.switchMode(t(e,G).x5=="81"?"05rw":"x5d",!0);let n="",i=t(e,G).x5,s=0,f=0,h="MSB\tPRG\tLSB\tNME";fe(a,function(l,u){if(u<16400){let m=u%164;switch(!0){case m<10:{l>31&&(n+=String.fromCharCode(l));break}case m==10:break;case m==11:{h+=` -${i} ${s} ${f} ${n.trim().replace("Init Voice","")}`,s++,n="";break}}s>99&&(i=90,s=0)}}),e.userBank.clearRange({msb:t(e,G).x5,prg:[0,99],lsb:0}),e.userBank.load(h),A()&&console.debug(h),e.forceVoiceRefresh()}).add([54,77,0],(a,c)=>{e.switchMode(t(e,G).x5=="81"?"05rw":"x5d",!0);let n="",i=90,s=0,f=0,h="MSB\tPRG\tLSB\tNME";fe(a,function(l,u){if(u<13600){let m=u%136;switch(!0){case m<10:{l>31&&(n+=String.fromCharCode(l));break}case m==11:{h+=` -${i} ${s} ${f} ${n.trim().replace("Init Combi","")}`,s++,n="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(h),A()&&console.debug(h),e.forceVoiceRefresh()}).add([54,78],(a,c)=>{e.switchMode(t(e,G).x5=="81"?"05rw":"x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,c)=>{e.switchMode(t(e,G).x5=="81"?"05rw":"x5d",!0),fe(a,(n,i)=>{i>0&&i<3&&(e.setEffectType(i-1,44,n),e.dispatchEvent(`efx${["reverb","chorus"][i-1]}`,e.getEffectType(i-1)))})}).add([54,104],(a,c)=>{e.switchMode(t(e,G).x5=="81"?"05rw":"x5d",!0),fe(a,function(n,i,s,f){if(i<192){let h=e.chRedir(Math.floor(i/12),c,!0),l=h*v.cc;switch(i%12){case 0:{n<128?(e.setChType(h,e.CH_MELODIC,T.x5d),t(e,g)[l+y[0]]=t(e,G).x5,t(e,U)[h]=n):(e.setChType(h,e.CH_DRUMS,T.x5d),t(e,g)[l+y[0]]=62,t(e,U)[h]=ha[n-128]),n>0&&e.setChActive(h,1),e.dispatchEvent("voice",{part:h});break}case 1:{t(e,g)[l+y[7]]=n;break}case 2:{t(e,R)[h*v.rpn+3]=n>127?n-192:64+n,t(e,L)[v.rpnt*h+2]=1;break}case 3:{t(e,R)[h*v.rpn+1]=n>127?n-192:64+n,t(e,L)[v.rpnt*h+1]=1;break}case 4:{n<31&&(t(e,g)[l+y[10]]=Math.round((n-15)*4.2+64));break}case 5:{let u=n>>4,m=n&15;t(e,g)[l+y[91]]=ut(m),t(e,g)[l+y[93]]=ut(u);break}case 10:break;case 11:{let u=e.chRedir(n&15,c,!0),m=n>>4;t(e,K)[h]=n,(u!=h||m)&&(console.info(`X5D Part CH${h+1} receives from CH${u+1}.`),e.buildRchTree())}}}else{let h=e.chRedir(i-192,c,!0)}})}),t(this,ce).add([22,18,127],a=>{e.switchMode("mt32",!0),x(e,N,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,c,n)=>{e.switchMode("mt32");let i=e.chRedir(n,c,!0),s=a[1];a.subarray(2).forEach((f,h)=>{let l=h+s;t(e,Te)[l+(i-1)*16]=f,([!1,()=>{let u=t(e,Te)[i-1<<4];if(u<3){if(t(e,ge)[i]=1,u==2)for(let m=0;m{t(e,R)[i*v.rpn+3]=f+40,t(e,L)[v.rpnt*i+2]=1},()=>{t(e,R)[i*v.rpn+1]=f+14,t(e,L)[v.rpnt*i+1]=1},()=>{t(e,R)[i*v.rpn]=f,t(e,L)[v.rpnt*i]=1},!1,()=>{t(e,g)[v.cc*i+y[91]]=f?127:0},!1,()=>{t(e,g)[v.cc*i+y[7]]=f},()=>{t(e,g)[v.cc*i+y[10]]=Math.ceil(f*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(a,c,n)=>{e.switchMode("mt32");let i=n&7;console.debug(`MT-32 slot #${n+1} Drum: ${a}`);let s=a[0]<<7|a[1];a.subarray(2).forEach((f,h)=>{let l=h+s,u=(l>>2)+24,m=l&3,k=i*v.dpn;if(A()&&console.debug(`MT-32 temp drum note ${u} param ${m}: ${f}`),u<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${u}`);return}[()=>{},()=>{t(e,j)[(k+se[26])*v.dnc+u]=Math.round(f*1.27)},()=>{t(e,j)[(k+se[26])*v.dnc+u]=f*9+1&127},()=>{t(e,j)[(k+se[26])*v.dnc+u]=f?127:0}][m]()})}).add([22,18,2],(a,c,n)=>{e.switchMode("mt32");let i=e.chRedir(n,c,!0),s=a[1]+(a[0]<<7);s<10&&(t(e,ge)[i]=1),a.subarray(2).forEach((f,h)=>{let l=h+s;l<14&&(t(e,le)[(i-1)*v.cmt+l]=f)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(a,c,n)=>{e.switchMode("mt32");let i=n&7;if(a[0]){let s=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((f,h)=>{let l=h+s,u=(l>>2)+24,m=l&3,k=i*v.dpn;if(A()&&console.debug(`MT-32 dev drum note ${u} param ${m}: ${f}`),u<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${u}`);return}[()=>{},()=>{t(e,j)[(k+se[26])*v.dnc+u]=Math.round(f*1.27)},()=>{t(e,j)[(k+se[26])*v.dnc+u]=f*9+1&127},()=>{t(e,j)[(k+se[26])*v.dnc+u]=f?127:0}][m]()})}else{let s=a[1];a.subarray(2).forEach((f,h)=>{let l=h+s;t(e,Te)[l]=f;let u=e.chRedir(1+(l>>4),c,!0),m=l&15;([!1,()=>{let k=t(e,Te)[u-1<<4];if(k<3)if(t(e,ge)[u]=1,k==2)for(let C=0;C{t(e,R)[u*v.rpn+3]=f+40,t(e,L)[v.rpnt*u+2]=1},()=>{t(e,R)[u*v.rpn+1]=f+14,t(e,L)[v.rpnt*u+1]=1},()=>{t(e,R)[u*v.rpn]=f,t(e,L)[v.rpnt*u]=1},!1,()=>{t(e,g)[v.cc*u+y[91]]=f?127:0},!1,()=>{t(e,g)[v.cc*u+y[7]]=f},()=>{t(e,g)[v.cc*u+y[10]]=Math.ceil(f*9.05)}][m]||(()=>{}))()})}}).add([22,18,4],(a,c,n)=>{e.switchMode("mt32");let i=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((f,h)=>{let l=h+i,u=e.chRedir(Math.floor(l/246+1),c,!0),m=l%246;m<14&&(t(e,le)[(u-1)*v.cmt+m]=f),m<10&&(t(e,ge)[u]=1),s.indexOf(u)<0&&s.push(u)}),s.forEach(f=>{e.dispatchEvent("voice",{part:f})})}).add([22,18,5],(a,c,n)=>{e.switchMode("mt32");let i=(a[0]<<7)+a[1];a.subarray(2).forEach((s,f)=>{let h=i+f,l=Math.floor(h/8),u=h&7,m=l*8;t(e,rt)[h]=s,([!1,()=>{let k=t(e,rt)[m];if(k<3){let C="";if(k==2){let _=v.cmt*l;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:l});let M=`MSB LSB PRG NME -000 127 ${l} ${C}`;e.userBank.load(M,!0)}}][u]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,c,n)=>{e.switchMode("mt32");let i=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((s,f)=>{let h=i+f;h>1)*v.cmt+h]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(a,c,n)=>{e.switchMode("mt32");let i=a[1],s=!1,f=function(h,l){t(e,K)[l-12]=h,s=!0};a.subarray(2).forEach((h,l)=>{let u=l+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,f,f,f,f,f,f,f,f,f,()=>{x(e,B,h),e.dispatchEvent("mastervolume",t(e,B))}][u]||(()=>{}))(h,l)}),s&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let c=a[1],n=" ".repeat(c);a.subarray(2).forEach(i=>{i>31?n+=String.fromCharCode(i):n+=" "}),x(e,Re,n.padStart(20," ")),x(e,De,Date.now()+3200)}).add([22,18,82],(a,c)=>{let n=e.chRedir(0,c,!0);for(let i=0;i<16;i++)t(e,X).ano(n+i),i&&i<10&&(t(e,U)[n+i]=Lt[i-1]);console.info("MT-32 alt reset complete.")}),t(this,ke).add([66,0],(a,c)=>{e.switchMode("ns5r",!0),x(e,N,!1),console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,c)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),x(e,N,!1)}).add([66,18,0,0],(a,c)=>{let n=a[0];switch(n){case 124:case 126:case 127:{e.switchMode("ns5r",!0),x(e,N,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(n<10){let i=[0,0,0,0],s=(f,h)=>{i[h]=f};if(a.subarray(1).forEach((f,h)=>{[s,s,s,s,()=>{x(e,B,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,B))},()=>f-64,()=>f-64,()=>{},()=>{},()=>{}][n+h]()}),a[0]<4){let f=0;i.forEach(h=>{f=f<<4,f+=h}),f-=1024}}}}).add([66,18,0,1],(a,c)=>{}).add([66,18,0,2],(a,c)=>{}).add([66,18,1],(a,c)=>{let n=e.chRedir(a[0],c,!0),i=n*v.cc,s=a[1],f=`NS5R CH${n+1} `;a.subarray(2).forEach((h,l)=>{let u=s+l;u<3?([()=>{t(e,g)[i+y[0]]=h||pt.bank0},()=>{t(e,g)[i+y[32]]=h},()=>{t(e,U)[n]=h}][u](),e.dispatchEvent("voice",{part:n})):u<8||(u<14?[()=>{let m=e.chRedir(h,c,!0);t(e,K)[n]=m,n!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))},()=>{t(e,ee)[n]=+!h},()=>{e.setChType(n,h,T.ns5r),console.debug(`${f}type: ${ht[h]}`)},()=>{t(e,R)[v.rpn*n+3]=h,t(e,L)[v.rpnt*n+2]=1},()=>{},()=>{}][u-8]():u<16||(u<33?[()=>{t(e,g)[i+y[7]]=h},()=>{t(e,g)[i+y[11]]=h},()=>{},()=>{},()=>{t(e,g)[i+y[10]]=h||128},()=>{},()=>{},()=>{t(e,g)[i+y[93]]=h},()=>{t(e,g)[i+y[91]]=h},()=>{t(e,g)[i+y[76]]=h},()=>{t(e,g)[i+y[77]]=h},()=>{t(e,g)[i+y[78]]=h},()=>{t(e,g)[i+y[74]]=h},()=>{t(e,g)[i+y[71]]=h},()=>{t(e,g)[i+y[73]]=h},()=>{t(e,g)[i+y[75]]=h},()=>{t(e,g)[i+y[72]]=h}][u-16]():u<112||u<114&&[()=>{t(e,g)[i+y[5]]=h},()=>{t(e,g)[i+y[65]]=h}][u-112]()))})}).add([66,18,8,0],(a,c)=>{let n=a[0];if(n<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let i=n-32;x(e,ue,Date.now()+3200),x(e,W,10),t(e,re,ye).fill(0);let s=a.subarray(1),f=4;s.forEach(function(h,l){let u=l+i,m=u>>4,k=u&15;if(u<80){let C=m>3,M=0,_=m0;)t(e,re,ye)[k*32+m*7+(_-M)]=C&1,C=C>>1,M++}})}}).add([66,18,48],(a,c,n)=>{p(0,a)}).add([66,18,49],(a,c,n)=>{p(1,a)}).add([66,18,50],(a,c,n)=>{p(2,a)}).add([66,18,51],(a,c,n)=>{p(3,a)}).add([66,18,52],(a,c,n)=>{p(4,a)}).add([66,18,53],(a,c,n)=>{p(5,a)}).add([66,18,54],(a,c,n)=>{p(6,a)}).add([66,18,55],(a,c,n)=>{p(7,a)}).add([66,52],(a,c)=>{e.switchMode("ns5r",!0),x(e,N,!1);let n="";fe(a,(i,s)=>{s<8?(i>31&&(n+=String.fromCharCode(i)),s==7&&(e.aiEfxName=n)):s<10&&(e.setEffectType(s-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(a,c)=>{e.switchMode("ns5r",!0),x(e,N,!1);let n="",i=a[a.length-1],s=a.subarray(0,a.length-1),f=Ie(s);f!=i&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${f}, got ${i}.`),console.debug(a)),fe(s,function(h,l){switch(!0){case l<2944:{let u=e.chRedir(Math.floor(l/92),c,!0),m=u*v.cc;switch(l%92){case 0:{t(e,g)[m+y[0]]=h,e.dispatchEvent("voice",{part:u});break}case 1:{t(e,g)[m+y[32]]=h,!h&&!t(e,g)[m+y[0]]&&(t(e,g)[m+y[0]]=pt.bank0),e.dispatchEvent("voice",{part:u});break}case 2:{t(e,U)[u]=h,h>0&&e.setChActive(u,1),e.dispatchEvent("voice",{part:u});break}case 3:{let k=e.chRedir(h,c,!0);t(e,K)[u]=k,u!=k&&(console.info(`NS5R CH${u+1} receives from CH${k+1}.`),e.buildRchTree());break}case 7:{t(e,O)[u]=h,e.dispatchEvent("voice",{part:u});break}case 8:{t(e,R)[u*v.rpn+3]=h<40||h>88?h+(h>63?-192:64):h,t(e,L)[v.rpnt*u+2]=1;break}case 9:case 10:{t(e,g)[m+y[7]]=h;break}case 11:{t(e,g)[m+y[11]]=h;break}case 14:{t(e,g)[m+y[10]]=h||128;break}case 19:{t(e,g)[m+y[93]]=h;break}case 20:{t(e,g)[m+y[91]]=h;break}case 84:{t(e,g)[m+y[65]]=h;break}case 85:{t(e,g)[m+y[5]]=h;break}}break}case l<3096:break;case l<3134:{let u=l-3096;u<8?(h>31&&(n+=String.fromCharCode(h)),u==7&&(e.aiEfxName=n)):u<10&&(e.setEffectType(u-8,44,h),e.dispatchEvent(`efx${["reverb","chorus"][u-8]}`,e.getEffectType(u-8)));break}case l<8566:break}})}).add([66,54],(a,c)=>{e.switchMode("ns5r",!0);let n="",i=80,s=0,f=0,h="MSB\tPRG\tLSB\tNME";fe(a,function(l,u){let m=u%158;switch(!0){case m<10:{l>31&&(n+=String.fromCharCode(l));break}case m==10:break;case m==11:{i=l&127;break}case m==12:{f=l&127;break}case m==13:{h+=` -${i} ${s} ${f} ${n.trim().replace("Init Voice","")}`,s++,n="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(h),A()&&console.debug(h),e.forceVoiceRefresh()}).add([66,55],(a,c)=>{e.switchMode("ns5r",!0);let n="",i=88,s=0,f=0,h="MSB\tPRG\tLSB\tNME";fe(a,function(l,u){let m=u%126;switch(!0){case m<10:{l>31&&(n+=String.fromCharCode(l));break}case m==11:break;case m==12:break;case m==13:{h+=` -${i} ${s} ${f} ${n.trim().replace("Init Combi","")}`,s++,n="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(h),A()&&console.debug(h),e.forceVoiceRefresh()}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let c=a[a.length-1],n=a.subarray(0,a.length-1),i=Ie(n);i!=c&&(console.info(`NS5R screen dump checksum mismatch! Expected ${i}, got ${c}.`),console.debug(a));let s=new Uint8Array(5760);fe(a,(f,h,l)=>{if(h<720)for(let u=0;u<8;u++)s[h*8+u]=f>>7-u&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(a,c,n)=>{t(e,ke).run([66,...a],c,n)}),t(this,Ve).add([16,0,8,0],(a,c,n)=>{let i=(a[2]<<4)+a[3],s="K11 ";([()=>{e.switchMode("k11",!0),x(e,N,!1),x(e,ie,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,c,n)=>{let i=e.chRedir(a[1],c,!0),s=v.cc*i,f=v.rpn*i,h=(a[3]<<4)+a[4],l=`K11 CH${i+1} `;([()=>{h<128?(e.setChType(i,e.CH_MELODIC,T.k11),t(e,g)[s+y[0]]=0,t(e,U)[i]=h):(e.setChType(i,e.CH_DRUMS,T.k11),t(e,U)[i]=h-128),e.dispatchEvent("voice",{part:i})},()=>{let u=e.chRedir(h,c,!0);t(e,K)[i]=u,i!=u&&(e.buildRchTree(),console.info(`${l}receives from CH${u+1}`))},()=>{t(e,g)[s+y[7]]=h},()=>{uupThis.setChActive(i,h)},()=>{t(e,g)[s+y[10]]=h},()=>{t(e,R)[f+3]=h+40,t(e,L)[v.rpnt*i+2]=1},()=>{t(e,R)[f+1]=h>>1,t(e,R)[f+2]=h&1,t(e,L)[v.rpnt*i+1]=1},()=>{t(e,g)[s+y[91]]=h?127:0},()=>{},()=>{t(e,g)[s+y[74]]=h},()=>{t(e,g)[s+y[73]]=h},()=>{t(e,g)[s+y[72]]=h}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,c,n)=>{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,c,n)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],c,!0),f=s*v.cc;[()=>{i<128?(e.setChType(s,e.CH_MELODIC,T.k11),t(e,g)[f+y[0]]=0,t(e,g)[f+y[32]]=0,t(e,U)[s]=i):i<160?(e.setChType(s,e.CH_MELODIC,T.k11),t(e,g)[f+y[0]]=0,t(e,g)[f+y[32]]=7,t(e,U)[s]=i-100):(e.setChType(s,e.CH_DRUMS,T.k11),t(e,g)[f+y[0]]=122,t(e,g)[f+y[32]]=0,t(e,U)[s]=i-160),e.dispatchEvent("voice",{part:s})},()=>{let h=e.chRedir(i,c,!0);t(e,K)[s]=h,s!=h&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${h+1}`))}][a[0]]()}).add([16,0,9,4],(a,c,n)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],c,!0),f=s*v.cc,h=s*v.rpn,l=`GMLX CH${s+1} `;[()=>{e.setChActive(s,i)},()=>{t(e,g)[f+y[7]]=i},()=>{t(e,g)[f+y[10]]=i},()=>{t(e,g)[f+y[91]]=i?127:0},()=>{t(e,R)[h+3]=i+40,t(e,L)[v.rpnt*s+2]=1},()=>{t(e,R)[h+1]=i,t(e,L)[v.rpnt*s+1]=1},()=>{t(e,R)[h]=i,t(e,L)[v.rpnt*s]=1},()=>{}][a[0]]()}),t(this,Fe).add([66,93,64],(a,c,n)=>{let i=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{x(e,B,i*129/16383*100),e.dispatchEvent("mastervolume",t(e,B));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: ${Ot[i]}`);break}}break}default:if(a[0]>>4==1){let s=e.chRedir(a[0]&15,c,!0);if(a[1]==2){let f=e.chRedir(i,c,!0);t(e,K)[s]=f,s!=f&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${f+1}`))}else a[1]==19&&(t(e,g)[v.cc*s+y[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,Ke).add([9],(a,c,n)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),t(this,ne).add([127,0],(a,c,n)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...a]);t(e,ne).run(i,c,n)}).add([127,1,0,0],(a,c,n)=>{e.switchMode("s90es");let i="S90/Motif ES system ",s=a[0];a.subarray(1).forEach((f,h)=>{([()=>{x(e,B,f*12900/16383),e.dispatchEvent("mastervolume",t(e,B))}][s+h]||(()=>{console.info(`Unrecognized ${i}ID: ${s+h}`)}))()})}).add([127,1,0,0,14],(a,c,n)=>{e.switchMode("s90es");let i="S90/Motif ES bulk header ",s=[];s[95]=(f,h,l)=>{console.debug(`${i}multi edit buffer: ${f[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,c,n)=>{e.switchMode("s90es");let i="S90/Motif ES bulk footer ",s=[];s[95]=(f,h,l)=>{console.debug(`${i}multi edit buffer: ${f[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,c,n)=>{e.switchMode("s90es");let i=e.chRedir(a[0],c,!0),s=v.cc*i,f=a[1],h=`S90/Motif ES bulk CH${i<16?i+1:"U"+(i-95)} `;console.debug(h,a),!(a[0]>15)&&a.subarray(2).forEach((l,u)=>{([()=>{t(e,g)[s+y[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),t(e,g)[s+y[32]]=l,e.setChType(i,[32,40].indexOf(l)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,P),!0),e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),t(e,U)[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let m=e.chRedir(l,c,!0);t(e,K)[i]=m,i!=m&&(e.buildRchTree(),console.info(`${h}receives from CH${m+1}`))},()=>{t(e,ee)[i]=l?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{t(e,g)[s+y[7]]=l},()=>{t(e,g)[s+y[10]]=l},!1,!1,!1,()=>{t(e,g)[s+y[91]]=l},()=>{t(e,g)[s+y[93]]=l},()=>{t(e,g)[s+y[94]]=l},()=>{t(e,g)[s+y[128]]=l},()=>{},()=>{t(e,g)[s+y[74]]=l},()=>{t(e,g)[s+y[71]]=l},!1,()=>{t(e,g)[s+y[65]]=l},()=>{t(e,g)[s+y[5]]=l},()=>{}][f+u]||(()=>{}))()})}).add([127,1,54,16],(a,c,n)=>{e.switchMode("s90es");let i=a[0];a.subarray(1).forEach((s,f)=>{let l=`S90/Motif ES EQ${(f>>2)+1} `;([()=>{let u=s-64},()=>{let u=et[s]},()=>{let u=s/10},()=>{let u=s}][i+f&3]||(()=>{}))()})}),t(this,ce).add([0,72,18,0,0,0,0],(a,c,n)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,c,n)=>{let i=a[0]>>5,s=a[0]&31;switch(i){case 0:{let f=a[0]>>1,h=a[1];switch(f){case 1:{a.subarray(2).forEach((l,u,m)=>{let k=u+h;switch(k){case 0:{l&&(e.setEffectType(1,60,l-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${k} - ${l}`));break}}});break}case 2:{a.subarray(2).forEach((l,u)=>{let m=u+h;switch(m){case 0:{l&&(e.setEffectType(0,55+l,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${m} - ${l}`));break}}});break}case 3:case 4:case 5:{let l=f-1;a.subarray(2).forEach((u,m)=>{let k=m+h;switch(console.debug(`SD MFX ${l-2}: ${k} - ${u}`),k){case 0:{e.setEffectTypeRaw(l,62,u),e.dispatchEvent(`efx${l>2?"delay":"insert"+(l-4)}`,e.getEffectType(l));break}}}),console.debug(`SD MFX message: +`),a.slice(0,2)){case"@I":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(n=a.slice(2))==null?void 0:n.trimLeft()});break}case"@K":{x(this,N,!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":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(i=a.slice(2))==null?void 0:i.trimLeft()});break}case"@T":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(s=a.slice(2))==null?void 0:s.trimLeft()});break}case"@V":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(f=a.slice(2))==null?void 0:f.trimLeft()});break}case"XF":{let h=a.slice(2).split(":");switch(h[0]){case"hd":{h.slice(1).forEach((l,u)=>{l.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][u],data:l})});break}case"ln":{h.slice(1).forEach((l,u)=>{l.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][u],data:l})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:t(this,N)?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(e,q)[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},t(e,q)[3]=function(a,n){n<1&&t(this,Ne)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},t(e,q)[4]=function(a,n){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},t(e,q)[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(e,q)[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},t(e,q)[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},t(e,q)[32]=function(a){x(this,Ne,a[0]+1)},t(e,q)[33]=function(a,n){t(e,Ae)[n]=a+1},t(e,q)[81]=function(a,n){x(e,st,a/1e3)},t(e,q)[127]=function(a,n){t(e,_e).run(a,n)},t(e,_e).default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},t(e,_e).add([67,0,1],function(a,n){t(e,Ae)[n]=a[0]+1}),x(e,Ge,new de("universal non-realtime")),x(e,Xe,new de("universal realtime")),x(e,se,new de("Yamaha")),x(e,le,new de("Roland")),x(e,ke,new de("Korg")),x(e,Ve,new de("Kawai")),x(e,Fe,new de("Akai")),x(e,Ke,new de("Casio"));let r=new de("DX7+ Dump"),d=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,a)};t(e,Ge).default=d,t(e,Xe).default=d,t(e,se).default=d,t(e,le).default=d,t(e,ke).default=d,t(e,Ve).default=d,t(e,Fe).default=d,t(e,Ke).default=d,r.default=d,t(e,Ge).add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),x(e,N,t(e,N)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),t(e,Xe).add([4,1],a=>{x(e,B,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,B))}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64).add([4,5],a=>{let n=a[0],c=a[1],i=a[2],s=3,f=s+(n<<1),h=f+c;if(n!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${n})! +`,a);return}let l=0,u=0,m=0;switch(a.subarray(s,f).forEach(w=>{l=l<<7,l|=w}),a.subarray(f,h).forEach((w,C)=>{u|=w<{m|=w<{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),x(e,N,!1),console.info("MIDI reset: XG");break}default:{let n=[0,0,0,0],c=(i,s)=>{n[s]=i};if(a.subarray(1).forEach((i,s)=>{let f=s+a[0];([c,c,c,c,h=>{x(this,B,h*129/16383*100),e.dispatchEvent("mastervolume",t(e,B))},h=>{},h=>{}][f]||(()=>{}))(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((c,i)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${n}main type: ${ft[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: ${jt(s)}s`)},s=>{console.debug(`${n}diffusion: ${s}`)},s=>{console.debug(`${n}initial delay: ${s}`)},s=>{console.debug(`${n}HPF cutoff: ${et[s]}Hz`)},s=>{console.debug(`${n}LPF cutoff: ${et[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: ${J(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]}.`)})(c)})):a[0]<64?(n+="chorus ",a.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${n}main type: ${ft[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: ${Wt[s]}Hz`)},s=>{},s=>{console.debug(`${n}feedback: ${s}`)},s=>{console.debug(`${n}delay offset: ${Zt(s)}ms`)},s=>{},s=>{console.debug(`${n}low: ${et[s]}Hz`)},s=>{console.debug(`${n}low: ${s-64}dB`)},s=>{console.debug(`${n}high: ${et[s]}Hz`)},s=>{console.debug(`${n}high: ${s-64}dB`)},s=>{console.debug(`${n}dry/wet: ${s}`)},s=>{console.debug(`${n}send: ${J(s)}dB`)},s=>{console.debug(`${n}pan: ${s-64}`)},s=>{console.debug(`${n}to reverb: ${J(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]}.`)})(c)})):a[0]<86?(n+="variation ",a.subarray(1).forEach((c,i)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${n}main type: ${ft[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(){})(c)})):a[0]<97?(n+="variation ",a.subarray(1).forEach((c,i)=>{[s=>{console.debug(`${n}send: ${J(s)}dB`)},s=>{console.debug(`${n}pan: ${s-64}`)},s=>{console.debug(`${n}to reverb: ${J(s)}dB`)},s=>{console.debug(`${n}to chorus: ${J(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](c)})):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,c)=>{let i=c+a[0];if(i==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][n]}`);else{let s=i-1>>2,f=i-1&3,h=`XG EQ ${s} ${["gain","freq","Q","shape"][f]}: `;[()=>{console.debug(`${h}${n-64}dB`)},()=>{console.debug(`${h}${n} (raw)`)},()=>{console.debug(`${h}${n/10}`)},()=>{console.debug(`${h}${["shelf","peak"][+!!n]}`)}][f]()}})}).add([76,3],a=>{let n=a[0],c=a[1],i=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((s,f)=>{([h=>{e.setEffectTypeRaw(3+n,!1,h),console.info(`${i}main type: ${ft[h]}`),e.dispatchEvent(`efxinsert${n}`,e.getEffectType(3+n))},h=>{e.setEffectTypeRaw(3+n,!0,h),console.debug(`${i}sub type: ${h+1}`),e.dispatchEvent(`efxinsert${n}`,e.getEffectType(3+n))}][c+f]||function(){})(s)})}).add([76,6,0],a=>{let n=a[0];n<64?e.setLetterDisplay(a.subarray(1),"XG letter display",n):x(e,Oe,Date.now())}).add([76,7,0],a=>{let n=a[0];x(e,W,0),x(e,ge,Date.now()+3200),t(e,ie,Ee).fill(0);let c=a.subarray(1);for(let i=0;i>6-m&1,m++})}).add([76,8],(a,n)=>{let c=e.chRedir(a[0],n,!0),i=a[1],s=E.cc*c,f=`XG CH${c+1} `,h=`Unknown XG part address ${i}.`;a.subarray(2).forEach((l,u)=>{i<1?console.debug(h):i<41?([()=>{t(e,g)[s+y[0]]=l,e.dispatchEvent("voice",{part:c})},()=>{t(e,g)[s+y[32]]=l,e.dispatchEvent("voice",{part:c})},()=>{t(e,U)[c]=l,e.dispatchEvent("voice",{part:c})},()=>{let m=e.chRedir(l,n,!0);t(e,K)[c]=m,c!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))},()=>{t(e,ee)[c]=+!l},()=>{},()=>{e.setChType(c,l,T.xg),console.debug(`${f}type: ${ht[l]||l}`)},()=>{t(e,R)[E.rpn*c+3]=l,t(e,L)[E.rpnt*c+2]=1},!1,!1,()=>{t(e,g)[s+y[7]]=l},!1,!1,()=>{t(e,g)[s+y[10]]=l||128},!1,!1,()=>{t(e,g)[s+y[128]]=l},()=>{t(e,g)[s+y[93]]=l},()=>{t(e,g)[s+y[91]]=l},()=>{t(e,g)[s+y[94]]=l},()=>{t(e,g)[s+y[76]]=l},()=>{t(e,g)[s+y[77]]=l},()=>{t(e,g)[s+y[78]]=l},()=>{t(e,g)[s+y[74]]=l},()=>{t(e,g)[s+y[71]]=l},()=>{t(e,g)[s+y[73]]=l},()=>{t(e,g)[s+y[75]]=l},()=>{t(e,g)[s+y[72]]=l}][i+u-1]||(()=>{}))():i<48?console.debug(h):i<111?i>102&&i<105&&(t(e,g)[s+y[[5,65][i&1]]]=l):i<114?console.debug(h):i<116?console.debug(`${f}EQ ${["bass","treble"][i&1]} gain: ${l-64}dB`):i<118?console.debug(h):i<120?console.debug(`${f}EQ ${["bass","treble"][i&1]} freq: ${l}`):console.debug(h)})}).add([76,9],(a,n)=>{let c=e.chRedir(a[0],n,!0),i=a[1],s=E.cc*c,f=`PLG-VL CH${c+1} `;a.subarray(2).forEach((h,l)=>{let u=l+i;switch(u){case 1:{console.info(`${f}breath mode: ${["system","breath","velocity","touch EG"][h]}`);break}case 0:case 27:case 28:break;default:if(u<27){let m=u-3>>1,w=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][m];u&1?u<23?(console.debug(`${f}${w} control source: ${ta(h)}`),h&&h<96&&e.allocateAce(130+m),t(e,Be)[E.redir*c+m+2]=h,e.buildRccMap()):console.debug(`${f}${w} scale break point: ${h}`):(console.debug(`${f}${w} depth: ${h-64}`),t(e,g)[s+y[130+m]]=h)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{switch(console.debug(`XG enable PLG-${["VL","SG","DX","AN","PF","DR","PC","AP"][a[0]]} for CH${a[2]+1}.`),a[0]){case 0:{t(e,te)[E.ext*a[2]]=e.EXT_VL;break}case 2:{t(e,te)[E.ext*a[2]]=e.EXT_DX;break}default:t(e,te)[E.ext*a[2]]=e.EXT_NONE}}).add([73,0,0],(a,n)=>{let c=a[0],i="MU1000 System: ";a.subarray(1).forEach((s,f)=>{let h=c+f;h==8?console.debug(`${i}LCD contrast set to ${s}.`):h==18?(x(e,oe,s?126:0),console.debug(`${i}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):h>=64&&h<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")},()=>{x(e,ue,!!s),console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][h-64]()})}).add([73,10,0],(a,n)=>{let c=a[0],i=`MU1000 RS${t(e,ue)?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let s=e.chRedir(0,n,!0);t(e,ue)&&(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,ue)&&e.dispatchEvent("channelmin",s),t(e,ue)&&e.dispatchEvent("channelmax",s+31),console.info(`${i}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${i}unknown switch ${c} invoked.`)}else if(c<32){if(t(e,ue)){let s=e.chRedir(c-16+(t(e,nt)<<4),n,!0);e.dispatchEvent("channelactive",s)}}else if(c<36){let s=e.chRedir(c-32<<4,n,!0);t(e,ue)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),x(e,nt,c-32)),console.info(`${i}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(a,n)=>{let c=e.chRedir(a[0],n,!0),i=`PLG-100SG CH${c+1} `,s=Date.now();if(a[1]==0){let f="",h=0;a.subarray(2).forEach((l,u)=>{u%2==0?f+=Jt[l]||l.toString().padStart("0"):h+=l*13}),s>=t(e,it)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${ea(f)}`,amend:!0}),x(e,it,s+Math.ceil(h/2)+t(e,st)),A()&&console.debug(`${i}vocals: ${f}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)}).add([98,0],(a,n,c)=>{let i=a[0],s=a.length-5,f=a.length-1;if(i!=s){console.info(`PLG-DX native dump size mismatch! Gave ${i} instead of ${a.length-5}.`);return}let h=Te(a.subarray(4,f));if(h!=a[f]){console.info(`Bad PLG-DX checksum ${a[f]} - should be ${h}.`);return}a[0]=98,t(e,se).run(a.subarray(0,f),n,c,{noAce:!0})}).add([98,96],(a,n,c,i)=>{let s=e.chRedir(a[0],n,!0),f=E.cc*s,h=a[1];a.subarray(2).forEach((l,u)=>{let m=h+u;if(!(m<10)){if(m==10)e.resetAce();else if(m<27){let w=m+131;i!=null&&i.noAce||e.allocateAce(w),t(e,g)[f+y[w]]=l,e.dispatchEvent("cc",{part:s,cc:w,data:l})}}})}).add([100,0],(a,n,c)=>{let i=a.subarray(0,a.length-1);if(a[0]+5!=a.length){console.warn(`Yamaha DX7+ dump SysEx size mismatch! Expected ${a.length}, but got ${a[0]}: +`,a);return}let s=Te(i),f=a[a.length-1];if(s!=f){console.warn(`Yamaha DX7+ dump SysEx checksum mismatch! Expected ${s}, but got ${f}: +`,a);return}r.run(i.subarray(1))}).add([100,76],(a,n,c)=>{let i=a[0]>>4,s=a[0]&15,f=a[1];switch(i){case 2:{let h=e.chRedir(s,n,!0),l=E.cc*h;a.subarray(2).forEach((u,m)=>{let w=m+f;if(!(w<7)){if(w<23){let C=w+135;e.allocateAce(C),t(e,g)[l+y[C]]=u,e.dispatchEvent("cc",{part:h,cc:C,data:u})}}});break}default:console.info("Unknown DX7+ multipart: %o",a)}}),r.add([14,31],a=>{t(e,g)[E.cc*a[0]+y[64]]=0,t(e,X).ano(a[0]),e.switchMode("xg"),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${a[0]+1}.`)}).add([76,112],async a=>{let n=a[0],c=E.cc*n,i=E.ext*n,s=E.cvn*n;t(e,te)[i]=e.EXT_DX,t(e,fe)[n]=1;let f=t(e,gt).subarray(s,s+E.cvn);f.fill(32),a.subarray(1).forEach((h,l)=>{if(l<10)f[l]=Math.max(h,32);else if(!(l<40)){if(l<56){let u=l+102;t(e,g)[c+y[u]]=h,e.dispatchEvent("cc",{part:n,cc:u,data:h})}}}),t(e,U)[n]=n&127,t(e,g)[E.cc*n+y[0]]=35,t(e,g)[E.cc*n+y[32]]=n>>7|4,e.dispatchEvent("voice",{part:n}),console.debug(`DX7+ CH${n+1} dump: %o`,a)});let o=function(a,n,c,i){},p=function(a,n){let c=a*E.dpn,i=n[0],s=n[1];n.subarray(2).forEach((f,h)=>{let l=h+s,u=-1;l<16?([()=>{u=24},()=>{u=25},()=>{u=26},()=>{},()=>{u=28},()=>{u=29},()=>{u=30},()=>{u=31},()=>{},()=>{},()=>{},()=>{u=20},()=>{u=21},()=>{u=22},()=>{u=23},()=>{}][l]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))():l<32||(l<40?([()=>{u=48},()=>{u=49},!1,!1,()=>{u=52},()=>{u=53}][l-32]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))():l<80||([()=>{u=36}][l-80]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))()),u>=0?(A()&&console.debug(c,u,i,f),t(e,j)[(c+ne[u])*E.dnc+i]=f):A()&&console.debug(`XG-style drum param ${l} has no writes.`)})},$=function(a,n,c){let i=a*E.dpn,s=(n<<7)+c[0];c.subarray(1).forEach((f,h)=>{let l=h+s,u=l&127,m=l>>7,w=-1;m>1&&([()=>{w=26},()=>{},()=>{w=28},()=>{w=29},()=>{w=30},()=>{},()=>{},()=>{w=31}][m-2]||(()=>{console.debug(`Unknown GS-style drum param ${m} on set ${a+1}.`)}))(),w>-1?(A()&&console.debug(i,w,u,f),t(e,j)[(i+ne[w])*E.dnc+u]=f):A()&&console.debug(`GS-style drum param ${m} has no writes.`)})};t(this,se).add([76,48],(a,n,c)=>{p(0,a)}).add([76,49],(a,n,c)=>{p(1,a)}).add([76,50],(a,n,c)=>{p(2,a)}).add([76,51],(a,n,c)=>{p(3,a)}).add([76,52],(a,n,c)=>{p(4,a)}).add([76,53],(a,n,c)=>{p(5,a)}).add([76,54],(a,n,c)=>{p(6,a)}).add([76,55],(a,n,c)=>{p(7,a)}),t(this,se).add([89,0],(a,n,c)=>{if(e.eprom){let i=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")}, ${i} bytes.`);let f=e.eprom.data;a.subarray(4).forEach((h,l)=>{let u=l>>3,m=l&7;if(m==7)for(let w=0;w<7;w++)f[s+7*u+w]+=(h>>6-w&1)<<7;else f[s+7*u+m]=h})}}).add([89,1],(a,n,c)=>{let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];A()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(a,n,c)=>{if(e.eprom){let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);A()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;a.subarray(4).forEach((f,h)=>{let l=h>>3,u=h&7;if(u==7)for(let m=0;m<7;m++)s[i+7*l+m]+=(f>>6-m&1)<<7;else s[i+7*l+u]=f})}}).add([89,3],(a,n,c)=>{}),t(this,se).add([39,48],(a,n,c)=>{}).add([43,0,0],(a,n,c)=>{let i=[0,0,0,0],s=(f,h)=>{i[h]=f};if(a.subarray(1).forEach((f,h)=>{let l=h+a[0];[s,s,s,s,()=>{x(this,B,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,B))},()=>f-64,()=>f||128,()=>f,()=>f,()=>{console.debug(`TG300 variation on cc${f}.`)}][l](f,l)}),a[0]<4){let f=0;i.forEach(h=>{f=f<<4,f+=h}),f-=1024}}).add([43,1,0],(a,n,c)=>{}).add([43,2],(a,n,c)=>{let i=e.chRedir(a[0],n,!0),s=a[1],f=E.cc*i,h=`TG300 CH${i+1} `;a.subarray(2).forEach((l,u)=>{u<5?([()=>{},()=>{t(e,g)[f+y[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{t(e,g)[f+y[32]]=l,e.dispatchEvent("voice",{part:i})},()=>{t(e,U)[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let m=e.chRedir(l,n,!0);t(e,K)[i]=m,i!=m&&(e.buildRchTree(),console.info(`${h}receives from CH${m+1}`))}][u+s]||(()=>{}))(l,u+s):u<21||(u<47?([()=>{t(e,ee)[i]=+!l},()=>{},()=>{},()=>{t(e,R)[E.rpn*i+3]=l,t(e,L)[E.rpnt*i+2]=1},()=>{},()=>{t(e,g)[f+y[7]]=l},!1,!1,()=>{t(e,g)[f+y[10]]=l||128},!1,!1,()=>{console.debug(`${h} AC1 at cc${l}`)},()=>{console.debug(`${h} AC2 at cc${l}`)},()=>{t(e,g)[f+y[128]]=l},()=>{t(e,g)[f+y[93]]=l},()=>{t(e,g)[f+y[91]]=l},()=>{t(e,g)[f+y[94]]=l},()=>{t(e,g)[f+y[76]]=l},()=>{t(e,g)[f+y[77]]=l},()=>{t(e,g)[f+y[74]]=l},()=>{t(e,g)[f+y[71]]=l},()=>{t(e,g)[f+y[73]]=l},()=>{t(e,g)[f+y[75]]=l},()=>{t(e,g)[f+y[72]]=l},()=>{t(e,g)[f+y[78]]=l}][u+s-21]||(()=>{}))(l,u+s):u<95||([()=>{t(e,g)[f+y[65]]=l},()=>{t(e,g)[f+y[5]]=l}][u+s-95]||(()=>{}))(l,u+s))})}).add([43,7,0],(a,n,c)=>{let i=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",i)}).add([43,7,1],(a,n,c)=>{x(e,W,0),x(e,ge,Date.now()+3200),t(e,ie,Ee).fill(0),a.forEach(function(i,s){let f=Math.floor(s/16),h=s%16,l=(h*3+f)*7,u=7,m=0;for(l-=h*5,f==2&&(u=2);m>6-m&1,m++})}),t(this,le).add([66,18,0,0,127],(a,n,c)=>{e.switchMode("gs",!0),t(e,g)[E.cc*9]=120,t(e,g)[E.cc*25]=120,t(e,g)[E.cc*41]=120,t(e,g)[E.cc*57]=120,x(e,oe,3),x(e,N,!1),t(e,we).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,n,c)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),t(e,g)[E.cc*9]=120,t(e,g)[E.cc*25]=120,t(e,g)[E.cc*41]=120,t(e,g)[E.cc*57]=120,x(e,N,!1),t(e,we).fill(0),console.info("MIDI reset: GS");break}default:{let i=[0,0,0,0],s=(f,h)=>{i[h]=f};if(a.subarray(1).forEach((f,h)=>{let l=h+a[0];[s,s,s,s,u=>{x(this,B,u*129/16383*100),e.dispatchEvent("mastervolume",t(e,B))},u=>{},u=>{}][l](f,h)}),a[0]<4){let f=0;i.forEach(h=>{f=f<<4,f+=h}),f-=1024}}}}).add([66,18,64,1],a=>{let n=a[0];if(n<16){let c="".padStart(n," ");a.subarray(1).forEach((i,s)=>{c+=String.fromCharCode(Math.max(32,i))}),c=c.padEnd(16," "),console.debug(`GS patch name: ${c}`)}else n<48||(n<65?a.subarray(1).forEach((c,i)=>{let s=`GS ${n+i>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${At[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${c}ms`)},()=>{console.info(`${s}type: ${aa[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${J(c)}`)},()=>{console.debug(`${s}to delay: ${J(c)}`)}][n+i-48]||(()=>{}))()}):n<80?console.debug(`Unknown GS patch address: ${n}`):n<91?a.subarray(1).forEach((c,i)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${ra[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${J(c)}`)}][n+i-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${n}`))}).add([66,18,64,2],a=>{let n="GS EQ ";a.subarray(1).forEach((c,i)=>{([()=>{console.debug(`${n}low freq: ${[200,400][c]}Hz`)},()=>{console.debug(`${n}low gain: ${c-64}dB`)},()=>{console.debug(`${n}high freq: ${[3e3,6e3][c]}Hz`)},()=>{console.debug(`${n}high gain: ${c-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 ",c=function(i,s){let f=sa(t(e,ae).subarray(10,12),s,i);f&&console.debug(`${n}${Lt(t(e,ae).subarray(10,12))} ${f}`)};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: ${Lt(t(e,ae).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(`${n}to reverb: ${J(i)}dB`)},()=>{console.debug(`${n}to chorus: ${J(i)}dB`)},()=>{console.debug(`${n}to delay: ${J(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(f,h){console.warn(`Unknown GS EFX address: ${h}`)})(i,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 n;switch(a[0]){case 0:{let c=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",c);break}case 32:{x(e,ge,Date.now()+3200),a[1]==0&&(x(e,W,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,W)>9&&x(e,W,0);let c=a[0]-1<<1|a[1]>>6;t(e,W)==c&&x(e,ge,Date.now()+3200),(n=t(e,ve)[c])!=null&&n.length||(t(e,ve)[c]=new Uint8Array(256));let i=t(e,ve)[c];A()&&console.debug(`GS frame draw page ${c}.`);let s=a[1]&63;i.fill(0),a.subarray(2).forEach(function(h,l){let u=l+s,m=Math.floor(u/16),w=u%16,C=(w*4+m)*5,M=5,G=0;for(C-=w*4,m==3&&(M=1);G>4-G&1,G++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let v=function(a,n,c){let i=a[0],s=E.cc*n,f=E.rpn*n,h=`GS CH${n+1} `;i<3?(a.subarray(1).forEach((l,u)=>{[()=>{t(e,g)[s+y[0]]=l},()=>{t(e,U)[n]=l},()=>{let m=0;l<16?m=e.chRedir(l,c,!0):m=E.ch,t(e,K)[n]=m,n!=m&&(e.buildRchTree(),console.info(`${h}receives from CH${m+1}`))}][i+u]()}),e.dispatchEvent("voice",{part:n})):i<19||(i<44?a.subarray(1).forEach((l,u)=>{([()=>{t(e,ee)[n]=+!l},!1,()=>{e.setChType(n,l<<1,T.gs),console.debug(`${h}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{t(e,R)[f+3]=l,t(e,L)[E.rpnt*n+2]=1},!1,()=>{t(e,g)[s+y[7]]=l},!1,!1,()=>{t(e,g)[s+y[10]]=l||128},!1,!1,()=>{console.debug(`${h}CC 1: cc${l}`)},()=>{console.debug(`${h}CC 2: cc${l}`)},()=>{t(e,g)[s+y[93]]=l},()=>{t(e,g)[s+y[91]]=l},!1,!1,()=>{t(e,R)[f+1]=l,t(e,L)[E.rpnt*n+1]=1},()=>{t(e,R)[f+2]=l,t(e,L)[E.rpnt*n+1]=1},()=>{t(e,g)[s+y[94]]=l}][i+u-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},k=function(a,n){let c=a[0],i=`GS CH${n+1} `;c<2?a.subarray(1).forEach((s,f)=>{[()=>{t(e,g)[E.cc*n+y[32]]=s},()=>{}][c+f]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?a.subarray(1).forEach((s,f)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][s]}`),t(e,at)[n]=s,e.dispatchEvent("partefxtoggle",{part:n,active:s})}][c+f-32]()}):console.warn(`Unknown GS misc address: ${c}`)};t(this,le).add([66,18,64,16],(a,n)=>{v(a,e.chRedir(9,n,!0),n)}).add([66,18,64,17],(a,n)=>{v(a,e.chRedir(0,n,!0),n)}).add([66,18,64,18],(a,n)=>{v(a,e.chRedir(1,n,!0),n)}).add([66,18,64,19],(a,n)=>{v(a,e.chRedir(2,n,!0),n)}).add([66,18,64,20],(a,n)=>{v(a,e.chRedir(3,n,!0),n)}).add([66,18,64,21],(a,n)=>{v(a,e.chRedir(4,n,!0),n)}).add([66,18,64,22],(a,n)=>{v(a,e.chRedir(5,n,!0),n)}).add([66,18,64,23],(a,n)=>{v(a,e.chRedir(6,n,!0),n)}).add([66,18,64,24],(a,n)=>{v(a,e.chRedir(7,n,!0),n)}).add([66,18,64,25],(a,n)=>{v(a,e.chRedir(8,n,!0),n)}).add([66,18,64,26],(a,n)=>{v(a,e.chRedir(10,n,!0),n)}).add([66,18,64,27],(a,n)=>{v(a,e.chRedir(11,n,!0),n)}).add([66,18,64,28],(a,n)=>{v(a,e.chRedir(12,n,!0),n)}).add([66,18,64,29],(a,n)=>{v(a,e.chRedir(13,n,!0),n)}).add([66,18,64,30],(a,n)=>{v(a,e.chRedir(14,n,!0),n)}).add([66,18,64,31],(a,n)=>{v(a,e.chRedir(15,n,!0),n)}).add([66,18,64,64],(a,n)=>{k(a,e.chRedir(9,n,!0))}).add([66,18,64,65],(a,n)=>{k(a,e.chRedir(0,n,!0))}).add([66,18,64,66],(a,n)=>{k(a,e.chRedir(1,n,!0))}).add([66,18,64,67],(a,n)=>{k(a,e.chRedir(2,n,!0))}).add([66,18,64,68],(a,n)=>{k(a,e.chRedir(3,n,!0))}).add([66,18,64,69],(a,n)=>{k(a,e.chRedir(4,n,!0))}).add([66,18,64,70],(a,n)=>{k(a,e.chRedir(5,n,!0))}).add([66,18,64,71],(a,n)=>{k(a,e.chRedir(6,n,!0))}).add([66,18,64,72],(a,n)=>{k(a,e.chRedir(7,n,!0))}).add([66,18,64,73],(a,n)=>{k(a,e.chRedir(8,n,!0))}).add([66,18,64,74],(a,n)=>{k(a,e.chRedir(10,n,!0))}).add([66,18,64,75],(a,n)=>{k(a,e.chRedir(11,n,!0))}).add([66,18,64,76],(a,n)=>{k(a,e.chRedir(12,n,!0))}).add([66,18,64,77],(a,n)=>{k(a,e.chRedir(13,n,!0))}).add([66,18,64,78],(a,n)=>{k(a,e.chRedir(14,n,!0))}).add([66,18,64,79],(a,n)=>{k(a,e.chRedir(15,n,!0))}),t(this,ke).add([54,65],(a,n)=>{e.switchMode("x5d");let c=a[a.length-1],i=a.subarray(0,a.length-1),s=Te(i);s!=c&&(console.info(`X5D multi parameters checksum mismatch! Expected ${s}, got ${c}.`),console.debug(a));let f=(a[1]<<7)+a[0],h=(a[3]<<7)+a[2],l=e.chRedir(f&15,n,!0),u=E.cc*l;[()=>{h<1||(h<101?(e.setChType(l,e.CH_MELODIC,T.x5d),t(e,U)[l]=h-1,t(e,g)[u+y[0]]=t(e,_).x5):h<229?(e.setChType(l,e.CH_MELODIC,T.x5d),t(e,U)[l]=h-101,t(e,g)[u+y[0]]=56):(e.setChType(l,e.CH_DRUMS,T.x5d),t(e,U)[l]=ua[h-229]||0,t(e,g)[u+y[0]]=62)),e.dispatchEvent("voice",{part:l})},()=>{t(e,g)[u+y[7]]=h},()=>{h<31&&(t(e,g)[u+y[10]]=Math.round((h-15)*4.2+64))},()=>{t(e,g)[u+y[93]]=ut(h)},()=>{t(e,g)[u+y[91]]=ut(h)},()=>{t(e,R)[l*E.rpn+3]=h>8191?h-16320:64+h,t(e,L)[E.rpnt*l+2]=1},()=>{t(e,R)[l*E.rpn+1]=h>8191?h-16320:64+h,t(e,L)[E.rpnt*l+1]=1},()=>{h>0&&(t(e,R)[l*E.rpn]=h,t(e,L)[E.rpnt*l]=1)},()=>{}][f>>4]()}).add([54,76,0],(a,n)=>{e.switchMode(t(e,_).x5=="81"?"05rw":"x5d",!0);let c="",i=t(e,_).x5,s=0,f=0,h="MSB\tPRG\tLSB\tNME";pe(a,function(l,u){if(u<16400){let m=u%164;switch(!0){case m<10:{l>31&&(c+=String.fromCharCode(l));break}case m==10:break;case m==11:{h+=` +${i} ${s} ${f} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}s>99&&(i=90,s=0)}}),e.userBank.clearRange({msb:t(e,_).x5,prg:[0,99],lsb:0}),e.userBank.load(h),A()&&console.debug(h),e.forceVoiceRefresh()}).add([54,77,0],(a,n)=>{e.switchMode(t(e,_).x5=="81"?"05rw":"x5d",!0);let c="",i=90,s=0,f=0,h="MSB\tPRG\tLSB\tNME";pe(a,function(l,u){if(u<13600){let m=u%136;switch(!0){case m<10:{l>31&&(c+=String.fromCharCode(l));break}case m==11:{h+=` +${i} ${s} ${f} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(h),A()&&console.debug(h),e.forceVoiceRefresh()}).add([54,78],(a,n)=>{e.switchMode(t(e,_).x5=="81"?"05rw":"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(t(e,_).x5=="81"?"05rw":"x5d",!0),pe(a,(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],(a,n)=>{e.switchMode(t(e,_).x5=="81"?"05rw":"x5d",!0),pe(a,function(c,i,s,f){if(i<192){let h=e.chRedir(Math.floor(i/12),n,!0),l=h*E.cc;switch(i%12){case 0:{c<128?(e.setChType(h,e.CH_MELODIC,T.x5d),t(e,g)[l+y[0]]=t(e,_).x5,t(e,U)[h]=c):(e.setChType(h,e.CH_DRUMS,T.x5d),t(e,g)[l+y[0]]=62,t(e,U)[h]=ua[c-128]),c>0&&e.setChActive(h,1),e.dispatchEvent("voice",{part:h});break}case 1:{t(e,g)[l+y[7]]=c;break}case 2:{t(e,R)[h*E.rpn+3]=c>127?c-192:64+c,t(e,L)[E.rpnt*h+2]=1;break}case 3:{t(e,R)[h*E.rpn+1]=c>127?c-192:64+c,t(e,L)[E.rpnt*h+1]=1;break}case 4:{c<31&&(t(e,g)[l+y[10]]=Math.round((c-15)*4.2+64));break}case 5:{let u=c>>4,m=c&15;t(e,g)[l+y[91]]=ut(m),t(e,g)[l+y[93]]=ut(u);break}case 10:break;case 11:{let u=e.chRedir(c&15,n,!0),m=c>>4;t(e,K)[h]=c,(u!=h||m)&&(console.info(`X5D Part CH${h+1} receives from CH${u+1}.`),e.buildRchTree())}}}else{let h=e.chRedir(i-192,n,!0)}})}),t(this,le).add([22,18,127],a=>{e.switchMode("mt32",!0),x(e,N,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,n,c)=>{e.switchMode("mt32");let i=e.chRedir(c,n,!0),s=a[1];a.subarray(2).forEach((f,h)=>{let l=h+s;t(e,Ce)[l+(i-1)*16]=f,([!1,()=>{let u=t(e,Ce)[i-1<<4];if(u<3){if(t(e,fe)[i]=1,u==2)for(let m=0;m{t(e,R)[i*E.rpn+3]=f+40,t(e,L)[E.rpnt*i+2]=1},()=>{t(e,R)[i*E.rpn+1]=f+14,t(e,L)[E.rpnt*i+1]=1},()=>{t(e,R)[i*E.rpn]=f,t(e,L)[E.rpnt*i]=1},!1,()=>{t(e,g)[E.cc*i+y[91]]=f?127:0},!1,()=>{t(e,g)[E.cc*i+y[7]]=f},()=>{t(e,g)[E.cc*i+y[10]]=Math.ceil(f*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(a,n,c)=>{e.switchMode("mt32");let i=c&7;console.debug(`MT-32 slot #${c+1} Drum: ${a}`);let s=a[0]<<7|a[1];a.subarray(2).forEach((f,h)=>{let l=h+s,u=(l>>2)+24,m=l&3,w=i*E.dpn;if(A()&&console.debug(`MT-32 temp drum note ${u} param ${m}: ${f}`),u<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${u}`);return}[()=>{},()=>{t(e,j)[(w+ne[26])*E.dnc+u]=Math.round(f*1.27)},()=>{t(e,j)[(w+ne[26])*E.dnc+u]=f*9+1&127},()=>{t(e,j)[(w+ne[26])*E.dnc+u]=f?127:0}][m]()})}).add([22,18,2],(a,n,c)=>{e.switchMode("mt32");let i=e.chRedir(c,n,!0),s=a[1]+(a[0]<<7);s<10&&(t(e,fe)[i]=1),a.subarray(2).forEach((f,h)=>{let l=h+s;l<14&&(t(e,he)[(i-1)*E.cmt+l]=f)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(a,n,c)=>{e.switchMode("mt32");let i=c&7;if(a[0]){let s=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((f,h)=>{let l=h+s,u=(l>>2)+24,m=l&3,w=i*E.dpn;if(A()&&console.debug(`MT-32 dev drum note ${u} param ${m}: ${f}`),u<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${u}`);return}[()=>{},()=>{t(e,j)[(w+ne[26])*E.dnc+u]=Math.round(f*1.27)},()=>{t(e,j)[(w+ne[26])*E.dnc+u]=f*9+1&127},()=>{t(e,j)[(w+ne[26])*E.dnc+u]=f?127:0}][m]()})}else{let s=a[1];a.subarray(2).forEach((f,h)=>{let l=h+s;t(e,Ce)[l]=f;let u=e.chRedir(1+(l>>4),n,!0),m=l&15;([!1,()=>{let w=t(e,Ce)[u-1<<4];if(w<3)if(t(e,fe)[u]=1,w==2)for(let C=0;C{t(e,R)[u*E.rpn+3]=f+40,t(e,L)[E.rpnt*u+2]=1},()=>{t(e,R)[u*E.rpn+1]=f+14,t(e,L)[E.rpnt*u+1]=1},()=>{t(e,R)[u*E.rpn]=f,t(e,L)[E.rpnt*u]=1},!1,()=>{t(e,g)[E.cc*u+y[91]]=f?127:0},!1,()=>{t(e,g)[E.cc*u+y[7]]=f},()=>{t(e,g)[E.cc*u+y[10]]=Math.ceil(f*9.05)}][m]||(()=>{}))()})}}).add([22,18,4],(a,n,c)=>{e.switchMode("mt32");let i=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((f,h)=>{let l=h+i,u=e.chRedir(Math.floor(l/246+1),n,!0),m=l%246;m<14&&(t(e,he)[(u-1)*E.cmt+m]=f),m<10&&(t(e,fe)[u]=1),s.indexOf(u)<0&&s.push(u)}),s.forEach(f=>{e.dispatchEvent("voice",{part:f})})}).add([22,18,5],(a,n,c)=>{e.switchMode("mt32");let i=(a[0]<<7)+a[1];a.subarray(2).forEach((s,f)=>{let h=i+f,l=Math.floor(h/8),u=h&7,m=l*8;t(e,rt)[h]=s,([!1,()=>{let w=t(e,rt)[m];if(w<3){let C="";if(w==2){let G=E.cmt*l;C=`MT-m:${s.toString().padStart(3,"0")}`}else C=e.baseBank.get(0,s+(w<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l});let M=`MSB LSB PRG NME +000 127 ${l} ${C}`;e.userBank.load(M,!0)}}][u]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,n,c)=>{e.switchMode("mt32");let i=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((s,f)=>{let h=i+f;h>1)*E.cmt+h]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(a,n,c)=>{e.switchMode("mt32");let i=a[1],s=!1,f=function(h,l){t(e,K)[l-12]=h,s=!0};a.subarray(2).forEach((h,l)=>{let u=l+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,f,f,f,f,f,f,f,f,f,()=>{x(e,B,h),e.dispatchEvent("mastervolume",t(e,B))}][u]||(()=>{}))(h,l)}),s&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let n=a[1],c=" ".repeat(n);a.subarray(2).forEach(i=>{i>31?c+=String.fromCharCode(i):c+=" "}),x(e,De,c.padStart(20," ")),x(e,Oe,Date.now()+3200)}).add([22,18,82],(a,n)=>{let c=e.chRedir(0,n,!0);for(let i=0;i<16;i++)t(e,X).ano(c+i),i&&i<10&&(t(e,U)[c+i]=It[i-1]);console.info("MT-32 alt reset complete.")}),t(this,ke).add([66,0],(a,n)=>{e.switchMode("ns5r",!0),x(e,N,!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),x(e,N,!1)}).add([66,18,0,0],(a,n)=>{let c=a[0];switch(c){case 124:case 126:case 127:{e.switchMode("ns5r",!0),x(e,N,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(c<10){let i=[0,0,0,0],s=(f,h)=>{i[h]=f};if(a.subarray(1).forEach((f,h)=>{[s,s,s,s,()=>{x(e,B,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,B))},()=>f-64,()=>f-64,()=>{},()=>{},()=>{}][c+h]()}),a[0]<4){let f=0;i.forEach(h=>{f=f<<4,f+=h}),f-=1024}}}}).add([66,18,0,1],(a,n)=>{}).add([66,18,0,2],(a,n)=>{}).add([66,18,1],(a,n)=>{let c=e.chRedir(a[0],n,!0),i=c*E.cc,s=a[1],f=`NS5R CH${c+1} `;a.subarray(2).forEach((h,l)=>{let u=s+l;u<3?([()=>{t(e,g)[i+y[0]]=h||pt.bank0},()=>{t(e,g)[i+y[32]]=h},()=>{t(e,U)[c]=h}][u](),e.dispatchEvent("voice",{part:c})):u<8||(u<14?[()=>{let m=e.chRedir(h,n,!0);t(e,K)[c]=m,c!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))},()=>{t(e,ee)[c]=+!h},()=>{e.setChType(c,h,T.ns5r),console.debug(`${f}type: ${ht[h]}`)},()=>{t(e,R)[E.rpn*c+3]=h,t(e,L)[E.rpnt*c+2]=1},()=>{},()=>{}][u-8]():u<16||(u<33?[()=>{t(e,g)[i+y[7]]=h},()=>{t(e,g)[i+y[11]]=h},()=>{},()=>{},()=>{t(e,g)[i+y[10]]=h||128},()=>{},()=>{},()=>{t(e,g)[i+y[93]]=h},()=>{t(e,g)[i+y[91]]=h},()=>{t(e,g)[i+y[76]]=h},()=>{t(e,g)[i+y[77]]=h},()=>{t(e,g)[i+y[78]]=h},()=>{t(e,g)[i+y[74]]=h},()=>{t(e,g)[i+y[71]]=h},()=>{t(e,g)[i+y[73]]=h},()=>{t(e,g)[i+y[75]]=h},()=>{t(e,g)[i+y[72]]=h}][u-16]():u<112||u<114&&[()=>{t(e,g)[i+y[5]]=h},()=>{t(e,g)[i+y[65]]=h}][u-112]()))})}).add([66,18,8,0],(a,n)=>{let c=a[0];if(c<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let i=c-32;x(e,ge,Date.now()+3200),x(e,W,10),t(e,ie,Ee).fill(0);let s=a.subarray(1),f=4;s.forEach(function(h,l){let u=l+i,m=u>>4,w=u&15;if(u<80){let C=m>3,M=0,G=m0;)t(e,ie,Ee)[w*32+m*7+(G-M)]=C&1,C=C>>1,M++}})}}).add([66,18,48],(a,n,c)=>{p(0,a)}).add([66,18,49],(a,n,c)=>{p(1,a)}).add([66,18,50],(a,n,c)=>{p(2,a)}).add([66,18,51],(a,n,c)=>{p(3,a)}).add([66,18,52],(a,n,c)=>{p(4,a)}).add([66,18,53],(a,n,c)=>{p(5,a)}).add([66,18,54],(a,n,c)=>{p(6,a)}).add([66,18,55],(a,n,c)=>{p(7,a)}).add([66,52],(a,n)=>{e.switchMode("ns5r",!0),x(e,N,!1);let c="";pe(a,(i,s)=>{s<8?(i>31&&(c+=String.fromCharCode(i)),s==7&&(e.aiEfxName=c)):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),x(e,N,!1);let c="",i=a[a.length-1],s=a.subarray(0,a.length-1),f=Te(s);f!=i&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${f}, got ${i}.`),console.debug(a)),pe(s,function(h,l){switch(!0){case l<2944:{let u=e.chRedir(Math.floor(l/92),n,!0),m=u*E.cc;switch(l%92){case 0:{t(e,g)[m+y[0]]=h,e.dispatchEvent("voice",{part:u});break}case 1:{t(e,g)[m+y[32]]=h,!h&&!t(e,g)[m+y[0]]&&(t(e,g)[m+y[0]]=pt.bank0),e.dispatchEvent("voice",{part:u});break}case 2:{t(e,U)[u]=h,h>0&&e.setChActive(u,1),e.dispatchEvent("voice",{part:u});break}case 3:{let w=e.chRedir(h,n,!0);t(e,K)[u]=w,u!=w&&(console.info(`NS5R CH${u+1} receives from CH${w+1}.`),e.buildRchTree());break}case 7:{t(e,O)[u]=h,e.dispatchEvent("voice",{part:u});break}case 8:{t(e,R)[u*E.rpn+3]=h<40||h>88?h+(h>63?-192:64):h,t(e,L)[E.rpnt*u+2]=1;break}case 9:case 10:{t(e,g)[m+y[7]]=h;break}case 11:{t(e,g)[m+y[11]]=h;break}case 14:{t(e,g)[m+y[10]]=h||128;break}case 19:{t(e,g)[m+y[93]]=h;break}case 20:{t(e,g)[m+y[91]]=h;break}case 84:{t(e,g)[m+y[65]]=h;break}case 85:{t(e,g)[m+y[5]]=h;break}}break}case l<3096:break;case l<3134:{let u=l-3096;u<8?(h>31&&(c+=String.fromCharCode(h)),u==7&&(e.aiEfxName=c)):u<10&&(e.setEffectType(u-8,44,h),e.dispatchEvent(`efx${["reverb","chorus"][u-8]}`,e.getEffectType(u-8)));break}case l<8566:break}})}).add([66,54],(a,n)=>{e.switchMode("ns5r",!0);let c="",i=80,s=0,f=0,h="MSB\tPRG\tLSB\tNME";pe(a,function(l,u){let m=u%158;switch(!0){case m<10:{l>31&&(c+=String.fromCharCode(l));break}case m==10:break;case m==11:{i=l&127;break}case m==12:{f=l&127;break}case m==13:{h+=` +${i} ${s} ${f} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(h),A()&&console.debug(h),e.forceVoiceRefresh()}).add([66,55],(a,n)=>{e.switchMode("ns5r",!0);let c="",i=88,s=0,f=0,h="MSB\tPRG\tLSB\tNME";pe(a,function(l,u){let m=u%126;switch(!0){case m<10:{l>31&&(c+=String.fromCharCode(l));break}case m==11:break;case m==12:break;case m==13:{h+=` +${i} ${s} ${f} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(h),A()&&console.debug(h),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=a[a.length-1],c=a.subarray(0,a.length-1),i=Te(c);i!=n&&(console.info(`NS5R screen dump checksum mismatch! Expected ${i}, got ${n}.`),console.debug(a));let s=new Uint8Array(5760);pe(a,(f,h,l)=>{if(h<720)for(let u=0;u<8;u++)s[h*8+u]=f>>7-u&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(a,n,c)=>{t(e,ke).run([66,...a],n,c)}),t(this,Ve).add([16,0,8,0],(a,n,c)=>{let i=(a[2]<<4)+a[3],s="K11 ";([()=>{e.switchMode("k11",!0),x(e,N,!1),x(e,oe,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,c)=>{let i=e.chRedir(a[1],n,!0),s=E.cc*i,f=E.rpn*i,h=(a[3]<<4)+a[4],l=`K11 CH${i+1} `;([()=>{h<128?(e.setChType(i,e.CH_MELODIC,T.k11),t(e,g)[s+y[0]]=0,t(e,U)[i]=h):(e.setChType(i,e.CH_DRUMS,T.k11),t(e,U)[i]=h-128),e.dispatchEvent("voice",{part:i})},()=>{let u=e.chRedir(h,n,!0);t(e,K)[i]=u,i!=u&&(e.buildRchTree(),console.info(`${l}receives from CH${u+1}`))},()=>{t(e,g)[s+y[7]]=h},()=>{uupThis.setChActive(i,h)},()=>{t(e,g)[s+y[10]]=h},()=>{t(e,R)[f+3]=h+40,t(e,L)[E.rpnt*i+2]=1},()=>{t(e,R)[f+1]=h>>1,t(e,R)[f+2]=h&1,t(e,L)[E.rpnt*i+1]=1},()=>{t(e,g)[s+y[91]]=h?127:0},()=>{},()=>{t(e,g)[s+y[74]]=h},()=>{t(e,g)[s+y[73]]=h},()=>{t(e,g)[s+y[72]]=h}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,n,c)=>{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,c)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],n,!0),f=s*E.cc;[()=>{i<128?(e.setChType(s,e.CH_MELODIC,T.k11),t(e,g)[f+y[0]]=0,t(e,g)[f+y[32]]=0,t(e,U)[s]=i):i<160?(e.setChType(s,e.CH_MELODIC,T.k11),t(e,g)[f+y[0]]=0,t(e,g)[f+y[32]]=7,t(e,U)[s]=i-100):(e.setChType(s,e.CH_DRUMS,T.k11),t(e,g)[f+y[0]]=122,t(e,g)[f+y[32]]=0,t(e,U)[s]=i-160),e.dispatchEvent("voice",{part:s})},()=>{let h=e.chRedir(i,n,!0);t(e,K)[s]=h,s!=h&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${h+1}`))}][a[0]]()}).add([16,0,9,4],(a,n,c)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],n,!0),f=s*E.cc,h=s*E.rpn,l=`GMLX CH${s+1} `;[()=>{e.setChActive(s,i)},()=>{t(e,g)[f+y[7]]=i},()=>{t(e,g)[f+y[10]]=i},()=>{t(e,g)[f+y[91]]=i?127:0},()=>{t(e,R)[h+3]=i+40,t(e,L)[E.rpnt*s+2]=1},()=>{t(e,R)[h+1]=i,t(e,L)[E.rpnt*s+1]=1},()=>{t(e,R)[h]=i,t(e,L)[E.rpnt*s]=1},()=>{}][a[0]]()}),t(this,Fe).add([66,93,64],(a,n,c)=>{let i=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{x(e,B,i*129/16383*100),e.dispatchEvent("mastervolume",t(e,B));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: ${At[i]}`);break}}break}default:if(a[0]>>4==1){let s=e.chRedir(a[0]&15,n,!0);if(a[1]==2){let f=e.chRedir(i,n,!0);t(e,K)[s]=f,s!=f&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${f+1}`))}else a[1]==19&&(t(e,g)[E.cc*s+y[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,Ke).add([9],(a,n,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,se).add([127,0],(a,n,c)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...a]);t(e,se).run(i,n,c)}).add([127,1,0,0],(a,n,c)=>{e.switchMode("s90es");let i="S90/Motif ES system ",s=a[0];a.subarray(1).forEach((f,h)=>{([()=>{x(e,B,f*12900/16383),e.dispatchEvent("mastervolume",t(e,B))}][s+h]||(()=>{console.info(`Unrecognized ${i}ID: ${s+h}`)}))()})}).add([127,1,0,0,14],(a,n,c)=>{e.switchMode("s90es");let i="S90/Motif ES bulk header ",s=[];s[95]=(f,h,l)=>{console.debug(`${i}multi edit buffer: ${f[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,n,c)=>{e.switchMode("s90es");let i="S90/Motif ES bulk footer ",s=[];s[95]=(f,h,l)=>{console.debug(`${i}multi edit buffer: ${f[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,n,c)=>{e.switchMode("s90es");let i=e.chRedir(a[0],n,!0),s=E.cc*i,f=a[1],h=`S90/Motif ES bulk CH${i<16?i+1:"U"+(i-95)} `;console.debug(h,a),!(a[0]>15)&&a.subarray(2).forEach((l,u)=>{([()=>{t(e,g)[s+y[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),t(e,g)[s+y[32]]=l,e.setChType(i,[32,40].indexOf(l)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,P),!0),e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),t(e,U)[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let m=e.chRedir(l,n,!0);t(e,K)[i]=m,i!=m&&(e.buildRchTree(),console.info(`${h}receives from CH${m+1}`))},()=>{t(e,ee)[i]=l?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{t(e,g)[s+y[7]]=l},()=>{t(e,g)[s+y[10]]=l},!1,!1,!1,()=>{t(e,g)[s+y[91]]=l},()=>{t(e,g)[s+y[93]]=l},()=>{t(e,g)[s+y[94]]=l},()=>{t(e,g)[s+y[128]]=l},()=>{},()=>{t(e,g)[s+y[74]]=l},()=>{t(e,g)[s+y[71]]=l},!1,()=>{t(e,g)[s+y[65]]=l},()=>{t(e,g)[s+y[5]]=l},()=>{}][f+u]||(()=>{}))()})}).add([127,1,54,16],(a,n,c)=>{e.switchMode("s90es");let i=a[0];a.subarray(1).forEach((s,f)=>{let l=`S90/Motif ES EQ${(f>>2)+1} `;([()=>{let u=s-64},()=>{let u=et[s]},()=>{let u=s/10},()=>{let u=s}][i+f&3]||(()=>{}))()})}),t(this,le).add([0,72,18,0,0,0,0],(a,n,c)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,n,c)=>{let i=a[0]>>5,s=a[0]&31;switch(i){case 0:{let f=a[0]>>1,h=a[1];switch(f){case 1:{a.subarray(2).forEach((l,u,m)=>{let w=u+h;switch(w){case 0:{l&&(e.setEffectType(1,60,l-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${w} - ${l}`));break}}});break}case 2:{a.subarray(2).forEach((l,u)=>{let m=u+h;switch(m){case 0:{l&&(e.setEffectType(0,55+l,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${m} - ${l}`));break}}});break}case 3:case 4:case 5:{let l=f-1;a.subarray(2).forEach((u,m)=>{let w=m+h;switch(console.debug(`SD MFX ${l-2}: ${w} - ${u}`),w){case 0:{e.setEffectTypeRaw(l,62,u),e.dispatchEvent(`efx${l>2?"delay":"insert"+(l-4)}`,e.getEffectType(l));break}}}),console.debug(`SD MFX message: %o`,a);break}default:console.debug(`Unknown SD-90 global effects message: -%o`,a)}break}case 1:{let f=e.chRedir(s,c,!0),h=a[1],l=f*v.cc;a.subarray(2).forEach((u,m)=>{let k=h+m;k<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,g)[l+y[0]]=u,u){case 104:case 105:case 106:case 107:case 120:{t(e,O)[f]||e.setChType(f,e.CH_DRUMS);break}default:t(e,O)[f]&&e.setChType(f,e.CH_MELODIC)}e.dispatchEvent("voice",{part:f})},()=>{t(e,g)[l+y[32]]=u,e.dispatchEvent("voice",{part:f})},()=>{t(e,U)[f]=u,e.dispatchEvent("voice",{part:f})},()=>{t(e,g)[l+y[7]]=u},()=>{t(e,g)[l+y[10]]=u},()=>{},()=>{},()=>{u<2&&(t(e,ee)[f]=u)},()=>{u<2&&(t(e,g)[l+y[68]]=u?127:0)},()=>{},()=>{u<2&&(t(e,g)[l+y[65]]=u?127:0)},()=>{t(e,g)[l+y[5]]=u&15<<4|t(e,g)[l+y[5]]&15},()=>{t(e,g)[l+y[5]]=u&15|(t(e,g)[l+y[5]]&240)>>4},()=>{t(e,g)[l+y[74]]=u},()=>{t(e,g)[l+y[71]]=u},()=>{t(e,g)[l+y[73]]=u},()=>{t(e,g)[l+y[72]]=u},0,0,0,0,0,0,0,()=>{t(e,g)[l+y[128]]=u},()=>{t(e,g)[l+y[93]]=u},()=>{t(e,g)[l+y[91]]=u},0,0,()=>{t(e,g)[l+y[75]]=u},()=>{t(e,g)[l+y[76]]=u},()=>{t(e,g)[l+y[77]]=u},()=>{t(e,g)[l+y[78]]=u}][k]||(()=>{}))():k<63||(k<64?(t(e,O)[f]?t(e,g)[l+y[0]]=104|u:t(e,g)[l+y[0]]=96|u,e.dispatchEvent("voice",{part:f})):console.debug(`Unknown SD-90 global CH${f+1} param setup message: -%o`,a))});break}case 2:{let f=e.chRedir(s,c,!0),h=a[1];console.debug(`Unknown SD-90 global CH${f+1} MIDI setup message: +%o`,a)}break}case 1:{let f=e.chRedir(s,n,!0),h=a[1],l=f*E.cc;a.subarray(2).forEach((u,m)=>{let w=h+m;w<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,g)[l+y[0]]=u,u){case 104:case 105:case 106:case 107:case 120:{t(e,O)[f]||e.setChType(f,e.CH_DRUMS);break}default:t(e,O)[f]&&e.setChType(f,e.CH_MELODIC)}e.dispatchEvent("voice",{part:f})},()=>{t(e,g)[l+y[32]]=u,e.dispatchEvent("voice",{part:f})},()=>{t(e,U)[f]=u,e.dispatchEvent("voice",{part:f})},()=>{t(e,g)[l+y[7]]=u},()=>{t(e,g)[l+y[10]]=u},()=>{},()=>{},()=>{u<2&&(t(e,ee)[f]=u)},()=>{u<2&&(t(e,g)[l+y[68]]=u?127:0)},()=>{},()=>{u<2&&(t(e,g)[l+y[65]]=u?127:0)},()=>{t(e,g)[l+y[5]]=u&15<<4|t(e,g)[l+y[5]]&15},()=>{t(e,g)[l+y[5]]=u&15|(t(e,g)[l+y[5]]&240)>>4},()=>{t(e,g)[l+y[74]]=u},()=>{t(e,g)[l+y[71]]=u},()=>{t(e,g)[l+y[73]]=u},()=>{t(e,g)[l+y[72]]=u},0,0,0,0,0,0,0,()=>{t(e,g)[l+y[128]]=u},()=>{t(e,g)[l+y[93]]=u},()=>{t(e,g)[l+y[91]]=u},0,0,()=>{t(e,g)[l+y[75]]=u},()=>{t(e,g)[l+y[76]]=u},()=>{t(e,g)[l+y[77]]=u},()=>{t(e,g)[l+y[78]]=u}][w]||(()=>{}))():w<63||(w<64?(t(e,O)[f]?t(e,g)[l+y[0]]=104|u:t(e,g)[l+y[0]]=96|u,e.dispatchEvent("voice",{part:f})):console.debug(`Unknown SD-90 global CH${f+1} param setup message: +%o`,a))});break}case 2:{let f=e.chRedir(s,n,!0),h=a[1];console.debug(`Unknown SD-90 global CH${f+1} MIDI setup message: %o`,a.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,a)}})}chRedir(e,r,d){if(t(this,Oe)[r])return(t(this,Oe)[r]-1)*16+e;if([2,3].indexOf(t(this,ie))>-1){if(d==1)return e;let o=0,p=!0;for(;p;)t(this,we)[e+o]==0?(t(this,we)[e+o]=r,console.debug(`Assign track ${r} to channel ${e+o+1}.`),p=!1):t(this,we)[e+o]==r?p=!1:(o+=16,o>=128&&(o=0,p=!1));return e+o}else return e}forceVoiceRefresh(){for(let e=0;e{var o;r{r&&(t(e,He)[Math.floor(d/v.redir)][r]=d%v.redir|128)}),A()&&console.debug(t(e,He))}getActive(){return t(this,ve)}getCc(e){let r=e*v.cc,d=t(this,g).subarray(r,r+v.cc);return d[y[0]]=d[y[0]]||t(this,Me),d[y[32]]=d[y[32]]||t(this,ie),d[y[0]]==pt.bank0&&(d[y[0]]=0),d}getCcCh(e,r){if(bt.indexOf(r)<0)throw new Error("CC number not accepted");return t(this,g)[v.cc*e+y[r]]}getCcAll(){let e=t(this,g).slice();for(let r=0;r0&&!o&&(t(this,g)[e*v.cc+y[0]]=Pe[d])}setChActive(e,r=0){t(this,ve)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),t(this,ve)[e]=r}getExt(e){let r=v.ext*e,d=t(this,be).subarray(r,r+v.ext),o=new Uint8Array(d.length);return o.set(d),o[1]=o[1]||t(this,kt),o}getPitch(){return t(this,$e)}getProgram(){return t(this,U)}getTexts(){return t(this,ae).slice()}getVel(e){let r=new Map,d=this;return t(d,F).forEach(function(o,p){let $=Math.floor(o/128),E=o%128;e==$&&t(d,V)[o]>0&&r.set(E,{v:t(d,V)[o],s:t(d,z)[p]})}),r}getBitmap(){return{bitmap:t(this,re,ye),expire:t(this,ue)}}getLetter(){return{text:t(this,Re),set:t(this,gt),expire:t(this,De)}}getMode(){return he[t(this,P)]}getMaster(){return{volume:t(this,B)}}getRawStrength(){let e=this;return t(this,F).forEach(function(r){let d=Math.floor(r/128);t(e,V)[r]>t(e,pe)[d]&&(t(e,pe)[d]=t(e,V)[r])}),t(this,pe)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(d,o){e[o]=Math.floor(d*t(r,g)[o*v.cc+y[7]]*t(r,g)[o*v.cc+y[11]]*t(r,B)/803288)}),e}getRpn(){return t(this,R)}getNrpn(){return t(this,tt)}getVoice(e,r,d,o){let p=e||t(this,Me),$=r,E=d||t(this,ie);p==pt.bank0&&(p=0),he[t(this,P)]=="ns5r"&&p>0&&p<56&&(E=3);let w=this.userBank.get(p,$,E,o);if(he[t(this,P)]=="mt32"&&w.name.indexOf("MT-m:")==0){let a=parseInt(w.name.slice(5)),c=a*v.cmt,n="";t(this,Ce).subarray(c,c+10).forEach(s=>{s>31&&(n+=String.fromCharCode(s))});let i=`MSB LSB PRG NME -0 127 ${$} ${n}`;this.userBank.load(i,!0),w.name=n,w.ending=" "}return(w.ending!=" "||!w.name.length)&&(w=this.baseBank.get(p,$,E,o)),w}getChVoice(e){let r=this.getVoice(t(this,g)[e*v.cc+y[0]],t(this,U)[e],t(this,g)[e*v.cc+y[32]],he[t(this,P)]);if(t(this,ge)[e])switch(t(this,P)){case T.mt32:r.ending="~",r.name="",t(this,le).subarray(14*(e-1),14*(e-1)+10).forEach(d=>{r.name+=String.fromCharCode(Math.max(d,32))}),r.name=r.name.trimRight()}return r}getRawPitch(){return t(this,$e)}getPitchShift(e){let r=this,d=e*v.rpn,o=t(r,R)[d];return t(r,L)[e*v.rpnt]||t(r,P)==T.mt32&&(o=12),t(r,$e)[e]/8192*o+(t(r,R)[d+3]-64)+((t(r,R)[d+1]<<7)+t(r,R)[d+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return t(this,te).subarray(r,r+2)}setEffectTypeRaw(e=0,r,d){let o=3*e;t(this,te)[o]=1,t(this,te)[o+1+ +r]=d}setEffectType(e=0,r,d){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,d)}getEffectSink(){return t(this,at)}setLetterDisplay(e,r,d=0,o=3200){let p=this,$;x(p,Re," ".repeat(d)),e.forEach(E=>{x(p,Re,t(p,Re)+String.fromCharCode(E>31?E:32)),E<32&&($=$||new Set,$.add(E))}),x(p,gt,Date.now()),x(p,De,Date.now()+o),$&&($=Array.from($),$.forEach((E,w,a)=>{a[w]=E.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${$.length>1?"s":""}: 0x${$.join(", 0x")}`))}setDetectionTargets(e="?",r=0){let d=this,o=-1;switch(e.replaceAll(", ",",").split(",").forEach(p=>{p=p.toLowerCase();let $=he.indexOf(Ua[p]||p);A()&&console.debug(`Mapped mode "${p}" to ID "${$}".`),$>-1&&(o=$)}),A()&&console.debug(`Set detection target to ID "${o}".`),o>0&&(t(d,G).x5=82,t(d,G).ds=T.krs),o){case T["05rw"]:{t(d,G).x5=81;break}case T.s90es:t(d,G).ds=T.s90es;case T.motif:t(d,G).ds=T.motif}}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let r=!0,d=0;for(;r&&d=v.ace&&console.warn("ACE slots are full.")}getAce(){return t(this,me)}getChAce(e,r){if(r<0||r>=v.ace)throw new RangeError("No such ACE slot");let d=t(this,me)[r];if(d){if(bt.indexOf(d)>=0)return t(this,g)[e*v.cc+y[d]];throw new Error(`Invalid ACE source: ${d}`)}else return 0}initDrums(){let e=this;t(e,j).fill(64);for(let r=0;r-1){if(t(o,P)==0||r){let E=t(o,P);o.initOnReset&&r&&(this.init(1),E=T["?"]),x(o,P,p),x(o,W,0),x(o,Me,ia[0][p]),x(o,ie,ia[1][p]);for(let a=0;a0&&t(o,g)[a*v.cc+y[0]]==Pe[E]&&(t(o,g)[a*v.cc]=Pe[p]);switch(p){case T.mt32:{Lt.forEach((a,c)=>{let n=c+1;t(o,ve)[n]||(t(o,U)[n]=a,t(o,g)[n*v.cc+y[91]]=127)});for(let a=1;a<10;a++)o.dispatchEvent("voice",{part:a});break}}let w;switch(p){case T["?"]:case T.g2:{w=[52,4,52,18,0,0,0,0];break}case T.xg:{w=[1,0,65,0,5,0,0,0];break}case T.gm:case T.gs:{w=[40,4,40,18,40,32,32,0];break}case T.sd:{w=[58,0,60,0,61,0,61,0];break}case T["05rw"]:case T.x5d:case T.ns5r:{w=[44,1,44,19,44,0,44,0];break}case T.k11:case T.sg:{w=[24,0,0,0,0,0,0,0];break}case T.mt32:{w=[40,4,0,0,0,0,0,0];break}default:w=[0,0,0,0,0,0,0,0]}for(let a=0;a14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,Et)[e.type].call(this,e);{let d=this.chRedir(e.part,e.track),o=!1;(r=t(this,yt)[d])==null||r.forEach(p=>{e.channel=p,o=!0,t(this,Et)[e.type].call(this,e)}),o||console.warn(`${na[e.type]?na[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,ae).length>100&&t(this,ae).splice(100,t(this,ae).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":{wt.context=this,d.userBank.load(await wt.read(e,r));break}}d.forceVoiceRefresh()}},P=new WeakMap,W=new WeakMap,ue=new WeakMap,Ee=new WeakMap,re=new WeakSet,ye=function(){return t(this,Ee)[t(this,W)]},pa=function(e){t(this,Ee)[t(this,W)]=e},ve=new WeakMap,K=new WeakMap,O=new WeakMap,g=new WeakMap,me=new WeakMap,U=new WeakMap,V=new WeakMap,ee=new WeakMap,F=new WeakMap,z=new WeakMap,$e=new WeakMap,pe=new WeakMap,Ue=new WeakMap,be=new WeakMap,R=new WeakMap,L=new WeakMap,tt=new WeakMap,j=new WeakMap,te=new WeakMap,at=new WeakMap,Be=new WeakMap,ge=new WeakMap,Te=new WeakMap,le=new WeakMap,rt=new WeakMap,Ce=new WeakMap,Me=new WeakMap,ie=new WeakMap,G=new WeakMap,B=new WeakMap,Ne=new WeakMap,st=new WeakMap,it=new WeakMap,Re=new WeakMap,De=new WeakMap,gt=new WeakMap,nt=new WeakMap,de=new WeakMap,N=new WeakMap,kt=new WeakMap,yt=new WeakMap,He=new WeakMap,It=new WeakMap,ae=new WeakMap,we=new WeakMap,Oe=new WeakMap,q=new WeakMap,Ge=new WeakMap,X=new WeakMap,Et=new WeakMap,xt=new WeakMap,_e=new WeakMap,Xe=new WeakMap,ne=new WeakMap,ce=new WeakMap,ke=new WeakMap,Ve=new WeakMap,Fe=new WeakMap,Ke=new WeakMap,ua);var Nt=Da(ba(),1);I();I();var vt,ga,Ea=(ga=class{constructor(b,e,r,d){S(this,vt,!1);x(this,vt,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,vt)}},vt=new WeakMap,ga),Ut=class extends Ea{constructor(b,e,r){super(!0,b,e,r)}},va=class extends Ea{constructor(b,e){super(!1,b,b,e)}},ze,ya,Bt=(ya=class extends Array{constructor(){super(...arguments);S(this,ze,-1)}resetIndex(e){x(this,ze,-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 o=0;oe);o++){if(this[o].endt(p,ze)&&(d.push($),x(p,ze,$.index))})}return d}getRange(e,r){var E;e>r&&([e,r]=[r,e]);let d=[],o=-1,p=Math.ceil(Math.sqrt(this.length)),$=!0;for(let w=0;w=e&&(o=w):o=o<0?w:o;for(;$;)((E=this[o])==null?void 0:E.end)=e&&d.push(this[o]):$=!1,o++;return d}},ze=new WeakMap,ya);var Va=0xffffffffffff,ma=function(b){let e=new Bt,r=this,d=b.timeDivision,o=120,p=new Bt,$=0,E=0;p.push(new Ut(0,Va,[120,0])),b.track.forEach(function(n){$=0,n.event.forEach(function(i){$+=i.deltaTime,i.type==255&&(i==null?void 0:i.metaType)==81&&(o=6e7/i.data,p[p.length-1]&&p.push(new Ut($,0xffffffffffff,[o,0])))})}),p.fresh(),p.forEach(function(n,i,s){i>0&&(s[i-1].end=n.start)});let w=120;p.forEach(function(n,i,s){i>0&&(n.end==n.start?s.splice(s.indexOf(n),1):w==n.data[0]&&(s[i-1].end=n.end,s.splice(s.indexOf(n),1)),w=n.data[0])});let a=0,c=120;return p.forEach(function(n){let i=n.start,s=i/c/d*60+a;c=n.data[0],a=s-i/c/d*60,n.data[1]=a}),console.debug("All tempo changes: ",p),o=120,$=0,E=0,b.track.forEach(function(n,i){$=0,E=0;let s=i+1;n.event.forEach(function(f,h){$+=f.deltaTime;let l=p.step($,!0)[0];l&&(o=l.data[0],E=l.data[1]);let u={type:f.type,data:f.data,track:s,part:0};f.type>14?u.meta=f.metaType:u.part=f.channel,e.push(new va($/o/d*60+E,u))})}),e.fresh(),self.midiEvents=e,console.debug(`Parsed a type ${b.formatType} MIDI sequence.`),e};Nt.default.customInterpreter=sa;var H=function(b,e,r){b.addEventListener(r,d=>{e.dispatchEvent(r,d.data)})},qe,Qe,ct,xe,Ye,ot,We,mt,Ae,Le,Q,je,Se,Ze,$a,Wr=($a=class extends $t{constructor(e,r=.5,d=.5){super();D(this,"device");S(this,qe,void 0);S(this,Qe,{});S(this,ct,[]);S(this,xe,"");S(this,Ye,[]);S(this,ot,[]);S(this,We,new Uint8ClampedArray(128));S(this,mt,new Uint8ClampedArray(128));S(this,Ae,.5);S(this,Le,120);S(this,Q,4);S(this,je,4);S(this,Se,0);S(this,Ze,0);D(this,"smoothingAtk",0);D(this,"smoothingDcy",0);let o=this;o.smoothingAtk=r,o.smoothingDcy=d,o.device=e,o.addEventListener("meta",function(p){var $;($=p==null?void 0:p.data)==null||$.forEach(function(E){(t(o,Ye)[E.meta]||console.debug).call(o,E.meta,E.data)})}),H(o.device,o,"mode"),H(o.device,o,"mastervolume"),H(o.device,o,"channelactive"),H(o.device,o,"channelmin"),H(o.device,o,"channelmax"),H(o.device,o,"channelreset"),H(o.device,o,"channeltoggle"),H(o.device,o,"screen"),H(o.device,o,"metacommit"),H(o.device,o,"voice"),H(o.device,o,"pitch"),H(o.device,o,"note"),H(o.device,o,"reset"),H(o.device,o,"efxreverb"),H(o.device,o,"efxchorus"),H(o.device,o,"efxdelay"),H(o.device,o,"efxinsert0"),H(o.device,o,"efxinsert1"),H(o.device,o,"efxinsert2"),H(o.device,o,"efxinsert3"),H(o.device,o,"partefxtoggle"),o.addEventListener("note",function({data:p}){t(o,ot).push(p)}),t(o,Ye)[3]=function(p,$){var E;((E=t(o,xe))==null?void 0:E.length)<1&&(x(o,xe,$),o.dispatchEvent("title",t(o,xe)))},t(o,Ye)[81]=function(p,$){let E=o.noteProgress,w=t(o,Ae)||.5;x(o,Le,6e7/$),x(o,Ae,$/1e6),x(o,Se,t(o,Se)+(E*(w/t(o,Ae))-E)),o.dispatchEvent("tempo",t(o,Le))},t(o,Ye)[88]=function(p,$){let E=o.noteProgress,w=o.noteOverall,a=o.noteBar,c=o.noteBeat,n=t(o,Q),i=t(o,je);x(o,Q,$[0]),x(o,je,1<<$[1]);let s=24*(32/$[3])/$[2];if(n!=t(o,Q)){let f=a;x(o,Se,t(o,Se)-f*(t(o,Q)-n)),c+1>=n&&(n{if(!a)return;let n=a.split("\t");if(c){if(!$)return;let i="",s="";n.forEach((f,h)=>{switch(h){case E:{i=f;break}case w:{s=f;break}}}),!t(d,Qe)[i]||r?(t(d,Qe)[i]=s,o++):self.debugMode&&console.debug(`Voice "${s}" (${i}) seems to be in conflict with (${t(d,Qe)[i]}).`),p++}else n.forEach((i,s)=>{switch(i){case"ID":{E=s,$++;break}case"Name":{w=s,$++;break}default:console.debug(`Unknown map field: ${i}`)}})}),console.debug(`Voice names: ${p} total, ${o} loaded.`),d==null||d.device.forceVoiceRefresh()}async loadEfx(e,r){let d=this,o=0,p=0,$,E,w;e.split(` -`).forEach((a,c)=>{if(a)if(c){let n=0,i;a.split("\t").forEach((s,f)=>{switch(f){case $:{n|=parseInt(s,16)<<8;break}case E:{n|=parseInt(s,16);break}case w:{i=s;break}}}),!t(d,ct)[n]||r?(t(d,ct)[n]=i,o++):self.debugMode&&console.debug(`EFX ID 0x${n.toString(16).padStart(4,"0")} (${i}) seems to be in conflict.`),p++}else a.split("\t").forEach((n,i)=>{switch(n){case"MSB":{$=i;break}case"LSB":{E=i;break}case"Name":{w=i;break}default:console.debug(`Unknown EFX field: ${n}`)}})}),console.debug(`EFX: ${p} total, ${o} 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,Qe)[e]||e}getEfx([e,r]){let d=e<<8|r;return t(this,ct)[d]||`0x${d.toString(16).padStart(4,"0")}`}get noteProgress(){return t(this,Ze)/t(this,Ae)}get noteOverall(){return this.noteProgress-t(this,Se)}get noteBar(){return Math.floor(this.noteOverall/t(this,Q))}get noteBeat(){let e=this.noteOverall%t(this,Q);return e<0&&(e+=t(this,Q)),e}getTimeSig(){return[t(this,Q),t(this,je)]}getTempo(){return t(this,Le)}sendCmd(e){this.device.runJson(e)}render(e){var k;e>t(this,Ze)&&x(this,Ze,e);let r=((k=t(this,qe))==null?void 0:k.step(e))||[],d=0,o=new Set,p={},$=[],E=this,w=[];for(E.device.getStrength().forEach((C,M)=>{t(E,mt)[M]=C}),E.device.newStrength(),r.forEach(function(C){let M=C.data,_=E.device.runJson(M);switch(_==null?void 0:_.reply){case"meta":{w.push(_);break}}_!=null&&_.reply&&delete _.reply});t(E,ot).length>0;){let C=t(E,ot).shift(),M=C.part<<7|C.note;C.state?(o.add(M),p[M]=C.velo):o.has(M)&&($.push({part:C.part,note:C.note,velo:p[M],state:E.device.NOTE_SUSTAIN}),d++)}(w==null?void 0:w.length)>0&&E.dispatchEvent("meta",w);let a=E.device.getActive(),c=[],n=E.device.getPitch(),i=E.device.getCcAll(),s=E.device.getProgram(),f=E.device.getChType(),h=[],l=E.device.getStrength();l.forEach(function(C,M,_){_[M]=Math.max(t(E,mt)[M],C);let lt=_[M]-t(E,We)[M],Ht=y.length*M;if(lt>=0){let Tt=4*.25**(i[Ht+y[73]]/64);t(E,We)[M]+=Math.ceil(lt-lt*E.smoothingAtk**Tt)}else{let Tt=4*.25**(i[Ht+y[72]]/64);t(E,We)[M]+=Math.floor(lt-lt*E.smoothingDcy**Tt)}});let u=0;return a.forEach(function(C,M){C&&(c[M]=E.device.getVel(M),h[M]=E.device.getExt(M),u+=c[M].size)}),{extraPoly:d,extraNotes:$,curPoly:u,chInUse:a,chKeyPr:c,chPitch:n,chProgr:s,chContr:i,chType:f,chExt:h,eventCount:r.length,title:t(E,xe),bitmap:E.device.getBitmap(),letter:E.device.getLetter(),texts:E.device.getTexts(),master:E.device.getMaster(),mode:E.device.getMode(),strength:t(E,We).slice(),velo:l,rpn:E.device.getRpn(),tSig:E.getTimeSig(),tempo:E.getTempo(),noteBar:E.noteBar,noteBeat:E.noteBeat,ace:E.device.getAce(),rawVelo:E.device.getStrength(),rawPitch:E.device.getRawPitch(),efxSink:E.device.getEffectSink()}}},qe=new WeakMap,Qe=new WeakMap,ct=new WeakMap,xe=new WeakMap,Ye=new WeakMap,ot=new WeakMap,We=new WeakMap,mt=new WeakMap,Ae=new WeakMap,Le=new WeakMap,Q=new WeakMap,je=new WeakMap,Se=new WeakMap,Ze=new WeakMap,$a);export{Wr as RootDisplay,y as ccToPos,se as dnToPos}; \ No newline at end of file +%o`,a)}})}chRedir(e,r,d){if(t(this,Ae)[r])return(t(this,Ae)[r]-1)*16+e;if([2,3].indexOf(t(this,oe))>-1){if(d==1)return e;let o=0,p=!0;for(;p;)t(this,we)[e+o]==0?(t(this,we)[e+o]=r,console.debug(`Assign track ${r} to channel ${e+o+1}.`),p=!1):t(this,we)[e+o]==r?p=!1:(o+=16,o>=128&&(o=0,p=!1));return e+o}else return e}forceVoiceRefresh(){for(let e=0;e{var o;r{r&&(t(e,He)[Math.floor(d/E.redir)][r]=d%E.redir|128)}),A()&&console.debug(t(e,He))}getActive(){return t(this,me)}getCc(e){let r=e*E.cc,d=t(this,g).subarray(r,r+E.cc);return d[y[0]]=d[y[0]]||t(this,Re),d[y[32]]=d[y[32]]||t(this,oe),d[y[0]]==pt.bank0&&(d[y[0]]=0),d}getCcCh(e,r){if(bt.indexOf(r)<0)throw new Error("CC number not accepted");return t(this,g)[E.cc*e+y[r]]}getCcAll(){let e=t(this,g).slice();for(let r=0;r0&&!o&&(t(this,g)[e*E.cc+y[0]]=Pe[d])}setChActive(e,r=0){t(this,me)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),t(this,me)[e]=r}getExt(e){let r=E.ext*e,d=t(this,te).subarray(r,r+E.ext),o=new Uint8Array(d.length);return o.set(d),o[1]=o[1]||t(this,xt),o}getPitch(){return t(this,$e)}getProgram(){return t(this,U)}getTexts(){return t(this,re).slice()}getVel(e){let r=new Map,d=this;return t(d,F).forEach(function(o,p){let $=Math.floor(o/128),v=o%128;e==$&&t(d,V)[o]>0&&r.set(v,{v:t(d,V)[o],s:t(d,z)[p]})}),r}getBitmap(){return{bitmap:t(this,ie,Ee),expire:t(this,ge)}}getLetter(){return{text:t(this,De),set:t(this,yt),expire:t(this,Oe)}}getMode(){return be[t(this,P)]}getMaster(){return{volume:t(this,B)}}getRawStrength(){let e=this;return t(this,F).forEach(function(r){let d=Math.floor(r/128);t(e,V)[r]>t(e,ye)[d]&&(t(e,ye)[d]=t(e,V)[r])}),t(this,ye)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(d,o){e[o]=Math.floor(d*t(r,g)[o*E.cc+y[7]]*t(r,g)[o*E.cc+y[11]]*t(r,B)/803288)}),e}getRpn(){return t(this,R)}getNrpn(){return t(this,tt)}getVoice(e,r,d,o){let p=e||t(this,Re),$=r,v=d||t(this,oe);p==pt.bank0&&(p=0),be[t(this,P)]=="ns5r"&&p>0&&p<56&&(v=3);let k=this.userBank.get(p,$,v,o);if(be[t(this,P)]=="mt32"&&k.name.indexOf("MT-m:")==0){let a=parseInt(k.name.slice(5)),n=a*E.cmt,c="";t(this,Me).subarray(n,n+10).forEach(s=>{s>31&&(c+=String.fromCharCode(s))});let i=`MSB LSB PRG NME +0 127 ${$} ${c}`;this.userBank.load(i,!0),k.name=c,k.ending=" "}return(k.ending!=" "||!k.name.length)&&(k=this.baseBank.get(p,$,v,o)),k}getChVoice(e){let r=this.getVoice(t(this,g)[e*E.cc+y[0]],t(this,U)[e],t(this,g)[e*E.cc+y[32]],be[t(this,P)]);if(t(this,fe)[e]){let d="";switch(t(this,P)){case T.mt32:{t(this,he).subarray(E.cmt*(e-1),E.cmt*(e-1)+10).forEach(o=>{d+=String.fromCharCode(Math.max(o,32))}),d=d.trimRight();break}default:{let o=E.cvn*e;t(this,gt).subarray(o,o+E.cvn).forEach(p=>{d+=String.fromCharCode(Math.max(p,32))}),d=d.trimRight()}}d.length&&(r.ending="~",r.name=d)}return r}getRawPitch(){return t(this,$e)}getPitchShift(e){let r=this,d=e*E.rpn,o=t(r,R)[d];return t(r,L)[e*E.rpnt]||t(r,P)==T.mt32&&(o=12),t(r,$e)[e]/8192*o+(t(r,R)[d+3]-64)+((t(r,R)[d+1]<<7)+t(r,R)[d+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return t(this,ae).subarray(r,r+2)}setEffectTypeRaw(e=0,r,d){let o=3*e;t(this,ae)[o]=1,t(this,ae)[o+1+ +r]=d}setEffectType(e=0,r,d){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,d)}getEffectSink(){return t(this,at)}setLetterDisplay(e,r,d=0,o=3200){let p=this,$;x(p,De," ".repeat(d)),e.forEach(v=>{x(p,De,t(p,De)+String.fromCharCode(v>31?v:32)),v<32&&($=$||new Set,$.add(v))}),x(p,yt,Date.now()),x(p,Oe,Date.now()+o),$&&($=Array.from($),$.forEach((v,k,a)=>{a[k]=v.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${$.length>1?"s":""}: 0x${$.join(", 0x")}`))}setDetectionTargets(e="?",r=0){let d=this,o=-1;switch(e.replaceAll(", ",",").split(",").forEach(p=>{p=p.toLowerCase();let $=be.indexOf(Ba[p]||p);A()&&console.debug(`Mapped mode "${p}" to ID "${$}".`),$>-1&&(o=$)}),A()&&console.debug(`Set detection target to ID "${o}".`),o>0&&(t(d,_).x5=82,t(d,_).ds=T.krs),o){case T["05rw"]:{t(d,_).x5=81;break}case T.s90es:t(d,_).ds=T.s90es;case T.motif:t(d,_).ds=T.motif}}allocateAce(e){if(!e||e<128&&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.")}releaseAce(e){let r=!0,d=0;for(;r&&d=E.ace)throw new RangeError("No such ACE slot");let d=t(this,ce)[r];if(d){if(bt.indexOf(d)>=0)return t(this,g)[e*E.cc+y[d]];throw new Error(`Invalid ACE source: ${d}`)}else return 0}initDrums(){let e=this;t(e,j).fill(64);for(let r=0;r-1){if(t(o,P)==0||r){let v=t(o,P);o.initOnReset&&r&&(this.init(1),v=T["?"]),x(o,P,p),x(o,W,0),x(o,Re,na[0][p]),x(o,oe,na[1][p]);for(let a=0;a0&&t(o,g)[a*E.cc+y[0]]==Pe[v]&&(t(o,g)[a*E.cc]=Pe[p]);switch(p){case T.mt32:{It.forEach((a,n)=>{let c=n+1;t(o,me)[c]||(t(o,U)[c]=a,t(o,g)[c*E.cc+y[91]]=127)});for(let a=1;a<10;a++)o.dispatchEvent("voice",{part:a});break}}let k;switch(p){case T["?"]:case T.g2:{k=[52,4,52,18,0,0,0,0];break}case T.xg:{k=[1,0,65,0,5,0,0,0];break}case T.gm:case T.gs:{k=[40,4,40,18,40,32,32,0];break}case T.sd:{k=[58,0,60,0,61,0,61,0];break}case T["05rw"]:case T.x5d:case T.ns5r:{k=[44,1,44,19,44,0,44,0];break}case T.k11:case T.sg:{k=[24,0,0,0,0,0,0,0];break}case T.mt32:{k=[40,4,0,0,0,0,0,0];break}default:k=[0,0,0,0,0,0,0,0]}for(let a=0;a14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,vt)[e.type].call(this,e);{let d=this.chRedir(e.part,e.track),o=!1;(r=t(this,Et)[d])==null||r.forEach(p=>{e.channel=p,o=!0,t(this,vt)[e.type].call(this,e)}),o||console.warn(`${ca[e.type]?ca[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,re).length>100&&t(this,re).splice(100,t(this,re).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":{kt.context=this,d.userBank.load(await kt.read(e,r));break}}d.forceVoiceRefresh()}},P=new WeakMap,W=new WeakMap,ge=new WeakMap,ve=new WeakMap,ie=new WeakSet,Ee=function(){return t(this,ve)[t(this,W)]},ba=function(e){t(this,ve)[t(this,W)]=e},me=new WeakMap,K=new WeakMap,O=new WeakMap,g=new WeakMap,ce=new WeakMap,U=new WeakMap,V=new WeakMap,ee=new WeakMap,F=new WeakMap,z=new WeakMap,$e=new WeakMap,ye=new WeakMap,Ue=new WeakMap,te=new WeakMap,R=new WeakMap,L=new WeakMap,tt=new WeakMap,j=new WeakMap,ae=new WeakMap,at=new WeakMap,Be=new WeakMap,fe=new WeakMap,gt=new WeakMap,Ce=new WeakMap,he=new WeakMap,rt=new WeakMap,Me=new WeakMap,Re=new WeakMap,oe=new WeakMap,_=new WeakMap,B=new WeakMap,Ne=new WeakMap,st=new WeakMap,it=new WeakMap,De=new WeakMap,Oe=new WeakMap,yt=new WeakMap,nt=new WeakMap,ue=new WeakMap,N=new WeakMap,xt=new WeakMap,Et=new WeakMap,He=new WeakMap,Pt=new WeakMap,re=new WeakMap,we=new WeakMap,Ae=new WeakMap,q=new WeakMap,_e=new WeakMap,X=new WeakMap,vt=new WeakMap,St=new WeakMap,Ge=new WeakMap,Xe=new WeakMap,se=new WeakMap,le=new WeakMap,ke=new WeakMap,Ve=new WeakMap,Fe=new WeakMap,Ke=new WeakMap,pa);var Ht=Oa(ga(),1);I();I();var mt,ya,va=(ya=class{constructor(b,e,r,d){S(this,mt,!1);x(this,mt,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,mt)}},mt=new WeakMap,ya),Bt=class extends va{constructor(b,e,r){super(!0,b,e,r)}},ma=class extends va{constructor(b,e){super(!1,b,b,e)}},ze,Ea,Nt=(Ea=class extends Array{constructor(){super(...arguments);S(this,ze,-1)}resetIndex(e){x(this,ze,-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 o=0;oe);o++){if(this[o].endt(p,ze)&&(d.push($),x(p,ze,$.index))})}return d}getRange(e,r){var v;e>r&&([e,r]=[r,e]);let d=[],o=-1,p=Math.ceil(Math.sqrt(this.length)),$=!0;for(let k=0;k=e&&(o=k):o=o<0?k:o;for(;$;)((v=this[o])==null?void 0:v.end)=e&&d.push(this[o]):$=!1,o++;return d}},ze=new WeakMap,Ea);var Fa=0xffffffffffff,$a=function(b){let e=new Nt,r=this,d=b.timeDivision,o=120,p=new Nt,$=0,v=0;p.push(new Bt(0,Fa,[120,0])),b.track.forEach(function(c){$=0,c.event.forEach(function(i){$+=i.deltaTime,i.type==255&&(i==null?void 0:i.metaType)==81&&(o=6e7/i.data,p[p.length-1]&&p.push(new Bt($,0xffffffffffff,[o,0])))})}),p.fresh(),p.forEach(function(c,i,s){i>0&&(s[i-1].end=c.start)});let k=120;p.forEach(function(c,i,s){i>0&&(c.end==c.start?s.splice(s.indexOf(c),1):k==c.data[0]&&(s[i-1].end=c.end,s.splice(s.indexOf(c),1)),k=c.data[0])});let a=0,n=120;return p.forEach(function(c){let i=c.start,s=i/n/d*60+a;n=c.data[0],a=s-i/n/d*60,c.data[1]=a}),console.debug("All tempo changes: ",p),o=120,$=0,v=0,b.track.forEach(function(c,i){$=0,v=0;let s=i+1;c.event.forEach(function(f,h){$+=f.deltaTime;let l=p.step($,!0)[0];l&&(o=l.data[0],v=l.data[1]);let u={type:f.type,data:f.data,track:s,part:0};f.type>14?u.meta=f.metaType:u.part=f.channel,e.push(new ma($/o/d*60+v,u))})}),e.fresh(),self.midiEvents=e,console.debug(`Parsed a type ${b.formatType} MIDI sequence.`),e};Ht.default.customInterpreter=ia;var H=function(b,e,r){b.addEventListener(r,d=>{e.dispatchEvent(r,d.data)})},qe,Qe,ct,xe,Ye,ot,We,$t,Le,Ie,Q,je,Se,Ze,wa,jr=(wa=class extends wt{constructor(e,r=.5,d=.5){super();D(this,"device");S(this,qe,void 0);S(this,Qe,{});S(this,ct,[]);S(this,xe,"");S(this,Ye,[]);S(this,ot,[]);S(this,We,new Uint8ClampedArray(128));S(this,$t,new Uint8ClampedArray(128));S(this,Le,.5);S(this,Ie,120);S(this,Q,4);S(this,je,4);S(this,Se,0);S(this,Ze,0);D(this,"smoothingAtk",0);D(this,"smoothingDcy",0);let o=this;o.smoothingAtk=r,o.smoothingDcy=d,o.device=e,o.addEventListener("meta",function(p){var $;($=p==null?void 0:p.data)==null||$.forEach(function(v){(t(o,Ye)[v.meta]||console.debug).call(o,v.meta,v.data)})}),H(o.device,o,"mode"),H(o.device,o,"mastervolume"),H(o.device,o,"channelactive"),H(o.device,o,"channelmin"),H(o.device,o,"channelmax"),H(o.device,o,"channelreset"),H(o.device,o,"channeltoggle"),H(o.device,o,"screen"),H(o.device,o,"metacommit"),H(o.device,o,"voice"),H(o.device,o,"pitch"),H(o.device,o,"note"),H(o.device,o,"reset"),H(o.device,o,"efxreverb"),H(o.device,o,"efxchorus"),H(o.device,o,"efxdelay"),H(o.device,o,"efxinsert0"),H(o.device,o,"efxinsert1"),H(o.device,o,"efxinsert2"),H(o.device,o,"efxinsert3"),H(o.device,o,"partefxtoggle"),o.addEventListener("note",function({data:p}){t(o,ot).push(p)}),t(o,Ye)[3]=function(p,$){var v;((v=t(o,xe))==null?void 0:v.length)<1&&(x(o,xe,$),o.dispatchEvent("title",t(o,xe)))},t(o,Ye)[81]=function(p,$){let v=o.noteProgress,k=t(o,Le)||.5;x(o,Ie,6e7/$),x(o,Le,$/1e6),x(o,Se,t(o,Se)+(v*(k/t(o,Le))-v)),o.dispatchEvent("tempo",t(o,Ie))},t(o,Ye)[88]=function(p,$){let v=o.noteProgress,k=o.noteOverall,a=o.noteBar,n=o.noteBeat,c=t(o,Q),i=t(o,je);x(o,Q,$[0]),x(o,je,1<<$[1]);let s=24*(32/$[3])/$[2];if(c!=t(o,Q)){let f=a;x(o,Se,t(o,Se)-f*(t(o,Q)-c)),n+1>=c&&(c{if(!a)return;let c=a.split("\t");if(n){if(!$)return;let i="",s="";c.forEach((f,h)=>{switch(h){case v:{i=f;break}case k:{s=f;break}}}),!t(d,Qe)[i]||r?(t(d,Qe)[i]=s,o++):self.debugMode&&console.debug(`Voice "${s}" (${i}) seems to be in conflict with (${t(d,Qe)[i]}).`),p++}else c.forEach((i,s)=>{switch(i){case"ID":{v=s,$++;break}case"Name":{k=s,$++;break}default:console.debug(`Unknown map field: ${i}`)}})}),console.debug(`Voice names: ${p} total, ${o} loaded.`),d==null||d.device.forceVoiceRefresh()}async loadEfx(e,r){let d=this,o=0,p=0,$,v,k;e.split(` +`).forEach((a,n)=>{if(a)if(n){let c=0,i;a.split("\t").forEach((s,f)=>{switch(f){case $:{c|=parseInt(s,16)<<8;break}case v:{c|=parseInt(s,16);break}case k:{i=s;break}}}),!t(d,ct)[c]||r?(t(d,ct)[c]=i,o++):self.debugMode&&console.debug(`EFX ID 0x${c.toString(16).padStart(4,"0")} (${i}) seems to be in conflict.`),p++}else a.split("\t").forEach((c,i)=>{switch(c){case"MSB":{$=i;break}case"LSB":{v=i;break}case"Name":{k=i;break}default:console.debug(`Unknown EFX field: ${c}`)}})}),console.debug(`EFX: ${p} total, ${o} 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,Qe)[e]||e}getEfx([e,r]){let d=e<<8|r;return t(this,ct)[d]||`0x${d.toString(16).padStart(4,"0")}`}get noteProgress(){return t(this,Ze)/t(this,Le)}get noteOverall(){return this.noteProgress-t(this,Se)}get noteBar(){return Math.floor(this.noteOverall/t(this,Q))}get noteBeat(){let e=this.noteOverall%t(this,Q);return e<0&&(e+=t(this,Q)),e}getTimeSig(){return[t(this,Q),t(this,je)]}getTempo(){return t(this,Ie)}sendCmd(e){this.device.runJson(e)}render(e){var w;e>t(this,Ze)&&x(this,Ze,e);let r=((w=t(this,qe))==null?void 0:w.step(e))||[],d=0,o=new Set,p={},$=[],v=this,k=[];for(v.device.getStrength().forEach((C,M)=>{t(v,$t)[M]=C}),v.device.newStrength(),r.forEach(function(C){let M=C.data,G=v.device.runJson(M);switch(G==null?void 0:G.reply){case"meta":{k.push(G);break}}G!=null&&G.reply&&delete G.reply});t(v,ot).length>0;){let C=t(v,ot).shift(),M=C.part<<7|C.note;C.state?(o.add(M),p[M]=C.velo):o.has(M)&&($.push({part:C.part,note:C.note,velo:p[M],state:v.device.NOTE_SUSTAIN}),d++)}(k==null?void 0:k.length)>0&&v.dispatchEvent("meta",k);let a=v.device.getActive(),n=[],c=v.device.getPitch(),i=v.device.getCcAll(),s=v.device.getProgram(),f=v.device.getChType(),h=[],l=v.device.getStrength();l.forEach(function(C,M,G){G[M]=Math.max(t(v,$t)[M],C);let lt=G[M]-t(v,We)[M],_t=y.length*M;if(lt>=0){let Ct=4*.25**(i[_t+y[73]]/64);t(v,We)[M]+=Math.ceil(lt-lt*v.smoothingAtk**Ct)}else{let Ct=4*.25**(i[_t+y[72]]/64);t(v,We)[M]+=Math.floor(lt-lt*v.smoothingDcy**Ct)}});let u=0;return a.forEach(function(C,M){C&&(n[M]=v.device.getVel(M),h[M]=v.device.getExt(M),u+=n[M].size)}),{extraPoly:d,extraNotes:$,curPoly:u,chInUse:a,chKeyPr:n,chPitch:c,chProgr:s,chContr:i,chType:f,chExt:h,eventCount:r.length,title:t(v,xe),bitmap:v.device.getBitmap(),letter:v.device.getLetter(),texts:v.device.getTexts(),master:v.device.getMaster(),mode:v.device.getMode(),strength:t(v,We).slice(),velo:l,rpn:v.device.getRpn(),tSig:v.getTimeSig(),tempo:v.getTempo(),noteBar:v.noteBar,noteBeat:v.noteBeat,ace:v.device.getAce(),rawVelo:v.device.getStrength(),rawPitch:v.device.getRawPitch(),efxSink:v.device.getEffectSink()}}},qe=new WeakMap,Qe=new WeakMap,ct=new WeakMap,xe=new WeakMap,Ye=new WeakMap,ot=new WeakMap,We=new WeakMap,$t=new WeakMap,Le=new WeakMap,Ie=new WeakMap,Q=new WeakMap,je=new WeakMap,Se=new WeakMap,Ze=new WeakMap,wa);export{jr as RootDisplay,y as ccToPos,ne as dnToPos}; \ No newline at end of file diff --git a/dist/xp_state.mjs b/dist/xp_state.mjs index ee19485e..c077492c 100644 --- a/dist/xp_state.mjs +++ b/dist/xp_state.mjs @@ -1,8 +1,8 @@ -var Gt=Object.defineProperty;var _t=(E,e,r)=>e in E?Gt(E,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):E[e]=r;var R=(E,e,r)=>(_t(E,typeof e!="symbol"?e+"":e,r),r),ut=(E,e,r)=>{if(!e.has(E))throw TypeError("Cannot "+r)};var a=(E,e,r)=>(ut(E,e,"read from private field"),r?r.call(E):e.get(E)),x=(E,e,r)=>{if(e.has(E))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(E):e.set(E,r)},w=(E,e,r,h)=>(ut(E,e,"write to private field"),h?h.call(E,r):e.set(E,r),r);(function(){var E=function(v,k,t){var i,c;if(self.MessageEvent)switch(v){case"message":{c=new MessageEvent(v,{data:k,ports:t==null?void 0:t.ports}),Object.defineProperty(c,"source",{value:t==null?void 0:t.source});break}default:c=new Event(v)}else c=document.createEvent("Event"),c.initEvent(v,!1,!1),t&&v=="message"&&(c.data=k,t.source&&Object.defineProperty(c,"source",{value:t.source}),(i=t.ports)!=null&&i.length&&Object.defineProperty(c,"ports",{value:t.ports}));return c};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),r=[],h={},b=function(v){var k,t=this;if((this==null?void 0:this.constructor)!=b)throw new TypeError("Illegal constructor");r.push(this),(k=h[v])!=null&&k.constructor||(h[v]=[]),h[v].push(this);var i=Math.floor(Math.random()*281474976710656),c=[],n=0,s=[],f=!0,l=!1;Object.defineProperty(this,"id",{get:function(){return i}}),Object.defineProperty(this,"name",{value:v}),this.close=function(){var d,$=r.indexOf(t);$>-1?(e.postMessage({t:"d",c:v,i}),r.splice($,1),(d=h[v])!=null&&d.constructor&&($=h[v].indexOf(t),$>-1&&h[v].splice($,1)),h[v].length||delete h[v],console.debug("[Snowy] BroadcastChannel closed."),l=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(d){if(e){if(l)throw new Error("Channel already closed");e.postMessage({t:"m",c:v,i,m:n,d}),n++,n>4294967295&&(n=0)}else s.push(d),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(f){for(e.postMessage({t:"r",c:v,i}),console.debug("[Snowy] ".concat(s.length," message(s) in cache."));s.length;){var d=s.shift();t.postMessage(d)}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(d){d.c==v?d.i!=i&&t.dispatchEvent(E("message",d.d,{source:t})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(i," receives from ").concat(v,", not ").concat(d.c,"."))};var o={};this.dispatchEvent=function(d){var $,m;if(Object.defineProperty(d,"target",{value:t}),Object.defineProperty(d,"currentTarget",{value:t}),($=o[d.type])!=null&&$.length)for(var T=o[d.type],B=0;B-1&&o[d].splice(B,1)}!((T=o[d])!=null&&T.length)&&o[d].constructor&&delete o[d]}},self.BroadcastChannel=b,y=function(){if(e){e.addEventListener("message",function(k){var t=k.data,i=!1;switch(t.t){case"k":{i=!1,e.postMessage({t:"k"});break}case"m":{var c=h[t.c];if(c!=null&&c.length)for(var n=0;n{switch(h.addEventListener("abort",()=>{y(new Error("Blob read aborted"))}),h.addEventListener("error",S=>{y(h.error||S.data||new Error("Blob read error"))}),h.addEventListener("load",()=>{b(h.result)}),r.toLowerCase()){case"arraybuffer":case"buffer":{h.readAsArrayBuffer(e);break}case"string":case"text":{h.readAsText(e);break}default:y(new Error(`Unknown target ${r}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return E(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return E(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(E,e){let r=0,h=16,b=this,y=[];for(;r-1;){let S=b.lastIndexOf(E);y.unshift(b.slice(S+E.length)),b=b.slice(0,S),S==0&&y.unshift(""),r++}return b.length&&y.unshift(b),y.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(E,e){if(e){let r=this;for(;r.length0){let h=this.pool.length,b=1<=1&&S>=0;){if(S<=0)throw new Error("TTL reached.");if(y==h)y-=b;else{let k=pt(e,this.pool[y]);switch(k){case 0:{S=0;break}case 1:{y+b<=h&&(y+=b);break}case-1:{y!=0&&(y-=b);break}default:console.warn(`Unexpected result ${k}.`)}}b=b>>1,S--}let v=!0;if(y>=this.pool.length)v=!1;else{let k=this;this.pool[y].forEach(function(t,i,c){v&&t!=e[i]&&(v=!1)}),!v&&pt(e,this.pool[y])>0&&y++}return v||r?y:-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 h=this.point(e);h>-1?e.subarray?this.pool[h].data(e.subarray(this.pool[h].length),...r):this.pool[h].data(e.slice(this.pool[h].length),...r):this.default(e,...r)}};var q,bt,yt=(bt=class{constructor(){x(this,q,{})}addEventListener(E,e){a(this,q)[E]||(a(this,q)[E]=[]),a(this,q)[E].unshift(e)}removeEventListener(E,e){if(a(this,q)[E]){let r=a(this,q)[E].indexOf(e);r>-1&&a(this,q)[E].splice(r,1),a(this,q)[E].length<1&&delete a(this,q)[E]}}dispatchEvent(E,e){var b;let r=new Event(E),h=this;r.data=e,((b=a(this,q)[E])==null?void 0:b.length)>0&&a(this,q)[E].forEach(function(y){try{y==null||y.call(h,r)}catch(S){console.error(S)}}),this[`on${E}`]&&this[`on${E}`](r)}},q=new WeakMap,bt);var Xt=["MSB","PRG","LSB","NME","ELC","DRM"],nt=function(E){let e=Math.floor(E/10),r=E%10;return`${e.toString(16)}${r}`},K,gt,ct=(gt=class{constructor(...E){x(this,K,void 0);R(this,"strictMode",!1);this.loadFiles(...E)}get(E=0,e=0,r=0,h){var d,$;let b=[E,e,r],y,S=1,v=0,k,t=Array.from(arguments);switch(h){case"xg":{switch(E){case 0:{r==126?t[2]=125:r==127&&(t[2]=0);break}case 16:{r==126&&(t[2]=0);break}case 32:{r>125&&(t[2]=0),t[2]+=4;break}case 33:case 34:case 35:case 36:{r>125&&(t[2]=0),t[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:t[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{r==126&&(t[2]=0);break}case 48:case 64:case 126:case 127:{r==126&&(t[2]=0);break}}break}case"gs":{E==0&&r<5?t[2]=0:E>125&&r<5&&r!=2&&(t[2]=E,t[0]=0);break}case"g2":case"sd":{E>>1==40?t[2]|=16:E>95&&E<100&&(t[2]|=16,e>>3==15&&(t[0]=96));break}case"sg":{E==8&&r==0&&(t[2]=5);break}case"s90es":{r<8?t[2]+=17:r<32?t[2]+=13:t[2]=(t[2]>>3)+19;break}case"motif":{r<8?t[2]+=28:r<32?t[2]+=13:t[2]=(t[2]>>3)+19;break}}let i=" ",c="M",n=0,s=0;switch(t[0]){case 0:{t[2]==127?c="MT-a":t[2]==126?c="MT-b":t[2]==7?c="GM-k":t[2]==5?c="SG-a":t[2]==4?c="SP-l":t[2]==0||h=="gs"&&t[2]<5?c="GM-a":(c="y",n=3);break}case 8:{h=="sg"?c="GM-s":c="r:";break}case 32:case 33:case 34:case 35:case 36:{h=="xg"&&(c=`${["AP","VL","PF","DX","AN"][E&7]}-${"abcdefgh"[r]}`);break}case 48:{c=`yM${(t[2]>>3).toString().padStart(2,"0")}`,n=1;break}case 56:{c="GM-b";break}case 61:case 120:{c="rDrm";break}case 62:{c="kDrm";break}case 63:{if(t[2]<17){let m=t[2];c=m<10?"kP:":"kC:",c+=m%10}else t[2]<34?c=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][t[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"[t[0]-80]}`;break}case 88:case 89:case 90:case 91:{c=`Cmb${"UABC"[t[0]-88]}`;break}case 95:{c=`${["DR","PC"][t[2]]}-d`;break}case 96:{c=t[2]==106?"AP-a":t[2]>>4==1?"SDg":"PF",t[2]>63?s=63:t[2]>>4==1&&(s=16),n=3;break}case 97:{c=t[2]>>4==1?"SDa":"VL:",n=3,t[2]>>4==1?s=16:s=112;break}case 98:{c=t[2]>>4==1?"SDb":"SG-a",n=3,s=16;break}case 99:{c=t[2]>>4==1?"SDc":"DX",t[2]>63?s=63:t[2]>>4==1&&(s=16),n=3;break}case 100:{c="AN",t[2]>63?s=63:t[2]>>4==1&&(s=16),n=3;break}case 104:case 105:case 106:case 107:{c="SDd",s=104;break}case 121:{c=`GM-${t[2]?"":"a"}`,n=3;break}case 122:{c="lDrm";break}case 126:{c="yDrS";break}case 127:{t[2]==127?c="rDrm":c="yDrm";break}default:t[0]<48?c="r:":c="M"}c.length<4&&(c+=`${[E,r,t[0],t[2]][n]-s}`.padStart(4-c.length,"0")),h=="xg"&&(E==0?t[2]<100?c=c.replace("y0","y:"):t[2]==125&&(c="y126"):E==16&&(y=`Voice${(t[2]*128+t[1]+1).toString().padStart(3,"0")}`,i=" "));let f=[t[0],t[1],t[2]];for(;!((y==null?void 0:y.length)>=0);)if(y=(d=a(this,K)[t[1]||0][(t[0]<<7)+t[2]])==null?void 0:d.name,y){let m=a(this,K)[t[1]||0][(t[0]<<7)+t[2]];S=(m==null?void 0:m.poly)||S,v=(m==null?void 0:m.type)||v,k=m==null?void 0:m.drum}else if(this.strictMode)y="",i="?";else if(t[0]==0&&t[1]==0&&t[2]==0)y="Unloaded";else if(a(this,K)[t[1]||0][t[0]<<7])t[0]==0?(t[2]=0,i="^"):t[2]<1?(t[0]=0,i="*"):(t[2]--,i="^");else if(E==48)t[0]=0,t[2]=0,i="!";else if(E==62)t[1]--,i=" ",t[1]<1&&!(y!=null&&y.length)&&(t[0]=0,i="!");else if(E<63)t[0]==0?(t[2]=0,i="^"):t[2]<1?(t[0]=0,i="*"):t[2]--;else if(E==80)y=`PrgU:${e.toString().padStart(3,"0")}`,i="!";else if(E==88)y=`CmbU:${e.toString().padStart(3,"0")}`,i="!";else if(E==121)y=`GM2Vox0${r}`,i="#";else if(E==122){if(t[1]==32?t[1]==0:t[1]%=7,y=($=a(this,K)[t[1]||0][(t[0]<<7)+t[2]])==null?void 0:$.name,y){i=" ";let m=a(this,K)[t[1]||0][(t[0]<<7)+t[2]];S=(m==null?void 0:m.poly)||S,v=(m==null?void 0:m.type)||v,k=m==null?void 0:m.drum}else y="",i="*"}else t[1]==0?(y=`${E.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${r.toString().padStart(3,"0")}`,i="!"):t[0]==0?(t[2]=0,i="^"):t[2]>0?t[2]--:t[1]>0?(t[1]=0,i="!"):(t[0]=0,i="?");let l=[t[0],t[1],t[2]];(h=="gs"||h=="ns5r")&&i=="^"&&(i=" "),E==127&&i=="^"&&(i=" "),i!=" "&&self.debugMode&&(y="");let o="??";switch(t[0]){case 0:{t[2]==0?o="GM":t[2]==5||t[2]==7?o="KG":t[2]<126?o="XG":t[2]==127&&(o="MT");break}case 32:case 33:case 35:case 36:{t[2]>4?o=["AP","VL","PF","DX","AN"][t[0]-32]:o="GS";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:{t[2]<17?o="KR":t[2]<34?o="ES":o="DS";break}case 64:case 126:{o="XG";break}case 67:case 99:{o=t[2]>>4==1?"SD":"DX";break}case 81:{o="RW";break}case 95:{o=["DR","PC"][t[2]];break}case 96:{o=t[2]==106?"AP":t[2]>>4==1?"SD":"PF";break}case 97:{o=t[2]>>4==1?"SD":"VL";break}case 98:{o=t[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=t[2]?"G2":"GM";break}case 122:{o="KG";break}case 127:{o=t[2]==127?"MT":e==0?"GM":"XG";break}default:t[0]<48&&(t[0]==16&&h=="xg"?o="XG":o="GS")}return{name:y||`${nt(E||0)} ${nt(e||0)} ${nt(r||0)}`,poly:S,type:v,drum:k,iid:f,eid:l,sid:b,ending:i,sect:c,standard:o}}async load(E,e,r="(internal)"){let h=this,b=[],y=0,S=0;E.split(` -`).forEach(function(v,k){let t=v.split("\t"),i=[];if(k==0){if(t.forEach(function(c,n){b[Xt.indexOf(c)]=n}),b.length<4){console.debug("Debugger launched.");debugger}}else{let c=0,n=0,s=0,f,l=1,o=0,d;t.forEach(async function(m,T){switch(T){case b[0]:{c=parseInt(m);break}case b[1]:{n=parseInt(m);break}case b[2]:{s=parseInt(m);break}case b[3]:{f=m;break}case b[4]:{m=parseInt(m),m<16?l=m+1:o=(m&15)+1;break}case b[5]:{d=m;break}}}),a(h,K)[n]=a(h,K)[n]||[];let $=a(h,K)[n];if(!$[c<<7|s]||e){let m={msb:c,prg:n,lsb:s,name:f,poly:l,type:o,drum:d};$[c<<7|s]=m,y++}S++}}),e||console.debug(`Map "${r}": ${S} total, ${y} loaded.`)}clearRange(E){let e=E.prg!=null?E.prg.constructor==Array?E.prg:[E.prg,E.prg]:[0,127],r=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 b=r[0];b<=r[1];b++){let y=b<<7;for(let S=h[0];S<=h[1];S++){let v=y+S;for(let k=e[0];k<=e[1];k++)delete a(this,K)[k][v]}}}init(){w(this,K,[]);for(let E=0;E<128;E++)a(this,K).push([""])}async loadFiles(...E){this.init();let e=this;E.forEach(async function(r){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".`)}})}},K=new WeakMap,gt);var Ie,Et,$t=(Et=class{constructor(){x(this,Ie,{});R(this,"context")}set(E,e){a(this,Ie)[E]=e}has(E){return!!a(this,Ie)[E]}async read(E,e){if(!this.has(E))throw new Error(`No decoder registered for "${E}"`);return await a(this,Ie)[E].call(this.context||this,e)}},Ie=new WeakMap,Et);var Vt=function(E,e){let r=!0;return e.forEach((h,b)=>{r=r&&E[b]==h}),r},mt=function(E){let e=0;return E.forEach(r=>{e*=256,e+=r}),e},Qe=new TextDecoder,at=new $t;at.set("s7e",async function(E){let e=new Uint8Array(await E.slice(0,65536).arrayBuffer()),r="MSB\tLSB\tPRG\tNME",h=[0,0,0,0],b=32,y=0,S=0,v=!0,k=[],t=0;for(;v;){let i=e.subarray(y);([()=>{Qe.decode(i.subarray(0,4))=="YSFC"?(y+=80,S=1):y++},()=>{if(Vt(i.subarray(0,4),h))k.forEach((c,n,s)=>{let f=mt(e.subarray(c.start+4,c.start+8));c.length=f}),S=2;else{let c=Qe.decode(i.subarray(0,4)),n=mt(i.subarray(4,8));k.push({type:c,start:n}),y+=8}},()=>{let c=k[t],n=e.subarray(c.start,c.start+c.length),s=32;switch(c.type){case"ENVC":{let f=b;for(;f=k.length&&(S=3,v=!1)}][S]||(()=>{v=!1}))()}return r});var qe=["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"]),Ye=["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"],Ft=[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],Ge=[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],vt=[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],wt=function(E){let e=.1,r=-.3;return E>66?(e=5,r=315):E>56?(e=1,r=47):E>46&&(e=.5,r=18.5),e*E-r},kt=function(E){return E>105?Ft[E-106]:E>100?E*1.1-100:E/10},St=",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(","),ot={};`hi*, +var It=Object.defineProperty;var Xt=(E,e,r)=>e in E?It(E,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):E[e]=r;var R=(E,e,r)=>(Xt(E,typeof e!="symbol"?e+"":e,r),r),pt=(E,e,r)=>{if(!e.has(E))throw TypeError("Cannot "+r)};var a=(E,e,r)=>(pt(E,e,"read from private field"),r?r.call(E):e.get(E)),x=(E,e,r)=>{if(e.has(E))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(E):e.set(E,r)},w=(E,e,r,h)=>(pt(E,e,"write to private field"),h?h.call(E,r):e.set(E,r),r);(function(){var E=function(m,k,t){var s,c;if(self.MessageEvent)switch(m){case"message":{c=new MessageEvent(m,{data:k,ports:t==null?void 0:t.ports}),Object.defineProperty(c,"source",{value:t==null?void 0:t.source});break}default:c=new Event(m)}else c=document.createEvent("Event"),c.initEvent(m,!1,!1),t&&m=="message"&&(c.data=k,t.source&&Object.defineProperty(c,"source",{value:t.source}),(s=t.ports)!=null&&s.length&&Object.defineProperty(c,"ports",{value:t.ports}));return c};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),r=[],h={},b=function(m){var k,t=this;if((this==null?void 0:this.constructor)!=b)throw new TypeError("Illegal constructor");r.push(this),(k=h[m])!=null&&k.constructor||(h[m]=[]),h[m].push(this);var s=Math.floor(Math.random()*281474976710656),c=[],n=0,i=[],d=!0,l=!1;Object.defineProperty(this,"id",{get:function(){return s}}),Object.defineProperty(this,"name",{value:m}),this.close=function(){var f,$=r.indexOf(t);$>-1?(e.postMessage({t:"d",c:m,i:s}),r.splice($,1),(f=h[m])!=null&&f.constructor&&($=h[m].indexOf(t),$>-1&&h[m].splice($,1)),h[m].length||delete h[m],console.debug("[Snowy] BroadcastChannel closed."),l=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(f){if(e){if(l)throw new Error("Channel already closed");e.postMessage({t:"m",c:m,i:s,m:n,d:f}),n++,n>4294967295&&(n=0)}else i.push(f),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(d){for(e.postMessage({t:"r",c:m,i:s}),console.debug("[Snowy] ".concat(i.length," message(s) in cache."));i.length;){var f=i.shift();t.postMessage(f)}d=!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(f){f.c==m?f.i!=s&&t.dispatchEvent(E("message",f.d,{source:t})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(s," receives from ").concat(m,", not ").concat(f.c,"."))};var o={};this.dispatchEvent=function(f){var $,v;if(Object.defineProperty(f,"target",{value:t}),Object.defineProperty(f,"currentTarget",{value:t}),($=o[f.type])!=null&&$.length)for(var T=o[f.type],B=0;B-1&&o[f].splice(B,1)}!((T=o[f])!=null&&T.length)&&o[f].constructor&&delete o[f]}},self.BroadcastChannel=b,g=function(){if(e){e.addEventListener("message",function(k){var t=k.data,s=!1;switch(t.t){case"k":{s=!1,e.postMessage({t:"k"});break}case"m":{var c=h[t.c];if(c!=null&&c.length)for(var n=0;n{switch(h.addEventListener("abort",()=>{g(new Error("Blob read aborted"))}),h.addEventListener("error",S=>{g(h.error||S.data||new Error("Blob read error"))}),h.addEventListener("load",()=>{b(h.result)}),r.toLowerCase()){case"arraybuffer":case"buffer":{h.readAsArrayBuffer(e);break}case"string":case"text":{h.readAsText(e);break}default:g(new Error(`Unknown target ${r}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return E(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return E(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(E,e){let r=0,h=16,b=this,g=[];for(;r-1;){let S=b.lastIndexOf(E);g.unshift(b.slice(S+E.length)),b=b.slice(0,S),S==0&&g.unshift(""),r++}return b.length&&g.unshift(b),g.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(E,e){if(e){let r=this;for(;r.length0){let h=this.pool.length,b=1<=1&&S>=0;){if(S<=0)throw new Error("TTL reached.");if(g==h)g-=b;else{let k=bt(e,this.pool[g]);switch(k){case 0:{S=0;break}case 1:{g+b<=h&&(g+=b);break}case-1:{g!=0&&(g-=b);break}default:console.warn(`Unexpected result ${k}.`)}}b=b>>1,S--}let m=!0;if(g>=this.pool.length)m=!1;else{let k=this;this.pool[g].forEach(function(t,s,c){m&&t!=e[s]&&(m=!1)}),!m&&bt(e,this.pool[g])>0&&g++}return m||r?g:-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 h=this.point(e);h>-1?e.subarray?this.pool[h].data(e.subarray(this.pool[h].length),...r):this.pool[h].data(e.slice(this.pool[h].length),...r):this.default(e,...r)}};var q,yt,gt=(yt=class{constructor(){x(this,q,{})}addEventListener(E,e){a(this,q)[E]||(a(this,q)[E]=[]),a(this,q)[E].unshift(e)}removeEventListener(E,e){if(a(this,q)[E]){let r=a(this,q)[E].indexOf(e);r>-1&&a(this,q)[E].splice(r,1),a(this,q)[E].length<1&&delete a(this,q)[E]}}dispatchEvent(E,e){var b;let r=new Event(E),h=this;r.data=e,((b=a(this,q)[E])==null?void 0:b.length)>0&&a(this,q)[E].forEach(function(g){try{g==null||g.call(h,r)}catch(S){console.error(S)}}),this[`on${E}`]&&this[`on${E}`](r)}},q=new WeakMap,yt);var Vt=["MSB","PRG","LSB","NME","ELC","DRM"],ct=function(E){let e=Math.floor(E/10),r=E%10;return`${e.toString(16)}${r}`},K,Et,ot=(Et=class{constructor(...E){x(this,K,void 0);R(this,"strictMode",!1);this.loadFiles(...E)}get(E=0,e=0,r=0,h){var f,$;let b=[E,e,r],g,S=1,m=0,k,t=Array.from(arguments);switch(h){case"xg":{switch(E){case 0:{r==126?t[2]=125:r==127&&(t[2]=0);break}case 16:{r==126&&(t[2]=0);break}case 32:{r>125&&(t[2]=0),t[2]+=4;break}case 33:case 34:case 35:case 36:{r>125&&(t[2]=0),t[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:t[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{r==126&&(t[2]=0);break}case 48:case 64:case 126:case 127:{r==126&&(t[2]=0);break}}break}case"gs":{E==0&&r<5?t[2]=0:E>125&&r<5&&r!=2&&(t[2]=E,t[0]=0);break}case"g2":case"sd":{E>>1==40?t[2]|=16:E>95&&E<100&&(t[2]|=16,e>>3==15&&(t[0]=96));break}case"sg":{E==8&&r==0&&(t[2]=5);break}case"s90es":{r<8?t[2]+=17:r<32?t[2]+=13:t[2]=(t[2]>>3)+19;break}case"motif":{r<8?t[2]+=28:r<32?t[2]+=13:t[2]=(t[2]>>3)+19;break}}let s=" ",c="M",n=0,i=0;switch(t[0]){case 0:{t[2]==127?c="MT-a":t[2]==126?c="MT-b":t[2]==7?c="GM-k":t[2]==5?c="SG-a":t[2]==4?c="SP-l":t[2]==0||h=="gs"&&t[2]<5?c="GM-a":(c="y",n=3);break}case 8:{h=="sg"?c="GM-s":c="r:";break}case 32:case 33:case 34:case 35:case 36:{h=="xg"&&(c=`${["AP","VL","PF","DX","AN"][E&7]}-${"abcdefgh"[r]}`);break}case 48:{c=`yM${(t[2]>>3).toString().padStart(2,"0")}`,n=1;break}case 56:{c="GM-b";break}case 61:case 120:{c="rDrm";break}case 62:{c="kDrm";break}case 63:{if(t[2]<17){let v=t[2];c=v<10?"kP:":"kC:",c+=v%10}else t[2]<34?c=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][t[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"[t[0]-80]}`;break}case 88:case 89:case 90:case 91:{c=`Cmb${"UABC"[t[0]-88]}`;break}case 95:{c=`${["DR","PC"][t[2]]}-d`;break}case 96:{c=t[2]==106?"AP-a":t[2]>>4==1?"SDg":"PF",t[2]>63?i=63:t[2]>>4==1&&(i=16),n=3;break}case 97:{c=t[2]>>4==1?"SDa":"VL:",n=3,t[2]>>4==1?i=16:i=112;break}case 98:{c=t[2]>>4==1?"SDb":"SG-a",n=3,i=16;break}case 99:{c=t[2]>>4==1?"SDc":"DX",t[2]>63?i=63:t[2]>>4==1&&(i=16),n=3;break}case 100:{c="AN",t[2]>63?i=63:t[2]>>4==1&&(i=16),n=3;break}case 104:case 105:case 106:case 107:{c="SDd",i=104;break}case 121:{c=`GM-${t[2]?"":"a"}`,n=3;break}case 122:{c="lDrm";break}case 126:{c="yDrS";break}case 127:{t[2]==127?c="rDrm":c="yDrm";break}default:t[0]<48?c="r:":c="M"}c.length<4&&(c+=`${[E,r,t[0],t[2]][n]-i}`.padStart(4-c.length,"0")),h=="xg"&&(E==0?t[2]<100?c=c.replace("y0","y:"):t[2]==125&&(c="y126"):E==16?(g=`Voice${((t[2]<<7)+t[1]+1).toString().padStart(3,"0")}`,s=" "):E==35&&r>>1==2&&(g=`DXCH_${(((t[2]&1)<<7)+e+1).toString().padStart(3,"0")}`,s=" "));let d=[t[0],t[1],t[2]];for(;!((g==null?void 0:g.length)>=0);)if(g=(f=a(this,K)[t[1]||0][(t[0]<<7)+t[2]])==null?void 0:f.name,g){let v=a(this,K)[t[1]||0][(t[0]<<7)+t[2]];S=(v==null?void 0:v.poly)||S,m=(v==null?void 0:v.type)||m,k=v==null?void 0:v.drum}else if(this.strictMode)g="",s="?";else if(t[0]==0&&t[1]==0&&t[2]==0)g="Unloaded";else if(a(this,K)[t[1]||0][t[0]<<7])t[0]==0?(t[2]=0,s="^"):t[2]<1?(t[0]=0,s="*"):(t[2]--,s="^");else if(E==48)t[0]=0,t[2]=0,s="!";else if(E==62)t[1]--,s=" ",t[1]<1&&!(g!=null&&g.length)&&(t[0]=0,s="!");else if(E<63)t[0]==0?(t[2]=0,s="^"):t[2]<1?(t[0]=0,s="*"):t[2]--;else if(E==80)g=`PrgU:${e.toString().padStart(3,"0")}`,s="!";else if(E==88)g=`CmbU:${e.toString().padStart(3,"0")}`,s="!";else if(E==121)g=`GM2Vox0${r}`,s="#";else if(E==122){if(t[1]==32?t[1]==0:t[1]%=7,g=($=a(this,K)[t[1]||0][(t[0]<<7)+t[2]])==null?void 0:$.name,g){s=" ";let v=a(this,K)[t[1]||0][(t[0]<<7)+t[2]];S=(v==null?void 0:v.poly)||S,m=(v==null?void 0:v.type)||m,k=v==null?void 0:v.drum}else g="",s="*";}else t[1]==0?(g=`${E.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${r.toString().padStart(3,"0")}`,s="!"):t[0]==0?(t[2]=0,s="^"):t[2]>0?t[2]--:t[1]>0?(t[1]=0,s="!"):(t[0]=0,s="?");let l=[t[0],t[1],t[2]];(h=="gs"||h=="ns5r")&&s=="^"&&(s=" "),E==127&&s=="^"&&(s=" "),s!=" "&&self.debugMode&&(g="");let o="??";switch(t[0]){case 0:{t[2]==0?o="GM":t[2]==5||t[2]==7?o="KG":t[2]<126?o="XG":t[2]==127&&(o="MT");break}case 32:case 33:case 35:case 36:{t[2]>4?o=["AP","VL","PF","DX","AN"][t[0]-32]:o="GS";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:{t[2]<17?o="KR":t[2]<34?o="ES":o="DS";break}case 64:case 126:{o="XG";break}case 67:case 99:{o=t[2]>>4==1?"SD":"DX";break}case 81:{o="RW";break}case 95:{o=["DR","PC"][t[2]];break}case 96:{o=t[2]==106?"AP":t[2]>>4==1?"SD":"PF";break}case 97:{o=t[2]>>4==1?"SD":"VL";break}case 98:{o=t[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=t[2]?"G2":"GM";break}case 122:{o="KG";break}case 127:{o=t[2]==127?"MT":e==0?"GM":"XG";break}default:t[0]<48&&(t[0]==16&&h=="xg"?o="XG":o="GS")}return{name:g||`${ct(E||0)} ${ct(e||0)} ${ct(r||0)}`,poly:S,type:m,drum:k,iid:d,eid:l,sid:b,ending:s,sect:c,standard:o}}async load(E,e,r="(internal)"){let h=this,b=[],g=0,S=0;E.split(` +`).forEach(function(m,k){let t=m.split("\t"),s=[];if(k==0){if(t.forEach(function(c,n){b[Vt.indexOf(c)]=n}),b.length<4){console.debug("Debugger launched.");debugger}}else{let c=0,n=0,i=0,d,l=1,o=0,f;t.forEach(async function(v,T){switch(T){case b[0]:{c=parseInt(v);break}case b[1]:{n=parseInt(v);break}case b[2]:{i=parseInt(v);break}case b[3]:{d=v;break}case b[4]:{v=parseInt(v),v<16?l=v+1:o=(v&15)+1;break}case b[5]:{f=v;break}}}),a(h,K)[n]=a(h,K)[n]||[];let $=a(h,K)[n];if(!$[c<<7|i]||e){let v={msb:c,prg:n,lsb:i,name:d,poly:l,type:o,drum:f};$[c<<7|i]=v,g++}S++}}),e||console.debug(`Map "${r}": ${S} total, ${g} loaded.`)}clearRange(E){let e=E.prg!=null?E.prg.constructor==Array?E.prg:[E.prg,E.prg]:[0,127],r=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 b=r[0];b<=r[1];b++){let g=b<<7;for(let S=h[0];S<=h[1];S++){let m=g+S;for(let k=e[0];k<=e[1];k++)delete a(this,K)[k][m]}}}init(){w(this,K,[]);for(let E=0;E<128;E++)a(this,K).push([""])}async loadFiles(...E){this.init();let e=this;E.forEach(async function(r){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".`)}})}},K=new WeakMap,Et);var _e,$t,vt=($t=class{constructor(){x(this,_e,{});R(this,"context")}set(E,e){a(this,_e)[E]=e}has(E){return!!a(this,_e)[E]}async read(E,e){if(!this.has(E))throw new Error(`No decoder registered for "${E}"`);return await a(this,_e)[E].call(this.context||this,e)}},_e=new WeakMap,$t);var Ft=function(E,e){let r=!0;return e.forEach((h,b)=>{r=r&&E[b]==h}),r},mt=function(E){let e=0;return E.forEach(r=>{e*=256,e+=r}),e},Qe=new TextDecoder,rt=new vt;rt.set("s7e",async function(E){let e=new Uint8Array(await E.slice(0,65536).arrayBuffer()),r="MSB\tLSB\tPRG\tNME",h=[0,0,0,0],b=32,g=0,S=0,m=!0,k=[],t=0;for(;m;){let s=e.subarray(g);([()=>{Qe.decode(s.subarray(0,4))=="YSFC"?(g+=80,S=1):g++},()=>{if(Ft(s.subarray(0,4),h))k.forEach((c,n,i)=>{let d=mt(e.subarray(c.start+4,c.start+8));c.length=d}),S=2;else{let c=Qe.decode(s.subarray(0,4)),n=mt(s.subarray(4,8));k.push({type:c,start:n}),g+=8}},()=>{let c=k[t],n=e.subarray(c.start,c.start+c.length),i=32;switch(c.type){case"ENVC":{let d=b;for(;d=k.length&&(S=3,m=!1)}][S]||(()=>{m=!1}))()}return r});var qe=["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"]),Ye=["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"],Kt=[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],Ge=[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],wt=[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],kt=function(E){let e=.1,r=-.3;return E>66?(e=5,r=315):E>56?(e=1,r=47):E>46&&(e=.5,r=18.5),e*E-r},St=function(E){return E>105?Kt[E-106]:E>100?E*1.1-100:E/10},xt=",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(","),lt={};`hi*, ka,か ki,き ku,く @@ -139,7 +139,7 @@ o,お ~, ^, _,`.split(` -`).forEach(E=>{let e=E.split(",");ot[e[0]]=e[1]});var xt=function(E){let e=E;E[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 ot)e=e.replaceAll(h,ot[h]);e.indexOf("\u3093")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},Ct=function(E){return E?E<96?`cc${E}`:["aftertouch","velocity","pitch bend"][E-96]:"off"};var lt=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],Mt=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],Tt=["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 Kt={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"},zt={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]]},dt=function(E){return Kt[(E[0]-32<<8)+E[1]]||`0x${E[0].toString(16).padStart(2,"0")}${E[1].toString(16).padStart(2,"0")}`},Rt=function(E,e,r){let h=(E[0]-32<<16)+(E[1]<<8)+e,b=zt[h]||{},y=b[0];if(y!=null&&y.length)return y+=`: ${(b[1]||function(){})(r)||r}`,y},ft=[68,48,95,78,41,3,110,122,0];var Y=function(E=64){return Math.round(2e3*Math.log10(E/64))/100};var Me=function(E){let e=0;return E.forEach(r=>{e+=r,e=e&127}),~e+1&127},ce=function(E,e){let r=0,h=0;for(let b=0;b>y&1)<<7,v=E[b];v+=S,b%8!=0?(e(v,r,E),r++):h=E[b]}};var We=function(E){let e=Math.floor(E*14.2);return e<128?e:0};var oe=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],Qt={gm2:"g2","mt-32":"mt32","c/m":"mt32",ag10:"05rw","ag-10":"05rw","05r/w":"05rw",x5:"05rw",x5dr:"x5d",gmega:"k11","kross 2":"krs","motif es":"motif","s90 es":"s90es"},qt=["melodic","drum","menu"],Dt=[[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]],Te=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],Yt=[0,3,81,84,88],Ot={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Lt={0:0,1:1,2:3,5:4},At={0:0,1:1,2:2,5:3},Ut=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Pt=[36,37,48,49,52,53],it=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Nt={26:127,29:0,30:0,31:0,52:12,53:54},Ze=[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,14,15,20,21,26,28,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157],Wt=[2,12,13,14,15,16,17,18,19,20,21,136,130,131,132,133,134,135,137,138,139],Jt=[33,99,100,32,102,8,9,10],Bt=[0,16,25,40,32,64,26,48],C={};oe.forEach((E,e)=>{C[E]=e});var p={length:Ze.length};Ze.forEach((E,e)=>{p[E]=e});var se={length:it.length};it.forEach((E,e)=>{se[E]=e});var Zt={};qt.forEach((E,e)=>{Zt[E]=e});var O=function(){return!!self.Bun||self.debugMode||!1},jt=function(E){let e=[],r=0;return E==null||E.forEach(function(h,b){h==247?e.push(E.subarray(r,b)):h==240&&(r=b+1)}),e.length||e.push(E.subarray(0)),O()&&console.debug(e),e};var g={ch:128,cc:Ze.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:it.length,dnc:128,ext:2,efx:7,redir:32},Je={bank0:128},A,z,le,pe,j,ue,It,be,X,D,u,ye,U,G,W,_,V,ge,de,Re,fe,M,L,_e,Q,J,Xe,De,he,me,ie,Ve,ve,we,ee,H,P,Oe,Fe,Ke,ke,Se,je,ze,ne,N,rt,et,Le,ht,Z,Ee,xe,F,Ae,I,tt,st,Ue,Pe,te,ae,$e,Ne,Be,He,Ht,Ia=(Ht=class extends yt{constructor(){super();x(this,j);R(this,"NOTE_IDLE",0);R(this,"NOTE_ATTACK",1);R(this,"NOTE_DECAY",2);R(this,"NOTE_SUSTAIN",3);R(this,"NOTE_HELD",4);R(this,"NOTE_RELEASE",5);R(this,"NOTE_SOSTENUTO_ATTACK",8);R(this,"NOTE_SOSTENUTO_DECAY",9);R(this,"NOTE_SOSTENUTO_SUSTAIN",10);R(this,"NOTE_SOSTENUTO_HELD",11);R(this,"CH_MELODIC",0);R(this,"CH_DRUMS",1);R(this,"CH_DRUM1",2);R(this,"CH_DRUM2",3);R(this,"CH_DRUM3",4);R(this,"CH_DRUM4",5);R(this,"CH_DRUM5",6);R(this,"CH_DRUM6",7);R(this,"CH_DRUM7",8);R(this,"CH_DRUM8",9);R(this,"EXT_NONE",0);R(this,"EXT_VL",1);R(this,"VLBC_BRTHEXPR",1);R(this,"VLBC_VELOINIT",2);R(this,"VLBC_VELOALL",3);x(this,A,0);x(this,z,0);x(this,le,0);x(this,pe,new Array(11));x(this,be,new Uint8Array(g.ch));x(this,X,new Uint8Array(g.ch));x(this,D,new Uint8Array(g.ch));x(this,u,new Uint8Array(g.ch*g.cc));x(this,ye,new Uint8Array(g.ace));x(this,U,new Uint8Array(g.ch));x(this,G,new Uint8Array(g.ch*g.nn));x(this,W,new Uint8Array(g.ch));x(this,_,new Uint16Array(g.pl));x(this,V,new Uint8Array(g.pl));x(this,ge,new Int16Array(g.ch));x(this,de,new Uint8Array(g.ch));x(this,Re,0);x(this,fe,new Uint8Array(g.ch*g.ext));x(this,M,new Uint8Array(g.ch*g.rpn));x(this,L,new Uint8Array(g.ch*g.rpnt));x(this,_e,new Int8Array(g.ch*Pt.length));x(this,Q,new Uint8Array(g.drm*g.dpn*g.dnc));x(this,J,new Uint8Array(g.efx*3));x(this,Xe,new Uint8Array(g.ch));x(this,De,new Uint8Array(g.ch*g.redir));x(this,he,new Uint8Array(g.ch));x(this,me,new Uint8Array(128));x(this,ie,new Uint8Array(g.cmt*8));x(this,Ve,new Uint8Array(1024));x(this,ve,new Uint8Array(g.cmt*64));x(this,we,0);x(this,ee,0);x(this,H,void 0);x(this,P,100);x(this,Oe,0);x(this,Fe,500);x(this,Ke,0);x(this,ke,"");x(this,Se,0);x(this,je,0);x(this,ze,0);x(this,ne,!0);x(this,N,!1);x(this,rt,1);x(this,et,void 0);x(this,Le,new Array(g.ch));x(this,ht,new Uint8Array(2));x(this,Z,[]);x(this,Ee,new Uint8Array(g.ch));x(this,xe,new Uint8Array(g.tr));R(this,"baseBank",new ct("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","krs","s90es"));R(this,"userBank",new ct("gm"));R(this,"initOnReset",!1);R(this,"aiEfxName","");x(this,F,[]);x(this,Ae,void 0);x(this,I,{nOff:(e,r)=>{let h=e*128+r,b=a(this,_).lastIndexOf(h);if(b>-1)if(a(this,u)[g.cc*e+p[64]]>63)a(this,V)[b]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:a(this,G)[h],state:this.NOTE_HELD});else if(a(this,u)[g.cc*e+p[66]]>63&&a(this,V)[b]==this.NOTE_SOSTENUTO_SUSTAIN)a(this,V)[b]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:a(this,G)[h],state:this.NOTE_SOSTENUTO_HELD});else{a(this,_)[b]=0,a(this,G)[h]=0,a(this,V)[b]=this.NOTE_IDLE;let y=this.getExt(e)[1];(y==this.VLBC_VELOINIT||y==this.VLBC_VELOALL)&&(a(this,u)[g.cc*e+p[129]]=0),this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})}},nOn:(e,r,h)=>{let b=e*128+r,y=0;for(a(this,W)[e]&&a(this,I).ano(e);a(this,V)[y]>0&&a(this,_)[y]!=b;)y++;if(y{},cAt:(e,r)=>{},hoOf:e=>{a(this,V).forEach((r,h)=>{if(r==this.NOTE_HELD){let b=a(this,_)[h],y=b>>7;e==y&&(a(this,V)[h]=this.NOTE_IDLE,a(this,_)[h]=0,a(this,G)[b]=0,this.dispatchEvent("note",{part:e,note:b&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{a(this,V).forEach((r,h)=>{let b;switch(r){case this.NOTE_ATTACK:{b=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{b=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{b=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(b){a(this,V)[h]=b;let y=a(this,_)[h];this.dispatchEvent("note",{part:e,note:y&127,velo:a(this,G)[y],state:b})}})},soOf:e=>{a(this,V).forEach((r,h)=>{if(r==this.NOTE_SOSTENUTO_HELD){let b=a(this,_)[h],y=b>>7;e==y&&(a(this,V)[h]=this.NOTE_IDLE,a(this,_)[h]=0,a(this,G)[b]=0,this.dispatchEvent("note",{part:e,note:b&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{a(this,_).forEach((r,h,b)=>{let y=r>>7,S=r&127;r==0&&a(this,G)[0]==0||y==e&&a(this,I).nOff(y,S)})}});x(this,tt,{8:function(e){let r=e.channel,h=e.data[0];a(this,I).nOff(r,h)},9:function(e){let r=e.channel;this.setChActive(r,1);let h=e.data[0],b=e.data[1];b>0?a(this,I).nOn(r,h,b):a(this,I).nOff(r,h)},10:function(e){let r=e.channel,h=r*128+e.data[0];a(this,_).indexOf(h)>-1&&(a(this,G)[h]=data[1],this.getExt(r)[1]==this.VLBC_VELOALL&&(a(this,u)[g.cc*r+p[129]]=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,h=a(this,Le)[r],b=h[e.data[0]];b&&(e.data[0]=b),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(a(this,A)){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 y=r*g.cc,S=r*g.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{a(this,I).ano(r),a(this,ge)[r]=0,a(this,u)[y+p[1]]=0,a(this,u)[y+p[5]]=0,a(this,u)[y+p[64]]=0,a(this,u)[y+p[65]]=0,a(this,u)[y+p[66]]=0,a(this,u)[y+p[67]]=0,a(this,u)[y+p[11]]=127,a(this,u)[y+p[101]]=127,a(this,u)[y+p[100]]=127,a(this,u)[y+p[99]]=127,a(this,u)[y+p[98]]=127;return}case 123:{a(this,I).ano(r);return}case 124:{a(this,I).ano(r);return}case 125:{a(this,I).ano(r);return}case 126:{a(this,W)[r]=1,a(this,I).ano(r);return}case 127:{a(this,W)[r]=0,a(this,I).ano(r);return}}if(p[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Wt.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(O()&&console.debug(`${oe[a(this,A)]}, CH${r+1}: ${e.data[1]}`),a(this,A)==0?e.data[1]<48?(a(this,D)[r]>0&&(e.data[1]=a(this,u)[y],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(a(this,H).x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(this.modeIdx[a(this,H).ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):a(this,A)==C.gs?e.data[1]<56&&a(this,D)[r]>0&&(e.data[1]=a(this,u)[y],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):a(this,A)==C.gm&&(e.data[1]<48?a(this,D)[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)),a(this,A)){case C.xg:{[79,95,126,127].indexOf(e.data[1])>-1?a(this,D)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):a(this,D)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?a(this,fe)[S]=this.EXT_VL:a(this,fe)[S]=this.EXT_NONE;break}case C["05rw"]:case C.x5d:case C.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?a(this,D)[r]==this.CH_MELODIC&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):[80,81,82,83].indexOf(e.data[1])>-1||a(this,D)[r]!=this.CH_MELODIC&&(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?a(this,D)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):a(this,D)[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?a(this,D)[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):a(this,D)[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 2:{this.getExt(r)[1]==this.VLBC_BRTHEXPR&&(a(this,u)[y+p[129]]=e.data[1]);break}case 6:{if(a(this,Re)){[C.xg,C.gs,C.ns5r].indexOf(a(this,A))<0&&console.warn(`NRPN commits are not available under "${oe[a(this,A)]}" mode, even when they are supported in Octavia.`);let v=a(this,u)[y+p[99]],k=a(this,u)[y+p[98]];if(v==1){let t=Jt.indexOf(k);if(t>-1)a(this,u)[y+p[71+t]]=e.data[1],O()&&console.debug(`Redirected NRPN 1 ${k} to cc${71+t}.`),this.dispatchEvent("cc",{part:r,cc:71+t,data:e.data[1]});else{let i=Pt.indexOf(k);i>-1?a(this,_e)[r*10+i]=e.data[1]-64:console.warn(`NRPN 0x01${k.toString(16).padStart(2,"0")} is not supported.`),O()&&console.debug(`CH${r+1} voice NRPN ${k} commit`)}}else{if(it.indexOf(v)<0){let i=`NRPN 0x${v.toString(16).padStart(2,"0")}${k.toString(16).padStart(2,"0")} `;v==127?console.warn(`${i}is not necessary. Consider removing it.`):console.warn(`${i}is not supported.`)}else{let i=a(this,D)[r]-2;i<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${Ye[a(this,D)[r]]}.`):a(this,Q)[(i*g.dpn+se[v])*g.dnc+k]=e.data[1]}O()&&console.debug(`CH${r+1} (${Ye[a(this,D)[r]]}) drum NRPN ${v} commit`)}}else{let v=Lt[a(this,u)[y+p[100]]],k=At[a(this,u)[y+p[100]]];a(this,u)[y+p[101]]==0&&v!=null&&(O()&&console.debug(`CH${r+1} RPN 0 ${a(this,u)[y+p[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Ut[v][0]),Ut[v][1]),a(this,M)[r*g.rpn+v]=e.data[1],a(this,L)[r*g.rpnt+k]=1)}break}case 32:{switch(O()&&console.debug(`${oe[a(this,A)]}, CH${r+1} LSB: ${e.data[1]}`),a(this,A)){case C.s90es:case C.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,a(this,A),!0);break}}this.dispatchEvent("voice",{part:r});break}case 38:{if(!a(this,Re)){let v=Lt[a(this,u)[y+100]],k=At[a(this,u)[y+100]];a(this,u)[y+101]==0&&v!=null&&(a(this,M)[r*g.rpn+v+1]=e.data[1],a(this,L)[r*g.rpnt+k]=1)}break}case 64:{e.data[1]<64&&a(this,I).hoOf(r);break}case 66:{e.data[1]>>6?a(this,I).soOn(r):a(this,I).soOf(r);break}case 98:case 99:{w(this,Re,1);break}case 100:case 101:{w(this,Re,0);break}}a(this,u)[y+p[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(a(this,A)){case C.s90es:case C.motif:{e.data&&this.setChActive(r,1);break}default:this.setChActive(r,1)}a(this,U)[r]=e.data,a(this,he)[r]=0,O()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),this.dispatchEvent("voice",{part:r})},13:function(e){let r=this,h=e.channel;a(this,_).forEach(function(b){let y=b>>7;h==y&&(a(r,G)[b]=e.data,r.dispatchEvent("note",{part:h,note:b&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;a(this,ge)[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){jt(e.data).forEach(r=>{let h=r[0],b=r[1];(a(this,st)[h]||function(){console.debug(`Unknown manufacturer ${h}.`)})(b,r.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(a(this,F)[e.meta]||function(h,b,y){}).call(this,e.data,e.track,e.meta),e.meta!=32&&w(this,Oe,0);let r=Yt.indexOf(e.meta)>-1;if(O()&&console.debug(e),r)return e.reply="meta",e}});x(this,st,{64:(e,r,h)=>{a(this,Ne).run(r,h,e)},65:(e,r,h)=>{if(r[0]<16){if(r[1]==72){let b=r[r.length-1],y=Me(r.subarray(3,r.length-1));b==y?a(this,ae).run(r.subarray(0,r.length-1),h,e):console.warn(`Bad SD checksum ${b}. Should be ${y}.`)}else a(this,ae).run(r,h,e)}else{let b=r[r.length-1],y=Me(r.subarray(2,r.length-1));b==y?a(this,ae).run(r.subarray(0,r.length-1),h,e):console.warn(`Bad GS checksum ${b}. Should be ${y}.`)}},66:(e,r,h)=>{a(this,$e).run(r,h,e)},67:(e,r,h)=>{a(this,te).run(r,h,e)},68:(e,r,h)=>{a(this,He).run(r,h,e)},71:(e,r,h)=>{a(this,Be).run(r,h,e)},126:(e,r,h)=>{a(this,Ue).run(r,h,e)},127:(e,r,h)=>{this.switchMode("gm"),a(this,Pe).run(r,h,e)}});x(this,Ue,void 0);x(this,Pe,void 0);x(this,te,void 0);x(this,ae,void 0);x(this,$e,void 0);x(this,Ne,void 0);x(this,Be,void 0);x(this,He,void 0);let e=this;w(e,j,new Uint8Array(256),It),a(e,pe)[10]=new Uint8Array(512),w(e,Ae,new re),w(e,H,{x5:82,ds:C.krs}),e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME +`).forEach(E=>{let e=E.split(",");lt[e[0]]=e[1]});var Ct=function(E){let e=E;E[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 lt)e=e.replaceAll(h,lt[h]);e.indexOf("\u3093")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},Mt=function(E){return E?E<96?`cc${E}`:["aftertouch","velocity","pitch bend"][E-96]:"off"};var ft=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],Tt=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],Rt=["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 zt={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"},Qt={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]]},dt=function(E){return zt[(E[0]-32<<8)+E[1]]||`0x${E[0].toString(16).padStart(2,"0")}${E[1].toString(16).padStart(2,"0")}`},Dt=function(E,e,r){let h=(E[0]-32<<16)+(E[1]<<8)+e,b=Qt[h]||{},g=b[0];if(g!=null&&g.length)return g+=`: ${(b[1]||function(){})(r)||r}`,g},ht=[68,48,95,78,41,3,110,122,0];var Y=function(E=64){return Math.round(2e3*Math.log10(E/64))/100};var ve=function(E){let e=0;return E.forEach(r=>{e+=r,e=e&127}),~e+1&127},fe=function(E,e){let r=0,h=0;for(let b=0;b>g&1)<<7,m=E[b];m+=S,b%8!=0?(e(m,r,E),r++):h=E[b]}};var We=function(E){let e=Math.floor(E*14.2);return e<128?e:0};var de=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],qt={gm2:"g2","mt-32":"mt32","c/m":"mt32",ag10:"05rw","ag-10":"05rw","05r/w":"05rw",x5:"05rw",x5dr:"x5d",gmega:"k11","kross 2":"krs","motif es":"motif","s90 es":"s90es"},Yt=["melodic","drum","menu"],Ot=[[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]],Te=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],Wt=[0,3,81,84,88],At={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Lt={0:0,1:1,2:3,5:4},Ut={0:0,1:1,2:2,5:3},Pt=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Nt=[36,37,48,49,52,53],nt=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Bt={26:127,29:0,30:0,31:0,52:12,53:54},Ze=[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,14,15,20,21,26,28,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157],Jt=[2,12,13,14,15,16,17,18,19,20,21,136,130,131,132,133,134,135,137,138,139,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157],Zt=[33,99,100,32,102,8,9,10],Ht=[0,16,25,40,32,64,26,48],C={};de.forEach((E,e)=>{C[E]=e});var p={length:Ze.length};Ze.forEach((E,e)=>{p[E]=e});var ne={length:nt.length};nt.forEach((E,e)=>{ne[E]=e});var jt={};Yt.forEach((E,e)=>{jt[E]=e});var O=function(){return!!self.Bun||self.debugMode||!1},ea=function(E){let e=[],r=0;return E==null||E.forEach(function(h,b){h==247?e.push(E.subarray(r,b)):h==240&&(r=b+1)}),e.length||e.push(E.subarray(0)),O()&&console.debug(e),e};var y={ch:128,cc:Ze.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:nt.length,dnc:128,ext:2,efx:7,cvn:12,redir:32},Je={bank0:128},L,z,he,be,te,pe,Gt,ye,X,D,u,ae,U,G,W,I,V,ge,ue,Re,J,M,A,Ie,Q,Z,Xe,De,ce,je,me,oe,Ve,we,ke,re,H,P,Oe,Fe,Ke,Se,xe,et,ze,le,N,st,tt,Ae,ut,j,Ee,Ce,F,Le,_,at,it,Ue,Pe,ee,se,$e,Ne,Be,He,_t,Ga=(_t=class extends gt{constructor(){super();x(this,te);R(this,"NOTE_IDLE",0);R(this,"NOTE_ATTACK",1);R(this,"NOTE_DECAY",2);R(this,"NOTE_SUSTAIN",3);R(this,"NOTE_HELD",4);R(this,"NOTE_RELEASE",5);R(this,"NOTE_SOSTENUTO_ATTACK",8);R(this,"NOTE_SOSTENUTO_DECAY",9);R(this,"NOTE_SOSTENUTO_SUSTAIN",10);R(this,"NOTE_SOSTENUTO_HELD",11);R(this,"CH_MELODIC",0);R(this,"CH_DRUMS",1);R(this,"CH_DRUM1",2);R(this,"CH_DRUM2",3);R(this,"CH_DRUM3",4);R(this,"CH_DRUM4",5);R(this,"CH_DRUM5",6);R(this,"CH_DRUM6",7);R(this,"CH_DRUM7",8);R(this,"CH_DRUM8",9);R(this,"EXT_NONE",0);R(this,"EXT_VL",1);R(this,"EXT_DX",3);R(this,"VLBC_BRTHEXPR",1);R(this,"VLBC_VELOINIT",2);R(this,"VLBC_VELOALL",3);x(this,L,0);x(this,z,0);x(this,he,0);x(this,be,new Array(11));x(this,ye,new Uint8Array(y.ch));x(this,X,new Uint8Array(y.ch));x(this,D,new Uint8Array(y.ch));x(this,u,new Uint8Array(y.ch*y.cc));x(this,ae,new Uint8Array(y.ace));x(this,U,new Uint8Array(y.ch));x(this,G,new Uint8Array(y.ch*y.nn));x(this,W,new Uint8Array(y.ch));x(this,I,new Uint16Array(y.pl));x(this,V,new Uint8Array(y.pl));x(this,ge,new Int16Array(y.ch));x(this,ue,new Uint8Array(y.ch));x(this,Re,0);x(this,J,new Uint8Array(y.ch*y.ext));x(this,M,new Uint8Array(y.ch*y.rpn));x(this,A,new Uint8Array(y.ch*y.rpnt));x(this,Ie,new Int8Array(y.ch*Nt.length));x(this,Q,new Uint8Array(y.drm*y.dpn*y.dnc));x(this,Z,new Uint8Array(y.efx*3));x(this,Xe,new Uint8Array(y.ch));x(this,De,new Uint8Array(y.ch*y.redir));x(this,ce,new Uint8Array(y.ch));x(this,je,new Uint8Array(y.ch*y.cvn));x(this,me,new Uint8Array(128));x(this,oe,new Uint8Array(y.cmt*8));x(this,Ve,new Uint8Array(1024));x(this,we,new Uint8Array(y.cmt*64));x(this,ke,0);x(this,re,0);x(this,H,void 0);x(this,P,100);x(this,Oe,0);x(this,Fe,500);x(this,Ke,0);x(this,Se,"");x(this,xe,0);x(this,et,0);x(this,ze,0);x(this,le,!0);x(this,N,!1);x(this,st,1);x(this,tt,void 0);x(this,Ae,new Array(y.ch));x(this,ut,new Uint8Array(2));x(this,j,[]);x(this,Ee,new Uint8Array(y.ch));x(this,Ce,new Uint8Array(y.tr));R(this,"baseBank",new ot("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","krs","s90es"));R(this,"userBank",new ot("gm"));R(this,"initOnReset",!1);R(this,"aiEfxName","");x(this,F,[]);x(this,Le,void 0);x(this,_,{nOff:(e,r)=>{let h=e*128+r,b=a(this,I).lastIndexOf(h);if(b>-1)if(a(this,u)[y.cc*e+p[64]]>63)a(this,V)[b]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:a(this,G)[h],state:this.NOTE_HELD});else if(a(this,u)[y.cc*e+p[66]]>63&&a(this,V)[b]==this.NOTE_SOSTENUTO_SUSTAIN)a(this,V)[b]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:a(this,G)[h],state:this.NOTE_SOSTENUTO_HELD});else{a(this,I)[b]=0,a(this,G)[h]=0,a(this,V)[b]=this.NOTE_IDLE;let g=this.getExt(e)[1];(g==this.VLBC_VELOINIT||g==this.VLBC_VELOALL)&&(a(this,u)[y.cc*e+p[129]]=0),this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})}},nOn:(e,r,h)=>{let b=e*128+r,g=0;for(a(this,W)[e]&&a(this,_).ano(e);a(this,V)[g]>0&&a(this,I)[g]!=b;)g++;if(g{},cAt:(e,r)=>{},hoOf:e=>{a(this,V).forEach((r,h)=>{if(r==this.NOTE_HELD){let b=a(this,I)[h],g=b>>7;e==g&&(a(this,V)[h]=this.NOTE_IDLE,a(this,I)[h]=0,a(this,G)[b]=0,this.dispatchEvent("note",{part:e,note:b&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{a(this,V).forEach((r,h)=>{let b;switch(r){case this.NOTE_ATTACK:{b=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{b=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{b=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(b){a(this,V)[h]=b;let g=a(this,I)[h];this.dispatchEvent("note",{part:e,note:g&127,velo:a(this,G)[g],state:b})}})},soOf:e=>{a(this,V).forEach((r,h)=>{if(r==this.NOTE_SOSTENUTO_HELD){let b=a(this,I)[h],g=b>>7;e==g&&(a(this,V)[h]=this.NOTE_IDLE,a(this,I)[h]=0,a(this,G)[b]=0,this.dispatchEvent("note",{part:e,note:b&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{a(this,I).forEach((r,h,b)=>{let g=r>>7,S=r&127;r==0&&a(this,G)[0]==0||g==e&&a(this,_).nOff(g,S)})}});x(this,at,{8:function(e){let r=e.channel,h=e.data[0];a(this,_).nOff(r,h)},9:function(e){let r=e.channel;this.setChActive(r,1);let h=e.data[0],b=e.data[1];b>0?a(this,_).nOn(r,h,b):a(this,_).nOff(r,h)},10:function(e){let r=e.channel,h=r*128+e.data[0];a(this,I).indexOf(h)>-1&&(a(this,G)[h]=data[1],this.getExt(r)[1]==this.VLBC_VELOALL&&(a(this,u)[y.cc*r+p[129]]=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,h=a(this,Ae)[r],b=h[e.data[0]];b&&(e.data[0]=b),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(a(this,L)){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 g=r*y.cc,S=r*y.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{a(this,_).ano(r),a(this,ge)[r]=0,a(this,u)[g+p[1]]=0,a(this,u)[g+p[5]]=0,a(this,u)[g+p[64]]=0,a(this,u)[g+p[65]]=0,a(this,u)[g+p[66]]=0,a(this,u)[g+p[67]]=0,a(this,u)[g+p[11]]=127,a(this,u)[g+p[101]]=127,a(this,u)[g+p[100]]=127,a(this,u)[g+p[99]]=127,a(this,u)[g+p[98]]=127;return}case 123:{a(this,_).ano(r);return}case 124:{a(this,_).ano(r);return}case 125:{a(this,_).ano(r);return}case 126:{a(this,W)[r]=1,a(this,_).ano(r);return}case 127:{a(this,W)[r]=0,a(this,_).ano(r);return}}if(p[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Jt.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(O()&&console.debug(`${de[a(this,L)]}, CH${r+1}: ${e.data[1]}`),a(this,L)==0?e.data[1]<48?(a(this,D)[r]>0&&(e.data[1]=a(this,u)[g],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(a(this,H).x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(this.modeIdx[a(this,H).ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):a(this,L)==C.gs?e.data[1]<56&&a(this,D)[r]>0&&(e.data[1]=a(this,u)[g],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):a(this,L)==C.gm&&(e.data[1]<48?a(this,D)[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)),a(this,L)){case C.xg:{[79,95,126,127].indexOf(e.data[1])>-1?a(this,D)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):a(this,D)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?a(this,J)[S]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?a(this,J)[S]=this.EXT_DX:a(this,J)[S]=this.EXT_NONE;break}case C["05rw"]:case C.x5d:case C.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?a(this,D)[r]==this.CH_MELODIC&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):[80,81,82,83].indexOf(e.data[1])>-1||a(this,D)[r]!=this.CH_MELODIC&&(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?a(this,D)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):a(this,D)[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?a(this,D)[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):a(this,D)[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 2:{this.getExt(r)[1]==this.VLBC_BRTHEXPR&&(a(this,u)[g+p[129]]=e.data[1]);break}case 6:{if(a(this,Re)){[C.xg,C.gs,C.ns5r].indexOf(a(this,L))<0&&console.warn(`NRPN commits are not available under "${de[a(this,L)]}" mode, even when they are supported in Octavia.`);let m=a(this,u)[g+p[99]],k=a(this,u)[g+p[98]];if(m==1){let t=Zt.indexOf(k);if(t>-1)a(this,u)[g+p[71+t]]=e.data[1],O()&&console.debug(`Redirected NRPN 1 ${k} to cc${71+t}.`),this.dispatchEvent("cc",{part:r,cc:71+t,data:e.data[1]});else{let s=Nt.indexOf(k);s>-1?a(this,Ie)[r*10+s]=e.data[1]-64:console.warn(`NRPN 0x01${k.toString(16).padStart(2,"0")} is not supported.`),O()&&console.debug(`CH${r+1} voice NRPN ${k} commit`)}}else{if(nt.indexOf(m)<0){let s=`NRPN 0x${m.toString(16).padStart(2,"0")}${k.toString(16).padStart(2,"0")} `;m==127?console.warn(`${s}is not necessary. Consider removing it.`):console.warn(`${s}is not supported.`)}else{let s=a(this,D)[r]-2;s<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${Ye[a(this,D)[r]]}.`):a(this,Q)[(s*y.dpn+ne[m])*y.dnc+k]=e.data[1]}O()&&console.debug(`CH${r+1} (${Ye[a(this,D)[r]]}) drum NRPN ${m} commit`)}}else{let m=Lt[a(this,u)[g+p[100]]],k=Ut[a(this,u)[g+p[100]]];a(this,u)[g+p[101]]==0&&m!=null&&(O()&&console.debug(`CH${r+1} RPN 0 ${a(this,u)[g+p[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Pt[m][0]),Pt[m][1]),a(this,M)[r*y.rpn+m]=e.data[1],a(this,A)[r*y.rpnt+k]=1)}break}case 32:{switch(O()&&console.debug(`${de[a(this,L)]}, CH${r+1} LSB: ${e.data[1]}`),a(this,L)){case C.s90es:case C.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,a(this,L),!0);break}}this.getExt(r)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:r});break}case 38:{if(!a(this,Re)){let m=Lt[a(this,u)[g+100]],k=Ut[a(this,u)[g+100]];a(this,u)[g+101]==0&&m!=null&&(a(this,M)[r*y.rpn+m+1]=e.data[1],a(this,A)[r*y.rpnt+k]=1)}break}case 64:{e.data[1]<64&&a(this,_).hoOf(r);break}case 66:{e.data[1]>>6?a(this,_).soOn(r):a(this,_).soOf(r);break}case 98:case 99:{w(this,Re,1);break}case 100:case 101:{w(this,Re,0);break}}a(this,u)[g+p[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(a(this,L)){case C.s90es:case C.motif:{e.data&&this.setChActive(r,1);break}default:this.setChActive(r,1)}if(this.getExt(r)[0]==this.EXT_DX){let h=y.cc*r}a(this,U)[r]=e.data,a(this,ce)[r]=0,O()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),this.dispatchEvent("voice",{part:r})},13:function(e){let r=this,h=e.channel;a(this,I).forEach(function(b){let g=b>>7;h==g&&(a(r,G)[b]=e.data,r.dispatchEvent("note",{part:h,note:b&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;a(this,ge)[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){ea(e.data).forEach(r=>{let h=r[0],b=r[1];(a(this,it)[h]||function(){console.debug(`Unknown manufacturer ${h}.`)})(b,r.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(a(this,F)[e.meta]||function(h,b,g){}).call(this,e.data,e.track,e.meta),e.meta!=32&&w(this,Oe,0);let r=Wt.indexOf(e.meta)>-1;if(O()&&console.debug(e),r)return e.reply="meta",e}});x(this,it,{64:(e,r,h)=>{a(this,Ne).run(r,h,e)},65:(e,r,h)=>{if(r[0]<16){if(r[1]==72){let b=r[r.length-1],g=ve(r.subarray(3,r.length-1));b==g?a(this,se).run(r.subarray(0,r.length-1),h,e):console.warn(`Bad SD checksum ${b} - should be ${g}.`)}else a(this,se).run(r,h,e);}else{let b=r[r.length-1],g=ve(r.subarray(2,r.length-1));b==g?a(this,se).run(r.subarray(0,r.length-1),h,e):console.warn(`Bad GS checksum ${b} - should be ${g}.`)}},66:(e,r,h)=>{a(this,$e).run(r,h,e)},67:(e,r,h)=>{a(this,ee).run(r,h,e)},68:(e,r,h)=>{a(this,He).run(r,h,e)},71:(e,r,h)=>{a(this,Be).run(r,h,e)},126:(e,r,h)=>{a(this,Ue).run(r,h,e)},127:(e,r,h)=>{this.switchMode("gm"),a(this,Pe).run(r,h,e)}});x(this,Ue,void 0);x(this,Pe,void 0);x(this,ee,void 0);x(this,se,void 0);x(this,$e,void 0);x(this,Ne,void 0);x(this,Be,void 0);x(this,He,void 0);let e=this;w(e,te,new Uint8Array(256),Gt),a(e,be)[10]=new Uint8Array(512),w(e,Le,new ie),w(e,H,{x5:82,ds:C.krs}),e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -147,22 +147,23 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),e.addEventListener("metacommit",function(t){var c,n;let{data:i}=t;((c=a(e,Z)[0])==null?void 0:c.type)==i.type&&(n=a(e,Z)[0])!=null&&n.amend?(a(e,Z)[0].amend=i.amend,a(e,Z)[0].data+=i.data):a(e,Z).unshift(i)}),a(e,F)[1]=function(t){var i,c,n,s,f;switch(t=t.replaceAll(`\r +122 006 000 `),e.addEventListener("metacommit",function(t){var c,n;let{data:s}=t;((c=a(e,j)[0])==null?void 0:c.type)==s.type&&(n=a(e,j)[0])!=null&&n.amend?(a(e,j)[0].amend=s.amend,a(e,j)[0].data+=s.data):a(e,j).unshift(s)}),a(e,F)[1]=function(t){var s,c,n,i,d;switch(t=t.replaceAll(`\r `,` `).replaceAll("\r",` -`),t.slice(0,2)){case"@I":{w(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(i=t.slice(2))==null?void 0:i.trimLeft()});break}case"@K":{w(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(c=t.slice(2))==null?void 0:c.trimLeft()}),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{w(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(n=t.slice(2))==null?void 0:n.trimLeft()});break}case"@T":{w(this,N,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(s=t.slice(2))==null?void 0:s.trimLeft()});break}case"@V":{w(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(f=t.slice(2))==null?void 0:f.trimLeft()});break}case"XF":{let l=t.slice(2).split(":");switch(l[0]){case"hd":{l.slice(1).forEach((o,d)=>{o.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][d],data:o})});break}case"ln":{l.slice(1).forEach((o,d)=>{o.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][d],data:o})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:t})}break}default:a(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((l,o)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:l,mask:o!=0})})}},a(e,F)[2]=function(t){this.dispatchEvent("metacommit",{type:"Copyrite",data:t})},a(e,F)[3]=function(t,i){i<1&&a(this,Oe)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:t})},a(e,F)[4]=function(t,i){this.dispatchEvent("metacommit",{type:"Instrmnt",data:t})},a(e,F)[5]=function(t){t.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:t,amend:!0})},a(e,F)[6]=function(t){this.dispatchEvent("metacommit",{type:"C.Marker",data:t})},a(e,F)[7]=function(t){this.dispatchEvent("metacommit",{type:"CuePoint",data:t})},a(e,F)[32]=function(t){w(this,Oe,t[0]+1)},a(e,F)[33]=function(t,i){a(e,xe)[i]=t+1},a(e,F)[81]=function(t,i){w(e,Fe,t/1e3)},a(e,F)[127]=function(t,i){a(e,Ae).run(t,i)},a(e,Ae).default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},a(e,Ae).add([67,0,1],function(t,i){a(e,xe)[i]=t[0]+1}),w(e,Ue,new re("universal non-realtime")),w(e,Pe,new re("universal realtime")),w(e,te,new re("Yamaha")),w(e,ae,new re("Roland")),w(e,$e,new re("Korg")),w(e,Ne,new re("Kawai")),w(e,Be,new re("Akai")),w(e,He,new re("Casio"));let r=new re("DX7+ Dump"),h=function(t){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,t)};a(e,Ue).default=h,a(e,Pe).default=h,a(e,te).default=h,a(e,ae).default=h,a(e,$e).default=h,a(e,Ne).default=h,a(e,Be).default=h,a(e,He).default=h,r.default=h,a(e,Ue).add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),w(e,N,a(e,N)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),a(e,Pe).add([4,1],t=>{w(e,P,((t[1]<<7)+t[0])/16383*100),e.dispatchEvent("mastervolume",a(e,P))}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64).add([4,5],t=>{let i=t[0],c=t[1],n=t[2],s=3,f=s+(i<<1),l=f+c;if(i!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${i})! -`,t);return}let o=0,d=0,$=0;switch(t.subarray(s,f).forEach(m=>{o=o<<7,o|=m}),t.subarray(f,l).forEach((m,T)=>{d|=m<{$|=m<{switch(t[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${t}`);break}case 126:{e.switchMode("xg",!0),w(e,N,!1),console.info("MIDI reset: XG");break}default:{let i=[0,0,0,0],c=(n,s)=>{i[s]=n};if(t.subarray(1).forEach((n,s)=>{let f=s+t[0];([c,c,c,c,l=>{w(this,P,l*129/16383*100),e.dispatchEvent("mastervolume",a(e,P))},l=>{},l=>{}][f]||(()=>{}))(n,s)}),t[0]<4){let n=0;i.forEach(s=>{n=n<<4,n+=s}),n-=1024}}}}).add([76,2,1],t=>{let i="XG ";t[0]<32?(i+="reverb ",t.subarray(1).forEach((c,n)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${i}main type: ${qe[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: ${wt(s)}s`)},s=>{console.debug(`${i}diffusion: ${s}`)},s=>{console.debug(`${i}initial delay: ${s}`)},s=>{console.debug(`${i}HPF cutoff: ${Ge[s]}Hz`)},s=>{console.debug(`${i}LPF cutoff: ${Ge[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: ${Y(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=>{}][t[0]+n]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(c)})):t[0]<64?(i+="chorus ",t.subarray(1).forEach((c,n)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${i}main type: ${qe[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: ${vt[s]}Hz`)},s=>{},s=>{console.debug(`${i}feedback: ${s}`)},s=>{console.debug(`${i}delay offset: ${kt(s)}ms`)},s=>{},s=>{console.debug(`${i}low: ${Ge[s]}Hz`)},s=>{console.debug(`${i}low: ${s-64}dB`)},s=>{console.debug(`${i}high: ${Ge[s]}Hz`)},s=>{console.debug(`${i}high: ${s-64}dB`)},s=>{console.debug(`${i}dry/wet: ${s}`)},s=>{console.debug(`${i}send: ${Y(s)}dB`)},s=>{console.debug(`${i}pan: ${s-64}`)},s=>{console.debug(`${i}to reverb: ${Y(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=>{}][t[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(c)})):t[0]<86?(i+="variation ",t.subarray(1).forEach((c,n)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${i}main type: ${qe[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))}][t[0]-64+n]||function(){})(c)})):t[0]<97?(i+="variation ",t.subarray(1).forEach((c,n)=>{[s=>{console.debug(`${i}send: ${Y(s)}dB`)},s=>{console.debug(`${i}pan: ${s-64}`)},s=>{console.debug(`${i}to reverb: ${Y(s)}dB`)},s=>{console.debug(`${i}to chorus: ${Y(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}`)}][t[0]-86+n](c)})):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,c)=>{let n=c+t[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let s=n-1>>2,f=n-1&3,l=`XG EQ ${s} ${["gain","freq","Q","shape"][f]}: `;[()=>{console.debug(`${l}${i-64}dB`)},()=>{console.debug(`${l}${i} (raw)`)},()=>{console.debug(`${l}${i/10}`)},()=>{console.debug(`${l}${["shelf","peak"][+!!i]}`)}][f]()}})}).add([76,3],t=>{let i=t[0],c=t[1],n=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((s,f)=>{([l=>{e.setEffectTypeRaw(3+i,!1,l),console.info(`${n}main type: ${qe[l]}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))},l=>{e.setEffectTypeRaw(3+i,!0,l),console.debug(`${n}sub type: ${l+1}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))}][c+f]||function(){})(s)})}).add([76,6,0],t=>{let i=t[0];i<64?e.setLetterDisplay(t.subarray(1),"XG letter display",i):w(e,Se,Date.now())}).add([76,7,0],t=>{let i=t[0];w(e,z,0),w(e,le,Date.now()+3200),a(e,j,ue).fill(0);let c=t.subarray(1);for(let n=0;n>6-$&1,$++})}).add([76,8],(t,i)=>{let c=e.chRedir(t[0],i,!0),n=t[1],s=g.cc*c,f=`XG CH${c+1} `,l=`Unknown XG part address ${n}.`;t.subarray(2).forEach((o,d)=>{n<1?console.debug(l):n<41?([()=>{a(e,u)[s+p[0]]=o,e.dispatchEvent("voice",{part:c})},()=>{a(e,u)[s+p[32]]=o,e.dispatchEvent("voice",{part:c})},()=>{a(e,U)[c]=o,e.dispatchEvent("voice",{part:c})},()=>{let $=e.chRedir(o,i,!0);a(e,X)[c]=$,c!=$&&(e.buildRchTree(),console.info(`${f}receives from CH${$+1}`))},()=>{a(e,W)[c]=+!o},()=>{},()=>{e.setChType(c,o,C.xg),console.debug(`${f}type: ${Ye[o]||o}`)},()=>{a(e,M)[g.rpn*c+3]=o,a(e,L)[g.rpnt*c+2]=1},!1,!1,()=>{a(e,u)[s+p[7]]=o},!1,!1,()=>{a(e,u)[s+p[10]]=o||128},!1,!1,()=>{a(e,u)[s+p[128]]=o},()=>{a(e,u)[s+p[93]]=o},()=>{a(e,u)[s+p[91]]=o},()=>{a(e,u)[s+p[94]]=o},()=>{a(e,u)[s+p[76]]=o},()=>{a(e,u)[s+p[77]]=o},()=>{a(e,u)[s+p[78]]=o},()=>{a(e,u)[s+p[74]]=o},()=>{a(e,u)[s+p[71]]=o},()=>{a(e,u)[s+p[73]]=o},()=>{a(e,u)[s+p[75]]=o},()=>{a(e,u)[s+p[72]]=o}][n+d-1]||(()=>{}))():n<48?console.debug(l):n<111?n>102&&n<105&&(a(e,u)[s+p[[5,65][n&1]]]=o):n<114?console.debug(l):n<116?console.debug(`${f}EQ ${["bass","treble"][n&1]} gain: ${o-64}dB`):n<118?console.debug(l):n<120?console.debug(`${f}EQ ${["bass","treble"][n&1]} freq: ${o}`):console.debug(l)})}).add([76,9],(t,i)=>{let c=e.chRedir(t[0],i,!0),n=t[1],s=g.cc*c,f=`PLG-VL CH${c+1} `;t.subarray(2).forEach((l,o)=>{let d=o+n;switch(d){case 1:{console.info(`${f}breath mode: ${["system","breath","velocity","touch EG"][l]}`);break}case 0:case 27:case 28:break;default:if(d<27){let $=d-3>>1,m=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][$];d&1?d<23?(console.debug(`${f}${m} control source: ${Ct(l)}`),l&&l<96&&e.allocateAce(130+$),a(e,De)[g.redir*c+$+2]=l,e.buildRccMap()):console.debug(`${f}${m} scale break point: ${l}`):(console.debug(`${f}${m} depth: ${l-64}`),a(e,u)[s+p[130+$]]=l)}}})}).add([76,10],t=>{}).add([76,16],t=>{}).add([76,17,0,0],t=>{}).add([76,112],t=>{switch(console.debug(`XG enable PLG-${["VL","SG","DX","AN","PF","DR","PC","AP"][t[0]]} for CH${t[2]+1}.`),t[0]){case 0:{a(e,fe)[g.ext*t[2]]=e.EXT_VL;break}default:a(e,fe)[g.ext*t[2]]=e.EXT_NONE}}).add([73,0,0],(t,i)=>{let c=t[0],n="MU1000 System: ";t.subarray(1).forEach((s,f)=>{let l=c+f;l==8?console.debug(`${n}LCD contrast set to ${s}.`):l==18?(w(e,ee,s?126:0),console.debug(`${n}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):l>=64&&l<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.`)}][l-64]()})}).add([73,10,0],(t,i)=>{let c=t[0],n=`MU1000 RS${a(e,ne)?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let s=e.chRedir(0,i,!0);a(e,ne)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${n}Show CH1~64`);break}case 3:{let s=e.chRedir(t[1]<<5,i,!0);a(e,ne)&&e.dispatchEvent("channelmin",s),a(e,ne)&&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(a(e,ne)){let s=e.chRedir(c-16+(a(e,ze)<<4),i,!0);e.dispatchEvent("channelactive",s)}}else if(c<36){let s=e.chRedir(c-32<<4,i,!0);a(e,ne)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),w(e,ze,c-32)),console.info(`${n}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(t,i)=>{let c=e.chRedir(t[0],i,!0),n=`PLG-100SG CH${c+1} `,s=Date.now();if(t[1]==0){let f="",l=0;t.subarray(2).forEach((o,d)=>{d%2==0?f+=St[o]||o.toString().padStart("0"):l+=o*13}),s>=a(e,Ke)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${xt(f)}`,amend:!0}),w(e,Ke,s+Math.ceil(l/2)+a(e,Fe)),O()&&console.debug(`${n}vocals: ${f}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}).add([100,0],(t,i,c)=>{let n=t.subarray(0,t.length-1),s=Me(n),f=t[t.length-1];if(s!=f){console.warn(`Yamaha DX7 dump SysEx checksum mismatch! Expected ${s}, but got ${f}: -`,t);return}else r.run(n)}),r.add([0,14,31],t=>{a(e,u)[g.cc*t[0]+p[64]]=0,a(e,I).ano(t[0]),e.switchMode("xg"),console.debug(`Yamaha DX7+ reset CH${t[0]+1}.`)}).add([56,76,112],async t=>{let i=t[0],c="";t.subarray(1).forEach((n,s)=>{s<10&&(c+=String.fromCharCode(Math.max(n,32)))}),a(e,U)[i]=i&127,a(e,u)[g.cc*i+p[0]]=35,a(e,u)[g.cc*i+p[32]]=i>>7|2,e.dispatchEvent("voice",{part:i}),c.length>0&&(c=c.trimRight(),console.debug(`DX7+ CH${i+1} dumped voice name: "${c}"`))});let b=function(t,i,c,n){},y=function(t,i){let c=t*g.dpn,n=i[0],s=i[1];i.subarray(2).forEach((f,l)=>{let o=l+s,d=-1;o<16?([()=>{d=24},()=>{d=25},()=>{d=26},()=>{},()=>{d=28},()=>{d=29},()=>{d=30},()=>{d=31},()=>{},()=>{},()=>{},()=>{d=20},()=>{d=21},()=>{d=22},()=>{d=23},()=>{}][o]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${t+1}.`)}))():o<32||(o<40?([()=>{d=48},()=>{d=49},!1,!1,()=>{d=52},()=>{d=53}][o-32]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${t+1}.`)}))():o<80||([()=>{d=36}][o-80]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${t+1}.`)}))()),d>=0?(O()&&console.debug(c,d,n,f),a(e,Q)[(c+se[d])*g.dnc+n]=f):O()&&console.debug(`XG-style drum param ${o} has no writes.`)})},S=function(t,i,c){let n=t*g.dpn,s=(i<<7)+c[0];c.subarray(1).forEach((f,l)=>{let o=l+s,d=o&127,$=o>>7,m=-1;$>1&&([()=>{m=26},()=>{},()=>{m=28},()=>{m=29},()=>{m=30},()=>{},()=>{},()=>{m=31}][$-2]||(()=>{console.debug(`Unknown GS-style drum param ${$} on set ${t+1}.`)}))(),m>-1?(O()&&console.debug(n,m,d,f),a(e,Q)[(n+se[m])*g.dnc+d]=f):O()&&console.debug(`GS-style drum param ${$} has no writes.`)})};a(this,te).add([76,48],(t,i,c)=>{y(0,t)}).add([76,49],(t,i,c)=>{y(1,t)}).add([76,50],(t,i,c)=>{y(2,t)}).add([76,51],(t,i,c)=>{y(3,t)}).add([76,52],(t,i,c)=>{y(4,t)}).add([76,53],(t,i,c)=>{y(5,t)}).add([76,54],(t,i,c)=>{y(6,t)}).add([76,55],(t,i,c)=>{y(7,t)}),a(this,te).add([89,0],(t,i,c)=>{if(e.eprom){let n=t[0],s=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);O()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${n} bytes.`);let f=e.eprom.data;t.subarray(4).forEach((l,o)=>{let d=o>>3,$=o&7;if($==7)for(let m=0;m<7;m++)f[s+7*d+m]+=(l>>6-m&1)<<7;else f[s+7*d+$]=l})}}).add([89,1],(t,i,c)=>{let n=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];O()&&console.debug(`MU1000 EPROM jump to 0x${n.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=n)}).add([89,2],(t,i,c)=>{if(e.eprom){let n=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);O()&&console.debug(`MU1000 EPROM write to 0x${n.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;t.subarray(4).forEach((f,l)=>{let o=l>>3,d=l&7;if(d==7)for(let $=0;$<7;$++)s[n+7*o+$]+=(f>>6-$&1)<<7;else s[n+7*o+d]=f})}}).add([89,3],(t,i,c)=>{}),a(this,te).add([39,48],(t,i,c)=>{}).add([43,0,0],(t,i,c)=>{let n=[0,0,0,0],s=(f,l)=>{n[l]=f};if(t.subarray(1).forEach((f,l)=>{let o=l+t[0];[s,s,s,s,()=>{w(this,P,f*129/16383*100),e.dispatchEvent("mastervolume",a(e,P))},()=>f-64,()=>f||128,()=>f,()=>f,()=>{console.debug(`TG300 variation on cc${f}.`)}][o](f,o)}),t[0]<4){let f=0;n.forEach(l=>{f=f<<4,f+=l}),f-=1024}}).add([43,1,0],(t,i,c)=>{}).add([43,2],(t,i,c)=>{let n=e.chRedir(t[0],i,!0),s=t[1],f=g.cc*n,l=`TG300 CH${n+1} `;t.subarray(2).forEach((o,d)=>{d<5?([()=>{},()=>{a(e,u)[f+p[0]]=o,e.dispatchEvent("voice",{part:n})},()=>{a(e,u)[f+p[32]]=o,e.dispatchEvent("voice",{part:n})},()=>{a(e,U)[n]=o,e.dispatchEvent("voice",{part:n})},()=>{let $=e.chRedir(o,i,!0);a(e,X)[n]=$,n!=$&&(e.buildRchTree(),console.info(`${l}receives from CH${$+1}`))}][d+s]||(()=>{}))(o,d+s):d<21||(d<47?([()=>{a(e,W)[n]=+!o},()=>{},()=>{},()=>{a(e,M)[g.rpn*n+3]=o,a(e,L)[g.rpnt*n+2]=1},()=>{},()=>{a(e,u)[f+p[7]]=o},!1,!1,()=>{a(e,u)[f+p[10]]=o||128},!1,!1,()=>{console.debug(`${l} AC1 at cc${o}`)},()=>{console.debug(`${l} AC2 at cc${o}`)},()=>{a(e,u)[f+p[128]]=o},()=>{a(e,u)[f+p[93]]=o},()=>{a(e,u)[f+p[91]]=o},()=>{a(e,u)[f+p[94]]=o},()=>{a(e,u)[f+p[76]]=o},()=>{a(e,u)[f+p[77]]=o},()=>{a(e,u)[f+p[74]]=o},()=>{a(e,u)[f+p[71]]=o},()=>{a(e,u)[f+p[73]]=o},()=>{a(e,u)[f+p[75]]=o},()=>{a(e,u)[f+p[72]]=o},()=>{a(e,u)[f+p[78]]=o}][d+s-21]||(()=>{}))(o,d+s):d<95||([()=>{a(e,u)[f+p[65]]=o},()=>{a(e,u)[f+p[5]]=o}][d+s-95]||(()=>{}))(o,d+s))})}).add([43,7,0],(t,i,c)=>{let n=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",n)}).add([43,7,1],(t,i,c)=>{w(e,z,0),w(e,le,Date.now()+3200),a(e,j,ue).fill(0),t.forEach(function(n,s){let f=Math.floor(s/16),l=s%16,o=(l*3+f)*7,d=7,$=0;for(o-=l*5,f==2&&(d=2);$>6-$&1,$++})}),a(this,ae).add([66,18,0,0,127],(t,i,c)=>{e.switchMode("gs",!0),a(e,u)[g.cc*9]=120,a(e,u)[g.cc*25]=120,a(e,u)[g.cc*41]=120,a(e,u)[g.cc*57]=120,w(e,ee,3),w(e,N,!1),a(e,Ee).fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,i,c)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),a(e,u)[g.cc*9]=120,a(e,u)[g.cc*25]=120,a(e,u)[g.cc*41]=120,a(e,u)[g.cc*57]=120,w(e,N,!1),a(e,Ee).fill(0),console.info("MIDI reset: GS");break}default:{let n=[0,0,0,0],s=(f,l)=>{n[l]=f};if(t.subarray(1).forEach((f,l)=>{let o=l+t[0];[s,s,s,s,d=>{w(this,P,d*129/16383*100),e.dispatchEvent("mastervolume",a(e,P))},d=>{},d=>{}][o](f,l)}),t[0]<4){let f=0;n.forEach(l=>{f=f<<4,f+=l}),f-=1024}}}}).add([66,18,64,1],t=>{let i=t[0];if(i<16){let c="".padStart(i," ");t.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?t.subarray(1).forEach((c,n)=>{let s=`GS ${i+n>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${lt[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${c}ms`)},()=>{console.info(`${s}type: ${Mt[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${Y(c)}`)},()=>{console.debug(`${s}to delay: ${Y(c)}`)}][i+n-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?t.subarray(1).forEach((c,n)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${Tt[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${Y(c)}`)}][i+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],t=>{let i="GS EQ ";t.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`)}][t[0]+n]||function(){console.warn(`Unknown GS EQ address: ${t[0]+n}`)})()})}).add([66,18,64,3],t=>{let i="GS EFX ",c=function(n,s){let f=Rt(a(e,J).subarray(10,12),s,n);f&&console.debug(`${i}${dt(a(e,J).subarray(10,12))} ${f}`)};t.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: ${dt(a(e,J).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: ${Y(n)}dB`)},()=>{console.debug(`${i}to chorus: ${Y(n)}dB`)},()=>{console.debug(`${i}to delay: ${Y(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]+s]||function(f,l){console.warn(`Unknown GS EFX address: ${l}`)})(n,t[0]+s)})}).add([66,18,65],t=>{S((t[0]>>4)+1<<1,t[0]&15,t.subarray(1))}).add([69,18,16],t=>{var i;switch(t[0]){case 0:{let c=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",c);break}case 32:{w(e,le,Date.now()+3200),t[1]==0&&(w(e,z,Math.max(Math.min(t[2]-1,9),0)),O()&&console.debug(`GS switch display page ${t[2]-1}.`));break}default:if(t[0]<6){a(e,z)>9&&w(e,z,0);let c=t[0]-1<<1|t[1]>>6;a(e,z)==c&&w(e,le,Date.now()+3200),(i=a(e,pe)[c])!=null&&i.length||(a(e,pe)[c]=new Uint8Array(256));let n=a(e,pe)[c];O()&&console.debug(`GS frame draw page ${c}.`);let s=t[1]&63;n.fill(0),t.subarray(2).forEach(function(l,o){let d=o+s,$=Math.floor(d/16),m=d%16,T=(m*4+$)*5,B=5,Ce=0;for(T-=m*4,$==3&&(B=1);Ce>4-Ce&1,Ce++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let v=function(t,i,c){let n=t[0],s=g.cc*i,f=g.rpn*i,l=`GS CH${i+1} `;n<3?(t.subarray(1).forEach((o,d)=>{[()=>{a(e,u)[s+p[0]]=o},()=>{a(e,U)[i]=o},()=>{let $=0;o<16?$=e.chRedir(o,c,!0):$=g.ch,a(e,X)[i]=$,i!=$&&(e.buildRchTree(),console.info(`${l}receives from CH${$+1}`))}][n+d]()}),e.dispatchEvent("voice",{part:i})):n<19||(n<44?t.subarray(1).forEach((o,d)=>{([()=>{a(e,W)[i]=+!o},!1,()=>{e.setChType(i,o<<1,C.gs),console.debug(`${l}type: ${o?"drum ":"melodic"}${o||""}`)},()=>{a(e,M)[f+3]=o,a(e,L)[g.rpnt*i+2]=1},!1,()=>{a(e,u)[s+p[7]]=o},!1,!1,()=>{a(e,u)[s+p[10]]=o||128},!1,!1,()=>{console.debug(`${l}CC 1: cc${o}`)},()=>{console.debug(`${l}CC 2: cc${o}`)},()=>{a(e,u)[s+p[93]]=o},()=>{a(e,u)[s+p[91]]=o},!1,!1,()=>{a(e,M)[f+1]=o,a(e,L)[g.rpnt*i+1]=1},()=>{a(e,M)[f+2]=o,a(e,L)[g.rpnt*i+1]=1},()=>{a(e,u)[s+p[94]]=o}][n+d-19]||(()=>{}))()}):n<76||console.debug(`Unknown GS part address: ${n}`))},k=function(t,i){let c=t[0],n=`GS CH${i+1} `;c<2?t.subarray(1).forEach((s,f)=>{[()=>{a(e,u)[g.cc*i+p[32]]=s},()=>{}][c+f]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?t.subarray(1).forEach((s,f)=>{[()=>{console.debug(`${n}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${n}EFX: o${["ff","n"][s]}`),a(e,Xe)[i]=s,e.dispatchEvent("partefxtoggle",{part:i,active:s})}][c+f-32]()}):console.warn(`Unknown GS misc address: ${c}`)};a(this,ae).add([66,18,64,16],(t,i)=>{v(t,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(t,i)=>{v(t,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(t,i)=>{v(t,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(t,i)=>{v(t,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(t,i)=>{v(t,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(t,i)=>{v(t,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(t,i)=>{v(t,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(t,i)=>{v(t,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(t,i)=>{v(t,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(t,i)=>{v(t,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(t,i)=>{v(t,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(t,i)=>{v(t,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(t,i)=>{v(t,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(t,i)=>{v(t,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(t,i)=>{v(t,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(t,i)=>{v(t,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(t,i)=>{k(t,e.chRedir(9,i,!0))}).add([66,18,64,65],(t,i)=>{k(t,e.chRedir(0,i,!0))}).add([66,18,64,66],(t,i)=>{k(t,e.chRedir(1,i,!0))}).add([66,18,64,67],(t,i)=>{k(t,e.chRedir(2,i,!0))}).add([66,18,64,68],(t,i)=>{k(t,e.chRedir(3,i,!0))}).add([66,18,64,69],(t,i)=>{k(t,e.chRedir(4,i,!0))}).add([66,18,64,70],(t,i)=>{k(t,e.chRedir(5,i,!0))}).add([66,18,64,71],(t,i)=>{k(t,e.chRedir(6,i,!0))}).add([66,18,64,72],(t,i)=>{k(t,e.chRedir(7,i,!0))}).add([66,18,64,73],(t,i)=>{k(t,e.chRedir(8,i,!0))}).add([66,18,64,74],(t,i)=>{k(t,e.chRedir(10,i,!0))}).add([66,18,64,75],(t,i)=>{k(t,e.chRedir(11,i,!0))}).add([66,18,64,76],(t,i)=>{k(t,e.chRedir(12,i,!0))}).add([66,18,64,77],(t,i)=>{k(t,e.chRedir(13,i,!0))}).add([66,18,64,78],(t,i)=>{k(t,e.chRedir(14,i,!0))}).add([66,18,64,79],(t,i)=>{k(t,e.chRedir(15,i,!0))}),a(this,$e).add([54,65],(t,i)=>{e.switchMode("x5d");let c=t[t.length-1],n=t.subarray(0,t.length-1),s=Me(n);s!=c&&(console.info(`X5D multi parameters checksum mismatch! Expected ${s}, got ${c}.`),console.debug(t));let f=(t[1]<<7)+t[0],l=(t[3]<<7)+t[2],o=e.chRedir(f&15,i,!0),d=g.cc*o;[()=>{l<1||(l<101?(e.setChType(o,e.CH_MELODIC,C.x5d),a(e,U)[o]=l-1,a(e,u)[d+p[0]]=a(e,H).x5):l<229?(e.setChType(o,e.CH_MELODIC,C.x5d),a(e,U)[o]=l-101,a(e,u)[d+p[0]]=56):(e.setChType(o,e.CH_DRUMS,C.x5d),a(e,U)[o]=Bt[l-229]||0,a(e,u)[d+p[0]]=62)),e.dispatchEvent("voice",{part:o})},()=>{a(e,u)[d+p[7]]=l},()=>{l<31&&(a(e,u)[d+p[10]]=Math.round((l-15)*4.2+64))},()=>{a(e,u)[d+p[93]]=We(l)},()=>{a(e,u)[d+p[91]]=We(l)},()=>{a(e,M)[o*g.rpn+3]=l>8191?l-16320:64+l,a(e,L)[g.rpnt*o+2]=1},()=>{a(e,M)[o*g.rpn+1]=l>8191?l-16320:64+l,a(e,L)[g.rpnt*o+1]=1},()=>{l>0&&(a(e,M)[o*g.rpn]=l,a(e,L)[g.rpnt*o]=1)},()=>{}][f>>4]()}).add([54,76,0],(t,i)=>{e.switchMode(a(e,H).x5=="81"?"05rw":"x5d",!0);let c="",n=a(e,H).x5,s=0,f=0,l="MSB\tPRG\tLSB\tNME";ce(t,function(o,d){if(d<16400){let $=d%164;switch(!0){case $<10:{o>31&&(c+=String.fromCharCode(o));break}case $==10:break;case $==11:{l+=` -${n} ${s} ${f} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}s>99&&(n=90,s=0)}}),e.userBank.clearRange({msb:a(e,H).x5,prg:[0,99],lsb:0}),e.userBank.load(l),O()&&console.debug(l),e.forceVoiceRefresh()}).add([54,77,0],(t,i)=>{e.switchMode(a(e,H).x5=="81"?"05rw":"x5d",!0);let c="",n=90,s=0,f=0,l="MSB\tPRG\tLSB\tNME";ce(t,function(o,d){if(d<13600){let $=d%136;switch(!0){case $<10:{o>31&&(c+=String.fromCharCode(o));break}case $==11:{l+=` -${n} ${s} ${f} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(l),O()&&console.debug(l),e.forceVoiceRefresh()}).add([54,78],(t,i)=>{e.switchMode(a(e,H).x5=="81"?"05rw":"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(a(e,H).x5=="81"?"05rw":"x5d",!0),ce(t,(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],(t,i)=>{e.switchMode(a(e,H).x5=="81"?"05rw":"x5d",!0),ce(t,function(c,n,s,f){if(n<192){let l=e.chRedir(Math.floor(n/12),i,!0),o=l*g.cc;switch(n%12){case 0:{c<128?(e.setChType(l,e.CH_MELODIC,C.x5d),a(e,u)[o+p[0]]=a(e,H).x5,a(e,U)[l]=c):(e.setChType(l,e.CH_DRUMS,C.x5d),a(e,u)[o+p[0]]=62,a(e,U)[l]=Bt[c-128]),c>0&&e.setChActive(l,1),e.dispatchEvent("voice",{part:l});break}case 1:{a(e,u)[o+p[7]]=c;break}case 2:{a(e,M)[l*g.rpn+3]=c>127?c-192:64+c,a(e,L)[g.rpnt*l+2]=1;break}case 3:{a(e,M)[l*g.rpn+1]=c>127?c-192:64+c,a(e,L)[g.rpnt*l+1]=1;break}case 4:{c<31&&(a(e,u)[o+p[10]]=Math.round((c-15)*4.2+64));break}case 5:{let d=c>>4,$=c&15;a(e,u)[o+p[91]]=We($),a(e,u)[o+p[93]]=We(d);break}case 10:break;case 11:{let d=e.chRedir(c&15,i,!0),$=c>>4;a(e,X)[l]=c,(d!=l||$)&&(console.info(`X5D Part CH${l+1} receives from CH${d+1}.`),e.buildRchTree())}}}else{let l=e.chRedir(n-192,i,!0)}})}),a(this,ae).add([22,18,127],t=>{e.switchMode("mt32",!0),w(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,c)=>{e.switchMode("mt32");let n=e.chRedir(c,i,!0),s=t[1];t.subarray(2).forEach((f,l)=>{let o=l+s;a(e,me)[o+(n-1)*16]=f,([!1,()=>{let d=a(e,me)[n-1<<4];if(d<3){if(a(e,he)[n]=1,d==2)for(let $=0;${a(e,M)[n*g.rpn+3]=f+40,a(e,L)[g.rpnt*n+2]=1},()=>{a(e,M)[n*g.rpn+1]=f+14,a(e,L)[g.rpnt*n+1]=1},()=>{a(e,M)[n*g.rpn]=f,a(e,L)[g.rpnt*n]=1},!1,()=>{a(e,u)[g.cc*n+p[91]]=f?127:0},!1,()=>{a(e,u)[g.cc*n+p[7]]=f},()=>{a(e,u)[g.cc*n+p[10]]=Math.ceil(f*9.05)}][o]||(()=>{}))()})}).add([22,18,1],(t,i,c)=>{e.switchMode("mt32");let n=c&7;console.debug(`MT-32 slot #${c+1} Drum: ${t}`);let s=t[0]<<7|t[1];t.subarray(2).forEach((f,l)=>{let o=l+s,d=(o>>2)+24,$=o&3,m=n*g.dpn;if(O()&&console.debug(`MT-32 temp drum note ${d} param ${$}: ${f}`),d<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${d}`);return}[()=>{},()=>{a(e,Q)[(m+se[26])*g.dnc+d]=Math.round(f*1.27)},()=>{a(e,Q)[(m+se[26])*g.dnc+d]=f*9+1&127},()=>{a(e,Q)[(m+se[26])*g.dnc+d]=f?127:0}][$]()})}).add([22,18,2],(t,i,c)=>{e.switchMode("mt32");let n=e.chRedir(c,i,!0),s=t[1]+(t[0]<<7);s<10&&(a(e,he)[n]=1),t.subarray(2).forEach((f,l)=>{let o=l+s;o<14&&(a(e,ie)[(n-1)*g.cmt+o]=f)}),e.dispatchEvent("voice",{part:n})}).add([22,18,3],(t,i,c)=>{e.switchMode("mt32");let n=c&7;if(t[0]){let s=(t[0]-1<<7)+t[1]-16;t.subarray(2).forEach((f,l)=>{let o=l+s,d=(o>>2)+24,$=o&3,m=n*g.dpn;if(O()&&console.debug(`MT-32 dev drum note ${d} param ${$}: ${f}`),d<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${d}`);return}[()=>{},()=>{a(e,Q)[(m+se[26])*g.dnc+d]=Math.round(f*1.27)},()=>{a(e,Q)[(m+se[26])*g.dnc+d]=f*9+1&127},()=>{a(e,Q)[(m+se[26])*g.dnc+d]=f?127:0}][$]()})}else{let s=t[1];t.subarray(2).forEach((f,l)=>{let o=l+s;a(e,me)[o]=f;let d=e.chRedir(1+(o>>4),i,!0),$=o&15;([!1,()=>{let m=a(e,me)[d-1<<4];if(m<3)if(a(e,he)[d]=1,m==2)for(let T=0;T{a(e,M)[d*g.rpn+3]=f+40,a(e,L)[g.rpnt*d+2]=1},()=>{a(e,M)[d*g.rpn+1]=f+14,a(e,L)[g.rpnt*d+1]=1},()=>{a(e,M)[d*g.rpn]=f,a(e,L)[g.rpnt*d]=1},!1,()=>{a(e,u)[g.cc*d+p[91]]=f?127:0},!1,()=>{a(e,u)[g.cc*d+p[7]]=f},()=>{a(e,u)[g.cc*d+p[10]]=Math.ceil(f*9.05)}][$]||(()=>{}))()})}}).add([22,18,4],(t,i,c)=>{e.switchMode("mt32");let n=t[1]+(t[0]<<7),s=[];t.subarray(2).forEach((f,l)=>{let o=l+n,d=e.chRedir(Math.floor(o/246+1),i,!0),$=o%246;$<14&&(a(e,ie)[(d-1)*g.cmt+$]=f),$<10&&(a(e,he)[d]=1),s.indexOf(d)<0&&s.push(d)}),s.forEach(f=>{e.dispatchEvent("voice",{part:f})})}).add([22,18,5],(t,i,c)=>{e.switchMode("mt32");let n=(t[0]<<7)+t[1];t.subarray(2).forEach((s,f)=>{let l=n+f,o=Math.floor(l/8),d=l&7,$=o*8;a(e,Ve)[l]=s,([!1,()=>{let m=a(e,Ve)[$];if(m<3){let T="";if(m==2){let Ce=g.cmt*o;T=`MT-m:${s.toString().padStart(3,"0")}`}else T=e.baseBank.get(0,s+(m<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:o});let B=`MSB LSB PRG NME -000 127 ${o} ${T}`;e.userBank.load(B,!0)}}][d]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(t,i,c)=>{e.switchMode("mt32");let n=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((s,f)=>{let l=n+f;l>1)*g.cmt+l]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(t,i,c)=>{e.switchMode("mt32");let n=t[1],s=!1,f=function(l,o){a(e,X)[o-12]=l,s=!0};t.subarray(2).forEach((l,o)=>{let d=o+n;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,f,f,f,f,f,f,f,f,f,()=>{w(e,P,l),e.dispatchEvent("mastervolume",a(e,P))}][d]||(()=>{}))(l,o)}),s&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let i=t[1],c=" ".repeat(i);t.subarray(2).forEach(n=>{n>31?c+=String.fromCharCode(n):c+=" "}),w(e,ke,c.padStart(20," ")),w(e,Se,Date.now()+3200)}).add([22,18,82],(t,i)=>{let c=e.chRedir(0,i,!0);for(let n=0;n<16;n++)a(e,I).ano(c+n),n&&n<10&&(a(e,U)[c+n]=ft[n-1]);console.info("MT-32 alt reset complete.")}),a(this,$e).add([66,0],(t,i)=>{e.switchMode("ns5r",!0),w(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),w(e,N,!1)}).add([66,18,0,0],(t,i)=>{let c=t[0];switch(c){case 124:case 126:case 127:{e.switchMode("ns5r",!0),w(e,N,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${t}`);break}default:if(c<10){let n=[0,0,0,0],s=(f,l)=>{n[l]=f};if(t.subarray(1).forEach((f,l)=>{[s,s,s,s,()=>{w(e,P,f*129/16383*100),e.dispatchEvent("mastervolume",a(e,P))},()=>f-64,()=>f-64,()=>{},()=>{},()=>{}][c+l]()}),t[0]<4){let f=0;n.forEach(l=>{f=f<<4,f+=l}),f-=1024}}}}).add([66,18,0,1],(t,i)=>{}).add([66,18,0,2],(t,i)=>{}).add([66,18,1],(t,i)=>{let c=e.chRedir(t[0],i,!0),n=c*g.cc,s=t[1],f=`NS5R CH${c+1} `;t.subarray(2).forEach((l,o)=>{let d=s+o;d<3?([()=>{a(e,u)[n+p[0]]=l||Je.bank0},()=>{a(e,u)[n+p[32]]=l},()=>{a(e,U)[c]=l}][d](),e.dispatchEvent("voice",{part:c})):d<8||(d<14?[()=>{let $=e.chRedir(l,i,!0);a(e,X)[c]=$,c!=$&&(e.buildRchTree(),console.info(`${f}receives from CH${$+1}`))},()=>{a(e,W)[c]=+!l},()=>{e.setChType(c,l,C.ns5r),console.debug(`${f}type: ${Ye[l]}`)},()=>{a(e,M)[g.rpn*c+3]=l,a(e,L)[g.rpnt*c+2]=1},()=>{},()=>{}][d-8]():d<16||(d<33?[()=>{a(e,u)[n+p[7]]=l},()=>{a(e,u)[n+p[11]]=l},()=>{},()=>{},()=>{a(e,u)[n+p[10]]=l||128},()=>{},()=>{},()=>{a(e,u)[n+p[93]]=l},()=>{a(e,u)[n+p[91]]=l},()=>{a(e,u)[n+p[76]]=l},()=>{a(e,u)[n+p[77]]=l},()=>{a(e,u)[n+p[78]]=l},()=>{a(e,u)[n+p[74]]=l},()=>{a(e,u)[n+p[71]]=l},()=>{a(e,u)[n+p[73]]=l},()=>{a(e,u)[n+p[75]]=l},()=>{a(e,u)[n+p[72]]=l}][d-16]():d<112||d<114&&[()=>{a(e,u)[n+p[5]]=l},()=>{a(e,u)[n+p[65]]=l}][d-112]()))})}).add([66,18,8,0],(t,i)=>{let c=t[0];if(c<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let n=c-32;w(e,le,Date.now()+3200),w(e,z,10),a(e,j,ue).fill(0);let s=t.subarray(1),f=4;s.forEach(function(l,o){let d=o+n,$=d>>4,m=d&15;if(d<80){let T=$>3,B=0,Ce=$0;)a(e,j,ue)[m*32+$*7+(Ce-B)]=T&1,T=T>>1,B++}})}}).add([66,18,48],(t,i,c)=>{y(0,t)}).add([66,18,49],(t,i,c)=>{y(1,t)}).add([66,18,50],(t,i,c)=>{y(2,t)}).add([66,18,51],(t,i,c)=>{y(3,t)}).add([66,18,52],(t,i,c)=>{y(4,t)}).add([66,18,53],(t,i,c)=>{y(5,t)}).add([66,18,54],(t,i,c)=>{y(6,t)}).add([66,18,55],(t,i,c)=>{y(7,t)}).add([66,52],(t,i)=>{e.switchMode("ns5r",!0),w(e,N,!1);let c="";ce(t,(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],(t,i)=>{e.switchMode("ns5r",!0),w(e,N,!1);let c="",n=t[t.length-1],s=t.subarray(0,t.length-1),f=Me(s);f!=n&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${f}, got ${n}.`),console.debug(t)),ce(s,function(l,o){switch(!0){case o<2944:{let d=e.chRedir(Math.floor(o/92),i,!0),$=d*g.cc;switch(o%92){case 0:{a(e,u)[$+p[0]]=l,e.dispatchEvent("voice",{part:d});break}case 1:{a(e,u)[$+p[32]]=l,!l&&!a(e,u)[$+p[0]]&&(a(e,u)[$+p[0]]=Je.bank0),e.dispatchEvent("voice",{part:d});break}case 2:{a(e,U)[d]=l,l>0&&e.setChActive(d,1),e.dispatchEvent("voice",{part:d});break}case 3:{let m=e.chRedir(l,i,!0);a(e,X)[d]=m,d!=m&&(console.info(`NS5R CH${d+1} receives from CH${m+1}.`),e.buildRchTree());break}case 7:{a(e,D)[d]=l,e.dispatchEvent("voice",{part:d});break}case 8:{a(e,M)[d*g.rpn+3]=l<40||l>88?l+(l>63?-192:64):l,a(e,L)[g.rpnt*d+2]=1;break}case 9:case 10:{a(e,u)[$+p[7]]=l;break}case 11:{a(e,u)[$+p[11]]=l;break}case 14:{a(e,u)[$+p[10]]=l||128;break}case 19:{a(e,u)[$+p[93]]=l;break}case 20:{a(e,u)[$+p[91]]=l;break}case 84:{a(e,u)[$+p[65]]=l;break}case 85:{a(e,u)[$+p[5]]=l;break}}break}case o<3096:break;case o<3134:{let d=o-3096;d<8?(l>31&&(c+=String.fromCharCode(l)),d==7&&(e.aiEfxName=c)):d<10&&(e.setEffectType(d-8,44,l),e.dispatchEvent(`efx${["reverb","chorus"][d-8]}`,e.getEffectType(d-8)));break}case o<8566:break}})}).add([66,54],(t,i)=>{e.switchMode("ns5r",!0);let c="",n=80,s=0,f=0,l="MSB\tPRG\tLSB\tNME";ce(t,function(o,d){let $=d%158;switch(!0){case $<10:{o>31&&(c+=String.fromCharCode(o));break}case $==10:break;case $==11:{n=o&127;break}case $==12:{f=o&127;break}case $==13:{l+=` -${n} ${s} ${f} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(l),O()&&console.debug(l),e.forceVoiceRefresh()}).add([66,55],(t,i)=>{e.switchMode("ns5r",!0);let c="",n=88,s=0,f=0,l="MSB\tPRG\tLSB\tNME";ce(t,function(o,d){let $=d%126;switch(!0){case $<10:{o>31&&(c+=String.fromCharCode(o));break}case $==11:break;case $==12:break;case $==13:{l+=` -${n} ${s} ${f} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(l),O()&&console.debug(l),e.forceVoiceRefresh()}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let i=t[t.length-1],c=t.subarray(0,t.length-1),n=Me(c);n!=i&&(console.info(`NS5R screen dump checksum mismatch! Expected ${n}, got ${i}.`),console.debug(t));let s=new Uint8Array(5760);ce(t,(f,l,o)=>{if(l<720)for(let d=0;d<8;d++)s[l*8+d]=f>>7-d&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(t,i,c)=>{a(e,$e).run([66,...t],i,c)}),a(this,Ne).add([16,0,8,0],(t,i,c)=>{let n=(t[2]<<4)+t[3],s="K11 ";([()=>{e.switchMode("k11",!0),w(e,N,!1),w(e,ee,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}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,i,c)=>{let n=e.chRedir(t[1],i,!0),s=g.cc*n,f=g.rpn*n,l=(t[3]<<4)+t[4],o=`K11 CH${n+1} `;([()=>{l<128?(e.setChType(n,e.CH_MELODIC,C.k11),a(e,u)[s+p[0]]=0,a(e,U)[n]=l):(e.setChType(n,e.CH_DRUMS,C.k11),a(e,U)[n]=l-128),e.dispatchEvent("voice",{part:n})},()=>{let d=e.chRedir(l,i,!0);a(e,X)[n]=d,n!=d&&(e.buildRchTree(),console.info(`${o}receives from CH${d+1}`))},()=>{a(e,u)[s+p[7]]=l},()=>{uupThis.setChActive(n,l)},()=>{a(e,u)[s+p[10]]=l},()=>{a(e,M)[f+3]=l+40,a(e,L)[g.rpnt*n+2]=1},()=>{a(e,M)[f+1]=l>>1,a(e,M)[f+2]=l&1,a(e,L)[g.rpnt*n+1]=1},()=>{a(e,u)[s+p[91]]=l?127:0},()=>{},()=>{a(e,u)[s+p[74]]=l},()=>{a(e,u)[s+p[73]]=l},()=>{a(e,u)[s+p[72]]=l}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,i,c)=>{let n=(t[2]<<4)+t[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}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,i,c)=>{let n=(t[2]<<4)+t[3],s=e.chRedir(t[1],i,!0),f=s*g.cc;[()=>{n<128?(e.setChType(s,e.CH_MELODIC,C.k11),a(e,u)[f+p[0]]=0,a(e,u)[f+p[32]]=0,a(e,U)[s]=n):n<160?(e.setChType(s,e.CH_MELODIC,C.k11),a(e,u)[f+p[0]]=0,a(e,u)[f+p[32]]=7,a(e,U)[s]=n-100):(e.setChType(s,e.CH_DRUMS,C.k11),a(e,u)[f+p[0]]=122,a(e,u)[f+p[32]]=0,a(e,U)[s]=n-160),e.dispatchEvent("voice",{part:s})},()=>{let l=e.chRedir(n,i,!0);a(e,X)[s]=l,s!=l&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${l+1}`))}][t[0]]()}).add([16,0,9,4],(t,i,c)=>{let n=(t[2]<<4)+t[3],s=e.chRedir(t[1],i,!0),f=s*g.cc,l=s*g.rpn,o=`GMLX CH${s+1} `;[()=>{e.setChActive(s,n)},()=>{a(e,u)[f+p[7]]=n},()=>{a(e,u)[f+p[10]]=n},()=>{a(e,u)[f+p[91]]=n?127:0},()=>{a(e,M)[l+3]=n+40,a(e,L)[g.rpnt*s+2]=1},()=>{a(e,M)[l+1]=n,a(e,L)[g.rpnt*s+1]=1},()=>{a(e,M)[l]=n,a(e,L)[g.rpnt*s]=1},()=>{}][t[0]]()}),a(this,Be).add([66,93,64],(t,i,c)=>{let n=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{w(e,P,n*129/16383*100),e.dispatchEvent("mastervolume",a(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(t[1]){case 48:{console.debug(`SG reverb type: ${lt[n]}`);break}}break}default:if(t[0]>>4==1){let s=e.chRedir(t[0]&15,i,!0);if(t[1]==2){let f=e.chRedir(n,i,!0);a(e,X)[s]=f,s!=f&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${f+1}`))}else t[1]==19&&(a(e,u)[g.cc*s+p[7]]=n)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),a(this,He).add([9],(t,i,c)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)}),a(this,te).add([127,0],(t,i,c)=>{e.switchMode("motif");let n=new Uint8Array([127,1,...t]);a(e,te).run(n,i,c)}).add([127,1,0,0],(t,i,c)=>{e.switchMode("s90es");let n="S90/Motif ES system ",s=t[0];t.subarray(1).forEach((f,l)=>{([()=>{w(e,P,f*12900/16383),e.dispatchEvent("mastervolume",a(e,P))}][s+l]||(()=>{console.info(`Unrecognized ${n}ID: ${s+l}`)}))()})}).add([127,1,0,0,14],(t,i,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk header ",s=[];s[95]=(f,l,o)=>{console.debug(`${n}multi edit buffer: ${f[1]}`)},(s[t[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,0,15],(t,i,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk footer ",s=[];s[95]=(f,l,o)=>{console.debug(`${n}multi edit buffer: ${f[1]}`)},(s[t[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,58,55],(t,i,c)=>{e.switchMode("s90es");let n=e.chRedir(t[0],i,!0),s=g.cc*n,f=t[1],l=`S90/Motif ES bulk CH${n<16?n+1:"U"+(n-95)} `;console.debug(l,t),!(t[0]>15)&&t.subarray(2).forEach((o,d)=>{([()=>{a(e,u)[s+p[0]]=o,e.dispatchEvent("voice",{part:n})},()=>{o&&e.setChActive(n,1),a(e,u)[s+p[32]]=o,e.setChType(n,[32,40].indexOf(o)>-1?e.CH_DRUMS:e.CH_MELODIC,a(e,A),!0),e.dispatchEvent("voice",{part:n})},()=>{o&&e.setChActive(n,1),a(e,U)[n]=o,e.dispatchEvent("voice",{part:n})},()=>{let $=e.chRedir(o,i,!0);a(e,X)[n]=$,n!=$&&(e.buildRchTree(),console.info(`${l}receives from CH${$+1}`))},()=>{a(e,W)[n]=o?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{a(e,u)[s+p[7]]=o},()=>{a(e,u)[s+p[10]]=o},!1,!1,!1,()=>{a(e,u)[s+p[91]]=o},()=>{a(e,u)[s+p[93]]=o},()=>{a(e,u)[s+p[94]]=o},()=>{a(e,u)[s+p[128]]=o},()=>{},()=>{a(e,u)[s+p[74]]=o},()=>{a(e,u)[s+p[71]]=o},!1,()=>{a(e,u)[s+p[65]]=o},()=>{a(e,u)[s+p[5]]=o},()=>{}][f+d]||(()=>{}))()})}).add([127,1,54,16],(t,i,c)=>{e.switchMode("s90es");let n=t[0];t.subarray(1).forEach((s,f)=>{let o=`S90/Motif ES EQ${(f>>2)+1} `;([()=>{let d=s-64},()=>{let d=Ge[s]},()=>{let d=s/10},()=>{let d=s}][n+f&3]||(()=>{}))()})}),a(this,ae).add([0,72,18,0,0,0,0],(t,i,c)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(t,i,c)=>{let n=t[0]>>5,s=t[0]&31;switch(n){case 0:{let f=t[0]>>1,l=t[1];switch(f){case 1:{t.subarray(2).forEach((o,d,$)=>{let m=d+l;switch(m){case 0:{o&&(e.setEffectType(1,60,o-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${m} - ${o}`));break}}});break}case 2:{t.subarray(2).forEach((o,d)=>{let $=d+l;switch($){case 0:{o&&(e.setEffectType(0,55+o,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${$} - ${o}`));break}}});break}case 3:case 4:case 5:{let o=f-1;t.subarray(2).forEach((d,$)=>{let m=$+l;switch(console.debug(`SD MFX ${o-2}: ${m} - ${d}`),m){case 0:{e.setEffectTypeRaw(o,62,d),e.dispatchEvent(`efx${o>2?"delay":"insert"+(o-4)}`,e.getEffectType(o));break}}}),console.debug(`SD MFX message: +`),t.slice(0,2)){case"@I":{w(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(s=t.slice(2))==null?void 0:s.trimLeft()});break}case"@K":{w(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(c=t.slice(2))==null?void 0:c.trimLeft()}),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{w(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(n=t.slice(2))==null?void 0:n.trimLeft()});break}case"@T":{w(this,N,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(i=t.slice(2))==null?void 0:i.trimLeft()});break}case"@V":{w(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(d=t.slice(2))==null?void 0:d.trimLeft()});break}case"XF":{let l=t.slice(2).split(":");switch(l[0]){case"hd":{l.slice(1).forEach((o,f)=>{o.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][f],data:o})});break}case"ln":{l.slice(1).forEach((o,f)=>{o.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][f],data:o})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:t})}break}default:a(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((l,o)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:l,mask:o!=0})})}},a(e,F)[2]=function(t){this.dispatchEvent("metacommit",{type:"Copyrite",data:t})},a(e,F)[3]=function(t,s){s<1&&a(this,Oe)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:t})},a(e,F)[4]=function(t,s){this.dispatchEvent("metacommit",{type:"Instrmnt",data:t})},a(e,F)[5]=function(t){t.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:t,amend:!0})},a(e,F)[6]=function(t){this.dispatchEvent("metacommit",{type:"C.Marker",data:t})},a(e,F)[7]=function(t){this.dispatchEvent("metacommit",{type:"CuePoint",data:t})},a(e,F)[32]=function(t){w(this,Oe,t[0]+1)},a(e,F)[33]=function(t,s){a(e,Ce)[s]=t+1},a(e,F)[81]=function(t,s){w(e,Fe,t/1e3)},a(e,F)[127]=function(t,s){a(e,Le).run(t,s)},a(e,Le).default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},a(e,Le).add([67,0,1],function(t,s){a(e,Ce)[s]=t[0]+1}),w(e,Ue,new ie("universal non-realtime")),w(e,Pe,new ie("universal realtime")),w(e,ee,new ie("Yamaha")),w(e,se,new ie("Roland")),w(e,$e,new ie("Korg")),w(e,Ne,new ie("Kawai")),w(e,Be,new ie("Akai")),w(e,He,new ie("Casio"));let r=new ie("DX7+ Dump"),h=function(t){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,t)};a(e,Ue).default=h,a(e,Pe).default=h,a(e,ee).default=h,a(e,se).default=h,a(e,$e).default=h,a(e,Ne).default=h,a(e,Be).default=h,a(e,He).default=h,r.default=h,a(e,Ue).add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),w(e,N,a(e,N)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),a(e,Pe).add([4,1],t=>{w(e,P,((t[1]<<7)+t[0])/16383*100),e.dispatchEvent("mastervolume",a(e,P))}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64).add([4,5],t=>{let s=t[0],c=t[1],n=t[2],i=3,d=i+(s<<1),l=d+c;if(s!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${s})! +`,t);return}let o=0,f=0,$=0;switch(t.subarray(i,d).forEach(v=>{o=o<<7,o|=v}),t.subarray(d,l).forEach((v,T)=>{f|=v<{$|=v<{switch(t[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${t}`);break}case 126:{e.switchMode("xg",!0),w(e,N,!1),console.info("MIDI reset: XG");break}default:{let s=[0,0,0,0],c=(n,i)=>{s[i]=n};if(t.subarray(1).forEach((n,i)=>{let d=i+t[0];([c,c,c,c,l=>{w(this,P,l*129/16383*100),e.dispatchEvent("mastervolume",a(e,P))},l=>{},l=>{}][d]||(()=>{}))(n,i)}),t[0]<4){let n=0;s.forEach(i=>{n=n<<4,n+=i}),n-=1024}}}}).add([76,2,1],t=>{let s="XG ";t[0]<32?(s+="reverb ",t.subarray(1).forEach((c,n)=>{([i=>{e.setEffectTypeRaw(0,!1,i),console.info(`${s}main type: ${qe[i]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},i=>{e.setEffectTypeRaw(0,!0,i),console.debug(`${s}sub type: ${i+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},i=>{console.debug(`${s}time: ${kt(i)}s`)},i=>{console.debug(`${s}diffusion: ${i}`)},i=>{console.debug(`${s}initial delay: ${i}`)},i=>{console.debug(`${s}HPF cutoff: ${Ge[i]}Hz`)},i=>{console.debug(`${s}LPF cutoff: ${Ge[i]}Hz`)},i=>{console.debug(`${s}width: ${i}`)},i=>{console.debug(`${s}height: ${i}`)},i=>{console.debug(`${s}depth: ${i}`)},i=>{console.debug(`${s}wall type: ${i}`)},i=>{console.debug(`${s}dry/wet: ${i}`)},i=>{console.debug(`${s}send: ${Y(i)}dB`)},i=>{console.debug(`${s}pan: ${i-64}`)},!1,!1,i=>{console.debug(`${s}delay: ${i}`)},i=>{console.debug(`${s}density: ${i}`)},i=>{console.debug(`${s}balance: ${i}`)},i=>{},i=>{console.debug(`${s}feedback: ${i}`)},i=>{}][t[0]+n]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(c)})):t[0]<64?(s+="chorus ",t.subarray(1).forEach((c,n)=>{([i=>{e.setEffectTypeRaw(1,!1,i),console.info(`${s}main type: ${qe[i]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},i=>{e.setEffectTypeRaw(1,!0,i),console.debug(`${s}sub type: ${i+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},i=>{console.debug(`${s}LFO: ${wt[i]}Hz`)},i=>{},i=>{console.debug(`${s}feedback: ${i}`)},i=>{console.debug(`${s}delay offset: ${St(i)}ms`)},i=>{},i=>{console.debug(`${s}low: ${Ge[i]}Hz`)},i=>{console.debug(`${s}low: ${i-64}dB`)},i=>{console.debug(`${s}high: ${Ge[i]}Hz`)},i=>{console.debug(`${s}high: ${i-64}dB`)},i=>{console.debug(`${s}dry/wet: ${i}`)},i=>{console.debug(`${s}send: ${Y(i)}dB`)},i=>{console.debug(`${s}pan: ${i-64}`)},i=>{console.debug(`${s}to reverb: ${Y(i)}dB`)},!1,i=>{},i=>{},i=>{},i=>{console.debug(`${s}LFO phase diff: ${(i-64)*3}deg`)},i=>{console.debug(`${s}input mode: ${i?"stereo":"mono"}`)},i=>{}][t[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(c)})):t[0]<86?(s+="variation ",t.subarray(1).forEach((c,n)=>{([i=>{e.setEffectTypeRaw(2,!1,i),console.info(`${s}main type: ${qe[i]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},i=>{e.setEffectTypeRaw(2,!0,i),console.debug(`${s}sub type: ${i+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][t[0]-64+n]||function(){})(c)})):t[0]<97?(s+="variation ",t.subarray(1).forEach((c,n)=>{[i=>{console.debug(`${s}send: ${Y(i)}dB`)},i=>{console.debug(`${s}pan: ${i-64}`)},i=>{console.debug(`${s}to reverb: ${Y(i)}dB`)},i=>{console.debug(`${s}to chorus: ${Y(i)}dB`)},i=>{console.debug(`${s}connection: ${i?"system":"insertion"}`)},i=>{console.debug(`${s}channel: CH${i+1}`)},i=>{console.debug(`${s}mod wheel: ${i-64}`)},i=>{console.debug(`${s}bend wheel: ${i-64}`)},i=>{console.debug(`${s}channel after touch: ${i-64}`)},i=>{console.debug(`${s}AC1: ${i-64}`)},i=>{console.debug(`${s}AC2: ${i-64}`)}][t[0]-86+n](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 n=c+t[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][s]}`);else{let i=n-1>>2,d=n-1&3,l=`XG EQ ${i} ${["gain","freq","Q","shape"][d]}: `;[()=>{console.debug(`${l}${s-64}dB`)},()=>{console.debug(`${l}${s} (raw)`)},()=>{console.debug(`${l}${s/10}`)},()=>{console.debug(`${l}${["shelf","peak"][+!!s]}`)}][d]()}})}).add([76,3],t=>{let s=t[0],c=t[1],n=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((i,d)=>{([l=>{e.setEffectTypeRaw(3+s,!1,l),console.info(`${n}main type: ${qe[l]}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))},l=>{e.setEffectTypeRaw(3+s,!0,l),console.debug(`${n}sub type: ${l+1}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))}][c+d]||function(){})(i)})}).add([76,6,0],t=>{let s=t[0];s<64?e.setLetterDisplay(t.subarray(1),"XG letter display",s):w(e,xe,Date.now())}).add([76,7,0],t=>{let s=t[0];w(e,z,0),w(e,he,Date.now()+3200),a(e,te,pe).fill(0);let c=t.subarray(1);for(let n=0;n>6-$&1,$++})}).add([76,8],(t,s)=>{let c=e.chRedir(t[0],s,!0),n=t[1],i=y.cc*c,d=`XG CH${c+1} `,l=`Unknown XG part address ${n}.`;t.subarray(2).forEach((o,f)=>{n<1?console.debug(l):n<41?([()=>{a(e,u)[i+p[0]]=o,e.dispatchEvent("voice",{part:c})},()=>{a(e,u)[i+p[32]]=o,e.dispatchEvent("voice",{part:c})},()=>{a(e,U)[c]=o,e.dispatchEvent("voice",{part:c})},()=>{let $=e.chRedir(o,s,!0);a(e,X)[c]=$,c!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))},()=>{a(e,W)[c]=+!o},()=>{},()=>{e.setChType(c,o,C.xg),console.debug(`${d}type: ${Ye[o]||o}`)},()=>{a(e,M)[y.rpn*c+3]=o,a(e,A)[y.rpnt*c+2]=1},!1,!1,()=>{a(e,u)[i+p[7]]=o},!1,!1,()=>{a(e,u)[i+p[10]]=o||128},!1,!1,()=>{a(e,u)[i+p[128]]=o},()=>{a(e,u)[i+p[93]]=o},()=>{a(e,u)[i+p[91]]=o},()=>{a(e,u)[i+p[94]]=o},()=>{a(e,u)[i+p[76]]=o},()=>{a(e,u)[i+p[77]]=o},()=>{a(e,u)[i+p[78]]=o},()=>{a(e,u)[i+p[74]]=o},()=>{a(e,u)[i+p[71]]=o},()=>{a(e,u)[i+p[73]]=o},()=>{a(e,u)[i+p[75]]=o},()=>{a(e,u)[i+p[72]]=o}][n+f-1]||(()=>{}))():n<48?console.debug(l):n<111?n>102&&n<105&&(a(e,u)[i+p[[5,65][n&1]]]=o):n<114?console.debug(l):n<116?console.debug(`${d}EQ ${["bass","treble"][n&1]} gain: ${o-64}dB`):n<118?console.debug(l):n<120?console.debug(`${d}EQ ${["bass","treble"][n&1]} freq: ${o}`):console.debug(l)})}).add([76,9],(t,s)=>{let c=e.chRedir(t[0],s,!0),n=t[1],i=y.cc*c,d=`PLG-VL CH${c+1} `;t.subarray(2).forEach((l,o)=>{let f=o+n;switch(f){case 1:{console.info(`${d}breath mode: ${["system","breath","velocity","touch EG"][l]}`);break}case 0:case 27:case 28:break;default:if(f<27){let $=f-3>>1,v=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][$];f&1?f<23?(console.debug(`${d}${v} control source: ${Mt(l)}`),l&&l<96&&e.allocateAce(130+$),a(e,De)[y.redir*c+$+2]=l,e.buildRccMap()):console.debug(`${d}${v} scale break point: ${l}`):(console.debug(`${d}${v} depth: ${l-64}`),a(e,u)[i+p[130+$]]=l)}}})}).add([76,10],t=>{}).add([76,16],t=>{}).add([76,17,0,0],t=>{}).add([76,112],t=>{switch(console.debug(`XG enable PLG-${["VL","SG","DX","AN","PF","DR","PC","AP"][t[0]]} for CH${t[2]+1}.`),t[0]){case 0:{a(e,J)[y.ext*t[2]]=e.EXT_VL;break}case 2:{a(e,J)[y.ext*t[2]]=e.EXT_DX;break}default:a(e,J)[y.ext*t[2]]=e.EXT_NONE}}).add([73,0,0],(t,s)=>{let c=t[0],n="MU1000 System: ";t.subarray(1).forEach((i,d)=>{let l=c+d;l==8?console.debug(`${n}LCD contrast set to ${i}.`):l==18?(w(e,re,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")},()=>{w(e,le,!!i),console.info(`Octavia System: RS receiving ${["dis","en"][i]}abled.`)}][l-64]()})}).add([73,10,0],(t,s)=>{let c=t[0],n=`MU1000 RS${a(e,le)?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let i=e.chRedir(0,s,!0);a(e,le)&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+63)),console.info(`${n}Show CH1~64`);break}case 3:{let i=e.chRedir(t[1]<<5,s,!0);a(e,le)&&e.dispatchEvent("channelmin",i),a(e,le)&&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(a(e,le)){let i=e.chRedir(c-16+(a(e,ze)<<4),s,!0);e.dispatchEvent("channelactive",i)}}else if(c<36){let i=e.chRedir(c-32<<4,s,!0);a(e,le)&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+15),w(e,ze,c-32)),console.info(`${n}Show CH${i+1}~CH${i+16}`)}}).add([93,3],(t,s)=>{let c=e.chRedir(t[0],s,!0),n=`PLG-100SG CH${c+1} `,i=Date.now();if(t[1]==0){let d="",l=0;t.subarray(2).forEach((o,f)=>{f%2==0?d+=xt[o]||o.toString().padStart("0"):l+=o*13}),i>=a(e,Ke)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${Ct(d)}`,amend:!0}),w(e,Ke,i+Math.ceil(l/2)+a(e,Fe)),O()&&console.debug(`${n}vocals: ${d}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}).add([98,0],(t,s,c)=>{let n=t[0],i=t.length-5,d=t.length-1;if(n!=i){console.info(`PLG-DX native dump size mismatch! Gave ${n} instead of ${t.length-5}.`);return}let l=ve(t.subarray(4,d));if(l!=t[d]){console.info(`Bad PLG-DX checksum ${t[d]} - should be ${l}.`);return}t[0]=98,a(e,ee).run(t.subarray(0,d),s,c,{noAce:!0})}).add([98,96],(t,s,c,n)=>{let i=e.chRedir(t[0],s,!0),d=y.cc*i,l=t[1];t.subarray(2).forEach((o,f)=>{let $=l+f;if(!($<10)){if($==10)e.resetAce();else if($<27){let v=$+131;n!=null&&n.noAce||e.allocateAce(v),a(e,u)[d+p[v]]=o,e.dispatchEvent("cc",{part:i,cc:v,data:o})}}})}).add([100,0],(t,s,c)=>{let n=t.subarray(0,t.length-1);if(t[0]+5!=t.length){console.warn(`Yamaha DX7+ dump SysEx size mismatch! Expected ${t.length}, but got ${t[0]}: +`,t);return}let i=ve(n),d=t[t.length-1];if(i!=d){console.warn(`Yamaha DX7+ dump SysEx checksum mismatch! Expected ${i}, but got ${d}: +`,t);return}r.run(n.subarray(1))}).add([100,76],(t,s,c)=>{let n=t[0]>>4,i=t[0]&15,d=t[1];switch(n){case 2:{let l=e.chRedir(i,s,!0),o=y.cc*l;t.subarray(2).forEach((f,$)=>{let v=$+d;if(!(v<7)){if(v<23){let T=v+135;e.allocateAce(T),a(e,u)[o+p[T]]=f,e.dispatchEvent("cc",{part:l,cc:T,data:f})}}});break}default:console.info("Unknown DX7+ multipart: %o",t)}}),r.add([14,31],t=>{a(e,u)[y.cc*t[0]+p[64]]=0,a(e,_).ano(t[0]),e.switchMode("xg"),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${t[0]+1}.`)}).add([76,112],async t=>{let s=t[0],c=y.cc*s,n=y.ext*s,i=y.cvn*s;a(e,J)[n]=e.EXT_DX,a(e,ce)[s]=1;let d=a(e,je).subarray(i,i+y.cvn);d.fill(32),t.subarray(1).forEach((l,o)=>{if(o<10)d[o]=Math.max(l,32);else if(!(o<40)){if(o<56){let f=o+102;a(e,u)[c+p[f]]=l,e.dispatchEvent("cc",{part:s,cc:f,data:l})}}}),a(e,U)[s]=s&127,a(e,u)[y.cc*s+p[0]]=35,a(e,u)[y.cc*s+p[32]]=s>>7|4,e.dispatchEvent("voice",{part:s}),console.debug(`DX7+ CH${s+1} dump: %o`,t)});let b=function(t,s,c,n){},g=function(t,s){let c=t*y.dpn,n=s[0],i=s[1];s.subarray(2).forEach((d,l)=>{let o=l+i,f=-1;o<16?([()=>{f=24},()=>{f=25},()=>{f=26},()=>{},()=>{f=28},()=>{f=29},()=>{f=30},()=>{f=31},()=>{},()=>{},()=>{},()=>{f=20},()=>{f=21},()=>{f=22},()=>{f=23},()=>{}][o]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${t+1}.`)}))():o<32||(o<40?([()=>{f=48},()=>{f=49},!1,!1,()=>{f=52},()=>{f=53}][o-32]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${t+1}.`)}))():o<80||([()=>{f=36}][o-80]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${t+1}.`)}))()),f>=0?(O()&&console.debug(c,f,n,d),a(e,Q)[(c+ne[f])*y.dnc+n]=d):O()&&console.debug(`XG-style drum param ${o} has no writes.`)})},S=function(t,s,c){let n=t*y.dpn,i=(s<<7)+c[0];c.subarray(1).forEach((d,l)=>{let o=l+i,f=o&127,$=o>>7,v=-1;$>1&&([()=>{v=26},()=>{},()=>{v=28},()=>{v=29},()=>{v=30},()=>{},()=>{},()=>{v=31}][$-2]||(()=>{console.debug(`Unknown GS-style drum param ${$} on set ${t+1}.`)}))(),v>-1?(O()&&console.debug(n,v,f,d),a(e,Q)[(n+ne[v])*y.dnc+f]=d):O()&&console.debug(`GS-style drum param ${$} has no writes.`)})};a(this,ee).add([76,48],(t,s,c)=>{g(0,t)}).add([76,49],(t,s,c)=>{g(1,t)}).add([76,50],(t,s,c)=>{g(2,t)}).add([76,51],(t,s,c)=>{g(3,t)}).add([76,52],(t,s,c)=>{g(4,t)}).add([76,53],(t,s,c)=>{g(5,t)}).add([76,54],(t,s,c)=>{g(6,t)}).add([76,55],(t,s,c)=>{g(7,t)}),a(this,ee).add([89,0],(t,s,c)=>{if(e.eprom){let n=t[0],i=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);O()&&console.debug(`MU1000 EPROM trail to 0x${i.toString(16).padStart(6,"0")}, ${n} bytes.`);let d=e.eprom.data;t.subarray(4).forEach((l,o)=>{let f=o>>3,$=o&7;if($==7)for(let v=0;v<7;v++)d[i+7*f+v]+=(l>>6-v&1)<<7;else d[i+7*f+$]=l})}}).add([89,1],(t,s,c)=>{let n=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];O()&&console.debug(`MU1000 EPROM jump to 0x${n.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=n)}).add([89,2],(t,s,c)=>{if(e.eprom){let n=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);O()&&console.debug(`MU1000 EPROM write to 0x${n.toString(16).padStart(6,"0")}.`);let i=e.eprom.data;t.subarray(4).forEach((d,l)=>{let o=l>>3,f=l&7;if(f==7)for(let $=0;$<7;$++)i[n+7*o+$]+=(d>>6-$&1)<<7;else i[n+7*o+f]=d})}}).add([89,3],(t,s,c)=>{}),a(this,ee).add([39,48],(t,s,c)=>{}).add([43,0,0],(t,s,c)=>{let n=[0,0,0,0],i=(d,l)=>{n[l]=d};if(t.subarray(1).forEach((d,l)=>{let o=l+t[0];[i,i,i,i,()=>{w(this,P,d*129/16383*100),e.dispatchEvent("mastervolume",a(e,P))},()=>d-64,()=>d||128,()=>d,()=>d,()=>{console.debug(`TG300 variation on cc${d}.`)}][o](d,o)}),t[0]<4){let d=0;n.forEach(l=>{d=d<<4,d+=l}),d-=1024}}).add([43,1,0],(t,s,c)=>{}).add([43,2],(t,s,c)=>{let n=e.chRedir(t[0],s,!0),i=t[1],d=y.cc*n,l=`TG300 CH${n+1} `;t.subarray(2).forEach((o,f)=>{f<5?([()=>{},()=>{a(e,u)[d+p[0]]=o,e.dispatchEvent("voice",{part:n})},()=>{a(e,u)[d+p[32]]=o,e.dispatchEvent("voice",{part:n})},()=>{a(e,U)[n]=o,e.dispatchEvent("voice",{part:n})},()=>{let $=e.chRedir(o,s,!0);a(e,X)[n]=$,n!=$&&(e.buildRchTree(),console.info(`${l}receives from CH${$+1}`))}][f+i]||(()=>{}))(o,f+i):f<21||(f<47?([()=>{a(e,W)[n]=+!o},()=>{},()=>{},()=>{a(e,M)[y.rpn*n+3]=o,a(e,A)[y.rpnt*n+2]=1},()=>{},()=>{a(e,u)[d+p[7]]=o},!1,!1,()=>{a(e,u)[d+p[10]]=o||128},!1,!1,()=>{console.debug(`${l} AC1 at cc${o}`)},()=>{console.debug(`${l} AC2 at cc${o}`)},()=>{a(e,u)[d+p[128]]=o},()=>{a(e,u)[d+p[93]]=o},()=>{a(e,u)[d+p[91]]=o},()=>{a(e,u)[d+p[94]]=o},()=>{a(e,u)[d+p[76]]=o},()=>{a(e,u)[d+p[77]]=o},()=>{a(e,u)[d+p[74]]=o},()=>{a(e,u)[d+p[71]]=o},()=>{a(e,u)[d+p[73]]=o},()=>{a(e,u)[d+p[75]]=o},()=>{a(e,u)[d+p[72]]=o},()=>{a(e,u)[d+p[78]]=o}][f+i-21]||(()=>{}))(o,f+i):f<95||([()=>{a(e,u)[d+p[65]]=o},()=>{a(e,u)[d+p[5]]=o}][f+i-95]||(()=>{}))(o,f+i))})}).add([43,7,0],(t,s,c)=>{let n=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",n)}).add([43,7,1],(t,s,c)=>{w(e,z,0),w(e,he,Date.now()+3200),a(e,te,pe).fill(0),t.forEach(function(n,i){let d=Math.floor(i/16),l=i%16,o=(l*3+d)*7,f=7,$=0;for(o-=l*5,d==2&&(f=2);$>6-$&1,$++})}),a(this,se).add([66,18,0,0,127],(t,s,c)=>{e.switchMode("gs",!0),a(e,u)[y.cc*9]=120,a(e,u)[y.cc*25]=120,a(e,u)[y.cc*41]=120,a(e,u)[y.cc*57]=120,w(e,re,3),w(e,N,!1),a(e,Ee).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),a(e,u)[y.cc*9]=120,a(e,u)[y.cc*25]=120,a(e,u)[y.cc*41]=120,a(e,u)[y.cc*57]=120,w(e,N,!1),a(e,Ee).fill(0),console.info("MIDI reset: GS");break}default:{let n=[0,0,0,0],i=(d,l)=>{n[l]=d};if(t.subarray(1).forEach((d,l)=>{let o=l+t[0];[i,i,i,i,f=>{w(this,P,f*129/16383*100),e.dispatchEvent("mastervolume",a(e,P))},f=>{},f=>{}][o](d,l)}),t[0]<4){let d=0;n.forEach(l=>{d=d<<4,d+=l}),d-=1024}}}}).add([66,18,64,1],t=>{let s=t[0];if(s<16){let c="".padStart(s," ");t.subarray(1).forEach((n,i)=>{c+=String.fromCharCode(Math.max(32,n))}),c=c.padEnd(16," "),console.debug(`GS patch name: ${c}`)}else s<48||(s<65?t.subarray(1).forEach((c,n)=>{let i=`GS ${s+n>55?"chorus":"reverb"} `;([()=>{console.info(`${i}type: ${ft[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${i}predelay: ${c}ms`)},()=>{console.info(`${i}type: ${Tt[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${i}to reverb: ${Y(c)}`)},()=>{console.debug(`${i}to delay: ${Y(c)}`)}][s+n-48]||(()=>{}))()}):s<80?console.debug(`Unknown GS patch address: ${s}`):s<91?t.subarray(1).forEach((c,n)=>{let i="GS delay ";([()=>{console.info(`${i}type: ${Rt[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${i}to reverb: ${Y(c)}`)}][s+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${s}`))}).add([66,18,64,2],t=>{let s="GS EQ ";t.subarray(1).forEach((c,n)=>{([()=>{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]+n]||function(){console.warn(`Unknown GS EQ address: ${t[0]+n}`)})()})}).add([66,18,64,3],t=>{let s="GS EFX ",c=function(n,i){let d=Dt(a(e,Z).subarray(10,12),i,n);d&&console.debug(`${s}${dt(a(e,Z).subarray(10,12))} ${d}`)};t.subarray(1).forEach((n,i)=>{([()=>{e.setEffectTypeRaw(3,!1,32+n),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,n),console.info(`${s}type: ${dt(a(e,Z).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: ${Y(n)}dB`)},()=>{console.debug(`${s}to chorus: ${Y(n)}dB`)},()=>{console.debug(`${s}to delay: ${Y(n)}dB`)},!1,()=>{console.debug(`${s}1 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${s}1 depth: ${n-64}`)},()=>{console.debug(`${s}2 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${s}2 depth: ${n-64}`)},()=>{console.debug(`${s}to EQ: ${n?"ON":"OFF"}`)}][t[0]+i]||function(d,l){console.warn(`Unknown GS EFX address: ${l}`)})(n,t[0]+i)})}).add([66,18,65],t=>{S((t[0]>>4)+1<<1,t[0]&15,t.subarray(1))}).add([69,18,16],t=>{var s;switch(t[0]){case 0:{let c=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",c);break}case 32:{w(e,he,Date.now()+3200),t[1]==0&&(w(e,z,Math.max(Math.min(t[2]-1,9),0)),O()&&console.debug(`GS switch display page ${t[2]-1}.`));break}default:if(t[0]<6){a(e,z)>9&&w(e,z,0);let c=t[0]-1<<1|t[1]>>6;a(e,z)==c&&w(e,he,Date.now()+3200),(s=a(e,be)[c])!=null&&s.length||(a(e,be)[c]=new Uint8Array(256));let n=a(e,be)[c];O()&&console.debug(`GS frame draw page ${c}.`);let i=t[1]&63;n.fill(0),t.subarray(2).forEach(function(l,o){let f=o+i,$=Math.floor(f/16),v=f%16,T=(v*4+$)*5,B=5,Me=0;for(T-=v*4,$==3&&(B=1);Me>4-Me&1,Me++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let m=function(t,s,c){let n=t[0],i=y.cc*s,d=y.rpn*s,l=`GS CH${s+1} `;n<3?(t.subarray(1).forEach((o,f)=>{[()=>{a(e,u)[i+p[0]]=o},()=>{a(e,U)[s]=o},()=>{let $=0;o<16?$=e.chRedir(o,c,!0):$=y.ch,a(e,X)[s]=$,s!=$&&(e.buildRchTree(),console.info(`${l}receives from CH${$+1}`))}][n+f]()}),e.dispatchEvent("voice",{part:s})):n<19||(n<44?t.subarray(1).forEach((o,f)=>{([()=>{a(e,W)[s]=+!o},!1,()=>{e.setChType(s,o<<1,C.gs),console.debug(`${l}type: ${o?"drum ":"melodic"}${o||""}`)},()=>{a(e,M)[d+3]=o,a(e,A)[y.rpnt*s+2]=1},!1,()=>{a(e,u)[i+p[7]]=o},!1,!1,()=>{a(e,u)[i+p[10]]=o||128},!1,!1,()=>{console.debug(`${l}CC 1: cc${o}`)},()=>{console.debug(`${l}CC 2: cc${o}`)},()=>{a(e,u)[i+p[93]]=o},()=>{a(e,u)[i+p[91]]=o},!1,!1,()=>{a(e,M)[d+1]=o,a(e,A)[y.rpnt*s+1]=1},()=>{a(e,M)[d+2]=o,a(e,A)[y.rpnt*s+1]=1},()=>{a(e,u)[i+p[94]]=o}][n+f-19]||(()=>{}))()}):n<76||console.debug(`Unknown GS part address: ${n}`))},k=function(t,s){let c=t[0],n=`GS CH${s+1} `;c<2?t.subarray(1).forEach((i,d)=>{[()=>{a(e,u)[y.cc*s+p[32]]=i},()=>{}][c+d]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?t.subarray(1).forEach((i,d)=>{[()=>{console.debug(`${n}EQ: o${["ff","n"][i]}`)},()=>{},()=>{console.debug(`${n}EFX: o${["ff","n"][i]}`),a(e,Xe)[s]=i,e.dispatchEvent("partefxtoggle",{part:s,active:i})}][c+d-32]()}):console.warn(`Unknown GS misc address: ${c}`)};a(this,se).add([66,18,64,16],(t,s)=>{m(t,e.chRedir(9,s,!0),s)}).add([66,18,64,17],(t,s)=>{m(t,e.chRedir(0,s,!0),s)}).add([66,18,64,18],(t,s)=>{m(t,e.chRedir(1,s,!0),s)}).add([66,18,64,19],(t,s)=>{m(t,e.chRedir(2,s,!0),s)}).add([66,18,64,20],(t,s)=>{m(t,e.chRedir(3,s,!0),s)}).add([66,18,64,21],(t,s)=>{m(t,e.chRedir(4,s,!0),s)}).add([66,18,64,22],(t,s)=>{m(t,e.chRedir(5,s,!0),s)}).add([66,18,64,23],(t,s)=>{m(t,e.chRedir(6,s,!0),s)}).add([66,18,64,24],(t,s)=>{m(t,e.chRedir(7,s,!0),s)}).add([66,18,64,25],(t,s)=>{m(t,e.chRedir(8,s,!0),s)}).add([66,18,64,26],(t,s)=>{m(t,e.chRedir(10,s,!0),s)}).add([66,18,64,27],(t,s)=>{m(t,e.chRedir(11,s,!0),s)}).add([66,18,64,28],(t,s)=>{m(t,e.chRedir(12,s,!0),s)}).add([66,18,64,29],(t,s)=>{m(t,e.chRedir(13,s,!0),s)}).add([66,18,64,30],(t,s)=>{m(t,e.chRedir(14,s,!0),s)}).add([66,18,64,31],(t,s)=>{m(t,e.chRedir(15,s,!0),s)}).add([66,18,64,64],(t,s)=>{k(t,e.chRedir(9,s,!0))}).add([66,18,64,65],(t,s)=>{k(t,e.chRedir(0,s,!0))}).add([66,18,64,66],(t,s)=>{k(t,e.chRedir(1,s,!0))}).add([66,18,64,67],(t,s)=>{k(t,e.chRedir(2,s,!0))}).add([66,18,64,68],(t,s)=>{k(t,e.chRedir(3,s,!0))}).add([66,18,64,69],(t,s)=>{k(t,e.chRedir(4,s,!0))}).add([66,18,64,70],(t,s)=>{k(t,e.chRedir(5,s,!0))}).add([66,18,64,71],(t,s)=>{k(t,e.chRedir(6,s,!0))}).add([66,18,64,72],(t,s)=>{k(t,e.chRedir(7,s,!0))}).add([66,18,64,73],(t,s)=>{k(t,e.chRedir(8,s,!0))}).add([66,18,64,74],(t,s)=>{k(t,e.chRedir(10,s,!0))}).add([66,18,64,75],(t,s)=>{k(t,e.chRedir(11,s,!0))}).add([66,18,64,76],(t,s)=>{k(t,e.chRedir(12,s,!0))}).add([66,18,64,77],(t,s)=>{k(t,e.chRedir(13,s,!0))}).add([66,18,64,78],(t,s)=>{k(t,e.chRedir(14,s,!0))}).add([66,18,64,79],(t,s)=>{k(t,e.chRedir(15,s,!0))}),a(this,$e).add([54,65],(t,s)=>{e.switchMode("x5d");let c=t[t.length-1],n=t.subarray(0,t.length-1),i=ve(n);i!=c&&(console.info(`X5D multi parameters checksum mismatch! Expected ${i}, got ${c}.`),console.debug(t));let d=(t[1]<<7)+t[0],l=(t[3]<<7)+t[2],o=e.chRedir(d&15,s,!0),f=y.cc*o;[()=>{l<1||(l<101?(e.setChType(o,e.CH_MELODIC,C.x5d),a(e,U)[o]=l-1,a(e,u)[f+p[0]]=a(e,H).x5):l<229?(e.setChType(o,e.CH_MELODIC,C.x5d),a(e,U)[o]=l-101,a(e,u)[f+p[0]]=56):(e.setChType(o,e.CH_DRUMS,C.x5d),a(e,U)[o]=Ht[l-229]||0,a(e,u)[f+p[0]]=62)),e.dispatchEvent("voice",{part:o})},()=>{a(e,u)[f+p[7]]=l},()=>{l<31&&(a(e,u)[f+p[10]]=Math.round((l-15)*4.2+64))},()=>{a(e,u)[f+p[93]]=We(l)},()=>{a(e,u)[f+p[91]]=We(l)},()=>{a(e,M)[o*y.rpn+3]=l>8191?l-16320:64+l,a(e,A)[y.rpnt*o+2]=1},()=>{a(e,M)[o*y.rpn+1]=l>8191?l-16320:64+l,a(e,A)[y.rpnt*o+1]=1},()=>{l>0&&(a(e,M)[o*y.rpn]=l,a(e,A)[y.rpnt*o]=1)},()=>{}][d>>4]()}).add([54,76,0],(t,s)=>{e.switchMode(a(e,H).x5=="81"?"05rw":"x5d",!0);let c="",n=a(e,H).x5,i=0,d=0,l="MSB\tPRG\tLSB\tNME";fe(t,function(o,f){if(f<16400){let $=f%164;switch(!0){case $<10:{o>31&&(c+=String.fromCharCode(o));break}case $==10:break;case $==11:{l+=` +${n} ${i} ${d} ${c.trim().replace("Init Voice","")}`,i++,c="";break}}i>99&&(n=90,i=0)}}),e.userBank.clearRange({msb:a(e,H).x5,prg:[0,99],lsb:0}),e.userBank.load(l),O()&&console.debug(l),e.forceVoiceRefresh()}).add([54,77,0],(t,s)=>{e.switchMode(a(e,H).x5=="81"?"05rw":"x5d",!0);let c="",n=90,i=0,d=0,l="MSB\tPRG\tLSB\tNME";fe(t,function(o,f){if(f<13600){let $=f%136;switch(!0){case $<10:{o>31&&(c+=String.fromCharCode(o));break}case $==11:{l+=` +${n} ${i} ${d} ${c.trim().replace("Init Combi","")}`,i++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(l),O()&&console.debug(l),e.forceVoiceRefresh()}).add([54,78],(t,s)=>{e.switchMode(a(e,H).x5=="81"?"05rw":"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(a(e,H).x5=="81"?"05rw":"x5d",!0),fe(t,(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],(t,s)=>{e.switchMode(a(e,H).x5=="81"?"05rw":"x5d",!0),fe(t,function(c,n,i,d){if(n<192){let l=e.chRedir(Math.floor(n/12),s,!0),o=l*y.cc;switch(n%12){case 0:{c<128?(e.setChType(l,e.CH_MELODIC,C.x5d),a(e,u)[o+p[0]]=a(e,H).x5,a(e,U)[l]=c):(e.setChType(l,e.CH_DRUMS,C.x5d),a(e,u)[o+p[0]]=62,a(e,U)[l]=Ht[c-128]),c>0&&e.setChActive(l,1),e.dispatchEvent("voice",{part:l});break}case 1:{a(e,u)[o+p[7]]=c;break}case 2:{a(e,M)[l*y.rpn+3]=c>127?c-192:64+c,a(e,A)[y.rpnt*l+2]=1;break}case 3:{a(e,M)[l*y.rpn+1]=c>127?c-192:64+c,a(e,A)[y.rpnt*l+1]=1;break}case 4:{c<31&&(a(e,u)[o+p[10]]=Math.round((c-15)*4.2+64));break}case 5:{let f=c>>4,$=c&15;a(e,u)[o+p[91]]=We($),a(e,u)[o+p[93]]=We(f);break}case 10:break;case 11:{let f=e.chRedir(c&15,s,!0),$=c>>4;a(e,X)[l]=c,(f!=l||$)&&(console.info(`X5D Part CH${l+1} receives from CH${f+1}.`),e.buildRchTree())}}}else{let l=e.chRedir(n-192,s,!0)}})}),a(this,se).add([22,18,127],t=>{e.switchMode("mt32",!0),w(e,N,!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 n=e.chRedir(c,s,!0),i=t[1];t.subarray(2).forEach((d,l)=>{let o=l+i;a(e,me)[o+(n-1)*16]=d,([!1,()=>{let f=a(e,me)[n-1<<4];if(f<3){if(a(e,ce)[n]=1,f==2)for(let $=0;${a(e,M)[n*y.rpn+3]=d+40,a(e,A)[y.rpnt*n+2]=1},()=>{a(e,M)[n*y.rpn+1]=d+14,a(e,A)[y.rpnt*n+1]=1},()=>{a(e,M)[n*y.rpn]=d,a(e,A)[y.rpnt*n]=1},!1,()=>{a(e,u)[y.cc*n+p[91]]=d?127:0},!1,()=>{a(e,u)[y.cc*n+p[7]]=d},()=>{a(e,u)[y.cc*n+p[10]]=Math.ceil(d*9.05)}][o]||(()=>{}))()})}).add([22,18,1],(t,s,c)=>{e.switchMode("mt32");let n=c&7;console.debug(`MT-32 slot #${c+1} Drum: ${t}`);let i=t[0]<<7|t[1];t.subarray(2).forEach((d,l)=>{let o=l+i,f=(o>>2)+24,$=o&3,v=n*y.dpn;if(O()&&console.debug(`MT-32 temp drum note ${f} param ${$}: ${d}`),f<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${f}`);return}[()=>{},()=>{a(e,Q)[(v+ne[26])*y.dnc+f]=Math.round(d*1.27)},()=>{a(e,Q)[(v+ne[26])*y.dnc+f]=d*9+1&127},()=>{a(e,Q)[(v+ne[26])*y.dnc+f]=d?127:0}][$]()})}).add([22,18,2],(t,s,c)=>{e.switchMode("mt32");let n=e.chRedir(c,s,!0),i=t[1]+(t[0]<<7);i<10&&(a(e,ce)[n]=1),t.subarray(2).forEach((d,l)=>{let o=l+i;o<14&&(a(e,oe)[(n-1)*y.cmt+o]=d)}),e.dispatchEvent("voice",{part:n})}).add([22,18,3],(t,s,c)=>{e.switchMode("mt32");let n=c&7;if(t[0]){let i=(t[0]-1<<7)+t[1]-16;t.subarray(2).forEach((d,l)=>{let o=l+i,f=(o>>2)+24,$=o&3,v=n*y.dpn;if(O()&&console.debug(`MT-32 dev drum note ${f} param ${$}: ${d}`),f<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${f}`);return}[()=>{},()=>{a(e,Q)[(v+ne[26])*y.dnc+f]=Math.round(d*1.27)},()=>{a(e,Q)[(v+ne[26])*y.dnc+f]=d*9+1&127},()=>{a(e,Q)[(v+ne[26])*y.dnc+f]=d?127:0}][$]()})}else{let i=t[1];t.subarray(2).forEach((d,l)=>{let o=l+i;a(e,me)[o]=d;let f=e.chRedir(1+(o>>4),s,!0),$=o&15;([!1,()=>{let v=a(e,me)[f-1<<4];if(v<3)if(a(e,ce)[f]=1,v==2)for(let T=0;T{a(e,M)[f*y.rpn+3]=d+40,a(e,A)[y.rpnt*f+2]=1},()=>{a(e,M)[f*y.rpn+1]=d+14,a(e,A)[y.rpnt*f+1]=1},()=>{a(e,M)[f*y.rpn]=d,a(e,A)[y.rpnt*f]=1},!1,()=>{a(e,u)[y.cc*f+p[91]]=d?127:0},!1,()=>{a(e,u)[y.cc*f+p[7]]=d},()=>{a(e,u)[y.cc*f+p[10]]=Math.ceil(d*9.05)}][$]||(()=>{}))()})}}).add([22,18,4],(t,s,c)=>{e.switchMode("mt32");let n=t[1]+(t[0]<<7),i=[];t.subarray(2).forEach((d,l)=>{let o=l+n,f=e.chRedir(Math.floor(o/246+1),s,!0),$=o%246;$<14&&(a(e,oe)[(f-1)*y.cmt+$]=d),$<10&&(a(e,ce)[f]=1),i.indexOf(f)<0&&i.push(f)}),i.forEach(d=>{e.dispatchEvent("voice",{part:d})})}).add([22,18,5],(t,s,c)=>{e.switchMode("mt32");let n=(t[0]<<7)+t[1];t.subarray(2).forEach((i,d)=>{let l=n+d,o=Math.floor(l/8),f=l&7,$=o*8;a(e,Ve)[l]=i,([!1,()=>{let v=a(e,Ve)[$];if(v<3){let T="";if(v==2){let Me=y.cmt*o;T=`MT-m:${i.toString().padStart(3,"0")}`}else T=e.baseBank.get(0,i+(v<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:o});let B=`MSB LSB PRG NME +000 127 ${o} ${T}`;e.userBank.load(B,!0)}}][f]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(t,s,c)=>{e.switchMode("mt32");let n=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((i,d)=>{let l=n+d;l>1)*y.cmt+l]=i)}),e.forceVoiceRefresh()}).add([22,18,16],(t,s,c)=>{e.switchMode("mt32");let n=t[1],i=!1,d=function(l,o){a(e,X)[o-12]=l,i=!0};t.subarray(2).forEach((l,o)=>{let f=o+n;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,d,d,d,d,d,d,d,d,d,()=>{w(e,P,l),e.dispatchEvent("mastervolume",a(e,P))}][f]||(()=>{}))(l,o)}),i&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let s=t[1],c=" ".repeat(s);t.subarray(2).forEach(n=>{n>31?c+=String.fromCharCode(n):c+=" "}),w(e,Se,c.padStart(20," ")),w(e,xe,Date.now()+3200)}).add([22,18,82],(t,s)=>{let c=e.chRedir(0,s,!0);for(let n=0;n<16;n++)a(e,_).ano(c+n),n&&n<10&&(a(e,U)[c+n]=ht[n-1]);console.info("MT-32 alt reset complete.")}),a(this,$e).add([66,0],(t,s)=>{e.switchMode("ns5r",!0),w(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,s)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),w(e,N,!1)}).add([66,18,0,0],(t,s)=>{let c=t[0];switch(c){case 124:case 126:case 127:{e.switchMode("ns5r",!0),w(e,N,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${t}`);break}default:if(c<10){let n=[0,0,0,0],i=(d,l)=>{n[l]=d};if(t.subarray(1).forEach((d,l)=>{[i,i,i,i,()=>{w(e,P,d*129/16383*100),e.dispatchEvent("mastervolume",a(e,P))},()=>d-64,()=>d-64,()=>{},()=>{},()=>{}][c+l]()}),t[0]<4){let d=0;n.forEach(l=>{d=d<<4,d+=l}),d-=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),n=c*y.cc,i=t[1],d=`NS5R CH${c+1} `;t.subarray(2).forEach((l,o)=>{let f=i+o;f<3?([()=>{a(e,u)[n+p[0]]=l||Je.bank0},()=>{a(e,u)[n+p[32]]=l},()=>{a(e,U)[c]=l}][f](),e.dispatchEvent("voice",{part:c})):f<8||(f<14?[()=>{let $=e.chRedir(l,s,!0);a(e,X)[c]=$,c!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))},()=>{a(e,W)[c]=+!l},()=>{e.setChType(c,l,C.ns5r),console.debug(`${d}type: ${Ye[l]}`)},()=>{a(e,M)[y.rpn*c+3]=l,a(e,A)[y.rpnt*c+2]=1},()=>{},()=>{}][f-8]():f<16||(f<33?[()=>{a(e,u)[n+p[7]]=l},()=>{a(e,u)[n+p[11]]=l},()=>{},()=>{},()=>{a(e,u)[n+p[10]]=l||128},()=>{},()=>{},()=>{a(e,u)[n+p[93]]=l},()=>{a(e,u)[n+p[91]]=l},()=>{a(e,u)[n+p[76]]=l},()=>{a(e,u)[n+p[77]]=l},()=>{a(e,u)[n+p[78]]=l},()=>{a(e,u)[n+p[74]]=l},()=>{a(e,u)[n+p[71]]=l},()=>{a(e,u)[n+p[73]]=l},()=>{a(e,u)[n+p[75]]=l},()=>{a(e,u)[n+p[72]]=l}][f-16]():f<112||f<114&&[()=>{a(e,u)[n+p[5]]=l},()=>{a(e,u)[n+p[65]]=l}][f-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 n=c-32;w(e,he,Date.now()+3200),w(e,z,10),a(e,te,pe).fill(0);let i=t.subarray(1),d=4;i.forEach(function(l,o){let f=o+n,$=f>>4,v=f&15;if(f<80){let T=$>3,B=0,Me=$0;)a(e,te,pe)[v*32+$*7+(Me-B)]=T&1,T=T>>1,B++}})}}).add([66,18,48],(t,s,c)=>{g(0,t)}).add([66,18,49],(t,s,c)=>{g(1,t)}).add([66,18,50],(t,s,c)=>{g(2,t)}).add([66,18,51],(t,s,c)=>{g(3,t)}).add([66,18,52],(t,s,c)=>{g(4,t)}).add([66,18,53],(t,s,c)=>{g(5,t)}).add([66,18,54],(t,s,c)=>{g(6,t)}).add([66,18,55],(t,s,c)=>{g(7,t)}).add([66,52],(t,s)=>{e.switchMode("ns5r",!0),w(e,N,!1);let c="";fe(t,(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],(t,s)=>{e.switchMode("ns5r",!0),w(e,N,!1);let c="",n=t[t.length-1],i=t.subarray(0,t.length-1),d=ve(i);d!=n&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${d}, got ${n}.`),console.debug(t)),fe(i,function(l,o){switch(!0){case o<2944:{let f=e.chRedir(Math.floor(o/92),s,!0),$=f*y.cc;switch(o%92){case 0:{a(e,u)[$+p[0]]=l,e.dispatchEvent("voice",{part:f});break}case 1:{a(e,u)[$+p[32]]=l,!l&&!a(e,u)[$+p[0]]&&(a(e,u)[$+p[0]]=Je.bank0),e.dispatchEvent("voice",{part:f});break}case 2:{a(e,U)[f]=l,l>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 3:{let v=e.chRedir(l,s,!0);a(e,X)[f]=v,f!=v&&(console.info(`NS5R CH${f+1} receives from CH${v+1}.`),e.buildRchTree());break}case 7:{a(e,D)[f]=l,e.dispatchEvent("voice",{part:f});break}case 8:{a(e,M)[f*y.rpn+3]=l<40||l>88?l+(l>63?-192:64):l,a(e,A)[y.rpnt*f+2]=1;break}case 9:case 10:{a(e,u)[$+p[7]]=l;break}case 11:{a(e,u)[$+p[11]]=l;break}case 14:{a(e,u)[$+p[10]]=l||128;break}case 19:{a(e,u)[$+p[93]]=l;break}case 20:{a(e,u)[$+p[91]]=l;break}case 84:{a(e,u)[$+p[65]]=l;break}case 85:{a(e,u)[$+p[5]]=l;break}}break}case o<3096:break;case o<3134:{let f=o-3096;f<8?(l>31&&(c+=String.fromCharCode(l)),f==7&&(e.aiEfxName=c)):f<10&&(e.setEffectType(f-8,44,l),e.dispatchEvent(`efx${["reverb","chorus"][f-8]}`,e.getEffectType(f-8)));break}case o<8566:break}})}).add([66,54],(t,s)=>{e.switchMode("ns5r",!0);let c="",n=80,i=0,d=0,l="MSB\tPRG\tLSB\tNME";fe(t,function(o,f){let $=f%158;switch(!0){case $<10:{o>31&&(c+=String.fromCharCode(o));break}case $==10:break;case $==11:{n=o&127;break}case $==12:{d=o&127;break}case $==13:{l+=` +${n} ${i} ${d} ${c.trim().replace("Init Voice","")}`,i++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(l),O()&&console.debug(l),e.forceVoiceRefresh()}).add([66,55],(t,s)=>{e.switchMode("ns5r",!0);let c="",n=88,i=0,d=0,l="MSB\tPRG\tLSB\tNME";fe(t,function(o,f){let $=f%126;switch(!0){case $<10:{o>31&&(c+=String.fromCharCode(o));break}case $==11:break;case $==12:break;case $==13:{l+=` +${n} ${i} ${d} ${c.trim().replace("Init Combi","")}`,i++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(l),O()&&console.debug(l),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=t[t.length-1],c=t.subarray(0,t.length-1),n=ve(c);n!=s&&(console.info(`NS5R screen dump checksum mismatch! Expected ${n}, got ${s}.`),console.debug(t));let i=new Uint8Array(5760);fe(t,(d,l,o)=>{if(l<720)for(let f=0;f<8;f++)i[l*8+f]=d>>7-f&1}),e.dispatchEvent("screen",{type:"ns5r",data:i})}).add([76],(t,s,c)=>{a(e,$e).run([66,...t],s,c)}),a(this,Ne).add([16,0,8,0],(t,s,c)=>{let n=(t[2]<<4)+t[3],i="K11 ";([()=>{e.switchMode("k11",!0),w(e,N,!1),w(e,re,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}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,s,c)=>{let n=e.chRedir(t[1],s,!0),i=y.cc*n,d=y.rpn*n,l=(t[3]<<4)+t[4],o=`K11 CH${n+1} `;([()=>{l<128?(e.setChType(n,e.CH_MELODIC,C.k11),a(e,u)[i+p[0]]=0,a(e,U)[n]=l):(e.setChType(n,e.CH_DRUMS,C.k11),a(e,U)[n]=l-128),e.dispatchEvent("voice",{part:n})},()=>{let f=e.chRedir(l,s,!0);a(e,X)[n]=f,n!=f&&(e.buildRchTree(),console.info(`${o}receives from CH${f+1}`))},()=>{a(e,u)[i+p[7]]=l},()=>{uupThis.setChActive(n,l)},()=>{a(e,u)[i+p[10]]=l},()=>{a(e,M)[d+3]=l+40,a(e,A)[y.rpnt*n+2]=1},()=>{a(e,M)[d+1]=l>>1,a(e,M)[d+2]=l&1,a(e,A)[y.rpnt*n+1]=1},()=>{a(e,u)[i+p[91]]=l?127:0},()=>{},()=>{a(e,u)[i+p[74]]=l},()=>{a(e,u)[i+p[73]]=l},()=>{a(e,u)[i+p[72]]=l}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,s,c)=>{let n=(t[2]<<4)+t[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}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,s,c)=>{let n=(t[2]<<4)+t[3],i=e.chRedir(t[1],s,!0),d=i*y.cc;[()=>{n<128?(e.setChType(i,e.CH_MELODIC,C.k11),a(e,u)[d+p[0]]=0,a(e,u)[d+p[32]]=0,a(e,U)[i]=n):n<160?(e.setChType(i,e.CH_MELODIC,C.k11),a(e,u)[d+p[0]]=0,a(e,u)[d+p[32]]=7,a(e,U)[i]=n-100):(e.setChType(i,e.CH_DRUMS,C.k11),a(e,u)[d+p[0]]=122,a(e,u)[d+p[32]]=0,a(e,U)[i]=n-160),e.dispatchEvent("voice",{part:i})},()=>{let l=e.chRedir(n,s,!0);a(e,X)[i]=l,i!=l&&(e.buildRchTree(),console.info(`GMLX CH${i+1} receives from CH${l+1}`))}][t[0]]()}).add([16,0,9,4],(t,s,c)=>{let n=(t[2]<<4)+t[3],i=e.chRedir(t[1],s,!0),d=i*y.cc,l=i*y.rpn,o=`GMLX CH${i+1} `;[()=>{e.setChActive(i,n)},()=>{a(e,u)[d+p[7]]=n},()=>{a(e,u)[d+p[10]]=n},()=>{a(e,u)[d+p[91]]=n?127:0},()=>{a(e,M)[l+3]=n+40,a(e,A)[y.rpnt*i+2]=1},()=>{a(e,M)[l+1]=n,a(e,A)[y.rpnt*i+1]=1},()=>{a(e,M)[l]=n,a(e,A)[y.rpnt*i]=1},()=>{}][t[0]]()}),a(this,Be).add([66,93,64],(t,s,c)=>{let n=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{w(e,P,n*129/16383*100),e.dispatchEvent("mastervolume",a(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(t[1]){case 48:{console.debug(`SG reverb type: ${ft[n]}`);break}}break}default:if(t[0]>>4==1){let i=e.chRedir(t[0]&15,s,!0);if(t[1]==2){let d=e.chRedir(n,s,!0);a(e,X)[i]=d,i!=d&&(e.buildRchTree(),console.info(`SG CH${i+1} receives from CH${d+1}`))}else t[1]==19&&(a(e,u)[y.cc*i+p[7]]=n)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),a(this,He).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"}`)}),a(this,ee).add([127,0],(t,s,c)=>{e.switchMode("motif");let n=new Uint8Array([127,1,...t]);a(e,ee).run(n,s,c)}).add([127,1,0,0],(t,s,c)=>{e.switchMode("s90es");let n="S90/Motif ES system ",i=t[0];t.subarray(1).forEach((d,l)=>{([()=>{w(e,P,d*12900/16383),e.dispatchEvent("mastervolume",a(e,P))}][i+l]||(()=>{console.info(`Unrecognized ${n}ID: ${i+l}`)}))()})}).add([127,1,0,0,14],(t,s,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk header ",i=[];i[95]=(d,l,o)=>{console.debug(`${n}multi edit buffer: ${d[1]}`)},(i[t[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,0,15],(t,s,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk footer ",i=[];i[95]=(d,l,o)=>{console.debug(`${n}multi edit buffer: ${d[1]}`)},(i[t[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,58,55],(t,s,c)=>{e.switchMode("s90es");let n=e.chRedir(t[0],s,!0),i=y.cc*n,d=t[1],l=`S90/Motif ES bulk CH${n<16?n+1:"U"+(n-95)} `;console.debug(l,t),!(t[0]>15)&&t.subarray(2).forEach((o,f)=>{([()=>{a(e,u)[i+p[0]]=o,e.dispatchEvent("voice",{part:n})},()=>{o&&e.setChActive(n,1),a(e,u)[i+p[32]]=o,e.setChType(n,[32,40].indexOf(o)>-1?e.CH_DRUMS:e.CH_MELODIC,a(e,L),!0),e.dispatchEvent("voice",{part:n})},()=>{o&&e.setChActive(n,1),a(e,U)[n]=o,e.dispatchEvent("voice",{part:n})},()=>{let $=e.chRedir(o,s,!0);a(e,X)[n]=$,n!=$&&(e.buildRchTree(),console.info(`${l}receives from CH${$+1}`))},()=>{a(e,W)[n]=o?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{a(e,u)[i+p[7]]=o},()=>{a(e,u)[i+p[10]]=o},!1,!1,!1,()=>{a(e,u)[i+p[91]]=o},()=>{a(e,u)[i+p[93]]=o},()=>{a(e,u)[i+p[94]]=o},()=>{a(e,u)[i+p[128]]=o},()=>{},()=>{a(e,u)[i+p[74]]=o},()=>{a(e,u)[i+p[71]]=o},!1,()=>{a(e,u)[i+p[65]]=o},()=>{a(e,u)[i+p[5]]=o},()=>{}][d+f]||(()=>{}))()})}).add([127,1,54,16],(t,s,c)=>{e.switchMode("s90es");let n=t[0];t.subarray(1).forEach((i,d)=>{let o=`S90/Motif ES EQ${(d>>2)+1} `;([()=>{let f=i-64},()=>{let f=Ge[i]},()=>{let f=i/10},()=>{let f=i}][n+d&3]||(()=>{}))()})}),a(this,se).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 n=t[0]>>5,i=t[0]&31;switch(n){case 0:{let d=t[0]>>1,l=t[1];switch(d){case 1:{t.subarray(2).forEach((o,f,$)=>{let v=f+l;switch(v){case 0:{o&&(e.setEffectType(1,60,o-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${v} - ${o}`));break}}});break}case 2:{t.subarray(2).forEach((o,f)=>{let $=f+l;switch($){case 0:{o&&(e.setEffectType(0,55+o,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${$} - ${o}`));break}}});break}case 3:case 4:case 5:{let o=d-1;t.subarray(2).forEach((f,$)=>{let v=$+l;switch(console.debug(`SD MFX ${o-2}: ${v} - ${f}`),v){case 0:{e.setEffectTypeRaw(o,62,f),e.dispatchEvent(`efx${o>2?"delay":"insert"+(o-4)}`,e.getEffectType(o));break}}}),console.debug(`SD MFX message: %o`,t);break}default:console.debug(`Unknown SD-90 global effects message: -%o`,t)}break}case 1:{let f=e.chRedir(s,i,!0),l=t[1],o=f*g.cc;t.subarray(2).forEach((d,$)=>{let m=l+$;m<37?([()=>{},()=>{},0,()=>{},()=>{switch(a(e,u)[o+p[0]]=d,d){case 104:case 105:case 106:case 107:case 120:{a(e,D)[f]||e.setChType(f,e.CH_DRUMS);break}default:a(e,D)[f]&&e.setChType(f,e.CH_MELODIC)}e.dispatchEvent("voice",{part:f})},()=>{a(e,u)[o+p[32]]=d,e.dispatchEvent("voice",{part:f})},()=>{a(e,U)[f]=d,e.dispatchEvent("voice",{part:f})},()=>{a(e,u)[o+p[7]]=d},()=>{a(e,u)[o+p[10]]=d},()=>{},()=>{},()=>{d<2&&(a(e,W)[f]=d)},()=>{d<2&&(a(e,u)[o+p[68]]=d?127:0)},()=>{},()=>{d<2&&(a(e,u)[o+p[65]]=d?127:0)},()=>{a(e,u)[o+p[5]]=d&15<<4|a(e,u)[o+p[5]]&15},()=>{a(e,u)[o+p[5]]=d&15|(a(e,u)[o+p[5]]&240)>>4},()=>{a(e,u)[o+p[74]]=d},()=>{a(e,u)[o+p[71]]=d},()=>{a(e,u)[o+p[73]]=d},()=>{a(e,u)[o+p[72]]=d},0,0,0,0,0,0,0,()=>{a(e,u)[o+p[128]]=d},()=>{a(e,u)[o+p[93]]=d},()=>{a(e,u)[o+p[91]]=d},0,0,()=>{a(e,u)[o+p[75]]=d},()=>{a(e,u)[o+p[76]]=d},()=>{a(e,u)[o+p[77]]=d},()=>{a(e,u)[o+p[78]]=d}][m]||(()=>{}))():m<63||(m<64?(a(e,D)[f]?a(e,u)[o+p[0]]=104|d:a(e,u)[o+p[0]]=96|d,e.dispatchEvent("voice",{part:f})):console.debug(`Unknown SD-90 global CH${f+1} param setup message: -%o`,t))});break}case 2:{let f=e.chRedir(s,i,!0),l=t[1];console.debug(`Unknown SD-90 global CH${f+1} MIDI setup message: +%o`,t)}break}case 1:{let d=e.chRedir(i,s,!0),l=t[1],o=d*y.cc;t.subarray(2).forEach((f,$)=>{let v=l+$;v<37?([()=>{},()=>{},0,()=>{},()=>{switch(a(e,u)[o+p[0]]=f,f){case 104:case 105:case 106:case 107:case 120:{a(e,D)[d]||e.setChType(d,e.CH_DRUMS);break}default:a(e,D)[d]&&e.setChType(d,e.CH_MELODIC)}e.dispatchEvent("voice",{part:d})},()=>{a(e,u)[o+p[32]]=f,e.dispatchEvent("voice",{part:d})},()=>{a(e,U)[d]=f,e.dispatchEvent("voice",{part:d})},()=>{a(e,u)[o+p[7]]=f},()=>{a(e,u)[o+p[10]]=f},()=>{},()=>{},()=>{f<2&&(a(e,W)[d]=f)},()=>{f<2&&(a(e,u)[o+p[68]]=f?127:0)},()=>{},()=>{f<2&&(a(e,u)[o+p[65]]=f?127:0)},()=>{a(e,u)[o+p[5]]=f&15<<4|a(e,u)[o+p[5]]&15},()=>{a(e,u)[o+p[5]]=f&15|(a(e,u)[o+p[5]]&240)>>4},()=>{a(e,u)[o+p[74]]=f},()=>{a(e,u)[o+p[71]]=f},()=>{a(e,u)[o+p[73]]=f},()=>{a(e,u)[o+p[72]]=f},0,0,0,0,0,0,0,()=>{a(e,u)[o+p[128]]=f},()=>{a(e,u)[o+p[93]]=f},()=>{a(e,u)[o+p[91]]=f},0,0,()=>{a(e,u)[o+p[75]]=f},()=>{a(e,u)[o+p[76]]=f},()=>{a(e,u)[o+p[77]]=f},()=>{a(e,u)[o+p[78]]=f}][v]||(()=>{}))():v<63||(v<64?(a(e,D)[d]?a(e,u)[o+p[0]]=104|f:a(e,u)[o+p[0]]=96|f,e.dispatchEvent("voice",{part:d})):console.debug(`Unknown SD-90 global CH${d+1} param setup message: +%o`,t))});break}case 2:{let d=e.chRedir(i,s,!0),l=t[1];console.debug(`Unknown SD-90 global CH${d+1} MIDI setup message: %o`,t.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,t)}})}chRedir(e,r,h){if(a(this,xe)[r])return(a(this,xe)[r]-1)*16+e;if([2,3].indexOf(a(this,ee))>-1){if(h==1)return e;let b=0,y=!0;for(;y;)a(this,Ee)[e+b]==0?(a(this,Ee)[e+b]=r,console.debug(`Assign track ${r} to channel ${e+b+1}.`),y=!1):a(this,Ee)[e+b]==r?y=!1:(b+=16,b>=128&&(b=0,y=!1));return e+b}else return e}forceVoiceRefresh(){for(let e=0;e{var b;r{r&&(a(e,Le)[Math.floor(h/g.redir)][r]=h%g.redir|128)}),O()&&console.debug(a(e,Le))}getActive(){return a(this,be)}getCc(e){let r=e*g.cc,h=a(this,u).subarray(r,r+g.cc);return h[p[0]]=h[p[0]]||a(this,we),h[p[32]]=h[p[32]]||a(this,ee),h[p[0]]==Je.bank0&&(h[p[0]]=0),h}getCcCh(e,r){if(Ze.indexOf(r)<0)throw new Error("CC number not accepted");return a(this,u)[g.cc*e+p[r]]}getCcAll(){let e=a(this,u).slice();for(let r=0;r0&&!b&&(a(this,u)[e*g.cc+p[0]]=Te[h])}setChActive(e,r=0){a(this,be)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),a(this,be)[e]=r}getExt(e){let r=g.ext*e,h=a(this,fe).subarray(r,r+g.ext),b=new Uint8Array(h.length);return b.set(h),b[1]=b[1]||a(this,rt),b}getPitch(){return a(this,ge)}getProgram(){return a(this,U)}getTexts(){return a(this,Z).slice()}getVel(e){let r=new Map,h=this;return a(h,_).forEach(function(b,y){let S=Math.floor(b/128),v=b%128;e==S&&a(h,G)[b]>0&&r.set(v,{v:a(h,G)[b],s:a(h,V)[y]})}),r}getBitmap(){return{bitmap:a(this,j,ue),expire:a(this,le)}}getLetter(){return{text:a(this,ke),set:a(this,je),expire:a(this,Se)}}getMode(){return oe[a(this,A)]}getMaster(){return{volume:a(this,P)}}getRawStrength(){let e=this;return a(this,_).forEach(function(r){let h=Math.floor(r/128);a(e,G)[r]>a(e,de)[h]&&(a(e,de)[h]=a(e,G)[r])}),a(this,de)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(h,b){e[b]=Math.floor(h*a(r,u)[b*g.cc+p[7]]*a(r,u)[b*g.cc+p[11]]*a(r,P)/803288)}),e}getRpn(){return a(this,M)}getNrpn(){return a(this,_e)}getVoice(e,r,h,b){let y=e||a(this,we),S=r,v=h||a(this,ee);y==Je.bank0&&(y=0),oe[a(this,A)]=="ns5r"&&y>0&&y<56&&(v=3);let k=this.userBank.get(y,S,v,b);if(oe[a(this,A)]=="mt32"&&k.name.indexOf("MT-m:")==0){let t=parseInt(k.name.slice(5)),i=t*g.cmt,c="";a(this,ve).subarray(i,i+10).forEach(s=>{s>31&&(c+=String.fromCharCode(s))});let n=`MSB LSB PRG NME -0 127 ${S} ${c}`;this.userBank.load(n,!0),k.name=c,k.ending=" "}return(k.ending!=" "||!k.name.length)&&(k=this.baseBank.get(y,S,v,b)),k}getChVoice(e){let r=this.getVoice(a(this,u)[e*g.cc+p[0]],a(this,U)[e],a(this,u)[e*g.cc+p[32]],oe[a(this,A)]);if(a(this,he)[e])switch(a(this,A)){case C.mt32:r.ending="~",r.name="",a(this,ie).subarray(14*(e-1),14*(e-1)+10).forEach(h=>{r.name+=String.fromCharCode(Math.max(h,32))}),r.name=r.name.trimRight()}return r}getRawPitch(){return a(this,ge)}getPitchShift(e){let r=this,h=e*g.rpn,b=a(r,M)[h];return a(r,L)[e*g.rpnt]||a(r,A)==C.mt32&&(b=12),a(r,ge)[e]/8192*b+(a(r,M)[h+3]-64)+((a(r,M)[h+1]<<7)+a(r,M)[h+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return a(this,J).subarray(r,r+2)}setEffectTypeRaw(e=0,r,h){let b=3*e;a(this,J)[b]=1,a(this,J)[b+1+ +r]=h}setEffectType(e=0,r,h){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,h)}getEffectSink(){return a(this,Xe)}setLetterDisplay(e,r,h=0,b=3200){let y=this,S;w(y,ke," ".repeat(h)),e.forEach(v=>{w(y,ke,a(y,ke)+String.fromCharCode(v>31?v:32)),v<32&&(S=S||new Set,S.add(v))}),w(y,je,Date.now()),w(y,Se,Date.now()+b),S&&(S=Array.from(S),S.forEach((v,k,t)=>{t[k]=v.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${S.length>1?"s":""}: 0x${S.join(", 0x")}`))}setDetectionTargets(e="?",r=0){let h=this,b=-1;switch(e.replaceAll(", ",",").split(",").forEach(y=>{y=y.toLowerCase();let S=oe.indexOf(Qt[y]||y);O()&&console.debug(`Mapped mode "${y}" to ID "${S}".`),S>-1&&(b=S)}),O()&&console.debug(`Set detection target to ID "${b}".`),b>0&&(a(h,H).x5=82,a(h,H).ds=C.krs),b){case C["05rw"]:{a(h,H).x5=81;break}case C.s90es:a(h,H).ds=C.s90es;case C.motif:a(h,H).ds=C.motif}}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let r=!0,h=0;for(;r&&h=g.ace&&console.warn("ACE slots are full.")}getAce(){return a(this,ye)}getChAce(e,r){if(r<0||r>=g.ace)throw new RangeError("No such ACE slot");let h=a(this,ye)[r];if(h){if(Ze.indexOf(h)>=0)return a(this,u)[e*g.cc+p[h]];throw new Error(`Invalid ACE source: ${h}`)}else return 0}initDrums(){let e=this;a(e,Q).fill(64);for(let r=0;r-1){if(a(b,A)==0||r){let v=a(b,A);b.initOnReset&&r&&(this.init(1),v=C["?"]),w(b,A,y),w(b,z,0),w(b,we,Dt[0][y]),w(b,ee,Dt[1][y]);for(let t=0;t0&&a(b,u)[t*g.cc+p[0]]==Te[v]&&(a(b,u)[t*g.cc]=Te[y]);switch(y){case C.mt32:{ft.forEach((t,i)=>{let c=i+1;a(b,be)[c]||(a(b,U)[c]=t,a(b,u)[c*g.cc+p[91]]=127)});for(let t=1;t<10;t++)b.dispatchEvent("voice",{part:t});break}}let k;switch(y){case C["?"]:case C.g2:{k=[52,4,52,18,0,0,0,0];break}case C.xg:{k=[1,0,65,0,5,0,0,0];break}case C.gm:case C.gs:{k=[40,4,40,18,40,32,32,0];break}case C.sd:{k=[58,0,60,0,61,0,61,0];break}case C["05rw"]:case C.x5d:case C.ns5r:{k=[44,1,44,19,44,0,44,0];break}case C.k11:case C.sg:{k=[24,0,0,0,0,0,0,0];break}case C.mt32:{k=[40,4,0,0,0,0,0,0];break}default:k=[0,0,0,0,0,0,0,0]}for(let t=0;t14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),a(this,tt)[e.type].call(this,e);{let h=this.chRedir(e.part,e.track),b=!1;(r=a(this,et)[h])==null||r.forEach(y=>{e.channel=y,b=!0,a(this,tt)[e.type].call(this,e)}),b||console.warn(`${Ot[e.type]?Ot[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.`)}a(this,Z).length>100&&a(this,Z).splice(100,a(this,Z).length-99)}runRaw(e){}async loadBank(e,r){let h=this;switch(e=e.toLowerCase(),e){case"s7e":{h.userBank.clearRange({msb:63,lsb:[21,22]}),h.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{at.context=this,h.userBank.load(await at.read(e,r));break}}h.forceVoiceRefresh()}},A=new WeakMap,z=new WeakMap,le=new WeakMap,pe=new WeakMap,j=new WeakSet,ue=function(){return a(this,pe)[a(this,z)]},It=function(e){a(this,pe)[a(this,z)]=e},be=new WeakMap,X=new WeakMap,D=new WeakMap,u=new WeakMap,ye=new WeakMap,U=new WeakMap,G=new WeakMap,W=new WeakMap,_=new WeakMap,V=new WeakMap,ge=new WeakMap,de=new WeakMap,Re=new WeakMap,fe=new WeakMap,M=new WeakMap,L=new WeakMap,_e=new WeakMap,Q=new WeakMap,J=new WeakMap,Xe=new WeakMap,De=new WeakMap,he=new WeakMap,me=new WeakMap,ie=new WeakMap,Ve=new WeakMap,ve=new WeakMap,we=new WeakMap,ee=new WeakMap,H=new WeakMap,P=new WeakMap,Oe=new WeakMap,Fe=new WeakMap,Ke=new WeakMap,ke=new WeakMap,Se=new WeakMap,je=new WeakMap,ze=new WeakMap,ne=new WeakMap,N=new WeakMap,rt=new WeakMap,et=new WeakMap,Le=new WeakMap,ht=new WeakMap,Z=new WeakMap,Ee=new WeakMap,xe=new WeakMap,F=new WeakMap,Ae=new WeakMap,I=new WeakMap,tt=new WeakMap,st=new WeakMap,Ue=new WeakMap,Pe=new WeakMap,te=new WeakMap,ae=new WeakMap,$e=new WeakMap,Ne=new WeakMap,Be=new WeakMap,He=new WeakMap,Ht);export{Ia as OctaviaDevice,g as allocated,p as ccToPos,se as dnToPos}; \ No newline at end of file +%o`,t)}})}chRedir(e,r,h){if(a(this,Ce)[r])return(a(this,Ce)[r]-1)*16+e;if([2,3].indexOf(a(this,re))>-1){if(h==1)return e;let b=0,g=!0;for(;g;)a(this,Ee)[e+b]==0?(a(this,Ee)[e+b]=r,console.debug(`Assign track ${r} to channel ${e+b+1}.`),g=!1):a(this,Ee)[e+b]==r?g=!1:(b+=16,b>=128&&(b=0,g=!1));return e+b}else return e}forceVoiceRefresh(){for(let e=0;e{var b;r{r&&(a(e,Ae)[Math.floor(h/y.redir)][r]=h%y.redir|128)}),O()&&console.debug(a(e,Ae))}getActive(){return a(this,ye)}getCc(e){let r=e*y.cc,h=a(this,u).subarray(r,r+y.cc);return h[p[0]]=h[p[0]]||a(this,ke),h[p[32]]=h[p[32]]||a(this,re),h[p[0]]==Je.bank0&&(h[p[0]]=0),h}getCcCh(e,r){if(Ze.indexOf(r)<0)throw new Error("CC number not accepted");return a(this,u)[y.cc*e+p[r]]}getCcAll(){let e=a(this,u).slice();for(let r=0;r0&&!b&&(a(this,u)[e*y.cc+p[0]]=Te[h])}setChActive(e,r=0){a(this,ye)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),a(this,ye)[e]=r}getExt(e){let r=y.ext*e,h=a(this,J).subarray(r,r+y.ext),b=new Uint8Array(h.length);return b.set(h),b[1]=b[1]||a(this,st),b}getPitch(){return a(this,ge)}getProgram(){return a(this,U)}getTexts(){return a(this,j).slice()}getVel(e){let r=new Map,h=this;return a(h,I).forEach(function(b,g){let S=Math.floor(b/128),m=b%128;e==S&&a(h,G)[b]>0&&r.set(m,{v:a(h,G)[b],s:a(h,V)[g]})}),r}getBitmap(){return{bitmap:a(this,te,pe),expire:a(this,he)}}getLetter(){return{text:a(this,Se),set:a(this,et),expire:a(this,xe)}}getMode(){return de[a(this,L)]}getMaster(){return{volume:a(this,P)}}getRawStrength(){let e=this;return a(this,I).forEach(function(r){let h=Math.floor(r/128);a(e,G)[r]>a(e,ue)[h]&&(a(e,ue)[h]=a(e,G)[r])}),a(this,ue)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(h,b){e[b]=Math.floor(h*a(r,u)[b*y.cc+p[7]]*a(r,u)[b*y.cc+p[11]]*a(r,P)/803288)}),e}getRpn(){return a(this,M)}getNrpn(){return a(this,Ie)}getVoice(e,r,h,b){let g=e||a(this,ke),S=r,m=h||a(this,re);g==Je.bank0&&(g=0),de[a(this,L)]=="ns5r"&&g>0&&g<56&&(m=3);let k=this.userBank.get(g,S,m,b);if(de[a(this,L)]=="mt32"&&k.name.indexOf("MT-m:")==0){let t=parseInt(k.name.slice(5)),s=t*y.cmt,c="";a(this,we).subarray(s,s+10).forEach(i=>{i>31&&(c+=String.fromCharCode(i))});let n=`MSB LSB PRG NME +0 127 ${S} ${c}`;this.userBank.load(n,!0),k.name=c,k.ending=" "}return(k.ending!=" "||!k.name.length)&&(k=this.baseBank.get(g,S,m,b)),k}getChVoice(e){let r=this.getVoice(a(this,u)[e*y.cc+p[0]],a(this,U)[e],a(this,u)[e*y.cc+p[32]],de[a(this,L)]);if(a(this,ce)[e]){let h="";switch(a(this,L)){case C.mt32:{a(this,oe).subarray(y.cmt*(e-1),y.cmt*(e-1)+10).forEach(b=>{h+=String.fromCharCode(Math.max(b,32))}),h=h.trimRight();break}default:{let b=y.cvn*e;a(this,je).subarray(b,b+y.cvn).forEach(g=>{h+=String.fromCharCode(Math.max(g,32))}),h=h.trimRight()}}h.length&&(r.ending="~",r.name=h)}return r}getRawPitch(){return a(this,ge)}getPitchShift(e){let r=this,h=e*y.rpn,b=a(r,M)[h];return a(r,A)[e*y.rpnt]||a(r,L)==C.mt32&&(b=12),a(r,ge)[e]/8192*b+(a(r,M)[h+3]-64)+((a(r,M)[h+1]<<7)+a(r,M)[h+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return a(this,Z).subarray(r,r+2)}setEffectTypeRaw(e=0,r,h){let b=3*e;a(this,Z)[b]=1,a(this,Z)[b+1+ +r]=h}setEffectType(e=0,r,h){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,h)}getEffectSink(){return a(this,Xe)}setLetterDisplay(e,r,h=0,b=3200){let g=this,S;w(g,Se," ".repeat(h)),e.forEach(m=>{w(g,Se,a(g,Se)+String.fromCharCode(m>31?m:32)),m<32&&(S=S||new Set,S.add(m))}),w(g,et,Date.now()),w(g,xe,Date.now()+b),S&&(S=Array.from(S),S.forEach((m,k,t)=>{t[k]=m.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${S.length>1?"s":""}: 0x${S.join(", 0x")}`))}setDetectionTargets(e="?",r=0){let h=this,b=-1;switch(e.replaceAll(", ",",").split(",").forEach(g=>{g=g.toLowerCase();let S=de.indexOf(qt[g]||g);O()&&console.debug(`Mapped mode "${g}" to ID "${S}".`),S>-1&&(b=S)}),O()&&console.debug(`Set detection target to ID "${b}".`),b>0&&(a(h,H).x5=82,a(h,H).ds=C.krs),b){case C["05rw"]:{a(h,H).x5=81;break}case C.s90es:a(h,H).ds=C.s90es;case C.motif:a(h,H).ds=C.motif}}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let r=!0,h=0;for(;r&&h=y.ace&&console.warn("ACE slots are full.")}releaseAce(e){let r=!0,h=0;for(;r&&h=y.ace)throw new RangeError("No such ACE slot");let h=a(this,ae)[r];if(h){if(Ze.indexOf(h)>=0)return a(this,u)[e*y.cc+p[h]];throw new Error(`Invalid ACE source: ${h}`)}else return 0}initDrums(){let e=this;a(e,Q).fill(64);for(let r=0;r-1){if(a(b,L)==0||r){let m=a(b,L);b.initOnReset&&r&&(this.init(1),m=C["?"]),w(b,L,g),w(b,z,0),w(b,ke,Ot[0][g]),w(b,re,Ot[1][g]);for(let t=0;t0&&a(b,u)[t*y.cc+p[0]]==Te[m]&&(a(b,u)[t*y.cc]=Te[g]);switch(g){case C.mt32:{ht.forEach((t,s)=>{let c=s+1;a(b,ye)[c]||(a(b,U)[c]=t,a(b,u)[c*y.cc+p[91]]=127)});for(let t=1;t<10;t++)b.dispatchEvent("voice",{part:t});break}}let k;switch(g){case C["?"]:case C.g2:{k=[52,4,52,18,0,0,0,0];break}case C.xg:{k=[1,0,65,0,5,0,0,0];break}case C.gm:case C.gs:{k=[40,4,40,18,40,32,32,0];break}case C.sd:{k=[58,0,60,0,61,0,61,0];break}case C["05rw"]:case C.x5d:case C.ns5r:{k=[44,1,44,19,44,0,44,0];break}case C.k11:case C.sg:{k=[24,0,0,0,0,0,0,0];break}case C.mt32:{k=[40,4,0,0,0,0,0,0];break}default:k=[0,0,0,0,0,0,0,0]}for(let t=0;t14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),a(this,at)[e.type].call(this,e);{let h=this.chRedir(e.part,e.track),b=!1;(r=a(this,tt)[h])==null||r.forEach(g=>{e.channel=g,b=!0,a(this,at)[e.type].call(this,e)}),b||console.warn(`${At[e.type]?At[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.`)}a(this,j).length>100&&a(this,j).splice(100,a(this,j).length-99)}runRaw(e){}async loadBank(e,r){let h=this;switch(e=e.toLowerCase(),e){case"s7e":{h.userBank.clearRange({msb:63,lsb:[21,22]}),h.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{rt.context=this,h.userBank.load(await rt.read(e,r));break}}h.forceVoiceRefresh()}},L=new WeakMap,z=new WeakMap,he=new WeakMap,be=new WeakMap,te=new WeakSet,pe=function(){return a(this,be)[a(this,z)]},Gt=function(e){a(this,be)[a(this,z)]=e},ye=new WeakMap,X=new WeakMap,D=new WeakMap,u=new WeakMap,ae=new WeakMap,U=new WeakMap,G=new WeakMap,W=new WeakMap,I=new WeakMap,V=new WeakMap,ge=new WeakMap,ue=new WeakMap,Re=new WeakMap,J=new WeakMap,M=new WeakMap,A=new WeakMap,Ie=new WeakMap,Q=new WeakMap,Z=new WeakMap,Xe=new WeakMap,De=new WeakMap,ce=new WeakMap,je=new WeakMap,me=new WeakMap,oe=new WeakMap,Ve=new WeakMap,we=new WeakMap,ke=new WeakMap,re=new WeakMap,H=new WeakMap,P=new WeakMap,Oe=new WeakMap,Fe=new WeakMap,Ke=new WeakMap,Se=new WeakMap,xe=new WeakMap,et=new WeakMap,ze=new WeakMap,le=new WeakMap,N=new WeakMap,st=new WeakMap,tt=new WeakMap,Ae=new WeakMap,ut=new WeakMap,j=new WeakMap,Ee=new WeakMap,Ce=new WeakMap,F=new WeakMap,Le=new WeakMap,_=new WeakMap,at=new WeakMap,it=new WeakMap,Ue=new WeakMap,Pe=new WeakMap,ee=new WeakMap,se=new WeakMap,$e=new WeakMap,Ne=new WeakMap,Be=new WeakMap,He=new WeakMap,_t);export{Ga as OctaviaDevice,y as allocated,p as ccToPos,ne as dnToPos}; \ No newline at end of file