From ab878ae15a2ba581a5011e980b28f5b45433b7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lumi=C3=A8re=20=C3=89lev=C3=A9?= <88174309+PoneyClairDeLune@users.noreply.github.com> Date: Mon, 22 Apr 2024 19:09:03 +0000 Subject: [PATCH] Supported DOC Global Reverb Depth On. --- dist/basic.mjs | 14 ++++++------ dist/cambiare.mjs | 48 ++++++++++++++++++++-------------------- dist/state.mjs | 42 +++++++++++++++++------------------ dist/state_skim.mjs | 18 +++++++-------- dist/xp_basic.mjs | 54 ++++++++++++++++++++++----------------------- dist/xp_state.mjs | 22 +++++++++--------- src/state/index.mjs | 11 +++++++++ 7 files changed, 110 insertions(+), 99 deletions(-) diff --git a/dist/basic.mjs b/dist/basic.mjs index 4950f597..c875a958 100644 --- a/dist/basic.mjs +++ b/dist/basic.mjs @@ -1,9 +1,9 @@ -var K=Object.create;var U=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var Y=(t,s)=>()=>(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 q(s))!Q.call(t,n)&&n!==o&&U(t,n,{get:()=>s[n],enumerable:!(e=z(s,n))||e.enumerable});return t};var Z=(t,s,o)=>(o=t!=null?K(W(t)):{},j(s||!t||!t.__esModule?U(o,"default",{value:t,enumerable:!0}):o,t));var G=Y((tt,P)=>{(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(h){n(o.Uint8(new Uint8Array(h.target.result)))}})},Base64:function(e){let n=function(h){var g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(h=h.replace(/^.*?base64,/,""),h=String(h).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(h))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");h+="==".slice(2-(3&h.length));let u,f="",a,i,d=0;for(;d>16&255):i===64?String.fromCharCode(u>>16&255,u>>8&255):String.fromCharCode(u>>16&255,u>>8&255,255&u);return f}(e=String(e));var r=n.length;let c=new Uint8Array(new ArrayBuffer(r));for(let h=0;h{i[p]=this.readInt(1)});for(let b=0;b191||E>127&&E<160)throw new RangeError(`Invalid code point: ${E}`)}d=!0,console.debug(`String byte sequence in ${s[b].encoding}`)}catch(p){console.debug(`SMF string ${p}`)}return l||"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 d=[];for(;128<=this.data.getUint8(this.pointer);)d.push(this.readInt(1)-128);var i=this.readInt(1);for(let l=1;l<=d.length;l++)a+=d[d.length-l]*Math.pow(128,l);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),h=n.readInt(1);128<=c?(r.timeDivision=[],r.timeDivision[0]=c-128,r.timeDivision[1]=h):r.timeDivision=256*c+h;for(let a=1;a<=r.tracks;a++){r.track[a-1]={event:[]};var g,u=n.readInt(4);if(u===-1)break;if(u!==1297379947)return!1;n.readInt(4);let i=0,d=!1,l,b;for(;!d&&(i++,r.track[a-1].event[i-1]={},r.track[a-1].event[i-1].deltaTime=n.readIntVLV(),(l=n.readInt(1))!==-1);)if(128<=l?b=l:(l=b,n.movePointer(-1)),l===255){r.track[a-1].event[i-1].type=255,r.track[a-1].event[i-1].metaType=n.readInt(1);var f=n.readIntVLV();switch(r.track[a-1].event[i-1].metaType){case 47:case-1:d=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:r.track[a-1].event[i-1].data=n.readStr(f);break;case 33:case 89:case 81:r.track[a-1].event[i-1].data=n.readInt(f);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,f)),this.customInterpreter!==null&&r.track[a-1].event[i-1].data!==!1||(n.readInt(f),r.track[a-1].event[i-1].data=n.readInt(f),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((l=l.toString(16).split(""))[1]||l.unshift("0"),r.track[a-1].event[i-1].type=parseInt(l[0],16),r.track[a-1].event[i-1].channel=parseInt(l[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||(g=n.readIntVLV(),r.track[a-1].event[i-1].data=n.readInt(g),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=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:d=!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 P<"u")P.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 C=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 N=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 J=function(t,s){let o=!0;return s.forEach((e,n)=>{o=o&&t[n]==e}),o},x=function(t){let s=0;return t.forEach(o=>{s*=256,s+=o}),s},$=new TextDecoder,M=new N;M.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,h=!0,g=[],u=0;for(;h;){let f=s.subarray(r);([()=>{$.decode(f.subarray(0,4))=="YSFC"?(r+=80,c=1):r++},()=>{if(J(f.subarray(0,4),e))g.forEach((a,i,d)=>{let l=x(s.subarray(a.start+4,a.start+8));a.length=l}),c=2;else{let a=$.decode(f.subarray(0,4)),i=x(f.subarray(4,8));g.push({type:a,start:i}),r+=8}},()=>{let a=g[u],i=s.subarray(a.start,a.start+a.length),d=32;switch(a.type){case"ENVC":{let l=n;for(;l()=>(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 q(s))!Q.call(t,n)&&n!==o&&U(t,n,{get:()=>s[n],enumerable:!(e=z(s,n))||e.enumerable});return t};var Z=(t,s,o)=>(o=t!=null?K(W(t)):{},j(s||!t||!t.__esModule?U(o,"default",{value:t,enumerable:!0}):o,t));var G=Y((tt,P)=>{(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(h){n(o.Uint8(new Uint8Array(h.target.result)))}})},Base64:function(e){let n=function(h){var g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(h=h.replace(/^.*?base64,/,""),h=String(h).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(h))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");h+="==".slice(2-(3&h.length));let u,f="",a,i,d=0;for(;d>16&255):i===64?String.fromCharCode(u>>16&255,u>>8&255):String.fromCharCode(u>>16&255,u>>8&255,255&u);return f}(e=String(e));var r=n.length;let c=new Uint8Array(new ArrayBuffer(r));for(let h=0;h{i[p]=this.readInt(1)});for(let b=0;b191||m>127&&m<160)throw new RangeError(`Invalid code point: ${m}`)}d=!0,console.debug(`String byte sequence in ${s[b].encoding}`)}catch(p){console.debug(`SMF string ${p}`)}return l||"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 d=[];for(;128<=this.data.getUint8(this.pointer);)d.push(this.readInt(1)-128);var i=this.readInt(1);for(let l=1;l<=d.length;l++)a+=d[d.length-l]*Math.pow(128,l);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),h=n.readInt(1);128<=c?(r.timeDivision=[],r.timeDivision[0]=c-128,r.timeDivision[1]=h):r.timeDivision=256*c+h;for(let a=1;a<=r.tracks;a++){r.track[a-1]={event:[]};var g,u=n.readInt(4);if(u===-1)break;if(u!==1297379947)return!1;n.readInt(4);let i=0,d=!1,l,b;for(;!d&&(i++,r.track[a-1].event[i-1]={},r.track[a-1].event[i-1].deltaTime=n.readIntVLV(),(l=n.readInt(1))!==-1);)if(128<=l?b=l:(l=b,n.movePointer(-1)),l===255){r.track[a-1].event[i-1].type=255,r.track[a-1].event[i-1].metaType=n.readInt(1);var f=n.readIntVLV();switch(r.track[a-1].event[i-1].metaType){case 47:case-1:d=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:r.track[a-1].event[i-1].data=n.readStr(f);break;case 33:case 89:case 81:r.track[a-1].event[i-1].data=n.readInt(f);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,f)),this.customInterpreter!==null&&r.track[a-1].event[i-1].data!==!1||(n.readInt(f),r.track[a-1].event[i-1].data=n.readInt(f),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((l=l.toString(16).split(""))[1]||l.unshift("0"),r.track[a-1].event[i-1].type=parseInt(l[0],16),r.track[a-1].event[i-1].channel=parseInt(l[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||(g=n.readIntVLV(),r.track[a-1].event[i-1].data=n.readInt(g),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=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:d=!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 P<"u")P.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 C=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 N=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 J=function(t,s){let o=!0;return s.forEach((e,n)=>{o=o&&t[n]==e}),o},x=function(t){let s=0;return t.forEach(o=>{s*=256,s+=o}),s},$=new TextDecoder,M=new N;M.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,h=!0,g=[],u=0;for(;h;){let f=s.subarray(r);([()=>{$.decode(f.subarray(0,4))=="YSFC"?(r+=80,c=1):r++},()=>{if(J(f.subarray(0,4),e))g.forEach((a,i,d)=>{let l=x(s.subarray(a.start+4,a.start+8));a.length=l}),c=2;else{let a=$.decode(f.subarray(0,4)),i=x(f.subarray(4,8));g.push({type:a,start:i}),r+=8}},()=>{let a=g[u],i=s.subarray(a.start,a.start+a.length),d=32;switch(a.type){case"ENVC":{let l=n;for(;l=g.length&&(c=3,h=!1)}][c]||(()=>{h=!1}))()}return o});M.set("pcg",async function(t){let s=new Uint8Array(await t.arrayBuffer()),o="MSB LSB PRG NME",e=100,n=0,r=0,c=!0,h=[],g=0;for(;c;){let u=s.subarray(e);([()=>{c=$.decode(u.subarray(0,4))=="INI2",r=u[15],e+=16,n=1},()=>{let f=$.decode(u.subarray(0,4)),a=u[5],i=u[7],d=u[11],l=x(u.subarray(12,16)),b=x(u.subarray(16,20)),p=x(u.subarray(36,40)),E=$.decode(u.subarray(44,44+d));h.push({type:f,tipMsb:a,tipLsb:i,nameLen:d,length:l,start:b,entryLen:p,name:E}),e+=64,r--,r<1&&(n=2)},()=>{let f=h[g],a=s.subarray(f.start,f.start+f.length);switch(f.type){case"PRG1":break;case"PBK1":{let i=63,d=(f.tipMsb?6:0)+f.tipLsb;for(let l=0;l<128;l++){let b=l*f.entryLen,p=a.subarray(b,b+f.entryLen),E=$.decode(p.subarray(0,24)).trimEnd().replace("InitProg","");E.length&&d>5&&(o+=` -${i.toString().padStart(3,"0")} ${d.toString().padStart(3,"0")} ${l.toString().padStart(3,"0")} ${E}`)}break}case"CBK1":{let i=63,d=(f.tipMsb?3:0)+f.tipLsb+10;for(let l=0;l<128;l++){let b=l*f.entryLen,p=a.subarray(b,b+f.entryLen),E=$.decode(p.subarray(0,24)).trimEnd().replace("InitCombi","");E.length&&d>12&&(o+=` -${i.toString().padStart(3,"0")} ${d.toString().padStart(3,"0")} ${l.toString().padStart(3,"0")} ${E}`)}break}}g++,g>=h.length&&(n=3,c=!1)}][n]||(()=>{c=!1}))()}return o});var ee=["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 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(","),ae={};`hi*, +063 024 ${b[19].toString().padStart(3,"0")} ${p}`),l+=d}break}case"EPVC":{let l=32,b=n;for(;b=g.length&&(c=3,h=!1)}][c]||(()=>{h=!1}))()}return o});M.set("pcg",async function(t){let s=new Uint8Array(await t.arrayBuffer()),o="MSB LSB PRG NME",e=100,n=0,r=0,c=!0,h=[],g=0;for(;c;){let u=s.subarray(e);([()=>{c=$.decode(u.subarray(0,4))=="INI2",r=u[15],e+=16,n=1},()=>{let f=$.decode(u.subarray(0,4)),a=u[5],i=u[7],d=u[11],l=x(u.subarray(12,16)),b=x(u.subarray(16,20)),p=x(u.subarray(36,40)),m=$.decode(u.subarray(44,44+d));h.push({type:f,tipMsb:a,tipLsb:i,nameLen:d,length:l,start:b,entryLen:p,name:m}),e+=64,r--,r<1&&(n=2)},()=>{let f=h[g],a=s.subarray(f.start,f.start+f.length);switch(f.type){case"PRG1":break;case"PBK1":{let i=63,d=(f.tipMsb?6:0)+f.tipLsb;for(let l=0;l<128;l++){let b=l*f.entryLen,p=a.subarray(b,b+f.entryLen),m=$.decode(p.subarray(0,24)).trimEnd().replace("InitProg","");m.length&&d>5&&(o+=` +${i.toString().padStart(3,"0")} ${d.toString().padStart(3,"0")} ${l.toString().padStart(3,"0")} ${m}`)}break}case"CBK1":{let i=63,d=(f.tipMsb?3:0)+f.tipLsb+10;for(let l=0;l<128;l++){let b=l*f.entryLen,p=a.subarray(b,b+f.entryLen),m=$.decode(p.subarray(0,24)).trimEnd().replace("InitCombi","");m.length&&d>12&&(o+=` +${i.toString().padStart(3,"0")} ${d.toString().padStart(3,"0")} ${l.toString().padStart(3,"0")} ${m}`)}break}}g++,g>=h.length&&(n=3,c=!1)}][n]||(()=>{c=!1}))()}return o});var ee=["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 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(","),ae={};`hi*, ka,か ki,き ku,く @@ -140,6 +140,6 @@ o,お ~, ^, _,`.split(` -`).forEach(t=>{let s=t.split(",");ae[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 re=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"];var ie=["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,80,81,83,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={};re.forEach((t,s)=>{se[t]=s});var S={length:D.length};D.forEach((t,s)=>{S[t]=s});var _={length:R.length};R.forEach((t,s)=>{_[t]=s});var ne={};ie.forEach((t,s)=>{ne[t]=s});var H=8,ce={port:H,ch:H<<4,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:3,efx:7,cvn:12,redir:32,invalidCh:255};var I=Z(G(),1);var X=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}},O=class extends X{constructor(t,s,o){super(!0,t,s,o)}},V=class extends X{constructor(t,s){super(!1,t,t,s)}},A=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 oe=0xffffffffffff,F=function(t){let s=new A,o=this,e=t.timeDivision,n=120,r=new A,c=0,h=0;r.push(new O(0,oe,[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 O(c,0xffffffffffff,[n,0])))})}),r.fresh(),r.forEach(function(a,i,d){i>0&&(d[i-1].end=a.start)});let g=120;r.forEach(function(a,i,d){i>0&&(a.end==a.start?d.splice(d.indexOf(a),1):g==a.data[0]&&(d[i-1].end=a.end,d.splice(d.indexOf(a),1)),g=a.data[0])});let u=0,f=120;return r.forEach(function(a){let i=a.start,d=i/f/e*60+u;f=a.data[0],u=d-i/f/e*60,a.data[1]=u}),console.debug("All tempo changes: ",r),n=120,c=0,h=0,t.track.forEach(function(a,i){c=0,h=0;let d=i+1;a.event.forEach(function(l,b){c+=l.deltaTime;let p=r.step(c,!0)[0];p&&(n=p.data[0],h=p.data[1]);let E={type:l.type,data:l.data,track:d,part:0};l.type>14?E.meta=l.metaType:E.part=l.channel,s.push(new V(c/n/e*60+h,E))})}),s.fresh(),self.midiEvents=s,console.debug(`Parsed a type ${t.formatType} MIDI sequence.`),s};I.default.customInterpreter=B;var m=function(t,s,o){t.addEventListener(o,e=>{s.dispatchEvent(o,e.data)})},ut=class extends C{device;#e;#n={};#f=[];#a="";#c=[];#h=[];#o=new Uint8ClampedArray(128);#u=new Uint8ClampedArray(128);#i=.5;#s=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.#i=.5,t.#s=120,t.#t=4,t.#l=4,t.#r=0,t.#d=0,t.dispatchEvent("tempo",t.#s),t.dispatchEvent("title",t.#a)}init(){this.reset(),this.#e=void 0}async loadFile(t){this.#e=F(I.default.parse(new Uint8Array(await t.arrayBuffer())))}async loadMap(t,s){let o=this,e=0,n=0,r=0,c,h;t.split(` +`).forEach(t=>{let s=t.split(",");ae[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 re=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"];var ie=["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,80,81,83,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={};re.forEach((t,s)=>{se[t]=s});var S={length:D.length};D.forEach((t,s)=>{S[t]=s});var _={length:R.length};R.forEach((t,s)=>{_[t]=s});var ne={};ie.forEach((t,s)=>{ne[t]=s});var H=8,ce={port:H,ch:H<<4,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:3,efx:7,cvn:12,redir:32,invalidCh:255};var I=Z(G(),1);var X=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}},O=class extends X{constructor(t,s,o){super(!0,t,s,o)}},V=class extends X{constructor(t,s){super(!1,t,t,s)}},A=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 oe=0xffffffffffff,F=function(t){let s=new A,o=this,e=t.timeDivision,n=120,r=new A,c=0,h=0;r.push(new O(0,oe,[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 O(c,0xffffffffffff,[n,0])))})}),r.fresh(),r.forEach(function(a,i,d){i>0&&(d[i-1].end=a.start)});let g=120;r.forEach(function(a,i,d){i>0&&(a.end==a.start?d.splice(d.indexOf(a),1):g==a.data[0]&&(d[i-1].end=a.end,d.splice(d.indexOf(a),1)),g=a.data[0])});let u=0,f=120;return r.forEach(function(a){let i=a.start,d=i/f/e*60+u;f=a.data[0],u=d-i/f/e*60,a.data[1]=u}),console.debug("All tempo changes: ",r),n=120,c=0,h=0,t.track.forEach(function(a,i){c=0,h=0;let d=i+1;a.event.forEach(function(l,b){c+=l.deltaTime;let p=r.step(c,!0)[0];p&&(n=p.data[0],h=p.data[1]);let m={type:l.type,data:l.data,track:d,part:0};l.type>14?m.meta=l.metaType:m.part=l.channel,s.push(new V(c/n/e*60+h,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)})},ut=class extends C{device;#e;#n={};#f=[];#a="";#c=[];#h=[];#o=new Uint8ClampedArray(128);#u=new Uint8ClampedArray(128);#i=.5;#s=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.#i=.5,t.#s=120,t.#t=4,t.#l=4,t.#r=0,t.#d=0,t.dispatchEvent("tempo",t.#s),t.dispatchEvent("title",t.#a)}init(){this.reset(),this.#e=void 0}async loadFile(t){this.#e=F(I.default.parse(new Uint8Array(await t.arrayBuffer())))}async loadMap(t,s){let o=this,e=0,n=0,r=0,c,h;t.split(` `).forEach((g,u)=>{if(!g)return;let f=g.split(" ");if(u){if(!r)return;let a="",i="";f.forEach((d,l)=>{switch(l){case c:{a=d;break}case h:{i=d;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 f.forEach((a,i)=>{switch(a){case"ID":{c=i,r++;break}case"Name":{h=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,h;t.split(` -`).forEach((g,u)=>{if(g)if(u){let f=0,a;g.split(" ").forEach((i,d)=>{switch(d){case r:{f|=parseInt(i,16)<<8;break}case c:{f|=parseInt(i,16);break}case h:{a=i;break}}}),!o.#f[f]||s?(o.#f[f]=a,e++):self.debugMode&&console.debug(`EFX ID 0x${f.toString(16).padStart(4,"0")} (${a}) seems to be in conflict.`),n++}else g.split(" ").forEach((f,a)=>{switch(f){case"MSB":{r=a;break}case"LSB":{c=a;break}case"Name":{h=a;break}default:console.debug(`Unknown EFX field: ${f}`)}})}),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.#i}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.#s}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,h=[];for(c.device.getStrength().forEach((v,y)=>{c.#u[y]=v}),c.device.newStrength(),s.forEach(function(v){let y=v.data,k=c.device.runJson(y);switch(k?.reply){case"meta":{h.push(k);break}}k?.reply&&delete k.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++)}h?.length>0&&c.dispatchEvent("meta",h);let g=c.device.getActive(),u=[],f=c.device.getPitch(),a=c.device.getCcAll(),i=c.device.getProgram(),d=c.device.getChType(),l=[],b=c.device.getStrength();b.forEach(function(v,y,k){k[y]=Math.max(c.#u[y],v);let w=k[y]-c.#o[y],L=S.length*y;if(w>=0){let T=4*.25**(a[L+S[73]]/64);c.#o[y]+=Math.ceil(w-w*c.smoothingAtk**T)}else{let T=4*.25**(a[L+S[72]]/64);c.#o[y]+=Math.floor(w-w*c.smoothingDcy**T)}});let p=0;return g.forEach(function(v,y){v&&(u[y]=c.device.getVel(y),l[y]=c.device.getExt(y),p+=u[y].size)}),{extraPoly:o,extraNotes:r,curPoly:p,chInUse:g,chKeyPr:u,chPitch:f,chProgr:i,chContr:a,chType:d,chExt:l,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:b,rpn:c.device.getRpn(),tSig:c.getTimeSig(),tempo:c.getTempo(),noteBar:c.noteBar,noteBeat:c.noteBeat,ace:c.device.getAce(),rawVelo:c.device.getStrength(),rawStrength:c.device.getRawStrength(),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)})}),m(e.device,e,"mode"),m(e.device,e,"mastervolume"),m(e.device,e,"channelactive"),m(e.device,e,"channelmin"),m(e.device,e,"channelmax"),m(e.device,e,"portrange"),m(e.device,e,"portstart"),m(e.device,e,"channelreset"),m(e.device,e,"channeltoggle"),m(e.device,e,"screen"),m(e.device,e,"metacommit"),m(e.device,e,"voice"),m(e.device,e,"pitch"),m(e.device,e,"note"),m(e.device,e,"reset"),m(e.device,e,"banklevel"),m(e.device,e,"efxreverb"),m(e.device,e,"efxchorus"),m(e.device,e,"efxdelay"),m(e.device,e,"efxinsert0"),m(e.device,e,"efxinsert1"),m(e.device,e,"efxinsert2"),m(e.device,e,"efxinsert3"),m(e.device,e,"partefxtoggle"),e.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,h=e.#i||.5;e.#s=6e7/r,e.#i=r/1e6,e.#r+=c*(h/e.#i)-c,e.dispatchEvent("tempo",e.#s)},e.#c[88]=function(n,r){let c=e.noteProgress,h=e.noteOverall,g=e.noteBar,u=e.noteBeat,f=e.#t,a=e.#l;e.#t=r[0],e.#l=1<=f&&(f{if(g)if(u){let f=0,a;g.split(" ").forEach((i,d)=>{switch(d){case r:{f|=parseInt(i,16)<<8;break}case c:{f|=parseInt(i,16);break}case h:{a=i;break}}}),!o.#f[f]||s?(o.#f[f]=a,e++):self.debugMode&&console.debug(`EFX ID 0x${f.toString(16).padStart(4,"0")} (${a}) seems to be in conflict.`),n++}else g.split(" ").forEach((f,a)=>{switch(f){case"MSB":{r=a;break}case"LSB":{c=a;break}case"Name":{h=a;break}default:console.debug(`Unknown EFX field: ${f}`)}})}),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.#i}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.#s}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,h=[];for(c.device.getStrength().forEach((v,y)=>{c.#u[y]=v}),c.device.newStrength(),s.forEach(function(v){let y=v.data,k=c.device.runJson(y);switch(k?.reply){case"meta":{h.push(k);break}}k?.reply&&delete k.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++)}h?.length>0&&c.dispatchEvent("meta",h);let g=c.device.getActive(),u=[],f=c.device.getPitch(),a=c.device.getCcAll(),i=c.device.getProgram(),d=c.device.getChType(),l=[],b=c.device.getStrength();b.forEach(function(v,y,k){k[y]=Math.max(c.#u[y],v);let w=k[y]-c.#o[y],L=S.length*y;if(w>=0){let T=4*.25**(a[L+S[73]]/64);c.#o[y]+=Math.ceil(w-w*c.smoothingAtk**T)}else{let T=4*.25**(a[L+S[72]]/64);c.#o[y]+=Math.floor(w-w*c.smoothingDcy**T)}});let p=0;return g.forEach(function(v,y){v&&(u[y]=c.device.getVel(y),l[y]=c.device.getExt(y),p+=u[y].size)}),{extraPoly:o,extraNotes:r,curPoly:p,chInUse:g,chKeyPr:u,chPitch:f,chProgr:i,chContr:a,chType:d,chExt:l,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:b,rpn:c.device.getRpn(),tSig:c.getTimeSig(),tempo:c.getTempo(),noteBar:c.noteBar,noteBeat:c.noteBeat,ace:c.device.getAce(),rawVelo:c.device.getStrength(),rawStrength:c.device.getRawStrength(),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,"portrange"),E(e.device,e,"portstart"),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,"banklevel"),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,h=e.#i||.5;e.#s=6e7/r,e.#i=r/1e6,e.#r+=c*(h/e.#i)-c,e.dispatchEvent("tempo",e.#s)},e.#c[88]=function(n,r){let c=e.noteProgress,h=e.noteOverall,g=e.noteBar,u=e.noteBeat,f=e.#t,a=e.#l;e.#t=r[0],e.#l=1<=f&&(f()=>(t||e((t={exports:{}}).exports,t),t.exports);var Je=(e,t,c,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let h of Ye(t))!je.call(e,h)&&h!==c&&ue(e,h,{get:()=>t[h],enumerable:!(l=We(t,h))||l.enumerable});return e};var et=(e,t,c)=>(c=e!=null?qe(Qe(e)):{},Je(t||!e||!e.__esModule?ue(c,"default",{value:e,enumerable:!0}):c,e));var Ne=Ze((Zt,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")],c={debug:!1,parse:function(l,h){if(l instanceof Uint8Array)return c.Uint8(l);if(typeof l=="string")return c.Base64(l);if(l instanceof HTMLElement&&l.type==="file")return c.addListener(l,h);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(l,h){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;h=h||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){h(c.Uint8(new Uint8Array(v.target.result)))}})},Base64:function(l){let h=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 i,f="",r,s,n=0;for(;n>16&255):s===64?String.fromCharCode(i>>16&255,i>>8&255):String.fromCharCode(i>>16&255,i>>8&255,255&i);return f}(l=String(l));var p=h.length;let g=new Uint8Array(new ArrayBuffer(p));for(let v=0;v{s[d]=this.readInt(1)});for(let u=0;u191||y>127&&y<160)throw new RangeError(`Invalid code point: ${y}`)}n=!0,console.debug(`String byte sequence in ${t[u].encoding}`)}catch(d){console.debug(`SMF string ${d}`)}return o||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let r=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)r=this.readInt(1);else{let n=[];for(;128<=this.data.getUint8(this.pointer);)n.push(this.readInt(1)-128);var s=this.readInt(1);for(let o=1;o<=n.length;o++)r+=n[n.length-o]*Math.pow(128,o);r+=s}return r}};if(h.data=new DataView(g.buffer,g.byteOffset,g.byteLength),h.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;h.readInt(4);let p={};p.formatType=h.readInt(2),p.tracks=h.readInt(2),p.track=[];var g=h.readInt(1),v=h.readInt(1);128<=g?(p.timeDivision=[],p.timeDivision[0]=g-128,p.timeDivision[1]=v):p.timeDivision=256*g+v;for(let r=1;r<=p.tracks;r++){p.track[r-1]={event:[]};var a,i=h.readInt(4);if(i===-1)break;if(i!==1297379947)return!1;h.readInt(4);let s=0,n=!1,o,u;for(;!n&&(s++,p.track[r-1].event[s-1]={},p.track[r-1].event[s-1].deltaTime=h.readIntVLV(),(o=h.readInt(1))!==-1);)if(128<=o?u=o:(o=u,h.movePointer(-1)),o===255){p.track[r-1].event[s-1].type=255,p.track[r-1].event[s-1].metaType=h.readInt(1);var f=h.readIntVLV();switch(p.track[r-1].event[s-1].metaType){case 47:case-1:n=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:p.track[r-1].event[s-1].data=h.readStr(f);break;case 33:case 89:case 81:p.track[r-1].event[s-1].data=h.readInt(f);break;case 84:p.track[r-1].event[s-1].data=[],p.track[r-1].event[s-1].data[0]=h.readInt(1),p.track[r-1].event[s-1].data[1]=h.readInt(1),p.track[r-1].event[s-1].data[2]=h.readInt(1),p.track[r-1].event[s-1].data[3]=h.readInt(1),p.track[r-1].event[s-1].data[4]=h.readInt(1);break;case 88:p.track[r-1].event[s-1].data=[],p.track[r-1].event[s-1].data[0]=h.readInt(1),p.track[r-1].event[s-1].data[1]=h.readInt(1),p.track[r-1].event[s-1].data[2]=h.readInt(1),p.track[r-1].event[s-1].data[3]=h.readInt(1);break;default:this.customInterpreter!==null&&(p.track[r-1].event[s-1].data=this.customInterpreter(p.track[r-1].event[s-1].metaType,h,f)),this.customInterpreter!==null&&p.track[r-1].event[s-1].data!==!1||(h.readInt(f),p.track[r-1].event[s-1].data=h.readInt(f),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((o=o.toString(16).split(""))[1]||o.unshift("0"),p.track[r-1].event[s-1].type=parseInt(o[0],16),p.track[r-1].event[s-1].channel=parseInt(o[1],16),p.track[r-1].event[s-1].type){case 15:this.customInterpreter!==null&&(p.track[r-1].event[s-1].data=this.customInterpreter(p.track[r-1].event[s-1].type,h,!1)),this.customInterpreter!==null&&p.track[r-1].event[s-1].data!==!1||(a=h.readIntVLV(),p.track[r-1].event[s-1].data=h.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[r-1].event[s-1].data=[],p.track[r-1].event[s-1].data[0]=h.readInt(1),p.track[r-1].event[s-1].data[1]=h.readInt(1);break;case 12:case 13:p.track[r-1].event[s-1].data=h.readInt(1);break;case-1:n=!0;break;default:if(this.customInterpreter!==null&&(p.track[r-1].event[s-1].data=this.customInterpreter(p.track[r-1].event[s-1].metaType,h,!1)),this.customInterpreter===null||p.track[r-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=c;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=c}})()});var pe=function(e,t){let c=Math.min(e.length,t.length),l=e.slice(0,c),h=t.slice(0,c),p=0,g=0;for(;g0){let l=this.pool.length,h=1<=1&&g>=0;){if(g<=0)throw new Error("TTL reached.");if(p==l)p-=h;else{let a=pe(t,this.pool[p]);switch(a){case 0:{g=0;break}case 1:{p+h<=l&&(p+=h);break}case-1:{p!=0&&(p-=h);break}default:console.warn(`Unexpected result ${a}.`)}}h=h>>1,g--}let v=!0;if(p>=this.pool.length)v=!1;else{let a=this;this.pool[p].forEach(function(i,f,r){v&&i!=t[f]&&(v=!1)}),!v&&pe(t,this.pool[p])>0&&p++}return v||c?p:-1}else return c?0:-1},this.add=function(t,c){return t.data=c,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 c=this.point(t);if(c>-1)return this.pool[c].data;this.default(t)},this.run=function(t,...c){let l=this.point(t);l>-1?t.subarray?this.pool[l].data(t.subarray(this.pool[l].length),...c):this.pool[l].data(t.slice(this.pool[l].length),...c):this.default(t,...c)}};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 c=this.#t[e].indexOf(t);c>-1&&this.#t[e].splice(c,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,t){let c=new Event(e),l=this;c.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(h){try{h?.call(l,c)}catch(p){console.error(p)}}),this[`on${e}`]&&this[`on${e}`](c)}};var tt=["MSB","PRG","LSB","NME","ELC","DRM"],J=function(e){let t=Math.floor(e/10),c=e%10;return`${t.toString(16)}${c}`},ee=class{#t;strictMode=!1;get(e=0,t=0,c=0,l){let h=[e,t,c],p,g=1,v=0,a,i=Array.from(arguments);switch(l){case"xg":{switch(e){case 0:{c==126?i[2]=125:c==127&&(i[2]=0);break}case 16:{c==126&&(i[2]=0);break}case 32:{c>125&&(i[2]=0),i[2]+=4;break}case 33:case 34:case 35:case 36:{c>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:{c==126&&(i[2]=0);break}case 48:case 64:case 126:case 127:{c==126&&(i[2]=0);break}}break}case"gs":case"sc":{e==0&&c<5?i[2]=0:e>125&&c<5&&c!=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>>4==7&&(i[0]=96));break}case"sg":{e==8&&c==0&&(i[2]=5);break}case"s90es":{c<8?i[2]+=17:c<32?i[2]+=13:i[2]=(i[2]>>3)+19;break}case"motif":{c<8?i[2]+=28:c<32?i[2]+=13:i[2]=(i[2]>>3)+19;break}}let f=" ",r="M",s=0,n=0;switch(i[0]){case 0:{i[2]==127?r="MT-a":i[2]==126?r="MT-b":i[2]==7?r="GM-k":i[2]==5?r="SG-a":i[2]==4?r="SP-l":i[2]==0||(l=="gs"||l=="sc")&&i[2]<5?r="GM-a":(r="y",s=3);break}case 8:{l=="sg"?r="GM-s":r="r:";break}case 32:case 33:case 34:case 35:case 36:{l=="xg"&&(r=`${["AP","VL","PF","DX","AN"][e&7]}-${"abcdefgh"[c]}`);break}case 48:{r=`yM${(i[2]>>3).toString().padStart(2,"0")}`,s=1;break}case 56:{r="GM-b";break}case 57:r=["yDOC","QY10","QY20"][i[2]-112]||"yMxv";case 61:case 120:{r="rDrm";break}case 62:{r="kDrm";break}case 63:{if(i[2]<17){let y=i[2];r=y<10?"kP:":"kC:",r+=y%10}else i[2]<34?r=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][i[2]-17]:r="Ds";break}case 64:{r="ySFX";break}case 67:{r="DX:S";break}case 80:case 81:case 82:case 83:{r=`Prg${"UABC"[i[0]-80]}`;break}case 88:case 89:case 90:case 91:{r=`Cmb${"UABC"[i[0]-88]}`;break}case 95:{r=`${["DR","PC"][i[2]]}-d`;break}case 96:{r=i[2]==106?"AP-a":i[2]>>4==1?"SDg":"PF",i[2]>63?n=63:i[2]>>4==1&&(n=16),s=3;break}case 97:{r=i[2]>>4==1?"SDa":"VL:",s=3,i[2]>>4==1?n=16:n=112;break}case 98:{r=i[2]>>4==1?"SDb":"SG-a",s=3,n=16;break}case 99:{r=i[2]>>4==1?"SDc":"DX",i[2]>63?n=63:i[2]>>4==1&&(n=16),s=3;break}case 100:{r="AN",i[2]>63?n=63:i[2]>>4==1&&(n=16),s=3;break}case 104:case 105:case 106:case 107:{r="SDd",n=104;break}case 121:{r=`GM-${i[2]?"":"a"}`,s=3;break}case 122:{r="lDrm";break}case 126:{r="yDrS";break}case 127:{i[2]==127?r="rDrm":r="yDrm";break}default:i[0]<48?r="r:":r="M"}r.length<4&&(r+=`${[e,c,i[0],i[2]][s]-n}`.padStart(4-r.length,"0")),l=="xg"&&(e==0?i[2]<100?r=r.replace("y0","y:"):i[2]==125&&(r="y126"):e==16?(p=`Voice${((i[2]<<7)+i[1]+1).toString().padStart(3,"0")}`,f=" "):e==35&&c>>1==2&&(p=`DXCH_${(((i[2]&1)<<7)+t+1).toString().padStart(3,"0")}`,f=" "));let o=[i[0],i[1],i[2]];for(;!(p?.length>=0);)if(p=this.#t[i[1]||0][(i[0]<<7)+i[2]]?.name,p){let y=this.#t[i[1]||0][(i[0]<<7)+i[2]];g=y?.poly||g,v=y?.type||v,a=y?.drum}else if(this.strictMode)p="",f="?";else if(i[0]==0&&i[1]==0&&i[2]==0)p="Unloaded";else if(this.#t[i[1]||0][i[0]<<7])i[0]==0?(i[2]=0,f="^"):i[2]<1?(i[0]=0,f="*"):(i[2]--,f="^");else if(e==48)i[0]=0,i[2]=0,f="!";else if(e==62)i[1]--,f=" ",i[1]<1&&!p?.length&&(i[0]=0,f="!");else if(e<63)i[0]==0?(i[2]=0,f="^"):i[2]<1?(i[0]=0,f="*"):i[2]--;else if(e==80)p=`PrgU:${t.toString().padStart(3,"0")}`,f="!";else if(e==88)p=`CmbU:${t.toString().padStart(3,"0")}`,f="!";else if(e==121)p=`GM2Vox0${c}`,f="#";else if(e==122)if(i[1]==32?i[1]==0:i[1]%=7,p=this.#t[i[1]||0][(i[0]<<7)+i[2]]?.name,p){f=" ";let y=this.#t[i[1]||0][(i[0]<<7)+i[2]];g=y?.poly||g,v=y?.type||v,a=y?.drum}else p="",f="*";else i[1]==0?(p=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")}`,f="!"):i[0]==0?(i[2]=0,f="^"):i[2]>0?i[2]--:i[1]>0?(i[1]=0,f="!"):(i[0]=0,f="?");let u=[i[0],i[1],i[2]];(l=="gs"||l=="sc"||l=="ns5r")&&f=="^"&&(f=" "),e==127&&f=="^"&&(f=" "),f!=" "&&self.debugMode&&(p="");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&&l=="xg"?d="XG":d="GS")}return{name:p||`${J(e||0)} ${J(t||0)} ${J(c||0)}`,poly:g,type:v,drum:a,iid:o,eid:u,sid:h,ending:f,sect:r,standard:d}}async load(e,t,c="(internal)"){let l=this,h=[],p=0,g=0;e.split(` -`).forEach(function(v,a){let i=v.split(" "),f=[];if(a==0){if(i.forEach(function(r,s){h[tt.indexOf(r)]=s}),h.length<4){console.debug("Debugger launched.");debugger}}else{let r=0,s=0,n=0,o,u=1,d=0,y;i.forEach(async function(w,x){switch(x){case h[0]:{r=parseInt(w);break}case h[1]:{s=parseInt(w);break}case h[2]:{n=parseInt(w);break}case h[3]:{o=w;break}case h[4]:{w=parseInt(w),w<16?u=w+1:d=(w&15)+1;break}case h[5]:{y=w;break}}}),l.#t[s]=l.#t[s]||[];let E=l.#t[s];if(!E[r<<7|n]||t){let w={msb:r,prg:s,lsb:n,name:o,poly:u,type:d,drum:y};E[r<<7|n]=w,p++}g++}}),t||console.debug(`Map "${c}": ${g} total, ${p} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],c=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],l=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let h=c[0];h<=c[1];h++){let p=h<<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(c){try{await fetch(`./data/bank/${c}.tsv`).then(function(l){return l.text()}).then(l=>{t.load(l,!1,c)})}catch{console.error(`Failed loading "${c}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var be=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 at=function(e,t){let c=!0;return t.forEach((l,h)=>{c=c&&e[h]==l}),c},V=function(e){let t=0;return e.forEach(c=>{t*=256,t+=c}),t},I=new TextDecoder,G=new be;G.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),c="MSB LSB PRG NME",l=[0,0,0,0],h=32,p=0,g=0,v=!0,a=[],i=0;for(;v;){let f=t.subarray(p);([()=>{I.decode(f.subarray(0,4))=="YSFC"?(p+=80,g=1):p++},()=>{if(at(f.subarray(0,4),l))a.forEach((r,s,n)=>{let o=V(t.subarray(r.start+4,r.start+8));r.length=o}),g=2;else{let r=I.decode(f.subarray(0,4)),s=V(f.subarray(4,8));a.push({type:r,start:s}),p+=8}},()=>{let r=a[i],s=t.subarray(r.start,r.start+r.length),n=32;switch(r.type){case"ENVC":{let o=h;for(;o=a.length&&(g=3,v=!1)}][g]||(()=>{v=!1}))()}return c});G.set("pcg",async function(e){let t=new Uint8Array(await e.arrayBuffer()),c="MSB LSB PRG NME",l=100,h=0,p=0,g=!0,v=[],a=0;for(;g;){let i=t.subarray(l);([()=>{g=I.decode(i.subarray(0,4))=="INI2",p=i[15],l+=16,h=1},()=>{let f=I.decode(i.subarray(0,4)),r=i[5],s=i[7],n=i[11],o=V(i.subarray(12,16)),u=V(i.subarray(16,20)),d=V(i.subarray(36,40)),y=I.decode(i.subarray(44,44+n));v.push({type:f,tipMsb:r,tipLsb:s,nameLen:n,length:o,start:u,entryLen:d,name:y}),l+=64,p--,p<1&&(h=2)},()=>{let f=v[a],r=t.subarray(f.start,f.start+f.length);switch(f.type){case"PRG1":break;case"PBK1":{let s=63,n=(f.tipMsb?6:0)+f.tipLsb;for(let o=0;o<128;o++){let u=o*f.entryLen,d=r.subarray(u,u+f.entryLen),y=I.decode(d.subarray(0,24)).trimEnd().replace("InitProg","");y.length&&n>5&&(c+=` -${s.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")} ${y}`)}break}case"CBK1":{let s=63,n=(f.tipMsb?3:0)+f.tipLsb+10;for(let o=0;o<128;o++){let u=o*f.entryLen,d=r.subarray(u,u+f.entryLen),y=I.decode(d.subarray(0,24)).trimEnd().replace("InitCombi","");y.length&&n>12&&(c+=` +var qe=Object.create;var ue=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var Ye=Object.getOwnPropertyNames;var Qe=Object.getPrototypeOf,je=Object.prototype.hasOwnProperty;var Ze=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Je=(e,t,c,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let h of Ye(t))!je.call(e,h)&&h!==c&&ue(e,h,{get:()=>t[h],enumerable:!(l=We(t,h))||l.enumerable});return e};var et=(e,t,c)=>(c=e!=null?qe(Qe(e)):{},Je(t||!e||!e.__esModule?ue(c,"default",{value:e,enumerable:!0}):c,e));var Ne=Ze((Zt,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")],c={debug:!1,parse:function(l,h){if(l instanceof Uint8Array)return c.Uint8(l);if(typeof l=="string")return c.Base64(l);if(l instanceof HTMLElement&&l.type==="file")return c.addListener(l,h);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(l,h){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;h=h||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){h(c.Uint8(new Uint8Array(v.target.result)))}})},Base64:function(l){let h=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 i,d="",r,s,n=0;for(;n>16&255):s===64?String.fromCharCode(i>>16&255,i>>8&255):String.fromCharCode(i>>16&255,i>>8&255,255&i);return d}(l=String(l));var p=h.length;let g=new Uint8Array(new ArrayBuffer(p));for(let v=0;v{s[f]=this.readInt(1)});for(let u=0;u191||y>127&&y<160)throw new RangeError(`Invalid code point: ${y}`)}n=!0,console.debug(`String byte sequence in ${t[u].encoding}`)}catch(f){console.debug(`SMF string ${f}`)}return o||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let r=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)r=this.readInt(1);else{let n=[];for(;128<=this.data.getUint8(this.pointer);)n.push(this.readInt(1)-128);var s=this.readInt(1);for(let o=1;o<=n.length;o++)r+=n[n.length-o]*Math.pow(128,o);r+=s}return r}};if(h.data=new DataView(g.buffer,g.byteOffset,g.byteLength),h.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;h.readInt(4);let p={};p.formatType=h.readInt(2),p.tracks=h.readInt(2),p.track=[];var g=h.readInt(1),v=h.readInt(1);128<=g?(p.timeDivision=[],p.timeDivision[0]=g-128,p.timeDivision[1]=v):p.timeDivision=256*g+v;for(let r=1;r<=p.tracks;r++){p.track[r-1]={event:[]};var a,i=h.readInt(4);if(i===-1)break;if(i!==1297379947)return!1;h.readInt(4);let s=0,n=!1,o,u;for(;!n&&(s++,p.track[r-1].event[s-1]={},p.track[r-1].event[s-1].deltaTime=h.readIntVLV(),(o=h.readInt(1))!==-1);)if(128<=o?u=o:(o=u,h.movePointer(-1)),o===255){p.track[r-1].event[s-1].type=255,p.track[r-1].event[s-1].metaType=h.readInt(1);var d=h.readIntVLV();switch(p.track[r-1].event[s-1].metaType){case 47:case-1:n=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:p.track[r-1].event[s-1].data=h.readStr(d);break;case 33:case 89:case 81:p.track[r-1].event[s-1].data=h.readInt(d);break;case 84:p.track[r-1].event[s-1].data=[],p.track[r-1].event[s-1].data[0]=h.readInt(1),p.track[r-1].event[s-1].data[1]=h.readInt(1),p.track[r-1].event[s-1].data[2]=h.readInt(1),p.track[r-1].event[s-1].data[3]=h.readInt(1),p.track[r-1].event[s-1].data[4]=h.readInt(1);break;case 88:p.track[r-1].event[s-1].data=[],p.track[r-1].event[s-1].data[0]=h.readInt(1),p.track[r-1].event[s-1].data[1]=h.readInt(1),p.track[r-1].event[s-1].data[2]=h.readInt(1),p.track[r-1].event[s-1].data[3]=h.readInt(1);break;default:this.customInterpreter!==null&&(p.track[r-1].event[s-1].data=this.customInterpreter(p.track[r-1].event[s-1].metaType,h,d)),this.customInterpreter!==null&&p.track[r-1].event[s-1].data!==!1||(h.readInt(d),p.track[r-1].event[s-1].data=h.readInt(d),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((o=o.toString(16).split(""))[1]||o.unshift("0"),p.track[r-1].event[s-1].type=parseInt(o[0],16),p.track[r-1].event[s-1].channel=parseInt(o[1],16),p.track[r-1].event[s-1].type){case 15:this.customInterpreter!==null&&(p.track[r-1].event[s-1].data=this.customInterpreter(p.track[r-1].event[s-1].type,h,!1)),this.customInterpreter!==null&&p.track[r-1].event[s-1].data!==!1||(a=h.readIntVLV(),p.track[r-1].event[s-1].data=h.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[r-1].event[s-1].data=[],p.track[r-1].event[s-1].data[0]=h.readInt(1),p.track[r-1].event[s-1].data[1]=h.readInt(1);break;case 12:case 13:p.track[r-1].event[s-1].data=h.readInt(1);break;case-1:n=!0;break;default:if(this.customInterpreter!==null&&(p.track[r-1].event[s-1].data=this.customInterpreter(p.track[r-1].event[s-1].metaType,h,!1)),this.customInterpreter===null||p.track[r-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=c;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=c}})()});var pe=function(e,t){let c=Math.min(e.length,t.length),l=e.slice(0,c),h=t.slice(0,c),p=0,g=0;for(;g0){let l=this.pool.length,h=1<=1&&g>=0;){if(g<=0)throw new Error("TTL reached.");if(p==l)p-=h;else{let a=pe(t,this.pool[p]);switch(a){case 0:{g=0;break}case 1:{p+h<=l&&(p+=h);break}case-1:{p!=0&&(p-=h);break}default:console.warn(`Unexpected result ${a}.`)}}h=h>>1,g--}let v=!0;if(p>=this.pool.length)v=!1;else{let a=this;this.pool[p].forEach(function(i,d,r){v&&i!=t[d]&&(v=!1)}),!v&&pe(t,this.pool[p])>0&&p++}return v||c?p:-1}else return c?0:-1},this.add=function(t,c){return t.data=c,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 c=this.point(t);if(c>-1)return this.pool[c].data;this.default(t)},this.run=function(t,...c){let l=this.point(t);l>-1?t.subarray?this.pool[l].data(t.subarray(this.pool[l].length),...c):this.pool[l].data(t.slice(this.pool[l].length),...c):this.default(t,...c)}};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 c=this.#t[e].indexOf(t);c>-1&&this.#t[e].splice(c,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,t){let c=new Event(e),l=this;c.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(h){try{h?.call(l,c)}catch(p){console.error(p)}}),this[`on${e}`]&&this[`on${e}`](c)}};var tt=["MSB","PRG","LSB","NME","ELC","DRM"],J=function(e){let t=Math.floor(e/10),c=e%10;return`${t.toString(16)}${c}`},ee=class{#t;strictMode=!1;get(e=0,t=0,c=0,l){let h=[e,t,c],p,g=1,v=0,a,i=Array.from(arguments);switch(l){case"xg":{switch(e){case 0:{c==126?i[2]=125:c==127&&(i[2]=0);break}case 16:{c==126&&(i[2]=0);break}case 32:{c>125&&(i[2]=0),i[2]+=4;break}case 33:case 34:case 35:case 36:{c>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:{c==126&&(i[2]=0);break}case 48:case 64:case 126:case 127:{c==126&&(i[2]=0);break}}break}case"gs":case"sc":{e==0&&c<5?i[2]=0:e>125&&c<5&&c!=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>>4==7&&(i[0]=96));break}case"sg":{e==8&&c==0&&(i[2]=5);break}case"s90es":{c<8?i[2]+=17:c<32?i[2]+=13:i[2]=(i[2]>>3)+19;break}case"motif":{c<8?i[2]+=28:c<32?i[2]+=13:i[2]=(i[2]>>3)+19;break}}let d=" ",r="M",s=0,n=0;switch(i[0]){case 0:{i[2]==127?r="MT-a":i[2]==126?r="MT-b":i[2]==7?r="GM-k":i[2]==5?r="SG-a":i[2]==4?r="SP-l":i[2]==0||(l=="gs"||l=="sc")&&i[2]<5?r="GM-a":(r="y",s=3);break}case 8:{l=="sg"?r="GM-s":r="r:";break}case 32:case 33:case 34:case 35:case 36:{l=="xg"&&(r=`${["AP","VL","PF","DX","AN"][e&7]}-${"abcdefgh"[c]}`);break}case 48:{r=`yM${(i[2]>>3).toString().padStart(2,"0")}`,s=1;break}case 56:{r="GM-b";break}case 57:r=["yDOC","QY10","QY20"][i[2]-112]||"yMxv";case 61:case 120:{r="rDrm";break}case 62:{r="kDrm";break}case 63:{if(i[2]<17){let y=i[2];r=y<10?"kP:":"kC:",r+=y%10}else i[2]<34?r=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][i[2]-17]:r="Ds";break}case 64:{r="ySFX";break}case 67:{r="DX:S";break}case 80:case 81:case 82:case 83:{r=`Prg${"UABC"[i[0]-80]}`;break}case 88:case 89:case 90:case 91:{r=`Cmb${"UABC"[i[0]-88]}`;break}case 95:{r=`${["DR","PC"][i[2]]}-d`;break}case 96:{r=i[2]==106?"AP-a":i[2]>>4==1?"SDg":"PF",i[2]>63?n=63:i[2]>>4==1&&(n=16),s=3;break}case 97:{r=i[2]>>4==1?"SDa":"VL:",s=3,i[2]>>4==1?n=16:n=112;break}case 98:{r=i[2]>>4==1?"SDb":"SG-a",s=3,n=16;break}case 99:{r=i[2]>>4==1?"SDc":"DX",i[2]>63?n=63:i[2]>>4==1&&(n=16),s=3;break}case 100:{r="AN",i[2]>63?n=63:i[2]>>4==1&&(n=16),s=3;break}case 104:case 105:case 106:case 107:{r="SDd",n=104;break}case 121:{r=`GM-${i[2]?"":"a"}`,s=3;break}case 122:{r="lDrm";break}case 126:{r="yDrS";break}case 127:{i[2]==127?r="rDrm":r="yDrm";break}default:i[0]<48?r="r:":r="M"}r.length<4&&(r+=`${[e,c,i[0],i[2]][s]-n}`.padStart(4-r.length,"0")),l=="xg"&&(e==0?i[2]<100?r=r.replace("y0","y:"):i[2]==125&&(r="y126"):e==16?(p=`Voice${((i[2]<<7)+i[1]+1).toString().padStart(3,"0")}`,d=" "):e==35&&c>>1==2&&(p=`DXCH_${(((i[2]&1)<<7)+t+1).toString().padStart(3,"0")}`,d=" "));let o=[i[0],i[1],i[2]];for(;!(p?.length>=0);)if(p=this.#t[i[1]||0][(i[0]<<7)+i[2]]?.name,p){let y=this.#t[i[1]||0][(i[0]<<7)+i[2]];g=y?.poly||g,v=y?.type||v,a=y?.drum}else if(this.strictMode)p="",d="?";else if(i[0]==0&&i[1]==0&&i[2]==0)p="Unloaded";else if(this.#t[i[1]||0][i[0]<<7])i[0]==0?(i[2]=0,d="^"):i[2]<1?(i[0]=0,d="*"):(i[2]--,d="^");else if(e==48)i[0]=0,i[2]=0,d="!";else if(e==62)i[1]--,d=" ",i[1]<1&&!p?.length&&(i[0]=0,d="!");else if(e<63)i[0]==0?(i[2]=0,d="^"):i[2]<1?(i[0]=0,d="*"):i[2]--;else if(e==80)p=`PrgU:${t.toString().padStart(3,"0")}`,d="!";else if(e==88)p=`CmbU:${t.toString().padStart(3,"0")}`,d="!";else if(e==121)p=`GM2Vox0${c}`,d="#";else if(e==122)if(i[1]==32?i[1]==0:i[1]%=7,p=this.#t[i[1]||0][(i[0]<<7)+i[2]]?.name,p){d=" ";let y=this.#t[i[1]||0][(i[0]<<7)+i[2]];g=y?.poly||g,v=y?.type||v,a=y?.drum}else p="",d="*";else i[1]==0?(p=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")}`,d="!"):i[0]==0?(i[2]=0,d="^"):i[2]>0?i[2]--:i[1]>0?(i[1]=0,d="!"):(i[0]=0,d="?");let u=[i[0],i[1],i[2]];(l=="gs"||l=="sc"||l=="ns5r")&&d=="^"&&(d=" "),e==127&&d=="^"&&(d=" "),d!=" "&&self.debugMode&&(p="");let f="??";switch(i[0]){case 0:{i[2]==0?f="GM":i[2]==5||i[2]==7?f="KG":i[2]<126?f="XG":i[2]==127&&(f="MT");break}case 32:case 33:case 35:case 36:{i[2]>4?f=["AP","VL","PF","DX","AN"][i[0]-32]:f="GS";break}case 48:{f="MU";break}case 56:{f="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{f="AI";break}case 62:case 82:case 90:{f="XD";break}case 63:{i[2]<17?f="KR":i[2]<34?f="ES":f="DS";break}case 64:case 126:{f="XG";break}case 67:case 99:{f=i[2]>>4==1?"SD":"DX";break}case 81:{f="RW";break}case 95:{f=["DR","PC"][i[2]];break}case 96:{f=i[2]==106?"AP":i[2]>>4==1?"SD":"PF";break}case 97:{f=i[2]>>4==1?"SD":"VL";break}case 98:{f=i[2]>>4==1?"SD":"SG";break}case 100:{f="AN";break}case 104:case 105:case 106:case 107:{f="SD";break}case 120:{f="GS";break}case 121:{f=i[2]?"G2":"GM";break}case 122:{f="KG";break}case 127:{f=i[2]==127?"MT":t==0?"GM":"XG";break}default:i[0]<48&&(i[0]==16&&l=="xg"?f="XG":f="GS")}return{name:p||`${J(e||0)} ${J(t||0)} ${J(c||0)}`,poly:g,type:v,drum:a,iid:o,eid:u,sid:h,ending:d,sect:r,standard:f}}async load(e,t,c="(internal)"){let l=this,h=[],p=0,g=0;e.split(` +`).forEach(function(v,a){let i=v.split(" "),d=[];if(a==0){if(i.forEach(function(r,s){h[tt.indexOf(r)]=s}),h.length<4){console.debug("Debugger launched.");debugger}}else{let r=0,s=0,n=0,o,u=1,f=0,y;i.forEach(async function(w,x){switch(x){case h[0]:{r=parseInt(w);break}case h[1]:{s=parseInt(w);break}case h[2]:{n=parseInt(w);break}case h[3]:{o=w;break}case h[4]:{w=parseInt(w),w<16?u=w+1:f=(w&15)+1;break}case h[5]:{y=w;break}}}),l.#t[s]=l.#t[s]||[];let E=l.#t[s];if(!E[r<<7|n]||t){let w={msb:r,prg:s,lsb:n,name:o,poly:u,type:f,drum:y};E[r<<7|n]=w,p++}g++}}),t||console.debug(`Map "${c}": ${g} total, ${p} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],c=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],l=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let h=c[0];h<=c[1];h++){let p=h<<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(c){try{await fetch(`./data/bank/${c}.tsv`).then(function(l){return l.text()}).then(l=>{t.load(l,!1,c)})}catch{console.error(`Failed loading "${c}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var be=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 at=function(e,t){let c=!0;return t.forEach((l,h)=>{c=c&&e[h]==l}),c},V=function(e){let t=0;return e.forEach(c=>{t*=256,t+=c}),t},I=new TextDecoder,G=new be;G.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),c="MSB LSB PRG NME",l=[0,0,0,0],h=32,p=0,g=0,v=!0,a=[],i=0;for(;v;){let d=t.subarray(p);([()=>{I.decode(d.subarray(0,4))=="YSFC"?(p+=80,g=1):p++},()=>{if(at(d.subarray(0,4),l))a.forEach((r,s,n)=>{let o=V(t.subarray(r.start+4,r.start+8));r.length=o}),g=2;else{let r=I.decode(d.subarray(0,4)),s=V(d.subarray(4,8));a.push({type:r,start:s}),p+=8}},()=>{let r=a[i],s=t.subarray(r.start,r.start+r.length),n=32;switch(r.type){case"ENVC":{let o=h;for(;o=a.length&&(g=3,v=!1)}][g]||(()=>{v=!1}))()}return c});G.set("pcg",async function(e){let t=new Uint8Array(await e.arrayBuffer()),c="MSB LSB PRG NME",l=100,h=0,p=0,g=!0,v=[],a=0;for(;g;){let i=t.subarray(l);([()=>{g=I.decode(i.subarray(0,4))=="INI2",p=i[15],l+=16,h=1},()=>{let d=I.decode(i.subarray(0,4)),r=i[5],s=i[7],n=i[11],o=V(i.subarray(12,16)),u=V(i.subarray(16,20)),f=V(i.subarray(36,40)),y=I.decode(i.subarray(44,44+n));v.push({type:d,tipMsb:r,tipLsb:s,nameLen:n,length:o,start:u,entryLen:f,name:y}),l+=64,p--,p<1&&(h=2)},()=>{let d=v[a],r=t.subarray(d.start,d.start+d.length);switch(d.type){case"PRG1":break;case"PBK1":{let s=63,n=(d.tipMsb?6:0)+d.tipLsb;for(let o=0;o<128;o++){let u=o*d.entryLen,f=r.subarray(u,u+d.entryLen),y=I.decode(f.subarray(0,24)).trimEnd().replace("InitProg","");y.length&&n>5&&(c+=` +${s.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")} ${y}`)}break}case"CBK1":{let s=63,n=(d.tipMsb?3:0)+d.tipLsb+10;for(let o=0;o<128;o++){let u=o*d.entryLen,f=r.subarray(u,u+d.entryLen),y=I.decode(f.subarray(0,24)).trimEnd().replace("InitCombi","");y.length&&n>12&&(c+=` ${s.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")} ${y}`)}break}}a++,a>=v.length&&(h=3,g=!1)}][h]||(()=>{g=!1}))()}return c});var _=["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"]),F=["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"],rt=[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],X=[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],me=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],ge=function(e){let t=.1,c=-.3;return e>66?(t=5,c=315):e>56?(t=1,c=47):e>46&&(t=.5,c=18.5),t*e-c},ye=function(e){return e>105?rt[e-106]:e>100?e*1.1-100:e/10},ve=",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,き @@ -141,8 +141,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let t=e.split(",");te[t[0]]=t[1]});var Ee=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 te)t=t.replaceAll(l,te[l]);t.indexOf("ん")==0&&t.length>1&&(t=t.slice(1));let c=t.indexOf("!");return c>-1&&t.length>1&&(t=t.slice(c+1)),t},we=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var ae=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],$e=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ke=["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 it={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"},st={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]]},re=function(e){return it[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},xe=function(e,t,c){let l=(e[0]-32<<16)+(e[1]<<8)+t,h=st[l]||{},p=h[0];if(p?.length)return p+=`: ${(h[1]||function(){})(c)||c}`,p},ie=[68,48,95,78,41,3,110,122,0];var P=function(e=64){return Math.round(2e3*Math.log10(e/64))/100},Te=function(e,t,c){let l=[],h=c==!1?t.readIntVLV():c;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(c=>{t+=c,t=t&127}),~t+1&127},A=function(e,t){let c=0,l=0;for(let h=0;h>p&1)<<7,v=e[h];v+=g,h%8!=0?(t(v,c,e),c++):l=e[h]}};var K=function(e){let t=Math.floor(e*14.2);return t<128?t:0},T=function(){return!!self.Bun||self.debugMode||!1};var C=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"],nt={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",trinity:"trin","tr-rack":"trin"},ct=["melodic","drum","menu"],Se={"?":[0,0,120],gm:[0,0,127],gs:[0,0,120],sc:[0,0,120],xg:[0,0,127],g2:[0,0,120],mt32:[0,127,127],doc:[57,112,127],qy10:[57,113,127],qy20:[57,114,127],ns5r:[0,0,61],x5d:[82,0,62],"05rw":[81,0,62],k11:[0,0,122],sg:[0,0,122],sd:[97,0,105],krs:[63,0,120],s90es:[63,0,127],motif:[63,0,127],trin:[63,0,127]};var se=[120,127,120,127,120,127,127,61,62,62,122,122,105,120,127,127,127],Ce=[9,25,41,57,73,89,105,121],ot=[0,3,81,84,88],Me={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Re={0:0,1:1,2:3,5:4},Pe={0:0,1:1,2:2,5:3},De=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Oe=[36,37,48,49,52,53],Y=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Ae={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,80,81,83,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],lt=[2,12,13,14,15,16,17,18,19,20,21,80,81,83,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],dt=[33,99,100,32,102,8,9,10],Le=[0,16,25,40,32,64,26,48],$={};C.forEach((e,t)=>{$[e]=t});var b={length:z.length};z.forEach((e,t)=>{b[e]=t});var D={length:Y.length};Y.forEach((e,t)=>{D[e]=t});var ft={};ct.forEach((e,t)=>{ft[e]=t});var ht=function(e){let t=[],c=0;return e?.forEach(function(l,h){l==247?t.push(e.subarray(c,h)):l==240&&(c=h+1)}),t.length||t.push(e.subarray(0)),T()&&console.debug(t),t};var Ie=8,m={port:Ie,ch:Ie<<4,cc:z.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:Y.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255},H={bank0:128},Ue=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;DUMP_ALL=0;DUMP_ONCE=1;DUMP_MODE=2;EXT_NONE=0;EXT_VL=1;EXT_DX=3;VLBC_BRTHEXPR=1;VLBC_VELOINIT=2;VLBC_VELOALL=3;CH_INACTIVE=0;CH_ACTIVE=1;CH_DISABLED=2;#t=0;#m=0;#T=0;#d=new Array(11);get#E(){return this.#d[this.#m]}set#E(e){this.#d[this.#m]=e}#$=new Uint8Array(m.ch);#f=new Uint8Array(m.ch);#i=new Uint8Array(m.ch);#e=new Uint8Array(m.ch*m.cc);#b=new Uint8Array(m.ace);#r=new Uint8Array(m.ch);#h=new Uint8Array(m.ch*m.nn);#g=new Uint8Array(m.ch);#u=new Uint16Array(m.pl);#k=new Uint8Array(m.pl);#L=new Int16Array(m.ch);#I=new Uint8Array(m.ch);#U=0;#M=new Uint8Array(m.ch*m.ext);#s=new Uint8Array(m.ch*m.rpn);#o=new Uint8Array(m.ch*m.rpnt);#X=new Int8Array(m.ch*Oe.length);#l=new Uint8Array(m.drm*m.dpn*m.dnc);#P=new Uint8Array(m.drm*2);#S=new Uint8Array(m.efx*3);#a=new Uint8Array(m.ch);#R=new Uint8Array(m.ch*m.redir);#n=new Uint8Array(m.port);#y=new Uint8Array(m.ch);#w=new Uint8Array(m.ch);#z=new Uint8Array(m.ch*m.cvn);#O=new Uint8Array(128);#A=new Uint8Array(m.cmt*8);#q=new Uint8Array(1024);#F=new Uint8Array(m.cmt*64);#x={};#c;#H;#Y;#p=100;#G=0;#ne=500;#ce=0;#Q="";#j=0;#le=0;#oe=0;#_=!0;#v=!1;#he=1;#de;#J=new Array(m.ch);#pe=new Uint8Array(2);#N=[];#W=new Uint8Array(m.ch);#Z=new Uint8Array(m.tr);baseBank=new ee("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es");userBank=new ee("gm");initOnReset=!1;aiEfxName="";chRedir(e,t,c){let l=this;if(l.#Z[t])return(l.#Z[t]-1)*16+e;if(l.#t==$.sc){if(c==1)return e;let h=0,p=!0;for(;p;)l.#W[e+h]==0?(l.#W[e+h]=t,console.debug(`Assign track ${t} to channel ${e+h+1}.`),p=!1):this.#W[e+h]==t?p=!1:(h+=16,h>=128&&(h=0,p=!1));return e+h}else return e}getTrackPort(e){return this.chRedir(0,e,!0)>>4}forceVoiceRefresh(){for(let e=0;e{let c=e*128+t,l=this.#u.lastIndexOf(c);if(l>-1)if(this.#e[m.cc*e+b[64]]>63)this.#k[l]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#h[c],state:this.NOTE_HELD});else if(this.#e[m.cc*e+b[66]]>63&&this.#k[l]==this.NOTE_SOSTENUTO_SUSTAIN)this.#k[l]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#h[c],state:this.NOTE_SOSTENUTO_HELD});else{this.#u[l]=0,this.#h[c]=0,this.#k[l]=this.NOTE_IDLE;let h=this.getExt(e)[1];(h==this.VLBC_VELOINIT||h==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,c)=>{let l=e*128+t,h=0;for(this.#g[e]&&this.#C.ano(e);this.#k[h]>0&&this.#u[h]!=l;)h++;if(h{},cAt:(e,t)=>{},hoOf:e=>{this.#k.forEach((t,c)=>{if(t==this.NOTE_HELD){let l=this.#u[c],h=l>>7;e==h&&(this.#k[c]=this.NOTE_IDLE,this.#u[c]=0,this.#h[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#k.forEach((t,c)=>{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.#k[c]=l;let h=this.#u[c];this.dispatchEvent("note",{part:e,note:h&127,velo:this.#h[h],state:l})}})},soOf:e=>{this.#k.forEach((t,c)=>{if(t==this.NOTE_SOSTENUTO_HELD){let l=this.#u[c],h=l>>7;e==h&&(this.#k[c]=this.NOTE_IDLE,this.#u[c]=0,this.#h[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#u.forEach((t,c,l)=>{let h=t>>7,p=t&127;t==0&&this.#h[0]==0||h==e&&this.#C.nOff(h,p)})}};#fe={8:function(e){let t=e.channel,c=e.data[0];this.#C.nOff(t,c)},9:function(e){let t=e.channel,c=this;if(c.getChModeId(t)==$.xg&&c.#i[t]>1){let p=c.getChDrumFirstWrite(t);p[0]&&p[1]!=m.invalidCh&&!c.#$[t]&&(c.copyChSetup(p[1],t),c.dispatchEvent("voice",{part:t}),console.debug(`Part CH${t+1} copied from CH${p[1]}.`))}c.setChActive(t,1);let l=e.data[0],h=e.data[1];h>0?c.#C.nOn(t,l,h):c.#C.nOff(t,l)},10:function(e){let t=e.channel,c=t*128+e.data[0];this.#u.indexOf(c)>-1&&(this.#h[c]=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,c=this,l=this.#J[t],h=l[e.data[0]];h&&(e.data[0]=h),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case $.s90es:case $.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 p=t*m.cc,g=t*m.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#C.ano(t),this.#L[t]=0,this.#e[p+b[1]]=0,this.#e[p+b[5]]=0,this.#e[p+b[64]]=0,this.#e[p+b[65]]=0,this.#e[p+b[66]]=0,this.#e[p+b[67]]=0,this.#e[p+b[11]]=127,this.#e[p+b[101]]=127,this.#e[p+b[100]]=127,this.#e[p+b[99]]=127,this.#e[p+b[98]]=127;return}case 123:{this.#C.ano(t);return}case 124:{this.#C.ano(t);return}case 125:{this.#C.ano(t);return}case 126:{this.#g[t]=1,this.#C.ano(t);return}case 127:{this.#g[t]=0,this.#C.ano(t);return}}if(b[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(lt.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(T()&&console.debug(`${C[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#i[t]>0&&(e.data[1]=this.#e[p],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]==56?this.switchMode(this.#c.x5==82?"x5d":"05rw"):e.data[1]==62?this.switchMode(this.#c.x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(C[this.#c.ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==$.gs||this.#t==$.sc?e.data[1]<56&&this.#i[t]>0&&(e.data[1]=this.#e[p],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)):this.#t==$.gm&&(e.data[1]<48?this.#i[t]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${t+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0)),this.#t){case $.xg:{[79,95,126,127].indexOf(e.data[1])>-1?this.#i[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?this.#M[g]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?this.#M[g]=this.EXT_DX:this.#M[g]=this.EXT_NONE;break}case $["05rw"]:case $.x5d:case $.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#i[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.#i[t]!=this.CH_MELODIC&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case $.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#i[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case $.g2:{e.data[1]==120?this.#i[t]==0&&(this.setChType(t,this.CH_DRUMS),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:t});break}case 2:{this.getExt(t)[1]==this.VLBC_BRTHEXPR&&(this.#e[p+b[129]]=e.data[1]);break}case 6:{if(this.#U){[$.xg,$.gs,$.sc,$.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${C[this.#t]}" mode, even when they are supported in Octavia.`);let v=this.#e[p+b[99]],a=this.#e[p+b[98]];if(v==1){let i=dt.indexOf(a);if(i>-1)this.#e[p+b[71+i]]=e.data[1],T()&&console.debug(`Redirected NRPN 1 ${a} to cc${71+i}.`),this.dispatchEvent("cc",{part:t,cc:71+i,data:e.data[1]});else{let f=Oe.indexOf(a);f>-1?this.#X[t*10+f]=e.data[1]-64:console.warn(`NRPN 0x01${a.toString(16).padStart(2,"0")} is not supported.`),T()&&console.debug(`CH${t+1} voice NRPN ${a} commit`)}}else{if(Y.indexOf(v)<0){let f=`NRPN 0x${v.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")} `;v==127?console.warn(`${f}is not necessary. Consider removing it.`):console.warn(`${f}is not supported.`)}else{let f=this.#i[t]-2;f<0?console.warn(`CH${t+1} cannot accept drum NRPN as type ${F[this.#i[t]]}.`):this.#l[(f*m.dpn+D[v])*m.dnc+a]=e.data[1]}T()&&console.debug(`CH${t+1} (${F[this.#i[t]]}) drum NRPN ${v} commit`)}}else{let v=Re[this.#e[p+b[100]]],a=Pe[this.#e[p+b[100]]];this.#e[p+b[101]]==0&&v!=null&&(T()&&console.debug(`CH${t+1} RPN 0 ${this.#e[p+b[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],De[v][0]),De[v][1]),this.#s[t*m.rpn+v]=e.data[1],this.#o[t*m.rpnt+a]=1,this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)}))}break}case 32:{switch(T()&&console.debug(`${C[this.#t]}, CH${t+1} LSB: ${e.data[1]}`),this.#t){case $.s90es:case $.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.#U){let v=Re[this.#e[p+100]],a=Pe[this.#e[p+100]];this.#e[p+101]==0&&v!=null&&(this.#s[t*m.rpn+v+1]=e.data[1],this.#o[t*m.rpnt+a]=1)}break}case 64:{e.data[1]<64&&this.#C.hoOf(t);break}case 66:{e.data[1]>>6?this.#C.soOn(t):this.#C.soOf(t);break}case 98:case 99:{this.#U=1;break}case 100:case 101:{this.#U=0;break}}this.#e[p+b[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:t,cc:e.data[0],data:e.data[1]})}c.getChModeId(t)==$.xg&&c.#i[t]&&c.setDrumFirstWrite(t)},12:function(e){let t=e.channel,c=this;switch(c.#t){case $.s90es:case $.motif:{e.data&&c.setChActive(t,1);break}default:c.setChActive(t,1)}if(c.getExt(t)[0]==c.EXT_DX){let l=m.cc*t}c.#r[t]=e.data,c.#w[t]=0,T()&&console.debug(`T:${e.track} C:${t} P:${e.data}`),c.dispatchEvent("voice",{part:t}),c.getChModeId(t)==$.xg&&c.#i[t]&&c.setDrumFirstWrite(t)},13:function(e){let t=this,c=e.channel;this.#u.forEach(function(l){let h=l>>7;c==h&&(t.#h[l]=e.data,t.dispatchEvent("note",{part:c,note:l&127,velo:e.data,state:t.NOTE_SUSTAIN}))})},14:function(e){let t=e.channel;this.#L[t]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)})},15:function(e){ht(e.data).forEach(t=>{let c=t[0],l=t[1];(this.#ue[c]||function(){console.debug(`Unknown manufacturer ${c}.`)})(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(c,l,h){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#G=0);let t=ot.indexOf(e.meta)>-1;if(T()&&console.debug(e),t)return e.reply="meta",e}};#ue={64:(e,t,c)=>{this.#re.run(t,c,e)},65:(e,t,c)=>{if(t[0]<16)if(t[1]==72){let l=t[t.length-1],h=N(t.subarray(3,t.length-1));l==h?this.#V.run(t.subarray(0,t.length-1),c,e):console.warn(`Bad SD checksum ${l} - should be ${h}.`)}else this.#V.run(t,c,e);else{let l=t[t.length-1],h=N(t.subarray(2,t.length-1));l==h?this.#V.run(t.subarray(0,t.length-1),c,e):console.warn(`Bad GS checksum ${l} - should be ${h}.`)}},66:(e,t,c)=>{this.#K.run(t,c,e)},67:(e,t,c)=>{this.#B.run(t,c,e)},68:(e,t,c)=>{this.#se.run(t,c,e)},71:(e,t,c)=>{this.#ie.run(t,c,e)},126:(e,t,c)=>{this.#te.run(t,c,e)},127:(e,t,c)=>{this.switchMode("gm"),this.#ae.run(t,c,e)}};#te;#ae;#B;#V;#K;#re;#ie;#se;buildRchTree(){let e=[];this.#f.forEach((t,c)=>{t{t&&(e.#J[Math.floor(c/m.redir)][t]=c%m.redir|128)}),T()&&console.debug(e.#J)}getActive(){return this.#$}getCc(e){let t=this,c=e*m.cc,l=t.#e.subarray(c,c+m.cc);return l[b[0]]=l[b[0]]||t.#x[t.getChModeId(e)][0],l[b[32]]=l[b[32]]||t.#x[t.getChModeId(e)][1],l[b[0]]==H.bank0&&(l[b[0]]=0),l}getCcCh(e,t){let c=this;if(z.indexOf(t)<0)throw new Error("CC number not accepted");let l=c.#e[m.cc*e+b[t]];switch(t){case 0:{l=l||c.#x[c.getChModeId(e)][0],l==H.bank0&&(l=0);break}case 32:{l=l||c.#x[c.getChModeId(e)][1];break}}return l}getCcAll(){let e=this,t=e.#e.slice();for(let c=0;c0&&!l&&(this.#e[e*m.cc+b[0]]=se[c])}setChActive(e,t=0){this.#$[e]!=t&&this.dispatchEvent("channeltoggle",{part:e,active:t}),this.#$[e]=t}getExt(e){let t=m.ext*e,c=this.#M.subarray(t,t+m.ext),l=new Uint8Array(c.length);return l.set(c),l[1]=l[1]||this.#he,l}getPitch(){return this.#L}getProgram(){return this.#r}getTexts(){return this.#N.slice()}getVel(e){let t=new Map,c=this;return c.#u.forEach(function(l,h){let p=Math.floor(l/128),g=l%128;e==p&&c.#h[l]>0&&t.set(g,{v:c.#h[l],s:c.#k[h]})}),t}getBitmap(){return{bitmap:this.#E,expire:this.#T}}getLetter(){return{text:this.#Q,set:this.#le,expire:this.#j}}getMode(){return C[this.#t]}getMaster(){return{volume:this.#p}}getRawStrength(){let e=this;return this.#u.forEach(function(t){let c=Math.floor(t/128);e.#h[t]>e.#I[c]&&(e.#I[c]=e.#h[t])}),this.#I}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(c,l){e[l]=Math.floor(c*t.#e[l*m.cc+b[7]]*t.#e[l*m.cc+b[11]]*t.#p/803288)}),e}getRpn(){return this.#s}getNrpn(){return this.#X}getVoice(e,t,c,l){let h=this,p=e||h.#x[h.#t][0],g=t,v=c||h.#x[h.#t][1];p==H.bank0&&(p=0),C[h.#t]=="ns5r"&&p>0&&p<56&&(v=3);let a=h.userBank.get(p,g,v,l);if(C[h.#t]=="mt32"&&a.name.indexOf("MT-m:")==0){let i=parseInt(a.name.slice(5)),f=i*m.cmt,r="";h.#F.subarray(f,f+10).forEach(n=>{n>31&&(r+=String.fromCharCode(n))});let s=`MSB LSB PRG NME -0 127 ${g} ${r}`;h.userBank.load(s,!0),a.name=r,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=h.baseBank.get(p,g,v,l)),a}getChVoice(e){let t=this,c=t.getVoice(t.getCcCh(e,0),t.#r[e],t.getCcCh(e,32),t.getChMode(e));if(t.#w[e]){let l="";switch(t.#t){case $.mt32:{t.#A.subarray(m.cmt*(e-1),m.cmt*(e-1)+10).forEach(h=>{l+=String.fromCharCode(Math.max(h,32))}),l=l.trimRight();break}default:{let h=m.cvn*e;t.#z.subarray(h,h+m.cvn).forEach(p=>{l+=String.fromCharCode(Math.max(p,32))}),l=l.trimRight()}}l.length&&(c.ending="~",c.name=l)}return c}getRawPitch(){return this.#L}getPitchShift(e){let t=this,c=e*m.rpn,l=t.#s[c];return t.#o[e*m.rpnt]||t.#t==$.mt32&&(l=12),t.#L[e]/8192*l+(t.#s[c+3]-64)+((t.#s[c+1]<<7)+t.#s[c+2]-8192)/8192}getEffectType(e=0){let t=3*e+1;return this.#S.subarray(t,t+2)}setEffectTypeRaw(e=0,t,c){let l=3*e;this.#S[l]=1,this.#S[l+1+ +t]=c}setEffectType(e=0,t,c){this.setEffectTypeRaw(e,!1,t),this.setEffectTypeRaw(e,!0,c)}getEffectSink(){return this.#a}setLetterDisplay(e,t,c=0,l=3200){let h=this,p;h.#Q=" ".repeat(c),e.forEach(g=>{h.#Q+=String.fromCharCode(g>31?g:32),g<32&&(p=p||new Set,p.add(g))}),h.#le=Date.now(),h.#j=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 c=this,l=-1;switch(e.replaceAll(", ",",").split(",").forEach(h=>{h=h.toLowerCase();let p=C.indexOf(nt[h]||h);T()&&console.debug(`Mapped mode "${h}" to ID "${p}".`),p>-1&&(l=p)}),T()&&console.debug(`Set detection target to ID "${l}".`),l>0&&(c.#c.x5=82,c.#c.ds=$.krs),l){case $["05rw"]:{c.#c.x5=81;break}case $.s90es:c.#c.ds=$.s90es,c.#c.smotif=$.s90es;case $.motif:c.#c.ds=$.motif,c.#c.smotif=$.motif}}setGsTargets(e=!1,t=4){if(!t)t=e?3:4;else{if(t>4||t<0)throw new Error(`Invalid GS level ${t}`);if(e&&t>>1!=1)throw new Error(`Invalid SC level ${t}`)}let c=this;c.#c[e?"sc":"gs"]=t,c.#x[$[e?"sc":"gs"]][1]=t,c.forceVoiceRefresh()}getConfigs(){return this.#Y}setDumpLimit(e){if(e>2||e<0)throw new RangeError("Invalid dump limit.");this.#H.dumpLimit=e}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let t=!0,c=0;for(;t&&c=m.ace&&console.warn("ACE slots are full.")}releaseAce(e){let t=!0,c=0;for(;t&&c=m.ace)throw new RangeError("No such ACE slot");let c=this.#b[t];if(c){if(z.indexOf(c)>=0)return this.#e[e*m.cc+b[c]];throw new Error(`Invalid ACE source: ${c}`)}else return 0}initDrums(){let e=this;e.#l.fill(64);for(let t=0;t{t.#e[m.cc*c]=se[0]}),t.#i.fill(t.CH_MELODIC),t.#i[9]=t.CH_DRUM1,t.#i[25]=t.CH_DRUM3,t.#i[41]=t.CH_DRUMS,t.#i[57]=t.CH_DRUMS,t.#i[73]=t.CH_DRUM5,t.#i[89]=t.CH_DRUM7,t.#i[105]=t.CH_DRUMS,t.#i[121]=t.CH_DRUMS;for(let c=0;c=m.ch)throw new RangeError(`Invalid CH${e+1}`);if(port<0||t>=C.length)throw new RangeError(`Invalid mode ID ${t}`);c.#y[e]=t,c.dispatchEvent("voice",{part:e})}getChMode(e,t){return C[this.getChModeId(e,t)]}getChModeId(e,t){return t?this.#y[e]||this.#n[e>>4]:this.#y[e]||this.#n[e>>4]||this.#t}setPortMode(e,t,c){let l=this;if(e<0||e>=m.ch>>4)throw new RangeError(`Invalid port ${e+1}`);if(t<1)throw new RangeError("Range must be a positive integer");if(e+t>=m.ch>>4)throw new RangeError("Range must be in bound");if(e<0||c>=C.length)throw new RangeError(`Invalid mode ID ${c}`);for(let h=e;h=0&&e-1){if(l.#t==0||t){let p=l.#t;l.initOnReset&&t&&(this.init(1),p=$["?"]),l.#t=h,l.#m=0;for(let v=0;v0&&l.#y[v]==0&&(l.#e[v*m.cc]=se[h]);switch(h){case $.mt32:{ie.forEach((v,a)=>{let i=a+1;l.#$[i]||(l.#r[i]=v,l.#e[i*m.cc+b[91]]=127)});for(let v=1;v<10;v++)l.dispatchEvent("voice",{part:v});break}}let g;switch(h){case $["?"]:case $.g2:{g=[52,4,52,18,0,0,0,0];break}case $.xg:{g=[1,0,65,0,5,0,0,0];break}case $.gm:case $.gs:case $.sc:{g=[40,4,40,18,40,32,32,0];break}case $.sd:{g=[58,0,60,0,61,0,61,0];break}case $["05rw"]:case $.x5d:case $.ns5r:{g=[44,1,44,19,44,0,44,0];break}case $.k11:case $.sg:{g=[24,0,0,0,0,0,0,0];break}case $.mt32:{g=[40,4,0,0,0,0,0,0];break}case $.motif:case $.s90es:{g=[113,0,117,0,114,0,0,0];break}default:g=[0,0,0,0,0,0,0,0]}for(let v=0;v{l.dispatchEvent("voice",{part:v})})}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#I.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#fe[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),c=!1;this.#de[t]?.forEach(l=>{e.channel=l,c=!0,this.#fe[e.type].call(this,e)}),c||console.warn(`${Me[e.type]?Me[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.#N.length>100&&this.#N.splice(100,this.#N.length-99)}runRaw(e){}async loadBank(e,t){let c=this;switch(e=e.toLowerCase(),e){case"s7e":{c.userBank.clearRange({msb:63,lsb:[21,22]}),c.userBank.clearRange({msb:63,lsb:[24,27]});break}case"pcg":{c.userBank.clearRange({msb:63,lsb:[6,9]}),c.userBank.clearRange({msb:63,lsb:[13,16]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":case"pcg":{G.context=this,await c.userBank.load(await G.read(e,t),!1);break}}c.forceVoiceRefresh()}constructor(){super();let e=this;e.#E=new Uint8Array(256),e.#d[10]=new Uint8Array(512),e.#ee=new O,e.#c={x5:82,ds:$.krs,smotif:$.s90es,gs:4,sc:3},e.#H={dumpLimit:e.DUMP_MODE},e.#Y=new Proxy(e.#H,{set:()=>{}});for(let a in Se){let i=$[a];i==null?console.debug(`SubDB build error: "${a}" does not exist`):e.#x[i]=new Uint8Array(Se[a])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let t=e.split(",");te[t[0]]=t[1]});var Ee=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 te)t=t.replaceAll(l,te[l]);t.indexOf("ん")==0&&t.length>1&&(t=t.slice(1));let c=t.indexOf("!");return c>-1&&t.length>1&&(t=t.slice(c+1)),t},we=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var ae=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],$e=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ke=["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 it={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"},st={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]]},re=function(e){return it[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},xe=function(e,t,c){let l=(e[0]-32<<16)+(e[1]<<8)+t,h=st[l]||{},p=h[0];if(p?.length)return p+=`: ${(h[1]||function(){})(c)||c}`,p},ie=[68,48,95,78,41,3,110,122,0];var P=function(e=64){return Math.round(2e3*Math.log10(e/64))/100},Te=function(e,t,c){let l=[],h=c==!1?t.readIntVLV():c;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(c=>{t+=c,t=t&127}),~t+1&127},A=function(e,t){let c=0,l=0;for(let h=0;h>p&1)<<7,v=e[h];v+=g,h%8!=0?(t(v,c,e),c++):l=e[h]}};var K=function(e){let t=Math.floor(e*14.2);return t<128?t:0},T=function(){return!!self.Bun||self.debugMode||!1};var C=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"],nt={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",trinity:"trin","tr-rack":"trin"},ct=["melodic","drum","menu"],Se={"?":[0,0,120],gm:[0,0,127],gs:[0,0,120],sc:[0,0,120],xg:[0,0,127],g2:[0,0,120],mt32:[0,127,127],doc:[57,112,127],qy10:[57,113,127],qy20:[57,114,127],ns5r:[0,0,61],x5d:[82,0,62],"05rw":[81,0,62],k11:[0,0,122],sg:[0,0,122],sd:[97,0,105],krs:[63,0,120],s90es:[63,0,127],motif:[63,0,127],trin:[63,0,127]};var se=[120,127,120,127,120,127,127,61,62,62,122,122,105,120,127,127,127],Ce=[9,25,41,57,73,89,105,121],ot=[0,3,81,84,88],Me={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Re={0:0,1:1,2:3,5:4},Pe={0:0,1:1,2:2,5:3},De=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Oe=[36,37,48,49,52,53],Y=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Ae={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,80,81,83,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],lt=[2,12,13,14,15,16,17,18,19,20,21,80,81,83,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],dt=[33,99,100,32,102,8,9,10],Le=[0,16,25,40,32,64,26,48],$={};C.forEach((e,t)=>{$[e]=t});var b={length:z.length};z.forEach((e,t)=>{b[e]=t});var D={length:Y.length};Y.forEach((e,t)=>{D[e]=t});var ft={};ct.forEach((e,t)=>{ft[e]=t});var ht=function(e){let t=[],c=0;return e?.forEach(function(l,h){l==247?t.push(e.subarray(c,h)):l==240&&(c=h+1)}),t.length||t.push(e.subarray(0)),T()&&console.debug(t),t};var Ie=8,m={port:Ie,ch:Ie<<4,cc:z.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:Y.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255},H={bank0:128},Ue=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;DUMP_ALL=0;DUMP_ONCE=1;DUMP_MODE=2;EXT_NONE=0;EXT_VL=1;EXT_DX=3;VLBC_BRTHEXPR=1;VLBC_VELOINIT=2;VLBC_VELOALL=3;CH_INACTIVE=0;CH_ACTIVE=1;CH_DISABLED=2;#t=0;#m=0;#T=0;#d=new Array(11);get#E(){return this.#d[this.#m]}set#E(e){this.#d[this.#m]=e}#$=new Uint8Array(m.ch);#f=new Uint8Array(m.ch);#i=new Uint8Array(m.ch);#e=new Uint8Array(m.ch*m.cc);#b=new Uint8Array(m.ace);#r=new Uint8Array(m.ch);#h=new Uint8Array(m.ch*m.nn);#g=new Uint8Array(m.ch);#u=new Uint16Array(m.pl);#k=new Uint8Array(m.pl);#L=new Int16Array(m.ch);#I=new Uint8Array(m.ch);#U=0;#M=new Uint8Array(m.ch*m.ext);#s=new Uint8Array(m.ch*m.rpn);#o=new Uint8Array(m.ch*m.rpnt);#X=new Int8Array(m.ch*Oe.length);#l=new Uint8Array(m.drm*m.dpn*m.dnc);#P=new Uint8Array(m.drm*2);#S=new Uint8Array(m.efx*3);#a=new Uint8Array(m.ch);#R=new Uint8Array(m.ch*m.redir);#n=new Uint8Array(m.port);#y=new Uint8Array(m.ch);#w=new Uint8Array(m.ch);#z=new Uint8Array(m.ch*m.cvn);#O=new Uint8Array(128);#A=new Uint8Array(m.cmt*8);#q=new Uint8Array(1024);#F=new Uint8Array(m.cmt*64);#x={};#c;#H;#Y;#p=100;#G=0;#ne=500;#ce=0;#Q="";#j=0;#le=0;#oe=0;#_=!0;#v=!1;#he=1;#de;#J=new Array(m.ch);#pe=new Uint8Array(2);#N=[];#W=new Uint8Array(m.ch);#Z=new Uint8Array(m.tr);baseBank=new ee("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es");userBank=new ee("gm");initOnReset=!1;aiEfxName="";chRedir(e,t,c){let l=this;if(l.#Z[t])return(l.#Z[t]-1)*16+e;if(l.#t==$.sc){if(c==1)return e;let h=0,p=!0;for(;p;)l.#W[e+h]==0?(l.#W[e+h]=t,console.debug(`Assign track ${t} to channel ${e+h+1}.`),p=!1):this.#W[e+h]==t?p=!1:(h+=16,h>=128&&(h=0,p=!1));return e+h}else return e}getTrackPort(e){return this.chRedir(0,e,!0)>>4}forceVoiceRefresh(){for(let e=0;e{let c=e*128+t,l=this.#u.lastIndexOf(c);if(l>-1)if(this.#e[m.cc*e+b[64]]>63)this.#k[l]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#h[c],state:this.NOTE_HELD});else if(this.#e[m.cc*e+b[66]]>63&&this.#k[l]==this.NOTE_SOSTENUTO_SUSTAIN)this.#k[l]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#h[c],state:this.NOTE_SOSTENUTO_HELD});else{this.#u[l]=0,this.#h[c]=0,this.#k[l]=this.NOTE_IDLE;let h=this.getExt(e)[1];(h==this.VLBC_VELOINIT||h==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,c)=>{let l=e*128+t,h=0;for(this.#g[e]&&this.#C.ano(e);this.#k[h]>0&&this.#u[h]!=l;)h++;if(h{},cAt:(e,t)=>{},hoOf:e=>{this.#k.forEach((t,c)=>{if(t==this.NOTE_HELD){let l=this.#u[c],h=l>>7;e==h&&(this.#k[c]=this.NOTE_IDLE,this.#u[c]=0,this.#h[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#k.forEach((t,c)=>{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.#k[c]=l;let h=this.#u[c];this.dispatchEvent("note",{part:e,note:h&127,velo:this.#h[h],state:l})}})},soOf:e=>{this.#k.forEach((t,c)=>{if(t==this.NOTE_SOSTENUTO_HELD){let l=this.#u[c],h=l>>7;e==h&&(this.#k[c]=this.NOTE_IDLE,this.#u[c]=0,this.#h[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#u.forEach((t,c,l)=>{let h=t>>7,p=t&127;t==0&&this.#h[0]==0||h==e&&this.#C.nOff(h,p)})}};#fe={8:function(e){let t=e.channel,c=e.data[0];this.#C.nOff(t,c)},9:function(e){let t=e.channel,c=this;if(c.getChModeId(t)==$.xg&&c.#i[t]>1){let p=c.getChDrumFirstWrite(t);p[0]&&p[1]!=m.invalidCh&&!c.#$[t]&&(c.copyChSetup(p[1],t),c.dispatchEvent("voice",{part:t}),console.debug(`Part CH${t+1} copied from CH${p[1]}.`))}c.setChActive(t,1);let l=e.data[0],h=e.data[1];h>0?c.#C.nOn(t,l,h):c.#C.nOff(t,l)},10:function(e){let t=e.channel,c=t*128+e.data[0];this.#u.indexOf(c)>-1&&(this.#h[c]=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,c=this,l=this.#J[t],h=l[e.data[0]];h&&(e.data[0]=h),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case $.s90es:case $.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 p=t*m.cc,g=t*m.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#C.ano(t),this.#L[t]=0,this.#e[p+b[1]]=0,this.#e[p+b[5]]=0,this.#e[p+b[64]]=0,this.#e[p+b[65]]=0,this.#e[p+b[66]]=0,this.#e[p+b[67]]=0,this.#e[p+b[11]]=127,this.#e[p+b[101]]=127,this.#e[p+b[100]]=127,this.#e[p+b[99]]=127,this.#e[p+b[98]]=127;return}case 123:{this.#C.ano(t);return}case 124:{this.#C.ano(t);return}case 125:{this.#C.ano(t);return}case 126:{this.#g[t]=1,this.#C.ano(t);return}case 127:{this.#g[t]=0,this.#C.ano(t);return}}if(b[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(lt.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(T()&&console.debug(`${C[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#i[t]>0&&(e.data[1]=this.#e[p],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]==56?this.switchMode(this.#c.x5==82?"x5d":"05rw"):e.data[1]==62?this.switchMode(this.#c.x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(C[this.#c.ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==$.gs||this.#t==$.sc?e.data[1]<56&&this.#i[t]>0&&(e.data[1]=this.#e[p],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)):this.#t==$.gm&&(e.data[1]<48?this.#i[t]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${t+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0)),this.#t){case $.xg:{[79,95,126,127].indexOf(e.data[1])>-1?this.#i[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?this.#M[g]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?this.#M[g]=this.EXT_DX:this.#M[g]=this.EXT_NONE;break}case $["05rw"]:case $.x5d:case $.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#i[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.#i[t]!=this.CH_MELODIC&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case $.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#i[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case $.g2:{e.data[1]==120?this.#i[t]==0&&(this.setChType(t,this.CH_DRUMS),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:t});break}case 2:{this.getExt(t)[1]==this.VLBC_BRTHEXPR&&(this.#e[p+b[129]]=e.data[1]);break}case 6:{if(this.#U){[$.xg,$.gs,$.sc,$.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${C[this.#t]}" mode, even when they are supported in Octavia.`);let v=this.#e[p+b[99]],a=this.#e[p+b[98]];if(v==1){let i=dt.indexOf(a);if(i>-1)this.#e[p+b[71+i]]=e.data[1],T()&&console.debug(`Redirected NRPN 1 ${a} to cc${71+i}.`),this.dispatchEvent("cc",{part:t,cc:71+i,data:e.data[1]});else{let d=Oe.indexOf(a);d>-1?this.#X[t*10+d]=e.data[1]-64:console.warn(`NRPN 0x01${a.toString(16).padStart(2,"0")} is not supported.`),T()&&console.debug(`CH${t+1} voice NRPN ${a} commit`)}}else{if(Y.indexOf(v)<0){let d=`NRPN 0x${v.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")} `;v==127?console.warn(`${d}is not necessary. Consider removing it.`):console.warn(`${d}is not supported.`)}else{let d=this.#i[t]-2;d<0?console.warn(`CH${t+1} cannot accept drum NRPN as type ${F[this.#i[t]]}.`):this.#l[(d*m.dpn+D[v])*m.dnc+a]=e.data[1]}T()&&console.debug(`CH${t+1} (${F[this.#i[t]]}) drum NRPN ${v} commit`)}}else{let v=Re[this.#e[p+b[100]]],a=Pe[this.#e[p+b[100]]];this.#e[p+b[101]]==0&&v!=null&&(T()&&console.debug(`CH${t+1} RPN 0 ${this.#e[p+b[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],De[v][0]),De[v][1]),this.#s[t*m.rpn+v]=e.data[1],this.#o[t*m.rpnt+a]=1,this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)}))}break}case 32:{switch(T()&&console.debug(`${C[this.#t]}, CH${t+1} LSB: ${e.data[1]}`),this.#t){case $.s90es:case $.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.#U){let v=Re[this.#e[p+100]],a=Pe[this.#e[p+100]];this.#e[p+101]==0&&v!=null&&(this.#s[t*m.rpn+v+1]=e.data[1],this.#o[t*m.rpnt+a]=1)}break}case 64:{e.data[1]<64&&this.#C.hoOf(t);break}case 66:{e.data[1]>>6?this.#C.soOn(t):this.#C.soOf(t);break}case 98:case 99:{this.#U=1;break}case 100:case 101:{this.#U=0;break}}this.#e[p+b[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:t,cc:e.data[0],data:e.data[1]})}c.getChModeId(t)==$.xg&&c.#i[t]&&c.setDrumFirstWrite(t)},12:function(e){let t=e.channel,c=this;switch(c.#t){case $.s90es:case $.motif:{e.data&&c.setChActive(t,1);break}default:c.setChActive(t,1)}if(c.getExt(t)[0]==c.EXT_DX){let l=m.cc*t}c.#r[t]=e.data,c.#w[t]=0,T()&&console.debug(`T:${e.track} C:${t} P:${e.data}`),c.dispatchEvent("voice",{part:t}),c.getChModeId(t)==$.xg&&c.#i[t]&&c.setDrumFirstWrite(t)},13:function(e){let t=this,c=e.channel;this.#u.forEach(function(l){let h=l>>7;c==h&&(t.#h[l]=e.data,t.dispatchEvent("note",{part:c,note:l&127,velo:e.data,state:t.NOTE_SUSTAIN}))})},14:function(e){let t=e.channel;this.#L[t]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)})},15:function(e){ht(e.data).forEach(t=>{let c=t[0],l=t[1];(this.#ue[c]||function(){console.debug(`Unknown manufacturer ${c}.`)})(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(c,l,h){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#G=0);let t=ot.indexOf(e.meta)>-1;if(T()&&console.debug(e),t)return e.reply="meta",e}};#ue={64:(e,t,c)=>{this.#re.run(t,c,e)},65:(e,t,c)=>{if(t[0]<16)if(t[1]==72){let l=t[t.length-1],h=N(t.subarray(3,t.length-1));l==h?this.#V.run(t.subarray(0,t.length-1),c,e):console.warn(`Bad SD checksum ${l} - should be ${h}.`)}else this.#V.run(t,c,e);else{let l=t[t.length-1],h=N(t.subarray(2,t.length-1));l==h?this.#V.run(t.subarray(0,t.length-1),c,e):console.warn(`Bad GS checksum ${l} - should be ${h}.`)}},66:(e,t,c)=>{this.#K.run(t,c,e)},67:(e,t,c)=>{this.#B.run(t,c,e)},68:(e,t,c)=>{this.#se.run(t,c,e)},71:(e,t,c)=>{this.#ie.run(t,c,e)},126:(e,t,c)=>{this.#te.run(t,c,e)},127:(e,t,c)=>{this.switchMode("gm"),this.#ae.run(t,c,e)}};#te;#ae;#B;#V;#K;#re;#ie;#se;buildRchTree(){let e=[];this.#f.forEach((t,c)=>{t{t&&(e.#J[Math.floor(c/m.redir)][t]=c%m.redir|128)}),T()&&console.debug(e.#J)}getActive(){return this.#$}getCc(e){let t=this,c=e*m.cc,l=t.#e.subarray(c,c+m.cc);return l[b[0]]=l[b[0]]||t.#x[t.getChModeId(e)][0],l[b[32]]=l[b[32]]||t.#x[t.getChModeId(e)][1],l[b[0]]==H.bank0&&(l[b[0]]=0),l}getCcCh(e,t){let c=this;if(z.indexOf(t)<0)throw new Error("CC number not accepted");let l=c.#e[m.cc*e+b[t]];switch(t){case 0:{l=l||c.#x[c.getChModeId(e)][0],l==H.bank0&&(l=0);break}case 32:{l=l||c.#x[c.getChModeId(e)][1];break}}return l}getCcAll(){let e=this,t=e.#e.slice();for(let c=0;c0&&!l&&(this.#e[e*m.cc+b[0]]=se[c])}setChActive(e,t=0){this.#$[e]!=t&&this.dispatchEvent("channeltoggle",{part:e,active:t}),this.#$[e]=t}getExt(e){let t=m.ext*e,c=this.#M.subarray(t,t+m.ext),l=new Uint8Array(c.length);return l.set(c),l[1]=l[1]||this.#he,l}getPitch(){return this.#L}getProgram(){return this.#r}getTexts(){return this.#N.slice()}getVel(e){let t=new Map,c=this;return c.#u.forEach(function(l,h){let p=Math.floor(l/128),g=l%128;e==p&&c.#h[l]>0&&t.set(g,{v:c.#h[l],s:c.#k[h]})}),t}getBitmap(){return{bitmap:this.#E,expire:this.#T}}getLetter(){return{text:this.#Q,set:this.#le,expire:this.#j}}getMode(){return C[this.#t]}getMaster(){return{volume:this.#p}}getRawStrength(){let e=this;return this.#u.forEach(function(t){let c=Math.floor(t/128);e.#h[t]>e.#I[c]&&(e.#I[c]=e.#h[t])}),this.#I}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(c,l){e[l]=Math.floor(c*t.#e[l*m.cc+b[7]]*t.#e[l*m.cc+b[11]]*t.#p/803288)}),e}getRpn(){return this.#s}getNrpn(){return this.#X}getVoice(e,t,c,l){let h=this,p=e||h.#x[h.#t][0],g=t,v=c||h.#x[h.#t][1];p==H.bank0&&(p=0),C[h.#t]=="ns5r"&&p>0&&p<56&&(v=3);let a=h.userBank.get(p,g,v,l);if(C[h.#t]=="mt32"&&a.name.indexOf("MT-m:")==0){let i=parseInt(a.name.slice(5)),d=i*m.cmt,r="";h.#F.subarray(d,d+10).forEach(n=>{n>31&&(r+=String.fromCharCode(n))});let s=`MSB LSB PRG NME +0 127 ${g} ${r}`;h.userBank.load(s,!0),a.name=r,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=h.baseBank.get(p,g,v,l)),a}getChVoice(e){let t=this,c=t.getVoice(t.getCcCh(e,0),t.#r[e],t.getCcCh(e,32),t.getChMode(e));if(t.#w[e]){let l="";switch(t.#t){case $.mt32:{t.#A.subarray(m.cmt*(e-1),m.cmt*(e-1)+10).forEach(h=>{l+=String.fromCharCode(Math.max(h,32))}),l=l.trimRight();break}default:{let h=m.cvn*e;t.#z.subarray(h,h+m.cvn).forEach(p=>{l+=String.fromCharCode(Math.max(p,32))}),l=l.trimRight()}}l.length&&(c.ending="~",c.name=l)}return c}getRawPitch(){return this.#L}getPitchShift(e){let t=this,c=e*m.rpn,l=t.#s[c];return t.#o[e*m.rpnt]||t.#t==$.mt32&&(l=12),t.#L[e]/8192*l+(t.#s[c+3]-64)+((t.#s[c+1]<<7)+t.#s[c+2]-8192)/8192}getEffectType(e=0){let t=3*e+1;return this.#S.subarray(t,t+2)}setEffectTypeRaw(e=0,t,c){let l=3*e;this.#S[l]=1,this.#S[l+1+ +t]=c}setEffectType(e=0,t,c){this.setEffectTypeRaw(e,!1,t),this.setEffectTypeRaw(e,!0,c)}getEffectSink(){return this.#a}setLetterDisplay(e,t,c=0,l=3200){let h=this,p;h.#Q=" ".repeat(c),e.forEach(g=>{h.#Q+=String.fromCharCode(g>31?g:32),g<32&&(p=p||new Set,p.add(g))}),h.#le=Date.now(),h.#j=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 c=this,l=-1;switch(e.replaceAll(", ",",").split(",").forEach(h=>{h=h.toLowerCase();let p=C.indexOf(nt[h]||h);T()&&console.debug(`Mapped mode "${h}" to ID "${p}".`),p>-1&&(l=p)}),T()&&console.debug(`Set detection target to ID "${l}".`),l>0&&(c.#c.x5=82,c.#c.ds=$.krs),l){case $["05rw"]:{c.#c.x5=81;break}case $.s90es:c.#c.ds=$.s90es,c.#c.smotif=$.s90es;case $.motif:c.#c.ds=$.motif,c.#c.smotif=$.motif}}setGsTargets(e=!1,t=4){if(!t)t=e?3:4;else{if(t>4||t<0)throw new Error(`Invalid GS level ${t}`);if(e&&t>>1!=1)throw new Error(`Invalid SC level ${t}`)}let c=this;c.#c[e?"sc":"gs"]=t,c.#x[$[e?"sc":"gs"]][1]=t,c.forceVoiceRefresh()}getConfigs(){return this.#Y}setDumpLimit(e){if(e>2||e<0)throw new RangeError("Invalid dump limit.");this.#H.dumpLimit=e}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let t=!0,c=0;for(;t&&c=m.ace&&console.warn("ACE slots are full.")}releaseAce(e){let t=!0,c=0;for(;t&&c=m.ace)throw new RangeError("No such ACE slot");let c=this.#b[t];if(c){if(z.indexOf(c)>=0)return this.#e[e*m.cc+b[c]];throw new Error(`Invalid ACE source: ${c}`)}else return 0}initDrums(){let e=this;e.#l.fill(64);for(let t=0;t{t.#e[m.cc*c]=se[0]}),t.#i.fill(t.CH_MELODIC),t.#i[9]=t.CH_DRUM1,t.#i[25]=t.CH_DRUM3,t.#i[41]=t.CH_DRUMS,t.#i[57]=t.CH_DRUMS,t.#i[73]=t.CH_DRUM5,t.#i[89]=t.CH_DRUM7,t.#i[105]=t.CH_DRUMS,t.#i[121]=t.CH_DRUMS;for(let c=0;c=m.ch)throw new RangeError(`Invalid CH${e+1}`);if(port<0||t>=C.length)throw new RangeError(`Invalid mode ID ${t}`);c.#y[e]=t,c.dispatchEvent("voice",{part:e})}getChMode(e,t){return C[this.getChModeId(e,t)]}getChModeId(e,t){return t?this.#y[e]||this.#n[e>>4]:this.#y[e]||this.#n[e>>4]||this.#t}setPortMode(e,t,c){let l=this;if(e<0||e>=m.ch>>4)throw new RangeError(`Invalid port ${e+1}`);if(t<1)throw new RangeError("Range must be a positive integer");if(e+t>=m.ch>>4)throw new RangeError("Range must be in bound");if(e<0||c>=C.length)throw new RangeError(`Invalid mode ID ${c}`);for(let h=e;h=0&&e-1){if(l.#t==0||t){let p=l.#t;l.initOnReset&&t&&(this.init(1),p=$["?"]),l.#t=h,l.#m=0;for(let v=0;v0&&l.#y[v]==0&&(l.#e[v*m.cc]=se[h]);switch(h){case $.mt32:{ie.forEach((v,a)=>{let i=a+1;l.#$[i]||(l.#r[i]=v,l.#e[i*m.cc+b[91]]=127)});for(let v=1;v<10;v++)l.dispatchEvent("voice",{part:v});break}}let g;switch(h){case $["?"]:case $.g2:{g=[52,4,52,18,0,0,0,0];break}case $.xg:{g=[1,0,65,0,5,0,0,0];break}case $.gm:case $.gs:case $.sc:{g=[40,4,40,18,40,32,32,0];break}case $.sd:{g=[58,0,60,0,61,0,61,0];break}case $["05rw"]:case $.x5d:case $.ns5r:{g=[44,1,44,19,44,0,44,0];break}case $.k11:case $.sg:{g=[24,0,0,0,0,0,0,0];break}case $.mt32:{g=[40,4,0,0,0,0,0,0];break}case $.doc:{g=[24,16,0,0,0,0,0,0];break}case $.motif:case $.s90es:{g=[113,0,117,0,114,0,0,0];break}default:g=[0,0,0,0,0,0,0,0]}for(let v=0;v{l.dispatchEvent("voice",{part:v})})}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#I.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#fe[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),c=!1;this.#de[t]?.forEach(l=>{e.channel=l,c=!0,this.#fe[e.type].call(this,e)}),c||console.warn(`${Me[e.type]?Me[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.#N.length>100&&this.#N.splice(100,this.#N.length-99)}runRaw(e){}async loadBank(e,t){let c=this;switch(e=e.toLowerCase(),e){case"s7e":{c.userBank.clearRange({msb:63,lsb:[21,22]}),c.userBank.clearRange({msb:63,lsb:[24,27]});break}case"pcg":{c.userBank.clearRange({msb:63,lsb:[6,9]}),c.userBank.clearRange({msb:63,lsb:[13,16]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":case"pcg":{G.context=this,await c.userBank.load(await G.read(e,t),!1);break}}c.forceVoiceRefresh()}constructor(){super();let e=this;e.#E=new Uint8Array(256),e.#d[10]=new Uint8Array(512),e.#ee=new O,e.#c={x5:82,ds:$.krs,smotif:$.s90es,gs:4,sc:3},e.#H={dumpLimit:e.DUMP_MODE},e.#Y=new Proxy(e.#H,{set:()=>{}});for(let a in Se){let i=$[a];i==null?console.debug(`SubDB build error: "${a}" does not exist`):e.#x[i]=new Uint8Array(Se[a])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -153,23 +153,23 @@ _,`.split(` 122 006 000 `),e.addEventListener("metacommit",function(a){let{data:i}=a;e.#N[0]?.type==i.type&&e.#N[0]?.amend?(e.#N[0].amend=i.amend,e.#N[0].data+=i.data):e.#N.unshift(i)}),e.#D[1]=function(a){switch(a=a.replaceAll(`\r `,` `).replaceAll("\r",` -`),a.slice(0,2)){case"@I":{this.#v=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:a.slice(2)?.trimLeft()});break}case"@K":{this.#v=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:a.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{this.#v=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:a.slice(2)?.trimLeft()});break}case"@T":{this.#v=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:a.slice(2)?.trimLeft()});break}case"@V":{this.#v=!0,this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:a.slice(2)?.trimLeft()});break}case"XF":{let i=a.slice(2).split(":");switch(i[0]){case"hd":{i.slice(1).forEach((f,r)=>{f.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][r],data:f})});break}case"ln":{i.slice(1).forEach((f,r)=>{f.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][r],data:f})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:this.#v?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` -`).forEach((i,f)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:i,mask:f!=0})})}},e.#D[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},e.#D[3]=function(a,i){i<1&&this.#G<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},e.#D[4]=function(a,i){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,i){T()&&console.debug(`Track ${i} requests to get assigned to output ${a}.`),e.#Z[i]=a+1},e.#D[81]=function(a,i){e.#ne=a/1e3},e.#D[127]=function(a,i){e.#ee.run(a,i)},e.#ee.default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},e.#ee.add([67,0,1],function(a,i){e.#Z[i]=a[0]+1}),e.#te=new O("universal non-realtime"),e.#ae=new O("universal realtime"),e.#B=new O("Yamaha"),e.#V=new O("Roland"),e.#K=new O("Korg"),e.#re=new O("Kawai"),e.#ie=new O("Akai"),e.#se=new O("Casio");let t=new O("DX7+ Dump"),c=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,a)};e.#te.default=c,e.#ae.default=c,e.#B.default=c,e.#V.default=c,e.#K.default=c,e.#re.default=c,e.#ie.default=c,e.#se.default=c,t.default=c,e.#te.add([9],(a,i,f)=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),e.setPortMode(e.getTrackPort(i),1,$[["gm","?","g2"][a[0]-1]]),e.#v=e.#v||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),e.#ae.add([4,1],(a,i,f)=>{e.dispatchEvent("mupromptex"),e.#p=((a[1]<<7)+a[0])/16383*100,e.dispatchEvent("mastervolume",e.#p)}).add([4,3],(a,i,f)=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],(a,i,f)=>a[1]-64).add([4,5],(a,i,f)=>{e.dispatchEvent("mupromptex");let r=a[0],s=a[1],n=a[2],o=3,u=o+(r<<1),d=u+s;if(r!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${r})! -`,a);return}let y=0,E=0,w=0;switch(a.subarray(o,u).forEach(x=>{y=y<<7,y|=x}),a.subarray(u,d).forEach((x,M)=>{E|=x<{w|=x<{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),e.setPortMode(e.getTrackPort(i),4,$.xg),e.#v=!1,console.info("MIDI reset: XG");break}default:{e.dispatchEvent("mupromptex");let r=[0,0,0,0],s=(n,o)=>{r[o]=n};if(a.subarray(1).forEach((n,o)=>{let u=o+a[0];([s,s,s,s,d=>{this.#p=d*129/16383*100,e.dispatchEvent("mastervolume",e.#p)},d=>{},d=>{}][u]||(()=>{}))(n,o)}),a[0]<4){let n=0;r.forEach(o=>{n=n<<4,n+=o}),n-=1024}}}}).add([76,2,1],(a,i,f)=>{e.dispatchEvent("mupromptex");let r="XG ";a[0]<32?(r+="reverb ",a.subarray(1).forEach((s,n)=>{([o=>{e.setEffectTypeRaw(0,!1,o),console.info(`${r}main type: ${_[o]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},o=>{e.setEffectTypeRaw(0,!0,o),console.debug(`${r}sub type: ${o+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},o=>{console.debug(`${r}time: ${ge(o)}s`)},o=>{console.debug(`${r}diffusion: ${o}`)},o=>{console.debug(`${r}initial delay: ${o}`)},o=>{console.debug(`${r}HPF cutoff: ${X[o]}Hz`)},o=>{console.debug(`${r}LPF cutoff: ${X[o]}Hz`)},o=>{console.debug(`${r}width: ${o}`)},o=>{console.debug(`${r}height: ${o}`)},o=>{console.debug(`${r}depth: ${o}`)},o=>{console.debug(`${r}wall type: ${o}`)},o=>{console.debug(`${r}dry/wet: ${o}`)},o=>{console.debug(`${r}send: ${P(o)}dB`)},o=>{console.debug(`${r}pan: ${o-64}`)},!1,!1,o=>{console.debug(`${r}delay: ${o}`)},o=>{console.debug(`${r}density: ${o}`)},o=>{console.debug(`${r}balance: ${o}`)},o=>{},o=>{console.debug(`${r}feedback: ${o}`)},o=>{}][a[0]+n]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(s)})):a[0]<64?(r+="chorus ",a.subarray(1).forEach((s,n)=>{([o=>{e.setEffectTypeRaw(1,!1,o),console.info(`${r}main type: ${_[o]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},o=>{e.setEffectTypeRaw(1,!0,o),console.debug(`${r}sub type: ${o+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},o=>{console.debug(`${r}LFO: ${me[o]}Hz`)},o=>{},o=>{console.debug(`${r}feedback: ${o}`)},o=>{console.debug(`${r}delay offset: ${ye(o)}ms`)},o=>{},o=>{console.debug(`${r}low: ${X[o]}Hz`)},o=>{console.debug(`${r}low: ${o-64}dB`)},o=>{console.debug(`${r}high: ${X[o]}Hz`)},o=>{console.debug(`${r}high: ${o-64}dB`)},o=>{console.debug(`${r}dry/wet: ${o}`)},o=>{console.debug(`${r}send: ${P(o)}dB`)},o=>{console.debug(`${r}pan: ${o-64}`)},o=>{console.debug(`${r}to reverb: ${P(o)}dB`)},!1,o=>{},o=>{},o=>{},o=>{console.debug(`${r}LFO phase diff: ${(o-64)*3}deg`)},o=>{console.debug(`${r}input mode: ${o?"stereo":"mono"}`)},o=>{}][a[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(s)})):a[0]<86?(r+="variation ",a.subarray(1).forEach((s,n)=>{([o=>{e.setEffectTypeRaw(2,!1,o),console.info(`${r}main type: ${_[o]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},o=>{e.setEffectTypeRaw(2,!0,o),console.debug(`${r}sub type: ${o+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+n]||function(){})(s)})):a[0]<97?(r+="variation ",a.subarray(1).forEach((s,n)=>{[o=>{console.debug(`${r}send: ${P(o)}dB`)},o=>{console.debug(`${r}pan: ${o-64}`)},o=>{console.debug(`${r}to reverb: ${P(o)}dB`)},o=>{console.debug(`${r}to chorus: ${P(o)}dB`)},o=>{console.debug(`${r}connection: ${o?"system":"insertion"}`)},o=>{console.debug(`${r}channel: CH${o+1}`)},o=>{console.debug(`${r}mod wheel: ${o-64}`)},o=>{console.debug(`${r}bend wheel: ${o-64}`)},o=>{console.debug(`${r}channel after touch: ${o-64}`)},o=>{console.debug(`${r}AC1: ${o-64}`)},o=>{console.debug(`${r}AC2: ${o-64}`)}][a[0]-86+n](s)})):a[0]>111&&a[0]<118?r+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],(a,i,f)=>{a.subarray(1).forEach((r,s)=>{let n=s+a[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][r]}`);else{let o=n-1>>2,u=n-1&3,d=`XG EQ ${o} ${["gain","freq","Q","shape"][u]}: `;[()=>{console.debug(`${d}${r-64}dB`)},()=>{console.debug(`${d}${r} (raw)`)},()=>{console.debug(`${d}${r/10}`)},()=>{console.debug(`${d}${["shelf","peak"][+!!r]}`)}][u]()}})}).add([76,3],(a,i,f)=>{e.dispatchEvent("mupromptex");let r=a[0],s=a[1],n=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((o,u)=>{([d=>{e.setEffectTypeRaw(3+r,!1,d),console.info(`${n}main type: ${_[d]}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))},d=>{e.setEffectTypeRaw(3+r,!0,d),console.debug(`${n}sub type: ${d+1}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))}][s+u]||function(){})(o)})}).add([76,6,0],(a,i,f)=>{let r=a[0];r<64?e.setLetterDisplay(a.subarray(1),"XG letter display",r):e.#j=Date.now()}).add([76,7,0],(a,i,f)=>{let r=a[0];e.#m=0,e.#T=Date.now()+3200,e.#E.fill(0);let s=a.subarray(1);for(let n=0;n>6-w&1,w++})}).add([76,8],(a,i)=>{e.dispatchEvent("mupromptex");let f=e.chRedir(a[0],i,!0),r=a[1],s=m.cc*f,n=`XG CH${f+1} `,o=`Unknown XG part address ${r}.`,u=!0;a.subarray(2).forEach((d,y)=>{u=!0,r<1?console.debug(o):r<41?([()=>{e.#e[s+b[0]]=d,e.dispatchEvent("voice",{part:f})},()=>{e.#e[s+b[32]]=d,e.dispatchEvent("voice",{part:f})},()=>{e.#r[f]=d,e.dispatchEvent("voice",{part:f})},()=>{u=!1;let E=e.chRedir(d,i,!0);e.#f[f]=E,f!=E&&(e.buildRchTree(),console.info(`${n}receives from CH${E+1}`)),e.#$[f]||(e.copyChSetup(E,f,!0),console.debug(`${n}copied from CH${E+1}.`),e.setChActive(f,1),e.dispatchEvent("voice",{part:f}))},()=>{e.#g[f]=+!d},()=>{},()=>{u=!1,e.setChType(f,d,$.xg),console.debug(`${n}type: ${F[d]||d}`),e.dispatchEvent("voice",{part:f})},()=>{e.#s[m.rpn*f+3]=d,e.#o[m.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},!1,!1,()=>{e.#e[s+b[7]]=d},!1,!1,()=>{e.#e[s+b[10]]=d||128},!1,!1,()=>{e.#e[s+b[128]]=d,e.allocateAce(128)},()=>{e.#e[s+b[93]]=d},()=>{e.#e[s+b[91]]=d},()=>{e.#e[s+b[94]]=d},()=>{e.#e[s+b[76]]=d},()=>{e.#e[s+b[77]]=d},()=>{e.#e[s+b[78]]=d},()=>{e.#e[s+b[74]]=d},()=>{e.#e[s+b[71]]=d},()=>{e.#e[s+b[73]]=d},()=>{e.#e[s+b[75]]=d},()=>{e.#e[s+b[72]]=d}][r+y-1]||(()=>{}))():r<48?console.debug(o):r<111?r>102&&r<105&&(e.#e[s+b[[5,65][r&1]]]=d):r<114?console.debug(o):r<116?console.debug(`${n}EQ ${["bass","treble"][r&1]} gain: ${d-64}dB`):r<118?console.debug(o):r<120?console.debug(`${n}EQ ${["bass","treble"][r&1]} freq: ${d}`):console.debug(o)}),u&&e.#i[f]>1&&e.setDrumFirstWrite(f)}).add([76,9],(a,i)=>{let f=e.chRedir(a[0],i,!0),r=a[1],s=m.cc*f,n=`PLG-VL CH${f+1} `;a.subarray(2).forEach((o,u)=>{let d=u+r;switch(d){case 1:{console.info(`${n}breath mode: ${["system","breath","velocity","touch EG"][o]}`);break}case 0:case 27:case 28:break;default:if(d<27){let y=d-3>>1,E=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][y];d&1?d<23?(console.debug(`${n}${E} control source: ${we(o)}`),o&&o<96&&e.allocateAce(130+y),e.#R[m.redir*f+y+2]=o,e.buildRccMap()):console.debug(`${n}${E} scale break point: ${o}`):(console.debug(`${n}${E} depth: ${o-64}`),e.#e[s+b[130+y]]=o)}}})}).add([76,10],(a,i,f)=>{}).add([76,16],(a,i,f)=>{}).add([76,17,0,0],(a,i,f)=>{}).add([76,112],(a,i,f)=>{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.#M[m.ext*a[2]]=e.EXT_VL;break}case 2:{e.#M[m.ext*a[2]]=e.EXT_DX;break}default:e.#M[m.ext*a[2]]=e.EXT_NONE}}).add([73,0,0],(a,i)=>{let f=a[0],r="MU1000 System - ";a.subarray(1).forEach((s,n)=>{let o=f+n;o==8?console.debug(`${r}LCD contrast: ${s}.`):o==18?(e.#x[$.xg][1]=s?126:0,console.debug(`${r}default bank: ${s?"MU100 Native":"MU Basic"}.`),e.dispatchEvent("banklevel",{mode:"xg",data:+!!s}),e.forceVoiceRefresh()):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.#_=!!s,console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][o-64]()})}).add([73,10,0],(a,i)=>{let f=a[0],r=`MU1000 RS${e.#_?"":" (ignored)"}: `;if(f<16)switch(f){case 2:{let s=e.chRedir(0,i,!0);e.#_&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${r}Show CH1~64`);break}case 3:{let s=e.chRedir(a[1]<<5,i,!0);e.#_&&e.dispatchEvent("channelmin",s),e.#_&&e.dispatchEvent("channelmax",s+31),console.info(`${r}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${r}unknown switch ${f} invoked.`)}else if(f<32){if(e.#_){let s=e.chRedir(f-16+(e.#oe<<4),i,!0);e.dispatchEvent("channelactive",s)}}else if(f<36){let s=e.chRedir(f-32<<4,i,!0);e.#_&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),e.#oe=f-32),console.info(`${r}Show CH${s+1}~CH${s+16}`)}}).add([73,11,0],(a,i)=>{let f="MU1000 System - channel ",r="Octavia System - channel ",s=a[0];a.subarray(1).forEach((n,o)=>{let u=s+o;([()=>{e.setChActive(n,1),e.dispatchEvent("channelactive",n),T()&&console.debug(`${f}current part: CH${n+1}`)},()=>{n<5?(e.dispatchEvent("portrange",1<{n<16?(e.dispatchEvent("portstart",n),console.debug(`${r}start port: ${"ABCDEFGHIJKLMNOP"[n]}`)):(e.dispatchEvent("portstart",255),console.debug(`${r}start port: reset`))}][u]||(()=>{console.debug(`${f}unknown address: ${u}`)}))()})}).add([93,3],(a,i)=>{let f=e.chRedir(a[0],i,!0),r=`PLG-100SG CH${f+1} `,s=Date.now();if(a[1]==0){let n="",o=0;a.subarray(2).forEach((u,d)=>{d%2==0?n+=ve[u]||u.toString().padStart("0"):o+=u*13}),s>=e.#ce&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${Ee(n)}`,amend:!0}),e.#ce=s+Math.ceil(o/2)+e.#ne,T()&&console.debug(`${r}vocals: ${n}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)}).add([98,0],(a,i,f)=>{e.dispatchEvent("mupromptex");let r=a[0],s=a.length-5,n=a.length-1;if(r!=s){console.info(`PLG-DX native dump size mismatch! Gave ${r} instead of ${a.length-5}.`);return}let o=N(a.subarray(4,n));if(o!=a[n]){console.info(`Bad PLG-DX checksum ${a[n]} - should be ${o}.`);return}a[0]=98,e.#B.run(a.subarray(0,n),i,f,{noAce:!0})}).add([98,96],(a,i,f,r)=>{let s=e.chRedir(a[0],i,!0),n=m.cc*s,o=a[1];a.subarray(2).forEach((u,d)=>{let y=o+d;if(!(y<10)){if(y==10)e.resetAce();else if(y<27){let E=y+131;r?.noAce||e.allocateAce(E),e.#e[n+b[E]]=u,e.dispatchEvent("cc",{part:s,cc:E,data:u})}}})}).add([100,0],(a,i,f)=>{let r=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.slice(0,2)){case"@I":{this.#v=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:a.slice(2)?.trimLeft()});break}case"@K":{this.#v=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:a.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{this.#v=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:a.slice(2)?.trimLeft()});break}case"@T":{this.#v=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:a.slice(2)?.trimLeft()});break}case"@V":{this.#v=!0,this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:a.slice(2)?.trimLeft()});break}case"XF":{let i=a.slice(2).split(":");switch(i[0]){case"hd":{i.slice(1).forEach((d,r)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][r],data:d})});break}case"ln":{i.slice(1).forEach((d,r)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][r],data:d})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:this.#v?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` +`).forEach((i,d)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:i,mask:d!=0})})}},e.#D[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},e.#D[3]=function(a,i){i<1&&this.#G<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},e.#D[4]=function(a,i){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,i){T()&&console.debug(`Track ${i} requests to get assigned to output ${a}.`),e.#Z[i]=a+1},e.#D[81]=function(a,i){e.#ne=a/1e3},e.#D[127]=function(a,i){e.#ee.run(a,i)},e.#ee.default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},e.#ee.add([67,0,1],function(a,i){e.#Z[i]=a[0]+1}),e.#te=new O("universal non-realtime"),e.#ae=new O("universal realtime"),e.#B=new O("Yamaha"),e.#V=new O("Roland"),e.#K=new O("Korg"),e.#re=new O("Kawai"),e.#ie=new O("Akai"),e.#se=new O("Casio");let t=new O("DX7+ Dump"),c=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,a)};e.#te.default=c,e.#ae.default=c,e.#B.default=c,e.#V.default=c,e.#K.default=c,e.#re.default=c,e.#ie.default=c,e.#se.default=c,t.default=c,e.#te.add([9],(a,i,d)=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),e.setPortMode(e.getTrackPort(i),1,$[["gm","?","g2"][a[0]-1]]),e.#v=e.#v||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),e.#ae.add([4,1],(a,i,d)=>{e.dispatchEvent("mupromptex"),e.#p=((a[1]<<7)+a[0])/16383*100,e.dispatchEvent("mastervolume",e.#p)}).add([4,3],(a,i,d)=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],(a,i,d)=>a[1]-64).add([4,5],(a,i,d)=>{e.dispatchEvent("mupromptex");let r=a[0],s=a[1],n=a[2],o=3,u=o+(r<<1),f=u+s;if(r!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${r})! +`,a);return}let y=0,E=0,w=0;switch(a.subarray(o,u).forEach(x=>{y=y<<7,y|=x}),a.subarray(u,f).forEach((x,M)=>{E|=x<{w|=x<{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),e.setPortMode(e.getTrackPort(i),4,$.xg),e.#v=!1,console.info("MIDI reset: XG");break}default:{e.dispatchEvent("mupromptex");let r=[0,0,0,0],s=(n,o)=>{r[o]=n};if(a.subarray(1).forEach((n,o)=>{let u=o+a[0];([s,s,s,s,f=>{this.#p=f*129/16383*100,e.dispatchEvent("mastervolume",e.#p)},f=>{},f=>{}][u]||(()=>{}))(n,o)}),a[0]<4){let n=0;r.forEach(o=>{n=n<<4,n+=o}),n-=1024}}}}).add([76,2,1],(a,i,d)=>{e.dispatchEvent("mupromptex");let r="XG ";a[0]<32?(r+="reverb ",a.subarray(1).forEach((s,n)=>{([o=>{e.setEffectTypeRaw(0,!1,o),console.info(`${r}main type: ${_[o]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},o=>{e.setEffectTypeRaw(0,!0,o),console.debug(`${r}sub type: ${o+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},o=>{console.debug(`${r}time: ${ge(o)}s`)},o=>{console.debug(`${r}diffusion: ${o}`)},o=>{console.debug(`${r}initial delay: ${o}`)},o=>{console.debug(`${r}HPF cutoff: ${X[o]}Hz`)},o=>{console.debug(`${r}LPF cutoff: ${X[o]}Hz`)},o=>{console.debug(`${r}width: ${o}`)},o=>{console.debug(`${r}height: ${o}`)},o=>{console.debug(`${r}depth: ${o}`)},o=>{console.debug(`${r}wall type: ${o}`)},o=>{console.debug(`${r}dry/wet: ${o}`)},o=>{console.debug(`${r}send: ${P(o)}dB`)},o=>{console.debug(`${r}pan: ${o-64}`)},!1,!1,o=>{console.debug(`${r}delay: ${o}`)},o=>{console.debug(`${r}density: ${o}`)},o=>{console.debug(`${r}balance: ${o}`)},o=>{},o=>{console.debug(`${r}feedback: ${o}`)},o=>{}][a[0]+n]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(s)})):a[0]<64?(r+="chorus ",a.subarray(1).forEach((s,n)=>{([o=>{e.setEffectTypeRaw(1,!1,o),console.info(`${r}main type: ${_[o]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},o=>{e.setEffectTypeRaw(1,!0,o),console.debug(`${r}sub type: ${o+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},o=>{console.debug(`${r}LFO: ${me[o]}Hz`)},o=>{},o=>{console.debug(`${r}feedback: ${o}`)},o=>{console.debug(`${r}delay offset: ${ye(o)}ms`)},o=>{},o=>{console.debug(`${r}low: ${X[o]}Hz`)},o=>{console.debug(`${r}low: ${o-64}dB`)},o=>{console.debug(`${r}high: ${X[o]}Hz`)},o=>{console.debug(`${r}high: ${o-64}dB`)},o=>{console.debug(`${r}dry/wet: ${o}`)},o=>{console.debug(`${r}send: ${P(o)}dB`)},o=>{console.debug(`${r}pan: ${o-64}`)},o=>{console.debug(`${r}to reverb: ${P(o)}dB`)},!1,o=>{},o=>{},o=>{},o=>{console.debug(`${r}LFO phase diff: ${(o-64)*3}deg`)},o=>{console.debug(`${r}input mode: ${o?"stereo":"mono"}`)},o=>{}][a[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(s)})):a[0]<86?(r+="variation ",a.subarray(1).forEach((s,n)=>{([o=>{e.setEffectTypeRaw(2,!1,o),console.info(`${r}main type: ${_[o]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},o=>{e.setEffectTypeRaw(2,!0,o),console.debug(`${r}sub type: ${o+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+n]||function(){})(s)})):a[0]<97?(r+="variation ",a.subarray(1).forEach((s,n)=>{[o=>{console.debug(`${r}send: ${P(o)}dB`)},o=>{console.debug(`${r}pan: ${o-64}`)},o=>{console.debug(`${r}to reverb: ${P(o)}dB`)},o=>{console.debug(`${r}to chorus: ${P(o)}dB`)},o=>{console.debug(`${r}connection: ${o?"system":"insertion"}`)},o=>{console.debug(`${r}channel: CH${o+1}`)},o=>{console.debug(`${r}mod wheel: ${o-64}`)},o=>{console.debug(`${r}bend wheel: ${o-64}`)},o=>{console.debug(`${r}channel after touch: ${o-64}`)},o=>{console.debug(`${r}AC1: ${o-64}`)},o=>{console.debug(`${r}AC2: ${o-64}`)}][a[0]-86+n](s)})):a[0]>111&&a[0]<118?r+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],(a,i,d)=>{a.subarray(1).forEach((r,s)=>{let n=s+a[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][r]}`);else{let o=n-1>>2,u=n-1&3,f=`XG EQ ${o} ${["gain","freq","Q","shape"][u]}: `;[()=>{console.debug(`${f}${r-64}dB`)},()=>{console.debug(`${f}${r} (raw)`)},()=>{console.debug(`${f}${r/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!r]}`)}][u]()}})}).add([76,3],(a,i,d)=>{e.dispatchEvent("mupromptex");let r=a[0],s=a[1],n=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((o,u)=>{([f=>{e.setEffectTypeRaw(3+r,!1,f),console.info(`${n}main type: ${_[f]}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))},f=>{e.setEffectTypeRaw(3+r,!0,f),console.debug(`${n}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))}][s+u]||function(){})(o)})}).add([76,6,0],(a,i,d)=>{let r=a[0];r<64?e.setLetterDisplay(a.subarray(1),"XG letter display",r):e.#j=Date.now()}).add([76,7,0],(a,i,d)=>{let r=a[0];e.#m=0,e.#T=Date.now()+3200,e.#E.fill(0);let s=a.subarray(1);for(let n=0;n>6-w&1,w++})}).add([76,8],(a,i)=>{e.dispatchEvent("mupromptex");let d=e.chRedir(a[0],i,!0),r=a[1],s=m.cc*d,n=`XG CH${d+1} `,o=`Unknown XG part address ${r}.`,u=!0;a.subarray(2).forEach((f,y)=>{u=!0,r<1?console.debug(o):r<41?([()=>{e.#e[s+b[0]]=f,e.dispatchEvent("voice",{part:d})},()=>{e.#e[s+b[32]]=f,e.dispatchEvent("voice",{part:d})},()=>{e.#r[d]=f,e.dispatchEvent("voice",{part:d})},()=>{u=!1;let E=e.chRedir(f,i,!0);e.#f[d]=E,d!=E&&(e.buildRchTree(),console.info(`${n}receives from CH${E+1}`)),e.#$[d]||(e.copyChSetup(E,d,!0),console.debug(`${n}copied from CH${E+1}.`),e.setChActive(d,1),e.dispatchEvent("voice",{part:d}))},()=>{e.#g[d]=+!f},()=>{},()=>{u=!1,e.setChType(d,f,$.xg),console.debug(`${n}type: ${F[f]||f}`),e.dispatchEvent("voice",{part:d})},()=>{e.#s[m.rpn*d+3]=f,e.#o[m.rpnt*d+2]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)})},!1,!1,()=>{e.#e[s+b[7]]=f},!1,!1,()=>{e.#e[s+b[10]]=f||128},!1,!1,()=>{e.#e[s+b[128]]=f,e.allocateAce(128)},()=>{e.#e[s+b[93]]=f},()=>{e.#e[s+b[91]]=f},()=>{e.#e[s+b[94]]=f},()=>{e.#e[s+b[76]]=f},()=>{e.#e[s+b[77]]=f},()=>{e.#e[s+b[78]]=f},()=>{e.#e[s+b[74]]=f},()=>{e.#e[s+b[71]]=f},()=>{e.#e[s+b[73]]=f},()=>{e.#e[s+b[75]]=f},()=>{e.#e[s+b[72]]=f}][r+y-1]||(()=>{}))():r<48?console.debug(o):r<111?r>102&&r<105&&(e.#e[s+b[[5,65][r&1]]]=f):r<114?console.debug(o):r<116?console.debug(`${n}EQ ${["bass","treble"][r&1]} gain: ${f-64}dB`):r<118?console.debug(o):r<120?console.debug(`${n}EQ ${["bass","treble"][r&1]} freq: ${f}`):console.debug(o)}),u&&e.#i[d]>1&&e.setDrumFirstWrite(d)}).add([76,9],(a,i)=>{let d=e.chRedir(a[0],i,!0),r=a[1],s=m.cc*d,n=`PLG-VL CH${d+1} `;a.subarray(2).forEach((o,u)=>{let f=u+r;switch(f){case 1:{console.info(`${n}breath mode: ${["system","breath","velocity","touch EG"][o]}`);break}case 0:case 27:case 28:break;default:if(f<27){let y=f-3>>1,E=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][y];f&1?f<23?(console.debug(`${n}${E} control source: ${we(o)}`),o&&o<96&&e.allocateAce(130+y),e.#R[m.redir*d+y+2]=o,e.buildRccMap()):console.debug(`${n}${E} scale break point: ${o}`):(console.debug(`${n}${E} depth: ${o-64}`),e.#e[s+b[130+y]]=o)}}})}).add([76,10],(a,i,d)=>{}).add([76,16],(a,i,d)=>{}).add([76,17,0,0],(a,i,d)=>{}).add([76,112],(a,i,d)=>{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.#M[m.ext*a[2]]=e.EXT_VL;break}case 2:{e.#M[m.ext*a[2]]=e.EXT_DX;break}default:e.#M[m.ext*a[2]]=e.EXT_NONE}}).add([73,0,0],(a,i)=>{let d=a[0],r="MU1000 System - ";a.subarray(1).forEach((s,n)=>{let o=d+n;o==8?console.debug(`${r}LCD contrast: ${s}.`):o==18?(e.#x[$.xg][1]=s?126:0,console.debug(`${r}default bank: ${s?"MU100 Native":"MU Basic"}.`),e.dispatchEvent("banklevel",{mode:"xg",data:+!!s}),e.forceVoiceRefresh()):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.#_=!!s,console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][o-64]()})}).add([73,10,0],(a,i)=>{let d=a[0],r=`MU1000 RS${e.#_?"":" (ignored)"}: `;if(d<16)switch(d){case 2:{let s=e.chRedir(0,i,!0);e.#_&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${r}Show CH1~64`);break}case 3:{let s=e.chRedir(a[1]<<5,i,!0);e.#_&&e.dispatchEvent("channelmin",s),e.#_&&e.dispatchEvent("channelmax",s+31),console.info(`${r}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${r}unknown switch ${d} invoked.`)}else if(d<32){if(e.#_){let s=e.chRedir(d-16+(e.#oe<<4),i,!0);e.dispatchEvent("channelactive",s)}}else if(d<36){let s=e.chRedir(d-32<<4,i,!0);e.#_&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),e.#oe=d-32),console.info(`${r}Show CH${s+1}~CH${s+16}`)}}).add([73,11,0],(a,i)=>{let d="MU1000 System - channel ",r="Octavia System - channel ",s=a[0];a.subarray(1).forEach((n,o)=>{let u=s+o;([()=>{e.setChActive(n,1),e.dispatchEvent("channelactive",n),T()&&console.debug(`${d}current part: CH${n+1}`)},()=>{n<5?(e.dispatchEvent("portrange",1<{n<16?(e.dispatchEvent("portstart",n),console.debug(`${r}start port: ${"ABCDEFGHIJKLMNOP"[n]}`)):(e.dispatchEvent("portstart",255),console.debug(`${r}start port: reset`))}][u]||(()=>{console.debug(`${d}unknown address: ${u}`)}))()})}).add([93,3],(a,i)=>{let d=e.chRedir(a[0],i,!0),r=`PLG-100SG CH${d+1} `,s=Date.now();if(a[1]==0){let n="",o=0;a.subarray(2).forEach((u,f)=>{f%2==0?n+=ve[u]||u.toString().padStart("0"):o+=u*13}),s>=e.#ce&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${Ee(n)}`,amend:!0}),e.#ce=s+Math.ceil(o/2)+e.#ne,T()&&console.debug(`${r}vocals: ${n}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)}).add([98,0],(a,i,d)=>{e.dispatchEvent("mupromptex");let r=a[0],s=a.length-5,n=a.length-1;if(r!=s){console.info(`PLG-DX native dump size mismatch! Gave ${r} instead of ${a.length-5}.`);return}let o=N(a.subarray(4,n));if(o!=a[n]){console.info(`Bad PLG-DX checksum ${a[n]} - should be ${o}.`);return}a[0]=98,e.#B.run(a.subarray(0,n),i,d,{noAce:!0})}).add([98,96],(a,i,d,r)=>{let s=e.chRedir(a[0],i,!0),n=m.cc*s,o=a[1];a.subarray(2).forEach((u,f)=>{let y=o+f;if(!(y<10)){if(y==10)e.resetAce();else if(y<27){let E=y+131;r?.noAce||e.allocateAce(E),e.#e[n+b[E]]=u,e.dispatchEvent("cc",{part:s,cc:E,data:u})}}})}).add([100,0],(a,i,d)=>{let r=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(r),n=a[a.length-1];if(s!=n){console.warn(`Yamaha DX7+ dump SysEx checksum mismatch! Expected ${s}, but got ${n}: -`,a);return}t.run(r.subarray(1))}).add([100,76],(a,i,f)=>{let r=a[0]>>4,s=a[0]&15,n=a[1];switch(r){case 2:{let o=e.chRedir(s,i,!0),u=m.cc*o;a.subarray(2).forEach((d,y)=>{let E=y+n;if(!(E<7)){if(E<23){let w=E+135;e.allocateAce(w),e.#e[u+b[w]]=d,e.dispatchEvent("cc",{part:o,cc:w,data:d})}}});break}default:console.info("Unknown DX7+ multipart: %o",a)}}),t.add([14,31],(a,i,f)=>{e.#e[m.cc*a[0]+b[64]]=0,e.#C.ano(a[0]),e.switchMode("xg"),e.setPortMode(e.getTrackPort(i),1,$.xg),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${a[0]+1}.`)}).add([76,112],async a=>{let i=a[0],f=m.cc*i,r=m.ext*i,s=m.cvn*i;e.#M[r]=e.EXT_DX,e.#w[i]=1;let n=e.#z.subarray(s,s+m.cvn);n.fill(32),a.subarray(1).forEach((o,u)=>{if(u<10)n[u]=Math.max(o,32);else if(!(u<40)){if(u<56){let d=u+102;e.#e[f+b[d]]=o,e.dispatchEvent("cc",{part:i,cc:d,data:o})}}}),e.#r[i]=i&127,e.#e[m.cc*i+b[0]]=35,e.#e[m.cc*i+b[32]]=i>>7|4,e.dispatchEvent("voice",{part:i}),console.debug(`DX7+ CH${i+1} dump: %o`,a)});let l=function(a,i,f,r){},h=function(a,i){e.dispatchEvent("mupromptex");let f=a*m.dpn,r=i[0],s=i[1];i.subarray(2).forEach((n,o)=>{let u=o+s,d=-1;u<16?([()=>{d=24},()=>{d=25},()=>{d=26},()=>{},()=>{d=28},()=>{d=29},()=>{d=30},()=>{d=31},()=>{},()=>{},()=>{},()=>{d=20},()=>{d=21},()=>{d=22},()=>{d=23},()=>{}][u]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))():u<32||(u<40?([()=>{d=48},()=>{d=49},!1,!1,()=>{d=52},()=>{d=53}][u-32]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))():u<80||([()=>{d=36}][u-80]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))()),d>=0?(T()&&console.debug(f,d,r,n),e.#l[(f+D[d])*m.dnc+r]=n):T()&&console.debug(`XG-style drum param ${u} has no writes.`)})},p=function(a,i,f){e.dispatchEvent("mupromptex");let r=a*m.dpn,s=(i<<7)+f[0];f.subarray(1).forEach((n,o)=>{let u=o+s,d=u&127,y=u>>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?(T()&&console.debug(r,E,d,n),e.#l[(r+D[E])*m.dnc+d]=n):T()&&console.debug(`GS-style drum param ${y} has no writes.`)})};this.#B.add([76,48],(a,i,f)=>{h(0,a)}).add([76,49],(a,i,f)=>{h(1,a)}).add([76,50],(a,i,f)=>{h(2,a)}).add([76,51],(a,i,f)=>{h(3,a)}).add([76,52],(a,i,f)=>{h(4,a)}).add([76,53],(a,i,f)=>{h(5,a)}).add([76,54],(a,i,f)=>{h(6,a)}).add([76,55],(a,i,f)=>{h(7,a)}),this.#B.add([89,0],(a,i,f)=>{if(e.eprom){let r=a[0],s=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);T()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${r} bytes.`);let n=e.eprom.data;a.subarray(4).forEach((o,u)=>{let d=u>>3,y=u&7;if(y==7)for(let E=0;E<7;E++)n[s+7*d+E]+=(o>>6-E&1)<<7;else n[s+7*d+y]=o})}}).add([89,1],(a,i,f)=>{let r=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];T()&&console.debug(`MU1000 EPROM jump to 0x${r.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=r)}).add([89,2],(a,i,f)=>{if(e.eprom){let r=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);T()&&console.debug(`MU1000 EPROM write to 0x${r.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;a.subarray(4).forEach((n,o)=>{let u=o>>3,d=o&7;if(d==7)for(let y=0;y<7;y++)s[r+7*u+y]+=(n>>6-y&1)<<7;else s[r+7*u+d]=n})}}).add([89,3],(a,i,f)=>{}),this.#B.add([39,48],(a,i,f)=>{}).add([43,0,0],(a,i,f)=>{e.dispatchEvent("mupromptex");let r=[0,0,0,0],s=(n,o)=>{r[o]=n};if(a.subarray(1).forEach((n,o)=>{let u=o+a[0];[s,s,s,s,()=>{this.#p=n*129/16383*100,e.dispatchEvent("mastervolume",e.#p)},()=>n-64,()=>n||128,()=>n,()=>n,()=>{console.debug(`TG300 variation on cc${n}.`)}][u](n,u)}),a[0]<4){let n=0;r.forEach(o=>{n=n<<4,n+=o}),n-=1024}}).add([43,1,0],(a,i,f)=>{e.dispatchEvent("mupromptex")}).add([43,2],(a,i,f)=>{e.dispatchEvent("mupromptex");let r=e.chRedir(a[0],i,!0),s=a[1],n=m.cc*r,o=`TG300 CH${r+1} `;a.subarray(2).forEach((u,d)=>{d<5?([()=>{},()=>{e.#e[n+b[0]]=u,e.dispatchEvent("voice",{part:r})},()=>{e.#e[n+b[32]]=u,e.dispatchEvent("voice",{part:r})},()=>{e.#r[r]=u,e.dispatchEvent("voice",{part:r})},()=>{let y=e.chRedir(u,i,!0);e.#f[r]=y,r!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))}][d+s]||(()=>{}))(u,d+s):d<21||(d<47?([()=>{e.#g[r]=+!u},()=>{},()=>{},()=>{e.#s[m.rpn*r+3]=u,e.#o[m.rpnt*r+2]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{},()=>{e.#e[n+b[7]]=u},!1,!1,()=>{e.#e[n+b[10]]=u||128},!1,!1,()=>{console.debug(`${o} AC1 at cc${u}`)},()=>{console.debug(`${o} AC2 at cc${u}`)},()=>{e.#e[n+b[128]]=u,e.allocateAce(128)},()=>{e.#e[n+b[93]]=u},()=>{e.#e[n+b[91]]=u},()=>{e.#e[n+b[94]]=u},()=>{e.#e[n+b[76]]=u},()=>{e.#e[n+b[77]]=u},()=>{e.#e[n+b[74]]=u},()=>{e.#e[n+b[71]]=u},()=>{e.#e[n+b[73]]=u},()=>{e.#e[n+b[75]]=u},()=>{e.#e[n+b[72]]=u},()=>{e.#e[n+b[78]]=u}][d+s-21]||(()=>{}))(u,d+s):d<95||([()=>{e.#e[n+b[65]]=u},()=>{e.#e[n+b[5]]=u}][d+s-95]||(()=>{}))(u,d+s))})}).add([43,7,0],(a,i,f)=>{let r=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",r)}).add([43,7,1],(a,i,f)=>{e.#m=0,e.#T=Date.now()+3200,e.#E.fill(0),a.forEach(function(r,s){let n=Math.floor(s/16),o=s%16,u=(o*3+n)*7,d=7,y=0;for(u-=o*5,n==2&&(d=2);y>6-y&1,y++})}),this.#V.add([66,18,0,0,127],(a,i,f)=>{e.switchMode("sc",!0),e.setPortMode(e.getTrackPort(i),2,$.sc),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.#x[$.sc][1]=e.#c.sc,e.#v=!1,e.#W.fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,i,f)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),e.setPortMode(e.getTrackPort(i),2,$.gs),e.#x[$.gs][1]=e.#c.gs,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.#v=!1,e.#W.fill(0),console.info("MIDI reset: GS");break}default:{e.dispatchEvent("mupromptex");let r=[0,0,0,0],s=(n,o)=>{r[o]=n};if(a.subarray(1).forEach((n,o)=>{let u=o+a[0];[s,s,s,s,d=>{this.#p=d*129/16383*100,e.dispatchEvent("mastervolume",e.#p)},d=>{},d=>{}][u](n,o)}),a[0]<4){let n=0;r.forEach(o=>{n=n<<4,n+=o}),n-=1024}}}}).add([66,18,64,1],(a,i,f)=>{e.dispatchEvent("mupromptex");let r=a[0];if(r<16){let s="".padStart(r," ");a.subarray(1).forEach((n,o)=>{s+=String.fromCharCode(Math.max(32,n))}),s=s.padEnd(16," "),console.debug(`GS patch name: ${s}`)}else r<48||(r<65?a.subarray(1).forEach((s,n)=>{let o=`GS ${r+n>55?"chorus":"reverb"} `;([()=>{console.info(`${o}type: ${ae[s]}`),e.setEffectType(0,40,s),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${o}predelay: ${s}ms`)},()=>{console.info(`${o}type: ${$e[s]}`),e.setEffectType(1,40,16+s),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${o}to reverb: ${P(s)}`)},()=>{console.debug(`${o}to delay: ${P(s)}`)}][r+n-48]||(()=>{}))()}):r<80?console.debug(`Unknown GS patch address: ${r}`):r<91?a.subarray(1).forEach((s,n)=>{let o="GS delay ";([()=>{console.info(`${o}type: ${ke[s]}`),e.setEffectType(2,40,32+s),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${o}to reverb: ${P(s)}`)}][r+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${r}`))}).add([66,18,64,2],(a,i,f)=>{let r="GS EQ ";a.subarray(1).forEach((s,n)=>{([()=>{console.debug(`${r}low freq: ${[200,400][s]}Hz`)},()=>{console.debug(`${r}low gain: ${s-64}dB`)},()=>{console.debug(`${r}high freq: ${[3e3,6e3][s]}Hz`)},()=>{console.debug(`${r}high gain: ${s-64}dB`)}][a[0]+n]||function(){console.warn(`Unknown GS EQ address: ${a[0]+n}`)})()})}).add([66,18,64,3],(a,i,f)=>{e.dispatchEvent("mupromptex");let r="GS EFX ",s=function(n,o){let u=xe(e.#S.subarray(10,12),o,n);u&&console.debug(`${r}${re(e.#S.subarray(10,12))} ${u}`)};a.subarray(1).forEach((n,o)=>{([()=>{e.setEffectTypeRaw(3,!1,32+n),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,n),console.info(`${r}type: ${re(e.#S.subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,()=>{console.debug(`${r}to reverb: ${P(n)}dB`)},()=>{console.debug(`${r}to chorus: ${P(n)}dB`)},()=>{console.debug(`${r}to delay: ${P(n)}dB`)},!1,()=>{console.debug(`${r}1 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${r}1 depth: ${n-64}`)},()=>{console.debug(`${r}2 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${r}2 depth: ${n-64}`)},()=>{console.debug(`${r}to EQ: ${n?"ON":"OFF"}`)}][a[0]+o]||function(u,d){console.warn(`Unknown GS EFX address: ${d}`)})(n,a[0]+o)})}).add([66,18,65],(a,i,f)=>{p((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],(a,i,f)=>{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&&(a[2]?(e.#m=Math.max(Math.min(a[2]-1,9),0),T()&&console.debug(`GS switch display page ${a[2]-1}.`)):(e.#m=0,e.#T=Date.now(),T()&&console.debug("GS disable display page.")));break}default:if(a[0]<6){e.#m>9&&(e.#m=0);let r=a[0]-1<<1|a[1]>>6;e.#m==r&&(e.#T=Date.now()+3200),e.#d[r]?.length||(e.#d[r]=new Uint8Array(256));let s=e.#d[r];T()&&console.debug(`GS frame draw page ${r}.`);let n=a[1]&63;s.fill(0),a.subarray(2).forEach(function(u,d){let y=d+n,E=Math.floor(y/16),w=y%16,x=(w*4+E)*5,M=5,B=0;for(x-=w*4,E==3&&(M=1);B>4-B&1,B++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let g=function(a,i,f){e.dispatchEvent("mupromptex");let r=a[0],s=m.cc*i,n=m.rpn*i,o=`GS CH${i+1} `;r<3?(a.subarray(1).forEach((u,d)=>{[()=>{e.#e[s+b[0]]=u},()=>{e.#r[i]=u},()=>{let y=0;u<16?y=e.chRedir(u,f,!0):y=m.ch,e.#f[i]=y,i!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))}][r+d]()}),e.dispatchEvent("voice",{part:i})):r<19||(r<44?a.subarray(1).forEach((u,d)=>{([()=>{e.#g[i]=+!u},!1,()=>{e.setChType(i,u<<1,$.gs),console.debug(`${o}type: ${u?"drum ":"melodic"}${u||""}`)},()=>{e.#s[n+3]=u,e.#o[m.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},!1,()=>{e.#e[s+b[7]]=u},!1,!1,()=>{e.#e[s+b[10]]=u||128},!1,!1,()=>{console.debug(`${o}CC 1: cc${u}`)},()=>{console.debug(`${o}CC 2: cc${u}`)},()=>{e.#e[s+b[93]]=u},()=>{e.#e[s+b[91]]=u},!1,!1,()=>{e.#s[n+1]=u,e.#o[m.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{e.#s[n+2]=u,e.#o[m.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{e.#e[s+b[94]]=u}][r+d-19]||(()=>{}))()}):r<76||console.debug(`Unknown GS part address: ${r}`))},v=function(a,i){let f=a[0],r=`GS CH${i+1} `;f<2?a.subarray(1).forEach((s,n)=>{[()=>{e.#e[m.cc*i+b[32]]=s},()=>{}][f+n]()}):f<32?console.warn(`Unknown GS misc address: ${f}`):f<35?a.subarray(1).forEach((s,n)=>{[()=>{console.debug(`${r}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${r}EFX: o${["ff","n"][s]}`),e.#a[i]=s,e.dispatchEvent("partefxtoggle",{part:i,active:s})}][f+n-32]()}):console.warn(`Unknown GS misc address: ${f}`)};this.#V.add([66,18,64,16],(a,i)=>{g(a,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(a,i)=>{g(a,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(a,i)=>{g(a,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(a,i)=>{g(a,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(a,i)=>{g(a,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(a,i)=>{g(a,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(a,i)=>{g(a,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(a,i)=>{g(a,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(a,i)=>{g(a,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(a,i)=>{g(a,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(a,i)=>{g(a,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(a,i)=>{g(a,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(a,i)=>{g(a,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(a,i)=>{g(a,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(a,i)=>{g(a,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(a,i)=>{g(a,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(a,i)=>{v(a,e.chRedir(9,i,!0))}).add([66,18,64,65],(a,i)=>{v(a,e.chRedir(0,i,!0))}).add([66,18,64,66],(a,i)=>{v(a,e.chRedir(1,i,!0))}).add([66,18,64,67],(a,i)=>{v(a,e.chRedir(2,i,!0))}).add([66,18,64,68],(a,i)=>{v(a,e.chRedir(3,i,!0))}).add([66,18,64,69],(a,i)=>{v(a,e.chRedir(4,i,!0))}).add([66,18,64,70],(a,i)=>{v(a,e.chRedir(5,i,!0))}).add([66,18,64,71],(a,i)=>{v(a,e.chRedir(6,i,!0))}).add([66,18,64,72],(a,i)=>{v(a,e.chRedir(7,i,!0))}).add([66,18,64,73],(a,i)=>{v(a,e.chRedir(8,i,!0))}).add([66,18,64,74],(a,i)=>{v(a,e.chRedir(10,i,!0))}).add([66,18,64,75],(a,i)=>{v(a,e.chRedir(11,i,!0))}).add([66,18,64,76],(a,i)=>{v(a,e.chRedir(12,i,!0))}).add([66,18,64,77],(a,i)=>{v(a,e.chRedir(13,i,!0))}).add([66,18,64,78],(a,i)=>{v(a,e.chRedir(14,i,!0))}).add([66,18,64,79],(a,i)=>{v(a,e.chRedir(15,i,!0))}),this.#K.add([54,65],(a,i)=>{let f=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(f,!0),e.setPortMode(e.getTrackPort(i),1,$[f]);let r=a[a.length-1],s=a.subarray(0,a.length-1),n=N(s);n!=r&&(console.info(`X5D multi parameters checksum mismatch! Expected ${n}, got ${r}.`),console.debug(a));let o=(a[1]<<7)+a[0],u=(a[3]<<7)+a[2],d=e.chRedir(o&15,i,!0),y=m.cc*d;[()=>{u<1||(u<101?(e.setChType(d,e.CH_MELODIC,$.x5d),e.#r[d]=u-1,e.#e[y+b[0]]=e.#c.x5):u<229?(e.setChType(d,e.CH_MELODIC,$.x5d),e.#r[d]=u-101,e.#e[y+b[0]]=56):(e.setChType(d,e.CH_DRUMS,$.x5d),e.#r[d]=Le[u-229]||0,e.#e[y+b[0]]=62)),e.dispatchEvent("voice",{part:d})},()=>{e.#e[y+b[7]]=u},()=>{u<31&&(e.#e[y+b[10]]=Math.round((u-15)*4.2+64))},()=>{e.#e[y+b[93]]=K(u)},()=>{e.#e[y+b[91]]=K(u)},()=>{e.#s[d*m.rpn+3]=u>8191?u-16320:64+u,e.#o[m.rpnt*d+2]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)})},()=>{e.#s[d*m.rpn+1]=u>8191?u-16320:64+u,e.#o[m.rpnt*d+1]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)})},()=>{u>0&&(e.#s[d*m.rpn]=u,e.#o[m.rpnt*d]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)}))},()=>{}][o>>4]()}).add([54,76,0],(a,i)=>{e.dispatchEvent("mupromptex");let f=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(i),1,$[f]);let r="",s=e.#c.x5,n=0,o=0,u="MSB PRG LSB NME";A(a,function(d,y){if(y<16400){let E=y%164;switch(!0){case E<10:{d>31&&(r+=String.fromCharCode(d));break}case E==10:break;case E==11:{u+=` -${s} ${n} ${o} ${r.trim().replace("Init Voice","")}`,n++,r="";break}}n>99&&(s=90,n=0)}}),e.userBank.clearRange({msb:e.#c.x5,prg:[0,99],lsb:0}),e.userBank.load(u),T()&&console.debug(u),e.forceVoiceRefresh()}).add([54,77,0],(a,i)=>{e.dispatchEvent("mupromptex");let f=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(i),1,$[f]);let r="",s=90,n=0,o=0,u="MSB PRG LSB NME";A(a,function(d,y){if(y<13600){let E=y%136;switch(!0){case E<10:{d>31&&(r+=String.fromCharCode(d));break}case E==11:{u+=` -${s} ${n} ${o} ${r.trim().replace("Init Combi","")}`,n++,r="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(u),T()&&console.debug(u),e.forceVoiceRefresh()}).add([54,78],(a,i)=>{let f=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(i),1,$[f]),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,i)=>{e.dispatchEvent("mupromptex");let f=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(i),1,$[f]),A(a,(r,s)=>{s>0&&s<3&&(e.setEffectType(s-1,44,r),e.dispatchEvent(`efx${["reverb","chorus"][s-1]}`,e.getEffectType(s-1)))})}).add([54,104],(a,i)=>{e.dispatchEvent("mupromptex");let f=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(f,!0);let r=e.getTrackPort(i);if(e.#n[r]&&e.#n[r]!=$[f])if(e.#H.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${i}. Port ${String.fromCharCode(65+r)} mode "${C[e.#n[r]]}" mismatch, should be "${f}".`);return}else console.info(`Track ${i} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+r)}.`);e.setPortMode(r,1,$[f]),A(a,function(s,n,o,u){if(n<192){let d=e.chRedir(Math.floor(n/12),i,!0),y=d*m.cc;switch(n%12){case 0:{s<128?(e.setChType(d,e.CH_MELODIC,$.x5d),e.#e[y+b[0]]=e.#c.x5,e.#r[d]=s):(e.setChType(d,e.CH_DRUMS,$.x5d),e.#e[y+b[0]]=62,e.#r[d]=Le[s-128]),s>0&&e.setChActive(d,1),e.dispatchEvent("voice",{part:d});break}case 1:{e.#e[y+b[7]]=s;break}case 2:{e.#s[d*m.rpn+3]=s>127?s-192:64+s,e.#o[m.rpnt*d+2]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)});break}case 3:{e.#s[d*m.rpn+1]=s>127?s-192:64+s,e.#o[m.rpnt*d+1]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)});break}case 4:{s<31&&(e.#e[y+b[10]]=Math.round((s-15)*4.2+64));break}case 5:{let E=s>>4,w=s&15;e.#e[y+b[91]]=K(w),e.#e[y+b[93]]=K(E);break}case 10:break;case 11:{let E=e.chRedir(s&15,i,!0),w=s>>4;e.#f[d]=s,(E!=d||w)&&(console.info(`X5D Part CH${d+1} receives from CH${E+1}.`),e.buildRchTree())}}}else{let d=e.chRedir(n-192,i,!0)}})}),this.#V.add([22,18,127],(a,i,f)=>{e.switchMode("mt32",!0),e.setPortMode(e.getTrackPort(i),1,$.mt32),e.#v=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,i,f)=>{e.switchMode("mt32");let r=e.chRedir(f,i,!0),s=a[1];a.subarray(2).forEach((n,o)=>{let u=o+s;e.#O[u+(r-1)*16]=n,([!1,()=>{let d=e.#O[r-1<<4];if(d<3){if(e.#w[r]=1,d==2)for(let y=0;y{e.#s[r*m.rpn+3]=n+40,e.#o[m.rpnt*r+2]=1},()=>{e.#s[r*m.rpn+1]=n+14,e.#o[m.rpnt*r+1]=1},()=>{e.#s[r*m.rpn]=n,e.#o[m.rpnt*r]=1},!1,()=>{e.#e[m.cc*r+b[91]]=n?127:0},!1,()=>{e.#e[m.cc*r+b[7]]=n},()=>{e.#e[m.cc*r+b[10]]=Math.ceil(n*9.05)}][u]||(()=>{}))()})}).add([22,18,1],(a,i,f)=>{e.switchMode("mt32");let r=f&7;console.debug(`MT-32 slot #${f+1} Drum: ${a}`);let s=a[0]<<7|a[1];a.subarray(2).forEach((n,o)=>{let u=o+s,d=(u>>2)+24,y=u&3,E=r*m.dpn;if(T()&&console.debug(`MT-32 temp drum note ${d} param ${y}: ${n}`),d<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${d}`);return}[()=>{},()=>{e.#l[(E+D[26])*m.dnc+d]=Math.round(n*1.27)},()=>{e.#l[(E+D[26])*m.dnc+d]=n*9+1&127},()=>{e.#l[(E+D[26])*m.dnc+d]=n?127:0}][y]()})}).add([22,18,2],(a,i,f)=>{e.switchMode("mt32");let r=e.chRedir(f,i,!0),s=a[1]+(a[0]<<7);s<10&&(e.#w[r]=1),a.subarray(2).forEach((n,o)=>{let u=o+s;u<14&&(e.#A[(r-1)*m.cmt+u]=n)}),e.dispatchEvent("voice",{part:r})}).add([22,18,3],(a,i,f)=>{e.switchMode("mt32");let r=f&7;if(a[0]){let s=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((n,o)=>{let u=o+s,d=(u>>2)+24,y=u&3,E=r*m.dpn;if(T()&&console.debug(`MT-32 dev drum note ${d} param ${y}: ${n}`),d<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${d}`);return}[()=>{},()=>{e.#l[(E+D[26])*m.dnc+d]=Math.round(n*1.27)},()=>{e.#l[(E+D[26])*m.dnc+d]=n*9+1&127},()=>{e.#l[(E+D[26])*m.dnc+d]=n?127:0}][y]()})}else{let s=a[1];a.subarray(2).forEach((n,o)=>{let u=o+s;e.#O[u]=n;let d=e.chRedir(1+(u>>4),i,!0),y=u&15;([!1,()=>{let E=e.#O[d-1<<4];if(E<3)if(e.#w[d]=1,E==2)for(let w=0;w{e.#s[d*m.rpn+3]=n+40,e.#o[m.rpnt*d+2]=1},()=>{e.#s[d*m.rpn+1]=n+14,e.#o[m.rpnt*d+1]=1},()=>{e.#s[d*m.rpn]=n,e.#o[m.rpnt*d]=1},!1,()=>{e.#e[m.cc*d+b[91]]=n?127:0},!1,()=>{e.#e[m.cc*d+b[7]]=n},()=>{e.#e[m.cc*d+b[10]]=Math.ceil(n*9.05)}][y]||(()=>{}))()})}}).add([22,18,4],(a,i,f)=>{e.switchMode("mt32");let r=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((n,o)=>{let u=o+r,d=e.chRedir(Math.floor(u/246+1),i,!0),y=u%246;y<14&&(e.#A[(d-1)*m.cmt+y]=n),y<10&&(e.#w[d]=1),s.indexOf(d)<0&&s.push(d)}),s.forEach(n=>{e.dispatchEvent("voice",{part:n})})}).add([22,18,5],(a,i,f)=>{e.switchMode("mt32");let r=(a[0]<<7)+a[1];a.subarray(2).forEach((s,n)=>{let o=r+n,u=Math.floor(o/8),d=o&7,y=u*8;e.#q[o]=s,([!1,()=>{let E=e.#q[y];if(E<3){let w="";if(E==2){let M=m.cmt*u;w=`MT-m:${s.toString().padStart(3,"0")}`}else w=e.baseBank.get(0,s+(E<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:u});let x=`MSB LSB PRG NME -000 127 ${u} ${w}`;e.userBank.load(x,!0)}}][d]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,i,f)=>{e.switchMode("mt32");let r=((a[0]&1)<<7)+a[1],s=a[0]>>1,n=!1;if(a.subarray(2).forEach((o,u)=>{let d=r+u;d{e.switchMode("mt32");let r=a[1],s=!1,n=function(o,u){e.#f[u-12]=o,s=!0};a.subarray(2).forEach((o,u)=>{let d=u+r;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,n,n,n,n,n,n,n,n,n,()=>{e.#p=o,e.dispatchEvent("mastervolume",e.#p)}][d]||(()=>{}))(o,u)}),s&&e.buildRchTree()}).add([22,18,32],(a,i,f)=>{e.switchMode("mt32");let r=a[1],s=" ".repeat(r);a.subarray(2).forEach(n=>{n>31?s+=String.fromCharCode(n):s+=" "}),e.#Q=s.padStart(20," "),e.#j=Date.now()+3200}).add([22,18,82],(a,i)=>{let f=e.chRedir(0,i,!0);for(let r=0;r<16;r++)e.#C.ano(f+r),r&&r<10&&(e.#r[f+r]=ie[r-1]);console.info("MT-32 alt reset complete.")}),this.#K.add([66,0],(a,i)=>{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(i),2,$.ns5r),e.#v=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,i)=>{let f=["ns5r","05rw"][a[0]];e.switchMode(f,!0),e.setPortMode(e.getTrackPort(i),2,$[f]),e.#v=!1}).add([66,18,0,0],(a,i)=>{let f=a[0];switch(f){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(i),2,$.ns5r),e.#v=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(f<10){let r=[0,0,0,0],s=(n,o)=>{r[o]=n};if(a.subarray(1).forEach((n,o)=>{[s,s,s,s,()=>{e.#p=n*129/16383*100,e.dispatchEvent("mastervolume",e.#p)},()=>n-64,()=>n-64,()=>{},()=>{},()=>{}][f+o]()}),a[0]<4){let n=0;r.forEach(o=>{n=n<<4,n+=o}),n-=1024}}}}).add([66,18,0,1],(a,i)=>{}).add([66,18,0,2],(a,i)=>{}).add([66,18,1],(a,i)=>{e.dispatchEvent("mupromptex");let f=e.chRedir(a[0],i,!0),r=f*m.cc,s=a[1],n=`NS5R CH${f+1} `;a.subarray(2).forEach((o,u)=>{let d=s+u;d<3?([()=>{e.#e[r+b[0]]=o||H.bank0},()=>{e.#e[r+b[32]]=o},()=>{e.#r[f]=o}][d](),e.dispatchEvent("voice",{part:f})):d<8||(d<14?[()=>{let y=e.chRedir(o,i,!0);e.#f[f]=y,f!=y&&(e.buildRchTree(),console.info(`${n}receives from CH${y+1}`))},()=>{e.#g[f]=+!o},()=>{e.setChType(f,o,$.ns5r),console.debug(`${n}type: ${F[o]}`)},()=>{e.#s[m.rpn*f+3]=o,e.#o[m.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{},()=>{}][d-8]():d<16||(d<33?[()=>{e.#e[r+b[7]]=o},()=>{e.#e[r+b[11]]=o},()=>{},()=>{},()=>{e.#e[r+b[10]]=o||128},()=>{},()=>{},()=>{e.#e[r+b[93]]=o},()=>{e.#e[r+b[91]]=o},()=>{e.#e[r+b[76]]=o},()=>{e.#e[r+b[77]]=o},()=>{e.#e[r+b[78]]=o},()=>{e.#e[r+b[74]]=o},()=>{e.#e[r+b[71]]=o},()=>{e.#e[r+b[73]]=o},()=>{e.#e[r+b[75]]=o},()=>{e.#e[r+b[72]]=o}][d-16]():d<112||d<114&&[()=>{e.#e[r+b[5]]=o},()=>{e.#e[r+b[65]]=o}][d-112]()))})}).add([66,18,8,0],(a,i)=>{let f=a[0];if(f<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let r=f-32;e.#T=Date.now()+3200,e.#m=10,e.#E.fill(0);let s=a.subarray(1),n=4;s.forEach(function(o,u){let d=u+r,y=d>>4,E=d&15;if(d<80){let w=y>3,x=0,M=y0;)e.#E[E*32+y*7+(M-x)]=w&1,w=w>>1,x++}})}}).add([66,18,48],(a,i,f)=>{h(0,a)}).add([66,18,49],(a,i,f)=>{h(1,a)}).add([66,18,50],(a,i,f)=>{h(2,a)}).add([66,18,51],(a,i,f)=>{h(3,a)}).add([66,18,52],(a,i,f)=>{h(4,a)}).add([66,18,53],(a,i,f)=>{h(5,a)}).add([66,18,54],(a,i,f)=>{h(6,a)}).add([66,18,55],(a,i,f)=>{h(7,a)}).add([66,52],(a,i)=>{e.switchMode("ns5r"),e.#v=!1;let f="";A(a,(r,s)=>{s<8?(r>31&&(f+=String.fromCharCode(r)),s==7&&(e.aiEfxName=f)):s<10&&(e.setEffectType(s-8,44,r),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(a,i)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r"),e.#v=!1;let f="",r=a[a.length-1],s=a.subarray(0,a.length-1),n=N(s);n!=r&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${n}, got ${r}.`),console.debug(a));let o=e.getTrackPort(i);if(e.#n[o]&&e.#n[o]!=$.ns5r)if(e.#H.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${i}. Port ${String.fromCharCode(65+o)} mode "${C[e.#n[o]]}" mismatch, should be "ns5r".`);return}else console.info(`Track ${i} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+o)}.`);e.setPortMode(o,2,$.ns5r),A(s,function(u,d){switch(!0){case d<2944:{let y=e.chRedir(Math.floor(d/92),i,!0),E=y*m.cc;switch(d%92){case 0:{e.#e[E+b[0]]=u,e.dispatchEvent("voice",{part:y});break}case 1:{e.#e[E+b[32]]=u,!u&&!e.#e[E+b[0]]&&(e.#e[E+b[0]]=H.bank0),e.dispatchEvent("voice",{part:y});break}case 2:{e.#r[y]=u,u>0&&e.setChActive(y,1),e.dispatchEvent("voice",{part:y});break}case 3:{let w=e.chRedir(u,i,!0);e.#f[y]=w,y!=w&&(console.info(`NS5R CH${y+1} receives from CH${w+1}.`),e.buildRchTree());break}case 7:{e.#i[y]=u,e.dispatchEvent("voice",{part:y});break}case 8:{e.#s[y*m.rpn+3]=u<40||u>88?u+(u>63?-192:64):u,e.#o[m.rpnt*y+2]=1,e.dispatchEvent("pitch",{part:y,pitch:e.getPitchShift(y)});break}case 9:case 10:{e.#e[E+b[7]]=u;break}case 11:{e.#e[E+b[11]]=u;break}case 14:{e.#e[E+b[10]]=u||128;break}case 19:{e.#e[E+b[93]]=u;break}case 20:{e.#e[E+b[91]]=u;break}case 84:{e.#e[E+b[65]]=u;break}case 85:{e.#e[E+b[5]]=u;break}}break}case d<3096:break;case d<3134:{let y=d-3096;y<8?(u>31&&(f+=String.fromCharCode(u)),y==7&&(e.aiEfxName=f)):y<10&&(e.setEffectType(y-8,44,u),e.dispatchEvent(`efx${["reverb","chorus"][y-8]}`,e.getEffectType(y-8)));break}case d<8566:break}})}).add([66,54],(a,i)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let f="",r=80,s=0,n=0,o="MSB PRG LSB NME";A(a,function(u,d){let y=d%158;switch(!0){case y<10:{u>31&&(f+=String.fromCharCode(u));break}case y==10:break;case y==11:{r=u&127;break}case y==12:{n=u&127;break}case y==13:{o+=` -${r} ${s} ${n} ${f.trim().replace("Init Voice","")}`,s++,f="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(o),T()&&console.debug(o),e.forceVoiceRefresh()}).add([66,55],(a,i)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let f="",r=88,s=0,n=0,o="MSB PRG LSB NME";A(a,function(u,d){let y=d%126;switch(!0){case y<10:{u>31&&(f+=String.fromCharCode(u));break}case y==11:break;case y==12:break;case y==13:{o+=` -${r} ${s} ${n} ${f.trim().replace("Init Combi","")}`,s++,f="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(o),T()&&console.debug(o),e.forceVoiceRefresh()}).add([66,125],(a,i,f)=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],(a,i,f)=>{let r=a[a.length-1],s=a.subarray(0,a.length-1),n=N(s);n!=r&&(console.info(`NS5R screen dump checksum mismatch! Expected ${n}, got ${r}.`),console.debug(a));let o=new Uint8Array(5760);A(a,(u,d,y)=>{if(d<720)for(let E=0;E<8;E++)o[d*8+E]=u>>7-E&1}),e.dispatchEvent("screen",{type:"ns5r",data:o})}).add([76],(a,i,f)=>{e.#K.run([66,...a],i,f)}),this.#re.add([16,0,8,0],(a,i,f)=>{let r=(a[2]<<4)+a[3],s="K11 ";([()=>{e.switchMode("k11",!0),e.setPortMode(e.getTrackPort(i),2,$.k11),e.#v=!1,e.#x[$.k11][1]=r?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,r),console.debug(`${s}reverb type: ${r}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${s}reverb time: ${r}`)},()=>{console.debug(`${s}reverb time: ${r}`)},()=>{console.debug(`${s}reverb predelay: ${r}`)},()=>{console.debug(`${s}reverb predelay: ${r}`)},()=>{console.debug(`${s}depth high: ${r}`)},()=>{console.debug(`${s}depth high: ${r}`)},()=>{console.debug(`${s}depth low: ${r}`)},()=>{console.debug(`${s}depth low: ${r}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,i,f)=>{e.dispatchEvent("mupromptex");let r=e.chRedir(a[1],i,!0),s=m.cc*r,n=m.rpn*r,o=(a[3]<<4)+a[4],u=`K11 CH${r+1} `;([()=>{o<128?(e.setChType(r,e.CH_MELODIC,$.k11),e.#e[s+b[0]]=0,e.#r[r]=o):(e.setChType(r,e.CH_DRUMS,$.k11),e.#r[r]=o-128),e.dispatchEvent("voice",{part:r})},()=>{let d=e.chRedir(o,i,!0);e.#f[r]=d,r!=d&&(e.buildRchTree(),console.info(`${u}receives from CH${d+1}`))},()=>{e.#e[s+b[7]]=o},()=>{uupThis.setChActive(r,o)},()=>{e.#e[s+b[10]]=o},()=>{e.#s[n+3]=o+40,e.#o[m.rpnt*r+2]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{e.#s[n+1]=o>>1,e.#s[n+2]=o&1,e.#o[m.rpnt*r+1]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{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,i,f)=>{e.dispatchEvent("mupromptex");let r=(a[2]<<4)+a[3],s="GMLX ";([()=>{console.debug(`${s}reverb type: ${r}`)},()=>{console.debug(`${s}reverb time: ${r}`)},()=>{console.debug(`${s}reverb predelay: ${r}`)},()=>{console.debug(`${s}depth high: ${r}`)},()=>{console.debug(`${s}depth low: ${r}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,i,f)=>{e.dispatchEvent("mupromptex");let r=(a[2]<<4)+a[3],s=e.chRedir(a[1],i,!0),n=s*m.cc;[()=>{r<128?(e.setChType(s,e.CH_MELODIC,$.k11),e.#e[n+b[0]]=0,e.#e[n+b[32]]=0,e.#r[s]=r):r<160?(e.setChType(s,e.CH_MELODIC,$.k11),e.#e[n+b[0]]=0,e.#e[n+b[32]]=7,e.#r[s]=r-100):(e.setChType(s,e.CH_DRUMS,$.k11),e.#e[n+b[0]]=122,e.#e[n+b[32]]=0,e.#r[s]=r-160),e.dispatchEvent("voice",{part:s})},()=>{let o=e.chRedir(r,i,!0);e.#f[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,i,f)=>{e.dispatchEvent("mupromptex");let r=(a[2]<<4)+a[3],s=e.chRedir(a[1],i,!0),n=s*m.cc,o=s*m.rpn,u=`GMLX CH${s+1} `;[()=>{e.setChActive(s,r)},()=>{e.#e[n+b[7]]=r},()=>{e.#e[n+b[10]]=r},()=>{e.#e[n+b[91]]=r?127:0},()=>{e.#s[o+3]=r+40,e.#o[m.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{e.#s[o+1]=r,e.#o[m.rpnt*s+1]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{e.#s[o]=r,e.#o[m.rpnt*s]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{}][a[0]]()}),this.#ie.add([66,93,64],(a,i,f)=>{let r=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{e.dispatchEvent("mupromptex"),e.#p=r*129/16383*100,e.dispatchEvent("mastervolume",e.#p);break}case 5:{e.dispatchEvent("mupromptex"),r-64;break}case 6:{e.dispatchEvent("mupromptex"),console.debug(`SG global reverb: ${r?"on":"off"}`);break}case 127:{e.switchMode("sg",!0),e.setPortMode(e.getTrackPort(i),1,$.sg);break}}break}case 1:{switch(a[1]){case 48:{e.dispatchEvent("mupromptex"),console.debug(`SG reverb type: ${ae[r]}`);break}}break}default:if(a[0]>>4==1){e.dispatchEvent("mupromptex");let s=e.chRedir(a[0]&15,i,!0);if(a[1]==2){let n=e.chRedir(r,i,!0);e.#f[s]=n,s!=n&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${n+1}`))}else a[1]==19&&(e.#e[m.cc*s+b[7]]=r)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),this.#se.add([9],(a,i,f)=>{e.dispatchEvent("mupromptex"),console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremolo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),this.#B.add([127,0],(a,i,f)=>{e.switchMode("motif");let r=new Uint8Array([127,1,...a]);e.#B.run(r,i,f)}).add([127,1,0,0],(a,i,f)=>{e.switchMode("s90es");let r="S90/Motif ES system ",s=a[0];a.subarray(1).forEach((n,o)=>{([()=>{e.#p=n*12900/16383,e.dispatchEvent("mastervolume",e.#p)}][s+o]||(()=>{console.info(`Unrecognized ${r}ID: ${s+o}`)}))()})}).add([127,1,0,36,54,1],(a,i,f)=>{e.switchMode("s90es");let r="S90/Motif ES reverb ",s=a[0];a.subarray(1).forEach((n,o)=>{([()=>{e.setEffectTypeRaw(0,!1,n&15|112)},()=>{e.setEffectTypeRaw(0,!0,n)}][s+o]||(()=>{}))()}),e.dispatchEvent("efxreverb",e.getEffectType(0))}).add([127,1,0,37,54,2],(a,i,f)=>{e.switchMode("s90es");let r="S90/Motif ES chorus ",s=a[0];a.subarray(1).forEach((n,o)=>{([()=>{e.setEffectTypeRaw(1,!1,n&15|112)},()=>{e.setEffectTypeRaw(1,!0,n)}][s+o]||(()=>{}))()}),e.dispatchEvent("efxchorus",e.getEffectType(1))}).add([127,1,0,34,54,3],(a,i,f)=>{e.switchMode("s90es");let r="S90/Motif ES insert 1 ",s=a[0];a.subarray(1).forEach((n,o)=>{([()=>{e.setEffectTypeRaw(3,!1,n&15|112)},()=>{e.setEffectTypeRaw(3,!0,n)}][s+o]||(()=>{}))()}),e.dispatchEvent("efxinsert0",e.getEffectType(3))}).add([127,1,0,34,54,4],(a,i,f)=>{e.switchMode("s90es");let r="S90/Motif ES insert 2 ",s=a[0];a.subarray(1).forEach((n,o)=>{([()=>{e.setEffectTypeRaw(4,!1,n&15|112)},()=>{e.setEffectTypeRaw(4,!0,n)}][s+o]||(()=>{}))()}),e.dispatchEvent("efxinsert1",e.getEffectType(4))}).add([127,1,0,35,54,17],(a,i,f)=>{e.switchMode("s90es");let r="S90/Motif ES variation ",s=a[0];a.subarray(1).forEach((n,o)=>{([()=>{e.setEffectTypeRaw(2,!1,n&15|112)},()=>{e.setEffectTypeRaw(2,!0,n)}][s+o]||(()=>{}))()}),e.dispatchEvent("efxdelay",e.getEffectType(2))}).add([127,1,0,58,55],(a,i,f)=>{e.dispatchEvent("mupromptex"),e.switchMode("s90es");let r=e.getTrackPort(i);if(e.#n[r]&&e.#n[r]!=e.#c.smotif)if(e.#H.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${i}. Port ${String.fromCharCode(65+r)} mode "${C[e.#n[r]]}" mismatch, should be "${C[e.#c.smotif]}".`);return}else console.info(`Track ${i} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+r)}.`);let s=e.chRedir(a[0],i,!0),n=m.cc*s,o=a[1];a[0]>15&&(s=a[0]+32);let u=`Track ${i} S90/Motif ES bulk CH${s<128?s+1:"U"+(s-127)} `;console.debug(u,a),!(a[0]>15)&&a.subarray(2).forEach((d,y)=>{([()=>{e.#e[n+b[0]]=d,e.dispatchEvent("voice",{part:s})},()=>{d&&e.setChActive(s,1),e.#e[n+b[32]]=d,e.setChType(s,[32,40].indexOf(d)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:s})},()=>{d&&e.setChActive(s,1),e.#r[s]=d,e.dispatchEvent("voice",{part:s})},()=>{let E=e.chRedir(d,i,!0);e.#f[s]=E,s!=E&&(e.buildRchTree(),console.info(`${u}receives from CH${E+1}`))},()=>{e.#g[s]=d?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{d!=100&&e.setChActive(s,1),e.#e[n+b[7]]=d},()=>{d!=64&&e.setChActive(s,1),e.#e[n+b[10]]=d},!1,!1,!1,()=>{e.#e[n+b[91]]=d},()=>{d&&e.setChActive(s,1),e.#e[n+b[93]]=d},()=>{d&&e.setChActive(s,1),e.#e[n+b[94]]=d},()=>{d!=127&&e.setChActive(s,1),e.#e[n+b[128]]=d,e.allocateAce(128)},()=>{},()=>{d!=64&&e.setChActive(s,1),e.#e[n+b[74]]=d},()=>{d!=64&&e.setChActive(s,1),e.#e[n+b[71]]=d},!1,()=>{e.#e[n+b[65]]=d},()=>{e.#e[n+b[5]]=d},()=>{}][o+y]||(()=>{}))()})}).add([127,1,54,16],(a,i,f)=>{e.switchMode("s90es");let r=a[0];a.subarray(1).forEach((s,n)=>{let u=`S90/Motif ES EQ${(n>>2)+1} `;([()=>{let d=s-64},()=>{let d=X[s]},()=>{let d=s/10},()=>{let d=s}][r+n&3]||(()=>{}))()})}),this.#V.add([0,72,18,0,0,0,0],(a,i,f)=>{e.switchMode("sd",!0),e.setPortMode(e.getTrackPort(i),2,$.sd),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,i,f)=>{e.dispatchEvent("mupromptex");let r=a[0]>>5,s=a[0]&31;switch(r){case 0:{let n=a[0]>>1,o=a[1];switch(n){case 1:{a.subarray(2).forEach((u,d,y)=>{let E=d+o;switch(E){case 0:{u&&(e.setEffectType(1,60,u-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${E} - ${u}`));break}}});break}case 2:{a.subarray(2).forEach((u,d)=>{let y=d+o;switch(y){case 0:{u&&(e.setEffectType(0,55+u,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${y} - ${u}`));break}}});break}case 3:case 4:case 5:{let u=n-1;a.subarray(2).forEach((d,y)=>{let E=y+o;switch(console.debug(`SD MFX ${u-2}: ${E} - ${d}`),E){case 0:{e.setEffectTypeRaw(u,62,d),e.dispatchEvent(`efx${u>2?"delay":"insert"+(u-4)}`,e.getEffectType(u));break}}}),console.debug(`SD MFX message: +`,a);return}t.run(r.subarray(1))}).add([100,76],(a,i,d)=>{let r=a[0]>>4,s=a[0]&15,n=a[1];switch(r){case 2:{let o=e.chRedir(s,i,!0),u=m.cc*o;a.subarray(2).forEach((f,y)=>{let E=y+n;if(!(E<7)){if(E<23){let w=E+135;e.allocateAce(w),e.#e[u+b[w]]=f,e.dispatchEvent("cc",{part:o,cc:w,data:f})}}});break}default:console.info("Unknown DX7+ multipart: %o",a)}}).add([1,20],(a,i,d)=>{d==115?(e.switchMode("doc",!0),e.setPortMode(e.getTrackPort(i),1,$.doc),console.info("MIDI reset: DOC")):console.debug(`Unknown Yamaha SysEx: 67, ${d}, ${a.join(", ")}`)}).add([1,17,15,89],(a,i,d)=>{d==115?(e.setEffectType(0,24,a[0]|16),e.dispatchEvent("efxreverb",e.getEffectType(0))):console.debug(`Unknown Yamaha SysEx: 67, ${d}, ${a.join(", ")}`)}).add([1,24],(a,i,d)=>{if(d==115){for(let r=0;r<16;r++){let s=e.chRedir(r,i,!0);e.#e[s*m.cc+b[91]]=127}console.info("DOC Global Reverb: on")}else console.debug(`Unknown Yamaha SysEx: 67, ${d}, ${a.join(", ")}`)}),t.add([14,31],(a,i,d)=>{e.#e[m.cc*a[0]+b[64]]=0,e.#C.ano(a[0]),e.switchMode("xg"),e.setPortMode(e.getTrackPort(i),1,$.xg),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${a[0]+1}.`)}).add([76,112],async a=>{let i=a[0],d=m.cc*i,r=m.ext*i,s=m.cvn*i;e.#M[r]=e.EXT_DX,e.#w[i]=1;let n=e.#z.subarray(s,s+m.cvn);n.fill(32),a.subarray(1).forEach((o,u)=>{if(u<10)n[u]=Math.max(o,32);else if(!(u<40)){if(u<56){let f=u+102;e.#e[d+b[f]]=o,e.dispatchEvent("cc",{part:i,cc:f,data:o})}}}),e.#r[i]=i&127,e.#e[m.cc*i+b[0]]=35,e.#e[m.cc*i+b[32]]=i>>7|4,e.dispatchEvent("voice",{part:i}),console.debug(`DX7+ CH${i+1} dump: %o`,a)});let l=function(a,i,d,r){},h=function(a,i){e.dispatchEvent("mupromptex");let d=a*m.dpn,r=i[0],s=i[1];i.subarray(2).forEach((n,o)=>{let u=o+s,f=-1;u<16?([()=>{f=24},()=>{f=25},()=>{f=26},()=>{},()=>{f=28},()=>{f=29},()=>{f=30},()=>{f=31},()=>{},()=>{},()=>{},()=>{f=20},()=>{f=21},()=>{f=22},()=>{f=23},()=>{}][u]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))():u<32||(u<40?([()=>{f=48},()=>{f=49},!1,!1,()=>{f=52},()=>{f=53}][u-32]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))():u<80||([()=>{f=36}][u-80]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))()),f>=0?(T()&&console.debug(d,f,r,n),e.#l[(d+D[f])*m.dnc+r]=n):T()&&console.debug(`XG-style drum param ${u} has no writes.`)})},p=function(a,i,d){e.dispatchEvent("mupromptex");let r=a*m.dpn,s=(i<<7)+d[0];d.subarray(1).forEach((n,o)=>{let u=o+s,f=u&127,y=u>>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?(T()&&console.debug(r,E,f,n),e.#l[(r+D[E])*m.dnc+f]=n):T()&&console.debug(`GS-style drum param ${y} has no writes.`)})};this.#B.add([76,48],(a,i,d)=>{h(0,a)}).add([76,49],(a,i,d)=>{h(1,a)}).add([76,50],(a,i,d)=>{h(2,a)}).add([76,51],(a,i,d)=>{h(3,a)}).add([76,52],(a,i,d)=>{h(4,a)}).add([76,53],(a,i,d)=>{h(5,a)}).add([76,54],(a,i,d)=>{h(6,a)}).add([76,55],(a,i,d)=>{h(7,a)}),this.#B.add([89,0],(a,i,d)=>{if(e.eprom){let r=a[0],s=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);T()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${r} bytes.`);let n=e.eprom.data;a.subarray(4).forEach((o,u)=>{let f=u>>3,y=u&7;if(y==7)for(let E=0;E<7;E++)n[s+7*f+E]+=(o>>6-E&1)<<7;else n[s+7*f+y]=o})}}).add([89,1],(a,i,d)=>{let r=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];T()&&console.debug(`MU1000 EPROM jump to 0x${r.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=r)}).add([89,2],(a,i,d)=>{if(e.eprom){let r=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);T()&&console.debug(`MU1000 EPROM write to 0x${r.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;a.subarray(4).forEach((n,o)=>{let u=o>>3,f=o&7;if(f==7)for(let y=0;y<7;y++)s[r+7*u+y]+=(n>>6-y&1)<<7;else s[r+7*u+f]=n})}}).add([89,3],(a,i,d)=>{}),this.#B.add([39,48],(a,i,d)=>{}).add([43,0,0],(a,i,d)=>{e.dispatchEvent("mupromptex");let r=[0,0,0,0],s=(n,o)=>{r[o]=n};if(a.subarray(1).forEach((n,o)=>{let u=o+a[0];[s,s,s,s,()=>{this.#p=n*129/16383*100,e.dispatchEvent("mastervolume",e.#p)},()=>n-64,()=>n||128,()=>n,()=>n,()=>{console.debug(`TG300 variation on cc${n}.`)}][u](n,u)}),a[0]<4){let n=0;r.forEach(o=>{n=n<<4,n+=o}),n-=1024}}).add([43,1,0],(a,i,d)=>{e.dispatchEvent("mupromptex")}).add([43,2],(a,i,d)=>{e.dispatchEvent("mupromptex");let r=e.chRedir(a[0],i,!0),s=a[1],n=m.cc*r,o=`TG300 CH${r+1} `;a.subarray(2).forEach((u,f)=>{f<5?([()=>{},()=>{e.#e[n+b[0]]=u,e.dispatchEvent("voice",{part:r})},()=>{e.#e[n+b[32]]=u,e.dispatchEvent("voice",{part:r})},()=>{e.#r[r]=u,e.dispatchEvent("voice",{part:r})},()=>{let y=e.chRedir(u,i,!0);e.#f[r]=y,r!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))}][f+s]||(()=>{}))(u,f+s):f<21||(f<47?([()=>{e.#g[r]=+!u},()=>{},()=>{},()=>{e.#s[m.rpn*r+3]=u,e.#o[m.rpnt*r+2]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{},()=>{e.#e[n+b[7]]=u},!1,!1,()=>{e.#e[n+b[10]]=u||128},!1,!1,()=>{console.debug(`${o} AC1 at cc${u}`)},()=>{console.debug(`${o} AC2 at cc${u}`)},()=>{e.#e[n+b[128]]=u,e.allocateAce(128)},()=>{e.#e[n+b[93]]=u},()=>{e.#e[n+b[91]]=u},()=>{e.#e[n+b[94]]=u},()=>{e.#e[n+b[76]]=u},()=>{e.#e[n+b[77]]=u},()=>{e.#e[n+b[74]]=u},()=>{e.#e[n+b[71]]=u},()=>{e.#e[n+b[73]]=u},()=>{e.#e[n+b[75]]=u},()=>{e.#e[n+b[72]]=u},()=>{e.#e[n+b[78]]=u}][f+s-21]||(()=>{}))(u,f+s):f<95||([()=>{e.#e[n+b[65]]=u},()=>{e.#e[n+b[5]]=u}][f+s-95]||(()=>{}))(u,f+s))})}).add([43,7,0],(a,i,d)=>{let r=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",r)}).add([43,7,1],(a,i,d)=>{e.#m=0,e.#T=Date.now()+3200,e.#E.fill(0),a.forEach(function(r,s){let n=Math.floor(s/16),o=s%16,u=(o*3+n)*7,f=7,y=0;for(u-=o*5,n==2&&(f=2);y>6-y&1,y++})}),this.#V.add([66,18,0,0,127],(a,i,d)=>{e.switchMode("sc",!0),e.setPortMode(e.getTrackPort(i),2,$.sc),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.#x[$.sc][1]=e.#c.sc,e.#v=!1,e.#W.fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,i,d)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),e.setPortMode(e.getTrackPort(i),2,$.gs),e.#x[$.gs][1]=e.#c.gs,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.#v=!1,e.#W.fill(0),console.info("MIDI reset: GS");break}default:{e.dispatchEvent("mupromptex");let r=[0,0,0,0],s=(n,o)=>{r[o]=n};if(a.subarray(1).forEach((n,o)=>{let u=o+a[0];[s,s,s,s,f=>{this.#p=f*129/16383*100,e.dispatchEvent("mastervolume",e.#p)},f=>{},f=>{}][u](n,o)}),a[0]<4){let n=0;r.forEach(o=>{n=n<<4,n+=o}),n-=1024}}}}).add([66,18,64,1],(a,i,d)=>{e.dispatchEvent("mupromptex");let r=a[0];if(r<16){let s="".padStart(r," ");a.subarray(1).forEach((n,o)=>{s+=String.fromCharCode(Math.max(32,n))}),s=s.padEnd(16," "),console.debug(`GS patch name: ${s}`)}else r<48||(r<65?a.subarray(1).forEach((s,n)=>{let o=`GS ${r+n>55?"chorus":"reverb"} `;([()=>{console.info(`${o}type: ${ae[s]}`),e.setEffectType(0,40,s),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${o}predelay: ${s}ms`)},()=>{console.info(`${o}type: ${$e[s]}`),e.setEffectType(1,40,16+s),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${o}to reverb: ${P(s)}`)},()=>{console.debug(`${o}to delay: ${P(s)}`)}][r+n-48]||(()=>{}))()}):r<80?console.debug(`Unknown GS patch address: ${r}`):r<91?a.subarray(1).forEach((s,n)=>{let o="GS delay ";([()=>{console.info(`${o}type: ${ke[s]}`),e.setEffectType(2,40,32+s),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${o}to reverb: ${P(s)}`)}][r+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${r}`))}).add([66,18,64,2],(a,i,d)=>{let r="GS EQ ";a.subarray(1).forEach((s,n)=>{([()=>{console.debug(`${r}low freq: ${[200,400][s]}Hz`)},()=>{console.debug(`${r}low gain: ${s-64}dB`)},()=>{console.debug(`${r}high freq: ${[3e3,6e3][s]}Hz`)},()=>{console.debug(`${r}high gain: ${s-64}dB`)}][a[0]+n]||function(){console.warn(`Unknown GS EQ address: ${a[0]+n}`)})()})}).add([66,18,64,3],(a,i,d)=>{e.dispatchEvent("mupromptex");let r="GS EFX ",s=function(n,o){let u=xe(e.#S.subarray(10,12),o,n);u&&console.debug(`${r}${re(e.#S.subarray(10,12))} ${u}`)};a.subarray(1).forEach((n,o)=>{([()=>{e.setEffectTypeRaw(3,!1,32+n),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,n),console.info(`${r}type: ${re(e.#S.subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,()=>{console.debug(`${r}to reverb: ${P(n)}dB`)},()=>{console.debug(`${r}to chorus: ${P(n)}dB`)},()=>{console.debug(`${r}to delay: ${P(n)}dB`)},!1,()=>{console.debug(`${r}1 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${r}1 depth: ${n-64}`)},()=>{console.debug(`${r}2 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${r}2 depth: ${n-64}`)},()=>{console.debug(`${r}to EQ: ${n?"ON":"OFF"}`)}][a[0]+o]||function(u,f){console.warn(`Unknown GS EFX address: ${f}`)})(n,a[0]+o)})}).add([66,18,65],(a,i,d)=>{p((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],(a,i,d)=>{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&&(a[2]?(e.#m=Math.max(Math.min(a[2]-1,9),0),T()&&console.debug(`GS switch display page ${a[2]-1}.`)):(e.#m=0,e.#T=Date.now(),T()&&console.debug("GS disable display page.")));break}default:if(a[0]<6){e.#m>9&&(e.#m=0);let r=a[0]-1<<1|a[1]>>6;e.#m==r&&(e.#T=Date.now()+3200),e.#d[r]?.length||(e.#d[r]=new Uint8Array(256));let s=e.#d[r];T()&&console.debug(`GS frame draw page ${r}.`);let n=a[1]&63;s.fill(0),a.subarray(2).forEach(function(u,f){let y=f+n,E=Math.floor(y/16),w=y%16,x=(w*4+E)*5,M=5,B=0;for(x-=w*4,E==3&&(M=1);B>4-B&1,B++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let g=function(a,i,d){e.dispatchEvent("mupromptex");let r=a[0],s=m.cc*i,n=m.rpn*i,o=`GS CH${i+1} `;r<3?(a.subarray(1).forEach((u,f)=>{[()=>{e.#e[s+b[0]]=u},()=>{e.#r[i]=u},()=>{let y=0;u<16?y=e.chRedir(u,d,!0):y=m.ch,e.#f[i]=y,i!=y&&(e.buildRchTree(),console.info(`${o}receives from CH${y+1}`))}][r+f]()}),e.dispatchEvent("voice",{part:i})):r<19||(r<44?a.subarray(1).forEach((u,f)=>{([()=>{e.#g[i]=+!u},!1,()=>{e.setChType(i,u<<1,$.gs),console.debug(`${o}type: ${u?"drum ":"melodic"}${u||""}`)},()=>{e.#s[n+3]=u,e.#o[m.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},!1,()=>{e.#e[s+b[7]]=u},!1,!1,()=>{e.#e[s+b[10]]=u||128},!1,!1,()=>{console.debug(`${o}CC 1: cc${u}`)},()=>{console.debug(`${o}CC 2: cc${u}`)},()=>{e.#e[s+b[93]]=u},()=>{e.#e[s+b[91]]=u},!1,!1,()=>{e.#s[n+1]=u,e.#o[m.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{e.#s[n+2]=u,e.#o[m.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{e.#e[s+b[94]]=u}][r+f-19]||(()=>{}))()}):r<76||console.debug(`Unknown GS part address: ${r}`))},v=function(a,i){let d=a[0],r=`GS CH${i+1} `;d<2?a.subarray(1).forEach((s,n)=>{[()=>{e.#e[m.cc*i+b[32]]=s},()=>{}][d+n]()}):d<32?console.warn(`Unknown GS misc address: ${d}`):d<35?a.subarray(1).forEach((s,n)=>{[()=>{console.debug(`${r}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${r}EFX: o${["ff","n"][s]}`),e.#a[i]=s,e.dispatchEvent("partefxtoggle",{part:i,active:s})}][d+n-32]()}):console.warn(`Unknown GS misc address: ${d}`)};this.#V.add([66,18,64,16],(a,i)=>{g(a,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(a,i)=>{g(a,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(a,i)=>{g(a,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(a,i)=>{g(a,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(a,i)=>{g(a,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(a,i)=>{g(a,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(a,i)=>{g(a,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(a,i)=>{g(a,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(a,i)=>{g(a,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(a,i)=>{g(a,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(a,i)=>{g(a,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(a,i)=>{g(a,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(a,i)=>{g(a,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(a,i)=>{g(a,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(a,i)=>{g(a,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(a,i)=>{g(a,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(a,i)=>{v(a,e.chRedir(9,i,!0))}).add([66,18,64,65],(a,i)=>{v(a,e.chRedir(0,i,!0))}).add([66,18,64,66],(a,i)=>{v(a,e.chRedir(1,i,!0))}).add([66,18,64,67],(a,i)=>{v(a,e.chRedir(2,i,!0))}).add([66,18,64,68],(a,i)=>{v(a,e.chRedir(3,i,!0))}).add([66,18,64,69],(a,i)=>{v(a,e.chRedir(4,i,!0))}).add([66,18,64,70],(a,i)=>{v(a,e.chRedir(5,i,!0))}).add([66,18,64,71],(a,i)=>{v(a,e.chRedir(6,i,!0))}).add([66,18,64,72],(a,i)=>{v(a,e.chRedir(7,i,!0))}).add([66,18,64,73],(a,i)=>{v(a,e.chRedir(8,i,!0))}).add([66,18,64,74],(a,i)=>{v(a,e.chRedir(10,i,!0))}).add([66,18,64,75],(a,i)=>{v(a,e.chRedir(11,i,!0))}).add([66,18,64,76],(a,i)=>{v(a,e.chRedir(12,i,!0))}).add([66,18,64,77],(a,i)=>{v(a,e.chRedir(13,i,!0))}).add([66,18,64,78],(a,i)=>{v(a,e.chRedir(14,i,!0))}).add([66,18,64,79],(a,i)=>{v(a,e.chRedir(15,i,!0))}),this.#K.add([54,65],(a,i)=>{let d=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(d,!0),e.setPortMode(e.getTrackPort(i),1,$[d]);let r=a[a.length-1],s=a.subarray(0,a.length-1),n=N(s);n!=r&&(console.info(`X5D multi parameters checksum mismatch! Expected ${n}, got ${r}.`),console.debug(a));let o=(a[1]<<7)+a[0],u=(a[3]<<7)+a[2],f=e.chRedir(o&15,i,!0),y=m.cc*f;[()=>{u<1||(u<101?(e.setChType(f,e.CH_MELODIC,$.x5d),e.#r[f]=u-1,e.#e[y+b[0]]=e.#c.x5):u<229?(e.setChType(f,e.CH_MELODIC,$.x5d),e.#r[f]=u-101,e.#e[y+b[0]]=56):(e.setChType(f,e.CH_DRUMS,$.x5d),e.#r[f]=Le[u-229]||0,e.#e[y+b[0]]=62)),e.dispatchEvent("voice",{part:f})},()=>{e.#e[y+b[7]]=u},()=>{u<31&&(e.#e[y+b[10]]=Math.round((u-15)*4.2+64))},()=>{e.#e[y+b[93]]=K(u)},()=>{e.#e[y+b[91]]=K(u)},()=>{e.#s[f*m.rpn+3]=u>8191?u-16320:64+u,e.#o[m.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{e.#s[f*m.rpn+1]=u>8191?u-16320:64+u,e.#o[m.rpnt*f+1]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{u>0&&(e.#s[f*m.rpn]=u,e.#o[m.rpnt*f]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)}))},()=>{}][o>>4]()}).add([54,76,0],(a,i)=>{e.dispatchEvent("mupromptex");let d=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(d),e.setPortMode(e.getTrackPort(i),1,$[d]);let r="",s=e.#c.x5,n=0,o=0,u="MSB PRG LSB NME";A(a,function(f,y){if(y<16400){let E=y%164;switch(!0){case E<10:{f>31&&(r+=String.fromCharCode(f));break}case E==10:break;case E==11:{u+=` +${s} ${n} ${o} ${r.trim().replace("Init Voice","")}`,n++,r="";break}}n>99&&(s=90,n=0)}}),e.userBank.clearRange({msb:e.#c.x5,prg:[0,99],lsb:0}),e.userBank.load(u),T()&&console.debug(u),e.forceVoiceRefresh()}).add([54,77,0],(a,i)=>{e.dispatchEvent("mupromptex");let d=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(d),e.setPortMode(e.getTrackPort(i),1,$[d]);let r="",s=90,n=0,o=0,u="MSB PRG LSB NME";A(a,function(f,y){if(y<13600){let E=y%136;switch(!0){case E<10:{f>31&&(r+=String.fromCharCode(f));break}case E==11:{u+=` +${s} ${n} ${o} ${r.trim().replace("Init Combi","")}`,n++,r="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(u),T()&&console.debug(u),e.forceVoiceRefresh()}).add([54,78],(a,i)=>{let d=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(d),e.setPortMode(e.getTrackPort(i),1,$[d]),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,i)=>{e.dispatchEvent("mupromptex");let d=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(d),e.setPortMode(e.getTrackPort(i),1,$[d]),A(a,(r,s)=>{s>0&&s<3&&(e.setEffectType(s-1,44,r),e.dispatchEvent(`efx${["reverb","chorus"][s-1]}`,e.getEffectType(s-1)))})}).add([54,104],(a,i)=>{e.dispatchEvent("mupromptex");let d=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(d,!0);let r=e.getTrackPort(i);if(e.#n[r]&&e.#n[r]!=$[d])if(e.#H.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${i}. Port ${String.fromCharCode(65+r)} mode "${C[e.#n[r]]}" mismatch, should be "${d}".`);return}else console.info(`Track ${i} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+r)}.`);e.setPortMode(r,1,$[d]),A(a,function(s,n,o,u){if(n<192){let f=e.chRedir(Math.floor(n/12),i,!0),y=f*m.cc;switch(n%12){case 0:{s<128?(e.setChType(f,e.CH_MELODIC,$.x5d),e.#e[y+b[0]]=e.#c.x5,e.#r[f]=s):(e.setChType(f,e.CH_DRUMS,$.x5d),e.#e[y+b[0]]=62,e.#r[f]=Le[s-128]),s>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{e.#e[y+b[7]]=s;break}case 2:{e.#s[f*m.rpn+3]=s>127?s-192:64+s,e.#o[m.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)});break}case 3:{e.#s[f*m.rpn+1]=s>127?s-192:64+s,e.#o[m.rpnt*f+1]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)});break}case 4:{s<31&&(e.#e[y+b[10]]=Math.round((s-15)*4.2+64));break}case 5:{let E=s>>4,w=s&15;e.#e[y+b[91]]=K(w),e.#e[y+b[93]]=K(E);break}case 10:break;case 11:{let E=e.chRedir(s&15,i,!0),w=s>>4;e.#f[f]=s,(E!=f||w)&&(console.info(`X5D Part CH${f+1} receives from CH${E+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(n-192,i,!0)}})}),this.#V.add([22,18,127],(a,i,d)=>{e.switchMode("mt32",!0),e.setPortMode(e.getTrackPort(i),1,$.mt32),e.#v=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,i,d)=>{e.switchMode("mt32");let r=e.chRedir(d,i,!0),s=a[1];a.subarray(2).forEach((n,o)=>{let u=o+s;e.#O[u+(r-1)*16]=n,([!1,()=>{let f=e.#O[r-1<<4];if(f<3){if(e.#w[r]=1,f==2)for(let y=0;y{e.#s[r*m.rpn+3]=n+40,e.#o[m.rpnt*r+2]=1},()=>{e.#s[r*m.rpn+1]=n+14,e.#o[m.rpnt*r+1]=1},()=>{e.#s[r*m.rpn]=n,e.#o[m.rpnt*r]=1},!1,()=>{e.#e[m.cc*r+b[91]]=n?127:0},!1,()=>{e.#e[m.cc*r+b[7]]=n},()=>{e.#e[m.cc*r+b[10]]=Math.ceil(n*9.05)}][u]||(()=>{}))()})}).add([22,18,1],(a,i,d)=>{e.switchMode("mt32");let r=d&7;console.debug(`MT-32 slot #${d+1} Drum: ${a}`);let s=a[0]<<7|a[1];a.subarray(2).forEach((n,o)=>{let u=o+s,f=(u>>2)+24,y=u&3,E=r*m.dpn;if(T()&&console.debug(`MT-32 temp drum note ${f} param ${y}: ${n}`),f<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${f}`);return}[()=>{},()=>{e.#l[(E+D[26])*m.dnc+f]=Math.round(n*1.27)},()=>{e.#l[(E+D[26])*m.dnc+f]=n*9+1&127},()=>{e.#l[(E+D[26])*m.dnc+f]=n?127:0}][y]()})}).add([22,18,2],(a,i,d)=>{e.switchMode("mt32");let r=e.chRedir(d,i,!0),s=a[1]+(a[0]<<7);s<10&&(e.#w[r]=1),a.subarray(2).forEach((n,o)=>{let u=o+s;u<14&&(e.#A[(r-1)*m.cmt+u]=n)}),e.dispatchEvent("voice",{part:r})}).add([22,18,3],(a,i,d)=>{e.switchMode("mt32");let r=d&7;if(a[0]){let s=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((n,o)=>{let u=o+s,f=(u>>2)+24,y=u&3,E=r*m.dpn;if(T()&&console.debug(`MT-32 dev drum note ${f} param ${y}: ${n}`),f<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${f}`);return}[()=>{},()=>{e.#l[(E+D[26])*m.dnc+f]=Math.round(n*1.27)},()=>{e.#l[(E+D[26])*m.dnc+f]=n*9+1&127},()=>{e.#l[(E+D[26])*m.dnc+f]=n?127:0}][y]()})}else{let s=a[1];a.subarray(2).forEach((n,o)=>{let u=o+s;e.#O[u]=n;let f=e.chRedir(1+(u>>4),i,!0),y=u&15;([!1,()=>{let E=e.#O[f-1<<4];if(E<3)if(e.#w[f]=1,E==2)for(let w=0;w{e.#s[f*m.rpn+3]=n+40,e.#o[m.rpnt*f+2]=1},()=>{e.#s[f*m.rpn+1]=n+14,e.#o[m.rpnt*f+1]=1},()=>{e.#s[f*m.rpn]=n,e.#o[m.rpnt*f]=1},!1,()=>{e.#e[m.cc*f+b[91]]=n?127:0},!1,()=>{e.#e[m.cc*f+b[7]]=n},()=>{e.#e[m.cc*f+b[10]]=Math.ceil(n*9.05)}][y]||(()=>{}))()})}}).add([22,18,4],(a,i,d)=>{e.switchMode("mt32");let r=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((n,o)=>{let u=o+r,f=e.chRedir(Math.floor(u/246+1),i,!0),y=u%246;y<14&&(e.#A[(f-1)*m.cmt+y]=n),y<10&&(e.#w[f]=1),s.indexOf(f)<0&&s.push(f)}),s.forEach(n=>{e.dispatchEvent("voice",{part:n})})}).add([22,18,5],(a,i,d)=>{e.switchMode("mt32");let r=(a[0]<<7)+a[1];a.subarray(2).forEach((s,n)=>{let o=r+n,u=Math.floor(o/8),f=o&7,y=u*8;e.#q[o]=s,([!1,()=>{let E=e.#q[y];if(E<3){let w="";if(E==2){let M=m.cmt*u;w=`MT-m:${s.toString().padStart(3,"0")}`}else w=e.baseBank.get(0,s+(E<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:u});let x=`MSB LSB PRG NME +000 127 ${u} ${w}`;e.userBank.load(x,!0)}}][f]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,i,d)=>{e.switchMode("mt32");let r=((a[0]&1)<<7)+a[1],s=a[0]>>1,n=!1;if(a.subarray(2).forEach((o,u)=>{let f=r+u;f{e.switchMode("mt32");let r=a[1],s=!1,n=function(o,u){e.#f[u-12]=o,s=!0};a.subarray(2).forEach((o,u)=>{let f=u+r;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,n,n,n,n,n,n,n,n,n,()=>{e.#p=o,e.dispatchEvent("mastervolume",e.#p)}][f]||(()=>{}))(o,u)}),s&&e.buildRchTree()}).add([22,18,32],(a,i,d)=>{e.switchMode("mt32");let r=a[1],s=" ".repeat(r);a.subarray(2).forEach(n=>{n>31?s+=String.fromCharCode(n):s+=" "}),e.#Q=s.padStart(20," "),e.#j=Date.now()+3200}).add([22,18,82],(a,i)=>{let d=e.chRedir(0,i,!0);for(let r=0;r<16;r++)e.#C.ano(d+r),r&&r<10&&(e.#r[d+r]=ie[r-1]);console.info("MT-32 alt reset complete.")}),this.#K.add([66,0],(a,i)=>{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(i),2,$.ns5r),e.#v=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,i)=>{let d=["ns5r","05rw"][a[0]];e.switchMode(d,!0),e.setPortMode(e.getTrackPort(i),2,$[d]),e.#v=!1}).add([66,18,0,0],(a,i)=>{let d=a[0];switch(d){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(i),2,$.ns5r),e.#v=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(d<10){let r=[0,0,0,0],s=(n,o)=>{r[o]=n};if(a.subarray(1).forEach((n,o)=>{[s,s,s,s,()=>{e.#p=n*129/16383*100,e.dispatchEvent("mastervolume",e.#p)},()=>n-64,()=>n-64,()=>{},()=>{},()=>{}][d+o]()}),a[0]<4){let n=0;r.forEach(o=>{n=n<<4,n+=o}),n-=1024}}}}).add([66,18,0,1],(a,i)=>{}).add([66,18,0,2],(a,i)=>{}).add([66,18,1],(a,i)=>{e.dispatchEvent("mupromptex");let d=e.chRedir(a[0],i,!0),r=d*m.cc,s=a[1],n=`NS5R CH${d+1} `;a.subarray(2).forEach((o,u)=>{let f=s+u;f<3?([()=>{e.#e[r+b[0]]=o||H.bank0},()=>{e.#e[r+b[32]]=o},()=>{e.#r[d]=o}][f](),e.dispatchEvent("voice",{part:d})):f<8||(f<14?[()=>{let y=e.chRedir(o,i,!0);e.#f[d]=y,d!=y&&(e.buildRchTree(),console.info(`${n}receives from CH${y+1}`))},()=>{e.#g[d]=+!o},()=>{e.setChType(d,o,$.ns5r),console.debug(`${n}type: ${F[o]}`)},()=>{e.#s[m.rpn*d+3]=o,e.#o[m.rpnt*d+2]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)})},()=>{},()=>{}][f-8]():f<16||(f<33?[()=>{e.#e[r+b[7]]=o},()=>{e.#e[r+b[11]]=o},()=>{},()=>{},()=>{e.#e[r+b[10]]=o||128},()=>{},()=>{},()=>{e.#e[r+b[93]]=o},()=>{e.#e[r+b[91]]=o},()=>{e.#e[r+b[76]]=o},()=>{e.#e[r+b[77]]=o},()=>{e.#e[r+b[78]]=o},()=>{e.#e[r+b[74]]=o},()=>{e.#e[r+b[71]]=o},()=>{e.#e[r+b[73]]=o},()=>{e.#e[r+b[75]]=o},()=>{e.#e[r+b[72]]=o}][f-16]():f<112||f<114&&[()=>{e.#e[r+b[5]]=o},()=>{e.#e[r+b[65]]=o}][f-112]()))})}).add([66,18,8,0],(a,i)=>{let d=a[0];if(d<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let r=d-32;e.#T=Date.now()+3200,e.#m=10,e.#E.fill(0);let s=a.subarray(1),n=4;s.forEach(function(o,u){let f=u+r,y=f>>4,E=f&15;if(f<80){let w=y>3,x=0,M=y0;)e.#E[E*32+y*7+(M-x)]=w&1,w=w>>1,x++}})}}).add([66,18,48],(a,i,d)=>{h(0,a)}).add([66,18,49],(a,i,d)=>{h(1,a)}).add([66,18,50],(a,i,d)=>{h(2,a)}).add([66,18,51],(a,i,d)=>{h(3,a)}).add([66,18,52],(a,i,d)=>{h(4,a)}).add([66,18,53],(a,i,d)=>{h(5,a)}).add([66,18,54],(a,i,d)=>{h(6,a)}).add([66,18,55],(a,i,d)=>{h(7,a)}).add([66,52],(a,i)=>{e.switchMode("ns5r"),e.#v=!1;let d="";A(a,(r,s)=>{s<8?(r>31&&(d+=String.fromCharCode(r)),s==7&&(e.aiEfxName=d)):s<10&&(e.setEffectType(s-8,44,r),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(a,i)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r"),e.#v=!1;let d="",r=a[a.length-1],s=a.subarray(0,a.length-1),n=N(s);n!=r&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${n}, got ${r}.`),console.debug(a));let o=e.getTrackPort(i);if(e.#n[o]&&e.#n[o]!=$.ns5r)if(e.#H.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${i}. Port ${String.fromCharCode(65+o)} mode "${C[e.#n[o]]}" mismatch, should be "ns5r".`);return}else console.info(`Track ${i} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+o)}.`);e.setPortMode(o,2,$.ns5r),A(s,function(u,f){switch(!0){case f<2944:{let y=e.chRedir(Math.floor(f/92),i,!0),E=y*m.cc;switch(f%92){case 0:{e.#e[E+b[0]]=u,e.dispatchEvent("voice",{part:y});break}case 1:{e.#e[E+b[32]]=u,!u&&!e.#e[E+b[0]]&&(e.#e[E+b[0]]=H.bank0),e.dispatchEvent("voice",{part:y});break}case 2:{e.#r[y]=u,u>0&&e.setChActive(y,1),e.dispatchEvent("voice",{part:y});break}case 3:{let w=e.chRedir(u,i,!0);e.#f[y]=w,y!=w&&(console.info(`NS5R CH${y+1} receives from CH${w+1}.`),e.buildRchTree());break}case 7:{e.#i[y]=u,e.dispatchEvent("voice",{part:y});break}case 8:{e.#s[y*m.rpn+3]=u<40||u>88?u+(u>63?-192:64):u,e.#o[m.rpnt*y+2]=1,e.dispatchEvent("pitch",{part:y,pitch:e.getPitchShift(y)});break}case 9:case 10:{e.#e[E+b[7]]=u;break}case 11:{e.#e[E+b[11]]=u;break}case 14:{e.#e[E+b[10]]=u||128;break}case 19:{e.#e[E+b[93]]=u;break}case 20:{e.#e[E+b[91]]=u;break}case 84:{e.#e[E+b[65]]=u;break}case 85:{e.#e[E+b[5]]=u;break}}break}case f<3096:break;case f<3134:{let y=f-3096;y<8?(u>31&&(d+=String.fromCharCode(u)),y==7&&(e.aiEfxName=d)):y<10&&(e.setEffectType(y-8,44,u),e.dispatchEvent(`efx${["reverb","chorus"][y-8]}`,e.getEffectType(y-8)));break}case f<8566:break}})}).add([66,54],(a,i)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let d="",r=80,s=0,n=0,o="MSB PRG LSB NME";A(a,function(u,f){let y=f%158;switch(!0){case y<10:{u>31&&(d+=String.fromCharCode(u));break}case y==10:break;case y==11:{r=u&127;break}case y==12:{n=u&127;break}case y==13:{o+=` +${r} ${s} ${n} ${d.trim().replace("Init Voice","")}`,s++,d="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(o),T()&&console.debug(o),e.forceVoiceRefresh()}).add([66,55],(a,i)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let d="",r=88,s=0,n=0,o="MSB PRG LSB NME";A(a,function(u,f){let y=f%126;switch(!0){case y<10:{u>31&&(d+=String.fromCharCode(u));break}case y==11:break;case y==12:break;case y==13:{o+=` +${r} ${s} ${n} ${d.trim().replace("Init Combi","")}`,s++,d="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(o),T()&&console.debug(o),e.forceVoiceRefresh()}).add([66,125],(a,i,d)=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],(a,i,d)=>{let r=a[a.length-1],s=a.subarray(0,a.length-1),n=N(s);n!=r&&(console.info(`NS5R screen dump checksum mismatch! Expected ${n}, got ${r}.`),console.debug(a));let o=new Uint8Array(5760);A(a,(u,f,y)=>{if(f<720)for(let E=0;E<8;E++)o[f*8+E]=u>>7-E&1}),e.dispatchEvent("screen",{type:"ns5r",data:o})}).add([76],(a,i,d)=>{e.#K.run([66,...a],i,d)}),this.#re.add([16,0,8,0],(a,i,d)=>{let r=(a[2]<<4)+a[3],s="K11 ";([()=>{e.switchMode("k11",!0),e.setPortMode(e.getTrackPort(i),2,$.k11),e.#v=!1,e.#x[$.k11][1]=r?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,r),console.debug(`${s}reverb type: ${r}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${s}reverb time: ${r}`)},()=>{console.debug(`${s}reverb time: ${r}`)},()=>{console.debug(`${s}reverb predelay: ${r}`)},()=>{console.debug(`${s}reverb predelay: ${r}`)},()=>{console.debug(`${s}depth high: ${r}`)},()=>{console.debug(`${s}depth high: ${r}`)},()=>{console.debug(`${s}depth low: ${r}`)},()=>{console.debug(`${s}depth low: ${r}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,i,d)=>{e.dispatchEvent("mupromptex");let r=e.chRedir(a[1],i,!0),s=m.cc*r,n=m.rpn*r,o=(a[3]<<4)+a[4],u=`K11 CH${r+1} `;([()=>{o<128?(e.setChType(r,e.CH_MELODIC,$.k11),e.#e[s+b[0]]=0,e.#r[r]=o):(e.setChType(r,e.CH_DRUMS,$.k11),e.#r[r]=o-128),e.dispatchEvent("voice",{part:r})},()=>{let f=e.chRedir(o,i,!0);e.#f[r]=f,r!=f&&(e.buildRchTree(),console.info(`${u}receives from CH${f+1}`))},()=>{e.#e[s+b[7]]=o},()=>{uupThis.setChActive(r,o)},()=>{e.#e[s+b[10]]=o},()=>{e.#s[n+3]=o+40,e.#o[m.rpnt*r+2]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{e.#s[n+1]=o>>1,e.#s[n+2]=o&1,e.#o[m.rpnt*r+1]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{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,i,d)=>{e.dispatchEvent("mupromptex");let r=(a[2]<<4)+a[3],s="GMLX ";([()=>{console.debug(`${s}reverb type: ${r}`)},()=>{console.debug(`${s}reverb time: ${r}`)},()=>{console.debug(`${s}reverb predelay: ${r}`)},()=>{console.debug(`${s}depth high: ${r}`)},()=>{console.debug(`${s}depth low: ${r}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,i,d)=>{e.dispatchEvent("mupromptex");let r=(a[2]<<4)+a[3],s=e.chRedir(a[1],i,!0),n=s*m.cc;[()=>{r<128?(e.setChType(s,e.CH_MELODIC,$.k11),e.#e[n+b[0]]=0,e.#e[n+b[32]]=0,e.#r[s]=r):r<160?(e.setChType(s,e.CH_MELODIC,$.k11),e.#e[n+b[0]]=0,e.#e[n+b[32]]=7,e.#r[s]=r-100):(e.setChType(s,e.CH_DRUMS,$.k11),e.#e[n+b[0]]=122,e.#e[n+b[32]]=0,e.#r[s]=r-160),e.dispatchEvent("voice",{part:s})},()=>{let o=e.chRedir(r,i,!0);e.#f[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,i,d)=>{e.dispatchEvent("mupromptex");let r=(a[2]<<4)+a[3],s=e.chRedir(a[1],i,!0),n=s*m.cc,o=s*m.rpn,u=`GMLX CH${s+1} `;[()=>{e.setChActive(s,r)},()=>{e.#e[n+b[7]]=r},()=>{e.#e[n+b[10]]=r},()=>{e.#e[n+b[91]]=r?127:0},()=>{e.#s[o+3]=r+40,e.#o[m.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{e.#s[o+1]=r,e.#o[m.rpnt*s+1]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{e.#s[o]=r,e.#o[m.rpnt*s]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{}][a[0]]()}),this.#ie.add([66,93,64],(a,i,d)=>{let r=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{e.dispatchEvent("mupromptex"),e.#p=r*129/16383*100,e.dispatchEvent("mastervolume",e.#p);break}case 5:{e.dispatchEvent("mupromptex"),r-64;break}case 6:{e.dispatchEvent("mupromptex"),console.debug(`SG global reverb: ${r?"on":"off"}`);break}case 127:{e.switchMode("sg",!0),e.setPortMode(e.getTrackPort(i),1,$.sg);break}}break}case 1:{switch(a[1]){case 48:{e.dispatchEvent("mupromptex"),console.debug(`SG reverb type: ${ae[r]}`);break}}break}default:if(a[0]>>4==1){e.dispatchEvent("mupromptex");let s=e.chRedir(a[0]&15,i,!0);if(a[1]==2){let n=e.chRedir(r,i,!0);e.#f[s]=n,s!=n&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${n+1}`))}else a[1]==19&&(e.#e[m.cc*s+b[7]]=r)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),this.#se.add([9],(a,i,d)=>{e.dispatchEvent("mupromptex"),console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremolo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),this.#B.add([127,0],(a,i,d)=>{e.switchMode("motif");let r=new Uint8Array([127,1,...a]);e.#B.run(r,i,d)}).add([127,1,0,0],(a,i,d)=>{e.switchMode("s90es");let r="S90/Motif ES system ",s=a[0];a.subarray(1).forEach((n,o)=>{([()=>{e.#p=n*12900/16383,e.dispatchEvent("mastervolume",e.#p)}][s+o]||(()=>{console.info(`Unrecognized ${r}ID: ${s+o}`)}))()})}).add([127,1,0,36,54,1],(a,i,d)=>{e.switchMode("s90es");let r="S90/Motif ES reverb ",s=a[0];a.subarray(1).forEach((n,o)=>{([()=>{e.setEffectTypeRaw(0,!1,n&15|112)},()=>{e.setEffectTypeRaw(0,!0,n)}][s+o]||(()=>{}))()}),e.dispatchEvent("efxreverb",e.getEffectType(0))}).add([127,1,0,37,54,2],(a,i,d)=>{e.switchMode("s90es");let r="S90/Motif ES chorus ",s=a[0];a.subarray(1).forEach((n,o)=>{([()=>{e.setEffectTypeRaw(1,!1,n&15|112)},()=>{e.setEffectTypeRaw(1,!0,n)}][s+o]||(()=>{}))()}),e.dispatchEvent("efxchorus",e.getEffectType(1))}).add([127,1,0,34,54,3],(a,i,d)=>{e.switchMode("s90es");let r="S90/Motif ES insert 1 ",s=a[0];a.subarray(1).forEach((n,o)=>{([()=>{e.setEffectTypeRaw(3,!1,n&15|112)},()=>{e.setEffectTypeRaw(3,!0,n)}][s+o]||(()=>{}))()}),e.dispatchEvent("efxinsert0",e.getEffectType(3))}).add([127,1,0,34,54,4],(a,i,d)=>{e.switchMode("s90es");let r="S90/Motif ES insert 2 ",s=a[0];a.subarray(1).forEach((n,o)=>{([()=>{e.setEffectTypeRaw(4,!1,n&15|112)},()=>{e.setEffectTypeRaw(4,!0,n)}][s+o]||(()=>{}))()}),e.dispatchEvent("efxinsert1",e.getEffectType(4))}).add([127,1,0,35,54,17],(a,i,d)=>{e.switchMode("s90es");let r="S90/Motif ES variation ",s=a[0];a.subarray(1).forEach((n,o)=>{([()=>{e.setEffectTypeRaw(2,!1,n&15|112)},()=>{e.setEffectTypeRaw(2,!0,n)}][s+o]||(()=>{}))()}),e.dispatchEvent("efxdelay",e.getEffectType(2))}).add([127,1,0,58,55],(a,i,d)=>{e.dispatchEvent("mupromptex"),e.switchMode("s90es");let r=e.getTrackPort(i);if(e.#n[r]&&e.#n[r]!=e.#c.smotif)if(e.#H.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${i}. Port ${String.fromCharCode(65+r)} mode "${C[e.#n[r]]}" mismatch, should be "${C[e.#c.smotif]}".`);return}else console.info(`Track ${i} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+r)}.`);let s=e.chRedir(a[0],i,!0),n=m.cc*s,o=a[1];a[0]>15&&(s=a[0]+32);let u=`Track ${i} S90/Motif ES bulk CH${s<128?s+1:"U"+(s-127)} `;console.debug(u,a),!(a[0]>15)&&a.subarray(2).forEach((f,y)=>{([()=>{e.#e[n+b[0]]=f,e.dispatchEvent("voice",{part:s})},()=>{f&&e.setChActive(s,1),e.#e[n+b[32]]=f,e.setChType(s,[32,40].indexOf(f)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:s})},()=>{f&&e.setChActive(s,1),e.#r[s]=f,e.dispatchEvent("voice",{part:s})},()=>{let E=e.chRedir(f,i,!0);e.#f[s]=E,s!=E&&(e.buildRchTree(),console.info(`${u}receives from CH${E+1}`))},()=>{e.#g[s]=f?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{f!=100&&e.setChActive(s,1),e.#e[n+b[7]]=f},()=>{f!=64&&e.setChActive(s,1),e.#e[n+b[10]]=f},!1,!1,!1,()=>{e.#e[n+b[91]]=f},()=>{f&&e.setChActive(s,1),e.#e[n+b[93]]=f},()=>{f&&e.setChActive(s,1),e.#e[n+b[94]]=f},()=>{f!=127&&e.setChActive(s,1),e.#e[n+b[128]]=f,e.allocateAce(128)},()=>{},()=>{f!=64&&e.setChActive(s,1),e.#e[n+b[74]]=f},()=>{f!=64&&e.setChActive(s,1),e.#e[n+b[71]]=f},!1,()=>{e.#e[n+b[65]]=f},()=>{e.#e[n+b[5]]=f},()=>{}][o+y]||(()=>{}))()})}).add([127,1,54,16],(a,i,d)=>{e.switchMode("s90es");let r=a[0];a.subarray(1).forEach((s,n)=>{let u=`S90/Motif ES EQ${(n>>2)+1} `;([()=>{let f=s-64},()=>{let f=X[s]},()=>{let f=s/10},()=>{let f=s}][r+n&3]||(()=>{}))()})}),this.#V.add([0,72,18,0,0,0,0],(a,i,d)=>{e.switchMode("sd",!0),e.setPortMode(e.getTrackPort(i),2,$.sd),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,i,d)=>{e.dispatchEvent("mupromptex");let r=a[0]>>5,s=a[0]&31;switch(r){case 0:{let n=a[0]>>1,o=a[1];switch(n){case 1:{a.subarray(2).forEach((u,f,y)=>{let E=f+o;switch(E){case 0:{u&&(e.setEffectType(1,60,u-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${E} - ${u}`));break}}});break}case 2:{a.subarray(2).forEach((u,f)=>{let y=f+o;switch(y){case 0:{u&&(e.setEffectType(0,55+u,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${y} - ${u}`));break}}});break}case 3:case 4:case 5:{let u=n-1;a.subarray(2).forEach((f,y)=>{let E=y+o;switch(console.debug(`SD MFX ${u-2}: ${E} - ${f}`),E){case 0:{e.setEffectTypeRaw(u,62,f),e.dispatchEvent(`efx${u>2?"delay":"insert"+(u-4)}`,e.getEffectType(u));break}}}),console.debug(`SD MFX message: %o`,a);break}default:console.debug(`Unknown SD-90 global effects message: -%o`,a)}break}case 1:{let n=e.chRedir(s,i,!0),o=a[1],u=n*m.cc;a.subarray(2).forEach((d,y)=>{let E=o+y;E<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[u+b[0]]=d,d){case 104:case 105:case 106:case 107:case 120:{e.#i[n]||e.setChType(n,e.CH_DRUMS);break}default:e.#i[n]&&e.setChType(n,e.CH_MELODIC)}e.dispatchEvent("voice",{part:n})},()=>{e.#e[u+b[32]]=d,e.dispatchEvent("voice",{part:n})},()=>{e.#r[n]=d,e.dispatchEvent("voice",{part:n})},()=>{e.#e[u+b[7]]=d},()=>{e.#e[u+b[10]]=d},()=>{},()=>{},()=>{d<2&&(e.#g[n]=d)},()=>{d<2&&(e.#e[u+b[68]]=d?127:0)},()=>{},()=>{d<2&&(e.#e[u+b[65]]=d?127:0)},()=>{e.#e[u+b[5]]=d&15<<4|e.#e[u+b[5]]&15},()=>{e.#e[u+b[5]]=d&15|(e.#e[u+b[5]]&240)>>4},()=>{e.#e[u+b[74]]=d},()=>{e.#e[u+b[71]]=d},()=>{e.#e[u+b[73]]=d},()=>{e.#e[u+b[72]]=d},0,0,0,0,0,0,0,()=>{e.#e[u+b[128]]=d,e.allocateAce(128)},()=>{e.#e[u+b[93]]=d},()=>{e.#e[u+b[91]]=d},0,0,()=>{e.#e[u+b[75]]=d},()=>{e.#e[u+b[76]]=d},()=>{e.#e[u+b[77]]=d},()=>{e.#e[u+b[78]]=d}][E]||(()=>{}))():E<63||(E<64?(e.#i[n]?e.#e[u+b[0]]=104|d:e.#e[u+b[0]]=96|d,e.dispatchEvent("voice",{part:n})):console.debug(`Unknown SD-90 global CH${n+1} param setup message: +%o`,a)}break}case 1:{let n=e.chRedir(s,i,!0),o=a[1],u=n*m.cc;a.subarray(2).forEach((f,y)=>{let E=o+y;E<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[u+b[0]]=f,f){case 104:case 105:case 106:case 107:case 120:{e.#i[n]||e.setChType(n,e.CH_DRUMS);break}default:e.#i[n]&&e.setChType(n,e.CH_MELODIC)}e.dispatchEvent("voice",{part:n})},()=>{e.#e[u+b[32]]=f,e.dispatchEvent("voice",{part:n})},()=>{e.#r[n]=f,e.dispatchEvent("voice",{part:n})},()=>{e.#e[u+b[7]]=f},()=>{e.#e[u+b[10]]=f},()=>{},()=>{},()=>{f<2&&(e.#g[n]=f)},()=>{f<2&&(e.#e[u+b[68]]=f?127:0)},()=>{},()=>{f<2&&(e.#e[u+b[65]]=f?127:0)},()=>{e.#e[u+b[5]]=f&15<<4|e.#e[u+b[5]]&15},()=>{e.#e[u+b[5]]=f&15|(e.#e[u+b[5]]&240)>>4},()=>{e.#e[u+b[74]]=f},()=>{e.#e[u+b[71]]=f},()=>{e.#e[u+b[73]]=f},()=>{e.#e[u+b[72]]=f},0,0,0,0,0,0,0,()=>{e.#e[u+b[128]]=f,e.allocateAce(128)},()=>{e.#e[u+b[93]]=f},()=>{e.#e[u+b[91]]=f},0,0,()=>{e.#e[u+b[75]]=f},()=>{e.#e[u+b[76]]=f},()=>{e.#e[u+b[77]]=f},()=>{e.#e[u+b[78]]=f}][E]||(()=>{}))():E<63||(E<64?(e.#i[n]?e.#e[u+b[0]]=104|f:e.#e[u+b[0]]=96|f,e.dispatchEvent("voice",{part:n})):console.debug(`Unknown SD-90 global CH${n+1} param setup message: %o`,a))});break}case 2:{let n=e.chRedir(s,i,!0),o=a[1];console.debug(`Unknown SD-90 global CH${n+1} MIDI setup message: %o`,a.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,a)}}),e.#K.add([0,1,73,78],(a,i,f)=>{e.switchMode("krs"),e.setPortMode(e.getTrackPort(i),1,$.krs),console.debug("Might be KORG KROSS 2 mode reset... Not sure.")}).add([0,1,73,117,2,37],(a,i,f)=>{e.switchMode("krs");let r=e.getTrackPort(i);if(e.#n[r]&&e.#n[r]!=$.krs)if(e.#H.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+r)} mode "${C[e.#n[r]]}" mismatch, should be "krs".`);return}else console.info(`Track ${i} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+r)}.`);e.setPortMode(e.getTrackPort(i),1,$.krs);let s="KROSS 2 BMT1 ",n="";A(a,(o,u)=>{if(u<24)n+=String.fromCharCode(Math.max(32,o));else if(!(u<1276)){let d=u-1276,y=e.chRedir(Math.floor(d/44),i,!0),E=d%44,w=m.cc*y;E<15?([()=>{o&&e.setChActive(y,1),e.#r[y]=o,e.dispatchEvent("voice",{part:y})},()=>{o&&e.setChActive(y,1),o<10?(e.#e[w+b[0]]=63,e.#e[w+b[32]]=o):o<20?(e.#e[w+b[0]]=121,e.#e[w+b[32]]=o-10):o<24&&(e.#e[w+b[0]]=[120,0,56,62][o-20],e.#e[w+b[32]]=0),e.dispatchEvent("voice",{part:y})},()=>{let x=e.chRedir(o&15,i,!0);e.#f[y]=x,console.info(`${s}CH${y+1} receives from CH${x+1}`),o>>5&1||(e.setChActive(y,0),console.debug(`KORG KROSS 2 CH${y+1} is disabled.`))},!1,!1,()=>{e.#e[w+b[7]]=o},!1,()=>{},()=>{},!1,!1,!1,!1,!1,()=>{e.#e[w+b[10]]=o||128}][E]||(()=>{}))():E<36||([()=>{e.#e[w+b[74]]=(o+128&255)-64},()=>{e.#e[w+b[71]]=(o+128&255)-64},!1,!1,()=>{e.#e[w+b[73]]=(o+128&255)-64},()=>{e.#e[w+b[75]]=(o+128&255)-64},!1,()=>{e.#e[w+b[72]]=(o+128&255)-64}][E]||(()=>{}))()}}),n=n.trimRight(),e.dispatchEvent("metacommit",{type:"EORTitle",data:n})})}};var le=et(Ne(),1);var Be=class{#t=!1;constructor(e,t,c,l){this.#t=e,this.start=t,this.end=c,this.data=l}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#t}},ce=class extends Be{constructor(e,t,c){super(!0,e,t,c)}},Xe=class extends Be{constructor(e,t){super(!1,e,e,t)}},oe=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 c=[];if(t)for(let l=0;le);l++){if(this[l].endh.#t&&(c.push(p),h.#t=p.index)})}return c}getRange(e,t){e>t&&([e,t]=[t,e]);let c=[],l=-1,h=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&&c.push(this[l]):p=!1,l++;return c}};var ut=0xffffffffffff,He=function(e){let t=new oe,c=this,l=e.timeDivision,h=120,p=new oe,g=0,v=0;p.push(new ce(0,ut,[120,0])),e.track.forEach(function(r){g=0,r.event.forEach(function(s){g+=s.deltaTime,s.type==255&&s?.metaType==81&&(h=6e7/s.data,p[p.length-1]&&p.push(new ce(g,0xffffffffffff,[h,0])))})}),p.fresh(),p.forEach(function(r,s,n){s>0&&(n[s-1].end=r.start)});let a=120;p.forEach(function(r,s,n){s>0&&(r.end==r.start?n.splice(n.indexOf(r),1):a==r.data[0]&&(n[s-1].end=r.end,n.splice(n.indexOf(r),1)),a=r.data[0])});let i=0,f=120;return p.forEach(function(r){let s=r.start,n=s/f/l*60+i;f=r.data[0],i=n-s/f/l*60,r.data[1]=i}),console.debug("All tempo changes: ",p),h=120,g=0,v=0,e.track.forEach(function(r,s){g=0,v=0;let n=s+1;r.event.forEach(function(o,u){g+=o.deltaTime;let d=p.step(g,!0)[0];d&&(h=d.data[0],v=d.data[1]);let y={type:o.type,data:o.data,track:n,part:0};o.type>14?y.meta=o.metaType:y.part=o.channel,t.push(new Xe(g/h/l*60+v,y))})}),t.fresh(),self.midiEvents=t,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),t};le.default.customInterpreter=Te;var S=function(e,t,c){e.addEventListener(c,l=>{t.dispatchEvent(c,l.data)})},Ve=class extends W{device;#t;#m={};#T=[];#d="";#E=[];#$=[];#f=new Uint8ClampedArray(128);#i=new Uint8ClampedArray(128);#e=.5;#b=120;#r=4;#h=4;#g=0;#u=0;smoothingAtk=0;smoothingDcy=0;reset(){let e=this;e.dispatchEvent("reset"),e.#t?.resetIndex(),e.device.init(),e.#d="",e.#e=.5,e.#b=120,e.#r=4,e.#h=4,e.#g=0,e.#u=0,e.dispatchEvent("tempo",e.#b),e.dispatchEvent("title",e.#d)}init(){this.reset(),this.#t=void 0}async loadFile(e){this.#t=He(le.default.parse(new Uint8Array(await e.arrayBuffer())))}async loadMap(e,t){let c=this,l=0,h=0,p=0,g,v;e.split(` -`).forEach((a,i)=>{if(!a)return;let f=a.split(" ");if(i){if(!p)return;let r="",s="";f.forEach((n,o)=>{switch(o){case g:{r=n;break}case v:{s=n;break}}}),!c.#m[r]||t?(c.#m[r]=s,l++):self.debugMode&&console.debug(`Voice "${s}" (${r}) seems to be in conflict with (${c.#m[r]}).`),h++}else f.forEach((r,s)=>{switch(r){case"ID":{g=s,p++;break}case"Name":{v=s,p++;break}default:console.debug(`Unknown map field: ${r}`)}})}),console.debug(`Voice names: ${h} total, ${l} loaded.`),c?.device.forceVoiceRefresh()}async loadEfx(e,t){let c=this,l=0,h=0,p,g,v;e.split(` -`).forEach((a,i)=>{if(a)if(i){let f=0,r;a.split(" ").forEach((s,n)=>{switch(n){case p:{f|=parseInt(s,16)<<8;break}case g:{f|=parseInt(s,16);break}case v:{r=s;break}}}),!c.#T[f]||t?(c.#T[f]=r,l++):self.debugMode&&console.debug(`EFX ID 0x${f.toString(16).padStart(4,"0")} (${r}) seems to be in conflict.`),h++}else a.split(" ").forEach((f,r)=>{switch(f){case"MSB":{p=r;break}case"LSB":{g=r;break}case"Name":{v=r;break}default:console.debug(`Unknown EFX field: ${f}`)}})}),console.debug(`EFX: ${h} total, ${l} loaded.`),c.dispatchEvent("efxreverb",c.device.getEffectType(0)),c.dispatchEvent("efxchorus",c.device.getEffectType(1)),c.dispatchEvent("efxdelay",c.device.getEffectType(2)),c.dispatchEvent("efxinsert0",c.device.getEffectType(3)),c.dispatchEvent("efxinsert1",c.device.getEffectType(4)),c.dispatchEvent("efxinsert2",c.device.getEffectType(5)),c.dispatchEvent("efxinsert3",c.device.getEffectType(6))}switchMode(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.#m[e]||e}getEfx([e,t]){let c=e<<8|t;return this.#T[c]||`0x${c.toString(16).padStart(4,"0")}`}get noteProgress(){return this.#u/this.#e}get noteOverall(){return this.noteProgress-this.#g}get noteBar(){return Math.floor(this.noteOverall/this.#r)}get noteBeat(){let e=this.noteOverall%this.#r;return e<0&&(e+=this.#r),e}getTimeSig(){return[this.#r,this.#h]}getTempo(){return this.#b}sendCmd(e){this.device.runJson(e)}render(e){e>this.#u&&(this.#u=e);let t=this.#t?.step(e)||[],c=0,l=new Set,h={},p=[],g=this,v=[];for(g.device.getStrength().forEach((E,w)=>{g.#i[w]=E}),g.device.newStrength(),t.forEach(function(E){let w=E.data,x=g.device.runJson(w);switch(x?.reply){case"meta":{v.push(x);break}}x?.reply&&delete x.reply});g.#$.length>0;){let E=g.#$.shift(),w=E.part<<7|E.note;E.state?(l.add(w),h[w]=E.velo):l.has(w)&&(p.push({part:E.part,note:E.note,velo:h[w],state:g.device.NOTE_SUSTAIN}),c++)}v?.length>0&&g.dispatchEvent("meta",v);let a=g.device.getActive(),i=[],f=g.device.getPitch(),r=g.device.getCcAll(),s=g.device.getProgram(),n=g.device.getChType(),o=[],u=g.device.getStrength();u.forEach(function(E,w,x){x[w]=Math.max(g.#i[w],E);let M=x[w]-g.#f[w],B=b.length*w;if(M>=0){let Z=4*.25**(r[B+b[73]]/64);g.#f[w]+=Math.ceil(M-M*g.smoothingAtk**Z)}else{let Z=4*.25**(r[B+b[72]]/64);g.#f[w]+=Math.floor(M-M*g.smoothingDcy**Z)}});let d=0;return a.forEach(function(E,w){E&&(i[w]=g.device.getVel(w),o[w]=g.device.getExt(w),d+=i[w].size)}),{extraPoly:c,extraNotes:p,curPoly:d,chInUse:a,chKeyPr:i,chPitch:f,chProgr:s,chContr:r,chType:n,chExt:o,eventCount:t.length,title:g.#d,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:u,rpn:g.device.getRpn(),tSig:g.getTimeSig(),tempo:g.getTempo(),noteBar:g.noteBar,noteBeat:g.noteBeat,ace:g.device.getAce(),rawVelo:g.device.getStrength(),rawStrength:g.device.getRawStrength(),rawPitch:g.device.getRawPitch(),efxSink:g.device.getEffectSink()}}constructor(e,t=.5,c=.5){super();let l=this;l.smoothingAtk=t,l.smoothingDcy=c,l.device=e,l.addEventListener("meta",function(h){h?.data?.forEach(function(p){(l.#E[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,"portrange"),S(l.device,l,"portstart"),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,"banklevel"),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:h}){l.#$.push(h)}),l.#E[3]=function(h,p){l.#d?.length<1&&(l.#d=p,l.dispatchEvent("title",l.#d))},l.#E[81]=function(h,p){let g=l.noteProgress,v=l.#e||.5;l.#b=6e7/p,l.#e=p/1e6,l.#g+=g*(v/l.#e)-g,l.dispatchEvent("tempo",l.#b)},l.#E[88]=function(h,p){let g=l.noteProgress,v=l.noteOverall,a=l.noteBar,i=l.noteBeat,f=l.#r,r=l.#h;l.#r=p[0],l.#h=1<=f&&(f{fe&&(de[q]=!de[q],q++,q>34&&(q=0))},1e3/50);Uint8Array.prototype.render=function(e){let t=0,c=0,l=this.width||5,h=this.height||8;for(let p=0;p=l&&(t=0,c++)};var Ge=class{#t=[];async load(e,t=!1,c="(internal)"){let l=this,h=0,p=0;console.debug(`Font "${c||"(internal)"}": loading started.`),e.split(` -`).forEach(function(g,v){if(v>0&&g?.length>0){let a=g.split(" "),i=parseInt(a[0],16);if(p++,l.#t[i]&&!t)return;let f=new Uint8Array(40);Array.from(a[1]).forEach(async function(r,s){let n=s%2?4:0,o=Math.floor(s/2),u=parseInt(r,16),d=3;for(;u>0||d>=0;){let y=(n+d)*5+o;f[y]=u&1,u=u>>1,d--}}),l.#t[i]=f,h++}}),console.debug(`Font "${c||"(internal)"}": ${p} total, ${h} loaded.`)}async loadFile(e,t=!1){let c=this;console.debug(`Requested font file from "${e}".`),await c.load(await(await fetch(e)).text(),t,e),fe=!1}constructor(...e){fe=!0,(async()=>{for(let t=0;t{l.classList.add(f)});let{t:h,l:p,w:g,h:v,i:a,a:i}=c;return h?.constructor&&(l.style.top=h?.length?h:`${h}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)),i?.constructor&&(l.style.textAlign=i),l};var R=function(e,t){t?.forEach(c=>{e.appendChild(c)})},L=function(e,t){t.forEach(c=>{e.classList.contains(c)&&e.classList.remove(c)})},U=function(e,t){t.forEach(c=>{e.classList.contains(c)||e.classList.add(c)})},wt=new Array(128).fill(0);wt.forEach((e,t,c)=>{c[t]=Math.floor(24*t/12.7)/10});var $t=new Array(128).fill(0);$t.forEach((e,t,c)=>{c[t]=Math.abs(Math.round(48*(t-64)/12.7)/10)});var ze=new Array(11).fill(null);ze.forEach((e,t,c)=>{c[t]=`${Math.round(t*12/.0128)/100}%`});var kt=new Array(128).fill(null);kt.forEach((e,t,c)=>{c[t]=`${Math.round(t/1.27)/100}`});var Ke=function(e,t){e.innerText=t,e.rNew=!0;let c=e.measureText(t);e.rWidth=c.width},ya=class extends Ve{#t=128;#m=!1;#T="";#d;#E=0;#$=0;#f=0;#i=0;#e=m.invalidCh;#b=1;#r=0;#h=0;#g=new Uint8Array(1280);#u=new Uint8Array(1280);#k=new Uint8Array(1280);#L=new Uint8Array(512);#I=new Uint8Array(512);#U=new Uint8Array(512);#M=new Uint8Array(m.ch);#s;#o;#X;#l;#P;#S="fcdaff";#a={};#R={};#n=[];#y={};#w={};eventViewMode=0;#z=[];#O="comb";glyphs=new Ge;#A(e,t,c,l=0,h=0){let p=this,{width:g,height:v}=e.canvas,a,i,f,r,s=p.#b,n=l>3,o=bt.indexOf(t%12)>-1;switch(p.#O){case"block":case"comb":{a=Math.round(t*g/128),i=Math.round((t+1)*g/128),f=i-a,r=s==1?2:1;break}case"piano":{a=Math.round((Math.floor(t/12)*7+_e[t%12])*g/75*1.0044642857142856),i=Math.round((Math.floor(t/12)*7+_e[t%12]+1)*g/75*1.0044642857142856)-1,f=i-a,r=s==1?3:1;break}case"line":{let u=t-h;Math.abs(h)>2&&(u=t-Math.sign(h)*2),i=Math.round((t+.5)*g/128),a=Math.round((u+.5)*g/128)}default:}switch(e.fillStyle=`#${o?p.#S:"ffffff"}${(c<<1|c>>6).toString(16).padStart(2,"0")}`,e.strokeStyle=e.fillStyle,e.lineWidth=s==1?4:2,e.lineDashOffset=0,p.#O){case"block":{let u=e.canvas.height-1;e.fillRect(a,1,f,u),n&&e.clearRect(a+r,r+1,f-(r<<1),u-(r<<1));break}case"comb":{let u=(o?Math.round((e.canvas.height<<1)/3):e.canvas.height)-1;e.fillRect(a,1,f,u),n&&e.clearRect(a+r,r+1,f-(r<<1),u-(r<<1));break}case"piano":{let u=(o?0:e.canvas.height>>1)+1,d=(e.canvas.height>>1)-1;e.fillRect(a,u,f,d),n&&e.clearRect(a+r,u+r,f-(r<<1),d-(r<<1));break}case"line":{if(n)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,i+=.5);e.beginPath(),e.moveTo(a,(s==4||!n)&&self?.document?.mozFullScreen?2:1),e.lineTo(i,(v>>1)+1),e.lineTo(a,v),e.stroke();break}default:}}#q(e,t){let c=this;(e?.chInUse||t).forEach((l,h)=>{if(l){let p=c.#n[h>>4][h&15].cxt;p.clearRect(0,0,p.canvas.width,p.canvas.height),e.chKeyPr[h].forEach(({v:g,s:v},a)=>{c.#A(p,a,g,v,c.device.getPitchShift(h))})}})}#F(e){let t=this;Date.now()-t.#E>4e3&&(t.#$=0,t.#f=142-t.#y.view.clientHeight,(t.#d?.clientWidth||0)>840&&(t.#$=840-t.#d.clientWidth),t.#y.view.style.transform=`translateX(${t.#$}px) translateY(${t.#f}px)`,e&&(t.#E=0))}#x(){let e=self.innerWidth/self.innerHeight,t=1,c=self.innerWidth,l=self.innerHeight;e>=Q?(t=Math.min(Math.round(self.innerHeight/1080*1e4)/1e4,100),c=Math.ceil(self.innerHeight*Q)):e>4,s=f*m.cc,n=e.#n[r][f&15];if(c.chInUse[f]&&r>=e.#r&&r0){let x=24-w;n.ccVis.fillRect(d*6,x,4,w)}}}let o=c.chContr[s+b[10]]||1,u=Math.abs(o-64)/2.625;if(o<64?n.ccVis.fillRect(84-u,0,u,24):o>127?(n.ccVis.fillRect(60,0,49,24),n.ccVis.clearRect(61,1,47,22)):n.ccVis.fillRect(85,0,u,24),n.ccVis.fillStyle="#fff",n.ccVis.fillRect(84,0,1,24),n.metre.clearRect(0,0,121,25),n.metre.globalCompositeOperation="source-over",n.metre.rWidth>n.metre.canvas.width){n.metre.rNew&&(n.metre.rNew=!1,n.metre.rOffset=t);let d=t-(n.metre.rOffset||0),y=32,E=n.metre.rWidth-n.metre.canvas.width+y,w=d*-25%(n.metre.rWidth+y+48)+48;w>0&&(w=0),n.metre.fillText(n.metre.innerText,w,3+e.#P.font4[0]),Math.abs(w)>E&&n.metre.fillText(n.metre.innerText,w+n.metre.rWidth+y,3+e.#P.font4[0])}else n.metre.fillText(n.metre.innerText,0,3+e.#P.font4[0]);switch(n.metre.globalCompositeOperation="xor",n.metre.fillRect(0,0,c.strength[f]*121/255,25),n.extVis.clearRect(0,0,47,25),n.extVis.fillStyle="#fff",c.chExt[f][0]){case e.device.EXT_VL:{let d=(c.chContr[s+b[136]]-64)/64||c.rawPitch[f]/8192;d=d*-4+4;let y=+!!c.rawVelo[f]*(c.chContr[s+b[129]]*c.chContr[s+b[11]]/16129);!y&&c.rawStrength[f]&&(y=c.rawStrength[f]*c.chContr[s+b[11]]/16129),y*=32;let E=c.chContr[s+b[1]]/127*8;n.extVis.beginPath(),n.extVis.moveTo(0,12-d-3),n.extVis.lineTo(7+y,12),n.extVis.lineTo(0,12+d+3),n.extVis.fill(),n.extVis.fillStyle=`#${e.#S}`,n.extVis.beginPath(),n.extVis.ellipse(43,12,4,4+E,0,0,mt),n.extVis.fill();break}case e.device.EXT_DX:{c.chContr.subarray(s+b[142],s+b[157]+1).forEach((y,E)=>{E>=8&&(n.extVis.fillStyle=`#${e.#S}`);let w=E*3,x=(y-64)/5.82;x>=0?n.extVis.fillRect(w,12-x,2,x+1):n.extVis.fillRect(w,12,2,1-x)});break}}}}let v=new Array(m.ch);if(e.#n.forEach((f,r)=>{f.forEach((s,n)=>{s.refresh&&(s.refresh=!1,v[r<<7|n]=!0)})}),["line"].indexOf(e.#O)>-1)for(;e.#z.length>0;){let f=e.#z.shift();v[f.part]=!0}e.#q(c,v),c.extraNotes.forEach(f=>{let{part:r,note:s,velo:n,state:o}=f,u=e.#n[r>>4][r&15].cxt;e.#A(u,s,n,o,e.device.getPitchShift(r))});let a=e.#w.cxt;l>c.bitmap.expire?e.#U.fill(0):c.bitmap.bitmap.length>256?c.bitmap.bitmap.forEach((f,r)=>{e.#U[r]=f?255:0}):c.bitmap.bitmap.forEach((f,r)=>{e.#U[r<<1]=f?255:0,e.#U[r<<1|1]=f?255:0}),e.#k.fill(0),l<=c.letter.expire&&e.glyphs.getStr(c.letter.text).forEach((f,r)=>{let s=(r&15)*5,n=r>>4<<3;f.forEach((o,u)=>{let d=s+u%5,y=n+Math.floor(u/5);e.#k[y*80+d]=o?255:0})}),e.#L.forEach((f,r,s)=>{let n=e.#U[r];n>f?s[r]+=Math.min(n-f,j):n{let n=e.#k[r];n>f?s[r]+=Math.min(n-f,j):n{let s=r>>5,n=r&31;e.#I[r]!=f?(a.clearRect(252+(n<<2),s<<2,3,3),f&&(a.fillStyle=`#ffffff${f.toString(16).padStart(2,"0")}`,a.fillRect(252+(n<<2),s<<2,3,3))):self.debugMode&&(a.clearRect(252+(n<<2),s<<2,3,3),f&&(a.fillStyle=`#ff0000${f.toString(16).padStart(2,"0")}`,a.fillRect(252+(n<<2),s<<2,3,3)))}),e.#g.forEach((f,r)=>{let s=Math.floor(r/80),n=r%80;n+=Math.floor(n/5),e.#u[r]!=f?(a.clearRect(n<<2,(s|16)<<2,3,3),f&&(a.fillStyle=`#ffffff${f.toString(16).padStart(2,"0")}`,a.fillRect(n<<2,(s|16)<<2,3,3))):self.debugMode&&(a.clearRect(n<<2,(s|16)<<2,3,3),f&&(a.fillStyle=`#ff0000${f.toString(16).padStart(2,"0")}`,a.fillRect(n<<2,(s|16)<<2,3,3)))}),e.#I.forEach((f,r,s)=>{s[r]=e.#L[r]}),e.#u.forEach((f,r,s)=>{s[r]=e.#g[r]});let i=(self.performance||self.Date).now();switch(e.eventViewMode){case 0:{e.#a.events.innerText=`${c.eventCount}`.padStart(3,"0");break}case 1:{let f=1e3/(i-e.#h);f>99?(f=Math.round(f),e.#a.events.innerText=`${f}`):f>9?(f=Math.round(f*10)/10,e.#a.events.innerText=`${Math.floor(f)}.${Math.floor(f*10%10)}`):(f=Math.round(f*100)/100,e.#a.events.innerText=`${Math.floor(f)}.${Math.floor(f*100%100)}`);break}default:e.#a.events.innerText=""}e.#h=i}#Y;#p;get style(){return this.#O}set style(e){let t=this;t.#O=e,t.#q(t.render(t.#s?.currentTime||0)),L(t.#l,["cambiare-style-block","cambiare-style-comb","cambiare-style-piano","cambiare-style-line"]),U(t.#l,[`cambiare-style-${e}`])}setClockSource(e){this.#s=e}setPixelProfile(e){let t=this;if(Fe[e]){let c=Fe[e];t.#P=c,t.#l&&(t.#l.style.setProperty("--pcp-font4",`translate(${c.font4[1]}px, ${c.font4[0]}px)`),t.#l.style.setProperty("--pcp-font7",`translate(${c.font7[1]}px, ${c.font7[0]}px)`))}else throw new Error(`"${e}" is not a valid pixel correction profile`)}setMode(e){let t=this;L(t.#l,["cambiare-mode-gm","cambiare-mode-xg","cambiare-mode-gs","cambiare-mode-sc","cambiare-mode-ns5r","cambiare-mode-05rw","cambiare-mode-x5d","cambiare-mode-k11","cambiare-mode-sg","cambiare-mode-g2","cambiare-mode-mt32","cambiare-mode-doc","cambiare-mode-qy10","cambiare-mode-qy20","cambiare-mode-sd","cambiare-mode-krs","cambiare-mode-s90es","cambiare-mode-motif"]),e!="?"&&U(t.#l,[`cambiare-mode-${e}`]),t.#S={xg:"9efaa0",doc:"9efaa0",qy10:"9efaa0",qy20:"9efaa0",ns5r:"9efaa0",x5d:"9efaa0","05rw":"9efaa0",k11:"9efaa0",s90es:"9efaa0",motif:"9efaa0",gm:"a1f3ff",g2:"a1f3ff",krs:"a1f3ff",gs:"ffe1a5",sc:"ffe1a5",mt32:"ffe1a5",sd:"ffe1a5",sg:"ffdddd"}[e]||"fcdaff"}#G(e){let t=this,c=t.#b,l=t.#r;t.#n.forEach((h,p)=>{if(p>=l&&p{i.root.style.top=`${f*(c>2?26:52)}px`})}else L(h.root,["port-active"]),h.root.style.top="",h.root.style.left="",h.forEach((g,v)=>{g.root.style.top=""});e&&h.forEach((g,v)=>{g.cxt.canvas.width=t.#b==1?1193:495,g.cxt.canvas.height=t.#b==4?26:52})})}setPort(e){let t=this;L(t.#l,["cambiare-start0","cambiare-start1","cambiare-start2","cambiare-start3","cambiare-start4","cambiare-start5","cambiare-start6","cambiare-start7"]),U(t.#l,[`cambiare-start${e}`]),t.#r=e,t.#G(!1)}setRange(e){let t=this;L(t.#l,["cambiare-port1","cambiare-port2","cambiare-port4","cambiare-compact"]),U(t.#l,[`cambiare-${e}`]),t.#b=parseInt(e.slice(4))||1,t.#G(!0)}attach(e){let t=this;t.#o=e;let c=k("div",["cambiare-container"]);e.appendChild(c),t.#X=c;let l=k("div",["cambiare-canvas","cambiare-port1","cambiare-start0","cambiare-style-block"]);c.appendChild(l),t.#l=l,self.addEventListener("resize",t.#c),t.#c(),t.#p=setInterval(t.#Y,20),t.#a.root=k("div",["sect-info"]),t.#a.events=k("span",["field","pcp-font4"],{t:1,l:0,w:35,h:33}),t.#a.curPoly=k("span",["field","pcp-font4"],{t:1,l:52,w:35,h:33}),t.#a.maxPoly=k("span",["field","pcp-font4"],{t:1,l:98,w:35,h:33}),t.#a.sigN=k("span",["field","pcp-font4"],{t:1,l:194,w:23,h:33,a:"right"}),t.#a.sigD=k("span",["field","pcp-font4"],{t:1,l:232,w:23,h:33}),t.#a.barCount=k("span",["field","pcp-font4"],{t:1,l:304,w:35,h:33,a:"right"}),t.#a.barDelim=k("span",["field","field-label","pcp-font4"],{t:0,l:343,w:8,h:33,i:"/"}),t.#a.barNote=k("span",["field","pcp-font4"],{t:1,l:354,w:23,h:33}),t.#a.tempo=k("span",["field","pcp-font4"],{t:1,l:454,w:64,h:33,a:"right"}),t.#a.volume=k("span",["field","pcp-font4"],{t:1,l:562,w:63,h:33,a:"right"}),t.#a.mode=k("span",["field","pcp-font4"],{t:1,l:708,w:152,h:33}),t.#a.reverb=k("span",["field","pcp-font4"],{t:1,l:1e3,w:190,h:33}),t.#a.chorus=k("span",["field","pcp-font4"],{t:1,l:1240,w:190,h:33}),t.#a.delay=k("span",["field","pcp-font4"],{t:1,l:1475,w:190,h:33}),t.#a.insert=k("span",["field","pcp-font4"],{t:1,l:1706,w:190,h:33}),t.#a.title=k("span",["field","pcp-font4"],{t:35,l:50,w:810,h:33}),l.appendChild(t.#a.root),R(t.#a.root,[t.#a.events,t.#a.curPoly,k("span",["field","field-label","pcp-font4"],{t:1,l:89,w:5,h:33,i:":"}),t.#a.maxPoly,k("span",["field","field-key","pcp-font7"],{t:1,l:148,w:41,h:33,i:"TSig"}),t.#a.sigN,k("span",["field","field-label","pcp-font4"],{t:0,l:221,w:8,h:33,i:"/"}),t.#a.sigD,k("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,k("span",["field","field-key","pcp-font7"],{t:1,l:390,w:61,h:33,i:"Tempo",a:"right"}),t.#a.tempo,k("span",["field","field-key","pcp-font7"],{t:1,l:528,w:29,h:33,i:"Vol"}),t.#a.volume,k("span",["field","field-label","pcp-font4"],{t:1,l:626,w:17,h:33,i:"%"}),k("span",["field","field-key","pcp-font7"],{t:1,l:652,w:52,h:33,i:"Mode"}),t.#a.mode,k("span",["field","field-key","pcp-font7"],{t:1,l:960,w:34,h:33,i:"Rev"}),t.#a.reverb,k("span",["field","field-key","pcp-font7"],{t:1,l:1198,w:36,h:33,i:"Cho"}),t.#a.chorus,k("span",["field","field-key","pcp-font7"],{t:1,l:1438,w:31,h:33,i:"Var"}),t.#a.delay,k("span",["field","field-key","pcp-font7"],{t:1,l:1673,w:27,h:33,i:"Ins"}),t.#a.insert,k("span",["field","field-key","pcp-font7"],{t:35,l:0,w:44,h:33,i:"Title"}),t.#a.title]),t.#R.root=k("div",["sect-mark"]),t.#R.left=k("div",["sect-mark-left","boundary"],{t:0,l:0}),t.#R.right=k("div",["sect-mark-right","boundary"],{t:0,l:960}),l.appendChild(t.#R.root),R(t.#R.root,[t.#R.left,t.#R.right]),R(t.#R.left,[k("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),k("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),k("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),k("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),k("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),k("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),R(t.#R.right,[k("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),k("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),k("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),k("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),k("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),k("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),t.#n.root=k("div",["sect-part"]);for(let h=0;h>4;h++){let p=h<<4;t.#n[h]=[],t.#n[h].root=k("div",["boundary",`part-port-${h}`]);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.#n[h][g]={root:k("div",["boundary","part-channel"]),major:k("div",["boundary","part-info-major"]),minor:k("div",["boundary","part-info-minor"],{t:26}),keys:k("div",["boundary","part-keys"]),notes:k("div",["boundary","part-keyboard"]),cxt:k("canvas",["field"]).getContext("2d"),number:k("span",["field","field-label","pcp-font4"],{t:1,w:18,h:25,i:v}),voice:k("span",["field"],{l:22,t:1,w:121,h:25}),metre:k("canvas",["field"]).getContext("2d"),type:k("span",["field","field-label","pcp-font4"],{t:1,w:18,h:25}),std:k("span",["field","pcp-font4"],{l:22,t:1,w:20,h:25,a:"center"}),msb:k("span",["field","pcp-font4"],{l:48,t:1,w:27,h:25}),prg:k("span",["field","pcp-font4"],{l:81,t:1,w:27,h:25}),lsb:k("span",["field","pcp-font4"],{l:114,t:1,w:27,h:25}),ccVis:k("canvas",["field"],{l:145,t:1}).getContext("2d"),extVis:k("canvas",["field"],{l:207,t:1}).getContext("2d"),ccUpdate:!1};let a=t.#n[h][g];ze.forEach(i=>{a.notes.appendChild(k("span",["field","part-csplit"],{l:i}))}),a.notes.appendChild(k("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.ccVis.canvas.width=109,a.ccVis.canvas.height=25,a.ccVis.fillStyle="#fff",a.extVis.canvas.width=47,a.extVis.canvas.height=25,a.extVis.fillStyle="#fff",R(a.notes,[a.cxt.canvas]),R(a.keys,[a.notes]),R(a.voice,[a.metre.canvas]),R(a.major,[a.number,a.voice,a.ccVis.canvas]),R(a.minor,[a.type,a.std,a.msb,a.prg,a.lsb,a.extVis.canvas]),R(a.root,[a.major,a.minor,a.keys]),R(t.#n[h].root,[a.root]),a.number.addEventListener("contextmenu",i=>{i.preventDefault(),i.stopImmediatePropagation();let f=h<<4|g;t.#M[f]=+!t.#M[f],[L,U][t.#M[f]](a.root,["part-hidden"])})}t.#n.root.appendChild(t.#n[h].root)}l.appendChild(t.#n.root),t.#y.root=k("div",["sect-meta"]),t.#y.view=k("div",["boundary"]),l.appendChild(t.#y.root),R(t.#y.root,[t.#y.view]),t.#w.root=k("div",["sect-pix","boundary"],{l:1529,t:950,w:379,h:127}),t.#w.cxt=k("canvas",["field"]).getContext("2d"),t.#w.fps=k("span",["field","field-key"],{l:0,w:"100%",h:1}),t.#w.cxt.canvas.width=379,t.#w.cxt.canvas.height=127,R(t.#w.root,[t.#w.cxt.canvas]),l.appendChild(t.#w.root),t.addEventListener("mode",h=>{t.#a.mode.innerText=`${gt[h.data]}`,t.setMode(h.data)}),t.addEventListener("mastervolume",h=>{let p=Math.round(h.data*100)/100;t.#a.volume.innerText=`${Math.floor(p)}.${`${Math.floor(p%1*100)}`.padStart(2,"0")}`}),t.addEventListener("tempo",h=>{let p=Math.round(h.data*100);t.#a.tempo.innerText=`${Math.floor(p/100)}.${`${Math.floor(p%100)}`.padStart(2,"0")}`}),t.addEventListener("tsig",h=>{[t.#a.sigN.innerText,t.#a.sigD.innerText]=h.data}),t.addEventListener("title",h=>{t.#a.title.innerText=h.data||"No Title"}),t.addEventListener("voice",({data:h})=>{let p=t.getChVoice(h.part),g=t.#n[h.part>>4][h.part&15];Ke(g.metre,t.getMapped(p.name)),g.type.innerText=pt[t.device.getChType()[h.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",h=>{let{part:p,pitch:g}=h.data;t.#n[p>>4][p&15].notes.style.transform=`translateX(${g/1.28}%)`}),t.addEventListener("efxreverb",h=>{t.#a.reverb.innerText=t.getEfx(h.data)}),t.addEventListener("efxchorus",h=>{t.#a.chorus.innerText=t.getEfx(h.data)}),t.addEventListener("efxdelay",h=>{t.#a.delay.innerText=t.getEfx(h.data)}),t.addEventListener("efxinsert0",h=>{t.#a.insert.innerText=t.getEfx(h.data)}),t.addEventListener("partefxtoggle",h=>{let{part:p,active:g}=h.data;[L,U][g](t.#n[p>>4][p&15].number,["part-efx"])}),t.addEventListener("channeltoggle",h=>{let{part:p,active:g}=h.data;[L,U][g](t.#n[p>>4][p&15].root,["part-active"])}),t.addEventListener("channelactive",h=>{if(t.#e>4][t.#e&15].number;L(g,["part-focus"])}let p=h.data;if(p>4][p&15].number;U(g,["part-focus"]),t.#e=p}}),t.addEventListener("metacommit",h=>{let p=h.data;if(t.#m&&p.type==t.#T&&t.#d)switch(p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{R(t.#d,[k("span",["meta-slice"],{i:p.data})]);break}default:t.#d.childNodes[0].data+=p.data}else if(p.data?.length&&vt.indexOf(p.type)==-1){let g=k("div",["meta-line"]),v=k("span",["field","field-key","meta-type"],{i:yt[p.type]||p.type});switch(p.mask&&(v.style.display="none"),p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{t.#d=k("span",["field","meta-data"]),R(t.#d,[k("span",["meta-slice"],{i:p.data})]);break}default:t.#d=k("span",["field","meta-data"],{i:p.data})}for(t.#y.view.appendChild(g),R(g,[v,t.#d]);t.#y.view.children.length>t.#t;)t.#y.view.children[0].remove()}t.#m=p.amend||!1,t.#T=p.type||"",t.#F()}),t.#y.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.#c),t.#l.remove(),t.#l=void 0,t.#X.remove(),t.#X=void 0,t.#o=void 0,clearInterval(t.#p)}constructor(e,t){super(new Ue,.1,.75);let c=this;c.#c=c.#x.bind(this),c.#Y=c.#H.bind(this),e&&c.attach(e),t&&c.setClockSource(t),c.setPixelProfile("none"),c.addEventListener("reset",()=>{c.#i=0,c.#m=!1,c.#T="",c.#d=null,c.#e=m.invalidCh;try{let l=c.#y.view.children;for(let h=l.length-1;h>=0;h--)l[h].remove();c.#y.view.style.transform="translateX(0px) translateY(140px)";for(let h=0;h>4][h&15];L(p.root,["part-active"]),L(p.number,["part-efx","part-focus"]),Ke(p.metre,""),p.type.innerText="",p.std.innerText="",p.msb.innerText="",p.prg.innerText="",p.lsb.innerText="",p.notes.style.transform="",p.ccUpdate=!0}}catch{}}),c.addEventListener("pitch",({data:l})=>{c.#z.push(l)})}};export{ya as Cambiare}; +%o`,a)}}),e.#K.add([0,1,73,78],(a,i,d)=>{e.switchMode("krs"),e.setPortMode(e.getTrackPort(i),1,$.krs),console.debug("Might be KORG KROSS 2 mode reset... Not sure.")}).add([0,1,73,117,2,37],(a,i,d)=>{e.switchMode("krs");let r=e.getTrackPort(i);if(e.#n[r]&&e.#n[r]!=$.krs)if(e.#H.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+r)} mode "${C[e.#n[r]]}" mismatch, should be "krs".`);return}else console.info(`Track ${i} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+r)}.`);e.setPortMode(e.getTrackPort(i),1,$.krs);let s="KROSS 2 BMT1 ",n="";A(a,(o,u)=>{if(u<24)n+=String.fromCharCode(Math.max(32,o));else if(!(u<1276)){let f=u-1276,y=e.chRedir(Math.floor(f/44),i,!0),E=f%44,w=m.cc*y;E<15?([()=>{o&&e.setChActive(y,1),e.#r[y]=o,e.dispatchEvent("voice",{part:y})},()=>{o&&e.setChActive(y,1),o<10?(e.#e[w+b[0]]=63,e.#e[w+b[32]]=o):o<20?(e.#e[w+b[0]]=121,e.#e[w+b[32]]=o-10):o<24&&(e.#e[w+b[0]]=[120,0,56,62][o-20],e.#e[w+b[32]]=0),e.dispatchEvent("voice",{part:y})},()=>{let x=e.chRedir(o&15,i,!0);e.#f[y]=x,console.info(`${s}CH${y+1} receives from CH${x+1}`),o>>5&1||(e.setChActive(y,0),console.debug(`KORG KROSS 2 CH${y+1} is disabled.`))},!1,!1,()=>{e.#e[w+b[7]]=o},!1,()=>{},()=>{},!1,!1,!1,!1,!1,()=>{e.#e[w+b[10]]=o||128}][E]||(()=>{}))():E<36||([()=>{e.#e[w+b[74]]=(o+128&255)-64},()=>{e.#e[w+b[71]]=(o+128&255)-64},!1,!1,()=>{e.#e[w+b[73]]=(o+128&255)-64},()=>{e.#e[w+b[75]]=(o+128&255)-64},!1,()=>{e.#e[w+b[72]]=(o+128&255)-64}][E]||(()=>{}))()}}),n=n.trimRight(),e.dispatchEvent("metacommit",{type:"EORTitle",data:n})})}};var le=et(Ne(),1);var Be=class{#t=!1;constructor(e,t,c,l){this.#t=e,this.start=t,this.end=c,this.data=l}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#t}},ce=class extends Be{constructor(e,t,c){super(!0,e,t,c)}},Xe=class extends Be{constructor(e,t){super(!1,e,e,t)}},oe=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 c=[];if(t)for(let l=0;le);l++){if(this[l].endh.#t&&(c.push(p),h.#t=p.index)})}return c}getRange(e,t){e>t&&([e,t]=[t,e]);let c=[],l=-1,h=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&&c.push(this[l]):p=!1,l++;return c}};var ut=0xffffffffffff,He=function(e){let t=new oe,c=this,l=e.timeDivision,h=120,p=new oe,g=0,v=0;p.push(new ce(0,ut,[120,0])),e.track.forEach(function(r){g=0,r.event.forEach(function(s){g+=s.deltaTime,s.type==255&&s?.metaType==81&&(h=6e7/s.data,p[p.length-1]&&p.push(new ce(g,0xffffffffffff,[h,0])))})}),p.fresh(),p.forEach(function(r,s,n){s>0&&(n[s-1].end=r.start)});let a=120;p.forEach(function(r,s,n){s>0&&(r.end==r.start?n.splice(n.indexOf(r),1):a==r.data[0]&&(n[s-1].end=r.end,n.splice(n.indexOf(r),1)),a=r.data[0])});let i=0,d=120;return p.forEach(function(r){let s=r.start,n=s/d/l*60+i;d=r.data[0],i=n-s/d/l*60,r.data[1]=i}),console.debug("All tempo changes: ",p),h=120,g=0,v=0,e.track.forEach(function(r,s){g=0,v=0;let n=s+1;r.event.forEach(function(o,u){g+=o.deltaTime;let f=p.step(g,!0)[0];f&&(h=f.data[0],v=f.data[1]);let y={type:o.type,data:o.data,track:n,part:0};o.type>14?y.meta=o.metaType:y.part=o.channel,t.push(new Xe(g/h/l*60+v,y))})}),t.fresh(),self.midiEvents=t,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),t};le.default.customInterpreter=Te;var S=function(e,t,c){e.addEventListener(c,l=>{t.dispatchEvent(c,l.data)})},Ve=class extends W{device;#t;#m={};#T=[];#d="";#E=[];#$=[];#f=new Uint8ClampedArray(128);#i=new Uint8ClampedArray(128);#e=.5;#b=120;#r=4;#h=4;#g=0;#u=0;smoothingAtk=0;smoothingDcy=0;reset(){let e=this;e.dispatchEvent("reset"),e.#t?.resetIndex(),e.device.init(),e.#d="",e.#e=.5,e.#b=120,e.#r=4,e.#h=4,e.#g=0,e.#u=0,e.dispatchEvent("tempo",e.#b),e.dispatchEvent("title",e.#d)}init(){this.reset(),this.#t=void 0}async loadFile(e){this.#t=He(le.default.parse(new Uint8Array(await e.arrayBuffer())))}async loadMap(e,t){let c=this,l=0,h=0,p=0,g,v;e.split(` +`).forEach((a,i)=>{if(!a)return;let d=a.split(" ");if(i){if(!p)return;let r="",s="";d.forEach((n,o)=>{switch(o){case g:{r=n;break}case v:{s=n;break}}}),!c.#m[r]||t?(c.#m[r]=s,l++):self.debugMode&&console.debug(`Voice "${s}" (${r}) seems to be in conflict with (${c.#m[r]}).`),h++}else d.forEach((r,s)=>{switch(r){case"ID":{g=s,p++;break}case"Name":{v=s,p++;break}default:console.debug(`Unknown map field: ${r}`)}})}),console.debug(`Voice names: ${h} total, ${l} loaded.`),c?.device.forceVoiceRefresh()}async loadEfx(e,t){let c=this,l=0,h=0,p,g,v;e.split(` +`).forEach((a,i)=>{if(a)if(i){let d=0,r;a.split(" ").forEach((s,n)=>{switch(n){case p:{d|=parseInt(s,16)<<8;break}case g:{d|=parseInt(s,16);break}case v:{r=s;break}}}),!c.#T[d]||t?(c.#T[d]=r,l++):self.debugMode&&console.debug(`EFX ID 0x${d.toString(16).padStart(4,"0")} (${r}) seems to be in conflict.`),h++}else a.split(" ").forEach((d,r)=>{switch(d){case"MSB":{p=r;break}case"LSB":{g=r;break}case"Name":{v=r;break}default:console.debug(`Unknown EFX field: ${d}`)}})}),console.debug(`EFX: ${h} total, ${l} loaded.`),c.dispatchEvent("efxreverb",c.device.getEffectType(0)),c.dispatchEvent("efxchorus",c.device.getEffectType(1)),c.dispatchEvent("efxdelay",c.device.getEffectType(2)),c.dispatchEvent("efxinsert0",c.device.getEffectType(3)),c.dispatchEvent("efxinsert1",c.device.getEffectType(4)),c.dispatchEvent("efxinsert2",c.device.getEffectType(5)),c.dispatchEvent("efxinsert3",c.device.getEffectType(6))}switchMode(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.#m[e]||e}getEfx([e,t]){let c=e<<8|t;return this.#T[c]||`0x${c.toString(16).padStart(4,"0")}`}get noteProgress(){return this.#u/this.#e}get noteOverall(){return this.noteProgress-this.#g}get noteBar(){return Math.floor(this.noteOverall/this.#r)}get noteBeat(){let e=this.noteOverall%this.#r;return e<0&&(e+=this.#r),e}getTimeSig(){return[this.#r,this.#h]}getTempo(){return this.#b}sendCmd(e){this.device.runJson(e)}render(e){e>this.#u&&(this.#u=e);let t=this.#t?.step(e)||[],c=0,l=new Set,h={},p=[],g=this,v=[];for(g.device.getStrength().forEach((E,w)=>{g.#i[w]=E}),g.device.newStrength(),t.forEach(function(E){let w=E.data,x=g.device.runJson(w);switch(x?.reply){case"meta":{v.push(x);break}}x?.reply&&delete x.reply});g.#$.length>0;){let E=g.#$.shift(),w=E.part<<7|E.note;E.state?(l.add(w),h[w]=E.velo):l.has(w)&&(p.push({part:E.part,note:E.note,velo:h[w],state:g.device.NOTE_SUSTAIN}),c++)}v?.length>0&&g.dispatchEvent("meta",v);let a=g.device.getActive(),i=[],d=g.device.getPitch(),r=g.device.getCcAll(),s=g.device.getProgram(),n=g.device.getChType(),o=[],u=g.device.getStrength();u.forEach(function(E,w,x){x[w]=Math.max(g.#i[w],E);let M=x[w]-g.#f[w],B=b.length*w;if(M>=0){let Z=4*.25**(r[B+b[73]]/64);g.#f[w]+=Math.ceil(M-M*g.smoothingAtk**Z)}else{let Z=4*.25**(r[B+b[72]]/64);g.#f[w]+=Math.floor(M-M*g.smoothingDcy**Z)}});let f=0;return a.forEach(function(E,w){E&&(i[w]=g.device.getVel(w),o[w]=g.device.getExt(w),f+=i[w].size)}),{extraPoly:c,extraNotes:p,curPoly:f,chInUse:a,chKeyPr:i,chPitch:d,chProgr:s,chContr:r,chType:n,chExt:o,eventCount:t.length,title:g.#d,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:u,rpn:g.device.getRpn(),tSig:g.getTimeSig(),tempo:g.getTempo(),noteBar:g.noteBar,noteBeat:g.noteBeat,ace:g.device.getAce(),rawVelo:g.device.getStrength(),rawStrength:g.device.getRawStrength(),rawPitch:g.device.getRawPitch(),efxSink:g.device.getEffectSink()}}constructor(e,t=.5,c=.5){super();let l=this;l.smoothingAtk=t,l.smoothingDcy=c,l.device=e,l.addEventListener("meta",function(h){h?.data?.forEach(function(p){(l.#E[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,"portrange"),S(l.device,l,"portstart"),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,"banklevel"),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:h}){l.#$.push(h)}),l.#E[3]=function(h,p){l.#d?.length<1&&(l.#d=p,l.dispatchEvent("title",l.#d))},l.#E[81]=function(h,p){let g=l.noteProgress,v=l.#e||.5;l.#b=6e7/p,l.#e=p/1e6,l.#g+=g*(v/l.#e)-g,l.dispatchEvent("tempo",l.#b)},l.#E[88]=function(h,p){let g=l.noteProgress,v=l.noteOverall,a=l.noteBar,i=l.noteBeat,d=l.#r,r=l.#h;l.#r=p[0],l.#h=1<=d&&(d{fe&&(de[q]=!de[q],q++,q>34&&(q=0))},1e3/50);Uint8Array.prototype.render=function(e){let t=0,c=0,l=this.width||5,h=this.height||8;for(let p=0;p=l&&(t=0,c++)};var Ge=class{#t=[];async load(e,t=!1,c="(internal)"){let l=this,h=0,p=0;console.debug(`Font "${c||"(internal)"}": loading started.`),e.split(` +`).forEach(function(g,v){if(v>0&&g?.length>0){let a=g.split(" "),i=parseInt(a[0],16);if(p++,l.#t[i]&&!t)return;let d=new Uint8Array(40);Array.from(a[1]).forEach(async function(r,s){let n=s%2?4:0,o=Math.floor(s/2),u=parseInt(r,16),f=3;for(;u>0||f>=0;){let y=(n+f)*5+o;d[y]=u&1,u=u>>1,f--}}),l.#t[i]=d,h++}}),console.debug(`Font "${c||"(internal)"}": ${p} total, ${h} loaded.`)}async loadFile(e,t=!1){let c=this;console.debug(`Requested font file from "${e}".`),await c.load(await(await fetch(e)).text(),t,e),fe=!1}constructor(...e){fe=!0,(async()=>{for(let t=0;t{l.classList.add(d)});let{t:h,l:p,w:g,h:v,i:a,a:i}=c;return h?.constructor&&(l.style.top=h?.length?h:`${h}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)),i?.constructor&&(l.style.textAlign=i),l};var R=function(e,t){t?.forEach(c=>{e.appendChild(c)})},L=function(e,t){t.forEach(c=>{e.classList.contains(c)&&e.classList.remove(c)})},U=function(e,t){t.forEach(c=>{e.classList.contains(c)||e.classList.add(c)})},wt=new Array(128).fill(0);wt.forEach((e,t,c)=>{c[t]=Math.floor(24*t/12.7)/10});var $t=new Array(128).fill(0);$t.forEach((e,t,c)=>{c[t]=Math.abs(Math.round(48*(t-64)/12.7)/10)});var ze=new Array(11).fill(null);ze.forEach((e,t,c)=>{c[t]=`${Math.round(t*12/.0128)/100}%`});var kt=new Array(128).fill(null);kt.forEach((e,t,c)=>{c[t]=`${Math.round(t/1.27)/100}`});var Ke=function(e,t){e.innerText=t,e.rNew=!0;let c=e.measureText(t);e.rWidth=c.width},ya=class extends Ve{#t=128;#m=!1;#T="";#d;#E=0;#$=0;#f=0;#i=0;#e=m.invalidCh;#b=1;#r=0;#h=0;#g=new Uint8Array(1280);#u=new Uint8Array(1280);#k=new Uint8Array(1280);#L=new Uint8Array(512);#I=new Uint8Array(512);#U=new Uint8Array(512);#M=new Uint8Array(m.ch);#s;#o;#X;#l;#P;#S="fcdaff";#a={};#R={};#n=[];#y={};#w={};eventViewMode=0;#z=[];#O="comb";glyphs=new Ge;#A(e,t,c,l=0,h=0){let p=this,{width:g,height:v}=e.canvas,a,i,d,r,s=p.#b,n=l>3,o=bt.indexOf(t%12)>-1;switch(p.#O){case"block":case"comb":{a=Math.round(t*g/128),i=Math.round((t+1)*g/128),d=i-a,r=s==1?2:1;break}case"piano":{a=Math.round((Math.floor(t/12)*7+_e[t%12])*g/75*1.0044642857142856),i=Math.round((Math.floor(t/12)*7+_e[t%12]+1)*g/75*1.0044642857142856)-1,d=i-a,r=s==1?3:1;break}case"line":{let u=t-h;Math.abs(h)>2&&(u=t-Math.sign(h)*2),i=Math.round((t+.5)*g/128),a=Math.round((u+.5)*g/128)}default:}switch(e.fillStyle=`#${o?p.#S:"ffffff"}${(c<<1|c>>6).toString(16).padStart(2,"0")}`,e.strokeStyle=e.fillStyle,e.lineWidth=s==1?4:2,e.lineDashOffset=0,p.#O){case"block":{let u=e.canvas.height-1;e.fillRect(a,1,d,u),n&&e.clearRect(a+r,r+1,d-(r<<1),u-(r<<1));break}case"comb":{let u=(o?Math.round((e.canvas.height<<1)/3):e.canvas.height)-1;e.fillRect(a,1,d,u),n&&e.clearRect(a+r,r+1,d-(r<<1),u-(r<<1));break}case"piano":{let u=(o?0:e.canvas.height>>1)+1,f=(e.canvas.height>>1)-1;e.fillRect(a,u,d,f),n&&e.clearRect(a+r,u+r,d-(r<<1),f-(r<<1));break}case"line":{if(n)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,i+=.5);e.beginPath(),e.moveTo(a,(s==4||!n)&&self?.document?.mozFullScreen?2:1),e.lineTo(i,(v>>1)+1),e.lineTo(a,v),e.stroke();break}default:}}#q(e,t){let c=this;(e?.chInUse||t).forEach((l,h)=>{if(l){let p=c.#n[h>>4][h&15].cxt;p.clearRect(0,0,p.canvas.width,p.canvas.height),e.chKeyPr[h].forEach(({v:g,s:v},a)=>{c.#A(p,a,g,v,c.device.getPitchShift(h))})}})}#F(e){let t=this;Date.now()-t.#E>4e3&&(t.#$=0,t.#f=142-t.#y.view.clientHeight,(t.#d?.clientWidth||0)>840&&(t.#$=840-t.#d.clientWidth),t.#y.view.style.transform=`translateX(${t.#$}px) translateY(${t.#f}px)`,e&&(t.#E=0))}#x(){let e=self.innerWidth/self.innerHeight,t=1,c=self.innerWidth,l=self.innerHeight;e>=Q?(t=Math.min(Math.round(self.innerHeight/1080*1e4)/1e4,100),c=Math.ceil(self.innerHeight*Q)):e>4,s=d*m.cc,n=e.#n[r][d&15];if(c.chInUse[d]&&r>=e.#r&&r0){let x=24-w;n.ccVis.fillRect(f*6,x,4,w)}}}let o=c.chContr[s+b[10]]||1,u=Math.abs(o-64)/2.625;if(o<64?n.ccVis.fillRect(84-u,0,u,24):o>127?(n.ccVis.fillRect(60,0,49,24),n.ccVis.clearRect(61,1,47,22)):n.ccVis.fillRect(85,0,u,24),n.ccVis.fillStyle="#fff",n.ccVis.fillRect(84,0,1,24),n.metre.clearRect(0,0,121,25),n.metre.globalCompositeOperation="source-over",n.metre.rWidth>n.metre.canvas.width){n.metre.rNew&&(n.metre.rNew=!1,n.metre.rOffset=t);let f=t-(n.metre.rOffset||0),y=32,E=n.metre.rWidth-n.metre.canvas.width+y,w=f*-25%(n.metre.rWidth+y+48)+48;w>0&&(w=0),n.metre.fillText(n.metre.innerText,w,3+e.#P.font4[0]),Math.abs(w)>E&&n.metre.fillText(n.metre.innerText,w+n.metre.rWidth+y,3+e.#P.font4[0])}else n.metre.fillText(n.metre.innerText,0,3+e.#P.font4[0]);switch(n.metre.globalCompositeOperation="xor",n.metre.fillRect(0,0,c.strength[d]*121/255,25),n.extVis.clearRect(0,0,47,25),n.extVis.fillStyle="#fff",c.chExt[d][0]){case e.device.EXT_VL:{let f=(c.chContr[s+b[136]]-64)/64||c.rawPitch[d]/8192;f=f*-4+4;let y=+!!c.rawVelo[d]*(c.chContr[s+b[129]]*c.chContr[s+b[11]]/16129);!y&&c.rawStrength[d]&&(y=c.rawStrength[d]*c.chContr[s+b[11]]/16129),y*=32;let E=c.chContr[s+b[1]]/127*8;n.extVis.beginPath(),n.extVis.moveTo(0,12-f-3),n.extVis.lineTo(7+y,12),n.extVis.lineTo(0,12+f+3),n.extVis.fill(),n.extVis.fillStyle=`#${e.#S}`,n.extVis.beginPath(),n.extVis.ellipse(43,12,4,4+E,0,0,mt),n.extVis.fill();break}case e.device.EXT_DX:{c.chContr.subarray(s+b[142],s+b[157]+1).forEach((y,E)=>{E>=8&&(n.extVis.fillStyle=`#${e.#S}`);let w=E*3,x=(y-64)/5.82;x>=0?n.extVis.fillRect(w,12-x,2,x+1):n.extVis.fillRect(w,12,2,1-x)});break}}}}let v=new Array(m.ch);if(e.#n.forEach((d,r)=>{d.forEach((s,n)=>{s.refresh&&(s.refresh=!1,v[r<<7|n]=!0)})}),["line"].indexOf(e.#O)>-1)for(;e.#z.length>0;){let d=e.#z.shift();v[d.part]=!0}e.#q(c,v),c.extraNotes.forEach(d=>{let{part:r,note:s,velo:n,state:o}=d,u=e.#n[r>>4][r&15].cxt;e.#A(u,s,n,o,e.device.getPitchShift(r))});let a=e.#w.cxt;l>c.bitmap.expire?e.#U.fill(0):c.bitmap.bitmap.length>256?c.bitmap.bitmap.forEach((d,r)=>{e.#U[r]=d?255:0}):c.bitmap.bitmap.forEach((d,r)=>{e.#U[r<<1]=d?255:0,e.#U[r<<1|1]=d?255:0}),e.#k.fill(0),l<=c.letter.expire&&e.glyphs.getStr(c.letter.text).forEach((d,r)=>{let s=(r&15)*5,n=r>>4<<3;d.forEach((o,u)=>{let f=s+u%5,y=n+Math.floor(u/5);e.#k[y*80+f]=o?255:0})}),e.#L.forEach((d,r,s)=>{let n=e.#U[r];n>d?s[r]+=Math.min(n-d,j):n{let n=e.#k[r];n>d?s[r]+=Math.min(n-d,j):n{let s=r>>5,n=r&31;e.#I[r]!=d?(a.clearRect(252+(n<<2),s<<2,3,3),d&&(a.fillStyle=`#ffffff${d.toString(16).padStart(2,"0")}`,a.fillRect(252+(n<<2),s<<2,3,3))):self.debugMode&&(a.clearRect(252+(n<<2),s<<2,3,3),d&&(a.fillStyle=`#ff0000${d.toString(16).padStart(2,"0")}`,a.fillRect(252+(n<<2),s<<2,3,3)))}),e.#g.forEach((d,r)=>{let s=Math.floor(r/80),n=r%80;n+=Math.floor(n/5),e.#u[r]!=d?(a.clearRect(n<<2,(s|16)<<2,3,3),d&&(a.fillStyle=`#ffffff${d.toString(16).padStart(2,"0")}`,a.fillRect(n<<2,(s|16)<<2,3,3))):self.debugMode&&(a.clearRect(n<<2,(s|16)<<2,3,3),d&&(a.fillStyle=`#ff0000${d.toString(16).padStart(2,"0")}`,a.fillRect(n<<2,(s|16)<<2,3,3)))}),e.#I.forEach((d,r,s)=>{s[r]=e.#L[r]}),e.#u.forEach((d,r,s)=>{s[r]=e.#g[r]});let i=(self.performance||self.Date).now();switch(e.eventViewMode){case 0:{e.#a.events.innerText=`${c.eventCount}`.padStart(3,"0");break}case 1:{let d=1e3/(i-e.#h);d>99?(d=Math.round(d),e.#a.events.innerText=`${d}`):d>9?(d=Math.round(d*10)/10,e.#a.events.innerText=`${Math.floor(d)}.${Math.floor(d*10%10)}`):(d=Math.round(d*100)/100,e.#a.events.innerText=`${Math.floor(d)}.${Math.floor(d*100%100)}`);break}default:e.#a.events.innerText=""}e.#h=i}#Y;#p;get style(){return this.#O}set style(e){let t=this;t.#O=e,t.#q(t.render(t.#s?.currentTime||0)),L(t.#l,["cambiare-style-block","cambiare-style-comb","cambiare-style-piano","cambiare-style-line"]),U(t.#l,[`cambiare-style-${e}`])}setClockSource(e){this.#s=e}setPixelProfile(e){let t=this;if(Fe[e]){let c=Fe[e];t.#P=c,t.#l&&(t.#l.style.setProperty("--pcp-font4",`translate(${c.font4[1]}px, ${c.font4[0]}px)`),t.#l.style.setProperty("--pcp-font7",`translate(${c.font7[1]}px, ${c.font7[0]}px)`))}else throw new Error(`"${e}" is not a valid pixel correction profile`)}setMode(e){let t=this;L(t.#l,["cambiare-mode-gm","cambiare-mode-xg","cambiare-mode-gs","cambiare-mode-sc","cambiare-mode-ns5r","cambiare-mode-05rw","cambiare-mode-x5d","cambiare-mode-k11","cambiare-mode-sg","cambiare-mode-g2","cambiare-mode-mt32","cambiare-mode-doc","cambiare-mode-qy10","cambiare-mode-qy20","cambiare-mode-sd","cambiare-mode-krs","cambiare-mode-s90es","cambiare-mode-motif"]),e!="?"&&U(t.#l,[`cambiare-mode-${e}`]),t.#S={xg:"9efaa0",doc:"9efaa0",qy10:"9efaa0",qy20:"9efaa0",ns5r:"9efaa0",x5d:"9efaa0","05rw":"9efaa0",k11:"9efaa0",s90es:"9efaa0",motif:"9efaa0",gm:"a1f3ff",g2:"a1f3ff",krs:"a1f3ff",gs:"ffe1a5",sc:"ffe1a5",mt32:"ffe1a5",sd:"ffe1a5",sg:"ffdddd"}[e]||"fcdaff"}#G(e){let t=this,c=t.#b,l=t.#r;t.#n.forEach((h,p)=>{if(p>=l&&p{i.root.style.top=`${d*(c>2?26:52)}px`})}else L(h.root,["port-active"]),h.root.style.top="",h.root.style.left="",h.forEach((g,v)=>{g.root.style.top=""});e&&h.forEach((g,v)=>{g.cxt.canvas.width=t.#b==1?1193:495,g.cxt.canvas.height=t.#b==4?26:52})})}setPort(e){let t=this;L(t.#l,["cambiare-start0","cambiare-start1","cambiare-start2","cambiare-start3","cambiare-start4","cambiare-start5","cambiare-start6","cambiare-start7"]),U(t.#l,[`cambiare-start${e}`]),t.#r=e,t.#G(!1)}setRange(e){let t=this;L(t.#l,["cambiare-port1","cambiare-port2","cambiare-port4","cambiare-compact"]),U(t.#l,[`cambiare-${e}`]),t.#b=parseInt(e.slice(4))||1,t.#G(!0)}attach(e){let t=this;t.#o=e;let c=k("div",["cambiare-container"]);e.appendChild(c),t.#X=c;let l=k("div",["cambiare-canvas","cambiare-port1","cambiare-start0","cambiare-style-block"]);c.appendChild(l),t.#l=l,self.addEventListener("resize",t.#c),t.#c(),t.#p=setInterval(t.#Y,20),t.#a.root=k("div",["sect-info"]),t.#a.events=k("span",["field","pcp-font4"],{t:1,l:0,w:35,h:33}),t.#a.curPoly=k("span",["field","pcp-font4"],{t:1,l:52,w:35,h:33}),t.#a.maxPoly=k("span",["field","pcp-font4"],{t:1,l:98,w:35,h:33}),t.#a.sigN=k("span",["field","pcp-font4"],{t:1,l:194,w:23,h:33,a:"right"}),t.#a.sigD=k("span",["field","pcp-font4"],{t:1,l:232,w:23,h:33}),t.#a.barCount=k("span",["field","pcp-font4"],{t:1,l:304,w:35,h:33,a:"right"}),t.#a.barDelim=k("span",["field","field-label","pcp-font4"],{t:0,l:343,w:8,h:33,i:"/"}),t.#a.barNote=k("span",["field","pcp-font4"],{t:1,l:354,w:23,h:33}),t.#a.tempo=k("span",["field","pcp-font4"],{t:1,l:454,w:64,h:33,a:"right"}),t.#a.volume=k("span",["field","pcp-font4"],{t:1,l:562,w:63,h:33,a:"right"}),t.#a.mode=k("span",["field","pcp-font4"],{t:1,l:708,w:152,h:33}),t.#a.reverb=k("span",["field","pcp-font4"],{t:1,l:1e3,w:190,h:33}),t.#a.chorus=k("span",["field","pcp-font4"],{t:1,l:1240,w:190,h:33}),t.#a.delay=k("span",["field","pcp-font4"],{t:1,l:1475,w:190,h:33}),t.#a.insert=k("span",["field","pcp-font4"],{t:1,l:1706,w:190,h:33}),t.#a.title=k("span",["field","pcp-font4"],{t:35,l:50,w:810,h:33}),l.appendChild(t.#a.root),R(t.#a.root,[t.#a.events,t.#a.curPoly,k("span",["field","field-label","pcp-font4"],{t:1,l:89,w:5,h:33,i:":"}),t.#a.maxPoly,k("span",["field","field-key","pcp-font7"],{t:1,l:148,w:41,h:33,i:"TSig"}),t.#a.sigN,k("span",["field","field-label","pcp-font4"],{t:0,l:221,w:8,h:33,i:"/"}),t.#a.sigD,k("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,k("span",["field","field-key","pcp-font7"],{t:1,l:390,w:61,h:33,i:"Tempo",a:"right"}),t.#a.tempo,k("span",["field","field-key","pcp-font7"],{t:1,l:528,w:29,h:33,i:"Vol"}),t.#a.volume,k("span",["field","field-label","pcp-font4"],{t:1,l:626,w:17,h:33,i:"%"}),k("span",["field","field-key","pcp-font7"],{t:1,l:652,w:52,h:33,i:"Mode"}),t.#a.mode,k("span",["field","field-key","pcp-font7"],{t:1,l:960,w:34,h:33,i:"Rev"}),t.#a.reverb,k("span",["field","field-key","pcp-font7"],{t:1,l:1198,w:36,h:33,i:"Cho"}),t.#a.chorus,k("span",["field","field-key","pcp-font7"],{t:1,l:1438,w:31,h:33,i:"Var"}),t.#a.delay,k("span",["field","field-key","pcp-font7"],{t:1,l:1673,w:27,h:33,i:"Ins"}),t.#a.insert,k("span",["field","field-key","pcp-font7"],{t:35,l:0,w:44,h:33,i:"Title"}),t.#a.title]),t.#R.root=k("div",["sect-mark"]),t.#R.left=k("div",["sect-mark-left","boundary"],{t:0,l:0}),t.#R.right=k("div",["sect-mark-right","boundary"],{t:0,l:960}),l.appendChild(t.#R.root),R(t.#R.root,[t.#R.left,t.#R.right]),R(t.#R.left,[k("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),k("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),k("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),k("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),k("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),k("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),R(t.#R.right,[k("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),k("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),k("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),k("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),k("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),k("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),t.#n.root=k("div",["sect-part"]);for(let h=0;h>4;h++){let p=h<<4;t.#n[h]=[],t.#n[h].root=k("div",["boundary",`part-port-${h}`]);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.#n[h][g]={root:k("div",["boundary","part-channel"]),major:k("div",["boundary","part-info-major"]),minor:k("div",["boundary","part-info-minor"],{t:26}),keys:k("div",["boundary","part-keys"]),notes:k("div",["boundary","part-keyboard"]),cxt:k("canvas",["field"]).getContext("2d"),number:k("span",["field","field-label","pcp-font4"],{t:1,w:18,h:25,i:v}),voice:k("span",["field"],{l:22,t:1,w:121,h:25}),metre:k("canvas",["field"]).getContext("2d"),type:k("span",["field","field-label","pcp-font4"],{t:1,w:18,h:25}),std:k("span",["field","pcp-font4"],{l:22,t:1,w:20,h:25,a:"center"}),msb:k("span",["field","pcp-font4"],{l:48,t:1,w:27,h:25}),prg:k("span",["field","pcp-font4"],{l:81,t:1,w:27,h:25}),lsb:k("span",["field","pcp-font4"],{l:114,t:1,w:27,h:25}),ccVis:k("canvas",["field"],{l:145,t:1}).getContext("2d"),extVis:k("canvas",["field"],{l:207,t:1}).getContext("2d"),ccUpdate:!1};let a=t.#n[h][g];ze.forEach(i=>{a.notes.appendChild(k("span",["field","part-csplit"],{l:i}))}),a.notes.appendChild(k("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.ccVis.canvas.width=109,a.ccVis.canvas.height=25,a.ccVis.fillStyle="#fff",a.extVis.canvas.width=47,a.extVis.canvas.height=25,a.extVis.fillStyle="#fff",R(a.notes,[a.cxt.canvas]),R(a.keys,[a.notes]),R(a.voice,[a.metre.canvas]),R(a.major,[a.number,a.voice,a.ccVis.canvas]),R(a.minor,[a.type,a.std,a.msb,a.prg,a.lsb,a.extVis.canvas]),R(a.root,[a.major,a.minor,a.keys]),R(t.#n[h].root,[a.root]),a.number.addEventListener("contextmenu",i=>{i.preventDefault(),i.stopImmediatePropagation();let d=h<<4|g;t.#M[d]=+!t.#M[d],[L,U][t.#M[d]](a.root,["part-hidden"])})}t.#n.root.appendChild(t.#n[h].root)}l.appendChild(t.#n.root),t.#y.root=k("div",["sect-meta"]),t.#y.view=k("div",["boundary"]),l.appendChild(t.#y.root),R(t.#y.root,[t.#y.view]),t.#w.root=k("div",["sect-pix","boundary"],{l:1529,t:950,w:379,h:127}),t.#w.cxt=k("canvas",["field"]).getContext("2d"),t.#w.fps=k("span",["field","field-key"],{l:0,w:"100%",h:1}),t.#w.cxt.canvas.width=379,t.#w.cxt.canvas.height=127,R(t.#w.root,[t.#w.cxt.canvas]),l.appendChild(t.#w.root),t.addEventListener("mode",h=>{t.#a.mode.innerText=`${gt[h.data]}`,t.setMode(h.data)}),t.addEventListener("mastervolume",h=>{let p=Math.round(h.data*100)/100;t.#a.volume.innerText=`${Math.floor(p)}.${`${Math.floor(p%1*100)}`.padStart(2,"0")}`}),t.addEventListener("tempo",h=>{let p=Math.round(h.data*100);t.#a.tempo.innerText=`${Math.floor(p/100)}.${`${Math.floor(p%100)}`.padStart(2,"0")}`}),t.addEventListener("tsig",h=>{[t.#a.sigN.innerText,t.#a.sigD.innerText]=h.data}),t.addEventListener("title",h=>{t.#a.title.innerText=h.data||"No Title"}),t.addEventListener("voice",({data:h})=>{let p=t.getChVoice(h.part),g=t.#n[h.part>>4][h.part&15];Ke(g.metre,t.getMapped(p.name)),g.type.innerText=pt[t.device.getChType()[h.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",h=>{let{part:p,pitch:g}=h.data;t.#n[p>>4][p&15].notes.style.transform=`translateX(${g/1.28}%)`}),t.addEventListener("efxreverb",h=>{t.#a.reverb.innerText=t.getEfx(h.data)}),t.addEventListener("efxchorus",h=>{t.#a.chorus.innerText=t.getEfx(h.data)}),t.addEventListener("efxdelay",h=>{t.#a.delay.innerText=t.getEfx(h.data)}),t.addEventListener("efxinsert0",h=>{t.#a.insert.innerText=t.getEfx(h.data)}),t.addEventListener("partefxtoggle",h=>{let{part:p,active:g}=h.data;[L,U][g](t.#n[p>>4][p&15].number,["part-efx"])}),t.addEventListener("channeltoggle",h=>{let{part:p,active:g}=h.data;[L,U][g](t.#n[p>>4][p&15].root,["part-active"])}),t.addEventListener("channelactive",h=>{if(t.#e>4][t.#e&15].number;L(g,["part-focus"])}let p=h.data;if(p>4][p&15].number;U(g,["part-focus"]),t.#e=p}}),t.addEventListener("metacommit",h=>{let p=h.data;if(t.#m&&p.type==t.#T&&t.#d)switch(p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{R(t.#d,[k("span",["meta-slice"],{i:p.data})]);break}default:t.#d.childNodes[0].data+=p.data}else if(p.data?.length&&vt.indexOf(p.type)==-1){let g=k("div",["meta-line"]),v=k("span",["field","field-key","meta-type"],{i:yt[p.type]||p.type});switch(p.mask&&(v.style.display="none"),p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{t.#d=k("span",["field","meta-data"]),R(t.#d,[k("span",["meta-slice"],{i:p.data})]);break}default:t.#d=k("span",["field","meta-data"],{i:p.data})}for(t.#y.view.appendChild(g),R(g,[v,t.#d]);t.#y.view.children.length>t.#t;)t.#y.view.children[0].remove()}t.#m=p.amend||!1,t.#T=p.type||"",t.#F()}),t.#y.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.#c),t.#l.remove(),t.#l=void 0,t.#X.remove(),t.#X=void 0,t.#o=void 0,clearInterval(t.#p)}constructor(e,t){super(new Ue,.1,.75);let c=this;c.#c=c.#x.bind(this),c.#Y=c.#H.bind(this),e&&c.attach(e),t&&c.setClockSource(t),c.setPixelProfile("none"),c.addEventListener("reset",()=>{c.#i=0,c.#m=!1,c.#T="",c.#d=null,c.#e=m.invalidCh;try{let l=c.#y.view.children;for(let h=l.length-1;h>=0;h--)l[h].remove();c.#y.view.style.transform="translateX(0px) translateY(140px)";for(let h=0;h>4][h&15];L(p.root,["part-active"]),L(p.number,["part-efx","part-focus"]),Ke(p.metre,""),p.type.innerText="",p.std.innerText="",p.msb.innerText="",p.prg.innerText="",p.lsb.innerText="",p.notes.style.transform="",p.ccUpdate=!0}}catch{}}),c.addEventListener("pitch",({data:l})=>{c.#z.push(l)})}};export{ya as Cambiare}; diff --git a/dist/state.mjs b/dist/state.mjs index 5a795d7b..353ad708 100644 --- a/dist/state.mjs +++ b/dist/state.mjs @@ -1,9 +1,9 @@ -var Y=function(e,a){let l=Math.min(e.length,a.length),h=e.slice(0,l),g=a.slice(0,l),E=0,v=0;for(;v0){let h=this.pool.length,g=1<=1&&v>=0;){if(v<=0)throw new Error("TTL reached.");if(E==h)E-=g;else{let t=Y(a,this.pool[E]);switch(t){case 0:{v=0;break}case 1:{E+g<=h&&(E+=g);break}case-1:{E!=0&&(E-=g);break}default:console.warn(`Unexpected result ${t}.`)}}g=g>>1,v--}let $=!0;if(E>=this.pool.length)$=!1;else{let t=this;this.pool[E].forEach(function(r,f,s){$&&r!=a[f]&&($=!1)}),!$&&Y(a,this.pool[E])>0&&E++}return $||l?E:-1}else return l?0:-1},this.add=function(a,l){return a.data=l,this.pool.splice(this.point(a,!0),0,a),this},this.default=function(a){console.warn(`No match in "${this.name||"(unknown)"}" for "${a}". Default action not defined.`)},this.get=function(a){let l=this.point(a);if(l>-1)return this.pool[l].data;this.default(a)},this.run=function(a,...l){let h=this.point(a);h>-1?a.subarray?this.pool[h].data(a.subarray(this.pool[h].length),...l):this.pool[h].data(a.slice(this.pool[h].length),...l):this.default(a,...l)}};var J=class{#t={};addEventListener(e,a){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(a)}removeEventListener(e,a){if(this.#t[e]){let l=this.#t[e].indexOf(a);l>-1&&this.#t[e].splice(l,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,a){let l=new Event(e),h=this;l.data=a,this.#t[e]?.length>0&&this.#t[e].forEach(function(g){try{g?.call(h,l)}catch(E){console.error(E)}}),this[`on${e}`]&&this[`on${e}`](l)}};var ye=["MSB","PRG","LSB","NME","ELC","DRM"],V=function(e){let a=Math.floor(e/10),l=e%10;return`${a.toString(16)}${l}`},F=class{#t;strictMode=!1;get(e=0,a=0,l=0,h){let g=[e,a,l],E,v=1,$=0,t,r=Array.from(arguments);switch(h){case"xg":{switch(e){case 0:{l==126?r[2]=125:l==127&&(r[2]=0);break}case 16:{l==126&&(r[2]=0);break}case 32:{l>125&&(r[2]=0),r[2]+=4;break}case 33:case 34:case 35:case 36:{l>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:{l==126&&(r[2]=0);break}case 48:case 64:case 126:case 127:{l==126&&(r[2]=0);break}}break}case"gs":case"sc":{e==0&&l<5?r[2]=0:e>125&&l<5&&l!=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,a>>4==7&&(r[0]=96));break}case"sg":{e==8&&l==0&&(r[2]=5);break}case"s90es":{l<8?r[2]+=17:l<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}case"motif":{l<8?r[2]+=28:l<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}}let f=" ",s="M",i=0,n=0;switch(r[0]){case 0:{r[2]==127?s="MT-a":r[2]==126?s="MT-b":r[2]==7?s="GM-k":r[2]==5?s="SG-a":r[2]==4?s="SP-l":r[2]==0||(h=="gs"||h=="sc")&&r[2]<5?s="GM-a":(s="y",i=3);break}case 8:{h=="sg"?s="GM-s":s="r:";break}case 32:case 33:case 34:case 35:case 36:{h=="xg"&&(s=`${["AP","VL","PF","DX","AN"][e&7]}-${"abcdefgh"[l]}`);break}case 48:{s=`yM${(r[2]>>3).toString().padStart(2,"0")}`,i=1;break}case 56:{s="GM-b";break}case 57:s=["yDOC","QY10","QY20"][r[2]-112]||"yMxv";case 61:case 120:{s="rDrm";break}case 62:{s="kDrm";break}case 63:{if(r[2]<17){let b=r[2];s=b<10?"kP:":"kC:",s+=b%10}else r[2]<34?s=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][r[2]-17]:s="Ds";break}case 64:{s="ySFX";break}case 67:{s="DX:S";break}case 80:case 81:case 82:case 83:{s=`Prg${"UABC"[r[0]-80]}`;break}case 88:case 89:case 90:case 91:{s=`Cmb${"UABC"[r[0]-88]}`;break}case 95:{s=`${["DR","PC"][r[2]]}-d`;break}case 96:{s=r[2]==106?"AP-a":r[2]>>4==1?"SDg":"PF",r[2]>63?n=63:r[2]>>4==1&&(n=16),i=3;break}case 97:{s=r[2]>>4==1?"SDa":"VL:",i=3,r[2]>>4==1?n=16:n=112;break}case 98:{s=r[2]>>4==1?"SDb":"SG-a",i=3,n=16;break}case 99:{s=r[2]>>4==1?"SDc":"DX",r[2]>63?n=63:r[2]>>4==1&&(n=16),i=3;break}case 100:{s="AN",r[2]>63?n=63:r[2]>>4==1&&(n=16),i=3;break}case 104:case 105:case 106:case 107:{s="SDd",n=104;break}case 121:{s=`GM-${r[2]?"":"a"}`,i=3;break}case 122:{s="lDrm";break}case 126:{s="yDrS";break}case 127:{r[2]==127?s="rDrm":s="yDrm";break}default:r[0]<48?s="r:":s="M"}s.length<4&&(s+=`${[e,l,r[0],r[2]][i]-n}`.padStart(4-s.length,"0")),h=="xg"&&(e==0?r[2]<100?s=s.replace("y0","y:"):r[2]==125&&(s="y126"):e==16?(E=`Voice${((r[2]<<7)+r[1]+1).toString().padStart(3,"0")}`,f=" "):e==35&&l>>1==2&&(E=`DXCH_${(((r[2]&1)<<7)+a+1).toString().padStart(3,"0")}`,f=" "));let c=[r[0],r[1],r[2]];for(;!(E?.length>=0);)if(E=this.#t[r[1]||0][(r[0]<<7)+r[2]]?.name,E){let b=this.#t[r[1]||0][(r[0]<<7)+r[2]];v=b?.poly||v,$=b?.type||$,t=b?.drum}else if(this.strictMode)E="",f="?";else if(r[0]==0&&r[1]==0&&r[2]==0)E="Unloaded";else if(this.#t[r[1]||0][r[0]<<7])r[0]==0?(r[2]=0,f="^"):r[2]<1?(r[0]=0,f="*"):(r[2]--,f="^");else if(e==48)r[0]=0,r[2]=0,f="!";else if(e==62)r[1]--,f=" ",r[1]<1&&!E?.length&&(r[0]=0,f="!");else if(e<63)r[0]==0?(r[2]=0,f="^"):r[2]<1?(r[0]=0,f="*"):r[2]--;else if(e==80)E=`PrgU:${a.toString().padStart(3,"0")}`,f="!";else if(e==88)E=`CmbU:${a.toString().padStart(3,"0")}`,f="!";else if(e==121)E=`GM2Vox0${l}`,f="#";else if(e==122)if(r[1]==32?r[1]==0:r[1]%=7,E=this.#t[r[1]||0][(r[0]<<7)+r[2]]?.name,E){f=" ";let b=this.#t[r[1]||0][(r[0]<<7)+r[2]];v=b?.poly||v,$=b?.type||$,t=b?.drum}else E="",f="*";else r[1]==0?(E=`${e.toString().padStart(3,"0")} ${a.toString().padStart(3,"0")} ${l.toString().padStart(3,"0")}`,f="!"):r[0]==0?(r[2]=0,f="^"):r[2]>0?r[2]--:r[1]>0?(r[1]=0,f="!"):(r[0]=0,f="?");let d=[r[0],r[1],r[2]];(h=="gs"||h=="sc"||h=="ns5r")&&f=="^"&&(f=" "),e==127&&f=="^"&&(f=" "),f!=" "&&self.debugMode&&(E="");let o="??";switch(r[0]){case 0:{r[2]==0?o="GM":r[2]==5||r[2]==7?o="KG":r[2]<126?o="XG":r[2]==127&&(o="MT");break}case 32:case 33:case 35:case 36:{r[2]>4?o=["AP","VL","PF","DX","AN"][r[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:{r[2]<17?o="KR":r[2]<34?o="ES":o="DS";break}case 64:case 126:{o="XG";break}case 67:case 99:{o=r[2]>>4==1?"SD":"DX";break}case 81:{o="RW";break}case 95:{o=["DR","PC"][r[2]];break}case 96:{o=r[2]==106?"AP":r[2]>>4==1?"SD":"PF";break}case 97:{o=r[2]>>4==1?"SD":"VL";break}case 98:{o=r[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=r[2]?"G2":"GM";break}case 122:{o="KG";break}case 127:{o=r[2]==127?"MT":a==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&h=="xg"?o="XG":o="GS")}return{name:E||`${V(e||0)} ${V(a||0)} ${V(l||0)}`,poly:v,type:$,drum:t,iid:c,eid:d,sid:g,ending:f,sect:s,standard:o}}async load(e,a,l="(internal)"){let h=this,g=[],E=0,v=0;e.split(` -`).forEach(function($,t){let r=$.split(" "),f=[];if(t==0){if(r.forEach(function(s,i){g[ye.indexOf(s)]=i}),g.length<4){console.debug("Debugger launched.");debugger}}else{let s=0,i=0,n=0,c,d=1,o=0,b;r.forEach(async function(k,x){switch(x){case g[0]:{s=parseInt(k);break}case g[1]:{i=parseInt(k);break}case g[2]:{n=parseInt(k);break}case g[3]:{c=k;break}case g[4]:{k=parseInt(k),k<16?d=k+1:o=(k&15)+1;break}case g[5]:{b=k;break}}}),h.#t[i]=h.#t[i]||[];let y=h.#t[i];if(!y[s<<7|n]||a){let k={msb:s,prg:i,lsb:n,name:c,poly:d,type:o,drum:b};y[s<<7|n]=k,E++}v++}}),a||console.debug(`Map "${l}": ${v} total, ${E} loaded.`)}clearRange(e){let a=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],l=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],h=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let g=l[0];g<=l[1];g++){let E=g<<7;for(let v=h[0];v<=h[1];v++){let $=E+v;for(let t=a[0];t<=a[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 a=this;e.forEach(async function(l){try{await fetch(`./data/bank/${l}.tsv`).then(function(h){return h.text()}).then(h=>{a.load(h,!1,l)})}catch{console.error(`Failed loading "${l}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var j=class{#t={};context;set(e,a){this.#t[e]=a}has(e){return!!this.#t[e]}async read(e,a){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,a)}};var me=function(e,a){let l=!0;return a.forEach((h,g)=>{l=l&&e[g]==h}),l},U=function(e){let a=0;return e.forEach(l=>{a*=256,a+=l}),a},P=new TextDecoder,N=new j;N.set("s7e",async function(e){let a=new Uint8Array(await e.slice(0,65536).arrayBuffer()),l="MSB LSB PRG NME",h=[0,0,0,0],g=32,E=0,v=0,$=!0,t=[],r=0;for(;$;){let f=a.subarray(E);([()=>{P.decode(f.subarray(0,4))=="YSFC"?(E+=80,v=1):E++},()=>{if(me(f.subarray(0,4),h))t.forEach((s,i,n)=>{let c=U(a.subarray(s.start+4,s.start+8));s.length=c}),v=2;else{let s=P.decode(f.subarray(0,4)),i=U(f.subarray(4,8));t.push({type:s,start:i}),E+=8}},()=>{let s=t[r],i=a.subarray(s.start,s.start+s.length),n=32;switch(s.type){case"ENVC":{let c=g;for(;c=t.length&&(v=3,$=!1)}][v]||(()=>{$=!1}))()}return l});N.set("pcg",async function(e){let a=new Uint8Array(await e.arrayBuffer()),l="MSB LSB PRG NME",h=100,g=0,E=0,v=!0,$=[],t=0;for(;v;){let r=a.subarray(h);([()=>{v=P.decode(r.subarray(0,4))=="INI2",E=r[15],h+=16,g=1},()=>{let f=P.decode(r.subarray(0,4)),s=r[5],i=r[7],n=r[11],c=U(r.subarray(12,16)),d=U(r.subarray(16,20)),o=U(r.subarray(36,40)),b=P.decode(r.subarray(44,44+n));$.push({type:f,tipMsb:s,tipLsb:i,nameLen:n,length:c,start:d,entryLen:o,name:b}),h+=64,E--,E<1&&(g=2)},()=>{let f=$[t],s=a.subarray(f.start,f.start+f.length);switch(f.type){case"PRG1":break;case"PBK1":{let i=63,n=(f.tipMsb?6:0)+f.tipLsb;for(let c=0;c<128;c++){let d=c*f.entryLen,o=s.subarray(d,d+f.entryLen),b=P.decode(o.subarray(0,24)).trimEnd().replace("InitProg","");b.length&&n>5&&(l+=` -${i.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")} ${b}`)}break}case"CBK1":{let i=63,n=(f.tipMsb?3:0)+f.tipLsb+10;for(let c=0;c<128;c++){let d=c*f.entryLen,o=s.subarray(d,d+f.entryLen),b=P.decode(o.subarray(0,24)).trimEnd().replace("InitCombi","");b.length&&n>12&&(l+=` +var Y=function(e,a){let l=Math.min(e.length,a.length),h=e.slice(0,l),g=a.slice(0,l),E=0,v=0;for(;v0){let h=this.pool.length,g=1<=1&&v>=0;){if(v<=0)throw new Error("TTL reached.");if(E==h)E-=g;else{let t=Y(a,this.pool[E]);switch(t){case 0:{v=0;break}case 1:{E+g<=h&&(E+=g);break}case-1:{E!=0&&(E-=g);break}default:console.warn(`Unexpected result ${t}.`)}}g=g>>1,v--}let $=!0;if(E>=this.pool.length)$=!1;else{let t=this;this.pool[E].forEach(function(r,d,s){$&&r!=a[d]&&($=!1)}),!$&&Y(a,this.pool[E])>0&&E++}return $||l?E:-1}else return l?0:-1},this.add=function(a,l){return a.data=l,this.pool.splice(this.point(a,!0),0,a),this},this.default=function(a){console.warn(`No match in "${this.name||"(unknown)"}" for "${a}". Default action not defined.`)},this.get=function(a){let l=this.point(a);if(l>-1)return this.pool[l].data;this.default(a)},this.run=function(a,...l){let h=this.point(a);h>-1?a.subarray?this.pool[h].data(a.subarray(this.pool[h].length),...l):this.pool[h].data(a.slice(this.pool[h].length),...l):this.default(a,...l)}};var j=class{#t={};addEventListener(e,a){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(a)}removeEventListener(e,a){if(this.#t[e]){let l=this.#t[e].indexOf(a);l>-1&&this.#t[e].splice(l,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,a){let l=new Event(e),h=this;l.data=a,this.#t[e]?.length>0&&this.#t[e].forEach(function(g){try{g?.call(h,l)}catch(E){console.error(E)}}),this[`on${e}`]&&this[`on${e}`](l)}};var ye=["MSB","PRG","LSB","NME","ELC","DRM"],V=function(e){let a=Math.floor(e/10),l=e%10;return`${a.toString(16)}${l}`},F=class{#t;strictMode=!1;get(e=0,a=0,l=0,h){let g=[e,a,l],E,v=1,$=0,t,r=Array.from(arguments);switch(h){case"xg":{switch(e){case 0:{l==126?r[2]=125:l==127&&(r[2]=0);break}case 16:{l==126&&(r[2]=0);break}case 32:{l>125&&(r[2]=0),r[2]+=4;break}case 33:case 34:case 35:case 36:{l>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:{l==126&&(r[2]=0);break}case 48:case 64:case 126:case 127:{l==126&&(r[2]=0);break}}break}case"gs":case"sc":{e==0&&l<5?r[2]=0:e>125&&l<5&&l!=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,a>>4==7&&(r[0]=96));break}case"sg":{e==8&&l==0&&(r[2]=5);break}case"s90es":{l<8?r[2]+=17:l<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}case"motif":{l<8?r[2]+=28:l<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}}let d=" ",s="M",i=0,n=0;switch(r[0]){case 0:{r[2]==127?s="MT-a":r[2]==126?s="MT-b":r[2]==7?s="GM-k":r[2]==5?s="SG-a":r[2]==4?s="SP-l":r[2]==0||(h=="gs"||h=="sc")&&r[2]<5?s="GM-a":(s="y",i=3);break}case 8:{h=="sg"?s="GM-s":s="r:";break}case 32:case 33:case 34:case 35:case 36:{h=="xg"&&(s=`${["AP","VL","PF","DX","AN"][e&7]}-${"abcdefgh"[l]}`);break}case 48:{s=`yM${(r[2]>>3).toString().padStart(2,"0")}`,i=1;break}case 56:{s="GM-b";break}case 57:s=["yDOC","QY10","QY20"][r[2]-112]||"yMxv";case 61:case 120:{s="rDrm";break}case 62:{s="kDrm";break}case 63:{if(r[2]<17){let b=r[2];s=b<10?"kP:":"kC:",s+=b%10}else r[2]<34?s=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][r[2]-17]:s="Ds";break}case 64:{s="ySFX";break}case 67:{s="DX:S";break}case 80:case 81:case 82:case 83:{s=`Prg${"UABC"[r[0]-80]}`;break}case 88:case 89:case 90:case 91:{s=`Cmb${"UABC"[r[0]-88]}`;break}case 95:{s=`${["DR","PC"][r[2]]}-d`;break}case 96:{s=r[2]==106?"AP-a":r[2]>>4==1?"SDg":"PF",r[2]>63?n=63:r[2]>>4==1&&(n=16),i=3;break}case 97:{s=r[2]>>4==1?"SDa":"VL:",i=3,r[2]>>4==1?n=16:n=112;break}case 98:{s=r[2]>>4==1?"SDb":"SG-a",i=3,n=16;break}case 99:{s=r[2]>>4==1?"SDc":"DX",r[2]>63?n=63:r[2]>>4==1&&(n=16),i=3;break}case 100:{s="AN",r[2]>63?n=63:r[2]>>4==1&&(n=16),i=3;break}case 104:case 105:case 106:case 107:{s="SDd",n=104;break}case 121:{s=`GM-${r[2]?"":"a"}`,i=3;break}case 122:{s="lDrm";break}case 126:{s="yDrS";break}case 127:{r[2]==127?s="rDrm":s="yDrm";break}default:r[0]<48?s="r:":s="M"}s.length<4&&(s+=`${[e,l,r[0],r[2]][i]-n}`.padStart(4-s.length,"0")),h=="xg"&&(e==0?r[2]<100?s=s.replace("y0","y:"):r[2]==125&&(s="y126"):e==16?(E=`Voice${((r[2]<<7)+r[1]+1).toString().padStart(3,"0")}`,d=" "):e==35&&l>>1==2&&(E=`DXCH_${(((r[2]&1)<<7)+a+1).toString().padStart(3,"0")}`,d=" "));let c=[r[0],r[1],r[2]];for(;!(E?.length>=0);)if(E=this.#t[r[1]||0][(r[0]<<7)+r[2]]?.name,E){let b=this.#t[r[1]||0][(r[0]<<7)+r[2]];v=b?.poly||v,$=b?.type||$,t=b?.drum}else if(this.strictMode)E="",d="?";else if(r[0]==0&&r[1]==0&&r[2]==0)E="Unloaded";else if(this.#t[r[1]||0][r[0]<<7])r[0]==0?(r[2]=0,d="^"):r[2]<1?(r[0]=0,d="*"):(r[2]--,d="^");else if(e==48)r[0]=0,r[2]=0,d="!";else if(e==62)r[1]--,d=" ",r[1]<1&&!E?.length&&(r[0]=0,d="!");else if(e<63)r[0]==0?(r[2]=0,d="^"):r[2]<1?(r[0]=0,d="*"):r[2]--;else if(e==80)E=`PrgU:${a.toString().padStart(3,"0")}`,d="!";else if(e==88)E=`CmbU:${a.toString().padStart(3,"0")}`,d="!";else if(e==121)E=`GM2Vox0${l}`,d="#";else if(e==122)if(r[1]==32?r[1]==0:r[1]%=7,E=this.#t[r[1]||0][(r[0]<<7)+r[2]]?.name,E){d=" ";let b=this.#t[r[1]||0][(r[0]<<7)+r[2]];v=b?.poly||v,$=b?.type||$,t=b?.drum}else E="",d="*";else r[1]==0?(E=`${e.toString().padStart(3,"0")} ${a.toString().padStart(3,"0")} ${l.toString().padStart(3,"0")}`,d="!"):r[0]==0?(r[2]=0,d="^"):r[2]>0?r[2]--:r[1]>0?(r[1]=0,d="!"):(r[0]=0,d="?");let f=[r[0],r[1],r[2]];(h=="gs"||h=="sc"||h=="ns5r")&&d=="^"&&(d=" "),e==127&&d=="^"&&(d=" "),d!=" "&&self.debugMode&&(E="");let o="??";switch(r[0]){case 0:{r[2]==0?o="GM":r[2]==5||r[2]==7?o="KG":r[2]<126?o="XG":r[2]==127&&(o="MT");break}case 32:case 33:case 35:case 36:{r[2]>4?o=["AP","VL","PF","DX","AN"][r[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:{r[2]<17?o="KR":r[2]<34?o="ES":o="DS";break}case 64:case 126:{o="XG";break}case 67:case 99:{o=r[2]>>4==1?"SD":"DX";break}case 81:{o="RW";break}case 95:{o=["DR","PC"][r[2]];break}case 96:{o=r[2]==106?"AP":r[2]>>4==1?"SD":"PF";break}case 97:{o=r[2]>>4==1?"SD":"VL";break}case 98:{o=r[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=r[2]?"G2":"GM";break}case 122:{o="KG";break}case 127:{o=r[2]==127?"MT":a==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&h=="xg"?o="XG":o="GS")}return{name:E||`${V(e||0)} ${V(a||0)} ${V(l||0)}`,poly:v,type:$,drum:t,iid:c,eid:f,sid:g,ending:d,sect:s,standard:o}}async load(e,a,l="(internal)"){let h=this,g=[],E=0,v=0;e.split(` +`).forEach(function($,t){let r=$.split(" "),d=[];if(t==0){if(r.forEach(function(s,i){g[ye.indexOf(s)]=i}),g.length<4){console.debug("Debugger launched.");debugger}}else{let s=0,i=0,n=0,c,f=1,o=0,b;r.forEach(async function(k,x){switch(x){case g[0]:{s=parseInt(k);break}case g[1]:{i=parseInt(k);break}case g[2]:{n=parseInt(k);break}case g[3]:{c=k;break}case g[4]:{k=parseInt(k),k<16?f=k+1:o=(k&15)+1;break}case g[5]:{b=k;break}}}),h.#t[i]=h.#t[i]||[];let y=h.#t[i];if(!y[s<<7|n]||a){let k={msb:s,prg:i,lsb:n,name:c,poly:f,type:o,drum:b};y[s<<7|n]=k,E++}v++}}),a||console.debug(`Map "${l}": ${v} total, ${E} loaded.`)}clearRange(e){let a=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],l=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],h=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let g=l[0];g<=l[1];g++){let E=g<<7;for(let v=h[0];v<=h[1];v++){let $=E+v;for(let t=a[0];t<=a[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 a=this;e.forEach(async function(l){try{await fetch(`./data/bank/${l}.tsv`).then(function(h){return h.text()}).then(h=>{a.load(h,!1,l)})}catch{console.error(`Failed loading "${l}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var J=class{#t={};context;set(e,a){this.#t[e]=a}has(e){return!!this.#t[e]}async read(e,a){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,a)}};var me=function(e,a){let l=!0;return a.forEach((h,g)=>{l=l&&e[g]==h}),l},U=function(e){let a=0;return e.forEach(l=>{a*=256,a+=l}),a},P=new TextDecoder,N=new J;N.set("s7e",async function(e){let a=new Uint8Array(await e.slice(0,65536).arrayBuffer()),l="MSB LSB PRG NME",h=[0,0,0,0],g=32,E=0,v=0,$=!0,t=[],r=0;for(;$;){let d=a.subarray(E);([()=>{P.decode(d.subarray(0,4))=="YSFC"?(E+=80,v=1):E++},()=>{if(me(d.subarray(0,4),h))t.forEach((s,i,n)=>{let c=U(a.subarray(s.start+4,s.start+8));s.length=c}),v=2;else{let s=P.decode(d.subarray(0,4)),i=U(d.subarray(4,8));t.push({type:s,start:i}),E+=8}},()=>{let s=t[r],i=a.subarray(s.start,s.start+s.length),n=32;switch(s.type){case"ENVC":{let c=g;for(;c=t.length&&(v=3,$=!1)}][v]||(()=>{$=!1}))()}return l});N.set("pcg",async function(e){let a=new Uint8Array(await e.arrayBuffer()),l="MSB LSB PRG NME",h=100,g=0,E=0,v=!0,$=[],t=0;for(;v;){let r=a.subarray(h);([()=>{v=P.decode(r.subarray(0,4))=="INI2",E=r[15],h+=16,g=1},()=>{let d=P.decode(r.subarray(0,4)),s=r[5],i=r[7],n=r[11],c=U(r.subarray(12,16)),f=U(r.subarray(16,20)),o=U(r.subarray(36,40)),b=P.decode(r.subarray(44,44+n));$.push({type:d,tipMsb:s,tipLsb:i,nameLen:n,length:c,start:f,entryLen:o,name:b}),h+=64,E--,E<1&&(g=2)},()=>{let d=$[t],s=a.subarray(d.start,d.start+d.length);switch(d.type){case"PRG1":break;case"PBK1":{let i=63,n=(d.tipMsb?6:0)+d.tipLsb;for(let c=0;c<128;c++){let f=c*d.entryLen,o=s.subarray(f,f+d.entryLen),b=P.decode(o.subarray(0,24)).trimEnd().replace("InitProg","");b.length&&n>5&&(l+=` +${i.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")} ${b}`)}break}case"CBK1":{let i=63,n=(d.tipMsb?3:0)+d.tipLsb+10;for(let c=0;c<128;c++){let f=c*d.entryLen,o=s.subarray(f,f+d.entryLen),b=P.decode(o.subarray(0,24)).trimEnd().replace("InitCombi","");b.length&&n>12&&(l+=` ${i.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")} ${b}`)}break}}t++,t>=$.length&&(g=3,v=!1)}][g]||(()=>{v=!1}))()}return l});var H=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),I=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],$e=[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],Z=[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 a=.1,l=-.3;return e>66?(a=5,l=315):e>56?(a=1,l=47):e>46&&(a=.5,l=18.5),a*e-l},te=function(e){return e>105?$e[e-106]:e>100?e*1.1-100:e/10},ae=",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(","),K={};`hi*, ka,か ki,き @@ -141,8 +141,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let a=e.split(",");K[a[0]]=a[1]});var re=function(e){let a=e;e[0]=="*"&&(a=a.slice(1)),["aa","ii","uu","ee","oo"].forEach(h=>{for(;a.indexOf(h)>-1;)a=a.replace(h,h[0])});for(let h in K)a=a.replaceAll(h,K[h]);a.indexOf("ん")==0&&a.length>1&&(a=a.slice(1));let l=a.indexOf("!");return l>-1&&a.length>1&&(a=a.slice(l+1)),a},se=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var z=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],ie=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ce=["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 ve={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"},ke={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]]},q=function(e){return ve[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ne=function(e,a,l){let h=(e[0]-32<<16)+(e[1]<<8)+a,g=ke[h]||{},E=g[0];if(E?.length)return E+=`: ${(g[1]||function(){})(l)||l}`,E},W=[68,48,95,78,41,3,110,122,0];var C=function(e=64){return Math.round(2e3*Math.log10(e/64))/100};var O=function(e){let a=0;return e.forEach(l=>{a+=l,a=a&127}),~a+1&127},M=function(e,a){let l=0,h=0;for(let g=0;g>E&1)<<7,$=e[g];$+=v,g%8!=0?(a($,l,e),l++):h=e[g]}};var B=function(e){let a=Math.floor(e*14.2);return a<128?a:0},w=function(){return!!self.Bun||self.debugMode||!1};var S=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"],we={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",trinity:"trin","tr-rack":"trin"},xe=["melodic","drum","menu"],oe={"?":[0,0,120],gm:[0,0,127],gs:[0,0,120],sc:[0,0,120],xg:[0,0,127],g2:[0,0,120],mt32:[0,127,127],doc:[57,112,127],qy10:[57,113,127],qy20:[57,114,127],ns5r:[0,0,61],x5d:[82,0,62],"05rw":[81,0,62],k11:[0,0,122],sg:[0,0,122],sd:[97,0,105],krs:[63,0,120],s90es:[63,0,127],motif:[63,0,127],trin:[63,0,127]};var Q=[120,127,120,127,120,127,127,61,62,62,122,122,105,120,127,127,127],le=[9,25,41,57,73,89,105,121],Se=[0,3,81,84,88],de={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},fe={0:0,1:1,2:3,5:4},he={0:0,1:1,2:2,5:3},ue=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],pe=[36,37,48,49,52,53],X=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],be={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,80,81,83,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],Ce=[2,12,13,14,15,16,17,18,19,20,21,80,81,83,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],Te=[33,99,100,32,102,8,9,10],ge=[0,16,25,40,32,64,26,48],m={};S.forEach((e,a)=>{m[e]=a});var u={length:_.length};_.forEach((e,a)=>{u[e]=a});var R={length:X.length};X.forEach((e,a)=>{R[e]=a});var Me={};xe.forEach((e,a)=>{Me[e]=a});var Re=function(e){let a=[],l=0;return e?.forEach(function(h,g){h==247?a.push(e.subarray(l,g)):h==240&&(l=g+1)}),a.length||a.push(e.subarray(0)),w()&&console.debug(a),a};var Ee=8,p={port:Ee,ch:Ee<<4,cc:_.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:X.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255},L={bank0:128},tt=class extends J{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;DUMP_ALL=0;DUMP_ONCE=1;DUMP_MODE=2;EXT_NONE=0;EXT_VL=1;EXT_DX=3;VLBC_BRTHEXPR=1;VLBC_VELOINIT=2;VLBC_VELOALL=3;CH_INACTIVE=0;CH_ACTIVE=1;CH_DISABLED=2;#t=0;#g=0;#M=0;#N=new Array(11);get#m(){return this.#N[this.#g]}set#m(e){this.#N[this.#g]=e}#S=new Uint8Array(p.ch);#f=new Uint8Array(p.ch);#r=new Uint8Array(p.ch);#e=new Uint8Array(p.ch*p.cc);#C=new Uint8Array(p.ace);#s=new Uint8Array(p.ch);#h=new Uint8Array(p.ch*p.nn);#$=new Uint8Array(p.ch);#u=new Uint16Array(p.pl);#b=new Uint8Array(p.pl);#H=new Int16Array(p.ch);#A=new Uint8Array(p.ch);#K=0;#v=new Uint8Array(p.ch*p.ext);#a=new Uint8Array(p.ch*p.rpn);#i=new Uint8Array(p.ch*p.rpnt);#te=new Int8Array(p.ch*pe.length);#y=new Uint8Array(p.drm*p.dpn*p.dnc);#R=new Uint8Array(p.drm*2);#k=new Uint8Array(p.efx*3);#ae=new Uint8Array(p.ch);#z=new Uint8Array(p.ch*p.redir);#l=new Uint8Array(p.port);#B=new Uint8Array(p.ch);#D=new Uint8Array(p.ch);#ne=new Uint8Array(p.ch*p.cvn);#_=new Uint8Array(128);#P=new Uint8Array(p.cmt*8);#re=new Uint8Array(1024);#G=new Uint8Array(p.cmt*64);#p={};#c;#L;#oe;#n=100;#q=0;#se=500;#ie=0;#X="";#V=0;#le=0;#ce=0;#O=!0;#o=!1;#he=1;#de;#W=new Array(p.ch);#pe=new Uint8Array(2);#w=[];#I=new Uint8Array(p.ch);#F=new Uint8Array(p.tr);baseBank=new F("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es");userBank=new F("gm");initOnReset=!1;aiEfxName="";chRedir(e,a,l){let h=this;if(h.#F[a])return(h.#F[a]-1)*16+e;if(h.#t==m.sc){if(l==1)return e;let g=0,E=!0;for(;E;)h.#I[e+g]==0?(h.#I[e+g]=a,console.debug(`Assign track ${a} to channel ${e+g+1}.`),E=!1):this.#I[e+g]==a?E=!1:(g+=16,g>=128&&(g=0,E=!1));return e+g}else return e}getTrackPort(e){return this.chRedir(0,e,!0)>>4}forceVoiceRefresh(){for(let e=0;e{let l=e*128+a,h=this.#u.lastIndexOf(l);if(h>-1)if(this.#e[p.cc*e+u[64]]>63)this.#b[h]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:a,velo:this.#h[l],state:this.NOTE_HELD});else if(this.#e[p.cc*e+u[66]]>63&&this.#b[h]==this.NOTE_SOSTENUTO_SUSTAIN)this.#b[h]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:a,velo:this.#h[l],state:this.NOTE_SOSTENUTO_HELD});else{this.#u[h]=0,this.#h[l]=0,this.#b[h]=this.NOTE_IDLE;let g=this.getExt(e)[1];(g==this.VLBC_VELOINIT||g==this.VLBC_VELOALL)&&(this.#e[p.cc*e+u[129]]=0),this.dispatchEvent("note",{part:e,note:a,velo:0,state:this.NOTE_IDLE})}},nOn:(e,a,l)=>{let h=e*128+a,g=0;for(this.#$[e]&&this.#d.ano(e);this.#b[g]>0&&this.#u[g]!=h;)g++;if(g{},cAt:(e,a)=>{},hoOf:e=>{this.#b.forEach((a,l)=>{if(a==this.NOTE_HELD){let h=this.#u[l],g=h>>7;e==g&&(this.#b[l]=this.NOTE_IDLE,this.#u[l]=0,this.#h[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#b.forEach((a,l)=>{let h;switch(a){case this.NOTE_ATTACK:{h=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{h=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{h=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(h){this.#b[l]=h;let g=this.#u[l];this.dispatchEvent("note",{part:e,note:g&127,velo:this.#h[g],state:h})}})},soOf:e=>{this.#b.forEach((a,l)=>{if(a==this.NOTE_SOSTENUTO_HELD){let h=this.#u[l],g=h>>7;e==g&&(this.#b[l]=this.NOTE_IDLE,this.#u[l]=0,this.#h[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#u.forEach((a,l,h)=>{let g=a>>7,E=a&127;a==0&&this.#h[0]==0||g==e&&this.#d.nOff(g,E)})}};#fe={8:function(e){let a=e.channel,l=e.data[0];this.#d.nOff(a,l)},9:function(e){let a=e.channel,l=this;if(l.getChModeId(a)==m.xg&&l.#r[a]>1){let E=l.getChDrumFirstWrite(a);E[0]&&E[1]!=p.invalidCh&&!l.#S[a]&&(l.copyChSetup(E[1],a),l.dispatchEvent("voice",{part:a}),console.debug(`Part CH${a+1} copied from CH${E[1]}.`))}l.setChActive(a,1);let h=e.data[0],g=e.data[1];g>0?l.#d.nOn(a,h,g):l.#d.nOff(a,h)},10:function(e){let a=e.channel,l=a*128+e.data[0];this.#u.indexOf(l)>-1&&(this.#h[l]=data[1],this.getExt(a)[1]==this.VLBC_VELOALL&&(this.#e[p.cc*a+u[129]]=data[1]),this.dispatchEvent("note",{part:a,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let a=e.channel,l=this,h=this.#W[a],g=h[e.data[0]];g&&(e.data[0]=g),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case m.s90es:case m.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(a,1);break}e.data[1]&&this.setChActive(a,1);break}default:{this.setChActive(a,1);break}}})();let E=a*p.cc,v=a*p.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#d.ano(a),this.#H[a]=0,this.#e[E+u[1]]=0,this.#e[E+u[5]]=0,this.#e[E+u[64]]=0,this.#e[E+u[65]]=0,this.#e[E+u[66]]=0,this.#e[E+u[67]]=0,this.#e[E+u[11]]=127,this.#e[E+u[101]]=127,this.#e[E+u[100]]=127,this.#e[E+u[99]]=127,this.#e[E+u[98]]=127;return}case 123:{this.#d.ano(a);return}case 124:{this.#d.ano(a);return}case 125:{this.#d.ano(a);return}case 126:{this.#$[a]=1,this.#d.ano(a);return}case 127:{this.#$[a]=0,this.#d.ano(a);return}}if(u[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Ce.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(w()&&console.debug(`${S[this.#t]}, CH${a+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#r[a]>0&&(e.data[1]=this.#e[E],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==56?this.switchMode(this.#c.x5==82?"x5d":"05rw"):e.data[1]==62?this.switchMode(this.#c.x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(S[this.#c.ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==m.gs||this.#t==m.sc?e.data[1]<56&&this.#r[a]>0&&(e.data[1]=this.#e[E],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)):this.#t==m.gm&&(e.data[1]<48?this.#r[a]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${a+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0)),this.#t){case m.xg:{[79,95,126,127].indexOf(e.data[1])>-1?this.#r[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#r[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?this.#v[v]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?this.#v[v]=this.EXT_DX:this.#v[v]=this.EXT_NONE;break}case m["05rw"]:case m.x5d:case m.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#r[a]==this.CH_MELODIC&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):[80,81,82,83].indexOf(e.data[1])>-1||this.#r[a]!=this.CH_MELODIC&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#r[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#r[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m.g2:{e.data[1]==120?this.#r[a]==0&&(this.setChType(a,this.CH_DRUMS),console.debug(`CH${a+1} set to drums by MSB.`)):this.#r[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:a});break}case 2:{this.getExt(a)[1]==this.VLBC_BRTHEXPR&&(this.#e[E+u[129]]=e.data[1]);break}case 6:{if(this.#K){[m.xg,m.gs,m.sc,m.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${S[this.#t]}" mode, even when they are supported in Octavia.`);let $=this.#e[E+u[99]],t=this.#e[E+u[98]];if($==1){let r=Te.indexOf(t);if(r>-1)this.#e[E+u[71+r]]=e.data[1],w()&&console.debug(`Redirected NRPN 1 ${t} to cc${71+r}.`),this.dispatchEvent("cc",{part:a,cc:71+r,data:e.data[1]});else{let f=pe.indexOf(t);f>-1?this.#te[a*10+f]=e.data[1]-64:console.warn(`NRPN 0x01${t.toString(16).padStart(2,"0")} is not supported.`),w()&&console.debug(`CH${a+1} voice NRPN ${t} commit`)}}else{if(X.indexOf($)<0){let f=`NRPN 0x${$.toString(16).padStart(2,"0")}${t.toString(16).padStart(2,"0")} `;$==127?console.warn(`${f}is not necessary. Consider removing it.`):console.warn(`${f}is not supported.`)}else{let f=this.#r[a]-2;f<0?console.warn(`CH${a+1} cannot accept drum NRPN as type ${I[this.#r[a]]}.`):this.#y[(f*p.dpn+R[$])*p.dnc+t]=e.data[1]}w()&&console.debug(`CH${a+1} (${I[this.#r[a]]}) drum NRPN ${$} commit`)}}else{let $=fe[this.#e[E+u[100]]],t=he[this.#e[E+u[100]]];this.#e[E+u[101]]==0&&$!=null&&(w()&&console.debug(`CH${a+1} RPN 0 ${this.#e[E+u[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],ue[$][0]),ue[$][1]),this.#a[a*p.rpn+$]=e.data[1],this.#i[a*p.rpnt+t]=1,this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)}))}break}case 32:{switch(w()&&console.debug(`${S[this.#t]}, CH${a+1} LSB: ${e.data[1]}`),this.#t){case m.s90es:case m.motif:{this.setChType(a,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.getExt(a)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:a});break}case 38:{if(!this.#K){let $=fe[this.#e[E+100]],t=he[this.#e[E+100]];this.#e[E+101]==0&&$!=null&&(this.#a[a*p.rpn+$+1]=e.data[1],this.#i[a*p.rpnt+t]=1)}break}case 64:{e.data[1]<64&&this.#d.hoOf(a);break}case 66:{e.data[1]>>6?this.#d.soOn(a):this.#d.soOf(a);break}case 98:case 99:{this.#K=1;break}case 100:case 101:{this.#K=0;break}}this.#e[E+u[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:a,cc:e.data[0],data:e.data[1]})}l.getChModeId(a)==m.xg&&l.#r[a]&&l.setDrumFirstWrite(a)},12:function(e){let a=e.channel,l=this;switch(l.#t){case m.s90es:case m.motif:{e.data&&l.setChActive(a,1);break}default:l.setChActive(a,1)}if(l.getExt(a)[0]==l.EXT_DX){let h=p.cc*a}l.#s[a]=e.data,l.#D[a]=0,w()&&console.debug(`T:${e.track} C:${a} P:${e.data}`),l.dispatchEvent("voice",{part:a}),l.getChModeId(a)==m.xg&&l.#r[a]&&l.setDrumFirstWrite(a)},13:function(e){let a=this,l=e.channel;this.#u.forEach(function(h){let g=h>>7;l==g&&(a.#h[h]=e.data,a.dispatchEvent("note",{part:l,note:h&127,velo:e.data,state:a.NOTE_SUSTAIN}))})},14:function(e){let a=e.channel;this.#H[a]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)})},15:function(e){Re(e.data).forEach(a=>{let l=a[0],h=a[1];(this.#ue[l]||function(){console.debug(`Unknown manufacturer ${l}.`)})(h,a.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#E[e.meta]||function(l,h,g){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#q=0);let a=Se.indexOf(e.meta)>-1;if(w()&&console.debug(e),a)return e.reply="meta",e}};#ue={64:(e,a,l)=>{this.#j.run(a,l,e)},65:(e,a,l)=>{if(a[0]<16)if(a[1]==72){let h=a[a.length-1],g=O(a.subarray(3,a.length-1));h==g?this.#T.run(a.subarray(0,a.length-1),l,e):console.warn(`Bad SD checksum ${h} - should be ${g}.`)}else this.#T.run(a,l,e);else{let h=a[a.length-1],g=O(a.subarray(2,a.length-1));h==g?this.#T.run(a.subarray(0,a.length-1),l,e):console.warn(`Bad GS checksum ${h} - should be ${g}.`)}},66:(e,a,l)=>{this.#U.run(a,l,e)},67:(e,a,l)=>{this.#x.run(a,l,e)},68:(e,a,l)=>{this.#ee.run(a,l,e)},71:(e,a,l)=>{this.#Z.run(a,l,e)},126:(e,a,l)=>{this.#Y.run(a,l,e)},127:(e,a,l)=>{this.switchMode("gm"),this.#J.run(a,l,e)}};#Y;#J;#x;#T;#U;#j;#Z;#ee;buildRchTree(){let e=[];this.#f.forEach((a,l)=>{a{a&&(e.#W[Math.floor(l/p.redir)][a]=l%p.redir|128)}),w()&&console.debug(e.#W)}getActive(){return this.#S}getCc(e){let a=this,l=e*p.cc,h=a.#e.subarray(l,l+p.cc);return h[u[0]]=h[u[0]]||a.#p[a.getChModeId(e)][0],h[u[32]]=h[u[32]]||a.#p[a.getChModeId(e)][1],h[u[0]]==L.bank0&&(h[u[0]]=0),h}getCcCh(e,a){let l=this;if(_.indexOf(a)<0)throw new Error("CC number not accepted");let h=l.#e[p.cc*e+u[a]];switch(a){case 0:{h=h||l.#p[l.getChModeId(e)][0],h==L.bank0&&(h=0);break}case 32:{h=h||l.#p[l.getChModeId(e)][1];break}}return h}getCcAll(){let e=this,a=e.#e.slice();for(let l=0;l0&&!h&&(this.#e[e*p.cc+u[0]]=Q[l])}setChActive(e,a=0){this.#S[e]!=a&&this.dispatchEvent("channeltoggle",{part:e,active:a}),this.#S[e]=a}getExt(e){let a=p.ext*e,l=this.#v.subarray(a,a+p.ext),h=new Uint8Array(l.length);return h.set(l),h[1]=h[1]||this.#he,h}getPitch(){return this.#H}getProgram(){return this.#s}getTexts(){return this.#w.slice()}getVel(e){let a=new Map,l=this;return l.#u.forEach(function(h,g){let E=Math.floor(h/128),v=h%128;e==E&&l.#h[h]>0&&a.set(v,{v:l.#h[h],s:l.#b[g]})}),a}getBitmap(){return{bitmap:this.#m,expire:this.#M}}getLetter(){return{text:this.#X,set:this.#le,expire:this.#V}}getMode(){return S[this.#t]}getMaster(){return{volume:this.#n}}getRawStrength(){let e=this;return this.#u.forEach(function(a){let l=Math.floor(a/128);e.#h[a]>e.#A[l]&&(e.#A[l]=e.#h[a])}),this.#A}getStrength(){let e=[],a=this;return this.getRawStrength().forEach(function(l,h){e[h]=Math.floor(l*a.#e[h*p.cc+u[7]]*a.#e[h*p.cc+u[11]]*a.#n/803288)}),e}getRpn(){return this.#a}getNrpn(){return this.#te}getVoice(e,a,l,h){let g=this,E=e||g.#p[g.#t][0],v=a,$=l||g.#p[g.#t][1];E==L.bank0&&(E=0),S[g.#t]=="ns5r"&&E>0&&E<56&&($=3);let t=g.userBank.get(E,v,$,h);if(S[g.#t]=="mt32"&&t.name.indexOf("MT-m:")==0){let r=parseInt(t.name.slice(5)),f=r*p.cmt,s="";g.#G.subarray(f,f+10).forEach(n=>{n>31&&(s+=String.fromCharCode(n))});let i=`MSB LSB PRG NME -0 127 ${v} ${s}`;g.userBank.load(i,!0),t.name=s,t.ending=" "}return(t.ending!=" "||!t.name.length)&&(t=g.baseBank.get(E,v,$,h)),t}getChVoice(e){let a=this,l=a.getVoice(a.getCcCh(e,0),a.#s[e],a.getCcCh(e,32),a.getChMode(e));if(a.#D[e]){let h="";switch(a.#t){case m.mt32:{a.#P.subarray(p.cmt*(e-1),p.cmt*(e-1)+10).forEach(g=>{h+=String.fromCharCode(Math.max(g,32))}),h=h.trimRight();break}default:{let g=p.cvn*e;a.#ne.subarray(g,g+p.cvn).forEach(E=>{h+=String.fromCharCode(Math.max(E,32))}),h=h.trimRight()}}h.length&&(l.ending="~",l.name=h)}return l}getRawPitch(){return this.#H}getPitchShift(e){let a=this,l=e*p.rpn,h=a.#a[l];return a.#i[e*p.rpnt]||a.#t==m.mt32&&(h=12),a.#H[e]/8192*h+(a.#a[l+3]-64)+((a.#a[l+1]<<7)+a.#a[l+2]-8192)/8192}getEffectType(e=0){let a=3*e+1;return this.#k.subarray(a,a+2)}setEffectTypeRaw(e=0,a,l){let h=3*e;this.#k[h]=1,this.#k[h+1+ +a]=l}setEffectType(e=0,a,l){this.setEffectTypeRaw(e,!1,a),this.setEffectTypeRaw(e,!0,l)}getEffectSink(){return this.#ae}setLetterDisplay(e,a,l=0,h=3200){let g=this,E;g.#X=" ".repeat(l),e.forEach(v=>{g.#X+=String.fromCharCode(v>31?v:32),v<32&&(E=E||new Set,E.add(v))}),g.#le=Date.now(),g.#V=Date.now()+h,E&&(E=Array.from(E),E.forEach((v,$,t)=>{t[$]=v.toString(16).padStart(2,"0")}),console.warn(`${a}${a?" ":""}invalid code point${E.length>1?"s":""}: 0x${E.join(", 0x")}`))}setDetectionTargets(e="?",a=0){let l=this,h=-1;switch(e.replaceAll(", ",",").split(",").forEach(g=>{g=g.toLowerCase();let E=S.indexOf(we[g]||g);w()&&console.debug(`Mapped mode "${g}" to ID "${E}".`),E>-1&&(h=E)}),w()&&console.debug(`Set detection target to ID "${h}".`),h>0&&(l.#c.x5=82,l.#c.ds=m.krs),h){case m["05rw"]:{l.#c.x5=81;break}case m.s90es:l.#c.ds=m.s90es,l.#c.smotif=m.s90es;case m.motif:l.#c.ds=m.motif,l.#c.smotif=m.motif}}setGsTargets(e=!1,a=4){if(!a)a=e?3:4;else{if(a>4||a<0)throw new Error(`Invalid GS level ${a}`);if(e&&a>>1!=1)throw new Error(`Invalid SC level ${a}`)}let l=this;l.#c[e?"sc":"gs"]=a,l.#p[m[e?"sc":"gs"]][1]=a,l.forceVoiceRefresh()}getConfigs(){return this.#oe}setDumpLimit(e){if(e>2||e<0)throw new RangeError("Invalid dump limit.");this.#L.dumpLimit=e}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let a=!0,l=0;for(;a&&l=p.ace&&console.warn("ACE slots are full.")}releaseAce(e){let a=!0,l=0;for(;a&&l=p.ace)throw new RangeError("No such ACE slot");let l=this.#C[a];if(l){if(_.indexOf(l)>=0)return this.#e[e*p.cc+u[l]];throw new Error(`Invalid ACE source: ${l}`)}else return 0}initDrums(){let e=this;e.#y.fill(64);for(let a=0;a{a.#e[p.cc*l]=Q[0]}),a.#r.fill(a.CH_MELODIC),a.#r[9]=a.CH_DRUM1,a.#r[25]=a.CH_DRUM3,a.#r[41]=a.CH_DRUMS,a.#r[57]=a.CH_DRUMS,a.#r[73]=a.CH_DRUM5,a.#r[89]=a.CH_DRUM7,a.#r[105]=a.CH_DRUMS,a.#r[121]=a.CH_DRUMS;for(let l=0;l=p.ch)throw new RangeError(`Invalid CH${e+1}`);if(port<0||a>=S.length)throw new RangeError(`Invalid mode ID ${a}`);l.#B[e]=a,l.dispatchEvent("voice",{part:e})}getChMode(e,a){return S[this.getChModeId(e,a)]}getChModeId(e,a){return a?this.#B[e]||this.#l[e>>4]:this.#B[e]||this.#l[e>>4]||this.#t}setPortMode(e,a,l){let h=this;if(e<0||e>=p.ch>>4)throw new RangeError(`Invalid port ${e+1}`);if(a<1)throw new RangeError("Range must be a positive integer");if(e+a>=p.ch>>4)throw new RangeError("Range must be in bound");if(e<0||l>=S.length)throw new RangeError(`Invalid mode ID ${l}`);for(let g=e;g=0&&e-1){if(h.#t==0||a){let E=h.#t;h.initOnReset&&a&&(this.init(1),E=m["?"]),h.#t=g,h.#g=0;for(let $=0;$0&&h.#B[$]==0&&(h.#e[$*p.cc]=Q[g]);switch(g){case m.mt32:{W.forEach(($,t)=>{let r=t+1;h.#S[r]||(h.#s[r]=$,h.#e[r*p.cc+u[91]]=127)});for(let $=1;$<10;$++)h.dispatchEvent("voice",{part:$});break}}let v;switch(g){case m["?"]:case m.g2:{v=[52,4,52,18,0,0,0,0];break}case m.xg:{v=[1,0,65,0,5,0,0,0];break}case m.gm:case m.gs:case m.sc:{v=[40,4,40,18,40,32,32,0];break}case m.sd:{v=[58,0,60,0,61,0,61,0];break}case m["05rw"]:case m.x5d:case m.ns5r:{v=[44,1,44,19,44,0,44,0];break}case m.k11:case m.sg:{v=[24,0,0,0,0,0,0,0];break}case m.mt32:{v=[40,4,0,0,0,0,0,0];break}case m.motif:case m.s90es:{v=[113,0,117,0,114,0,0,0];break}default:v=[0,0,0,0,0,0,0,0]}for(let $=0;${h.dispatchEvent("voice",{part:$})})}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#A.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#fe[e.type].call(this,e);{let a=this.chRedir(e.part,e.track),l=!1;this.#de[a]?.forEach(h=>{e.channel=h,l=!0,this.#fe[e.type].call(this,e)}),l||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${a+1} without any recipient.`)}this.#w.length>100&&this.#w.splice(100,this.#w.length-99)}runRaw(e){}async loadBank(e,a){let l=this;switch(e=e.toLowerCase(),e){case"s7e":{l.userBank.clearRange({msb:63,lsb:[21,22]}),l.userBank.clearRange({msb:63,lsb:[24,27]});break}case"pcg":{l.userBank.clearRange({msb:63,lsb:[6,9]}),l.userBank.clearRange({msb:63,lsb:[13,16]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":case"pcg":{N.context=this,await l.userBank.load(await N.read(e,a),!1);break}}l.forceVoiceRefresh()}constructor(){super();let e=this;e.#m=new Uint8Array(256),e.#N[10]=new Uint8Array(512),e.#Q=new T,e.#c={x5:82,ds:m.krs,smotif:m.s90es,gs:4,sc:3},e.#L={dumpLimit:e.DUMP_MODE},e.#oe=new Proxy(e.#L,{set:()=>{}});for(let t in oe){let r=m[t];r==null?console.debug(`SubDB build error: "${t}" does not exist`):e.#p[r]=new Uint8Array(oe[t])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let a=e.split(",");K[a[0]]=a[1]});var re=function(e){let a=e;e[0]=="*"&&(a=a.slice(1)),["aa","ii","uu","ee","oo"].forEach(h=>{for(;a.indexOf(h)>-1;)a=a.replace(h,h[0])});for(let h in K)a=a.replaceAll(h,K[h]);a.indexOf("ん")==0&&a.length>1&&(a=a.slice(1));let l=a.indexOf("!");return l>-1&&a.length>1&&(a=a.slice(l+1)),a},se=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var z=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],ie=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ce=["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 ve={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"},ke={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]]},q=function(e){return ve[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ne=function(e,a,l){let h=(e[0]-32<<16)+(e[1]<<8)+a,g=ke[h]||{},E=g[0];if(E?.length)return E+=`: ${(g[1]||function(){})(l)||l}`,E},W=[68,48,95,78,41,3,110,122,0];var C=function(e=64){return Math.round(2e3*Math.log10(e/64))/100};var O=function(e){let a=0;return e.forEach(l=>{a+=l,a=a&127}),~a+1&127},M=function(e,a){let l=0,h=0;for(let g=0;g>E&1)<<7,$=e[g];$+=v,g%8!=0?(a($,l,e),l++):h=e[g]}};var B=function(e){let a=Math.floor(e*14.2);return a<128?a:0},w=function(){return!!self.Bun||self.debugMode||!1};var S=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"],we={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",trinity:"trin","tr-rack":"trin"},xe=["melodic","drum","menu"],oe={"?":[0,0,120],gm:[0,0,127],gs:[0,0,120],sc:[0,0,120],xg:[0,0,127],g2:[0,0,120],mt32:[0,127,127],doc:[57,112,127],qy10:[57,113,127],qy20:[57,114,127],ns5r:[0,0,61],x5d:[82,0,62],"05rw":[81,0,62],k11:[0,0,122],sg:[0,0,122],sd:[97,0,105],krs:[63,0,120],s90es:[63,0,127],motif:[63,0,127],trin:[63,0,127]};var Q=[120,127,120,127,120,127,127,61,62,62,122,122,105,120,127,127,127],le=[9,25,41,57,73,89,105,121],Se=[0,3,81,84,88],de={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},fe={0:0,1:1,2:3,5:4},he={0:0,1:1,2:2,5:3},ue=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],pe=[36,37,48,49,52,53],X=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],be={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,80,81,83,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],Ce=[2,12,13,14,15,16,17,18,19,20,21,80,81,83,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],Te=[33,99,100,32,102,8,9,10],ge=[0,16,25,40,32,64,26,48],m={};S.forEach((e,a)=>{m[e]=a});var u={length:_.length};_.forEach((e,a)=>{u[e]=a});var R={length:X.length};X.forEach((e,a)=>{R[e]=a});var Me={};xe.forEach((e,a)=>{Me[e]=a});var Re=function(e){let a=[],l=0;return e?.forEach(function(h,g){h==247?a.push(e.subarray(l,g)):h==240&&(l=g+1)}),a.length||a.push(e.subarray(0)),w()&&console.debug(a),a};var Ee=8,p={port:Ee,ch:Ee<<4,cc:_.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:X.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255},L={bank0:128},tt=class extends j{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;DUMP_ALL=0;DUMP_ONCE=1;DUMP_MODE=2;EXT_NONE=0;EXT_VL=1;EXT_DX=3;VLBC_BRTHEXPR=1;VLBC_VELOINIT=2;VLBC_VELOALL=3;CH_INACTIVE=0;CH_ACTIVE=1;CH_DISABLED=2;#t=0;#g=0;#M=0;#N=new Array(11);get#m(){return this.#N[this.#g]}set#m(e){this.#N[this.#g]=e}#S=new Uint8Array(p.ch);#f=new Uint8Array(p.ch);#r=new Uint8Array(p.ch);#e=new Uint8Array(p.ch*p.cc);#C=new Uint8Array(p.ace);#s=new Uint8Array(p.ch);#h=new Uint8Array(p.ch*p.nn);#$=new Uint8Array(p.ch);#u=new Uint16Array(p.pl);#b=new Uint8Array(p.pl);#H=new Int16Array(p.ch);#A=new Uint8Array(p.ch);#K=0;#v=new Uint8Array(p.ch*p.ext);#a=new Uint8Array(p.ch*p.rpn);#i=new Uint8Array(p.ch*p.rpnt);#te=new Int8Array(p.ch*pe.length);#y=new Uint8Array(p.drm*p.dpn*p.dnc);#R=new Uint8Array(p.drm*2);#k=new Uint8Array(p.efx*3);#ae=new Uint8Array(p.ch);#z=new Uint8Array(p.ch*p.redir);#l=new Uint8Array(p.port);#B=new Uint8Array(p.ch);#D=new Uint8Array(p.ch);#ne=new Uint8Array(p.ch*p.cvn);#_=new Uint8Array(128);#P=new Uint8Array(p.cmt*8);#re=new Uint8Array(1024);#G=new Uint8Array(p.cmt*64);#p={};#c;#L;#oe;#n=100;#q=0;#se=500;#ie=0;#X="";#V=0;#le=0;#ce=0;#O=!0;#o=!1;#he=1;#de;#W=new Array(p.ch);#pe=new Uint8Array(2);#w=[];#I=new Uint8Array(p.ch);#F=new Uint8Array(p.tr);baseBank=new F("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es");userBank=new F("gm");initOnReset=!1;aiEfxName="";chRedir(e,a,l){let h=this;if(h.#F[a])return(h.#F[a]-1)*16+e;if(h.#t==m.sc){if(l==1)return e;let g=0,E=!0;for(;E;)h.#I[e+g]==0?(h.#I[e+g]=a,console.debug(`Assign track ${a} to channel ${e+g+1}.`),E=!1):this.#I[e+g]==a?E=!1:(g+=16,g>=128&&(g=0,E=!1));return e+g}else return e}getTrackPort(e){return this.chRedir(0,e,!0)>>4}forceVoiceRefresh(){for(let e=0;e{let l=e*128+a,h=this.#u.lastIndexOf(l);if(h>-1)if(this.#e[p.cc*e+u[64]]>63)this.#b[h]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:a,velo:this.#h[l],state:this.NOTE_HELD});else if(this.#e[p.cc*e+u[66]]>63&&this.#b[h]==this.NOTE_SOSTENUTO_SUSTAIN)this.#b[h]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:a,velo:this.#h[l],state:this.NOTE_SOSTENUTO_HELD});else{this.#u[h]=0,this.#h[l]=0,this.#b[h]=this.NOTE_IDLE;let g=this.getExt(e)[1];(g==this.VLBC_VELOINIT||g==this.VLBC_VELOALL)&&(this.#e[p.cc*e+u[129]]=0),this.dispatchEvent("note",{part:e,note:a,velo:0,state:this.NOTE_IDLE})}},nOn:(e,a,l)=>{let h=e*128+a,g=0;for(this.#$[e]&&this.#d.ano(e);this.#b[g]>0&&this.#u[g]!=h;)g++;if(g{},cAt:(e,a)=>{},hoOf:e=>{this.#b.forEach((a,l)=>{if(a==this.NOTE_HELD){let h=this.#u[l],g=h>>7;e==g&&(this.#b[l]=this.NOTE_IDLE,this.#u[l]=0,this.#h[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#b.forEach((a,l)=>{let h;switch(a){case this.NOTE_ATTACK:{h=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{h=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{h=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(h){this.#b[l]=h;let g=this.#u[l];this.dispatchEvent("note",{part:e,note:g&127,velo:this.#h[g],state:h})}})},soOf:e=>{this.#b.forEach((a,l)=>{if(a==this.NOTE_SOSTENUTO_HELD){let h=this.#u[l],g=h>>7;e==g&&(this.#b[l]=this.NOTE_IDLE,this.#u[l]=0,this.#h[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#u.forEach((a,l,h)=>{let g=a>>7,E=a&127;a==0&&this.#h[0]==0||g==e&&this.#d.nOff(g,E)})}};#fe={8:function(e){let a=e.channel,l=e.data[0];this.#d.nOff(a,l)},9:function(e){let a=e.channel,l=this;if(l.getChModeId(a)==m.xg&&l.#r[a]>1){let E=l.getChDrumFirstWrite(a);E[0]&&E[1]!=p.invalidCh&&!l.#S[a]&&(l.copyChSetup(E[1],a),l.dispatchEvent("voice",{part:a}),console.debug(`Part CH${a+1} copied from CH${E[1]}.`))}l.setChActive(a,1);let h=e.data[0],g=e.data[1];g>0?l.#d.nOn(a,h,g):l.#d.nOff(a,h)},10:function(e){let a=e.channel,l=a*128+e.data[0];this.#u.indexOf(l)>-1&&(this.#h[l]=data[1],this.getExt(a)[1]==this.VLBC_VELOALL&&(this.#e[p.cc*a+u[129]]=data[1]),this.dispatchEvent("note",{part:a,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let a=e.channel,l=this,h=this.#W[a],g=h[e.data[0]];g&&(e.data[0]=g),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case m.s90es:case m.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(a,1);break}e.data[1]&&this.setChActive(a,1);break}default:{this.setChActive(a,1);break}}})();let E=a*p.cc,v=a*p.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#d.ano(a),this.#H[a]=0,this.#e[E+u[1]]=0,this.#e[E+u[5]]=0,this.#e[E+u[64]]=0,this.#e[E+u[65]]=0,this.#e[E+u[66]]=0,this.#e[E+u[67]]=0,this.#e[E+u[11]]=127,this.#e[E+u[101]]=127,this.#e[E+u[100]]=127,this.#e[E+u[99]]=127,this.#e[E+u[98]]=127;return}case 123:{this.#d.ano(a);return}case 124:{this.#d.ano(a);return}case 125:{this.#d.ano(a);return}case 126:{this.#$[a]=1,this.#d.ano(a);return}case 127:{this.#$[a]=0,this.#d.ano(a);return}}if(u[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Ce.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(w()&&console.debug(`${S[this.#t]}, CH${a+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#r[a]>0&&(e.data[1]=this.#e[E],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==56?this.switchMode(this.#c.x5==82?"x5d":"05rw"):e.data[1]==62?this.switchMode(this.#c.x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(S[this.#c.ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==m.gs||this.#t==m.sc?e.data[1]<56&&this.#r[a]>0&&(e.data[1]=this.#e[E],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)):this.#t==m.gm&&(e.data[1]<48?this.#r[a]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${a+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0)),this.#t){case m.xg:{[79,95,126,127].indexOf(e.data[1])>-1?this.#r[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#r[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?this.#v[v]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?this.#v[v]=this.EXT_DX:this.#v[v]=this.EXT_NONE;break}case m["05rw"]:case m.x5d:case m.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#r[a]==this.CH_MELODIC&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):[80,81,82,83].indexOf(e.data[1])>-1||this.#r[a]!=this.CH_MELODIC&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#r[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#r[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m.g2:{e.data[1]==120?this.#r[a]==0&&(this.setChType(a,this.CH_DRUMS),console.debug(`CH${a+1} set to drums by MSB.`)):this.#r[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:a});break}case 2:{this.getExt(a)[1]==this.VLBC_BRTHEXPR&&(this.#e[E+u[129]]=e.data[1]);break}case 6:{if(this.#K){[m.xg,m.gs,m.sc,m.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${S[this.#t]}" mode, even when they are supported in Octavia.`);let $=this.#e[E+u[99]],t=this.#e[E+u[98]];if($==1){let r=Te.indexOf(t);if(r>-1)this.#e[E+u[71+r]]=e.data[1],w()&&console.debug(`Redirected NRPN 1 ${t} to cc${71+r}.`),this.dispatchEvent("cc",{part:a,cc:71+r,data:e.data[1]});else{let d=pe.indexOf(t);d>-1?this.#te[a*10+d]=e.data[1]-64:console.warn(`NRPN 0x01${t.toString(16).padStart(2,"0")} is not supported.`),w()&&console.debug(`CH${a+1} voice NRPN ${t} commit`)}}else{if(X.indexOf($)<0){let d=`NRPN 0x${$.toString(16).padStart(2,"0")}${t.toString(16).padStart(2,"0")} `;$==127?console.warn(`${d}is not necessary. Consider removing it.`):console.warn(`${d}is not supported.`)}else{let d=this.#r[a]-2;d<0?console.warn(`CH${a+1} cannot accept drum NRPN as type ${I[this.#r[a]]}.`):this.#y[(d*p.dpn+R[$])*p.dnc+t]=e.data[1]}w()&&console.debug(`CH${a+1} (${I[this.#r[a]]}) drum NRPN ${$} commit`)}}else{let $=fe[this.#e[E+u[100]]],t=he[this.#e[E+u[100]]];this.#e[E+u[101]]==0&&$!=null&&(w()&&console.debug(`CH${a+1} RPN 0 ${this.#e[E+u[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],ue[$][0]),ue[$][1]),this.#a[a*p.rpn+$]=e.data[1],this.#i[a*p.rpnt+t]=1,this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)}))}break}case 32:{switch(w()&&console.debug(`${S[this.#t]}, CH${a+1} LSB: ${e.data[1]}`),this.#t){case m.s90es:case m.motif:{this.setChType(a,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.getExt(a)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:a});break}case 38:{if(!this.#K){let $=fe[this.#e[E+100]],t=he[this.#e[E+100]];this.#e[E+101]==0&&$!=null&&(this.#a[a*p.rpn+$+1]=e.data[1],this.#i[a*p.rpnt+t]=1)}break}case 64:{e.data[1]<64&&this.#d.hoOf(a);break}case 66:{e.data[1]>>6?this.#d.soOn(a):this.#d.soOf(a);break}case 98:case 99:{this.#K=1;break}case 100:case 101:{this.#K=0;break}}this.#e[E+u[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:a,cc:e.data[0],data:e.data[1]})}l.getChModeId(a)==m.xg&&l.#r[a]&&l.setDrumFirstWrite(a)},12:function(e){let a=e.channel,l=this;switch(l.#t){case m.s90es:case m.motif:{e.data&&l.setChActive(a,1);break}default:l.setChActive(a,1)}if(l.getExt(a)[0]==l.EXT_DX){let h=p.cc*a}l.#s[a]=e.data,l.#D[a]=0,w()&&console.debug(`T:${e.track} C:${a} P:${e.data}`),l.dispatchEvent("voice",{part:a}),l.getChModeId(a)==m.xg&&l.#r[a]&&l.setDrumFirstWrite(a)},13:function(e){let a=this,l=e.channel;this.#u.forEach(function(h){let g=h>>7;l==g&&(a.#h[h]=e.data,a.dispatchEvent("note",{part:l,note:h&127,velo:e.data,state:a.NOTE_SUSTAIN}))})},14:function(e){let a=e.channel;this.#H[a]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)})},15:function(e){Re(e.data).forEach(a=>{let l=a[0],h=a[1];(this.#ue[l]||function(){console.debug(`Unknown manufacturer ${l}.`)})(h,a.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#E[e.meta]||function(l,h,g){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#q=0);let a=Se.indexOf(e.meta)>-1;if(w()&&console.debug(e),a)return e.reply="meta",e}};#ue={64:(e,a,l)=>{this.#J.run(a,l,e)},65:(e,a,l)=>{if(a[0]<16)if(a[1]==72){let h=a[a.length-1],g=O(a.subarray(3,a.length-1));h==g?this.#T.run(a.subarray(0,a.length-1),l,e):console.warn(`Bad SD checksum ${h} - should be ${g}.`)}else this.#T.run(a,l,e);else{let h=a[a.length-1],g=O(a.subarray(2,a.length-1));h==g?this.#T.run(a.subarray(0,a.length-1),l,e):console.warn(`Bad GS checksum ${h} - should be ${g}.`)}},66:(e,a,l)=>{this.#U.run(a,l,e)},67:(e,a,l)=>{this.#x.run(a,l,e)},68:(e,a,l)=>{this.#ee.run(a,l,e)},71:(e,a,l)=>{this.#Z.run(a,l,e)},126:(e,a,l)=>{this.#Y.run(a,l,e)},127:(e,a,l)=>{this.switchMode("gm"),this.#j.run(a,l,e)}};#Y;#j;#x;#T;#U;#J;#Z;#ee;buildRchTree(){let e=[];this.#f.forEach((a,l)=>{a{a&&(e.#W[Math.floor(l/p.redir)][a]=l%p.redir|128)}),w()&&console.debug(e.#W)}getActive(){return this.#S}getCc(e){let a=this,l=e*p.cc,h=a.#e.subarray(l,l+p.cc);return h[u[0]]=h[u[0]]||a.#p[a.getChModeId(e)][0],h[u[32]]=h[u[32]]||a.#p[a.getChModeId(e)][1],h[u[0]]==L.bank0&&(h[u[0]]=0),h}getCcCh(e,a){let l=this;if(_.indexOf(a)<0)throw new Error("CC number not accepted");let h=l.#e[p.cc*e+u[a]];switch(a){case 0:{h=h||l.#p[l.getChModeId(e)][0],h==L.bank0&&(h=0);break}case 32:{h=h||l.#p[l.getChModeId(e)][1];break}}return h}getCcAll(){let e=this,a=e.#e.slice();for(let l=0;l0&&!h&&(this.#e[e*p.cc+u[0]]=Q[l])}setChActive(e,a=0){this.#S[e]!=a&&this.dispatchEvent("channeltoggle",{part:e,active:a}),this.#S[e]=a}getExt(e){let a=p.ext*e,l=this.#v.subarray(a,a+p.ext),h=new Uint8Array(l.length);return h.set(l),h[1]=h[1]||this.#he,h}getPitch(){return this.#H}getProgram(){return this.#s}getTexts(){return this.#w.slice()}getVel(e){let a=new Map,l=this;return l.#u.forEach(function(h,g){let E=Math.floor(h/128),v=h%128;e==E&&l.#h[h]>0&&a.set(v,{v:l.#h[h],s:l.#b[g]})}),a}getBitmap(){return{bitmap:this.#m,expire:this.#M}}getLetter(){return{text:this.#X,set:this.#le,expire:this.#V}}getMode(){return S[this.#t]}getMaster(){return{volume:this.#n}}getRawStrength(){let e=this;return this.#u.forEach(function(a){let l=Math.floor(a/128);e.#h[a]>e.#A[l]&&(e.#A[l]=e.#h[a])}),this.#A}getStrength(){let e=[],a=this;return this.getRawStrength().forEach(function(l,h){e[h]=Math.floor(l*a.#e[h*p.cc+u[7]]*a.#e[h*p.cc+u[11]]*a.#n/803288)}),e}getRpn(){return this.#a}getNrpn(){return this.#te}getVoice(e,a,l,h){let g=this,E=e||g.#p[g.#t][0],v=a,$=l||g.#p[g.#t][1];E==L.bank0&&(E=0),S[g.#t]=="ns5r"&&E>0&&E<56&&($=3);let t=g.userBank.get(E,v,$,h);if(S[g.#t]=="mt32"&&t.name.indexOf("MT-m:")==0){let r=parseInt(t.name.slice(5)),d=r*p.cmt,s="";g.#G.subarray(d,d+10).forEach(n=>{n>31&&(s+=String.fromCharCode(n))});let i=`MSB LSB PRG NME +0 127 ${v} ${s}`;g.userBank.load(i,!0),t.name=s,t.ending=" "}return(t.ending!=" "||!t.name.length)&&(t=g.baseBank.get(E,v,$,h)),t}getChVoice(e){let a=this,l=a.getVoice(a.getCcCh(e,0),a.#s[e],a.getCcCh(e,32),a.getChMode(e));if(a.#D[e]){let h="";switch(a.#t){case m.mt32:{a.#P.subarray(p.cmt*(e-1),p.cmt*(e-1)+10).forEach(g=>{h+=String.fromCharCode(Math.max(g,32))}),h=h.trimRight();break}default:{let g=p.cvn*e;a.#ne.subarray(g,g+p.cvn).forEach(E=>{h+=String.fromCharCode(Math.max(E,32))}),h=h.trimRight()}}h.length&&(l.ending="~",l.name=h)}return l}getRawPitch(){return this.#H}getPitchShift(e){let a=this,l=e*p.rpn,h=a.#a[l];return a.#i[e*p.rpnt]||a.#t==m.mt32&&(h=12),a.#H[e]/8192*h+(a.#a[l+3]-64)+((a.#a[l+1]<<7)+a.#a[l+2]-8192)/8192}getEffectType(e=0){let a=3*e+1;return this.#k.subarray(a,a+2)}setEffectTypeRaw(e=0,a,l){let h=3*e;this.#k[h]=1,this.#k[h+1+ +a]=l}setEffectType(e=0,a,l){this.setEffectTypeRaw(e,!1,a),this.setEffectTypeRaw(e,!0,l)}getEffectSink(){return this.#ae}setLetterDisplay(e,a,l=0,h=3200){let g=this,E;g.#X=" ".repeat(l),e.forEach(v=>{g.#X+=String.fromCharCode(v>31?v:32),v<32&&(E=E||new Set,E.add(v))}),g.#le=Date.now(),g.#V=Date.now()+h,E&&(E=Array.from(E),E.forEach((v,$,t)=>{t[$]=v.toString(16).padStart(2,"0")}),console.warn(`${a}${a?" ":""}invalid code point${E.length>1?"s":""}: 0x${E.join(", 0x")}`))}setDetectionTargets(e="?",a=0){let l=this,h=-1;switch(e.replaceAll(", ",",").split(",").forEach(g=>{g=g.toLowerCase();let E=S.indexOf(we[g]||g);w()&&console.debug(`Mapped mode "${g}" to ID "${E}".`),E>-1&&(h=E)}),w()&&console.debug(`Set detection target to ID "${h}".`),h>0&&(l.#c.x5=82,l.#c.ds=m.krs),h){case m["05rw"]:{l.#c.x5=81;break}case m.s90es:l.#c.ds=m.s90es,l.#c.smotif=m.s90es;case m.motif:l.#c.ds=m.motif,l.#c.smotif=m.motif}}setGsTargets(e=!1,a=4){if(!a)a=e?3:4;else{if(a>4||a<0)throw new Error(`Invalid GS level ${a}`);if(e&&a>>1!=1)throw new Error(`Invalid SC level ${a}`)}let l=this;l.#c[e?"sc":"gs"]=a,l.#p[m[e?"sc":"gs"]][1]=a,l.forceVoiceRefresh()}getConfigs(){return this.#oe}setDumpLimit(e){if(e>2||e<0)throw new RangeError("Invalid dump limit.");this.#L.dumpLimit=e}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let a=!0,l=0;for(;a&&l=p.ace&&console.warn("ACE slots are full.")}releaseAce(e){let a=!0,l=0;for(;a&&l=p.ace)throw new RangeError("No such ACE slot");let l=this.#C[a];if(l){if(_.indexOf(l)>=0)return this.#e[e*p.cc+u[l]];throw new Error(`Invalid ACE source: ${l}`)}else return 0}initDrums(){let e=this;e.#y.fill(64);for(let a=0;a{a.#e[p.cc*l]=Q[0]}),a.#r.fill(a.CH_MELODIC),a.#r[9]=a.CH_DRUM1,a.#r[25]=a.CH_DRUM3,a.#r[41]=a.CH_DRUMS,a.#r[57]=a.CH_DRUMS,a.#r[73]=a.CH_DRUM5,a.#r[89]=a.CH_DRUM7,a.#r[105]=a.CH_DRUMS,a.#r[121]=a.CH_DRUMS;for(let l=0;l=p.ch)throw new RangeError(`Invalid CH${e+1}`);if(port<0||a>=S.length)throw new RangeError(`Invalid mode ID ${a}`);l.#B[e]=a,l.dispatchEvent("voice",{part:e})}getChMode(e,a){return S[this.getChModeId(e,a)]}getChModeId(e,a){return a?this.#B[e]||this.#l[e>>4]:this.#B[e]||this.#l[e>>4]||this.#t}setPortMode(e,a,l){let h=this;if(e<0||e>=p.ch>>4)throw new RangeError(`Invalid port ${e+1}`);if(a<1)throw new RangeError("Range must be a positive integer");if(e+a>=p.ch>>4)throw new RangeError("Range must be in bound");if(e<0||l>=S.length)throw new RangeError(`Invalid mode ID ${l}`);for(let g=e;g=0&&e-1){if(h.#t==0||a){let E=h.#t;h.initOnReset&&a&&(this.init(1),E=m["?"]),h.#t=g,h.#g=0;for(let $=0;$0&&h.#B[$]==0&&(h.#e[$*p.cc]=Q[g]);switch(g){case m.mt32:{W.forEach(($,t)=>{let r=t+1;h.#S[r]||(h.#s[r]=$,h.#e[r*p.cc+u[91]]=127)});for(let $=1;$<10;$++)h.dispatchEvent("voice",{part:$});break}}let v;switch(g){case m["?"]:case m.g2:{v=[52,4,52,18,0,0,0,0];break}case m.xg:{v=[1,0,65,0,5,0,0,0];break}case m.gm:case m.gs:case m.sc:{v=[40,4,40,18,40,32,32,0];break}case m.sd:{v=[58,0,60,0,61,0,61,0];break}case m["05rw"]:case m.x5d:case m.ns5r:{v=[44,1,44,19,44,0,44,0];break}case m.k11:case m.sg:{v=[24,0,0,0,0,0,0,0];break}case m.mt32:{v=[40,4,0,0,0,0,0,0];break}case m.doc:{v=[24,16,0,0,0,0,0,0];break}case m.motif:case m.s90es:{v=[113,0,117,0,114,0,0,0];break}default:v=[0,0,0,0,0,0,0,0]}for(let $=0;${h.dispatchEvent("voice",{part:$})})}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#A.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#fe[e.type].call(this,e);{let a=this.chRedir(e.part,e.track),l=!1;this.#de[a]?.forEach(h=>{e.channel=h,l=!0,this.#fe[e.type].call(this,e)}),l||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${a+1} without any recipient.`)}this.#w.length>100&&this.#w.splice(100,this.#w.length-99)}runRaw(e){}async loadBank(e,a){let l=this;switch(e=e.toLowerCase(),e){case"s7e":{l.userBank.clearRange({msb:63,lsb:[21,22]}),l.userBank.clearRange({msb:63,lsb:[24,27]});break}case"pcg":{l.userBank.clearRange({msb:63,lsb:[6,9]}),l.userBank.clearRange({msb:63,lsb:[13,16]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":case"pcg":{N.context=this,await l.userBank.load(await N.read(e,a),!1);break}}l.forceVoiceRefresh()}constructor(){super();let e=this;e.#m=new Uint8Array(256),e.#N[10]=new Uint8Array(512),e.#Q=new T,e.#c={x5:82,ds:m.krs,smotif:m.s90es,gs:4,sc:3},e.#L={dumpLimit:e.DUMP_MODE},e.#oe=new Proxy(e.#L,{set:()=>{}});for(let t in oe){let r=m[t];r==null?console.debug(`SubDB build error: "${t}" does not exist`):e.#p[r]=new Uint8Array(oe[t])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -153,20 +153,20 @@ _,`.split(` 122 006 000 `),e.addEventListener("metacommit",function(t){let{data:r}=t;e.#w[0]?.type==r.type&&e.#w[0]?.amend?(e.#w[0].amend=r.amend,e.#w[0].data+=r.data):e.#w.unshift(r)}),e.#E[1]=function(t){switch(t=t.replaceAll(`\r `,` `).replaceAll("\r",` -`),t.slice(0,2)){case"@I":{this.#o=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:t.slice(2)?.trimLeft()});break}case"@K":{this.#o=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:t.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#o=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:t.slice(2)?.trimLeft()});break}case"@T":{this.#o=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:t.slice(2)?.trimLeft()});break}case"@V":{this.#o=!0,this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:t.slice(2)?.trimLeft()});break}case"XF":{let r=t.slice(2).split(":");switch(r[0]){case"hd":{r.slice(1).forEach((f,s)=>{f.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][s],data:f})});break}case"ln":{r.slice(1).forEach((f,s)=>{f.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][s],data:f})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:t})}break}default:this.#o?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((r,f)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:r,mask:f!=0})})}},e.#E[2]=function(t){this.dispatchEvent("metacommit",{type:"Copyrite",data:t})},e.#E[3]=function(t,r){r<1&&this.#q<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:t})},e.#E[4]=function(t,r){this.dispatchEvent("metacommit",{type:"Instrmnt",data:t})},e.#E[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.#E[6]=function(t){this.dispatchEvent("metacommit",{type:"C.Marker",data:t})},e.#E[7]=function(t){this.dispatchEvent("metacommit",{type:"CuePoint",data:t})},e.#E[32]=function(t){this.#q=t[0]+1},e.#E[33]=function(t,r){w()&&console.debug(`Track ${r} requests to get assigned to output ${t}.`),e.#F[r]=t+1},e.#E[81]=function(t,r){e.#se=t/1e3},e.#E[127]=function(t,r){e.#Q.run(t,r)},e.#Q.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},e.#Q.add([67,0,1],function(t,r){e.#F[r]=t[0]+1}),e.#Y=new T("universal non-realtime"),e.#J=new T("universal realtime"),e.#x=new T("Yamaha"),e.#T=new T("Roland"),e.#U=new T("Korg"),e.#j=new T("Kawai"),e.#Z=new T("Akai"),e.#ee=new T("Casio");let a=new T("DX7+ Dump"),l=function(t){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,t)};e.#Y.default=l,e.#J.default=l,e.#x.default=l,e.#T.default=l,e.#U.default=l,e.#j.default=l,e.#Z.default=l,e.#ee.default=l,a.default=l,e.#Y.add([9],(t,r,f)=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.setPortMode(e.getTrackPort(r),1,m[["gm","?","g2"][t[0]-1]]),e.#o=e.#o||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),e.#J.add([4,1],(t,r,f)=>{e.dispatchEvent("mupromptex"),e.#n=((t[1]<<7)+t[0])/16383*100,e.dispatchEvent("mastervolume",e.#n)}).add([4,3],(t,r,f)=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],(t,r,f)=>t[1]-64).add([4,5],(t,r,f)=>{e.dispatchEvent("mupromptex");let s=t[0],i=t[1],n=t[2],c=3,d=c+(s<<1),o=d+i;if(s!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${s})! -`,t);return}let b=0,y=0,k=0;switch(t.subarray(c,d).forEach(x=>{b=b<<7,b|=x}),t.subarray(d,o).forEach((x,D)=>{y|=x<{k|=x<{switch(t[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${t}`);break}case 126:{e.switchMode("xg",!0),e.setPortMode(e.getTrackPort(r),4,m.xg),e.#o=!1,console.info("MIDI reset: XG");break}default:{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(n,c)=>{s[c]=n};if(t.subarray(1).forEach((n,c)=>{let d=c+t[0];([i,i,i,i,o=>{this.#n=o*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},o=>{},o=>{}][d]||(()=>{}))(n,c)}),t[0]<4){let n=0;s.forEach(c=>{n=n<<4,n+=c}),n-=1024}}}}).add([76,2,1],(t,r,f)=>{e.dispatchEvent("mupromptex");let s="XG ";t[0]<32?(s+="reverb ",t.subarray(1).forEach((i,n)=>{([c=>{e.setEffectTypeRaw(0,!1,c),console.info(`${s}main type: ${H[c]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},c=>{e.setEffectTypeRaw(0,!0,c),console.debug(`${s}sub type: ${c+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},c=>{console.debug(`${s}time: ${ee(c)}s`)},c=>{console.debug(`${s}diffusion: ${c}`)},c=>{console.debug(`${s}initial delay: ${c}`)},c=>{console.debug(`${s}HPF cutoff: ${A[c]}Hz`)},c=>{console.debug(`${s}LPF cutoff: ${A[c]}Hz`)},c=>{console.debug(`${s}width: ${c}`)},c=>{console.debug(`${s}height: ${c}`)},c=>{console.debug(`${s}depth: ${c}`)},c=>{console.debug(`${s}wall type: ${c}`)},c=>{console.debug(`${s}dry/wet: ${c}`)},c=>{console.debug(`${s}send: ${C(c)}dB`)},c=>{console.debug(`${s}pan: ${c-64}`)},!1,!1,c=>{console.debug(`${s}delay: ${c}`)},c=>{console.debug(`${s}density: ${c}`)},c=>{console.debug(`${s}balance: ${c}`)},c=>{},c=>{console.debug(`${s}feedback: ${c}`)},c=>{}][t[0]+n]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(i)})):t[0]<64?(s+="chorus ",t.subarray(1).forEach((i,n)=>{([c=>{e.setEffectTypeRaw(1,!1,c),console.info(`${s}main type: ${H[c]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},c=>{e.setEffectTypeRaw(1,!0,c),console.debug(`${s}sub type: ${c+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},c=>{console.debug(`${s}LFO: ${Z[c]}Hz`)},c=>{},c=>{console.debug(`${s}feedback: ${c}`)},c=>{console.debug(`${s}delay offset: ${te(c)}ms`)},c=>{},c=>{console.debug(`${s}low: ${A[c]}Hz`)},c=>{console.debug(`${s}low: ${c-64}dB`)},c=>{console.debug(`${s}high: ${A[c]}Hz`)},c=>{console.debug(`${s}high: ${c-64}dB`)},c=>{console.debug(`${s}dry/wet: ${c}`)},c=>{console.debug(`${s}send: ${C(c)}dB`)},c=>{console.debug(`${s}pan: ${c-64}`)},c=>{console.debug(`${s}to reverb: ${C(c)}dB`)},!1,c=>{},c=>{},c=>{},c=>{console.debug(`${s}LFO phase diff: ${(c-64)*3}deg`)},c=>{console.debug(`${s}input mode: ${c?"stereo":"mono"}`)},c=>{}][t[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(i)})):t[0]<86?(s+="variation ",t.subarray(1).forEach((i,n)=>{([c=>{e.setEffectTypeRaw(2,!1,c),console.info(`${s}main type: ${H[c]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},c=>{e.setEffectTypeRaw(2,!0,c),console.debug(`${s}sub type: ${c+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][t[0]-64+n]||function(){})(i)})):t[0]<97?(s+="variation ",t.subarray(1).forEach((i,n)=>{[c=>{console.debug(`${s}send: ${C(c)}dB`)},c=>{console.debug(`${s}pan: ${c-64}`)},c=>{console.debug(`${s}to reverb: ${C(c)}dB`)},c=>{console.debug(`${s}to chorus: ${C(c)}dB`)},c=>{console.debug(`${s}connection: ${c?"system":"insertion"}`)},c=>{console.debug(`${s}channel: CH${c+1}`)},c=>{console.debug(`${s}mod wheel: ${c-64}`)},c=>{console.debug(`${s}bend wheel: ${c-64}`)},c=>{console.debug(`${s}channel after touch: ${c-64}`)},c=>{console.debug(`${s}AC1: ${c-64}`)},c=>{console.debug(`${s}AC2: ${c-64}`)}][t[0]-86+n](i)})):t[0]>111&&t[0]<118?s+="variation ":console.warn(`Unknown XG variation address: ${t[0]}`)}).add([76,2,64],(t,r,f)=>{t.subarray(1).forEach((s,i)=>{let n=i+t[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][s]}`);else{let c=n-1>>2,d=n-1&3,o=`XG EQ ${c} ${["gain","freq","Q","shape"][d]}: `;[()=>{console.debug(`${o}${s-64}dB`)},()=>{console.debug(`${o}${s} (raw)`)},()=>{console.debug(`${o}${s/10}`)},()=>{console.debug(`${o}${["shelf","peak"][+!!s]}`)}][d]()}})}).add([76,3],(t,r,f)=>{e.dispatchEvent("mupromptex");let s=t[0],i=t[1],n=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((c,d)=>{([o=>{e.setEffectTypeRaw(3+s,!1,o),console.info(`${n}main type: ${H[o]}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))},o=>{e.setEffectTypeRaw(3+s,!0,o),console.debug(`${n}sub type: ${o+1}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))}][i+d]||function(){})(c)})}).add([76,6,0],(t,r,f)=>{let s=t[0];s<64?e.setLetterDisplay(t.subarray(1),"XG letter display",s):e.#V=Date.now()}).add([76,7,0],(t,r,f)=>{let s=t[0];e.#g=0,e.#M=Date.now()+3200,e.#m.fill(0);let i=t.subarray(1);for(let n=0;n>6-k&1,k++})}).add([76,8],(t,r)=>{e.dispatchEvent("mupromptex");let f=e.chRedir(t[0],r,!0),s=t[1],i=p.cc*f,n=`XG CH${f+1} `,c=`Unknown XG part address ${s}.`,d=!0;t.subarray(2).forEach((o,b)=>{d=!0,s<1?console.debug(c):s<41?([()=>{e.#e[i+u[0]]=o,e.dispatchEvent("voice",{part:f})},()=>{e.#e[i+u[32]]=o,e.dispatchEvent("voice",{part:f})},()=>{e.#s[f]=o,e.dispatchEvent("voice",{part:f})},()=>{d=!1;let y=e.chRedir(o,r,!0);e.#f[f]=y,f!=y&&(e.buildRchTree(),console.info(`${n}receives from CH${y+1}`)),e.#S[f]||(e.copyChSetup(y,f,!0),console.debug(`${n}copied from CH${y+1}.`),e.setChActive(f,1),e.dispatchEvent("voice",{part:f}))},()=>{e.#$[f]=+!o},()=>{},()=>{d=!1,e.setChType(f,o,m.xg),console.debug(`${n}type: ${I[o]||o}`),e.dispatchEvent("voice",{part:f})},()=>{e.#a[p.rpn*f+3]=o,e.#i[p.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},!1,!1,()=>{e.#e[i+u[7]]=o},!1,!1,()=>{e.#e[i+u[10]]=o||128},!1,!1,()=>{e.#e[i+u[128]]=o,e.allocateAce(128)},()=>{e.#e[i+u[93]]=o},()=>{e.#e[i+u[91]]=o},()=>{e.#e[i+u[94]]=o},()=>{e.#e[i+u[76]]=o},()=>{e.#e[i+u[77]]=o},()=>{e.#e[i+u[78]]=o},()=>{e.#e[i+u[74]]=o},()=>{e.#e[i+u[71]]=o},()=>{e.#e[i+u[73]]=o},()=>{e.#e[i+u[75]]=o},()=>{e.#e[i+u[72]]=o}][s+b-1]||(()=>{}))():s<48?console.debug(c):s<111?s>102&&s<105&&(e.#e[i+u[[5,65][s&1]]]=o):s<114?console.debug(c):s<116?console.debug(`${n}EQ ${["bass","treble"][s&1]} gain: ${o-64}dB`):s<118?console.debug(c):s<120?console.debug(`${n}EQ ${["bass","treble"][s&1]} freq: ${o}`):console.debug(c)}),d&&e.#r[f]>1&&e.setDrumFirstWrite(f)}).add([76,9],(t,r)=>{let f=e.chRedir(t[0],r,!0),s=t[1],i=p.cc*f,n=`PLG-VL CH${f+1} `;t.subarray(2).forEach((c,d)=>{let o=d+s;switch(o){case 1:{console.info(`${n}breath mode: ${["system","breath","velocity","touch EG"][c]}`);break}case 0:case 27:case 28:break;default:if(o<27){let b=o-3>>1,y=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][b];o&1?o<23?(console.debug(`${n}${y} control source: ${se(c)}`),c&&c<96&&e.allocateAce(130+b),e.#z[p.redir*f+b+2]=c,e.buildRccMap()):console.debug(`${n}${y} scale break point: ${c}`):(console.debug(`${n}${y} depth: ${c-64}`),e.#e[i+u[130+b]]=c)}}})}).add([76,10],(t,r,f)=>{}).add([76,16],(t,r,f)=>{}).add([76,17,0,0],(t,r,f)=>{}).add([76,112],(t,r,f)=>{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.#v[p.ext*t[2]]=e.EXT_VL;break}case 2:{e.#v[p.ext*t[2]]=e.EXT_DX;break}default:e.#v[p.ext*t[2]]=e.EXT_NONE}}).add([73,0,0],(t,r)=>{let f=t[0],s="MU1000 System - ";t.subarray(1).forEach((i,n)=>{let c=f+n;c==8?console.debug(`${s}LCD contrast: ${i}.`):c==18?(e.#p[m.xg][1]=i?126:0,console.debug(`${s}default bank: ${i?"MU100 Native":"MU Basic"}.`),e.dispatchEvent("banklevel",{mode:"xg",data:+!!i}),e.forceVoiceRefresh()):c>=64&&c<69&&[()=>{e.dispatchEvent("channelactive",i)},()=>{i<8?(e.dispatchEvent("channelmin",i<<4),console.debug(`Octavia System: Minimum CH${(i<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{i<8?(e.dispatchEvent("channelmax",(i<<4)+15),console.debug(`Octavia System: Maximum CH${(i<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#O=!!i,console.info(`Octavia System: RS receiving ${["dis","en"][i]}abled.`)}][c-64]()})}).add([73,10,0],(t,r)=>{let f=t[0],s=`MU1000 RS${e.#O?"":" (ignored)"}: `;if(f<16)switch(f){case 2:{let i=e.chRedir(0,r,!0);e.#O&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+63)),console.info(`${s}Show CH1~64`);break}case 3:{let i=e.chRedir(t[1]<<5,r,!0);e.#O&&e.dispatchEvent("channelmin",i),e.#O&&e.dispatchEvent("channelmax",i+31),console.info(`${s}Show CH${i+1}~CH${i+32}`);break}default:console.debug(`${s}unknown switch ${f} invoked.`)}else if(f<32){if(e.#O){let i=e.chRedir(f-16+(e.#ce<<4),r,!0);e.dispatchEvent("channelactive",i)}}else if(f<36){let i=e.chRedir(f-32<<4,r,!0);e.#O&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+15),e.#ce=f-32),console.info(`${s}Show CH${i+1}~CH${i+16}`)}}).add([73,11,0],(t,r)=>{let f="MU1000 System - channel ",s="Octavia System - channel ",i=t[0];t.subarray(1).forEach((n,c)=>{let d=i+c;([()=>{e.setChActive(n,1),e.dispatchEvent("channelactive",n),w()&&console.debug(`${f}current part: CH${n+1}`)},()=>{n<5?(e.dispatchEvent("portrange",1<{n<16?(e.dispatchEvent("portstart",n),console.debug(`${s}start port: ${"ABCDEFGHIJKLMNOP"[n]}`)):(e.dispatchEvent("portstart",255),console.debug(`${s}start port: reset`))}][d]||(()=>{console.debug(`${f}unknown address: ${d}`)}))()})}).add([93,3],(t,r)=>{let f=e.chRedir(t[0],r,!0),s=`PLG-100SG CH${f+1} `,i=Date.now();if(t[1]==0){let n="",c=0;t.subarray(2).forEach((d,o)=>{o%2==0?n+=ae[d]||d.toString().padStart("0"):c+=d*13}),i>=e.#ie&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${re(n)}`,amend:!0}),e.#ie=i+Math.ceil(c/2)+e.#se,w()&&console.debug(`${s}vocals: ${n}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}).add([98,0],(t,r,f)=>{e.dispatchEvent("mupromptex");let s=t[0],i=t.length-5,n=t.length-1;if(s!=i){console.info(`PLG-DX native dump size mismatch! Gave ${s} instead of ${t.length-5}.`);return}let c=O(t.subarray(4,n));if(c!=t[n]){console.info(`Bad PLG-DX checksum ${t[n]} - should be ${c}.`);return}t[0]=98,e.#x.run(t.subarray(0,n),r,f,{noAce:!0})}).add([98,96],(t,r,f,s)=>{let i=e.chRedir(t[0],r,!0),n=p.cc*i,c=t[1];t.subarray(2).forEach((d,o)=>{let b=c+o;if(!(b<10)){if(b==10)e.resetAce();else if(b<27){let y=b+131;s?.noAce||e.allocateAce(y),e.#e[n+u[y]]=d,e.dispatchEvent("cc",{part:i,cc:y,data:d})}}})}).add([100,0],(t,r,f)=>{let s=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.slice(0,2)){case"@I":{this.#o=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:t.slice(2)?.trimLeft()});break}case"@K":{this.#o=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:t.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#o=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:t.slice(2)?.trimLeft()});break}case"@T":{this.#o=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:t.slice(2)?.trimLeft()});break}case"@V":{this.#o=!0,this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:t.slice(2)?.trimLeft()});break}case"XF":{let r=t.slice(2).split(":");switch(r[0]){case"hd":{r.slice(1).forEach((d,s)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][s],data:d})});break}case"ln":{r.slice(1).forEach((d,s)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][s],data:d})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:t})}break}default:this.#o?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((r,d)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:r,mask:d!=0})})}},e.#E[2]=function(t){this.dispatchEvent("metacommit",{type:"Copyrite",data:t})},e.#E[3]=function(t,r){r<1&&this.#q<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:t})},e.#E[4]=function(t,r){this.dispatchEvent("metacommit",{type:"Instrmnt",data:t})},e.#E[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.#E[6]=function(t){this.dispatchEvent("metacommit",{type:"C.Marker",data:t})},e.#E[7]=function(t){this.dispatchEvent("metacommit",{type:"CuePoint",data:t})},e.#E[32]=function(t){this.#q=t[0]+1},e.#E[33]=function(t,r){w()&&console.debug(`Track ${r} requests to get assigned to output ${t}.`),e.#F[r]=t+1},e.#E[81]=function(t,r){e.#se=t/1e3},e.#E[127]=function(t,r){e.#Q.run(t,r)},e.#Q.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},e.#Q.add([67,0,1],function(t,r){e.#F[r]=t[0]+1}),e.#Y=new T("universal non-realtime"),e.#j=new T("universal realtime"),e.#x=new T("Yamaha"),e.#T=new T("Roland"),e.#U=new T("Korg"),e.#J=new T("Kawai"),e.#Z=new T("Akai"),e.#ee=new T("Casio");let a=new T("DX7+ Dump"),l=function(t){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,t)};e.#Y.default=l,e.#j.default=l,e.#x.default=l,e.#T.default=l,e.#U.default=l,e.#J.default=l,e.#Z.default=l,e.#ee.default=l,a.default=l,e.#Y.add([9],(t,r,d)=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.setPortMode(e.getTrackPort(r),1,m[["gm","?","g2"][t[0]-1]]),e.#o=e.#o||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),e.#j.add([4,1],(t,r,d)=>{e.dispatchEvent("mupromptex"),e.#n=((t[1]<<7)+t[0])/16383*100,e.dispatchEvent("mastervolume",e.#n)}).add([4,3],(t,r,d)=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],(t,r,d)=>t[1]-64).add([4,5],(t,r,d)=>{e.dispatchEvent("mupromptex");let s=t[0],i=t[1],n=t[2],c=3,f=c+(s<<1),o=f+i;if(s!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${s})! +`,t);return}let b=0,y=0,k=0;switch(t.subarray(c,f).forEach(x=>{b=b<<7,b|=x}),t.subarray(f,o).forEach((x,D)=>{y|=x<{k|=x<{switch(t[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${t}`);break}case 126:{e.switchMode("xg",!0),e.setPortMode(e.getTrackPort(r),4,m.xg),e.#o=!1,console.info("MIDI reset: XG");break}default:{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(n,c)=>{s[c]=n};if(t.subarray(1).forEach((n,c)=>{let f=c+t[0];([i,i,i,i,o=>{this.#n=o*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},o=>{},o=>{}][f]||(()=>{}))(n,c)}),t[0]<4){let n=0;s.forEach(c=>{n=n<<4,n+=c}),n-=1024}}}}).add([76,2,1],(t,r,d)=>{e.dispatchEvent("mupromptex");let s="XG ";t[0]<32?(s+="reverb ",t.subarray(1).forEach((i,n)=>{([c=>{e.setEffectTypeRaw(0,!1,c),console.info(`${s}main type: ${H[c]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},c=>{e.setEffectTypeRaw(0,!0,c),console.debug(`${s}sub type: ${c+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},c=>{console.debug(`${s}time: ${ee(c)}s`)},c=>{console.debug(`${s}diffusion: ${c}`)},c=>{console.debug(`${s}initial delay: ${c}`)},c=>{console.debug(`${s}HPF cutoff: ${A[c]}Hz`)},c=>{console.debug(`${s}LPF cutoff: ${A[c]}Hz`)},c=>{console.debug(`${s}width: ${c}`)},c=>{console.debug(`${s}height: ${c}`)},c=>{console.debug(`${s}depth: ${c}`)},c=>{console.debug(`${s}wall type: ${c}`)},c=>{console.debug(`${s}dry/wet: ${c}`)},c=>{console.debug(`${s}send: ${C(c)}dB`)},c=>{console.debug(`${s}pan: ${c-64}`)},!1,!1,c=>{console.debug(`${s}delay: ${c}`)},c=>{console.debug(`${s}density: ${c}`)},c=>{console.debug(`${s}balance: ${c}`)},c=>{},c=>{console.debug(`${s}feedback: ${c}`)},c=>{}][t[0]+n]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(i)})):t[0]<64?(s+="chorus ",t.subarray(1).forEach((i,n)=>{([c=>{e.setEffectTypeRaw(1,!1,c),console.info(`${s}main type: ${H[c]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},c=>{e.setEffectTypeRaw(1,!0,c),console.debug(`${s}sub type: ${c+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},c=>{console.debug(`${s}LFO: ${Z[c]}Hz`)},c=>{},c=>{console.debug(`${s}feedback: ${c}`)},c=>{console.debug(`${s}delay offset: ${te(c)}ms`)},c=>{},c=>{console.debug(`${s}low: ${A[c]}Hz`)},c=>{console.debug(`${s}low: ${c-64}dB`)},c=>{console.debug(`${s}high: ${A[c]}Hz`)},c=>{console.debug(`${s}high: ${c-64}dB`)},c=>{console.debug(`${s}dry/wet: ${c}`)},c=>{console.debug(`${s}send: ${C(c)}dB`)},c=>{console.debug(`${s}pan: ${c-64}`)},c=>{console.debug(`${s}to reverb: ${C(c)}dB`)},!1,c=>{},c=>{},c=>{},c=>{console.debug(`${s}LFO phase diff: ${(c-64)*3}deg`)},c=>{console.debug(`${s}input mode: ${c?"stereo":"mono"}`)},c=>{}][t[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(i)})):t[0]<86?(s+="variation ",t.subarray(1).forEach((i,n)=>{([c=>{e.setEffectTypeRaw(2,!1,c),console.info(`${s}main type: ${H[c]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},c=>{e.setEffectTypeRaw(2,!0,c),console.debug(`${s}sub type: ${c+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][t[0]-64+n]||function(){})(i)})):t[0]<97?(s+="variation ",t.subarray(1).forEach((i,n)=>{[c=>{console.debug(`${s}send: ${C(c)}dB`)},c=>{console.debug(`${s}pan: ${c-64}`)},c=>{console.debug(`${s}to reverb: ${C(c)}dB`)},c=>{console.debug(`${s}to chorus: ${C(c)}dB`)},c=>{console.debug(`${s}connection: ${c?"system":"insertion"}`)},c=>{console.debug(`${s}channel: CH${c+1}`)},c=>{console.debug(`${s}mod wheel: ${c-64}`)},c=>{console.debug(`${s}bend wheel: ${c-64}`)},c=>{console.debug(`${s}channel after touch: ${c-64}`)},c=>{console.debug(`${s}AC1: ${c-64}`)},c=>{console.debug(`${s}AC2: ${c-64}`)}][t[0]-86+n](i)})):t[0]>111&&t[0]<118?s+="variation ":console.warn(`Unknown XG variation address: ${t[0]}`)}).add([76,2,64],(t,r,d)=>{t.subarray(1).forEach((s,i)=>{let n=i+t[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][s]}`);else{let c=n-1>>2,f=n-1&3,o=`XG EQ ${c} ${["gain","freq","Q","shape"][f]}: `;[()=>{console.debug(`${o}${s-64}dB`)},()=>{console.debug(`${o}${s} (raw)`)},()=>{console.debug(`${o}${s/10}`)},()=>{console.debug(`${o}${["shelf","peak"][+!!s]}`)}][f]()}})}).add([76,3],(t,r,d)=>{e.dispatchEvent("mupromptex");let s=t[0],i=t[1],n=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((c,f)=>{([o=>{e.setEffectTypeRaw(3+s,!1,o),console.info(`${n}main type: ${H[o]}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))},o=>{e.setEffectTypeRaw(3+s,!0,o),console.debug(`${n}sub type: ${o+1}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))}][i+f]||function(){})(c)})}).add([76,6,0],(t,r,d)=>{let s=t[0];s<64?e.setLetterDisplay(t.subarray(1),"XG letter display",s):e.#V=Date.now()}).add([76,7,0],(t,r,d)=>{let s=t[0];e.#g=0,e.#M=Date.now()+3200,e.#m.fill(0);let i=t.subarray(1);for(let n=0;n>6-k&1,k++})}).add([76,8],(t,r)=>{e.dispatchEvent("mupromptex");let d=e.chRedir(t[0],r,!0),s=t[1],i=p.cc*d,n=`XG CH${d+1} `,c=`Unknown XG part address ${s}.`,f=!0;t.subarray(2).forEach((o,b)=>{f=!0,s<1?console.debug(c):s<41?([()=>{e.#e[i+u[0]]=o,e.dispatchEvent("voice",{part:d})},()=>{e.#e[i+u[32]]=o,e.dispatchEvent("voice",{part:d})},()=>{e.#s[d]=o,e.dispatchEvent("voice",{part:d})},()=>{f=!1;let y=e.chRedir(o,r,!0);e.#f[d]=y,d!=y&&(e.buildRchTree(),console.info(`${n}receives from CH${y+1}`)),e.#S[d]||(e.copyChSetup(y,d,!0),console.debug(`${n}copied from CH${y+1}.`),e.setChActive(d,1),e.dispatchEvent("voice",{part:d}))},()=>{e.#$[d]=+!o},()=>{},()=>{f=!1,e.setChType(d,o,m.xg),console.debug(`${n}type: ${I[o]||o}`),e.dispatchEvent("voice",{part:d})},()=>{e.#a[p.rpn*d+3]=o,e.#i[p.rpnt*d+2]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)})},!1,!1,()=>{e.#e[i+u[7]]=o},!1,!1,()=>{e.#e[i+u[10]]=o||128},!1,!1,()=>{e.#e[i+u[128]]=o,e.allocateAce(128)},()=>{e.#e[i+u[93]]=o},()=>{e.#e[i+u[91]]=o},()=>{e.#e[i+u[94]]=o},()=>{e.#e[i+u[76]]=o},()=>{e.#e[i+u[77]]=o},()=>{e.#e[i+u[78]]=o},()=>{e.#e[i+u[74]]=o},()=>{e.#e[i+u[71]]=o},()=>{e.#e[i+u[73]]=o},()=>{e.#e[i+u[75]]=o},()=>{e.#e[i+u[72]]=o}][s+b-1]||(()=>{}))():s<48?console.debug(c):s<111?s>102&&s<105&&(e.#e[i+u[[5,65][s&1]]]=o):s<114?console.debug(c):s<116?console.debug(`${n}EQ ${["bass","treble"][s&1]} gain: ${o-64}dB`):s<118?console.debug(c):s<120?console.debug(`${n}EQ ${["bass","treble"][s&1]} freq: ${o}`):console.debug(c)}),f&&e.#r[d]>1&&e.setDrumFirstWrite(d)}).add([76,9],(t,r)=>{let d=e.chRedir(t[0],r,!0),s=t[1],i=p.cc*d,n=`PLG-VL CH${d+1} `;t.subarray(2).forEach((c,f)=>{let o=f+s;switch(o){case 1:{console.info(`${n}breath mode: ${["system","breath","velocity","touch EG"][c]}`);break}case 0:case 27:case 28:break;default:if(o<27){let b=o-3>>1,y=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][b];o&1?o<23?(console.debug(`${n}${y} control source: ${se(c)}`),c&&c<96&&e.allocateAce(130+b),e.#z[p.redir*d+b+2]=c,e.buildRccMap()):console.debug(`${n}${y} scale break point: ${c}`):(console.debug(`${n}${y} depth: ${c-64}`),e.#e[i+u[130+b]]=c)}}})}).add([76,10],(t,r,d)=>{}).add([76,16],(t,r,d)=>{}).add([76,17,0,0],(t,r,d)=>{}).add([76,112],(t,r,d)=>{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.#v[p.ext*t[2]]=e.EXT_VL;break}case 2:{e.#v[p.ext*t[2]]=e.EXT_DX;break}default:e.#v[p.ext*t[2]]=e.EXT_NONE}}).add([73,0,0],(t,r)=>{let d=t[0],s="MU1000 System - ";t.subarray(1).forEach((i,n)=>{let c=d+n;c==8?console.debug(`${s}LCD contrast: ${i}.`):c==18?(e.#p[m.xg][1]=i?126:0,console.debug(`${s}default bank: ${i?"MU100 Native":"MU Basic"}.`),e.dispatchEvent("banklevel",{mode:"xg",data:+!!i}),e.forceVoiceRefresh()):c>=64&&c<69&&[()=>{e.dispatchEvent("channelactive",i)},()=>{i<8?(e.dispatchEvent("channelmin",i<<4),console.debug(`Octavia System: Minimum CH${(i<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{i<8?(e.dispatchEvent("channelmax",(i<<4)+15),console.debug(`Octavia System: Maximum CH${(i<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#O=!!i,console.info(`Octavia System: RS receiving ${["dis","en"][i]}abled.`)}][c-64]()})}).add([73,10,0],(t,r)=>{let d=t[0],s=`MU1000 RS${e.#O?"":" (ignored)"}: `;if(d<16)switch(d){case 2:{let i=e.chRedir(0,r,!0);e.#O&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+63)),console.info(`${s}Show CH1~64`);break}case 3:{let i=e.chRedir(t[1]<<5,r,!0);e.#O&&e.dispatchEvent("channelmin",i),e.#O&&e.dispatchEvent("channelmax",i+31),console.info(`${s}Show CH${i+1}~CH${i+32}`);break}default:console.debug(`${s}unknown switch ${d} invoked.`)}else if(d<32){if(e.#O){let i=e.chRedir(d-16+(e.#ce<<4),r,!0);e.dispatchEvent("channelactive",i)}}else if(d<36){let i=e.chRedir(d-32<<4,r,!0);e.#O&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+15),e.#ce=d-32),console.info(`${s}Show CH${i+1}~CH${i+16}`)}}).add([73,11,0],(t,r)=>{let d="MU1000 System - channel ",s="Octavia System - channel ",i=t[0];t.subarray(1).forEach((n,c)=>{let f=i+c;([()=>{e.setChActive(n,1),e.dispatchEvent("channelactive",n),w()&&console.debug(`${d}current part: CH${n+1}`)},()=>{n<5?(e.dispatchEvent("portrange",1<{n<16?(e.dispatchEvent("portstart",n),console.debug(`${s}start port: ${"ABCDEFGHIJKLMNOP"[n]}`)):(e.dispatchEvent("portstart",255),console.debug(`${s}start port: reset`))}][f]||(()=>{console.debug(`${d}unknown address: ${f}`)}))()})}).add([93,3],(t,r)=>{let d=e.chRedir(t[0],r,!0),s=`PLG-100SG CH${d+1} `,i=Date.now();if(t[1]==0){let n="",c=0;t.subarray(2).forEach((f,o)=>{o%2==0?n+=ae[f]||f.toString().padStart("0"):c+=f*13}),i>=e.#ie&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${re(n)}`,amend:!0}),e.#ie=i+Math.ceil(c/2)+e.#se,w()&&console.debug(`${s}vocals: ${n}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}).add([98,0],(t,r,d)=>{e.dispatchEvent("mupromptex");let s=t[0],i=t.length-5,n=t.length-1;if(s!=i){console.info(`PLG-DX native dump size mismatch! Gave ${s} instead of ${t.length-5}.`);return}let c=O(t.subarray(4,n));if(c!=t[n]){console.info(`Bad PLG-DX checksum ${t[n]} - should be ${c}.`);return}t[0]=98,e.#x.run(t.subarray(0,n),r,d,{noAce:!0})}).add([98,96],(t,r,d,s)=>{let i=e.chRedir(t[0],r,!0),n=p.cc*i,c=t[1];t.subarray(2).forEach((f,o)=>{let b=c+o;if(!(b<10)){if(b==10)e.resetAce();else if(b<27){let y=b+131;s?.noAce||e.allocateAce(y),e.#e[n+u[y]]=f,e.dispatchEvent("cc",{part:i,cc:y,data:f})}}})}).add([100,0],(t,r,d)=>{let s=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=O(s),n=t[t.length-1];if(i!=n){console.warn(`Yamaha DX7+ dump SysEx checksum mismatch! Expected ${i}, but got ${n}: -`,t);return}a.run(s.subarray(1))}).add([100,76],(t,r,f)=>{let s=t[0]>>4,i=t[0]&15,n=t[1];switch(s){case 2:{let c=e.chRedir(i,r,!0),d=p.cc*c;t.subarray(2).forEach((o,b)=>{let y=b+n;if(!(y<7)){if(y<23){let k=y+135;e.allocateAce(k),e.#e[d+u[k]]=o,e.dispatchEvent("cc",{part:c,cc:k,data:o})}}});break}default:console.info("Unknown DX7+ multipart: %o",t)}}),a.add([14,31],(t,r,f)=>{e.#e[p.cc*t[0]+u[64]]=0,e.#d.ano(t[0]),e.switchMode("xg"),e.setPortMode(e.getTrackPort(r),1,m.xg),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${t[0]+1}.`)}).add([76,112],async t=>{let r=t[0],f=p.cc*r,s=p.ext*r,i=p.cvn*r;e.#v[s]=e.EXT_DX,e.#D[r]=1;let n=e.#ne.subarray(i,i+p.cvn);n.fill(32),t.subarray(1).forEach((c,d)=>{if(d<10)n[d]=Math.max(c,32);else if(!(d<40)){if(d<56){let o=d+102;e.#e[f+u[o]]=c,e.dispatchEvent("cc",{part:r,cc:o,data:c})}}}),e.#s[r]=r&127,e.#e[p.cc*r+u[0]]=35,e.#e[p.cc*r+u[32]]=r>>7|4,e.dispatchEvent("voice",{part:r}),console.debug(`DX7+ CH${r+1} dump: %o`,t)});let h=function(t,r,f,s){},g=function(t,r){e.dispatchEvent("mupromptex");let f=t*p.dpn,s=r[0],i=r[1];r.subarray(2).forEach((n,c)=>{let d=c+i,o=-1;d<16?([()=>{o=24},()=>{o=25},()=>{o=26},()=>{},()=>{o=28},()=>{o=29},()=>{o=30},()=>{o=31},()=>{},()=>{},()=>{},()=>{o=20},()=>{o=21},()=>{o=22},()=>{o=23},()=>{}][d]||(()=>{console.debug(`Unknown XG-style drum param ${d} on set ${t+1}.`)}))():d<32||(d<40?([()=>{o=48},()=>{o=49},!1,!1,()=>{o=52},()=>{o=53}][d-32]||(()=>{console.debug(`Unknown XG-style drum param ${d} on set ${t+1}.`)}))():d<80||([()=>{o=36}][d-80]||(()=>{console.debug(`Unknown XG-style drum param ${d} on set ${t+1}.`)}))()),o>=0?(w()&&console.debug(f,o,s,n),e.#y[(f+R[o])*p.dnc+s]=n):w()&&console.debug(`XG-style drum param ${d} has no writes.`)})},E=function(t,r,f){e.dispatchEvent("mupromptex");let s=t*p.dpn,i=(r<<7)+f[0];f.subarray(1).forEach((n,c)=>{let d=c+i,o=d&127,b=d>>7,y=-1;b>1&&([()=>{y=26},()=>{},()=>{y=28},()=>{y=29},()=>{y=30},()=>{},()=>{},()=>{y=31}][b-2]||(()=>{console.debug(`Unknown GS-style drum param ${b} on set ${t+1}.`)}))(),y>-1?(w()&&console.debug(s,y,o,n),e.#y[(s+R[y])*p.dnc+o]=n):w()&&console.debug(`GS-style drum param ${b} has no writes.`)})};this.#x.add([76,48],(t,r,f)=>{g(0,t)}).add([76,49],(t,r,f)=>{g(1,t)}).add([76,50],(t,r,f)=>{g(2,t)}).add([76,51],(t,r,f)=>{g(3,t)}).add([76,52],(t,r,f)=>{g(4,t)}).add([76,53],(t,r,f)=>{g(5,t)}).add([76,54],(t,r,f)=>{g(6,t)}).add([76,55],(t,r,f)=>{g(7,t)}),this.#x.add([89,0],(t,r,f)=>{if(e.eprom){let s=t[0],i=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);w()&&console.debug(`MU1000 EPROM trail to 0x${i.toString(16).padStart(6,"0")}, ${s} bytes.`);let n=e.eprom.data;t.subarray(4).forEach((c,d)=>{let o=d>>3,b=d&7;if(b==7)for(let y=0;y<7;y++)n[i+7*o+y]+=(c>>6-y&1)<<7;else n[i+7*o+b]=c})}}).add([89,1],(t,r,f)=>{let s=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];w()&&console.debug(`MU1000 EPROM jump to 0x${s.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=s)}).add([89,2],(t,r,f)=>{if(e.eprom){let s=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);w()&&console.debug(`MU1000 EPROM write to 0x${s.toString(16).padStart(6,"0")}.`);let i=e.eprom.data;t.subarray(4).forEach((n,c)=>{let d=c>>3,o=c&7;if(o==7)for(let b=0;b<7;b++)i[s+7*d+b]+=(n>>6-b&1)<<7;else i[s+7*d+o]=n})}}).add([89,3],(t,r,f)=>{}),this.#x.add([39,48],(t,r,f)=>{}).add([43,0,0],(t,r,f)=>{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(n,c)=>{s[c]=n};if(t.subarray(1).forEach((n,c)=>{let d=c+t[0];[i,i,i,i,()=>{this.#n=n*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},()=>n-64,()=>n||128,()=>n,()=>n,()=>{console.debug(`TG300 variation on cc${n}.`)}][d](n,d)}),t[0]<4){let n=0;s.forEach(c=>{n=n<<4,n+=c}),n-=1024}}).add([43,1,0],(t,r,f)=>{e.dispatchEvent("mupromptex")}).add([43,2],(t,r,f)=>{e.dispatchEvent("mupromptex");let s=e.chRedir(t[0],r,!0),i=t[1],n=p.cc*s,c=`TG300 CH${s+1} `;t.subarray(2).forEach((d,o)=>{o<5?([()=>{},()=>{e.#e[n+u[0]]=d,e.dispatchEvent("voice",{part:s})},()=>{e.#e[n+u[32]]=d,e.dispatchEvent("voice",{part:s})},()=>{e.#s[s]=d,e.dispatchEvent("voice",{part:s})},()=>{let b=e.chRedir(d,r,!0);e.#f[s]=b,s!=b&&(e.buildRchTree(),console.info(`${c}receives from CH${b+1}`))}][o+i]||(()=>{}))(d,o+i):o<21||(o<47?([()=>{e.#$[s]=+!d},()=>{},()=>{},()=>{e.#a[p.rpn*s+3]=d,e.#i[p.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{},()=>{e.#e[n+u[7]]=d},!1,!1,()=>{e.#e[n+u[10]]=d||128},!1,!1,()=>{console.debug(`${c} AC1 at cc${d}`)},()=>{console.debug(`${c} AC2 at cc${d}`)},()=>{e.#e[n+u[128]]=d,e.allocateAce(128)},()=>{e.#e[n+u[93]]=d},()=>{e.#e[n+u[91]]=d},()=>{e.#e[n+u[94]]=d},()=>{e.#e[n+u[76]]=d},()=>{e.#e[n+u[77]]=d},()=>{e.#e[n+u[74]]=d},()=>{e.#e[n+u[71]]=d},()=>{e.#e[n+u[73]]=d},()=>{e.#e[n+u[75]]=d},()=>{e.#e[n+u[72]]=d},()=>{e.#e[n+u[78]]=d}][o+i-21]||(()=>{}))(d,o+i):o<95||([()=>{e.#e[n+u[65]]=d},()=>{e.#e[n+u[5]]=d}][o+i-95]||(()=>{}))(d,o+i))})}).add([43,7,0],(t,r,f)=>{let s=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",s)}).add([43,7,1],(t,r,f)=>{e.#g=0,e.#M=Date.now()+3200,e.#m.fill(0),t.forEach(function(s,i){let n=Math.floor(i/16),c=i%16,d=(c*3+n)*7,o=7,b=0;for(d-=c*5,n==2&&(o=2);b>6-b&1,b++})}),this.#T.add([66,18,0,0,127],(t,r,f)=>{e.switchMode("sc",!0),e.setPortMode(e.getTrackPort(r),2,m.sc),e.#e[p.cc*9]=120,e.#e[p.cc*25]=120,e.#e[p.cc*41]=120,e.#e[p.cc*57]=120,e.#p[m.sc][1]=e.#c.sc,e.#o=!1,e.#I.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,r,f)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.setPortMode(e.getTrackPort(r),2,m.gs),e.#p[m.gs][1]=e.#c.gs,e.#e[p.cc*9]=120,e.#e[p.cc*25]=120,e.#e[p.cc*41]=120,e.#e[p.cc*57]=120,e.#o=!1,e.#I.fill(0),console.info("MIDI reset: GS");break}default:{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(n,c)=>{s[c]=n};if(t.subarray(1).forEach((n,c)=>{let d=c+t[0];[i,i,i,i,o=>{this.#n=o*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},o=>{},o=>{}][d](n,c)}),t[0]<4){let n=0;s.forEach(c=>{n=n<<4,n+=c}),n-=1024}}}}).add([66,18,64,1],(t,r,f)=>{e.dispatchEvent("mupromptex");let s=t[0];if(s<16){let i="".padStart(s," ");t.subarray(1).forEach((n,c)=>{i+=String.fromCharCode(Math.max(32,n))}),i=i.padEnd(16," "),console.debug(`GS patch name: ${i}`)}else s<48||(s<65?t.subarray(1).forEach((i,n)=>{let c=`GS ${s+n>55?"chorus":"reverb"} `;([()=>{console.info(`${c}type: ${z[i]}`),e.setEffectType(0,40,i),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${c}predelay: ${i}ms`)},()=>{console.info(`${c}type: ${ie[i]}`),e.setEffectType(1,40,16+i),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${c}to reverb: ${C(i)}`)},()=>{console.debug(`${c}to delay: ${C(i)}`)}][s+n-48]||(()=>{}))()}):s<80?console.debug(`Unknown GS patch address: ${s}`):s<91?t.subarray(1).forEach((i,n)=>{let c="GS delay ";([()=>{console.info(`${c}type: ${ce[i]}`),e.setEffectType(2,40,32+i),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${c}to reverb: ${C(i)}`)}][s+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${s}`))}).add([66,18,64,2],(t,r,f)=>{let s="GS EQ ";t.subarray(1).forEach((i,n)=>{([()=>{console.debug(`${s}low freq: ${[200,400][i]}Hz`)},()=>{console.debug(`${s}low gain: ${i-64}dB`)},()=>{console.debug(`${s}high freq: ${[3e3,6e3][i]}Hz`)},()=>{console.debug(`${s}high gain: ${i-64}dB`)}][t[0]+n]||function(){console.warn(`Unknown GS EQ address: ${t[0]+n}`)})()})}).add([66,18,64,3],(t,r,f)=>{e.dispatchEvent("mupromptex");let s="GS EFX ",i=function(n,c){let d=ne(e.#k.subarray(10,12),c,n);d&&console.debug(`${s}${q(e.#k.subarray(10,12))} ${d}`)};t.subarray(1).forEach((n,c)=>{([()=>{e.setEffectTypeRaw(3,!1,32+n),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,n),console.info(`${s}type: ${q(e.#k.subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,()=>{console.debug(`${s}to reverb: ${C(n)}dB`)},()=>{console.debug(`${s}to chorus: ${C(n)}dB`)},()=>{console.debug(`${s}to delay: ${C(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]+c]||function(d,o){console.warn(`Unknown GS EFX address: ${o}`)})(n,t[0]+c)})}).add([66,18,65],(t,r,f)=>{E((t[0]>>4)+1<<1,t[0]&15,t.subarray(1))}).add([69,18,16],(t,r,f)=>{switch(t[0]){case 0:{let s=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",s);break}case 32:{e.#M=Date.now()+3200,t[1]==0&&(t[2]?(e.#g=Math.max(Math.min(t[2]-1,9),0),w()&&console.debug(`GS switch display page ${t[2]-1}.`)):(e.#g=0,e.#M=Date.now(),w()&&console.debug("GS disable display page.")));break}default:if(t[0]<6){e.#g>9&&(e.#g=0);let s=t[0]-1<<1|t[1]>>6;e.#g==s&&(e.#M=Date.now()+3200),e.#N[s]?.length||(e.#N[s]=new Uint8Array(256));let i=e.#N[s];w()&&console.debug(`GS frame draw page ${s}.`);let n=t[1]&63;i.fill(0),t.subarray(2).forEach(function(d,o){let b=o+n,y=Math.floor(b/16),k=b%16,x=(k*4+y)*5,D=5,G=0;for(x-=k*4,y==3&&(D=1);G>4-G&1,G++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let v=function(t,r,f){e.dispatchEvent("mupromptex");let s=t[0],i=p.cc*r,n=p.rpn*r,c=`GS CH${r+1} `;s<3?(t.subarray(1).forEach((d,o)=>{[()=>{e.#e[i+u[0]]=d},()=>{e.#s[r]=d},()=>{let b=0;d<16?b=e.chRedir(d,f,!0):b=p.ch,e.#f[r]=b,r!=b&&(e.buildRchTree(),console.info(`${c}receives from CH${b+1}`))}][s+o]()}),e.dispatchEvent("voice",{part:r})):s<19||(s<44?t.subarray(1).forEach((d,o)=>{([()=>{e.#$[r]=+!d},!1,()=>{e.setChType(r,d<<1,m.gs),console.debug(`${c}type: ${d?"drum ":"melodic"}${d||""}`)},()=>{e.#a[n+3]=d,e.#i[p.rpnt*r+2]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},!1,()=>{e.#e[i+u[7]]=d},!1,!1,()=>{e.#e[i+u[10]]=d||128},!1,!1,()=>{console.debug(`${c}CC 1: cc${d}`)},()=>{console.debug(`${c}CC 2: cc${d}`)},()=>{e.#e[i+u[93]]=d},()=>{e.#e[i+u[91]]=d},!1,!1,()=>{e.#a[n+1]=d,e.#i[p.rpnt*r+1]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{e.#a[n+2]=d,e.#i[p.rpnt*r+1]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{e.#e[i+u[94]]=d}][s+o-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},$=function(t,r){let f=t[0],s=`GS CH${r+1} `;f<2?t.subarray(1).forEach((i,n)=>{[()=>{e.#e[p.cc*r+u[32]]=i},()=>{}][f+n]()}):f<32?console.warn(`Unknown GS misc address: ${f}`):f<35?t.subarray(1).forEach((i,n)=>{[()=>{console.debug(`${s}EQ: o${["ff","n"][i]}`)},()=>{},()=>{console.debug(`${s}EFX: o${["ff","n"][i]}`),e.#ae[r]=i,e.dispatchEvent("partefxtoggle",{part:r,active:i})}][f+n-32]()}):console.warn(`Unknown GS misc address: ${f}`)};this.#T.add([66,18,64,16],(t,r)=>{v(t,e.chRedir(9,r,!0),r)}).add([66,18,64,17],(t,r)=>{v(t,e.chRedir(0,r,!0),r)}).add([66,18,64,18],(t,r)=>{v(t,e.chRedir(1,r,!0),r)}).add([66,18,64,19],(t,r)=>{v(t,e.chRedir(2,r,!0),r)}).add([66,18,64,20],(t,r)=>{v(t,e.chRedir(3,r,!0),r)}).add([66,18,64,21],(t,r)=>{v(t,e.chRedir(4,r,!0),r)}).add([66,18,64,22],(t,r)=>{v(t,e.chRedir(5,r,!0),r)}).add([66,18,64,23],(t,r)=>{v(t,e.chRedir(6,r,!0),r)}).add([66,18,64,24],(t,r)=>{v(t,e.chRedir(7,r,!0),r)}).add([66,18,64,25],(t,r)=>{v(t,e.chRedir(8,r,!0),r)}).add([66,18,64,26],(t,r)=>{v(t,e.chRedir(10,r,!0),r)}).add([66,18,64,27],(t,r)=>{v(t,e.chRedir(11,r,!0),r)}).add([66,18,64,28],(t,r)=>{v(t,e.chRedir(12,r,!0),r)}).add([66,18,64,29],(t,r)=>{v(t,e.chRedir(13,r,!0),r)}).add([66,18,64,30],(t,r)=>{v(t,e.chRedir(14,r,!0),r)}).add([66,18,64,31],(t,r)=>{v(t,e.chRedir(15,r,!0),r)}).add([66,18,64,64],(t,r)=>{$(t,e.chRedir(9,r,!0))}).add([66,18,64,65],(t,r)=>{$(t,e.chRedir(0,r,!0))}).add([66,18,64,66],(t,r)=>{$(t,e.chRedir(1,r,!0))}).add([66,18,64,67],(t,r)=>{$(t,e.chRedir(2,r,!0))}).add([66,18,64,68],(t,r)=>{$(t,e.chRedir(3,r,!0))}).add([66,18,64,69],(t,r)=>{$(t,e.chRedir(4,r,!0))}).add([66,18,64,70],(t,r)=>{$(t,e.chRedir(5,r,!0))}).add([66,18,64,71],(t,r)=>{$(t,e.chRedir(6,r,!0))}).add([66,18,64,72],(t,r)=>{$(t,e.chRedir(7,r,!0))}).add([66,18,64,73],(t,r)=>{$(t,e.chRedir(8,r,!0))}).add([66,18,64,74],(t,r)=>{$(t,e.chRedir(10,r,!0))}).add([66,18,64,75],(t,r)=>{$(t,e.chRedir(11,r,!0))}).add([66,18,64,76],(t,r)=>{$(t,e.chRedir(12,r,!0))}).add([66,18,64,77],(t,r)=>{$(t,e.chRedir(13,r,!0))}).add([66,18,64,78],(t,r)=>{$(t,e.chRedir(14,r,!0))}).add([66,18,64,79],(t,r)=>{$(t,e.chRedir(15,r,!0))}),this.#U.add([54,65],(t,r)=>{let f=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(f,!0),e.setPortMode(e.getTrackPort(r),1,m[f]);let s=t[t.length-1],i=t.subarray(0,t.length-1),n=O(i);n!=s&&(console.info(`X5D multi parameters checksum mismatch! Expected ${n}, got ${s}.`),console.debug(t));let c=(t[1]<<7)+t[0],d=(t[3]<<7)+t[2],o=e.chRedir(c&15,r,!0),b=p.cc*o;[()=>{d<1||(d<101?(e.setChType(o,e.CH_MELODIC,m.x5d),e.#s[o]=d-1,e.#e[b+u[0]]=e.#c.x5):d<229?(e.setChType(o,e.CH_MELODIC,m.x5d),e.#s[o]=d-101,e.#e[b+u[0]]=56):(e.setChType(o,e.CH_DRUMS,m.x5d),e.#s[o]=ge[d-229]||0,e.#e[b+u[0]]=62)),e.dispatchEvent("voice",{part:o})},()=>{e.#e[b+u[7]]=d},()=>{d<31&&(e.#e[b+u[10]]=Math.round((d-15)*4.2+64))},()=>{e.#e[b+u[93]]=B(d)},()=>{e.#e[b+u[91]]=B(d)},()=>{e.#a[o*p.rpn+3]=d>8191?d-16320:64+d,e.#i[p.rpnt*o+2]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)})},()=>{e.#a[o*p.rpn+1]=d>8191?d-16320:64+d,e.#i[p.rpnt*o+1]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)})},()=>{d>0&&(e.#a[o*p.rpn]=d,e.#i[p.rpnt*o]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)}))},()=>{}][c>>4]()}).add([54,76,0],(t,r)=>{e.dispatchEvent("mupromptex");let f=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(r),1,m[f]);let s="",i=e.#c.x5,n=0,c=0,d="MSB PRG LSB NME";M(t,function(o,b){if(b<16400){let y=b%164;switch(!0){case y<10:{o>31&&(s+=String.fromCharCode(o));break}case y==10:break;case y==11:{d+=` -${i} ${n} ${c} ${s.trim().replace("Init Voice","")}`,n++,s="";break}}n>99&&(i=90,n=0)}}),e.userBank.clearRange({msb:e.#c.x5,prg:[0,99],lsb:0}),e.userBank.load(d),w()&&console.debug(d),e.forceVoiceRefresh()}).add([54,77,0],(t,r)=>{e.dispatchEvent("mupromptex");let f=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(r),1,m[f]);let s="",i=90,n=0,c=0,d="MSB PRG LSB NME";M(t,function(o,b){if(b<13600){let y=b%136;switch(!0){case y<10:{o>31&&(s+=String.fromCharCode(o));break}case y==11:{d+=` -${i} ${n} ${c} ${s.trim().replace("Init Combi","")}`,n++,s="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(d),w()&&console.debug(d),e.forceVoiceRefresh()}).add([54,78],(t,r)=>{let f=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(r),1,m[f]),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][t[0]]} mode.`)}).add([54,85],(t,r)=>{e.dispatchEvent("mupromptex");let f=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(r),1,m[f]),M(t,(s,i)=>{i>0&&i<3&&(e.setEffectType(i-1,44,s),e.dispatchEvent(`efx${["reverb","chorus"][i-1]}`,e.getEffectType(i-1)))})}).add([54,104],(t,r)=>{e.dispatchEvent("mupromptex");let f=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(f,!0);let s=e.getTrackPort(r);if(e.#l[s]&&e.#l[s]!=m[f])if(e.#L.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${r}. Port ${String.fromCharCode(65+s)} mode "${S[e.#l[s]]}" mismatch, should be "${f}".`);return}else console.info(`Track ${r} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+s)}.`);e.setPortMode(s,1,m[f]),M(t,function(i,n,c,d){if(n<192){let o=e.chRedir(Math.floor(n/12),r,!0),b=o*p.cc;switch(n%12){case 0:{i<128?(e.setChType(o,e.CH_MELODIC,m.x5d),e.#e[b+u[0]]=e.#c.x5,e.#s[o]=i):(e.setChType(o,e.CH_DRUMS,m.x5d),e.#e[b+u[0]]=62,e.#s[o]=ge[i-128]),i>0&&e.setChActive(o,1),e.dispatchEvent("voice",{part:o});break}case 1:{e.#e[b+u[7]]=i;break}case 2:{e.#a[o*p.rpn+3]=i>127?i-192:64+i,e.#i[p.rpnt*o+2]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)});break}case 3:{e.#a[o*p.rpn+1]=i>127?i-192:64+i,e.#i[p.rpnt*o+1]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)});break}case 4:{i<31&&(e.#e[b+u[10]]=Math.round((i-15)*4.2+64));break}case 5:{let y=i>>4,k=i&15;e.#e[b+u[91]]=B(k),e.#e[b+u[93]]=B(y);break}case 10:break;case 11:{let y=e.chRedir(i&15,r,!0),k=i>>4;e.#f[o]=i,(y!=o||k)&&(console.info(`X5D Part CH${o+1} receives from CH${y+1}.`),e.buildRchTree())}}}else{let o=e.chRedir(n-192,r,!0)}})}),this.#T.add([22,18,127],(t,r,f)=>{e.switchMode("mt32",!0),e.setPortMode(e.getTrackPort(r),1,m.mt32),e.#o=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(t,r,f)=>{e.switchMode("mt32");let s=e.chRedir(f,r,!0),i=t[1];t.subarray(2).forEach((n,c)=>{let d=c+i;e.#_[d+(s-1)*16]=n,([!1,()=>{let o=e.#_[s-1<<4];if(o<3){if(e.#D[s]=1,o==2)for(let b=0;b{e.#a[s*p.rpn+3]=n+40,e.#i[p.rpnt*s+2]=1},()=>{e.#a[s*p.rpn+1]=n+14,e.#i[p.rpnt*s+1]=1},()=>{e.#a[s*p.rpn]=n,e.#i[p.rpnt*s]=1},!1,()=>{e.#e[p.cc*s+u[91]]=n?127:0},!1,()=>{e.#e[p.cc*s+u[7]]=n},()=>{e.#e[p.cc*s+u[10]]=Math.ceil(n*9.05)}][d]||(()=>{}))()})}).add([22,18,1],(t,r,f)=>{e.switchMode("mt32");let s=f&7;console.debug(`MT-32 slot #${f+1} Drum: ${t}`);let i=t[0]<<7|t[1];t.subarray(2).forEach((n,c)=>{let d=c+i,o=(d>>2)+24,b=d&3,y=s*p.dpn;if(w()&&console.debug(`MT-32 temp drum note ${o} param ${b}: ${n}`),o<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${o}`);return}[()=>{},()=>{e.#y[(y+R[26])*p.dnc+o]=Math.round(n*1.27)},()=>{e.#y[(y+R[26])*p.dnc+o]=n*9+1&127},()=>{e.#y[(y+R[26])*p.dnc+o]=n?127:0}][b]()})}).add([22,18,2],(t,r,f)=>{e.switchMode("mt32");let s=e.chRedir(f,r,!0),i=t[1]+(t[0]<<7);i<10&&(e.#D[s]=1),t.subarray(2).forEach((n,c)=>{let d=c+i;d<14&&(e.#P[(s-1)*p.cmt+d]=n)}),e.dispatchEvent("voice",{part:s})}).add([22,18,3],(t,r,f)=>{e.switchMode("mt32");let s=f&7;if(t[0]){let i=(t[0]-1<<7)+t[1]-16;t.subarray(2).forEach((n,c)=>{let d=c+i,o=(d>>2)+24,b=d&3,y=s*p.dpn;if(w()&&console.debug(`MT-32 dev drum note ${o} param ${b}: ${n}`),o<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${o}`);return}[()=>{},()=>{e.#y[(y+R[26])*p.dnc+o]=Math.round(n*1.27)},()=>{e.#y[(y+R[26])*p.dnc+o]=n*9+1&127},()=>{e.#y[(y+R[26])*p.dnc+o]=n?127:0}][b]()})}else{let i=t[1];t.subarray(2).forEach((n,c)=>{let d=c+i;e.#_[d]=n;let o=e.chRedir(1+(d>>4),r,!0),b=d&15;([!1,()=>{let y=e.#_[o-1<<4];if(y<3)if(e.#D[o]=1,y==2)for(let k=0;k{e.#a[o*p.rpn+3]=n+40,e.#i[p.rpnt*o+2]=1},()=>{e.#a[o*p.rpn+1]=n+14,e.#i[p.rpnt*o+1]=1},()=>{e.#a[o*p.rpn]=n,e.#i[p.rpnt*o]=1},!1,()=>{e.#e[p.cc*o+u[91]]=n?127:0},!1,()=>{e.#e[p.cc*o+u[7]]=n},()=>{e.#e[p.cc*o+u[10]]=Math.ceil(n*9.05)}][b]||(()=>{}))()})}}).add([22,18,4],(t,r,f)=>{e.switchMode("mt32");let s=t[1]+(t[0]<<7),i=[];t.subarray(2).forEach((n,c)=>{let d=c+s,o=e.chRedir(Math.floor(d/246+1),r,!0),b=d%246;b<14&&(e.#P[(o-1)*p.cmt+b]=n),b<10&&(e.#D[o]=1),i.indexOf(o)<0&&i.push(o)}),i.forEach(n=>{e.dispatchEvent("voice",{part:n})})}).add([22,18,5],(t,r,f)=>{e.switchMode("mt32");let s=(t[0]<<7)+t[1];t.subarray(2).forEach((i,n)=>{let c=s+n,d=Math.floor(c/8),o=c&7,b=d*8;e.#re[c]=i,([!1,()=>{let y=e.#re[b];if(y<3){let k="";if(y==2){let D=p.cmt*d;k=`MT-m:${i.toString().padStart(3,"0")}`}else k=e.baseBank.get(0,i+(y<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:d});let x=`MSB LSB PRG NME -000 127 ${d} ${k}`;e.userBank.load(x,!0)}}][o]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(t,r,f)=>{e.switchMode("mt32");let s=((t[0]&1)<<7)+t[1],i=t[0]>>1,n=!1;if(t.subarray(2).forEach((c,d)=>{let o=s+d;o{e.switchMode("mt32");let s=t[1],i=!1,n=function(c,d){e.#f[d-12]=c,i=!0};t.subarray(2).forEach((c,d)=>{let o=d+s;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,n,n,n,n,n,n,n,n,n,()=>{e.#n=c,e.dispatchEvent("mastervolume",e.#n)}][o]||(()=>{}))(c,d)}),i&&e.buildRchTree()}).add([22,18,32],(t,r,f)=>{e.switchMode("mt32");let s=t[1],i=" ".repeat(s);t.subarray(2).forEach(n=>{n>31?i+=String.fromCharCode(n):i+=" "}),e.#X=i.padStart(20," "),e.#V=Date.now()+3200}).add([22,18,82],(t,r)=>{let f=e.chRedir(0,r,!0);for(let s=0;s<16;s++)e.#d.ano(f+s),s&&s<10&&(e.#s[f+s]=W[s-1]);console.info("MT-32 alt reset complete.")}),this.#U.add([66,0],(t,r)=>{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(r),2,m.ns5r),e.#o=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,r)=>{let f=["ns5r","05rw"][t[0]];e.switchMode(f,!0),e.setPortMode(e.getTrackPort(r),2,m[f]),e.#o=!1}).add([66,18,0,0],(t,r)=>{let f=t[0];switch(f){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(r),2,m.ns5r),e.#o=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${t}`);break}default:if(f<10){let s=[0,0,0,0],i=(n,c)=>{s[c]=n};if(t.subarray(1).forEach((n,c)=>{[i,i,i,i,()=>{e.#n=n*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},()=>n-64,()=>n-64,()=>{},()=>{},()=>{}][f+c]()}),t[0]<4){let n=0;s.forEach(c=>{n=n<<4,n+=c}),n-=1024}}}}).add([66,18,0,1],(t,r)=>{}).add([66,18,0,2],(t,r)=>{}).add([66,18,1],(t,r)=>{e.dispatchEvent("mupromptex");let f=e.chRedir(t[0],r,!0),s=f*p.cc,i=t[1],n=`NS5R CH${f+1} `;t.subarray(2).forEach((c,d)=>{let o=i+d;o<3?([()=>{e.#e[s+u[0]]=c||L.bank0},()=>{e.#e[s+u[32]]=c},()=>{e.#s[f]=c}][o](),e.dispatchEvent("voice",{part:f})):o<8||(o<14?[()=>{let b=e.chRedir(c,r,!0);e.#f[f]=b,f!=b&&(e.buildRchTree(),console.info(`${n}receives from CH${b+1}`))},()=>{e.#$[f]=+!c},()=>{e.setChType(f,c,m.ns5r),console.debug(`${n}type: ${I[c]}`)},()=>{e.#a[p.rpn*f+3]=c,e.#i[p.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{},()=>{}][o-8]():o<16||(o<33?[()=>{e.#e[s+u[7]]=c},()=>{e.#e[s+u[11]]=c},()=>{},()=>{},()=>{e.#e[s+u[10]]=c||128},()=>{},()=>{},()=>{e.#e[s+u[93]]=c},()=>{e.#e[s+u[91]]=c},()=>{e.#e[s+u[76]]=c},()=>{e.#e[s+u[77]]=c},()=>{e.#e[s+u[78]]=c},()=>{e.#e[s+u[74]]=c},()=>{e.#e[s+u[71]]=c},()=>{e.#e[s+u[73]]=c},()=>{e.#e[s+u[75]]=c},()=>{e.#e[s+u[72]]=c}][o-16]():o<112||o<114&&[()=>{e.#e[s+u[5]]=c},()=>{e.#e[s+u[65]]=c}][o-112]()))})}).add([66,18,8,0],(t,r)=>{let f=t[0];if(f<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let s=f-32;e.#M=Date.now()+3200,e.#g=10,e.#m.fill(0);let i=t.subarray(1),n=4;i.forEach(function(c,d){let o=d+s,b=o>>4,y=o&15;if(o<80){let k=b>3,x=0,D=b0;)e.#m[y*32+b*7+(D-x)]=k&1,k=k>>1,x++}})}}).add([66,18,48],(t,r,f)=>{g(0,t)}).add([66,18,49],(t,r,f)=>{g(1,t)}).add([66,18,50],(t,r,f)=>{g(2,t)}).add([66,18,51],(t,r,f)=>{g(3,t)}).add([66,18,52],(t,r,f)=>{g(4,t)}).add([66,18,53],(t,r,f)=>{g(5,t)}).add([66,18,54],(t,r,f)=>{g(6,t)}).add([66,18,55],(t,r,f)=>{g(7,t)}).add([66,52],(t,r)=>{e.switchMode("ns5r"),e.#o=!1;let f="";M(t,(s,i)=>{i<8?(s>31&&(f+=String.fromCharCode(s)),i==7&&(e.aiEfxName=f)):i<10&&(e.setEffectType(i-8,44,s),e.dispatchEvent(`efx${["reverb","chorus"][i-8]}`,e.getEffectType(i-8)))})}).add([66,53],(t,r)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r"),e.#o=!1;let f="",s=t[t.length-1],i=t.subarray(0,t.length-1),n=O(i);n!=s&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${n}, got ${s}.`),console.debug(t));let c=e.getTrackPort(r);if(e.#l[c]&&e.#l[c]!=m.ns5r)if(e.#L.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${r}. Port ${String.fromCharCode(65+c)} mode "${S[e.#l[c]]}" mismatch, should be "ns5r".`);return}else console.info(`Track ${r} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+c)}.`);e.setPortMode(c,2,m.ns5r),M(i,function(d,o){switch(!0){case o<2944:{let b=e.chRedir(Math.floor(o/92),r,!0),y=b*p.cc;switch(o%92){case 0:{e.#e[y+u[0]]=d,e.dispatchEvent("voice",{part:b});break}case 1:{e.#e[y+u[32]]=d,!d&&!e.#e[y+u[0]]&&(e.#e[y+u[0]]=L.bank0),e.dispatchEvent("voice",{part:b});break}case 2:{e.#s[b]=d,d>0&&e.setChActive(b,1),e.dispatchEvent("voice",{part:b});break}case 3:{let k=e.chRedir(d,r,!0);e.#f[b]=k,b!=k&&(console.info(`NS5R CH${b+1} receives from CH${k+1}.`),e.buildRchTree());break}case 7:{e.#r[b]=d,e.dispatchEvent("voice",{part:b});break}case 8:{e.#a[b*p.rpn+3]=d<40||d>88?d+(d>63?-192:64):d,e.#i[p.rpnt*b+2]=1,e.dispatchEvent("pitch",{part:b,pitch:e.getPitchShift(b)});break}case 9:case 10:{e.#e[y+u[7]]=d;break}case 11:{e.#e[y+u[11]]=d;break}case 14:{e.#e[y+u[10]]=d||128;break}case 19:{e.#e[y+u[93]]=d;break}case 20:{e.#e[y+u[91]]=d;break}case 84:{e.#e[y+u[65]]=d;break}case 85:{e.#e[y+u[5]]=d;break}}break}case o<3096:break;case o<3134:{let b=o-3096;b<8?(d>31&&(f+=String.fromCharCode(d)),b==7&&(e.aiEfxName=f)):b<10&&(e.setEffectType(b-8,44,d),e.dispatchEvent(`efx${["reverb","chorus"][b-8]}`,e.getEffectType(b-8)));break}case o<8566:break}})}).add([66,54],(t,r)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let f="",s=80,i=0,n=0,c="MSB PRG LSB NME";M(t,function(d,o){let b=o%158;switch(!0){case b<10:{d>31&&(f+=String.fromCharCode(d));break}case b==10:break;case b==11:{s=d&127;break}case b==12:{n=d&127;break}case b==13:{c+=` -${s} ${i} ${n} ${f.trim().replace("Init Voice","")}`,i++,f="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(c),w()&&console.debug(c),e.forceVoiceRefresh()}).add([66,55],(t,r)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let f="",s=88,i=0,n=0,c="MSB PRG LSB NME";M(t,function(d,o){let b=o%126;switch(!0){case b<10:{d>31&&(f+=String.fromCharCode(d));break}case b==11:break;case b==12:break;case b==13:{c+=` -${s} ${i} ${n} ${f.trim().replace("Init Combi","")}`,i++,f="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(c),w()&&console.debug(c),e.forceVoiceRefresh()}).add([66,125],(t,r,f)=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],(t,r,f)=>{let s=t[t.length-1],i=t.subarray(0,t.length-1),n=O(i);n!=s&&(console.info(`NS5R screen dump checksum mismatch! Expected ${n}, got ${s}.`),console.debug(t));let c=new Uint8Array(5760);M(t,(d,o,b)=>{if(o<720)for(let y=0;y<8;y++)c[o*8+y]=d>>7-y&1}),e.dispatchEvent("screen",{type:"ns5r",data:c})}).add([76],(t,r,f)=>{e.#U.run([66,...t],r,f)}),this.#j.add([16,0,8,0],(t,r,f)=>{let s=(t[2]<<4)+t[3],i="K11 ";([()=>{e.switchMode("k11",!0),e.setPortMode(e.getTrackPort(r),2,m.k11),e.#o=!1,e.#p[m.k11][1]=s?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,s),console.debug(`${i}reverb type: ${s}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${i}reverb time: ${s}`)},()=>{console.debug(`${i}reverb time: ${s}`)},()=>{console.debug(`${i}reverb predelay: ${s}`)},()=>{console.debug(`${i}reverb predelay: ${s}`)},()=>{console.debug(`${i}depth high: ${s}`)},()=>{console.debug(`${i}depth high: ${s}`)},()=>{console.debug(`${i}depth low: ${s}`)},()=>{console.debug(`${i}depth low: ${s}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,r,f)=>{e.dispatchEvent("mupromptex");let s=e.chRedir(t[1],r,!0),i=p.cc*s,n=p.rpn*s,c=(t[3]<<4)+t[4],d=`K11 CH${s+1} `;([()=>{c<128?(e.setChType(s,e.CH_MELODIC,m.k11),e.#e[i+u[0]]=0,e.#s[s]=c):(e.setChType(s,e.CH_DRUMS,m.k11),e.#s[s]=c-128),e.dispatchEvent("voice",{part:s})},()=>{let o=e.chRedir(c,r,!0);e.#f[s]=o,s!=o&&(e.buildRchTree(),console.info(`${d}receives from CH${o+1}`))},()=>{e.#e[i+u[7]]=c},()=>{uupThis.setChActive(s,c)},()=>{e.#e[i+u[10]]=c},()=>{e.#a[n+3]=c+40,e.#i[p.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{e.#a[n+1]=c>>1,e.#a[n+2]=c&1,e.#i[p.rpnt*s+1]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{e.#e[i+u[91]]=c?127:0},()=>{},()=>{e.#e[i+u[74]]=c},()=>{e.#e[i+u[73]]=c},()=>{e.#e[i+u[72]]=c}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,r,f)=>{e.dispatchEvent("mupromptex");let s=(t[2]<<4)+t[3],i="GMLX ";([()=>{console.debug(`${i}reverb type: ${s}`)},()=>{console.debug(`${i}reverb time: ${s}`)},()=>{console.debug(`${i}reverb predelay: ${s}`)},()=>{console.debug(`${i}depth high: ${s}`)},()=>{console.debug(`${i}depth low: ${s}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,r,f)=>{e.dispatchEvent("mupromptex");let s=(t[2]<<4)+t[3],i=e.chRedir(t[1],r,!0),n=i*p.cc;[()=>{s<128?(e.setChType(i,e.CH_MELODIC,m.k11),e.#e[n+u[0]]=0,e.#e[n+u[32]]=0,e.#s[i]=s):s<160?(e.setChType(i,e.CH_MELODIC,m.k11),e.#e[n+u[0]]=0,e.#e[n+u[32]]=7,e.#s[i]=s-100):(e.setChType(i,e.CH_DRUMS,m.k11),e.#e[n+u[0]]=122,e.#e[n+u[32]]=0,e.#s[i]=s-160),e.dispatchEvent("voice",{part:i})},()=>{let c=e.chRedir(s,r,!0);e.#f[i]=c,i!=c&&(e.buildRchTree(),console.info(`GMLX CH${i+1} receives from CH${c+1}`))}][t[0]]()}).add([16,0,9,4],(t,r,f)=>{e.dispatchEvent("mupromptex");let s=(t[2]<<4)+t[3],i=e.chRedir(t[1],r,!0),n=i*p.cc,c=i*p.rpn,d=`GMLX CH${i+1} `;[()=>{e.setChActive(i,s)},()=>{e.#e[n+u[7]]=s},()=>{e.#e[n+u[10]]=s},()=>{e.#e[n+u[91]]=s?127:0},()=>{e.#a[c+3]=s+40,e.#i[p.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{e.#a[c+1]=s,e.#i[p.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{e.#a[c]=s,e.#i[p.rpnt*i]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{}][t[0]]()}),this.#Z.add([66,93,64],(t,r,f)=>{let s=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{e.dispatchEvent("mupromptex"),e.#n=s*129/16383*100,e.dispatchEvent("mastervolume",e.#n);break}case 5:{e.dispatchEvent("mupromptex"),s-64;break}case 6:{e.dispatchEvent("mupromptex"),console.debug(`SG global reverb: ${s?"on":"off"}`);break}case 127:{e.switchMode("sg",!0),e.setPortMode(e.getTrackPort(r),1,m.sg);break}}break}case 1:{switch(t[1]){case 48:{e.dispatchEvent("mupromptex"),console.debug(`SG reverb type: ${z[s]}`);break}}break}default:if(t[0]>>4==1){e.dispatchEvent("mupromptex");let i=e.chRedir(t[0]&15,r,!0);if(t[1]==2){let n=e.chRedir(s,r,!0);e.#f[i]=n,i!=n&&(e.buildRchTree(),console.info(`SG CH${i+1} receives from CH${n+1}`))}else t[1]==19&&(e.#e[p.cc*i+u[7]]=s)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),this.#ee.add([9],(t,r,f)=>{e.dispatchEvent("mupromptex"),console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremolo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)}),this.#x.add([127,0],(t,r,f)=>{e.switchMode("motif");let s=new Uint8Array([127,1,...t]);e.#x.run(s,r,f)}).add([127,1,0,0],(t,r,f)=>{e.switchMode("s90es");let s="S90/Motif ES system ",i=t[0];t.subarray(1).forEach((n,c)=>{([()=>{e.#n=n*12900/16383,e.dispatchEvent("mastervolume",e.#n)}][i+c]||(()=>{console.info(`Unrecognized ${s}ID: ${i+c}`)}))()})}).add([127,1,0,36,54,1],(t,r,f)=>{e.switchMode("s90es");let s="S90/Motif ES reverb ",i=t[0];t.subarray(1).forEach((n,c)=>{([()=>{e.setEffectTypeRaw(0,!1,n&15|112)},()=>{e.setEffectTypeRaw(0,!0,n)}][i+c]||(()=>{}))()}),e.dispatchEvent("efxreverb",e.getEffectType(0))}).add([127,1,0,37,54,2],(t,r,f)=>{e.switchMode("s90es");let s="S90/Motif ES chorus ",i=t[0];t.subarray(1).forEach((n,c)=>{([()=>{e.setEffectTypeRaw(1,!1,n&15|112)},()=>{e.setEffectTypeRaw(1,!0,n)}][i+c]||(()=>{}))()}),e.dispatchEvent("efxchorus",e.getEffectType(1))}).add([127,1,0,34,54,3],(t,r,f)=>{e.switchMode("s90es");let s="S90/Motif ES insert 1 ",i=t[0];t.subarray(1).forEach((n,c)=>{([()=>{e.setEffectTypeRaw(3,!1,n&15|112)},()=>{e.setEffectTypeRaw(3,!0,n)}][i+c]||(()=>{}))()}),e.dispatchEvent("efxinsert0",e.getEffectType(3))}).add([127,1,0,34,54,4],(t,r,f)=>{e.switchMode("s90es");let s="S90/Motif ES insert 2 ",i=t[0];t.subarray(1).forEach((n,c)=>{([()=>{e.setEffectTypeRaw(4,!1,n&15|112)},()=>{e.setEffectTypeRaw(4,!0,n)}][i+c]||(()=>{}))()}),e.dispatchEvent("efxinsert1",e.getEffectType(4))}).add([127,1,0,35,54,17],(t,r,f)=>{e.switchMode("s90es");let s="S90/Motif ES variation ",i=t[0];t.subarray(1).forEach((n,c)=>{([()=>{e.setEffectTypeRaw(2,!1,n&15|112)},()=>{e.setEffectTypeRaw(2,!0,n)}][i+c]||(()=>{}))()}),e.dispatchEvent("efxdelay",e.getEffectType(2))}).add([127,1,0,58,55],(t,r,f)=>{e.dispatchEvent("mupromptex"),e.switchMode("s90es");let s=e.getTrackPort(r);if(e.#l[s]&&e.#l[s]!=e.#c.smotif)if(e.#L.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${r}. Port ${String.fromCharCode(65+s)} mode "${S[e.#l[s]]}" mismatch, should be "${S[e.#c.smotif]}".`);return}else console.info(`Track ${r} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+s)}.`);let i=e.chRedir(t[0],r,!0),n=p.cc*i,c=t[1];t[0]>15&&(i=t[0]+32);let d=`Track ${r} S90/Motif ES bulk CH${i<128?i+1:"U"+(i-127)} `;console.debug(d,t),!(t[0]>15)&&t.subarray(2).forEach((o,b)=>{([()=>{e.#e[n+u[0]]=o,e.dispatchEvent("voice",{part:i})},()=>{o&&e.setChActive(i,1),e.#e[n+u[32]]=o,e.setChType(i,[32,40].indexOf(o)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:i})},()=>{o&&e.setChActive(i,1),e.#s[i]=o,e.dispatchEvent("voice",{part:i})},()=>{let y=e.chRedir(o,r,!0);e.#f[i]=y,i!=y&&(e.buildRchTree(),console.info(`${d}receives from CH${y+1}`))},()=>{e.#$[i]=o?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{o!=100&&e.setChActive(i,1),e.#e[n+u[7]]=o},()=>{o!=64&&e.setChActive(i,1),e.#e[n+u[10]]=o},!1,!1,!1,()=>{e.#e[n+u[91]]=o},()=>{o&&e.setChActive(i,1),e.#e[n+u[93]]=o},()=>{o&&e.setChActive(i,1),e.#e[n+u[94]]=o},()=>{o!=127&&e.setChActive(i,1),e.#e[n+u[128]]=o,e.allocateAce(128)},()=>{},()=>{o!=64&&e.setChActive(i,1),e.#e[n+u[74]]=o},()=>{o!=64&&e.setChActive(i,1),e.#e[n+u[71]]=o},!1,()=>{e.#e[n+u[65]]=o},()=>{e.#e[n+u[5]]=o},()=>{}][c+b]||(()=>{}))()})}).add([127,1,54,16],(t,r,f)=>{e.switchMode("s90es");let s=t[0];t.subarray(1).forEach((i,n)=>{let d=`S90/Motif ES EQ${(n>>2)+1} `;([()=>{let o=i-64},()=>{let o=A[i]},()=>{let o=i/10},()=>{let o=i}][s+n&3]||(()=>{}))()})}),this.#T.add([0,72,18,0,0,0,0],(t,r,f)=>{e.switchMode("sd",!0),e.setPortMode(e.getTrackPort(r),2,m.sd),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(t,r,f)=>{e.dispatchEvent("mupromptex");let s=t[0]>>5,i=t[0]&31;switch(s){case 0:{let n=t[0]>>1,c=t[1];switch(n){case 1:{t.subarray(2).forEach((d,o,b)=>{let y=o+c;switch(y){case 0:{d&&(e.setEffectType(1,60,d-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${y} - ${d}`));break}}});break}case 2:{t.subarray(2).forEach((d,o)=>{let b=o+c;switch(b){case 0:{d&&(e.setEffectType(0,55+d,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${b} - ${d}`));break}}});break}case 3:case 4:case 5:{let d=n-1;t.subarray(2).forEach((o,b)=>{let y=b+c;switch(console.debug(`SD MFX ${d-2}: ${y} - ${o}`),y){case 0:{e.setEffectTypeRaw(d,62,o),e.dispatchEvent(`efx${d>2?"delay":"insert"+(d-4)}`,e.getEffectType(d));break}}}),console.debug(`SD MFX message: +`,t);return}a.run(s.subarray(1))}).add([100,76],(t,r,d)=>{let s=t[0]>>4,i=t[0]&15,n=t[1];switch(s){case 2:{let c=e.chRedir(i,r,!0),f=p.cc*c;t.subarray(2).forEach((o,b)=>{let y=b+n;if(!(y<7)){if(y<23){let k=y+135;e.allocateAce(k),e.#e[f+u[k]]=o,e.dispatchEvent("cc",{part:c,cc:k,data:o})}}});break}default:console.info("Unknown DX7+ multipart: %o",t)}}).add([1,20],(t,r,d)=>{d==115?(e.switchMode("doc",!0),e.setPortMode(e.getTrackPort(r),1,m.doc),console.info("MIDI reset: DOC")):console.debug(`Unknown Yamaha SysEx: 67, ${d}, ${t.join(", ")}`)}).add([1,17,15,89],(t,r,d)=>{d==115?(e.setEffectType(0,24,t[0]|16),e.dispatchEvent("efxreverb",e.getEffectType(0))):console.debug(`Unknown Yamaha SysEx: 67, ${d}, ${t.join(", ")}`)}).add([1,24],(t,r,d)=>{if(d==115){for(let s=0;s<16;s++){let i=e.chRedir(s,r,!0);e.#e[i*p.cc+u[91]]=127}console.info("DOC Global Reverb: on")}else console.debug(`Unknown Yamaha SysEx: 67, ${d}, ${t.join(", ")}`)}),a.add([14,31],(t,r,d)=>{e.#e[p.cc*t[0]+u[64]]=0,e.#d.ano(t[0]),e.switchMode("xg"),e.setPortMode(e.getTrackPort(r),1,m.xg),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${t[0]+1}.`)}).add([76,112],async t=>{let r=t[0],d=p.cc*r,s=p.ext*r,i=p.cvn*r;e.#v[s]=e.EXT_DX,e.#D[r]=1;let n=e.#ne.subarray(i,i+p.cvn);n.fill(32),t.subarray(1).forEach((c,f)=>{if(f<10)n[f]=Math.max(c,32);else if(!(f<40)){if(f<56){let o=f+102;e.#e[d+u[o]]=c,e.dispatchEvent("cc",{part:r,cc:o,data:c})}}}),e.#s[r]=r&127,e.#e[p.cc*r+u[0]]=35,e.#e[p.cc*r+u[32]]=r>>7|4,e.dispatchEvent("voice",{part:r}),console.debug(`DX7+ CH${r+1} dump: %o`,t)});let h=function(t,r,d,s){},g=function(t,r){e.dispatchEvent("mupromptex");let d=t*p.dpn,s=r[0],i=r[1];r.subarray(2).forEach((n,c)=>{let f=c+i,o=-1;f<16?([()=>{o=24},()=>{o=25},()=>{o=26},()=>{},()=>{o=28},()=>{o=29},()=>{o=30},()=>{o=31},()=>{},()=>{},()=>{},()=>{o=20},()=>{o=21},()=>{o=22},()=>{o=23},()=>{}][f]||(()=>{console.debug(`Unknown XG-style drum param ${f} on set ${t+1}.`)}))():f<32||(f<40?([()=>{o=48},()=>{o=49},!1,!1,()=>{o=52},()=>{o=53}][f-32]||(()=>{console.debug(`Unknown XG-style drum param ${f} on set ${t+1}.`)}))():f<80||([()=>{o=36}][f-80]||(()=>{console.debug(`Unknown XG-style drum param ${f} on set ${t+1}.`)}))()),o>=0?(w()&&console.debug(d,o,s,n),e.#y[(d+R[o])*p.dnc+s]=n):w()&&console.debug(`XG-style drum param ${f} has no writes.`)})},E=function(t,r,d){e.dispatchEvent("mupromptex");let s=t*p.dpn,i=(r<<7)+d[0];d.subarray(1).forEach((n,c)=>{let f=c+i,o=f&127,b=f>>7,y=-1;b>1&&([()=>{y=26},()=>{},()=>{y=28},()=>{y=29},()=>{y=30},()=>{},()=>{},()=>{y=31}][b-2]||(()=>{console.debug(`Unknown GS-style drum param ${b} on set ${t+1}.`)}))(),y>-1?(w()&&console.debug(s,y,o,n),e.#y[(s+R[y])*p.dnc+o]=n):w()&&console.debug(`GS-style drum param ${b} has no writes.`)})};this.#x.add([76,48],(t,r,d)=>{g(0,t)}).add([76,49],(t,r,d)=>{g(1,t)}).add([76,50],(t,r,d)=>{g(2,t)}).add([76,51],(t,r,d)=>{g(3,t)}).add([76,52],(t,r,d)=>{g(4,t)}).add([76,53],(t,r,d)=>{g(5,t)}).add([76,54],(t,r,d)=>{g(6,t)}).add([76,55],(t,r,d)=>{g(7,t)}),this.#x.add([89,0],(t,r,d)=>{if(e.eprom){let s=t[0],i=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);w()&&console.debug(`MU1000 EPROM trail to 0x${i.toString(16).padStart(6,"0")}, ${s} bytes.`);let n=e.eprom.data;t.subarray(4).forEach((c,f)=>{let o=f>>3,b=f&7;if(b==7)for(let y=0;y<7;y++)n[i+7*o+y]+=(c>>6-y&1)<<7;else n[i+7*o+b]=c})}}).add([89,1],(t,r,d)=>{let s=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];w()&&console.debug(`MU1000 EPROM jump to 0x${s.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=s)}).add([89,2],(t,r,d)=>{if(e.eprom){let s=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);w()&&console.debug(`MU1000 EPROM write to 0x${s.toString(16).padStart(6,"0")}.`);let i=e.eprom.data;t.subarray(4).forEach((n,c)=>{let f=c>>3,o=c&7;if(o==7)for(let b=0;b<7;b++)i[s+7*f+b]+=(n>>6-b&1)<<7;else i[s+7*f+o]=n})}}).add([89,3],(t,r,d)=>{}),this.#x.add([39,48],(t,r,d)=>{}).add([43,0,0],(t,r,d)=>{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(n,c)=>{s[c]=n};if(t.subarray(1).forEach((n,c)=>{let f=c+t[0];[i,i,i,i,()=>{this.#n=n*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},()=>n-64,()=>n||128,()=>n,()=>n,()=>{console.debug(`TG300 variation on cc${n}.`)}][f](n,f)}),t[0]<4){let n=0;s.forEach(c=>{n=n<<4,n+=c}),n-=1024}}).add([43,1,0],(t,r,d)=>{e.dispatchEvent("mupromptex")}).add([43,2],(t,r,d)=>{e.dispatchEvent("mupromptex");let s=e.chRedir(t[0],r,!0),i=t[1],n=p.cc*s,c=`TG300 CH${s+1} `;t.subarray(2).forEach((f,o)=>{o<5?([()=>{},()=>{e.#e[n+u[0]]=f,e.dispatchEvent("voice",{part:s})},()=>{e.#e[n+u[32]]=f,e.dispatchEvent("voice",{part:s})},()=>{e.#s[s]=f,e.dispatchEvent("voice",{part:s})},()=>{let b=e.chRedir(f,r,!0);e.#f[s]=b,s!=b&&(e.buildRchTree(),console.info(`${c}receives from CH${b+1}`))}][o+i]||(()=>{}))(f,o+i):o<21||(o<47?([()=>{e.#$[s]=+!f},()=>{},()=>{},()=>{e.#a[p.rpn*s+3]=f,e.#i[p.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{},()=>{e.#e[n+u[7]]=f},!1,!1,()=>{e.#e[n+u[10]]=f||128},!1,!1,()=>{console.debug(`${c} AC1 at cc${f}`)},()=>{console.debug(`${c} AC2 at cc${f}`)},()=>{e.#e[n+u[128]]=f,e.allocateAce(128)},()=>{e.#e[n+u[93]]=f},()=>{e.#e[n+u[91]]=f},()=>{e.#e[n+u[94]]=f},()=>{e.#e[n+u[76]]=f},()=>{e.#e[n+u[77]]=f},()=>{e.#e[n+u[74]]=f},()=>{e.#e[n+u[71]]=f},()=>{e.#e[n+u[73]]=f},()=>{e.#e[n+u[75]]=f},()=>{e.#e[n+u[72]]=f},()=>{e.#e[n+u[78]]=f}][o+i-21]||(()=>{}))(f,o+i):o<95||([()=>{e.#e[n+u[65]]=f},()=>{e.#e[n+u[5]]=f}][o+i-95]||(()=>{}))(f,o+i))})}).add([43,7,0],(t,r,d)=>{let s=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",s)}).add([43,7,1],(t,r,d)=>{e.#g=0,e.#M=Date.now()+3200,e.#m.fill(0),t.forEach(function(s,i){let n=Math.floor(i/16),c=i%16,f=(c*3+n)*7,o=7,b=0;for(f-=c*5,n==2&&(o=2);b>6-b&1,b++})}),this.#T.add([66,18,0,0,127],(t,r,d)=>{e.switchMode("sc",!0),e.setPortMode(e.getTrackPort(r),2,m.sc),e.#e[p.cc*9]=120,e.#e[p.cc*25]=120,e.#e[p.cc*41]=120,e.#e[p.cc*57]=120,e.#p[m.sc][1]=e.#c.sc,e.#o=!1,e.#I.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,r,d)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.setPortMode(e.getTrackPort(r),2,m.gs),e.#p[m.gs][1]=e.#c.gs,e.#e[p.cc*9]=120,e.#e[p.cc*25]=120,e.#e[p.cc*41]=120,e.#e[p.cc*57]=120,e.#o=!1,e.#I.fill(0),console.info("MIDI reset: GS");break}default:{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(n,c)=>{s[c]=n};if(t.subarray(1).forEach((n,c)=>{let f=c+t[0];[i,i,i,i,o=>{this.#n=o*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},o=>{},o=>{}][f](n,c)}),t[0]<4){let n=0;s.forEach(c=>{n=n<<4,n+=c}),n-=1024}}}}).add([66,18,64,1],(t,r,d)=>{e.dispatchEvent("mupromptex");let s=t[0];if(s<16){let i="".padStart(s," ");t.subarray(1).forEach((n,c)=>{i+=String.fromCharCode(Math.max(32,n))}),i=i.padEnd(16," "),console.debug(`GS patch name: ${i}`)}else s<48||(s<65?t.subarray(1).forEach((i,n)=>{let c=`GS ${s+n>55?"chorus":"reverb"} `;([()=>{console.info(`${c}type: ${z[i]}`),e.setEffectType(0,40,i),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${c}predelay: ${i}ms`)},()=>{console.info(`${c}type: ${ie[i]}`),e.setEffectType(1,40,16+i),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${c}to reverb: ${C(i)}`)},()=>{console.debug(`${c}to delay: ${C(i)}`)}][s+n-48]||(()=>{}))()}):s<80?console.debug(`Unknown GS patch address: ${s}`):s<91?t.subarray(1).forEach((i,n)=>{let c="GS delay ";([()=>{console.info(`${c}type: ${ce[i]}`),e.setEffectType(2,40,32+i),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${c}to reverb: ${C(i)}`)}][s+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${s}`))}).add([66,18,64,2],(t,r,d)=>{let s="GS EQ ";t.subarray(1).forEach((i,n)=>{([()=>{console.debug(`${s}low freq: ${[200,400][i]}Hz`)},()=>{console.debug(`${s}low gain: ${i-64}dB`)},()=>{console.debug(`${s}high freq: ${[3e3,6e3][i]}Hz`)},()=>{console.debug(`${s}high gain: ${i-64}dB`)}][t[0]+n]||function(){console.warn(`Unknown GS EQ address: ${t[0]+n}`)})()})}).add([66,18,64,3],(t,r,d)=>{e.dispatchEvent("mupromptex");let s="GS EFX ",i=function(n,c){let f=ne(e.#k.subarray(10,12),c,n);f&&console.debug(`${s}${q(e.#k.subarray(10,12))} ${f}`)};t.subarray(1).forEach((n,c)=>{([()=>{e.setEffectTypeRaw(3,!1,32+n),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,n),console.info(`${s}type: ${q(e.#k.subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,()=>{console.debug(`${s}to reverb: ${C(n)}dB`)},()=>{console.debug(`${s}to chorus: ${C(n)}dB`)},()=>{console.debug(`${s}to delay: ${C(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]+c]||function(f,o){console.warn(`Unknown GS EFX address: ${o}`)})(n,t[0]+c)})}).add([66,18,65],(t,r,d)=>{E((t[0]>>4)+1<<1,t[0]&15,t.subarray(1))}).add([69,18,16],(t,r,d)=>{switch(t[0]){case 0:{let s=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",s);break}case 32:{e.#M=Date.now()+3200,t[1]==0&&(t[2]?(e.#g=Math.max(Math.min(t[2]-1,9),0),w()&&console.debug(`GS switch display page ${t[2]-1}.`)):(e.#g=0,e.#M=Date.now(),w()&&console.debug("GS disable display page.")));break}default:if(t[0]<6){e.#g>9&&(e.#g=0);let s=t[0]-1<<1|t[1]>>6;e.#g==s&&(e.#M=Date.now()+3200),e.#N[s]?.length||(e.#N[s]=new Uint8Array(256));let i=e.#N[s];w()&&console.debug(`GS frame draw page ${s}.`);let n=t[1]&63;i.fill(0),t.subarray(2).forEach(function(f,o){let b=o+n,y=Math.floor(b/16),k=b%16,x=(k*4+y)*5,D=5,G=0;for(x-=k*4,y==3&&(D=1);G>4-G&1,G++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let v=function(t,r,d){e.dispatchEvent("mupromptex");let s=t[0],i=p.cc*r,n=p.rpn*r,c=`GS CH${r+1} `;s<3?(t.subarray(1).forEach((f,o)=>{[()=>{e.#e[i+u[0]]=f},()=>{e.#s[r]=f},()=>{let b=0;f<16?b=e.chRedir(f,d,!0):b=p.ch,e.#f[r]=b,r!=b&&(e.buildRchTree(),console.info(`${c}receives from CH${b+1}`))}][s+o]()}),e.dispatchEvent("voice",{part:r})):s<19||(s<44?t.subarray(1).forEach((f,o)=>{([()=>{e.#$[r]=+!f},!1,()=>{e.setChType(r,f<<1,m.gs),console.debug(`${c}type: ${f?"drum ":"melodic"}${f||""}`)},()=>{e.#a[n+3]=f,e.#i[p.rpnt*r+2]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},!1,()=>{e.#e[i+u[7]]=f},!1,!1,()=>{e.#e[i+u[10]]=f||128},!1,!1,()=>{console.debug(`${c}CC 1: cc${f}`)},()=>{console.debug(`${c}CC 2: cc${f}`)},()=>{e.#e[i+u[93]]=f},()=>{e.#e[i+u[91]]=f},!1,!1,()=>{e.#a[n+1]=f,e.#i[p.rpnt*r+1]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{e.#a[n+2]=f,e.#i[p.rpnt*r+1]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{e.#e[i+u[94]]=f}][s+o-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},$=function(t,r){let d=t[0],s=`GS CH${r+1} `;d<2?t.subarray(1).forEach((i,n)=>{[()=>{e.#e[p.cc*r+u[32]]=i},()=>{}][d+n]()}):d<32?console.warn(`Unknown GS misc address: ${d}`):d<35?t.subarray(1).forEach((i,n)=>{[()=>{console.debug(`${s}EQ: o${["ff","n"][i]}`)},()=>{},()=>{console.debug(`${s}EFX: o${["ff","n"][i]}`),e.#ae[r]=i,e.dispatchEvent("partefxtoggle",{part:r,active:i})}][d+n-32]()}):console.warn(`Unknown GS misc address: ${d}`)};this.#T.add([66,18,64,16],(t,r)=>{v(t,e.chRedir(9,r,!0),r)}).add([66,18,64,17],(t,r)=>{v(t,e.chRedir(0,r,!0),r)}).add([66,18,64,18],(t,r)=>{v(t,e.chRedir(1,r,!0),r)}).add([66,18,64,19],(t,r)=>{v(t,e.chRedir(2,r,!0),r)}).add([66,18,64,20],(t,r)=>{v(t,e.chRedir(3,r,!0),r)}).add([66,18,64,21],(t,r)=>{v(t,e.chRedir(4,r,!0),r)}).add([66,18,64,22],(t,r)=>{v(t,e.chRedir(5,r,!0),r)}).add([66,18,64,23],(t,r)=>{v(t,e.chRedir(6,r,!0),r)}).add([66,18,64,24],(t,r)=>{v(t,e.chRedir(7,r,!0),r)}).add([66,18,64,25],(t,r)=>{v(t,e.chRedir(8,r,!0),r)}).add([66,18,64,26],(t,r)=>{v(t,e.chRedir(10,r,!0),r)}).add([66,18,64,27],(t,r)=>{v(t,e.chRedir(11,r,!0),r)}).add([66,18,64,28],(t,r)=>{v(t,e.chRedir(12,r,!0),r)}).add([66,18,64,29],(t,r)=>{v(t,e.chRedir(13,r,!0),r)}).add([66,18,64,30],(t,r)=>{v(t,e.chRedir(14,r,!0),r)}).add([66,18,64,31],(t,r)=>{v(t,e.chRedir(15,r,!0),r)}).add([66,18,64,64],(t,r)=>{$(t,e.chRedir(9,r,!0))}).add([66,18,64,65],(t,r)=>{$(t,e.chRedir(0,r,!0))}).add([66,18,64,66],(t,r)=>{$(t,e.chRedir(1,r,!0))}).add([66,18,64,67],(t,r)=>{$(t,e.chRedir(2,r,!0))}).add([66,18,64,68],(t,r)=>{$(t,e.chRedir(3,r,!0))}).add([66,18,64,69],(t,r)=>{$(t,e.chRedir(4,r,!0))}).add([66,18,64,70],(t,r)=>{$(t,e.chRedir(5,r,!0))}).add([66,18,64,71],(t,r)=>{$(t,e.chRedir(6,r,!0))}).add([66,18,64,72],(t,r)=>{$(t,e.chRedir(7,r,!0))}).add([66,18,64,73],(t,r)=>{$(t,e.chRedir(8,r,!0))}).add([66,18,64,74],(t,r)=>{$(t,e.chRedir(10,r,!0))}).add([66,18,64,75],(t,r)=>{$(t,e.chRedir(11,r,!0))}).add([66,18,64,76],(t,r)=>{$(t,e.chRedir(12,r,!0))}).add([66,18,64,77],(t,r)=>{$(t,e.chRedir(13,r,!0))}).add([66,18,64,78],(t,r)=>{$(t,e.chRedir(14,r,!0))}).add([66,18,64,79],(t,r)=>{$(t,e.chRedir(15,r,!0))}),this.#U.add([54,65],(t,r)=>{let d=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(d,!0),e.setPortMode(e.getTrackPort(r),1,m[d]);let s=t[t.length-1],i=t.subarray(0,t.length-1),n=O(i);n!=s&&(console.info(`X5D multi parameters checksum mismatch! Expected ${n}, got ${s}.`),console.debug(t));let c=(t[1]<<7)+t[0],f=(t[3]<<7)+t[2],o=e.chRedir(c&15,r,!0),b=p.cc*o;[()=>{f<1||(f<101?(e.setChType(o,e.CH_MELODIC,m.x5d),e.#s[o]=f-1,e.#e[b+u[0]]=e.#c.x5):f<229?(e.setChType(o,e.CH_MELODIC,m.x5d),e.#s[o]=f-101,e.#e[b+u[0]]=56):(e.setChType(o,e.CH_DRUMS,m.x5d),e.#s[o]=ge[f-229]||0,e.#e[b+u[0]]=62)),e.dispatchEvent("voice",{part:o})},()=>{e.#e[b+u[7]]=f},()=>{f<31&&(e.#e[b+u[10]]=Math.round((f-15)*4.2+64))},()=>{e.#e[b+u[93]]=B(f)},()=>{e.#e[b+u[91]]=B(f)},()=>{e.#a[o*p.rpn+3]=f>8191?f-16320:64+f,e.#i[p.rpnt*o+2]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)})},()=>{e.#a[o*p.rpn+1]=f>8191?f-16320:64+f,e.#i[p.rpnt*o+1]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)})},()=>{f>0&&(e.#a[o*p.rpn]=f,e.#i[p.rpnt*o]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)}))},()=>{}][c>>4]()}).add([54,76,0],(t,r)=>{e.dispatchEvent("mupromptex");let d=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(d),e.setPortMode(e.getTrackPort(r),1,m[d]);let s="",i=e.#c.x5,n=0,c=0,f="MSB PRG LSB NME";M(t,function(o,b){if(b<16400){let y=b%164;switch(!0){case y<10:{o>31&&(s+=String.fromCharCode(o));break}case y==10:break;case y==11:{f+=` +${i} ${n} ${c} ${s.trim().replace("Init Voice","")}`,n++,s="";break}}n>99&&(i=90,n=0)}}),e.userBank.clearRange({msb:e.#c.x5,prg:[0,99],lsb:0}),e.userBank.load(f),w()&&console.debug(f),e.forceVoiceRefresh()}).add([54,77,0],(t,r)=>{e.dispatchEvent("mupromptex");let d=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(d),e.setPortMode(e.getTrackPort(r),1,m[d]);let s="",i=90,n=0,c=0,f="MSB PRG LSB NME";M(t,function(o,b){if(b<13600){let y=b%136;switch(!0){case y<10:{o>31&&(s+=String.fromCharCode(o));break}case y==11:{f+=` +${i} ${n} ${c} ${s.trim().replace("Init Combi","")}`,n++,s="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f),w()&&console.debug(f),e.forceVoiceRefresh()}).add([54,78],(t,r)=>{let d=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(d),e.setPortMode(e.getTrackPort(r),1,m[d]),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][t[0]]} mode.`)}).add([54,85],(t,r)=>{e.dispatchEvent("mupromptex");let d=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(d),e.setPortMode(e.getTrackPort(r),1,m[d]),M(t,(s,i)=>{i>0&&i<3&&(e.setEffectType(i-1,44,s),e.dispatchEvent(`efx${["reverb","chorus"][i-1]}`,e.getEffectType(i-1)))})}).add([54,104],(t,r)=>{e.dispatchEvent("mupromptex");let d=e.#c.x5=="81"?"05rw":"x5d";e.switchMode(d,!0);let s=e.getTrackPort(r);if(e.#l[s]&&e.#l[s]!=m[d])if(e.#L.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${r}. Port ${String.fromCharCode(65+s)} mode "${S[e.#l[s]]}" mismatch, should be "${d}".`);return}else console.info(`Track ${r} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+s)}.`);e.setPortMode(s,1,m[d]),M(t,function(i,n,c,f){if(n<192){let o=e.chRedir(Math.floor(n/12),r,!0),b=o*p.cc;switch(n%12){case 0:{i<128?(e.setChType(o,e.CH_MELODIC,m.x5d),e.#e[b+u[0]]=e.#c.x5,e.#s[o]=i):(e.setChType(o,e.CH_DRUMS,m.x5d),e.#e[b+u[0]]=62,e.#s[o]=ge[i-128]),i>0&&e.setChActive(o,1),e.dispatchEvent("voice",{part:o});break}case 1:{e.#e[b+u[7]]=i;break}case 2:{e.#a[o*p.rpn+3]=i>127?i-192:64+i,e.#i[p.rpnt*o+2]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)});break}case 3:{e.#a[o*p.rpn+1]=i>127?i-192:64+i,e.#i[p.rpnt*o+1]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)});break}case 4:{i<31&&(e.#e[b+u[10]]=Math.round((i-15)*4.2+64));break}case 5:{let y=i>>4,k=i&15;e.#e[b+u[91]]=B(k),e.#e[b+u[93]]=B(y);break}case 10:break;case 11:{let y=e.chRedir(i&15,r,!0),k=i>>4;e.#f[o]=i,(y!=o||k)&&(console.info(`X5D Part CH${o+1} receives from CH${y+1}.`),e.buildRchTree())}}}else{let o=e.chRedir(n-192,r,!0)}})}),this.#T.add([22,18,127],(t,r,d)=>{e.switchMode("mt32",!0),e.setPortMode(e.getTrackPort(r),1,m.mt32),e.#o=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(t,r,d)=>{e.switchMode("mt32");let s=e.chRedir(d,r,!0),i=t[1];t.subarray(2).forEach((n,c)=>{let f=c+i;e.#_[f+(s-1)*16]=n,([!1,()=>{let o=e.#_[s-1<<4];if(o<3){if(e.#D[s]=1,o==2)for(let b=0;b{e.#a[s*p.rpn+3]=n+40,e.#i[p.rpnt*s+2]=1},()=>{e.#a[s*p.rpn+1]=n+14,e.#i[p.rpnt*s+1]=1},()=>{e.#a[s*p.rpn]=n,e.#i[p.rpnt*s]=1},!1,()=>{e.#e[p.cc*s+u[91]]=n?127:0},!1,()=>{e.#e[p.cc*s+u[7]]=n},()=>{e.#e[p.cc*s+u[10]]=Math.ceil(n*9.05)}][f]||(()=>{}))()})}).add([22,18,1],(t,r,d)=>{e.switchMode("mt32");let s=d&7;console.debug(`MT-32 slot #${d+1} Drum: ${t}`);let i=t[0]<<7|t[1];t.subarray(2).forEach((n,c)=>{let f=c+i,o=(f>>2)+24,b=f&3,y=s*p.dpn;if(w()&&console.debug(`MT-32 temp drum note ${o} param ${b}: ${n}`),o<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${o}`);return}[()=>{},()=>{e.#y[(y+R[26])*p.dnc+o]=Math.round(n*1.27)},()=>{e.#y[(y+R[26])*p.dnc+o]=n*9+1&127},()=>{e.#y[(y+R[26])*p.dnc+o]=n?127:0}][b]()})}).add([22,18,2],(t,r,d)=>{e.switchMode("mt32");let s=e.chRedir(d,r,!0),i=t[1]+(t[0]<<7);i<10&&(e.#D[s]=1),t.subarray(2).forEach((n,c)=>{let f=c+i;f<14&&(e.#P[(s-1)*p.cmt+f]=n)}),e.dispatchEvent("voice",{part:s})}).add([22,18,3],(t,r,d)=>{e.switchMode("mt32");let s=d&7;if(t[0]){let i=(t[0]-1<<7)+t[1]-16;t.subarray(2).forEach((n,c)=>{let f=c+i,o=(f>>2)+24,b=f&3,y=s*p.dpn;if(w()&&console.debug(`MT-32 dev drum note ${o} param ${b}: ${n}`),o<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${o}`);return}[()=>{},()=>{e.#y[(y+R[26])*p.dnc+o]=Math.round(n*1.27)},()=>{e.#y[(y+R[26])*p.dnc+o]=n*9+1&127},()=>{e.#y[(y+R[26])*p.dnc+o]=n?127:0}][b]()})}else{let i=t[1];t.subarray(2).forEach((n,c)=>{let f=c+i;e.#_[f]=n;let o=e.chRedir(1+(f>>4),r,!0),b=f&15;([!1,()=>{let y=e.#_[o-1<<4];if(y<3)if(e.#D[o]=1,y==2)for(let k=0;k{e.#a[o*p.rpn+3]=n+40,e.#i[p.rpnt*o+2]=1},()=>{e.#a[o*p.rpn+1]=n+14,e.#i[p.rpnt*o+1]=1},()=>{e.#a[o*p.rpn]=n,e.#i[p.rpnt*o]=1},!1,()=>{e.#e[p.cc*o+u[91]]=n?127:0},!1,()=>{e.#e[p.cc*o+u[7]]=n},()=>{e.#e[p.cc*o+u[10]]=Math.ceil(n*9.05)}][b]||(()=>{}))()})}}).add([22,18,4],(t,r,d)=>{e.switchMode("mt32");let s=t[1]+(t[0]<<7),i=[];t.subarray(2).forEach((n,c)=>{let f=c+s,o=e.chRedir(Math.floor(f/246+1),r,!0),b=f%246;b<14&&(e.#P[(o-1)*p.cmt+b]=n),b<10&&(e.#D[o]=1),i.indexOf(o)<0&&i.push(o)}),i.forEach(n=>{e.dispatchEvent("voice",{part:n})})}).add([22,18,5],(t,r,d)=>{e.switchMode("mt32");let s=(t[0]<<7)+t[1];t.subarray(2).forEach((i,n)=>{let c=s+n,f=Math.floor(c/8),o=c&7,b=f*8;e.#re[c]=i,([!1,()=>{let y=e.#re[b];if(y<3){let k="";if(y==2){let D=p.cmt*f;k=`MT-m:${i.toString().padStart(3,"0")}`}else k=e.baseBank.get(0,i+(y<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:f});let x=`MSB LSB PRG NME +000 127 ${f} ${k}`;e.userBank.load(x,!0)}}][o]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(t,r,d)=>{e.switchMode("mt32");let s=((t[0]&1)<<7)+t[1],i=t[0]>>1,n=!1;if(t.subarray(2).forEach((c,f)=>{let o=s+f;o{e.switchMode("mt32");let s=t[1],i=!1,n=function(c,f){e.#f[f-12]=c,i=!0};t.subarray(2).forEach((c,f)=>{let o=f+s;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,n,n,n,n,n,n,n,n,n,()=>{e.#n=c,e.dispatchEvent("mastervolume",e.#n)}][o]||(()=>{}))(c,f)}),i&&e.buildRchTree()}).add([22,18,32],(t,r,d)=>{e.switchMode("mt32");let s=t[1],i=" ".repeat(s);t.subarray(2).forEach(n=>{n>31?i+=String.fromCharCode(n):i+=" "}),e.#X=i.padStart(20," "),e.#V=Date.now()+3200}).add([22,18,82],(t,r)=>{let d=e.chRedir(0,r,!0);for(let s=0;s<16;s++)e.#d.ano(d+s),s&&s<10&&(e.#s[d+s]=W[s-1]);console.info("MT-32 alt reset complete.")}),this.#U.add([66,0],(t,r)=>{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(r),2,m.ns5r),e.#o=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,r)=>{let d=["ns5r","05rw"][t[0]];e.switchMode(d,!0),e.setPortMode(e.getTrackPort(r),2,m[d]),e.#o=!1}).add([66,18,0,0],(t,r)=>{let d=t[0];switch(d){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(r),2,m.ns5r),e.#o=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${t}`);break}default:if(d<10){let s=[0,0,0,0],i=(n,c)=>{s[c]=n};if(t.subarray(1).forEach((n,c)=>{[i,i,i,i,()=>{e.#n=n*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},()=>n-64,()=>n-64,()=>{},()=>{},()=>{}][d+c]()}),t[0]<4){let n=0;s.forEach(c=>{n=n<<4,n+=c}),n-=1024}}}}).add([66,18,0,1],(t,r)=>{}).add([66,18,0,2],(t,r)=>{}).add([66,18,1],(t,r)=>{e.dispatchEvent("mupromptex");let d=e.chRedir(t[0],r,!0),s=d*p.cc,i=t[1],n=`NS5R CH${d+1} `;t.subarray(2).forEach((c,f)=>{let o=i+f;o<3?([()=>{e.#e[s+u[0]]=c||L.bank0},()=>{e.#e[s+u[32]]=c},()=>{e.#s[d]=c}][o](),e.dispatchEvent("voice",{part:d})):o<8||(o<14?[()=>{let b=e.chRedir(c,r,!0);e.#f[d]=b,d!=b&&(e.buildRchTree(),console.info(`${n}receives from CH${b+1}`))},()=>{e.#$[d]=+!c},()=>{e.setChType(d,c,m.ns5r),console.debug(`${n}type: ${I[c]}`)},()=>{e.#a[p.rpn*d+3]=c,e.#i[p.rpnt*d+2]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)})},()=>{},()=>{}][o-8]():o<16||(o<33?[()=>{e.#e[s+u[7]]=c},()=>{e.#e[s+u[11]]=c},()=>{},()=>{},()=>{e.#e[s+u[10]]=c||128},()=>{},()=>{},()=>{e.#e[s+u[93]]=c},()=>{e.#e[s+u[91]]=c},()=>{e.#e[s+u[76]]=c},()=>{e.#e[s+u[77]]=c},()=>{e.#e[s+u[78]]=c},()=>{e.#e[s+u[74]]=c},()=>{e.#e[s+u[71]]=c},()=>{e.#e[s+u[73]]=c},()=>{e.#e[s+u[75]]=c},()=>{e.#e[s+u[72]]=c}][o-16]():o<112||o<114&&[()=>{e.#e[s+u[5]]=c},()=>{e.#e[s+u[65]]=c}][o-112]()))})}).add([66,18,8,0],(t,r)=>{let d=t[0];if(d<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let s=d-32;e.#M=Date.now()+3200,e.#g=10,e.#m.fill(0);let i=t.subarray(1),n=4;i.forEach(function(c,f){let o=f+s,b=o>>4,y=o&15;if(o<80){let k=b>3,x=0,D=b0;)e.#m[y*32+b*7+(D-x)]=k&1,k=k>>1,x++}})}}).add([66,18,48],(t,r,d)=>{g(0,t)}).add([66,18,49],(t,r,d)=>{g(1,t)}).add([66,18,50],(t,r,d)=>{g(2,t)}).add([66,18,51],(t,r,d)=>{g(3,t)}).add([66,18,52],(t,r,d)=>{g(4,t)}).add([66,18,53],(t,r,d)=>{g(5,t)}).add([66,18,54],(t,r,d)=>{g(6,t)}).add([66,18,55],(t,r,d)=>{g(7,t)}).add([66,52],(t,r)=>{e.switchMode("ns5r"),e.#o=!1;let d="";M(t,(s,i)=>{i<8?(s>31&&(d+=String.fromCharCode(s)),i==7&&(e.aiEfxName=d)):i<10&&(e.setEffectType(i-8,44,s),e.dispatchEvent(`efx${["reverb","chorus"][i-8]}`,e.getEffectType(i-8)))})}).add([66,53],(t,r)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r"),e.#o=!1;let d="",s=t[t.length-1],i=t.subarray(0,t.length-1),n=O(i);n!=s&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${n}, got ${s}.`),console.debug(t));let c=e.getTrackPort(r);if(e.#l[c]&&e.#l[c]!=m.ns5r)if(e.#L.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${r}. Port ${String.fromCharCode(65+c)} mode "${S[e.#l[c]]}" mismatch, should be "ns5r".`);return}else console.info(`Track ${r} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+c)}.`);e.setPortMode(c,2,m.ns5r),M(i,function(f,o){switch(!0){case o<2944:{let b=e.chRedir(Math.floor(o/92),r,!0),y=b*p.cc;switch(o%92){case 0:{e.#e[y+u[0]]=f,e.dispatchEvent("voice",{part:b});break}case 1:{e.#e[y+u[32]]=f,!f&&!e.#e[y+u[0]]&&(e.#e[y+u[0]]=L.bank0),e.dispatchEvent("voice",{part:b});break}case 2:{e.#s[b]=f,f>0&&e.setChActive(b,1),e.dispatchEvent("voice",{part:b});break}case 3:{let k=e.chRedir(f,r,!0);e.#f[b]=k,b!=k&&(console.info(`NS5R CH${b+1} receives from CH${k+1}.`),e.buildRchTree());break}case 7:{e.#r[b]=f,e.dispatchEvent("voice",{part:b});break}case 8:{e.#a[b*p.rpn+3]=f<40||f>88?f+(f>63?-192:64):f,e.#i[p.rpnt*b+2]=1,e.dispatchEvent("pitch",{part:b,pitch:e.getPitchShift(b)});break}case 9:case 10:{e.#e[y+u[7]]=f;break}case 11:{e.#e[y+u[11]]=f;break}case 14:{e.#e[y+u[10]]=f||128;break}case 19:{e.#e[y+u[93]]=f;break}case 20:{e.#e[y+u[91]]=f;break}case 84:{e.#e[y+u[65]]=f;break}case 85:{e.#e[y+u[5]]=f;break}}break}case o<3096:break;case o<3134:{let b=o-3096;b<8?(f>31&&(d+=String.fromCharCode(f)),b==7&&(e.aiEfxName=d)):b<10&&(e.setEffectType(b-8,44,f),e.dispatchEvent(`efx${["reverb","chorus"][b-8]}`,e.getEffectType(b-8)));break}case o<8566:break}})}).add([66,54],(t,r)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let d="",s=80,i=0,n=0,c="MSB PRG LSB NME";M(t,function(f,o){let b=o%158;switch(!0){case b<10:{f>31&&(d+=String.fromCharCode(f));break}case b==10:break;case b==11:{s=f&127;break}case b==12:{n=f&127;break}case b==13:{c+=` +${s} ${i} ${n} ${d.trim().replace("Init Voice","")}`,i++,d="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(c),w()&&console.debug(c),e.forceVoiceRefresh()}).add([66,55],(t,r)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let d="",s=88,i=0,n=0,c="MSB PRG LSB NME";M(t,function(f,o){let b=o%126;switch(!0){case b<10:{f>31&&(d+=String.fromCharCode(f));break}case b==11:break;case b==12:break;case b==13:{c+=` +${s} ${i} ${n} ${d.trim().replace("Init Combi","")}`,i++,d="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(c),w()&&console.debug(c),e.forceVoiceRefresh()}).add([66,125],(t,r,d)=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],(t,r,d)=>{let s=t[t.length-1],i=t.subarray(0,t.length-1),n=O(i);n!=s&&(console.info(`NS5R screen dump checksum mismatch! Expected ${n}, got ${s}.`),console.debug(t));let c=new Uint8Array(5760);M(t,(f,o,b)=>{if(o<720)for(let y=0;y<8;y++)c[o*8+y]=f>>7-y&1}),e.dispatchEvent("screen",{type:"ns5r",data:c})}).add([76],(t,r,d)=>{e.#U.run([66,...t],r,d)}),this.#J.add([16,0,8,0],(t,r,d)=>{let s=(t[2]<<4)+t[3],i="K11 ";([()=>{e.switchMode("k11",!0),e.setPortMode(e.getTrackPort(r),2,m.k11),e.#o=!1,e.#p[m.k11][1]=s?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,s),console.debug(`${i}reverb type: ${s}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${i}reverb time: ${s}`)},()=>{console.debug(`${i}reverb time: ${s}`)},()=>{console.debug(`${i}reverb predelay: ${s}`)},()=>{console.debug(`${i}reverb predelay: ${s}`)},()=>{console.debug(`${i}depth high: ${s}`)},()=>{console.debug(`${i}depth high: ${s}`)},()=>{console.debug(`${i}depth low: ${s}`)},()=>{console.debug(`${i}depth low: ${s}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,r,d)=>{e.dispatchEvent("mupromptex");let s=e.chRedir(t[1],r,!0),i=p.cc*s,n=p.rpn*s,c=(t[3]<<4)+t[4],f=`K11 CH${s+1} `;([()=>{c<128?(e.setChType(s,e.CH_MELODIC,m.k11),e.#e[i+u[0]]=0,e.#s[s]=c):(e.setChType(s,e.CH_DRUMS,m.k11),e.#s[s]=c-128),e.dispatchEvent("voice",{part:s})},()=>{let o=e.chRedir(c,r,!0);e.#f[s]=o,s!=o&&(e.buildRchTree(),console.info(`${f}receives from CH${o+1}`))},()=>{e.#e[i+u[7]]=c},()=>{uupThis.setChActive(s,c)},()=>{e.#e[i+u[10]]=c},()=>{e.#a[n+3]=c+40,e.#i[p.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{e.#a[n+1]=c>>1,e.#a[n+2]=c&1,e.#i[p.rpnt*s+1]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{e.#e[i+u[91]]=c?127:0},()=>{},()=>{e.#e[i+u[74]]=c},()=>{e.#e[i+u[73]]=c},()=>{e.#e[i+u[72]]=c}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,r,d)=>{e.dispatchEvent("mupromptex");let s=(t[2]<<4)+t[3],i="GMLX ";([()=>{console.debug(`${i}reverb type: ${s}`)},()=>{console.debug(`${i}reverb time: ${s}`)},()=>{console.debug(`${i}reverb predelay: ${s}`)},()=>{console.debug(`${i}depth high: ${s}`)},()=>{console.debug(`${i}depth low: ${s}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,r,d)=>{e.dispatchEvent("mupromptex");let s=(t[2]<<4)+t[3],i=e.chRedir(t[1],r,!0),n=i*p.cc;[()=>{s<128?(e.setChType(i,e.CH_MELODIC,m.k11),e.#e[n+u[0]]=0,e.#e[n+u[32]]=0,e.#s[i]=s):s<160?(e.setChType(i,e.CH_MELODIC,m.k11),e.#e[n+u[0]]=0,e.#e[n+u[32]]=7,e.#s[i]=s-100):(e.setChType(i,e.CH_DRUMS,m.k11),e.#e[n+u[0]]=122,e.#e[n+u[32]]=0,e.#s[i]=s-160),e.dispatchEvent("voice",{part:i})},()=>{let c=e.chRedir(s,r,!0);e.#f[i]=c,i!=c&&(e.buildRchTree(),console.info(`GMLX CH${i+1} receives from CH${c+1}`))}][t[0]]()}).add([16,0,9,4],(t,r,d)=>{e.dispatchEvent("mupromptex");let s=(t[2]<<4)+t[3],i=e.chRedir(t[1],r,!0),n=i*p.cc,c=i*p.rpn,f=`GMLX CH${i+1} `;[()=>{e.setChActive(i,s)},()=>{e.#e[n+u[7]]=s},()=>{e.#e[n+u[10]]=s},()=>{e.#e[n+u[91]]=s?127:0},()=>{e.#a[c+3]=s+40,e.#i[p.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{e.#a[c+1]=s,e.#i[p.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{e.#a[c]=s,e.#i[p.rpnt*i]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{}][t[0]]()}),this.#Z.add([66,93,64],(t,r,d)=>{let s=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{e.dispatchEvent("mupromptex"),e.#n=s*129/16383*100,e.dispatchEvent("mastervolume",e.#n);break}case 5:{e.dispatchEvent("mupromptex"),s-64;break}case 6:{e.dispatchEvent("mupromptex"),console.debug(`SG global reverb: ${s?"on":"off"}`);break}case 127:{e.switchMode("sg",!0),e.setPortMode(e.getTrackPort(r),1,m.sg);break}}break}case 1:{switch(t[1]){case 48:{e.dispatchEvent("mupromptex"),console.debug(`SG reverb type: ${z[s]}`);break}}break}default:if(t[0]>>4==1){e.dispatchEvent("mupromptex");let i=e.chRedir(t[0]&15,r,!0);if(t[1]==2){let n=e.chRedir(s,r,!0);e.#f[i]=n,i!=n&&(e.buildRchTree(),console.info(`SG CH${i+1} receives from CH${n+1}`))}else t[1]==19&&(e.#e[p.cc*i+u[7]]=s)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),this.#ee.add([9],(t,r,d)=>{e.dispatchEvent("mupromptex"),console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremolo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)}),this.#x.add([127,0],(t,r,d)=>{e.switchMode("motif");let s=new Uint8Array([127,1,...t]);e.#x.run(s,r,d)}).add([127,1,0,0],(t,r,d)=>{e.switchMode("s90es");let s="S90/Motif ES system ",i=t[0];t.subarray(1).forEach((n,c)=>{([()=>{e.#n=n*12900/16383,e.dispatchEvent("mastervolume",e.#n)}][i+c]||(()=>{console.info(`Unrecognized ${s}ID: ${i+c}`)}))()})}).add([127,1,0,36,54,1],(t,r,d)=>{e.switchMode("s90es");let s="S90/Motif ES reverb ",i=t[0];t.subarray(1).forEach((n,c)=>{([()=>{e.setEffectTypeRaw(0,!1,n&15|112)},()=>{e.setEffectTypeRaw(0,!0,n)}][i+c]||(()=>{}))()}),e.dispatchEvent("efxreverb",e.getEffectType(0))}).add([127,1,0,37,54,2],(t,r,d)=>{e.switchMode("s90es");let s="S90/Motif ES chorus ",i=t[0];t.subarray(1).forEach((n,c)=>{([()=>{e.setEffectTypeRaw(1,!1,n&15|112)},()=>{e.setEffectTypeRaw(1,!0,n)}][i+c]||(()=>{}))()}),e.dispatchEvent("efxchorus",e.getEffectType(1))}).add([127,1,0,34,54,3],(t,r,d)=>{e.switchMode("s90es");let s="S90/Motif ES insert 1 ",i=t[0];t.subarray(1).forEach((n,c)=>{([()=>{e.setEffectTypeRaw(3,!1,n&15|112)},()=>{e.setEffectTypeRaw(3,!0,n)}][i+c]||(()=>{}))()}),e.dispatchEvent("efxinsert0",e.getEffectType(3))}).add([127,1,0,34,54,4],(t,r,d)=>{e.switchMode("s90es");let s="S90/Motif ES insert 2 ",i=t[0];t.subarray(1).forEach((n,c)=>{([()=>{e.setEffectTypeRaw(4,!1,n&15|112)},()=>{e.setEffectTypeRaw(4,!0,n)}][i+c]||(()=>{}))()}),e.dispatchEvent("efxinsert1",e.getEffectType(4))}).add([127,1,0,35,54,17],(t,r,d)=>{e.switchMode("s90es");let s="S90/Motif ES variation ",i=t[0];t.subarray(1).forEach((n,c)=>{([()=>{e.setEffectTypeRaw(2,!1,n&15|112)},()=>{e.setEffectTypeRaw(2,!0,n)}][i+c]||(()=>{}))()}),e.dispatchEvent("efxdelay",e.getEffectType(2))}).add([127,1,0,58,55],(t,r,d)=>{e.dispatchEvent("mupromptex"),e.switchMode("s90es");let s=e.getTrackPort(r);if(e.#l[s]&&e.#l[s]!=e.#c.smotif)if(e.#L.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${r}. Port ${String.fromCharCode(65+s)} mode "${S[e.#l[s]]}" mismatch, should be "${S[e.#c.smotif]}".`);return}else console.info(`Track ${r} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+s)}.`);let i=e.chRedir(t[0],r,!0),n=p.cc*i,c=t[1];t[0]>15&&(i=t[0]+32);let f=`Track ${r} S90/Motif ES bulk CH${i<128?i+1:"U"+(i-127)} `;console.debug(f,t),!(t[0]>15)&&t.subarray(2).forEach((o,b)=>{([()=>{e.#e[n+u[0]]=o,e.dispatchEvent("voice",{part:i})},()=>{o&&e.setChActive(i,1),e.#e[n+u[32]]=o,e.setChType(i,[32,40].indexOf(o)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:i})},()=>{o&&e.setChActive(i,1),e.#s[i]=o,e.dispatchEvent("voice",{part:i})},()=>{let y=e.chRedir(o,r,!0);e.#f[i]=y,i!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))},()=>{e.#$[i]=o?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{o!=100&&e.setChActive(i,1),e.#e[n+u[7]]=o},()=>{o!=64&&e.setChActive(i,1),e.#e[n+u[10]]=o},!1,!1,!1,()=>{e.#e[n+u[91]]=o},()=>{o&&e.setChActive(i,1),e.#e[n+u[93]]=o},()=>{o&&e.setChActive(i,1),e.#e[n+u[94]]=o},()=>{o!=127&&e.setChActive(i,1),e.#e[n+u[128]]=o,e.allocateAce(128)},()=>{},()=>{o!=64&&e.setChActive(i,1),e.#e[n+u[74]]=o},()=>{o!=64&&e.setChActive(i,1),e.#e[n+u[71]]=o},!1,()=>{e.#e[n+u[65]]=o},()=>{e.#e[n+u[5]]=o},()=>{}][c+b]||(()=>{}))()})}).add([127,1,54,16],(t,r,d)=>{e.switchMode("s90es");let s=t[0];t.subarray(1).forEach((i,n)=>{let f=`S90/Motif ES EQ${(n>>2)+1} `;([()=>{let o=i-64},()=>{let o=A[i]},()=>{let o=i/10},()=>{let o=i}][s+n&3]||(()=>{}))()})}),this.#T.add([0,72,18,0,0,0,0],(t,r,d)=>{e.switchMode("sd",!0),e.setPortMode(e.getTrackPort(r),2,m.sd),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(t,r,d)=>{e.dispatchEvent("mupromptex");let s=t[0]>>5,i=t[0]&31;switch(s){case 0:{let n=t[0]>>1,c=t[1];switch(n){case 1:{t.subarray(2).forEach((f,o,b)=>{let y=o+c;switch(y){case 0:{f&&(e.setEffectType(1,60,f-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${y} - ${f}`));break}}});break}case 2:{t.subarray(2).forEach((f,o)=>{let b=o+c;switch(b){case 0:{f&&(e.setEffectType(0,55+f,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${b} - ${f}`));break}}});break}case 3:case 4:case 5:{let f=n-1;t.subarray(2).forEach((o,b)=>{let y=b+c;switch(console.debug(`SD MFX ${f-2}: ${y} - ${o}`),y){case 0:{e.setEffectTypeRaw(f,62,o),e.dispatchEvent(`efx${f>2?"delay":"insert"+(f-4)}`,e.getEffectType(f));break}}}),console.debug(`SD MFX message: %o`,t);break}default:console.debug(`Unknown SD-90 global effects message: -%o`,t)}break}case 1:{let n=e.chRedir(i,r,!0),c=t[1],d=n*p.cc;t.subarray(2).forEach((o,b)=>{let y=c+b;y<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[d+u[0]]=o,o){case 104:case 105:case 106:case 107:case 120:{e.#r[n]||e.setChType(n,e.CH_DRUMS);break}default:e.#r[n]&&e.setChType(n,e.CH_MELODIC)}e.dispatchEvent("voice",{part:n})},()=>{e.#e[d+u[32]]=o,e.dispatchEvent("voice",{part:n})},()=>{e.#s[n]=o,e.dispatchEvent("voice",{part:n})},()=>{e.#e[d+u[7]]=o},()=>{e.#e[d+u[10]]=o},()=>{},()=>{},()=>{o<2&&(e.#$[n]=o)},()=>{o<2&&(e.#e[d+u[68]]=o?127:0)},()=>{},()=>{o<2&&(e.#e[d+u[65]]=o?127:0)},()=>{e.#e[d+u[5]]=o&15<<4|e.#e[d+u[5]]&15},()=>{e.#e[d+u[5]]=o&15|(e.#e[d+u[5]]&240)>>4},()=>{e.#e[d+u[74]]=o},()=>{e.#e[d+u[71]]=o},()=>{e.#e[d+u[73]]=o},()=>{e.#e[d+u[72]]=o},0,0,0,0,0,0,0,()=>{e.#e[d+u[128]]=o,e.allocateAce(128)},()=>{e.#e[d+u[93]]=o},()=>{e.#e[d+u[91]]=o},0,0,()=>{e.#e[d+u[75]]=o},()=>{e.#e[d+u[76]]=o},()=>{e.#e[d+u[77]]=o},()=>{e.#e[d+u[78]]=o}][y]||(()=>{}))():y<63||(y<64?(e.#r[n]?e.#e[d+u[0]]=104|o:e.#e[d+u[0]]=96|o,e.dispatchEvent("voice",{part:n})):console.debug(`Unknown SD-90 global CH${n+1} param setup message: +%o`,t)}break}case 1:{let n=e.chRedir(i,r,!0),c=t[1],f=n*p.cc;t.subarray(2).forEach((o,b)=>{let y=c+b;y<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[f+u[0]]=o,o){case 104:case 105:case 106:case 107:case 120:{e.#r[n]||e.setChType(n,e.CH_DRUMS);break}default:e.#r[n]&&e.setChType(n,e.CH_MELODIC)}e.dispatchEvent("voice",{part:n})},()=>{e.#e[f+u[32]]=o,e.dispatchEvent("voice",{part:n})},()=>{e.#s[n]=o,e.dispatchEvent("voice",{part:n})},()=>{e.#e[f+u[7]]=o},()=>{e.#e[f+u[10]]=o},()=>{},()=>{},()=>{o<2&&(e.#$[n]=o)},()=>{o<2&&(e.#e[f+u[68]]=o?127:0)},()=>{},()=>{o<2&&(e.#e[f+u[65]]=o?127:0)},()=>{e.#e[f+u[5]]=o&15<<4|e.#e[f+u[5]]&15},()=>{e.#e[f+u[5]]=o&15|(e.#e[f+u[5]]&240)>>4},()=>{e.#e[f+u[74]]=o},()=>{e.#e[f+u[71]]=o},()=>{e.#e[f+u[73]]=o},()=>{e.#e[f+u[72]]=o},0,0,0,0,0,0,0,()=>{e.#e[f+u[128]]=o,e.allocateAce(128)},()=>{e.#e[f+u[93]]=o},()=>{e.#e[f+u[91]]=o},0,0,()=>{e.#e[f+u[75]]=o},()=>{e.#e[f+u[76]]=o},()=>{e.#e[f+u[77]]=o},()=>{e.#e[f+u[78]]=o}][y]||(()=>{}))():y<63||(y<64?(e.#r[n]?e.#e[f+u[0]]=104|o:e.#e[f+u[0]]=96|o,e.dispatchEvent("voice",{part:n})):console.debug(`Unknown SD-90 global CH${n+1} param setup message: %o`,t))});break}case 2:{let n=e.chRedir(i,r,!0),c=t[1];console.debug(`Unknown SD-90 global CH${n+1} MIDI setup message: %o`,t.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,t)}}),e.#U.add([0,1,73,78],(t,r,f)=>{e.switchMode("krs"),e.setPortMode(e.getTrackPort(r),1,m.krs),console.debug("Might be KORG KROSS 2 mode reset... Not sure.")}).add([0,1,73,117,2,37],(t,r,f)=>{e.switchMode("krs");let s=e.getTrackPort(r);if(e.#l[s]&&e.#l[s]!=m.krs)if(e.#L.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+s)} mode "${S[e.#l[s]]}" mismatch, should be "krs".`);return}else console.info(`Track ${r} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+s)}.`);e.setPortMode(e.getTrackPort(r),1,m.krs);let i="KROSS 2 BMT1 ",n="";M(t,(c,d)=>{if(d<24)n+=String.fromCharCode(Math.max(32,c));else if(!(d<1276)){let o=d-1276,b=e.chRedir(Math.floor(o/44),r,!0),y=o%44,k=p.cc*b;y<15?([()=>{c&&e.setChActive(b,1),e.#s[b]=c,e.dispatchEvent("voice",{part:b})},()=>{c&&e.setChActive(b,1),c<10?(e.#e[k+u[0]]=63,e.#e[k+u[32]]=c):c<20?(e.#e[k+u[0]]=121,e.#e[k+u[32]]=c-10):c<24&&(e.#e[k+u[0]]=[120,0,56,62][c-20],e.#e[k+u[32]]=0),e.dispatchEvent("voice",{part:b})},()=>{let x=e.chRedir(c&15,r,!0);e.#f[b]=x,console.info(`${i}CH${b+1} receives from CH${x+1}`),c>>5&1||(e.setChActive(b,0),console.debug(`KORG KROSS 2 CH${b+1} is disabled.`))},!1,!1,()=>{e.#e[k+u[7]]=c},!1,()=>{},()=>{},!1,!1,!1,!1,!1,()=>{e.#e[k+u[10]]=c||128}][y]||(()=>{}))():y<36||([()=>{e.#e[k+u[74]]=(c+128&255)-64},()=>{e.#e[k+u[71]]=(c+128&255)-64},!1,!1,()=>{e.#e[k+u[73]]=(c+128&255)-64},()=>{e.#e[k+u[75]]=(c+128&255)-64},!1,()=>{e.#e[k+u[72]]=(c+128&255)-64}][y]||(()=>{}))()}}),n=n.trimRight(),e.dispatchEvent("metacommit",{type:"EORTitle",data:n})})}};export{tt as OctaviaDevice,p as allocated,u as ccToPos,R as dnToPos}; +%o`,t)}}),e.#U.add([0,1,73,78],(t,r,d)=>{e.switchMode("krs"),e.setPortMode(e.getTrackPort(r),1,m.krs),console.debug("Might be KORG KROSS 2 mode reset... Not sure.")}).add([0,1,73,117,2,37],(t,r,d)=>{e.switchMode("krs");let s=e.getTrackPort(r);if(e.#l[s]&&e.#l[s]!=m.krs)if(e.#L.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+s)} mode "${S[e.#l[s]]}" mismatch, should be "krs".`);return}else console.info(`Track ${r} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+s)}.`);e.setPortMode(e.getTrackPort(r),1,m.krs);let i="KROSS 2 BMT1 ",n="";M(t,(c,f)=>{if(f<24)n+=String.fromCharCode(Math.max(32,c));else if(!(f<1276)){let o=f-1276,b=e.chRedir(Math.floor(o/44),r,!0),y=o%44,k=p.cc*b;y<15?([()=>{c&&e.setChActive(b,1),e.#s[b]=c,e.dispatchEvent("voice",{part:b})},()=>{c&&e.setChActive(b,1),c<10?(e.#e[k+u[0]]=63,e.#e[k+u[32]]=c):c<20?(e.#e[k+u[0]]=121,e.#e[k+u[32]]=c-10):c<24&&(e.#e[k+u[0]]=[120,0,56,62][c-20],e.#e[k+u[32]]=0),e.dispatchEvent("voice",{part:b})},()=>{let x=e.chRedir(c&15,r,!0);e.#f[b]=x,console.info(`${i}CH${b+1} receives from CH${x+1}`),c>>5&1||(e.setChActive(b,0),console.debug(`KORG KROSS 2 CH${b+1} is disabled.`))},!1,!1,()=>{e.#e[k+u[7]]=c},!1,()=>{},()=>{},!1,!1,!1,!1,!1,()=>{e.#e[k+u[10]]=c||128}][y]||(()=>{}))():y<36||([()=>{e.#e[k+u[74]]=(c+128&255)-64},()=>{e.#e[k+u[71]]=(c+128&255)-64},!1,!1,()=>{e.#e[k+u[73]]=(c+128&255)-64},()=>{e.#e[k+u[75]]=(c+128&255)-64},!1,()=>{e.#e[k+u[72]]=(c+128&255)-64}][y]||(()=>{}))()}}),n=n.trimRight(),e.dispatchEvent("metacommit",{type:"EORTitle",data:n})})}};export{tt as OctaviaDevice,p as allocated,u as ccToPos,R as dnToPos}; diff --git a/dist/state_skim.mjs b/dist/state_skim.mjs index 455e9d25..18c42b4b 100644 --- a/dist/state_skim.mjs +++ b/dist/state_skim.mjs @@ -1,9 +1,9 @@ -var I=function(e,t){let a=Math.min(e.length,t.length),r=e.slice(0,a),s=t.slice(0,a),c=0,l=0;for(;l0){let r=this.pool.length,s=1<=1&&l>=0;){if(l<=0)throw new Error("TTL reached.");if(c==r)c-=s;else{let p=I(t,this.pool[c]);switch(p){case 0:{l=0;break}case 1:{c+s<=r&&(c+=s);break}case-1:{c!=0&&(c-=s);break}default:console.warn(`Unexpected result ${p}.`)}}s=s>>1,l--}let u=!0;if(c>=this.pool.length)u=!1;else{let p=this;this.pool[c].forEach(function(i,o,n){u&&i!=t[o]&&(u=!1)}),!u&&I(t,this.pool[c])>0&&c++}return u||a?c:-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 r=this.point(t);r>-1?t.subarray?this.pool[r].data(t.subarray(this.pool[r].length),...a):this.pool[r].data(t.slice(this.pool[r].length),...a):this.default(t,...a)}};var R=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),r=this;a.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(s){try{s?.call(r,a)}catch(c){console.error(c)}}),this[`on${e}`]&&this[`on${e}`](a)}};var B=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 z=function(e,t){let a=!0;return t.forEach((r,s)=>{a=a&&e[s]==r}),a},M=function(e){let t=0;return e.forEach(a=>{t*=256,t+=a}),t},k=new TextDecoder,D=new B;D.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),a="MSB LSB PRG NME",r=[0,0,0,0],s=32,c=0,l=0,u=!0,p=[],i=0;for(;u;){let o=t.subarray(c);([()=>{k.decode(o.subarray(0,4))=="YSFC"?(c+=80,l=1):c++},()=>{if(z(o.subarray(0,4),r))p.forEach((n,b,g)=>{let m=M(t.subarray(n.start+4,n.start+8));n.length=m}),l=2;else{let n=k.decode(o.subarray(0,4)),b=M(o.subarray(4,8));p.push({type:n,start:b}),c+=8}},()=>{let n=p[i],b=t.subarray(n.start,n.start+n.length),g=32;switch(n.type){case"ENVC":{let m=s;for(;m=p.length&&(l=3,u=!1)}][l]||(()=>{u=!1}))()}return a});D.set("pcg",async function(e){let t=new Uint8Array(await e.arrayBuffer()),a="MSB LSB PRG NME",r=100,s=0,c=0,l=!0,u=[],p=0;for(;l;){let i=t.subarray(r);([()=>{l=k.decode(i.subarray(0,4))=="INI2",c=i[15],r+=16,s=1},()=>{let o=k.decode(i.subarray(0,4)),n=i[5],b=i[7],g=i[11],m=M(i.subarray(12,16)),E=M(i.subarray(16,20)),f=M(i.subarray(36,40)),y=k.decode(i.subarray(44,44+g));u.push({type:o,tipMsb:n,tipLsb:b,nameLen:g,length:m,start:E,entryLen:f,name:y}),r+=64,c--,c<1&&(s=2)},()=>{let o=u[p],n=t.subarray(o.start,o.start+o.length);switch(o.type){case"PRG1":break;case"PBK1":{let b=63,g=(o.tipMsb?6:0)+o.tipLsb;for(let m=0;m<128;m++){let E=m*o.entryLen,f=n.subarray(E,E+o.entryLen),y=k.decode(f.subarray(0,24)).trimEnd().replace("InitProg","");y.length&&g>5&&(a+=` +var I=function(e,t){let a=Math.min(e.length,t.length),r=e.slice(0,a),i=t.slice(0,a),c=0,l=0;for(;l0){let r=this.pool.length,i=1<=1&&l>=0;){if(l<=0)throw new Error("TTL reached.");if(c==r)c-=i;else{let p=I(t,this.pool[c]);switch(p){case 0:{l=0;break}case 1:{c+i<=r&&(c+=i);break}case-1:{c!=0&&(c-=i);break}default:console.warn(`Unexpected result ${p}.`)}}i=i>>1,l--}let u=!0;if(c>=this.pool.length)u=!1;else{let p=this;this.pool[c].forEach(function(s,o,n){u&&s!=t[o]&&(u=!1)}),!u&&I(t,this.pool[c])>0&&c++}return u||a?c:-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 r=this.point(t);r>-1?t.subarray?this.pool[r].data(t.subarray(this.pool[r].length),...a):this.pool[r].data(t.slice(this.pool[r].length),...a):this.default(t,...a)}};var R=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),r=this;a.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(i){try{i?.call(r,a)}catch(c){console.error(c)}}),this[`on${e}`]&&this[`on${e}`](a)}};var B=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 z=function(e,t){let a=!0;return t.forEach((r,i)=>{a=a&&e[i]==r}),a},M=function(e){let t=0;return e.forEach(a=>{t*=256,t+=a}),t},k=new TextDecoder,D=new B;D.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),a="MSB LSB PRG NME",r=[0,0,0,0],i=32,c=0,l=0,u=!0,p=[],s=0;for(;u;){let o=t.subarray(c);([()=>{k.decode(o.subarray(0,4))=="YSFC"?(c+=80,l=1):c++},()=>{if(z(o.subarray(0,4),r))p.forEach((n,b,g)=>{let m=M(t.subarray(n.start+4,n.start+8));n.length=m}),l=2;else{let n=k.decode(o.subarray(0,4)),b=M(o.subarray(4,8));p.push({type:n,start:b}),c+=8}},()=>{let n=p[s],b=t.subarray(n.start,n.start+n.length),g=32;switch(n.type){case"ENVC":{let m=i;for(;m=p.length&&(l=3,u=!1)}][l]||(()=>{u=!1}))()}return a});D.set("pcg",async function(e){let t=new Uint8Array(await e.arrayBuffer()),a="MSB LSB PRG NME",r=100,i=0,c=0,l=!0,u=[],p=0;for(;l;){let s=t.subarray(r);([()=>{l=k.decode(s.subarray(0,4))=="INI2",c=s[15],r+=16,i=1},()=>{let o=k.decode(s.subarray(0,4)),n=s[5],b=s[7],g=s[11],m=M(s.subarray(12,16)),E=M(s.subarray(16,20)),f=M(s.subarray(36,40)),y=k.decode(s.subarray(44,44+g));u.push({type:o,tipMsb:n,tipLsb:b,nameLen:g,length:m,start:E,entryLen:f,name:y}),r+=64,c--,c<1&&(i=2)},()=>{let o=u[p],n=t.subarray(o.start,o.start+o.length);switch(o.type){case"PRG1":break;case"PBK1":{let b=63,g=(o.tipMsb?6:0)+o.tipLsb;for(let m=0;m<128;m++){let E=m*o.entryLen,f=n.subarray(E,E+o.entryLen),y=k.decode(f.subarray(0,24)).trimEnd().replace("InitProg","");y.length&&g>5&&(a+=` ${b.toString().padStart(3,"0")} ${g.toString().padStart(3,"0")} ${m.toString().padStart(3,"0")} ${y}`)}break}case"CBK1":{let b=63,g=(o.tipMsb?3:0)+o.tipLsb+10;for(let m=0;m<128;m++){let E=m*o.entryLen,f=n.subarray(E,E+o.entryLen),y=k.decode(f.subarray(0,24)).trimEnd().replace("InitCombi","");y.length&&g>12&&(a+=` -${b.toString().padStart(3,"0")} ${g.toString().padStart(3,"0")} ${m.toString().padStart(3,"0")} ${y}`)}break}}p++,p>=u.length&&(s=3,l=!1)}][s]||(()=>{l=!1}))()}return a});var q=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]);var W=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),Q={};`hi*, +${b.toString().padStart(3,"0")} ${g.toString().padStart(3,"0")} ${m.toString().padStart(3,"0")} ${y}`)}break}}p++,p>=u.length&&(i=3,l=!1)}][i]||(()=>{l=!1}))()}return a});var q=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]);var W=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),Q={};`hi*, ka,か ki,き ku,く @@ -140,9 +140,9 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let t=e.split(",");Q[t[0]]=t[1]});var Y=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"];var J=["melodic","drum","menu"];var P=[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,80,81,83,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 Z={};Y.forEach((e,t)=>{Z[e]=t});var j={length:O.length};O.forEach((e,t)=>{j[e]=t});var ee={length:P.length};P.forEach((e,t)=>{ee[e]=t});var te={};J.forEach((e,t)=>{te[e]=t});var H=8,Ke={port:H,ch:H<<4,cc:O.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:P.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255};var ae=["MSB","PRG","LSB","NME","ELC","DRM"],A=function(e){let t=Math.floor(e/10),a=e%10;return`${t.toString(16)}${a}`},T=class{#t;strictMode=!1;get(e=0,t=0,a=0,r){let s=[e,t,a],c,l=1,u=0,p,i=Array.from(arguments);switch(r){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":case"sc":{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>>4==7&&(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=" ",n="M",b=0,g=0;switch(i[0]){case 0:{i[2]==127?n="MT-a":i[2]==126?n="MT-b":i[2]==7?n="GM-k":i[2]==5?n="SG-a":i[2]==4?n="SP-l":i[2]==0||(r=="gs"||r=="sc")&&i[2]<5?n="GM-a":(n="y",b=3);break}case 8:{r=="sg"?n="GM-s":n="r:";break}case 32:case 33:case 34:case 35:case 36:{r=="xg"&&(n=`${["AP","VL","PF","DX","AN"][e&7]}-${"abcdefgh"[a]}`);break}case 48:{n=`yM${(i[2]>>3).toString().padStart(2,"0")}`,b=1;break}case 56:{n="GM-b";break}case 57:n=["yDOC","QY10","QY20"][i[2]-112]||"yMxv";case 61:case 120:{n="rDrm";break}case 62:{n="kDrm";break}case 63:{if(i[2]<17){let y=i[2];n=y<10?"kP:":"kC:",n+=y%10}else i[2]<34?n=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][i[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"[i[0]-80]}`;break}case 88:case 89:case 90:case 91:{n=`Cmb${"UABC"[i[0]-88]}`;break}case 95:{n=`${["DR","PC"][i[2]]}-d`;break}case 96:{n=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:{n=i[2]>>4==1?"SDa":"VL:",b=3,i[2]>>4==1?g=16:g=112;break}case 98:{n=i[2]>>4==1?"SDb":"SG-a",b=3,g=16;break}case 99:{n=i[2]>>4==1?"SDc":"DX",i[2]>63?g=63:i[2]>>4==1&&(g=16),b=3;break}case 100:{n="AN",i[2]>63?g=63:i[2]>>4==1&&(g=16),b=3;break}case 104:case 105:case 106:case 107:{n="SDd",g=104;break}case 121:{n=`GM-${i[2]?"":"a"}`,b=3;break}case 122:{n="lDrm";break}case 126:{n="yDrS";break}case 127:{i[2]==127?n="rDrm":n="yDrm";break}default:i[0]<48?n="r:":n="M"}n.length<4&&(n+=`${[e,a,i[0],i[2]][b]-g}`.padStart(4-n.length,"0")),r=="xg"&&(e==0?i[2]<100?n=n.replace("y0","y:"):i[2]==125&&(n="y126"):e==16?(c=`Voice${((i[2]<<7)+i[1]+1).toString().padStart(3,"0")}`,o=" "):e==35&&a>>1==2&&(c=`DXCH_${(((i[2]&1)<<7)+t+1).toString().padStart(3,"0")}`,o=" "));let m=[i[0],i[1],i[2]];for(;!(c?.length>=0);)if(c=this.#t[i[1]||0][(i[0]<<7)+i[2]]?.name,c){let y=this.#t[i[1]||0][(i[0]<<7)+i[2]];l=y?.poly||l,u=y?.type||u,p=y?.drum}else if(this.strictMode)c="",o="?";else if(i[0]==0&&i[1]==0&&i[2]==0)c="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&&!c?.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)c=`PrgU:${t.toString().padStart(3,"0")}`,o="!";else if(e==88)c=`CmbU:${t.toString().padStart(3,"0")}`,o="!";else if(e==121)c=`GM2Vox0${a}`,o="#";else if(e==122)if(i[1]==32?i[1]==0:i[1]%=7,c=this.#t[i[1]||0][(i[0]<<7)+i[2]]?.name,c){o=" ";let y=this.#t[i[1]||0][(i[0]<<7)+i[2]];l=y?.poly||l,u=y?.type||u,p=y?.drum}else c="",o="*";else i[1]==0?(c=`${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]];(r=="gs"||r=="sc"||r=="ns5r")&&o=="^"&&(o=" "),e==127&&o=="^"&&(o=" "),o!=" "&&self.debugMode&&(c="");let f="??";switch(i[0]){case 0:{i[2]==0?f="GM":i[2]==5||i[2]==7?f="KG":i[2]<126?f="XG":i[2]==127&&(f="MT");break}case 32:case 33:case 35:case 36:{i[2]>4?f=["AP","VL","PF","DX","AN"][i[0]-32]:f="GS";break}case 48:{f="MU";break}case 56:{f="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{f="AI";break}case 62:case 82:case 90:{f="XD";break}case 63:{i[2]<17?f="KR":i[2]<34?f="ES":f="DS";break}case 64:case 126:{f="XG";break}case 67:case 99:{f=i[2]>>4==1?"SD":"DX";break}case 81:{f="RW";break}case 95:{f=["DR","PC"][i[2]];break}case 96:{f=i[2]==106?"AP":i[2]>>4==1?"SD":"PF";break}case 97:{f=i[2]>>4==1?"SD":"VL";break}case 98:{f=i[2]>>4==1?"SD":"SG";break}case 100:{f="AN";break}case 104:case 105:case 106:case 107:{f="SD";break}case 120:{f="GS";break}case 121:{f=i[2]?"G2":"GM";break}case 122:{f="KG";break}case 127:{f=i[2]==127?"MT":t==0?"GM":"XG";break}default:i[0]<48&&(i[0]==16&&r=="xg"?f="XG":f="GS")}return{name:c||`${A(e||0)} ${A(t||0)} ${A(a||0)}`,poly:l,type:u,drum:p,iid:m,eid:E,sid:s,ending:o,sect:n,standard:f}}async load(e,t,a="(internal)"){let r=this,s=[],c=0,l=0;e.split(` -`).forEach(function(u,p){let i=u.split(" "),o=[];if(p==0){if(i.forEach(function(n,b){s[ae.indexOf(n)]=b}),s.length<4){console.debug("Debugger launched.");debugger}}else{let n=0,b=0,g=0,m,E=1,f=0,y;i.forEach(async function($,K){switch(K){case s[0]:{n=parseInt($);break}case s[1]:{b=parseInt($);break}case s[2]:{g=parseInt($);break}case s[3]:{m=$;break}case s[4]:{$=parseInt($),$<16?E=$+1:f=($&15)+1;break}case s[5]:{y=$;break}}}),r.#t[b]=r.#t[b]||[];let N=r.#t[b];if(!N[n<<7|g]||t){let $={msb:n,prg:b,lsb:g,name:m,poly:E,type:f,drum:y};N[n<<7|g]=$,c++}l++}}),t||console.debug(`Map "${a}": ${l} total, ${c} 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],r=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let s=a[0];s<=a[1];s++){let c=s<<7;for(let l=r[0];l<=r[1];l++){let u=c+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(r){return r.text()}).then(r=>{t.load(r,!1,a)})}catch{console.error(`Failed loading "${a}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var S=["?","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]],C=[120,127,120,127,120,127,61,62,62,62,120,122,122],re=[0,3,81,84,88],_={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},U={0:0,1:1,2:3,5:4},X=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],V=[36,37];var L=[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],ie=[33,99,100,32,102,8,9,10];var v={};S.forEach((e,t)=>{v[e]=t});var d={length:L.length};L.forEach((e,t)=>{d[e]=t});var x=function(){return!!self.Bun||self.debugMode||!1},se=function(e){let t=[],a=0;return e?.forEach(function(r,s){r==247?t.push(e.subarray(a,s)):r==240&&(a=s+1)}),t.length||t.push(e.subarray(0)),x(),t},F=function(e,t="",a="",r=2){return e?`${t}${e.toString().padStart(r,"0")}${a}`:""},h={ch:128,cc:L.length,nn:128,pl:512,tr:256,cmt:14,rpn:6},et=class extends R{#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}#m=new Uint8Array(h.ch);#B=new Uint8Array(h.ch);#e=new Uint8ClampedArray(h.ch*h.cc);#y=new Uint8ClampedArray(h.ch);#o=new Uint8ClampedArray(h.ch*h.nn);#P=new Uint8Array(h.ch);#c=new Uint16Array(h.pl);#f=new Uint8Array(h.pl);#x=new Int16Array(h.ch);#d=new Uint8Array(h.ch);#C=0;#l=new Uint8Array(h.ch*h.rpn);#O=new Int8Array(h.ch*V.length);#A=new Uint8Array(h.ch);#F=new Uint8Array(128);#H=new Uint8Array(h.cmt*8);#K=new Uint8Array(1024);#G=new Uint8Array(h.cmt*64);#k=0;#u=0;#M=100;#E=0;#_=500;#z=0;#i="";#p=0;#q=0;#W=!0;#r=!1;#X;#Q=new Uint8Array(2);#a=[];#$=new Uint8Array(h.ch);#v=new Uint8Array(h.tr);baseBank=new T("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new T("gm");initOnReset=!1;chRedir(e,t,a){if(this.#v[t])return(this.#v[t]-1)*16+e;if([v.gs,v.ns5r].indexOf(this.#t)>-1){if(a==1)return e;let r=0,s=!0;for(;s;)this.#$[e+r]==0?(this.#$[e+r]=t,console.debug(`Assign track ${t} to channel ${e+r+1}.`),s=!1):this.#$[e+r]==t?s=!1:(r+=16,r>=128&&(r=0,s=!1));return e+r}else return e}#n=[];#T;#s={nOff:(e,t)=>{let a=e*128+t,r=this.#c.lastIndexOf(a);r>-1&&(this.#e[h.cc*e+d[64]]>63&&!this.config?.disableCc64?this.#f[r]=4:(this.#c[r]=0,this.#o[a]=0,this.#f[r]=0))},nOn:(e,t,a)=>{let r=e*128+t,s=0;for(this.#P[e]&&this.#s.ano(e);this.#f[s]>0&&this.#c[s]!=r;)s++;s{},cAt:(e,t)=>{},hoOf:e=>{this.#f.forEach((t,a)=>{if(t==4){let r=this.#c[a],s=r>>7;e==s&&(this.#f[a]=0,this.#c[a]=0,this.#o[r]=0)}})},soOf:e=>{},ano:e=>{this.#c.forEach((t,a,r)=>{let s=t>>7,c=t&127;t==0&&this.#o[0]==0||s==e&&this.#s.nOff(s,c)})}};#V={8:function(e){let t=e.channel,a=e.data[0];this.#s.nOff(t,a)},9:function(e){let t=e.channel;this.#m[t]=1;let a=e.data[0],r=e.data[1];r>0?this.#s.nOn(t,a,r):this.#s.nOff(t,a)},10:function(e){let a=e.channel*128+e.data[0];this.#c.indexOf(a)>-1&&(this.#o[a]=data[1])},11:function(e){let t=e.channel;this.#m[t]=1;let a=t*h.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#s.ano(t),this.#x[t]=0;let r=t*h.cc;this.#e[r+d[1]]=0,this.#e[r+d[5]]=0,this.#e[r+d[64]]=0,this.#e[r+d[65]]=0,this.#e[r+d[66]]=0,this.#e[r+d[67]]=0,this.#e[r+d[11]]=127,this.#e[r+d[101]]=127,this.#e[r+d[100]]=127,this.#e[r+d[99]]=127,this.#e[r+d[98]]=127;return}case 123:{this.#s.ano(t);return}case 124:{this.#s.ano(t);return}case 125:{this.#s.ano(t);return}case 126:{this.#P[t]=1,this.#s.ano(t);return}case 127:{this.#P[t]=0,this.#s.ano(t);return}}if(d[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(e.data[0]){case 0:{if(x()&&console.debug(`${S[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==v.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==v.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==v.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let r=0;for(let s=0;s<16;s++){let c=this.#e[h.cc*s];(c==56||c==62)&&r++}r>14&&this.switchMode("ag10",!0)}}break}case 6:{if(this.#C){let r=this.#e[a+d[99]],s=this.#e[a+d[98]];if(r==1){let c=ie.indexOf(s);if(c>-1)this.#e[a+d[71+c]]=e.data[1],x()&&console.debug(`Redirected NRPN 1 ${s} to cc${71+c}.`);else{let l=V.indexOf(s);l>-1&&(this.#O[t*10+l]=e.data[1]-64),x()&&console.debug(`CH${t+1} voice NRPN ${s} commit`)}}}else{let r=U[this.#e[a+d[100]]];this.#e[a+d[101]]==0&&r!=null&&(x()&&console.debug(`CH${t+1} RPN 0 ${this.#e[a+d[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],X[r][0]),X[r][1]),this.#l[t*h.rpn+r]=e.data[1])}break}case 38:{this.#C||this.#e[a+101]==0&&U[this.#e[a+100]]!=null&&(this.#l[t*h.rpn+U[this.#e[a+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#s.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+d[e.data[0]]]=e.data[1]}},12:function(e){let t=e.channel;this.#m[t]=1,this.#y[t]=e.data,this.#A[t]=0,x()&&console.debug(`T:${e.track} C:${t} P:${e.data}`)},13:function(e){let t=this,a=e.channel;this.#c.forEach(function(r){let s=r>>7;a==s&&(t.#o[r]=e.data)})},14:function(e){let t=e.channel;this.#x[t]=e.data[1]*128+e.data[0]-8192},15:function(e){se(e.data).forEach(t=>{let a=t[0],r=t[1];(this.#Y[a]||function(){console.debug(`Unknown manufacturer ${a}.`)})(r,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.#n[e.meta]||function(a,r,s){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#E=0),re.indexOf(e.meta)>-1)return e.reply="meta",e;x()&&console.debug(e)}};#Y={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 r=t[t.length-1],s=gsChecksum(t.subarray(2,t.length-1));r==s?this.#S.run(t.subarray(0,t.length-1),a,e):console.warn(`Bad GS checksum ${r}. Should be ${s}.`)}},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.#U.run(t,a,e)},127:(e,t,a)=>{this.switchMode("gm"),this.#L.run(t,a,e)}};#U;#L;#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.#m.slice();return this.#t==v.mt32,e}getCc(e){let t=e*h.cc,a=this.#e.slice(t,t+h.cc);return a[d[0]]=a[d[0]]||this.#k,a[d[32]]=a[d[32]]||this.#u,a}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&t.set(l,{v:a.#o[r],s:a.#f[s]})}),t}getBitmap(){return{bitmap:this.#h,expire:this.#b}}getLetter(){return{text:this.#i,expire:this.#p}}getMode(){return S[this.#t]}getMaster(){return{volume:this.#M}}getRawStrength(){let e=this;return this.#c.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,r){e[r]=Math.floor(a*t.#e[r*h.cc+d[7]]*t.#e[r*h.cc+d[11]]*t.#M/803288)}),e}getRpn(){return this.#l}getNrpn(){return this.#O}getVoice(e,t,a,r){let s=e||this.#k,c=t,l=a||this.#u;S[this.#t]=="ns5r"&&s>0&&s<56&&(l=3);let u=this.userBank.get(s,c,l,r);if(S[this.#t]=="mt32"&&u.name.indexOf("MT-m:")==0){let p=parseInt(u.name.slice(5)),i=p*h.cmt,o="";this.#G.subarray(i,i+10).forEach(n=>{n>31&&(o+=String.fromCharCode(n))}),this.userBank.load(`MSB LSB PRG -0 127 ${c} ${o}`,!0),u.name=o,u.ending=" "}return(u.ending!=" "||!u.name.length)&&(u=this.baseBank.get(s,c,l,r)),u}getChVoice(e){let t=this.getVoice(this.#e[e*h.cc+d[0]],this.#y[e],this.#e[e*h.cc+d[32]],S[this.#t]);if(this.#A[e])switch(this.#t){case v.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.#m.fill(0),this.#e.fill(0),this.#y.fill(0),this.#o.fill(0),this.#c.fill(0),this.#d.fill(0),this.#x.fill(0),this.#O.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.#r=!1,this.#q=0,this.#W=!0,this.#B.forEach(function(t,a,r){r[a]=a}),this.buildRchTree(),e==0&&(this.#$.fill(0),this.#v.fill(0)),this.#e[h.cc*9]=C[0],this.#e[h.cc*25]=C[0],this.#e[h.cc*41]=C[0],this.#e[h.cc*57]=C[0],this.#Q.fill(0),this.#K.fill(0),this.#G.fill(0),this.#F.fill(0),this.#H.fill(0),this.#A.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 r=0;r-1&&(this.#e[r*h.cc]=C[a]);switch(this.initOnReset,a){case v.mt32:{mt32DefProg.forEach((r,s)=>{let c=s+1;this.#m[c]||(this.#y[c]=r,this.#e[c*h.cc+d[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(r=>{e.channel=r,a=!0,this.#V[e.type].call(this,e)}),a||console.warn(`${_[e.type]?_[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","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"];var J=["melodic","drum","menu"];var P=[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,80,81,83,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 Z={};Y.forEach((e,t)=>{Z[e]=t});var j={length:O.length};O.forEach((e,t)=>{j[e]=t});var ee={length:P.length};P.forEach((e,t)=>{ee[e]=t});var te={};J.forEach((e,t)=>{te[e]=t});var H=8,Ke={port:H,ch:H<<4,cc:O.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:P.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255};var ae=["MSB","PRG","LSB","NME","ELC","DRM"],A=function(e){let t=Math.floor(e/10),a=e%10;return`${t.toString(16)}${a}`},T=class{#t;strictMode=!1;get(e=0,t=0,a=0,r){let i=[e,t,a],c,l=1,u=0,p,s=Array.from(arguments);switch(r){case"xg":{switch(e){case 0:{a==126?s[2]=125:a==127&&(s[2]=0);break}case 16:{a==126&&(s[2]=0);break}case 32:{a>125&&(s[2]=0),s[2]+=4;break}case 33:case 34:case 35:case 36:{a>125&&(s[2]=0),s[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:s[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{a==126&&(s[2]=0);break}case 48:case 64:case 126:case 127:{a==126&&(s[2]=0);break}}break}case"gs":case"sc":{e==0&&a<5?s[2]=0:e>125&&a<5&&a!=2&&(s[2]=e,s[0]=0);break}case"g2":case"sd":{e>>1==40?s[2]|=16:e>95&&e<100&&(s[2]|=16,t>>4==7&&(s[0]=96));break}case"sg":{e==8&&a==0&&(s[2]=5);break}case"s90es":{a<8?s[2]+=17:a<32?s[2]+=13:s[2]=(s[2]>>3)+19;break}case"motif":{a<8?s[2]+=28:a<32?s[2]+=13:s[2]=(s[2]>>3)+19;break}}let o=" ",n="M",b=0,g=0;switch(s[0]){case 0:{s[2]==127?n="MT-a":s[2]==126?n="MT-b":s[2]==7?n="GM-k":s[2]==5?n="SG-a":s[2]==4?n="SP-l":s[2]==0||(r=="gs"||r=="sc")&&s[2]<5?n="GM-a":(n="y",b=3);break}case 8:{r=="sg"?n="GM-s":n="r:";break}case 32:case 33:case 34:case 35:case 36:{r=="xg"&&(n=`${["AP","VL","PF","DX","AN"][e&7]}-${"abcdefgh"[a]}`);break}case 48:{n=`yM${(s[2]>>3).toString().padStart(2,"0")}`,b=1;break}case 56:{n="GM-b";break}case 57:n=["yDOC","QY10","QY20"][s[2]-112]||"yMxv";case 61:case 120:{n="rDrm";break}case 62:{n="kDrm";break}case 63:{if(s[2]<17){let y=s[2];n=y<10?"kP:":"kC:",n+=y%10}else s[2]<34?n=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][s[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"[s[0]-80]}`;break}case 88:case 89:case 90:case 91:{n=`Cmb${"UABC"[s[0]-88]}`;break}case 95:{n=`${["DR","PC"][s[2]]}-d`;break}case 96:{n=s[2]==106?"AP-a":s[2]>>4==1?"SDg":"PF",s[2]>63?g=63:s[2]>>4==1&&(g=16),b=3;break}case 97:{n=s[2]>>4==1?"SDa":"VL:",b=3,s[2]>>4==1?g=16:g=112;break}case 98:{n=s[2]>>4==1?"SDb":"SG-a",b=3,g=16;break}case 99:{n=s[2]>>4==1?"SDc":"DX",s[2]>63?g=63:s[2]>>4==1&&(g=16),b=3;break}case 100:{n="AN",s[2]>63?g=63:s[2]>>4==1&&(g=16),b=3;break}case 104:case 105:case 106:case 107:{n="SDd",g=104;break}case 121:{n=`GM-${s[2]?"":"a"}`,b=3;break}case 122:{n="lDrm";break}case 126:{n="yDrS";break}case 127:{s[2]==127?n="rDrm":n="yDrm";break}default:s[0]<48?n="r:":n="M"}n.length<4&&(n+=`${[e,a,s[0],s[2]][b]-g}`.padStart(4-n.length,"0")),r=="xg"&&(e==0?s[2]<100?n=n.replace("y0","y:"):s[2]==125&&(n="y126"):e==16?(c=`Voice${((s[2]<<7)+s[1]+1).toString().padStart(3,"0")}`,o=" "):e==35&&a>>1==2&&(c=`DXCH_${(((s[2]&1)<<7)+t+1).toString().padStart(3,"0")}`,o=" "));let m=[s[0],s[1],s[2]];for(;!(c?.length>=0);)if(c=this.#t[s[1]||0][(s[0]<<7)+s[2]]?.name,c){let y=this.#t[s[1]||0][(s[0]<<7)+s[2]];l=y?.poly||l,u=y?.type||u,p=y?.drum}else if(this.strictMode)c="",o="?";else if(s[0]==0&&s[1]==0&&s[2]==0)c="Unloaded";else if(this.#t[s[1]||0][s[0]<<7])s[0]==0?(s[2]=0,o="^"):s[2]<1?(s[0]=0,o="*"):(s[2]--,o="^");else if(e==48)s[0]=0,s[2]=0,o="!";else if(e==62)s[1]--,o=" ",s[1]<1&&!c?.length&&(s[0]=0,o="!");else if(e<63)s[0]==0?(s[2]=0,o="^"):s[2]<1?(s[0]=0,o="*"):s[2]--;else if(e==80)c=`PrgU:${t.toString().padStart(3,"0")}`,o="!";else if(e==88)c=`CmbU:${t.toString().padStart(3,"0")}`,o="!";else if(e==121)c=`GM2Vox0${a}`,o="#";else if(e==122)if(s[1]==32?s[1]==0:s[1]%=7,c=this.#t[s[1]||0][(s[0]<<7)+s[2]]?.name,c){o=" ";let y=this.#t[s[1]||0][(s[0]<<7)+s[2]];l=y?.poly||l,u=y?.type||u,p=y?.drum}else c="",o="*";else s[1]==0?(c=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${a.toString().padStart(3,"0")}`,o="!"):s[0]==0?(s[2]=0,o="^"):s[2]>0?s[2]--:s[1]>0?(s[1]=0,o="!"):(s[0]=0,o="?");let E=[s[0],s[1],s[2]];(r=="gs"||r=="sc"||r=="ns5r")&&o=="^"&&(o=" "),e==127&&o=="^"&&(o=" "),o!=" "&&self.debugMode&&(c="");let f="??";switch(s[0]){case 0:{s[2]==0?f="GM":s[2]==5||s[2]==7?f="KG":s[2]<126?f="XG":s[2]==127&&(f="MT");break}case 32:case 33:case 35:case 36:{s[2]>4?f=["AP","VL","PF","DX","AN"][s[0]-32]:f="GS";break}case 48:{f="MU";break}case 56:{f="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{f="AI";break}case 62:case 82:case 90:{f="XD";break}case 63:{s[2]<17?f="KR":s[2]<34?f="ES":f="DS";break}case 64:case 126:{f="XG";break}case 67:case 99:{f=s[2]>>4==1?"SD":"DX";break}case 81:{f="RW";break}case 95:{f=["DR","PC"][s[2]];break}case 96:{f=s[2]==106?"AP":s[2]>>4==1?"SD":"PF";break}case 97:{f=s[2]>>4==1?"SD":"VL";break}case 98:{f=s[2]>>4==1?"SD":"SG";break}case 100:{f="AN";break}case 104:case 105:case 106:case 107:{f="SD";break}case 120:{f="GS";break}case 121:{f=s[2]?"G2":"GM";break}case 122:{f="KG";break}case 127:{f=s[2]==127?"MT":t==0?"GM":"XG";break}default:s[0]<48&&(s[0]==16&&r=="xg"?f="XG":f="GS")}return{name:c||`${A(e||0)} ${A(t||0)} ${A(a||0)}`,poly:l,type:u,drum:p,iid:m,eid:E,sid:i,ending:o,sect:n,standard:f}}async load(e,t,a="(internal)"){let r=this,i=[],c=0,l=0;e.split(` +`).forEach(function(u,p){let s=u.split(" "),o=[];if(p==0){if(s.forEach(function(n,b){i[ae.indexOf(n)]=b}),i.length<4){console.debug("Debugger launched.");debugger}}else{let n=0,b=0,g=0,m,E=1,f=0,y;s.forEach(async function($,K){switch(K){case i[0]:{n=parseInt($);break}case i[1]:{b=parseInt($);break}case i[2]:{g=parseInt($);break}case i[3]:{m=$;break}case i[4]:{$=parseInt($),$<16?E=$+1:f=($&15)+1;break}case i[5]:{y=$;break}}}),r.#t[b]=r.#t[b]||[];let N=r.#t[b];if(!N[n<<7|g]||t){let $={msb:n,prg:b,lsb:g,name:m,poly:E,type:f,drum:y};N[n<<7|g]=$,c++}l++}}),t||console.debug(`Map "${a}": ${l} total, ${c} 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],r=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let i=a[0];i<=a[1];i++){let c=i<<7;for(let l=r[0];l<=r[1];l++){let u=c+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(r){return r.text()}).then(r=>{t.load(r,!1,a)})}catch{console.error(`Failed loading "${a}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var S=["?","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]],C=[120,127,120,127,120,127,61,62,62,62,120,122,122],re=[0,3,81,84,88],_={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},U={0:0,1:1,2:3,5:4},X=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],V=[36,37];var L=[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 v={};S.forEach((e,t)=>{v[e]=t});var d={length:L.length};L.forEach((e,t)=>{d[e]=t});var x=function(){return!!self.Bun||self.debugMode||!1},ie=function(e){let t=[],a=0;return e?.forEach(function(r,i){r==247?t.push(e.subarray(a,i)):r==240&&(a=i+1)}),t.length||t.push(e.subarray(0)),x(),t},F=function(e,t="",a="",r=2){return e?`${t}${e.toString().padStart(r,"0")}${a}`:""},h={ch:128,cc:L.length,nn:128,pl:512,tr:256,cmt:14,rpn:6},et=class extends R{#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}#m=new Uint8Array(h.ch);#B=new Uint8Array(h.ch);#e=new Uint8ClampedArray(h.ch*h.cc);#y=new Uint8ClampedArray(h.ch);#o=new Uint8ClampedArray(h.ch*h.nn);#P=new Uint8Array(h.ch);#c=new Uint16Array(h.pl);#f=new Uint8Array(h.pl);#x=new Int16Array(h.ch);#d=new Uint8Array(h.ch);#C=0;#l=new Uint8Array(h.ch*h.rpn);#O=new Int8Array(h.ch*V.length);#A=new Uint8Array(h.ch);#F=new Uint8Array(128);#H=new Uint8Array(h.cmt*8);#K=new Uint8Array(1024);#G=new Uint8Array(h.cmt*64);#k=0;#u=0;#M=100;#E=0;#_=500;#z=0;#s="";#p=0;#q=0;#W=!0;#r=!1;#X;#Q=new Uint8Array(2);#a=[];#$=new Uint8Array(h.ch);#v=new Uint8Array(h.tr);baseBank=new T("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new T("gm");initOnReset=!1;chRedir(e,t,a){if(this.#v[t])return(this.#v[t]-1)*16+e;if([v.gs,v.ns5r].indexOf(this.#t)>-1){if(a==1)return e;let r=0,i=!0;for(;i;)this.#$[e+r]==0?(this.#$[e+r]=t,console.debug(`Assign track ${t} to channel ${e+r+1}.`),i=!1):this.#$[e+r]==t?i=!1:(r+=16,r>=128&&(r=0,i=!1));return e+r}else return e}#n=[];#T;#i={nOff:(e,t)=>{let a=e*128+t,r=this.#c.lastIndexOf(a);r>-1&&(this.#e[h.cc*e+d[64]]>63&&!this.config?.disableCc64?this.#f[r]=4:(this.#c[r]=0,this.#o[a]=0,this.#f[r]=0))},nOn:(e,t,a)=>{let r=e*128+t,i=0;for(this.#P[e]&&this.#i.ano(e);this.#f[i]>0&&this.#c[i]!=r;)i++;i{},cAt:(e,t)=>{},hoOf:e=>{this.#f.forEach((t,a)=>{if(t==4){let r=this.#c[a],i=r>>7;e==i&&(this.#f[a]=0,this.#c[a]=0,this.#o[r]=0)}})},soOf:e=>{},ano:e=>{this.#c.forEach((t,a,r)=>{let i=t>>7,c=t&127;t==0&&this.#o[0]==0||i==e&&this.#i.nOff(i,c)})}};#V={8:function(e){let t=e.channel,a=e.data[0];this.#i.nOff(t,a)},9:function(e){let t=e.channel;this.#m[t]=1;let a=e.data[0],r=e.data[1];r>0?this.#i.nOn(t,a,r):this.#i.nOff(t,a)},10:function(e){let a=e.channel*128+e.data[0];this.#c.indexOf(a)>-1&&(this.#o[a]=data[1])},11:function(e){let t=e.channel;this.#m[t]=1;let a=t*h.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#i.ano(t),this.#x[t]=0;let r=t*h.cc;this.#e[r+d[1]]=0,this.#e[r+d[5]]=0,this.#e[r+d[64]]=0,this.#e[r+d[65]]=0,this.#e[r+d[66]]=0,this.#e[r+d[67]]=0,this.#e[r+d[11]]=127,this.#e[r+d[101]]=127,this.#e[r+d[100]]=127,this.#e[r+d[99]]=127,this.#e[r+d[98]]=127;return}case 123:{this.#i.ano(t);return}case 124:{this.#i.ano(t);return}case 125:{this.#i.ano(t);return}case 126:{this.#P[t]=1,this.#i.ano(t);return}case 127:{this.#P[t]=0,this.#i.ano(t);return}}if(d[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(e.data[0]){case 0:{if(x()&&console.debug(`${S[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==v.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==v.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==v.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let r=0;for(let i=0;i<16;i++){let c=this.#e[h.cc*i];(c==56||c==62)&&r++}r>14&&this.switchMode("ag10",!0)}}break}case 6:{if(this.#C){let r=this.#e[a+d[99]],i=this.#e[a+d[98]];if(r==1){let c=se.indexOf(i);if(c>-1)this.#e[a+d[71+c]]=e.data[1],x()&&console.debug(`Redirected NRPN 1 ${i} to cc${71+c}.`);else{let l=V.indexOf(i);l>-1&&(this.#O[t*10+l]=e.data[1]-64),x()&&console.debug(`CH${t+1} voice NRPN ${i} commit`)}}}else{let r=U[this.#e[a+d[100]]];this.#e[a+d[101]]==0&&r!=null&&(x()&&console.debug(`CH${t+1} RPN 0 ${this.#e[a+d[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],X[r][0]),X[r][1]),this.#l[t*h.rpn+r]=e.data[1])}break}case 38:{this.#C||this.#e[a+101]==0&&U[this.#e[a+100]]!=null&&(this.#l[t*h.rpn+U[this.#e[a+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#i.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+d[e.data[0]]]=e.data[1]}},12:function(e){let t=e.channel;this.#m[t]=1,this.#y[t]=e.data,this.#A[t]=0,x()&&console.debug(`T:${e.track} C:${t} P:${e.data}`)},13:function(e){let t=this,a=e.channel;this.#c.forEach(function(r){let i=r>>7;a==i&&(t.#o[r]=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],r=t[1];(this.#Y[a]||function(){console.debug(`Unknown manufacturer ${a}.`)})(r,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.#n[e.meta]||function(a,r,i){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#E=0),re.indexOf(e.meta)>-1)return e.reply="meta",e;x()&&console.debug(e)}};#Y={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 r=t[t.length-1],i=gsChecksum(t.subarray(2,t.length-1));r==i?this.#S.run(t.subarray(0,t.length-1),a,e):console.warn(`Bad GS checksum ${r}. Should be ${i}.`)}},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.#U.run(t,a,e)},127:(e,t,a)=>{this.switchMode("gm"),this.#L.run(t,a,e)}};#U;#L;#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.#m.slice();return this.#t==v.mt32,e}getCc(e){let t=e*h.cc,a=this.#e.slice(t,t+h.cc);return a[d[0]]=a[d[0]]||this.#k,a[d[32]]=a[d[32]]||this.#u,a}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&t.set(l,{v:a.#o[r],s:a.#f[i]})}),t}getBitmap(){return{bitmap:this.#h,expire:this.#b}}getLetter(){return{text:this.#s,expire:this.#p}}getMode(){return S[this.#t]}getMaster(){return{volume:this.#M}}getRawStrength(){let e=this;return this.#c.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,r){e[r]=Math.floor(a*t.#e[r*h.cc+d[7]]*t.#e[r*h.cc+d[11]]*t.#M/803288)}),e}getRpn(){return this.#l}getNrpn(){return this.#O}getVoice(e,t,a,r){let i=e||this.#k,c=t,l=a||this.#u;S[this.#t]=="ns5r"&&i>0&&i<56&&(l=3);let u=this.userBank.get(i,c,l,r);if(S[this.#t]=="mt32"&&u.name.indexOf("MT-m:")==0){let p=parseInt(u.name.slice(5)),s=p*h.cmt,o="";this.#G.subarray(s,s+10).forEach(n=>{n>31&&(o+=String.fromCharCode(n))}),this.userBank.load(`MSB LSB PRG +0 127 ${c} ${o}`,!0),u.name=o,u.ending=" "}return(u.ending!=" "||!u.name.length)&&(u=this.baseBank.get(i,c,l,r)),u}getChVoice(e){let t=this.getVoice(this.#e[e*h.cc+d[0]],this.#y[e],this.#e[e*h.cc+d[32]],S[this.#t]);if(this.#A[e])switch(this.#t){case v.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.#m.fill(0),this.#e.fill(0),this.#y.fill(0),this.#o.fill(0),this.#c.fill(0),this.#d.fill(0),this.#x.fill(0),this.#O.fill(0),this.#M=100,this.#a=[],this.#_=500,this.#z=0,this.#p=0,this.#s="",this.#b=0,this.#w=0,this.#h.fill(0),this.#r=!1,this.#q=0,this.#W=!0,this.#B.forEach(function(t,a,r){r[a]=a}),this.buildRchTree(),e==0&&(this.#$.fill(0),this.#v.fill(0)),this.#e[h.cc*9]=C[0],this.#e[h.cc*25]=C[0],this.#e[h.cc*41]=C[0],this.#e[h.cc*57]=C[0],this.#Q.fill(0),this.#K.fill(0),this.#G.fill(0),this.#F.fill(0),this.#H.fill(0),this.#A.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 r=0;r-1&&(this.#e[r*h.cc]=C[a]);switch(this.initOnReset,a){case v.mt32:{mt32DefProg.forEach((r,i)=>{let c=i+1;this.#m[c]||(this.#y[c]=r,this.#e[c*h.cc+d[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(r=>{e.channel=r,a=!0,this.#V[e.type].call(this,e)}),a||console.warn(`${_[e.type]?_[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 @@ -150,4 +150,4 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),this.#n[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#r=!0,this.#a.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#r=!0,this.#a.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#r=!0,this.#a.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#r=!0,this.#a.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#r=!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((r,s)=>{r.length&&this.#a.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][s]}: ${r}`)});break}case"ln":{a.slice(1).forEach((r,s)=>{r.length&&this.#a.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][s]}: ${r}`)});break}default:this.#a.unshift(`XGF_Data: ${t}`)}break}default:this.#r?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.#n[2]=function(t){this.#a.unshift(`Copyrite: ${t}`)},this.#n[3]=function(t,a){a<1&&this.#E<1&&this.#a.unshift(`TrkTitle: ${t}`)},this.#n[4]=function(t,a){this.#a.unshift(`${F(this.#E,""," ")}Instrmnt: ${t}`)},this.#n[5]=function(t){t.trim()==""?this.#a.unshift(""):this.#a[0]+=`${t}`},this.#n[6]=function(t){this.#a.unshift(`${F(this.#E,""," ")}C.Marker: ${t}`)},this.#n[7]=function(t){this.#a.unshift(`CuePoint: ${t}`)},this.#n[32]=function(t){this.#E=t[0]+1},this.#n[33]=function(t,a){console.debug(`Track ${a} requests to get assigned to output ${t}.`),e.#v[a]=t+1},this.#n[81]=function(t,a){e.#_=t/1e3},this.#n[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.#U=new w,this.#L=new w,this.#R=new w,this.#S=new w,this.#D=new w,this.#N=new w,this.#I=new w,this.#U.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#r=e.#r||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#L.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.#r=!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(r){e.#i+=String.fromCharCode(r)}),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 r=t.subarray(1);for(let s=0;s>6-o&1,o++})}),this.#R.add([43,7,0],(t,a,r)=>{e.#i=" ".repeat(offset),e.#p=Date.now()+3200,t.subarray(1).forEach(function(s){e.#i+=String.fromCharCode(s)}),e.#i=e.#i.padEnd(32," ")}).add([43,7,1],(t,a,r)=>{e.#b=Date.now()+3200,e.#h.fill(0),t.forEach(function(s,c){let l=Math.floor(c/16),u=c%16,p=(u*3+l)*7,i=7,o=0;for(p-=u*5,l==2&&(i=2);o>6-o&1,o++})}),this.#S.add([66,18,0,0,127],(t,a,r)=>{e.switchMode("gs",!0),e.#e[h.cc*9]=120,e.#e[h.cc*25]=120,e.#e[h.cc*41]=120,e.#e[h.cc*57]=120,e.#u=3,e.#r=!1,e.#$.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,a,r)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[h.cc*9]=120,e.#e[h.cc*25]=120,e.#e[h.cc*41]=120,e.#e[h.cc*57]=120,e.#r=!1,e.#$.fill(0),console.info("MIDI reset: GS");break}}}).add([69,18,16],t=>{switch(t[0]){case 0:{e.#p=Date.now()+3200;let a=t[1];e.#i=" ".repeat(a),t.subarray(2).forEach(function(r){r<128&&(e.#i+=String.fromCharCode(r))});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],r=t[1];a.fill(0);let s=t.subarray(2);for(let c=0;c>4-n&1,n++})}else console.warn(`Unknown GS display section: ${t[0]}`)}}),this.#S.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#r=!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],r=" ".repeat(a);t.subarray(2).forEach(s=>{s>31&&(r+=String.fromCharCode(s))}),e.#i=r.padStart(20," "),e.#p=Date.now()+3200}).add([22,18,82],(t,a)=>{let r=e.chRedir(0,a,!0);for(let s=0;s<16;s++)e.#s.ano(r+s),s&&s<10&&(e.#y[r+s]=mt32DefProg[s-1]);console.info("MT-32 alt reset complete.")}),this.#D.add([66,0],(t,a)=>{e.switchMode("ns5r",!0),e.#r=!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.#r=!1}).add([66,18,0,0],(t,a)=>{switch(t[0]){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#r=!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,(r,s,c)=>{if(s<720)for(let l=0;l<8;l++)a[s*8+l]=r>>7-l&1}),e.dispatchEvent("screen",{type:"ns5r",data:a})}).add([76],(t,a,r)=>{e.#D.run([66,...t],a,r)}),this.#N.add([16,0,8,0],(t,a,r)=>{let s=(t[2]<<4)+t[3],c="K11 ";([()=>{e.switchMode("k11",!0),e.#r=!1,e.#u=s?4:0,console.info("MIDI reset: GMega/K11")}][t[0]]||(()=>{}))()}),this.#I.add([66,93,64],(t,a,r)=>{let s=t[2];switch(t[0]){case 0:{switch(t[1]){case 127:{e.switchMode("sg",!0);break}}break}}})}};export{et as OctaviaDevice,h as allocated,d as ccToPos}; +122 006 000 `),this.#n[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#r=!0,this.#a.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#r=!0,this.#a.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#r=!0,this.#a.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#r=!0,this.#a.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#r=!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((r,i)=>{r.length&&this.#a.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][i]}: ${r}`)});break}case"ln":{a.slice(1).forEach((r,i)=>{r.length&&this.#a.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][i]}: ${r}`)});break}default:this.#a.unshift(`XGF_Data: ${t}`)}break}default:this.#r?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.#n[2]=function(t){this.#a.unshift(`Copyrite: ${t}`)},this.#n[3]=function(t,a){a<1&&this.#E<1&&this.#a.unshift(`TrkTitle: ${t}`)},this.#n[4]=function(t,a){this.#a.unshift(`${F(this.#E,""," ")}Instrmnt: ${t}`)},this.#n[5]=function(t){t.trim()==""?this.#a.unshift(""):this.#a[0]+=`${t}`},this.#n[6]=function(t){this.#a.unshift(`${F(this.#E,""," ")}C.Marker: ${t}`)},this.#n[7]=function(t){this.#a.unshift(`CuePoint: ${t}`)},this.#n[32]=function(t){this.#E=t[0]+1},this.#n[33]=function(t,a){console.debug(`Track ${a} requests to get assigned to output ${t}.`),e.#v[a]=t+1},this.#n[81]=function(t,a){e.#_=t/1e3},this.#n[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.#U=new w,this.#L=new w,this.#R=new w,this.#S=new w,this.#D=new w,this.#N=new w,this.#I=new w,this.#U.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#r=e.#r||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#L.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.#r=!1,console.info("MIDI reset: XG");break}}}).add([76,6,0],t=>{let a=t[0];a<64?(e.#s=" ".repeat(a),e.#p=Date.now()+3200,t.subarray(1).forEach(function(r){e.#s+=String.fromCharCode(r)}),e.#s=e.#s.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 r=t.subarray(1);for(let i=0;i>6-o&1,o++})}),this.#R.add([43,7,0],(t,a,r)=>{e.#s=" ".repeat(offset),e.#p=Date.now()+3200,t.subarray(1).forEach(function(i){e.#s+=String.fromCharCode(i)}),e.#s=e.#s.padEnd(32," ")}).add([43,7,1],(t,a,r)=>{e.#b=Date.now()+3200,e.#h.fill(0),t.forEach(function(i,c){let l=Math.floor(c/16),u=c%16,p=(u*3+l)*7,s=7,o=0;for(p-=u*5,l==2&&(s=2);o>6-o&1,o++})}),this.#S.add([66,18,0,0,127],(t,a,r)=>{e.switchMode("gs",!0),e.#e[h.cc*9]=120,e.#e[h.cc*25]=120,e.#e[h.cc*41]=120,e.#e[h.cc*57]=120,e.#u=3,e.#r=!1,e.#$.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,a,r)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[h.cc*9]=120,e.#e[h.cc*25]=120,e.#e[h.cc*41]=120,e.#e[h.cc*57]=120,e.#r=!1,e.#$.fill(0),console.info("MIDI reset: GS");break}}}).add([69,18,16],t=>{switch(t[0]){case 0:{e.#p=Date.now()+3200;let a=t[1];e.#s=" ".repeat(a),t.subarray(2).forEach(function(r){r<128&&(e.#s+=String.fromCharCode(r))});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],r=t[1];a.fill(0);let i=t.subarray(2);for(let c=0;c>4-n&1,n++})}else console.warn(`Unknown GS display section: ${t[0]}`)}}),this.#S.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#r=!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],r=" ".repeat(a);t.subarray(2).forEach(i=>{i>31&&(r+=String.fromCharCode(i))}),e.#s=r.padStart(20," "),e.#p=Date.now()+3200}).add([22,18,82],(t,a)=>{let r=e.chRedir(0,a,!0);for(let i=0;i<16;i++)e.#i.ano(r+i),i&&i<10&&(e.#y[r+i]=mt32DefProg[i-1]);console.info("MT-32 alt reset complete.")}),this.#D.add([66,0],(t,a)=>{e.switchMode("ns5r",!0),e.#r=!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.#r=!1}).add([66,18,0,0],(t,a)=>{switch(t[0]){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#r=!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,(r,i,c)=>{if(i<720)for(let l=0;l<8;l++)a[i*8+l]=r>>7-l&1}),e.dispatchEvent("screen",{type:"ns5r",data:a})}).add([76],(t,a,r)=>{e.#D.run([66,...t],a,r)}),this.#N.add([16,0,8,0],(t,a,r)=>{let i=(t[2]<<4)+t[3],c="K11 ";([()=>{e.switchMode("k11",!0),e.#r=!1,e.#u=i?4:0,console.info("MIDI reset: GMega/K11")}][t[0]]||(()=>{}))()}),this.#I.add([66,93,64],(t,a,r)=>{let i=t[2];switch(t[0]){case 0:{switch(t[1]){case 127:{e.switchMode("sg",!0);break}}break}}})}};export{et as OctaviaDevice,h as allocated,d as ccToPos}; diff --git a/dist/xp_basic.mjs b/dist/xp_basic.mjs index 8588b711..aaa443f2 100644 --- a/dist/xp_basic.mjs +++ b/dist/xp_basic.mjs @@ -1,10 +1,10 @@ -var Pr=Object.create;var At=Object.defineProperty;var Rr=Object.getOwnPropertyDescriptor;var Dr=Object.getOwnPropertyNames;var Or=Object.getPrototypeOf,Ar=Object.prototype.hasOwnProperty;var Ir=(g,e,a)=>e in g?At(g,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):g[e]=a;var zt=(g,e)=>()=>(g&&(e=g(g=0)),e);var Lr=(g,e)=>()=>(e||g((e={exports:{}}).exports,e),e.exports);var Ur=(g,e,a,h)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Dr(e))!Ar.call(g,n)&&n!==a&&At(g,n,{get:()=>e[n],enumerable:!(h=Rr(e,n))||h.enumerable});return g};var Br=(g,e,a)=>(a=g!=null?Pr(Or(g)):{},Ur(e||!g||!g.__esModule?At(a,"default",{value:g,enumerable:!0}):a,g));var P=(g,e,a)=>(Ir(g,typeof e!="symbol"?e+"":e,a),a),qt=(g,e,a)=>{if(!e.has(g))throw TypeError("Cannot "+a)};var t=(g,e,a)=>(qt(g,e,"read from private field"),a?a.call(g):e.get(g)),T=(g,e,a)=>{if(e.has(g))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(g):e.set(g,a)},x=(g,e,a,h)=>(qt(g,e,"write to private field"),h?h.call(g,a):e.set(g,a),a);var Wt=zt(()=>{"use strict";U();(function(){var g=function(v,k,r){var o,l;if(self.MessageEvent)switch(v){case"message":{l=new MessageEvent(v,{data:k,ports:r==null?void 0:r.ports}),Object.defineProperty(l,"source",{value:r==null?void 0:r.source});break}default:l=new Event(v)}else l=document.createEvent("Event"),l.initEvent(v,!1,!1),r&&v=="message"&&(l.data=k,r.source&&Object.defineProperty(l,"source",{value:r.source}),(o=r.ports)!=null&&o.length&&Object.defineProperty(l,"ports",{value:r.ports}));return l};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),a=[],h={},n=function(v){var k,r=this;if((this==null?void 0:this.constructor)!=n)throw new TypeError("Illegal constructor");a.push(this),(k=h[v])!=null&&k.constructor||(h[v]=[]),h[v].push(this);var o=Math.floor(Math.random()*281474976710656),l=[],i=0,s=[],c=!0,d=!1;Object.defineProperty(this,"id",{get:function(){return o}}),Object.defineProperty(this,"name",{value:v}),this.close=function(){var f,$=a.indexOf(r);$>-1?(e.postMessage({t:"d",c:v,i:o}),a.splice($,1),(f=h[v])!=null&&f.constructor&&($=h[v].indexOf(r),$>-1&&h[v].splice($,1)),h[v].length||delete h[v],console.debug("[Snowy] BroadcastChannel closed."),d=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(f){if(e){if(d)throw new Error("Channel already closed");e.postMessage({t:"m",c:v,i:o,m:i,d:f}),i++,i>4294967295&&(i=0)}else s.push(f),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(c){for(e.postMessage({t:"r",c:v,i:o}),console.debug("[Snowy] ".concat(s.length," message(s) in cache."));s.length;){var f=s.shift();r.postMessage(f)}c=!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==v?f.i!=o&&r.dispatchEvent(g("message",f.d,{source:r})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(o," receives from ").concat(v,", not ").concat(f.c,"."))};var u={};this.dispatchEvent=function(f){var $,w;if(Object.defineProperty(f,"target",{value:r}),Object.defineProperty(f,"currentTarget",{value:r}),($=u[f.type])!=null&&$.length)for(var C=u[f.type],M=0;M-1&&u[f].splice(M,1)}!((C=u[f])!=null&&C.length)&&u[f].constructor&&delete u[f]}},self.BroadcastChannel=n,p=function(){if(e){e.addEventListener("message",function(k){var r=k.data,o=!1;switch(r.t){case"k":{o=!1,e.postMessage({t:"k"});break}case"m":{var l=h[r.c];if(l!=null&&l.length)for(var i=0;i{"use strict";Wt();{let g=function(e,a){let h=new FileReader;return new Promise((n,p)=>{switch(h.addEventListener("abort",()=>{p(new Error("Blob read aborted"))}),h.addEventListener("error",y=>{p(h.error||y.data||new Error("Blob read error"))}),h.addEventListener("load",()=>{n(h.result)}),a.toLowerCase()){case"arraybuffer":case"buffer":{h.readAsArrayBuffer(e);break}case"string":case"text":{h.readAsText(e);break}default:p(new Error(`Unknown target ${a}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return g(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return g(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(g,e){let a=0,h=16,n=this,p=[];for(;a-1;){let y=n.lastIndexOf(g);p.unshift(n.slice(y+g.length)),n=n.slice(0,y),y==0&&p.unshift(""),a++}return n.length&&p.unshift(n),p.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(g,e){if(e){let a=this;for(;a.length{U();(function(){"use strict";let g={fatal:!0},e=[new TextDecoder("iso-8859-15",g),new TextDecoder("sjis",g),new TextDecoder("euc-jp",g),new TextDecoder("utf-8",g),new TextDecoder("utf-16",g),new TextDecoder("ascii")],a={debug:!1,parse:function(h,n){if(h instanceof Uint8Array)return a.Uint8(h);if(typeof h=="string")return a.Base64(h);if(h instanceof HTMLElement&&h.type==="file")return a.addListener(h,n);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(h,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(h===void 0||!(h instanceof HTMLElement)||h.tagName!=="INPUT"||h.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;n=n||function(){},h.addEventListener("change",function(p){if(!p.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let y=new FileReader;y.readAsArrayBuffer(p.target.files[0]),y.onload=function(v){n(a.Uint8(new Uint8Array(v.target.result)))}})},Base64:function(h){let n=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 r,o="",l,i,s=0;for(;s>16&255):i===64?String.fromCharCode(r>>16&255,r>>8&255):String.fromCharCode(r>>16&255,r>>8&255,255&r);return o}(h=String(h));var p=n.length;let y=new Uint8Array(new ArrayBuffer(p));for(let v=0;v{i[u]=this.readInt(1)});for(let d=0;d191||f>127&&f<160)throw new RangeError(`Invalid code point: ${f}`)}s=!0,console.debug(`String byte sequence in ${e[d].encoding}`)}catch(u){console.debug(`SMF string ${u}`)}return c||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let l=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)l=this.readInt(1);else{let s=[];for(;128<=this.data.getUint8(this.pointer);)s.push(this.readInt(1)-128);var i=this.readInt(1);for(let c=1;c<=s.length;c++)l+=s[s.length-c]*Math.pow(128,c);l+=i}return l}};if(n.data=new DataView(y.buffer,y.byteOffset,y.byteLength),n.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;n.readInt(4);let p={};p.formatType=n.readInt(2),p.tracks=n.readInt(2),p.track=[];var y=n.readInt(1),v=n.readInt(1);128<=y?(p.timeDivision=[],p.timeDivision[0]=y-128,p.timeDivision[1]=v):p.timeDivision=256*y+v;for(let l=1;l<=p.tracks;l++){p.track[l-1]={event:[]};var k,r=n.readInt(4);if(r===-1)break;if(r!==1297379947)return!1;n.readInt(4);let i=0,s=!1,c,d;for(;!s&&(i++,p.track[l-1].event[i-1]={},p.track[l-1].event[i-1].deltaTime=n.readIntVLV(),(c=n.readInt(1))!==-1);)if(128<=c?d=c:(c=d,n.movePointer(-1)),c===255){p.track[l-1].event[i-1].type=255,p.track[l-1].event[i-1].metaType=n.readInt(1);var o=n.readIntVLV();switch(p.track[l-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[l-1].event[i-1].data=n.readStr(o);break;case 33:case 89:case 81:p.track[l-1].event[i-1].data=n.readInt(o);break;case 84:p.track[l-1].event[i-1].data=[],p.track[l-1].event[i-1].data[0]=n.readInt(1),p.track[l-1].event[i-1].data[1]=n.readInt(1),p.track[l-1].event[i-1].data[2]=n.readInt(1),p.track[l-1].event[i-1].data[3]=n.readInt(1),p.track[l-1].event[i-1].data[4]=n.readInt(1);break;case 88:p.track[l-1].event[i-1].data=[],p.track[l-1].event[i-1].data[0]=n.readInt(1),p.track[l-1].event[i-1].data[1]=n.readInt(1),p.track[l-1].event[i-1].data[2]=n.readInt(1),p.track[l-1].event[i-1].data[3]=n.readInt(1);break;default:this.customInterpreter!==null&&(p.track[l-1].event[i-1].data=this.customInterpreter(p.track[l-1].event[i-1].metaType,n,o)),this.customInterpreter!==null&&p.track[l-1].event[i-1].data!==!1||(n.readInt(o),p.track[l-1].event[i-1].data=n.readInt(o),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((c=c.toString(16).split(""))[1]||c.unshift("0"),p.track[l-1].event[i-1].type=parseInt(c[0],16),p.track[l-1].event[i-1].channel=parseInt(c[1],16),p.track[l-1].event[i-1].type){case 15:this.customInterpreter!==null&&(p.track[l-1].event[i-1].data=this.customInterpreter(p.track[l-1].event[i-1].type,n,!1)),this.customInterpreter!==null&&p.track[l-1].event[i-1].data!==!1||(k=n.readIntVLV(),p.track[l-1].event[i-1].data=n.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[l-1].event[i-1].data=[],p.track[l-1].event[i-1].data[0]=n.readInt(1),p.track[l-1].event[i-1].data[1]=n.readInt(1);break;case 12:case 13:p.track[l-1].event[i-1].data=n.readInt(1);break;case-1:s=!0;break;default:if(this.customInterpreter!==null&&(p.track[l-1].event[i-1].data=this.customInterpreter(p.track[l-1].event[i-1].metaType,n,!1)),this.customInterpreter===null||p.track[l-1].event[i-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return p},customInterpreter:null};if(typeof Xt<"u")Xt.exports=a;else{let h=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;h.MidiParser=a}})()});U();U();var te,Qt,Mt=(Qt=class{constructor(){T(this,te,{})}addEventListener(g,e){t(this,te)[g]||(t(this,te)[g]=[]),t(this,te)[g].unshift(e)}removeEventListener(g,e){if(t(this,te)[g]){let a=t(this,te)[g].indexOf(e);a>-1&&t(this,te)[g].splice(a,1),t(this,te)[g].length<1&&delete t(this,te)[g]}}dispatchEvent(g,e){var n;let a=new Event(g),h=this;a.data=e,((n=t(this,te)[g])==null?void 0:n.length)>0&&t(this,te)[g].forEach(function(p){try{p==null||p.call(h,a)}catch(y){console.error(y)}}),this[`on${g}`]&&this[`on${g}`](a)}},te=new WeakMap,Qt);U();U();var Yt=function(g,e){let a=Math.min(g.length,e.length),h=g.slice(0,a),n=e.slice(0,a),p=0,y=0;for(;y0){let h=this.pool.length,n=1<=1&&y>=0;){if(y<=0)throw new Error("TTL reached.");if(p==h)p-=n;else{let k=Yt(e,this.pool[p]);switch(k){case 0:{y=0;break}case 1:{p+n<=h&&(p+=n);break}case-1:{p!=0&&(p-=n);break}default:console.warn(`Unexpected result ${k}.`)}}n=n>>1,y--}let v=!0;if(p>=this.pool.length)v=!1;else{let k=this;this.pool[p].forEach(function(r,o,l){v&&r!=e[o]&&(v=!1)}),!v&&Yt(e,this.pool[p])>0&&p++}return v||a?p:-1}else return a?0:-1},this.add=function(e,a){return e.data=a,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 a=this.point(e);if(a>-1)return this.pool[a].data;this.default(e)},this.run=function(e,...a){let h=this.point(e);h>-1?e.subarray?this.pool[h].data(e.subarray(this.pool[h].length),...a):this.pool[h].data(e.slice(this.pool[h].length),...a):this.default(e,...a)}};U();var Nr=["MSB","PRG","LSB","NME","ELC","DRM"],It=function(g){let e=Math.floor(g/10),a=g%10;return`${e.toString(16)}${a}`},J,jt,Lt=(jt=class{constructor(...g){T(this,J,void 0);P(this,"strictMode",!1);this.loadFiles(...g)}get(g=0,e=0,a=0,h){var f,$;let n=[g,e,a],p,y=1,v=0,k,r=Array.from(arguments);switch(h){case"xg":{switch(g){case 0:{a==126?r[2]=125:a==127&&(r[2]=0);break}case 16:{a==126&&(r[2]=0);break}case 32:{a>125&&(r[2]=0),r[2]+=4;break}case 33:case 34:case 35:case 36:{a>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:{a==126&&(r[2]=0);break}case 48:case 64:case 126:case 127:{a==126&&(r[2]=0);break}}break}case"gs":case"sc":{g==0&&a<5?r[2]=0:g>125&&a<5&&a!=2&&(r[2]=g,r[0]=0);break}case"g2":case"sd":{g>>1==40?r[2]|=16:g>95&&g<100&&(r[2]|=16,e>>4==7&&(r[0]=96));break}case"sg":{g==8&&a==0&&(r[2]=5);break}case"s90es":{a<8?r[2]+=17:a<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}case"motif":{a<8?r[2]+=28:a<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}}let o=" ",l="M",i=0,s=0;switch(r[0]){case 0:{r[2]==127?l="MT-a":r[2]==126?l="MT-b":r[2]==7?l="GM-k":r[2]==5?l="SG-a":r[2]==4?l="SP-l":r[2]==0||(h=="gs"||h=="sc")&&r[2]<5?l="GM-a":(l="y",i=3);break}case 8:{h=="sg"?l="GM-s":l="r:";break}case 32:case 33:case 34:case 35:case 36:{h=="xg"&&(l=`${["AP","VL","PF","DX","AN"][g&7]}-${"abcdefgh"[a]}`);break}case 48:{l=`yM${(r[2]>>3).toString().padStart(2,"0")}`,i=1;break}case 56:{l="GM-b";break}case 57:l=["yDOC","QY10","QY20"][r[2]-112]||"yMxv";case 61:case 120:{l="rDrm";break}case 62:{l="kDrm";break}case 63:{if(r[2]<17){let w=r[2];l=w<10?"kP:":"kC:",l+=w%10}else r[2]<34?l=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][r[2]-17]:l="Ds";break}case 64:{l="ySFX";break}case 67:{l="DX:S";break}case 80:case 81:case 82:case 83:{l=`Prg${"UABC"[r[0]-80]}`;break}case 88:case 89:case 90:case 91:{l=`Cmb${"UABC"[r[0]-88]}`;break}case 95:{l=`${["DR","PC"][r[2]]}-d`;break}case 96:{l=r[2]==106?"AP-a":r[2]>>4==1?"SDg":"PF",r[2]>63?s=63:r[2]>>4==1&&(s=16),i=3;break}case 97:{l=r[2]>>4==1?"SDa":"VL:",i=3,r[2]>>4==1?s=16:s=112;break}case 98:{l=r[2]>>4==1?"SDb":"SG-a",i=3,s=16;break}case 99:{l=r[2]>>4==1?"SDc":"DX",r[2]>63?s=63:r[2]>>4==1&&(s=16),i=3;break}case 100:{l="AN",r[2]>63?s=63:r[2]>>4==1&&(s=16),i=3;break}case 104:case 105:case 106:case 107:{l="SDd",s=104;break}case 121:{l=`GM-${r[2]?"":"a"}`,i=3;break}case 122:{l="lDrm";break}case 126:{l="yDrS";break}case 127:{r[2]==127?l="rDrm":l="yDrm";break}default:r[0]<48?l="r:":l="M"}l.length<4&&(l+=`${[g,a,r[0],r[2]][i]-s}`.padStart(4-l.length,"0")),h=="xg"&&(g==0?r[2]<100?l=l.replace("y0","y:"):r[2]==125&&(l="y126"):g==16?(p=`Voice${((r[2]<<7)+r[1]+1).toString().padStart(3,"0")}`,o=" "):g==35&&a>>1==2&&(p=`DXCH_${(((r[2]&1)<<7)+e+1).toString().padStart(3,"0")}`,o=" "));let c=[r[0],r[1],r[2]];for(;!((p==null?void 0:p.length)>=0);)if(p=(f=t(this,J)[r[1]||0][(r[0]<<7)+r[2]])==null?void 0:f.name,p){let w=t(this,J)[r[1]||0][(r[0]<<7)+r[2]];y=(w==null?void 0:w.poly)||y,v=(w==null?void 0:w.type)||v,k=w==null?void 0:w.drum}else if(this.strictMode)p="",o="?";else if(r[0]==0&&r[1]==0&&r[2]==0)p="Unloaded";else if(t(this,J)[r[1]||0][r[0]<<7])r[0]==0?(r[2]=0,o="^"):r[2]<1?(r[0]=0,o="*"):(r[2]--,o="^");else if(g==48)r[0]=0,r[2]=0,o="!";else if(g==62)r[1]--,o=" ",r[1]<1&&!(p!=null&&p.length)&&(r[0]=0,o="!");else if(g<63)r[0]==0?(r[2]=0,o="^"):r[2]<1?(r[0]=0,o="*"):r[2]--;else if(g==80)p=`PrgU:${e.toString().padStart(3,"0")}`,o="!";else if(g==88)p=`CmbU:${e.toString().padStart(3,"0")}`,o="!";else if(g==121)p=`GM2Vox0${a}`,o="#";else if(g==122)if(r[1]==32?r[1]==0:r[1]%=7,p=($=t(this,J)[r[1]||0][(r[0]<<7)+r[2]])==null?void 0:$.name,p){o=" ";let w=t(this,J)[r[1]||0][(r[0]<<7)+r[2]];y=(w==null?void 0:w.poly)||y,v=(w==null?void 0:w.type)||v,k=w==null?void 0:w.drum}else p="",o="*";else r[1]==0?(p=`${g.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${a.toString().padStart(3,"0")}`,o="!"):r[0]==0?(r[2]=0,o="^"):r[2]>0?r[2]--:r[1]>0?(r[1]=0,o="!"):(r[0]=0,o="?");let d=[r[0],r[1],r[2]];(h=="gs"||h=="sc"||h=="ns5r")&&o=="^"&&(o=" "),g==127&&o=="^"&&(o=" "),o!=" "&&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":e==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&h=="xg"?u="XG":u="GS")}return{name:p||`${It(g||0)} ${It(e||0)} ${It(a||0)}`,poly:y,type:v,drum:k,iid:c,eid:d,sid:n,ending:o,sect:l,standard:u}}async load(g,e,a="(internal)"){let h=this,n=[],p=0,y=0;g.split(` -`).forEach(function(v,k){let r=v.split(" "),o=[];if(k==0){if(r.forEach(function(l,i){n[Nr.indexOf(l)]=i}),n.length<4){console.debug("Debugger launched.");debugger}}else{let l=0,i=0,s=0,c,d=1,u=0,f;r.forEach(async function(w,C){switch(C){case n[0]:{l=parseInt(w);break}case n[1]:{i=parseInt(w);break}case n[2]:{s=parseInt(w);break}case n[3]:{c=w;break}case n[4]:{w=parseInt(w),w<16?d=w+1:u=(w&15)+1;break}case n[5]:{f=w;break}}}),t(h,J)[i]=t(h,J)[i]||[];let $=t(h,J)[i];if(!$[l<<7|s]||e){let w={msb:l,prg:i,lsb:s,name:c,poly:d,type:u,drum:f};$[l<<7|s]=w,p++}y++}}),e||console.debug(`Map "${a}": ${y} total, ${p} loaded.`)}clearRange(g){let e=g.prg!=null?g.prg.constructor==Array?g.prg:[g.prg,g.prg]:[0,127],a=g.msb!=null?g.msb.constructor==Array?g.msb:[g.msb,g.msb]:[0,127],h=g.lsb!=null?g.lsb.constructor==Array?g.lsb:[g.lsb,g.lsb]:[0,127];for(let n=a[0];n<=a[1];n++){let p=n<<7;for(let y=h[0];y<=h[1];y++){let v=p+y;for(let k=e[0];k<=e[1];k++)delete t(this,J)[k][v]}}}init(){x(this,J,[]);for(let g=0;g<128;g++)t(this,J).push([""])}async loadFiles(...g){this.init();let e=this;g.forEach(async function(a){try{await fetch(`./data/bank/${a}.tsv`).then(function(h){return h.text()}).then(h=>{e.load(h,!1,a)})}catch(h){console.error(`Failed loading "${a}.tsv".`)}})}},J=new WeakMap,jt);U();U();var it,Zt,Jt=(Zt=class{constructor(){T(this,it,{});P(this,"context")}set(g,e){t(this,it)[g]=e}has(g){return!!t(this,it)[g]}async read(g,e){if(!this.has(g))throw new Error(`No decoder registered for "${g}"`);return await t(this,it)[g].call(this.context||this,e)}},it=new WeakMap,Zt);var Hr=function(g,e){let a=!0;return e.forEach((h,n)=>{a=a&&g[n]==h}),a},gt=function(g){let e=0;return g.forEach(a=>{e*=256,e+=a}),e},ve=new TextDecoder,bt=new Jt;bt.set("s7e",async function(g){let e=new Uint8Array(await g.slice(0,65536).arrayBuffer()),a="MSB LSB PRG NME",h=[0,0,0,0],n=32,p=0,y=0,v=!0,k=[],r=0;for(;v;){let o=e.subarray(p);([()=>{ve.decode(o.subarray(0,4))=="YSFC"?(p+=80,y=1):p++},()=>{if(Hr(o.subarray(0,4),h))k.forEach((l,i,s)=>{let c=gt(e.subarray(l.start+4,l.start+8));l.length=c}),y=2;else{let l=ve.decode(o.subarray(0,4)),i=gt(o.subarray(4,8));k.push({type:l,start:i}),p+=8}},()=>{let l=k[r],i=e.subarray(l.start,l.start+l.length),s=32;switch(l.type){case"ENVC":{let c=n;for(;c=k.length&&(y=3,v=!1)}][y]||(()=>{v=!1}))()}return a});bt.set("pcg",async function(g){let e=new Uint8Array(await g.arrayBuffer()),a="MSB LSB PRG NME",h=100,n=0,p=0,y=!0,v=[],k=0;for(;y;){let r=e.subarray(h);([()=>{y=ve.decode(r.subarray(0,4))=="INI2",p=r[15],h+=16,n=1},()=>{let o=ve.decode(r.subarray(0,4)),l=r[5],i=r[7],s=r[11],c=gt(r.subarray(12,16)),d=gt(r.subarray(16,20)),u=gt(r.subarray(36,40)),f=ve.decode(r.subarray(44,44+s));v.push({type:o,tipMsb:l,tipLsb:i,nameLen:s,length:c,start:d,entryLen:u,name:f}),h+=64,p--,p<1&&(n=2)},()=>{let o=v[k],l=e.subarray(o.start,o.start+o.length);switch(o.type){case"PRG1":break;case"PBK1":{let i=63,s=(o.tipMsb?6:0)+o.tipLsb;for(let c=0;c<128;c++){let d=c*o.entryLen,u=l.subarray(d,d+o.entryLen),f=ve.decode(u.subarray(0,24)).trimEnd().replace("InitProg","");f.length&&s>5&&(a+=` -${i.toString().padStart(3,"0")} ${s.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")} ${f}`)}break}case"CBK1":{let i=63,s=(o.tipMsb?3:0)+o.tipLsb+10;for(let c=0;c<128;c++){let d=c*o.entryLen,u=l.subarray(d,d+o.entryLen),f=ve.decode(u.subarray(0,24)).trimEnd().replace("InitCombi","");f.length&&s>12&&(a+=` -${i.toString().padStart(3,"0")} ${s.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")} ${f}`)}break}}k++,k>=v.length&&(n=3,y=!1)}][n]||(()=>{y=!1}))()}return a});U();var Et=["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"]),mt=["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"],_r=[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],st=[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],er=[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],tr=function(g){let e=.1,a=-.3;return g>66?(e=5,a=315):g>56?(e=1,a=47):g>46&&(e=.5,a=18.5),e*g-a},rr=function(g){return g>105?_r[g-106]:g>100?g*1.1-100:g/10},ar=",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(","),Ut={};`hi*, +var Pr=Object.create;var At=Object.defineProperty;var Rr=Object.getOwnPropertyDescriptor;var Dr=Object.getOwnPropertyNames;var Or=Object.getPrototypeOf,Ar=Object.prototype.hasOwnProperty;var Ir=(g,e,a)=>e in g?At(g,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):g[e]=a;var zt=(g,e)=>()=>(g&&(e=g(g=0)),e);var Lr=(g,e)=>()=>(e||g((e={exports:{}}).exports,e),e.exports);var Ur=(g,e,a,h)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Dr(e))!Ar.call(g,n)&&n!==a&&At(g,n,{get:()=>e[n],enumerable:!(h=Rr(e,n))||h.enumerable});return g};var Br=(g,e,a)=>(a=g!=null?Pr(Or(g)):{},Ur(e||!g||!g.__esModule?At(a,"default",{value:g,enumerable:!0}):a,g));var P=(g,e,a)=>(Ir(g,typeof e!="symbol"?e+"":e,a),a),qt=(g,e,a)=>{if(!e.has(g))throw TypeError("Cannot "+a)};var t=(g,e,a)=>(qt(g,e,"read from private field"),a?a.call(g):e.get(g)),T=(g,e,a)=>{if(e.has(g))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(g):e.set(g,a)},x=(g,e,a,h)=>(qt(g,e,"write to private field"),h?h.call(g,a):e.set(g,a),a);var Wt=zt(()=>{"use strict";U();(function(){var g=function(v,k,r){var c,o;if(self.MessageEvent)switch(v){case"message":{o=new MessageEvent(v,{data:k,ports:r==null?void 0:r.ports}),Object.defineProperty(o,"source",{value:r==null?void 0:r.source});break}default:o=new Event(v)}else o=document.createEvent("Event"),o.initEvent(v,!1,!1),r&&v=="message"&&(o.data=k,r.source&&Object.defineProperty(o,"source",{value:r.source}),(c=r.ports)!=null&&c.length&&Object.defineProperty(o,"ports",{value:r.ports}));return o};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),a=[],h={},n=function(v){var k,r=this;if((this==null?void 0:this.constructor)!=n)throw new TypeError("Illegal constructor");a.push(this),(k=h[v])!=null&&k.constructor||(h[v]=[]),h[v].push(this);var c=Math.floor(Math.random()*281474976710656),o=[],i=0,s=[],l=!0,d=!1;Object.defineProperty(this,"id",{get:function(){return c}}),Object.defineProperty(this,"name",{value:v}),this.close=function(){var f,$=a.indexOf(r);$>-1?(e.postMessage({t:"d",c:v,i:c}),a.splice($,1),(f=h[v])!=null&&f.constructor&&($=h[v].indexOf(r),$>-1&&h[v].splice($,1)),h[v].length||delete h[v],console.debug("[Snowy] BroadcastChannel closed."),d=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(f){if(e){if(d)throw new Error("Channel already closed");e.postMessage({t:"m",c:v,i:c,m:i,d:f}),i++,i>4294967295&&(i=0)}else s.push(f),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(l){for(e.postMessage({t:"r",c:v,i:c}),console.debug("[Snowy] ".concat(s.length," message(s) in cache."));s.length;){var f=s.shift();r.postMessage(f)}l=!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==v?f.i!=c&&r.dispatchEvent(g("message",f.d,{source:r})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(c," receives from ").concat(v,", not ").concat(f.c,"."))};var u={};this.dispatchEvent=function(f){var $,w;if(Object.defineProperty(f,"target",{value:r}),Object.defineProperty(f,"currentTarget",{value:r}),($=u[f.type])!=null&&$.length)for(var C=u[f.type],M=0;M-1&&u[f].splice(M,1)}!((C=u[f])!=null&&C.length)&&u[f].constructor&&delete u[f]}},self.BroadcastChannel=n,p=function(){if(e){e.addEventListener("message",function(k){var r=k.data,c=!1;switch(r.t){case"k":{c=!1,e.postMessage({t:"k"});break}case"m":{var o=h[r.c];if(o!=null&&o.length)for(var i=0;i{"use strict";Wt();{let g=function(e,a){let h=new FileReader;return new Promise((n,p)=>{switch(h.addEventListener("abort",()=>{p(new Error("Blob read aborted"))}),h.addEventListener("error",y=>{p(h.error||y.data||new Error("Blob read error"))}),h.addEventListener("load",()=>{n(h.result)}),a.toLowerCase()){case"arraybuffer":case"buffer":{h.readAsArrayBuffer(e);break}case"string":case"text":{h.readAsText(e);break}default:p(new Error(`Unknown target ${a}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return g(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return g(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(g,e){let a=0,h=16,n=this,p=[];for(;a-1;){let y=n.lastIndexOf(g);p.unshift(n.slice(y+g.length)),n=n.slice(0,y),y==0&&p.unshift(""),a++}return n.length&&p.unshift(n),p.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(g,e){if(e){let a=this;for(;a.length{U();(function(){"use strict";let g={fatal:!0},e=[new TextDecoder("iso-8859-15",g),new TextDecoder("sjis",g),new TextDecoder("euc-jp",g),new TextDecoder("utf-8",g),new TextDecoder("utf-16",g),new TextDecoder("ascii")],a={debug:!1,parse:function(h,n){if(h instanceof Uint8Array)return a.Uint8(h);if(typeof h=="string")return a.Base64(h);if(h instanceof HTMLElement&&h.type==="file")return a.addListener(h,n);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(h,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(h===void 0||!(h instanceof HTMLElement)||h.tagName!=="INPUT"||h.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;n=n||function(){},h.addEventListener("change",function(p){if(!p.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let y=new FileReader;y.readAsArrayBuffer(p.target.files[0]),y.onload=function(v){n(a.Uint8(new Uint8Array(v.target.result)))}})},Base64:function(h){let n=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 r,c="",o,i,s=0;for(;s>16&255):i===64?String.fromCharCode(r>>16&255,r>>8&255):String.fromCharCode(r>>16&255,r>>8&255,255&r);return c}(h=String(h));var p=n.length;let y=new Uint8Array(new ArrayBuffer(p));for(let v=0;v{i[u]=this.readInt(1)});for(let d=0;d191||f>127&&f<160)throw new RangeError(`Invalid code point: ${f}`)}s=!0,console.debug(`String byte sequence in ${e[d].encoding}`)}catch(u){console.debug(`SMF string ${u}`)}return l||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let o=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)o=this.readInt(1);else{let s=[];for(;128<=this.data.getUint8(this.pointer);)s.push(this.readInt(1)-128);var i=this.readInt(1);for(let l=1;l<=s.length;l++)o+=s[s.length-l]*Math.pow(128,l);o+=i}return o}};if(n.data=new DataView(y.buffer,y.byteOffset,y.byteLength),n.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;n.readInt(4);let p={};p.formatType=n.readInt(2),p.tracks=n.readInt(2),p.track=[];var y=n.readInt(1),v=n.readInt(1);128<=y?(p.timeDivision=[],p.timeDivision[0]=y-128,p.timeDivision[1]=v):p.timeDivision=256*y+v;for(let o=1;o<=p.tracks;o++){p.track[o-1]={event:[]};var k,r=n.readInt(4);if(r===-1)break;if(r!==1297379947)return!1;n.readInt(4);let i=0,s=!1,l,d;for(;!s&&(i++,p.track[o-1].event[i-1]={},p.track[o-1].event[i-1].deltaTime=n.readIntVLV(),(l=n.readInt(1))!==-1);)if(128<=l?d=l:(l=d,n.movePointer(-1)),l===255){p.track[o-1].event[i-1].type=255,p.track[o-1].event[i-1].metaType=n.readInt(1);var c=n.readIntVLV();switch(p.track[o-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[o-1].event[i-1].data=n.readStr(c);break;case 33:case 89:case 81:p.track[o-1].event[i-1].data=n.readInt(c);break;case 84:p.track[o-1].event[i-1].data=[],p.track[o-1].event[i-1].data[0]=n.readInt(1),p.track[o-1].event[i-1].data[1]=n.readInt(1),p.track[o-1].event[i-1].data[2]=n.readInt(1),p.track[o-1].event[i-1].data[3]=n.readInt(1),p.track[o-1].event[i-1].data[4]=n.readInt(1);break;case 88:p.track[o-1].event[i-1].data=[],p.track[o-1].event[i-1].data[0]=n.readInt(1),p.track[o-1].event[i-1].data[1]=n.readInt(1),p.track[o-1].event[i-1].data[2]=n.readInt(1),p.track[o-1].event[i-1].data[3]=n.readInt(1);break;default:this.customInterpreter!==null&&(p.track[o-1].event[i-1].data=this.customInterpreter(p.track[o-1].event[i-1].metaType,n,c)),this.customInterpreter!==null&&p.track[o-1].event[i-1].data!==!1||(n.readInt(c),p.track[o-1].event[i-1].data=n.readInt(c),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((l=l.toString(16).split(""))[1]||l.unshift("0"),p.track[o-1].event[i-1].type=parseInt(l[0],16),p.track[o-1].event[i-1].channel=parseInt(l[1],16),p.track[o-1].event[i-1].type){case 15:this.customInterpreter!==null&&(p.track[o-1].event[i-1].data=this.customInterpreter(p.track[o-1].event[i-1].type,n,!1)),this.customInterpreter!==null&&p.track[o-1].event[i-1].data!==!1||(k=n.readIntVLV(),p.track[o-1].event[i-1].data=n.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[o-1].event[i-1].data=[],p.track[o-1].event[i-1].data[0]=n.readInt(1),p.track[o-1].event[i-1].data[1]=n.readInt(1);break;case 12:case 13:p.track[o-1].event[i-1].data=n.readInt(1);break;case-1:s=!0;break;default:if(this.customInterpreter!==null&&(p.track[o-1].event[i-1].data=this.customInterpreter(p.track[o-1].event[i-1].metaType,n,!1)),this.customInterpreter===null||p.track[o-1].event[i-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return p},customInterpreter:null};if(typeof Xt<"u")Xt.exports=a;else{let h=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;h.MidiParser=a}})()});U();U();var te,Qt,Mt=(Qt=class{constructor(){T(this,te,{})}addEventListener(g,e){t(this,te)[g]||(t(this,te)[g]=[]),t(this,te)[g].unshift(e)}removeEventListener(g,e){if(t(this,te)[g]){let a=t(this,te)[g].indexOf(e);a>-1&&t(this,te)[g].splice(a,1),t(this,te)[g].length<1&&delete t(this,te)[g]}}dispatchEvent(g,e){var n;let a=new Event(g),h=this;a.data=e,((n=t(this,te)[g])==null?void 0:n.length)>0&&t(this,te)[g].forEach(function(p){try{p==null||p.call(h,a)}catch(y){console.error(y)}}),this[`on${g}`]&&this[`on${g}`](a)}},te=new WeakMap,Qt);U();U();var Yt=function(g,e){let a=Math.min(g.length,e.length),h=g.slice(0,a),n=e.slice(0,a),p=0,y=0;for(;y0){let h=this.pool.length,n=1<=1&&y>=0;){if(y<=0)throw new Error("TTL reached.");if(p==h)p-=n;else{let k=Yt(e,this.pool[p]);switch(k){case 0:{y=0;break}case 1:{p+n<=h&&(p+=n);break}case-1:{p!=0&&(p-=n);break}default:console.warn(`Unexpected result ${k}.`)}}n=n>>1,y--}let v=!0;if(p>=this.pool.length)v=!1;else{let k=this;this.pool[p].forEach(function(r,c,o){v&&r!=e[c]&&(v=!1)}),!v&&Yt(e,this.pool[p])>0&&p++}return v||a?p:-1}else return a?0:-1},this.add=function(e,a){return e.data=a,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 a=this.point(e);if(a>-1)return this.pool[a].data;this.default(e)},this.run=function(e,...a){let h=this.point(e);h>-1?e.subarray?this.pool[h].data(e.subarray(this.pool[h].length),...a):this.pool[h].data(e.slice(this.pool[h].length),...a):this.default(e,...a)}};U();var Nr=["MSB","PRG","LSB","NME","ELC","DRM"],It=function(g){let e=Math.floor(g/10),a=g%10;return`${e.toString(16)}${a}`},J,jt,Lt=(jt=class{constructor(...g){T(this,J,void 0);P(this,"strictMode",!1);this.loadFiles(...g)}get(g=0,e=0,a=0,h){var f,$;let n=[g,e,a],p,y=1,v=0,k,r=Array.from(arguments);switch(h){case"xg":{switch(g){case 0:{a==126?r[2]=125:a==127&&(r[2]=0);break}case 16:{a==126&&(r[2]=0);break}case 32:{a>125&&(r[2]=0),r[2]+=4;break}case 33:case 34:case 35:case 36:{a>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:{a==126&&(r[2]=0);break}case 48:case 64:case 126:case 127:{a==126&&(r[2]=0);break}}break}case"gs":case"sc":{g==0&&a<5?r[2]=0:g>125&&a<5&&a!=2&&(r[2]=g,r[0]=0);break}case"g2":case"sd":{g>>1==40?r[2]|=16:g>95&&g<100&&(r[2]|=16,e>>4==7&&(r[0]=96));break}case"sg":{g==8&&a==0&&(r[2]=5);break}case"s90es":{a<8?r[2]+=17:a<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}case"motif":{a<8?r[2]+=28:a<32?r[2]+=13:r[2]=(r[2]>>3)+19;break}}let c=" ",o="M",i=0,s=0;switch(r[0]){case 0:{r[2]==127?o="MT-a":r[2]==126?o="MT-b":r[2]==7?o="GM-k":r[2]==5?o="SG-a":r[2]==4?o="SP-l":r[2]==0||(h=="gs"||h=="sc")&&r[2]<5?o="GM-a":(o="y",i=3);break}case 8:{h=="sg"?o="GM-s":o="r:";break}case 32:case 33:case 34:case 35:case 36:{h=="xg"&&(o=`${["AP","VL","PF","DX","AN"][g&7]}-${"abcdefgh"[a]}`);break}case 48:{o=`yM${(r[2]>>3).toString().padStart(2,"0")}`,i=1;break}case 56:{o="GM-b";break}case 57:o=["yDOC","QY10","QY20"][r[2]-112]||"yMxv";case 61:case 120:{o="rDrm";break}case 62:{o="kDrm";break}case 63:{if(r[2]<17){let w=r[2];o=w<10?"kP:":"kC:",o+=w%10}else r[2]<34?o=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][r[2]-17]:o="Ds";break}case 64:{o="ySFX";break}case 67:{o="DX:S";break}case 80:case 81:case 82:case 83:{o=`Prg${"UABC"[r[0]-80]}`;break}case 88:case 89:case 90:case 91:{o=`Cmb${"UABC"[r[0]-88]}`;break}case 95:{o=`${["DR","PC"][r[2]]}-d`;break}case 96:{o=r[2]==106?"AP-a":r[2]>>4==1?"SDg":"PF",r[2]>63?s=63:r[2]>>4==1&&(s=16),i=3;break}case 97:{o=r[2]>>4==1?"SDa":"VL:",i=3,r[2]>>4==1?s=16:s=112;break}case 98:{o=r[2]>>4==1?"SDb":"SG-a",i=3,s=16;break}case 99:{o=r[2]>>4==1?"SDc":"DX",r[2]>63?s=63:r[2]>>4==1&&(s=16),i=3;break}case 100:{o="AN",r[2]>63?s=63:r[2]>>4==1&&(s=16),i=3;break}case 104:case 105:case 106:case 107:{o="SDd",s=104;break}case 121:{o=`GM-${r[2]?"":"a"}`,i=3;break}case 122:{o="lDrm";break}case 126:{o="yDrS";break}case 127:{r[2]==127?o="rDrm":o="yDrm";break}default:r[0]<48?o="r:":o="M"}o.length<4&&(o+=`${[g,a,r[0],r[2]][i]-s}`.padStart(4-o.length,"0")),h=="xg"&&(g==0?r[2]<100?o=o.replace("y0","y:"):r[2]==125&&(o="y126"):g==16?(p=`Voice${((r[2]<<7)+r[1]+1).toString().padStart(3,"0")}`,c=" "):g==35&&a>>1==2&&(p=`DXCH_${(((r[2]&1)<<7)+e+1).toString().padStart(3,"0")}`,c=" "));let l=[r[0],r[1],r[2]];for(;!((p==null?void 0:p.length)>=0);)if(p=(f=t(this,J)[r[1]||0][(r[0]<<7)+r[2]])==null?void 0:f.name,p){let w=t(this,J)[r[1]||0][(r[0]<<7)+r[2]];y=(w==null?void 0:w.poly)||y,v=(w==null?void 0:w.type)||v,k=w==null?void 0:w.drum}else if(this.strictMode)p="",c="?";else if(r[0]==0&&r[1]==0&&r[2]==0)p="Unloaded";else if(t(this,J)[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(g==48)r[0]=0,r[2]=0,c="!";else if(g==62)r[1]--,c=" ",r[1]<1&&!(p!=null&&p.length)&&(r[0]=0,c="!");else if(g<63)r[0]==0?(r[2]=0,c="^"):r[2]<1?(r[0]=0,c="*"):r[2]--;else if(g==80)p=`PrgU:${e.toString().padStart(3,"0")}`,c="!";else if(g==88)p=`CmbU:${e.toString().padStart(3,"0")}`,c="!";else if(g==121)p=`GM2Vox0${a}`,c="#";else if(g==122)if(r[1]==32?r[1]==0:r[1]%=7,p=($=t(this,J)[r[1]||0][(r[0]<<7)+r[2]])==null?void 0:$.name,p){c=" ";let w=t(this,J)[r[1]||0][(r[0]<<7)+r[2]];y=(w==null?void 0:w.poly)||y,v=(w==null?void 0:w.type)||v,k=w==null?void 0:w.drum}else p="",c="*";else r[1]==0?(p=`${g.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${a.toString().padStart(3,"0")}`,c="!"):r[0]==0?(r[2]=0,c="^"):r[2]>0?r[2]--:r[1]>0?(r[1]=0,c="!"):(r[0]=0,c="?");let d=[r[0],r[1],r[2]];(h=="gs"||h=="sc"||h=="ns5r")&&c=="^"&&(c=" "),g==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":e==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&h=="xg"?u="XG":u="GS")}return{name:p||`${It(g||0)} ${It(e||0)} ${It(a||0)}`,poly:y,type:v,drum:k,iid:l,eid:d,sid:n,ending:c,sect:o,standard:u}}async load(g,e,a="(internal)"){let h=this,n=[],p=0,y=0;g.split(` +`).forEach(function(v,k){let r=v.split(" "),c=[];if(k==0){if(r.forEach(function(o,i){n[Nr.indexOf(o)]=i}),n.length<4){console.debug("Debugger launched.");debugger}}else{let o=0,i=0,s=0,l,d=1,u=0,f;r.forEach(async function(w,C){switch(C){case n[0]:{o=parseInt(w);break}case n[1]:{i=parseInt(w);break}case n[2]:{s=parseInt(w);break}case n[3]:{l=w;break}case n[4]:{w=parseInt(w),w<16?d=w+1:u=(w&15)+1;break}case n[5]:{f=w;break}}}),t(h,J)[i]=t(h,J)[i]||[];let $=t(h,J)[i];if(!$[o<<7|s]||e){let w={msb:o,prg:i,lsb:s,name:l,poly:d,type:u,drum:f};$[o<<7|s]=w,p++}y++}}),e||console.debug(`Map "${a}": ${y} total, ${p} loaded.`)}clearRange(g){let e=g.prg!=null?g.prg.constructor==Array?g.prg:[g.prg,g.prg]:[0,127],a=g.msb!=null?g.msb.constructor==Array?g.msb:[g.msb,g.msb]:[0,127],h=g.lsb!=null?g.lsb.constructor==Array?g.lsb:[g.lsb,g.lsb]:[0,127];for(let n=a[0];n<=a[1];n++){let p=n<<7;for(let y=h[0];y<=h[1];y++){let v=p+y;for(let k=e[0];k<=e[1];k++)delete t(this,J)[k][v]}}}init(){x(this,J,[]);for(let g=0;g<128;g++)t(this,J).push([""])}async loadFiles(...g){this.init();let e=this;g.forEach(async function(a){try{await fetch(`./data/bank/${a}.tsv`).then(function(h){return h.text()}).then(h=>{e.load(h,!1,a)})}catch(h){console.error(`Failed loading "${a}.tsv".`)}})}},J=new WeakMap,jt);U();U();var it,Zt,Jt=(Zt=class{constructor(){T(this,it,{});P(this,"context")}set(g,e){t(this,it)[g]=e}has(g){return!!t(this,it)[g]}async read(g,e){if(!this.has(g))throw new Error(`No decoder registered for "${g}"`);return await t(this,it)[g].call(this.context||this,e)}},it=new WeakMap,Zt);var Hr=function(g,e){let a=!0;return e.forEach((h,n)=>{a=a&&g[n]==h}),a},gt=function(g){let e=0;return g.forEach(a=>{e*=256,e+=a}),e},ve=new TextDecoder,bt=new Jt;bt.set("s7e",async function(g){let e=new Uint8Array(await g.slice(0,65536).arrayBuffer()),a="MSB LSB PRG NME",h=[0,0,0,0],n=32,p=0,y=0,v=!0,k=[],r=0;for(;v;){let c=e.subarray(p);([()=>{ve.decode(c.subarray(0,4))=="YSFC"?(p+=80,y=1):p++},()=>{if(Hr(c.subarray(0,4),h))k.forEach((o,i,s)=>{let l=gt(e.subarray(o.start+4,o.start+8));o.length=l}),y=2;else{let o=ve.decode(c.subarray(0,4)),i=gt(c.subarray(4,8));k.push({type:o,start:i}),p+=8}},()=>{let o=k[r],i=e.subarray(o.start,o.start+o.length),s=32;switch(o.type){case"ENVC":{let l=n;for(;l=k.length&&(y=3,v=!1)}][y]||(()=>{v=!1}))()}return a});bt.set("pcg",async function(g){let e=new Uint8Array(await g.arrayBuffer()),a="MSB LSB PRG NME",h=100,n=0,p=0,y=!0,v=[],k=0;for(;y;){let r=e.subarray(h);([()=>{y=ve.decode(r.subarray(0,4))=="INI2",p=r[15],h+=16,n=1},()=>{let c=ve.decode(r.subarray(0,4)),o=r[5],i=r[7],s=r[11],l=gt(r.subarray(12,16)),d=gt(r.subarray(16,20)),u=gt(r.subarray(36,40)),f=ve.decode(r.subarray(44,44+s));v.push({type:c,tipMsb:o,tipLsb:i,nameLen:s,length:l,start:d,entryLen:u,name:f}),h+=64,p--,p<1&&(n=2)},()=>{let c=v[k],o=e.subarray(c.start,c.start+c.length);switch(c.type){case"PRG1":break;case"PBK1":{let i=63,s=(c.tipMsb?6:0)+c.tipLsb;for(let l=0;l<128;l++){let d=l*c.entryLen,u=o.subarray(d,d+c.entryLen),f=ve.decode(u.subarray(0,24)).trimEnd().replace("InitProg","");f.length&&s>5&&(a+=` +${i.toString().padStart(3,"0")} ${s.toString().padStart(3,"0")} ${l.toString().padStart(3,"0")} ${f}`)}break}case"CBK1":{let i=63,s=(c.tipMsb?3:0)+c.tipLsb+10;for(let l=0;l<128;l++){let d=l*c.entryLen,u=o.subarray(d,d+c.entryLen),f=ve.decode(u.subarray(0,24)).trimEnd().replace("InitCombi","");f.length&&s>12&&(a+=` +${i.toString().padStart(3,"0")} ${s.toString().padStart(3,"0")} ${l.toString().padStart(3,"0")} ${f}`)}break}}k++,k>=v.length&&(n=3,y=!1)}][n]||(()=>{y=!1}))()}return a});U();var Et=["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"]),mt=["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"],_r=[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],st=[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],er=[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],tr=function(g){let e=.1,a=-.3;return g>66?(e=5,a=315):g>56?(e=1,a=47):g>46&&(e=.5,a=18.5),e*g-a},rr=function(g){return g>105?_r[g-106]:g>100?g*1.1-100:g/10},ar=",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(","),Ut={};`hi*, ka,か ki,き ku,く @@ -141,7 +141,7 @@ o,お ~, ^, _,`.split(` -`).forEach(g=>{let e=g.split(",");Ut[e[0]]=e[1]});var ir=function(g){let e=g;g[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 Ut)e=e.replaceAll(h,Ut[h]);e.indexOf("ん")==0&&e.length>1&&(e=e.slice(1));let a=e.indexOf("!");return a>-1&&e.length>1&&(e=e.slice(a+1)),e},sr=function(g){return g?g<96?`cc${g}`:["aftertouch","velocity","pitch bend"][g-96]:"off"};U();var Bt=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],nr=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],cr=["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 Gr={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"},Xr={66307:["drive"],66309:["vowel",g=>"aiueo"[g]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",g=>["off","LPF","HPF"][g]],94984:["noise type",g=>["white","pink"][g]],94987:["disc type",g=>["LP","SP","EP","RND"]],94990:["hum type",g=>`${g+5}0Hz`],94993:["M/S",g=>["mono","stereo"][g]]},Nt=function(g){return Gr[(g[0]-32<<8)+g[1]]||`0x${g[0].toString(16).padStart(2,"0")}${g[1].toString(16).padStart(2,"0")}`},or=function(g,e,a){let h=(g[0]-32<<16)+(g[1]<<8)+e,n=Xr[h]||{},p=n[0];if(p!=null&&p.length)return p+=`: ${(n[1]||function(){})(a)||a}`,p},Ht=[68,48,95,78,41,3,110,122,0];U();var re=function(g=64){return Math.round(2e3*Math.log10(g/64))/100},lr=function(g,e,a){let h=[],n=a==!1?e.readIntVLV():a;g==0||g==127;for(let p=0;p127)return console.debug(`Early termination: ${h}`),h.pop(),e.backOne(),e.backOne(),new Uint8Array(h)}}}return new Uint8Array(h)},De=function(g){let e=0;return g.forEach(a=>{e+=a,e=e&127}),~e+1&127},pe=function(g,e){let a=0,h=0;for(let n=0;n>p&1)<<7,v=g[n];v+=y,n%8!=0?(e(v,a,g),a++):h=g[n]}};var yt=function(g){let e=Math.floor(g*14.2);return e<128?e:0},O=function(){return!!self.Bun||self.debugMode||!1};var W=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"],Vr={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",trinity:"trin","tr-rack":"trin"},Fr=["melodic","drum","menu"],dr={"?":[0,0,120],gm:[0,0,127],gs:[0,0,120],sc:[0,0,120],xg:[0,0,127],g2:[0,0,120],mt32:[0,127,127],doc:[57,112,127],qy10:[57,113,127],qy20:[57,114,127],ns5r:[0,0,61],x5d:[82,0,62],"05rw":[81,0,62],k11:[0,0,122],sg:[0,0,122],sd:[97,0,105],krs:[63,0,120],s90es:[63,0,127],motif:[63,0,127],trin:[63,0,127]};var _t=[120,127,120,127,120,127,127,61,62,62,122,122,105,120,127,127,127],fr=[9,25,41,57,73,89,105,121],Kr=[0,3,81,84,88],hr={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},ur={0:0,1:1,2:3,5:4},pr={0:0,1:1,2:2,5:3},gr=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],br=[36,37,48,49,52,53],Dt=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Er={26:127,29:0,30:0,31:0,52:12,53:54},vt=[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,80,81,83,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],zr=[2,12,13,14,15,16,17,18,19,20,21,80,81,83,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],qr=[33,99,100,32,102,8,9,10],mr=[0,16,25,40,32,64,26,48],S={};W.forEach((g,e)=>{S[g]=e});var E={length:vt.length};vt.forEach((g,e)=>{E[g]=e});var le={length:Dt.length};Dt.forEach((g,e)=>{le[g]=e});var Wr={};Fr.forEach((g,e)=>{Wr[g]=e});var Qr=function(g){let e=[],a=0;return g==null||g.forEach(function(h,n){h==247?e.push(g.subarray(a,n)):h==240&&(a=n+1)}),e.length||e.push(g.subarray(0)),O()&&console.debug(e),e};var yr=8,m={port:yr,ch:yr<<4,cc:vt.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:Dt.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255},nt={bank0:128},A,Y,ge,Se,oe,xe,$r,de,F,D,b,fe,I,K,ae,z,Q,Te,$e,Ge,ie,R,L,ct,ee,be,se,ot,Xe,X,Oe,Ee,$t,Ae,me,lt,Ie,q,B,we,wt,H,Ve,dt,ft,Le,Ue,kt,ht,ye,G,Pt,xt,Fe,Gt,ne,Ce,Be,j,Ke,V,St,Rt,ze,qe,ce,he,ke,We,Qe,Ye,vr,Ua=(vr=class extends Mt{constructor(){super();T(this,oe);P(this,"NOTE_IDLE",0);P(this,"NOTE_ATTACK",1);P(this,"NOTE_DECAY",2);P(this,"NOTE_SUSTAIN",3);P(this,"NOTE_HELD",4);P(this,"NOTE_RELEASE",5);P(this,"NOTE_SOSTENUTO_ATTACK",8);P(this,"NOTE_SOSTENUTO_DECAY",9);P(this,"NOTE_SOSTENUTO_SUSTAIN",10);P(this,"NOTE_SOSTENUTO_HELD",11);P(this,"CH_MELODIC",0);P(this,"CH_DRUMS",1);P(this,"CH_DRUM1",2);P(this,"CH_DRUM2",3);P(this,"CH_DRUM3",4);P(this,"CH_DRUM4",5);P(this,"CH_DRUM5",6);P(this,"CH_DRUM6",7);P(this,"CH_DRUM7",8);P(this,"CH_DRUM8",9);P(this,"DUMP_ALL",0);P(this,"DUMP_ONCE",1);P(this,"DUMP_MODE",2);P(this,"EXT_NONE",0);P(this,"EXT_VL",1);P(this,"EXT_DX",3);P(this,"VLBC_BRTHEXPR",1);P(this,"VLBC_VELOINIT",2);P(this,"VLBC_VELOALL",3);P(this,"CH_INACTIVE",0);P(this,"CH_ACTIVE",1);P(this,"CH_DISABLED",2);T(this,A,0);T(this,Y,0);T(this,ge,0);T(this,Se,new Array(11));T(this,de,new Uint8Array(m.ch));T(this,F,new Uint8Array(m.ch));T(this,D,new Uint8Array(m.ch));T(this,b,new Uint8Array(m.ch*m.cc));T(this,fe,new Uint8Array(m.ace));T(this,I,new Uint8Array(m.ch));T(this,K,new Uint8Array(m.ch*m.nn));T(this,ae,new Uint8Array(m.ch));T(this,z,new Uint16Array(m.pl));T(this,Q,new Uint8Array(m.pl));T(this,Te,new Int16Array(m.ch));T(this,$e,new Uint8Array(m.ch));T(this,Ge,0);T(this,ie,new Uint8Array(m.ch*m.ext));T(this,R,new Uint8Array(m.ch*m.rpn));T(this,L,new Uint8Array(m.ch*m.rpnt));T(this,ct,new Int8Array(m.ch*br.length));T(this,ee,new Uint8Array(m.drm*m.dpn*m.dnc));T(this,be,new Uint8Array(m.drm*2));T(this,se,new Uint8Array(m.efx*3));T(this,ot,new Uint8Array(m.ch));T(this,Xe,new Uint8Array(m.ch*m.redir));T(this,X,new Uint8Array(m.port));T(this,Oe,new Uint8Array(m.ch));T(this,Ee,new Uint8Array(m.ch));T(this,$t,new Uint8Array(m.ch*m.cvn));T(this,Ae,new Uint8Array(128));T(this,me,new Uint8Array(m.cmt*8));T(this,lt,new Uint8Array(1024));T(this,Ie,new Uint8Array(m.cmt*64));T(this,q,{});T(this,B,void 0);T(this,we,void 0);T(this,wt,void 0);T(this,H,100);T(this,Ve,0);T(this,dt,500);T(this,ft,0);T(this,Le,"");T(this,Ue,0);T(this,kt,0);T(this,ht,0);T(this,ye,!0);T(this,G,!1);T(this,Pt,1);T(this,xt,void 0);T(this,Fe,new Array(m.ch));T(this,Gt,new Uint8Array(2));T(this,ne,[]);T(this,Ce,new Uint8Array(m.ch));T(this,Be,new Uint8Array(m.tr));P(this,"baseBank",new Lt("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es"));P(this,"userBank",new Lt("gm"));P(this,"initOnReset",!1);P(this,"aiEfxName","");T(this,j,[]);T(this,Ke,void 0);T(this,V,{nOff:(e,a)=>{let h=e*128+a,n=t(this,z).lastIndexOf(h);if(n>-1)if(t(this,b)[m.cc*e+E[64]]>63)t(this,Q)[n]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:a,velo:t(this,K)[h],state:this.NOTE_HELD});else if(t(this,b)[m.cc*e+E[66]]>63&&t(this,Q)[n]==this.NOTE_SOSTENUTO_SUSTAIN)t(this,Q)[n]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:a,velo:t(this,K)[h],state:this.NOTE_SOSTENUTO_HELD});else{t(this,z)[n]=0,t(this,K)[h]=0,t(this,Q)[n]=this.NOTE_IDLE;let p=this.getExt(e)[1];(p==this.VLBC_VELOINIT||p==this.VLBC_VELOALL)&&(t(this,b)[m.cc*e+E[129]]=0),this.dispatchEvent("note",{part:e,note:a,velo:0,state:this.NOTE_IDLE})}},nOn:(e,a,h)=>{let n=e*128+a,p=0;for(t(this,ae)[e]&&t(this,V).ano(e);t(this,Q)[p]>0&&t(this,z)[p]!=n;)p++;if(p{},cAt:(e,a)=>{},hoOf:e=>{t(this,Q).forEach((a,h)=>{if(a==this.NOTE_HELD){let n=t(this,z)[h],p=n>>7;e==p&&(t(this,Q)[h]=this.NOTE_IDLE,t(this,z)[h]=0,t(this,K)[n]=0,this.dispatchEvent("note",{part:e,note:n&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,Q).forEach((a,h)=>{let n;switch(a){case this.NOTE_ATTACK:{n=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{n=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{n=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(n){t(this,Q)[h]=n;let p=t(this,z)[h];this.dispatchEvent("note",{part:e,note:p&127,velo:t(this,K)[p],state:n})}})},soOf:e=>{t(this,Q).forEach((a,h)=>{if(a==this.NOTE_SOSTENUTO_HELD){let n=t(this,z)[h],p=n>>7;e==p&&(t(this,Q)[h]=this.NOTE_IDLE,t(this,z)[h]=0,t(this,K)[n]=0,this.dispatchEvent("note",{part:e,note:n&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,z).forEach((a,h,n)=>{let p=a>>7,y=a&127;a==0&&t(this,K)[0]==0||p==e&&t(this,V).nOff(p,y)})}});T(this,St,{8:function(e){let a=e.channel,h=e.data[0];t(this,V).nOff(a,h)},9:function(e){let a=e.channel,h=this;if(h.getChModeId(a)==S.xg&&t(h,D)[a]>1){let y=h.getChDrumFirstWrite(a);y[0]&&y[1]!=m.invalidCh&&!t(h,de)[a]&&(h.copyChSetup(y[1],a),h.dispatchEvent("voice",{part:a}),console.debug(`Part CH${a+1} copied from CH${y[1]}.`))}h.setChActive(a,1);let n=e.data[0],p=e.data[1];p>0?t(h,V).nOn(a,n,p):t(h,V).nOff(a,n)},10:function(e){let a=e.channel,h=a*128+e.data[0];t(this,z).indexOf(h)>-1&&(t(this,K)[h]=data[1],this.getExt(a)[1]==this.VLBC_VELOALL&&(t(this,b)[m.cc*a+E[129]]=data[1]),this.dispatchEvent("note",{part:a,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let a=e.channel,h=this,n=t(this,Fe)[a],p=n[e.data[0]];p&&(e.data[0]=p),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,A)){case S.s90es:case S.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(a,1);break}e.data[1]&&this.setChActive(a,1);break}default:{this.setChActive(a,1);break}}})();let y=a*m.cc,v=a*m.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,V).ano(a),t(this,Te)[a]=0,t(this,b)[y+E[1]]=0,t(this,b)[y+E[5]]=0,t(this,b)[y+E[64]]=0,t(this,b)[y+E[65]]=0,t(this,b)[y+E[66]]=0,t(this,b)[y+E[67]]=0,t(this,b)[y+E[11]]=127,t(this,b)[y+E[101]]=127,t(this,b)[y+E[100]]=127,t(this,b)[y+E[99]]=127,t(this,b)[y+E[98]]=127;return}case 123:{t(this,V).ano(a);return}case 124:{t(this,V).ano(a);return}case 125:{t(this,V).ano(a);return}case 126:{t(this,ae)[a]=1,t(this,V).ano(a);return}case 127:{t(this,ae)[a]=0,t(this,V).ano(a);return}}if(E[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(zr.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(O()&&console.debug(`${W[t(this,A)]}, CH${a+1}: ${e.data[1]}`),t(this,A)==0?e.data[1]<48?(t(this,D)[a]>0&&(e.data[1]=t(this,b)[y],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==56?this.switchMode(t(this,B).x5==82?"x5d":"05rw"):e.data[1]==62?this.switchMode(t(this,B).x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(W[t(this,B).ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,A)==S.gs||t(this,A)==S.sc?e.data[1]<56&&t(this,D)[a]>0&&(e.data[1]=t(this,b)[y],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)):t(this,A)==S.gm&&(e.data[1]<48?t(this,D)[a]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${a+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0)),t(this,A)){case S.xg:{[79,95,126,127].indexOf(e.data[1])>-1?t(this,D)[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):t(this,D)[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?t(this,ie)[v]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?t(this,ie)[v]=this.EXT_DX:t(this,ie)[v]=this.EXT_NONE;break}case S["05rw"]:case S.x5d:case S.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(this,D)[a]==this.CH_MELODIC&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):[80,81,82,83].indexOf(e.data[1])>-1||t(this,D)[a]!=this.CH_MELODIC&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case S.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,D)[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):t(this,D)[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case S.g2:{e.data[1]==120?t(this,D)[a]==0&&(this.setChType(a,this.CH_DRUMS),console.debug(`CH${a+1} set to drums by MSB.`)):t(this,D)[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:a});break}case 2:{this.getExt(a)[1]==this.VLBC_BRTHEXPR&&(t(this,b)[y+E[129]]=e.data[1]);break}case 6:{if(t(this,Ge)){[S.xg,S.gs,S.sc,S.ns5r].indexOf(t(this,A))<0&&console.warn(`NRPN commits are not available under "${W[t(this,A)]}" mode, even when they are supported in Octavia.`);let k=t(this,b)[y+E[99]],r=t(this,b)[y+E[98]];if(k==1){let o=qr.indexOf(r);if(o>-1)t(this,b)[y+E[71+o]]=e.data[1],O()&&console.debug(`Redirected NRPN 1 ${r} to cc${71+o}.`),this.dispatchEvent("cc",{part:a,cc:71+o,data:e.data[1]});else{let l=br.indexOf(r);l>-1?t(this,ct)[a*10+l]=e.data[1]-64:console.warn(`NRPN 0x01${r.toString(16).padStart(2,"0")} is not supported.`),O()&&console.debug(`CH${a+1} voice NRPN ${r} commit`)}}else{if(Dt.indexOf(k)<0){let l=`NRPN 0x${k.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")} `;k==127?console.warn(`${l}is not necessary. Consider removing it.`):console.warn(`${l}is not supported.`)}else{let l=t(this,D)[a]-2;l<0?console.warn(`CH${a+1} cannot accept drum NRPN as type ${mt[t(this,D)[a]]}.`):t(this,ee)[(l*m.dpn+le[k])*m.dnc+r]=e.data[1]}O()&&console.debug(`CH${a+1} (${mt[t(this,D)[a]]}) drum NRPN ${k} commit`)}}else{let k=ur[t(this,b)[y+E[100]]],r=pr[t(this,b)[y+E[100]]];t(this,b)[y+E[101]]==0&&k!=null&&(O()&&console.debug(`CH${a+1} RPN 0 ${t(this,b)[y+E[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],gr[k][0]),gr[k][1]),t(this,R)[a*m.rpn+k]=e.data[1],t(this,L)[a*m.rpnt+r]=1,this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)}))}break}case 32:{switch(O()&&console.debug(`${W[t(this,A)]}, CH${a+1} LSB: ${e.data[1]}`),t(this,A)){case S.s90es:case S.motif:{this.setChType(a,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,A),!0);break}}this.getExt(a)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:a});break}case 38:{if(!t(this,Ge)){let k=ur[t(this,b)[y+100]],r=pr[t(this,b)[y+100]];t(this,b)[y+101]==0&&k!=null&&(t(this,R)[a*m.rpn+k+1]=e.data[1],t(this,L)[a*m.rpnt+r]=1)}break}case 64:{e.data[1]<64&&t(this,V).hoOf(a);break}case 66:{e.data[1]>>6?t(this,V).soOn(a):t(this,V).soOf(a);break}case 98:case 99:{x(this,Ge,1);break}case 100:case 101:{x(this,Ge,0);break}}t(this,b)[y+E[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:a,cc:e.data[0],data:e.data[1]})}h.getChModeId(a)==S.xg&&t(h,D)[a]&&h.setDrumFirstWrite(a)},12:function(e){let a=e.channel,h=this;switch(t(h,A)){case S.s90es:case S.motif:{e.data&&h.setChActive(a,1);break}default:h.setChActive(a,1)}if(h.getExt(a)[0]==h.EXT_DX){let n=m.cc*a}t(h,I)[a]=e.data,t(h,Ee)[a]=0,O()&&console.debug(`T:${e.track} C:${a} P:${e.data}`),h.dispatchEvent("voice",{part:a}),h.getChModeId(a)==S.xg&&t(h,D)[a]&&h.setDrumFirstWrite(a)},13:function(e){let a=this,h=e.channel;t(this,z).forEach(function(n){let p=n>>7;h==p&&(t(a,K)[n]=e.data,a.dispatchEvent("note",{part:h,note:n&127,velo:e.data,state:a.NOTE_SUSTAIN}))})},14:function(e){let a=e.channel;t(this,Te)[a]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)})},15:function(e){Qr(e.data).forEach(a=>{let h=a[0],n=a[1];(t(this,Rt)[h]||function(){console.debug(`Unknown manufacturer ${h}.`)})(n,a.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(t(this,j)[e.meta]||function(h,n,p){}).call(this,e.data,e.track,e.meta),e.meta!=32&&x(this,Ve,0);let a=Kr.indexOf(e.meta)>-1;if(O()&&console.debug(e),a)return e.reply="meta",e}});T(this,Rt,{64:(e,a,h)=>{t(this,We).run(a,h,e)},65:(e,a,h)=>{if(a[0]<16)if(a[1]==72){let n=a[a.length-1],p=De(a.subarray(3,a.length-1));n==p?t(this,he).run(a.subarray(0,a.length-1),h,e):console.warn(`Bad SD checksum ${n} - should be ${p}.`)}else t(this,he).run(a,h,e);else{let n=a[a.length-1],p=De(a.subarray(2,a.length-1));n==p?t(this,he).run(a.subarray(0,a.length-1),h,e):console.warn(`Bad GS checksum ${n} - should be ${p}.`)}},66:(e,a,h)=>{t(this,ke).run(a,h,e)},67:(e,a,h)=>{t(this,ce).run(a,h,e)},68:(e,a,h)=>{t(this,Ye).run(a,h,e)},71:(e,a,h)=>{t(this,Qe).run(a,h,e)},126:(e,a,h)=>{t(this,ze).run(a,h,e)},127:(e,a,h)=>{this.switchMode("gm"),t(this,qe).run(a,h,e)}});T(this,ze,void 0);T(this,qe,void 0);T(this,ce,void 0);T(this,he,void 0);T(this,ke,void 0);T(this,We,void 0);T(this,Qe,void 0);T(this,Ye,void 0);let e=this;x(e,oe,new Uint8Array(256),$r),t(e,Se)[10]=new Uint8Array(512),x(e,Ke,new ue),x(e,B,{x5:82,ds:S.krs,smotif:S.s90es,gs:4,sc:3}),x(e,we,{dumpLimit:e.DUMP_MODE}),x(e,wt,new Proxy(t(e,we),{set:()=>{}}));for(let r in dr){let o=S[r];o==null?console.debug(`SubDB build error: "${r}" does not exist`):t(e,q)[o]=new Uint8Array(dr[r])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME +`).forEach(g=>{let e=g.split(",");Ut[e[0]]=e[1]});var ir=function(g){let e=g;g[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 Ut)e=e.replaceAll(h,Ut[h]);e.indexOf("ん")==0&&e.length>1&&(e=e.slice(1));let a=e.indexOf("!");return a>-1&&e.length>1&&(e=e.slice(a+1)),e},sr=function(g){return g?g<96?`cc${g}`:["aftertouch","velocity","pitch bend"][g-96]:"off"};U();var Bt=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],nr=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],cr=["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 Gr={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"},Xr={66307:["drive"],66309:["vowel",g=>"aiueo"[g]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",g=>["off","LPF","HPF"][g]],94984:["noise type",g=>["white","pink"][g]],94987:["disc type",g=>["LP","SP","EP","RND"]],94990:["hum type",g=>`${g+5}0Hz`],94993:["M/S",g=>["mono","stereo"][g]]},Nt=function(g){return Gr[(g[0]-32<<8)+g[1]]||`0x${g[0].toString(16).padStart(2,"0")}${g[1].toString(16).padStart(2,"0")}`},or=function(g,e,a){let h=(g[0]-32<<16)+(g[1]<<8)+e,n=Xr[h]||{},p=n[0];if(p!=null&&p.length)return p+=`: ${(n[1]||function(){})(a)||a}`,p},Ht=[68,48,95,78,41,3,110,122,0];U();var re=function(g=64){return Math.round(2e3*Math.log10(g/64))/100},lr=function(g,e,a){let h=[],n=a==!1?e.readIntVLV():a;g==0||g==127;for(let p=0;p127)return console.debug(`Early termination: ${h}`),h.pop(),e.backOne(),e.backOne(),new Uint8Array(h)}}}return new Uint8Array(h)},De=function(g){let e=0;return g.forEach(a=>{e+=a,e=e&127}),~e+1&127},pe=function(g,e){let a=0,h=0;for(let n=0;n>p&1)<<7,v=g[n];v+=y,n%8!=0?(e(v,a,g),a++):h=g[n]}};var yt=function(g){let e=Math.floor(g*14.2);return e<128?e:0},O=function(){return!!self.Bun||self.debugMode||!1};var W=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"],Vr={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",trinity:"trin","tr-rack":"trin"},Fr=["melodic","drum","menu"],dr={"?":[0,0,120],gm:[0,0,127],gs:[0,0,120],sc:[0,0,120],xg:[0,0,127],g2:[0,0,120],mt32:[0,127,127],doc:[57,112,127],qy10:[57,113,127],qy20:[57,114,127],ns5r:[0,0,61],x5d:[82,0,62],"05rw":[81,0,62],k11:[0,0,122],sg:[0,0,122],sd:[97,0,105],krs:[63,0,120],s90es:[63,0,127],motif:[63,0,127],trin:[63,0,127]};var _t=[120,127,120,127,120,127,127,61,62,62,122,122,105,120,127,127,127],fr=[9,25,41,57,73,89,105,121],Kr=[0,3,81,84,88],hr={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},ur={0:0,1:1,2:3,5:4},pr={0:0,1:1,2:2,5:3},gr=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],br=[36,37,48,49,52,53],Dt=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Er={26:127,29:0,30:0,31:0,52:12,53:54},vt=[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,80,81,83,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],zr=[2,12,13,14,15,16,17,18,19,20,21,80,81,83,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],qr=[33,99,100,32,102,8,9,10],mr=[0,16,25,40,32,64,26,48],S={};W.forEach((g,e)=>{S[g]=e});var E={length:vt.length};vt.forEach((g,e)=>{E[g]=e});var le={length:Dt.length};Dt.forEach((g,e)=>{le[g]=e});var Wr={};Fr.forEach((g,e)=>{Wr[g]=e});var Qr=function(g){let e=[],a=0;return g==null||g.forEach(function(h,n){h==247?e.push(g.subarray(a,n)):h==240&&(a=n+1)}),e.length||e.push(g.subarray(0)),O()&&console.debug(e),e};var yr=8,m={port:yr,ch:yr<<4,cc:vt.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:Dt.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255},nt={bank0:128},A,Y,ge,Se,oe,xe,$r,de,F,D,b,fe,I,K,ae,z,Q,Te,$e,Ge,ie,R,L,ct,ee,be,se,ot,Xe,X,Oe,Ee,$t,Ae,me,lt,Ie,q,B,we,wt,H,Ve,dt,ft,Le,Ue,kt,ht,ye,G,Pt,xt,Fe,Gt,ne,Ce,Be,j,Ke,V,St,Rt,ze,qe,ce,he,ke,We,Qe,Ye,vr,Ua=(vr=class extends Mt{constructor(){super();T(this,oe);P(this,"NOTE_IDLE",0);P(this,"NOTE_ATTACK",1);P(this,"NOTE_DECAY",2);P(this,"NOTE_SUSTAIN",3);P(this,"NOTE_HELD",4);P(this,"NOTE_RELEASE",5);P(this,"NOTE_SOSTENUTO_ATTACK",8);P(this,"NOTE_SOSTENUTO_DECAY",9);P(this,"NOTE_SOSTENUTO_SUSTAIN",10);P(this,"NOTE_SOSTENUTO_HELD",11);P(this,"CH_MELODIC",0);P(this,"CH_DRUMS",1);P(this,"CH_DRUM1",2);P(this,"CH_DRUM2",3);P(this,"CH_DRUM3",4);P(this,"CH_DRUM4",5);P(this,"CH_DRUM5",6);P(this,"CH_DRUM6",7);P(this,"CH_DRUM7",8);P(this,"CH_DRUM8",9);P(this,"DUMP_ALL",0);P(this,"DUMP_ONCE",1);P(this,"DUMP_MODE",2);P(this,"EXT_NONE",0);P(this,"EXT_VL",1);P(this,"EXT_DX",3);P(this,"VLBC_BRTHEXPR",1);P(this,"VLBC_VELOINIT",2);P(this,"VLBC_VELOALL",3);P(this,"CH_INACTIVE",0);P(this,"CH_ACTIVE",1);P(this,"CH_DISABLED",2);T(this,A,0);T(this,Y,0);T(this,ge,0);T(this,Se,new Array(11));T(this,de,new Uint8Array(m.ch));T(this,F,new Uint8Array(m.ch));T(this,D,new Uint8Array(m.ch));T(this,b,new Uint8Array(m.ch*m.cc));T(this,fe,new Uint8Array(m.ace));T(this,I,new Uint8Array(m.ch));T(this,K,new Uint8Array(m.ch*m.nn));T(this,ae,new Uint8Array(m.ch));T(this,z,new Uint16Array(m.pl));T(this,Q,new Uint8Array(m.pl));T(this,Te,new Int16Array(m.ch));T(this,$e,new Uint8Array(m.ch));T(this,Ge,0);T(this,ie,new Uint8Array(m.ch*m.ext));T(this,R,new Uint8Array(m.ch*m.rpn));T(this,L,new Uint8Array(m.ch*m.rpnt));T(this,ct,new Int8Array(m.ch*br.length));T(this,ee,new Uint8Array(m.drm*m.dpn*m.dnc));T(this,be,new Uint8Array(m.drm*2));T(this,se,new Uint8Array(m.efx*3));T(this,ot,new Uint8Array(m.ch));T(this,Xe,new Uint8Array(m.ch*m.redir));T(this,X,new Uint8Array(m.port));T(this,Oe,new Uint8Array(m.ch));T(this,Ee,new Uint8Array(m.ch));T(this,$t,new Uint8Array(m.ch*m.cvn));T(this,Ae,new Uint8Array(128));T(this,me,new Uint8Array(m.cmt*8));T(this,lt,new Uint8Array(1024));T(this,Ie,new Uint8Array(m.cmt*64));T(this,q,{});T(this,B,void 0);T(this,we,void 0);T(this,wt,void 0);T(this,H,100);T(this,Ve,0);T(this,dt,500);T(this,ft,0);T(this,Le,"");T(this,Ue,0);T(this,kt,0);T(this,ht,0);T(this,ye,!0);T(this,G,!1);T(this,Pt,1);T(this,xt,void 0);T(this,Fe,new Array(m.ch));T(this,Gt,new Uint8Array(2));T(this,ne,[]);T(this,Ce,new Uint8Array(m.ch));T(this,Be,new Uint8Array(m.tr));P(this,"baseBank",new Lt("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es"));P(this,"userBank",new Lt("gm"));P(this,"initOnReset",!1);P(this,"aiEfxName","");T(this,j,[]);T(this,Ke,void 0);T(this,V,{nOff:(e,a)=>{let h=e*128+a,n=t(this,z).lastIndexOf(h);if(n>-1)if(t(this,b)[m.cc*e+E[64]]>63)t(this,Q)[n]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:a,velo:t(this,K)[h],state:this.NOTE_HELD});else if(t(this,b)[m.cc*e+E[66]]>63&&t(this,Q)[n]==this.NOTE_SOSTENUTO_SUSTAIN)t(this,Q)[n]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:a,velo:t(this,K)[h],state:this.NOTE_SOSTENUTO_HELD});else{t(this,z)[n]=0,t(this,K)[h]=0,t(this,Q)[n]=this.NOTE_IDLE;let p=this.getExt(e)[1];(p==this.VLBC_VELOINIT||p==this.VLBC_VELOALL)&&(t(this,b)[m.cc*e+E[129]]=0),this.dispatchEvent("note",{part:e,note:a,velo:0,state:this.NOTE_IDLE})}},nOn:(e,a,h)=>{let n=e*128+a,p=0;for(t(this,ae)[e]&&t(this,V).ano(e);t(this,Q)[p]>0&&t(this,z)[p]!=n;)p++;if(p{},cAt:(e,a)=>{},hoOf:e=>{t(this,Q).forEach((a,h)=>{if(a==this.NOTE_HELD){let n=t(this,z)[h],p=n>>7;e==p&&(t(this,Q)[h]=this.NOTE_IDLE,t(this,z)[h]=0,t(this,K)[n]=0,this.dispatchEvent("note",{part:e,note:n&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,Q).forEach((a,h)=>{let n;switch(a){case this.NOTE_ATTACK:{n=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{n=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{n=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(n){t(this,Q)[h]=n;let p=t(this,z)[h];this.dispatchEvent("note",{part:e,note:p&127,velo:t(this,K)[p],state:n})}})},soOf:e=>{t(this,Q).forEach((a,h)=>{if(a==this.NOTE_SOSTENUTO_HELD){let n=t(this,z)[h],p=n>>7;e==p&&(t(this,Q)[h]=this.NOTE_IDLE,t(this,z)[h]=0,t(this,K)[n]=0,this.dispatchEvent("note",{part:e,note:n&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,z).forEach((a,h,n)=>{let p=a>>7,y=a&127;a==0&&t(this,K)[0]==0||p==e&&t(this,V).nOff(p,y)})}});T(this,St,{8:function(e){let a=e.channel,h=e.data[0];t(this,V).nOff(a,h)},9:function(e){let a=e.channel,h=this;if(h.getChModeId(a)==S.xg&&t(h,D)[a]>1){let y=h.getChDrumFirstWrite(a);y[0]&&y[1]!=m.invalidCh&&!t(h,de)[a]&&(h.copyChSetup(y[1],a),h.dispatchEvent("voice",{part:a}),console.debug(`Part CH${a+1} copied from CH${y[1]}.`))}h.setChActive(a,1);let n=e.data[0],p=e.data[1];p>0?t(h,V).nOn(a,n,p):t(h,V).nOff(a,n)},10:function(e){let a=e.channel,h=a*128+e.data[0];t(this,z).indexOf(h)>-1&&(t(this,K)[h]=data[1],this.getExt(a)[1]==this.VLBC_VELOALL&&(t(this,b)[m.cc*a+E[129]]=data[1]),this.dispatchEvent("note",{part:a,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let a=e.channel,h=this,n=t(this,Fe)[a],p=n[e.data[0]];p&&(e.data[0]=p),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,A)){case S.s90es:case S.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(a,1);break}e.data[1]&&this.setChActive(a,1);break}default:{this.setChActive(a,1);break}}})();let y=a*m.cc,v=a*m.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,V).ano(a),t(this,Te)[a]=0,t(this,b)[y+E[1]]=0,t(this,b)[y+E[5]]=0,t(this,b)[y+E[64]]=0,t(this,b)[y+E[65]]=0,t(this,b)[y+E[66]]=0,t(this,b)[y+E[67]]=0,t(this,b)[y+E[11]]=127,t(this,b)[y+E[101]]=127,t(this,b)[y+E[100]]=127,t(this,b)[y+E[99]]=127,t(this,b)[y+E[98]]=127;return}case 123:{t(this,V).ano(a);return}case 124:{t(this,V).ano(a);return}case 125:{t(this,V).ano(a);return}case 126:{t(this,ae)[a]=1,t(this,V).ano(a);return}case 127:{t(this,ae)[a]=0,t(this,V).ano(a);return}}if(E[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(zr.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(O()&&console.debug(`${W[t(this,A)]}, CH${a+1}: ${e.data[1]}`),t(this,A)==0?e.data[1]<48?(t(this,D)[a]>0&&(e.data[1]=t(this,b)[y],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==56?this.switchMode(t(this,B).x5==82?"x5d":"05rw"):e.data[1]==62?this.switchMode(t(this,B).x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(W[t(this,B).ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,A)==S.gs||t(this,A)==S.sc?e.data[1]<56&&t(this,D)[a]>0&&(e.data[1]=t(this,b)[y],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)):t(this,A)==S.gm&&(e.data[1]<48?t(this,D)[a]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${a+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0)),t(this,A)){case S.xg:{[79,95,126,127].indexOf(e.data[1])>-1?t(this,D)[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):t(this,D)[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`)),[33,81,97].indexOf(e.data[1])>-1?t(this,ie)[v]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?t(this,ie)[v]=this.EXT_DX:t(this,ie)[v]=this.EXT_NONE;break}case S["05rw"]:case S.x5d:case S.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(this,D)[a]==this.CH_MELODIC&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):[80,81,82,83].indexOf(e.data[1])>-1||t(this,D)[a]!=this.CH_MELODIC&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case S.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,D)[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):t(this,D)[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case S.g2:{e.data[1]==120?t(this,D)[a]==0&&(this.setChType(a,this.CH_DRUMS),console.debug(`CH${a+1} set to drums by MSB.`)):t(this,D)[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:a});break}case 2:{this.getExt(a)[1]==this.VLBC_BRTHEXPR&&(t(this,b)[y+E[129]]=e.data[1]);break}case 6:{if(t(this,Ge)){[S.xg,S.gs,S.sc,S.ns5r].indexOf(t(this,A))<0&&console.warn(`NRPN commits are not available under "${W[t(this,A)]}" mode, even when they are supported in Octavia.`);let k=t(this,b)[y+E[99]],r=t(this,b)[y+E[98]];if(k==1){let c=qr.indexOf(r);if(c>-1)t(this,b)[y+E[71+c]]=e.data[1],O()&&console.debug(`Redirected NRPN 1 ${r} to cc${71+c}.`),this.dispatchEvent("cc",{part:a,cc:71+c,data:e.data[1]});else{let o=br.indexOf(r);o>-1?t(this,ct)[a*10+o]=e.data[1]-64:console.warn(`NRPN 0x01${r.toString(16).padStart(2,"0")} is not supported.`),O()&&console.debug(`CH${a+1} voice NRPN ${r} commit`)}}else{if(Dt.indexOf(k)<0){let o=`NRPN 0x${k.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")} `;k==127?console.warn(`${o}is not necessary. Consider removing it.`):console.warn(`${o}is not supported.`)}else{let o=t(this,D)[a]-2;o<0?console.warn(`CH${a+1} cannot accept drum NRPN as type ${mt[t(this,D)[a]]}.`):t(this,ee)[(o*m.dpn+le[k])*m.dnc+r]=e.data[1]}O()&&console.debug(`CH${a+1} (${mt[t(this,D)[a]]}) drum NRPN ${k} commit`)}}else{let k=ur[t(this,b)[y+E[100]]],r=pr[t(this,b)[y+E[100]]];t(this,b)[y+E[101]]==0&&k!=null&&(O()&&console.debug(`CH${a+1} RPN 0 ${t(this,b)[y+E[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],gr[k][0]),gr[k][1]),t(this,R)[a*m.rpn+k]=e.data[1],t(this,L)[a*m.rpnt+r]=1,this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)}))}break}case 32:{switch(O()&&console.debug(`${W[t(this,A)]}, CH${a+1} LSB: ${e.data[1]}`),t(this,A)){case S.s90es:case S.motif:{this.setChType(a,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,A),!0);break}}this.getExt(a)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:a});break}case 38:{if(!t(this,Ge)){let k=ur[t(this,b)[y+100]],r=pr[t(this,b)[y+100]];t(this,b)[y+101]==0&&k!=null&&(t(this,R)[a*m.rpn+k+1]=e.data[1],t(this,L)[a*m.rpnt+r]=1)}break}case 64:{e.data[1]<64&&t(this,V).hoOf(a);break}case 66:{e.data[1]>>6?t(this,V).soOn(a):t(this,V).soOf(a);break}case 98:case 99:{x(this,Ge,1);break}case 100:case 101:{x(this,Ge,0);break}}t(this,b)[y+E[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:a,cc:e.data[0],data:e.data[1]})}h.getChModeId(a)==S.xg&&t(h,D)[a]&&h.setDrumFirstWrite(a)},12:function(e){let a=e.channel,h=this;switch(t(h,A)){case S.s90es:case S.motif:{e.data&&h.setChActive(a,1);break}default:h.setChActive(a,1)}if(h.getExt(a)[0]==h.EXT_DX){let n=m.cc*a}t(h,I)[a]=e.data,t(h,Ee)[a]=0,O()&&console.debug(`T:${e.track} C:${a} P:${e.data}`),h.dispatchEvent("voice",{part:a}),h.getChModeId(a)==S.xg&&t(h,D)[a]&&h.setDrumFirstWrite(a)},13:function(e){let a=this,h=e.channel;t(this,z).forEach(function(n){let p=n>>7;h==p&&(t(a,K)[n]=e.data,a.dispatchEvent("note",{part:h,note:n&127,velo:e.data,state:a.NOTE_SUSTAIN}))})},14:function(e){let a=e.channel;t(this,Te)[a]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)})},15:function(e){Qr(e.data).forEach(a=>{let h=a[0],n=a[1];(t(this,Rt)[h]||function(){console.debug(`Unknown manufacturer ${h}.`)})(n,a.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(t(this,j)[e.meta]||function(h,n,p){}).call(this,e.data,e.track,e.meta),e.meta!=32&&x(this,Ve,0);let a=Kr.indexOf(e.meta)>-1;if(O()&&console.debug(e),a)return e.reply="meta",e}});T(this,Rt,{64:(e,a,h)=>{t(this,We).run(a,h,e)},65:(e,a,h)=>{if(a[0]<16)if(a[1]==72){let n=a[a.length-1],p=De(a.subarray(3,a.length-1));n==p?t(this,he).run(a.subarray(0,a.length-1),h,e):console.warn(`Bad SD checksum ${n} - should be ${p}.`)}else t(this,he).run(a,h,e);else{let n=a[a.length-1],p=De(a.subarray(2,a.length-1));n==p?t(this,he).run(a.subarray(0,a.length-1),h,e):console.warn(`Bad GS checksum ${n} - should be ${p}.`)}},66:(e,a,h)=>{t(this,ke).run(a,h,e)},67:(e,a,h)=>{t(this,ce).run(a,h,e)},68:(e,a,h)=>{t(this,Ye).run(a,h,e)},71:(e,a,h)=>{t(this,Qe).run(a,h,e)},126:(e,a,h)=>{t(this,ze).run(a,h,e)},127:(e,a,h)=>{this.switchMode("gm"),t(this,qe).run(a,h,e)}});T(this,ze,void 0);T(this,qe,void 0);T(this,ce,void 0);T(this,he,void 0);T(this,ke,void 0);T(this,We,void 0);T(this,Qe,void 0);T(this,Ye,void 0);let e=this;x(e,oe,new Uint8Array(256),$r),t(e,Se)[10]=new Uint8Array(512),x(e,Ke,new ue),x(e,B,{x5:82,ds:S.krs,smotif:S.s90es,gs:4,sc:3}),x(e,we,{dumpLimit:e.DUMP_MODE}),x(e,wt,new Proxy(t(e,we),{set:()=>{}}));for(let r in dr){let c=S[r];c==null?console.debug(`SubDB build error: "${r}" does not exist`):t(e,q)[c]=new Uint8Array(dr[r])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -149,26 +149,26 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),e.addEventListener("metacommit",function(r){var l,i;let{data:o}=r;((l=t(e,ne)[0])==null?void 0:l.type)==o.type&&((i=t(e,ne)[0])!=null&&i.amend)?(t(e,ne)[0].amend=o.amend,t(e,ne)[0].data+=o.data):t(e,ne).unshift(o)}),t(e,j)[1]=function(r){var o,l,i,s,c;switch(r=r.replaceAll(`\r +122 006 000 `),e.addEventListener("metacommit",function(r){var o,i;let{data:c}=r;((o=t(e,ne)[0])==null?void 0:o.type)==c.type&&((i=t(e,ne)[0])!=null&&i.amend)?(t(e,ne)[0].amend=c.amend,t(e,ne)[0].data+=c.data):t(e,ne).unshift(c)}),t(e,j)[1]=function(r){var c,o,i,s,l;switch(r=r.replaceAll(`\r `,` `).replaceAll("\r",` -`),r.slice(0,2)){case"@I":{x(this,G,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(o=r.slice(2))==null?void 0:o.trimLeft()});break}case"@K":{x(this,G,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(l=r.slice(2))==null?void 0:l.trimLeft()}),console.debug(`Karaoke mode active: ${r.slice(2)}`);break}case"@L":{x(this,G,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(i=r.slice(2))==null?void 0:i.trimLeft()});break}case"@T":{x(this,G,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(s=r.slice(2))==null?void 0:s.trimLeft()});break}case"@V":{x(this,G,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(c=r.slice(2))==null?void 0:c.trimLeft()});break}case"XF":{let d=r.slice(2).split(":");switch(d[0]){case"hd":{d.slice(1).forEach((u,f)=>{u.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][f],data:u})});break}case"ln":{d.slice(1).forEach((u,f)=>{u.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][f],data:u})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:r})}break}default:t(this,G)?r[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:r.slice(1),amend:!0})):r[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:r.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:r,amend:!0}):r.split(` -`).forEach((d,u)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:d,mask:u!=0})})}},t(e,j)[2]=function(r){this.dispatchEvent("metacommit",{type:"Copyrite",data:r})},t(e,j)[3]=function(r,o){o<1&&t(this,Ve)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:r})},t(e,j)[4]=function(r,o){this.dispatchEvent("metacommit",{type:"Instrmnt",data:r})},t(e,j)[5]=function(r){r.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:r,amend:!0})},t(e,j)[6]=function(r){this.dispatchEvent("metacommit",{type:"C.Marker",data:r})},t(e,j)[7]=function(r){this.dispatchEvent("metacommit",{type:"CuePoint",data:r})},t(e,j)[32]=function(r){x(this,Ve,r[0]+1)},t(e,j)[33]=function(r,o){O()&&console.debug(`Track ${o} requests to get assigned to output ${r}.`),t(e,Be)[o]=r+1},t(e,j)[81]=function(r,o){x(e,dt,r/1e3)},t(e,j)[127]=function(r,o){t(e,Ke).run(r,o)},t(e,Ke).default=function(r){console.warn(`Unrecognized sequencer-specific byte sequence: ${r}`)},t(e,Ke).add([67,0,1],function(r,o){t(e,Be)[o]=r[0]+1}),x(e,ze,new ue("universal non-realtime")),x(e,qe,new ue("universal realtime")),x(e,ce,new ue("Yamaha")),x(e,he,new ue("Roland")),x(e,ke,new ue("Korg")),x(e,We,new ue("Kawai")),x(e,Qe,new ue("Akai")),x(e,Ye,new ue("Casio"));let a=new ue("DX7+ Dump"),h=function(r){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,r)};t(e,ze).default=h,t(e,qe).default=h,t(e,ce).default=h,t(e,he).default=h,t(e,ke).default=h,t(e,We).default=h,t(e,Qe).default=h,t(e,Ye).default=h,a.default=h,t(e,ze).add([9],(r,o,l)=>{e.switchMode(["gm","?","g2"][r[0]-1],!0),e.setPortMode(e.getTrackPort(o),1,S[["gm","?","g2"][r[0]-1]]),x(e,G,t(e,G)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][r[0]-1]}`),r[0]==2&&e.init()}),t(e,qe).add([4,1],(r,o,l)=>{e.dispatchEvent("mupromptex"),x(e,H,((r[1]<<7)+r[0])/16383*100),e.dispatchEvent("mastervolume",t(e,H))}).add([4,3],(r,o,l)=>((r[1]<<7)+r[0]-8192)/8192).add([4,4],(r,o,l)=>r[1]-64).add([4,5],(r,o,l)=>{e.dispatchEvent("mupromptex");let i=r[0],s=r[1],c=r[2],d=3,u=d+(i<<1),f=u+s;if(i!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${i})! -`,r);return}let $=0,w=0,C=0;switch(r.subarray(d,u).forEach(M=>{$=$<<7,$|=M}),r.subarray(u,f).forEach((M,_)=>{w|=M<<_*7}),r.subarray(f).forEach((M,_)=>{C|=M<<_*7}),O()&&console.debug(`GM2 global parameter: (${r.subarray(3,u)}; p: ${w}, v: ${C})`),$){case 129:{w==0&&(e.setEffectType(0,52,C),e.dispatchEvent("efxreverb",e.getEffectType(0)));break}case 130:{w==0&&(e.setEffectType(1,52,C|16),e.dispatchEvent("efxchorus",e.getEffectType(1)));break}default:O()&&console.debug("GM2 global paramater slot path unknown.")}}),t(this,ce).add([76,0,0],(r,o,l)=>{switch(r[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${r}`);break}case 126:{e.switchMode("xg",!0),e.setPortMode(e.getTrackPort(o),4,S.xg),x(e,G,!1),console.info("MIDI reset: XG");break}default:{e.dispatchEvent("mupromptex");let i=[0,0,0,0],s=(c,d)=>{i[d]=c};if(r.subarray(1).forEach((c,d)=>{let u=d+r[0];([s,s,s,s,f=>{x(this,H,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},f=>{},f=>{}][u]||(()=>{}))(c,d)}),r[0]<4){let c=0;i.forEach(d=>{c=c<<4,c+=d}),c-=1024}}}}).add([76,2,1],(r,o,l)=>{e.dispatchEvent("mupromptex");let i="XG ";r[0]<32?(i+="reverb ",r.subarray(1).forEach((s,c)=>{([d=>{e.setEffectTypeRaw(0,!1,d),console.info(`${i}main type: ${Et[d]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},d=>{e.setEffectTypeRaw(0,!0,d),console.debug(`${i}sub type: ${d+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},d=>{console.debug(`${i}time: ${tr(d)}s`)},d=>{console.debug(`${i}diffusion: ${d}`)},d=>{console.debug(`${i}initial delay: ${d}`)},d=>{console.debug(`${i}HPF cutoff: ${st[d]}Hz`)},d=>{console.debug(`${i}LPF cutoff: ${st[d]}Hz`)},d=>{console.debug(`${i}width: ${d}`)},d=>{console.debug(`${i}height: ${d}`)},d=>{console.debug(`${i}depth: ${d}`)},d=>{console.debug(`${i}wall type: ${d}`)},d=>{console.debug(`${i}dry/wet: ${d}`)},d=>{console.debug(`${i}send: ${re(d)}dB`)},d=>{console.debug(`${i}pan: ${d-64}`)},!1,!1,d=>{console.debug(`${i}delay: ${d}`)},d=>{console.debug(`${i}density: ${d}`)},d=>{console.debug(`${i}balance: ${d}`)},d=>{},d=>{console.debug(`${i}feedback: ${d}`)},d=>{}][r[0]+c]||function(){console.warn(`Unknown XG reverb address: ${r[0]}.`)})(s)})):r[0]<64?(i+="chorus ",r.subarray(1).forEach((s,c)=>{([d=>{e.setEffectTypeRaw(1,!1,d),console.info(`${i}main type: ${Et[d]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},d=>{e.setEffectTypeRaw(1,!0,d),console.debug(`${i}sub type: ${d+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},d=>{console.debug(`${i}LFO: ${er[d]}Hz`)},d=>{},d=>{console.debug(`${i}feedback: ${d}`)},d=>{console.debug(`${i}delay offset: ${rr(d)}ms`)},d=>{},d=>{console.debug(`${i}low: ${st[d]}Hz`)},d=>{console.debug(`${i}low: ${d-64}dB`)},d=>{console.debug(`${i}high: ${st[d]}Hz`)},d=>{console.debug(`${i}high: ${d-64}dB`)},d=>{console.debug(`${i}dry/wet: ${d}`)},d=>{console.debug(`${i}send: ${re(d)}dB`)},d=>{console.debug(`${i}pan: ${d-64}`)},d=>{console.debug(`${i}to reverb: ${re(d)}dB`)},!1,d=>{},d=>{},d=>{},d=>{console.debug(`${i}LFO phase diff: ${(d-64)*3}deg`)},d=>{console.debug(`${i}input mode: ${d?"stereo":"mono"}`)},d=>{}][r[0]-32+c]||function(){console.warn(`Unknown XG chorus address: ${r[0]}.`)})(s)})):r[0]<86?(i+="variation ",r.subarray(1).forEach((s,c)=>{([d=>{e.setEffectTypeRaw(2,!1,d),console.info(`${i}main type: ${Et[d]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},d=>{e.setEffectTypeRaw(2,!0,d),console.debug(`${i}sub type: ${d+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][r[0]-64+c]||function(){})(s)})):r[0]<97?(i+="variation ",r.subarray(1).forEach((s,c)=>{[d=>{console.debug(`${i}send: ${re(d)}dB`)},d=>{console.debug(`${i}pan: ${d-64}`)},d=>{console.debug(`${i}to reverb: ${re(d)}dB`)},d=>{console.debug(`${i}to chorus: ${re(d)}dB`)},d=>{console.debug(`${i}connection: ${d?"system":"insertion"}`)},d=>{console.debug(`${i}channel: CH${d+1}`)},d=>{console.debug(`${i}mod wheel: ${d-64}`)},d=>{console.debug(`${i}bend wheel: ${d-64}`)},d=>{console.debug(`${i}channel after touch: ${d-64}`)},d=>{console.debug(`${i}AC1: ${d-64}`)},d=>{console.debug(`${i}AC2: ${d-64}`)}][r[0]-86+c](s)})):r[0]>111&&r[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${r[0]}`)}).add([76,2,64],(r,o,l)=>{r.subarray(1).forEach((i,s)=>{let c=s+r[0];if(c==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let d=c-1>>2,u=c-1&3,f=`XG EQ ${d} ${["gain","freq","Q","shape"][u]}: `;[()=>{console.debug(`${f}${i-64}dB`)},()=>{console.debug(`${f}${i} (raw)`)},()=>{console.debug(`${f}${i/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!i]}`)}][u]()}})}).add([76,3],(r,o,l)=>{e.dispatchEvent("mupromptex");let i=r[0],s=r[1],c=`XG Insertion ${r[0]+1} `;r.subarray(2).forEach((d,u)=>{([f=>{e.setEffectTypeRaw(3+i,!1,f),console.info(`${c}main type: ${Et[f]}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))},f=>{e.setEffectTypeRaw(3+i,!0,f),console.debug(`${c}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))}][s+u]||function(){})(d)})}).add([76,6,0],(r,o,l)=>{let i=r[0];i<64?e.setLetterDisplay(r.subarray(1),"XG letter display",i):x(e,Ue,Date.now())}).add([76,7,0],(r,o,l)=>{let i=r[0];x(e,Y,0),x(e,ge,Date.now()+3200),t(e,oe,xe).fill(0);let s=r.subarray(1);for(let c=0;c>6-C&1,C++})}).add([76,8],(r,o)=>{e.dispatchEvent("mupromptex");let l=e.chRedir(r[0],o,!0),i=r[1],s=m.cc*l,c=`XG CH${l+1} `,d=`Unknown XG part address ${i}.`,u=!0;r.subarray(2).forEach((f,$)=>{u=!0,i<1?console.debug(d):i<41?([()=>{t(e,b)[s+E[0]]=f,e.dispatchEvent("voice",{part:l})},()=>{t(e,b)[s+E[32]]=f,e.dispatchEvent("voice",{part:l})},()=>{t(e,I)[l]=f,e.dispatchEvent("voice",{part:l})},()=>{u=!1;let w=e.chRedir(f,o,!0);t(e,F)[l]=w,l!=w&&(e.buildRchTree(),console.info(`${c}receives from CH${w+1}`)),t(e,de)[l]||(e.copyChSetup(w,l,!0),console.debug(`${c}copied from CH${w+1}.`),e.setChActive(l,1),e.dispatchEvent("voice",{part:l}))},()=>{t(e,ae)[l]=+!f},()=>{},()=>{u=!1,e.setChType(l,f,S.xg),console.debug(`${c}type: ${mt[f]||f}`),e.dispatchEvent("voice",{part:l})},()=>{t(e,R)[m.rpn*l+3]=f,t(e,L)[m.rpnt*l+2]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)})},!1,!1,()=>{t(e,b)[s+E[7]]=f},!1,!1,()=>{t(e,b)[s+E[10]]=f||128},!1,!1,()=>{t(e,b)[s+E[128]]=f,e.allocateAce(128)},()=>{t(e,b)[s+E[93]]=f},()=>{t(e,b)[s+E[91]]=f},()=>{t(e,b)[s+E[94]]=f},()=>{t(e,b)[s+E[76]]=f},()=>{t(e,b)[s+E[77]]=f},()=>{t(e,b)[s+E[78]]=f},()=>{t(e,b)[s+E[74]]=f},()=>{t(e,b)[s+E[71]]=f},()=>{t(e,b)[s+E[73]]=f},()=>{t(e,b)[s+E[75]]=f},()=>{t(e,b)[s+E[72]]=f}][i+$-1]||(()=>{}))():i<48?console.debug(d):i<111?i>102&&i<105&&(t(e,b)[s+E[[5,65][i&1]]]=f):i<114?console.debug(d):i<116?console.debug(`${c}EQ ${["bass","treble"][i&1]} gain: ${f-64}dB`):i<118?console.debug(d):i<120?console.debug(`${c}EQ ${["bass","treble"][i&1]} freq: ${f}`):console.debug(d)}),u&&t(e,D)[l]>1&&e.setDrumFirstWrite(l)}).add([76,9],(r,o)=>{let l=e.chRedir(r[0],o,!0),i=r[1],s=m.cc*l,c=`PLG-VL CH${l+1} `;r.subarray(2).forEach((d,u)=>{let f=u+i;switch(f){case 1:{console.info(`${c}breath mode: ${["system","breath","velocity","touch EG"][d]}`);break}case 0:case 27:case 28:break;default:if(f<27){let $=f-3>>1,w=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][$];f&1?f<23?(console.debug(`${c}${w} control source: ${sr(d)}`),d&&d<96&&e.allocateAce(130+$),t(e,Xe)[m.redir*l+$+2]=d,e.buildRccMap()):console.debug(`${c}${w} scale break point: ${d}`):(console.debug(`${c}${w} depth: ${d-64}`),t(e,b)[s+E[130+$]]=d)}}})}).add([76,10],(r,o,l)=>{}).add([76,16],(r,o,l)=>{}).add([76,17,0,0],(r,o,l)=>{}).add([76,112],(r,o,l)=>{switch(console.debug(`XG enable PLG-${["VL","SG","DX","AN","PF","DR","PC","AP"][r[0]]} for CH${r[2]+1}.`),r[0]){case 0:{t(e,ie)[m.ext*r[2]]=e.EXT_VL;break}case 2:{t(e,ie)[m.ext*r[2]]=e.EXT_DX;break}default:t(e,ie)[m.ext*r[2]]=e.EXT_NONE}}).add([73,0,0],(r,o)=>{let l=r[0],i="MU1000 System - ";r.subarray(1).forEach((s,c)=>{let d=l+c;d==8?console.debug(`${i}LCD contrast: ${s}.`):d==18?(t(e,q)[S.xg][1]=s?126:0,console.debug(`${i}default bank: ${s?"MU100 Native":"MU Basic"}.`),e.dispatchEvent("banklevel",{mode:"xg",data:+!!s}),e.forceVoiceRefresh()):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")},()=>{x(e,ye,!!s),console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][d-64]()})}).add([73,10,0],(r,o)=>{let l=r[0],i=`MU1000 RS${t(e,ye)?"":" (ignored)"}: `;if(l<16)switch(l){case 2:{let s=e.chRedir(0,o,!0);t(e,ye)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${i}Show CH1~64`);break}case 3:{let s=e.chRedir(r[1]<<5,o,!0);t(e,ye)&&e.dispatchEvent("channelmin",s),t(e,ye)&&e.dispatchEvent("channelmax",s+31),console.info(`${i}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${i}unknown switch ${l} invoked.`)}else if(l<32){if(t(e,ye)){let s=e.chRedir(l-16+(t(e,ht)<<4),o,!0);e.dispatchEvent("channelactive",s)}}else if(l<36){let s=e.chRedir(l-32<<4,o,!0);t(e,ye)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),x(e,ht,l-32)),console.info(`${i}Show CH${s+1}~CH${s+16}`)}}).add([73,11,0],(r,o)=>{let l="MU1000 System - channel ",i="Octavia System - channel ",s=r[0];r.subarray(1).forEach((c,d)=>{let u=s+d;([()=>{e.setChActive(c,1),e.dispatchEvent("channelactive",c),O()&&console.debug(`${l}current part: CH${c+1}`)},()=>{c<5?(e.dispatchEvent("portrange",1<{c<16?(e.dispatchEvent("portstart",c),console.debug(`${i}start port: ${"ABCDEFGHIJKLMNOP"[c]}`)):(e.dispatchEvent("portstart",255),console.debug(`${i}start port: reset`))}][u]||(()=>{console.debug(`${l}unknown address: ${u}`)}))()})}).add([93,3],(r,o)=>{let l=e.chRedir(r[0],o,!0),i=`PLG-100SG CH${l+1} `,s=Date.now();if(r[1]==0){let c="",d=0;r.subarray(2).forEach((u,f)=>{f%2==0?c+=ar[u]||u.toString().padStart("0"):d+=u*13}),s>=t(e,ft)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${ir(c)}`,amend:!0}),x(e,ft,s+Math.ceil(d/2)+t(e,dt)),O()&&console.debug(`${i}vocals: ${c}`)}else console.warn(`Unknown PLG-100SG data: ${r}`)}).add([98,0],(r,o,l)=>{e.dispatchEvent("mupromptex");let i=r[0],s=r.length-5,c=r.length-1;if(i!=s){console.info(`PLG-DX native dump size mismatch! Gave ${i} instead of ${r.length-5}.`);return}let d=De(r.subarray(4,c));if(d!=r[c]){console.info(`Bad PLG-DX checksum ${r[c]} - should be ${d}.`);return}r[0]=98,t(e,ce).run(r.subarray(0,c),o,l,{noAce:!0})}).add([98,96],(r,o,l,i)=>{let s=e.chRedir(r[0],o,!0),c=m.cc*s,d=r[1];r.subarray(2).forEach((u,f)=>{let $=d+f;if(!($<10)){if($==10)e.resetAce();else if($<27){let w=$+131;i!=null&&i.noAce||e.allocateAce(w),t(e,b)[c+E[w]]=u,e.dispatchEvent("cc",{part:s,cc:w,data:u})}}})}).add([100,0],(r,o,l)=>{let i=r.subarray(0,r.length-1);if(r[0]+5!=r.length){console.warn(`Yamaha DX7+ dump SysEx size mismatch! Expected ${r.length}, but got ${r[0]}: -`,r);return}let s=De(i),c=r[r.length-1];if(s!=c){console.warn(`Yamaha DX7+ dump SysEx checksum mismatch! Expected ${s}, but got ${c}: -`,r);return}a.run(i.subarray(1))}).add([100,76],(r,o,l)=>{let i=r[0]>>4,s=r[0]&15,c=r[1];switch(i){case 2:{let d=e.chRedir(s,o,!0),u=m.cc*d;r.subarray(2).forEach((f,$)=>{let w=$+c;if(!(w<7)){if(w<23){let C=w+135;e.allocateAce(C),t(e,b)[u+E[C]]=f,e.dispatchEvent("cc",{part:d,cc:C,data:f})}}});break}default:console.info("Unknown DX7+ multipart: %o",r)}}),a.add([14,31],(r,o,l)=>{t(e,b)[m.cc*r[0]+E[64]]=0,t(e,V).ano(r[0]),e.switchMode("xg"),e.setPortMode(e.getTrackPort(o),1,S.xg),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${r[0]+1}.`)}).add([76,112],async r=>{let o=r[0],l=m.cc*o,i=m.ext*o,s=m.cvn*o;t(e,ie)[i]=e.EXT_DX,t(e,Ee)[o]=1;let c=t(e,$t).subarray(s,s+m.cvn);c.fill(32),r.subarray(1).forEach((d,u)=>{if(u<10)c[u]=Math.max(d,32);else if(!(u<40)){if(u<56){let f=u+102;t(e,b)[l+E[f]]=d,e.dispatchEvent("cc",{part:o,cc:f,data:d})}}}),t(e,I)[o]=o&127,t(e,b)[m.cc*o+E[0]]=35,t(e,b)[m.cc*o+E[32]]=o>>7|4,e.dispatchEvent("voice",{part:o}),console.debug(`DX7+ CH${o+1} dump: %o`,r)});let n=function(r,o,l,i){},p=function(r,o){e.dispatchEvent("mupromptex");let l=r*m.dpn,i=o[0],s=o[1];o.subarray(2).forEach((c,d)=>{let u=d+s,f=-1;u<16?([()=>{f=24},()=>{f=25},()=>{f=26},()=>{},()=>{f=28},()=>{f=29},()=>{f=30},()=>{f=31},()=>{},()=>{},()=>{},()=>{f=20},()=>{f=21},()=>{f=22},()=>{f=23},()=>{}][u]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${r+1}.`)}))():u<32||(u<40?([()=>{f=48},()=>{f=49},!1,!1,()=>{f=52},()=>{f=53}][u-32]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${r+1}.`)}))():u<80||([()=>{f=36}][u-80]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${r+1}.`)}))()),f>=0?(O()&&console.debug(l,f,i,c),t(e,ee)[(l+le[f])*m.dnc+i]=c):O()&&console.debug(`XG-style drum param ${u} has no writes.`)})},y=function(r,o,l){e.dispatchEvent("mupromptex");let i=r*m.dpn,s=(o<<7)+l[0];l.subarray(1).forEach((c,d)=>{let u=d+s,f=u&127,$=u>>7,w=-1;$>1&&([()=>{w=26},()=>{},()=>{w=28},()=>{w=29},()=>{w=30},()=>{},()=>{},()=>{w=31}][$-2]||(()=>{console.debug(`Unknown GS-style drum param ${$} on set ${r+1}.`)}))(),w>-1?(O()&&console.debug(i,w,f,c),t(e,ee)[(i+le[w])*m.dnc+f]=c):O()&&console.debug(`GS-style drum param ${$} has no writes.`)})};t(this,ce).add([76,48],(r,o,l)=>{p(0,r)}).add([76,49],(r,o,l)=>{p(1,r)}).add([76,50],(r,o,l)=>{p(2,r)}).add([76,51],(r,o,l)=>{p(3,r)}).add([76,52],(r,o,l)=>{p(4,r)}).add([76,53],(r,o,l)=>{p(5,r)}).add([76,54],(r,o,l)=>{p(6,r)}).add([76,55],(r,o,l)=>{p(7,r)}),t(this,ce).add([89,0],(r,o,l)=>{if(e.eprom){let i=r[0],s=(r[1]<<14)+(r[2]<<7)+r[3]+(e.eprom.offset||0);O()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${i} bytes.`);let c=e.eprom.data;r.subarray(4).forEach((d,u)=>{let f=u>>3,$=u&7;if($==7)for(let w=0;w<7;w++)c[s+7*f+w]+=(d>>6-w&1)<<7;else c[s+7*f+$]=d})}}).add([89,1],(r,o,l)=>{let i=(r[0]<<21)+(r[1]<<14)+(r[2]<<7)+r[3];O()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(r,o,l)=>{if(e.eprom){let i=(r[0]<<21)+(r[1]<<14)+(r[2]<<7)+r[3]+(e.eprom.offset||0);O()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;r.subarray(4).forEach((c,d)=>{let u=d>>3,f=d&7;if(f==7)for(let $=0;$<7;$++)s[i+7*u+$]+=(c>>6-$&1)<<7;else s[i+7*u+f]=c})}}).add([89,3],(r,o,l)=>{}),t(this,ce).add([39,48],(r,o,l)=>{}).add([43,0,0],(r,o,l)=>{e.dispatchEvent("mupromptex");let i=[0,0,0,0],s=(c,d)=>{i[d]=c};if(r.subarray(1).forEach((c,d)=>{let u=d+r[0];[s,s,s,s,()=>{x(this,H,c*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},()=>c-64,()=>c||128,()=>c,()=>c,()=>{console.debug(`TG300 variation on cc${c}.`)}][u](c,u)}),r[0]<4){let c=0;i.forEach(d=>{c=c<<4,c+=d}),c-=1024}}).add([43,1,0],(r,o,l)=>{e.dispatchEvent("mupromptex")}).add([43,2],(r,o,l)=>{e.dispatchEvent("mupromptex");let i=e.chRedir(r[0],o,!0),s=r[1],c=m.cc*i,d=`TG300 CH${i+1} `;r.subarray(2).forEach((u,f)=>{f<5?([()=>{},()=>{t(e,b)[c+E[0]]=u,e.dispatchEvent("voice",{part:i})},()=>{t(e,b)[c+E[32]]=u,e.dispatchEvent("voice",{part:i})},()=>{t(e,I)[i]=u,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(u,o,!0);t(e,F)[i]=$,i!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))}][f+s]||(()=>{}))(u,f+s):f<21||(f<47?([()=>{t(e,ae)[i]=+!u},()=>{},()=>{},()=>{t(e,R)[m.rpn*i+3]=u,t(e,L)[m.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{},()=>{t(e,b)[c+E[7]]=u},!1,!1,()=>{t(e,b)[c+E[10]]=u||128},!1,!1,()=>{console.debug(`${d} AC1 at cc${u}`)},()=>{console.debug(`${d} AC2 at cc${u}`)},()=>{t(e,b)[c+E[128]]=u,e.allocateAce(128)},()=>{t(e,b)[c+E[93]]=u},()=>{t(e,b)[c+E[91]]=u},()=>{t(e,b)[c+E[94]]=u},()=>{t(e,b)[c+E[76]]=u},()=>{t(e,b)[c+E[77]]=u},()=>{t(e,b)[c+E[74]]=u},()=>{t(e,b)[c+E[71]]=u},()=>{t(e,b)[c+E[73]]=u},()=>{t(e,b)[c+E[75]]=u},()=>{t(e,b)[c+E[72]]=u},()=>{t(e,b)[c+E[78]]=u}][f+s-21]||(()=>{}))(u,f+s):f<95||([()=>{t(e,b)[c+E[65]]=u},()=>{t(e,b)[c+E[5]]=u}][f+s-95]||(()=>{}))(u,f+s))})}).add([43,7,0],(r,o,l)=>{let i=r[0];e.setLetterDisplay(r.subarray(1),"TG300 letter display",i)}).add([43,7,1],(r,o,l)=>{x(e,Y,0),x(e,ge,Date.now()+3200),t(e,oe,xe).fill(0),r.forEach(function(i,s){let c=Math.floor(s/16),d=s%16,u=(d*3+c)*7,f=7,$=0;for(u-=d*5,c==2&&(f=2);$>6-$&1,$++})}),t(this,he).add([66,18,0,0,127],(r,o,l)=>{e.switchMode("sc",!0),e.setPortMode(e.getTrackPort(o),2,S.sc),t(e,b)[m.cc*9]=120,t(e,b)[m.cc*25]=120,t(e,b)[m.cc*41]=120,t(e,b)[m.cc*57]=120,t(e,q)[S.sc][1]=t(e,B).sc,x(e,G,!1),t(e,Ce).fill(0),console.info(`GS system to ${["single","dual"][r[0]]} mode.`)}).add([66,18,64,0],(r,o,l)=>{switch(r[0]){case 127:{e.switchMode("gs",!0),e.setPortMode(e.getTrackPort(o),2,S.gs),t(e,q)[S.gs][1]=t(e,B).gs,t(e,b)[m.cc*9]=120,t(e,b)[m.cc*25]=120,t(e,b)[m.cc*41]=120,t(e,b)[m.cc*57]=120,x(e,G,!1),t(e,Ce).fill(0),console.info("MIDI reset: GS");break}default:{e.dispatchEvent("mupromptex");let i=[0,0,0,0],s=(c,d)=>{i[d]=c};if(r.subarray(1).forEach((c,d)=>{let u=d+r[0];[s,s,s,s,f=>{x(this,H,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},f=>{},f=>{}][u](c,d)}),r[0]<4){let c=0;i.forEach(d=>{c=c<<4,c+=d}),c-=1024}}}}).add([66,18,64,1],(r,o,l)=>{e.dispatchEvent("mupromptex");let i=r[0];if(i<16){let s="".padStart(i," ");r.subarray(1).forEach((c,d)=>{s+=String.fromCharCode(Math.max(32,c))}),s=s.padEnd(16," "),console.debug(`GS patch name: ${s}`)}else i<48||(i<65?r.subarray(1).forEach((s,c)=>{let d=`GS ${i+c>55?"chorus":"reverb"} `;([()=>{console.info(`${d}type: ${Bt[s]}`),e.setEffectType(0,40,s),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${d}predelay: ${s}ms`)},()=>{console.info(`${d}type: ${nr[s]}`),e.setEffectType(1,40,16+s),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${d}to reverb: ${re(s)}`)},()=>{console.debug(`${d}to delay: ${re(s)}`)}][i+c-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?r.subarray(1).forEach((s,c)=>{let d="GS delay ";([()=>{console.info(`${d}type: ${cr[s]}`),e.setEffectType(2,40,32+s),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${d}to reverb: ${re(s)}`)}][i+c-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],(r,o,l)=>{let i="GS EQ ";r.subarray(1).forEach((s,c)=>{([()=>{console.debug(`${i}low freq: ${[200,400][s]}Hz`)},()=>{console.debug(`${i}low gain: ${s-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][s]}Hz`)},()=>{console.debug(`${i}high gain: ${s-64}dB`)}][r[0]+c]||function(){console.warn(`Unknown GS EQ address: ${r[0]+c}`)})()})}).add([66,18,64,3],(r,o,l)=>{e.dispatchEvent("mupromptex");let i="GS EFX ",s=function(c,d){let u=or(t(e,se).subarray(10,12),d,c);u&&console.debug(`${i}${Nt(t(e,se).subarray(10,12))} ${u}`)};r.subarray(1).forEach((c,d)=>{([()=>{e.setEffectTypeRaw(3,!1,32+c),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,c),console.info(`${i}type: ${Nt(t(e,se).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,()=>{console.debug(`${i}to reverb: ${re(c)}dB`)},()=>{console.debug(`${i}to chorus: ${re(c)}dB`)},()=>{console.debug(`${i}to delay: ${re(c)}dB`)},!1,()=>{console.debug(`${i}1 source: ${c}`),c&&c<96&&e.allocateAce(c)},()=>{console.debug(`${i}1 depth: ${c-64}`)},()=>{console.debug(`${i}2 source: ${c}`),c&&c<96&&e.allocateAce(c)},()=>{console.debug(`${i}2 depth: ${c-64}`)},()=>{console.debug(`${i}to EQ: ${c?"ON":"OFF"}`)}][r[0]+d]||function(u,f){console.warn(`Unknown GS EFX address: ${f}`)})(c,r[0]+d)})}).add([66,18,65],(r,o,l)=>{y((r[0]>>4)+1<<1,r[0]&15,r.subarray(1))}).add([69,18,16],(r,o,l)=>{var i;switch(r[0]){case 0:{let s=r[1];e.setLetterDisplay(r.subarray(2),"GS display text",s);break}case 32:{x(e,ge,Date.now()+3200),r[1]==0&&(r[2]?(x(e,Y,Math.max(Math.min(r[2]-1,9),0)),O()&&console.debug(`GS switch display page ${r[2]-1}.`)):(x(e,Y,0),x(e,ge,Date.now()),O()&&console.debug("GS disable display page.")));break}default:if(r[0]<6){t(e,Y)>9&&x(e,Y,0);let s=r[0]-1<<1|r[1]>>6;t(e,Y)==s&&x(e,ge,Date.now()+3200),(i=t(e,Se)[s])!=null&&i.length||(t(e,Se)[s]=new Uint8Array(256));let c=t(e,Se)[s];O()&&console.debug(`GS frame draw page ${s}.`);let d=r[1]&63;c.fill(0),r.subarray(2).forEach(function(f,$){let w=$+d,C=Math.floor(w/16),M=w%16,_=(M*4+C)*5,Re=5,_e=0;for(_-=M*4,C==3&&(Re=1);_e>4-_e&1,_e++})}else console.warn(`Unknown GS display section: ${r[0]}`)}});let v=function(r,o,l){e.dispatchEvent("mupromptex");let i=r[0],s=m.cc*o,c=m.rpn*o,d=`GS CH${o+1} `;i<3?(r.subarray(1).forEach((u,f)=>{[()=>{t(e,b)[s+E[0]]=u},()=>{t(e,I)[o]=u},()=>{let $=0;u<16?$=e.chRedir(u,l,!0):$=m.ch,t(e,F)[o]=$,o!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))}][i+f]()}),e.dispatchEvent("voice",{part:o})):i<19||(i<44?r.subarray(1).forEach((u,f)=>{([()=>{t(e,ae)[o]=+!u},!1,()=>{e.setChType(o,u<<1,S.gs),console.debug(`${d}type: ${u?"drum ":"melodic"}${u||""}`)},()=>{t(e,R)[c+3]=u,t(e,L)[m.rpnt*o+2]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)})},!1,()=>{t(e,b)[s+E[7]]=u},!1,!1,()=>{t(e,b)[s+E[10]]=u||128},!1,!1,()=>{console.debug(`${d}CC 1: cc${u}`)},()=>{console.debug(`${d}CC 2: cc${u}`)},()=>{t(e,b)[s+E[93]]=u},()=>{t(e,b)[s+E[91]]=u},!1,!1,()=>{t(e,R)[c+1]=u,t(e,L)[m.rpnt*o+1]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)})},()=>{t(e,R)[c+2]=u,t(e,L)[m.rpnt*o+1]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)})},()=>{t(e,b)[s+E[94]]=u}][i+f-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},k=function(r,o){let l=r[0],i=`GS CH${o+1} `;l<2?r.subarray(1).forEach((s,c)=>{[()=>{t(e,b)[m.cc*o+E[32]]=s},()=>{}][l+c]()}):l<32?console.warn(`Unknown GS misc address: ${l}`):l<35?r.subarray(1).forEach((s,c)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][s]}`),t(e,ot)[o]=s,e.dispatchEvent("partefxtoggle",{part:o,active:s})}][l+c-32]()}):console.warn(`Unknown GS misc address: ${l}`)};t(this,he).add([66,18,64,16],(r,o)=>{v(r,e.chRedir(9,o,!0),o)}).add([66,18,64,17],(r,o)=>{v(r,e.chRedir(0,o,!0),o)}).add([66,18,64,18],(r,o)=>{v(r,e.chRedir(1,o,!0),o)}).add([66,18,64,19],(r,o)=>{v(r,e.chRedir(2,o,!0),o)}).add([66,18,64,20],(r,o)=>{v(r,e.chRedir(3,o,!0),o)}).add([66,18,64,21],(r,o)=>{v(r,e.chRedir(4,o,!0),o)}).add([66,18,64,22],(r,o)=>{v(r,e.chRedir(5,o,!0),o)}).add([66,18,64,23],(r,o)=>{v(r,e.chRedir(6,o,!0),o)}).add([66,18,64,24],(r,o)=>{v(r,e.chRedir(7,o,!0),o)}).add([66,18,64,25],(r,o)=>{v(r,e.chRedir(8,o,!0),o)}).add([66,18,64,26],(r,o)=>{v(r,e.chRedir(10,o,!0),o)}).add([66,18,64,27],(r,o)=>{v(r,e.chRedir(11,o,!0),o)}).add([66,18,64,28],(r,o)=>{v(r,e.chRedir(12,o,!0),o)}).add([66,18,64,29],(r,o)=>{v(r,e.chRedir(13,o,!0),o)}).add([66,18,64,30],(r,o)=>{v(r,e.chRedir(14,o,!0),o)}).add([66,18,64,31],(r,o)=>{v(r,e.chRedir(15,o,!0),o)}).add([66,18,64,64],(r,o)=>{k(r,e.chRedir(9,o,!0))}).add([66,18,64,65],(r,o)=>{k(r,e.chRedir(0,o,!0))}).add([66,18,64,66],(r,o)=>{k(r,e.chRedir(1,o,!0))}).add([66,18,64,67],(r,o)=>{k(r,e.chRedir(2,o,!0))}).add([66,18,64,68],(r,o)=>{k(r,e.chRedir(3,o,!0))}).add([66,18,64,69],(r,o)=>{k(r,e.chRedir(4,o,!0))}).add([66,18,64,70],(r,o)=>{k(r,e.chRedir(5,o,!0))}).add([66,18,64,71],(r,o)=>{k(r,e.chRedir(6,o,!0))}).add([66,18,64,72],(r,o)=>{k(r,e.chRedir(7,o,!0))}).add([66,18,64,73],(r,o)=>{k(r,e.chRedir(8,o,!0))}).add([66,18,64,74],(r,o)=>{k(r,e.chRedir(10,o,!0))}).add([66,18,64,75],(r,o)=>{k(r,e.chRedir(11,o,!0))}).add([66,18,64,76],(r,o)=>{k(r,e.chRedir(12,o,!0))}).add([66,18,64,77],(r,o)=>{k(r,e.chRedir(13,o,!0))}).add([66,18,64,78],(r,o)=>{k(r,e.chRedir(14,o,!0))}).add([66,18,64,79],(r,o)=>{k(r,e.chRedir(15,o,!0))}),t(this,ke).add([54,65],(r,o)=>{let l=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(l,!0),e.setPortMode(e.getTrackPort(o),1,S[l]);let i=r[r.length-1],s=r.subarray(0,r.length-1),c=De(s);c!=i&&(console.info(`X5D multi parameters checksum mismatch! Expected ${c}, got ${i}.`),console.debug(r));let d=(r[1]<<7)+r[0],u=(r[3]<<7)+r[2],f=e.chRedir(d&15,o,!0),$=m.cc*f;[()=>{u<1||(u<101?(e.setChType(f,e.CH_MELODIC,S.x5d),t(e,I)[f]=u-1,t(e,b)[$+E[0]]=t(e,B).x5):u<229?(e.setChType(f,e.CH_MELODIC,S.x5d),t(e,I)[f]=u-101,t(e,b)[$+E[0]]=56):(e.setChType(f,e.CH_DRUMS,S.x5d),t(e,I)[f]=mr[u-229]||0,t(e,b)[$+E[0]]=62)),e.dispatchEvent("voice",{part:f})},()=>{t(e,b)[$+E[7]]=u},()=>{u<31&&(t(e,b)[$+E[10]]=Math.round((u-15)*4.2+64))},()=>{t(e,b)[$+E[93]]=yt(u)},()=>{t(e,b)[$+E[91]]=yt(u)},()=>{t(e,R)[f*m.rpn+3]=u>8191?u-16320:64+u,t(e,L)[m.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{t(e,R)[f*m.rpn+1]=u>8191?u-16320:64+u,t(e,L)[m.rpnt*f+1]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{u>0&&(t(e,R)[f*m.rpn]=u,t(e,L)[m.rpnt*f]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)}))},()=>{}][d>>4]()}).add([54,76,0],(r,o)=>{e.dispatchEvent("mupromptex");let l=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(l),e.setPortMode(e.getTrackPort(o),1,S[l]);let i="",s=t(e,B).x5,c=0,d=0,u="MSB PRG LSB NME";pe(r,function(f,$){if($<16400){let w=$%164;switch(!0){case w<10:{f>31&&(i+=String.fromCharCode(f));break}case w==10:break;case w==11:{u+=` -${s} ${c} ${d} ${i.trim().replace("Init Voice","")}`,c++,i="";break}}c>99&&(s=90,c=0)}}),e.userBank.clearRange({msb:t(e,B).x5,prg:[0,99],lsb:0}),e.userBank.load(u),O()&&console.debug(u),e.forceVoiceRefresh()}).add([54,77,0],(r,o)=>{e.dispatchEvent("mupromptex");let l=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(l),e.setPortMode(e.getTrackPort(o),1,S[l]);let i="",s=90,c=0,d=0,u="MSB PRG LSB NME";pe(r,function(f,$){if($<13600){let w=$%136;switch(!0){case w<10:{f>31&&(i+=String.fromCharCode(f));break}case w==11:{u+=` -${s} ${c} ${d} ${i.trim().replace("Init Combi","")}`,c++,i="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(u),O()&&console.debug(u),e.forceVoiceRefresh()}).add([54,78],(r,o)=>{let l=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(l),e.setPortMode(e.getTrackPort(o),1,S[l]),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][r[0]]} mode.`)}).add([54,85],(r,o)=>{e.dispatchEvent("mupromptex");let l=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(l),e.setPortMode(e.getTrackPort(o),1,S[l]),pe(r,(i,s)=>{s>0&&s<3&&(e.setEffectType(s-1,44,i),e.dispatchEvent(`efx${["reverb","chorus"][s-1]}`,e.getEffectType(s-1)))})}).add([54,104],(r,o)=>{e.dispatchEvent("mupromptex");let l=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(l,!0);let i=e.getTrackPort(o);if(t(e,X)[i]&&t(e,X)[i]!=S[l])if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${o}. Port ${String.fromCharCode(65+i)} mode "${W[t(e,X)[i]]}" mismatch, should be "${l}".`);return}else console.info(`Track ${o} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+i)}.`);e.setPortMode(i,1,S[l]),pe(r,function(s,c,d,u){if(c<192){let f=e.chRedir(Math.floor(c/12),o,!0),$=f*m.cc;switch(c%12){case 0:{s<128?(e.setChType(f,e.CH_MELODIC,S.x5d),t(e,b)[$+E[0]]=t(e,B).x5,t(e,I)[f]=s):(e.setChType(f,e.CH_DRUMS,S.x5d),t(e,b)[$+E[0]]=62,t(e,I)[f]=mr[s-128]),s>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{t(e,b)[$+E[7]]=s;break}case 2:{t(e,R)[f*m.rpn+3]=s>127?s-192:64+s,t(e,L)[m.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)});break}case 3:{t(e,R)[f*m.rpn+1]=s>127?s-192:64+s,t(e,L)[m.rpnt*f+1]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)});break}case 4:{s<31&&(t(e,b)[$+E[10]]=Math.round((s-15)*4.2+64));break}case 5:{let w=s>>4,C=s&15;t(e,b)[$+E[91]]=yt(C),t(e,b)[$+E[93]]=yt(w);break}case 10:break;case 11:{let w=e.chRedir(s&15,o,!0),C=s>>4;t(e,F)[f]=s,(w!=f||C)&&(console.info(`X5D Part CH${f+1} receives from CH${w+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(c-192,o,!0)}})}),t(this,he).add([22,18,127],(r,o,l)=>{e.switchMode("mt32",!0),e.setPortMode(e.getTrackPort(o),1,S.mt32),x(e,G,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(r,o,l)=>{e.switchMode("mt32");let i=e.chRedir(l,o,!0),s=r[1];r.subarray(2).forEach((c,d)=>{let u=d+s;t(e,Ae)[u+(i-1)*16]=c,([!1,()=>{let f=t(e,Ae)[i-1<<4];if(f<3){if(t(e,Ee)[i]=1,f==2)for(let $=0;${t(e,R)[i*m.rpn+3]=c+40,t(e,L)[m.rpnt*i+2]=1},()=>{t(e,R)[i*m.rpn+1]=c+14,t(e,L)[m.rpnt*i+1]=1},()=>{t(e,R)[i*m.rpn]=c,t(e,L)[m.rpnt*i]=1},!1,()=>{t(e,b)[m.cc*i+E[91]]=c?127:0},!1,()=>{t(e,b)[m.cc*i+E[7]]=c},()=>{t(e,b)[m.cc*i+E[10]]=Math.ceil(c*9.05)}][u]||(()=>{}))()})}).add([22,18,1],(r,o,l)=>{e.switchMode("mt32");let i=l&7;console.debug(`MT-32 slot #${l+1} Drum: ${r}`);let s=r[0]<<7|r[1];r.subarray(2).forEach((c,d)=>{let u=d+s,f=(u>>2)+24,$=u&3,w=i*m.dpn;if(O()&&console.debug(`MT-32 temp drum note ${f} param ${$}: ${c}`),f<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${f}`);return}[()=>{},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=Math.round(c*1.27)},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=c*9+1&127},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=c?127:0}][$]()})}).add([22,18,2],(r,o,l)=>{e.switchMode("mt32");let i=e.chRedir(l,o,!0),s=r[1]+(r[0]<<7);s<10&&(t(e,Ee)[i]=1),r.subarray(2).forEach((c,d)=>{let u=d+s;u<14&&(t(e,me)[(i-1)*m.cmt+u]=c)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(r,o,l)=>{e.switchMode("mt32");let i=l&7;if(r[0]){let s=(r[0]-1<<7)+r[1]-16;r.subarray(2).forEach((c,d)=>{let u=d+s,f=(u>>2)+24,$=u&3,w=i*m.dpn;if(O()&&console.debug(`MT-32 dev drum note ${f} param ${$}: ${c}`),f<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${f}`);return}[()=>{},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=Math.round(c*1.27)},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=c*9+1&127},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=c?127:0}][$]()})}else{let s=r[1];r.subarray(2).forEach((c,d)=>{let u=d+s;t(e,Ae)[u]=c;let f=e.chRedir(1+(u>>4),o,!0),$=u&15;([!1,()=>{let w=t(e,Ae)[f-1<<4];if(w<3)if(t(e,Ee)[f]=1,w==2)for(let C=0;C{t(e,R)[f*m.rpn+3]=c+40,t(e,L)[m.rpnt*f+2]=1},()=>{t(e,R)[f*m.rpn+1]=c+14,t(e,L)[m.rpnt*f+1]=1},()=>{t(e,R)[f*m.rpn]=c,t(e,L)[m.rpnt*f]=1},!1,()=>{t(e,b)[m.cc*f+E[91]]=c?127:0},!1,()=>{t(e,b)[m.cc*f+E[7]]=c},()=>{t(e,b)[m.cc*f+E[10]]=Math.ceil(c*9.05)}][$]||(()=>{}))()})}}).add([22,18,4],(r,o,l)=>{e.switchMode("mt32");let i=r[1]+(r[0]<<7),s=[];r.subarray(2).forEach((c,d)=>{let u=d+i,f=e.chRedir(Math.floor(u/246+1),o,!0),$=u%246;$<14&&(t(e,me)[(f-1)*m.cmt+$]=c),$<10&&(t(e,Ee)[f]=1),s.indexOf(f)<0&&s.push(f)}),s.forEach(c=>{e.dispatchEvent("voice",{part:c})})}).add([22,18,5],(r,o,l)=>{e.switchMode("mt32");let i=(r[0]<<7)+r[1];r.subarray(2).forEach((s,c)=>{let d=i+c,u=Math.floor(d/8),f=d&7,$=u*8;t(e,lt)[d]=s,([!1,()=>{let w=t(e,lt)[$];if(w<3){let C="";if(w==2){let _=m.cmt*u;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:u});let M=`MSB LSB PRG NME -000 127 ${u} ${C}`;e.userBank.load(M,!0)}}][f]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(r,o,l)=>{e.switchMode("mt32");let i=((r[0]&1)<<7)+r[1],s=r[0]>>1,c=!1;if(r.subarray(2).forEach((d,u)=>{let f=i+u;f{e.switchMode("mt32");let i=r[1],s=!1,c=function(d,u){t(e,F)[u-12]=d,s=!0};r.subarray(2).forEach((d,u)=>{let f=u+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,c,c,c,c,c,c,c,c,c,()=>{x(e,H,d),e.dispatchEvent("mastervolume",t(e,H))}][f]||(()=>{}))(d,u)}),s&&e.buildRchTree()}).add([22,18,32],(r,o,l)=>{e.switchMode("mt32");let i=r[1],s=" ".repeat(i);r.subarray(2).forEach(c=>{c>31?s+=String.fromCharCode(c):s+=" "}),x(e,Le,s.padStart(20," ")),x(e,Ue,Date.now()+3200)}).add([22,18,82],(r,o)=>{let l=e.chRedir(0,o,!0);for(let i=0;i<16;i++)t(e,V).ano(l+i),i&&i<10&&(t(e,I)[l+i]=Ht[i-1]);console.info("MT-32 alt reset complete.")}),t(this,ke).add([66,0],(r,o)=>{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(o),2,S.ns5r),x(e,G,!1),console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][r[0]]} mode.`)}).add([66,1],(r,o)=>{let l=["ns5r","05rw"][r[0]];e.switchMode(l,!0),e.setPortMode(e.getTrackPort(o),2,S[l]),x(e,G,!1)}).add([66,18,0,0],(r,o)=>{let l=r[0];switch(l){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(o),2,S.ns5r),x(e,G,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${r}`);break}default:if(l<10){let i=[0,0,0,0],s=(c,d)=>{i[d]=c};if(r.subarray(1).forEach((c,d)=>{[s,s,s,s,()=>{x(e,H,c*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},()=>c-64,()=>c-64,()=>{},()=>{},()=>{}][l+d]()}),r[0]<4){let c=0;i.forEach(d=>{c=c<<4,c+=d}),c-=1024}}}}).add([66,18,0,1],(r,o)=>{}).add([66,18,0,2],(r,o)=>{}).add([66,18,1],(r,o)=>{e.dispatchEvent("mupromptex");let l=e.chRedir(r[0],o,!0),i=l*m.cc,s=r[1],c=`NS5R CH${l+1} `;r.subarray(2).forEach((d,u)=>{let f=s+u;f<3?([()=>{t(e,b)[i+E[0]]=d||nt.bank0},()=>{t(e,b)[i+E[32]]=d},()=>{t(e,I)[l]=d}][f](),e.dispatchEvent("voice",{part:l})):f<8||(f<14?[()=>{let $=e.chRedir(d,o,!0);t(e,F)[l]=$,l!=$&&(e.buildRchTree(),console.info(`${c}receives from CH${$+1}`))},()=>{t(e,ae)[l]=+!d},()=>{e.setChType(l,d,S.ns5r),console.debug(`${c}type: ${mt[d]}`)},()=>{t(e,R)[m.rpn*l+3]=d,t(e,L)[m.rpnt*l+2]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)})},()=>{},()=>{}][f-8]():f<16||(f<33?[()=>{t(e,b)[i+E[7]]=d},()=>{t(e,b)[i+E[11]]=d},()=>{},()=>{},()=>{t(e,b)[i+E[10]]=d||128},()=>{},()=>{},()=>{t(e,b)[i+E[93]]=d},()=>{t(e,b)[i+E[91]]=d},()=>{t(e,b)[i+E[76]]=d},()=>{t(e,b)[i+E[77]]=d},()=>{t(e,b)[i+E[78]]=d},()=>{t(e,b)[i+E[74]]=d},()=>{t(e,b)[i+E[71]]=d},()=>{t(e,b)[i+E[73]]=d},()=>{t(e,b)[i+E[75]]=d},()=>{t(e,b)[i+E[72]]=d}][f-16]():f<112||f<114&&[()=>{t(e,b)[i+E[5]]=d},()=>{t(e,b)[i+E[65]]=d}][f-112]()))})}).add([66,18,8,0],(r,o)=>{let l=r[0];if(l<32)e.setLetterDisplay(r.subarray(1,33),"NS5R letter display");else{let i=l-32;x(e,ge,Date.now()+3200),x(e,Y,10),t(e,oe,xe).fill(0);let s=r.subarray(1),c=4;s.forEach(function(d,u){let f=u+i,$=f>>4,w=f&15;if(f<80){let C=$>3,M=0,_=$0;)t(e,oe,xe)[w*32+$*7+(_-M)]=C&1,C=C>>1,M++}})}}).add([66,18,48],(r,o,l)=>{p(0,r)}).add([66,18,49],(r,o,l)=>{p(1,r)}).add([66,18,50],(r,o,l)=>{p(2,r)}).add([66,18,51],(r,o,l)=>{p(3,r)}).add([66,18,52],(r,o,l)=>{p(4,r)}).add([66,18,53],(r,o,l)=>{p(5,r)}).add([66,18,54],(r,o,l)=>{p(6,r)}).add([66,18,55],(r,o,l)=>{p(7,r)}).add([66,52],(r,o)=>{e.switchMode("ns5r"),x(e,G,!1);let l="";pe(r,(i,s)=>{s<8?(i>31&&(l+=String.fromCharCode(i)),s==7&&(e.aiEfxName=l)):s<10&&(e.setEffectType(s-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(r,o)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r"),x(e,G,!1);let l="",i=r[r.length-1],s=r.subarray(0,r.length-1),c=De(s);c!=i&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${c}, got ${i}.`),console.debug(r));let d=e.getTrackPort(o);if(t(e,X)[d]&&t(e,X)[d]!=S.ns5r)if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${o}. Port ${String.fromCharCode(65+d)} mode "${W[t(e,X)[d]]}" mismatch, should be "ns5r".`);return}else console.info(`Track ${o} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+d)}.`);e.setPortMode(d,2,S.ns5r),pe(s,function(u,f){switch(!0){case f<2944:{let $=e.chRedir(Math.floor(f/92),o,!0),w=$*m.cc;switch(f%92){case 0:{t(e,b)[w+E[0]]=u,e.dispatchEvent("voice",{part:$});break}case 1:{t(e,b)[w+E[32]]=u,!u&&!t(e,b)[w+E[0]]&&(t(e,b)[w+E[0]]=nt.bank0),e.dispatchEvent("voice",{part:$});break}case 2:{t(e,I)[$]=u,u>0&&e.setChActive($,1),e.dispatchEvent("voice",{part:$});break}case 3:{let C=e.chRedir(u,o,!0);t(e,F)[$]=C,$!=C&&(console.info(`NS5R CH${$+1} receives from CH${C+1}.`),e.buildRchTree());break}case 7:{t(e,D)[$]=u,e.dispatchEvent("voice",{part:$});break}case 8:{t(e,R)[$*m.rpn+3]=u<40||u>88?u+(u>63?-192:64):u,t(e,L)[m.rpnt*$+2]=1,e.dispatchEvent("pitch",{part:$,pitch:e.getPitchShift($)});break}case 9:case 10:{t(e,b)[w+E[7]]=u;break}case 11:{t(e,b)[w+E[11]]=u;break}case 14:{t(e,b)[w+E[10]]=u||128;break}case 19:{t(e,b)[w+E[93]]=u;break}case 20:{t(e,b)[w+E[91]]=u;break}case 84:{t(e,b)[w+E[65]]=u;break}case 85:{t(e,b)[w+E[5]]=u;break}}break}case f<3096:break;case f<3134:{let $=f-3096;$<8?(u>31&&(l+=String.fromCharCode(u)),$==7&&(e.aiEfxName=l)):$<10&&(e.setEffectType($-8,44,u),e.dispatchEvent(`efx${["reverb","chorus"][$-8]}`,e.getEffectType($-8)));break}case f<8566:break}})}).add([66,54],(r,o)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let l="",i=80,s=0,c=0,d="MSB PRG LSB NME";pe(r,function(u,f){let $=f%158;switch(!0){case $<10:{u>31&&(l+=String.fromCharCode(u));break}case $==10:break;case $==11:{i=u&127;break}case $==12:{c=u&127;break}case $==13:{d+=` -${i} ${s} ${c} ${l.trim().replace("Init Voice","")}`,s++,l="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(d),O()&&console.debug(d),e.forceVoiceRefresh()}).add([66,55],(r,o)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let l="",i=88,s=0,c=0,d="MSB PRG LSB NME";pe(r,function(u,f){let $=f%126;switch(!0){case $<10:{u>31&&(l+=String.fromCharCode(u));break}case $==11:break;case $==12:break;case $==13:{d+=` -${i} ${s} ${c} ${l.trim().replace("Init Combi","")}`,s++,l="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(d),O()&&console.debug(d),e.forceVoiceRefresh()}).add([66,125],(r,o,l)=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][r[0]]||"white")}).add([66,127],(r,o,l)=>{let i=r[r.length-1],s=r.subarray(0,r.length-1),c=De(s);c!=i&&(console.info(`NS5R screen dump checksum mismatch! Expected ${c}, got ${i}.`),console.debug(r));let d=new Uint8Array(5760);pe(r,(u,f,$)=>{if(f<720)for(let w=0;w<8;w++)d[f*8+w]=u>>7-w&1}),e.dispatchEvent("screen",{type:"ns5r",data:d})}).add([76],(r,o,l)=>{t(e,ke).run([66,...r],o,l)}),t(this,We).add([16,0,8,0],(r,o,l)=>{let i=(r[2]<<4)+r[3],s="K11 ";([()=>{e.switchMode("k11",!0),e.setPortMode(e.getTrackPort(o),2,S.k11),x(e,G,!1),t(e,q)[S.k11][1]=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}`)}][r[0]]||(()=>{}))()}).add([16,0,8,1],(r,o,l)=>{e.dispatchEvent("mupromptex");let i=e.chRedir(r[1],o,!0),s=m.cc*i,c=m.rpn*i,d=(r[3]<<4)+r[4],u=`K11 CH${i+1} `;([()=>{d<128?(e.setChType(i,e.CH_MELODIC,S.k11),t(e,b)[s+E[0]]=0,t(e,I)[i]=d):(e.setChType(i,e.CH_DRUMS,S.k11),t(e,I)[i]=d-128),e.dispatchEvent("voice",{part:i})},()=>{let f=e.chRedir(d,o,!0);t(e,F)[i]=f,i!=f&&(e.buildRchTree(),console.info(`${u}receives from CH${f+1}`))},()=>{t(e,b)[s+E[7]]=d},()=>{uupThis.setChActive(i,d)},()=>{t(e,b)[s+E[10]]=d},()=>{t(e,R)[c+3]=d+40,t(e,L)[m.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,R)[c+1]=d>>1,t(e,R)[c+2]=d&1,t(e,L)[m.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,b)[s+E[91]]=d?127:0},()=>{},()=>{t(e,b)[s+E[74]]=d},()=>{t(e,b)[s+E[73]]=d},()=>{t(e,b)[s+E[72]]=d}][r[0]]||(()=>{}))()}).add([16,0,9,0],(r,o,l)=>{e.dispatchEvent("mupromptex");let i=(r[2]<<4)+r[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}`)}][r[0]]||(()=>{}))()}).add([16,0,9,3],(r,o,l)=>{e.dispatchEvent("mupromptex");let i=(r[2]<<4)+r[3],s=e.chRedir(r[1],o,!0),c=s*m.cc;[()=>{i<128?(e.setChType(s,e.CH_MELODIC,S.k11),t(e,b)[c+E[0]]=0,t(e,b)[c+E[32]]=0,t(e,I)[s]=i):i<160?(e.setChType(s,e.CH_MELODIC,S.k11),t(e,b)[c+E[0]]=0,t(e,b)[c+E[32]]=7,t(e,I)[s]=i-100):(e.setChType(s,e.CH_DRUMS,S.k11),t(e,b)[c+E[0]]=122,t(e,b)[c+E[32]]=0,t(e,I)[s]=i-160),e.dispatchEvent("voice",{part:s})},()=>{let d=e.chRedir(i,o,!0);t(e,F)[s]=d,s!=d&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${d+1}`))}][r[0]]()}).add([16,0,9,4],(r,o,l)=>{e.dispatchEvent("mupromptex");let i=(r[2]<<4)+r[3],s=e.chRedir(r[1],o,!0),c=s*m.cc,d=s*m.rpn,u=`GMLX CH${s+1} `;[()=>{e.setChActive(s,i)},()=>{t(e,b)[c+E[7]]=i},()=>{t(e,b)[c+E[10]]=i},()=>{t(e,b)[c+E[91]]=i?127:0},()=>{t(e,R)[d+3]=i+40,t(e,L)[m.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{t(e,R)[d+1]=i,t(e,L)[m.rpnt*s+1]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{t(e,R)[d]=i,t(e,L)[m.rpnt*s]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{}][r[0]]()}),t(this,Qe).add([66,93,64],(r,o,l)=>{let i=r[2];switch(r[0]){case 0:{switch(r[1]){case 4:{e.dispatchEvent("mupromptex"),x(e,H,i*129/16383*100),e.dispatchEvent("mastervolume",t(e,H));break}case 5:{e.dispatchEvent("mupromptex"),i-64;break}case 6:{e.dispatchEvent("mupromptex"),console.debug(`SG global reverb: ${i?"on":"off"}`);break}case 127:{e.switchMode("sg",!0),e.setPortMode(e.getTrackPort(o),1,S.sg);break}}break}case 1:{switch(r[1]){case 48:{e.dispatchEvent("mupromptex"),console.debug(`SG reverb type: ${Bt[i]}`);break}}break}default:if(r[0]>>4==1){e.dispatchEvent("mupromptex");let s=e.chRedir(r[0]&15,o,!0);if(r[1]==2){let c=e.chRedir(i,o,!0);t(e,F)[s]=c,s!=c&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${c+1}`))}else r[1]==19&&(t(e,b)[m.cc*s+E[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${r}`)}}),t(this,Ye).add([9],(r,o,l)=>{e.dispatchEvent("mupromptex"),console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremolo","phaser","rotary speaker","enhancer","flanger","EQ"][r[0]]||"off"}`)}),t(this,ce).add([127,0],(r,o,l)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...r]);t(e,ce).run(i,o,l)}).add([127,1,0,0],(r,o,l)=>{e.switchMode("s90es");let i="S90/Motif ES system ",s=r[0];r.subarray(1).forEach((c,d)=>{([()=>{x(e,H,c*12900/16383),e.dispatchEvent("mastervolume",t(e,H))}][s+d]||(()=>{console.info(`Unrecognized ${i}ID: ${s+d}`)}))()})}).add([127,1,0,36,54,1],(r,o,l)=>{e.switchMode("s90es");let i="S90/Motif ES reverb ",s=r[0];r.subarray(1).forEach((c,d)=>{([()=>{e.setEffectTypeRaw(0,!1,c&15|112)},()=>{e.setEffectTypeRaw(0,!0,c)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxreverb",e.getEffectType(0))}).add([127,1,0,37,54,2],(r,o,l)=>{e.switchMode("s90es");let i="S90/Motif ES chorus ",s=r[0];r.subarray(1).forEach((c,d)=>{([()=>{e.setEffectTypeRaw(1,!1,c&15|112)},()=>{e.setEffectTypeRaw(1,!0,c)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxchorus",e.getEffectType(1))}).add([127,1,0,34,54,3],(r,o,l)=>{e.switchMode("s90es");let i="S90/Motif ES insert 1 ",s=r[0];r.subarray(1).forEach((c,d)=>{([()=>{e.setEffectTypeRaw(3,!1,c&15|112)},()=>{e.setEffectTypeRaw(3,!0,c)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxinsert0",e.getEffectType(3))}).add([127,1,0,34,54,4],(r,o,l)=>{e.switchMode("s90es");let i="S90/Motif ES insert 2 ",s=r[0];r.subarray(1).forEach((c,d)=>{([()=>{e.setEffectTypeRaw(4,!1,c&15|112)},()=>{e.setEffectTypeRaw(4,!0,c)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxinsert1",e.getEffectType(4))}).add([127,1,0,35,54,17],(r,o,l)=>{e.switchMode("s90es");let i="S90/Motif ES variation ",s=r[0];r.subarray(1).forEach((c,d)=>{([()=>{e.setEffectTypeRaw(2,!1,c&15|112)},()=>{e.setEffectTypeRaw(2,!0,c)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxdelay",e.getEffectType(2))}).add([127,1,0,58,55],(r,o,l)=>{e.dispatchEvent("mupromptex"),e.switchMode("s90es");let i=e.getTrackPort(o);if(t(e,X)[i]&&t(e,X)[i]!=t(e,B).smotif)if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${o}. Port ${String.fromCharCode(65+i)} mode "${W[t(e,X)[i]]}" mismatch, should be "${W[t(e,B).smotif]}".`);return}else console.info(`Track ${o} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+i)}.`);let s=e.chRedir(r[0],o,!0),c=m.cc*s,d=r[1];r[0]>15&&(s=r[0]+32);let u=`Track ${o} S90/Motif ES bulk CH${s<128?s+1:"U"+(s-127)} `;console.debug(u,r),!(r[0]>15)&&r.subarray(2).forEach((f,$)=>{([()=>{t(e,b)[c+E[0]]=f,e.dispatchEvent("voice",{part:s})},()=>{f&&e.setChActive(s,1),t(e,b)[c+E[32]]=f,e.setChType(s,[32,40].indexOf(f)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,A),!0),e.dispatchEvent("voice",{part:s})},()=>{f&&e.setChActive(s,1),t(e,I)[s]=f,e.dispatchEvent("voice",{part:s})},()=>{let w=e.chRedir(f,o,!0);t(e,F)[s]=w,s!=w&&(e.buildRchTree(),console.info(`${u}receives from CH${w+1}`))},()=>{t(e,ae)[s]=f?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{f!=100&&e.setChActive(s,1),t(e,b)[c+E[7]]=f},()=>{f!=64&&e.setChActive(s,1),t(e,b)[c+E[10]]=f},!1,!1,!1,()=>{t(e,b)[c+E[91]]=f},()=>{f&&e.setChActive(s,1),t(e,b)[c+E[93]]=f},()=>{f&&e.setChActive(s,1),t(e,b)[c+E[94]]=f},()=>{f!=127&&e.setChActive(s,1),t(e,b)[c+E[128]]=f,e.allocateAce(128)},()=>{},()=>{f!=64&&e.setChActive(s,1),t(e,b)[c+E[74]]=f},()=>{f!=64&&e.setChActive(s,1),t(e,b)[c+E[71]]=f},!1,()=>{t(e,b)[c+E[65]]=f},()=>{t(e,b)[c+E[5]]=f},()=>{}][d+$]||(()=>{}))()})}).add([127,1,54,16],(r,o,l)=>{e.switchMode("s90es");let i=r[0];r.subarray(1).forEach((s,c)=>{let u=`S90/Motif ES EQ${(c>>2)+1} `;([()=>{let f=s-64},()=>{let f=st[s]},()=>{let f=s/10},()=>{let f=s}][i+c&3]||(()=>{}))()})}),t(this,he).add([0,72,18,0,0,0,0],(r,o,l)=>{e.switchMode("sd",!0),e.setPortMode(e.getTrackPort(o),2,S.sd),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(r,o,l)=>{e.dispatchEvent("mupromptex");let i=r[0]>>5,s=r[0]&31;switch(i){case 0:{let c=r[0]>>1,d=r[1];switch(c){case 1:{r.subarray(2).forEach((u,f,$)=>{let w=f+d;switch(w){case 0:{u&&(e.setEffectType(1,60,u-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${w} - ${u}`));break}}});break}case 2:{r.subarray(2).forEach((u,f)=>{let $=f+d;switch($){case 0:{u&&(e.setEffectType(0,55+u,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${$} - ${u}`));break}}});break}case 3:case 4:case 5:{let u=c-1;r.subarray(2).forEach((f,$)=>{let w=$+d;switch(console.debug(`SD MFX ${u-2}: ${w} - ${f}`),w){case 0:{e.setEffectTypeRaw(u,62,f),e.dispatchEvent(`efx${u>2?"delay":"insert"+(u-4)}`,e.getEffectType(u));break}}}),console.debug(`SD MFX message: +`),r.slice(0,2)){case"@I":{x(this,G,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(c=r.slice(2))==null?void 0:c.trimLeft()});break}case"@K":{x(this,G,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(o=r.slice(2))==null?void 0:o.trimLeft()}),console.debug(`Karaoke mode active: ${r.slice(2)}`);break}case"@L":{x(this,G,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(i=r.slice(2))==null?void 0:i.trimLeft()});break}case"@T":{x(this,G,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(s=r.slice(2))==null?void 0:s.trimLeft()});break}case"@V":{x(this,G,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(l=r.slice(2))==null?void 0:l.trimLeft()});break}case"XF":{let d=r.slice(2).split(":");switch(d[0]){case"hd":{d.slice(1).forEach((u,f)=>{u.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][f],data:u})});break}case"ln":{d.slice(1).forEach((u,f)=>{u.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][f],data:u})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:r})}break}default:t(this,G)?r[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:r.slice(1),amend:!0})):r[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:r.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:r,amend:!0}):r.split(` +`).forEach((d,u)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:d,mask:u!=0})})}},t(e,j)[2]=function(r){this.dispatchEvent("metacommit",{type:"Copyrite",data:r})},t(e,j)[3]=function(r,c){c<1&&t(this,Ve)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:r})},t(e,j)[4]=function(r,c){this.dispatchEvent("metacommit",{type:"Instrmnt",data:r})},t(e,j)[5]=function(r){r.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:r,amend:!0})},t(e,j)[6]=function(r){this.dispatchEvent("metacommit",{type:"C.Marker",data:r})},t(e,j)[7]=function(r){this.dispatchEvent("metacommit",{type:"CuePoint",data:r})},t(e,j)[32]=function(r){x(this,Ve,r[0]+1)},t(e,j)[33]=function(r,c){O()&&console.debug(`Track ${c} requests to get assigned to output ${r}.`),t(e,Be)[c]=r+1},t(e,j)[81]=function(r,c){x(e,dt,r/1e3)},t(e,j)[127]=function(r,c){t(e,Ke).run(r,c)},t(e,Ke).default=function(r){console.warn(`Unrecognized sequencer-specific byte sequence: ${r}`)},t(e,Ke).add([67,0,1],function(r,c){t(e,Be)[c]=r[0]+1}),x(e,ze,new ue("universal non-realtime")),x(e,qe,new ue("universal realtime")),x(e,ce,new ue("Yamaha")),x(e,he,new ue("Roland")),x(e,ke,new ue("Korg")),x(e,We,new ue("Kawai")),x(e,Qe,new ue("Akai")),x(e,Ye,new ue("Casio"));let a=new ue("DX7+ Dump"),h=function(r){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,r)};t(e,ze).default=h,t(e,qe).default=h,t(e,ce).default=h,t(e,he).default=h,t(e,ke).default=h,t(e,We).default=h,t(e,Qe).default=h,t(e,Ye).default=h,a.default=h,t(e,ze).add([9],(r,c,o)=>{e.switchMode(["gm","?","g2"][r[0]-1],!0),e.setPortMode(e.getTrackPort(c),1,S[["gm","?","g2"][r[0]-1]]),x(e,G,t(e,G)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][r[0]-1]}`),r[0]==2&&e.init()}),t(e,qe).add([4,1],(r,c,o)=>{e.dispatchEvent("mupromptex"),x(e,H,((r[1]<<7)+r[0])/16383*100),e.dispatchEvent("mastervolume",t(e,H))}).add([4,3],(r,c,o)=>((r[1]<<7)+r[0]-8192)/8192).add([4,4],(r,c,o)=>r[1]-64).add([4,5],(r,c,o)=>{e.dispatchEvent("mupromptex");let i=r[0],s=r[1],l=r[2],d=3,u=d+(i<<1),f=u+s;if(i!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${i})! +`,r);return}let $=0,w=0,C=0;switch(r.subarray(d,u).forEach(M=>{$=$<<7,$|=M}),r.subarray(u,f).forEach((M,_)=>{w|=M<<_*7}),r.subarray(f).forEach((M,_)=>{C|=M<<_*7}),O()&&console.debug(`GM2 global parameter: (${r.subarray(3,u)}; p: ${w}, v: ${C})`),$){case 129:{w==0&&(e.setEffectType(0,52,C),e.dispatchEvent("efxreverb",e.getEffectType(0)));break}case 130:{w==0&&(e.setEffectType(1,52,C|16),e.dispatchEvent("efxchorus",e.getEffectType(1)));break}default:O()&&console.debug("GM2 global paramater slot path unknown.")}}),t(this,ce).add([76,0,0],(r,c,o)=>{switch(r[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${r}`);break}case 126:{e.switchMode("xg",!0),e.setPortMode(e.getTrackPort(c),4,S.xg),x(e,G,!1),console.info("MIDI reset: XG");break}default:{e.dispatchEvent("mupromptex");let i=[0,0,0,0],s=(l,d)=>{i[d]=l};if(r.subarray(1).forEach((l,d)=>{let u=d+r[0];([s,s,s,s,f=>{x(this,H,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},f=>{},f=>{}][u]||(()=>{}))(l,d)}),r[0]<4){let l=0;i.forEach(d=>{l=l<<4,l+=d}),l-=1024}}}}).add([76,2,1],(r,c,o)=>{e.dispatchEvent("mupromptex");let i="XG ";r[0]<32?(i+="reverb ",r.subarray(1).forEach((s,l)=>{([d=>{e.setEffectTypeRaw(0,!1,d),console.info(`${i}main type: ${Et[d]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},d=>{e.setEffectTypeRaw(0,!0,d),console.debug(`${i}sub type: ${d+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},d=>{console.debug(`${i}time: ${tr(d)}s`)},d=>{console.debug(`${i}diffusion: ${d}`)},d=>{console.debug(`${i}initial delay: ${d}`)},d=>{console.debug(`${i}HPF cutoff: ${st[d]}Hz`)},d=>{console.debug(`${i}LPF cutoff: ${st[d]}Hz`)},d=>{console.debug(`${i}width: ${d}`)},d=>{console.debug(`${i}height: ${d}`)},d=>{console.debug(`${i}depth: ${d}`)},d=>{console.debug(`${i}wall type: ${d}`)},d=>{console.debug(`${i}dry/wet: ${d}`)},d=>{console.debug(`${i}send: ${re(d)}dB`)},d=>{console.debug(`${i}pan: ${d-64}`)},!1,!1,d=>{console.debug(`${i}delay: ${d}`)},d=>{console.debug(`${i}density: ${d}`)},d=>{console.debug(`${i}balance: ${d}`)},d=>{},d=>{console.debug(`${i}feedback: ${d}`)},d=>{}][r[0]+l]||function(){console.warn(`Unknown XG reverb address: ${r[0]}.`)})(s)})):r[0]<64?(i+="chorus ",r.subarray(1).forEach((s,l)=>{([d=>{e.setEffectTypeRaw(1,!1,d),console.info(`${i}main type: ${Et[d]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},d=>{e.setEffectTypeRaw(1,!0,d),console.debug(`${i}sub type: ${d+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},d=>{console.debug(`${i}LFO: ${er[d]}Hz`)},d=>{},d=>{console.debug(`${i}feedback: ${d}`)},d=>{console.debug(`${i}delay offset: ${rr(d)}ms`)},d=>{},d=>{console.debug(`${i}low: ${st[d]}Hz`)},d=>{console.debug(`${i}low: ${d-64}dB`)},d=>{console.debug(`${i}high: ${st[d]}Hz`)},d=>{console.debug(`${i}high: ${d-64}dB`)},d=>{console.debug(`${i}dry/wet: ${d}`)},d=>{console.debug(`${i}send: ${re(d)}dB`)},d=>{console.debug(`${i}pan: ${d-64}`)},d=>{console.debug(`${i}to reverb: ${re(d)}dB`)},!1,d=>{},d=>{},d=>{},d=>{console.debug(`${i}LFO phase diff: ${(d-64)*3}deg`)},d=>{console.debug(`${i}input mode: ${d?"stereo":"mono"}`)},d=>{}][r[0]-32+l]||function(){console.warn(`Unknown XG chorus address: ${r[0]}.`)})(s)})):r[0]<86?(i+="variation ",r.subarray(1).forEach((s,l)=>{([d=>{e.setEffectTypeRaw(2,!1,d),console.info(`${i}main type: ${Et[d]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},d=>{e.setEffectTypeRaw(2,!0,d),console.debug(`${i}sub type: ${d+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][r[0]-64+l]||function(){})(s)})):r[0]<97?(i+="variation ",r.subarray(1).forEach((s,l)=>{[d=>{console.debug(`${i}send: ${re(d)}dB`)},d=>{console.debug(`${i}pan: ${d-64}`)},d=>{console.debug(`${i}to reverb: ${re(d)}dB`)},d=>{console.debug(`${i}to chorus: ${re(d)}dB`)},d=>{console.debug(`${i}connection: ${d?"system":"insertion"}`)},d=>{console.debug(`${i}channel: CH${d+1}`)},d=>{console.debug(`${i}mod wheel: ${d-64}`)},d=>{console.debug(`${i}bend wheel: ${d-64}`)},d=>{console.debug(`${i}channel after touch: ${d-64}`)},d=>{console.debug(`${i}AC1: ${d-64}`)},d=>{console.debug(`${i}AC2: ${d-64}`)}][r[0]-86+l](s)})):r[0]>111&&r[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${r[0]}`)}).add([76,2,64],(r,c,o)=>{r.subarray(1).forEach((i,s)=>{let l=s+r[0];if(l==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let d=l-1>>2,u=l-1&3,f=`XG EQ ${d} ${["gain","freq","Q","shape"][u]}: `;[()=>{console.debug(`${f}${i-64}dB`)},()=>{console.debug(`${f}${i} (raw)`)},()=>{console.debug(`${f}${i/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!i]}`)}][u]()}})}).add([76,3],(r,c,o)=>{e.dispatchEvent("mupromptex");let i=r[0],s=r[1],l=`XG Insertion ${r[0]+1} `;r.subarray(2).forEach((d,u)=>{([f=>{e.setEffectTypeRaw(3+i,!1,f),console.info(`${l}main type: ${Et[f]}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))},f=>{e.setEffectTypeRaw(3+i,!0,f),console.debug(`${l}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))}][s+u]||function(){})(d)})}).add([76,6,0],(r,c,o)=>{let i=r[0];i<64?e.setLetterDisplay(r.subarray(1),"XG letter display",i):x(e,Ue,Date.now())}).add([76,7,0],(r,c,o)=>{let i=r[0];x(e,Y,0),x(e,ge,Date.now()+3200),t(e,oe,xe).fill(0);let s=r.subarray(1);for(let l=0;l>6-C&1,C++})}).add([76,8],(r,c)=>{e.dispatchEvent("mupromptex");let o=e.chRedir(r[0],c,!0),i=r[1],s=m.cc*o,l=`XG CH${o+1} `,d=`Unknown XG part address ${i}.`,u=!0;r.subarray(2).forEach((f,$)=>{u=!0,i<1?console.debug(d):i<41?([()=>{t(e,b)[s+E[0]]=f,e.dispatchEvent("voice",{part:o})},()=>{t(e,b)[s+E[32]]=f,e.dispatchEvent("voice",{part:o})},()=>{t(e,I)[o]=f,e.dispatchEvent("voice",{part:o})},()=>{u=!1;let w=e.chRedir(f,c,!0);t(e,F)[o]=w,o!=w&&(e.buildRchTree(),console.info(`${l}receives from CH${w+1}`)),t(e,de)[o]||(e.copyChSetup(w,o,!0),console.debug(`${l}copied from CH${w+1}.`),e.setChActive(o,1),e.dispatchEvent("voice",{part:o}))},()=>{t(e,ae)[o]=+!f},()=>{},()=>{u=!1,e.setChType(o,f,S.xg),console.debug(`${l}type: ${mt[f]||f}`),e.dispatchEvent("voice",{part:o})},()=>{t(e,R)[m.rpn*o+3]=f,t(e,L)[m.rpnt*o+2]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)})},!1,!1,()=>{t(e,b)[s+E[7]]=f},!1,!1,()=>{t(e,b)[s+E[10]]=f||128},!1,!1,()=>{t(e,b)[s+E[128]]=f,e.allocateAce(128)},()=>{t(e,b)[s+E[93]]=f},()=>{t(e,b)[s+E[91]]=f},()=>{t(e,b)[s+E[94]]=f},()=>{t(e,b)[s+E[76]]=f},()=>{t(e,b)[s+E[77]]=f},()=>{t(e,b)[s+E[78]]=f},()=>{t(e,b)[s+E[74]]=f},()=>{t(e,b)[s+E[71]]=f},()=>{t(e,b)[s+E[73]]=f},()=>{t(e,b)[s+E[75]]=f},()=>{t(e,b)[s+E[72]]=f}][i+$-1]||(()=>{}))():i<48?console.debug(d):i<111?i>102&&i<105&&(t(e,b)[s+E[[5,65][i&1]]]=f):i<114?console.debug(d):i<116?console.debug(`${l}EQ ${["bass","treble"][i&1]} gain: ${f-64}dB`):i<118?console.debug(d):i<120?console.debug(`${l}EQ ${["bass","treble"][i&1]} freq: ${f}`):console.debug(d)}),u&&t(e,D)[o]>1&&e.setDrumFirstWrite(o)}).add([76,9],(r,c)=>{let o=e.chRedir(r[0],c,!0),i=r[1],s=m.cc*o,l=`PLG-VL CH${o+1} `;r.subarray(2).forEach((d,u)=>{let f=u+i;switch(f){case 1:{console.info(`${l}breath mode: ${["system","breath","velocity","touch EG"][d]}`);break}case 0:case 27:case 28:break;default:if(f<27){let $=f-3>>1,w=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][$];f&1?f<23?(console.debug(`${l}${w} control source: ${sr(d)}`),d&&d<96&&e.allocateAce(130+$),t(e,Xe)[m.redir*o+$+2]=d,e.buildRccMap()):console.debug(`${l}${w} scale break point: ${d}`):(console.debug(`${l}${w} depth: ${d-64}`),t(e,b)[s+E[130+$]]=d)}}})}).add([76,10],(r,c,o)=>{}).add([76,16],(r,c,o)=>{}).add([76,17,0,0],(r,c,o)=>{}).add([76,112],(r,c,o)=>{switch(console.debug(`XG enable PLG-${["VL","SG","DX","AN","PF","DR","PC","AP"][r[0]]} for CH${r[2]+1}.`),r[0]){case 0:{t(e,ie)[m.ext*r[2]]=e.EXT_VL;break}case 2:{t(e,ie)[m.ext*r[2]]=e.EXT_DX;break}default:t(e,ie)[m.ext*r[2]]=e.EXT_NONE}}).add([73,0,0],(r,c)=>{let o=r[0],i="MU1000 System - ";r.subarray(1).forEach((s,l)=>{let d=o+l;d==8?console.debug(`${i}LCD contrast: ${s}.`):d==18?(t(e,q)[S.xg][1]=s?126:0,console.debug(`${i}default bank: ${s?"MU100 Native":"MU Basic"}.`),e.dispatchEvent("banklevel",{mode:"xg",data:+!!s}),e.forceVoiceRefresh()):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")},()=>{x(e,ye,!!s),console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][d-64]()})}).add([73,10,0],(r,c)=>{let o=r[0],i=`MU1000 RS${t(e,ye)?"":" (ignored)"}: `;if(o<16)switch(o){case 2:{let s=e.chRedir(0,c,!0);t(e,ye)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${i}Show CH1~64`);break}case 3:{let s=e.chRedir(r[1]<<5,c,!0);t(e,ye)&&e.dispatchEvent("channelmin",s),t(e,ye)&&e.dispatchEvent("channelmax",s+31),console.info(`${i}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${i}unknown switch ${o} invoked.`)}else if(o<32){if(t(e,ye)){let s=e.chRedir(o-16+(t(e,ht)<<4),c,!0);e.dispatchEvent("channelactive",s)}}else if(o<36){let s=e.chRedir(o-32<<4,c,!0);t(e,ye)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),x(e,ht,o-32)),console.info(`${i}Show CH${s+1}~CH${s+16}`)}}).add([73,11,0],(r,c)=>{let o="MU1000 System - channel ",i="Octavia System - channel ",s=r[0];r.subarray(1).forEach((l,d)=>{let u=s+d;([()=>{e.setChActive(l,1),e.dispatchEvent("channelactive",l),O()&&console.debug(`${o}current part: CH${l+1}`)},()=>{l<5?(e.dispatchEvent("portrange",1<{l<16?(e.dispatchEvent("portstart",l),console.debug(`${i}start port: ${"ABCDEFGHIJKLMNOP"[l]}`)):(e.dispatchEvent("portstart",255),console.debug(`${i}start port: reset`))}][u]||(()=>{console.debug(`${o}unknown address: ${u}`)}))()})}).add([93,3],(r,c)=>{let o=e.chRedir(r[0],c,!0),i=`PLG-100SG CH${o+1} `,s=Date.now();if(r[1]==0){let l="",d=0;r.subarray(2).forEach((u,f)=>{f%2==0?l+=ar[u]||u.toString().padStart("0"):d+=u*13}),s>=t(e,ft)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${ir(l)}`,amend:!0}),x(e,ft,s+Math.ceil(d/2)+t(e,dt)),O()&&console.debug(`${i}vocals: ${l}`)}else console.warn(`Unknown PLG-100SG data: ${r}`)}).add([98,0],(r,c,o)=>{e.dispatchEvent("mupromptex");let i=r[0],s=r.length-5,l=r.length-1;if(i!=s){console.info(`PLG-DX native dump size mismatch! Gave ${i} instead of ${r.length-5}.`);return}let d=De(r.subarray(4,l));if(d!=r[l]){console.info(`Bad PLG-DX checksum ${r[l]} - should be ${d}.`);return}r[0]=98,t(e,ce).run(r.subarray(0,l),c,o,{noAce:!0})}).add([98,96],(r,c,o,i)=>{let s=e.chRedir(r[0],c,!0),l=m.cc*s,d=r[1];r.subarray(2).forEach((u,f)=>{let $=d+f;if(!($<10)){if($==10)e.resetAce();else if($<27){let w=$+131;i!=null&&i.noAce||e.allocateAce(w),t(e,b)[l+E[w]]=u,e.dispatchEvent("cc",{part:s,cc:w,data:u})}}})}).add([100,0],(r,c,o)=>{let i=r.subarray(0,r.length-1);if(r[0]+5!=r.length){console.warn(`Yamaha DX7+ dump SysEx size mismatch! Expected ${r.length}, but got ${r[0]}: +`,r);return}let s=De(i),l=r[r.length-1];if(s!=l){console.warn(`Yamaha DX7+ dump SysEx checksum mismatch! Expected ${s}, but got ${l}: +`,r);return}a.run(i.subarray(1))}).add([100,76],(r,c,o)=>{let i=r[0]>>4,s=r[0]&15,l=r[1];switch(i){case 2:{let d=e.chRedir(s,c,!0),u=m.cc*d;r.subarray(2).forEach((f,$)=>{let w=$+l;if(!(w<7)){if(w<23){let C=w+135;e.allocateAce(C),t(e,b)[u+E[C]]=f,e.dispatchEvent("cc",{part:d,cc:C,data:f})}}});break}default:console.info("Unknown DX7+ multipart: %o",r)}}).add([1,20],(r,c,o)=>{o==115?(e.switchMode("doc",!0),e.setPortMode(e.getTrackPort(c),1,S.doc),console.info("MIDI reset: DOC")):console.debug(`Unknown Yamaha SysEx: 67, ${o}, ${r.join(", ")}`)}).add([1,17,15,89],(r,c,o)=>{o==115?(e.setEffectType(0,24,r[0]|16),e.dispatchEvent("efxreverb",e.getEffectType(0))):console.debug(`Unknown Yamaha SysEx: 67, ${o}, ${r.join(", ")}`)}).add([1,24],(r,c,o)=>{if(o==115){for(let i=0;i<16;i++){let s=e.chRedir(i,c,!0);t(e,b)[s*m.cc+E[91]]=127}console.info("DOC Global Reverb: on")}else console.debug(`Unknown Yamaha SysEx: 67, ${o}, ${r.join(", ")}`)}),a.add([14,31],(r,c,o)=>{t(e,b)[m.cc*r[0]+E[64]]=0,t(e,V).ano(r[0]),e.switchMode("xg"),e.setPortMode(e.getTrackPort(c),1,S.xg),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${r[0]+1}.`)}).add([76,112],async r=>{let c=r[0],o=m.cc*c,i=m.ext*c,s=m.cvn*c;t(e,ie)[i]=e.EXT_DX,t(e,Ee)[c]=1;let l=t(e,$t).subarray(s,s+m.cvn);l.fill(32),r.subarray(1).forEach((d,u)=>{if(u<10)l[u]=Math.max(d,32);else if(!(u<40)){if(u<56){let f=u+102;t(e,b)[o+E[f]]=d,e.dispatchEvent("cc",{part:c,cc:f,data:d})}}}),t(e,I)[c]=c&127,t(e,b)[m.cc*c+E[0]]=35,t(e,b)[m.cc*c+E[32]]=c>>7|4,e.dispatchEvent("voice",{part:c}),console.debug(`DX7+ CH${c+1} dump: %o`,r)});let n=function(r,c,o,i){},p=function(r,c){e.dispatchEvent("mupromptex");let o=r*m.dpn,i=c[0],s=c[1];c.subarray(2).forEach((l,d)=>{let u=d+s,f=-1;u<16?([()=>{f=24},()=>{f=25},()=>{f=26},()=>{},()=>{f=28},()=>{f=29},()=>{f=30},()=>{f=31},()=>{},()=>{},()=>{},()=>{f=20},()=>{f=21},()=>{f=22},()=>{f=23},()=>{}][u]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${r+1}.`)}))():u<32||(u<40?([()=>{f=48},()=>{f=49},!1,!1,()=>{f=52},()=>{f=53}][u-32]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${r+1}.`)}))():u<80||([()=>{f=36}][u-80]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${r+1}.`)}))()),f>=0?(O()&&console.debug(o,f,i,l),t(e,ee)[(o+le[f])*m.dnc+i]=l):O()&&console.debug(`XG-style drum param ${u} has no writes.`)})},y=function(r,c,o){e.dispatchEvent("mupromptex");let i=r*m.dpn,s=(c<<7)+o[0];o.subarray(1).forEach((l,d)=>{let u=d+s,f=u&127,$=u>>7,w=-1;$>1&&([()=>{w=26},()=>{},()=>{w=28},()=>{w=29},()=>{w=30},()=>{},()=>{},()=>{w=31}][$-2]||(()=>{console.debug(`Unknown GS-style drum param ${$} on set ${r+1}.`)}))(),w>-1?(O()&&console.debug(i,w,f,l),t(e,ee)[(i+le[w])*m.dnc+f]=l):O()&&console.debug(`GS-style drum param ${$} has no writes.`)})};t(this,ce).add([76,48],(r,c,o)=>{p(0,r)}).add([76,49],(r,c,o)=>{p(1,r)}).add([76,50],(r,c,o)=>{p(2,r)}).add([76,51],(r,c,o)=>{p(3,r)}).add([76,52],(r,c,o)=>{p(4,r)}).add([76,53],(r,c,o)=>{p(5,r)}).add([76,54],(r,c,o)=>{p(6,r)}).add([76,55],(r,c,o)=>{p(7,r)}),t(this,ce).add([89,0],(r,c,o)=>{if(e.eprom){let i=r[0],s=(r[1]<<14)+(r[2]<<7)+r[3]+(e.eprom.offset||0);O()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${i} bytes.`);let l=e.eprom.data;r.subarray(4).forEach((d,u)=>{let f=u>>3,$=u&7;if($==7)for(let w=0;w<7;w++)l[s+7*f+w]+=(d>>6-w&1)<<7;else l[s+7*f+$]=d})}}).add([89,1],(r,c,o)=>{let i=(r[0]<<21)+(r[1]<<14)+(r[2]<<7)+r[3];O()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(r,c,o)=>{if(e.eprom){let i=(r[0]<<21)+(r[1]<<14)+(r[2]<<7)+r[3]+(e.eprom.offset||0);O()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;r.subarray(4).forEach((l,d)=>{let u=d>>3,f=d&7;if(f==7)for(let $=0;$<7;$++)s[i+7*u+$]+=(l>>6-$&1)<<7;else s[i+7*u+f]=l})}}).add([89,3],(r,c,o)=>{}),t(this,ce).add([39,48],(r,c,o)=>{}).add([43,0,0],(r,c,o)=>{e.dispatchEvent("mupromptex");let i=[0,0,0,0],s=(l,d)=>{i[d]=l};if(r.subarray(1).forEach((l,d)=>{let u=d+r[0];[s,s,s,s,()=>{x(this,H,l*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},()=>l-64,()=>l||128,()=>l,()=>l,()=>{console.debug(`TG300 variation on cc${l}.`)}][u](l,u)}),r[0]<4){let l=0;i.forEach(d=>{l=l<<4,l+=d}),l-=1024}}).add([43,1,0],(r,c,o)=>{e.dispatchEvent("mupromptex")}).add([43,2],(r,c,o)=>{e.dispatchEvent("mupromptex");let i=e.chRedir(r[0],c,!0),s=r[1],l=m.cc*i,d=`TG300 CH${i+1} `;r.subarray(2).forEach((u,f)=>{f<5?([()=>{},()=>{t(e,b)[l+E[0]]=u,e.dispatchEvent("voice",{part:i})},()=>{t(e,b)[l+E[32]]=u,e.dispatchEvent("voice",{part:i})},()=>{t(e,I)[i]=u,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(u,c,!0);t(e,F)[i]=$,i!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))}][f+s]||(()=>{}))(u,f+s):f<21||(f<47?([()=>{t(e,ae)[i]=+!u},()=>{},()=>{},()=>{t(e,R)[m.rpn*i+3]=u,t(e,L)[m.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{},()=>{t(e,b)[l+E[7]]=u},!1,!1,()=>{t(e,b)[l+E[10]]=u||128},!1,!1,()=>{console.debug(`${d} AC1 at cc${u}`)},()=>{console.debug(`${d} AC2 at cc${u}`)},()=>{t(e,b)[l+E[128]]=u,e.allocateAce(128)},()=>{t(e,b)[l+E[93]]=u},()=>{t(e,b)[l+E[91]]=u},()=>{t(e,b)[l+E[94]]=u},()=>{t(e,b)[l+E[76]]=u},()=>{t(e,b)[l+E[77]]=u},()=>{t(e,b)[l+E[74]]=u},()=>{t(e,b)[l+E[71]]=u},()=>{t(e,b)[l+E[73]]=u},()=>{t(e,b)[l+E[75]]=u},()=>{t(e,b)[l+E[72]]=u},()=>{t(e,b)[l+E[78]]=u}][f+s-21]||(()=>{}))(u,f+s):f<95||([()=>{t(e,b)[l+E[65]]=u},()=>{t(e,b)[l+E[5]]=u}][f+s-95]||(()=>{}))(u,f+s))})}).add([43,7,0],(r,c,o)=>{let i=r[0];e.setLetterDisplay(r.subarray(1),"TG300 letter display",i)}).add([43,7,1],(r,c,o)=>{x(e,Y,0),x(e,ge,Date.now()+3200),t(e,oe,xe).fill(0),r.forEach(function(i,s){let l=Math.floor(s/16),d=s%16,u=(d*3+l)*7,f=7,$=0;for(u-=d*5,l==2&&(f=2);$>6-$&1,$++})}),t(this,he).add([66,18,0,0,127],(r,c,o)=>{e.switchMode("sc",!0),e.setPortMode(e.getTrackPort(c),2,S.sc),t(e,b)[m.cc*9]=120,t(e,b)[m.cc*25]=120,t(e,b)[m.cc*41]=120,t(e,b)[m.cc*57]=120,t(e,q)[S.sc][1]=t(e,B).sc,x(e,G,!1),t(e,Ce).fill(0),console.info(`GS system to ${["single","dual"][r[0]]} mode.`)}).add([66,18,64,0],(r,c,o)=>{switch(r[0]){case 127:{e.switchMode("gs",!0),e.setPortMode(e.getTrackPort(c),2,S.gs),t(e,q)[S.gs][1]=t(e,B).gs,t(e,b)[m.cc*9]=120,t(e,b)[m.cc*25]=120,t(e,b)[m.cc*41]=120,t(e,b)[m.cc*57]=120,x(e,G,!1),t(e,Ce).fill(0),console.info("MIDI reset: GS");break}default:{e.dispatchEvent("mupromptex");let i=[0,0,0,0],s=(l,d)=>{i[d]=l};if(r.subarray(1).forEach((l,d)=>{let u=d+r[0];[s,s,s,s,f=>{x(this,H,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},f=>{},f=>{}][u](l,d)}),r[0]<4){let l=0;i.forEach(d=>{l=l<<4,l+=d}),l-=1024}}}}).add([66,18,64,1],(r,c,o)=>{e.dispatchEvent("mupromptex");let i=r[0];if(i<16){let s="".padStart(i," ");r.subarray(1).forEach((l,d)=>{s+=String.fromCharCode(Math.max(32,l))}),s=s.padEnd(16," "),console.debug(`GS patch name: ${s}`)}else i<48||(i<65?r.subarray(1).forEach((s,l)=>{let d=`GS ${i+l>55?"chorus":"reverb"} `;([()=>{console.info(`${d}type: ${Bt[s]}`),e.setEffectType(0,40,s),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${d}predelay: ${s}ms`)},()=>{console.info(`${d}type: ${nr[s]}`),e.setEffectType(1,40,16+s),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${d}to reverb: ${re(s)}`)},()=>{console.debug(`${d}to delay: ${re(s)}`)}][i+l-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?r.subarray(1).forEach((s,l)=>{let d="GS delay ";([()=>{console.info(`${d}type: ${cr[s]}`),e.setEffectType(2,40,32+s),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${d}to reverb: ${re(s)}`)}][i+l-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],(r,c,o)=>{let i="GS EQ ";r.subarray(1).forEach((s,l)=>{([()=>{console.debug(`${i}low freq: ${[200,400][s]}Hz`)},()=>{console.debug(`${i}low gain: ${s-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][s]}Hz`)},()=>{console.debug(`${i}high gain: ${s-64}dB`)}][r[0]+l]||function(){console.warn(`Unknown GS EQ address: ${r[0]+l}`)})()})}).add([66,18,64,3],(r,c,o)=>{e.dispatchEvent("mupromptex");let i="GS EFX ",s=function(l,d){let u=or(t(e,se).subarray(10,12),d,l);u&&console.debug(`${i}${Nt(t(e,se).subarray(10,12))} ${u}`)};r.subarray(1).forEach((l,d)=>{([()=>{e.setEffectTypeRaw(3,!1,32+l),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,l),console.info(`${i}type: ${Nt(t(e,se).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,()=>{console.debug(`${i}to reverb: ${re(l)}dB`)},()=>{console.debug(`${i}to chorus: ${re(l)}dB`)},()=>{console.debug(`${i}to delay: ${re(l)}dB`)},!1,()=>{console.debug(`${i}1 source: ${l}`),l&&l<96&&e.allocateAce(l)},()=>{console.debug(`${i}1 depth: ${l-64}`)},()=>{console.debug(`${i}2 source: ${l}`),l&&l<96&&e.allocateAce(l)},()=>{console.debug(`${i}2 depth: ${l-64}`)},()=>{console.debug(`${i}to EQ: ${l?"ON":"OFF"}`)}][r[0]+d]||function(u,f){console.warn(`Unknown GS EFX address: ${f}`)})(l,r[0]+d)})}).add([66,18,65],(r,c,o)=>{y((r[0]>>4)+1<<1,r[0]&15,r.subarray(1))}).add([69,18,16],(r,c,o)=>{var i;switch(r[0]){case 0:{let s=r[1];e.setLetterDisplay(r.subarray(2),"GS display text",s);break}case 32:{x(e,ge,Date.now()+3200),r[1]==0&&(r[2]?(x(e,Y,Math.max(Math.min(r[2]-1,9),0)),O()&&console.debug(`GS switch display page ${r[2]-1}.`)):(x(e,Y,0),x(e,ge,Date.now()),O()&&console.debug("GS disable display page.")));break}default:if(r[0]<6){t(e,Y)>9&&x(e,Y,0);let s=r[0]-1<<1|r[1]>>6;t(e,Y)==s&&x(e,ge,Date.now()+3200),(i=t(e,Se)[s])!=null&&i.length||(t(e,Se)[s]=new Uint8Array(256));let l=t(e,Se)[s];O()&&console.debug(`GS frame draw page ${s}.`);let d=r[1]&63;l.fill(0),r.subarray(2).forEach(function(f,$){let w=$+d,C=Math.floor(w/16),M=w%16,_=(M*4+C)*5,Re=5,_e=0;for(_-=M*4,C==3&&(Re=1);_e>4-_e&1,_e++})}else console.warn(`Unknown GS display section: ${r[0]}`)}});let v=function(r,c,o){e.dispatchEvent("mupromptex");let i=r[0],s=m.cc*c,l=m.rpn*c,d=`GS CH${c+1} `;i<3?(r.subarray(1).forEach((u,f)=>{[()=>{t(e,b)[s+E[0]]=u},()=>{t(e,I)[c]=u},()=>{let $=0;u<16?$=e.chRedir(u,o,!0):$=m.ch,t(e,F)[c]=$,c!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))}][i+f]()}),e.dispatchEvent("voice",{part:c})):i<19||(i<44?r.subarray(1).forEach((u,f)=>{([()=>{t(e,ae)[c]=+!u},!1,()=>{e.setChType(c,u<<1,S.gs),console.debug(`${d}type: ${u?"drum ":"melodic"}${u||""}`)},()=>{t(e,R)[l+3]=u,t(e,L)[m.rpnt*c+2]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},!1,()=>{t(e,b)[s+E[7]]=u},!1,!1,()=>{t(e,b)[s+E[10]]=u||128},!1,!1,()=>{console.debug(`${d}CC 1: cc${u}`)},()=>{console.debug(`${d}CC 2: cc${u}`)},()=>{t(e,b)[s+E[93]]=u},()=>{t(e,b)[s+E[91]]=u},!1,!1,()=>{t(e,R)[l+1]=u,t(e,L)[m.rpnt*c+1]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},()=>{t(e,R)[l+2]=u,t(e,L)[m.rpnt*c+1]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},()=>{t(e,b)[s+E[94]]=u}][i+f-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},k=function(r,c){let o=r[0],i=`GS CH${c+1} `;o<2?r.subarray(1).forEach((s,l)=>{[()=>{t(e,b)[m.cc*c+E[32]]=s},()=>{}][o+l]()}):o<32?console.warn(`Unknown GS misc address: ${o}`):o<35?r.subarray(1).forEach((s,l)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][s]}`),t(e,ot)[c]=s,e.dispatchEvent("partefxtoggle",{part:c,active:s})}][o+l-32]()}):console.warn(`Unknown GS misc address: ${o}`)};t(this,he).add([66,18,64,16],(r,c)=>{v(r,e.chRedir(9,c,!0),c)}).add([66,18,64,17],(r,c)=>{v(r,e.chRedir(0,c,!0),c)}).add([66,18,64,18],(r,c)=>{v(r,e.chRedir(1,c,!0),c)}).add([66,18,64,19],(r,c)=>{v(r,e.chRedir(2,c,!0),c)}).add([66,18,64,20],(r,c)=>{v(r,e.chRedir(3,c,!0),c)}).add([66,18,64,21],(r,c)=>{v(r,e.chRedir(4,c,!0),c)}).add([66,18,64,22],(r,c)=>{v(r,e.chRedir(5,c,!0),c)}).add([66,18,64,23],(r,c)=>{v(r,e.chRedir(6,c,!0),c)}).add([66,18,64,24],(r,c)=>{v(r,e.chRedir(7,c,!0),c)}).add([66,18,64,25],(r,c)=>{v(r,e.chRedir(8,c,!0),c)}).add([66,18,64,26],(r,c)=>{v(r,e.chRedir(10,c,!0),c)}).add([66,18,64,27],(r,c)=>{v(r,e.chRedir(11,c,!0),c)}).add([66,18,64,28],(r,c)=>{v(r,e.chRedir(12,c,!0),c)}).add([66,18,64,29],(r,c)=>{v(r,e.chRedir(13,c,!0),c)}).add([66,18,64,30],(r,c)=>{v(r,e.chRedir(14,c,!0),c)}).add([66,18,64,31],(r,c)=>{v(r,e.chRedir(15,c,!0),c)}).add([66,18,64,64],(r,c)=>{k(r,e.chRedir(9,c,!0))}).add([66,18,64,65],(r,c)=>{k(r,e.chRedir(0,c,!0))}).add([66,18,64,66],(r,c)=>{k(r,e.chRedir(1,c,!0))}).add([66,18,64,67],(r,c)=>{k(r,e.chRedir(2,c,!0))}).add([66,18,64,68],(r,c)=>{k(r,e.chRedir(3,c,!0))}).add([66,18,64,69],(r,c)=>{k(r,e.chRedir(4,c,!0))}).add([66,18,64,70],(r,c)=>{k(r,e.chRedir(5,c,!0))}).add([66,18,64,71],(r,c)=>{k(r,e.chRedir(6,c,!0))}).add([66,18,64,72],(r,c)=>{k(r,e.chRedir(7,c,!0))}).add([66,18,64,73],(r,c)=>{k(r,e.chRedir(8,c,!0))}).add([66,18,64,74],(r,c)=>{k(r,e.chRedir(10,c,!0))}).add([66,18,64,75],(r,c)=>{k(r,e.chRedir(11,c,!0))}).add([66,18,64,76],(r,c)=>{k(r,e.chRedir(12,c,!0))}).add([66,18,64,77],(r,c)=>{k(r,e.chRedir(13,c,!0))}).add([66,18,64,78],(r,c)=>{k(r,e.chRedir(14,c,!0))}).add([66,18,64,79],(r,c)=>{k(r,e.chRedir(15,c,!0))}),t(this,ke).add([54,65],(r,c)=>{let o=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(o,!0),e.setPortMode(e.getTrackPort(c),1,S[o]);let i=r[r.length-1],s=r.subarray(0,r.length-1),l=De(s);l!=i&&(console.info(`X5D multi parameters checksum mismatch! Expected ${l}, got ${i}.`),console.debug(r));let d=(r[1]<<7)+r[0],u=(r[3]<<7)+r[2],f=e.chRedir(d&15,c,!0),$=m.cc*f;[()=>{u<1||(u<101?(e.setChType(f,e.CH_MELODIC,S.x5d),t(e,I)[f]=u-1,t(e,b)[$+E[0]]=t(e,B).x5):u<229?(e.setChType(f,e.CH_MELODIC,S.x5d),t(e,I)[f]=u-101,t(e,b)[$+E[0]]=56):(e.setChType(f,e.CH_DRUMS,S.x5d),t(e,I)[f]=mr[u-229]||0,t(e,b)[$+E[0]]=62)),e.dispatchEvent("voice",{part:f})},()=>{t(e,b)[$+E[7]]=u},()=>{u<31&&(t(e,b)[$+E[10]]=Math.round((u-15)*4.2+64))},()=>{t(e,b)[$+E[93]]=yt(u)},()=>{t(e,b)[$+E[91]]=yt(u)},()=>{t(e,R)[f*m.rpn+3]=u>8191?u-16320:64+u,t(e,L)[m.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{t(e,R)[f*m.rpn+1]=u>8191?u-16320:64+u,t(e,L)[m.rpnt*f+1]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{u>0&&(t(e,R)[f*m.rpn]=u,t(e,L)[m.rpnt*f]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)}))},()=>{}][d>>4]()}).add([54,76,0],(r,c)=>{e.dispatchEvent("mupromptex");let o=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(o),e.setPortMode(e.getTrackPort(c),1,S[o]);let i="",s=t(e,B).x5,l=0,d=0,u="MSB PRG LSB NME";pe(r,function(f,$){if($<16400){let w=$%164;switch(!0){case w<10:{f>31&&(i+=String.fromCharCode(f));break}case w==10:break;case w==11:{u+=` +${s} ${l} ${d} ${i.trim().replace("Init Voice","")}`,l++,i="";break}}l>99&&(s=90,l=0)}}),e.userBank.clearRange({msb:t(e,B).x5,prg:[0,99],lsb:0}),e.userBank.load(u),O()&&console.debug(u),e.forceVoiceRefresh()}).add([54,77,0],(r,c)=>{e.dispatchEvent("mupromptex");let o=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(o),e.setPortMode(e.getTrackPort(c),1,S[o]);let i="",s=90,l=0,d=0,u="MSB PRG LSB NME";pe(r,function(f,$){if($<13600){let w=$%136;switch(!0){case w<10:{f>31&&(i+=String.fromCharCode(f));break}case w==11:{u+=` +${s} ${l} ${d} ${i.trim().replace("Init Combi","")}`,l++,i="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(u),O()&&console.debug(u),e.forceVoiceRefresh()}).add([54,78],(r,c)=>{let o=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(o),e.setPortMode(e.getTrackPort(c),1,S[o]),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][r[0]]} mode.`)}).add([54,85],(r,c)=>{e.dispatchEvent("mupromptex");let o=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(o),e.setPortMode(e.getTrackPort(c),1,S[o]),pe(r,(i,s)=>{s>0&&s<3&&(e.setEffectType(s-1,44,i),e.dispatchEvent(`efx${["reverb","chorus"][s-1]}`,e.getEffectType(s-1)))})}).add([54,104],(r,c)=>{e.dispatchEvent("mupromptex");let o=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(o,!0);let i=e.getTrackPort(c);if(t(e,X)[i]&&t(e,X)[i]!=S[o])if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+i)} mode "${W[t(e,X)[i]]}" mismatch, should be "${o}".`);return}else console.info(`Track ${c} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+i)}.`);e.setPortMode(i,1,S[o]),pe(r,function(s,l,d,u){if(l<192){let f=e.chRedir(Math.floor(l/12),c,!0),$=f*m.cc;switch(l%12){case 0:{s<128?(e.setChType(f,e.CH_MELODIC,S.x5d),t(e,b)[$+E[0]]=t(e,B).x5,t(e,I)[f]=s):(e.setChType(f,e.CH_DRUMS,S.x5d),t(e,b)[$+E[0]]=62,t(e,I)[f]=mr[s-128]),s>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{t(e,b)[$+E[7]]=s;break}case 2:{t(e,R)[f*m.rpn+3]=s>127?s-192:64+s,t(e,L)[m.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)});break}case 3:{t(e,R)[f*m.rpn+1]=s>127?s-192:64+s,t(e,L)[m.rpnt*f+1]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)});break}case 4:{s<31&&(t(e,b)[$+E[10]]=Math.round((s-15)*4.2+64));break}case 5:{let w=s>>4,C=s&15;t(e,b)[$+E[91]]=yt(C),t(e,b)[$+E[93]]=yt(w);break}case 10:break;case 11:{let w=e.chRedir(s&15,c,!0),C=s>>4;t(e,F)[f]=s,(w!=f||C)&&(console.info(`X5D Part CH${f+1} receives from CH${w+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(l-192,c,!0)}})}),t(this,he).add([22,18,127],(r,c,o)=>{e.switchMode("mt32",!0),e.setPortMode(e.getTrackPort(c),1,S.mt32),x(e,G,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(r,c,o)=>{e.switchMode("mt32");let i=e.chRedir(o,c,!0),s=r[1];r.subarray(2).forEach((l,d)=>{let u=d+s;t(e,Ae)[u+(i-1)*16]=l,([!1,()=>{let f=t(e,Ae)[i-1<<4];if(f<3){if(t(e,Ee)[i]=1,f==2)for(let $=0;${t(e,R)[i*m.rpn+3]=l+40,t(e,L)[m.rpnt*i+2]=1},()=>{t(e,R)[i*m.rpn+1]=l+14,t(e,L)[m.rpnt*i+1]=1},()=>{t(e,R)[i*m.rpn]=l,t(e,L)[m.rpnt*i]=1},!1,()=>{t(e,b)[m.cc*i+E[91]]=l?127:0},!1,()=>{t(e,b)[m.cc*i+E[7]]=l},()=>{t(e,b)[m.cc*i+E[10]]=Math.ceil(l*9.05)}][u]||(()=>{}))()})}).add([22,18,1],(r,c,o)=>{e.switchMode("mt32");let i=o&7;console.debug(`MT-32 slot #${o+1} Drum: ${r}`);let s=r[0]<<7|r[1];r.subarray(2).forEach((l,d)=>{let u=d+s,f=(u>>2)+24,$=u&3,w=i*m.dpn;if(O()&&console.debug(`MT-32 temp drum note ${f} param ${$}: ${l}`),f<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${f}`);return}[()=>{},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=Math.round(l*1.27)},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=l*9+1&127},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=l?127:0}][$]()})}).add([22,18,2],(r,c,o)=>{e.switchMode("mt32");let i=e.chRedir(o,c,!0),s=r[1]+(r[0]<<7);s<10&&(t(e,Ee)[i]=1),r.subarray(2).forEach((l,d)=>{let u=d+s;u<14&&(t(e,me)[(i-1)*m.cmt+u]=l)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(r,c,o)=>{e.switchMode("mt32");let i=o&7;if(r[0]){let s=(r[0]-1<<7)+r[1]-16;r.subarray(2).forEach((l,d)=>{let u=d+s,f=(u>>2)+24,$=u&3,w=i*m.dpn;if(O()&&console.debug(`MT-32 dev drum note ${f} param ${$}: ${l}`),f<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${f}`);return}[()=>{},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=Math.round(l*1.27)},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=l*9+1&127},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=l?127:0}][$]()})}else{let s=r[1];r.subarray(2).forEach((l,d)=>{let u=d+s;t(e,Ae)[u]=l;let f=e.chRedir(1+(u>>4),c,!0),$=u&15;([!1,()=>{let w=t(e,Ae)[f-1<<4];if(w<3)if(t(e,Ee)[f]=1,w==2)for(let C=0;C{t(e,R)[f*m.rpn+3]=l+40,t(e,L)[m.rpnt*f+2]=1},()=>{t(e,R)[f*m.rpn+1]=l+14,t(e,L)[m.rpnt*f+1]=1},()=>{t(e,R)[f*m.rpn]=l,t(e,L)[m.rpnt*f]=1},!1,()=>{t(e,b)[m.cc*f+E[91]]=l?127:0},!1,()=>{t(e,b)[m.cc*f+E[7]]=l},()=>{t(e,b)[m.cc*f+E[10]]=Math.ceil(l*9.05)}][$]||(()=>{}))()})}}).add([22,18,4],(r,c,o)=>{e.switchMode("mt32");let i=r[1]+(r[0]<<7),s=[];r.subarray(2).forEach((l,d)=>{let u=d+i,f=e.chRedir(Math.floor(u/246+1),c,!0),$=u%246;$<14&&(t(e,me)[(f-1)*m.cmt+$]=l),$<10&&(t(e,Ee)[f]=1),s.indexOf(f)<0&&s.push(f)}),s.forEach(l=>{e.dispatchEvent("voice",{part:l})})}).add([22,18,5],(r,c,o)=>{e.switchMode("mt32");let i=(r[0]<<7)+r[1];r.subarray(2).forEach((s,l)=>{let d=i+l,u=Math.floor(d/8),f=d&7,$=u*8;t(e,lt)[d]=s,([!1,()=>{let w=t(e,lt)[$];if(w<3){let C="";if(w==2){let _=m.cmt*u;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:u});let M=`MSB LSB PRG NME +000 127 ${u} ${C}`;e.userBank.load(M,!0)}}][f]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(r,c,o)=>{e.switchMode("mt32");let i=((r[0]&1)<<7)+r[1],s=r[0]>>1,l=!1;if(r.subarray(2).forEach((d,u)=>{let f=i+u;f{e.switchMode("mt32");let i=r[1],s=!1,l=function(d,u){t(e,F)[u-12]=d,s=!0};r.subarray(2).forEach((d,u)=>{let f=u+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,l,l,l,l,l,l,l,l,l,()=>{x(e,H,d),e.dispatchEvent("mastervolume",t(e,H))}][f]||(()=>{}))(d,u)}),s&&e.buildRchTree()}).add([22,18,32],(r,c,o)=>{e.switchMode("mt32");let i=r[1],s=" ".repeat(i);r.subarray(2).forEach(l=>{l>31?s+=String.fromCharCode(l):s+=" "}),x(e,Le,s.padStart(20," ")),x(e,Ue,Date.now()+3200)}).add([22,18,82],(r,c)=>{let o=e.chRedir(0,c,!0);for(let i=0;i<16;i++)t(e,V).ano(o+i),i&&i<10&&(t(e,I)[o+i]=Ht[i-1]);console.info("MT-32 alt reset complete.")}),t(this,ke).add([66,0],(r,c)=>{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(c),2,S.ns5r),x(e,G,!1),console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][r[0]]} mode.`)}).add([66,1],(r,c)=>{let o=["ns5r","05rw"][r[0]];e.switchMode(o,!0),e.setPortMode(e.getTrackPort(c),2,S[o]),x(e,G,!1)}).add([66,18,0,0],(r,c)=>{let o=r[0];switch(o){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(c),2,S.ns5r),x(e,G,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${r}`);break}default:if(o<10){let i=[0,0,0,0],s=(l,d)=>{i[d]=l};if(r.subarray(1).forEach((l,d)=>{[s,s,s,s,()=>{x(e,H,l*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},()=>l-64,()=>l-64,()=>{},()=>{},()=>{}][o+d]()}),r[0]<4){let l=0;i.forEach(d=>{l=l<<4,l+=d}),l-=1024}}}}).add([66,18,0,1],(r,c)=>{}).add([66,18,0,2],(r,c)=>{}).add([66,18,1],(r,c)=>{e.dispatchEvent("mupromptex");let o=e.chRedir(r[0],c,!0),i=o*m.cc,s=r[1],l=`NS5R CH${o+1} `;r.subarray(2).forEach((d,u)=>{let f=s+u;f<3?([()=>{t(e,b)[i+E[0]]=d||nt.bank0},()=>{t(e,b)[i+E[32]]=d},()=>{t(e,I)[o]=d}][f](),e.dispatchEvent("voice",{part:o})):f<8||(f<14?[()=>{let $=e.chRedir(d,c,!0);t(e,F)[o]=$,o!=$&&(e.buildRchTree(),console.info(`${l}receives from CH${$+1}`))},()=>{t(e,ae)[o]=+!d},()=>{e.setChType(o,d,S.ns5r),console.debug(`${l}type: ${mt[d]}`)},()=>{t(e,R)[m.rpn*o+3]=d,t(e,L)[m.rpnt*o+2]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)})},()=>{},()=>{}][f-8]():f<16||(f<33?[()=>{t(e,b)[i+E[7]]=d},()=>{t(e,b)[i+E[11]]=d},()=>{},()=>{},()=>{t(e,b)[i+E[10]]=d||128},()=>{},()=>{},()=>{t(e,b)[i+E[93]]=d},()=>{t(e,b)[i+E[91]]=d},()=>{t(e,b)[i+E[76]]=d},()=>{t(e,b)[i+E[77]]=d},()=>{t(e,b)[i+E[78]]=d},()=>{t(e,b)[i+E[74]]=d},()=>{t(e,b)[i+E[71]]=d},()=>{t(e,b)[i+E[73]]=d},()=>{t(e,b)[i+E[75]]=d},()=>{t(e,b)[i+E[72]]=d}][f-16]():f<112||f<114&&[()=>{t(e,b)[i+E[5]]=d},()=>{t(e,b)[i+E[65]]=d}][f-112]()))})}).add([66,18,8,0],(r,c)=>{let o=r[0];if(o<32)e.setLetterDisplay(r.subarray(1,33),"NS5R letter display");else{let i=o-32;x(e,ge,Date.now()+3200),x(e,Y,10),t(e,oe,xe).fill(0);let s=r.subarray(1),l=4;s.forEach(function(d,u){let f=u+i,$=f>>4,w=f&15;if(f<80){let C=$>3,M=0,_=$0;)t(e,oe,xe)[w*32+$*7+(_-M)]=C&1,C=C>>1,M++}})}}).add([66,18,48],(r,c,o)=>{p(0,r)}).add([66,18,49],(r,c,o)=>{p(1,r)}).add([66,18,50],(r,c,o)=>{p(2,r)}).add([66,18,51],(r,c,o)=>{p(3,r)}).add([66,18,52],(r,c,o)=>{p(4,r)}).add([66,18,53],(r,c,o)=>{p(5,r)}).add([66,18,54],(r,c,o)=>{p(6,r)}).add([66,18,55],(r,c,o)=>{p(7,r)}).add([66,52],(r,c)=>{e.switchMode("ns5r"),x(e,G,!1);let o="";pe(r,(i,s)=>{s<8?(i>31&&(o+=String.fromCharCode(i)),s==7&&(e.aiEfxName=o)):s<10&&(e.setEffectType(s-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(r,c)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r"),x(e,G,!1);let o="",i=r[r.length-1],s=r.subarray(0,r.length-1),l=De(s);l!=i&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${l}, got ${i}.`),console.debug(r));let d=e.getTrackPort(c);if(t(e,X)[d]&&t(e,X)[d]!=S.ns5r)if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+d)} mode "${W[t(e,X)[d]]}" mismatch, should be "ns5r".`);return}else console.info(`Track ${c} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+d)}.`);e.setPortMode(d,2,S.ns5r),pe(s,function(u,f){switch(!0){case f<2944:{let $=e.chRedir(Math.floor(f/92),c,!0),w=$*m.cc;switch(f%92){case 0:{t(e,b)[w+E[0]]=u,e.dispatchEvent("voice",{part:$});break}case 1:{t(e,b)[w+E[32]]=u,!u&&!t(e,b)[w+E[0]]&&(t(e,b)[w+E[0]]=nt.bank0),e.dispatchEvent("voice",{part:$});break}case 2:{t(e,I)[$]=u,u>0&&e.setChActive($,1),e.dispatchEvent("voice",{part:$});break}case 3:{let C=e.chRedir(u,c,!0);t(e,F)[$]=C,$!=C&&(console.info(`NS5R CH${$+1} receives from CH${C+1}.`),e.buildRchTree());break}case 7:{t(e,D)[$]=u,e.dispatchEvent("voice",{part:$});break}case 8:{t(e,R)[$*m.rpn+3]=u<40||u>88?u+(u>63?-192:64):u,t(e,L)[m.rpnt*$+2]=1,e.dispatchEvent("pitch",{part:$,pitch:e.getPitchShift($)});break}case 9:case 10:{t(e,b)[w+E[7]]=u;break}case 11:{t(e,b)[w+E[11]]=u;break}case 14:{t(e,b)[w+E[10]]=u||128;break}case 19:{t(e,b)[w+E[93]]=u;break}case 20:{t(e,b)[w+E[91]]=u;break}case 84:{t(e,b)[w+E[65]]=u;break}case 85:{t(e,b)[w+E[5]]=u;break}}break}case f<3096:break;case f<3134:{let $=f-3096;$<8?(u>31&&(o+=String.fromCharCode(u)),$==7&&(e.aiEfxName=o)):$<10&&(e.setEffectType($-8,44,u),e.dispatchEvent(`efx${["reverb","chorus"][$-8]}`,e.getEffectType($-8)));break}case f<8566:break}})}).add([66,54],(r,c)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let o="",i=80,s=0,l=0,d="MSB PRG LSB NME";pe(r,function(u,f){let $=f%158;switch(!0){case $<10:{u>31&&(o+=String.fromCharCode(u));break}case $==10:break;case $==11:{i=u&127;break}case $==12:{l=u&127;break}case $==13:{d+=` +${i} ${s} ${l} ${o.trim().replace("Init Voice","")}`,s++,o="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(d),O()&&console.debug(d),e.forceVoiceRefresh()}).add([66,55],(r,c)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let o="",i=88,s=0,l=0,d="MSB PRG LSB NME";pe(r,function(u,f){let $=f%126;switch(!0){case $<10:{u>31&&(o+=String.fromCharCode(u));break}case $==11:break;case $==12:break;case $==13:{d+=` +${i} ${s} ${l} ${o.trim().replace("Init Combi","")}`,s++,o="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(d),O()&&console.debug(d),e.forceVoiceRefresh()}).add([66,125],(r,c,o)=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][r[0]]||"white")}).add([66,127],(r,c,o)=>{let i=r[r.length-1],s=r.subarray(0,r.length-1),l=De(s);l!=i&&(console.info(`NS5R screen dump checksum mismatch! Expected ${l}, got ${i}.`),console.debug(r));let d=new Uint8Array(5760);pe(r,(u,f,$)=>{if(f<720)for(let w=0;w<8;w++)d[f*8+w]=u>>7-w&1}),e.dispatchEvent("screen",{type:"ns5r",data:d})}).add([76],(r,c,o)=>{t(e,ke).run([66,...r],c,o)}),t(this,We).add([16,0,8,0],(r,c,o)=>{let i=(r[2]<<4)+r[3],s="K11 ";([()=>{e.switchMode("k11",!0),e.setPortMode(e.getTrackPort(c),2,S.k11),x(e,G,!1),t(e,q)[S.k11][1]=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}`)}][r[0]]||(()=>{}))()}).add([16,0,8,1],(r,c,o)=>{e.dispatchEvent("mupromptex");let i=e.chRedir(r[1],c,!0),s=m.cc*i,l=m.rpn*i,d=(r[3]<<4)+r[4],u=`K11 CH${i+1} `;([()=>{d<128?(e.setChType(i,e.CH_MELODIC,S.k11),t(e,b)[s+E[0]]=0,t(e,I)[i]=d):(e.setChType(i,e.CH_DRUMS,S.k11),t(e,I)[i]=d-128),e.dispatchEvent("voice",{part:i})},()=>{let f=e.chRedir(d,c,!0);t(e,F)[i]=f,i!=f&&(e.buildRchTree(),console.info(`${u}receives from CH${f+1}`))},()=>{t(e,b)[s+E[7]]=d},()=>{uupThis.setChActive(i,d)},()=>{t(e,b)[s+E[10]]=d},()=>{t(e,R)[l+3]=d+40,t(e,L)[m.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,R)[l+1]=d>>1,t(e,R)[l+2]=d&1,t(e,L)[m.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,b)[s+E[91]]=d?127:0},()=>{},()=>{t(e,b)[s+E[74]]=d},()=>{t(e,b)[s+E[73]]=d},()=>{t(e,b)[s+E[72]]=d}][r[0]]||(()=>{}))()}).add([16,0,9,0],(r,c,o)=>{e.dispatchEvent("mupromptex");let i=(r[2]<<4)+r[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}`)}][r[0]]||(()=>{}))()}).add([16,0,9,3],(r,c,o)=>{e.dispatchEvent("mupromptex");let i=(r[2]<<4)+r[3],s=e.chRedir(r[1],c,!0),l=s*m.cc;[()=>{i<128?(e.setChType(s,e.CH_MELODIC,S.k11),t(e,b)[l+E[0]]=0,t(e,b)[l+E[32]]=0,t(e,I)[s]=i):i<160?(e.setChType(s,e.CH_MELODIC,S.k11),t(e,b)[l+E[0]]=0,t(e,b)[l+E[32]]=7,t(e,I)[s]=i-100):(e.setChType(s,e.CH_DRUMS,S.k11),t(e,b)[l+E[0]]=122,t(e,b)[l+E[32]]=0,t(e,I)[s]=i-160),e.dispatchEvent("voice",{part:s})},()=>{let d=e.chRedir(i,c,!0);t(e,F)[s]=d,s!=d&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${d+1}`))}][r[0]]()}).add([16,0,9,4],(r,c,o)=>{e.dispatchEvent("mupromptex");let i=(r[2]<<4)+r[3],s=e.chRedir(r[1],c,!0),l=s*m.cc,d=s*m.rpn,u=`GMLX CH${s+1} `;[()=>{e.setChActive(s,i)},()=>{t(e,b)[l+E[7]]=i},()=>{t(e,b)[l+E[10]]=i},()=>{t(e,b)[l+E[91]]=i?127:0},()=>{t(e,R)[d+3]=i+40,t(e,L)[m.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{t(e,R)[d+1]=i,t(e,L)[m.rpnt*s+1]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{t(e,R)[d]=i,t(e,L)[m.rpnt*s]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{}][r[0]]()}),t(this,Qe).add([66,93,64],(r,c,o)=>{let i=r[2];switch(r[0]){case 0:{switch(r[1]){case 4:{e.dispatchEvent("mupromptex"),x(e,H,i*129/16383*100),e.dispatchEvent("mastervolume",t(e,H));break}case 5:{e.dispatchEvent("mupromptex"),i-64;break}case 6:{e.dispatchEvent("mupromptex"),console.debug(`SG global reverb: ${i?"on":"off"}`);break}case 127:{e.switchMode("sg",!0),e.setPortMode(e.getTrackPort(c),1,S.sg);break}}break}case 1:{switch(r[1]){case 48:{e.dispatchEvent("mupromptex"),console.debug(`SG reverb type: ${Bt[i]}`);break}}break}default:if(r[0]>>4==1){e.dispatchEvent("mupromptex");let s=e.chRedir(r[0]&15,c,!0);if(r[1]==2){let l=e.chRedir(i,c,!0);t(e,F)[s]=l,s!=l&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${l+1}`))}else r[1]==19&&(t(e,b)[m.cc*s+E[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${r}`)}}),t(this,Ye).add([9],(r,c,o)=>{e.dispatchEvent("mupromptex"),console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremolo","phaser","rotary speaker","enhancer","flanger","EQ"][r[0]]||"off"}`)}),t(this,ce).add([127,0],(r,c,o)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...r]);t(e,ce).run(i,c,o)}).add([127,1,0,0],(r,c,o)=>{e.switchMode("s90es");let i="S90/Motif ES system ",s=r[0];r.subarray(1).forEach((l,d)=>{([()=>{x(e,H,l*12900/16383),e.dispatchEvent("mastervolume",t(e,H))}][s+d]||(()=>{console.info(`Unrecognized ${i}ID: ${s+d}`)}))()})}).add([127,1,0,36,54,1],(r,c,o)=>{e.switchMode("s90es");let i="S90/Motif ES reverb ",s=r[0];r.subarray(1).forEach((l,d)=>{([()=>{e.setEffectTypeRaw(0,!1,l&15|112)},()=>{e.setEffectTypeRaw(0,!0,l)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxreverb",e.getEffectType(0))}).add([127,1,0,37,54,2],(r,c,o)=>{e.switchMode("s90es");let i="S90/Motif ES chorus ",s=r[0];r.subarray(1).forEach((l,d)=>{([()=>{e.setEffectTypeRaw(1,!1,l&15|112)},()=>{e.setEffectTypeRaw(1,!0,l)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxchorus",e.getEffectType(1))}).add([127,1,0,34,54,3],(r,c,o)=>{e.switchMode("s90es");let i="S90/Motif ES insert 1 ",s=r[0];r.subarray(1).forEach((l,d)=>{([()=>{e.setEffectTypeRaw(3,!1,l&15|112)},()=>{e.setEffectTypeRaw(3,!0,l)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxinsert0",e.getEffectType(3))}).add([127,1,0,34,54,4],(r,c,o)=>{e.switchMode("s90es");let i="S90/Motif ES insert 2 ",s=r[0];r.subarray(1).forEach((l,d)=>{([()=>{e.setEffectTypeRaw(4,!1,l&15|112)},()=>{e.setEffectTypeRaw(4,!0,l)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxinsert1",e.getEffectType(4))}).add([127,1,0,35,54,17],(r,c,o)=>{e.switchMode("s90es");let i="S90/Motif ES variation ",s=r[0];r.subarray(1).forEach((l,d)=>{([()=>{e.setEffectTypeRaw(2,!1,l&15|112)},()=>{e.setEffectTypeRaw(2,!0,l)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxdelay",e.getEffectType(2))}).add([127,1,0,58,55],(r,c,o)=>{e.dispatchEvent("mupromptex"),e.switchMode("s90es");let i=e.getTrackPort(c);if(t(e,X)[i]&&t(e,X)[i]!=t(e,B).smotif)if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+i)} mode "${W[t(e,X)[i]]}" mismatch, should be "${W[t(e,B).smotif]}".`);return}else console.info(`Track ${c} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+i)}.`);let s=e.chRedir(r[0],c,!0),l=m.cc*s,d=r[1];r[0]>15&&(s=r[0]+32);let u=`Track ${c} S90/Motif ES bulk CH${s<128?s+1:"U"+(s-127)} `;console.debug(u,r),!(r[0]>15)&&r.subarray(2).forEach((f,$)=>{([()=>{t(e,b)[l+E[0]]=f,e.dispatchEvent("voice",{part:s})},()=>{f&&e.setChActive(s,1),t(e,b)[l+E[32]]=f,e.setChType(s,[32,40].indexOf(f)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,A),!0),e.dispatchEvent("voice",{part:s})},()=>{f&&e.setChActive(s,1),t(e,I)[s]=f,e.dispatchEvent("voice",{part:s})},()=>{let w=e.chRedir(f,c,!0);t(e,F)[s]=w,s!=w&&(e.buildRchTree(),console.info(`${u}receives from CH${w+1}`))},()=>{t(e,ae)[s]=f?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{f!=100&&e.setChActive(s,1),t(e,b)[l+E[7]]=f},()=>{f!=64&&e.setChActive(s,1),t(e,b)[l+E[10]]=f},!1,!1,!1,()=>{t(e,b)[l+E[91]]=f},()=>{f&&e.setChActive(s,1),t(e,b)[l+E[93]]=f},()=>{f&&e.setChActive(s,1),t(e,b)[l+E[94]]=f},()=>{f!=127&&e.setChActive(s,1),t(e,b)[l+E[128]]=f,e.allocateAce(128)},()=>{},()=>{f!=64&&e.setChActive(s,1),t(e,b)[l+E[74]]=f},()=>{f!=64&&e.setChActive(s,1),t(e,b)[l+E[71]]=f},!1,()=>{t(e,b)[l+E[65]]=f},()=>{t(e,b)[l+E[5]]=f},()=>{}][d+$]||(()=>{}))()})}).add([127,1,54,16],(r,c,o)=>{e.switchMode("s90es");let i=r[0];r.subarray(1).forEach((s,l)=>{let u=`S90/Motif ES EQ${(l>>2)+1} `;([()=>{let f=s-64},()=>{let f=st[s]},()=>{let f=s/10},()=>{let f=s}][i+l&3]||(()=>{}))()})}),t(this,he).add([0,72,18,0,0,0,0],(r,c,o)=>{e.switchMode("sd",!0),e.setPortMode(e.getTrackPort(c),2,S.sd),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(r,c,o)=>{e.dispatchEvent("mupromptex");let i=r[0]>>5,s=r[0]&31;switch(i){case 0:{let l=r[0]>>1,d=r[1];switch(l){case 1:{r.subarray(2).forEach((u,f,$)=>{let w=f+d;switch(w){case 0:{u&&(e.setEffectType(1,60,u-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${w} - ${u}`));break}}});break}case 2:{r.subarray(2).forEach((u,f)=>{let $=f+d;switch($){case 0:{u&&(e.setEffectType(0,55+u,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${$} - ${u}`));break}}});break}case 3:case 4:case 5:{let u=l-1;r.subarray(2).forEach((f,$)=>{let w=$+d;switch(console.debug(`SD MFX ${u-2}: ${w} - ${f}`),w){case 0:{e.setEffectTypeRaw(u,62,f),e.dispatchEvent(`efx${u>2?"delay":"insert"+(u-4)}`,e.getEffectType(u));break}}}),console.debug(`SD MFX message: %o`,r);break}default:console.debug(`Unknown SD-90 global effects message: -%o`,r)}break}case 1:{let c=e.chRedir(s,o,!0),d=r[1],u=c*m.cc;r.subarray(2).forEach((f,$)=>{let w=d+$;w<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,b)[u+E[0]]=f,f){case 104:case 105:case 106:case 107:case 120:{t(e,D)[c]||e.setChType(c,e.CH_DRUMS);break}default:t(e,D)[c]&&e.setChType(c,e.CH_MELODIC)}e.dispatchEvent("voice",{part:c})},()=>{t(e,b)[u+E[32]]=f,e.dispatchEvent("voice",{part:c})},()=>{t(e,I)[c]=f,e.dispatchEvent("voice",{part:c})},()=>{t(e,b)[u+E[7]]=f},()=>{t(e,b)[u+E[10]]=f},()=>{},()=>{},()=>{f<2&&(t(e,ae)[c]=f)},()=>{f<2&&(t(e,b)[u+E[68]]=f?127:0)},()=>{},()=>{f<2&&(t(e,b)[u+E[65]]=f?127:0)},()=>{t(e,b)[u+E[5]]=f&15<<4|t(e,b)[u+E[5]]&15},()=>{t(e,b)[u+E[5]]=f&15|(t(e,b)[u+E[5]]&240)>>4},()=>{t(e,b)[u+E[74]]=f},()=>{t(e,b)[u+E[71]]=f},()=>{t(e,b)[u+E[73]]=f},()=>{t(e,b)[u+E[72]]=f},0,0,0,0,0,0,0,()=>{t(e,b)[u+E[128]]=f,e.allocateAce(128)},()=>{t(e,b)[u+E[93]]=f},()=>{t(e,b)[u+E[91]]=f},0,0,()=>{t(e,b)[u+E[75]]=f},()=>{t(e,b)[u+E[76]]=f},()=>{t(e,b)[u+E[77]]=f},()=>{t(e,b)[u+E[78]]=f}][w]||(()=>{}))():w<63||(w<64?(t(e,D)[c]?t(e,b)[u+E[0]]=104|f:t(e,b)[u+E[0]]=96|f,e.dispatchEvent("voice",{part:c})):console.debug(`Unknown SD-90 global CH${c+1} param setup message: -%o`,r))});break}case 2:{let c=e.chRedir(s,o,!0),d=r[1];console.debug(`Unknown SD-90 global CH${c+1} MIDI setup message: +%o`,r)}break}case 1:{let l=e.chRedir(s,c,!0),d=r[1],u=l*m.cc;r.subarray(2).forEach((f,$)=>{let w=d+$;w<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,b)[u+E[0]]=f,f){case 104:case 105:case 106:case 107:case 120:{t(e,D)[l]||e.setChType(l,e.CH_DRUMS);break}default:t(e,D)[l]&&e.setChType(l,e.CH_MELODIC)}e.dispatchEvent("voice",{part:l})},()=>{t(e,b)[u+E[32]]=f,e.dispatchEvent("voice",{part:l})},()=>{t(e,I)[l]=f,e.dispatchEvent("voice",{part:l})},()=>{t(e,b)[u+E[7]]=f},()=>{t(e,b)[u+E[10]]=f},()=>{},()=>{},()=>{f<2&&(t(e,ae)[l]=f)},()=>{f<2&&(t(e,b)[u+E[68]]=f?127:0)},()=>{},()=>{f<2&&(t(e,b)[u+E[65]]=f?127:0)},()=>{t(e,b)[u+E[5]]=f&15<<4|t(e,b)[u+E[5]]&15},()=>{t(e,b)[u+E[5]]=f&15|(t(e,b)[u+E[5]]&240)>>4},()=>{t(e,b)[u+E[74]]=f},()=>{t(e,b)[u+E[71]]=f},()=>{t(e,b)[u+E[73]]=f},()=>{t(e,b)[u+E[72]]=f},0,0,0,0,0,0,0,()=>{t(e,b)[u+E[128]]=f,e.allocateAce(128)},()=>{t(e,b)[u+E[93]]=f},()=>{t(e,b)[u+E[91]]=f},0,0,()=>{t(e,b)[u+E[75]]=f},()=>{t(e,b)[u+E[76]]=f},()=>{t(e,b)[u+E[77]]=f},()=>{t(e,b)[u+E[78]]=f}][w]||(()=>{}))():w<63||(w<64?(t(e,D)[l]?t(e,b)[u+E[0]]=104|f:t(e,b)[u+E[0]]=96|f,e.dispatchEvent("voice",{part:l})):console.debug(`Unknown SD-90 global CH${l+1} param setup message: +%o`,r))});break}case 2:{let l=e.chRedir(s,c,!0),d=r[1];console.debug(`Unknown SD-90 global CH${l+1} MIDI setup message: %o`,r.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,r)}}),t(e,ke).add([0,1,73,78],(r,o,l)=>{e.switchMode("krs"),e.setPortMode(e.getTrackPort(o),1,S.krs),console.debug("Might be KORG KROSS 2 mode reset... Not sure.")}).add([0,1,73,117,2,37],(r,o,l)=>{e.switchMode("krs");let i=e.getTrackPort(o);if(t(e,X)[i]&&t(e,X)[i]!=S.krs)if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+i)} mode "${W[t(e,X)[i]]}" mismatch, should be "krs".`);return}else console.info(`Track ${o} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+i)}.`);e.setPortMode(e.getTrackPort(o),1,S.krs);let s="KROSS 2 BMT1 ",c="";pe(r,(d,u)=>{if(u<24)c+=String.fromCharCode(Math.max(32,d));else if(!(u<1276)){let f=u-1276,$=e.chRedir(Math.floor(f/44),o,!0),w=f%44,C=m.cc*$;w<15?([()=>{d&&e.setChActive($,1),t(e,I)[$]=d,e.dispatchEvent("voice",{part:$})},()=>{d&&e.setChActive($,1),d<10?(t(e,b)[C+E[0]]=63,t(e,b)[C+E[32]]=d):d<20?(t(e,b)[C+E[0]]=121,t(e,b)[C+E[32]]=d-10):d<24&&(t(e,b)[C+E[0]]=[120,0,56,62][d-20],t(e,b)[C+E[32]]=0),e.dispatchEvent("voice",{part:$})},()=>{let M=e.chRedir(d&15,o,!0);t(e,F)[$]=M,console.info(`${s}CH${$+1} receives from CH${M+1}`),d>>5&1||(e.setChActive($,0),console.debug(`KORG KROSS 2 CH${$+1} is disabled.`))},!1,!1,()=>{t(e,b)[C+E[7]]=d},!1,()=>{},()=>{},!1,!1,!1,!1,!1,()=>{t(e,b)[C+E[10]]=d||128}][w]||(()=>{}))():w<36||([()=>{t(e,b)[C+E[74]]=(d+128&255)-64},()=>{t(e,b)[C+E[71]]=(d+128&255)-64},!1,!1,()=>{t(e,b)[C+E[73]]=(d+128&255)-64},()=>{t(e,b)[C+E[75]]=(d+128&255)-64},!1,()=>{t(e,b)[C+E[72]]=(d+128&255)-64}][w]||(()=>{}))()}}),c=c.trimRight(),e.dispatchEvent("metacommit",{type:"EORTitle",data:c})})}chRedir(e,a,h){let n=this;if(t(n,Be)[a])return(t(n,Be)[a]-1)*16+e;if(t(n,A)==S.sc){if(h==1)return e;let p=0,y=!0;for(;y;)t(n,Ce)[e+p]==0?(t(n,Ce)[e+p]=a,console.debug(`Assign track ${a} to channel ${e+p+1}.`),y=!1):t(this,Ce)[e+p]==a?y=!1:(p+=16,p>=128&&(p=0,y=!1));return e+p}else return e}getTrackPort(e){return this.chRedir(0,e,!0)>>4}forceVoiceRefresh(){for(let e=0;e{var n;a{a&&(t(e,Fe)[Math.floor(h/m.redir)][a]=h%m.redir|128)}),O()&&console.debug(t(e,Fe))}getActive(){return t(this,de)}getCc(e){let a=this,h=e*m.cc,n=t(a,b).subarray(h,h+m.cc);return n[E[0]]=n[E[0]]||t(a,q)[a.getChModeId(e)][0],n[E[32]]=n[E[32]]||t(a,q)[a.getChModeId(e)][1],n[E[0]]==nt.bank0&&(n[E[0]]=0),n}getCcCh(e,a){let h=this;if(vt.indexOf(a)<0)throw new Error("CC number not accepted");let n=t(h,b)[m.cc*e+E[a]];switch(a){case 0:{n=n||t(h,q)[h.getChModeId(e)][0],n==nt.bank0&&(n=0);break}case 32:{n=n||t(h,q)[h.getChModeId(e)][1];break}}return n}getCcAll(){let e=this,a=t(e,b).slice();for(let h=0;h0&&!n&&(t(this,b)[e*m.cc+E[0]]=_t[h])}setChActive(e,a=0){t(this,de)[e]!=a&&this.dispatchEvent("channeltoggle",{part:e,active:a}),t(this,de)[e]=a}getExt(e){let a=m.ext*e,h=t(this,ie).subarray(a,a+m.ext),n=new Uint8Array(h.length);return n.set(h),n[1]=n[1]||t(this,Pt),n}getPitch(){return t(this,Te)}getProgram(){return t(this,I)}getTexts(){return t(this,ne).slice()}getVel(e){let a=new Map,h=this;return t(h,z).forEach(function(n,p){let y=Math.floor(n/128),v=n%128;e==y&&t(h,K)[n]>0&&a.set(v,{v:t(h,K)[n],s:t(h,Q)[p]})}),a}getBitmap(){return{bitmap:t(this,oe,xe),expire:t(this,ge)}}getLetter(){return{text:t(this,Le),set:t(this,kt),expire:t(this,Ue)}}getMode(){return W[t(this,A)]}getMaster(){return{volume:t(this,H)}}getRawStrength(){let e=this;return t(this,z).forEach(function(a){let h=Math.floor(a/128);t(e,K)[a]>t(e,$e)[h]&&(t(e,$e)[h]=t(e,K)[a])}),t(this,$e)}getStrength(){let e=[],a=this;return this.getRawStrength().forEach(function(h,n){e[n]=Math.floor(h*t(a,b)[n*m.cc+E[7]]*t(a,b)[n*m.cc+E[11]]*t(a,H)/803288)}),e}getRpn(){return t(this,R)}getNrpn(){return t(this,ct)}getVoice(e,a,h,n){let p=this,y=e||t(p,q)[t(p,A)][0],v=a,k=h||t(p,q)[t(p,A)][1];y==nt.bank0&&(y=0),W[t(p,A)]=="ns5r"&&y>0&&y<56&&(k=3);let r=p.userBank.get(y,v,k,n);if(W[t(p,A)]=="mt32"&&r.name.indexOf("MT-m:")==0){let o=parseInt(r.name.slice(5)),l=o*m.cmt,i="";t(p,Ie).subarray(l,l+10).forEach(c=>{c>31&&(i+=String.fromCharCode(c))});let s=`MSB LSB PRG NME -0 127 ${v} ${i}`;p.userBank.load(s,!0),r.name=i,r.ending=" "}return(r.ending!=" "||!r.name.length)&&(r=p.baseBank.get(y,v,k,n)),r}getChVoice(e){let a=this,h=a.getVoice(a.getCcCh(e,0),t(a,I)[e],a.getCcCh(e,32),a.getChMode(e));if(t(a,Ee)[e]){let n="";switch(t(a,A)){case S.mt32:{t(a,me).subarray(m.cmt*(e-1),m.cmt*(e-1)+10).forEach(p=>{n+=String.fromCharCode(Math.max(p,32))}),n=n.trimRight();break}default:{let p=m.cvn*e;t(a,$t).subarray(p,p+m.cvn).forEach(y=>{n+=String.fromCharCode(Math.max(y,32))}),n=n.trimRight()}}n.length&&(h.ending="~",h.name=n)}return h}getRawPitch(){return t(this,Te)}getPitchShift(e){let a=this,h=e*m.rpn,n=t(a,R)[h];return t(a,L)[e*m.rpnt]||t(a,A)==S.mt32&&(n=12),t(a,Te)[e]/8192*n+(t(a,R)[h+3]-64)+((t(a,R)[h+1]<<7)+t(a,R)[h+2]-8192)/8192}getEffectType(e=0){let a=3*e+1;return t(this,se).subarray(a,a+2)}setEffectTypeRaw(e=0,a,h){let n=3*e;t(this,se)[n]=1,t(this,se)[n+1+ +a]=h}setEffectType(e=0,a,h){this.setEffectTypeRaw(e,!1,a),this.setEffectTypeRaw(e,!0,h)}getEffectSink(){return t(this,ot)}setLetterDisplay(e,a,h=0,n=3200){let p=this,y;x(p,Le," ".repeat(h)),e.forEach(v=>{x(p,Le,t(p,Le)+String.fromCharCode(v>31?v:32)),v<32&&(y=y||new Set,y.add(v))}),x(p,kt,Date.now()),x(p,Ue,Date.now()+n),y&&(y=Array.from(y),y.forEach((v,k,r)=>{r[k]=v.toString(16).padStart(2,"0")}),console.warn(`${a}${a?" ":""}invalid code point${y.length>1?"s":""}: 0x${y.join(", 0x")}`))}setDetectionTargets(e="?",a=0){let h=this,n=-1;switch(e.replaceAll(", ",",").split(",").forEach(p=>{p=p.toLowerCase();let y=W.indexOf(Vr[p]||p);O()&&console.debug(`Mapped mode "${p}" to ID "${y}".`),y>-1&&(n=y)}),O()&&console.debug(`Set detection target to ID "${n}".`),n>0&&(t(h,B).x5=82,t(h,B).ds=S.krs),n){case S["05rw"]:{t(h,B).x5=81;break}case S.s90es:t(h,B).ds=S.s90es,t(h,B).smotif=S.s90es;case S.motif:t(h,B).ds=S.motif,t(h,B).smotif=S.motif}}setGsTargets(e=!1,a=4){if(!a)a=e?3:4;else{if(a>4||a<0)throw new Error(`Invalid GS level ${a}`);if(e&&a>>1!=1)throw new Error(`Invalid SC level ${a}`)}let h=this;t(h,B)[e?"sc":"gs"]=a,t(h,q)[S[e?"sc":"gs"]][1]=a,h.forceVoiceRefresh()}getConfigs(){return t(this,wt)}setDumpLimit(e){if(e>2||e<0)throw new RangeError("Invalid dump limit.");t(this,we).dumpLimit=e}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let a=!0,h=0;for(;a&&h=m.ace&&console.warn("ACE slots are full.")}releaseAce(e){let a=!0,h=0;for(;a&&h=m.ace)throw new RangeError("No such ACE slot");let h=t(this,fe)[a];if(h){if(vt.indexOf(h)>=0)return t(this,b)[e*m.cc+E[h]];throw new Error(`Invalid ACE source: ${h}`)}else return 0}initDrums(){let e=this;t(e,ee).fill(64);for(let a=0;a{t(a,b)[m.cc*h]=_t[0]}),t(a,D).fill(a.CH_MELODIC),t(a,D)[9]=a.CH_DRUM1,t(a,D)[25]=a.CH_DRUM3,t(a,D)[41]=a.CH_DRUMS,t(a,D)[57]=a.CH_DRUMS,t(a,D)[73]=a.CH_DRUM5,t(a,D)[89]=a.CH_DRUM7,t(a,D)[105]=a.CH_DRUMS,t(a,D)[121]=a.CH_DRUMS;for(let h=0;h=m.ch)throw new RangeError(`Invalid CH${e+1}`);if(port<0||a>=W.length)throw new RangeError(`Invalid mode ID ${a}`);t(h,Oe)[e]=a,h.dispatchEvent("voice",{part:e})}getChMode(e,a){return W[this.getChModeId(e,a)]}getChModeId(e,a){return a?t(this,Oe)[e]||t(this,X)[e>>4]:t(this,Oe)[e]||t(this,X)[e>>4]||t(this,A)}setPortMode(e,a,h){let n=this;if(e<0||e>=m.ch>>4)throw new RangeError(`Invalid port ${e+1}`);if(a<1)throw new RangeError("Range must be a positive integer");if(e+a>=m.ch>>4)throw new RangeError("Range must be in bound");if(e<0||h>=W.length)throw new RangeError(`Invalid mode ID ${h}`);for(let p=e;p=0&&e-1){if(t(n,A)==0||a){let v=t(n,A);n.initOnReset&&a&&(this.init(1),v=S["?"]),x(n,A,p),x(n,Y,0);for(let r=0;r0&&t(n,Oe)[r]==0&&(t(n,b)[r*m.cc]=_t[p]);switch(p){case S.mt32:{Ht.forEach((r,o)=>{let l=o+1;t(n,de)[l]||(t(n,I)[l]=r,t(n,b)[l*m.cc+E[91]]=127)});for(let r=1;r<10;r++)n.dispatchEvent("voice",{part:r});break}}let k;switch(p){case S["?"]:case S.g2:{k=[52,4,52,18,0,0,0,0];break}case S.xg:{k=[1,0,65,0,5,0,0,0];break}case S.gm:case S.gs:case S.sc:{k=[40,4,40,18,40,32,32,0];break}case S.sd:{k=[58,0,60,0,61,0,61,0];break}case S["05rw"]:case S.x5d:case S.ns5r:{k=[44,1,44,19,44,0,44,0];break}case S.k11:case S.sg:{k=[24,0,0,0,0,0,0,0];break}case S.mt32:{k=[40,4,0,0,0,0,0,0];break}case S.motif:case S.s90es:{k=[113,0,117,0,114,0,0,0];break}default:k=[0,0,0,0,0,0,0,0]}for(let r=0;r{n.dispatchEvent("voice",{part:r})})}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,$e).fill(0)}runJson(e){var a;if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,St)[e.type].call(this,e);{let h=this.chRedir(e.part,e.track),n=!1;(a=t(this,xt)[h])==null||a.forEach(p=>{e.channel=p,n=!0,t(this,St)[e.type].call(this,e)}),n||console.warn(`${hr[e.type]?hr[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${h+1} without any recipient.`)}t(this,ne).length>100&&t(this,ne).splice(100,t(this,ne).length-99)}runRaw(e){}async loadBank(e,a){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}case"pcg":{h.userBank.clearRange({msb:63,lsb:[6,9]}),h.userBank.clearRange({msb:63,lsb:[13,16]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":case"pcg":{bt.context=this,await h.userBank.load(await bt.read(e,a),!1);break}}h.forceVoiceRefresh()}},A=new WeakMap,Y=new WeakMap,ge=new WeakMap,Se=new WeakMap,oe=new WeakSet,xe=function(){return t(this,Se)[t(this,Y)]},$r=function(e){t(this,Se)[t(this,Y)]=e},de=new WeakMap,F=new WeakMap,D=new WeakMap,b=new WeakMap,fe=new WeakMap,I=new WeakMap,K=new WeakMap,ae=new WeakMap,z=new WeakMap,Q=new WeakMap,Te=new WeakMap,$e=new WeakMap,Ge=new WeakMap,ie=new WeakMap,R=new WeakMap,L=new WeakMap,ct=new WeakMap,ee=new WeakMap,be=new WeakMap,se=new WeakMap,ot=new WeakMap,Xe=new WeakMap,X=new WeakMap,Oe=new WeakMap,Ee=new WeakMap,$t=new WeakMap,Ae=new WeakMap,me=new WeakMap,lt=new WeakMap,Ie=new WeakMap,q=new WeakMap,B=new WeakMap,we=new WeakMap,wt=new WeakMap,H=new WeakMap,Ve=new WeakMap,dt=new WeakMap,ft=new WeakMap,Le=new WeakMap,Ue=new WeakMap,kt=new WeakMap,ht=new WeakMap,ye=new WeakMap,G=new WeakMap,Pt=new WeakMap,xt=new WeakMap,Fe=new WeakMap,Gt=new WeakMap,ne=new WeakMap,Ce=new WeakMap,Be=new WeakMap,j=new WeakMap,Ke=new WeakMap,V=new WeakMap,St=new WeakMap,Rt=new WeakMap,ze=new WeakMap,qe=new WeakMap,ce=new WeakMap,he=new WeakMap,ke=new WeakMap,We=new WeakMap,Qe=new WeakMap,Ye=new WeakMap,vr);var Kt=Br(wr(),1);U();U();var Tt,kr,Sr=(kr=class{constructor(g,e,a,h){T(this,Tt,!1);x(this,Tt,g),this.start=e,this.end=a,this.data=h}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return t(this,Tt)}},Tt=new WeakMap,kr),Vt=class extends Sr{constructor(g,e,a){super(!0,g,e,a)}},Tr=class extends Sr{constructor(g,e){super(!1,g,g,e)}},je,xr,Ft=(xr=class extends Array{constructor(){super(...arguments);T(this,je,-1)}resetIndex(e){x(this,je,-1)}fresh(){this.sort(function(e,a){return e.start==a.start?0:(+(e.start>a.start)<<1)-1}),this.forEach(function(e,a){e.index=a})}step(e,a=!1){let h=[];if(a)for(let n=0;ne);n++){if(this[n].endt(p,je)&&(h.push(y),x(p,je,y.index))})}return h}getRange(e,a){var v;e>a&&([e,a]=[a,e]);let h=[],n=-1,p=Math.ceil(Math.sqrt(this.length)),y=!0;for(let k=0;k=e&&(n=k):n=n<0?k:n;for(;y;)((v=this[n])==null?void 0:v.end)=e&&h.push(this[n]):y=!1,n++;return h}},je=new WeakMap,xr);var Yr=0xffffffffffff,Cr=function(g){let e=new Ft,a=this,h=g.timeDivision,n=120,p=new Ft,y=0,v=0;p.push(new Vt(0,Yr,[120,0])),g.track.forEach(function(l){y=0,l.event.forEach(function(i){y+=i.deltaTime,i.type==255&&(i==null?void 0:i.metaType)==81&&(n=6e7/i.data,p[p.length-1]&&p.push(new Vt(y,0xffffffffffff,[n,0])))})}),p.fresh(),p.forEach(function(l,i,s){i>0&&(s[i-1].end=l.start)});let k=120;p.forEach(function(l,i,s){i>0&&(l.end==l.start?s.splice(s.indexOf(l),1):k==l.data[0]&&(s[i-1].end=l.end,s.splice(s.indexOf(l),1)),k=l.data[0])});let r=0,o=120;return p.forEach(function(l){let i=l.start,s=i/o/h*60+r;o=l.data[0],r=s-i/o/h*60,l.data[1]=r}),console.debug("All tempo changes: ",p),n=120,y=0,v=0,g.track.forEach(function(l,i){y=0,v=0;let s=i+1;l.event.forEach(function(c,d){y+=c.deltaTime;let u=p.step(y,!0)[0];u&&(n=u.data[0],v=u.data[1]);let f={type:c.type,data:c.data,track:s,part:0};c.type>14?f.meta=c.metaType:f.part=c.channel,e.push(new Tr(y/n/h*60+v,f))})}),e.fresh(),self.midiEvents=e,console.debug(`Parsed a type ${g.formatType} MIDI sequence.`),e};Kt.default.customInterpreter=lr;var N=function(g,e,a){g.addEventListener(a,h=>{e.dispatchEvent(a,h.data)})},Ze,Je,ut,Me,et,pt,tt,Ct,Ne,He,Z,rt,Pe,at,Mr,ai=(Mr=class extends Mt{constructor(e,a=.5,h=.5){super();P(this,"device");T(this,Ze,void 0);T(this,Je,{});T(this,ut,[]);T(this,Me,"");T(this,et,[]);T(this,pt,[]);T(this,tt,new Uint8ClampedArray(128));T(this,Ct,new Uint8ClampedArray(128));T(this,Ne,.5);T(this,He,120);T(this,Z,4);T(this,rt,4);T(this,Pe,0);T(this,at,0);P(this,"smoothingAtk",0);P(this,"smoothingDcy",0);let n=this;n.smoothingAtk=a,n.smoothingDcy=h,n.device=e,n.addEventListener("meta",function(p){var y;(y=p==null?void 0:p.data)==null||y.forEach(function(v){(t(n,et)[v.meta]||console.debug).call(n,v.meta,v.data)})}),N(n.device,n,"mode"),N(n.device,n,"mastervolume"),N(n.device,n,"channelactive"),N(n.device,n,"channelmin"),N(n.device,n,"channelmax"),N(n.device,n,"portrange"),N(n.device,n,"portstart"),N(n.device,n,"channelreset"),N(n.device,n,"channeltoggle"),N(n.device,n,"screen"),N(n.device,n,"metacommit"),N(n.device,n,"voice"),N(n.device,n,"pitch"),N(n.device,n,"note"),N(n.device,n,"reset"),N(n.device,n,"banklevel"),N(n.device,n,"efxreverb"),N(n.device,n,"efxchorus"),N(n.device,n,"efxdelay"),N(n.device,n,"efxinsert0"),N(n.device,n,"efxinsert1"),N(n.device,n,"efxinsert2"),N(n.device,n,"efxinsert3"),N(n.device,n,"partefxtoggle"),n.addEventListener("note",function({data:p}){t(n,pt).push(p)}),t(n,et)[3]=function(p,y){var v;((v=t(n,Me))==null?void 0:v.length)<1&&(x(n,Me,y),n.dispatchEvent("title",t(n,Me)))},t(n,et)[81]=function(p,y){let v=n.noteProgress,k=t(n,Ne)||.5;x(n,He,6e7/y),x(n,Ne,y/1e6),x(n,Pe,t(n,Pe)+(v*(k/t(n,Ne))-v)),n.dispatchEvent("tempo",t(n,He))},t(n,et)[88]=function(p,y){let v=n.noteProgress,k=n.noteOverall,r=n.noteBar,o=n.noteBeat,l=t(n,Z),i=t(n,rt);x(n,Z,y[0]),x(n,rt,1<=l&&(l{if(!r)return;let l=r.split(" ");if(o){if(!y)return;let i="",s="";l.forEach((c,d)=>{switch(d){case v:{i=c;break}case k:{s=c;break}}}),!t(h,Je)[i]||a?(t(h,Je)[i]=s,n++):self.debugMode&&console.debug(`Voice "${s}" (${i}) seems to be in conflict with (${t(h,Je)[i]}).`),p++}else l.forEach((i,s)=>{switch(i){case"ID":{v=s,y++;break}case"Name":{k=s,y++;break}default:console.debug(`Unknown map field: ${i}`)}})}),console.debug(`Voice names: ${p} total, ${n} loaded.`),h==null||h.device.forceVoiceRefresh()}async loadEfx(e,a){let h=this,n=0,p=0,y,v,k;e.split(` -`).forEach((r,o)=>{if(r)if(o){let l=0,i;r.split(" ").forEach((s,c)=>{switch(c){case y:{l|=parseInt(s,16)<<8;break}case v:{l|=parseInt(s,16);break}case k:{i=s;break}}}),!t(h,ut)[l]||a?(t(h,ut)[l]=i,n++):self.debugMode&&console.debug(`EFX ID 0x${l.toString(16).padStart(4,"0")} (${i}) seems to be in conflict.`),p++}else r.split(" ").forEach((l,i)=>{switch(l){case"MSB":{y=i;break}case"LSB":{v=i;break}case"Name":{k=i;break}default:console.debug(`Unknown EFX field: ${l}`)}})}),console.debug(`EFX: ${p} total, ${n} loaded.`),h.dispatchEvent("efxreverb",h.device.getEffectType(0)),h.dispatchEvent("efxchorus",h.device.getEffectType(1)),h.dispatchEvent("efxdelay",h.device.getEffectType(2)),h.dispatchEvent("efxinsert0",h.device.getEffectType(3)),h.dispatchEvent("efxinsert1",h.device.getEffectType(4)),h.dispatchEvent("efxinsert2",h.device.getEffectType(5)),h.dispatchEvent("efxinsert3",h.device.getEffectType(6))}switchMode(e,a=!1){this.device.switchMode(e,a)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}getMapped(e){return t(this,Je)[e]||e}getEfx([e,a]){let h=e<<8|a;return t(this,ut)[h]||`0x${h.toString(16).padStart(4,"0")}`}get noteProgress(){return t(this,at)/t(this,Ne)}get noteOverall(){return this.noteProgress-t(this,Pe)}get noteBar(){return Math.floor(this.noteOverall/t(this,Z))}get noteBeat(){let e=this.noteOverall%t(this,Z);return e<0&&(e+=t(this,Z)),e}getTimeSig(){return[t(this,Z),t(this,rt)]}getTempo(){return t(this,He)}sendCmd(e){this.device.runJson(e)}render(e){var w;e>t(this,at)&&x(this,at,e);let a=((w=t(this,Ze))==null?void 0:w.step(e))||[],h=0,n=new Set,p={},y=[],v=this,k=[];for(v.device.getStrength().forEach((C,M)=>{t(v,Ct)[M]=C}),v.device.newStrength(),a.forEach(function(C){let M=C.data,_=v.device.runJson(M);switch(_==null?void 0:_.reply){case"meta":{k.push(_);break}}_!=null&&_.reply&&delete _.reply});t(v,pt).length>0;){let C=t(v,pt).shift(),M=C.part<<7|C.note;C.state?(n.add(M),p[M]=C.velo):n.has(M)&&(y.push({part:C.part,note:C.note,velo:p[M],state:v.device.NOTE_SUSTAIN}),h++)}(k==null?void 0:k.length)>0&&v.dispatchEvent("meta",k);let r=v.device.getActive(),o=[],l=v.device.getPitch(),i=v.device.getCcAll(),s=v.device.getProgram(),c=v.device.getChType(),d=[],u=v.device.getStrength();u.forEach(function(C,M,_){_[M]=Math.max(t(v,Ct)[M],C);let Re=_[M]-t(v,tt)[M],_e=E.length*M;if(Re>=0){let Ot=4*.25**(i[_e+E[73]]/64);t(v,tt)[M]+=Math.ceil(Re-Re*v.smoothingAtk**Ot)}else{let Ot=4*.25**(i[_e+E[72]]/64);t(v,tt)[M]+=Math.floor(Re-Re*v.smoothingDcy**Ot)}});let f=0;return r.forEach(function(C,M){C&&(o[M]=v.device.getVel(M),d[M]=v.device.getExt(M),f+=o[M].size)}),{extraPoly:h,extraNotes:y,curPoly:f,chInUse:r,chKeyPr:o,chPitch:l,chProgr:s,chContr:i,chType:c,chExt:d,eventCount:a.length,title:t(v,Me),bitmap:v.device.getBitmap(),letter:v.device.getLetter(),texts:v.device.getTexts(),master:v.device.getMaster(),mode:v.device.getMode(),strength:t(v,tt).slice(),velo:u,rpn:v.device.getRpn(),tSig:v.getTimeSig(),tempo:v.getTempo(),noteBar:v.noteBar,noteBeat:v.noteBeat,ace:v.device.getAce(),rawVelo:v.device.getStrength(),rawStrength:v.device.getRawStrength(),rawPitch:v.device.getRawPitch(),efxSink:v.device.getEffectSink()}}},Ze=new WeakMap,Je=new WeakMap,ut=new WeakMap,Me=new WeakMap,et=new WeakMap,pt=new WeakMap,tt=new WeakMap,Ct=new WeakMap,Ne=new WeakMap,He=new WeakMap,Z=new WeakMap,rt=new WeakMap,Pe=new WeakMap,at=new WeakMap,Mr);export{ai as RootDisplay,m as allocated,E as ccToPos,le as dnToPos}; +%o`,r)}}),t(e,ke).add([0,1,73,78],(r,c,o)=>{e.switchMode("krs"),e.setPortMode(e.getTrackPort(c),1,S.krs),console.debug("Might be KORG KROSS 2 mode reset... Not sure.")}).add([0,1,73,117,2,37],(r,c,o)=>{e.switchMode("krs");let i=e.getTrackPort(c);if(t(e,X)[i]&&t(e,X)[i]!=S.krs)if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+i)} mode "${W[t(e,X)[i]]}" mismatch, should be "krs".`);return}else console.info(`Track ${c} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+i)}.`);e.setPortMode(e.getTrackPort(c),1,S.krs);let s="KROSS 2 BMT1 ",l="";pe(r,(d,u)=>{if(u<24)l+=String.fromCharCode(Math.max(32,d));else if(!(u<1276)){let f=u-1276,$=e.chRedir(Math.floor(f/44),c,!0),w=f%44,C=m.cc*$;w<15?([()=>{d&&e.setChActive($,1),t(e,I)[$]=d,e.dispatchEvent("voice",{part:$})},()=>{d&&e.setChActive($,1),d<10?(t(e,b)[C+E[0]]=63,t(e,b)[C+E[32]]=d):d<20?(t(e,b)[C+E[0]]=121,t(e,b)[C+E[32]]=d-10):d<24&&(t(e,b)[C+E[0]]=[120,0,56,62][d-20],t(e,b)[C+E[32]]=0),e.dispatchEvent("voice",{part:$})},()=>{let M=e.chRedir(d&15,c,!0);t(e,F)[$]=M,console.info(`${s}CH${$+1} receives from CH${M+1}`),d>>5&1||(e.setChActive($,0),console.debug(`KORG KROSS 2 CH${$+1} is disabled.`))},!1,!1,()=>{t(e,b)[C+E[7]]=d},!1,()=>{},()=>{},!1,!1,!1,!1,!1,()=>{t(e,b)[C+E[10]]=d||128}][w]||(()=>{}))():w<36||([()=>{t(e,b)[C+E[74]]=(d+128&255)-64},()=>{t(e,b)[C+E[71]]=(d+128&255)-64},!1,!1,()=>{t(e,b)[C+E[73]]=(d+128&255)-64},()=>{t(e,b)[C+E[75]]=(d+128&255)-64},!1,()=>{t(e,b)[C+E[72]]=(d+128&255)-64}][w]||(()=>{}))()}}),l=l.trimRight(),e.dispatchEvent("metacommit",{type:"EORTitle",data:l})})}chRedir(e,a,h){let n=this;if(t(n,Be)[a])return(t(n,Be)[a]-1)*16+e;if(t(n,A)==S.sc){if(h==1)return e;let p=0,y=!0;for(;y;)t(n,Ce)[e+p]==0?(t(n,Ce)[e+p]=a,console.debug(`Assign track ${a} to channel ${e+p+1}.`),y=!1):t(this,Ce)[e+p]==a?y=!1:(p+=16,p>=128&&(p=0,y=!1));return e+p}else return e}getTrackPort(e){return this.chRedir(0,e,!0)>>4}forceVoiceRefresh(){for(let e=0;e{var n;a{a&&(t(e,Fe)[Math.floor(h/m.redir)][a]=h%m.redir|128)}),O()&&console.debug(t(e,Fe))}getActive(){return t(this,de)}getCc(e){let a=this,h=e*m.cc,n=t(a,b).subarray(h,h+m.cc);return n[E[0]]=n[E[0]]||t(a,q)[a.getChModeId(e)][0],n[E[32]]=n[E[32]]||t(a,q)[a.getChModeId(e)][1],n[E[0]]==nt.bank0&&(n[E[0]]=0),n}getCcCh(e,a){let h=this;if(vt.indexOf(a)<0)throw new Error("CC number not accepted");let n=t(h,b)[m.cc*e+E[a]];switch(a){case 0:{n=n||t(h,q)[h.getChModeId(e)][0],n==nt.bank0&&(n=0);break}case 32:{n=n||t(h,q)[h.getChModeId(e)][1];break}}return n}getCcAll(){let e=this,a=t(e,b).slice();for(let h=0;h0&&!n&&(t(this,b)[e*m.cc+E[0]]=_t[h])}setChActive(e,a=0){t(this,de)[e]!=a&&this.dispatchEvent("channeltoggle",{part:e,active:a}),t(this,de)[e]=a}getExt(e){let a=m.ext*e,h=t(this,ie).subarray(a,a+m.ext),n=new Uint8Array(h.length);return n.set(h),n[1]=n[1]||t(this,Pt),n}getPitch(){return t(this,Te)}getProgram(){return t(this,I)}getTexts(){return t(this,ne).slice()}getVel(e){let a=new Map,h=this;return t(h,z).forEach(function(n,p){let y=Math.floor(n/128),v=n%128;e==y&&t(h,K)[n]>0&&a.set(v,{v:t(h,K)[n],s:t(h,Q)[p]})}),a}getBitmap(){return{bitmap:t(this,oe,xe),expire:t(this,ge)}}getLetter(){return{text:t(this,Le),set:t(this,kt),expire:t(this,Ue)}}getMode(){return W[t(this,A)]}getMaster(){return{volume:t(this,H)}}getRawStrength(){let e=this;return t(this,z).forEach(function(a){let h=Math.floor(a/128);t(e,K)[a]>t(e,$e)[h]&&(t(e,$e)[h]=t(e,K)[a])}),t(this,$e)}getStrength(){let e=[],a=this;return this.getRawStrength().forEach(function(h,n){e[n]=Math.floor(h*t(a,b)[n*m.cc+E[7]]*t(a,b)[n*m.cc+E[11]]*t(a,H)/803288)}),e}getRpn(){return t(this,R)}getNrpn(){return t(this,ct)}getVoice(e,a,h,n){let p=this,y=e||t(p,q)[t(p,A)][0],v=a,k=h||t(p,q)[t(p,A)][1];y==nt.bank0&&(y=0),W[t(p,A)]=="ns5r"&&y>0&&y<56&&(k=3);let r=p.userBank.get(y,v,k,n);if(W[t(p,A)]=="mt32"&&r.name.indexOf("MT-m:")==0){let c=parseInt(r.name.slice(5)),o=c*m.cmt,i="";t(p,Ie).subarray(o,o+10).forEach(l=>{l>31&&(i+=String.fromCharCode(l))});let s=`MSB LSB PRG NME +0 127 ${v} ${i}`;p.userBank.load(s,!0),r.name=i,r.ending=" "}return(r.ending!=" "||!r.name.length)&&(r=p.baseBank.get(y,v,k,n)),r}getChVoice(e){let a=this,h=a.getVoice(a.getCcCh(e,0),t(a,I)[e],a.getCcCh(e,32),a.getChMode(e));if(t(a,Ee)[e]){let n="";switch(t(a,A)){case S.mt32:{t(a,me).subarray(m.cmt*(e-1),m.cmt*(e-1)+10).forEach(p=>{n+=String.fromCharCode(Math.max(p,32))}),n=n.trimRight();break}default:{let p=m.cvn*e;t(a,$t).subarray(p,p+m.cvn).forEach(y=>{n+=String.fromCharCode(Math.max(y,32))}),n=n.trimRight()}}n.length&&(h.ending="~",h.name=n)}return h}getRawPitch(){return t(this,Te)}getPitchShift(e){let a=this,h=e*m.rpn,n=t(a,R)[h];return t(a,L)[e*m.rpnt]||t(a,A)==S.mt32&&(n=12),t(a,Te)[e]/8192*n+(t(a,R)[h+3]-64)+((t(a,R)[h+1]<<7)+t(a,R)[h+2]-8192)/8192}getEffectType(e=0){let a=3*e+1;return t(this,se).subarray(a,a+2)}setEffectTypeRaw(e=0,a,h){let n=3*e;t(this,se)[n]=1,t(this,se)[n+1+ +a]=h}setEffectType(e=0,a,h){this.setEffectTypeRaw(e,!1,a),this.setEffectTypeRaw(e,!0,h)}getEffectSink(){return t(this,ot)}setLetterDisplay(e,a,h=0,n=3200){let p=this,y;x(p,Le," ".repeat(h)),e.forEach(v=>{x(p,Le,t(p,Le)+String.fromCharCode(v>31?v:32)),v<32&&(y=y||new Set,y.add(v))}),x(p,kt,Date.now()),x(p,Ue,Date.now()+n),y&&(y=Array.from(y),y.forEach((v,k,r)=>{r[k]=v.toString(16).padStart(2,"0")}),console.warn(`${a}${a?" ":""}invalid code point${y.length>1?"s":""}: 0x${y.join(", 0x")}`))}setDetectionTargets(e="?",a=0){let h=this,n=-1;switch(e.replaceAll(", ",",").split(",").forEach(p=>{p=p.toLowerCase();let y=W.indexOf(Vr[p]||p);O()&&console.debug(`Mapped mode "${p}" to ID "${y}".`),y>-1&&(n=y)}),O()&&console.debug(`Set detection target to ID "${n}".`),n>0&&(t(h,B).x5=82,t(h,B).ds=S.krs),n){case S["05rw"]:{t(h,B).x5=81;break}case S.s90es:t(h,B).ds=S.s90es,t(h,B).smotif=S.s90es;case S.motif:t(h,B).ds=S.motif,t(h,B).smotif=S.motif}}setGsTargets(e=!1,a=4){if(!a)a=e?3:4;else{if(a>4||a<0)throw new Error(`Invalid GS level ${a}`);if(e&&a>>1!=1)throw new Error(`Invalid SC level ${a}`)}let h=this;t(h,B)[e?"sc":"gs"]=a,t(h,q)[S[e?"sc":"gs"]][1]=a,h.forceVoiceRefresh()}getConfigs(){return t(this,wt)}setDumpLimit(e){if(e>2||e<0)throw new RangeError("Invalid dump limit.");t(this,we).dumpLimit=e}allocateAce(e){if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let a=!0,h=0;for(;a&&h=m.ace&&console.warn("ACE slots are full.")}releaseAce(e){let a=!0,h=0;for(;a&&h=m.ace)throw new RangeError("No such ACE slot");let h=t(this,fe)[a];if(h){if(vt.indexOf(h)>=0)return t(this,b)[e*m.cc+E[h]];throw new Error(`Invalid ACE source: ${h}`)}else return 0}initDrums(){let e=this;t(e,ee).fill(64);for(let a=0;a{t(a,b)[m.cc*h]=_t[0]}),t(a,D).fill(a.CH_MELODIC),t(a,D)[9]=a.CH_DRUM1,t(a,D)[25]=a.CH_DRUM3,t(a,D)[41]=a.CH_DRUMS,t(a,D)[57]=a.CH_DRUMS,t(a,D)[73]=a.CH_DRUM5,t(a,D)[89]=a.CH_DRUM7,t(a,D)[105]=a.CH_DRUMS,t(a,D)[121]=a.CH_DRUMS;for(let h=0;h=m.ch)throw new RangeError(`Invalid CH${e+1}`);if(port<0||a>=W.length)throw new RangeError(`Invalid mode ID ${a}`);t(h,Oe)[e]=a,h.dispatchEvent("voice",{part:e})}getChMode(e,a){return W[this.getChModeId(e,a)]}getChModeId(e,a){return a?t(this,Oe)[e]||t(this,X)[e>>4]:t(this,Oe)[e]||t(this,X)[e>>4]||t(this,A)}setPortMode(e,a,h){let n=this;if(e<0||e>=m.ch>>4)throw new RangeError(`Invalid port ${e+1}`);if(a<1)throw new RangeError("Range must be a positive integer");if(e+a>=m.ch>>4)throw new RangeError("Range must be in bound");if(e<0||h>=W.length)throw new RangeError(`Invalid mode ID ${h}`);for(let p=e;p=0&&e-1){if(t(n,A)==0||a){let v=t(n,A);n.initOnReset&&a&&(this.init(1),v=S["?"]),x(n,A,p),x(n,Y,0);for(let r=0;r0&&t(n,Oe)[r]==0&&(t(n,b)[r*m.cc]=_t[p]);switch(p){case S.mt32:{Ht.forEach((r,c)=>{let o=c+1;t(n,de)[o]||(t(n,I)[o]=r,t(n,b)[o*m.cc+E[91]]=127)});for(let r=1;r<10;r++)n.dispatchEvent("voice",{part:r});break}}let k;switch(p){case S["?"]:case S.g2:{k=[52,4,52,18,0,0,0,0];break}case S.xg:{k=[1,0,65,0,5,0,0,0];break}case S.gm:case S.gs:case S.sc:{k=[40,4,40,18,40,32,32,0];break}case S.sd:{k=[58,0,60,0,61,0,61,0];break}case S["05rw"]:case S.x5d:case S.ns5r:{k=[44,1,44,19,44,0,44,0];break}case S.k11:case S.sg:{k=[24,0,0,0,0,0,0,0];break}case S.mt32:{k=[40,4,0,0,0,0,0,0];break}case S.doc:{k=[24,16,0,0,0,0,0,0];break}case S.motif:case S.s90es:{k=[113,0,117,0,114,0,0,0];break}default:k=[0,0,0,0,0,0,0,0]}for(let r=0;r{n.dispatchEvent("voice",{part:r})})}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,$e).fill(0)}runJson(e){var a;if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,St)[e.type].call(this,e);{let h=this.chRedir(e.part,e.track),n=!1;(a=t(this,xt)[h])==null||a.forEach(p=>{e.channel=p,n=!0,t(this,St)[e.type].call(this,e)}),n||console.warn(`${hr[e.type]?hr[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${h+1} without any recipient.`)}t(this,ne).length>100&&t(this,ne).splice(100,t(this,ne).length-99)}runRaw(e){}async loadBank(e,a){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}case"pcg":{h.userBank.clearRange({msb:63,lsb:[6,9]}),h.userBank.clearRange({msb:63,lsb:[13,16]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":case"pcg":{bt.context=this,await h.userBank.load(await bt.read(e,a),!1);break}}h.forceVoiceRefresh()}},A=new WeakMap,Y=new WeakMap,ge=new WeakMap,Se=new WeakMap,oe=new WeakSet,xe=function(){return t(this,Se)[t(this,Y)]},$r=function(e){t(this,Se)[t(this,Y)]=e},de=new WeakMap,F=new WeakMap,D=new WeakMap,b=new WeakMap,fe=new WeakMap,I=new WeakMap,K=new WeakMap,ae=new WeakMap,z=new WeakMap,Q=new WeakMap,Te=new WeakMap,$e=new WeakMap,Ge=new WeakMap,ie=new WeakMap,R=new WeakMap,L=new WeakMap,ct=new WeakMap,ee=new WeakMap,be=new WeakMap,se=new WeakMap,ot=new WeakMap,Xe=new WeakMap,X=new WeakMap,Oe=new WeakMap,Ee=new WeakMap,$t=new WeakMap,Ae=new WeakMap,me=new WeakMap,lt=new WeakMap,Ie=new WeakMap,q=new WeakMap,B=new WeakMap,we=new WeakMap,wt=new WeakMap,H=new WeakMap,Ve=new WeakMap,dt=new WeakMap,ft=new WeakMap,Le=new WeakMap,Ue=new WeakMap,kt=new WeakMap,ht=new WeakMap,ye=new WeakMap,G=new WeakMap,Pt=new WeakMap,xt=new WeakMap,Fe=new WeakMap,Gt=new WeakMap,ne=new WeakMap,Ce=new WeakMap,Be=new WeakMap,j=new WeakMap,Ke=new WeakMap,V=new WeakMap,St=new WeakMap,Rt=new WeakMap,ze=new WeakMap,qe=new WeakMap,ce=new WeakMap,he=new WeakMap,ke=new WeakMap,We=new WeakMap,Qe=new WeakMap,Ye=new WeakMap,vr);var Kt=Br(wr(),1);U();U();var Tt,kr,Sr=(kr=class{constructor(g,e,a,h){T(this,Tt,!1);x(this,Tt,g),this.start=e,this.end=a,this.data=h}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return t(this,Tt)}},Tt=new WeakMap,kr),Vt=class extends Sr{constructor(g,e,a){super(!0,g,e,a)}},Tr=class extends Sr{constructor(g,e){super(!1,g,g,e)}},je,xr,Ft=(xr=class extends Array{constructor(){super(...arguments);T(this,je,-1)}resetIndex(e){x(this,je,-1)}fresh(){this.sort(function(e,a){return e.start==a.start?0:(+(e.start>a.start)<<1)-1}),this.forEach(function(e,a){e.index=a})}step(e,a=!1){let h=[];if(a)for(let n=0;ne);n++){if(this[n].endt(p,je)&&(h.push(y),x(p,je,y.index))})}return h}getRange(e,a){var v;e>a&&([e,a]=[a,e]);let h=[],n=-1,p=Math.ceil(Math.sqrt(this.length)),y=!0;for(let k=0;k=e&&(n=k):n=n<0?k:n;for(;y;)((v=this[n])==null?void 0:v.end)=e&&h.push(this[n]):y=!1,n++;return h}},je=new WeakMap,xr);var Yr=0xffffffffffff,Cr=function(g){let e=new Ft,a=this,h=g.timeDivision,n=120,p=new Ft,y=0,v=0;p.push(new Vt(0,Yr,[120,0])),g.track.forEach(function(o){y=0,o.event.forEach(function(i){y+=i.deltaTime,i.type==255&&(i==null?void 0:i.metaType)==81&&(n=6e7/i.data,p[p.length-1]&&p.push(new Vt(y,0xffffffffffff,[n,0])))})}),p.fresh(),p.forEach(function(o,i,s){i>0&&(s[i-1].end=o.start)});let k=120;p.forEach(function(o,i,s){i>0&&(o.end==o.start?s.splice(s.indexOf(o),1):k==o.data[0]&&(s[i-1].end=o.end,s.splice(s.indexOf(o),1)),k=o.data[0])});let r=0,c=120;return p.forEach(function(o){let i=o.start,s=i/c/h*60+r;c=o.data[0],r=s-i/c/h*60,o.data[1]=r}),console.debug("All tempo changes: ",p),n=120,y=0,v=0,g.track.forEach(function(o,i){y=0,v=0;let s=i+1;o.event.forEach(function(l,d){y+=l.deltaTime;let u=p.step(y,!0)[0];u&&(n=u.data[0],v=u.data[1]);let f={type:l.type,data:l.data,track:s,part:0};l.type>14?f.meta=l.metaType:f.part=l.channel,e.push(new Tr(y/n/h*60+v,f))})}),e.fresh(),self.midiEvents=e,console.debug(`Parsed a type ${g.formatType} MIDI sequence.`),e};Kt.default.customInterpreter=lr;var N=function(g,e,a){g.addEventListener(a,h=>{e.dispatchEvent(a,h.data)})},Ze,Je,ut,Me,et,pt,tt,Ct,Ne,He,Z,rt,Pe,at,Mr,ai=(Mr=class extends Mt{constructor(e,a=.5,h=.5){super();P(this,"device");T(this,Ze,void 0);T(this,Je,{});T(this,ut,[]);T(this,Me,"");T(this,et,[]);T(this,pt,[]);T(this,tt,new Uint8ClampedArray(128));T(this,Ct,new Uint8ClampedArray(128));T(this,Ne,.5);T(this,He,120);T(this,Z,4);T(this,rt,4);T(this,Pe,0);T(this,at,0);P(this,"smoothingAtk",0);P(this,"smoothingDcy",0);let n=this;n.smoothingAtk=a,n.smoothingDcy=h,n.device=e,n.addEventListener("meta",function(p){var y;(y=p==null?void 0:p.data)==null||y.forEach(function(v){(t(n,et)[v.meta]||console.debug).call(n,v.meta,v.data)})}),N(n.device,n,"mode"),N(n.device,n,"mastervolume"),N(n.device,n,"channelactive"),N(n.device,n,"channelmin"),N(n.device,n,"channelmax"),N(n.device,n,"portrange"),N(n.device,n,"portstart"),N(n.device,n,"channelreset"),N(n.device,n,"channeltoggle"),N(n.device,n,"screen"),N(n.device,n,"metacommit"),N(n.device,n,"voice"),N(n.device,n,"pitch"),N(n.device,n,"note"),N(n.device,n,"reset"),N(n.device,n,"banklevel"),N(n.device,n,"efxreverb"),N(n.device,n,"efxchorus"),N(n.device,n,"efxdelay"),N(n.device,n,"efxinsert0"),N(n.device,n,"efxinsert1"),N(n.device,n,"efxinsert2"),N(n.device,n,"efxinsert3"),N(n.device,n,"partefxtoggle"),n.addEventListener("note",function({data:p}){t(n,pt).push(p)}),t(n,et)[3]=function(p,y){var v;((v=t(n,Me))==null?void 0:v.length)<1&&(x(n,Me,y),n.dispatchEvent("title",t(n,Me)))},t(n,et)[81]=function(p,y){let v=n.noteProgress,k=t(n,Ne)||.5;x(n,He,6e7/y),x(n,Ne,y/1e6),x(n,Pe,t(n,Pe)+(v*(k/t(n,Ne))-v)),n.dispatchEvent("tempo",t(n,He))},t(n,et)[88]=function(p,y){let v=n.noteProgress,k=n.noteOverall,r=n.noteBar,c=n.noteBeat,o=t(n,Z),i=t(n,rt);x(n,Z,y[0]),x(n,rt,1<=o&&(o{if(!r)return;let o=r.split(" ");if(c){if(!y)return;let i="",s="";o.forEach((l,d)=>{switch(d){case v:{i=l;break}case k:{s=l;break}}}),!t(h,Je)[i]||a?(t(h,Je)[i]=s,n++):self.debugMode&&console.debug(`Voice "${s}" (${i}) seems to be in conflict with (${t(h,Je)[i]}).`),p++}else o.forEach((i,s)=>{switch(i){case"ID":{v=s,y++;break}case"Name":{k=s,y++;break}default:console.debug(`Unknown map field: ${i}`)}})}),console.debug(`Voice names: ${p} total, ${n} loaded.`),h==null||h.device.forceVoiceRefresh()}async loadEfx(e,a){let h=this,n=0,p=0,y,v,k;e.split(` +`).forEach((r,c)=>{if(r)if(c){let o=0,i;r.split(" ").forEach((s,l)=>{switch(l){case y:{o|=parseInt(s,16)<<8;break}case v:{o|=parseInt(s,16);break}case k:{i=s;break}}}),!t(h,ut)[o]||a?(t(h,ut)[o]=i,n++):self.debugMode&&console.debug(`EFX ID 0x${o.toString(16).padStart(4,"0")} (${i}) seems to be in conflict.`),p++}else r.split(" ").forEach((o,i)=>{switch(o){case"MSB":{y=i;break}case"LSB":{v=i;break}case"Name":{k=i;break}default:console.debug(`Unknown EFX field: ${o}`)}})}),console.debug(`EFX: ${p} total, ${n} loaded.`),h.dispatchEvent("efxreverb",h.device.getEffectType(0)),h.dispatchEvent("efxchorus",h.device.getEffectType(1)),h.dispatchEvent("efxdelay",h.device.getEffectType(2)),h.dispatchEvent("efxinsert0",h.device.getEffectType(3)),h.dispatchEvent("efxinsert1",h.device.getEffectType(4)),h.dispatchEvent("efxinsert2",h.device.getEffectType(5)),h.dispatchEvent("efxinsert3",h.device.getEffectType(6))}switchMode(e,a=!1){this.device.switchMode(e,a)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}getMapped(e){return t(this,Je)[e]||e}getEfx([e,a]){let h=e<<8|a;return t(this,ut)[h]||`0x${h.toString(16).padStart(4,"0")}`}get noteProgress(){return t(this,at)/t(this,Ne)}get noteOverall(){return this.noteProgress-t(this,Pe)}get noteBar(){return Math.floor(this.noteOverall/t(this,Z))}get noteBeat(){let e=this.noteOverall%t(this,Z);return e<0&&(e+=t(this,Z)),e}getTimeSig(){return[t(this,Z),t(this,rt)]}getTempo(){return t(this,He)}sendCmd(e){this.device.runJson(e)}render(e){var w;e>t(this,at)&&x(this,at,e);let a=((w=t(this,Ze))==null?void 0:w.step(e))||[],h=0,n=new Set,p={},y=[],v=this,k=[];for(v.device.getStrength().forEach((C,M)=>{t(v,Ct)[M]=C}),v.device.newStrength(),a.forEach(function(C){let M=C.data,_=v.device.runJson(M);switch(_==null?void 0:_.reply){case"meta":{k.push(_);break}}_!=null&&_.reply&&delete _.reply});t(v,pt).length>0;){let C=t(v,pt).shift(),M=C.part<<7|C.note;C.state?(n.add(M),p[M]=C.velo):n.has(M)&&(y.push({part:C.part,note:C.note,velo:p[M],state:v.device.NOTE_SUSTAIN}),h++)}(k==null?void 0:k.length)>0&&v.dispatchEvent("meta",k);let r=v.device.getActive(),c=[],o=v.device.getPitch(),i=v.device.getCcAll(),s=v.device.getProgram(),l=v.device.getChType(),d=[],u=v.device.getStrength();u.forEach(function(C,M,_){_[M]=Math.max(t(v,Ct)[M],C);let Re=_[M]-t(v,tt)[M],_e=E.length*M;if(Re>=0){let Ot=4*.25**(i[_e+E[73]]/64);t(v,tt)[M]+=Math.ceil(Re-Re*v.smoothingAtk**Ot)}else{let Ot=4*.25**(i[_e+E[72]]/64);t(v,tt)[M]+=Math.floor(Re-Re*v.smoothingDcy**Ot)}});let f=0;return r.forEach(function(C,M){C&&(c[M]=v.device.getVel(M),d[M]=v.device.getExt(M),f+=c[M].size)}),{extraPoly:h,extraNotes:y,curPoly:f,chInUse:r,chKeyPr:c,chPitch:o,chProgr:s,chContr:i,chType:l,chExt:d,eventCount:a.length,title:t(v,Me),bitmap:v.device.getBitmap(),letter:v.device.getLetter(),texts:v.device.getTexts(),master:v.device.getMaster(),mode:v.device.getMode(),strength:t(v,tt).slice(),velo:u,rpn:v.device.getRpn(),tSig:v.getTimeSig(),tempo:v.getTempo(),noteBar:v.noteBar,noteBeat:v.noteBeat,ace:v.device.getAce(),rawVelo:v.device.getStrength(),rawStrength:v.device.getRawStrength(),rawPitch:v.device.getRawPitch(),efxSink:v.device.getEffectSink()}}},Ze=new WeakMap,Je=new WeakMap,ut=new WeakMap,Me=new WeakMap,et=new WeakMap,pt=new WeakMap,tt=new WeakMap,Ct=new WeakMap,Ne=new WeakMap,He=new WeakMap,Z=new WeakMap,rt=new WeakMap,Pe=new WeakMap,at=new WeakMap,Mr);export{ai as RootDisplay,m as allocated,E as ccToPos,le as dnToPos}; diff --git a/dist/xp_state.mjs b/dist/xp_state.mjs index 64a89342..5f389cd3 100644 --- a/dist/xp_state.mjs +++ b/dist/xp_state.mjs @@ -1,10 +1,10 @@ -var Qt=Object.defineProperty;var Yt=(y,e,r)=>e in y?Qt(y,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):y[e]=r;var T=(y,e,r)=>(Yt(y,typeof e!="symbol"?e+"":e,r),r),vt=(y,e,r)=>{if(!e.has(y))throw TypeError("Cannot "+r)};var t=(y,e,r)=>(vt(y,e,"read from private field"),r?r.call(y):e.get(y)),C=(y,e,r)=>{if(e.has(y))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(y):e.set(y,r)},x=(y,e,r,h)=>(vt(y,e,"write to private field"),h?h.call(y,r):e.set(y,r),r);(function(){var y=function(k,S,a){var c,f;if(self.MessageEvent)switch(k){case"message":{f=new MessageEvent(k,{data:S,ports:a==null?void 0:a.ports}),Object.defineProperty(f,"source",{value:a==null?void 0:a.source});break}default:f=new Event(k)}else f=document.createEvent("Event"),f.initEvent(k,!1,!1),a&&k=="message"&&(f.data=S,a.source&&Object.defineProperty(f,"source",{value:a.source}),(c=a.ports)!=null&&c.length&&Object.defineProperty(f,"ports",{value:a.ports}));return f};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),r=[],h={},u=function(k){var S,a=this;if((this==null?void 0:this.constructor)!=u)throw new TypeError("Illegal constructor");r.push(this),(S=h[k])!=null&&S.constructor||(h[k]=[]),h[k].push(this);var c=Math.floor(Math.random()*281474976710656),f=[],s=0,i=[],o=!0,n=!1;Object.defineProperty(this,"id",{get:function(){return c}}),Object.defineProperty(this,"name",{value:k}),this.close=function(){var l,m=r.indexOf(a);m>-1?(e.postMessage({t:"d",c:k,i:c}),r.splice(m,1),(l=h[k])!=null&&l.constructor&&(m=h[k].indexOf(a),m>-1&&h[k].splice(m,1)),h[k].length||delete h[k],console.debug("[Snowy] BroadcastChannel closed."),n=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(l){if(e){if(n)throw new Error("Channel already closed");e.postMessage({t:"m",c:k,i:c,m:s,d:l}),s++,s>4294967295&&(s=0)}else i.push(l),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(o){for(e.postMessage({t:"r",c:k,i:c}),console.debug("[Snowy] ".concat(i.length," message(s) in cache."));i.length;){var l=i.shift();a.postMessage(l)}o=!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(l){l.c==k?l.i!=c&&a.dispatchEvent(y("message",l.d,{source:a})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(c," receives from ").concat(k,", not ").concat(l.c,"."))};var d={};this.dispatchEvent=function(l){var m,$;if(Object.defineProperty(l,"target",{value:a}),Object.defineProperty(l,"currentTarget",{value:a}),(m=d[l.type])!=null&&m.length)for(var M=d[l.type],U=0;U-1&&d[l].splice(U,1)}!((M=d[l])!=null&&M.length)&&d[l].constructor&&delete d[l]}},self.BroadcastChannel=u,E=function(){if(e){e.addEventListener("message",function(S){var a=S.data,c=!1;switch(a.t){case"k":{c=!1,e.postMessage({t:"k"});break}case"m":{var f=h[a.c];if(f!=null&&f.length)for(var s=0;s{switch(h.addEventListener("abort",()=>{E(new Error("Blob read aborted"))}),h.addEventListener("error",v=>{E(h.error||v.data||new Error("Blob read error"))}),h.addEventListener("load",()=>{u(h.result)}),r.toLowerCase()){case"arraybuffer":case"buffer":{h.readAsArrayBuffer(e);break}case"string":case"text":{h.readAsText(e);break}default:E(new Error(`Unknown target ${r}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return y(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return y(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(y,e){let r=0,h=16,u=this,E=[];for(;r-1;){let v=u.lastIndexOf(y);E.unshift(u.slice(v+y.length)),u=u.slice(0,v),v==0&&E.unshift(""),r++}return u.length&&E.unshift(u),E.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(y,e){if(e){let r=this;for(;r.length0){let h=this.pool.length,u=1<=1&&v>=0;){if(v<=0)throw new Error("TTL reached.");if(E==h)E-=u;else{let S=wt(e,this.pool[E]);switch(S){case 0:{v=0;break}case 1:{E+u<=h&&(E+=u);break}case-1:{E!=0&&(E-=u);break}default:console.warn(`Unexpected result ${S}.`)}}u=u>>1,v--}let k=!0;if(E>=this.pool.length)k=!1;else{let S=this;this.pool[E].forEach(function(a,c,f){k&&a!=e[c]&&(k=!1)}),!k&&wt(e,this.pool[E])>0&&E++}return k||r?E:-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 J,kt,St=(kt=class{constructor(){C(this,J,{})}addEventListener(y,e){t(this,J)[y]||(t(this,J)[y]=[]),t(this,J)[y].unshift(e)}removeEventListener(y,e){if(t(this,J)[y]){let r=t(this,J)[y].indexOf(e);r>-1&&t(this,J)[y].splice(r,1),t(this,J)[y].length<1&&delete t(this,J)[y]}}dispatchEvent(y,e){var u;let r=new Event(y),h=this;r.data=e,((u=t(this,J)[y])==null?void 0:u.length)>0&&t(this,J)[y].forEach(function(E){try{E==null||E.call(h,r)}catch(v){console.error(v)}}),this[`on${y}`]&&this[`on${y}`](r)}},J=new WeakMap,kt);var Jt=["MSB","PRG","LSB","NME","ELC","DRM"],ht=function(y){let e=Math.floor(y/10),r=y%10;return`${e.toString(16)}${r}`},Q,xt,ut=(xt=class{constructor(...y){C(this,Q,void 0);T(this,"strictMode",!1);this.loadFiles(...y)}get(y=0,e=0,r=0,h){var l,m;let u=[y,e,r],E,v=1,k=0,S,a=Array.from(arguments);switch(h){case"xg":{switch(y){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":case"sc":{y==0&&r<5?a[2]=0:y>125&&r<5&&r!=2&&(a[2]=y,a[0]=0);break}case"g2":case"sd":{y>>1==40?a[2]|=16:y>95&&y<100&&(a[2]|=16,e>>4==7&&(a[0]=96));break}case"sg":{y==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=" ",f="M",s=0,i=0;switch(a[0]){case 0:{a[2]==127?f="MT-a":a[2]==126?f="MT-b":a[2]==7?f="GM-k":a[2]==5?f="SG-a":a[2]==4?f="SP-l":a[2]==0||(h=="gs"||h=="sc")&&a[2]<5?f="GM-a":(f="y",s=3);break}case 8:{h=="sg"?f="GM-s":f="r:";break}case 32:case 33:case 34:case 35:case 36:{h=="xg"&&(f=`${["AP","VL","PF","DX","AN"][y&7]}-${"abcdefgh"[r]}`);break}case 48:{f=`yM${(a[2]>>3).toString().padStart(2,"0")}`,s=1;break}case 56:{f="GM-b";break}case 57:f=["yDOC","QY10","QY20"][a[2]-112]||"yMxv";case 61:case 120:{f="rDrm";break}case 62:{f="kDrm";break}case 63:{if(a[2]<17){let $=a[2];f=$<10?"kP:":"kC:",f+=$%10}else a[2]<34?f=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][a[2]-17]:f="Ds";break}case 64:{f="ySFX";break}case 67:{f="DX:S";break}case 80:case 81:case 82:case 83:{f=`Prg${"UABC"[a[0]-80]}`;break}case 88:case 89:case 90:case 91:{f=`Cmb${"UABC"[a[0]-88]}`;break}case 95:{f=`${["DR","PC"][a[2]]}-d`;break}case 96:{f=a[2]==106?"AP-a":a[2]>>4==1?"SDg":"PF",a[2]>63?i=63:a[2]>>4==1&&(i=16),s=3;break}case 97:{f=a[2]>>4==1?"SDa":"VL:",s=3,a[2]>>4==1?i=16:i=112;break}case 98:{f=a[2]>>4==1?"SDb":"SG-a",s=3,i=16;break}case 99:{f=a[2]>>4==1?"SDc":"DX",a[2]>63?i=63:a[2]>>4==1&&(i=16),s=3;break}case 100:{f="AN",a[2]>63?i=63:a[2]>>4==1&&(i=16),s=3;break}case 104:case 105:case 106:case 107:{f="SDd",i=104;break}case 121:{f=`GM-${a[2]?"":"a"}`,s=3;break}case 122:{f="lDrm";break}case 126:{f="yDrS";break}case 127:{a[2]==127?f="rDrm":f="yDrm";break}default:a[0]<48?f="r:":f="M"}f.length<4&&(f+=`${[y,r,a[0],a[2]][s]-i}`.padStart(4-f.length,"0")),h=="xg"&&(y==0?a[2]<100?f=f.replace("y0","y:"):a[2]==125&&(f="y126"):y==16?(E=`Voice${((a[2]<<7)+a[1]+1).toString().padStart(3,"0")}`,c=" "):y==35&&r>>1==2&&(E=`DXCH_${(((a[2]&1)<<7)+e+1).toString().padStart(3,"0")}`,c=" "));let o=[a[0],a[1],a[2]];for(;!((E==null?void 0:E.length)>=0);)if(E=(l=t(this,Q)[a[1]||0][(a[0]<<7)+a[2]])==null?void 0:l.name,E){let $=t(this,Q)[a[1]||0][(a[0]<<7)+a[2]];v=($==null?void 0:$.poly)||v,k=($==null?void 0:$.type)||k,S=$==null?void 0:$.drum}else if(this.strictMode)E="",c="?";else if(a[0]==0&&a[1]==0&&a[2]==0)E="Unloaded";else if(t(this,Q)[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(y==48)a[0]=0,a[2]=0,c="!";else if(y==62)a[1]--,c=" ",a[1]<1&&!(E!=null&&E.length)&&(a[0]=0,c="!");else if(y<63)a[0]==0?(a[2]=0,c="^"):a[2]<1?(a[0]=0,c="*"):a[2]--;else if(y==80)E=`PrgU:${e.toString().padStart(3,"0")}`,c="!";else if(y==88)E=`CmbU:${e.toString().padStart(3,"0")}`,c="!";else if(y==121)E=`GM2Vox0${r}`,c="#";else if(y==122)if(a[1]==32?a[1]==0:a[1]%=7,E=(m=t(this,Q)[a[1]||0][(a[0]<<7)+a[2]])==null?void 0:m.name,E){c=" ";let $=t(this,Q)[a[1]||0][(a[0]<<7)+a[2]];v=($==null?void 0:$.poly)||v,k=($==null?void 0:$.type)||k,S=$==null?void 0:$.drum}else E="",c="*";else a[1]==0?(E=`${y.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 n=[a[0],a[1],a[2]];(h=="gs"||h=="sc"||h=="ns5r")&&c=="^"&&(c=" "),y==127&&c=="^"&&(c=" "),c!=" "&&self.debugMode&&(E="");let d="??";switch(a[0]){case 0:{a[2]==0?d="GM":a[2]==5||a[2]==7?d="KG":a[2]<126?d="XG":a[2]==127&&(d="MT");break}case 32:case 33:case 35:case 36:{a[2]>4?d=["AP","VL","PF","DX","AN"][a[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:{a[2]<17?d="KR":a[2]<34?d="ES":d="DS";break}case 64:case 126:{d="XG";break}case 67:case 99:{d=a[2]>>4==1?"SD":"DX";break}case 81:{d="RW";break}case 95:{d=["DR","PC"][a[2]];break}case 96:{d=a[2]==106?"AP":a[2]>>4==1?"SD":"PF";break}case 97:{d=a[2]>>4==1?"SD":"VL";break}case 98:{d=a[2]>>4==1?"SD":"SG";break}case 100:{d="AN";break}case 104:case 105:case 106:case 107:{d="SD";break}case 120:{d="GS";break}case 121:{d=a[2]?"G2":"GM";break}case 122:{d="KG";break}case 127:{d=a[2]==127?"MT":e==0?"GM":"XG";break}default:a[0]<48&&(a[0]==16&&h=="xg"?d="XG":d="GS")}return{name:E||`${ht(y||0)} ${ht(e||0)} ${ht(r||0)}`,poly:v,type:k,drum:S,iid:o,eid:n,sid:u,ending:c,sect:f,standard:d}}async load(y,e,r="(internal)"){let h=this,u=[],E=0,v=0;y.split(` -`).forEach(function(k,S){let a=k.split(" "),c=[];if(S==0){if(a.forEach(function(f,s){u[Jt.indexOf(f)]=s}),u.length<4){console.debug("Debugger launched.");debugger}}else{let f=0,s=0,i=0,o,n=1,d=0,l;a.forEach(async function($,M){switch(M){case u[0]:{f=parseInt($);break}case u[1]:{s=parseInt($);break}case u[2]:{i=parseInt($);break}case u[3]:{o=$;break}case u[4]:{$=parseInt($),$<16?n=$+1:d=($&15)+1;break}case u[5]:{l=$;break}}}),t(h,Q)[s]=t(h,Q)[s]||[];let m=t(h,Q)[s];if(!m[f<<7|i]||e){let $={msb:f,prg:s,lsb:i,name:o,poly:n,type:d,drum:l};m[f<<7|i]=$,E++}v++}}),e||console.debug(`Map "${r}": ${v} total, ${E} loaded.`)}clearRange(y){let e=y.prg!=null?y.prg.constructor==Array?y.prg:[y.prg,y.prg]:[0,127],r=y.msb!=null?y.msb.constructor==Array?y.msb:[y.msb,y.msb]:[0,127],h=y.lsb!=null?y.lsb.constructor==Array?y.lsb:[y.lsb,y.lsb]:[0,127];for(let u=r[0];u<=r[1];u++){let E=u<<7;for(let v=h[0];v<=h[1];v++){let k=E+v;for(let S=e[0];S<=e[1];S++)delete t(this,Q)[S][k]}}}init(){x(this,Q,[]);for(let y=0;y<128;y++)t(this,Q).push([""])}async loadFiles(...y){this.init();let e=this;y.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".`)}})}},Q=new WeakMap,xt);var Xe,Ct,Mt=(Ct=class{constructor(){C(this,Xe,{});T(this,"context")}set(y,e){t(this,Xe)[y]=e}has(y){return!!t(this,Xe)[y]}async read(y,e){if(!this.has(y))throw new Error(`No decoder registered for "${y}"`);return await t(this,Xe)[y].call(this.context||this,e)}},Xe=new WeakMap,Ct);var Zt=function(y,e){let r=!0;return e.forEach((h,u)=>{r=r&&y[u]==h}),r},Je=function(y){let e=0;return y.forEach(r=>{e*=256,e+=r}),e},Ee=new TextDecoder,Ze=new Mt;Ze.set("s7e",async function(y){let e=new Uint8Array(await y.slice(0,65536).arrayBuffer()),r="MSB LSB PRG NME",h=[0,0,0,0],u=32,E=0,v=0,k=!0,S=[],a=0;for(;k;){let c=e.subarray(E);([()=>{Ee.decode(c.subarray(0,4))=="YSFC"?(E+=80,v=1):E++},()=>{if(Zt(c.subarray(0,4),h))S.forEach((f,s,i)=>{let o=Je(e.subarray(f.start+4,f.start+8));f.length=o}),v=2;else{let f=Ee.decode(c.subarray(0,4)),s=Je(c.subarray(4,8));S.push({type:f,start:s}),E+=8}},()=>{let f=S[a],s=e.subarray(f.start,f.start+f.length),i=32;switch(f.type){case"ENVC":{let o=u;for(;oe in y?Qt(y,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):y[e]=r;var T=(y,e,r)=>(Yt(y,typeof e!="symbol"?e+"":e,r),r),vt=(y,e,r)=>{if(!e.has(y))throw TypeError("Cannot "+r)};var t=(y,e,r)=>(vt(y,e,"read from private field"),r?r.call(y):e.get(y)),C=(y,e,r)=>{if(e.has(y))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(y):e.set(y,r)},x=(y,e,r,h)=>(vt(y,e,"write to private field"),h?h.call(y,r):e.set(y,r),r);(function(){var y=function(k,S,a){var c,f;if(self.MessageEvent)switch(k){case"message":{f=new MessageEvent(k,{data:S,ports:a==null?void 0:a.ports}),Object.defineProperty(f,"source",{value:a==null?void 0:a.source});break}default:f=new Event(k)}else f=document.createEvent("Event"),f.initEvent(k,!1,!1),a&&k=="message"&&(f.data=S,a.source&&Object.defineProperty(f,"source",{value:a.source}),(c=a.ports)!=null&&c.length&&Object.defineProperty(f,"ports",{value:a.ports}));return f};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),r=[],h={},u=function(k){var S,a=this;if((this==null?void 0:this.constructor)!=u)throw new TypeError("Illegal constructor");r.push(this),(S=h[k])!=null&&S.constructor||(h[k]=[]),h[k].push(this);var c=Math.floor(Math.random()*281474976710656),f=[],s=0,i=[],o=!0,n=!1;Object.defineProperty(this,"id",{get:function(){return c}}),Object.defineProperty(this,"name",{value:k}),this.close=function(){var l,m=r.indexOf(a);m>-1?(e.postMessage({t:"d",c:k,i:c}),r.splice(m,1),(l=h[k])!=null&&l.constructor&&(m=h[k].indexOf(a),m>-1&&h[k].splice(m,1)),h[k].length||delete h[k],console.debug("[Snowy] BroadcastChannel closed."),n=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(l){if(e){if(n)throw new Error("Channel already closed");e.postMessage({t:"m",c:k,i:c,m:s,d:l}),s++,s>4294967295&&(s=0)}else i.push(l),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(o){for(e.postMessage({t:"r",c:k,i:c}),console.debug("[Snowy] ".concat(i.length," message(s) in cache."));i.length;){var l=i.shift();a.postMessage(l)}o=!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(l){l.c==k?l.i!=c&&a.dispatchEvent(y("message",l.d,{source:a})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(c," receives from ").concat(k,", not ").concat(l.c,"."))};var d={};this.dispatchEvent=function(l){var m,$;if(Object.defineProperty(l,"target",{value:a}),Object.defineProperty(l,"currentTarget",{value:a}),(m=d[l.type])!=null&&m.length)for(var M=d[l.type],U=0;U-1&&d[l].splice(U,1)}!((M=d[l])!=null&&M.length)&&d[l].constructor&&delete d[l]}},self.BroadcastChannel=u,E=function(){if(e){e.addEventListener("message",function(S){var a=S.data,c=!1;switch(a.t){case"k":{c=!1,e.postMessage({t:"k"});break}case"m":{var f=h[a.c];if(f!=null&&f.length)for(var s=0;s{switch(h.addEventListener("abort",()=>{E(new Error("Blob read aborted"))}),h.addEventListener("error",v=>{E(h.error||v.data||new Error("Blob read error"))}),h.addEventListener("load",()=>{u(h.result)}),r.toLowerCase()){case"arraybuffer":case"buffer":{h.readAsArrayBuffer(e);break}case"string":case"text":{h.readAsText(e);break}default:E(new Error(`Unknown target ${r}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return y(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return y(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(y,e){let r=0,h=16,u=this,E=[];for(;r-1;){let v=u.lastIndexOf(y);E.unshift(u.slice(v+y.length)),u=u.slice(0,v),v==0&&E.unshift(""),r++}return u.length&&E.unshift(u),E.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(y,e){if(e){let r=this;for(;r.length0){let h=this.pool.length,u=1<=1&&v>=0;){if(v<=0)throw new Error("TTL reached.");if(E==h)E-=u;else{let S=wt(e,this.pool[E]);switch(S){case 0:{v=0;break}case 1:{E+u<=h&&(E+=u);break}case-1:{E!=0&&(E-=u);break}default:console.warn(`Unexpected result ${S}.`)}}u=u>>1,v--}let k=!0;if(E>=this.pool.length)k=!1;else{let S=this;this.pool[E].forEach(function(a,c,f){k&&a!=e[c]&&(k=!1)}),!k&&wt(e,this.pool[E])>0&&E++}return k||r?E:-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 j,kt,St=(kt=class{constructor(){C(this,j,{})}addEventListener(y,e){t(this,j)[y]||(t(this,j)[y]=[]),t(this,j)[y].unshift(e)}removeEventListener(y,e){if(t(this,j)[y]){let r=t(this,j)[y].indexOf(e);r>-1&&t(this,j)[y].splice(r,1),t(this,j)[y].length<1&&delete t(this,j)[y]}}dispatchEvent(y,e){var u;let r=new Event(y),h=this;r.data=e,((u=t(this,j)[y])==null?void 0:u.length)>0&&t(this,j)[y].forEach(function(E){try{E==null||E.call(h,r)}catch(v){console.error(v)}}),this[`on${y}`]&&this[`on${y}`](r)}},j=new WeakMap,kt);var jt=["MSB","PRG","LSB","NME","ELC","DRM"],ht=function(y){let e=Math.floor(y/10),r=y%10;return`${e.toString(16)}${r}`},Q,xt,ut=(xt=class{constructor(...y){C(this,Q,void 0);T(this,"strictMode",!1);this.loadFiles(...y)}get(y=0,e=0,r=0,h){var l,m;let u=[y,e,r],E,v=1,k=0,S,a=Array.from(arguments);switch(h){case"xg":{switch(y){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":case"sc":{y==0&&r<5?a[2]=0:y>125&&r<5&&r!=2&&(a[2]=y,a[0]=0);break}case"g2":case"sd":{y>>1==40?a[2]|=16:y>95&&y<100&&(a[2]|=16,e>>4==7&&(a[0]=96));break}case"sg":{y==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=" ",f="M",s=0,i=0;switch(a[0]){case 0:{a[2]==127?f="MT-a":a[2]==126?f="MT-b":a[2]==7?f="GM-k":a[2]==5?f="SG-a":a[2]==4?f="SP-l":a[2]==0||(h=="gs"||h=="sc")&&a[2]<5?f="GM-a":(f="y",s=3);break}case 8:{h=="sg"?f="GM-s":f="r:";break}case 32:case 33:case 34:case 35:case 36:{h=="xg"&&(f=`${["AP","VL","PF","DX","AN"][y&7]}-${"abcdefgh"[r]}`);break}case 48:{f=`yM${(a[2]>>3).toString().padStart(2,"0")}`,s=1;break}case 56:{f="GM-b";break}case 57:f=["yDOC","QY10","QY20"][a[2]-112]||"yMxv";case 61:case 120:{f="rDrm";break}case 62:{f="kDrm";break}case 63:{if(a[2]<17){let $=a[2];f=$<10?"kP:":"kC:",f+=$%10}else a[2]<34?f=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][a[2]-17]:f="Ds";break}case 64:{f="ySFX";break}case 67:{f="DX:S";break}case 80:case 81:case 82:case 83:{f=`Prg${"UABC"[a[0]-80]}`;break}case 88:case 89:case 90:case 91:{f=`Cmb${"UABC"[a[0]-88]}`;break}case 95:{f=`${["DR","PC"][a[2]]}-d`;break}case 96:{f=a[2]==106?"AP-a":a[2]>>4==1?"SDg":"PF",a[2]>63?i=63:a[2]>>4==1&&(i=16),s=3;break}case 97:{f=a[2]>>4==1?"SDa":"VL:",s=3,a[2]>>4==1?i=16:i=112;break}case 98:{f=a[2]>>4==1?"SDb":"SG-a",s=3,i=16;break}case 99:{f=a[2]>>4==1?"SDc":"DX",a[2]>63?i=63:a[2]>>4==1&&(i=16),s=3;break}case 100:{f="AN",a[2]>63?i=63:a[2]>>4==1&&(i=16),s=3;break}case 104:case 105:case 106:case 107:{f="SDd",i=104;break}case 121:{f=`GM-${a[2]?"":"a"}`,s=3;break}case 122:{f="lDrm";break}case 126:{f="yDrS";break}case 127:{a[2]==127?f="rDrm":f="yDrm";break}default:a[0]<48?f="r:":f="M"}f.length<4&&(f+=`${[y,r,a[0],a[2]][s]-i}`.padStart(4-f.length,"0")),h=="xg"&&(y==0?a[2]<100?f=f.replace("y0","y:"):a[2]==125&&(f="y126"):y==16?(E=`Voice${((a[2]<<7)+a[1]+1).toString().padStart(3,"0")}`,c=" "):y==35&&r>>1==2&&(E=`DXCH_${(((a[2]&1)<<7)+e+1).toString().padStart(3,"0")}`,c=" "));let o=[a[0],a[1],a[2]];for(;!((E==null?void 0:E.length)>=0);)if(E=(l=t(this,Q)[a[1]||0][(a[0]<<7)+a[2]])==null?void 0:l.name,E){let $=t(this,Q)[a[1]||0][(a[0]<<7)+a[2]];v=($==null?void 0:$.poly)||v,k=($==null?void 0:$.type)||k,S=$==null?void 0:$.drum}else if(this.strictMode)E="",c="?";else if(a[0]==0&&a[1]==0&&a[2]==0)E="Unloaded";else if(t(this,Q)[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(y==48)a[0]=0,a[2]=0,c="!";else if(y==62)a[1]--,c=" ",a[1]<1&&!(E!=null&&E.length)&&(a[0]=0,c="!");else if(y<63)a[0]==0?(a[2]=0,c="^"):a[2]<1?(a[0]=0,c="*"):a[2]--;else if(y==80)E=`PrgU:${e.toString().padStart(3,"0")}`,c="!";else if(y==88)E=`CmbU:${e.toString().padStart(3,"0")}`,c="!";else if(y==121)E=`GM2Vox0${r}`,c="#";else if(y==122)if(a[1]==32?a[1]==0:a[1]%=7,E=(m=t(this,Q)[a[1]||0][(a[0]<<7)+a[2]])==null?void 0:m.name,E){c=" ";let $=t(this,Q)[a[1]||0][(a[0]<<7)+a[2]];v=($==null?void 0:$.poly)||v,k=($==null?void 0:$.type)||k,S=$==null?void 0:$.drum}else E="",c="*";else a[1]==0?(E=`${y.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 n=[a[0],a[1],a[2]];(h=="gs"||h=="sc"||h=="ns5r")&&c=="^"&&(c=" "),y==127&&c=="^"&&(c=" "),c!=" "&&self.debugMode&&(E="");let d="??";switch(a[0]){case 0:{a[2]==0?d="GM":a[2]==5||a[2]==7?d="KG":a[2]<126?d="XG":a[2]==127&&(d="MT");break}case 32:case 33:case 35:case 36:{a[2]>4?d=["AP","VL","PF","DX","AN"][a[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:{a[2]<17?d="KR":a[2]<34?d="ES":d="DS";break}case 64:case 126:{d="XG";break}case 67:case 99:{d=a[2]>>4==1?"SD":"DX";break}case 81:{d="RW";break}case 95:{d=["DR","PC"][a[2]];break}case 96:{d=a[2]==106?"AP":a[2]>>4==1?"SD":"PF";break}case 97:{d=a[2]>>4==1?"SD":"VL";break}case 98:{d=a[2]>>4==1?"SD":"SG";break}case 100:{d="AN";break}case 104:case 105:case 106:case 107:{d="SD";break}case 120:{d="GS";break}case 121:{d=a[2]?"G2":"GM";break}case 122:{d="KG";break}case 127:{d=a[2]==127?"MT":e==0?"GM":"XG";break}default:a[0]<48&&(a[0]==16&&h=="xg"?d="XG":d="GS")}return{name:E||`${ht(y||0)} ${ht(e||0)} ${ht(r||0)}`,poly:v,type:k,drum:S,iid:o,eid:n,sid:u,ending:c,sect:f,standard:d}}async load(y,e,r="(internal)"){let h=this,u=[],E=0,v=0;y.split(` +`).forEach(function(k,S){let a=k.split(" "),c=[];if(S==0){if(a.forEach(function(f,s){u[jt.indexOf(f)]=s}),u.length<4){console.debug("Debugger launched.");debugger}}else{let f=0,s=0,i=0,o,n=1,d=0,l;a.forEach(async function($,M){switch(M){case u[0]:{f=parseInt($);break}case u[1]:{s=parseInt($);break}case u[2]:{i=parseInt($);break}case u[3]:{o=$;break}case u[4]:{$=parseInt($),$<16?n=$+1:d=($&15)+1;break}case u[5]:{l=$;break}}}),t(h,Q)[s]=t(h,Q)[s]||[];let m=t(h,Q)[s];if(!m[f<<7|i]||e){let $={msb:f,prg:s,lsb:i,name:o,poly:n,type:d,drum:l};m[f<<7|i]=$,E++}v++}}),e||console.debug(`Map "${r}": ${v} total, ${E} loaded.`)}clearRange(y){let e=y.prg!=null?y.prg.constructor==Array?y.prg:[y.prg,y.prg]:[0,127],r=y.msb!=null?y.msb.constructor==Array?y.msb:[y.msb,y.msb]:[0,127],h=y.lsb!=null?y.lsb.constructor==Array?y.lsb:[y.lsb,y.lsb]:[0,127];for(let u=r[0];u<=r[1];u++){let E=u<<7;for(let v=h[0];v<=h[1];v++){let k=E+v;for(let S=e[0];S<=e[1];S++)delete t(this,Q)[S][k]}}}init(){x(this,Q,[]);for(let y=0;y<128;y++)t(this,Q).push([""])}async loadFiles(...y){this.init();let e=this;y.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".`)}})}},Q=new WeakMap,xt);var Xe,Ct,Mt=(Ct=class{constructor(){C(this,Xe,{});T(this,"context")}set(y,e){t(this,Xe)[y]=e}has(y){return!!t(this,Xe)[y]}async read(y,e){if(!this.has(y))throw new Error(`No decoder registered for "${y}"`);return await t(this,Xe)[y].call(this.context||this,e)}},Xe=new WeakMap,Ct);var Jt=function(y,e){let r=!0;return e.forEach((h,u)=>{r=r&&y[u]==h}),r},je=function(y){let e=0;return y.forEach(r=>{e*=256,e+=r}),e},Ee=new TextDecoder,Je=new Mt;Je.set("s7e",async function(y){let e=new Uint8Array(await y.slice(0,65536).arrayBuffer()),r="MSB LSB PRG NME",h=[0,0,0,0],u=32,E=0,v=0,k=!0,S=[],a=0;for(;k;){let c=e.subarray(E);([()=>{Ee.decode(c.subarray(0,4))=="YSFC"?(E+=80,v=1):E++},()=>{if(Jt(c.subarray(0,4),h))S.forEach((f,s,i)=>{let o=je(e.subarray(f.start+4,f.start+8));f.length=o}),v=2;else{let f=Ee.decode(c.subarray(0,4)),s=je(c.subarray(4,8));S.push({type:f,start:s}),E+=8}},()=>{let f=S[a],s=e.subarray(f.start,f.start+f.length),i=32;switch(f.type){case"ENVC":{let o=u;for(;o=S.length&&(v=3,k=!1)}][v]||(()=>{k=!1}))()}return r});Ze.set("pcg",async function(y){let e=new Uint8Array(await y.arrayBuffer()),r="MSB LSB PRG NME",h=100,u=0,E=0,v=!0,k=[],S=0;for(;v;){let a=e.subarray(h);([()=>{v=Ee.decode(a.subarray(0,4))=="INI2",E=a[15],h+=16,u=1},()=>{let c=Ee.decode(a.subarray(0,4)),f=a[5],s=a[7],i=a[11],o=Je(a.subarray(12,16)),n=Je(a.subarray(16,20)),d=Je(a.subarray(36,40)),l=Ee.decode(a.subarray(44,44+i));k.push({type:c,tipMsb:f,tipLsb:s,nameLen:i,length:o,start:n,entryLen:d,name:l}),h+=64,E--,E<1&&(u=2)},()=>{let c=k[S],f=e.subarray(c.start,c.start+c.length);switch(c.type){case"PRG1":break;case"PBK1":{let s=63,i=(c.tipMsb?6:0)+c.tipLsb;for(let o=0;o<128;o++){let n=o*c.entryLen,d=f.subarray(n,n+c.entryLen),l=Ee.decode(d.subarray(0,24)).trimEnd().replace("InitProg","");l.length&&i>5&&(r+=` +063 ${(d[17]+1).toString().padStart(3,"0")} ${d[19].toString().padStart(3,"0")} ${l}`),n+=o}break}}a++,a>=S.length&&(v=3,k=!1)}][v]||(()=>{k=!1}))()}return r});Je.set("pcg",async function(y){let e=new Uint8Array(await y.arrayBuffer()),r="MSB LSB PRG NME",h=100,u=0,E=0,v=!0,k=[],S=0;for(;v;){let a=e.subarray(h);([()=>{v=Ee.decode(a.subarray(0,4))=="INI2",E=a[15],h+=16,u=1},()=>{let c=Ee.decode(a.subarray(0,4)),f=a[5],s=a[7],i=a[11],o=je(a.subarray(12,16)),n=je(a.subarray(16,20)),d=je(a.subarray(36,40)),l=Ee.decode(a.subarray(44,44+i));k.push({type:c,tipMsb:f,tipLsb:s,nameLen:i,length:o,start:n,entryLen:d,name:l}),h+=64,E--,E<1&&(u=2)},()=>{let c=k[S],f=e.subarray(c.start,c.start+c.length);switch(c.type){case"PRG1":break;case"PBK1":{let s=63,i=(c.tipMsb?6:0)+c.tipLsb;for(let o=0;o<128;o++){let n=o*c.entryLen,d=f.subarray(n,n+c.entryLen),l=Ee.decode(d.subarray(0,24)).trimEnd().replace("InitProg","");l.length&&i>5&&(r+=` ${s.toString().padStart(3,"0")} ${i.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")} ${l}`)}break}case"CBK1":{let s=63,i=(c.tipMsb?3:0)+c.tipLsb+10;for(let o=0;o<128;o++){let n=o*c.entryLen,d=f.subarray(n,n+c.entryLen),l=Ee.decode(d.subarray(0,24)).trimEnd().replace("InitCombi","");l.length&&i>12&&(r+=` -${s.toString().padStart(3,"0")} ${i.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")} ${l}`)}break}}S++,S>=k.length&&(u=3,v=!1)}][u]||(()=>{v=!1}))()}return r});var je=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),et=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],jt=[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],Ve=[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],Tt=[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],Rt=function(y){let e=.1,r=-.3;return y>66?(e=5,r=315):y>56?(e=1,r=47):y>46&&(e=.5,r=18.5),e*y-r},Dt=function(y){return y>105?jt[y-106]:y>100?y*1.1-100:y/10},Pt=",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(","),pt={};`hi*, +${s.toString().padStart(3,"0")} ${i.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")} ${l}`)}break}}S++,S>=k.length&&(u=3,v=!1)}][u]||(()=>{v=!1}))()}return r});var Ze=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),et=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],Zt=[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],Ve=[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],Tt=[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],Rt=function(y){let e=.1,r=-.3;return y>66?(e=5,r=315):y>56?(e=1,r=47):y>46&&(e=.5,r=18.5),e*y-r},Dt=function(y){return y>105?Zt[y-106]:y>100?y*1.1-100:y/10},Pt=",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(","),pt={};`hi*, ka,か ki,き ku,く @@ -141,7 +141,7 @@ o,お ~, ^, _,`.split(` -`).forEach(y=>{let e=y.split(",");pt[e[0]]=e[1]});var Ot=function(y){let e=y;y[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 pt)e=e.replaceAll(h,pt[h]);e.indexOf("ん")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},At=function(y){return y?y<96?`cc${y}`:["aftertouch","velocity","pitch bend"][y-96]:"off"};var bt=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],Lt=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],Ut=["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 ea={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"},ta={66307:["drive"],66309:["vowel",y=>"aiueo"[y]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",y=>["off","LPF","HPF"][y]],94984:["noise type",y=>["white","pink"][y]],94987:["disc type",y=>["LP","SP","EP","RND"]],94990:["hum type",y=>`${y+5}0Hz`],94993:["M/S",y=>["mono","stereo"][y]]},gt=function(y){return ea[(y[0]-32<<8)+y[1]]||`0x${y[0].toString(16).padStart(2,"0")}${y[1].toString(16).padStart(2,"0")}`},Bt=function(y,e,r){let h=(y[0]-32<<16)+(y[1]<<8)+e,u=ta[h]||{},E=u[0];if(E!=null&&E.length)return E+=`: ${(u[1]||function(){})(r)||r}`,E},Et=[68,48,95,78,41,3,110,122,0];var Z=function(y=64){return Math.round(2e3*Math.log10(y/64))/100};var xe=function(y){let e=0;return y.forEach(r=>{e+=r,e=e&127}),~e+1&127},le=function(y,e){let r=0,h=0;for(let u=0;u>E&1)<<7,k=y[u];k+=v,u%8!=0?(e(k,r,y),r++):h=y[u]}};var tt=function(y){let e=Math.floor(y*14.2);return e<128?e:0},P=function(){return!!self.Bun||self.debugMode||!1};var K=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"],aa={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",trinity:"trin","tr-rack":"trin"},ra=["melodic","drum","menu"],Ht={"?":[0,0,120],gm:[0,0,127],gs:[0,0,120],sc:[0,0,120],xg:[0,0,127],g2:[0,0,120],mt32:[0,127,127],doc:[57,112,127],qy10:[57,113,127],qy20:[57,114,127],ns5r:[0,0,61],x5d:[82,0,62],"05rw":[81,0,62],k11:[0,0,122],sg:[0,0,122],sd:[97,0,105],krs:[63,0,120],s90es:[63,0,127],motif:[63,0,127],trin:[63,0,127]};var yt=[120,127,120,127,120,127,127,61,62,62,122,122,105,120,127,127,127],Nt=[9,25,41,57,73,89,105,121],sa=[0,3,81,84,88],It={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},_t={0:0,1:1,2:3,5:4},Gt={0:0,1:1,2:2,5:3},Xt=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Vt=[36,37,48,49,52,53],ft=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Ft={26:127,29:0,30:0,31:0,52:12,53:54},at=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19,14,15,20,21,26,28,80,81,83,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],ia=[2,12,13,14,15,16,17,18,19,20,21,80,81,83,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],ca=[33,99,100,32,102,8,9,10],Kt=[0,16,25,40,32,64,26,48],w={};K.forEach((y,e)=>{w[y]=e});var b={length:at.length};at.forEach((y,e)=>{b[y]=e});var de={length:ft.length};ft.forEach((y,e)=>{de[y]=e});var na={};ra.forEach((y,e)=>{na[y]=e});var oa=function(y){let e=[],r=0;return y==null||y.forEach(function(h,u){h==247?e.push(y.subarray(r,u)):h==240&&(r=u+1)}),e.length||e.push(y.subarray(0)),P()&&console.debug(e),e};var zt=8,g={port:zt,ch:zt<<4,cc:at.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:ft.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255},Fe={bank0:128},O,W,fe,we,se,ve,qt,ie,G,D,p,ce,A,X,j,V,z,ke,ye,Oe,ee,R,L,Ke,Y,he,te,ze,Ae,I,Ce,ue,rt,Me,pe,We,Te,F,B,me,st,H,Le,qe,Qe,Re,De,it,Ye,be,N,lt,ct,Ue,mt,ae,Se,Pe,q,Be,_,nt,dt,He,Ne,re,ne,$e,Ie,_e,Ge,Wt,qa=(Wt=class extends St{constructor(){super();C(this,se);T(this,"NOTE_IDLE",0);T(this,"NOTE_ATTACK",1);T(this,"NOTE_DECAY",2);T(this,"NOTE_SUSTAIN",3);T(this,"NOTE_HELD",4);T(this,"NOTE_RELEASE",5);T(this,"NOTE_SOSTENUTO_ATTACK",8);T(this,"NOTE_SOSTENUTO_DECAY",9);T(this,"NOTE_SOSTENUTO_SUSTAIN",10);T(this,"NOTE_SOSTENUTO_HELD",11);T(this,"CH_MELODIC",0);T(this,"CH_DRUMS",1);T(this,"CH_DRUM1",2);T(this,"CH_DRUM2",3);T(this,"CH_DRUM3",4);T(this,"CH_DRUM4",5);T(this,"CH_DRUM5",6);T(this,"CH_DRUM6",7);T(this,"CH_DRUM7",8);T(this,"CH_DRUM8",9);T(this,"DUMP_ALL",0);T(this,"DUMP_ONCE",1);T(this,"DUMP_MODE",2);T(this,"EXT_NONE",0);T(this,"EXT_VL",1);T(this,"EXT_DX",3);T(this,"VLBC_BRTHEXPR",1);T(this,"VLBC_VELOINIT",2);T(this,"VLBC_VELOALL",3);T(this,"CH_INACTIVE",0);T(this,"CH_ACTIVE",1);T(this,"CH_DISABLED",2);C(this,O,0);C(this,W,0);C(this,fe,0);C(this,we,new Array(11));C(this,ie,new Uint8Array(g.ch));C(this,G,new Uint8Array(g.ch));C(this,D,new Uint8Array(g.ch));C(this,p,new Uint8Array(g.ch*g.cc));C(this,ce,new Uint8Array(g.ace));C(this,A,new Uint8Array(g.ch));C(this,X,new Uint8Array(g.ch*g.nn));C(this,j,new Uint8Array(g.ch));C(this,V,new Uint16Array(g.pl));C(this,z,new Uint8Array(g.pl));C(this,ke,new Int16Array(g.ch));C(this,ye,new Uint8Array(g.ch));C(this,Oe,0);C(this,ee,new Uint8Array(g.ch*g.ext));C(this,R,new Uint8Array(g.ch*g.rpn));C(this,L,new Uint8Array(g.ch*g.rpnt));C(this,Ke,new Int8Array(g.ch*Vt.length));C(this,Y,new Uint8Array(g.drm*g.dpn*g.dnc));C(this,he,new Uint8Array(g.drm*2));C(this,te,new Uint8Array(g.efx*3));C(this,ze,new Uint8Array(g.ch));C(this,Ae,new Uint8Array(g.ch*g.redir));C(this,I,new Uint8Array(g.port));C(this,Ce,new Uint8Array(g.ch));C(this,ue,new Uint8Array(g.ch));C(this,rt,new Uint8Array(g.ch*g.cvn));C(this,Me,new Uint8Array(128));C(this,pe,new Uint8Array(g.cmt*8));C(this,We,new Uint8Array(1024));C(this,Te,new Uint8Array(g.cmt*64));C(this,F,{});C(this,B,void 0);C(this,me,void 0);C(this,st,void 0);C(this,H,100);C(this,Le,0);C(this,qe,500);C(this,Qe,0);C(this,Re,"");C(this,De,0);C(this,it,0);C(this,Ye,0);C(this,be,!0);C(this,N,!1);C(this,lt,1);C(this,ct,void 0);C(this,Ue,new Array(g.ch));C(this,mt,new Uint8Array(2));C(this,ae,[]);C(this,Se,new Uint8Array(g.ch));C(this,Pe,new Uint8Array(g.tr));T(this,"baseBank",new ut("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es"));T(this,"userBank",new ut("gm"));T(this,"initOnReset",!1);T(this,"aiEfxName","");C(this,q,[]);C(this,Be,void 0);C(this,_,{nOff:(e,r)=>{let h=e*128+r,u=t(this,V).lastIndexOf(h);if(u>-1)if(t(this,p)[g.cc*e+b[64]]>63)t(this,z)[u]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,X)[h],state:this.NOTE_HELD});else if(t(this,p)[g.cc*e+b[66]]>63&&t(this,z)[u]==this.NOTE_SOSTENUTO_SUSTAIN)t(this,z)[u]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,X)[h],state:this.NOTE_SOSTENUTO_HELD});else{t(this,V)[u]=0,t(this,X)[h]=0,t(this,z)[u]=this.NOTE_IDLE;let E=this.getExt(e)[1];(E==this.VLBC_VELOINIT||E==this.VLBC_VELOALL)&&(t(this,p)[g.cc*e+b[129]]=0),this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})}},nOn:(e,r,h)=>{let u=e*128+r,E=0;for(t(this,j)[e]&&t(this,_).ano(e);t(this,z)[E]>0&&t(this,V)[E]!=u;)E++;if(E{},cAt:(e,r)=>{},hoOf:e=>{t(this,z).forEach((r,h)=>{if(r==this.NOTE_HELD){let u=t(this,V)[h],E=u>>7;e==E&&(t(this,z)[h]=this.NOTE_IDLE,t(this,V)[h]=0,t(this,X)[u]=0,this.dispatchEvent("note",{part:e,note:u&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,z).forEach((r,h)=>{let u;switch(r){case this.NOTE_ATTACK:{u=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{u=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{u=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(u){t(this,z)[h]=u;let E=t(this,V)[h];this.dispatchEvent("note",{part:e,note:E&127,velo:t(this,X)[E],state:u})}})},soOf:e=>{t(this,z).forEach((r,h)=>{if(r==this.NOTE_SOSTENUTO_HELD){let u=t(this,V)[h],E=u>>7;e==E&&(t(this,z)[h]=this.NOTE_IDLE,t(this,V)[h]=0,t(this,X)[u]=0,this.dispatchEvent("note",{part:e,note:u&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,V).forEach((r,h,u)=>{let E=r>>7,v=r&127;r==0&&t(this,X)[0]==0||E==e&&t(this,_).nOff(E,v)})}});C(this,nt,{8:function(e){let r=e.channel,h=e.data[0];t(this,_).nOff(r,h)},9:function(e){let r=e.channel,h=this;if(h.getChModeId(r)==w.xg&&t(h,D)[r]>1){let v=h.getChDrumFirstWrite(r);v[0]&&v[1]!=g.invalidCh&&!t(h,ie)[r]&&(h.copyChSetup(v[1],r),h.dispatchEvent("voice",{part:r}),console.debug(`Part CH${r+1} copied from CH${v[1]}.`))}h.setChActive(r,1);let u=e.data[0],E=e.data[1];E>0?t(h,_).nOn(r,u,E):t(h,_).nOff(r,u)},10:function(e){let r=e.channel,h=r*128+e.data[0];t(this,V).indexOf(h)>-1&&(t(this,X)[h]=data[1],this.getExt(r)[1]==this.VLBC_VELOALL&&(t(this,p)[g.cc*r+b[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=this,u=t(this,Ue)[r],E=u[e.data[0]];E&&(e.data[0]=E),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,O)){case w.s90es:case w.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 v=r*g.cc,k=r*g.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,_).ano(r),t(this,ke)[r]=0,t(this,p)[v+b[1]]=0,t(this,p)[v+b[5]]=0,t(this,p)[v+b[64]]=0,t(this,p)[v+b[65]]=0,t(this,p)[v+b[66]]=0,t(this,p)[v+b[67]]=0,t(this,p)[v+b[11]]=127,t(this,p)[v+b[101]]=127,t(this,p)[v+b[100]]=127,t(this,p)[v+b[99]]=127,t(this,p)[v+b[98]]=127;return}case 123:{t(this,_).ano(r);return}case 124:{t(this,_).ano(r);return}case 125:{t(this,_).ano(r);return}case 126:{t(this,j)[r]=1,t(this,_).ano(r);return}case 127:{t(this,j)[r]=0,t(this,_).ano(r);return}}if(b[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(ia.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(P()&&console.debug(`${K[t(this,O)]}, CH${r+1}: ${e.data[1]}`),t(this,O)==0?e.data[1]<48?(t(this,D)[r]>0&&(e.data[1]=t(this,p)[v],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]==56?this.switchMode(t(this,B).x5==82?"x5d":"05rw"):e.data[1]==62?this.switchMode(t(this,B).x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(K[t(this,B).ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,O)==w.gs||t(this,O)==w.sc?e.data[1]<56&&t(this,D)[r]>0&&(e.data[1]=t(this,p)[v],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):t(this,O)==w.gm&&(e.data[1]<48?t(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)),t(this,O)){case w.xg:{[79,95,126,127].indexOf(e.data[1])>-1?t(this,D)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(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?t(this,ee)[k]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?t(this,ee)[k]=this.EXT_DX:t(this,ee)[k]=this.EXT_NONE;break}case w["05rw"]:case w.x5d:case w.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(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||t(this,D)[r]!=this.CH_MELODIC&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case w.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,D)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,D)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case w.g2:{e.data[1]==120?t(this,D)[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):t(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&&(t(this,p)[v+b[129]]=e.data[1]);break}case 6:{if(t(this,Oe)){[w.xg,w.gs,w.sc,w.ns5r].indexOf(t(this,O))<0&&console.warn(`NRPN commits are not available under "${K[t(this,O)]}" mode, even when they are supported in Octavia.`);let S=t(this,p)[v+b[99]],a=t(this,p)[v+b[98]];if(S==1){let c=ca.indexOf(a);if(c>-1)t(this,p)[v+b[71+c]]=e.data[1],P()&&console.debug(`Redirected NRPN 1 ${a} to cc${71+c}.`),this.dispatchEvent("cc",{part:r,cc:71+c,data:e.data[1]});else{let f=Vt.indexOf(a);f>-1?t(this,Ke)[r*10+f]=e.data[1]-64:console.warn(`NRPN 0x01${a.toString(16).padStart(2,"0")} is not supported.`),P()&&console.debug(`CH${r+1} voice NRPN ${a} commit`)}}else{if(ft.indexOf(S)<0){let f=`NRPN 0x${S.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")} `;S==127?console.warn(`${f}is not necessary. Consider removing it.`):console.warn(`${f}is not supported.`)}else{let f=t(this,D)[r]-2;f<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${et[t(this,D)[r]]}.`):t(this,Y)[(f*g.dpn+de[S])*g.dnc+a]=e.data[1]}P()&&console.debug(`CH${r+1} (${et[t(this,D)[r]]}) drum NRPN ${S} commit`)}}else{let S=_t[t(this,p)[v+b[100]]],a=Gt[t(this,p)[v+b[100]]];t(this,p)[v+b[101]]==0&&S!=null&&(P()&&console.debug(`CH${r+1} RPN 0 ${t(this,p)[v+b[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Xt[S][0]),Xt[S][1]),t(this,R)[r*g.rpn+S]=e.data[1],t(this,L)[r*g.rpnt+a]=1,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)}))}break}case 32:{switch(P()&&console.debug(`${K[t(this,O)]}, CH${r+1} LSB: ${e.data[1]}`),t(this,O)){case w.s90es:case w.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,O),!0);break}}this.getExt(r)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:r});break}case 38:{if(!t(this,Oe)){let S=_t[t(this,p)[v+100]],a=Gt[t(this,p)[v+100]];t(this,p)[v+101]==0&&S!=null&&(t(this,R)[r*g.rpn+S+1]=e.data[1],t(this,L)[r*g.rpnt+a]=1)}break}case 64:{e.data[1]<64&&t(this,_).hoOf(r);break}case 66:{e.data[1]>>6?t(this,_).soOn(r):t(this,_).soOf(r);break}case 98:case 99:{x(this,Oe,1);break}case 100:case 101:{x(this,Oe,0);break}}t(this,p)[v+b[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:r,cc:e.data[0],data:e.data[1]})}h.getChModeId(r)==w.xg&&t(h,D)[r]&&h.setDrumFirstWrite(r)},12:function(e){let r=e.channel,h=this;switch(t(h,O)){case w.s90es:case w.motif:{e.data&&h.setChActive(r,1);break}default:h.setChActive(r,1)}if(h.getExt(r)[0]==h.EXT_DX){let u=g.cc*r}t(h,A)[r]=e.data,t(h,ue)[r]=0,P()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),h.dispatchEvent("voice",{part:r}),h.getChModeId(r)==w.xg&&t(h,D)[r]&&h.setDrumFirstWrite(r)},13:function(e){let r=this,h=e.channel;t(this,V).forEach(function(u){let E=u>>7;h==E&&(t(r,X)[u]=e.data,r.dispatchEvent("note",{part:h,note:u&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;t(this,ke)[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){oa(e.data).forEach(r=>{let h=r[0],u=r[1];(t(this,dt)[h]||function(){console.debug(`Unknown manufacturer ${h}.`)})(u,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(h,u,E){}).call(this,e.data,e.track,e.meta),e.meta!=32&&x(this,Le,0);let r=sa.indexOf(e.meta)>-1;if(P()&&console.debug(e),r)return e.reply="meta",e}});C(this,dt,{64:(e,r,h)=>{t(this,Ie).run(r,h,e)},65:(e,r,h)=>{if(r[0]<16)if(r[1]==72){let u=r[r.length-1],E=xe(r.subarray(3,r.length-1));u==E?t(this,ne).run(r.subarray(0,r.length-1),h,e):console.warn(`Bad SD checksum ${u} - should be ${E}.`)}else t(this,ne).run(r,h,e);else{let u=r[r.length-1],E=xe(r.subarray(2,r.length-1));u==E?t(this,ne).run(r.subarray(0,r.length-1),h,e):console.warn(`Bad GS checksum ${u} - should be ${E}.`)}},66:(e,r,h)=>{t(this,$e).run(r,h,e)},67:(e,r,h)=>{t(this,re).run(r,h,e)},68:(e,r,h)=>{t(this,Ge).run(r,h,e)},71:(e,r,h)=>{t(this,_e).run(r,h,e)},126:(e,r,h)=>{t(this,He).run(r,h,e)},127:(e,r,h)=>{this.switchMode("gm"),t(this,Ne).run(r,h,e)}});C(this,He,void 0);C(this,Ne,void 0);C(this,re,void 0);C(this,ne,void 0);C(this,$e,void 0);C(this,Ie,void 0);C(this,_e,void 0);C(this,Ge,void 0);let e=this;x(e,se,new Uint8Array(256),qt),t(e,we)[10]=new Uint8Array(512),x(e,Be,new oe),x(e,B,{x5:82,ds:w.krs,smotif:w.s90es,gs:4,sc:3}),x(e,me,{dumpLimit:e.DUMP_MODE}),x(e,st,new Proxy(t(e,me),{set:()=>{}}));for(let a in Ht){let c=w[a];c==null?console.debug(`SubDB build error: "${a}" does not exist`):t(e,F)[c]=new Uint8Array(Ht[a])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME +`).forEach(y=>{let e=y.split(",");pt[e[0]]=e[1]});var Ot=function(y){let e=y;y[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 pt)e=e.replaceAll(h,pt[h]);e.indexOf("ん")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},At=function(y){return y?y<96?`cc${y}`:["aftertouch","velocity","pitch bend"][y-96]:"off"};var bt=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],Lt=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],Ut=["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 ea={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"},ta={66307:["drive"],66309:["vowel",y=>"aiueo"[y]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",y=>["off","LPF","HPF"][y]],94984:["noise type",y=>["white","pink"][y]],94987:["disc type",y=>["LP","SP","EP","RND"]],94990:["hum type",y=>`${y+5}0Hz`],94993:["M/S",y=>["mono","stereo"][y]]},gt=function(y){return ea[(y[0]-32<<8)+y[1]]||`0x${y[0].toString(16).padStart(2,"0")}${y[1].toString(16).padStart(2,"0")}`},Bt=function(y,e,r){let h=(y[0]-32<<16)+(y[1]<<8)+e,u=ta[h]||{},E=u[0];if(E!=null&&E.length)return E+=`: ${(u[1]||function(){})(r)||r}`,E},Et=[68,48,95,78,41,3,110,122,0];var J=function(y=64){return Math.round(2e3*Math.log10(y/64))/100};var xe=function(y){let e=0;return y.forEach(r=>{e+=r,e=e&127}),~e+1&127},le=function(y,e){let r=0,h=0;for(let u=0;u>E&1)<<7,k=y[u];k+=v,u%8!=0?(e(k,r,y),r++):h=y[u]}};var tt=function(y){let e=Math.floor(y*14.2);return e<128?e:0},P=function(){return!!self.Bun||self.debugMode||!1};var K=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"],aa={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",trinity:"trin","tr-rack":"trin"},ra=["melodic","drum","menu"],Ht={"?":[0,0,120],gm:[0,0,127],gs:[0,0,120],sc:[0,0,120],xg:[0,0,127],g2:[0,0,120],mt32:[0,127,127],doc:[57,112,127],qy10:[57,113,127],qy20:[57,114,127],ns5r:[0,0,61],x5d:[82,0,62],"05rw":[81,0,62],k11:[0,0,122],sg:[0,0,122],sd:[97,0,105],krs:[63,0,120],s90es:[63,0,127],motif:[63,0,127],trin:[63,0,127]};var yt=[120,127,120,127,120,127,127,61,62,62,122,122,105,120,127,127,127],Nt=[9,25,41,57,73,89,105,121],sa=[0,3,81,84,88],It={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},_t={0:0,1:1,2:3,5:4},Gt={0:0,1:1,2:2,5:3},Xt=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Vt=[36,37,48,49,52,53],ft=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Ft={26:127,29:0,30:0,31:0,52:12,53:54},at=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19,14,15,20,21,26,28,80,81,83,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],ia=[2,12,13,14,15,16,17,18,19,20,21,80,81,83,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],ca=[33,99,100,32,102,8,9,10],Kt=[0,16,25,40,32,64,26,48],w={};K.forEach((y,e)=>{w[y]=e});var b={length:at.length};at.forEach((y,e)=>{b[y]=e});var de={length:ft.length};ft.forEach((y,e)=>{de[y]=e});var na={};ra.forEach((y,e)=>{na[y]=e});var oa=function(y){let e=[],r=0;return y==null||y.forEach(function(h,u){h==247?e.push(y.subarray(r,u)):h==240&&(r=u+1)}),e.length||e.push(y.subarray(0)),P()&&console.debug(e),e};var zt=8,g={port:zt,ch:zt<<4,cc:at.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:ft.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255},Fe={bank0:128},O,W,fe,we,se,ve,qt,ie,G,D,p,ce,A,X,Z,V,z,ke,ye,Oe,ee,R,L,Ke,Y,he,te,ze,Ae,I,Ce,ue,rt,Me,pe,We,Te,F,B,me,st,H,Le,qe,Qe,Re,De,it,Ye,be,N,lt,ct,Ue,mt,ae,Se,Pe,q,Be,_,nt,dt,He,Ne,re,ne,$e,Ie,_e,Ge,Wt,qa=(Wt=class extends St{constructor(){super();C(this,se);T(this,"NOTE_IDLE",0);T(this,"NOTE_ATTACK",1);T(this,"NOTE_DECAY",2);T(this,"NOTE_SUSTAIN",3);T(this,"NOTE_HELD",4);T(this,"NOTE_RELEASE",5);T(this,"NOTE_SOSTENUTO_ATTACK",8);T(this,"NOTE_SOSTENUTO_DECAY",9);T(this,"NOTE_SOSTENUTO_SUSTAIN",10);T(this,"NOTE_SOSTENUTO_HELD",11);T(this,"CH_MELODIC",0);T(this,"CH_DRUMS",1);T(this,"CH_DRUM1",2);T(this,"CH_DRUM2",3);T(this,"CH_DRUM3",4);T(this,"CH_DRUM4",5);T(this,"CH_DRUM5",6);T(this,"CH_DRUM6",7);T(this,"CH_DRUM7",8);T(this,"CH_DRUM8",9);T(this,"DUMP_ALL",0);T(this,"DUMP_ONCE",1);T(this,"DUMP_MODE",2);T(this,"EXT_NONE",0);T(this,"EXT_VL",1);T(this,"EXT_DX",3);T(this,"VLBC_BRTHEXPR",1);T(this,"VLBC_VELOINIT",2);T(this,"VLBC_VELOALL",3);T(this,"CH_INACTIVE",0);T(this,"CH_ACTIVE",1);T(this,"CH_DISABLED",2);C(this,O,0);C(this,W,0);C(this,fe,0);C(this,we,new Array(11));C(this,ie,new Uint8Array(g.ch));C(this,G,new Uint8Array(g.ch));C(this,D,new Uint8Array(g.ch));C(this,p,new Uint8Array(g.ch*g.cc));C(this,ce,new Uint8Array(g.ace));C(this,A,new Uint8Array(g.ch));C(this,X,new Uint8Array(g.ch*g.nn));C(this,Z,new Uint8Array(g.ch));C(this,V,new Uint16Array(g.pl));C(this,z,new Uint8Array(g.pl));C(this,ke,new Int16Array(g.ch));C(this,ye,new Uint8Array(g.ch));C(this,Oe,0);C(this,ee,new Uint8Array(g.ch*g.ext));C(this,R,new Uint8Array(g.ch*g.rpn));C(this,L,new Uint8Array(g.ch*g.rpnt));C(this,Ke,new Int8Array(g.ch*Vt.length));C(this,Y,new Uint8Array(g.drm*g.dpn*g.dnc));C(this,he,new Uint8Array(g.drm*2));C(this,te,new Uint8Array(g.efx*3));C(this,ze,new Uint8Array(g.ch));C(this,Ae,new Uint8Array(g.ch*g.redir));C(this,I,new Uint8Array(g.port));C(this,Ce,new Uint8Array(g.ch));C(this,ue,new Uint8Array(g.ch));C(this,rt,new Uint8Array(g.ch*g.cvn));C(this,Me,new Uint8Array(128));C(this,pe,new Uint8Array(g.cmt*8));C(this,We,new Uint8Array(1024));C(this,Te,new Uint8Array(g.cmt*64));C(this,F,{});C(this,B,void 0);C(this,me,void 0);C(this,st,void 0);C(this,H,100);C(this,Le,0);C(this,qe,500);C(this,Qe,0);C(this,Re,"");C(this,De,0);C(this,it,0);C(this,Ye,0);C(this,be,!0);C(this,N,!1);C(this,lt,1);C(this,ct,void 0);C(this,Ue,new Array(g.ch));C(this,mt,new Uint8Array(2));C(this,ae,[]);C(this,Se,new Uint8Array(g.ch));C(this,Pe,new Uint8Array(g.tr));T(this,"baseBank",new ut("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es"));T(this,"userBank",new ut("gm"));T(this,"initOnReset",!1);T(this,"aiEfxName","");C(this,q,[]);C(this,Be,void 0);C(this,_,{nOff:(e,r)=>{let h=e*128+r,u=t(this,V).lastIndexOf(h);if(u>-1)if(t(this,p)[g.cc*e+b[64]]>63)t(this,z)[u]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,X)[h],state:this.NOTE_HELD});else if(t(this,p)[g.cc*e+b[66]]>63&&t(this,z)[u]==this.NOTE_SOSTENUTO_SUSTAIN)t(this,z)[u]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,X)[h],state:this.NOTE_SOSTENUTO_HELD});else{t(this,V)[u]=0,t(this,X)[h]=0,t(this,z)[u]=this.NOTE_IDLE;let E=this.getExt(e)[1];(E==this.VLBC_VELOINIT||E==this.VLBC_VELOALL)&&(t(this,p)[g.cc*e+b[129]]=0),this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})}},nOn:(e,r,h)=>{let u=e*128+r,E=0;for(t(this,Z)[e]&&t(this,_).ano(e);t(this,z)[E]>0&&t(this,V)[E]!=u;)E++;if(E{},cAt:(e,r)=>{},hoOf:e=>{t(this,z).forEach((r,h)=>{if(r==this.NOTE_HELD){let u=t(this,V)[h],E=u>>7;e==E&&(t(this,z)[h]=this.NOTE_IDLE,t(this,V)[h]=0,t(this,X)[u]=0,this.dispatchEvent("note",{part:e,note:u&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,z).forEach((r,h)=>{let u;switch(r){case this.NOTE_ATTACK:{u=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{u=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{u=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(u){t(this,z)[h]=u;let E=t(this,V)[h];this.dispatchEvent("note",{part:e,note:E&127,velo:t(this,X)[E],state:u})}})},soOf:e=>{t(this,z).forEach((r,h)=>{if(r==this.NOTE_SOSTENUTO_HELD){let u=t(this,V)[h],E=u>>7;e==E&&(t(this,z)[h]=this.NOTE_IDLE,t(this,V)[h]=0,t(this,X)[u]=0,this.dispatchEvent("note",{part:e,note:u&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,V).forEach((r,h,u)=>{let E=r>>7,v=r&127;r==0&&t(this,X)[0]==0||E==e&&t(this,_).nOff(E,v)})}});C(this,nt,{8:function(e){let r=e.channel,h=e.data[0];t(this,_).nOff(r,h)},9:function(e){let r=e.channel,h=this;if(h.getChModeId(r)==w.xg&&t(h,D)[r]>1){let v=h.getChDrumFirstWrite(r);v[0]&&v[1]!=g.invalidCh&&!t(h,ie)[r]&&(h.copyChSetup(v[1],r),h.dispatchEvent("voice",{part:r}),console.debug(`Part CH${r+1} copied from CH${v[1]}.`))}h.setChActive(r,1);let u=e.data[0],E=e.data[1];E>0?t(h,_).nOn(r,u,E):t(h,_).nOff(r,u)},10:function(e){let r=e.channel,h=r*128+e.data[0];t(this,V).indexOf(h)>-1&&(t(this,X)[h]=data[1],this.getExt(r)[1]==this.VLBC_VELOALL&&(t(this,p)[g.cc*r+b[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=this,u=t(this,Ue)[r],E=u[e.data[0]];E&&(e.data[0]=E),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,O)){case w.s90es:case w.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 v=r*g.cc,k=r*g.ext;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,_).ano(r),t(this,ke)[r]=0,t(this,p)[v+b[1]]=0,t(this,p)[v+b[5]]=0,t(this,p)[v+b[64]]=0,t(this,p)[v+b[65]]=0,t(this,p)[v+b[66]]=0,t(this,p)[v+b[67]]=0,t(this,p)[v+b[11]]=127,t(this,p)[v+b[101]]=127,t(this,p)[v+b[100]]=127,t(this,p)[v+b[99]]=127,t(this,p)[v+b[98]]=127;return}case 123:{t(this,_).ano(r);return}case 124:{t(this,_).ano(r);return}case 125:{t(this,_).ano(r);return}case 126:{t(this,Z)[r]=1,t(this,_).ano(r);return}case 127:{t(this,Z)[r]=0,t(this,_).ano(r);return}}if(b[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(ia.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(P()&&console.debug(`${K[t(this,O)]}, CH${r+1}: ${e.data[1]}`),t(this,O)==0?e.data[1]<48?(t(this,D)[r]>0&&(e.data[1]=t(this,p)[v],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]==56?this.switchMode(t(this,B).x5==82?"x5d":"05rw"):e.data[1]==62?this.switchMode(t(this,B).x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(K[t(this,B).ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,O)==w.gs||t(this,O)==w.sc?e.data[1]<56&&t(this,D)[r]>0&&(e.data[1]=t(this,p)[v],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):t(this,O)==w.gm&&(e.data[1]<48?t(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)),t(this,O)){case w.xg:{[79,95,126,127].indexOf(e.data[1])>-1?t(this,D)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(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?t(this,ee)[k]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?t(this,ee)[k]=this.EXT_DX:t(this,ee)[k]=this.EXT_NONE;break}case w["05rw"]:case w.x5d:case w.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(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||t(this,D)[r]!=this.CH_MELODIC&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case w.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,D)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,D)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case w.g2:{e.data[1]==120?t(this,D)[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):t(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&&(t(this,p)[v+b[129]]=e.data[1]);break}case 6:{if(t(this,Oe)){[w.xg,w.gs,w.sc,w.ns5r].indexOf(t(this,O))<0&&console.warn(`NRPN commits are not available under "${K[t(this,O)]}" mode, even when they are supported in Octavia.`);let S=t(this,p)[v+b[99]],a=t(this,p)[v+b[98]];if(S==1){let c=ca.indexOf(a);if(c>-1)t(this,p)[v+b[71+c]]=e.data[1],P()&&console.debug(`Redirected NRPN 1 ${a} to cc${71+c}.`),this.dispatchEvent("cc",{part:r,cc:71+c,data:e.data[1]});else{let f=Vt.indexOf(a);f>-1?t(this,Ke)[r*10+f]=e.data[1]-64:console.warn(`NRPN 0x01${a.toString(16).padStart(2,"0")} is not supported.`),P()&&console.debug(`CH${r+1} voice NRPN ${a} commit`)}}else{if(ft.indexOf(S)<0){let f=`NRPN 0x${S.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")} `;S==127?console.warn(`${f}is not necessary. Consider removing it.`):console.warn(`${f}is not supported.`)}else{let f=t(this,D)[r]-2;f<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${et[t(this,D)[r]]}.`):t(this,Y)[(f*g.dpn+de[S])*g.dnc+a]=e.data[1]}P()&&console.debug(`CH${r+1} (${et[t(this,D)[r]]}) drum NRPN ${S} commit`)}}else{let S=_t[t(this,p)[v+b[100]]],a=Gt[t(this,p)[v+b[100]]];t(this,p)[v+b[101]]==0&&S!=null&&(P()&&console.debug(`CH${r+1} RPN 0 ${t(this,p)[v+b[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Xt[S][0]),Xt[S][1]),t(this,R)[r*g.rpn+S]=e.data[1],t(this,L)[r*g.rpnt+a]=1,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)}))}break}case 32:{switch(P()&&console.debug(`${K[t(this,O)]}, CH${r+1} LSB: ${e.data[1]}`),t(this,O)){case w.s90es:case w.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,O),!0);break}}this.getExt(r)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:r});break}case 38:{if(!t(this,Oe)){let S=_t[t(this,p)[v+100]],a=Gt[t(this,p)[v+100]];t(this,p)[v+101]==0&&S!=null&&(t(this,R)[r*g.rpn+S+1]=e.data[1],t(this,L)[r*g.rpnt+a]=1)}break}case 64:{e.data[1]<64&&t(this,_).hoOf(r);break}case 66:{e.data[1]>>6?t(this,_).soOn(r):t(this,_).soOf(r);break}case 98:case 99:{x(this,Oe,1);break}case 100:case 101:{x(this,Oe,0);break}}t(this,p)[v+b[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:r,cc:e.data[0],data:e.data[1]})}h.getChModeId(r)==w.xg&&t(h,D)[r]&&h.setDrumFirstWrite(r)},12:function(e){let r=e.channel,h=this;switch(t(h,O)){case w.s90es:case w.motif:{e.data&&h.setChActive(r,1);break}default:h.setChActive(r,1)}if(h.getExt(r)[0]==h.EXT_DX){let u=g.cc*r}t(h,A)[r]=e.data,t(h,ue)[r]=0,P()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),h.dispatchEvent("voice",{part:r}),h.getChModeId(r)==w.xg&&t(h,D)[r]&&h.setDrumFirstWrite(r)},13:function(e){let r=this,h=e.channel;t(this,V).forEach(function(u){let E=u>>7;h==E&&(t(r,X)[u]=e.data,r.dispatchEvent("note",{part:h,note:u&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;t(this,ke)[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){oa(e.data).forEach(r=>{let h=r[0],u=r[1];(t(this,dt)[h]||function(){console.debug(`Unknown manufacturer ${h}.`)})(u,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(h,u,E){}).call(this,e.data,e.track,e.meta),e.meta!=32&&x(this,Le,0);let r=sa.indexOf(e.meta)>-1;if(P()&&console.debug(e),r)return e.reply="meta",e}});C(this,dt,{64:(e,r,h)=>{t(this,Ie).run(r,h,e)},65:(e,r,h)=>{if(r[0]<16)if(r[1]==72){let u=r[r.length-1],E=xe(r.subarray(3,r.length-1));u==E?t(this,ne).run(r.subarray(0,r.length-1),h,e):console.warn(`Bad SD checksum ${u} - should be ${E}.`)}else t(this,ne).run(r,h,e);else{let u=r[r.length-1],E=xe(r.subarray(2,r.length-1));u==E?t(this,ne).run(r.subarray(0,r.length-1),h,e):console.warn(`Bad GS checksum ${u} - should be ${E}.`)}},66:(e,r,h)=>{t(this,$e).run(r,h,e)},67:(e,r,h)=>{t(this,re).run(r,h,e)},68:(e,r,h)=>{t(this,Ge).run(r,h,e)},71:(e,r,h)=>{t(this,_e).run(r,h,e)},126:(e,r,h)=>{t(this,He).run(r,h,e)},127:(e,r,h)=>{this.switchMode("gm"),t(this,Ne).run(r,h,e)}});C(this,He,void 0);C(this,Ne,void 0);C(this,re,void 0);C(this,ne,void 0);C(this,$e,void 0);C(this,Ie,void 0);C(this,_e,void 0);C(this,Ge,void 0);let e=this;x(e,se,new Uint8Array(256),qt),t(e,we)[10]=new Uint8Array(512),x(e,Be,new oe),x(e,B,{x5:82,ds:w.krs,smotif:w.s90es,gs:4,sc:3}),x(e,me,{dumpLimit:e.DUMP_MODE}),x(e,st,new Proxy(t(e,me),{set:()=>{}}));for(let a in Ht){let c=w[a];c==null?console.debug(`SubDB build error: "${a}" does not exist`):t(e,F)[c]=new Uint8Array(Ht[a])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -155,18 +155,18 @@ _,`.split(` `),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:(f=a.slice(2))==null?void 0:f.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(s=a.slice(2))==null?void 0:s.trimLeft()});break}case"@T":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(i=a.slice(2))==null?void 0:i.trimLeft()});break}case"@V":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(o=a.slice(2))==null?void 0:o.trimLeft()});break}case"XF":{let n=a.slice(2).split(":");switch(n[0]){case"hd":{n.slice(1).forEach((d,l)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][l],data:d})});break}case"ln":{n.slice(1).forEach((d,l)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][l],data:d})});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((n,d)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:n,mask:d!=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,Le)<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,Le,a[0]+1)},t(e,q)[33]=function(a,c){P()&&console.debug(`Track ${c} requests to get assigned to output ${a}.`),t(e,Pe)[c]=a+1},t(e,q)[81]=function(a,c){x(e,qe,a/1e3)},t(e,q)[127]=function(a,c){t(e,Be).run(a,c)},t(e,Be).default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},t(e,Be).add([67,0,1],function(a,c){t(e,Pe)[c]=a[0]+1}),x(e,He,new oe("universal non-realtime")),x(e,Ne,new oe("universal realtime")),x(e,re,new oe("Yamaha")),x(e,ne,new oe("Roland")),x(e,$e,new oe("Korg")),x(e,Ie,new oe("Kawai")),x(e,_e,new oe("Akai")),x(e,Ge,new oe("Casio"));let r=new oe("DX7+ Dump"),h=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. %o`,a)};t(e,He).default=h,t(e,Ne).default=h,t(e,re).default=h,t(e,ne).default=h,t(e,$e).default=h,t(e,Ie).default=h,t(e,_e).default=h,t(e,Ge).default=h,r.default=h,t(e,He).add([9],(a,c,f)=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),e.setPortMode(e.getTrackPort(c),1,w[["gm","?","g2"][a[0]-1]]),x(e,N,t(e,N)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),t(e,Ne).add([4,1],(a,c,f)=>{e.dispatchEvent("mupromptex"),x(e,H,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,H))}).add([4,3],(a,c,f)=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],(a,c,f)=>a[1]-64).add([4,5],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=a[0],i=a[1],o=a[2],n=3,d=n+(s<<1),l=d+i;if(s!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${s})! -`,a);return}let m=0,$=0,M=0;switch(a.subarray(n,d).forEach(U=>{m=m<<7,m|=U}),a.subarray(d,l).forEach((U,ge)=>{$|=U<{M|=U<{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),e.setPortMode(e.getTrackPort(c),4,w.xg),x(e,N,!1),console.info("MIDI reset: XG");break}default:{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(o,n)=>{s[n]=o};if(a.subarray(1).forEach((o,n)=>{let d=n+a[0];([i,i,i,i,l=>{x(this,H,l*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},l=>{},l=>{}][d]||(()=>{}))(o,n)}),a[0]<4){let o=0;s.forEach(n=>{o=o<<4,o+=n}),o-=1024}}}}).add([76,2,1],(a,c,f)=>{e.dispatchEvent("mupromptex");let s="XG ";a[0]<32?(s+="reverb ",a.subarray(1).forEach((i,o)=>{([n=>{e.setEffectTypeRaw(0,!1,n),console.info(`${s}main type: ${je[n]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},n=>{e.setEffectTypeRaw(0,!0,n),console.debug(`${s}sub type: ${n+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},n=>{console.debug(`${s}time: ${Rt(n)}s`)},n=>{console.debug(`${s}diffusion: ${n}`)},n=>{console.debug(`${s}initial delay: ${n}`)},n=>{console.debug(`${s}HPF cutoff: ${Ve[n]}Hz`)},n=>{console.debug(`${s}LPF cutoff: ${Ve[n]}Hz`)},n=>{console.debug(`${s}width: ${n}`)},n=>{console.debug(`${s}height: ${n}`)},n=>{console.debug(`${s}depth: ${n}`)},n=>{console.debug(`${s}wall type: ${n}`)},n=>{console.debug(`${s}dry/wet: ${n}`)},n=>{console.debug(`${s}send: ${Z(n)}dB`)},n=>{console.debug(`${s}pan: ${n-64}`)},!1,!1,n=>{console.debug(`${s}delay: ${n}`)},n=>{console.debug(`${s}density: ${n}`)},n=>{console.debug(`${s}balance: ${n}`)},n=>{},n=>{console.debug(`${s}feedback: ${n}`)},n=>{}][a[0]+o]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(i)})):a[0]<64?(s+="chorus ",a.subarray(1).forEach((i,o)=>{([n=>{e.setEffectTypeRaw(1,!1,n),console.info(`${s}main type: ${je[n]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},n=>{e.setEffectTypeRaw(1,!0,n),console.debug(`${s}sub type: ${n+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},n=>{console.debug(`${s}LFO: ${Tt[n]}Hz`)},n=>{},n=>{console.debug(`${s}feedback: ${n}`)},n=>{console.debug(`${s}delay offset: ${Dt(n)}ms`)},n=>{},n=>{console.debug(`${s}low: ${Ve[n]}Hz`)},n=>{console.debug(`${s}low: ${n-64}dB`)},n=>{console.debug(`${s}high: ${Ve[n]}Hz`)},n=>{console.debug(`${s}high: ${n-64}dB`)},n=>{console.debug(`${s}dry/wet: ${n}`)},n=>{console.debug(`${s}send: ${Z(n)}dB`)},n=>{console.debug(`${s}pan: ${n-64}`)},n=>{console.debug(`${s}to reverb: ${Z(n)}dB`)},!1,n=>{},n=>{},n=>{},n=>{console.debug(`${s}LFO phase diff: ${(n-64)*3}deg`)},n=>{console.debug(`${s}input mode: ${n?"stereo":"mono"}`)},n=>{}][a[0]-32+o]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(i)})):a[0]<86?(s+="variation ",a.subarray(1).forEach((i,o)=>{([n=>{e.setEffectTypeRaw(2,!1,n),console.info(`${s}main type: ${je[n]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},n=>{e.setEffectTypeRaw(2,!0,n),console.debug(`${s}sub type: ${n+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+o]||function(){})(i)})):a[0]<97?(s+="variation ",a.subarray(1).forEach((i,o)=>{[n=>{console.debug(`${s}send: ${Z(n)}dB`)},n=>{console.debug(`${s}pan: ${n-64}`)},n=>{console.debug(`${s}to reverb: ${Z(n)}dB`)},n=>{console.debug(`${s}to chorus: ${Z(n)}dB`)},n=>{console.debug(`${s}connection: ${n?"system":"insertion"}`)},n=>{console.debug(`${s}channel: CH${n+1}`)},n=>{console.debug(`${s}mod wheel: ${n-64}`)},n=>{console.debug(`${s}bend wheel: ${n-64}`)},n=>{console.debug(`${s}channel after touch: ${n-64}`)},n=>{console.debug(`${s}AC1: ${n-64}`)},n=>{console.debug(`${s}AC2: ${n-64}`)}][a[0]-86+o](i)})):a[0]>111&&a[0]<118?s+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],(a,c,f)=>{a.subarray(1).forEach((s,i)=>{let o=i+a[0];if(o==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][s]}`);else{let n=o-1>>2,d=o-1&3,l=`XG EQ ${n} ${["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],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=a[0],i=a[1],o=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((n,d)=>{([l=>{e.setEffectTypeRaw(3+s,!1,l),console.info(`${o}main type: ${je[l]}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))},l=>{e.setEffectTypeRaw(3+s,!0,l),console.debug(`${o}sub type: ${l+1}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))}][i+d]||function(){})(n)})}).add([76,6,0],(a,c,f)=>{let s=a[0];s<64?e.setLetterDisplay(a.subarray(1),"XG letter display",s):x(e,De,Date.now())}).add([76,7,0],(a,c,f)=>{let s=a[0];x(e,W,0),x(e,fe,Date.now()+3200),t(e,se,ve).fill(0);let i=a.subarray(1);for(let o=0;o>6-M&1,M++})}).add([76,8],(a,c)=>{e.dispatchEvent("mupromptex");let f=e.chRedir(a[0],c,!0),s=a[1],i=g.cc*f,o=`XG CH${f+1} `,n=`Unknown XG part address ${s}.`,d=!0;a.subarray(2).forEach((l,m)=>{d=!0,s<1?console.debug(n):s<41?([()=>{t(e,p)[i+b[0]]=l,e.dispatchEvent("voice",{part:f})},()=>{t(e,p)[i+b[32]]=l,e.dispatchEvent("voice",{part:f})},()=>{t(e,A)[f]=l,e.dispatchEvent("voice",{part:f})},()=>{d=!1;let $=e.chRedir(l,c,!0);t(e,G)[f]=$,f!=$&&(e.buildRchTree(),console.info(`${o}receives from CH${$+1}`)),t(e,ie)[f]||(e.copyChSetup($,f,!0),console.debug(`${o}copied from CH${$+1}.`),e.setChActive(f,1),e.dispatchEvent("voice",{part:f}))},()=>{t(e,j)[f]=+!l},()=>{},()=>{d=!1,e.setChType(f,l,w.xg),console.debug(`${o}type: ${et[l]||l}`),e.dispatchEvent("voice",{part:f})},()=>{t(e,R)[g.rpn*f+3]=l,t(e,L)[g.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},!1,!1,()=>{t(e,p)[i+b[7]]=l},!1,!1,()=>{t(e,p)[i+b[10]]=l||128},!1,!1,()=>{t(e,p)[i+b[128]]=l,e.allocateAce(128)},()=>{t(e,p)[i+b[93]]=l},()=>{t(e,p)[i+b[91]]=l},()=>{t(e,p)[i+b[94]]=l},()=>{t(e,p)[i+b[76]]=l},()=>{t(e,p)[i+b[77]]=l},()=>{t(e,p)[i+b[78]]=l},()=>{t(e,p)[i+b[74]]=l},()=>{t(e,p)[i+b[71]]=l},()=>{t(e,p)[i+b[73]]=l},()=>{t(e,p)[i+b[75]]=l},()=>{t(e,p)[i+b[72]]=l}][s+m-1]||(()=>{}))():s<48?console.debug(n):s<111?s>102&&s<105&&(t(e,p)[i+b[[5,65][s&1]]]=l):s<114?console.debug(n):s<116?console.debug(`${o}EQ ${["bass","treble"][s&1]} gain: ${l-64}dB`):s<118?console.debug(n):s<120?console.debug(`${o}EQ ${["bass","treble"][s&1]} freq: ${l}`):console.debug(n)}),d&&t(e,D)[f]>1&&e.setDrumFirstWrite(f)}).add([76,9],(a,c)=>{let f=e.chRedir(a[0],c,!0),s=a[1],i=g.cc*f,o=`PLG-VL CH${f+1} `;a.subarray(2).forEach((n,d)=>{let l=d+s;switch(l){case 1:{console.info(`${o}breath mode: ${["system","breath","velocity","touch EG"][n]}`);break}case 0:case 27:case 28:break;default:if(l<27){let m=l-3>>1,$=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][m];l&1?l<23?(console.debug(`${o}${$} control source: ${At(n)}`),n&&n<96&&e.allocateAce(130+m),t(e,Ae)[g.redir*f+m+2]=n,e.buildRccMap()):console.debug(`${o}${$} scale break point: ${n}`):(console.debug(`${o}${$} depth: ${n-64}`),t(e,p)[i+b[130+m]]=n)}}})}).add([76,10],(a,c,f)=>{}).add([76,16],(a,c,f)=>{}).add([76,17,0,0],(a,c,f)=>{}).add([76,112],(a,c,f)=>{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,ee)[g.ext*a[2]]=e.EXT_VL;break}case 2:{t(e,ee)[g.ext*a[2]]=e.EXT_DX;break}default:t(e,ee)[g.ext*a[2]]=e.EXT_NONE}}).add([73,0,0],(a,c)=>{let f=a[0],s="MU1000 System - ";a.subarray(1).forEach((i,o)=>{let n=f+o;n==8?console.debug(`${s}LCD contrast: ${i}.`):n==18?(t(e,F)[w.xg][1]=i?126:0,console.debug(`${s}default bank: ${i?"MU100 Native":"MU Basic"}.`),e.dispatchEvent("banklevel",{mode:"xg",data:+!!i}),e.forceVoiceRefresh()):n>=64&&n<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")},()=>{x(e,be,!!i),console.info(`Octavia System: RS receiving ${["dis","en"][i]}abled.`)}][n-64]()})}).add([73,10,0],(a,c)=>{let f=a[0],s=`MU1000 RS${t(e,be)?"":" (ignored)"}: `;if(f<16)switch(f){case 2:{let i=e.chRedir(0,c,!0);t(e,be)&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+63)),console.info(`${s}Show CH1~64`);break}case 3:{let i=e.chRedir(a[1]<<5,c,!0);t(e,be)&&e.dispatchEvent("channelmin",i),t(e,be)&&e.dispatchEvent("channelmax",i+31),console.info(`${s}Show CH${i+1}~CH${i+32}`);break}default:console.debug(`${s}unknown switch ${f} invoked.`)}else if(f<32){if(t(e,be)){let i=e.chRedir(f-16+(t(e,Ye)<<4),c,!0);e.dispatchEvent("channelactive",i)}}else if(f<36){let i=e.chRedir(f-32<<4,c,!0);t(e,be)&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+15),x(e,Ye,f-32)),console.info(`${s}Show CH${i+1}~CH${i+16}`)}}).add([73,11,0],(a,c)=>{let f="MU1000 System - channel ",s="Octavia System - channel ",i=a[0];a.subarray(1).forEach((o,n)=>{let d=i+n;([()=>{e.setChActive(o,1),e.dispatchEvent("channelactive",o),P()&&console.debug(`${f}current part: CH${o+1}`)},()=>{o<5?(e.dispatchEvent("portrange",1<{o<16?(e.dispatchEvent("portstart",o),console.debug(`${s}start port: ${"ABCDEFGHIJKLMNOP"[o]}`)):(e.dispatchEvent("portstart",255),console.debug(`${s}start port: reset`))}][d]||(()=>{console.debug(`${f}unknown address: ${d}`)}))()})}).add([93,3],(a,c)=>{let f=e.chRedir(a[0],c,!0),s=`PLG-100SG CH${f+1} `,i=Date.now();if(a[1]==0){let o="",n=0;a.subarray(2).forEach((d,l)=>{l%2==0?o+=Pt[d]||d.toString().padStart("0"):n+=d*13}),i>=t(e,Qe)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${Ot(o)}`,amend:!0}),x(e,Qe,i+Math.ceil(n/2)+t(e,qe)),P()&&console.debug(`${s}vocals: ${o}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)}).add([98,0],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=a[0],i=a.length-5,o=a.length-1;if(s!=i){console.info(`PLG-DX native dump size mismatch! Gave ${s} instead of ${a.length-5}.`);return}let n=xe(a.subarray(4,o));if(n!=a[o]){console.info(`Bad PLG-DX checksum ${a[o]} - should be ${n}.`);return}a[0]=98,t(e,re).run(a.subarray(0,o),c,f,{noAce:!0})}).add([98,96],(a,c,f,s)=>{let i=e.chRedir(a[0],c,!0),o=g.cc*i,n=a[1];a.subarray(2).forEach((d,l)=>{let m=n+l;if(!(m<10)){if(m==10)e.resetAce();else if(m<27){let $=m+131;s!=null&&s.noAce||e.allocateAce($),t(e,p)[o+b[$]]=d,e.dispatchEvent("cc",{part:i,cc:$,data:d})}}})}).add([100,0],(a,c,f)=>{let s=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 m=0,$=0,M=0;switch(a.subarray(n,d).forEach(U=>{m=m<<7,m|=U}),a.subarray(d,l).forEach((U,ge)=>{$|=U<{M|=U<{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),e.setPortMode(e.getTrackPort(c),4,w.xg),x(e,N,!1),console.info("MIDI reset: XG");break}default:{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(o,n)=>{s[n]=o};if(a.subarray(1).forEach((o,n)=>{let d=n+a[0];([i,i,i,i,l=>{x(this,H,l*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},l=>{},l=>{}][d]||(()=>{}))(o,n)}),a[0]<4){let o=0;s.forEach(n=>{o=o<<4,o+=n}),o-=1024}}}}).add([76,2,1],(a,c,f)=>{e.dispatchEvent("mupromptex");let s="XG ";a[0]<32?(s+="reverb ",a.subarray(1).forEach((i,o)=>{([n=>{e.setEffectTypeRaw(0,!1,n),console.info(`${s}main type: ${Ze[n]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},n=>{e.setEffectTypeRaw(0,!0,n),console.debug(`${s}sub type: ${n+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},n=>{console.debug(`${s}time: ${Rt(n)}s`)},n=>{console.debug(`${s}diffusion: ${n}`)},n=>{console.debug(`${s}initial delay: ${n}`)},n=>{console.debug(`${s}HPF cutoff: ${Ve[n]}Hz`)},n=>{console.debug(`${s}LPF cutoff: ${Ve[n]}Hz`)},n=>{console.debug(`${s}width: ${n}`)},n=>{console.debug(`${s}height: ${n}`)},n=>{console.debug(`${s}depth: ${n}`)},n=>{console.debug(`${s}wall type: ${n}`)},n=>{console.debug(`${s}dry/wet: ${n}`)},n=>{console.debug(`${s}send: ${J(n)}dB`)},n=>{console.debug(`${s}pan: ${n-64}`)},!1,!1,n=>{console.debug(`${s}delay: ${n}`)},n=>{console.debug(`${s}density: ${n}`)},n=>{console.debug(`${s}balance: ${n}`)},n=>{},n=>{console.debug(`${s}feedback: ${n}`)},n=>{}][a[0]+o]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(i)})):a[0]<64?(s+="chorus ",a.subarray(1).forEach((i,o)=>{([n=>{e.setEffectTypeRaw(1,!1,n),console.info(`${s}main type: ${Ze[n]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},n=>{e.setEffectTypeRaw(1,!0,n),console.debug(`${s}sub type: ${n+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},n=>{console.debug(`${s}LFO: ${Tt[n]}Hz`)},n=>{},n=>{console.debug(`${s}feedback: ${n}`)},n=>{console.debug(`${s}delay offset: ${Dt(n)}ms`)},n=>{},n=>{console.debug(`${s}low: ${Ve[n]}Hz`)},n=>{console.debug(`${s}low: ${n-64}dB`)},n=>{console.debug(`${s}high: ${Ve[n]}Hz`)},n=>{console.debug(`${s}high: ${n-64}dB`)},n=>{console.debug(`${s}dry/wet: ${n}`)},n=>{console.debug(`${s}send: ${J(n)}dB`)},n=>{console.debug(`${s}pan: ${n-64}`)},n=>{console.debug(`${s}to reverb: ${J(n)}dB`)},!1,n=>{},n=>{},n=>{},n=>{console.debug(`${s}LFO phase diff: ${(n-64)*3}deg`)},n=>{console.debug(`${s}input mode: ${n?"stereo":"mono"}`)},n=>{}][a[0]-32+o]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(i)})):a[0]<86?(s+="variation ",a.subarray(1).forEach((i,o)=>{([n=>{e.setEffectTypeRaw(2,!1,n),console.info(`${s}main type: ${Ze[n]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},n=>{e.setEffectTypeRaw(2,!0,n),console.debug(`${s}sub type: ${n+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+o]||function(){})(i)})):a[0]<97?(s+="variation ",a.subarray(1).forEach((i,o)=>{[n=>{console.debug(`${s}send: ${J(n)}dB`)},n=>{console.debug(`${s}pan: ${n-64}`)},n=>{console.debug(`${s}to reverb: ${J(n)}dB`)},n=>{console.debug(`${s}to chorus: ${J(n)}dB`)},n=>{console.debug(`${s}connection: ${n?"system":"insertion"}`)},n=>{console.debug(`${s}channel: CH${n+1}`)},n=>{console.debug(`${s}mod wheel: ${n-64}`)},n=>{console.debug(`${s}bend wheel: ${n-64}`)},n=>{console.debug(`${s}channel after touch: ${n-64}`)},n=>{console.debug(`${s}AC1: ${n-64}`)},n=>{console.debug(`${s}AC2: ${n-64}`)}][a[0]-86+o](i)})):a[0]>111&&a[0]<118?s+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],(a,c,f)=>{a.subarray(1).forEach((s,i)=>{let o=i+a[0];if(o==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][s]}`);else{let n=o-1>>2,d=o-1&3,l=`XG EQ ${n} ${["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],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=a[0],i=a[1],o=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((n,d)=>{([l=>{e.setEffectTypeRaw(3+s,!1,l),console.info(`${o}main type: ${Ze[l]}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))},l=>{e.setEffectTypeRaw(3+s,!0,l),console.debug(`${o}sub type: ${l+1}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))}][i+d]||function(){})(n)})}).add([76,6,0],(a,c,f)=>{let s=a[0];s<64?e.setLetterDisplay(a.subarray(1),"XG letter display",s):x(e,De,Date.now())}).add([76,7,0],(a,c,f)=>{let s=a[0];x(e,W,0),x(e,fe,Date.now()+3200),t(e,se,ve).fill(0);let i=a.subarray(1);for(let o=0;o>6-M&1,M++})}).add([76,8],(a,c)=>{e.dispatchEvent("mupromptex");let f=e.chRedir(a[0],c,!0),s=a[1],i=g.cc*f,o=`XG CH${f+1} `,n=`Unknown XG part address ${s}.`,d=!0;a.subarray(2).forEach((l,m)=>{d=!0,s<1?console.debug(n):s<41?([()=>{t(e,p)[i+b[0]]=l,e.dispatchEvent("voice",{part:f})},()=>{t(e,p)[i+b[32]]=l,e.dispatchEvent("voice",{part:f})},()=>{t(e,A)[f]=l,e.dispatchEvent("voice",{part:f})},()=>{d=!1;let $=e.chRedir(l,c,!0);t(e,G)[f]=$,f!=$&&(e.buildRchTree(),console.info(`${o}receives from CH${$+1}`)),t(e,ie)[f]||(e.copyChSetup($,f,!0),console.debug(`${o}copied from CH${$+1}.`),e.setChActive(f,1),e.dispatchEvent("voice",{part:f}))},()=>{t(e,Z)[f]=+!l},()=>{},()=>{d=!1,e.setChType(f,l,w.xg),console.debug(`${o}type: ${et[l]||l}`),e.dispatchEvent("voice",{part:f})},()=>{t(e,R)[g.rpn*f+3]=l,t(e,L)[g.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},!1,!1,()=>{t(e,p)[i+b[7]]=l},!1,!1,()=>{t(e,p)[i+b[10]]=l||128},!1,!1,()=>{t(e,p)[i+b[128]]=l,e.allocateAce(128)},()=>{t(e,p)[i+b[93]]=l},()=>{t(e,p)[i+b[91]]=l},()=>{t(e,p)[i+b[94]]=l},()=>{t(e,p)[i+b[76]]=l},()=>{t(e,p)[i+b[77]]=l},()=>{t(e,p)[i+b[78]]=l},()=>{t(e,p)[i+b[74]]=l},()=>{t(e,p)[i+b[71]]=l},()=>{t(e,p)[i+b[73]]=l},()=>{t(e,p)[i+b[75]]=l},()=>{t(e,p)[i+b[72]]=l}][s+m-1]||(()=>{}))():s<48?console.debug(n):s<111?s>102&&s<105&&(t(e,p)[i+b[[5,65][s&1]]]=l):s<114?console.debug(n):s<116?console.debug(`${o}EQ ${["bass","treble"][s&1]} gain: ${l-64}dB`):s<118?console.debug(n):s<120?console.debug(`${o}EQ ${["bass","treble"][s&1]} freq: ${l}`):console.debug(n)}),d&&t(e,D)[f]>1&&e.setDrumFirstWrite(f)}).add([76,9],(a,c)=>{let f=e.chRedir(a[0],c,!0),s=a[1],i=g.cc*f,o=`PLG-VL CH${f+1} `;a.subarray(2).forEach((n,d)=>{let l=d+s;switch(l){case 1:{console.info(`${o}breath mode: ${["system","breath","velocity","touch EG"][n]}`);break}case 0:case 27:case 28:break;default:if(l<27){let m=l-3>>1,$=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][m];l&1?l<23?(console.debug(`${o}${$} control source: ${At(n)}`),n&&n<96&&e.allocateAce(130+m),t(e,Ae)[g.redir*f+m+2]=n,e.buildRccMap()):console.debug(`${o}${$} scale break point: ${n}`):(console.debug(`${o}${$} depth: ${n-64}`),t(e,p)[i+b[130+m]]=n)}}})}).add([76,10],(a,c,f)=>{}).add([76,16],(a,c,f)=>{}).add([76,17,0,0],(a,c,f)=>{}).add([76,112],(a,c,f)=>{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,ee)[g.ext*a[2]]=e.EXT_VL;break}case 2:{t(e,ee)[g.ext*a[2]]=e.EXT_DX;break}default:t(e,ee)[g.ext*a[2]]=e.EXT_NONE}}).add([73,0,0],(a,c)=>{let f=a[0],s="MU1000 System - ";a.subarray(1).forEach((i,o)=>{let n=f+o;n==8?console.debug(`${s}LCD contrast: ${i}.`):n==18?(t(e,F)[w.xg][1]=i?126:0,console.debug(`${s}default bank: ${i?"MU100 Native":"MU Basic"}.`),e.dispatchEvent("banklevel",{mode:"xg",data:+!!i}),e.forceVoiceRefresh()):n>=64&&n<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")},()=>{x(e,be,!!i),console.info(`Octavia System: RS receiving ${["dis","en"][i]}abled.`)}][n-64]()})}).add([73,10,0],(a,c)=>{let f=a[0],s=`MU1000 RS${t(e,be)?"":" (ignored)"}: `;if(f<16)switch(f){case 2:{let i=e.chRedir(0,c,!0);t(e,be)&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+63)),console.info(`${s}Show CH1~64`);break}case 3:{let i=e.chRedir(a[1]<<5,c,!0);t(e,be)&&e.dispatchEvent("channelmin",i),t(e,be)&&e.dispatchEvent("channelmax",i+31),console.info(`${s}Show CH${i+1}~CH${i+32}`);break}default:console.debug(`${s}unknown switch ${f} invoked.`)}else if(f<32){if(t(e,be)){let i=e.chRedir(f-16+(t(e,Ye)<<4),c,!0);e.dispatchEvent("channelactive",i)}}else if(f<36){let i=e.chRedir(f-32<<4,c,!0);t(e,be)&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+15),x(e,Ye,f-32)),console.info(`${s}Show CH${i+1}~CH${i+16}`)}}).add([73,11,0],(a,c)=>{let f="MU1000 System - channel ",s="Octavia System - channel ",i=a[0];a.subarray(1).forEach((o,n)=>{let d=i+n;([()=>{e.setChActive(o,1),e.dispatchEvent("channelactive",o),P()&&console.debug(`${f}current part: CH${o+1}`)},()=>{o<5?(e.dispatchEvent("portrange",1<{o<16?(e.dispatchEvent("portstart",o),console.debug(`${s}start port: ${"ABCDEFGHIJKLMNOP"[o]}`)):(e.dispatchEvent("portstart",255),console.debug(`${s}start port: reset`))}][d]||(()=>{console.debug(`${f}unknown address: ${d}`)}))()})}).add([93,3],(a,c)=>{let f=e.chRedir(a[0],c,!0),s=`PLG-100SG CH${f+1} `,i=Date.now();if(a[1]==0){let o="",n=0;a.subarray(2).forEach((d,l)=>{l%2==0?o+=Pt[d]||d.toString().padStart("0"):n+=d*13}),i>=t(e,Qe)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${Ot(o)}`,amend:!0}),x(e,Qe,i+Math.ceil(n/2)+t(e,qe)),P()&&console.debug(`${s}vocals: ${o}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)}).add([98,0],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=a[0],i=a.length-5,o=a.length-1;if(s!=i){console.info(`PLG-DX native dump size mismatch! Gave ${s} instead of ${a.length-5}.`);return}let n=xe(a.subarray(4,o));if(n!=a[o]){console.info(`Bad PLG-DX checksum ${a[o]} - should be ${n}.`);return}a[0]=98,t(e,re).run(a.subarray(0,o),c,f,{noAce:!0})}).add([98,96],(a,c,f,s)=>{let i=e.chRedir(a[0],c,!0),o=g.cc*i,n=a[1];a.subarray(2).forEach((d,l)=>{let m=n+l;if(!(m<10)){if(m==10)e.resetAce();else if(m<27){let $=m+131;s!=null&&s.noAce||e.allocateAce($),t(e,p)[o+b[$]]=d,e.dispatchEvent("cc",{part:i,cc:$,data:d})}}})}).add([100,0],(a,c,f)=>{let s=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 i=xe(s),o=a[a.length-1];if(i!=o){console.warn(`Yamaha DX7+ dump SysEx checksum mismatch! Expected ${i}, but got ${o}: -`,a);return}r.run(s.subarray(1))}).add([100,76],(a,c,f)=>{let s=a[0]>>4,i=a[0]&15,o=a[1];switch(s){case 2:{let n=e.chRedir(i,c,!0),d=g.cc*n;a.subarray(2).forEach((l,m)=>{let $=m+o;if(!($<7)){if($<23){let M=$+135;e.allocateAce(M),t(e,p)[d+b[M]]=l,e.dispatchEvent("cc",{part:n,cc:M,data:l})}}});break}default:console.info("Unknown DX7+ multipart: %o",a)}}),r.add([14,31],(a,c,f)=>{t(e,p)[g.cc*a[0]+b[64]]=0,t(e,_).ano(a[0]),e.switchMode("xg"),e.setPortMode(e.getTrackPort(c),1,w.xg),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${a[0]+1}.`)}).add([76,112],async a=>{let c=a[0],f=g.cc*c,s=g.ext*c,i=g.cvn*c;t(e,ee)[s]=e.EXT_DX,t(e,ue)[c]=1;let o=t(e,rt).subarray(i,i+g.cvn);o.fill(32),a.subarray(1).forEach((n,d)=>{if(d<10)o[d]=Math.max(n,32);else if(!(d<40)){if(d<56){let l=d+102;t(e,p)[f+b[l]]=n,e.dispatchEvent("cc",{part:c,cc:l,data:n})}}}),t(e,A)[c]=c&127,t(e,p)[g.cc*c+b[0]]=35,t(e,p)[g.cc*c+b[32]]=c>>7|4,e.dispatchEvent("voice",{part:c}),console.debug(`DX7+ CH${c+1} dump: %o`,a)});let u=function(a,c,f,s){},E=function(a,c){e.dispatchEvent("mupromptex");let f=a*g.dpn,s=c[0],i=c[1];c.subarray(2).forEach((o,n)=>{let d=n+i,l=-1;d<16?([()=>{l=24},()=>{l=25},()=>{l=26},()=>{},()=>{l=28},()=>{l=29},()=>{l=30},()=>{l=31},()=>{},()=>{},()=>{},()=>{l=20},()=>{l=21},()=>{l=22},()=>{l=23},()=>{}][d]||(()=>{console.debug(`Unknown XG-style drum param ${d} on set ${a+1}.`)}))():d<32||(d<40?([()=>{l=48},()=>{l=49},!1,!1,()=>{l=52},()=>{l=53}][d-32]||(()=>{console.debug(`Unknown XG-style drum param ${d} on set ${a+1}.`)}))():d<80||([()=>{l=36}][d-80]||(()=>{console.debug(`Unknown XG-style drum param ${d} on set ${a+1}.`)}))()),l>=0?(P()&&console.debug(f,l,s,o),t(e,Y)[(f+de[l])*g.dnc+s]=o):P()&&console.debug(`XG-style drum param ${d} has no writes.`)})},v=function(a,c,f){e.dispatchEvent("mupromptex");let s=a*g.dpn,i=(c<<7)+f[0];f.subarray(1).forEach((o,n)=>{let d=n+i,l=d&127,m=d>>7,$=-1;m>1&&([()=>{$=26},()=>{},()=>{$=28},()=>{$=29},()=>{$=30},()=>{},()=>{},()=>{$=31}][m-2]||(()=>{console.debug(`Unknown GS-style drum param ${m} on set ${a+1}.`)}))(),$>-1?(P()&&console.debug(s,$,l,o),t(e,Y)[(s+de[$])*g.dnc+l]=o):P()&&console.debug(`GS-style drum param ${m} has no writes.`)})};t(this,re).add([76,48],(a,c,f)=>{E(0,a)}).add([76,49],(a,c,f)=>{E(1,a)}).add([76,50],(a,c,f)=>{E(2,a)}).add([76,51],(a,c,f)=>{E(3,a)}).add([76,52],(a,c,f)=>{E(4,a)}).add([76,53],(a,c,f)=>{E(5,a)}).add([76,54],(a,c,f)=>{E(6,a)}).add([76,55],(a,c,f)=>{E(7,a)}),t(this,re).add([89,0],(a,c,f)=>{if(e.eprom){let s=a[0],i=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);P()&&console.debug(`MU1000 EPROM trail to 0x${i.toString(16).padStart(6,"0")}, ${s} bytes.`);let o=e.eprom.data;a.subarray(4).forEach((n,d)=>{let l=d>>3,m=d&7;if(m==7)for(let $=0;$<7;$++)o[i+7*l+$]+=(n>>6-$&1)<<7;else o[i+7*l+m]=n})}}).add([89,1],(a,c,f)=>{let s=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];P()&&console.debug(`MU1000 EPROM jump to 0x${s.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=s)}).add([89,2],(a,c,f)=>{if(e.eprom){let s=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);P()&&console.debug(`MU1000 EPROM write to 0x${s.toString(16).padStart(6,"0")}.`);let i=e.eprom.data;a.subarray(4).forEach((o,n)=>{let d=n>>3,l=n&7;if(l==7)for(let m=0;m<7;m++)i[s+7*d+m]+=(o>>6-m&1)<<7;else i[s+7*d+l]=o})}}).add([89,3],(a,c,f)=>{}),t(this,re).add([39,48],(a,c,f)=>{}).add([43,0,0],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(o,n)=>{s[n]=o};if(a.subarray(1).forEach((o,n)=>{let d=n+a[0];[i,i,i,i,()=>{x(this,H,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},()=>o-64,()=>o||128,()=>o,()=>o,()=>{console.debug(`TG300 variation on cc${o}.`)}][d](o,d)}),a[0]<4){let o=0;s.forEach(n=>{o=o<<4,o+=n}),o-=1024}}).add([43,1,0],(a,c,f)=>{e.dispatchEvent("mupromptex")}).add([43,2],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=e.chRedir(a[0],c,!0),i=a[1],o=g.cc*s,n=`TG300 CH${s+1} `;a.subarray(2).forEach((d,l)=>{l<5?([()=>{},()=>{t(e,p)[o+b[0]]=d,e.dispatchEvent("voice",{part:s})},()=>{t(e,p)[o+b[32]]=d,e.dispatchEvent("voice",{part:s})},()=>{t(e,A)[s]=d,e.dispatchEvent("voice",{part:s})},()=>{let m=e.chRedir(d,c,!0);t(e,G)[s]=m,s!=m&&(e.buildRchTree(),console.info(`${n}receives from CH${m+1}`))}][l+i]||(()=>{}))(d,l+i):l<21||(l<47?([()=>{t(e,j)[s]=+!d},()=>{},()=>{},()=>{t(e,R)[g.rpn*s+3]=d,t(e,L)[g.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{},()=>{t(e,p)[o+b[7]]=d},!1,!1,()=>{t(e,p)[o+b[10]]=d||128},!1,!1,()=>{console.debug(`${n} AC1 at cc${d}`)},()=>{console.debug(`${n} AC2 at cc${d}`)},()=>{t(e,p)[o+b[128]]=d,e.allocateAce(128)},()=>{t(e,p)[o+b[93]]=d},()=>{t(e,p)[o+b[91]]=d},()=>{t(e,p)[o+b[94]]=d},()=>{t(e,p)[o+b[76]]=d},()=>{t(e,p)[o+b[77]]=d},()=>{t(e,p)[o+b[74]]=d},()=>{t(e,p)[o+b[71]]=d},()=>{t(e,p)[o+b[73]]=d},()=>{t(e,p)[o+b[75]]=d},()=>{t(e,p)[o+b[72]]=d},()=>{t(e,p)[o+b[78]]=d}][l+i-21]||(()=>{}))(d,l+i):l<95||([()=>{t(e,p)[o+b[65]]=d},()=>{t(e,p)[o+b[5]]=d}][l+i-95]||(()=>{}))(d,l+i))})}).add([43,7,0],(a,c,f)=>{let s=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",s)}).add([43,7,1],(a,c,f)=>{x(e,W,0),x(e,fe,Date.now()+3200),t(e,se,ve).fill(0),a.forEach(function(s,i){let o=Math.floor(i/16),n=i%16,d=(n*3+o)*7,l=7,m=0;for(d-=n*5,o==2&&(l=2);m>6-m&1,m++})}),t(this,ne).add([66,18,0,0,127],(a,c,f)=>{e.switchMode("sc",!0),e.setPortMode(e.getTrackPort(c),2,w.sc),t(e,p)[g.cc*9]=120,t(e,p)[g.cc*25]=120,t(e,p)[g.cc*41]=120,t(e,p)[g.cc*57]=120,t(e,F)[w.sc][1]=t(e,B).sc,x(e,N,!1),t(e,Se).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,c,f)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),e.setPortMode(e.getTrackPort(c),2,w.gs),t(e,F)[w.gs][1]=t(e,B).gs,t(e,p)[g.cc*9]=120,t(e,p)[g.cc*25]=120,t(e,p)[g.cc*41]=120,t(e,p)[g.cc*57]=120,x(e,N,!1),t(e,Se).fill(0),console.info("MIDI reset: GS");break}default:{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(o,n)=>{s[n]=o};if(a.subarray(1).forEach((o,n)=>{let d=n+a[0];[i,i,i,i,l=>{x(this,H,l*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},l=>{},l=>{}][d](o,n)}),a[0]<4){let o=0;s.forEach(n=>{o=o<<4,o+=n}),o-=1024}}}}).add([66,18,64,1],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=a[0];if(s<16){let i="".padStart(s," ");a.subarray(1).forEach((o,n)=>{i+=String.fromCharCode(Math.max(32,o))}),i=i.padEnd(16," "),console.debug(`GS patch name: ${i}`)}else s<48||(s<65?a.subarray(1).forEach((i,o)=>{let n=`GS ${s+o>55?"chorus":"reverb"} `;([()=>{console.info(`${n}type: ${bt[i]}`),e.setEffectType(0,40,i),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${n}predelay: ${i}ms`)},()=>{console.info(`${n}type: ${Lt[i]}`),e.setEffectType(1,40,16+i),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${n}to reverb: ${Z(i)}`)},()=>{console.debug(`${n}to delay: ${Z(i)}`)}][s+o-48]||(()=>{}))()}):s<80?console.debug(`Unknown GS patch address: ${s}`):s<91?a.subarray(1).forEach((i,o)=>{let n="GS delay ";([()=>{console.info(`${n}type: ${Ut[i]}`),e.setEffectType(2,40,32+i),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${n}to reverb: ${Z(i)}`)}][s+o-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${s}`))}).add([66,18,64,2],(a,c,f)=>{let s="GS EQ ";a.subarray(1).forEach((i,o)=>{([()=>{console.debug(`${s}low freq: ${[200,400][i]}Hz`)},()=>{console.debug(`${s}low gain: ${i-64}dB`)},()=>{console.debug(`${s}high freq: ${[3e3,6e3][i]}Hz`)},()=>{console.debug(`${s}high gain: ${i-64}dB`)}][a[0]+o]||function(){console.warn(`Unknown GS EQ address: ${a[0]+o}`)})()})}).add([66,18,64,3],(a,c,f)=>{e.dispatchEvent("mupromptex");let s="GS EFX ",i=function(o,n){let d=Bt(t(e,te).subarray(10,12),n,o);d&&console.debug(`${s}${gt(t(e,te).subarray(10,12))} ${d}`)};a.subarray(1).forEach((o,n)=>{([()=>{e.setEffectTypeRaw(3,!1,32+o),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,o),console.info(`${s}type: ${gt(t(e,te).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,()=>{console.debug(`${s}to reverb: ${Z(o)}dB`)},()=>{console.debug(`${s}to chorus: ${Z(o)}dB`)},()=>{console.debug(`${s}to delay: ${Z(o)}dB`)},!1,()=>{console.debug(`${s}1 source: ${o}`),o&&o<96&&e.allocateAce(o)},()=>{console.debug(`${s}1 depth: ${o-64}`)},()=>{console.debug(`${s}2 source: ${o}`),o&&o<96&&e.allocateAce(o)},()=>{console.debug(`${s}2 depth: ${o-64}`)},()=>{console.debug(`${s}to EQ: ${o?"ON":"OFF"}`)}][a[0]+n]||function(d,l){console.warn(`Unknown GS EFX address: ${l}`)})(o,a[0]+n)})}).add([66,18,65],(a,c,f)=>{v((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],(a,c,f)=>{var s;switch(a[0]){case 0:{let i=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",i);break}case 32:{x(e,fe,Date.now()+3200),a[1]==0&&(a[2]?(x(e,W,Math.max(Math.min(a[2]-1,9),0)),P()&&console.debug(`GS switch display page ${a[2]-1}.`)):(x(e,W,0),x(e,fe,Date.now()),P()&&console.debug("GS disable display page.")));break}default:if(a[0]<6){t(e,W)>9&&x(e,W,0);let i=a[0]-1<<1|a[1]>>6;t(e,W)==i&&x(e,fe,Date.now()+3200),(s=t(e,we)[i])!=null&&s.length||(t(e,we)[i]=new Uint8Array(256));let o=t(e,we)[i];P()&&console.debug(`GS frame draw page ${i}.`);let n=a[1]&63;o.fill(0),a.subarray(2).forEach(function(l,m){let $=m+n,M=Math.floor($/16),U=$%16,ge=(U*4+M)*5,$t=5,ot=0;for(ge-=U*4,M==3&&($t=1);ot<$t;)o[ge+ot]=l>>4-ot&1,ot++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let k=function(a,c,f){e.dispatchEvent("mupromptex");let s=a[0],i=g.cc*c,o=g.rpn*c,n=`GS CH${c+1} `;s<3?(a.subarray(1).forEach((d,l)=>{[()=>{t(e,p)[i+b[0]]=d},()=>{t(e,A)[c]=d},()=>{let m=0;d<16?m=e.chRedir(d,f,!0):m=g.ch,t(e,G)[c]=m,c!=m&&(e.buildRchTree(),console.info(`${n}receives from CH${m+1}`))}][s+l]()}),e.dispatchEvent("voice",{part:c})):s<19||(s<44?a.subarray(1).forEach((d,l)=>{([()=>{t(e,j)[c]=+!d},!1,()=>{e.setChType(c,d<<1,w.gs),console.debug(`${n}type: ${d?"drum ":"melodic"}${d||""}`)},()=>{t(e,R)[o+3]=d,t(e,L)[g.rpnt*c+2]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},!1,()=>{t(e,p)[i+b[7]]=d},!1,!1,()=>{t(e,p)[i+b[10]]=d||128},!1,!1,()=>{console.debug(`${n}CC 1: cc${d}`)},()=>{console.debug(`${n}CC 2: cc${d}`)},()=>{t(e,p)[i+b[93]]=d},()=>{t(e,p)[i+b[91]]=d},!1,!1,()=>{t(e,R)[o+1]=d,t(e,L)[g.rpnt*c+1]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},()=>{t(e,R)[o+2]=d,t(e,L)[g.rpnt*c+1]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},()=>{t(e,p)[i+b[94]]=d}][s+l-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},S=function(a,c){let f=a[0],s=`GS CH${c+1} `;f<2?a.subarray(1).forEach((i,o)=>{[()=>{t(e,p)[g.cc*c+b[32]]=i},()=>{}][f+o]()}):f<32?console.warn(`Unknown GS misc address: ${f}`):f<35?a.subarray(1).forEach((i,o)=>{[()=>{console.debug(`${s}EQ: o${["ff","n"][i]}`)},()=>{},()=>{console.debug(`${s}EFX: o${["ff","n"][i]}`),t(e,ze)[c]=i,e.dispatchEvent("partefxtoggle",{part:c,active:i})}][f+o-32]()}):console.warn(`Unknown GS misc address: ${f}`)};t(this,ne).add([66,18,64,16],(a,c)=>{k(a,e.chRedir(9,c,!0),c)}).add([66,18,64,17],(a,c)=>{k(a,e.chRedir(0,c,!0),c)}).add([66,18,64,18],(a,c)=>{k(a,e.chRedir(1,c,!0),c)}).add([66,18,64,19],(a,c)=>{k(a,e.chRedir(2,c,!0),c)}).add([66,18,64,20],(a,c)=>{k(a,e.chRedir(3,c,!0),c)}).add([66,18,64,21],(a,c)=>{k(a,e.chRedir(4,c,!0),c)}).add([66,18,64,22],(a,c)=>{k(a,e.chRedir(5,c,!0),c)}).add([66,18,64,23],(a,c)=>{k(a,e.chRedir(6,c,!0),c)}).add([66,18,64,24],(a,c)=>{k(a,e.chRedir(7,c,!0),c)}).add([66,18,64,25],(a,c)=>{k(a,e.chRedir(8,c,!0),c)}).add([66,18,64,26],(a,c)=>{k(a,e.chRedir(10,c,!0),c)}).add([66,18,64,27],(a,c)=>{k(a,e.chRedir(11,c,!0),c)}).add([66,18,64,28],(a,c)=>{k(a,e.chRedir(12,c,!0),c)}).add([66,18,64,29],(a,c)=>{k(a,e.chRedir(13,c,!0),c)}).add([66,18,64,30],(a,c)=>{k(a,e.chRedir(14,c,!0),c)}).add([66,18,64,31],(a,c)=>{k(a,e.chRedir(15,c,!0),c)}).add([66,18,64,64],(a,c)=>{S(a,e.chRedir(9,c,!0))}).add([66,18,64,65],(a,c)=>{S(a,e.chRedir(0,c,!0))}).add([66,18,64,66],(a,c)=>{S(a,e.chRedir(1,c,!0))}).add([66,18,64,67],(a,c)=>{S(a,e.chRedir(2,c,!0))}).add([66,18,64,68],(a,c)=>{S(a,e.chRedir(3,c,!0))}).add([66,18,64,69],(a,c)=>{S(a,e.chRedir(4,c,!0))}).add([66,18,64,70],(a,c)=>{S(a,e.chRedir(5,c,!0))}).add([66,18,64,71],(a,c)=>{S(a,e.chRedir(6,c,!0))}).add([66,18,64,72],(a,c)=>{S(a,e.chRedir(7,c,!0))}).add([66,18,64,73],(a,c)=>{S(a,e.chRedir(8,c,!0))}).add([66,18,64,74],(a,c)=>{S(a,e.chRedir(10,c,!0))}).add([66,18,64,75],(a,c)=>{S(a,e.chRedir(11,c,!0))}).add([66,18,64,76],(a,c)=>{S(a,e.chRedir(12,c,!0))}).add([66,18,64,77],(a,c)=>{S(a,e.chRedir(13,c,!0))}).add([66,18,64,78],(a,c)=>{S(a,e.chRedir(14,c,!0))}).add([66,18,64,79],(a,c)=>{S(a,e.chRedir(15,c,!0))}),t(this,$e).add([54,65],(a,c)=>{let f=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(f,!0),e.setPortMode(e.getTrackPort(c),1,w[f]);let s=a[a.length-1],i=a.subarray(0,a.length-1),o=xe(i);o!=s&&(console.info(`X5D multi parameters checksum mismatch! Expected ${o}, got ${s}.`),console.debug(a));let n=(a[1]<<7)+a[0],d=(a[3]<<7)+a[2],l=e.chRedir(n&15,c,!0),m=g.cc*l;[()=>{d<1||(d<101?(e.setChType(l,e.CH_MELODIC,w.x5d),t(e,A)[l]=d-1,t(e,p)[m+b[0]]=t(e,B).x5):d<229?(e.setChType(l,e.CH_MELODIC,w.x5d),t(e,A)[l]=d-101,t(e,p)[m+b[0]]=56):(e.setChType(l,e.CH_DRUMS,w.x5d),t(e,A)[l]=Kt[d-229]||0,t(e,p)[m+b[0]]=62)),e.dispatchEvent("voice",{part:l})},()=>{t(e,p)[m+b[7]]=d},()=>{d<31&&(t(e,p)[m+b[10]]=Math.round((d-15)*4.2+64))},()=>{t(e,p)[m+b[93]]=tt(d)},()=>{t(e,p)[m+b[91]]=tt(d)},()=>{t(e,R)[l*g.rpn+3]=d>8191?d-16320:64+d,t(e,L)[g.rpnt*l+2]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)})},()=>{t(e,R)[l*g.rpn+1]=d>8191?d-16320:64+d,t(e,L)[g.rpnt*l+1]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)})},()=>{d>0&&(t(e,R)[l*g.rpn]=d,t(e,L)[g.rpnt*l]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)}))},()=>{}][n>>4]()}).add([54,76,0],(a,c)=>{e.dispatchEvent("mupromptex");let f=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(c),1,w[f]);let s="",i=t(e,B).x5,o=0,n=0,d="MSB PRG LSB NME";le(a,function(l,m){if(m<16400){let $=m%164;switch(!0){case $<10:{l>31&&(s+=String.fromCharCode(l));break}case $==10:break;case $==11:{d+=` +`,a);return}r.run(s.subarray(1))}).add([100,76],(a,c,f)=>{let s=a[0]>>4,i=a[0]&15,o=a[1];switch(s){case 2:{let n=e.chRedir(i,c,!0),d=g.cc*n;a.subarray(2).forEach((l,m)=>{let $=m+o;if(!($<7)){if($<23){let M=$+135;e.allocateAce(M),t(e,p)[d+b[M]]=l,e.dispatchEvent("cc",{part:n,cc:M,data:l})}}});break}default:console.info("Unknown DX7+ multipart: %o",a)}}).add([1,20],(a,c,f)=>{f==115?(e.switchMode("doc",!0),e.setPortMode(e.getTrackPort(c),1,w.doc),console.info("MIDI reset: DOC")):console.debug(`Unknown Yamaha SysEx: 67, ${f}, ${a.join(", ")}`)}).add([1,17,15,89],(a,c,f)=>{f==115?(e.setEffectType(0,24,a[0]|16),e.dispatchEvent("efxreverb",e.getEffectType(0))):console.debug(`Unknown Yamaha SysEx: 67, ${f}, ${a.join(", ")}`)}).add([1,24],(a,c,f)=>{if(f==115){for(let s=0;s<16;s++){let i=e.chRedir(s,c,!0);t(e,p)[i*g.cc+b[91]]=127}console.info("DOC Global Reverb: on")}else console.debug(`Unknown Yamaha SysEx: 67, ${f}, ${a.join(", ")}`)}),r.add([14,31],(a,c,f)=>{t(e,p)[g.cc*a[0]+b[64]]=0,t(e,_).ano(a[0]),e.switchMode("xg"),e.setPortMode(e.getTrackPort(c),1,w.xg),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${a[0]+1}.`)}).add([76,112],async a=>{let c=a[0],f=g.cc*c,s=g.ext*c,i=g.cvn*c;t(e,ee)[s]=e.EXT_DX,t(e,ue)[c]=1;let o=t(e,rt).subarray(i,i+g.cvn);o.fill(32),a.subarray(1).forEach((n,d)=>{if(d<10)o[d]=Math.max(n,32);else if(!(d<40)){if(d<56){let l=d+102;t(e,p)[f+b[l]]=n,e.dispatchEvent("cc",{part:c,cc:l,data:n})}}}),t(e,A)[c]=c&127,t(e,p)[g.cc*c+b[0]]=35,t(e,p)[g.cc*c+b[32]]=c>>7|4,e.dispatchEvent("voice",{part:c}),console.debug(`DX7+ CH${c+1} dump: %o`,a)});let u=function(a,c,f,s){},E=function(a,c){e.dispatchEvent("mupromptex");let f=a*g.dpn,s=c[0],i=c[1];c.subarray(2).forEach((o,n)=>{let d=n+i,l=-1;d<16?([()=>{l=24},()=>{l=25},()=>{l=26},()=>{},()=>{l=28},()=>{l=29},()=>{l=30},()=>{l=31},()=>{},()=>{},()=>{},()=>{l=20},()=>{l=21},()=>{l=22},()=>{l=23},()=>{}][d]||(()=>{console.debug(`Unknown XG-style drum param ${d} on set ${a+1}.`)}))():d<32||(d<40?([()=>{l=48},()=>{l=49},!1,!1,()=>{l=52},()=>{l=53}][d-32]||(()=>{console.debug(`Unknown XG-style drum param ${d} on set ${a+1}.`)}))():d<80||([()=>{l=36}][d-80]||(()=>{console.debug(`Unknown XG-style drum param ${d} on set ${a+1}.`)}))()),l>=0?(P()&&console.debug(f,l,s,o),t(e,Y)[(f+de[l])*g.dnc+s]=o):P()&&console.debug(`XG-style drum param ${d} has no writes.`)})},v=function(a,c,f){e.dispatchEvent("mupromptex");let s=a*g.dpn,i=(c<<7)+f[0];f.subarray(1).forEach((o,n)=>{let d=n+i,l=d&127,m=d>>7,$=-1;m>1&&([()=>{$=26},()=>{},()=>{$=28},()=>{$=29},()=>{$=30},()=>{},()=>{},()=>{$=31}][m-2]||(()=>{console.debug(`Unknown GS-style drum param ${m} on set ${a+1}.`)}))(),$>-1?(P()&&console.debug(s,$,l,o),t(e,Y)[(s+de[$])*g.dnc+l]=o):P()&&console.debug(`GS-style drum param ${m} has no writes.`)})};t(this,re).add([76,48],(a,c,f)=>{E(0,a)}).add([76,49],(a,c,f)=>{E(1,a)}).add([76,50],(a,c,f)=>{E(2,a)}).add([76,51],(a,c,f)=>{E(3,a)}).add([76,52],(a,c,f)=>{E(4,a)}).add([76,53],(a,c,f)=>{E(5,a)}).add([76,54],(a,c,f)=>{E(6,a)}).add([76,55],(a,c,f)=>{E(7,a)}),t(this,re).add([89,0],(a,c,f)=>{if(e.eprom){let s=a[0],i=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);P()&&console.debug(`MU1000 EPROM trail to 0x${i.toString(16).padStart(6,"0")}, ${s} bytes.`);let o=e.eprom.data;a.subarray(4).forEach((n,d)=>{let l=d>>3,m=d&7;if(m==7)for(let $=0;$<7;$++)o[i+7*l+$]+=(n>>6-$&1)<<7;else o[i+7*l+m]=n})}}).add([89,1],(a,c,f)=>{let s=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];P()&&console.debug(`MU1000 EPROM jump to 0x${s.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=s)}).add([89,2],(a,c,f)=>{if(e.eprom){let s=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);P()&&console.debug(`MU1000 EPROM write to 0x${s.toString(16).padStart(6,"0")}.`);let i=e.eprom.data;a.subarray(4).forEach((o,n)=>{let d=n>>3,l=n&7;if(l==7)for(let m=0;m<7;m++)i[s+7*d+m]+=(o>>6-m&1)<<7;else i[s+7*d+l]=o})}}).add([89,3],(a,c,f)=>{}),t(this,re).add([39,48],(a,c,f)=>{}).add([43,0,0],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(o,n)=>{s[n]=o};if(a.subarray(1).forEach((o,n)=>{let d=n+a[0];[i,i,i,i,()=>{x(this,H,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},()=>o-64,()=>o||128,()=>o,()=>o,()=>{console.debug(`TG300 variation on cc${o}.`)}][d](o,d)}),a[0]<4){let o=0;s.forEach(n=>{o=o<<4,o+=n}),o-=1024}}).add([43,1,0],(a,c,f)=>{e.dispatchEvent("mupromptex")}).add([43,2],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=e.chRedir(a[0],c,!0),i=a[1],o=g.cc*s,n=`TG300 CH${s+1} `;a.subarray(2).forEach((d,l)=>{l<5?([()=>{},()=>{t(e,p)[o+b[0]]=d,e.dispatchEvent("voice",{part:s})},()=>{t(e,p)[o+b[32]]=d,e.dispatchEvent("voice",{part:s})},()=>{t(e,A)[s]=d,e.dispatchEvent("voice",{part:s})},()=>{let m=e.chRedir(d,c,!0);t(e,G)[s]=m,s!=m&&(e.buildRchTree(),console.info(`${n}receives from CH${m+1}`))}][l+i]||(()=>{}))(d,l+i):l<21||(l<47?([()=>{t(e,Z)[s]=+!d},()=>{},()=>{},()=>{t(e,R)[g.rpn*s+3]=d,t(e,L)[g.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{},()=>{t(e,p)[o+b[7]]=d},!1,!1,()=>{t(e,p)[o+b[10]]=d||128},!1,!1,()=>{console.debug(`${n} AC1 at cc${d}`)},()=>{console.debug(`${n} AC2 at cc${d}`)},()=>{t(e,p)[o+b[128]]=d,e.allocateAce(128)},()=>{t(e,p)[o+b[93]]=d},()=>{t(e,p)[o+b[91]]=d},()=>{t(e,p)[o+b[94]]=d},()=>{t(e,p)[o+b[76]]=d},()=>{t(e,p)[o+b[77]]=d},()=>{t(e,p)[o+b[74]]=d},()=>{t(e,p)[o+b[71]]=d},()=>{t(e,p)[o+b[73]]=d},()=>{t(e,p)[o+b[75]]=d},()=>{t(e,p)[o+b[72]]=d},()=>{t(e,p)[o+b[78]]=d}][l+i-21]||(()=>{}))(d,l+i):l<95||([()=>{t(e,p)[o+b[65]]=d},()=>{t(e,p)[o+b[5]]=d}][l+i-95]||(()=>{}))(d,l+i))})}).add([43,7,0],(a,c,f)=>{let s=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",s)}).add([43,7,1],(a,c,f)=>{x(e,W,0),x(e,fe,Date.now()+3200),t(e,se,ve).fill(0),a.forEach(function(s,i){let o=Math.floor(i/16),n=i%16,d=(n*3+o)*7,l=7,m=0;for(d-=n*5,o==2&&(l=2);m>6-m&1,m++})}),t(this,ne).add([66,18,0,0,127],(a,c,f)=>{e.switchMode("sc",!0),e.setPortMode(e.getTrackPort(c),2,w.sc),t(e,p)[g.cc*9]=120,t(e,p)[g.cc*25]=120,t(e,p)[g.cc*41]=120,t(e,p)[g.cc*57]=120,t(e,F)[w.sc][1]=t(e,B).sc,x(e,N,!1),t(e,Se).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,c,f)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),e.setPortMode(e.getTrackPort(c),2,w.gs),t(e,F)[w.gs][1]=t(e,B).gs,t(e,p)[g.cc*9]=120,t(e,p)[g.cc*25]=120,t(e,p)[g.cc*41]=120,t(e,p)[g.cc*57]=120,x(e,N,!1),t(e,Se).fill(0),console.info("MIDI reset: GS");break}default:{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(o,n)=>{s[n]=o};if(a.subarray(1).forEach((o,n)=>{let d=n+a[0];[i,i,i,i,l=>{x(this,H,l*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},l=>{},l=>{}][d](o,n)}),a[0]<4){let o=0;s.forEach(n=>{o=o<<4,o+=n}),o-=1024}}}}).add([66,18,64,1],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=a[0];if(s<16){let i="".padStart(s," ");a.subarray(1).forEach((o,n)=>{i+=String.fromCharCode(Math.max(32,o))}),i=i.padEnd(16," "),console.debug(`GS patch name: ${i}`)}else s<48||(s<65?a.subarray(1).forEach((i,o)=>{let n=`GS ${s+o>55?"chorus":"reverb"} `;([()=>{console.info(`${n}type: ${bt[i]}`),e.setEffectType(0,40,i),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${n}predelay: ${i}ms`)},()=>{console.info(`${n}type: ${Lt[i]}`),e.setEffectType(1,40,16+i),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${n}to reverb: ${J(i)}`)},()=>{console.debug(`${n}to delay: ${J(i)}`)}][s+o-48]||(()=>{}))()}):s<80?console.debug(`Unknown GS patch address: ${s}`):s<91?a.subarray(1).forEach((i,o)=>{let n="GS delay ";([()=>{console.info(`${n}type: ${Ut[i]}`),e.setEffectType(2,40,32+i),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${n}to reverb: ${J(i)}`)}][s+o-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${s}`))}).add([66,18,64,2],(a,c,f)=>{let s="GS EQ ";a.subarray(1).forEach((i,o)=>{([()=>{console.debug(`${s}low freq: ${[200,400][i]}Hz`)},()=>{console.debug(`${s}low gain: ${i-64}dB`)},()=>{console.debug(`${s}high freq: ${[3e3,6e3][i]}Hz`)},()=>{console.debug(`${s}high gain: ${i-64}dB`)}][a[0]+o]||function(){console.warn(`Unknown GS EQ address: ${a[0]+o}`)})()})}).add([66,18,64,3],(a,c,f)=>{e.dispatchEvent("mupromptex");let s="GS EFX ",i=function(o,n){let d=Bt(t(e,te).subarray(10,12),n,o);d&&console.debug(`${s}${gt(t(e,te).subarray(10,12))} ${d}`)};a.subarray(1).forEach((o,n)=>{([()=>{e.setEffectTypeRaw(3,!1,32+o),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,o),console.info(`${s}type: ${gt(t(e,te).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,i,()=>{console.debug(`${s}to reverb: ${J(o)}dB`)},()=>{console.debug(`${s}to chorus: ${J(o)}dB`)},()=>{console.debug(`${s}to delay: ${J(o)}dB`)},!1,()=>{console.debug(`${s}1 source: ${o}`),o&&o<96&&e.allocateAce(o)},()=>{console.debug(`${s}1 depth: ${o-64}`)},()=>{console.debug(`${s}2 source: ${o}`),o&&o<96&&e.allocateAce(o)},()=>{console.debug(`${s}2 depth: ${o-64}`)},()=>{console.debug(`${s}to EQ: ${o?"ON":"OFF"}`)}][a[0]+n]||function(d,l){console.warn(`Unknown GS EFX address: ${l}`)})(o,a[0]+n)})}).add([66,18,65],(a,c,f)=>{v((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],(a,c,f)=>{var s;switch(a[0]){case 0:{let i=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",i);break}case 32:{x(e,fe,Date.now()+3200),a[1]==0&&(a[2]?(x(e,W,Math.max(Math.min(a[2]-1,9),0)),P()&&console.debug(`GS switch display page ${a[2]-1}.`)):(x(e,W,0),x(e,fe,Date.now()),P()&&console.debug("GS disable display page.")));break}default:if(a[0]<6){t(e,W)>9&&x(e,W,0);let i=a[0]-1<<1|a[1]>>6;t(e,W)==i&&x(e,fe,Date.now()+3200),(s=t(e,we)[i])!=null&&s.length||(t(e,we)[i]=new Uint8Array(256));let o=t(e,we)[i];P()&&console.debug(`GS frame draw page ${i}.`);let n=a[1]&63;o.fill(0),a.subarray(2).forEach(function(l,m){let $=m+n,M=Math.floor($/16),U=$%16,ge=(U*4+M)*5,$t=5,ot=0;for(ge-=U*4,M==3&&($t=1);ot<$t;)o[ge+ot]=l>>4-ot&1,ot++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let k=function(a,c,f){e.dispatchEvent("mupromptex");let s=a[0],i=g.cc*c,o=g.rpn*c,n=`GS CH${c+1} `;s<3?(a.subarray(1).forEach((d,l)=>{[()=>{t(e,p)[i+b[0]]=d},()=>{t(e,A)[c]=d},()=>{let m=0;d<16?m=e.chRedir(d,f,!0):m=g.ch,t(e,G)[c]=m,c!=m&&(e.buildRchTree(),console.info(`${n}receives from CH${m+1}`))}][s+l]()}),e.dispatchEvent("voice",{part:c})):s<19||(s<44?a.subarray(1).forEach((d,l)=>{([()=>{t(e,Z)[c]=+!d},!1,()=>{e.setChType(c,d<<1,w.gs),console.debug(`${n}type: ${d?"drum ":"melodic"}${d||""}`)},()=>{t(e,R)[o+3]=d,t(e,L)[g.rpnt*c+2]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},!1,()=>{t(e,p)[i+b[7]]=d},!1,!1,()=>{t(e,p)[i+b[10]]=d||128},!1,!1,()=>{console.debug(`${n}CC 1: cc${d}`)},()=>{console.debug(`${n}CC 2: cc${d}`)},()=>{t(e,p)[i+b[93]]=d},()=>{t(e,p)[i+b[91]]=d},!1,!1,()=>{t(e,R)[o+1]=d,t(e,L)[g.rpnt*c+1]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},()=>{t(e,R)[o+2]=d,t(e,L)[g.rpnt*c+1]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},()=>{t(e,p)[i+b[94]]=d}][s+l-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},S=function(a,c){let f=a[0],s=`GS CH${c+1} `;f<2?a.subarray(1).forEach((i,o)=>{[()=>{t(e,p)[g.cc*c+b[32]]=i},()=>{}][f+o]()}):f<32?console.warn(`Unknown GS misc address: ${f}`):f<35?a.subarray(1).forEach((i,o)=>{[()=>{console.debug(`${s}EQ: o${["ff","n"][i]}`)},()=>{},()=>{console.debug(`${s}EFX: o${["ff","n"][i]}`),t(e,ze)[c]=i,e.dispatchEvent("partefxtoggle",{part:c,active:i})}][f+o-32]()}):console.warn(`Unknown GS misc address: ${f}`)};t(this,ne).add([66,18,64,16],(a,c)=>{k(a,e.chRedir(9,c,!0),c)}).add([66,18,64,17],(a,c)=>{k(a,e.chRedir(0,c,!0),c)}).add([66,18,64,18],(a,c)=>{k(a,e.chRedir(1,c,!0),c)}).add([66,18,64,19],(a,c)=>{k(a,e.chRedir(2,c,!0),c)}).add([66,18,64,20],(a,c)=>{k(a,e.chRedir(3,c,!0),c)}).add([66,18,64,21],(a,c)=>{k(a,e.chRedir(4,c,!0),c)}).add([66,18,64,22],(a,c)=>{k(a,e.chRedir(5,c,!0),c)}).add([66,18,64,23],(a,c)=>{k(a,e.chRedir(6,c,!0),c)}).add([66,18,64,24],(a,c)=>{k(a,e.chRedir(7,c,!0),c)}).add([66,18,64,25],(a,c)=>{k(a,e.chRedir(8,c,!0),c)}).add([66,18,64,26],(a,c)=>{k(a,e.chRedir(10,c,!0),c)}).add([66,18,64,27],(a,c)=>{k(a,e.chRedir(11,c,!0),c)}).add([66,18,64,28],(a,c)=>{k(a,e.chRedir(12,c,!0),c)}).add([66,18,64,29],(a,c)=>{k(a,e.chRedir(13,c,!0),c)}).add([66,18,64,30],(a,c)=>{k(a,e.chRedir(14,c,!0),c)}).add([66,18,64,31],(a,c)=>{k(a,e.chRedir(15,c,!0),c)}).add([66,18,64,64],(a,c)=>{S(a,e.chRedir(9,c,!0))}).add([66,18,64,65],(a,c)=>{S(a,e.chRedir(0,c,!0))}).add([66,18,64,66],(a,c)=>{S(a,e.chRedir(1,c,!0))}).add([66,18,64,67],(a,c)=>{S(a,e.chRedir(2,c,!0))}).add([66,18,64,68],(a,c)=>{S(a,e.chRedir(3,c,!0))}).add([66,18,64,69],(a,c)=>{S(a,e.chRedir(4,c,!0))}).add([66,18,64,70],(a,c)=>{S(a,e.chRedir(5,c,!0))}).add([66,18,64,71],(a,c)=>{S(a,e.chRedir(6,c,!0))}).add([66,18,64,72],(a,c)=>{S(a,e.chRedir(7,c,!0))}).add([66,18,64,73],(a,c)=>{S(a,e.chRedir(8,c,!0))}).add([66,18,64,74],(a,c)=>{S(a,e.chRedir(10,c,!0))}).add([66,18,64,75],(a,c)=>{S(a,e.chRedir(11,c,!0))}).add([66,18,64,76],(a,c)=>{S(a,e.chRedir(12,c,!0))}).add([66,18,64,77],(a,c)=>{S(a,e.chRedir(13,c,!0))}).add([66,18,64,78],(a,c)=>{S(a,e.chRedir(14,c,!0))}).add([66,18,64,79],(a,c)=>{S(a,e.chRedir(15,c,!0))}),t(this,$e).add([54,65],(a,c)=>{let f=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(f,!0),e.setPortMode(e.getTrackPort(c),1,w[f]);let s=a[a.length-1],i=a.subarray(0,a.length-1),o=xe(i);o!=s&&(console.info(`X5D multi parameters checksum mismatch! Expected ${o}, got ${s}.`),console.debug(a));let n=(a[1]<<7)+a[0],d=(a[3]<<7)+a[2],l=e.chRedir(n&15,c,!0),m=g.cc*l;[()=>{d<1||(d<101?(e.setChType(l,e.CH_MELODIC,w.x5d),t(e,A)[l]=d-1,t(e,p)[m+b[0]]=t(e,B).x5):d<229?(e.setChType(l,e.CH_MELODIC,w.x5d),t(e,A)[l]=d-101,t(e,p)[m+b[0]]=56):(e.setChType(l,e.CH_DRUMS,w.x5d),t(e,A)[l]=Kt[d-229]||0,t(e,p)[m+b[0]]=62)),e.dispatchEvent("voice",{part:l})},()=>{t(e,p)[m+b[7]]=d},()=>{d<31&&(t(e,p)[m+b[10]]=Math.round((d-15)*4.2+64))},()=>{t(e,p)[m+b[93]]=tt(d)},()=>{t(e,p)[m+b[91]]=tt(d)},()=>{t(e,R)[l*g.rpn+3]=d>8191?d-16320:64+d,t(e,L)[g.rpnt*l+2]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)})},()=>{t(e,R)[l*g.rpn+1]=d>8191?d-16320:64+d,t(e,L)[g.rpnt*l+1]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)})},()=>{d>0&&(t(e,R)[l*g.rpn]=d,t(e,L)[g.rpnt*l]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)}))},()=>{}][n>>4]()}).add([54,76,0],(a,c)=>{e.dispatchEvent("mupromptex");let f=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(c),1,w[f]);let s="",i=t(e,B).x5,o=0,n=0,d="MSB PRG LSB NME";le(a,function(l,m){if(m<16400){let $=m%164;switch(!0){case $<10:{l>31&&(s+=String.fromCharCode(l));break}case $==10:break;case $==11:{d+=` ${i} ${o} ${n} ${s.trim().replace("Init Voice","")}`,o++,s="";break}}o>99&&(i=90,o=0)}}),e.userBank.clearRange({msb:t(e,B).x5,prg:[0,99],lsb:0}),e.userBank.load(d),P()&&console.debug(d),e.forceVoiceRefresh()}).add([54,77,0],(a,c)=>{e.dispatchEvent("mupromptex");let f=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(c),1,w[f]);let s="",i=90,o=0,n=0,d="MSB PRG LSB NME";le(a,function(l,m){if(m<13600){let $=m%136;switch(!0){case $<10:{l>31&&(s+=String.fromCharCode(l));break}case $==11:{d+=` ${i} ${o} ${n} ${s.trim().replace("Init Combi","")}`,o++,s="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(d),P()&&console.debug(d),e.forceVoiceRefresh()}).add([54,78],(a,c)=>{let f=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(c),1,w[f]),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,c)=>{e.dispatchEvent("mupromptex");let f=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(f),e.setPortMode(e.getTrackPort(c),1,w[f]),le(a,(s,i)=>{i>0&&i<3&&(e.setEffectType(i-1,44,s),e.dispatchEvent(`efx${["reverb","chorus"][i-1]}`,e.getEffectType(i-1)))})}).add([54,104],(a,c)=>{e.dispatchEvent("mupromptex");let f=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(f,!0);let s=e.getTrackPort(c);if(t(e,I)[s]&&t(e,I)[s]!=w[f])if(t(e,me).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+s)} mode "${K[t(e,I)[s]]}" mismatch, should be "${f}".`);return}else console.info(`Track ${c} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+s)}.`);e.setPortMode(s,1,w[f]),le(a,function(i,o,n,d){if(o<192){let l=e.chRedir(Math.floor(o/12),c,!0),m=l*g.cc;switch(o%12){case 0:{i<128?(e.setChType(l,e.CH_MELODIC,w.x5d),t(e,p)[m+b[0]]=t(e,B).x5,t(e,A)[l]=i):(e.setChType(l,e.CH_DRUMS,w.x5d),t(e,p)[m+b[0]]=62,t(e,A)[l]=Kt[i-128]),i>0&&e.setChActive(l,1),e.dispatchEvent("voice",{part:l});break}case 1:{t(e,p)[m+b[7]]=i;break}case 2:{t(e,R)[l*g.rpn+3]=i>127?i-192:64+i,t(e,L)[g.rpnt*l+2]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)});break}case 3:{t(e,R)[l*g.rpn+1]=i>127?i-192:64+i,t(e,L)[g.rpnt*l+1]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)});break}case 4:{i<31&&(t(e,p)[m+b[10]]=Math.round((i-15)*4.2+64));break}case 5:{let $=i>>4,M=i&15;t(e,p)[m+b[91]]=tt(M),t(e,p)[m+b[93]]=tt($);break}case 10:break;case 11:{let $=e.chRedir(i&15,c,!0),M=i>>4;t(e,G)[l]=i,($!=l||M)&&(console.info(`X5D Part CH${l+1} receives from CH${$+1}.`),e.buildRchTree())}}}else{let l=e.chRedir(o-192,c,!0)}})}),t(this,ne).add([22,18,127],(a,c,f)=>{e.switchMode("mt32",!0),e.setPortMode(e.getTrackPort(c),1,w.mt32),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,f)=>{e.switchMode("mt32");let s=e.chRedir(f,c,!0),i=a[1];a.subarray(2).forEach((o,n)=>{let d=n+i;t(e,Me)[d+(s-1)*16]=o,([!1,()=>{let l=t(e,Me)[s-1<<4];if(l<3){if(t(e,ue)[s]=1,l==2)for(let m=0;m{t(e,R)[s*g.rpn+3]=o+40,t(e,L)[g.rpnt*s+2]=1},()=>{t(e,R)[s*g.rpn+1]=o+14,t(e,L)[g.rpnt*s+1]=1},()=>{t(e,R)[s*g.rpn]=o,t(e,L)[g.rpnt*s]=1},!1,()=>{t(e,p)[g.cc*s+b[91]]=o?127:0},!1,()=>{t(e,p)[g.cc*s+b[7]]=o},()=>{t(e,p)[g.cc*s+b[10]]=Math.ceil(o*9.05)}][d]||(()=>{}))()})}).add([22,18,1],(a,c,f)=>{e.switchMode("mt32");let s=f&7;console.debug(`MT-32 slot #${f+1} Drum: ${a}`);let i=a[0]<<7|a[1];a.subarray(2).forEach((o,n)=>{let d=n+i,l=(d>>2)+24,m=d&3,$=s*g.dpn;if(P()&&console.debug(`MT-32 temp drum note ${l} param ${m}: ${o}`),l<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${l}`);return}[()=>{},()=>{t(e,Y)[($+de[26])*g.dnc+l]=Math.round(o*1.27)},()=>{t(e,Y)[($+de[26])*g.dnc+l]=o*9+1&127},()=>{t(e,Y)[($+de[26])*g.dnc+l]=o?127:0}][m]()})}).add([22,18,2],(a,c,f)=>{e.switchMode("mt32");let s=e.chRedir(f,c,!0),i=a[1]+(a[0]<<7);i<10&&(t(e,ue)[s]=1),a.subarray(2).forEach((o,n)=>{let d=n+i;d<14&&(t(e,pe)[(s-1)*g.cmt+d]=o)}),e.dispatchEvent("voice",{part:s})}).add([22,18,3],(a,c,f)=>{e.switchMode("mt32");let s=f&7;if(a[0]){let i=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((o,n)=>{let d=n+i,l=(d>>2)+24,m=d&3,$=s*g.dpn;if(P()&&console.debug(`MT-32 dev drum note ${l} param ${m}: ${o}`),l<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${l}`);return}[()=>{},()=>{t(e,Y)[($+de[26])*g.dnc+l]=Math.round(o*1.27)},()=>{t(e,Y)[($+de[26])*g.dnc+l]=o*9+1&127},()=>{t(e,Y)[($+de[26])*g.dnc+l]=o?127:0}][m]()})}else{let i=a[1];a.subarray(2).forEach((o,n)=>{let d=n+i;t(e,Me)[d]=o;let l=e.chRedir(1+(d>>4),c,!0),m=d&15;([!1,()=>{let $=t(e,Me)[l-1<<4];if($<3)if(t(e,ue)[l]=1,$==2)for(let M=0;M{t(e,R)[l*g.rpn+3]=o+40,t(e,L)[g.rpnt*l+2]=1},()=>{t(e,R)[l*g.rpn+1]=o+14,t(e,L)[g.rpnt*l+1]=1},()=>{t(e,R)[l*g.rpn]=o,t(e,L)[g.rpnt*l]=1},!1,()=>{t(e,p)[g.cc*l+b[91]]=o?127:0},!1,()=>{t(e,p)[g.cc*l+b[7]]=o},()=>{t(e,p)[g.cc*l+b[10]]=Math.ceil(o*9.05)}][m]||(()=>{}))()})}}).add([22,18,4],(a,c,f)=>{e.switchMode("mt32");let s=a[1]+(a[0]<<7),i=[];a.subarray(2).forEach((o,n)=>{let d=n+s,l=e.chRedir(Math.floor(d/246+1),c,!0),m=d%246;m<14&&(t(e,pe)[(l-1)*g.cmt+m]=o),m<10&&(t(e,ue)[l]=1),i.indexOf(l)<0&&i.push(l)}),i.forEach(o=>{e.dispatchEvent("voice",{part:o})})}).add([22,18,5],(a,c,f)=>{e.switchMode("mt32");let s=(a[0]<<7)+a[1];a.subarray(2).forEach((i,o)=>{let n=s+o,d=Math.floor(n/8),l=n&7,m=d*8;t(e,We)[n]=i,([!1,()=>{let $=t(e,We)[m];if($<3){let M="";if($==2){let ge=g.cmt*d;M=`MT-m:${i.toString().padStart(3,"0")}`}else M=e.baseBank.get(0,i+($<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:d});let U=`MSB LSB PRG NME 000 127 ${d} ${M}`;e.userBank.load(U,!0)}}][l]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,c,f)=>{e.switchMode("mt32");let s=((a[0]&1)<<7)+a[1],i=a[0]>>1,o=!1;if(a.subarray(2).forEach((n,d)=>{let l=s+d;l{e.switchMode("mt32");let s=a[1],i=!1,o=function(n,d){t(e,G)[d-12]=n,i=!0};a.subarray(2).forEach((n,d)=>{let l=d+s;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,o,o,o,o,o,o,o,o,o,()=>{x(e,H,n),e.dispatchEvent("mastervolume",t(e,H))}][l]||(()=>{}))(n,d)}),i&&e.buildRchTree()}).add([22,18,32],(a,c,f)=>{e.switchMode("mt32");let s=a[1],i=" ".repeat(s);a.subarray(2).forEach(o=>{o>31?i+=String.fromCharCode(o):i+=" "}),x(e,Re,i.padStart(20," ")),x(e,De,Date.now()+3200)}).add([22,18,82],(a,c)=>{let f=e.chRedir(0,c,!0);for(let s=0;s<16;s++)t(e,_).ano(f+s),s&&s<10&&(t(e,A)[f+s]=Et[s-1]);console.info("MT-32 alt reset complete.")}),t(this,$e).add([66,0],(a,c)=>{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(c),2,w.ns5r),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)=>{let f=["ns5r","05rw"][a[0]];e.switchMode(f,!0),e.setPortMode(e.getTrackPort(c),2,w[f]),x(e,N,!1)}).add([66,18,0,0],(a,c)=>{let f=a[0];switch(f){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(c),2,w.ns5r),x(e,N,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(f<10){let s=[0,0,0,0],i=(o,n)=>{s[n]=o};if(a.subarray(1).forEach((o,n)=>{[i,i,i,i,()=>{x(e,H,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][f+n]()}),a[0]<4){let o=0;s.forEach(n=>{o=o<<4,o+=n}),o-=1024}}}}).add([66,18,0,1],(a,c)=>{}).add([66,18,0,2],(a,c)=>{}).add([66,18,1],(a,c)=>{e.dispatchEvent("mupromptex");let f=e.chRedir(a[0],c,!0),s=f*g.cc,i=a[1],o=`NS5R CH${f+1} `;a.subarray(2).forEach((n,d)=>{let l=i+d;l<3?([()=>{t(e,p)[s+b[0]]=n||Fe.bank0},()=>{t(e,p)[s+b[32]]=n},()=>{t(e,A)[f]=n}][l](),e.dispatchEvent("voice",{part:f})):l<8||(l<14?[()=>{let m=e.chRedir(n,c,!0);t(e,G)[f]=m,f!=m&&(e.buildRchTree(),console.info(`${o}receives from CH${m+1}`))},()=>{t(e,j)[f]=+!n},()=>{e.setChType(f,n,w.ns5r),console.debug(`${o}type: ${et[n]}`)},()=>{t(e,R)[g.rpn*f+3]=n,t(e,L)[g.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{},()=>{}][l-8]():l<16||(l<33?[()=>{t(e,p)[s+b[7]]=n},()=>{t(e,p)[s+b[11]]=n},()=>{},()=>{},()=>{t(e,p)[s+b[10]]=n||128},()=>{},()=>{},()=>{t(e,p)[s+b[93]]=n},()=>{t(e,p)[s+b[91]]=n},()=>{t(e,p)[s+b[76]]=n},()=>{t(e,p)[s+b[77]]=n},()=>{t(e,p)[s+b[78]]=n},()=>{t(e,p)[s+b[74]]=n},()=>{t(e,p)[s+b[71]]=n},()=>{t(e,p)[s+b[73]]=n},()=>{t(e,p)[s+b[75]]=n},()=>{t(e,p)[s+b[72]]=n}][l-16]():l<112||l<114&&[()=>{t(e,p)[s+b[5]]=n},()=>{t(e,p)[s+b[65]]=n}][l-112]()))})}).add([66,18,8,0],(a,c)=>{let f=a[0];if(f<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let s=f-32;x(e,fe,Date.now()+3200),x(e,W,10),t(e,se,ve).fill(0);let i=a.subarray(1),o=4;i.forEach(function(n,d){let l=d+s,m=l>>4,$=l&15;if(l<80){let M=m>3,U=0,ge=m0;)t(e,se,ve)[$*32+m*7+(ge-U)]=M&1,M=M>>1,U++}})}}).add([66,18,48],(a,c,f)=>{E(0,a)}).add([66,18,49],(a,c,f)=>{E(1,a)}).add([66,18,50],(a,c,f)=>{E(2,a)}).add([66,18,51],(a,c,f)=>{E(3,a)}).add([66,18,52],(a,c,f)=>{E(4,a)}).add([66,18,53],(a,c,f)=>{E(5,a)}).add([66,18,54],(a,c,f)=>{E(6,a)}).add([66,18,55],(a,c,f)=>{E(7,a)}).add([66,52],(a,c)=>{e.switchMode("ns5r"),x(e,N,!1);let f="";le(a,(s,i)=>{i<8?(s>31&&(f+=String.fromCharCode(s)),i==7&&(e.aiEfxName=f)):i<10&&(e.setEffectType(i-8,44,s),e.dispatchEvent(`efx${["reverb","chorus"][i-8]}`,e.getEffectType(i-8)))})}).add([66,53],(a,c)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r"),x(e,N,!1);let f="",s=a[a.length-1],i=a.subarray(0,a.length-1),o=xe(i);o!=s&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${o}, got ${s}.`),console.debug(a));let n=e.getTrackPort(c);if(t(e,I)[n]&&t(e,I)[n]!=w.ns5r)if(t(e,me).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+n)} mode "${K[t(e,I)[n]]}" mismatch, should be "ns5r".`);return}else console.info(`Track ${c} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+n)}.`);e.setPortMode(n,2,w.ns5r),le(i,function(d,l){switch(!0){case l<2944:{let m=e.chRedir(Math.floor(l/92),c,!0),$=m*g.cc;switch(l%92){case 0:{t(e,p)[$+b[0]]=d,e.dispatchEvent("voice",{part:m});break}case 1:{t(e,p)[$+b[32]]=d,!d&&!t(e,p)[$+b[0]]&&(t(e,p)[$+b[0]]=Fe.bank0),e.dispatchEvent("voice",{part:m});break}case 2:{t(e,A)[m]=d,d>0&&e.setChActive(m,1),e.dispatchEvent("voice",{part:m});break}case 3:{let M=e.chRedir(d,c,!0);t(e,G)[m]=M,m!=M&&(console.info(`NS5R CH${m+1} receives from CH${M+1}.`),e.buildRchTree());break}case 7:{t(e,D)[m]=d,e.dispatchEvent("voice",{part:m});break}case 8:{t(e,R)[m*g.rpn+3]=d<40||d>88?d+(d>63?-192:64):d,t(e,L)[g.rpnt*m+2]=1,e.dispatchEvent("pitch",{part:m,pitch:e.getPitchShift(m)});break}case 9:case 10:{t(e,p)[$+b[7]]=d;break}case 11:{t(e,p)[$+b[11]]=d;break}case 14:{t(e,p)[$+b[10]]=d||128;break}case 19:{t(e,p)[$+b[93]]=d;break}case 20:{t(e,p)[$+b[91]]=d;break}case 84:{t(e,p)[$+b[65]]=d;break}case 85:{t(e,p)[$+b[5]]=d;break}}break}case l<3096:break;case l<3134:{let m=l-3096;m<8?(d>31&&(f+=String.fromCharCode(d)),m==7&&(e.aiEfxName=f)):m<10&&(e.setEffectType(m-8,44,d),e.dispatchEvent(`efx${["reverb","chorus"][m-8]}`,e.getEffectType(m-8)));break}case l<8566:break}})}).add([66,54],(a,c)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let f="",s=80,i=0,o=0,n="MSB PRG LSB NME";le(a,function(d,l){let m=l%158;switch(!0){case m<10:{d>31&&(f+=String.fromCharCode(d));break}case m==10:break;case m==11:{s=d&127;break}case m==12:{o=d&127;break}case m==13:{n+=` +000 127 ${i} MT-m:${i}`;e.userBank.load(n,!0)}e.forceVoiceRefresh()}).add([22,18,16],(a,c,f)=>{e.switchMode("mt32");let s=a[1],i=!1,o=function(n,d){t(e,G)[d-12]=n,i=!0};a.subarray(2).forEach((n,d)=>{let l=d+s;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,o,o,o,o,o,o,o,o,o,()=>{x(e,H,n),e.dispatchEvent("mastervolume",t(e,H))}][l]||(()=>{}))(n,d)}),i&&e.buildRchTree()}).add([22,18,32],(a,c,f)=>{e.switchMode("mt32");let s=a[1],i=" ".repeat(s);a.subarray(2).forEach(o=>{o>31?i+=String.fromCharCode(o):i+=" "}),x(e,Re,i.padStart(20," ")),x(e,De,Date.now()+3200)}).add([22,18,82],(a,c)=>{let f=e.chRedir(0,c,!0);for(let s=0;s<16;s++)t(e,_).ano(f+s),s&&s<10&&(t(e,A)[f+s]=Et[s-1]);console.info("MT-32 alt reset complete.")}),t(this,$e).add([66,0],(a,c)=>{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(c),2,w.ns5r),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)=>{let f=["ns5r","05rw"][a[0]];e.switchMode(f,!0),e.setPortMode(e.getTrackPort(c),2,w[f]),x(e,N,!1)}).add([66,18,0,0],(a,c)=>{let f=a[0];switch(f){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(c),2,w.ns5r),x(e,N,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(f<10){let s=[0,0,0,0],i=(o,n)=>{s[n]=o};if(a.subarray(1).forEach((o,n)=>{[i,i,i,i,()=>{x(e,H,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][f+n]()}),a[0]<4){let o=0;s.forEach(n=>{o=o<<4,o+=n}),o-=1024}}}}).add([66,18,0,1],(a,c)=>{}).add([66,18,0,2],(a,c)=>{}).add([66,18,1],(a,c)=>{e.dispatchEvent("mupromptex");let f=e.chRedir(a[0],c,!0),s=f*g.cc,i=a[1],o=`NS5R CH${f+1} `;a.subarray(2).forEach((n,d)=>{let l=i+d;l<3?([()=>{t(e,p)[s+b[0]]=n||Fe.bank0},()=>{t(e,p)[s+b[32]]=n},()=>{t(e,A)[f]=n}][l](),e.dispatchEvent("voice",{part:f})):l<8||(l<14?[()=>{let m=e.chRedir(n,c,!0);t(e,G)[f]=m,f!=m&&(e.buildRchTree(),console.info(`${o}receives from CH${m+1}`))},()=>{t(e,Z)[f]=+!n},()=>{e.setChType(f,n,w.ns5r),console.debug(`${o}type: ${et[n]}`)},()=>{t(e,R)[g.rpn*f+3]=n,t(e,L)[g.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{},()=>{}][l-8]():l<16||(l<33?[()=>{t(e,p)[s+b[7]]=n},()=>{t(e,p)[s+b[11]]=n},()=>{},()=>{},()=>{t(e,p)[s+b[10]]=n||128},()=>{},()=>{},()=>{t(e,p)[s+b[93]]=n},()=>{t(e,p)[s+b[91]]=n},()=>{t(e,p)[s+b[76]]=n},()=>{t(e,p)[s+b[77]]=n},()=>{t(e,p)[s+b[78]]=n},()=>{t(e,p)[s+b[74]]=n},()=>{t(e,p)[s+b[71]]=n},()=>{t(e,p)[s+b[73]]=n},()=>{t(e,p)[s+b[75]]=n},()=>{t(e,p)[s+b[72]]=n}][l-16]():l<112||l<114&&[()=>{t(e,p)[s+b[5]]=n},()=>{t(e,p)[s+b[65]]=n}][l-112]()))})}).add([66,18,8,0],(a,c)=>{let f=a[0];if(f<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let s=f-32;x(e,fe,Date.now()+3200),x(e,W,10),t(e,se,ve).fill(0);let i=a.subarray(1),o=4;i.forEach(function(n,d){let l=d+s,m=l>>4,$=l&15;if(l<80){let M=m>3,U=0,ge=m0;)t(e,se,ve)[$*32+m*7+(ge-U)]=M&1,M=M>>1,U++}})}}).add([66,18,48],(a,c,f)=>{E(0,a)}).add([66,18,49],(a,c,f)=>{E(1,a)}).add([66,18,50],(a,c,f)=>{E(2,a)}).add([66,18,51],(a,c,f)=>{E(3,a)}).add([66,18,52],(a,c,f)=>{E(4,a)}).add([66,18,53],(a,c,f)=>{E(5,a)}).add([66,18,54],(a,c,f)=>{E(6,a)}).add([66,18,55],(a,c,f)=>{E(7,a)}).add([66,52],(a,c)=>{e.switchMode("ns5r"),x(e,N,!1);let f="";le(a,(s,i)=>{i<8?(s>31&&(f+=String.fromCharCode(s)),i==7&&(e.aiEfxName=f)):i<10&&(e.setEffectType(i-8,44,s),e.dispatchEvent(`efx${["reverb","chorus"][i-8]}`,e.getEffectType(i-8)))})}).add([66,53],(a,c)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r"),x(e,N,!1);let f="",s=a[a.length-1],i=a.subarray(0,a.length-1),o=xe(i);o!=s&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${o}, got ${s}.`),console.debug(a));let n=e.getTrackPort(c);if(t(e,I)[n]&&t(e,I)[n]!=w.ns5r)if(t(e,me).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+n)} mode "${K[t(e,I)[n]]}" mismatch, should be "ns5r".`);return}else console.info(`Track ${c} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+n)}.`);e.setPortMode(n,2,w.ns5r),le(i,function(d,l){switch(!0){case l<2944:{let m=e.chRedir(Math.floor(l/92),c,!0),$=m*g.cc;switch(l%92){case 0:{t(e,p)[$+b[0]]=d,e.dispatchEvent("voice",{part:m});break}case 1:{t(e,p)[$+b[32]]=d,!d&&!t(e,p)[$+b[0]]&&(t(e,p)[$+b[0]]=Fe.bank0),e.dispatchEvent("voice",{part:m});break}case 2:{t(e,A)[m]=d,d>0&&e.setChActive(m,1),e.dispatchEvent("voice",{part:m});break}case 3:{let M=e.chRedir(d,c,!0);t(e,G)[m]=M,m!=M&&(console.info(`NS5R CH${m+1} receives from CH${M+1}.`),e.buildRchTree());break}case 7:{t(e,D)[m]=d,e.dispatchEvent("voice",{part:m});break}case 8:{t(e,R)[m*g.rpn+3]=d<40||d>88?d+(d>63?-192:64):d,t(e,L)[g.rpnt*m+2]=1,e.dispatchEvent("pitch",{part:m,pitch:e.getPitchShift(m)});break}case 9:case 10:{t(e,p)[$+b[7]]=d;break}case 11:{t(e,p)[$+b[11]]=d;break}case 14:{t(e,p)[$+b[10]]=d||128;break}case 19:{t(e,p)[$+b[93]]=d;break}case 20:{t(e,p)[$+b[91]]=d;break}case 84:{t(e,p)[$+b[65]]=d;break}case 85:{t(e,p)[$+b[5]]=d;break}}break}case l<3096:break;case l<3134:{let m=l-3096;m<8?(d>31&&(f+=String.fromCharCode(d)),m==7&&(e.aiEfxName=f)):m<10&&(e.setEffectType(m-8,44,d),e.dispatchEvent(`efx${["reverb","chorus"][m-8]}`,e.getEffectType(m-8)));break}case l<8566:break}})}).add([66,54],(a,c)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let f="",s=80,i=0,o=0,n="MSB PRG LSB NME";le(a,function(d,l){let m=l%158;switch(!0){case m<10:{d>31&&(f+=String.fromCharCode(d));break}case m==10:break;case m==11:{s=d&127;break}case m==12:{o=d&127;break}case m==13:{n+=` ${s} ${i} ${o} ${f.trim().replace("Init Voice","")}`,i++,f="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(n),P()&&console.debug(n),e.forceVoiceRefresh()}).add([66,55],(a,c)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let f="",s=88,i=0,o=0,n="MSB PRG LSB NME";le(a,function(d,l){let m=l%126;switch(!0){case m<10:{d>31&&(f+=String.fromCharCode(d));break}case m==11:break;case m==12:break;case m==13:{n+=` -${s} ${i} ${o} ${f.trim().replace("Init Combi","")}`,i++,f="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(n),P()&&console.debug(n),e.forceVoiceRefresh()}).add([66,125],(a,c,f)=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],(a,c,f)=>{let s=a[a.length-1],i=a.subarray(0,a.length-1),o=xe(i);o!=s&&(console.info(`NS5R screen dump checksum mismatch! Expected ${o}, got ${s}.`),console.debug(a));let n=new Uint8Array(5760);le(a,(d,l,m)=>{if(l<720)for(let $=0;$<8;$++)n[l*8+$]=d>>7-$&1}),e.dispatchEvent("screen",{type:"ns5r",data:n})}).add([76],(a,c,f)=>{t(e,$e).run([66,...a],c,f)}),t(this,Ie).add([16,0,8,0],(a,c,f)=>{let s=(a[2]<<4)+a[3],i="K11 ";([()=>{e.switchMode("k11",!0),e.setPortMode(e.getTrackPort(c),2,w.k11),x(e,N,!1),t(e,F)[w.k11][1]=s?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,s),console.debug(`${i}reverb type: ${s}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${i}reverb time: ${s}`)},()=>{console.debug(`${i}reverb time: ${s}`)},()=>{console.debug(`${i}reverb predelay: ${s}`)},()=>{console.debug(`${i}reverb predelay: ${s}`)},()=>{console.debug(`${i}depth high: ${s}`)},()=>{console.debug(`${i}depth high: ${s}`)},()=>{console.debug(`${i}depth low: ${s}`)},()=>{console.debug(`${i}depth low: ${s}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=e.chRedir(a[1],c,!0),i=g.cc*s,o=g.rpn*s,n=(a[3]<<4)+a[4],d=`K11 CH${s+1} `;([()=>{n<128?(e.setChType(s,e.CH_MELODIC,w.k11),t(e,p)[i+b[0]]=0,t(e,A)[s]=n):(e.setChType(s,e.CH_DRUMS,w.k11),t(e,A)[s]=n-128),e.dispatchEvent("voice",{part:s})},()=>{let l=e.chRedir(n,c,!0);t(e,G)[s]=l,s!=l&&(e.buildRchTree(),console.info(`${d}receives from CH${l+1}`))},()=>{t(e,p)[i+b[7]]=n},()=>{uupThis.setChActive(s,n)},()=>{t(e,p)[i+b[10]]=n},()=>{t(e,R)[o+3]=n+40,t(e,L)[g.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{t(e,R)[o+1]=n>>1,t(e,R)[o+2]=n&1,t(e,L)[g.rpnt*s+1]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{t(e,p)[i+b[91]]=n?127:0},()=>{},()=>{t(e,p)[i+b[74]]=n},()=>{t(e,p)[i+b[73]]=n},()=>{t(e,p)[i+b[72]]=n}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=(a[2]<<4)+a[3],i="GMLX ";([()=>{console.debug(`${i}reverb type: ${s}`)},()=>{console.debug(`${i}reverb time: ${s}`)},()=>{console.debug(`${i}reverb predelay: ${s}`)},()=>{console.debug(`${i}depth high: ${s}`)},()=>{console.debug(`${i}depth low: ${s}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=(a[2]<<4)+a[3],i=e.chRedir(a[1],c,!0),o=i*g.cc;[()=>{s<128?(e.setChType(i,e.CH_MELODIC,w.k11),t(e,p)[o+b[0]]=0,t(e,p)[o+b[32]]=0,t(e,A)[i]=s):s<160?(e.setChType(i,e.CH_MELODIC,w.k11),t(e,p)[o+b[0]]=0,t(e,p)[o+b[32]]=7,t(e,A)[i]=s-100):(e.setChType(i,e.CH_DRUMS,w.k11),t(e,p)[o+b[0]]=122,t(e,p)[o+b[32]]=0,t(e,A)[i]=s-160),e.dispatchEvent("voice",{part:i})},()=>{let n=e.chRedir(s,c,!0);t(e,G)[i]=n,i!=n&&(e.buildRchTree(),console.info(`GMLX CH${i+1} receives from CH${n+1}`))}][a[0]]()}).add([16,0,9,4],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=(a[2]<<4)+a[3],i=e.chRedir(a[1],c,!0),o=i*g.cc,n=i*g.rpn,d=`GMLX CH${i+1} `;[()=>{e.setChActive(i,s)},()=>{t(e,p)[o+b[7]]=s},()=>{t(e,p)[o+b[10]]=s},()=>{t(e,p)[o+b[91]]=s?127:0},()=>{t(e,R)[n+3]=s+40,t(e,L)[g.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,R)[n+1]=s,t(e,L)[g.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,R)[n]=s,t(e,L)[g.rpnt*i]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{}][a[0]]()}),t(this,_e).add([66,93,64],(a,c,f)=>{let s=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{e.dispatchEvent("mupromptex"),x(e,H,s*129/16383*100),e.dispatchEvent("mastervolume",t(e,H));break}case 5:{e.dispatchEvent("mupromptex"),s-64;break}case 6:{e.dispatchEvent("mupromptex"),console.debug(`SG global reverb: ${s?"on":"off"}`);break}case 127:{e.switchMode("sg",!0),e.setPortMode(e.getTrackPort(c),1,w.sg);break}}break}case 1:{switch(a[1]){case 48:{e.dispatchEvent("mupromptex"),console.debug(`SG reverb type: ${bt[s]}`);break}}break}default:if(a[0]>>4==1){e.dispatchEvent("mupromptex");let i=e.chRedir(a[0]&15,c,!0);if(a[1]==2){let o=e.chRedir(s,c,!0);t(e,G)[i]=o,i!=o&&(e.buildRchTree(),console.info(`SG CH${i+1} receives from CH${o+1}`))}else a[1]==19&&(t(e,p)[g.cc*i+b[7]]=s)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,Ge).add([9],(a,c,f)=>{e.dispatchEvent("mupromptex"),console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremolo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),t(this,re).add([127,0],(a,c,f)=>{e.switchMode("motif");let s=new Uint8Array([127,1,...a]);t(e,re).run(s,c,f)}).add([127,1,0,0],(a,c,f)=>{e.switchMode("s90es");let s="S90/Motif ES system ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{x(e,H,o*12900/16383),e.dispatchEvent("mastervolume",t(e,H))}][i+n]||(()=>{console.info(`Unrecognized ${s}ID: ${i+n}`)}))()})}).add([127,1,0,36,54,1],(a,c,f)=>{e.switchMode("s90es");let s="S90/Motif ES reverb ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{e.setEffectTypeRaw(0,!1,o&15|112)},()=>{e.setEffectTypeRaw(0,!0,o)}][i+n]||(()=>{}))()}),e.dispatchEvent("efxreverb",e.getEffectType(0))}).add([127,1,0,37,54,2],(a,c,f)=>{e.switchMode("s90es");let s="S90/Motif ES chorus ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{e.setEffectTypeRaw(1,!1,o&15|112)},()=>{e.setEffectTypeRaw(1,!0,o)}][i+n]||(()=>{}))()}),e.dispatchEvent("efxchorus",e.getEffectType(1))}).add([127,1,0,34,54,3],(a,c,f)=>{e.switchMode("s90es");let s="S90/Motif ES insert 1 ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{e.setEffectTypeRaw(3,!1,o&15|112)},()=>{e.setEffectTypeRaw(3,!0,o)}][i+n]||(()=>{}))()}),e.dispatchEvent("efxinsert0",e.getEffectType(3))}).add([127,1,0,34,54,4],(a,c,f)=>{e.switchMode("s90es");let s="S90/Motif ES insert 2 ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{e.setEffectTypeRaw(4,!1,o&15|112)},()=>{e.setEffectTypeRaw(4,!0,o)}][i+n]||(()=>{}))()}),e.dispatchEvent("efxinsert1",e.getEffectType(4))}).add([127,1,0,35,54,17],(a,c,f)=>{e.switchMode("s90es");let s="S90/Motif ES variation ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{e.setEffectTypeRaw(2,!1,o&15|112)},()=>{e.setEffectTypeRaw(2,!0,o)}][i+n]||(()=>{}))()}),e.dispatchEvent("efxdelay",e.getEffectType(2))}).add([127,1,0,58,55],(a,c,f)=>{e.dispatchEvent("mupromptex"),e.switchMode("s90es");let s=e.getTrackPort(c);if(t(e,I)[s]&&t(e,I)[s]!=t(e,B).smotif)if(t(e,me).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+s)} mode "${K[t(e,I)[s]]}" mismatch, should be "${K[t(e,B).smotif]}".`);return}else console.info(`Track ${c} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+s)}.`);let i=e.chRedir(a[0],c,!0),o=g.cc*i,n=a[1];a[0]>15&&(i=a[0]+32);let d=`Track ${c} S90/Motif ES bulk CH${i<128?i+1:"U"+(i-127)} `;console.debug(d,a),!(a[0]>15)&&a.subarray(2).forEach((l,m)=>{([()=>{t(e,p)[o+b[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),t(e,p)[o+b[32]]=l,e.setChType(i,[32,40].indexOf(l)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,O),!0),e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),t(e,A)[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(l,c,!0);t(e,G)[i]=$,i!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))},()=>{t(e,j)[i]=l?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{l!=100&&e.setChActive(i,1),t(e,p)[o+b[7]]=l},()=>{l!=64&&e.setChActive(i,1),t(e,p)[o+b[10]]=l},!1,!1,!1,()=>{t(e,p)[o+b[91]]=l},()=>{l&&e.setChActive(i,1),t(e,p)[o+b[93]]=l},()=>{l&&e.setChActive(i,1),t(e,p)[o+b[94]]=l},()=>{l!=127&&e.setChActive(i,1),t(e,p)[o+b[128]]=l,e.allocateAce(128)},()=>{},()=>{l!=64&&e.setChActive(i,1),t(e,p)[o+b[74]]=l},()=>{l!=64&&e.setChActive(i,1),t(e,p)[o+b[71]]=l},!1,()=>{t(e,p)[o+b[65]]=l},()=>{t(e,p)[o+b[5]]=l},()=>{}][n+m]||(()=>{}))()})}).add([127,1,54,16],(a,c,f)=>{e.switchMode("s90es");let s=a[0];a.subarray(1).forEach((i,o)=>{let d=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let l=i-64},()=>{let l=Ve[i]},()=>{let l=i/10},()=>{let l=i}][s+o&3]||(()=>{}))()})}),t(this,ne).add([0,72,18,0,0,0,0],(a,c,f)=>{e.switchMode("sd",!0),e.setPortMode(e.getTrackPort(c),2,w.sd),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=a[0]>>5,i=a[0]&31;switch(s){case 0:{let o=a[0]>>1,n=a[1];switch(o){case 1:{a.subarray(2).forEach((d,l,m)=>{let $=l+n;switch($){case 0:{d&&(e.setEffectType(1,60,d-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${$} - ${d}`));break}}});break}case 2:{a.subarray(2).forEach((d,l)=>{let m=l+n;switch(m){case 0:{d&&(e.setEffectType(0,55+d,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${m} - ${d}`));break}}});break}case 3:case 4:case 5:{let d=o-1;a.subarray(2).forEach((l,m)=>{let $=m+n;switch(console.debug(`SD MFX ${d-2}: ${$} - ${l}`),$){case 0:{e.setEffectTypeRaw(d,62,l),e.dispatchEvent(`efx${d>2?"delay":"insert"+(d-4)}`,e.getEffectType(d));break}}}),console.debug(`SD MFX message: +${s} ${i} ${o} ${f.trim().replace("Init Combi","")}`,i++,f="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(n),P()&&console.debug(n),e.forceVoiceRefresh()}).add([66,125],(a,c,f)=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],(a,c,f)=>{let s=a[a.length-1],i=a.subarray(0,a.length-1),o=xe(i);o!=s&&(console.info(`NS5R screen dump checksum mismatch! Expected ${o}, got ${s}.`),console.debug(a));let n=new Uint8Array(5760);le(a,(d,l,m)=>{if(l<720)for(let $=0;$<8;$++)n[l*8+$]=d>>7-$&1}),e.dispatchEvent("screen",{type:"ns5r",data:n})}).add([76],(a,c,f)=>{t(e,$e).run([66,...a],c,f)}),t(this,Ie).add([16,0,8,0],(a,c,f)=>{let s=(a[2]<<4)+a[3],i="K11 ";([()=>{e.switchMode("k11",!0),e.setPortMode(e.getTrackPort(c),2,w.k11),x(e,N,!1),t(e,F)[w.k11][1]=s?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,s),console.debug(`${i}reverb type: ${s}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${i}reverb time: ${s}`)},()=>{console.debug(`${i}reverb time: ${s}`)},()=>{console.debug(`${i}reverb predelay: ${s}`)},()=>{console.debug(`${i}reverb predelay: ${s}`)},()=>{console.debug(`${i}depth high: ${s}`)},()=>{console.debug(`${i}depth high: ${s}`)},()=>{console.debug(`${i}depth low: ${s}`)},()=>{console.debug(`${i}depth low: ${s}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=e.chRedir(a[1],c,!0),i=g.cc*s,o=g.rpn*s,n=(a[3]<<4)+a[4],d=`K11 CH${s+1} `;([()=>{n<128?(e.setChType(s,e.CH_MELODIC,w.k11),t(e,p)[i+b[0]]=0,t(e,A)[s]=n):(e.setChType(s,e.CH_DRUMS,w.k11),t(e,A)[s]=n-128),e.dispatchEvent("voice",{part:s})},()=>{let l=e.chRedir(n,c,!0);t(e,G)[s]=l,s!=l&&(e.buildRchTree(),console.info(`${d}receives from CH${l+1}`))},()=>{t(e,p)[i+b[7]]=n},()=>{uupThis.setChActive(s,n)},()=>{t(e,p)[i+b[10]]=n},()=>{t(e,R)[o+3]=n+40,t(e,L)[g.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{t(e,R)[o+1]=n>>1,t(e,R)[o+2]=n&1,t(e,L)[g.rpnt*s+1]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{t(e,p)[i+b[91]]=n?127:0},()=>{},()=>{t(e,p)[i+b[74]]=n},()=>{t(e,p)[i+b[73]]=n},()=>{t(e,p)[i+b[72]]=n}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=(a[2]<<4)+a[3],i="GMLX ";([()=>{console.debug(`${i}reverb type: ${s}`)},()=>{console.debug(`${i}reverb time: ${s}`)},()=>{console.debug(`${i}reverb predelay: ${s}`)},()=>{console.debug(`${i}depth high: ${s}`)},()=>{console.debug(`${i}depth low: ${s}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=(a[2]<<4)+a[3],i=e.chRedir(a[1],c,!0),o=i*g.cc;[()=>{s<128?(e.setChType(i,e.CH_MELODIC,w.k11),t(e,p)[o+b[0]]=0,t(e,p)[o+b[32]]=0,t(e,A)[i]=s):s<160?(e.setChType(i,e.CH_MELODIC,w.k11),t(e,p)[o+b[0]]=0,t(e,p)[o+b[32]]=7,t(e,A)[i]=s-100):(e.setChType(i,e.CH_DRUMS,w.k11),t(e,p)[o+b[0]]=122,t(e,p)[o+b[32]]=0,t(e,A)[i]=s-160),e.dispatchEvent("voice",{part:i})},()=>{let n=e.chRedir(s,c,!0);t(e,G)[i]=n,i!=n&&(e.buildRchTree(),console.info(`GMLX CH${i+1} receives from CH${n+1}`))}][a[0]]()}).add([16,0,9,4],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=(a[2]<<4)+a[3],i=e.chRedir(a[1],c,!0),o=i*g.cc,n=i*g.rpn,d=`GMLX CH${i+1} `;[()=>{e.setChActive(i,s)},()=>{t(e,p)[o+b[7]]=s},()=>{t(e,p)[o+b[10]]=s},()=>{t(e,p)[o+b[91]]=s?127:0},()=>{t(e,R)[n+3]=s+40,t(e,L)[g.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,R)[n+1]=s,t(e,L)[g.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,R)[n]=s,t(e,L)[g.rpnt*i]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{}][a[0]]()}),t(this,_e).add([66,93,64],(a,c,f)=>{let s=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{e.dispatchEvent("mupromptex"),x(e,H,s*129/16383*100),e.dispatchEvent("mastervolume",t(e,H));break}case 5:{e.dispatchEvent("mupromptex"),s-64;break}case 6:{e.dispatchEvent("mupromptex"),console.debug(`SG global reverb: ${s?"on":"off"}`);break}case 127:{e.switchMode("sg",!0),e.setPortMode(e.getTrackPort(c),1,w.sg);break}}break}case 1:{switch(a[1]){case 48:{e.dispatchEvent("mupromptex"),console.debug(`SG reverb type: ${bt[s]}`);break}}break}default:if(a[0]>>4==1){e.dispatchEvent("mupromptex");let i=e.chRedir(a[0]&15,c,!0);if(a[1]==2){let o=e.chRedir(s,c,!0);t(e,G)[i]=o,i!=o&&(e.buildRchTree(),console.info(`SG CH${i+1} receives from CH${o+1}`))}else a[1]==19&&(t(e,p)[g.cc*i+b[7]]=s)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,Ge).add([9],(a,c,f)=>{e.dispatchEvent("mupromptex"),console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremolo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),t(this,re).add([127,0],(a,c,f)=>{e.switchMode("motif");let s=new Uint8Array([127,1,...a]);t(e,re).run(s,c,f)}).add([127,1,0,0],(a,c,f)=>{e.switchMode("s90es");let s="S90/Motif ES system ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{x(e,H,o*12900/16383),e.dispatchEvent("mastervolume",t(e,H))}][i+n]||(()=>{console.info(`Unrecognized ${s}ID: ${i+n}`)}))()})}).add([127,1,0,36,54,1],(a,c,f)=>{e.switchMode("s90es");let s="S90/Motif ES reverb ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{e.setEffectTypeRaw(0,!1,o&15|112)},()=>{e.setEffectTypeRaw(0,!0,o)}][i+n]||(()=>{}))()}),e.dispatchEvent("efxreverb",e.getEffectType(0))}).add([127,1,0,37,54,2],(a,c,f)=>{e.switchMode("s90es");let s="S90/Motif ES chorus ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{e.setEffectTypeRaw(1,!1,o&15|112)},()=>{e.setEffectTypeRaw(1,!0,o)}][i+n]||(()=>{}))()}),e.dispatchEvent("efxchorus",e.getEffectType(1))}).add([127,1,0,34,54,3],(a,c,f)=>{e.switchMode("s90es");let s="S90/Motif ES insert 1 ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{e.setEffectTypeRaw(3,!1,o&15|112)},()=>{e.setEffectTypeRaw(3,!0,o)}][i+n]||(()=>{}))()}),e.dispatchEvent("efxinsert0",e.getEffectType(3))}).add([127,1,0,34,54,4],(a,c,f)=>{e.switchMode("s90es");let s="S90/Motif ES insert 2 ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{e.setEffectTypeRaw(4,!1,o&15|112)},()=>{e.setEffectTypeRaw(4,!0,o)}][i+n]||(()=>{}))()}),e.dispatchEvent("efxinsert1",e.getEffectType(4))}).add([127,1,0,35,54,17],(a,c,f)=>{e.switchMode("s90es");let s="S90/Motif ES variation ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{e.setEffectTypeRaw(2,!1,o&15|112)},()=>{e.setEffectTypeRaw(2,!0,o)}][i+n]||(()=>{}))()}),e.dispatchEvent("efxdelay",e.getEffectType(2))}).add([127,1,0,58,55],(a,c,f)=>{e.dispatchEvent("mupromptex"),e.switchMode("s90es");let s=e.getTrackPort(c);if(t(e,I)[s]&&t(e,I)[s]!=t(e,B).smotif)if(t(e,me).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+s)} mode "${K[t(e,I)[s]]}" mismatch, should be "${K[t(e,B).smotif]}".`);return}else console.info(`Track ${c} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+s)}.`);let i=e.chRedir(a[0],c,!0),o=g.cc*i,n=a[1];a[0]>15&&(i=a[0]+32);let d=`Track ${c} S90/Motif ES bulk CH${i<128?i+1:"U"+(i-127)} `;console.debug(d,a),!(a[0]>15)&&a.subarray(2).forEach((l,m)=>{([()=>{t(e,p)[o+b[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),t(e,p)[o+b[32]]=l,e.setChType(i,[32,40].indexOf(l)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,O),!0),e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),t(e,A)[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(l,c,!0);t(e,G)[i]=$,i!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))},()=>{t(e,Z)[i]=l?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{l!=100&&e.setChActive(i,1),t(e,p)[o+b[7]]=l},()=>{l!=64&&e.setChActive(i,1),t(e,p)[o+b[10]]=l},!1,!1,!1,()=>{t(e,p)[o+b[91]]=l},()=>{l&&e.setChActive(i,1),t(e,p)[o+b[93]]=l},()=>{l&&e.setChActive(i,1),t(e,p)[o+b[94]]=l},()=>{l!=127&&e.setChActive(i,1),t(e,p)[o+b[128]]=l,e.allocateAce(128)},()=>{},()=>{l!=64&&e.setChActive(i,1),t(e,p)[o+b[74]]=l},()=>{l!=64&&e.setChActive(i,1),t(e,p)[o+b[71]]=l},!1,()=>{t(e,p)[o+b[65]]=l},()=>{t(e,p)[o+b[5]]=l},()=>{}][n+m]||(()=>{}))()})}).add([127,1,54,16],(a,c,f)=>{e.switchMode("s90es");let s=a[0];a.subarray(1).forEach((i,o)=>{let d=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let l=i-64},()=>{let l=Ve[i]},()=>{let l=i/10},()=>{let l=i}][s+o&3]||(()=>{}))()})}),t(this,ne).add([0,72,18,0,0,0,0],(a,c,f)=>{e.switchMode("sd",!0),e.setPortMode(e.getTrackPort(c),2,w.sd),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,c,f)=>{e.dispatchEvent("mupromptex");let s=a[0]>>5,i=a[0]&31;switch(s){case 0:{let o=a[0]>>1,n=a[1];switch(o){case 1:{a.subarray(2).forEach((d,l,m)=>{let $=l+n;switch($){case 0:{d&&(e.setEffectType(1,60,d-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${$} - ${d}`));break}}});break}case 2:{a.subarray(2).forEach((d,l)=>{let m=l+n;switch(m){case 0:{d&&(e.setEffectType(0,55+d,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${m} - ${d}`));break}}});break}case 3:case 4:case 5:{let d=o-1;a.subarray(2).forEach((l,m)=>{let $=m+n;switch(console.debug(`SD MFX ${d-2}: ${$} - ${l}`),$){case 0:{e.setEffectTypeRaw(d,62,l),e.dispatchEvent(`efx${d>2?"delay":"insert"+(d-4)}`,e.getEffectType(d));break}}}),console.debug(`SD MFX message: %o`,a);break}default:console.debug(`Unknown SD-90 global effects message: -%o`,a)}break}case 1:{let o=e.chRedir(i,c,!0),n=a[1],d=o*g.cc;a.subarray(2).forEach((l,m)=>{let $=n+m;$<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,p)[d+b[0]]=l,l){case 104:case 105:case 106:case 107:case 120:{t(e,D)[o]||e.setChType(o,e.CH_DRUMS);break}default:t(e,D)[o]&&e.setChType(o,e.CH_MELODIC)}e.dispatchEvent("voice",{part:o})},()=>{t(e,p)[d+b[32]]=l,e.dispatchEvent("voice",{part:o})},()=>{t(e,A)[o]=l,e.dispatchEvent("voice",{part:o})},()=>{t(e,p)[d+b[7]]=l},()=>{t(e,p)[d+b[10]]=l},()=>{},()=>{},()=>{l<2&&(t(e,j)[o]=l)},()=>{l<2&&(t(e,p)[d+b[68]]=l?127:0)},()=>{},()=>{l<2&&(t(e,p)[d+b[65]]=l?127:0)},()=>{t(e,p)[d+b[5]]=l&15<<4|t(e,p)[d+b[5]]&15},()=>{t(e,p)[d+b[5]]=l&15|(t(e,p)[d+b[5]]&240)>>4},()=>{t(e,p)[d+b[74]]=l},()=>{t(e,p)[d+b[71]]=l},()=>{t(e,p)[d+b[73]]=l},()=>{t(e,p)[d+b[72]]=l},0,0,0,0,0,0,0,()=>{t(e,p)[d+b[128]]=l,e.allocateAce(128)},()=>{t(e,p)[d+b[93]]=l},()=>{t(e,p)[d+b[91]]=l},0,0,()=>{t(e,p)[d+b[75]]=l},()=>{t(e,p)[d+b[76]]=l},()=>{t(e,p)[d+b[77]]=l},()=>{t(e,p)[d+b[78]]=l}][$]||(()=>{}))():$<63||($<64?(t(e,D)[o]?t(e,p)[d+b[0]]=104|l:t(e,p)[d+b[0]]=96|l,e.dispatchEvent("voice",{part:o})):console.debug(`Unknown SD-90 global CH${o+1} param setup message: +%o`,a)}break}case 1:{let o=e.chRedir(i,c,!0),n=a[1],d=o*g.cc;a.subarray(2).forEach((l,m)=>{let $=n+m;$<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,p)[d+b[0]]=l,l){case 104:case 105:case 106:case 107:case 120:{t(e,D)[o]||e.setChType(o,e.CH_DRUMS);break}default:t(e,D)[o]&&e.setChType(o,e.CH_MELODIC)}e.dispatchEvent("voice",{part:o})},()=>{t(e,p)[d+b[32]]=l,e.dispatchEvent("voice",{part:o})},()=>{t(e,A)[o]=l,e.dispatchEvent("voice",{part:o})},()=>{t(e,p)[d+b[7]]=l},()=>{t(e,p)[d+b[10]]=l},()=>{},()=>{},()=>{l<2&&(t(e,Z)[o]=l)},()=>{l<2&&(t(e,p)[d+b[68]]=l?127:0)},()=>{},()=>{l<2&&(t(e,p)[d+b[65]]=l?127:0)},()=>{t(e,p)[d+b[5]]=l&15<<4|t(e,p)[d+b[5]]&15},()=>{t(e,p)[d+b[5]]=l&15|(t(e,p)[d+b[5]]&240)>>4},()=>{t(e,p)[d+b[74]]=l},()=>{t(e,p)[d+b[71]]=l},()=>{t(e,p)[d+b[73]]=l},()=>{t(e,p)[d+b[72]]=l},0,0,0,0,0,0,0,()=>{t(e,p)[d+b[128]]=l,e.allocateAce(128)},()=>{t(e,p)[d+b[93]]=l},()=>{t(e,p)[d+b[91]]=l},0,0,()=>{t(e,p)[d+b[75]]=l},()=>{t(e,p)[d+b[76]]=l},()=>{t(e,p)[d+b[77]]=l},()=>{t(e,p)[d+b[78]]=l}][$]||(()=>{}))():$<63||($<64?(t(e,D)[o]?t(e,p)[d+b[0]]=104|l:t(e,p)[d+b[0]]=96|l,e.dispatchEvent("voice",{part:o})):console.debug(`Unknown SD-90 global CH${o+1} param setup message: %o`,a))});break}case 2:{let o=e.chRedir(i,c,!0),n=a[1];console.debug(`Unknown SD-90 global CH${o+1} MIDI setup message: %o`,a.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: %o`,a)}}),t(e,$e).add([0,1,73,78],(a,c,f)=>{e.switchMode("krs"),e.setPortMode(e.getTrackPort(c),1,w.krs),console.debug("Might be KORG KROSS 2 mode reset... Not sure.")}).add([0,1,73,117,2,37],(a,c,f)=>{e.switchMode("krs");let s=e.getTrackPort(c);if(t(e,I)[s]&&t(e,I)[s]!=w.krs)if(t(e,me).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+s)} mode "${K[t(e,I)[s]]}" mismatch, should be "krs".`);return}else console.info(`Track ${c} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+s)}.`);e.setPortMode(e.getTrackPort(c),1,w.krs);let i="KROSS 2 BMT1 ",o="";le(a,(n,d)=>{if(d<24)o+=String.fromCharCode(Math.max(32,n));else if(!(d<1276)){let l=d-1276,m=e.chRedir(Math.floor(l/44),c,!0),$=l%44,M=g.cc*m;$<15?([()=>{n&&e.setChActive(m,1),t(e,A)[m]=n,e.dispatchEvent("voice",{part:m})},()=>{n&&e.setChActive(m,1),n<10?(t(e,p)[M+b[0]]=63,t(e,p)[M+b[32]]=n):n<20?(t(e,p)[M+b[0]]=121,t(e,p)[M+b[32]]=n-10):n<24&&(t(e,p)[M+b[0]]=[120,0,56,62][n-20],t(e,p)[M+b[32]]=0),e.dispatchEvent("voice",{part:m})},()=>{let U=e.chRedir(n&15,c,!0);t(e,G)[m]=U,console.info(`${i}CH${m+1} receives from CH${U+1}`),n>>5&1||(e.setChActive(m,0),console.debug(`KORG KROSS 2 CH${m+1} is disabled.`))},!1,!1,()=>{t(e,p)[M+b[7]]=n},!1,()=>{},()=>{},!1,!1,!1,!1,!1,()=>{t(e,p)[M+b[10]]=n||128}][$]||(()=>{}))():$<36||([()=>{t(e,p)[M+b[74]]=(n+128&255)-64},()=>{t(e,p)[M+b[71]]=(n+128&255)-64},!1,!1,()=>{t(e,p)[M+b[73]]=(n+128&255)-64},()=>{t(e,p)[M+b[75]]=(n+128&255)-64},!1,()=>{t(e,p)[M+b[72]]=(n+128&255)-64}][$]||(()=>{}))()}}),o=o.trimRight(),e.dispatchEvent("metacommit",{type:"EORTitle",data:o})})}chRedir(e,r,h){let u=this;if(t(u,Pe)[r])return(t(u,Pe)[r]-1)*16+e;if(t(u,O)==w.sc){if(h==1)return e;let E=0,v=!0;for(;v;)t(u,Se)[e+E]==0?(t(u,Se)[e+E]=r,console.debug(`Assign track ${r} to channel ${e+E+1}.`),v=!1):t(this,Se)[e+E]==r?v=!1:(E+=16,E>=128&&(E=0,v=!1));return e+E}else return e}getTrackPort(e){return this.chRedir(0,e,!0)>>4}forceVoiceRefresh(){for(let e=0;e{var u;r{r&&(t(e,Ue)[Math.floor(h/g.redir)][r]=h%g.redir|128)}),P()&&console.debug(t(e,Ue))}getActive(){return t(this,ie)}getCc(e){let r=this,h=e*g.cc,u=t(r,p).subarray(h,h+g.cc);return u[b[0]]=u[b[0]]||t(r,F)[r.getChModeId(e)][0],u[b[32]]=u[b[32]]||t(r,F)[r.getChModeId(e)][1],u[b[0]]==Fe.bank0&&(u[b[0]]=0),u}getCcCh(e,r){let h=this;if(at.indexOf(r)<0)throw new Error("CC number not accepted");let u=t(h,p)[g.cc*e+b[r]];switch(r){case 0:{u=u||t(h,F)[h.getChModeId(e)][0],u==Fe.bank0&&(u=0);break}case 32:{u=u||t(h,F)[h.getChModeId(e)][1];break}}return u}getCcAll(){let e=this,r=t(e,p).slice();for(let h=0;h0&&!u&&(t(this,p)[e*g.cc+b[0]]=yt[h])}setChActive(e,r=0){t(this,ie)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),t(this,ie)[e]=r}getExt(e){let r=g.ext*e,h=t(this,ee).subarray(r,r+g.ext),u=new Uint8Array(h.length);return u.set(h),u[1]=u[1]||t(this,lt),u}getPitch(){return t(this,ke)}getProgram(){return t(this,A)}getTexts(){return t(this,ae).slice()}getVel(e){let r=new Map,h=this;return t(h,V).forEach(function(u,E){let v=Math.floor(u/128),k=u%128;e==v&&t(h,X)[u]>0&&r.set(k,{v:t(h,X)[u],s:t(h,z)[E]})}),r}getBitmap(){return{bitmap:t(this,se,ve),expire:t(this,fe)}}getLetter(){return{text:t(this,Re),set:t(this,it),expire:t(this,De)}}getMode(){return K[t(this,O)]}getMaster(){return{volume:t(this,H)}}getRawStrength(){let e=this;return t(this,V).forEach(function(r){let h=Math.floor(r/128);t(e,X)[r]>t(e,ye)[h]&&(t(e,ye)[h]=t(e,X)[r])}),t(this,ye)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(h,u){e[u]=Math.floor(h*t(r,p)[u*g.cc+b[7]]*t(r,p)[u*g.cc+b[11]]*t(r,H)/803288)}),e}getRpn(){return t(this,R)}getNrpn(){return t(this,Ke)}getVoice(e,r,h,u){let E=this,v=e||t(E,F)[t(E,O)][0],k=r,S=h||t(E,F)[t(E,O)][1];v==Fe.bank0&&(v=0),K[t(E,O)]=="ns5r"&&v>0&&v<56&&(S=3);let a=E.userBank.get(v,k,S,u);if(K[t(E,O)]=="mt32"&&a.name.indexOf("MT-m:")==0){let c=parseInt(a.name.slice(5)),f=c*g.cmt,s="";t(E,Te).subarray(f,f+10).forEach(o=>{o>31&&(s+=String.fromCharCode(o))});let i=`MSB LSB PRG NME -0 127 ${k} ${s}`;E.userBank.load(i,!0),a.name=s,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=E.baseBank.get(v,k,S,u)),a}getChVoice(e){let r=this,h=r.getVoice(r.getCcCh(e,0),t(r,A)[e],r.getCcCh(e,32),r.getChMode(e));if(t(r,ue)[e]){let u="";switch(t(r,O)){case w.mt32:{t(r,pe).subarray(g.cmt*(e-1),g.cmt*(e-1)+10).forEach(E=>{u+=String.fromCharCode(Math.max(E,32))}),u=u.trimRight();break}default:{let E=g.cvn*e;t(r,rt).subarray(E,E+g.cvn).forEach(v=>{u+=String.fromCharCode(Math.max(v,32))}),u=u.trimRight()}}u.length&&(h.ending="~",h.name=u)}return h}getRawPitch(){return t(this,ke)}getPitchShift(e){let r=this,h=e*g.rpn,u=t(r,R)[h];return t(r,L)[e*g.rpnt]||t(r,O)==w.mt32&&(u=12),t(r,ke)[e]/8192*u+(t(r,R)[h+3]-64)+((t(r,R)[h+1]<<7)+t(r,R)[h+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return t(this,te).subarray(r,r+2)}setEffectTypeRaw(e=0,r,h){let u=3*e;t(this,te)[u]=1,t(this,te)[u+1+ +r]=h}setEffectType(e=0,r,h){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,h)}getEffectSink(){return t(this,ze)}setLetterDisplay(e,r,h=0,u=3200){let E=this,v;x(E,Re," ".repeat(h)),e.forEach(k=>{x(E,Re,t(E,Re)+String.fromCharCode(k>31?k:32)),k<32&&(v=v||new Set,v.add(k))}),x(E,it,Date.now()),x(E,De,Date.now()+u),v&&(v=Array.from(v),v.forEach((k,S,a)=>{a[S]=k.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${v.length>1?"s":""}: 0x${v.join(", 0x")}`))}setDetectionTargets(e="?",r=0){let h=this,u=-1;switch(e.replaceAll(", ",",").split(",").forEach(E=>{E=E.toLowerCase();let v=K.indexOf(aa[E]||E);P()&&console.debug(`Mapped mode "${E}" to ID "${v}".`),v>-1&&(u=v)}),P()&&console.debug(`Set detection target to ID "${u}".`),u>0&&(t(h,B).x5=82,t(h,B).ds=w.krs),u){case w["05rw"]:{t(h,B).x5=81;break}case w.s90es:t(h,B).ds=w.s90es,t(h,B).smotif=w.s90es;case w.motif:t(h,B).ds=w.motif,t(h,B).smotif=w.motif}}setGsTargets(e=!1,r=4){if(!r)r=e?3:4;else{if(r>4||r<0)throw new Error(`Invalid GS level ${r}`);if(e&&r>>1!=1)throw new Error(`Invalid SC level ${r}`)}let h=this;t(h,B)[e?"sc":"gs"]=r,t(h,F)[w[e?"sc":"gs"]][1]=r,h.forceVoiceRefresh()}getConfigs(){return t(this,st)}setDumpLimit(e){if(e>2||e<0)throw new RangeError("Invalid dump limit.");t(this,me).dumpLimit=e}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.")}releaseAce(e){let r=!0,h=0;for(;r&&h=g.ace)throw new RangeError("No such ACE slot");let h=t(this,ce)[r];if(h){if(at.indexOf(h)>=0)return t(this,p)[e*g.cc+b[h]];throw new Error(`Invalid ACE source: ${h}`)}else return 0}initDrums(){let e=this;t(e,Y).fill(64);for(let r=0;r{t(r,p)[g.cc*h]=yt[0]}),t(r,D).fill(r.CH_MELODIC),t(r,D)[9]=r.CH_DRUM1,t(r,D)[25]=r.CH_DRUM3,t(r,D)[41]=r.CH_DRUMS,t(r,D)[57]=r.CH_DRUMS,t(r,D)[73]=r.CH_DRUM5,t(r,D)[89]=r.CH_DRUM7,t(r,D)[105]=r.CH_DRUMS,t(r,D)[121]=r.CH_DRUMS;for(let h=0;h=g.ch)throw new RangeError(`Invalid CH${e+1}`);if(port<0||r>=K.length)throw new RangeError(`Invalid mode ID ${r}`);t(h,Ce)[e]=r,h.dispatchEvent("voice",{part:e})}getChMode(e,r){return K[this.getChModeId(e,r)]}getChModeId(e,r){return r?t(this,Ce)[e]||t(this,I)[e>>4]:t(this,Ce)[e]||t(this,I)[e>>4]||t(this,O)}setPortMode(e,r,h){let u=this;if(e<0||e>=g.ch>>4)throw new RangeError(`Invalid port ${e+1}`);if(r<1)throw new RangeError("Range must be a positive integer");if(e+r>=g.ch>>4)throw new RangeError("Range must be in bound");if(e<0||h>=K.length)throw new RangeError(`Invalid mode ID ${h}`);for(let E=e;E=0&&e-1){if(t(u,O)==0||r){let k=t(u,O);u.initOnReset&&r&&(this.init(1),k=w["?"]),x(u,O,E),x(u,W,0);for(let a=0;a0&&t(u,Ce)[a]==0&&(t(u,p)[a*g.cc]=yt[E]);switch(E){case w.mt32:{Et.forEach((a,c)=>{let f=c+1;t(u,ie)[f]||(t(u,A)[f]=a,t(u,p)[f*g.cc+b[91]]=127)});for(let a=1;a<10;a++)u.dispatchEvent("voice",{part:a});break}}let S;switch(E){case w["?"]:case w.g2:{S=[52,4,52,18,0,0,0,0];break}case w.xg:{S=[1,0,65,0,5,0,0,0];break}case w.gm:case w.gs:case w.sc:{S=[40,4,40,18,40,32,32,0];break}case w.sd:{S=[58,0,60,0,61,0,61,0];break}case w["05rw"]:case w.x5d:case w.ns5r:{S=[44,1,44,19,44,0,44,0];break}case w.k11:case w.sg:{S=[24,0,0,0,0,0,0,0];break}case w.mt32:{S=[40,4,0,0,0,0,0,0];break}case w.motif:case w.s90es:{S=[113,0,117,0,114,0,0,0];break}default:S=[0,0,0,0,0,0,0,0]}for(let a=0;a{u.dispatchEvent("voice",{part:a})})}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,ye).fill(0)}runJson(e){var r;if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,nt)[e.type].call(this,e);{let h=this.chRedir(e.part,e.track),u=!1;(r=t(this,ct)[h])==null||r.forEach(E=>{e.channel=E,u=!0,t(this,nt)[e.type].call(this,e)}),u||console.warn(`${It[e.type]?It[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${h+1} without any recipient.`)}t(this,ae).length>100&&t(this,ae).splice(100,t(this,ae).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}case"pcg":{h.userBank.clearRange({msb:63,lsb:[6,9]}),h.userBank.clearRange({msb:63,lsb:[13,16]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":case"pcg":{Ze.context=this,await h.userBank.load(await Ze.read(e,r),!1);break}}h.forceVoiceRefresh()}},O=new WeakMap,W=new WeakMap,fe=new WeakMap,we=new WeakMap,se=new WeakSet,ve=function(){return t(this,we)[t(this,W)]},qt=function(e){t(this,we)[t(this,W)]=e},ie=new WeakMap,G=new WeakMap,D=new WeakMap,p=new WeakMap,ce=new WeakMap,A=new WeakMap,X=new WeakMap,j=new WeakMap,V=new WeakMap,z=new WeakMap,ke=new WeakMap,ye=new WeakMap,Oe=new WeakMap,ee=new WeakMap,R=new WeakMap,L=new WeakMap,Ke=new WeakMap,Y=new WeakMap,he=new WeakMap,te=new WeakMap,ze=new WeakMap,Ae=new WeakMap,I=new WeakMap,Ce=new WeakMap,ue=new WeakMap,rt=new WeakMap,Me=new WeakMap,pe=new WeakMap,We=new WeakMap,Te=new WeakMap,F=new WeakMap,B=new WeakMap,me=new WeakMap,st=new WeakMap,H=new WeakMap,Le=new WeakMap,qe=new WeakMap,Qe=new WeakMap,Re=new WeakMap,De=new WeakMap,it=new WeakMap,Ye=new WeakMap,be=new WeakMap,N=new WeakMap,lt=new WeakMap,ct=new WeakMap,Ue=new WeakMap,mt=new WeakMap,ae=new WeakMap,Se=new WeakMap,Pe=new WeakMap,q=new WeakMap,Be=new WeakMap,_=new WeakMap,nt=new WeakMap,dt=new WeakMap,He=new WeakMap,Ne=new WeakMap,re=new WeakMap,ne=new WeakMap,$e=new WeakMap,Ie=new WeakMap,_e=new WeakMap,Ge=new WeakMap,Wt);export{qa as OctaviaDevice,g as allocated,b as ccToPos,de as dnToPos}; +0 127 ${k} ${s}`;E.userBank.load(i,!0),a.name=s,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=E.baseBank.get(v,k,S,u)),a}getChVoice(e){let r=this,h=r.getVoice(r.getCcCh(e,0),t(r,A)[e],r.getCcCh(e,32),r.getChMode(e));if(t(r,ue)[e]){let u="";switch(t(r,O)){case w.mt32:{t(r,pe).subarray(g.cmt*(e-1),g.cmt*(e-1)+10).forEach(E=>{u+=String.fromCharCode(Math.max(E,32))}),u=u.trimRight();break}default:{let E=g.cvn*e;t(r,rt).subarray(E,E+g.cvn).forEach(v=>{u+=String.fromCharCode(Math.max(v,32))}),u=u.trimRight()}}u.length&&(h.ending="~",h.name=u)}return h}getRawPitch(){return t(this,ke)}getPitchShift(e){let r=this,h=e*g.rpn,u=t(r,R)[h];return t(r,L)[e*g.rpnt]||t(r,O)==w.mt32&&(u=12),t(r,ke)[e]/8192*u+(t(r,R)[h+3]-64)+((t(r,R)[h+1]<<7)+t(r,R)[h+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return t(this,te).subarray(r,r+2)}setEffectTypeRaw(e=0,r,h){let u=3*e;t(this,te)[u]=1,t(this,te)[u+1+ +r]=h}setEffectType(e=0,r,h){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,h)}getEffectSink(){return t(this,ze)}setLetterDisplay(e,r,h=0,u=3200){let E=this,v;x(E,Re," ".repeat(h)),e.forEach(k=>{x(E,Re,t(E,Re)+String.fromCharCode(k>31?k:32)),k<32&&(v=v||new Set,v.add(k))}),x(E,it,Date.now()),x(E,De,Date.now()+u),v&&(v=Array.from(v),v.forEach((k,S,a)=>{a[S]=k.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${v.length>1?"s":""}: 0x${v.join(", 0x")}`))}setDetectionTargets(e="?",r=0){let h=this,u=-1;switch(e.replaceAll(", ",",").split(",").forEach(E=>{E=E.toLowerCase();let v=K.indexOf(aa[E]||E);P()&&console.debug(`Mapped mode "${E}" to ID "${v}".`),v>-1&&(u=v)}),P()&&console.debug(`Set detection target to ID "${u}".`),u>0&&(t(h,B).x5=82,t(h,B).ds=w.krs),u){case w["05rw"]:{t(h,B).x5=81;break}case w.s90es:t(h,B).ds=w.s90es,t(h,B).smotif=w.s90es;case w.motif:t(h,B).ds=w.motif,t(h,B).smotif=w.motif}}setGsTargets(e=!1,r=4){if(!r)r=e?3:4;else{if(r>4||r<0)throw new Error(`Invalid GS level ${r}`);if(e&&r>>1!=1)throw new Error(`Invalid SC level ${r}`)}let h=this;t(h,B)[e?"sc":"gs"]=r,t(h,F)[w[e?"sc":"gs"]][1]=r,h.forceVoiceRefresh()}getConfigs(){return t(this,st)}setDumpLimit(e){if(e>2||e<0)throw new RangeError("Invalid dump limit.");t(this,me).dumpLimit=e}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.")}releaseAce(e){let r=!0,h=0;for(;r&&h=g.ace)throw new RangeError("No such ACE slot");let h=t(this,ce)[r];if(h){if(at.indexOf(h)>=0)return t(this,p)[e*g.cc+b[h]];throw new Error(`Invalid ACE source: ${h}`)}else return 0}initDrums(){let e=this;t(e,Y).fill(64);for(let r=0;r{t(r,p)[g.cc*h]=yt[0]}),t(r,D).fill(r.CH_MELODIC),t(r,D)[9]=r.CH_DRUM1,t(r,D)[25]=r.CH_DRUM3,t(r,D)[41]=r.CH_DRUMS,t(r,D)[57]=r.CH_DRUMS,t(r,D)[73]=r.CH_DRUM5,t(r,D)[89]=r.CH_DRUM7,t(r,D)[105]=r.CH_DRUMS,t(r,D)[121]=r.CH_DRUMS;for(let h=0;h=g.ch)throw new RangeError(`Invalid CH${e+1}`);if(port<0||r>=K.length)throw new RangeError(`Invalid mode ID ${r}`);t(h,Ce)[e]=r,h.dispatchEvent("voice",{part:e})}getChMode(e,r){return K[this.getChModeId(e,r)]}getChModeId(e,r){return r?t(this,Ce)[e]||t(this,I)[e>>4]:t(this,Ce)[e]||t(this,I)[e>>4]||t(this,O)}setPortMode(e,r,h){let u=this;if(e<0||e>=g.ch>>4)throw new RangeError(`Invalid port ${e+1}`);if(r<1)throw new RangeError("Range must be a positive integer");if(e+r>=g.ch>>4)throw new RangeError("Range must be in bound");if(e<0||h>=K.length)throw new RangeError(`Invalid mode ID ${h}`);for(let E=e;E=0&&e-1){if(t(u,O)==0||r){let k=t(u,O);u.initOnReset&&r&&(this.init(1),k=w["?"]),x(u,O,E),x(u,W,0);for(let a=0;a0&&t(u,Ce)[a]==0&&(t(u,p)[a*g.cc]=yt[E]);switch(E){case w.mt32:{Et.forEach((a,c)=>{let f=c+1;t(u,ie)[f]||(t(u,A)[f]=a,t(u,p)[f*g.cc+b[91]]=127)});for(let a=1;a<10;a++)u.dispatchEvent("voice",{part:a});break}}let S;switch(E){case w["?"]:case w.g2:{S=[52,4,52,18,0,0,0,0];break}case w.xg:{S=[1,0,65,0,5,0,0,0];break}case w.gm:case w.gs:case w.sc:{S=[40,4,40,18,40,32,32,0];break}case w.sd:{S=[58,0,60,0,61,0,61,0];break}case w["05rw"]:case w.x5d:case w.ns5r:{S=[44,1,44,19,44,0,44,0];break}case w.k11:case w.sg:{S=[24,0,0,0,0,0,0,0];break}case w.mt32:{S=[40,4,0,0,0,0,0,0];break}case w.doc:{S=[24,16,0,0,0,0,0,0];break}case w.motif:case w.s90es:{S=[113,0,117,0,114,0,0,0];break}default:S=[0,0,0,0,0,0,0,0]}for(let a=0;a{u.dispatchEvent("voice",{part:a})})}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,ye).fill(0)}runJson(e){var r;if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,nt)[e.type].call(this,e);{let h=this.chRedir(e.part,e.track),u=!1;(r=t(this,ct)[h])==null||r.forEach(E=>{e.channel=E,u=!0,t(this,nt)[e.type].call(this,e)}),u||console.warn(`${It[e.type]?It[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${h+1} without any recipient.`)}t(this,ae).length>100&&t(this,ae).splice(100,t(this,ae).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}case"pcg":{h.userBank.clearRange({msb:63,lsb:[6,9]}),h.userBank.clearRange({msb:63,lsb:[13,16]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":case"pcg":{Je.context=this,await h.userBank.load(await Je.read(e,r),!1);break}}h.forceVoiceRefresh()}},O=new WeakMap,W=new WeakMap,fe=new WeakMap,we=new WeakMap,se=new WeakSet,ve=function(){return t(this,we)[t(this,W)]},qt=function(e){t(this,we)[t(this,W)]=e},ie=new WeakMap,G=new WeakMap,D=new WeakMap,p=new WeakMap,ce=new WeakMap,A=new WeakMap,X=new WeakMap,Z=new WeakMap,V=new WeakMap,z=new WeakMap,ke=new WeakMap,ye=new WeakMap,Oe=new WeakMap,ee=new WeakMap,R=new WeakMap,L=new WeakMap,Ke=new WeakMap,Y=new WeakMap,he=new WeakMap,te=new WeakMap,ze=new WeakMap,Ae=new WeakMap,I=new WeakMap,Ce=new WeakMap,ue=new WeakMap,rt=new WeakMap,Me=new WeakMap,pe=new WeakMap,We=new WeakMap,Te=new WeakMap,F=new WeakMap,B=new WeakMap,me=new WeakMap,st=new WeakMap,H=new WeakMap,Le=new WeakMap,qe=new WeakMap,Qe=new WeakMap,Re=new WeakMap,De=new WeakMap,it=new WeakMap,Ye=new WeakMap,be=new WeakMap,N=new WeakMap,lt=new WeakMap,ct=new WeakMap,Ue=new WeakMap,mt=new WeakMap,ae=new WeakMap,Se=new WeakMap,Pe=new WeakMap,q=new WeakMap,Be=new WeakMap,_=new WeakMap,nt=new WeakMap,dt=new WeakMap,He=new WeakMap,Ne=new WeakMap,re=new WeakMap,ne=new WeakMap,$e=new WeakMap,Ie=new WeakMap,_e=new WeakMap,Ge=new WeakMap,Wt);export{qa as OctaviaDevice,g as allocated,b as ccToPos,de as dnToPos}; diff --git a/src/state/index.mjs b/src/state/index.mjs index 08d91cc2..78dcbca1 100644 --- a/src/state/index.mjs +++ b/src/state/index.mjs @@ -3197,6 +3197,17 @@ let OctaviaDevice = class extends CustomEventSource { } else { console.debug(`Unknown Yamaha SysEx: 67, ${id}, ${msg.join(', ')}`); }; + }).add([1, 24], (msg, track, id) => { + if (id == 115) { + // DOC global reverb depth on + for (let ch = 0; ch < 16; ch ++) { + let part = upThis.chRedir(ch, track, true); + upThis.#cc[part * allocated.cc + ccToPos[91]] = 127; + }; + console.info("DOC Global Reverb: on"); + } else { + console.debug(`Unknown Yamaha SysEx: 67, ${id}, ${msg.join(', ')}`); + }; }); // DX7 Dumps // Placeholder until further documentation