From dcda33fa2ace872acb07a6377d77fc7af4349d31 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: Sun, 16 Jun 2024 01:32:13 +0000 Subject: [PATCH] Deprecate the old middleware. --- dist/basic.mjs | 18 ++--- dist/bridge.mjs | 144 ++++++++++++++++++++++++++++++++++++++- dist/cambiare.mjs | 56 +++++++-------- dist/micc.mjs | 19 ++++++ dist/state.mjs | 36 +++++----- dist/state_skim.mjs | 20 +++--- dist/xp_basic.mjs | 58 ++++++++-------- dist/xp_state.mjs | 48 ++++++------- src/bridge/index.mjs | 127 +--------------------------------- src/bridge/index.old.mjs | 77 +++++++++++++++++++++ src/demoMw/index.js | 6 +- 11 files changed, 361 insertions(+), 248 deletions(-) create mode 100644 dist/micc.mjs create mode 100644 src/bridge/index.old.mjs diff --git a/dist/basic.mjs b/dist/basic.mjs index 8f1d2336..63da8d27 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||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)),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*, +var z=Object.create;var B=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var Z=(t,a)=>()=>(a||t((a={exports:{}}).exports,a),a.exports);var J=(t,a,i,e)=>{if(a&&typeof a=="object"||typeof a=="function")for(let c of Q(a))!Y.call(t,c)&&c!==i&&B(t,c,{get:()=>a[c],enumerable:!(e=q(a,c))||e.enumerable});return t};var j=(t,a,i)=>(i=t!=null?z(W(t)):{},J(a||!t||!t.__esModule?B(i,"default",{value:t,enumerable:!0}):i,t));var X=Z((at,A)=>{(function(){"use strict";let t={fatal:!0},a=[new TextDecoder("iso-8859-15",t),new TextDecoder("sjis",t),new TextDecoder("euc-jp",t),new TextDecoder("utf-8",t),new TextDecoder("utf-16",t),new TextDecoder("ascii")],i={debug:!1,parse:function(e,c){if(e instanceof Uint8Array)return i.Uint8(e);if(typeof e=="string")return i.Base64(e);if(e instanceof HTMLElement&&e.type==="file")return i.addListener(e,c);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(e,c){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(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;c=c||function(){},e.addEventListener("change",function(s){if(!s.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let o=new FileReader;o.readAsArrayBuffer(s.target.files[0]),o.onload=function(h){c(i.Uint8(new Uint8Array(h.target.result)))}})},Base64:function(e){let c=function(h){var b="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="",r,n,d=0;for(;d>16&255):n===64?String.fromCharCode(u>>16&255,u>>8&255):String.fromCharCode(u>>16&255,u>>8&255,255&u);return f}(e=String(e));var s=c.length;let o=new Uint8Array(new ArrayBuffer(s));for(let h=0;h{n[p]=this.readInt(1)});for(let g=0;g191||E>127&&E<160)throw new RangeError(`Invalid code point: ${E}`)}d=!0,console.debug(`String byte sequence in ${a[g].encoding}`)}catch(p){console.debug(`SMF string ${p}`)}return l||"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 d=[];for(;128<=this.data.getUint8(this.pointer);)d.push(this.readInt(1)-128);var n=this.readInt(1);for(let l=1;l<=d.length;l++)r+=d[d.length-l]*Math.pow(128,l);r+=n}return r}};if(c.data=new DataView(o.buffer,o.byteOffset,o.byteLength),c.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;c.readInt(4);let s={};s.formatType=c.readInt(2),s.tracks=c.readInt(2),s.track=[];var o=c.readInt(1),h=c.readInt(1);128<=o?(s.timeDivision=[],s.timeDivision[0]=o-128,s.timeDivision[1]=h):s.timeDivision=256*o+h;for(let r=1;r<=s.tracks;r++){s.track[r-1]={event:[]};var b,u=c.readInt(4);if(u===-1)break;if(u!==1297379947)return!1;c.readInt(4);let n=0,d=!1,l,g;for(;!d&&(n++,s.track[r-1].event[n-1]={},s.track[r-1].event[n-1].deltaTime=c.readIntVLV(),(l=c.readInt(1))!==-1);)if(128<=l?g=l:(l=g,c.movePointer(-1)),l===255){s.track[r-1].event[n-1].type=255,s.track[r-1].event[n-1].metaType=c.readInt(1);var f=c.readIntVLV();switch(s.track[r-1].event[n-1].metaType){case 47:case-1:d=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:s.track[r-1].event[n-1].data=c.readStr(f);break;case 33:case 89:case 81:s.track[r-1].event[n-1].data=c.readInt(f);break;case 84:s.track[r-1].event[n-1].data=[],s.track[r-1].event[n-1].data[0]=c.readInt(1),s.track[r-1].event[n-1].data[1]=c.readInt(1),s.track[r-1].event[n-1].data[2]=c.readInt(1),s.track[r-1].event[n-1].data[3]=c.readInt(1),s.track[r-1].event[n-1].data[4]=c.readInt(1);break;case 88:s.track[r-1].event[n-1].data=[],s.track[r-1].event[n-1].data[0]=c.readInt(1),s.track[r-1].event[n-1].data[1]=c.readInt(1),s.track[r-1].event[n-1].data[2]=c.readInt(1),s.track[r-1].event[n-1].data[3]=c.readInt(1);break;default:this.customInterpreter!==null&&(s.track[r-1].event[n-1].data=this.customInterpreter(s.track[r-1].event[n-1].metaType,c,f)),this.customInterpreter!==null&&s.track[r-1].event[n-1].data!==!1||(c.readInt(f),s.track[r-1].event[n-1].data=c.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"),s.track[r-1].event[n-1].type=parseInt(l[0],16),s.track[r-1].event[n-1].channel=parseInt(l[1],16),s.track[r-1].event[n-1].type){case 15:this.customInterpreter!==null&&(s.track[r-1].event[n-1].data=this.customInterpreter(s.track[r-1].event[n-1].type,c,!1)),this.customInterpreter!==null&&s.track[r-1].event[n-1].data!==!1||(b=c.readIntVLV(),s.track[r-1].event[n-1].data=c.readInt(b),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:s.track[r-1].event[n-1].data=[],s.track[r-1].event[n-1].data[0]=c.readInt(1),s.track[r-1].event[n-1].data[1]=c.readInt(1);break;case 12:case 13:s.track[r-1].event[n-1].data=c.readInt(1);break;case-1:d=!0;break;default:if(this.customInterpreter!==null&&(s.track[r-1].event[n-1].data=this.customInterpreter(s.track[r-1].event[n-1].metaType,c,!1)),this.customInterpreter===null||s.track[r-1].event[n-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return s},customInterpreter:null};if(typeof A<"u")A.exports=i;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=i}})()});var M=class{#e={};addEventListener(t,a){this.#e[t]||(this.#e[t]=[]),this.#e[t].unshift(a)}removeEventListener(t,a){if(this.#e[t]){let i=this.#e[t].indexOf(a);i>-1&&this.#e[t].splice(i,1),this.#e[t].length<1&&delete this.#e[t]}}dispatchEvent(t,a){let i=new Event(t),e=this;i.data=a,this.#e[t]?.length>0&&this.#e[t].forEach(function(c){try{c?.call(e,i)}catch(s){console.error(s)}}),this[`on${t}`]&&this[`on${t}`](i)}};var N=class{#e={};context;set(t,a){this.#e[t]=a}has(t){return!!this.#e[t]}async read(t,a){if(!this.has(t))throw new Error(`No decoder registered for "${t}"`);return await this.#e[t].call(this.context||this,a)}};var ee=function(t,a){let i=!0;return a.forEach((e,c)=>{i=i&&t[c]==e}),i},T=function(t){let a=0;return t.forEach(i=>{a*=256,a+=i}),a},$=new TextDecoder,R=new N;R.set("s7e",async function(t){let a=new Uint8Array(await t.slice(0,65536).arrayBuffer()),i="MSB LSB PRG NME",e=[0,0,0,0],c=32,s=0,o=0,h=!0,b=[],u=0;for(;h;){let f=a.subarray(s);([()=>{$.decode(f.subarray(0,4))=="YSFC"?(s+=80,o=1):s++},()=>{if(ee(f.subarray(0,4),e))b.forEach((r,n,d)=>{let l=T(a.subarray(r.start+4,r.start+8));r.length=l}),o=2;else{let r=$.decode(f.subarray(0,4)),n=T(f.subarray(4,8));b.push({type:r,start:n}),s+=8}},()=>{let r=b[u],n=a.subarray(r.start,r.start+r.length),d=32;switch(r.type){case"ENVC":{let l=c;for(;l=b.length&&(o=3,h=!1)}][o]||(()=>{h=!1}))()}return i});R.set("pcg",async function(t){let a=new Uint8Array(await t.arrayBuffer()),i="MSB LSB PRG NME",e=100,c=0,s=0,o=!0,h=[],b=0;for(;o;){let u=a.subarray(e);([()=>{o=$.decode(u.subarray(0,4))=="INI2",s=u[15],e+=16,c=1},()=>{let f=$.decode(u.subarray(0,4)),r=u[5],n=u[7],d=u[11],l=T(u.subarray(12,16)),g=T(u.subarray(16,20)),p=T(u.subarray(36,40)),E=$.decode(u.subarray(44,44+d));h.push({type:f,tipMsb:r,tipLsb:n,nameLen:d,length:l,start:g,entryLen:p,name:E}),e+=64,s--,s<1&&(c=2)},()=>{let f=h[b],r=a.subarray(f.start,f.start+f.length);switch(f.type){case"PRG1":break;case"PBK1":{let n=63,d=(f.tipMsb?6:0)+f.tipLsb;for(let l=0;l<128;l++){let g=l*f.entryLen,p=r.subarray(g,g+f.entryLen),E=$.decode(p.subarray(0,24)).trimEnd().replace("InitProg","");E.length&&d>5&&(i+=` +${n.toString().padStart(3,"0")} ${d.toString().padStart(3,"0")} ${l.toString().padStart(3,"0")} ${E}`)}break}case"CBK1":{let n=63,d=(f.tipMsb?3:0)+f.tipLsb+10;for(let l=0;l<128;l++){let g=l*f.entryLen,p=r.subarray(g,g+f.entryLen),E=$.decode(p.subarray(0,24)).trimEnd().replace("InitCombi","");E.length&&d>12&&(i+=` +${n.toString().padStart(3,"0")} ${d.toString().padStart(3,"0")} ${l.toString().padStart(3,"0")} ${E}`)}break}}b++,b>=h.length&&(c=3,o=!1)}][c]||(()=>{o=!1}))()}return i});var te=["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 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(","),re={};`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 T={length:D.length};D.forEach((t,s)=>{T[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=T.length*y;if(w>=0){let S=4*.25**(a[L+T[73]]/64);c.#o[y]+=Math.ceil(w-w*c.smoothingAtk**S)}else{let S=4*.25**(a[L+T[72]]/64);c.#o[y]+=Math.floor(w-w*c.smoothingDcy**S)}});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{let a=t.split(",");re[a[0]]=a[1]});var H=function(t,a,i){let e=[],c=i==!1?a.readIntVLV():i;t==0||t==127;for(let s=0;s127)return console.debug(`Early termination: ${e}`),e.pop(),a.backOne(),a.backOne(),new Uint8Array(e)}}}return new Uint8Array(e)};var se=["?","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 D=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var P=[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 ne={};se.forEach((t,a)=>{ne[t]=a});var S={length:P.length};P.forEach((t,a)=>{S[t]=a});var _={length:D.length};D.forEach((t,a)=>{_[t]=a});var ce={};ie.forEach((t,a)=>{ce[t]=a});var G=8,oe={port:G,ch:G<<4,cc:P.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:D.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255},w={bank0:128};var L=j(X(),1);var V=class{#e=!1;constructor(t,a,i,e){this.#e=t,this.start=a,this.end=i,this.data=e}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#e}},O=class extends V{constructor(t,a,i){super(!0,t,a,i)}},F=class extends V{constructor(t,a){super(!1,t,t,a)}},I=class extends Array{#e=-1;constructor(){super(...arguments)}resetIndex(t){this.#e=-1}fresh(){this.sort(function(t,a){return t.start==a.start?0:(+(t.start>a.start)<<1)-1}),this.forEach(function(t,a){t.index=a})}step(t,a=!1){let i=[];if(a)for(let e=0;et);e++){if(this[e].endc.#e&&(i.push(s),c.#e=s.index)})}return i}getRange(t,a){t>a&&([t,a]=[a,t]);let i=[],e=-1,c=Math.ceil(Math.sqrt(this.length)),s=!0;for(let o=0;o=t&&(e=o):e=e<0?o:e;for(;s;)this[e]?.end=t&&i.push(this[e]):s=!1,e++;return i}};var le=0xffffffffffff,K=function(t){let a=new I,i=this,e=t.timeDivision,c=120,s=new I,o=0,h=0;s.push(new O(0,le,[120,0])),t.track.forEach(function(r){o=0,r.event.forEach(function(n){o+=n.deltaTime,n.type==255&&n?.metaType==81&&(c=6e7/n.data,s[s.length-1]&&s.push(new O(o,0xffffffffffff,[c,0])))})}),s.fresh(),s.forEach(function(r,n,d){n>0&&(d[n-1].end=r.start)});let b=120;s.forEach(function(r,n,d){n>0&&(r.end==r.start?d.splice(d.indexOf(r),1):b==r.data[0]&&(d[n-1].end=r.end,d.splice(d.indexOf(r),1)),b=r.data[0])});let u=0,f=120;return s.forEach(function(r){let n=r.start,d=n/f/e*60+u;f=r.data[0],u=d-n/f/e*60,r.data[1]=u}),console.debug("All tempo changes: ",s),c=120,o=0,h=0,t.track.forEach(function(r,n){o=0,h=0;let d=n+1;r.event.forEach(function(l,g){o+=l.deltaTime;let p=s.step(o,!0)[0];p&&(c=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,a.push(new F(o/c/e*60+h,E))})}),a.fresh(),self.midiEvents=a,console.debug(`Parsed a type ${t.formatType} MIDI sequence.`),a};L.default.customInterpreter=H;var m=function(t,a,i){t.addEventListener(i,e=>{a.dispatchEvent(i,e.data)})},pt=class extends M{device;#e;#n={};#f=[];#a="";#c=[];#h=[];#o=new Uint8ClampedArray(128);#u=new Uint8ClampedArray(128);#s=.5;#i=120;#t=4;#l=4;#r=0;#d=0;smoothingAtk=0;smoothingDcy=0;reset(){let t=this;t.dispatchEvent("reset"),t.#e?.resetIndex(),t.device.init(),t.#a="",t.#s=.5,t.#i=120,t.#t=4,t.#l=4,t.#r=0,t.#d=0,t.dispatchEvent("tempo",t.#i),t.dispatchEvent("title",t.#a)}init(){this.reset(),this.#e=void 0}async loadFile(t){this.#e=K(L.default.parse(new Uint8Array(await t.arrayBuffer())))}async loadMap(t,a){let i=this,e=0,c=0,s=0,o,h;t.split(` +`).forEach((b,u)=>{if(!b)return;let f=b.split(" ");if(u){if(!s)return;let r="",n="";f.forEach((d,l)=>{switch(l){case o:{r=d;break}case h:{n=d;break}}}),!i.#n[r]||a?(i.#n[r]=n,e++):self.debugMode&&console.debug(`Voice "${n}" (${r}) seems to be in conflict with (${i.#n[r]}).`),c++}else f.forEach((r,n)=>{switch(r){case"ID":{o=n,s++;break}case"Name":{h=n,s++;break}default:console.debug(`Unknown map field: ${r}`)}})}),console.debug(`Voice names: ${c} total, ${e} loaded.`),i?.device.forceVoiceRefresh()}async loadEfx(t,a){let i=this,e=0,c=0,s,o,h;t.split(` +`).forEach((b,u)=>{if(b)if(u){let f=0,r;b.split(" ").forEach((n,d)=>{switch(d){case s:{f|=parseInt(n,16)<<8;break}case o:{f|=parseInt(n,16);break}case h:{r=n;break}}}),!i.#f[f]||a?(i.#f[f]=r,e++):self.debugMode&&console.debug(`EFX ID 0x${f.toString(16).padStart(4,"0")} (${r}) seems to be in conflict.`),c++}else b.split(" ").forEach((f,r)=>{switch(f){case"MSB":{s=r;break}case"LSB":{o=r;break}case"Name":{h=r;break}default:console.debug(`Unknown EFX field: ${f}`)}})}),console.debug(`EFX: ${c} total, ${e} loaded.`),i.dispatchEvent("efxreverb",i.device.getEffectType(0)),i.dispatchEvent("efxchorus",i.device.getEffectType(1)),i.dispatchEvent("efxdelay",i.device.getEffectType(2)),i.dispatchEvent("efxinsert0",i.device.getEffectType(3)),i.dispatchEvent("efxinsert1",i.device.getEffectType(4)),i.dispatchEvent("efxinsert2",i.device.getEffectType(5)),i.dispatchEvent("efxinsert3",i.device.getEffectType(6))}switchMode(t,a=!1){this.device.switchMode(t,a)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(t){return this.device.getChVoice(t)}getMapped(t){return this.#n[t]||t}getEfx([t,a]){let i=t<<8|a;return this.#f[i]||`0x${i.toString(16).padStart(4,"0")}`}getVoxBm(t){if(!t)throw new Error("Voice object must be valid");let a=this;if(!a.voxBm)throw new Error("Voice bitmap repository isn't yet initialized");let i=a.voxBm.getBm(t.name);if(!i)switch(t.mode){case"xg":{switch(t.sid[0]){case 0:case 80:case 81:case 83:case 84:case 96:case 97:case 99:case 100:{i=a.voxBm.getBm(a.getVoice(w.bank0,t.sid[1],w.bank0,t.mode).name);break}}break}case"g2":case"sd":{switch(t.sid[0]){case 96:case 97:case 98:case 99:{i=a.voxBm.getBm(a.getVoice(w.bank0,t.sid[1],w.bank0,t.mode).name);break}case 104:case 105:case 106:case 107:{i=a.voxBm.getBm(a.getVoice(120,t.sid[1],w.bank0,t.mode).name);break}}break}case"gs":case"sc":case"k11":case"sg":case"gm":{switch(t.sid[0]){case 120:break;case 122:case 127:{i=a.voxBm.getBm(a.getVoice(120,t.sid[1],0,t.mode).name);break}default:i=a.voxBm.getBm(a.getVoice(0,t.sid[1],0,t.mode).name)}break}default:switch(t.sid[0]){case 56:{i=a.voxBm.getBm(a.getVoice(0,t.sid[1],0,t.mode).name);break}}}return i||(i=a.voxBm.getBm(a.getVoice(t.sid[0],t.sid[1],0,t.mode).name)),i}getChBm(t,a){let i=this;return a=a||i.getChVoice(t),i.getVoxBm(a)}get noteProgress(){return this.#d/this.#s}get noteOverall(){return this.noteProgress-this.#r}get noteBar(){return Math.floor(this.noteOverall/this.#t)}get noteBeat(){let t=this.noteOverall%this.#t;return t<0&&(t+=this.#t),t}getTimeSig(){return[this.#t,this.#l]}getTempo(){return this.#i}sendCmd(t){this.device.runJson(t)}render(t){t>this.#d&&(this.#d=t);let a=this.#e?.step(t)||[],i=0,e=new Set,c={},s=[],o=this,h=[];for(o.device.getStrength().forEach((v,y)=>{o.#u[y]=v}),o.device.newStrength(),a.forEach(function(v){let y=v.data,k=o.device.runJson(y);switch(k?.reply){case"meta":{h.push(k);break}}k?.reply&&delete k.reply});o.#h.length>0;){let v=o.#h.shift(),y=v.part<<7|v.note;v.state?(e.add(y),c[y]=v.velo):e.has(y)&&(s.push({part:v.part,note:v.note,velo:c[y],state:o.device.NOTE_SUSTAIN}),i++)}h?.length>0&&o.dispatchEvent("meta",h);let b=o.device.getActive(),u=[],f=o.device.getPitch(),r=o.device.getCcAll(),n=o.device.getProgram(),d=o.device.getChType(),l=[],g=o.device.getStrength();g.forEach(function(v,y,k){k[y]=Math.max(o.#u[y],v);let x=k[y]-o.#o[y],U=S.length*y;if(x>=0){let C=4*.25**(r[U+S[73]]/64);o.#o[y]+=Math.ceil(x-x*o.smoothingAtk**C)}else{let C=4*.25**(r[U+S[72]]/64);o.#o[y]+=Math.floor(x-x*o.smoothingDcy**C)}});let p=0;return b.forEach(function(v,y){v&&(u[y]=o.device.getVel(y),l[y]=o.device.getExt(y),p+=u[y].size)}),{extraPoly:i,extraNotes:s,curPoly:p,chInUse:b,chKeyPr:u,chPitch:f,chProgr:n,chContr:r,chType:d,chExt:l,eventCount:a.length,title:o.#a,bitmap:o.device.getBitmap(),letter:o.device.getLetter(),texts:o.device.getTexts(),master:o.device.getMaster(),mode:o.device.getMode(),strength:o.#o.slice(),velo:g,rpn:o.device.getRpn(),tSig:o.getTimeSig(),tempo:o.getTempo(),noteBar:o.noteBar,noteBeat:o.noteBeat,ace:o.device.getAce(),rawVelo:o.device.getStrength(),rawStrength:o.device.getRawStrength(),rawPitch:o.device.getRawPitch(),efxSink:o.device.getEffectSink()}}constructor(t,a=.5,i=.5){super();let e=this;e.smoothingAtk=a,e.smoothingDcy=i,e.device=t,e.addEventListener("meta",function(c){c?.data?.forEach(function(s){(e.#c[s.meta]||console.debug).call(e,s.meta,s.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:c}){e.#h.push(c)}),e.#c[3]=function(c,s){e.#a?.length<1&&(e.#a=s,e.dispatchEvent("title",e.#a))},e.#c[81]=function(c,s){let o=e.noteProgress,h=e.#s||.5;e.#i=6e7/s,e.#s=s/1e6,e.#r+=o*(h/e.#s)-o,e.dispatchEvent("tempo",e.#i)},e.#c[88]=function(c,s){let o=e.noteProgress,h=e.noteOverall,b=e.noteBar,u=e.noteBeat,f=e.#t,r=e.#l;e.#t=s[0],e.#l=1<=f&&(f()=>(i||e((i={exports:{}}).exports,i),i.exports);var F=(e,i,o,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of A(i))!C.call(e,t)&&t!==o&&E(e,t,{get:()=>i[t],enumerable:!(s=P(i,t))||s.enumerable});return e};var B=(e,i,o)=>(o=e!=null?D(O(e)):{},F(i||!e||!e.__esModule?E(o,"default",{value:e,enumerable:!0}):o,e));var T=S((q,k)=>{(function(){"use strict";let e={fatal:!0},i=[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")],o={debug:!1,parse:function(s,t){if(s instanceof Uint8Array)return o.Uint8(s);if(typeof s=="string")return o.Base64(s);if(s instanceof HTMLElement&&s.type==="file")return o.addListener(s,t);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(s,t){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(s===void 0||!(s instanceof HTMLElement)||s.tagName!=="INPUT"||s.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;t=t||function(){},s.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(d){t(o.Uint8(new Uint8Array(d.target.result)))}})},Base64:function(s){let t=function(d){var g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(d=d.replace(/^.*?base64,/,""),d=String(d).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(d))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");d+="==".slice(2-(3&d.length));let h,u="",n,a,l=0;for(;l>16&255):a===64?String.fromCharCode(h>>16&255,h>>8&255):String.fromCharCode(h>>16&255,h>>8&255,255&h);return u}(s=String(s));var r=t.length;let c=new Uint8Array(new ArrayBuffer(r));for(let d=0;d{a[p]=this.readInt(1)});for(let v=0;v191||m>127&&m<160)throw new RangeError(`Invalid code point: ${m}`)}l=!0,console.debug(`String byte sequence in ${i[v].encoding}`)}catch(p){console.debug(`SMF string ${p}`)}return f||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let n=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)n=this.readInt(1);else{let l=[];for(;128<=this.data.getUint8(this.pointer);)l.push(this.readInt(1)-128);var a=this.readInt(1);for(let f=1;f<=l.length;f++)n+=l[l.length-f]*Math.pow(128,f);n+=a}return n}};if(t.data=new DataView(c.buffer,c.byteOffset,c.byteLength),t.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;t.readInt(4);let r={};r.formatType=t.readInt(2),r.tracks=t.readInt(2),r.track=[];var c=t.readInt(1),d=t.readInt(1);128<=c?(r.timeDivision=[],r.timeDivision[0]=c-128,r.timeDivision[1]=d):r.timeDivision=256*c+d;for(let n=1;n<=r.tracks;n++){r.track[n-1]={event:[]};var g,h=t.readInt(4);if(h===-1)break;if(h!==1297379947)return!1;t.readInt(4);let a=0,l=!1,f,v;for(;!l&&(a++,r.track[n-1].event[a-1]={},r.track[n-1].event[a-1].deltaTime=t.readIntVLV(),(f=t.readInt(1))!==-1);)if(128<=f?v=f:(f=v,t.movePointer(-1)),f===255){r.track[n-1].event[a-1].type=255,r.track[n-1].event[a-1].metaType=t.readInt(1);var u=t.readIntVLV();switch(r.track[n-1].event[a-1].metaType){case 47:case-1:l=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:r.track[n-1].event[a-1].data=t.readStr(u);break;case 33:case 89:case 81:r.track[n-1].event[a-1].data=t.readInt(u);break;case 84:r.track[n-1].event[a-1].data=[],r.track[n-1].event[a-1].data[0]=t.readInt(1),r.track[n-1].event[a-1].data[1]=t.readInt(1),r.track[n-1].event[a-1].data[2]=t.readInt(1),r.track[n-1].event[a-1].data[3]=t.readInt(1),r.track[n-1].event[a-1].data[4]=t.readInt(1);break;case 88:r.track[n-1].event[a-1].data=[],r.track[n-1].event[a-1].data[0]=t.readInt(1),r.track[n-1].event[a-1].data[1]=t.readInt(1),r.track[n-1].event[a-1].data[2]=t.readInt(1),r.track[n-1].event[a-1].data[3]=t.readInt(1);break;default:this.customInterpreter!==null&&(r.track[n-1].event[a-1].data=this.customInterpreter(r.track[n-1].event[a-1].metaType,t,u)),this.customInterpreter!==null&&r.track[n-1].event[a-1].data!==!1||(t.readInt(u),r.track[n-1].event[a-1].data=t.readInt(u),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((f=f.toString(16).split(""))[1]||f.unshift("0"),r.track[n-1].event[a-1].type=parseInt(f[0],16),r.track[n-1].event[a-1].channel=parseInt(f[1],16),r.track[n-1].event[a-1].type){case 15:this.customInterpreter!==null&&(r.track[n-1].event[a-1].data=this.customInterpreter(r.track[n-1].event[a-1].type,t,!1)),this.customInterpreter!==null&&r.track[n-1].event[a-1].data!==!1||(g=t.readIntVLV(),r.track[n-1].event[a-1].data=t.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[n-1].event[a-1].data=[],r.track[n-1].event[a-1].data[0]=t.readInt(1),r.track[n-1].event[a-1].data[1]=t.readInt(1);break;case 12:case 13:r.track[n-1].event[a-1].data=t.readInt(1);break;case-1:l=!0;break;default:if(this.customInterpreter!==null&&(r.track[n-1].event[a-1].data=this.customInterpreter(r.track[n-1].event[a-1].metaType,t,!1)),this.customInterpreter===null||r.track[n-1].event[a-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return r},customInterpreter:null};if(typeof k<"u")k.exports=o;else{let s=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;s.MidiParser=o}})()});var b=class{#e={};addEventListener(e,i){this.#e[e]||(this.#e[e]=[]),this.#e[e].unshift(i)}removeEventListener(e,i){if(this.#e[e]){let o=this.#e[e].indexOf(i);o>-1&&this.#e[e].splice(o,1),this.#e[e].length<1&&delete this.#e[e]}}dispatchEvent(e,i){let o=new Event(e),s=this;o.data=i,this.#e[e]?.length>0&&this.#e[e].forEach(function(t){try{t?.call(s,o)}catch(r){console.error(r)}}),this[`on${e}`]&&this[`on${e}`](o)}};var y=B(T(),1);var x=class{#e=!1;constructor(e,i,o,s){this.#e=e,this.start=i,this.end=o,this.data=s}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#e}},I=class extends x{constructor(e,i,o){super(!0,e,i,o)}},M=class extends x{constructor(e,i){super(!1,e,e,i)}},w=class extends Array{#e=-1;constructor(){super(...arguments)}resetIndex(e){this.#e=-1}fresh(){this.sort(function(e,i){return e.start==i.start?0:(+(e.start>i.start)<<1)-1}),this.forEach(function(e,i){e.index=i})}step(e,i=!1){let o=[];if(i)for(let s=0;se);s++){if(this[s].endt.#e&&(o.push(r),t.#e=r.index)})}return o}getRange(e,i){e>i&&([e,i]=[i,e]);let o=[],s=-1,t=Math.ceil(Math.sqrt(this.length)),r=!0;for(let c=0;c=e&&(s=c):s=s<0?c:s;for(;r;)this[s]?.end=e&&o.push(this[s]):r=!1,s++;return o}};var V=0xffffffffffff,U=function(e){let i=new w,o=this,s=e.timeDivision,t=120,r=new w,c=0,d=0;r.push(new I(0,V,[120,0])),e.track.forEach(function(n){c=0,n.event.forEach(function(a){c+=a.deltaTime,a.type==255&&a?.metaType==81&&(t=6e7/a.data,r[r.length-1]&&r.push(new I(c,0xffffffffffff,[t,0])))})}),r.fresh(),r.forEach(function(n,a,l){a>0&&(l[a-1].end=n.start)});let g=120;r.forEach(function(n,a,l){a>0&&(n.end==n.start?l.splice(l.indexOf(n),1):g==n.data[0]&&(l[a-1].end=n.end,l.splice(l.indexOf(n),1)),g=n.data[0])});let h=0,u=120;return r.forEach(function(n){let a=n.start,l=a/u/s*60+h;u=n.data[0],h=l-a/u/s*60,n.data[1]=h}),console.debug("All tempo changes: ",r),t=120,c=0,d=0,e.track.forEach(function(n,a){c=0,d=0;let l=a+1;n.event.forEach(function(f,v){c+=f.deltaTime;let p=r.step(c,!0)[0];p&&(t=p.data[0],d=p.data[1]);let m={type:f.type,data:f.data,track:l,part:0};f.type>14?m.meta=f.metaType:m.part=f.channel,i.push(new M(c/t/s*60+d,m))})}),i.fresh(),self.midiEvents=i,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),i};var L=function(e,i,o){let s=[],t=o==!1?i.readIntVLV():o;e==0||e==127;for(let r=0;r127)return console.debug(`Early termination: ${s}`),s.pop(),i.backOne(),i.backOne(),new Uint8Array(s)}}}return new Uint8Array(s)};y.default.customInterpreter=L;var J=function(e,i=0){let o=e[0]>>4,s=e[0]&15,t={track:(i&15)+240,type:o,data:e.slice(1)};if(o<15)return t.part=s,t;if(o==12)t.data=e[1];else{if(s==0)return t;console.warn(`Unknown special event channel ${s}.`)}},ee=function(e){let i=e.type,o=e.part;if(i==255)return;let s=3;i==12?s=2:i==15&&(s=e.data.length+1);let t=new Uint8Array(s);return i!=15?t[0]=e.type*16+e.part:t[0]=240,i==12?t[1]=e.data:e.data.forEach?e.data.forEach((r,c)=>{t[c+1]=r}):console.debug(`Type ${i} value ${e.data.constructor.name} cannot be iterated.`),t},te=function(){return new BroadcastChannel("cc.ltgc.octavia:MainInput")},re=function(){return new BroadcastChannel("cc.ltgc.octavia:MainOutput")},ne=class extends b{#e;#a=!0;#r=0;#n=0;#t=-1;get currentTime(){return this.#r/1e3}get duration(){return this.#e?this.#e[this.#e.length-1].end+4:0}async load(e){e?this.#e=U(y.default.parse(new Uint8Array(await e.arrayBuffer()))):(this.pause(),this.#r=0)}pause(){if(this.#t>-1){clearInterval(this.#t);for(let e=0;e<16;e++)this.dispatchEvent("midi",{delay:0,data:{part:e,type:11,data:[123,0]}});this.dispatchEvent("pause"),this.#t=-1}}async play(){this.#t<0&&(this.#n=Date.now(),this.#t=setInterval(()=>{let e=Date.now(),i=this.#r,o=e-this.#n;this.#r+=o,this.#e.step(this.currentTime)?.forEach(t=>{this.dispatchEvent("midi",{delay:Math.round(t.start*1e3-i),data:t.data})}),this.#n=e},12.5),this.dispatchEvent("play"))}constructor(e){super(),e&&this.load(e)}};export{ne as SimpleMidiEventEmitter,ee as fromJson,te as getBridge,re as getBridgeOut,J as toJson}; +var D=Object.create;var x=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var L=(i,s)=>()=>(s||i((s={exports:{}}).exports,s),s.exports);var U=(i,s,l,o)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of O(s))!I.call(i,r)&&r!==l&&x(i,r,{get:()=>s[r],enumerable:!(o=P(s,r))||o.enumerable});return i};var N=(i,s,l)=>(l=i!=null?D(A(i)):{},U(s||!i||!i.__esModule?x(l,"default",{value:i,enumerable:!0}):l,i));var M=L((_e,w)=>{(function(){"use strict";let i={fatal:!0},s=[new TextDecoder("iso-8859-15",i),new TextDecoder("sjis",i),new TextDecoder("euc-jp",i),new TextDecoder("utf-8",i),new TextDecoder("utf-16",i),new TextDecoder("ascii")],l={debug:!1,parse:function(o,r){if(o instanceof Uint8Array)return l.Uint8(o);if(typeof o=="string")return l.Base64(o);if(o instanceof HTMLElement&&o.type==="file")return l.addListener(o,r);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(o,r){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(o===void 0||!(o instanceof HTMLElement)||o.tagName!=="INPUT"||o.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;r=r||function(){},o.addEventListener("change",function(a){if(!a.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let h=new FileReader;h.readAsArrayBuffer(a.target.files[0]),h.onload=function(d){r(l.Uint8(new Uint8Array(d.target.result)))}})},Base64:function(o){let r=function(d){var E="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(d=d.replace(/^.*?base64,/,""),d=String(d).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(d))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");d+="==".slice(2-(3&d.length));let b,u="",e,t,c=0;for(;c>16&255):t===64?String.fromCharCode(b>>16&255,b>>8&255):String.fromCharCode(b>>16&255,b>>8&255,255&b);return u}(o=String(o));var a=r.length;let h=new Uint8Array(new ArrayBuffer(a));for(let d=0;d{t[p]=this.readInt(1)});for(let f=0;f191||g>127&&g<160)throw new RangeError(`Invalid code point: ${g}`)}c=!0,console.debug(`String byte sequence in ${s[f].encoding}`)}catch(p){console.debug(`SMF string ${p}`)}return n||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let e=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)e=this.readInt(1);else{let c=[];for(;128<=this.data.getUint8(this.pointer);)c.push(this.readInt(1)-128);var t=this.readInt(1);for(let n=1;n<=c.length;n++)e+=c[c.length-n]*Math.pow(128,n);e+=t}return e}};if(r.data=new DataView(h.buffer,h.byteOffset,h.byteLength),r.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;r.readInt(4);let a={};a.formatType=r.readInt(2),a.tracks=r.readInt(2),a.track=[];var h=r.readInt(1),d=r.readInt(1);128<=h?(a.timeDivision=[],a.timeDivision[0]=h-128,a.timeDivision[1]=d):a.timeDivision=256*h+d;for(let e=1;e<=a.tracks;e++){a.track[e-1]={event:[]};var E,b=r.readInt(4);if(b===-1)break;if(b!==1297379947)return!1;r.readInt(4);let t=0,c=!1,n,f;for(;!c&&(t++,a.track[e-1].event[t-1]={},a.track[e-1].event[t-1].deltaTime=r.readIntVLV(),(n=r.readInt(1))!==-1);)if(128<=n?f=n:(n=f,r.movePointer(-1)),n===255){a.track[e-1].event[t-1].type=255,a.track[e-1].event[t-1].metaType=r.readInt(1);var u=r.readIntVLV();switch(a.track[e-1].event[t-1].metaType){case 47:case-1:c=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:a.track[e-1].event[t-1].data=r.readStr(u);break;case 33:case 89:case 81:a.track[e-1].event[t-1].data=r.readInt(u);break;case 84:a.track[e-1].event[t-1].data=[],a.track[e-1].event[t-1].data[0]=r.readInt(1),a.track[e-1].event[t-1].data[1]=r.readInt(1),a.track[e-1].event[t-1].data[2]=r.readInt(1),a.track[e-1].event[t-1].data[3]=r.readInt(1),a.track[e-1].event[t-1].data[4]=r.readInt(1);break;case 88:a.track[e-1].event[t-1].data=[],a.track[e-1].event[t-1].data[0]=r.readInt(1),a.track[e-1].event[t-1].data[1]=r.readInt(1),a.track[e-1].event[t-1].data[2]=r.readInt(1),a.track[e-1].event[t-1].data[3]=r.readInt(1);break;default:this.customInterpreter!==null&&(a.track[e-1].event[t-1].data=this.customInterpreter(a.track[e-1].event[t-1].metaType,r,u)),this.customInterpreter!==null&&a.track[e-1].event[t-1].data!==!1||(r.readInt(u),a.track[e-1].event[t-1].data=r.readInt(u),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((n=n.toString(16).split(""))[1]||n.unshift("0"),a.track[e-1].event[t-1].type=parseInt(n[0],16),a.track[e-1].event[t-1].channel=parseInt(n[1],16),a.track[e-1].event[t-1].type){case 15:this.customInterpreter!==null&&(a.track[e-1].event[t-1].data=this.customInterpreter(a.track[e-1].event[t-1].type,r,!1)),this.customInterpreter!==null&&a.track[e-1].event[t-1].data!==!1||(E=r.readIntVLV(),a.track[e-1].event[t-1].data=r.readInt(E),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:a.track[e-1].event[t-1].data=[],a.track[e-1].event[t-1].data[0]=r.readInt(1),a.track[e-1].event[t-1].data[1]=r.readInt(1);break;case 12:case 13:a.track[e-1].event[t-1].data=r.readInt(1);break;case-1:c=!0;break;default:if(this.customInterpreter!==null&&(a.track[e-1].event[t-1].data=this.customInterpreter(a.track[e-1].event[t-1].metaType,r,!1)),this.customInterpreter===null||a.track[e-1].event[t-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return a},customInterpreter:null};if(typeof w<"u")w.exports=l;else{let o=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;o.MidiParser=l}})()});var S=class{#e={};context;set(i,s){this.#e[i]=s}has(i){return!!this.#e[i]}async read(i,s){if(!this.has(i))throw new Error(`No decoder registered for "${i}"`);return await this.#e[i].call(this.context||this,s)}};var H=function(i,s){let l=!0;return s.forEach((o,r)=>{l=l&&i[r]==o}),l},m=function(i){let s=0;return i.forEach(l=>{s*=256,s+=l}),s},y=new TextDecoder,$=new S;$.set("s7e",async function(i){let s=new Uint8Array(await i.slice(0,65536).arrayBuffer()),l="MSB LSB PRG NME",o=[0,0,0,0],r=32,a=0,h=0,d=!0,E=[],b=0;for(;d;){let u=s.subarray(a);([()=>{y.decode(u.subarray(0,4))=="YSFC"?(a+=80,h=1):a++},()=>{if(H(u.subarray(0,4),o))E.forEach((e,t,c)=>{let n=m(s.subarray(e.start+4,e.start+8));e.length=n}),h=2;else{let e=y.decode(u.subarray(0,4)),t=m(u.subarray(4,8));E.push({type:e,start:t}),a+=8}},()=>{let e=E[b],t=s.subarray(e.start,e.start+e.length),c=32;switch(e.type){case"ENVC":{let n=r;for(;n=E.length&&(h=3,d=!1)}][h]||(()=>{d=!1}))()}return l});$.set("pcg",async function(i){let s=new Uint8Array(await i.arrayBuffer()),l="MSB LSB PRG NME",o=100,r=0,a=0,h=!0,d=[],E=0;for(;h;){let b=s.subarray(o);([()=>{h=y.decode(b.subarray(0,4))=="INI2",a=b[15],o+=16,r=1},()=>{let u=y.decode(b.subarray(0,4)),e=b[5],t=b[7],c=b[11],n=m(b.subarray(12,16)),f=m(b.subarray(16,20)),p=m(b.subarray(36,40)),g=y.decode(b.subarray(44,44+c));d.push({type:u,tipMsb:e,tipLsb:t,nameLen:c,length:n,start:f,entryLen:p,name:g}),o+=64,a--,a<1&&(r=2)},()=>{let u=d[E],e=s.subarray(u.start,u.start+u.length);switch(u.type){case"PRG1":break;case"PBK1":{let t=63,c=(u.tipMsb?6:0)+u.tipLsb;for(let n=0;n<128;n++){let f=n*u.entryLen,p=e.subarray(f,f+u.entryLen),g=y.decode(p.subarray(0,24)).trimEnd().replace("InitProg","");g.length&&c>5&&(l+=` +${t.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")} ${g}`)}break}case"CBK1":{let t=63,c=(u.tipMsb?3:0)+u.tipLsb+10;for(let n=0;n<128;n++){let f=n*u.entryLen,p=e.subarray(f,f+u.entryLen),g=y.decode(p.subarray(0,24)).trimEnd().replace("InitCombi","");g.length&&c>12&&(l+=` +${t.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")} ${g}`)}break}}E++,E>=d.length&&(r=3,h=!1)}][r]||(()=>{h=!1}))()}return l});var B=["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 G=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),_={};`hi*, +ka,か +ki,き +ku,く +ke,け +ko,こ +ky,き! +kw,くl +tsu,つ +ts,つl +sa,さ +si,すぃ +su,す +se,せ +so,そ +shi,し +sh,し! +ta,た +ti,てぃ +tu,とぅ +te,て +to,と +tchy,ち! +tchi,ち +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, +ra,ら +ri,り +ru,る +re,れ +ro,ろ +ry,り! +wa,わ +wi,うぃ +we,うぇ +wo,を +nga,ガ +ngi,ギ +ngu,グ +nge,ゲ +ngo,ゴ +ngy,ギ! +ng, +ga,が +gi,ぎ +gu,ぐ +ge,げ +go,ご +gy,ぎ! +gw,ぐl +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,ぴ! +!ya,ゃ +!yu,ゅ +!ye,ぇ +!yo,ょ +ya,や +yu,ゆ +ye,いぇ +yo,よ +!a,ゃ +!u,ゅ +!e,ぇ +!o,ょ +!a,ゃ +!u,ゅ +!e,ぇ +!o,ょ +la,ぁ +li,ぃ +lu,ぅ +le,ぇ +lo,ぉ +a,あ +i,い +u,う +e,え +o,お +*,っ +~, +^, +_,`.split(` +`).forEach(i=>{let s=i.split(",");_[s[0]]=s[1]});var C=function(i,s,l){let o=[],r=l==!1?s.readIntVLV():l;i==0||i==127;for(let a=0;a127)return console.debug(`Early termination: ${o}`),o.pop(),s.backOne(),s.backOne(),new Uint8Array(o)}}}return new Uint8Array(o)};var X=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"];var V=["melodic","drum","menu"];var v=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var k=[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 F={};X.forEach((i,s)=>{F[i]=s});var K={length:k.length};k.forEach((i,s)=>{K[i]=s});var z={length:v.length};v.forEach((i,s)=>{z[i]=s});var q={};V.forEach((i,s)=>{q[i]=s});var T=8,Be={port:T,ch:T<<4,cc:k.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:v.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255};var R=N(M(),1);R.default.customInterpreter=C;var Je=function(){return new BroadcastChannel("cc.ltgc.octavia:MainInput")},et=function(){return new BroadcastChannel("cc.ltgc.octavia:MainOutput")};export{Je as getBridge,et as getBridgeOut}; diff --git a/dist/cambiare.mjs b/dist/cambiare.mjs index d0813477..275f2e00 100644 --- a/dist/cambiare.mjs +++ b/dist/cambiare.mjs @@ -1,10 +1,10 @@ -var ze=Object.create;var he=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var We=Object.getOwnPropertyNames;var Ye=Object.getPrototypeOf,Qe=Object.prototype.hasOwnProperty;var je=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ze=(e,t,c,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let h of We(t))!Qe.call(e,h)&&h!==c&&he(e,h,{get:()=>t[h],enumerable:!(l=qe(t,h))||l.enumerable});return e};var Je=(e,t,c)=>(c=e!=null?ze(Ye(e)):{},Ze(t||!e||!e.__esModule?he(c,"default",{value:e,enumerable:!0}):c,e));var Ue=je((jt,se)=>{(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 se<"u")se.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 ue=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=ue(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&&ue(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 et=["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[et.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($,x){switch(x){case h[0]:{r=parseInt($);break}case h[1]:{s=parseInt($);break}case h[2]:{n=parseInt($);break}case h[3]:{o=$;break}case h[4]:{$=parseInt($),$<16?u=$+1:f=($&15)+1;break}case h[5]:{y=$;break}}}),l.#t[s]=l.#t[s]||[];let E=l.#t[s];if(!E[r<<7|n]||t){let $={msb:r,prg:s,lsb:n,name:o,poly:u,type:f,drum:y};E[r<<7|n]=$,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 pe=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 tt=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 pe;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(tt(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"],at=[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],be=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],me=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},ge=function(e){return e>105?at[e-106]:e>100?e*1.1-100:e/10},ye=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),te={};`hi*, +var ze=Object.create;var he=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var We=Object.getOwnPropertyNames;var Ye=Object.getPrototypeOf,Qe=Object.prototype.hasOwnProperty;var Ze=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Je=(e,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let h of We(t))!Qe.call(e,h)&&h!==n&&he(e,h,{get:()=>t[h],enumerable:!(l=qe(t,h))||l.enumerable});return e};var je=(e,t,n)=>(n=e!=null?ze(Ye(e)):{},Je(t||!e||!e.__esModule?he(n,"default",{value:e,enumerable:!0}):n,e));var Ue=Ze((Zt,se)=>{(function(){"use strict";let e={fatal:!0},t=[new TextDecoder("iso-8859-15",e),new TextDecoder("sjis",e),new TextDecoder("euc-jp",e),new TextDecoder("utf-8",e),new TextDecoder("utf-16",e),new TextDecoder("ascii")],n={debug:!1,parse:function(l,h){if(l instanceof Uint8Array)return n.Uint8(l);if(typeof l=="string")return n.Base64(l);if(l instanceof HTMLElement&&l.type==="file")return n.addListener(l,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 y=new FileReader;y.readAsArrayBuffer(p.target.files[0]),y.onload=function(v){h(n.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,o=0;for(;o>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 y=new Uint8Array(new ArrayBuffer(p));for(let v=0;v{s[f]=this.readInt(1)});for(let u=0;u191||b>127&&b<160)throw new RangeError(`Invalid code point: ${b}`)}o=!0,console.debug(`String byte sequence in ${t[u].encoding}`)}catch(f){console.debug(`SMF string ${f}`)}return c||"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 o=[];for(;128<=this.data.getUint8(this.pointer);)o.push(this.readInt(1)-128);var s=this.readInt(1);for(let c=1;c<=o.length;c++)r+=o[o.length-c]*Math.pow(128,c);r+=s}return r}};if(h.data=new DataView(y.buffer,y.byteOffset,y.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 y=h.readInt(1),v=h.readInt(1);128<=y?(p.timeDivision=[],p.timeDivision[0]=y-128,p.timeDivision[1]=v):p.timeDivision=256*y+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,o=!1,c,u;for(;!o&&(s++,p.track[r-1].event[s-1]={},p.track[r-1].event[s-1].deltaTime=h.readIntVLV(),(c=h.readInt(1))!==-1);)if(128<=c?u=c:(c=u,h.movePointer(-1)),c===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:o=!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((c=c.toString(16).split(""))[1]||c.unshift("0"),p.track[r-1].event[s-1].type=parseInt(c[0],16),p.track[r-1].event[s-1].channel=parseInt(c[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:o=!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 se<"u")se.exports=n;else{let l=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;l.MidiParser=n}})()});var ue=function(e,t){let n=Math.min(e.length,t.length),l=e.slice(0,n),h=t.slice(0,n),p=0,y=0;for(;y0){let l=this.pool.length,h=1<=1&&y>=0;){if(y<=0)throw new Error("TTL reached.");if(p==l)p-=h;else{let a=ue(t,this.pool[p]);switch(a){case 0:{y=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,y--}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&&ue(t,this.pool[p])>0&&p++}return v||n?p:-1}else return n?0:-1},this.add=function(t,n){return t.data=n,this.pool.splice(this.point(t,!0),0,t),this},this.default=function(t){console.warn(`No match in "${this.name||"(unknown)"}" for "${t}". Default action not defined.`)},this.get=function(t){let n=this.point(t);if(n>-1)return this.pool[n].data;this.default(t)},this.run=function(t,...n){let l=this.point(t);l>-1?t.subarray?this.pool[l].data(t.subarray(this.pool[l].length),...n):this.pool[l].data(t.slice(this.pool[l].length),...n):this.default(t,...n)}};var W=class{#t={};addEventListener(e,t){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(t)}removeEventListener(e,t){if(this.#t[e]){let n=this.#t[e].indexOf(t);n>-1&&this.#t[e].splice(n,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,t){let n=new Event(e),l=this;n.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(h){try{h?.call(l,n)}catch(p){console.error(p)}}),this[`on${e}`]&&this[`on${e}`](n)}};var et=["MSB","PRG","LSB","NME","ELC","DRM"],j=function(e){let t=Math.floor(e/10),n=e%10;return`${t.toString(16)}${n}`},ee=class{#t;strictMode=!1;get(e=0,t=0,n=0,l){let h=[e,t,n],p,y=1,v=0,a,i=Array.from(arguments);switch(l){case"xg":{switch(e){case 0:{n==126?i[2]=125:n==127&&(i[2]=0);break}case 16:{n==126&&(i[2]=0);break}case 32:{n>125&&(i[2]=0),i[2]+=4;break}case 33:case 34:case 35:case 36:{n>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:{n==126&&(i[2]=0);break}case 48:case 64:case 126:case 127:{n==126&&(i[2]=0);break}}break}case"gs":case"sc":{e==0&&n<5?i[2]=0:e>125&&n<5&&n!=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&&n==0&&(i[2]=5);break}case"s90es":{n<8?i[2]+=17:n<32?i[2]+=13:i[2]=(i[2]>>3)+19;break}case"motif":{n<8?i[2]+=28:n<32?i[2]+=13:i[2]=(i[2]>>3)+19;break}}let d=" ",r="M",s="",o=0,c=0;switch(i[0]){case 0:{switch(i[2]){case 127:{l=="xg"?r="GM-a":(r="MT-a",s="C/M");break}case 126:{l=="xg"?r="GM-n":(r="MT-b",s="C/M");break}case 7:{r="GM-k",s="GLX";break}case 5:{r="SG-a",s="000";break}case 4:{l=="gs"||l=="sc"?(r="GM-a",s="000"):(r="SP-l",s="C/M");break}case 3:case 2:case 1:{(l=="gs"||l=="sc")&&(r="GM-a",s="000");break}case 0:{r="GM-a";break}default:r="y",o=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"[n]}`,o=3);break}case 48:{s=`M${(i[2]>>3).toString().padStart(2,"0")}`,r=`y${s}`,o=1;break}case 56:{r="GM-b";break}case 57:r=["yDOC","QY10","QY20"][i[2]-112]||"yMxv",s=["DOC","QY1","QY2"][i[2]-112]||"057";case 61:case 120:{r="rDrm";break}case 62:{r="kDrm";break}case 63:{if(i[2]<17){let E=i[2];r=E<10?"kP:":"kC:",r+=E%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";o=1;break}case 64:{r="ySFX",s="SFX";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?c=63:i[2]>>4==1&&(c=16),o=3;break}case 97:{r=i[2]>>4==1?"SDa":"VL:",o=3,i[2]>>4==1?c=16:c=112;break}case 98:{r=i[2]>>4==1?"SDb":"SG-a",o=3,c=16;break}case 99:{r=i[2]>>4==1?"SDc":"DX",i[2]>63?c=63:i[2]>>4==1&&(c=16),o=3;break}case 100:{r="AN",i[2]>63?c=63:i[2]>>4==1&&(c=16),o=3;break}case 104:case 105:case 106:case 107:{r="SDd",c=104;break}case 121:{r=`GM-${i[2]?"":"a"}`,o=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,n,i[0],i[2]][o]-c}`.padStart(4-r.length,"0")),s.length<3&&(s+=`${[e,n,e,n][o]}`.padStart(3-s.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&&n>>1==2&&(p=`DXCH_${(((i[2]&1)<<7)+t+1).toString().padStart(3,"0")}`,d=" "));let u=[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 E=this.#t[i[1]||0][(i[0]<<7)+i[2]];y=E?.poly||y,v=E?.type||v,a=E?.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${n}`,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 E=this.#t[i[1]||0][(i[0]<<7)+i[2]];y=E?.poly||y,v=E?.type||v,a=E?.drum}else p="",d="*";else i[1]==0?(p=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${n.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 f=[i[0],i[1],i[2]];switch(d){case"^":{switch(l){case"gs":case"sc":case"ns5r":{d=" ";break}}e==127&&d=="^"&&(d=" ");break}}let b="??";switch(i[0]){case 0:{i[2]==0?b="GM":i[2]==5||i[2]==7?b="KG":i[2]<126?b="XG":i[2]==127&&(b="MT");break}case 32:case 33:case 35:case 36:{i[2]>4?b=["AP","VL","PF","DX","AN"][i[0]-32]:b="GS";break}case 48:{b="MU";break}case 56:{b="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{b="AI";break}case 62:case 82:case 90:{b="XD";break}case 63:{i[2]<17?b="KR":i[2]<34?b="ES":b="DS";break}case 64:case 126:{b="XG";break}case 67:case 99:{b=i[2]>>4==1?"SD":"DX";break}case 81:{b="RW";break}case 95:{b=["DR","PC"][i[2]];break}case 96:{b=i[2]==106?"AP":i[2]>>4==1?"SD":"PF";break}case 97:{b=i[2]>>4==1?"SD":"VL";break}case 98:{b=i[2]>>4==1?"SD":"SG";break}case 100:{b="AN";break}case 104:case 105:case 106:case 107:{b="SD";break}case 120:{b="GS";break}case 121:{b=i[2]?"G2":"GM";break}case 122:{b="KG";break}case 127:{b=i[2]==127?"MT":t==0?"GM":"XG";break}default:i[0]<48&&(i[0]==16&&l=="xg"?b="XG":b="GS")}return d!=" "&&(l=="krs"||self.debugMode)&&(p="",b="KR"),{name:p||`${j(e||0)} ${j(t||0)} ${j(n||0)}`,poly:y,type:v,drum:a,iid:u,eid:f,sid:h,ending:d,sect:r,bank:s,standard:b,mode:l}}async load(e,t,n="(internal)"){let l=this,h=[],p=0,y=0;e.split(` +`).forEach(function(v,a){let i=v.split(" "),d=[];if(a==0){if(i.forEach(function(r,s){h[et.indexOf(r)]=s}),h.length<4){console.debug("Debugger launched.");debugger}}else{let r=0,s=0,o=0,c,u=1,f=0,b;i.forEach(async function($,x){switch(x){case h[0]:{r=parseInt($);break}case h[1]:{s=parseInt($);break}case h[2]:{o=parseInt($);break}case h[3]:{c=$;break}case h[4]:{$=parseInt($),$<16?u=$+1:f=($&15)+1;break}case h[5]:{b=$;break}}}),l.#t[s]=l.#t[s]||[];let E=l.#t[s];if(!E[r<<7|o]||t){let $={msb:r,prg:s,lsb:o,name:c,poly:u,type:f,drum:b};E[r<<7|o]=$,p++}y++}}),t||console.debug(`Map "${n}": ${y} total, ${p} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],n=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],l=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let h=n[0];h<=n[1];h++){let p=h<<7;for(let y=l[0];y<=l[1];y++){let v=p+y;for(let a=t[0];a<=t[1];a++)delete this.#t[a][v]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let t=this;e.forEach(async function(n){try{await fetch(`./data/bank/${n}.tsv`).then(function(l){return l.text()}).then(l=>{t.load(l,!1,n)})}catch{console.error(`Failed loading "${n}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var pe=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 tt=function(e,t){let n=!0;return t.forEach((l,h)=>{n=n&&e[h]==l}),n},V=function(e){let t=0;return e.forEach(n=>{t*=256,t+=n}),t},U=new TextDecoder,G=new pe;G.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),n="MSB LSB PRG NME",l=[0,0,0,0],h=32,p=0,y=0,v=!0,a=[],i=0;for(;v;){let d=t.subarray(p);([()=>{U.decode(d.subarray(0,4))=="YSFC"?(p+=80,y=1):p++},()=>{if(tt(d.subarray(0,4),l))a.forEach((r,s,o)=>{let c=V(t.subarray(r.start+4,r.start+8));r.length=c}),y=2;else{let r=U.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),o=32;switch(r.type){case"ENVC":{let c=h;for(;c=a.length&&(y=3,v=!1)}][y]||(()=>{v=!1}))()}return n});G.set("pcg",async function(e){let t=new Uint8Array(await e.arrayBuffer()),n="MSB LSB PRG NME",l=100,h=0,p=0,y=!0,v=[],a=0;for(;y;){let i=t.subarray(l);([()=>{y=U.decode(i.subarray(0,4))=="INI2",p=i[15],l+=16,h=1},()=>{let d=U.decode(i.subarray(0,4)),r=i[5],s=i[7],o=i[11],c=V(i.subarray(12,16)),u=V(i.subarray(16,20)),f=V(i.subarray(36,40)),b=U.decode(i.subarray(44,44+o));v.push({type:d,tipMsb:r,tipLsb:s,nameLen:o,length:c,start:u,entryLen:f,name:b}),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,o=(d.tipMsb?6:0)+d.tipLsb;for(let c=0;c<128;c++){let u=c*d.entryLen,f=r.subarray(u,u+d.entryLen),b=U.decode(f.subarray(0,24)).trimEnd().replace("InitProg","");b.length&&o>5&&(n+=` +${s.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")} ${b}`)}break}case"CBK1":{let s=63,o=(d.tipMsb?3:0)+d.tipLsb+10;for(let c=0;c<128;c++){let u=c*d.entryLen,f=r.subarray(u,u+d.entryLen),b=U.decode(f.subarray(0,24)).trimEnd().replace("InitCombi","");b.length&&o>12&&(n+=` +${s.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")} ${b}`)}break}}a++,a>=v.length&&(h=3,y=!1)}][h]||(()=>{y=!1}))()}return n});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"],at=[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],ge=[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],me=function(e){let t=.1,n=-.3;return e>66?(t=5,n=315):e>56?(t=1,n=47):e>46&&(t=.5,n=18.5),t*e-n},be=function(e){return e>105?at[e-106]:e>100?e*1.1-100:e/10},ye=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),te={};`hi*, ka,か ki,き ku,く @@ -141,8 +141,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let t=e.split(",");te[t[0]]=t[1]});var ve=function(e){let t=e;e[0]=="*"&&(t=t.slice(1)),["aa","ii","uu","ee","oo"].forEach(l=>{for(;t.indexOf(l)>-1;)t=t.replace(l,l[0])});for(let l in 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},Ee=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"],we=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],$e=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var rt={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"},it={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 rt[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ke=function(e,t,c){let l=(e[0]-32<<16)+(e[1]<<8)+t,h=it[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},xe=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"],st={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"},nt=["melodic","drum","menu"],Te={"?":[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=[9,25,41,57,73,89,105,121],ct=[0,3,81,84,88],Ce={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Me={0:0,1:1,2:3,5:4},Re={0:0,1:1,2:2,5:3},Pe=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],De=[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],Oe={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],ot=[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],lt=[33,99,100,32,102,8,9,10],Ae=[0,16,25,40,32,64,26,48],w={};C.forEach((e,t)=>{w[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 dt={};nt.forEach((e,t)=>{dt[e]=t});var ft=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 Le=8,m={port:Le,ch:Le<<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},Ie=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#w(){return this.#d[this.#m]}set#w(e){this.#d[this.#m]=e}#k=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);#x=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*De.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);#v=new Uint8Array(m.ch);#$=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);#y={};#c;#H;#Y;#p=100;#G=0;#ne=500;#ce=0;#Q="";#j=0;#le=0;#oe=0;#_=!0;#E=!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==w.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.#x[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.#x[l]==this.NOTE_SOSTENUTO_SUSTAIN)this.#x[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.#x[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.#x[h]>0&&this.#u[h]!=l;)h++;if(h{},cAt:(e,t)=>{},hoOf:e=>{this.#x.forEach((t,c)=>{if(t==this.NOTE_HELD){let l=this.#u[c],h=l>>7;e==h&&(this.#x[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.#x.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.#x[c]=l;let h=this.#u[c];this.dispatchEvent("note",{part:e,note:h&127,velo:this.#h[h],state:l})}})},soOf:e=>{this.#x.forEach((t,c)=>{if(t==this.NOTE_SOSTENUTO_HELD){let l=this.#u[c],h=l>>7;e==h&&(this.#x[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)==w.xg&&c.#i[t]>1){let p=c.getChDrumFirstWrite(t);p[0]&&p[1]!=m.invalidCh&&!c.#k[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 w.s90es:case w.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(t,1);break}e.data[1]&&this.setChActive(t,1);break}default:{this.setChActive(t,1);break}}})();let p=t*m.cc,g=t*m.ext,v=this.getChModeId(t);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(ot.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==w.gs||this.#t==w.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==w.gm&&(e.data[1]<48?this.#i[t]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${t+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0)),this.#t){case w.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 w["05rw"]:case w.x5d:case w.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 w.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#i[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case w.g2:{e.data[1]==120?this.#i[t]==0&&(this.setChType(t,this.CH_DRUMS),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:t});break}case 2:{this.getExt(t)[1]==this.VLBC_BRTHEXPR&&(this.#e[p+b[129]]=e.data[1]);break}case 6:{if(this.#U){[w.xg,w.gs,w.sc,w.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 a=this.#e[p+b[99]],i=this.#e[p+b[98]];if(a==1){let d=lt.indexOf(i);if(d>-1)this.#e[p+b[71+d]]=e.data[1],T()&&console.debug(`Redirected NRPN 1 ${i} to cc${71+d}.`),this.dispatchEvent("cc",{part:t,cc:71+d,data:e.data[1]});else{let r=De.indexOf(i);r>-1?this.#X[t*10+r]=e.data[1]-64:console.warn(`NRPN 0x01${i.toString(16).padStart(2,"0")} is not supported.`),T()&&console.debug(`CH${t+1} voice NRPN ${i} commit`)}}else{if(Y.indexOf(a)<0){let r=`NRPN 0x${a.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")} `;a==127?console.warn(`${r}is not necessary. Consider removing it.`):console.warn(`${r}is not supported.`)}else{let r=this.#i[t]-2;r<0?console.warn(`CH${t+1} cannot accept drum NRPN as type ${F[this.#i[t]]}.`):this.#l[(r*m.dpn+D[a])*m.dnc+i]=e.data[1]}T()&&console.debug(`CH${t+1} (${F[this.#i[t]]}) drum NRPN ${a} commit`)}}else{let a=Me[this.#e[p+b[100]]],i=Re[this.#e[p+b[100]]];if(this.#e[p+b[101]]==0&&a!=null)switch(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],Pe[a][0]),Pe[a][1]),this.#s[t*m.rpn+a]=e.data[1],this.#o[t*m.rpnt+i]=1,v){case w.xg:case w.gs:case w.sc:case w.mt32:case w.s90es:case w.motif:{switch(this.#e[p+b[100]]){case 1:case 2:{this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)});break}}break}default: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 w.s90es:case w.motif:{this.setChType(t,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.getExt(t)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:t});break}case 38:{if(!this.#U){let a=Me[this.#e[p+100]],i=Re[this.#e[p+100]];this.#e[p+101]==0&&a!=null&&(this.#s[t*m.rpn+a+1]=e.data[1],this.#o[t*m.rpnt+i]=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)==w.xg&&c.#i[t]&&c.setDrumFirstWrite(t)},12:function(e){let t=e.channel,c=this;switch(c.#t){case w.s90es:case w.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.#$[t]=0,T()&&console.debug(`T:${e.track} C:${t} P:${e.data}`),c.dispatchEvent("voice",{part:t}),c.getChModeId(t)==w.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){ft(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=ct.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.#k}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.#y[t.getChModeId(e)][0],l[b[32]]=l[b[32]]||t.#y[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.#y[c.getChModeId(e)][0],l==H.bank0&&(l=0);break}case 32:{l=l||c.#y[c.getChModeId(e)][1];break}}return l}getCcAll(){let e=this,t=e.#e.slice();for(let c=0;c0&&!l&&(h.#e[e*m.cc+b[0]]=h.#y[c][2])}setChActive(e,t=0){this.#k[e]!=t&&this.dispatchEvent("channeltoggle",{part:e,active:t}),this.#k[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.#x[h]})}),t}getBitmap(){return{bitmap:this.#w,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.#y[h.#t][0],g=t,v=c||h.#y[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.#$[e]){let l="";switch(t.#t){case w.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==w.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(st[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=w.krs),l){case w["05rw"]:{c.#c.x5=81;break}case w.s90es:c.#c.ds=w.s90es,c.#c.smotif=w.s90es;case w.motif:c.#c.ds=w.motif,c.#c.smotif=w.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.#y[w[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]=t.#y[t.getChModeId(c)][2]}),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.#v[e]=t,c.dispatchEvent("voice",{part:e})}getChMode(e,t){return C[this.getChModeId(e,t)]}getChModeId(e,t){return t?this.#v[e]||this.#n[e>>4]:this.#v[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=w["?"]),l.#t=h,l.#m=0;for(let v=0;v0&&l.#v[v]==0&&(l.#e[v*m.cc]=l.#y[h][2]);switch(h){case w.mt32:{ie.forEach((v,a)=>{let i=a+1;l.#k[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 w["?"]:case w.g2:{g=[52,4,52,18,0,0,0,0];break}case w.xg:{g=[1,0,65,0,5,0,0,0];break}case w.gm:case w.gs:case w.sc:{g=[40,4,40,18,40,32,32,0];break}case w.sd:{g=[58,0,60,0,61,0,61,0];break}case w["05rw"]:case w.x5d:case w.ns5r:{g=[44,1,44,19,44,0,44,0];break}case w.k11:case w.sg:{g=[24,0,0,0,0,0,0,0];break}case w.mt32:{g=[40,4,0,0,0,0,0,0];break}case w.doc:{g=[24,16,0,0,0,0,0,0];break}case w.motif:case w.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(`${Ce[e.type]?Ce[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${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.#w=new Uint8Array(256),e.#d[10]=new Uint8Array(512),e.#ee=new O,e.#c={x5:82,ds:w.krs,smotif:w.s90es,gs:4,sc:3},e.#H={dumpLimit:e.DUMP_MODE},e.#Y=new Proxy(e.#H,{set:()=>{}});for(let a in Te){let i=w[a];i==null?console.debug(`SubDB build error: "${a}" does not exist`):e.#y[i]=new Uint8Array(Te[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 n=t.indexOf("!");return n>-1&&t.length>1&&(t=t.slice(n+1)),t},ve=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"],we=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],$e=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var rt={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"},it={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 rt[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ke=function(e,t,n){let l=(e[0]-32<<16)+(e[1]<<8)+t,h=it[l]||{},p=h[0];if(p?.length)return p+=`: ${(h[1]||function(){})(n)||n}`,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},xe=function(e,t,n){let l=[],h=n==!1?t.readIntVLV():n;e==0||e==127;for(let p=0;p127)return console.debug(`Early termination: ${l}`),l.pop(),t.backOne(),t.backOne(),new Uint8Array(l)}}}return new Uint8Array(l)},N=function(e){let t=0;return e.forEach(n=>{t+=n,t=t&127}),~t+1&127},I=function(e,t){let n=0,l=0;for(let h=0;h>p&1)<<7,v=e[h];v+=y,h%8!=0?(t(v,n,e),n++):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 R=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"],st={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"},nt=["melodic","drum","menu"],Te={"?":[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:[121,0,120],s90es:[0,0,127],motif:[0,0,127],trin:[0,0,127]},Se=[9,25,41,57,73,89,105,121],ct=[0,3,81,84,88],Ce={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Me={0:0,1:1,2:3,5:4},Re={0:0,1:1,2:2,5:3},Pe=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],De=[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],ot=[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],lt=[33,99,100,32,102,8,9,10],Le=[0,16,25,40,32,64,26,48],w={};R.forEach((e,t)=>{w[e]=t});var m={length:z.length};z.forEach((e,t)=>{m[e]=t});var A={length:Y.length};Y.forEach((e,t)=>{A[e]=t});var dt={};nt.forEach((e,t)=>{dt[e]=t});var ft=function(e){let t=[],n=0;return e?.forEach(function(l,h){l==247?t.push(e.subarray(n,h)):l==240&&(n=h+1)}),t.length||t.push(e.subarray(0)),T()&&console.debug(t),t};var Ie=8,g={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},D={bank0:128},Oe=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;#h=new Array(11);get#w(){return this.#h[this.#m]}set#w(e){this.#h[this.#m]=e}#k=new Uint8Array(g.ch);#u=new Uint8Array(g.ch);#i=new Uint8Array(g.ch);#e=new Uint8Array(g.ch*g.cc);#d=new Uint8Array(g.ch*g.ace);#r=new Uint8Array(g.ch);#p=new Uint8Array(g.ch*g.nn);#b=new Uint8Array(g.ch);#g=new Uint16Array(g.pl);#x=new Uint8Array(g.pl);#I=new Int16Array(g.ch);#O=new Uint8Array(g.ch);#U=new Uint8Array(g.ch);#M=new Uint8Array(g.ch*g.ext);#s=new Uint8Array(g.ch*g.rpn);#o=new Uint8Array(g.ch*g.rpnt);#H=new Int8Array(g.ch*De.length);#l=new Uint8Array(g.drm*g.dpn*g.dnc);#P=new Uint8Array(g.drm*2);#S=new Uint8Array(g.efx*3);#a=new Uint8Array(g.ch);#R=new Uint8Array(g.ch*g.redir);#n=new Uint8Array(g.port);#E=new Uint8Array(g.ch);#$=new Uint8Array(g.ch);#z=new Uint8Array(g.ch*g.cvn);#A=new Uint8Array(128);#L=new Uint8Array(g.cmt*8);#q=new Uint8Array(1024);#_=new Uint8Array(g.cmt*64);#y={};#c;#X;#Y;#f=100;#G=0;#ne=500;#ce=0;#Q="";#Z=0;#le=0;#oe=0;#F=!0;#v=!1;#he=1;#de;#j=new Array(g.ch);#B=[];#W=new Uint8Array(g.ch);#J=new Uint8Array(g.tr);baseBank=new ee("gm","gm2","xg","gs","ns5r","sd","gmega","plg-vl","plg-pf","plg-dx","plg-an","plg-dr","plg-sg","kross","s90es");userBank=new ee("gm");initOnReset=!1;aiEfxName="";chRedir(e,t,n){let l=this;if(l.#J[t])return(l.#J[t]-1)*16+e;if(l.#t==w.sc){if(n==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 n=e*128+t,l=this.#g.lastIndexOf(n);if(l>-1)if(this.#e[g.cc*e+m[64]]>63)this.#x[l]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#p[n],state:this.NOTE_HELD});else if(this.#e[g.cc*e+m[66]]>63&&this.#x[l]==this.NOTE_SOSTENUTO_SUSTAIN)this.#x[l]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#p[n],state:this.NOTE_SOSTENUTO_HELD});else{this.#g[l]=0,this.#p[n]=0,this.#x[l]=this.NOTE_IDLE;let h=this.getExt(e)[1];(h==this.VLBC_VELOINIT||h==this.VLBC_VELOALL)&&(this.#e[g.cc*e+m[129]]=0),this.dispatchEvent("note",{part:e,note:t,velo:0,state:this.NOTE_IDLE})}},nOn:(e,t,n)=>{let l=e*128+t,h=0;for(this.#b[e]&&this.#C.ano(e);this.#x[h]>0&&this.#g[h]!=l;)h++;if(h{},cAt:(e,t)=>{},hoOf:e=>{this.#x.forEach((t,n)=>{if(t==this.NOTE_HELD){let l=this.#g[n],h=l>>7;e==h&&(this.#x[n]=this.NOTE_IDLE,this.#g[n]=0,this.#p[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#x.forEach((t,n)=>{let l;switch(t){case this.NOTE_ATTACK:{l=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{l=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{l=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(l){this.#x[n]=l;let h=this.#g[n];this.dispatchEvent("note",{part:e,note:h&127,velo:this.#p[h],state:l})}})},soOf:e=>{this.#x.forEach((t,n)=>{if(t==this.NOTE_SOSTENUTO_HELD){let l=this.#g[n],h=l>>7;e==h&&(this.#x[n]=this.NOTE_IDLE,this.#g[n]=0,this.#p[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#g.forEach((t,n,l)=>{let h=t>>7,p=t&127;t==0&&this.#p[0]==0||h==e&&this.#C.nOff(h,p)})}};#fe={8:function(e){let t=e.channel,n=e.data[0];this.#C.nOff(t,n)},9:function(e){let t=e.channel,n=this;if(n.getChModeId(t)==w.xg&&n.#i[t]>1){let p=n.getChDrumFirstWrite(t);p[0]&&p[1]!=g.invalidCh&&!n.#k[t]&&(n.copyChSetup(p[1],t),n.dispatchEvent("voice",{part:t}),console.debug(`Part CH${t+1} copied from CH${p[1]}.`))}n.setChActive(t,1);let l=e.data[0],h=e.data[1];h>0?n.#C.nOn(t,l,h):n.#C.nOff(t,l)},10:function(e){let t=e.channel,n=t*128+e.data[0];this.#g.indexOf(n)>-1&&(this.#p[n]=data[1],this.getExt(t)[1]==this.VLBC_VELOALL&&(this.#e[g.cc*t+m[129]]=data[1]),this.dispatchEvent("note",{part:t,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let t=e.channel,n=this,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 w.s90es:case w.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(t,1);break}e.data[1]&&this.setChActive(t,1);break}default:{this.setChActive(t,1);break}}})();let p=t*g.cc,y=t*g.ext,v=this.getChModeId(t);switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#C.ano(t),this.#I[t]=0,this.#e[p+m[1]]=0,this.#e[p+m[5]]=0,this.#e[p+m[64]]=0,this.#e[p+m[65]]=0,this.#e[p+m[66]]=0,this.#e[p+m[67]]=0,this.#e[p+m[11]]=127,this.#e[p+m[101]]=127,this.#e[p+m[100]]=127,this.#e[p+m[99]]=127,this.#e[p+m[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.#b[t]=1,this.#C.ano(t);return}case 127:{this.#b[t]=0,this.#C.ano(t);return}}if(m[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(ot.indexOf(e.data[0])>-1&&this.allocateAce(t,e.data[0]),e.data[0]){case 0:{switch(T()&&console.debug(`${R[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(R[this.#c.ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==w.gs||this.#t==w.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==w.gm&&(e.data[1]<48?this.#i[t]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${t+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0)),this.#t){case w.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[y]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?this.#M[y]=this.EXT_DX:this.#M[y]=this.EXT_NONE;break}case w["05rw"]:case w.x5d:case w.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 w.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#i[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case w.g2:{e.data[1]==120?this.#i[t]==0&&(this.setChType(t,this.CH_DRUMS),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:t});break}case 2:{this.getExt(t)[1]==this.VLBC_BRTHEXPR&&(this.#e[p+m[129]]=e.data[1]);break}case 6:{if(this.#U[t]){[w.xg,w.gs,w.sc,w.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${R[this.#t]}" mode, even when they are supported in Octavia.`);let a=this.#e[p+m[99]],i=this.#e[p+m[98]];if(a==1){let d=lt.indexOf(i);if(d>-1)this.#e[p+m[71+d]]=e.data[1],T()&&console.debug(`Redirected NRPN 1 ${i} to cc${71+d}.`),this.dispatchEvent("cc",{part:t,cc:71+d,data:e.data[1]});else{let r=De.indexOf(i);r>-1?this.#H[t*10+r]=e.data[1]-64:console.warn(`NRPN 0x01${i.toString(16).padStart(2,"0")} is not supported.`),T()&&console.debug(`CH${t+1} voice NRPN ${i} commit`)}}else{if(Y.indexOf(a)<0){let r=`NRPN 0x${a.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")} `;a==127?console.warn(`${r}is not necessary. Consider removing it.`):console.warn(`${r}is not supported.`)}else{let r=this.#i[t]-2;r<0?console.warn(`CH${t+1} cannot accept drum NRPN as type ${F[this.#i[t]]}.`):this.#l[(r*g.dpn+A[a])*g.dnc+i]=e.data[1]}T()&&console.debug(`CH${t+1} (${F[this.#i[t]]}) drum NRPN ${a} commit`)}}else{let a=Me[this.#e[p+m[100]]],i=Re[this.#e[p+m[100]]];if(this.#e[p+m[101]]==0&&a!=null)switch(T()&&console.debug(`CH${t+1} RPN 0 ${this.#e[p+m[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Pe[a][0]),Pe[a][1]),this.#s[t*g.rpn+a]=e.data[1],this.#o[t*g.rpnt+i]=1,v){case w.xg:case w.gs:case w.sc:case w.mt32:case w.s90es:case w.motif:{switch(this.#e[p+m[100]]){case 1:case 2:{this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)});break}}break}default:this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)})}}break}case 32:{switch(T()&&console.debug(`${R[this.#t]}, CH${t+1} LSB: ${e.data[1]}`),this.#t){case w.s90es:case w.motif:{this.setChType(t,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.getExt(t)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:t});break}case 38:{if(!this.#U[t]){let a=Me[this.#e[p+100]],i=Re[this.#e[p+100]];this.#e[p+101]==0&&a!=null&&(this.#s[t*g.rpn+a+1]=e.data[1],this.#o[t*g.rpnt+i]=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[t]=1;break}case 100:case 101:{this.#U[t]=0;break}}this.#e[p+m[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:t,cc:e.data[0],data:e.data[1]})}n.getChModeId(t)==w.xg&&n.#i[t]&&n.setDrumFirstWrite(t)},12:function(e){let t=e.channel,n=this;switch(n.#t){case w.s90es:case w.motif:{e.data&&n.setChActive(t,1);break}default:n.setChActive(t,1)}if(n.getExt(t)[0]==n.EXT_DX){let l=g.cc*t}n.#r[t]=e.data,n.#$[t]=0,T()&&console.debug(`T:${e.track} C:${t} P:${e.data}`),n.dispatchEvent("voice",{part:t}),n.getChModeId(t)==w.xg&&n.#i[t]&&n.setDrumFirstWrite(t)},13:function(e){let t=this,n=e.channel;this.#g.forEach(function(l){let h=l>>7;n==h&&(t.#p[l]=e.data,t.dispatchEvent("note",{part:n,note:l&127,velo:e.data,state:t.NOTE_SUSTAIN}))})},14:function(e){let t=e.channel;this.#I[t]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)})},15:function(e){ft(e.data).forEach(t=>{let n=t[0],l=t[1];(this.#ue[n]||function(){console.debug(`Unknown manufacturer ${n}.`)})(l,t.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#D[e.meta]||function(n,l,h){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#G=0);let t=ct.indexOf(e.meta)>-1;if(T()&&console.debug(e),t)return e.reply="meta",e}};#ue={64:(e,t,n)=>{this.#re.run(t,n,e)},65:(e,t,n)=>{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),n,e):console.warn(`Bad SD checksum ${l} - should be ${h}.`)}else this.#V.run(t,n,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),n,e):console.warn(`Bad GS checksum ${l} - should be ${h}.`)}},66:(e,t,n)=>{this.#K.run(t,n,e)},67:(e,t,n)=>{this.#N.run(t,n,e)},68:(e,t,n)=>{this.#se.run(t,n,e)},71:(e,t,n)=>{this.#ie.run(t,n,e)},126:(e,t,n)=>{this.#te.run(t,n,e)},127:(e,t,n)=>{this.switchMode("gm"),this.#ae.run(t,n,e)}};#te;#ae;#N;#V;#K;#re;#ie;#se;buildRchTree(){let e=[];this.#u.forEach((t,n)=>{t{t&&(e.#j[Math.floor(n/g.redir)][t]=n%g.redir|128)}),T()&&console.debug(e.#j)}getActive(){return this.#k}getCc(e){let t=this,n=e*g.cc,l=t.#e.subarray(n,n+g.cc);return l[m[0]]=l[m[0]]||t.#y[t.getChModeId(e)][0],l[m[32]]=l[m[32]]||t.#y[t.getChModeId(e)][1],l[m[0]]==D.bank0&&(l[m[0]]=0),l}getCcCh(e,t){let n=this;if(z.indexOf(t)<0)throw new Error("CC number not accepted");let l=n.#e[g.cc*e+m[t]];switch(t){case 0:{l=l||n.#y[n.getChModeId(e)][0],l==D.bank0&&(l=0);break}case 32:{l=l||n.#y[n.getChModeId(e)][1];break}}return l}getCcAll(){let e=this,t=e.#e.slice();for(let n=0;n0&&!l&&(h.#e[e*g.cc+m[0]]=h.#y[n][2])}setChActive(e,t=0){this.#k[e]!=t&&this.dispatchEvent("channeltoggle",{part:e,active:t}),this.#k[e]=t}getExt(e){let t=g.ext*e,n=this.#M.subarray(t,t+g.ext),l=new Uint8Array(n.length);return l.set(n),l[1]=l[1]||this.#he,l}getPitch(){return this.#I}getProgram(){return this.#r}getTexts(){return this.#B.slice()}getVel(e){let t=new Map,n=this;return n.#g.forEach(function(l,h){let p=Math.floor(l/128),y=l%128;e==p&&n.#p[l]>0&&t.set(y,{v:n.#p[l],s:n.#x[h]})}),t}getBitmap(){return{bitmap:this.#w,expire:this.#T}}getLetter(){return{text:this.#Q,set:this.#le,expire:this.#Z}}getMode(){return R[this.#t]}getMaster(){return{volume:this.#f}}getRawStrength(){let e=this;return this.#g.forEach(function(t){let n=Math.floor(t/128);e.#p[t]>e.#O[n]&&(e.#O[n]=e.#p[t])}),this.#O}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(n,l){e[l]=Math.floor(n*t.#e[l*g.cc+m[7]]*t.#e[l*g.cc+m[11]]*t.#f/803288)}),e}getRpn(){return this.#s}getNrpn(){return this.#H}getSubDb(){return self?.structuredClone(this.#y)}getVoice(e,t,n,l="?"){let h=this;w[l]?.constructor||(l="?");let p=w[l],y=e||h.#y[p][0],v=t,a=n||h.#y[p][1];y==D.bank0&&(y=0),a==D.bank0&&(a=0),l=="ns5r"&&y>0&&y<56&&(a=3);let i=h.userBank.get(y,v,a,l);if(l=="mt32"&&i.name.indexOf("MT-m:")==0){let d=parseInt(i.name.slice(5)),r=d*g.cmt,s="";h.#_.subarray(r,r+10).forEach(c=>{c>31&&(s+=String.fromCharCode(c))});let o=`MSB LSB PRG NME +0 127 ${v} ${s}`;h.userBank.load(o,!0),i.name=s,i.ending=" "}return(i.ending!=" "||!i.name.length)&&(i=h.baseBank.get(y,v,a,l)),i}getChVoice(e){let t=this,n=t.getVoice(t.getCcCh(e,0),t.#r[e],t.getCcCh(e,32),t.getChMode(e));if(t.#$[e]){let l="";switch(t.#t){case w.mt32:{t.#L.subarray(g.cmt*(e-1),g.cmt*(e-1)+10).forEach(h=>{l+=String.fromCharCode(Math.max(h,32))}),l=l.trimRight();break}default:{let h=g.cvn*e;t.#z.subarray(h,h+g.cvn).forEach(p=>{l+=String.fromCharCode(Math.max(p,32))}),l=l.trimRight()}}l.length&&(n.ending="~",n.name=l)}return n}getRawPitch(){return this.#I}getPitchShift(e){let t=this,n=e*g.rpn,l=t.#s[n];return t.#o[e*g.rpnt]||t.#t==w.mt32&&(l=12),t.#I[e]/8192*l+(t.#s[n+3]-64)+((t.#s[n+1]<<7)+t.#s[n+2]-8192)/8192}getEffectType(e=0){let t=3*e+1;return this.#S.subarray(t,t+2)}setEffectTypeRaw(e=0,t,n){let l=3*e;this.#S[l]=1,this.#S[l+1+ +t]=n}setEffectType(e=0,t,n){this.setEffectTypeRaw(e,!1,t),this.setEffectTypeRaw(e,!0,n)}getEffectSink(){return this.#a}setLetterDisplay(e,t,n=0,l=3200){let h=this,p;h.#Q=" ".repeat(n),e.forEach(y=>{h.#Q+=String.fromCharCode(y>31?y:32),y<32&&(p=p||new Set,p.add(y))}),h.#le=Date.now(),h.#Z=Date.now()+l,p&&(p=Array.from(p),p.forEach((y,v,a)=>{a[v]=y.toString(16).padStart(2,"0")}),console.warn(`${t}${t?" ":""}invalid code point${p.length>1?"s":""}: 0x${p.join(", 0x")}`))}setDetectionTargets(e="?",t=0){let n=this,l=-1;switch(e.replaceAll(", ",",").split(",").forEach(h=>{h=h.toLowerCase();let p=R.indexOf(st[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&&(n.#c.x5=82,n.#c.ds=w.krs),l){case w["05rw"]:{n.#c.x5=81;break}case w.s90es:n.#c.ds=w.s90es,n.#c.smotif=w.s90es;case w.motif:n.#c.ds=w.motif,n.#c.smotif=w.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 n=this;n.#c[e?"sc":"gs"]=t,n.#y[w[e?"sc":"gs"]][1]=t,n.forceVoiceRefresh()}getConfigs(){return this.#Y}setDumpLimit(e){if(e>2||e<0)throw new RangeError("Invalid dump limit.");this.#X.dumpLimit=e}allocateAce(e=0,t){let n=this;if(!t||t<128&&t>95){console.warn(`cc${t} cannot be allocated as an active custom effect.`);return}let l=!0,h=0,p=g.ace*e;for(;l&&h=g.ace&&console.warn(`ACE slots are full in CH${e+1}.`)}allocateAceAll(e){let t=this;if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}for(let n=0;n=g.ace&&console.warn(`ACE slots are full in CH${n+1}.`)}}releaseAce(e=0,t){let n=!0,l=g.ace*e,h=l+g.ace;for(;n&&l=g.ace)throw new RangeError("No such ACE slot");let n=this.#d[g.ace*e+t];if(n){if(z.indexOf(n)>=0)return this.#e[e*g.cc+m[n]];throw new Error(`Invalid ACE source in CH${e+1}: ${n}`)}else return 0}initDrums(){let e=this;e.#l.fill(64);for(let t=0;t{t.#e[g.cc*n]=t.#y[t.getChModeId(n)][2]}),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 n=0;n=g.ch)throw new RangeError(`Invalid CH${e+1}`);if(port<0||t>=R.length)throw new RangeError(`Invalid mode ID ${t}`);n.#E[e]=t,n.dispatchEvent("voice",{part:e})}getChMode(e,t){return R[this.getChModeId(e,t)]}getChModeId(e,t){return t?this.#E[e]||this.#n[e>>4]:this.#E[e]||this.#n[e>>4]||this.#t}setPortMode(e,t,n){let l=this;if(e<0||e>=g.ch>>4)throw new RangeError(`Invalid port ${e+1}`);if(t<1)throw new RangeError("Range must be a positive integer");if(e+t>=g.ch>>4)throw new RangeError("Range must be in bound");if(e<0||n>=R.length)throw new RangeError(`Invalid mode ID ${n}`);for(let h=e;h=0&&e-1){if(l.#t==0||t){let p=l.#t;l.initOnReset&&t&&(this.init(1),p=w["?"]),l.#t=h,l.#m=0;for(let v=0;v0&&l.#E[v]==0&&(l.#e[v*g.cc]=l.#y[h][2]);switch(h){case w.mt32:{ie.forEach((v,a)=>{let i=a+1;l.#k[i]||(l.#r[i]=v,l.#e[i*g.cc+m[91]]=127)});for(let v=1;v<10;v++)l.dispatchEvent("voice",{part:v});break}}let y;switch(h){case w["?"]:case w.g2:{y=[52,4,52,18,0,0,0,0];break}case w.xg:{y=[1,0,65,0,5,0,0,0];break}case w.gm:case w.gs:case w.sc:{y=[40,4,40,18,40,32,32,0];break}case w.sd:{y=[58,0,60,0,61,0,61,0];break}case w["05rw"]:case w.x5d:case w.ns5r:{y=[44,1,44,19,44,0,44,0];break}case w.k11:case w.sg:{y=[24,0,0,0,0,0,0,0];break}case w.mt32:{y=[40,4,0,0,0,0,0,0];break}case w.doc:{y=[24,16,0,0,0,0,0,0];break}case w.motif:case w.s90es:{y=[113,0,117,0,114,0,0,0];break}default:y=[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.#O.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),n=!1;this.#de[t]?.forEach(l=>{e.channel=l,n=!0,this.#fe[e.type].call(this,e)}),n||console.warn(`${Ce[e.type]?Ce[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${t+1} without any recipient.`)}this.#B.length>100&&this.#B.splice(100,this.#B.length-99)}runRaw(e){}async loadBank(e,t){let n=this;switch(e=e.toLowerCase(),e){case"s7e":{n.userBank.clearRange({msb:63,lsb:[21,22]}),n.userBank.clearRange({msb:63,lsb:[24,27]});break}case"pcg":{n.userBank.clearRange({msb:63,lsb:[6,9]}),n.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 n.userBank.load(await G.read(e,t),!1);break}}n.forceVoiceRefresh()}constructor(){super();let e=this;e.#w=new Uint8Array(256),e.#h[10]=new Uint8Array(512),e.#ee=new L,e.#c={x5:82,ds:w.krs,smotif:w.s90es,gs:4,sc:3},e.#X={dumpLimit:e.DUMP_MODE},e.#Y=new Proxy(e.#X,{set:()=>{}});for(let a in Te){let i=w[a];i==null?console.debug(`SubDB build error: "${a}" does not exist`):e.#y[i]=new Uint8Array(Te[a])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -150,26 +150,26 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -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 +122 006 000 `),e.addEventListener("metacommit",function(a){let{data:i}=a;e.#B[0]?.type==i.type&&e.#B[0]?.amend?(e.#B[0].amend=i.amend,e.#B[0].data+=i.data):e.#B.unshift(i)}),e.#D[1]=function(a){switch(a=a.replaceAll(`\r `,` `).replaceAll("\r",` -`),a.slice(0,2)){case"@I":{this.#E=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:a.slice(2)?.trimLeft()});break}case"@K":{this.#E=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:a.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{this.#E=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:a.slice(2)?.trimLeft()});break}case"@T":{this.#E=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:a.slice(2)?.trimLeft()});break}case"@V":{this.#E=!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.#E?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,w[["gm","?","g2"][a[0]-1]]),e.#E=e.#E||!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,$=0;switch(a.subarray(o,u).forEach(x=>{y=y<<7,y|=x}),a.subarray(u,f).forEach((x,R)=>{E|=x<{$|=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,w.xg),e.#E=!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: ${me(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: ${be[o]}Hz`)},o=>{},o=>{console.debug(`${r}feedback: ${o}`)},o=>{console.debug(`${r}delay offset: ${ge(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.#w.fill(0);let s=a.subarray(1);for(let n=0;n>6-$&1,$++})}).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.#k[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,w.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: ${Ee(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.#y[w.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+=ye[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:`${ve(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,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 $=E+135;e.allocateAce($),e.#e[u+b[$]]=f,e.dispatchEvent("cc",{part:o,cc:$,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,w.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,w.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.#$[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.#w.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,w.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.#y[w.sc][1]=e.#c.sc,e.#E=!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,w.gs),e.#y[w.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.#E=!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: ${we[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: ${$e[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=ke(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),$=y%16,x=($*4+E)*5,R=5,B=0;for(x-=$*4,E==3&&(R=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,w.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,w[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,w.x5d),e.#r[f]=u-1,e.#e[y+b[0]]=e.#c.x5):u<229?(e.setChType(f,e.CH_MELODIC,w.x5d),e.#r[f]=u-101,e.#e[y+b[0]]=56):(e.setChType(f,e.CH_DRUMS,w.x5d),e.#r[f]=Ae[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,w[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,w[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,w[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,w[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]!=w[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,w[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,w.x5d),e.#e[y+b[0]]=e.#c.x5,e.#r[f]=s):(e.setChType(f,e.CH_DRUMS,w.x5d),e.#e[y+b[0]]=62,e.#r[f]=Ae[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,$=s&15;e.#e[y+b[91]]=K($),e.#e[y+b[93]]=K(E);break}case 10:break;case 11:{let E=e.chRedir(s&15,i,!0),$=s>>4;e.#f[f]=s,(E!=f||$)&&(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,w.mt32),e.#E=!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.#$[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.#$[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.#$[f]=1,E==2)for(let $=0;${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.#$[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 $="";if(E==2){let R=m.cmt*u;$=`MT-m:${s.toString().padStart(3,"0")}`}else $=e.baseBank.get(0,s+(E<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:u});let x=`MSB LSB PRG NME -000 127 ${u} ${$}`;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,w.ns5r),e.#E=!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,w[d]),e.#E=!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,w.ns5r),e.#E=!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,w.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.#w.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 $=y>3,x=0,R=y0;)e.#w[E*32+y*7+(R-x)]=$&1,$=$>>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.#E=!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.#E=!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]!=w.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,w.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 $=e.chRedir(u,i,!0);e.#f[y]=$,y!=$&&(console.info(`NS5R CH${y+1} receives from CH${$+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,w.k11),e.#E=!1,e.#y[w.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,w.k11),e.#e[s+b[0]]=0,e.#r[r]=o):(e.setChType(r,e.CH_DRUMS,w.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,w.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,w.k11),e.#e[n+b[0]]=0,e.#e[n+b[32]]=7,e.#r[s]=r-100):(e.setChType(s,e.CH_DRUMS,w.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,w.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,w.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: +`),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.#J[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){T()&&console.debug(`XGworks requests assigning track ${i} to output ${a[0]}.`),e.#J[i]=a[0]+1}),e.#te=new L("universal non-realtime"),e.#ae=new L("universal realtime"),e.#N=new L("Yamaha"),e.#V=new L("Roland"),e.#K=new L("Korg"),e.#re=new L("Kawai"),e.#ie=new L("Akai"),e.#se=new L("Casio");let t=new L("DX7+ Dump"),n=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,a)};e.#te.default=n,e.#ae.default=n,e.#N.default=n,e.#V.default=n,e.#K.default=n,e.#re.default=n,e.#ie.default=n,e.#se.default=n,t.default=n,e.#te.add([9],(a,i,d)=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),e.setPortMode(e.getTrackPort(i),1,w[["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.#f=((a[1]<<7)+a[0])/16383*100,e.dispatchEvent("mastervolume",e.#f)}).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],o=a[2],c=3,u=c+(r<<1),f=u+s;if(r!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${r})! +`,a);return}let b=0,E=0,$=0;switch(a.subarray(c,u).forEach(x=>{b=b<<7,b|=x}),a.subarray(u,f).forEach((x,C)=>{E|=x<{$|=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,w.xg),e.#v=!1,console.info("MIDI reset: XG");break}default:{e.dispatchEvent("mupromptex");let r=[0,0,0,0],s=(o,c)=>{r[c]=o};if(a.subarray(1).forEach((o,c)=>{let u=c+a[0];([s,s,s,s,f=>{this.#f=f*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},f=>{},f=>{}][u]||(()=>{}))(o,c)}),a[0]<4){let o=0;r.forEach(c=>{o=o<<4,o+=c}),o-=1024}}}}).add([76,2,1],(a,i,d)=>{e.dispatchEvent("mupromptex");let r="XG ";a[0]<32?(r+="reverb ",a.subarray(1).forEach((s,o)=>{([c=>{e.setEffectTypeRaw(0,!1,c),console.info(`${r}main type: ${_[c]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},c=>{e.setEffectTypeRaw(0,!0,c),console.debug(`${r}sub type: ${c+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},c=>{console.debug(`${r}time: ${me(c)}s`)},c=>{console.debug(`${r}diffusion: ${c}`)},c=>{console.debug(`${r}initial delay: ${c}`)},c=>{console.debug(`${r}HPF cutoff: ${X[c]}Hz`)},c=>{console.debug(`${r}LPF cutoff: ${X[c]}Hz`)},c=>{console.debug(`${r}width: ${c}`)},c=>{console.debug(`${r}height: ${c}`)},c=>{console.debug(`${r}depth: ${c}`)},c=>{console.debug(`${r}wall type: ${c}`)},c=>{console.debug(`${r}dry/wet: ${c}`)},c=>{console.debug(`${r}send: ${P(c)}dB`)},c=>{console.debug(`${r}pan: ${c-64}`)},!1,!1,c=>{console.debug(`${r}delay: ${c}`)},c=>{console.debug(`${r}density: ${c}`)},c=>{console.debug(`${r}balance: ${c}`)},c=>{},c=>{console.debug(`${r}feedback: ${c}`)},c=>{}][a[0]+o]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(s)})):a[0]<64?(r+="chorus ",a.subarray(1).forEach((s,o)=>{([c=>{e.setEffectTypeRaw(1,!1,c),console.info(`${r}main type: ${_[c]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},c=>{e.setEffectTypeRaw(1,!0,c),console.debug(`${r}sub type: ${c+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},c=>{console.debug(`${r}LFO: ${ge[c]}Hz`)},c=>{},c=>{console.debug(`${r}feedback: ${c}`)},c=>{console.debug(`${r}delay offset: ${be(c)}ms`)},c=>{},c=>{console.debug(`${r}low: ${X[c]}Hz`)},c=>{console.debug(`${r}low: ${c-64}dB`)},c=>{console.debug(`${r}high: ${X[c]}Hz`)},c=>{console.debug(`${r}high: ${c-64}dB`)},c=>{console.debug(`${r}dry/wet: ${c}`)},c=>{console.debug(`${r}send: ${P(c)}dB`)},c=>{console.debug(`${r}pan: ${c-64}`)},c=>{console.debug(`${r}to reverb: ${P(c)}dB`)},!1,c=>{},c=>{},c=>{},c=>{console.debug(`${r}LFO phase diff: ${(c-64)*3}deg`)},c=>{console.debug(`${r}input mode: ${c?"stereo":"mono"}`)},c=>{}][a[0]-32+o]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(s)})):a[0]<86?(r+="variation ",a.subarray(1).forEach((s,o)=>{([c=>{e.setEffectTypeRaw(2,!1,c),console.info(`${r}main type: ${_[c]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},c=>{e.setEffectTypeRaw(2,!0,c),console.debug(`${r}sub type: ${c+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+o]||function(){})(s)})):a[0]<97?(r+="variation ",a.subarray(1).forEach((s,o)=>{[c=>{console.debug(`${r}send: ${P(c)}dB`)},c=>{console.debug(`${r}pan: ${c-64}`)},c=>{console.debug(`${r}to reverb: ${P(c)}dB`)},c=>{console.debug(`${r}to chorus: ${P(c)}dB`)},c=>{console.debug(`${r}connection: ${c?"system":"insertion"}`)},c=>{console.debug(`${r}channel: CH${c+1}`)},c=>{console.debug(`${r}mod wheel: ${c-64}`)},c=>{console.debug(`${r}bend wheel: ${c-64}`)},c=>{console.debug(`${r}channel after touch: ${c-64}`)},c=>{console.debug(`${r}AC1: ${c-64}`)},c=>{console.debug(`${r}AC2: ${c-64}`)}][a[0]-86+o](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 o=s+a[0];if(o==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][r]}`);else{let c=o-1>>2,u=o-1&3,f=`XG EQ ${c} ${["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],o=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((c,u)=>{([f=>{e.setEffectTypeRaw(3+r,!1,f),console.info(`${o}main type: ${_[f]}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))},f=>{e.setEffectTypeRaw(3+r,!0,f),console.debug(`${o}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${r}`,e.getEffectType(3+r))}][s+u]||function(){})(c)})}).add([76,6,0],(a,i,d)=>{let r=a[0];r<64?e.setLetterDisplay(a.subarray(1),"XG letter display",r):e.#Z=Date.now()}).add([76,7,0],(a,i,d)=>{let r=a[0];e.#m=0,e.#T=Date.now()+3200,e.#w.fill(0);let s=a.subarray(1);for(let o=0;o>6-$&1,$++})}).add([76,8],(a,i)=>{e.dispatchEvent("mupromptex");let d=e.chRedir(a[0],i,!0),r=a[1],s=g.cc*d,o=`XG CH${d+1} `,c=`Unknown XG part address ${r}.`,u=!0;a.subarray(2).forEach((f,b)=>{u=!0,r<1?console.debug(c):r<41?([()=>{e.#e[s+m[0]]=f,e.dispatchEvent("voice",{part:d})},()=>{e.#e[s+m[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.#u[d]=E,d!=E&&(e.buildRchTree(),console.info(`${o}receives from CH${E+1}`)),e.#k[d]||(e.copyChSetup(E,d,!0),console.debug(`${o}copied from CH${E+1}.`),e.setChActive(d,1),e.dispatchEvent("voice",{part:d}))},()=>{e.#b[d]=+!f},()=>{},()=>{u=!1,e.setChType(d,f,w.xg),console.debug(`${o}type: ${F[f]||f}`),e.dispatchEvent("voice",{part:d})},()=>{e.#s[g.rpn*d+3]=f,e.#o[g.rpnt*d+2]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)})},!1,!1,()=>{e.#e[s+m[7]]=f},!1,!1,()=>{e.#e[s+m[10]]=f||128},!1,!1,()=>{e.#e[s+m[128]]=f,e.allocateAce(d,128)},()=>{e.#e[s+m[93]]=f},()=>{e.#e[s+m[91]]=f},()=>{e.#e[s+m[94]]=f},()=>{e.#e[s+m[76]]=f},()=>{e.#e[s+m[77]]=f},()=>{e.#e[s+m[78]]=f},()=>{e.#e[s+m[74]]=f},()=>{e.#e[s+m[71]]=f},()=>{e.#e[s+m[73]]=f},()=>{e.#e[s+m[75]]=f},()=>{e.#e[s+m[72]]=f}][r+b-1]||(()=>{}))():r<48?console.debug(c):r<111?r>102&&r<105&&(e.#e[s+m[[5,65][r&1]]]=f):r<114?console.debug(c):r<116?console.debug(`${o}EQ ${["bass","treble"][r&1]} gain: ${f-64}dB`):r<118?console.debug(c):r<120?console.debug(`${o}EQ ${["bass","treble"][r&1]} freq: ${f}`):console.debug(c)}),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=g.cc*d,o=`PLG-VL CH${d+1} `;a.subarray(2).forEach((c,u)=>{let f=u+r;switch(f){case 1:{console.info(`${o}breath mode: ${["system","breath","velocity","touch EG"][c]}`);break}case 0:case 27:case 28:break;default:if(f<27){let b=f-3>>1,E=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][b];f&1?f<23?(console.debug(`${o}${E} control source: ${ve(c)}`),c&&c<96&&e.allocateAce(d,130+b),e.#R[g.redir*d+b+2]=c,e.buildRccMap()):console.debug(`${o}${E} scale break point: ${c}`):(console.debug(`${o}${E} depth: ${c-64}`),e.#e[s+m[130+b]]=c)}}})}).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[g.ext*a[2]]=e.EXT_VL;break}case 2:{e.#M[g.ext*a[2]]=e.EXT_DX;break}default:e.#M[g.ext*a[2]]=e.EXT_NONE}}).add([73,0,0],(a,i)=>{let d=a[0],r="MU1000 System - ";a.subarray(1).forEach((s,o)=>{let c=d+o;c==8?console.debug(`${r}LCD contrast: ${s}.`):c==18?(e.#y[w.xg][1]=s?126:0,console.debug(`${r}default bank: ${s?"MU100 Native":"MU Basic"}.`),e.dispatchEvent("banklevel",{mode:"xg",data:+!!s}),e.forceVoiceRefresh()):c>=64&&c<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.#F=!!s,console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][c-64]()})}).add([73,10,0],(a,i)=>{let d=a[0],r=`MU1000 RS${e.#F?"":" (ignored)"}: `;if(d<16)switch(d){case 2:{let s=e.chRedir(0,i,!0);e.#F&&(e.dispatchEvent("portrange",4),e.dispatchEvent("portstart",s)),console.info(`${r}Show CH${s+1}~CH${s+64}`);break}case 3:{let s=e.chRedir(a[1]<<5,i,!0);e.#F&&(e.dispatchEvent("portrange",2),e.dispatchEvent("portstart",s)),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.#F){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.#F&&(e.dispatchEvent("portrange",1),e.dispatchEvent("portstart",s>>4),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((o,c)=>{let u=s+c;([()=>{e.setChActive(o,1),e.dispatchEvent("channelactive",o),T()&&console.debug(`${d}current part: CH${o+1}`)},()=>{o<5?(e.dispatchEvent("portrange",1<{o<16?(e.dispatchEvent("portstart",o),console.debug(`${r}start port: ${"ABCDEFGHIJKLMNOP"[o]}`)):(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-SG CH${d+1} `,s=Date.now();if(a[1]==0){let o="",c=0;a.subarray(2).forEach((u,f)=>{f%2==0?o+=ye[u]||u.toString().padStart("0"):c+=u*13}),s>=e.#ce&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${Ee(o)}`,amend:!0}),e.#ce=s+Math.ceil(c/2)+e.#ne,T()&&console.debug(`${r}vocals: ${o}`)}else console.warn(`Unknown PLG-SG data: ${a}`)}).add([98,0],(a,i,d)=>{e.dispatchEvent("mupromptex");let r=a[0],s=a.length-5,o=a.length-1;if(r!=s){console.info(`PLG-DX native dump size mismatch! Gave ${r} instead of ${a.length-5}.`);return}let c=N(a.subarray(4,o));if(c!=a[o]){console.info(`Bad PLG-DX checksum ${a[o]} - should be ${c}.`);return}a[0]=98,e.#N.run(a.subarray(0,o),i,d,{noAce:!0})}).add([98,96],(a,i,d,r)=>{let s=e.chRedir(a[0],i,!0),o=g.cc*s,c=a[1];a.subarray(2).forEach((u,f)=>{let b=c+f;if(!(b<10)){if(b==10)e.resetAce();else if(b<27){let E=b+131;r?.noAce||e.allocateAce(s,E),e.#e[o+m[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),o=a[a.length-1];if(s!=o){console.warn(`Yamaha DX7+ dump SysEx checksum mismatch! Expected ${s}, but got ${o}: +`,a);return}t.run(r.subarray(1))}).add([100,76],(a,i,d)=>{let r=a[0]>>4,s=a[0]&15,o=a[1];switch(r){case 2:{let c=e.chRedir(s,i,!0),u=g.cc*c;a.subarray(2).forEach((f,b)=>{let E=b+o;if(!(E<7)){if(E<23){let $=E+135;e.allocateAce(c,$),e.#e[u+m[$]]=f,e.dispatchEvent("cc",{part:c,cc:$,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,w.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*g.cc+m[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[g.cc*a[0]+m[64]]=0,e.#C.ano(a[0]),e.switchMode("xg"),e.setPortMode(e.getTrackPort(i),1,w.xg),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${a[0]+1}.`)}).add([76,112],async a=>{let i=a[0],d=g.cc*i,r=g.ext*i,s=g.cvn*i;e.#M[r]=e.EXT_DX,e.#$[i]=1;let o=e.#z.subarray(s,s+g.cvn);o.fill(32),a.subarray(1).forEach((c,u)=>{if(u<10)o[u]=Math.max(c,32);else if(!(u<40)){if(u<56){let f=u+102;e.#e[d+m[f]]=c,e.dispatchEvent("cc",{part:i,cc:f,data:c})}}}),e.#r[i]=i&127,e.#e[g.cc*i+m[0]]=35,e.#e[g.cc*i+m[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*g.dpn,r=i[0],s=i[1];i.subarray(2).forEach((o,c)=>{let u=c+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,o),e.#l[(d+A[f])*g.dnc+r]=o):T()&&console.debug(`XG-style drum param ${u} has no writes.`)})},p=function(a,i,d){e.dispatchEvent("mupromptex");let r=a*g.dpn,s=(i<<7)+d[0];d.subarray(1).forEach((o,c)=>{let u=c+s,f=u&127,b=u>>7,E=-1;b>1&&([()=>{E=26},()=>{},()=>{E=28},()=>{E=29},()=>{E=30},()=>{},()=>{},()=>{E=31}][b-2]||(()=>{console.debug(`Unknown GS-style drum param ${b} on set ${a+1}.`)}))(),E>-1?(T()&&console.debug(r,E,f,o),e.#l[(r+A[E])*g.dnc+f]=o):T()&&console.debug(`GS-style drum param ${b} has no writes.`)})};this.#N.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.#N.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 o=e.eprom.data;a.subarray(4).forEach((c,u)=>{let f=u>>3,b=u&7;if(b==7)for(let E=0;E<7;E++)o[s+7*f+E]+=(c>>6-E&1)<<7;else o[s+7*f+b]=c})}}).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((o,c)=>{let u=c>>3,f=c&7;if(f==7)for(let b=0;b<7;b++)s[r+7*u+b]+=(o>>6-b&1)<<7;else s[r+7*u+f]=o})}}).add([89,3],(a,i,d)=>{}),this.#N.add([39,48],(a,i,d)=>{}).add([43,0,0],(a,i,d)=>{e.dispatchEvent("mupromptex");let r=[0,0,0,0],s=(o,c)=>{r[c]=o};if(a.subarray(1).forEach((o,c)=>{let u=c+a[0];[s,s,s,s,()=>{this.#f=o*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},()=>o-64,()=>o||128,()=>o,()=>o,()=>{console.debug(`TG300 variation on cc${o}.`)}][u](o,u)}),a[0]<4){let o=0;r.forEach(c=>{o=o<<4,o+=c}),o-=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],o=g.cc*r,c=`TG300 CH${r+1} `;a.subarray(2).forEach((u,f)=>{f<5?([()=>{},()=>{e.#e[o+m[0]]=u,e.dispatchEvent("voice",{part:r})},()=>{e.#e[o+m[32]]=u,e.dispatchEvent("voice",{part:r})},()=>{e.#r[r]=u,e.dispatchEvent("voice",{part:r})},()=>{let b=e.chRedir(u,i,!0);e.#u[r]=b,r!=b&&(e.buildRchTree(),console.info(`${c}receives from CH${b+1}`))}][f+s]||(()=>{}))(u,f+s):f<21||(f<47?([()=>{e.#b[r]=+!u},()=>{},()=>{},()=>{e.#s[g.rpn*r+3]=u,e.#o[g.rpnt*r+2]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{},()=>{e.#e[o+m[7]]=u},!1,!1,()=>{e.#e[o+m[10]]=u||128},!1,!1,()=>{console.debug(`${c} AC1 at cc${u}`)},()=>{console.debug(`${c} AC2 at cc${u}`)},()=>{e.#e[o+m[128]]=u,e.allocateAce(r,128)},()=>{e.#e[o+m[93]]=u},()=>{e.#e[o+m[91]]=u},()=>{e.#e[o+m[94]]=u},()=>{e.#e[o+m[76]]=u},()=>{e.#e[o+m[77]]=u},()=>{e.#e[o+m[74]]=u},()=>{e.#e[o+m[71]]=u},()=>{e.#e[o+m[73]]=u},()=>{e.#e[o+m[75]]=u},()=>{e.#e[o+m[72]]=u},()=>{e.#e[o+m[78]]=u}][f+s-21]||(()=>{}))(u,f+s):f<95||([()=>{e.#e[o+m[65]]=u},()=>{e.#e[o+m[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.#w.fill(0),a.forEach(function(r,s){let o=Math.floor(s/16),c=s%16,u=(c*3+o)*7,f=7,b=0;for(u-=c*5,o==2&&(f=2);b>6-b&1,b++})}),this.#V.add([66,18,0,0,127],(a,i,d)=>{e.switchMode("sc",!0),e.setPortMode(e.getTrackPort(i),2,w.sc),e.#e[g.cc*9]=120,e.#e[g.cc*25]=120,e.#e[g.cc*41]=120,e.#e[g.cc*57]=120,e.#y[w.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,w.gs),e.#y[w.gs][1]=e.#c.gs,e.#e[g.cc*9]=120,e.#e[g.cc*25]=120,e.#e[g.cc*41]=120,e.#e[g.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=(o,c)=>{r[c]=o};if(a.subarray(1).forEach((o,c)=>{let u=c+a[0];[s,s,s,s,f=>{this.#f=f*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},f=>{},f=>{}][u](o,c)}),a[0]<4){let o=0;r.forEach(c=>{o=o<<4,o+=c}),o-=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((o,c)=>{s+=String.fromCharCode(Math.max(32,o))}),s=s.padEnd(16," "),console.debug(`GS patch name: ${s}`)}else r<48||(r<65?a.subarray(1).forEach((s,o)=>{let c=`GS ${r+o>55?"chorus":"reverb"} `;([()=>{console.info(`${c}type: ${ae[s]}`),e.setEffectType(0,40,s),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${c}predelay: ${s}ms`)},()=>{console.info(`${c}type: ${we[s]}`),e.setEffectType(1,40,16+s),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${c}to reverb: ${P(s)}`)},()=>{console.debug(`${c}to delay: ${P(s)}`)}][r+o-48]||(()=>{}))()}):r<80?console.debug(`Unknown GS patch address: ${r}`):r<91?a.subarray(1).forEach((s,o)=>{let c="GS delay ";([()=>{console.info(`${c}type: ${$e[s]}`),e.setEffectType(2,40,32+s),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${c}to reverb: ${P(s)}`)}][r+o-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,o)=>{([()=>{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]+o]||function(){console.warn(`Unknown GS EQ address: ${a[0]+o}`)})()})}).add([66,18,64,3],(a,i,d)=>{e.dispatchEvent("mupromptex");let r="GS EFX ",s=function(o,c){let u=ke(e.#S.subarray(10,12),c,o);u&&console.debug(`${r}${re(e.#S.subarray(10,12))} ${u}`)};a.subarray(1).forEach((o,c)=>{([()=>{e.setEffectTypeRaw(3,!1,32+o),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,o),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(o)}dB`)},()=>{console.debug(`${r}to chorus: ${P(o)}dB`)},()=>{console.debug(`${r}to delay: ${P(o)}dB`)},!1,()=>{console.debug(`${r}1 source: ${o}`),o&&o<96&&e.allocateAceAll(o)},()=>{console.debug(`${r}1 depth: ${o-64}`)},()=>{console.debug(`${r}2 source: ${o}`),o&&o<96&&e.allocateAceAll(o)},()=>{console.debug(`${r}2 depth: ${o-64}`)},()=>{console.debug(`${r}to EQ: ${o?"ON":"OFF"}`)}][a[0]+c]||function(u,f){console.warn(`Unknown GS EFX address: ${f}`)})(o,a[0]+c)})}).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.#h[r]?.length||(e.#h[r]=new Uint8Array(256));let s=e.#h[r];T()&&console.debug(`GS frame draw page ${r}.`);let o=a[1]&63;s.fill(0),a.subarray(2).forEach(function(u,f){let b=f+o,E=Math.floor(b/16),$=b%16,x=($*4+E)*5,C=5,H=0;for(x-=$*4,E==3&&(C=1);H>4-H&1,H++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let y=function(a,i,d){e.dispatchEvent("mupromptex");let r=a[0],s=g.cc*i,o=g.rpn*i,c=`GS CH${i+1} `;r<3?(a.subarray(1).forEach((u,f)=>{[()=>{e.#e[s+m[0]]=u},()=>{e.#r[i]=u},()=>{let b=0;u<16?b=e.chRedir(u,d,!0):b=g.ch,e.#u[i]=b,i!=b&&(e.buildRchTree(),console.info(`${c}receives from CH${b+1}`))}][r+f]()}),e.dispatchEvent("voice",{part:i})):r<19||(r<44?a.subarray(1).forEach((u,f)=>{([()=>{e.#b[i]=+!u},!1,()=>{e.setChType(i,u<<1,w.gs),console.debug(`${c}type: ${u?"drum ":"melodic"}${u||""}`)},()=>{e.#s[o+3]=u,e.#o[g.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},!1,()=>{e.#e[s+m[7]]=u},!1,!1,()=>{e.#e[s+m[10]]=u||128},!1,!1,()=>{console.debug(`${c}CC 1: cc${u}`)},()=>{console.debug(`${c}CC 2: cc${u}`)},()=>{e.#e[s+m[93]]=u},()=>{e.#e[s+m[91]]=u},!1,!1,()=>{e.#s[o+1]=u,e.#o[g.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{e.#s[o+2]=u,e.#o[g.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{e.#e[s+m[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,o)=>{[()=>{e.#e[g.cc*i+m[32]]=s},()=>{}][d+o]()}):d<32?console.warn(`Unknown GS misc address: ${d}`):d<35?a.subarray(1).forEach((s,o)=>{[()=>{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+o-32]()}):console.warn(`Unknown GS misc address: ${d}`)};this.#V.add([66,18,64,16],(a,i)=>{y(a,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(a,i)=>{y(a,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(a,i)=>{y(a,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(a,i)=>{y(a,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(a,i)=>{y(a,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(a,i)=>{y(a,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(a,i)=>{y(a,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(a,i)=>{y(a,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(a,i)=>{y(a,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(a,i)=>{y(a,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(a,i)=>{y(a,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(a,i)=>{y(a,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(a,i)=>{y(a,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(a,i)=>{y(a,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(a,i)=>{y(a,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(a,i)=>{y(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,w[d]);let r=a[a.length-1],s=a.subarray(0,a.length-1),o=N(s);o!=r&&(console.info(`X5D multi parameters checksum mismatch! Expected ${o}, got ${r}.`),console.debug(a));let c=(a[1]<<7)+a[0],u=(a[3]<<7)+a[2],f=e.chRedir(c&15,i,!0),b=g.cc*f;[()=>{u<1||(u<101?(e.setChType(f,e.CH_MELODIC,w.x5d),e.#r[f]=u-1,e.#e[b+m[0]]=e.#c.x5):u<229?(e.setChType(f,e.CH_MELODIC,w.x5d),e.#r[f]=u-101,e.#e[b+m[0]]=56):(e.setChType(f,e.CH_DRUMS,w.x5d),e.#r[f]=Le[u-229]||0,e.#e[b+m[0]]=62)),e.dispatchEvent("voice",{part:f})},()=>{e.#e[b+m[7]]=u},()=>{u<31&&(e.#e[b+m[10]]=Math.round((u-15)*4.2+64))},()=>{e.#e[b+m[93]]=K(u)},()=>{e.#e[b+m[91]]=K(u)},()=>{e.#s[f*g.rpn+3]=u>8191?u-16320:64+u,e.#o[g.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{e.#s[f*g.rpn+1]=u>8191?u-16320:64+u,e.#o[g.rpnt*f+1]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{u>0&&(e.#s[f*g.rpn]=u,e.#o[g.rpnt*f]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)}))},()=>{}][c>>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,w[d]);let r="",s=e.#c.x5,o=0,c=0,u="MSB PRG LSB NME";I(a,function(f,b){if(b<16400){let E=b%164;switch(!0){case E<10:{f>31&&(r+=String.fromCharCode(f));break}case E==10:break;case E==11:{u+=` +${s} ${o} ${c} ${r.trim().replace("Init Voice","")}`,o++,r="";break}}o>99&&(s=90,o=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,w[d]);let r="",s=90,o=0,c=0,u="MSB PRG LSB NME";I(a,function(f,b){if(b<13600){let E=b%136;switch(!0){case E<10:{f>31&&(r+=String.fromCharCode(f));break}case E==11:{u+=` +${s} ${o} ${c} ${r.trim().replace("Init Combi","")}`,o++,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,w[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,w[d]),I(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]!=w[d])if(e.#X.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${i}. Port ${String.fromCharCode(65+r)} mode "${R[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,w[d]),I(a,function(s,o,c,u){if(o<192){let f=e.chRedir(Math.floor(o/12),i,!0),b=f*g.cc;switch(o%12){case 0:{s<128?(e.setChType(f,e.CH_MELODIC,w.x5d),e.#e[b+m[0]]=e.#c.x5,e.#r[f]=s):(e.setChType(f,e.CH_DRUMS,w.x5d),e.#e[b+m[0]]=62,e.#r[f]=Le[s-128]),s>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{e.#e[b+m[7]]=s;break}case 2:{e.#s[f*g.rpn+3]=s>127?s-192:64+s,e.#o[g.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)});break}case 3:{e.#s[f*g.rpn+1]=s>127?s-192:64+s,e.#o[g.rpnt*f+1]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)});break}case 4:{s<31&&(e.#e[b+m[10]]=Math.round((s-15)*4.2+64));break}case 5:{let E=s>>4,$=s&15;e.#e[b+m[91]]=K($),e.#e[b+m[93]]=K(E);break}case 10:break;case 11:{let E=e.chRedir(s&15,i,!0),$=s>>4;e.#u[f]=s,(E!=f||$)&&(console.info(`X5D Part CH${f+1} receives from CH${E+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(o-192,i,!0)}})}),this.#V.add([22,18,127],(a,i,d)=>{e.switchMode("mt32",!0),e.setPortMode(e.getTrackPort(i),1,w.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((o,c)=>{let u=c+s;e.#A[u+(r-1)*16]=o,([!1,()=>{let f=e.#A[r-1<<4];if(f<3){if(e.#$[r]=1,f==2)for(let b=0;b{e.#s[r*g.rpn+3]=o+40,e.#o[g.rpnt*r+2]=1},()=>{e.#s[r*g.rpn+1]=o+14,e.#o[g.rpnt*r+1]=1},()=>{e.#s[r*g.rpn]=o,e.#o[g.rpnt*r]=1},!1,()=>{e.#e[g.cc*r+m[91]]=o?127:0},!1,()=>{e.#e[g.cc*r+m[7]]=o},()=>{e.#e[g.cc*r+m[10]]=Math.ceil(o*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((o,c)=>{let u=c+s,f=(u>>2)+24,b=u&3,E=r*g.dpn;if(T()&&console.debug(`MT-32 temp drum note ${f} param ${b}: ${o}`),f<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${f}`);return}[()=>{},()=>{e.#l[(E+A[26])*g.dnc+f]=Math.round(o*1.27)},()=>{e.#l[(E+A[26])*g.dnc+f]=o*9+1&127},()=>{e.#l[(E+A[26])*g.dnc+f]=o?127:0}][b]()})}).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.#$[r]=1),a.subarray(2).forEach((o,c)=>{let u=c+s;u<14&&(e.#L[(r-1)*g.cmt+u]=o)}),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((o,c)=>{let u=c+s,f=(u>>2)+24,b=u&3,E=r*g.dpn;if(T()&&console.debug(`MT-32 dev drum note ${f} param ${b}: ${o}`),f<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${f}`);return}[()=>{},()=>{e.#l[(E+A[26])*g.dnc+f]=Math.round(o*1.27)},()=>{e.#l[(E+A[26])*g.dnc+f]=o*9+1&127},()=>{e.#l[(E+A[26])*g.dnc+f]=o?127:0}][b]()})}else{let s=a[1];a.subarray(2).forEach((o,c)=>{let u=c+s;e.#A[u]=o;let f=e.chRedir(1+(u>>4),i,!0),b=u&15;([!1,()=>{let E=e.#A[f-1<<4];if(E<3)if(e.#$[f]=1,E==2)for(let $=0;${e.#s[f*g.rpn+3]=o+40,e.#o[g.rpnt*f+2]=1},()=>{e.#s[f*g.rpn+1]=o+14,e.#o[g.rpnt*f+1]=1},()=>{e.#s[f*g.rpn]=o,e.#o[g.rpnt*f]=1},!1,()=>{e.#e[g.cc*f+m[91]]=o?127:0},!1,()=>{e.#e[g.cc*f+m[7]]=o},()=>{e.#e[g.cc*f+m[10]]=Math.ceil(o*9.05)}][b]||(()=>{}))()})}}).add([22,18,4],(a,i,d)=>{e.switchMode("mt32");let r=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((o,c)=>{let u=c+r,f=e.chRedir(Math.floor(u/246+1),i,!0),b=u%246;b<14&&(e.#L[(f-1)*g.cmt+b]=o),b<10&&(e.#$[f]=1),s.indexOf(f)<0&&s.push(f)}),s.forEach(o=>{e.dispatchEvent("voice",{part:o})})}).add([22,18,5],(a,i,d)=>{e.switchMode("mt32");let r=(a[0]<<7)+a[1];a.subarray(2).forEach((s,o)=>{let c=r+o,u=Math.floor(c/8),f=c&7,b=u*8;e.#q[c]=s,([!1,()=>{let E=e.#q[b];if(E<3){let $="";if(E==2){let C=g.cmt*u;$=`MT-m:${s.toString().padStart(3,"0")}`}else $=e.baseBank.get(0,s+(E<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:u});let x=`MSB LSB PRG NME +000 127 ${u} ${$}`;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,o=!1;if(a.subarray(2).forEach((c,u)=>{let f=r+u;f{e.switchMode("mt32");let r=a[1],s=!1,o=function(c,u){e.#u[u-12]=c,s=!0};a.subarray(2).forEach((c,u)=>{let f=u+r;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,o,o,o,o,o,o,o,o,o,()=>{e.#f=c,e.dispatchEvent("mastervolume",e.#f)}][f]||(()=>{}))(c,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(o=>{o>31?s+=String.fromCharCode(o):s+=" "}),e.#Q=s.padStart(20," "),e.#Z=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,w.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,w[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,w.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=(o,c)=>{r[c]=o};if(a.subarray(1).forEach((o,c)=>{[s,s,s,s,()=>{e.#f=o*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][d+c]()}),a[0]<4){let o=0;r.forEach(c=>{o=o<<4,o+=c}),o-=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*g.cc,s=a[1],o=`NS5R CH${d+1} `;a.subarray(2).forEach((c,u)=>{let f=s+u;f<3?([()=>{e.#e[r+m[0]]=c||D.bank0},()=>{e.#e[r+m[32]]=c},()=>{e.#r[d]=c}][f](),e.dispatchEvent("voice",{part:d})):f<8||(f<14?[()=>{let b=e.chRedir(c,i,!0);e.#u[d]=b,d!=b&&(e.buildRchTree(),console.info(`${o}receives from CH${b+1}`))},()=>{e.#b[d]=+!c},()=>{e.setChType(d,c,w.ns5r),console.debug(`${o}type: ${F[c]}`)},()=>{e.#s[g.rpn*d+3]=c,e.#o[g.rpnt*d+2]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)})},()=>{},()=>{}][f-8]():f<16||(f<33?[()=>{e.#e[r+m[7]]=c},()=>{e.#e[r+m[11]]=c},()=>{},()=>{},()=>{e.#e[r+m[10]]=c||128},()=>{},()=>{},()=>{e.#e[r+m[93]]=c},()=>{e.#e[r+m[91]]=c},()=>{e.#e[r+m[76]]=c},()=>{e.#e[r+m[77]]=c},()=>{e.#e[r+m[78]]=c},()=>{e.#e[r+m[74]]=c},()=>{e.#e[r+m[71]]=c},()=>{e.#e[r+m[73]]=c},()=>{e.#e[r+m[75]]=c},()=>{e.#e[r+m[72]]=c}][f-16]():f<112||f<114&&[()=>{e.#e[r+m[5]]=c},()=>{e.#e[r+m[65]]=c}][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.#w.fill(0);let s=a.subarray(1),o=4;s.forEach(function(c,u){let f=u+r,b=f>>4,E=f&15;if(f<80){let $=b>3,x=0,C=b0;)e.#w[E*32+b*7+(C-x)]=$&1,$=$>>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="";I(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),o=N(s);o!=r&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${o}, got ${r}.`),console.debug(a));let c=e.getTrackPort(i);if(e.#n[c]&&e.#n[c]!=w.ns5r)if(e.#X.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${i}. Port ${String.fromCharCode(65+c)} mode "${R[e.#n[c]]}" mismatch, should be "ns5r".`);return}else console.info(`Track ${i} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+c)}.`);e.setPortMode(c,2,w.ns5r),I(s,function(u,f){switch(!0){case f<2944:{let b=e.chRedir(Math.floor(f/92),i,!0),E=b*g.cc;switch(f%92){case 0:{e.#e[E+m[0]]=u,e.dispatchEvent("voice",{part:b});break}case 1:{e.#e[E+m[32]]=u,!u&&!e.#e[E+m[0]]&&(e.#e[E+m[0]]=D.bank0),e.dispatchEvent("voice",{part:b});break}case 2:{e.#r[b]=u,u>0&&e.setChActive(b,1),e.dispatchEvent("voice",{part:b});break}case 3:{let $=e.chRedir(u,i,!0);e.#u[b]=$,b!=$&&(console.info(`NS5R CH${b+1} receives from CH${$+1}.`),e.buildRchTree());break}case 7:{e.#i[b]=u,e.dispatchEvent("voice",{part:b});break}case 8:{e.#s[b*g.rpn+3]=u<40||u>88?u+(u>63?-192:64):u,e.#o[g.rpnt*b+2]=1,e.dispatchEvent("pitch",{part:b,pitch:e.getPitchShift(b)});break}case 9:case 10:{e.#e[E+m[7]]=u;break}case 11:{e.#e[E+m[11]]=u;break}case 14:{e.#e[E+m[10]]=u||128;break}case 19:{e.#e[E+m[93]]=u;break}case 20:{e.#e[E+m[91]]=u;break}case 84:{e.#e[E+m[65]]=u;break}case 85:{e.#e[E+m[5]]=u;break}}break}case f<3096:break;case f<3134:{let b=f-3096;b<8?(u>31&&(d+=String.fromCharCode(u)),b==7&&(e.aiEfxName=d)):b<10&&(e.setEffectType(b-8,44,u),e.dispatchEvent(`efx${["reverb","chorus"][b-8]}`,e.getEffectType(b-8)));break}case f<8566:break}})}).add([66,54],(a,i)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let d="",r=80,s=0,o=0,c="MSB PRG LSB NME";I(a,function(u,f){let b=f%158;switch(!0){case b<10:{u>31&&(d+=String.fromCharCode(u));break}case b==10:break;case b==11:{r=u&127;break}case b==12:{o=u&127;break}case b==13:{c+=` +${r} ${s} ${o} ${d.trim().replace("Init Voice","")}`,s++,d="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(c),T()&&console.debug(c),e.forceVoiceRefresh()}).add([66,55],(a,i)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let d="",r=88,s=0,o=0,c="MSB PRG LSB NME";I(a,function(u,f){let b=f%126;switch(!0){case b<10:{u>31&&(d+=String.fromCharCode(u));break}case b==11:break;case b==12:break;case b==13:{c+=` +${r} ${s} ${o} ${d.trim().replace("Init Combi","")}`,s++,d="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(c),T()&&console.debug(c),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),o=N(s);o!=r&&(console.info(`NS5R screen dump checksum mismatch! Expected ${o}, got ${r}.`),console.debug(a));let c=new Uint8Array(5760);I(a,(u,f,b)=>{if(f<720)for(let E=0;E<8;E++)c[f*8+E]=u>>7-E&1}),e.dispatchEvent("screen",{type:"ns5r",data:c})}).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,w.k11),e.#v=!1,e.#y[w.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=g.cc*r,o=g.rpn*r,c=(a[3]<<4)+a[4],u=`K11 CH${r+1} `;([()=>{c<128?(e.setChType(r,e.CH_MELODIC,w.k11),e.#e[s+m[0]]=0,e.#r[r]=c):(e.setChType(r,e.CH_DRUMS,w.k11),e.#r[r]=c-128),e.dispatchEvent("voice",{part:r})},()=>{let f=e.chRedir(c,i,!0);e.#u[r]=f,r!=f&&(e.buildRchTree(),console.info(`${u}receives from CH${f+1}`))},()=>{e.#e[s+m[7]]=c},()=>{uupThis.setChActive(r,c)},()=>{e.#e[s+m[10]]=c},()=>{e.#s[o+3]=c+40,e.#o[g.rpnt*r+2]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{e.#s[o+1]=c>>1,e.#s[o+2]=c&1,e.#o[g.rpnt*r+1]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{e.#e[s+m[91]]=c?127:0},()=>{},()=>{e.#e[s+m[74]]=c},()=>{e.#e[s+m[73]]=c},()=>{e.#e[s+m[72]]=c}][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),o=s*g.cc;[()=>{r<128?(e.setChType(s,e.CH_MELODIC,w.k11),e.#e[o+m[0]]=0,e.#e[o+m[32]]=0,e.#r[s]=r):r<160?(e.setChType(s,e.CH_MELODIC,w.k11),e.#e[o+m[0]]=0,e.#e[o+m[32]]=7,e.#r[s]=r-100):(e.setChType(s,e.CH_DRUMS,w.k11),e.#e[o+m[0]]=122,e.#e[o+m[32]]=0,e.#r[s]=r-160),e.dispatchEvent("voice",{part:s})},()=>{let c=e.chRedir(r,i,!0);e.#u[s]=c,s!=c&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${c+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),o=s*g.cc,c=s*g.rpn,u=`GMLX CH${s+1} `;[()=>{e.setChActive(s,r)},()=>{e.#e[o+m[7]]=r},()=>{e.#e[o+m[10]]=r},()=>{e.#e[o+m[91]]=r?127:0},()=>{e.#s[c+3]=r+40,e.#o[g.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{e.#s[c+1]=r,e.#o[g.rpnt*s+1]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{e.#s[c]=r,e.#o[g.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.#f=r*129/16383*100,e.dispatchEvent("mastervolume",e.#f);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,w.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 o=e.chRedir(r,i,!0);e.#u[s]=o,s!=o&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${o+1}`))}else a[1]==19&&(e.#e[g.cc*s+m[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.#N.add([127,0],(a,i,d)=>{e.switchMode("motif");let r=new Uint8Array([127,1,...a]);e.#N.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((o,c)=>{([()=>{e.#f=o*12900/16383,e.dispatchEvent("mastervolume",e.#f)}][s+c]||(()=>{console.info(`Unrecognized ${r}ID: ${s+c}`)}))()})}).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((o,c)=>{([()=>{e.setEffectTypeRaw(0,!1,o&15|112)},()=>{e.setEffectTypeRaw(0,!0,o)}][s+c]||(()=>{}))()}),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((o,c)=>{([()=>{e.setEffectTypeRaw(1,!1,o&15|112)},()=>{e.setEffectTypeRaw(1,!0,o)}][s+c]||(()=>{}))()}),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((o,c)=>{([()=>{e.setEffectTypeRaw(3,!1,o&15|112)},()=>{e.setEffectTypeRaw(3,!0,o)}][s+c]||(()=>{}))()}),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((o,c)=>{([()=>{e.setEffectTypeRaw(4,!1,o&15|112)},()=>{e.setEffectTypeRaw(4,!0,o)}][s+c]||(()=>{}))()}),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((o,c)=>{([()=>{e.setEffectTypeRaw(2,!1,o&15|112)},()=>{e.setEffectTypeRaw(2,!0,o)}][s+c]||(()=>{}))()}),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.#X.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${i}. Port ${String.fromCharCode(65+r)} mode "${R[e.#n[r]]}" mismatch, should be "${R[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),o=g.cc*s,c=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,b)=>{([()=>{e.#e[o+m[0]]=f,e.dispatchEvent("voice",{part:s})},()=>{f&&e.setChActive(s,1),e.#e[o+m[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.#u[s]=E,s!=E&&(e.buildRchTree(),console.info(`${u}receives from CH${E+1}`))},()=>{e.#b[s]=f?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{f!=100&&e.setChActive(s,1),e.#e[o+m[7]]=f},()=>{f!=64&&e.setChActive(s,1),e.#e[o+m[10]]=f},!1,!1,!1,()=>{e.#e[o+m[91]]=f},()=>{f&&e.setChActive(s,1),e.#e[o+m[93]]=f},()=>{f&&e.setChActive(s,1),e.#e[o+m[94]]=f},()=>{f!=127&&e.setChActive(s,1),e.#e[o+m[128]]=f,e.allocateAce(s,128)},()=>{},()=>{f!=64&&e.setChActive(s,1),e.#e[o+m[74]]=f},()=>{f!=64&&e.setChActive(s,1),e.#e[o+m[71]]=f},!1,()=>{e.#e[o+m[65]]=f},()=>{e.#e[o+m[5]]=f},()=>{}][c+b]||(()=>{}))()})}).add([127,1,54,16],(a,i,d)=>{e.switchMode("s90es");let r=a[0];a.subarray(1).forEach((s,o)=>{let u=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let f=s-64},()=>{let f=X[s]},()=>{let f=s/10},()=>{let f=s}][r+o&3]||(()=>{}))()})}),this.#V.add([0,72,18,0,0,0,0],(a,i,d)=>{e.switchMode("sd",!0),e.setPortMode(e.getTrackPort(i),2,w.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 o=a[0]>>1,c=a[1];switch(o){case 1:{a.subarray(2).forEach((u,f,b)=>{let E=f+c;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 b=f+c;switch(b){case 0:{u&&(e.setEffectType(0,55+u,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${b} - ${u}`));break}}});break}case 3:case 4:case 5:{let u=o-1;a.subarray(2).forEach((f,b)=>{let E=b+c;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((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)}break}case 1:{let o=e.chRedir(s,i,!0),c=a[1],u=o*g.cc;a.subarray(2).forEach((f,b)=>{let E=c+b;E<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[u+m[0]]=f,f){case 104:case 105:case 106:case 107:case 120:{e.#i[o]||e.setChType(o,e.CH_DRUMS);break}default:e.#i[o]&&e.setChType(o,e.CH_MELODIC)}e.dispatchEvent("voice",{part:o})},()=>{e.#e[u+m[32]]=f,e.dispatchEvent("voice",{part:o})},()=>{e.#r[o]=f,e.dispatchEvent("voice",{part:o})},()=>{e.#e[u+m[7]]=f},()=>{e.#e[u+m[10]]=f},()=>{},()=>{},()=>{f<2&&(e.#b[o]=f)},()=>{f<2&&(e.#e[u+m[68]]=f?127:0)},()=>{},()=>{f<2&&(e.#e[u+m[65]]=f?127:0)},()=>{e.#e[u+m[5]]=f&15<<4|e.#e[u+m[5]]&15},()=>{e.#e[u+m[5]]=f&15|(e.#e[u+m[5]]&240)>>4},()=>{e.#e[u+m[74]]=f},()=>{e.#e[u+m[71]]=f},()=>{e.#e[u+m[73]]=f},()=>{e.#e[u+m[72]]=f},0,0,0,0,0,0,0,()=>{e.#e[u+m[128]]=f,e.allocateAce(128)},()=>{e.#e[u+m[93]]=f},()=>{e.#e[u+m[91]]=f},0,0,()=>{e.#e[u+m[75]]=f},()=>{e.#e[u+m[76]]=f},()=>{e.#e[u+m[77]]=f},()=>{e.#e[u+m[78]]=f}][E]||(()=>{}))():E<63||(E<64?(e.#i[o]?e.#e[u+m[0]]=104|f:e.#e[u+m[0]]=96|f,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(s,i,!0),c=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)}}),e.#K.add([0,1,73,78],(a,i,d)=>{e.switchMode("krs"),e.setPortMode(e.getTrackPort(i),1,w.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]!=w.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,w.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,$=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[$+b[0]]=63,e.#e[$+b[32]]=o):o<20?(e.#e[$+b[0]]=121,e.#e[$+b[32]]=o-10):o<24&&(e.#e[$+b[0]]=[120,0,56,62][o-20],e.#e[$+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}`)},!1,!1,()=>{e.#e[$+b[7]]=o},!1,()=>{},()=>{},!1,!1,!1,!1,!1,()=>{e.#e[$+b[10]]=o||128}][E]||(()=>{}))():E<36||([()=>{e.#e[$+b[74]]=(o+128&255)-64},()=>{e.#e[$+b[71]]=(o+128&255)-64},!1,!1,()=>{e.#e[$+b[73]]=(o+128&255)-64},()=>{e.#e[$+b[75]]=(o+128&255)-64},!1,()=>{e.#e[$+b[72]]=(o+128&255)-64}][E]||(()=>{}))()}}),n=n.trimRight(),e.dispatchEvent("metacommit",{type:"EORTitle",data:n})})}};var oe=Je(Ue(),1);var Ne=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}},ne=class extends Ne{constructor(e,t,c){super(!0,e,t,c)}},Be=class extends Ne{constructor(e,t){super(!1,e,e,t)}},ce=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 ht=0xffffffffffff,Xe=function(e){let t=new ce,c=this,l=e.timeDivision,h=120,p=new ce,g=0,v=0;p.push(new ne(0,ht,[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 ne(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 Be(g/h/l*60+v,y))})}),t.fresh(),self.midiEvents=t,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),t};oe.default.customInterpreter=xe;var S=function(e,t,c){e.addEventListener(c,l=>{t.dispatchEvent(c,l.data)})},He=class extends W{device;#t;#m={};#T=[];#d="";#w=[];#k=[];#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=Xe(oe.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,$)=>{g.#i[$]=E}),g.device.newStrength(),t.forEach(function(E){let $=E.data,x=g.device.runJson($);switch(x?.reply){case"meta":{v.push(x);break}}x?.reply&&delete x.reply});g.#k.length>0;){let E=g.#k.shift(),$=E.part<<7|E.note;E.state?(l.add($),h[$]=E.velo):l.has($)&&(p.push({part:E.part,note:E.note,velo:h[$],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,$,x){x[$]=Math.max(g.#i[$],E);let R=x[$]-g.#f[$],B=b.length*$;if(R>=0){let Z=4*.25**(r[B+b[73]]/64);g.#f[$]+=Math.ceil(R-R*g.smoothingAtk**Z)}else{let Z=4*.25**(r[B+b[72]]/64);g.#f[$]+=Math.floor(R-R*g.smoothingDcy**Z)}});let f=0;return a.forEach(function(E,$){E&&(i[$]=g.device.getVel($),o[$]=g.device.getExt($),f+=i[$].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.#w[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.#k.push(h)}),l.#w[3]=function(h,p){l.#d?.length<1&&(l.#d=p,l.dispatchEvent("title",l.#d))},l.#w[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.#w[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{de&&(le[q]=!le[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 Ve=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),de=!1}constructor(...e){de=!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 M=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)})},Et=new Array(128).fill(0);Et.forEach((e,t,c)=>{c[t]=Math.floor(24*t/12.7)/10});var wt=new Array(128).fill(0);wt.forEach((e,t,c)=>{c[t]=Math.abs(Math.round(48*(t-64)/12.7)/10)});var Ke=new Array(11).fill(null);Ke.forEach((e,t,c)=>{c[t]=`${Math.round(t*12/.0128)/100}%`});var $t=new Array(128).fill(null);$t.forEach((e,t,c)=>{c[t]=`${Math.round(t/1.27)/100}`});var Fe=function(e,t){e.innerText=t,e.rNew=!0;let c=e.measureText(t);e.rWidth=c.width},ga=class extends He{#t=128;#m=!1;#T="";#d;#w=0;#k=0;#f=0;#i=0;#e=m.invalidCh;#b=1;#r=0;#h=0;#g=new Uint8Array(1280);#u=new Uint8Array(1280);#x=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=[];#v={};#$={};eventViewMode=0;#z=[];#O="comb";glyphs=new Ve;#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=pt.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+Ge[t%12])*g/75*1.0044642857142856),i=Math.round((Math.floor(t/12)*7+Ge[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(fe[2]);break}default:e.setLineDash(fe[1])}else e.setLineDash(fe[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.#w>4e3&&(t.#k=0,t.#f=142-t.#v.view.clientHeight,(t.#d?.clientWidth||0)>840&&(t.#k=840-t.#d.clientWidth),t.#v.view.style.transform=`translateX(${t.#k}px) translateY(${t.#f}px)`,e&&(t.#w=0))}#y(){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-$;n.ccVis.fillRect(f*6,x,4,$)}}}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,$=f*-25%(n.metre.rWidth+y+48)+48;$>0&&($=0),n.metre.fillText(n.metre.innerText,$,3+e.#P.font4[0]),Math.abs($)>E&&n.metre.fillText(n.metre.innerText,$+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,bt),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 $=E*3,x=(y-64)/5.82;x>=0?n.extVis.fillRect($,12-x,2,x+1):n.extVis.fillRect($,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.#$.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.#x.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.#x[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.#x[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(_e[e]){let c=_e[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),M(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),M(t.#R.root,[t.#R.left,t.#R.right]),M(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"})]),M(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];Ke.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",M(a.notes,[a.cxt.canvas]),M(a.keys,[a.notes]),M(a.voice,[a.metre.canvas]),M(a.major,[a.number,a.voice,a.ccVis.canvas]),M(a.minor,[a.type,a.std,a.msb,a.prg,a.lsb,a.extVis.canvas]),M(a.root,[a.major,a.minor,a.keys]),M(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.#v.root=k("div",["sect-meta"]),t.#v.view=k("div",["boundary"]),l.appendChild(t.#v.root),M(t.#v.root,[t.#v.view]),t.#$.root=k("div",["sect-pix","boundary"],{l:1529,t:950,w:379,h:127}),t.#$.cxt=k("canvas",["field"]).getContext("2d"),t.#$.fps=k("span",["field","field-key"],{l:0,w:"100%",h:1}),t.#$.cxt.canvas.width=379,t.#$.cxt.canvas.height=127,M(t.#$.root,[t.#$.cxt.canvas]),l.appendChild(t.#$.root),t.addEventListener("mode",h=>{t.#a.mode.innerText=`${mt[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];Fe(g.metre,t.getMapped(p.name)),g.type.innerText=ut[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":{M(t.#d,[k("span",["meta-slice"],{i:p.data})]);break}default:t.#d.childNodes[0].data+=p.data}else if(p.data?.length&&yt.indexOf(p.type)==-1){let g=k("div",["meta-line"]),v=k("span",["field","field-key","meta-type"],{i:gt[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"]),M(t.#d,[k("span",["meta-slice"],{i:p.data})]);break}default:t.#d=k("span",["field","meta-data"],{i:p.data})}for(t.#v.view.appendChild(g),M(g,[v,t.#d]);t.#v.view.children.length>t.#t;)t.#v.view.children[0].remove()}t.#m=p.amend||!1,t.#T=p.type||"",t.#F()}),t.#v.view.style.transform="translateX(0px) translateY(140px)",t.dispatchEvent("mode","?"),t.dispatchEvent("mastervolume",100),t.dispatchEvent("tempo",120),t.dispatchEvent("tsig",[4,4]),t.dispatchEvent("title",""),t.dispatchEvent("efxreverb",t.device.getEffectType(0)),t.dispatchEvent("efxchorus",t.device.getEffectType(1)),t.dispatchEvent("efxdelay",t.device.getEffectType(2)),t.dispatchEvent("efxinsert0",t.device.getEffectType(3)),t.#G(!0)}detach(e){let t=this;self.removeEventListener("resize",t.#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 Ie,.1,.75);let c=this;c.#c=c.#y.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.#v.view.children;for(let h=l.length-1;h>=0;h--)l[h].remove();c.#v.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"]),Fe(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{ga as Cambiare}; +%o`,a)}}),e.#K.add([0,1,73,78],(a,i,d)=>{e.switchMode("krs"),e.setPortMode(e.getTrackPort(i),1,w.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]!=w.krs)if(e.#X.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+r)} mode "${R[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,w.krs);let s="KROSS 2 BMT1 ",o="";I(a,(c,u)=>{if(u<24)o+=String.fromCharCode(Math.max(32,c));else if(!(u<1276)){let f=u-1276,b=e.chRedir(Math.floor(f/44),i,!0),E=f%44,$=g.cc*b;E<15?([()=>{c&&e.setChActive(b,1),e.#r[b]=c,e.dispatchEvent("voice",{part:b})},()=>{c&&e.setChActive(b,1),c<10?(e.#e[$+m[0]]=63,e.#e[$+m[32]]=c):c<20?(e.#e[$+m[0]]=121,e.#e[$+m[32]]=c-10):c<24&&(e.#e[$+m[0]]=[120,0,56,62][c-20],e.#e[$+m[32]]=0),e.dispatchEvent("voice",{part:b})},()=>{let x=e.chRedir(c&15,i,!0);e.#u[b]=x,console.info(`${s}CH${b+1} receives from CH${x+1}`)},!1,!1,()=>{e.#e[$+m[7]]=c},!1,()=>{},()=>{},!1,!1,!1,!1,!1,()=>{e.#e[$+m[10]]=c||128}][E]||(()=>{}))():E<36||([()=>{e.#e[$+m[74]]=(c+128&255)-64},()=>{e.#e[$+m[71]]=(c+128&255)-64},!1,!1,()=>{e.#e[$+m[73]]=(c+128&255)-64},()=>{e.#e[$+m[75]]=(c+128&255)-64},!1,()=>{e.#e[$+m[72]]=(c+128&255)-64}][E]||(()=>{}))()}}),o=o.trimRight(),e.dispatchEvent("metacommit",{type:"EORTitle",data:o})})}};var oe=je(Ue(),1);var Be=class{#t=!1;constructor(e,t,n,l){this.#t=e,this.start=t,this.end=n,this.data=l}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#t}},ne=class extends Be{constructor(e,t,n){super(!0,e,t,n)}},Ne=class extends Be{constructor(e,t){super(!1,e,e,t)}},ce=class extends Array{#t=-1;constructor(){super(...arguments)}resetIndex(e){this.#t=-1}fresh(){this.sort(function(e,t){return e.start==t.start?0:(+(e.start>t.start)<<1)-1}),this.forEach(function(e,t){e.index=t})}step(e,t=!1){let n=[];if(t)for(let l=0;le);l++){if(this[l].endh.#t&&(n.push(p),h.#t=p.index)})}return n}getRange(e,t){e>t&&([e,t]=[t,e]);let n=[],l=-1,h=Math.ceil(Math.sqrt(this.length)),p=!0;for(let y=0;y=e&&(l=y):l=l<0?y:l;for(;p;)this[l]?.end=e&&n.push(this[l]):p=!1,l++;return n}};var ht=0xffffffffffff,He=function(e){let t=new ce,n=this,l=e.timeDivision,h=120,p=new ce,y=0,v=0;p.push(new ne(0,ht,[120,0])),e.track.forEach(function(r){y=0,r.event.forEach(function(s){y+=s.deltaTime,s.type==255&&s?.metaType==81&&(h=6e7/s.data,p[p.length-1]&&p.push(new ne(y,0xffffffffffff,[h,0])))})}),p.fresh(),p.forEach(function(r,s,o){s>0&&(o[s-1].end=r.start)});let a=120;p.forEach(function(r,s,o){s>0&&(r.end==r.start?o.splice(o.indexOf(r),1):a==r.data[0]&&(o[s-1].end=r.end,o.splice(o.indexOf(r),1)),a=r.data[0])});let i=0,d=120;return p.forEach(function(r){let s=r.start,o=s/d/l*60+i;d=r.data[0],i=o-s/d/l*60,r.data[1]=i}),console.debug("All tempo changes: ",p),h=120,y=0,v=0,e.track.forEach(function(r,s){y=0,v=0;let o=s+1;r.event.forEach(function(c,u){y+=c.deltaTime;let f=p.step(y,!0)[0];f&&(h=f.data[0],v=f.data[1]);let b={type:c.type,data:c.data,track:o,part:0};c.type>14?b.meta=c.metaType:b.part=c.channel,t.push(new Ne(y/h/l*60+v,b))})}),t.fresh(),self.midiEvents=t,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),t};oe.default.customInterpreter=xe;var S=function(e,t,n){e.addEventListener(n,l=>{t.dispatchEvent(n,l.data)})},Xe=class extends W{device;#t;#m={};#T=[];#h="";#w=[];#k=[];#u=new Uint8ClampedArray(128);#i=new Uint8ClampedArray(128);#e=.5;#d=120;#r=4;#p=4;#b=0;#g=0;smoothingAtk=0;smoothingDcy=0;reset(){let e=this;e.dispatchEvent("reset"),e.#t?.resetIndex(),e.device.init(),e.#h="",e.#e=.5,e.#d=120,e.#r=4,e.#p=4,e.#b=0,e.#g=0,e.dispatchEvent("tempo",e.#d),e.dispatchEvent("title",e.#h)}init(){this.reset(),this.#t=void 0}async loadFile(e){this.#t=He(oe.default.parse(new Uint8Array(await e.arrayBuffer())))}async loadMap(e,t){let n=this,l=0,h=0,p=0,y,v;e.split(` +`).forEach((a,i)=>{if(!a)return;let d=a.split(" ");if(i){if(!p)return;let r="",s="";d.forEach((o,c)=>{switch(c){case y:{r=o;break}case v:{s=o;break}}}),!n.#m[r]||t?(n.#m[r]=s,l++):self.debugMode&&console.debug(`Voice "${s}" (${r}) seems to be in conflict with (${n.#m[r]}).`),h++}else d.forEach((r,s)=>{switch(r){case"ID":{y=s,p++;break}case"Name":{v=s,p++;break}default:console.debug(`Unknown map field: ${r}`)}})}),console.debug(`Voice names: ${h} total, ${l} loaded.`),n?.device.forceVoiceRefresh()}async loadEfx(e,t){let n=this,l=0,h=0,p,y,v;e.split(` +`).forEach((a,i)=>{if(a)if(i){let d=0,r;a.split(" ").forEach((s,o)=>{switch(o){case p:{d|=parseInt(s,16)<<8;break}case y:{d|=parseInt(s,16);break}case v:{r=s;break}}}),!n.#T[d]||t?(n.#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":{y=r;break}case"Name":{v=r;break}default:console.debug(`Unknown EFX field: ${d}`)}})}),console.debug(`EFX: ${h} total, ${l} loaded.`),n.dispatchEvent("efxreverb",n.device.getEffectType(0)),n.dispatchEvent("efxchorus",n.device.getEffectType(1)),n.dispatchEvent("efxdelay",n.device.getEffectType(2)),n.dispatchEvent("efxinsert0",n.device.getEffectType(3)),n.dispatchEvent("efxinsert1",n.device.getEffectType(4)),n.dispatchEvent("efxinsert2",n.device.getEffectType(5)),n.dispatchEvent("efxinsert3",n.device.getEffectType(6))}switchMode(e,t=!1){this.device.switchMode(e,t)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}getMapped(e){return this.#m[e]||e}getEfx([e,t]){let n=e<<8|t;return this.#T[n]||`0x${n.toString(16).padStart(4,"0")}`}getVoxBm(e){if(!e)throw new Error("Voice object must be valid");let t=this;if(!t.voxBm)throw new Error("Voice bitmap repository isn't yet initialized");let n=t.voxBm.getBm(e.name);if(!n)switch(e.mode){case"xg":{switch(e.sid[0]){case 0:case 80:case 81:case 83:case 84:case 96:case 97:case 99:case 100:{n=t.voxBm.getBm(t.getVoice(D.bank0,e.sid[1],D.bank0,e.mode).name);break}}break}case"g2":case"sd":{switch(e.sid[0]){case 96:case 97:case 98:case 99:{n=t.voxBm.getBm(t.getVoice(D.bank0,e.sid[1],D.bank0,e.mode).name);break}case 104:case 105:case 106:case 107:{n=t.voxBm.getBm(t.getVoice(120,e.sid[1],D.bank0,e.mode).name);break}}break}case"gs":case"sc":case"k11":case"sg":case"gm":{switch(e.sid[0]){case 120:break;case 122:case 127:{n=t.voxBm.getBm(t.getVoice(120,e.sid[1],0,e.mode).name);break}default:n=t.voxBm.getBm(t.getVoice(0,e.sid[1],0,e.mode).name)}break}default:switch(e.sid[0]){case 56:{n=t.voxBm.getBm(t.getVoice(0,e.sid[1],0,e.mode).name);break}}}return n||(n=t.voxBm.getBm(t.getVoice(e.sid[0],e.sid[1],0,e.mode).name)),n}getChBm(e,t){let n=this;return t=t||n.getChVoice(e),n.getVoxBm(t)}get noteProgress(){return this.#g/this.#e}get noteOverall(){return this.noteProgress-this.#b}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.#p]}getTempo(){return this.#d}sendCmd(e){this.device.runJson(e)}render(e){e>this.#g&&(this.#g=e);let t=this.#t?.step(e)||[],n=0,l=new Set,h={},p=[],y=this,v=[];for(y.device.getStrength().forEach((E,$)=>{y.#i[$]=E}),y.device.newStrength(),t.forEach(function(E){let $=E.data,x=y.device.runJson($);switch(x?.reply){case"meta":{v.push(x);break}}x?.reply&&delete x.reply});y.#k.length>0;){let E=y.#k.shift(),$=E.part<<7|E.note;E.state?(l.add($),h[$]=E.velo):l.has($)&&(p.push({part:E.part,note:E.note,velo:h[$],state:y.device.NOTE_SUSTAIN}),n++)}v?.length>0&&y.dispatchEvent("meta",v);let a=y.device.getActive(),i=[],d=y.device.getPitch(),r=y.device.getCcAll(),s=y.device.getProgram(),o=y.device.getChType(),c=[],u=y.device.getStrength();u.forEach(function(E,$,x){x[$]=Math.max(y.#i[$],E);let C=x[$]-y.#u[$],H=m.length*$;if(C>=0){let J=4*.25**(r[H+m[73]]/64);y.#u[$]+=Math.ceil(C-C*y.smoothingAtk**J)}else{let J=4*.25**(r[H+m[72]]/64);y.#u[$]+=Math.floor(C-C*y.smoothingDcy**J)}});let f=0;return a.forEach(function(E,$){E&&(i[$]=y.device.getVel($),c[$]=y.device.getExt($),f+=i[$].size)}),{extraPoly:n,extraNotes:p,curPoly:f,chInUse:a,chKeyPr:i,chPitch:d,chProgr:s,chContr:r,chType:o,chExt:c,eventCount:t.length,title:y.#h,bitmap:y.device.getBitmap(),letter:y.device.getLetter(),texts:y.device.getTexts(),master:y.device.getMaster(),mode:y.device.getMode(),strength:y.#u.slice(),velo:u,rpn:y.device.getRpn(),tSig:y.getTimeSig(),tempo:y.getTempo(),noteBar:y.noteBar,noteBeat:y.noteBeat,ace:y.device.getAce(),rawVelo:y.device.getStrength(),rawStrength:y.device.getRawStrength(),rawPitch:y.device.getRawPitch(),efxSink:y.device.getEffectSink()}}constructor(e,t=.5,n=.5){super();let l=this;l.smoothingAtk=t,l.smoothingDcy=n,l.device=e,l.addEventListener("meta",function(h){h?.data?.forEach(function(p){(l.#w[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.#k.push(h)}),l.#w[3]=function(h,p){l.#h?.length<1&&(l.#h=p,l.dispatchEvent("title",l.#h))},l.#w[81]=function(h,p){let y=l.noteProgress,v=l.#e||.5;l.#d=6e7/p,l.#e=p/1e6,l.#b+=y*(v/l.#e)-y,l.dispatchEvent("tempo",l.#d)},l.#w[88]=function(h,p){let y=l.noteProgress,v=l.noteOverall,a=l.noteBar,i=l.noteBeat,d=l.#r,r=l.#p;l.#r=p[0],l.#p=1<=d&&(d{de&&(le[q]=!le[q],q++,q>34&&(q=0))},1e3/50);Uint8Array.prototype.render=function(e){let t=0,n=0,l=this.width||5,h=this.height||8;for(let p=0;p=l&&(t=0,n++)};var Ve=class{#t=[];async load(e,t=!1,n="(internal)"){let l=this,h=0,p=0;console.debug(`Font "${n||"(internal)"}": loading started.`),e.split(` +`).forEach(function(y,v){if(v>0&&y?.length>0){let a=y.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 o=s&1?4:0,c=s>>1,u=parseInt(r,16),f=3;for(;u>0||f>=0;){let b=(o+f)*5+c;d[b]=u&1,u=u>>1,f--}}),l.#t[i]=d,h++}}),console.debug(`Font "${n||"(internal)"}": ${p} total, ${h} loaded.`)}async loadFile(e,t=!1){let n=this;console.debug(`Requested font file from "${e}".`),await n.load(await(await fetch(e)).text(),t,e),de=!1}constructor(...e){de=!0,(async()=>{for(let t=0;t{l.classList.add(d)});let{t:h,l:p,w:y,h:v,i:a,a:i}=n;return h?.constructor&&(l.style.top=h?.length?h:`${h}px`),p?.constructor&&(l.style.left=p?.length?p:`${p}px`),y?.constructor&&(l.style.width=y?.length?y:`${y}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 M=function(e,t){t?.forEach(n=>{e.appendChild(n)})},O=function(e,t){t.forEach(n=>{e.classList.contains(n)&&e.classList.remove(n)})},B=function(e,t){t.forEach(n=>{e.classList.contains(n)||e.classList.add(n)})},vt=new Array(128).fill(0);vt.forEach((e,t,n)=>{n[t]=Math.floor(24*t/12.7)/10});var wt=new Array(128).fill(0);wt.forEach((e,t,n)=>{n[t]=Math.abs(Math.round(48*(t-64)/12.7)/10)});var Ke=new Array(11).fill(null);Ke.forEach((e,t,n)=>{n[t]=`${Math.round(t*12/.0128)/100}%`});var $t=new Array(128).fill(null);$t.forEach((e,t,n)=>{n[t]=`${Math.round(t/1.27)/100}`});var Fe=function(e,t){e.innerText=t,e.rNew=!0;let n=e.measureText(t);e.rWidth=n.width},ba=class extends Xe{#t=128;#m=!1;#T="";#h;#w=0;#k=0;#u=0;#i=0;#e=g.invalidCh;#d=1;#r=0;#p=0;#b=new Uint8Array(1280);#g=new Uint8Array(1280);#x=new Uint8Array(1280);#I=new Uint8Array(512);#O=new Uint8Array(512);#U=new Uint8Array(512);#M=new Uint8Array(g.ch);#s;#o;#H;#l;#P;#S="fcdaff";#a={};#R={};#n=[];#E={};#$={};eventViewMode=0;#z=[];#A="comb";glyphs=new Ve;#L(e,t,n,l=0,h=0){let p=this,{width:y,height:v}=e.canvas,a,i,d,r,s=p.#d,o=l>3,c=pt.indexOf(t%12)>-1;switch(p.#A){case"block":case"comb":{a=Math.round(t*y/128),i=Math.round((t+1)*y/128),d=i-a,r=s==1?2:1;break}case"piano":{a=Math.round((Math.floor(t/12)*7+Ge[t%12])*y/75*1.0044642857142856),i=Math.round((Math.floor(t/12)*7+Ge[t%12]+1)*y/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)*y/128),a=Math.round((u+.5)*y/128)}default:}switch(e.fillStyle=`#${c?p.#S:"ffffff"}${(n<<1|n>>6).toString(16).padStart(2,"0")}`,e.strokeStyle=e.fillStyle,e.lineWidth=s==1?4:2,e.lineDashOffset=0,p.#A){case"block":{let u=e.canvas.height-1;e.fillRect(a,1,d,u),o&&e.clearRect(a+r,r+1,d-(r<<1),u-(r<<1));break}case"comb":{let u=(c?Math.round((e.canvas.height<<1)/3):e.canvas.height)-1;e.fillRect(a,1,d,u),o&&e.clearRect(a+r,r+1,d-(r<<1),u-(r<<1));break}case"piano":{let u=(c?0:e.canvas.height>>1)+1,f=(e.canvas.height>>1)-1;e.fillRect(a,u,d,f),o&&e.clearRect(a+r,u+r,d-(r<<1),f-(r<<1));break}case"line":{if(o)switch(s){case 4:{e.setLineDash(fe[2]);break}default:e.setLineDash(fe[1])}else e.setLineDash(fe[0]),s!=4&&self?.document?.mozFullScreen&&(a+=.5,i+=.5);e.beginPath(),e.moveTo(a,(s==4||!o)&&self?.document?.mozFullScreen?2:1),e.lineTo(i,(v>>1)+1),e.lineTo(a,v),e.stroke();break}default:}}#q(e,t){let n=this;(e?.chInUse||t).forEach((l,h)=>{if(l){let p=n.#n[h>>4][h&15].cxt;p.clearRect(0,0,p.canvas.width,p.canvas.height),e.chKeyPr[h].forEach(({v:y,s:v},a)=>{n.#L(p,a,y,v,n.device.getPitchShift(h))})}})}#_(e){let t=this;Date.now()-t.#w>4e3&&(t.#k=0,t.#u=142-t.#E.view.clientHeight,(t.#h?.clientWidth||0)>840&&(t.#k=840-t.#h.clientWidth),t.#E.view.style.transform=`translateX(${t.#k}px) translateY(${t.#u}px)`,e&&(t.#w=0))}#y(){let e=self.innerWidth/self.innerHeight,t=1,n=self.innerWidth,l=self.innerHeight;e>=Q?(t=Math.min(Math.round(self.innerHeight/1080*1e4)/1e4,100),n=Math.ceil(self.innerHeight*Q)):e>4,s=d*g.cc,o=d*g.ace,c=e.#n[r][d&15];if(n.chInUse[d]&&r>=e.#r&&r0){let C=24-x;c.ccVis.fillRect(b*6,C,4,x)}}}let u=n.chContr[s+m[10]]||1,f=Math.abs(u-64)/2.625;if(u<64?c.ccVis.fillRect(84-f,0,f,24):u>127?(c.ccVis.fillRect(60,0,49,24),c.ccVis.clearRect(61,1,47,22)):c.ccVis.fillRect(85,0,f,24),c.ccVis.fillStyle="#fff",c.ccVis.fillRect(84,0,1,24),c.metre.clearRect(0,0,121,25),c.metre.globalCompositeOperation="source-over",c.metre.rWidth>c.metre.canvas.width){c.metre.rNew&&(c.metre.rNew=!1,c.metre.rOffset=t);let b=t-(c.metre.rOffset||0),E=32,$=c.metre.rWidth-c.metre.canvas.width+E,x=b*-25%(c.metre.rWidth+E+48)+48;x>0&&(x=0),c.metre.fillText(c.metre.innerText,x,3+e.#P.font4[0]),Math.abs(x)>$&&c.metre.fillText(c.metre.innerText,x+c.metre.rWidth+E,3+e.#P.font4[0])}else c.metre.fillText(c.metre.innerText,0,3+e.#P.font4[0]);switch(c.metre.globalCompositeOperation="xor",c.metre.fillRect(0,0,n.strength[d]*121/255,25),c.extVis.clearRect(0,0,47,25),c.extVis.fillStyle="#fff",n.chExt[d][0]){case e.device.EXT_VL:{let b=(n.chContr[s+m[136]]-64)/64||n.rawPitch[d]/8192;b=b*-4+4;let E=+!!n.rawVelo[d]*(n.chContr[s+m[129]]*n.chContr[s+m[11]]/16129);!E&&n.rawStrength[d]&&(E=n.rawStrength[d]*n.chContr[s+m[11]]/16129),E*=32;let $=n.chContr[s+m[1]]/127*8;c.extVis.beginPath(),c.extVis.moveTo(0,12-b-3),c.extVis.lineTo(7+E,12),c.extVis.lineTo(0,12+b+3),c.extVis.fill(),c.extVis.fillStyle=`#${e.#S}`,c.extVis.beginPath(),c.extVis.ellipse(43,12,4,4+$,0,0,gt),c.extVis.fill();break}case e.device.EXT_DX:{n.chContr.subarray(s+m[142],s+m[157]+1).forEach((E,$)=>{$>=8&&(c.extVis.fillStyle=`#${e.#S}`);let x=$*3,C=(E-64)/5.82;C>=0?c.extVis.fillRect(x,12-C,2,C+1):c.extVis.fillRect(x,12,2,1-C)});break}}}}let v=new Array(g.ch);if(e.#n.forEach((d,r)=>{d.forEach((s,o)=>{s.refresh&&(s.refresh=!1,v[r<<7|o]=!0)})}),["line"].indexOf(e.#A)>-1)for(;e.#z.length>0;){let d=e.#z.shift();v[d.part]=!0}e.#q(n,v),n.extraNotes.forEach(d=>{let{part:r,note:s,velo:o,state:c}=d,u=e.#n[r>>4][r&15].cxt;e.#L(u,s,o,c,e.device.getPitchShift(r))});let a=e.#$.cxt;l>n.bitmap.expire?e.#U.fill(0):n.bitmap.bitmap.length>256?n.bitmap.bitmap.forEach((d,r)=>{e.#U[r]=d?255:0}):n.bitmap.bitmap.forEach((d,r)=>{e.#U[r<<1]=d?255:0,e.#U[r<<1|1]=d?255:0}),e.#x.fill(0),l<=n.letter.expire&&e.glyphs.getStr(n.letter.text).forEach((d,r)=>{let s=(r&15)*5,o=r>>4<<3;d.forEach((c,u)=>{let f=s+u%5,b=o+Math.floor(u/5);e.#x[b*80+f]=c?255:0})}),e.#I.forEach((d,r,s)=>{let o=e.#U[r];o>d?s[r]+=Math.min(o-d,Z):o{let o=e.#x[r];o>d?s[r]+=Math.min(o-d,Z):o{let s=r>>5,o=r&31;e.#O[r]!=d?(a.clearRect(252+(o<<2),s<<2,3,3),d&&(a.fillStyle=`#ffffff${d.toString(16).padStart(2,"0")}`,a.fillRect(252+(o<<2),s<<2,3,3))):self.debugMode&&(a.clearRect(252+(o<<2),s<<2,3,3),d&&(a.fillStyle=`#ff0000${d.toString(16).padStart(2,"0")}`,a.fillRect(252+(o<<2),s<<2,3,3)))}),e.#b.forEach((d,r)=>{let s=Math.floor(r/80),o=r%80;o+=Math.floor(o/5),e.#g[r]!=d?(a.clearRect(o<<2,(s|16)<<2,3,3),d&&(a.fillStyle=`#ffffff${d.toString(16).padStart(2,"0")}`,a.fillRect(o<<2,(s|16)<<2,3,3))):self.debugMode&&(a.clearRect(o<<2,(s|16)<<2,3,3),d&&(a.fillStyle=`#ff0000${d.toString(16).padStart(2,"0")}`,a.fillRect(o<<2,(s|16)<<2,3,3)))}),e.#O.forEach((d,r,s)=>{s[r]=e.#I[r]}),e.#g.forEach((d,r,s)=>{s[r]=e.#b[r]});let i=(self.performance||self.Date).now();switch(e.eventViewMode){case 0:{e.#a.events.innerText=`${n.eventCount}`.padStart(3,"0");break}case 1:{let d=1e3/(i-e.#p);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.#p=i}#Y;#f;get style(){return this.#A}set style(e){let t=this;t.#A=e,t.#q(t.render(t.#s?.currentTime||0)),O(t.#l,["cambiare-style-block","cambiare-style-comb","cambiare-style-piano","cambiare-style-line"]),B(t.#l,[`cambiare-style-${e}`])}setClockSource(e){this.#s=e}setPixelProfile(e){let t=this;if(_e[e]){let n=_e[e];t.#P=n,t.#l&&(t.#l.style.setProperty("--pcp-font4",`translate(${n.font4[1]}px, ${n.font4[0]}px)`),t.#l.style.setProperty("--pcp-font7",`translate(${n.font7[1]}px, ${n.font7[0]}px)`))}else throw new Error(`"${e}" is not a valid pixel correction profile`)}setMode(e){let t=this;O(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!="?"&&B(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,n=t.#d,l=t.#r;t.#n.forEach((h,p)=>{if(p>=l&&p{i.root.style.top=`${d*(n>2?26:52)}px`})}else O(h.root,["port-active"]),h.root.style.top="",h.root.style.left="",h.forEach((y,v)=>{y.root.style.top=""});e&&h.forEach((y,v)=>{y.cxt.canvas.width=t.#d==1?1193:495,y.cxt.canvas.height=t.#d==4?26:52})})}setPort(e){let t=this;O(t.#l,["cambiare-start0","cambiare-start1","cambiare-start2","cambiare-start3","cambiare-start4","cambiare-start5","cambiare-start6","cambiare-start7"]),B(t.#l,[`cambiare-start${e}`]),t.#r=e,t.#G(!1)}setRange(e){let t=this;O(t.#l,["cambiare-port1","cambiare-port2","cambiare-port4","cambiare-compact"]),B(t.#l,[`cambiare-${e}`]),t.#d=parseInt(e.slice(4))||1,t.#G(!0)}setFrameTime(e=20){let t=this;t.#f?.constructor&&clearInterval(t.#f),e<5?e=5:e>100&&(e=100),t.#f=setInterval(t.#Y,e),t.smoothingAtk=Math.pow(.1,e/20),t.smoothingDcy=Math.pow(.75,e/20)}attach(e){let t=this;t.#o=e;let n=k("div",["cambiare-container"]);e.appendChild(n),t.#H=n;let l=k("div",["cambiare-canvas","cambiare-port1","cambiare-start0","cambiare-style-block"]);n.appendChild(l),t.#l=l,self.addEventListener("resize",t.#c),t.#c(),t.setFrameTime(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),M(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),M(t.#R.root,[t.#R.left,t.#R.right]),M(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"})]),M(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 y=0;y<16;y++){let v=(p|y)+1;v>=100?v=`${Math.floor(v/10).toString(16)}${v%10}`:v=`${v}`.padStart(2,"0"),t.#n[h][y]={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][y];Ke.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",M(a.notes,[a.cxt.canvas]),M(a.keys,[a.notes]),M(a.voice,[a.metre.canvas]),M(a.major,[a.number,a.voice,a.ccVis.canvas]),M(a.minor,[a.type,a.std,a.msb,a.prg,a.lsb,a.extVis.canvas]),M(a.root,[a.major,a.minor,a.keys]),M(t.#n[h].root,[a.root]),a.number.addEventListener("contextmenu",i=>{i.preventDefault(),i.stopImmediatePropagation();let d=h<<4|y;t.#M[d]=+!t.#M[d],[O,B][t.#M[d]](a.root,["part-hidden"])})}t.#n.root.appendChild(t.#n[h].root)}l.appendChild(t.#n.root),t.#E.root=k("div",["sect-meta"]),t.#E.view=k("div",["boundary"]),l.appendChild(t.#E.root),M(t.#E.root,[t.#E.view]),t.#$.root=k("div",["sect-pix","boundary"],{l:1529,t:950,w:379,h:127}),t.#$.cxt=k("canvas",["field"]).getContext("2d"),t.#$.fps=k("span",["field","field-key"],{l:0,w:"100%",h:1}),t.#$.cxt.canvas.width=379,t.#$.cxt.canvas.height=127,M(t.#$.root,[t.#$.cxt.canvas]),l.appendChild(t.#$.root),t.addEventListener("mode",h=>{t.#a.mode.innerText=`${mt[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),y=t.#n[h.part>>4][h.part&15];Fe(y.metre,t.getMapped(p.name)),y.type.innerText=ut[t.device.getChType()[h.part]],y.std.innerText=p.standard,y.msb.innerText=`${p.sid[0]}`.padStart(3,"0"),y.prg.innerText=`${p.sid[1]}`.padStart(3,"0"),y.lsb.innerText=`${p.sid[2]}`.padStart(3,"0")}),t.addEventListener("pitch",h=>{let{part:p,pitch:y}=h.data;t.#n[p>>4][p&15].notes.style.transform=`translateX(${y/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:y}=h.data;[O,B][y](t.#n[p>>4][p&15].number,["part-efx"])}),t.addEventListener("channeltoggle",h=>{let{part:p,active:y}=h.data;[O,B][y](t.#n[p>>4][p&15].root,["part-active"])}),t.addEventListener("channelactive",h=>{if(t.#e>4][t.#e&15].number;O(y,["part-focus"])}let p=h.data;if(p>4][p&15].number;B(y,["part-focus"]),t.#e=p}}),t.addEventListener("metacommit",h=>{let p=h.data;if(t.#m&&p.type==t.#T&&t.#h)switch(p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{M(t.#h,[k("span",["meta-slice"],{i:p.data})]);break}default:t.#h.childNodes[0].data+=p.data}else if(p.data?.length&&yt.indexOf(p.type)==-1){let y=k("div",["meta-line"]),v=k("span",["field","field-key","meta-type"],{i:bt[p.type]||p.type});switch(p.mask&&(v.style.display="none"),p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{t.#h=k("span",["field","meta-data"]),M(t.#h,[k("span",["meta-slice"],{i:p.data})]);break}default:t.#h=k("span",["field","meta-data"],{i:p.data})}for(t.#E.view.appendChild(y),M(y,[v,t.#h]);t.#E.view.children.length>t.#t;)t.#E.view.children[0].remove()}t.#m=p.amend||!1,t.#T=p.type||"",t.#_()}),t.#E.view.style.transform="translateX(0px) translateY(140px)",t.dispatchEvent("mode","?"),t.dispatchEvent("mastervolume",100),t.dispatchEvent("tempo",120),t.dispatchEvent("tsig",[4,4]),t.dispatchEvent("title",""),t.dispatchEvent("efxreverb",t.device.getEffectType(0)),t.dispatchEvent("efxchorus",t.device.getEffectType(1)),t.dispatchEvent("efxdelay",t.device.getEffectType(2)),t.dispatchEvent("efxinsert0",t.device.getEffectType(3)),t.#G(!0)}detach(e){let t=this;self.removeEventListener("resize",t.#c),t.#l.remove(),t.#l=void 0,t.#H.remove(),t.#H=void 0,t.#o=void 0,clearInterval(t.#f)}constructor(e,t){super(new Oe,.1,.75);let n=this;n.#c=n.#y.bind(this),n.#Y=n.#X.bind(this),e&&n.attach(e),t&&n.setClockSource(t),n.setPixelProfile("none"),n.addEventListener("reset",()=>{n.#i=0,n.#m=!1,n.#T="",n.#h=null,n.#e=g.invalidCh;try{let l=n.#E.view.children;for(let h=l.length-1;h>=0;h--)l[h].remove();n.#E.view.style.transform="translateX(0px) translateY(140px)";for(let h=0;h>4][h&15];O(p.root,["part-active"]),O(p.number,["part-efx","part-focus"]),Fe(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{}}),n.addEventListener("pitch",({data:l})=>{n.#z.push(l)})}};export{ba as Cambiare}; diff --git a/dist/micc.mjs b/dist/micc.mjs new file mode 100644 index 00000000..b1dc0222 --- /dev/null +++ b/dist/micc.mjs @@ -0,0 +1,19 @@ +var _=Object.defineProperty;var I=(c,u,w)=>u in c?_(c,u,{enumerable:!0,configurable:!0,writable:!0,value:w}):c[u]=w;var T=(c,u,w)=>(I(c,typeof u!="symbol"?u+"":u,w),w);var L=["utf-8","utf-16","utf-16be"],E=(c,u)=>{c.unsent=!1,c.enqueue(u)},R,o=(R=class{static lineRaw(c,u=0){if(u?.constructor!=Number||u<0||u>=L.length)throw new TypeError("Invalid split mode");if(u)throw new Error("UTF-16LE/BE currently not implemented");if(!c||c?.constructor!=ReadableStream)throw new TypeError("Not a readable stream");let w=c.getReader(),e,a=!1,i=[],h=0,b=0,S=0;return new ReadableStream({pull:async $=>{for($.unsent=!0;$.unsent;){if(!e||h>=e.length){h>b&&(i.push(e.subarray(b)),b=0);let{value:k,done:p}=await w.read();e=k,a=p,h=0}if(e){let k=e[h],p=!1;switch(k){case 10:{S==13?b++:p=!0;break}case 13:{p=!0;break}}if(p){if(i.length){i.push(e.subarray(b,h));let t=0;for(let g=0;g{let{value:h,done:b}=await e.read();h&&i.enqueue(a.decode(h)),b&&i.close()}})}},T(R,"SPLIT_UTF_8",0),T(R,"SPLIT_UTF_16_LE",1),T(R,"SPLIT_UTF_16_BE",2),R),B=o;var s=new TextEncoder;var d=(c,u)=>{c.unsent=!1,c.enqueue(u)},A=function(c){let u=c.getReader(),w=0,e=0,a=0,i,h=0,b=0,S=!1,r=0,$="",k=0,p=0,t=0,m=0,y=!1,g=0,x=0;return new ReadableStream({pull:async n=>{for(n.unsent=!0;n.unsent;){if(!i||e>=i.length){let{value:f,done:U}=await u.read();if(i&&(w+=i.length),e=0,i=f,U){n.close();return}}let P=w+e,l=i[e];switch(r>4&&S&&P-h>=b&&(n.enqueue(s.encode(` +`)),r=0,h=0,b=0,S=!1),r){case 0:{switch($+=String.fromCharCode(l),$){case"MThd":{d(n,s.encode(`:hd +`)),r=1,k=3,p=4,a=e+1,$="",S=!1;break}case"MTrk":{x++,d(n,s.encode(`:tr#${x} +`)),r=1,k=3,p=5,a=e+1,$="",S=!1;break}default:$.length>=4&&($=$.substring(1,4))}break}case 1:{let f=e-a;f||(t=0),t=t<<8,t|=l,f>=3&&(t<0&&(t+=4294967296),r=k,e--);break}case 2:{let f=e-a;f||(t=0),t=t<<7,t|=l&127,(l<128||f>=3)&&(f&&e++,r=k,y&&(a=e+1,y=!1),e--);break}case 3:{d(n,s.encode(` ln ${t} +`)),r=p,a=e+1,h=a+w,b=t,S=!0;break}case 4:{let f=e-a;if(f&1||(t=0),t=t<<8,t|=l,f&1)switch(f>>1){case 0:{d(n,s.encode(` ft ${t} +`));break}case 1:{d(n,s.encode(` tc ${t} +`));break}case 2:{t<32768?d(n,s.encode(` dv ${t} +`)):d(n,s.encode(` td ${t} +`)),r=0,a=e+1,t=0;break}}break}case 5:{r=2,k=6,e--;break}case 6:{if(e-a)switch(t&&(d(n,s.encode(` dt ${t} +`)),t=0),l){case 240:{r=15;break}case 247:{r=16;break}case 255:{r=7;break}default:r=l>>4,g=l&15,a=e+1}else t&&d(n,s.encode(` dt ${t} +`)),t=0;break}case 7:{d(n,s.encode(` mt ${l}`)),r=2,k=17,y=!0,a=e+1;break}case 15:{d(n,s.encode(" se")),r=2,k=17,e--,y=!0,a=e+1;break}case 16:{d(n,s.encode(" sc")),r=2,k=17,e--,y=!0,a=e+1;break}case 17:{let f=e-a;f==0&&(m=t,d(n,s.encode(` (${m})`))),f<0||(f{let{value:h,done:b}=await u.read();b?i.close():w++}})};export{C as streamAssemble,A as streamDisassemble}; diff --git a/dist/state.mjs b/dist/state.mjs index 31f57221..42fe5ee2 100644 --- a/dist/state.mjs +++ b/dist/state.mjs @@ -1,10 +1,10 @@ -var Q=function(e,a){let l=Math.min(e.length,a.length),h=e.slice(0,l),g=a.slice(0,l),E=0,$=0;for(;$0){let h=this.pool.length,g=1<=1&&$>=0;){if($<=0)throw new Error("TTL reached.");if(E==h)E-=g;else{let t=Q(a,this.pool[E]);switch(t){case 0:{$=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,$--}let v=!0;if(E>=this.pool.length)v=!1;else{let t=this;this.pool[E].forEach(function(r,f,s){v&&r!=a[f]&&(v=!1)}),!v&&Q(a,this.pool[E])>0&&E++}return v||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 Y=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 Ee=["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,$=1,v=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]];$=b?.poly||$,v=b?.type||v,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]];$=b?.poly||$,v=b?.type||v,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:$,type:v,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,$=0;e.split(` -`).forEach(function(v,t){let r=v.split(" "),f=[];if(t==0){if(r.forEach(function(s,i){g[Ee.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++}$++}}),a||console.debug(`Map "${l}": ${$} 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 $=h[0];$<=h[1];$++){let v=E+$;for(let t=a[0];t<=a[1];t++)delete this.#t[t][v]}}}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 ye=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},D=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,$=0,v=!0,t=[],r=0;for(;v;){let f=a.subarray(E);([()=>{D.decode(f.subarray(0,4))=="YSFC"?(E+=80,$=1):E++},()=>{if(ye(f.subarray(0,4),h))t.forEach((s,i,n)=>{let c=U(a.subarray(s.start+4,s.start+8));s.length=c}),$=2;else{let s=D.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(;c0){let h=this.pool.length,g=1<=1&&$>=0;){if($<=0)throw new Error("TTL reached.");if(E==h)E-=g;else{let t=W(a,this.pool[E]);switch(t){case 0:{$=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,$--}let v=!0;if(E>=this.pool.length)v=!1;else{let t=this;this.pool[E].forEach(function(r,f,s){v&&r!=a[f]&&(v=!1)}),!v&&W(a,this.pool[E])>0&&E++}return v||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 Y=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 Ee=["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,$=1,v=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="",n=0,c=0;switch(r[0]){case 0:{switch(r[2]){case 127:{h=="xg"?s="GM-a":(s="MT-a",i="C/M");break}case 126:{h=="xg"?s="GM-n":(s="MT-b",i="C/M");break}case 7:{s="GM-k",i="GLX";break}case 5:{s="SG-a",i="000";break}case 4:{h=="gs"||h=="sc"?(s="GM-a",i="000"):(s="SP-l",i="C/M");break}case 3:case 2:case 1:{(h=="gs"||h=="sc")&&(s="GM-a",i="000");break}case 0:{s="GM-a";break}default:s="y",n=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]}`,n=3);break}case 48:{i=`M${(r[2]>>3).toString().padStart(2,"0")}`,s=`y${i}`,n=1;break}case 56:{s="GM-b";break}case 57:s=["yDOC","QY10","QY20"][r[2]-112]||"yMxv",i=["DOC","QY1","QY2"][r[2]-112]||"057";case 61:case 120:{s="rDrm";break}case 62:{s="kDrm";break}case 63:{if(r[2]<17){let y=r[2];s=y<10?"kP:":"kC:",s+=y%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";n=1;break}case 64:{s="ySFX",i="SFX";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?c=63:r[2]>>4==1&&(c=16),n=3;break}case 97:{s=r[2]>>4==1?"SDa":"VL:",n=3,r[2]>>4==1?c=16:c=112;break}case 98:{s=r[2]>>4==1?"SDb":"SG-a",n=3,c=16;break}case 99:{s=r[2]>>4==1?"SDc":"DX",r[2]>63?c=63:r[2]>>4==1&&(c=16),n=3;break}case 100:{s="AN",r[2]>63?c=63:r[2]>>4==1&&(c=16),n=3;break}case 104:case 105:case 106:case 107:{s="SDd",c=104;break}case 121:{s=`GM-${r[2]?"":"a"}`,n=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]][n]-c}`.padStart(4-s.length,"0")),i.length<3&&(i+=`${[e,l,e,l][n]}`.padStart(3-i.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 d=[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 y=this.#t[r[1]||0][(r[0]<<7)+r[2]];$=y?.poly||$,v=y?.type||v,t=y?.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 y=this.#t[r[1]||0][(r[0]<<7)+r[2]];$=y?.poly||$,v=y?.type||v,t=y?.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 o=[r[0],r[1],r[2]];switch(f){case"^":{switch(h){case"gs":case"sc":case"ns5r":{f=" ";break}}e==127&&f=="^"&&(f=" ");break}}let b="??";switch(r[0]){case 0:{r[2]==0?b="GM":r[2]==5||r[2]==7?b="KG":r[2]<126?b="XG":r[2]==127&&(b="MT");break}case 32:case 33:case 35:case 36:{r[2]>4?b=["AP","VL","PF","DX","AN"][r[0]-32]:b="GS";break}case 48:{b="MU";break}case 56:{b="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{b="AI";break}case 62:case 82:case 90:{b="XD";break}case 63:{r[2]<17?b="KR":r[2]<34?b="ES":b="DS";break}case 64:case 126:{b="XG";break}case 67:case 99:{b=r[2]>>4==1?"SD":"DX";break}case 81:{b="RW";break}case 95:{b=["DR","PC"][r[2]];break}case 96:{b=r[2]==106?"AP":r[2]>>4==1?"SD":"PF";break}case 97:{b=r[2]>>4==1?"SD":"VL";break}case 98:{b=r[2]>>4==1?"SD":"SG";break}case 100:{b="AN";break}case 104:case 105:case 106:case 107:{b="SD";break}case 120:{b="GS";break}case 121:{b=r[2]?"G2":"GM";break}case 122:{b="KG";break}case 127:{b=r[2]==127?"MT":a==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&h=="xg"?b="XG":b="GS")}return f!=" "&&(h=="krs"||self.debugMode)&&(E="",b="KR"),{name:E||`${V(e||0)} ${V(a||0)} ${V(l||0)}`,poly:$,type:v,drum:t,iid:d,eid:o,sid:g,ending:f,sect:s,bank:i,standard:b,mode:h}}async load(e,a,l="(internal)"){let h=this,g=[],E=0,$=0;e.split(` +`).forEach(function(v,t){let r=v.split(" "),f=[];if(t==0){if(r.forEach(function(s,i){g[Ee.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++}$++}}),a||console.debug(`Map "${l}": ${$} 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 $=h[0];$<=h[1];$++){let v=E+$;for(let t=a[0];t<=a[1];t++)delete this.#t[t][v]}}}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 ye=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},D=new TextDecoder,H=new j;H.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,$=0,v=!0,t=[],r=0;for(;v;){let f=a.subarray(E);([()=>{D.decode(f.subarray(0,4))=="YSFC"?(E+=80,$=1):E++},()=>{if(ye(f.subarray(0,4),h))t.forEach((s,i,n)=>{let c=U(a.subarray(s.start+4,s.start+8));s.length=c}),$=2;else{let s=D.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&&($=3,v=!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,$=!0,v=[],t=0;for(;$;){let r=a.subarray(h);([()=>{$=D.decode(r.subarray(0,4))=="INI2",E=r[15],h+=16,g=1},()=>{let f=D.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=D.decode(r.subarray(44,44+n));v.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=v[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=D.decode(o.subarray(0,24)).trimEnd().replace("InitProg","");b.length&&n>5&&(l+=` +063 ${(o[17]+1).toString().padStart(3,"0")} ${o[19].toString().padStart(3,"0")} ${b}`),d+=c}break}}r++,r>=t.length&&($=3,v=!1)}][$]||(()=>{v=!1}))()}return l});H.set("pcg",async function(e){let a=new Uint8Array(await e.arrayBuffer()),l="MSB LSB PRG NME",h=100,g=0,E=0,$=!0,v=[],t=0;for(;$;){let r=a.subarray(h);([()=>{$=D.decode(r.subarray(0,4))=="INI2",E=r[15],h+=16,g=1},()=>{let f=D.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=D.decode(r.subarray(44,44+n));v.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=v[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=D.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=D.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>=v.length&&(g=3,$=!1)}][g]||(()=>{$=!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"],me=[17.1,18.6,20.2,21.8,23.3,24.9,26.5,28,29.6,31.2,32.8,34.3,35.9,37.5,39,40.6,42.2,43.7,45.3,46.9,48.4,50],A=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],J=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],Z=function(e){let 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},ee=function(e){return e>105?me[e-106]:e>100?e*1.1-100:e/10},te=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),K={};`hi*, +${i.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")} ${c.toString().padStart(3,"0")} ${b}`)}break}}t++,t>=v.length&&(g=3,$=!1)}][g]||(()=>{$=!1}))()}return l});var N=["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"],me=[17.1,18.6,20.2,21.8,23.3,24.9,26.5,28,29.6,31.2,32.8,34.3,35.9,37.5,39,40.6,42.2,43.7,45.3,46.9,48.4,50],L=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],J=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],Z=function(e){let 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},ee=function(e){return e>105?me[e-106]:e>100?e*1.1-100:e/10},te=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),K={};`hi*, ka,か ki,き ku,く @@ -141,8 +141,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let a=e.split(",");K[a[0]]=a[1]});var ae=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},re=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"],se=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ie=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var $e={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},ve={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 $e[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ce=function(e,a,l){let h=(e[0]-32<<16)+(e[1]<<8)+a,g=ve[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,v=e[g];v+=$,g%8!=0?(a(v,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"],ke={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"},we=["melodic","drum","menu"],ne={"?":[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 oe=[9,25,41,57,73,89,105,121],xe=[0,3,81,84,88],le={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},de={0:0,1:1,2:3,5:4},fe={0:0,1:1,2:2,5:3},he=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],ue=[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],pe={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],Se=[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],Ce=[33,99,100,32,102,8,9,10],be=[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 Te={};we.forEach((e,a)=>{Te[e]=a});var Me=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 ge=8,p={port:ge,ch:ge<<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},et=class extends Y{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;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);#h=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);#u=new Uint8Array(p.ch*p.nn);#$=new Uint8Array(p.ch);#p=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*ue.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);#d=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);#l={};#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.#p.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.#u[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.#u[l],state:this.NOTE_SOSTENUTO_HELD});else{this.#p[h]=0,this.#u[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.#f.ano(e);this.#b[g]>0&&this.#p[g]!=h;)g++;if(g{},cAt:(e,a)=>{},hoOf:e=>{this.#b.forEach((a,l)=>{if(a==this.NOTE_HELD){let h=this.#p[l],g=h>>7;e==g&&(this.#b[l]=this.NOTE_IDLE,this.#p[l]=0,this.#u[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.#p[l];this.dispatchEvent("note",{part:e,note:g&127,velo:this.#u[g],state:h})}})},soOf:e=>{this.#b.forEach((a,l)=>{if(a==this.NOTE_SOSTENUTO_HELD){let h=this.#p[l],g=h>>7;e==g&&(this.#b[l]=this.NOTE_IDLE,this.#p[l]=0,this.#u[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#p.forEach((a,l,h)=>{let g=a>>7,E=a&127;a==0&&this.#u[0]==0||g==e&&this.#f.nOff(g,E)})}};#fe={8:function(e){let a=e.channel,l=e.data[0];this.#f.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.#f.nOn(a,h,g):l.#f.nOff(a,h)},10:function(e){let a=e.channel,l=a*128+e.data[0];this.#p.indexOf(l)>-1&&(this.#u[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,$=a*p.ext,v=this.getChModeId(a);switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#f.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.#f.ano(a);return}case 124:{this.#f.ano(a);return}case 125:{this.#f.ano(a);return}case 126:{this.#$[a]=1,this.#f.ano(a);return}case 127:{this.#$[a]=0,this.#f.ano(a);return}}if(u[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Se.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[$]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?this.#v[$]=this.EXT_DX:this.#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 t=this.#e[E+u[99]],r=this.#e[E+u[98]];if(t==1){let f=Ce.indexOf(r);if(f>-1)this.#e[E+u[71+f]]=e.data[1],w()&&console.debug(`Redirected NRPN 1 ${r} to cc${71+f}.`),this.dispatchEvent("cc",{part:a,cc:71+f,data:e.data[1]});else{let s=ue.indexOf(r);s>-1?this.#te[a*10+s]=e.data[1]-64:console.warn(`NRPN 0x01${r.toString(16).padStart(2,"0")} is not supported.`),w()&&console.debug(`CH${a+1} voice NRPN ${r} commit`)}}else{if(X.indexOf(t)<0){let s=`NRPN 0x${t.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")} `;t==127?console.warn(`${s}is not necessary. Consider removing it.`):console.warn(`${s}is not supported.`)}else{let s=this.#r[a]-2;s<0?console.warn(`CH${a+1} cannot accept drum NRPN as type ${I[this.#r[a]]}.`):this.#y[(s*p.dpn+R[t])*p.dnc+r]=e.data[1]}w()&&console.debug(`CH${a+1} (${I[this.#r[a]]}) drum NRPN ${t} commit`)}}else{let t=de[this.#e[E+u[100]]],r=fe[this.#e[E+u[100]]];if(this.#e[E+u[101]]==0&&t!=null)switch(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],he[t][0]),he[t][1]),this.#a[a*p.rpn+t]=e.data[1],this.#i[a*p.rpnt+r]=1,v){case m.xg:case m.gs:case m.sc:case m.mt32:case m.s90es:case m.motif:{switch(this.#e[E+u[100]]){case 1:case 2:{this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)});break}}break}default: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 t=de[this.#e[E+100]],r=fe[this.#e[E+100]];this.#e[E+101]==0&&t!=null&&(this.#a[a*p.rpn+t+1]=e.data[1],this.#i[a*p.rpnt+r]=1)}break}case 64:{e.data[1]<64&&this.#f.hoOf(a);break}case 66:{e.data[1]>>6?this.#f.soOn(a):this.#f.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.#p.forEach(function(h){let g=h>>7;l==g&&(a.#u[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){Me(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=xe.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.#h.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.#l[a.getChModeId(e)][0],h[u[32]]=h[u[32]]||a.#l[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.#l[l.getChModeId(e)][0],h==L.bank0&&(h=0);break}case 32:{h=h||l.#l[l.getChModeId(e)][1];break}}return h}getCcAll(){let e=this,a=e.#e.slice();for(let l=0;l0&&!h&&(g.#e[e*p.cc+u[0]]=g.#l[l][2])}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.#p.forEach(function(h,g){let E=Math.floor(h/128),$=h%128;e==E&&l.#u[h]>0&&a.set($,{v:l.#u[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.#p.forEach(function(a){let l=Math.floor(a/128);e.#u[a]>e.#A[l]&&(e.#A[l]=e.#u[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.#l[g.#t][0],$=a,v=l||g.#l[g.#t][1];E==L.bank0&&(E=0),S[g.#t]=="ns5r"&&E>0&&E<56&&(v=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 ${$} ${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($=>{g.#X+=String.fromCharCode($>31?$:32),$<32&&(E=E||new Set,E.add($))}),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(ke[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.#l[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]=a.#l[a.getChModeId(l)][2]}),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.#d[e>>4]:this.#B[e]||this.#d[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 v=0;v0&&h.#B[v]==0&&(h.#e[v*p.cc]=h.#l[g][2]);switch(g){case m.mt32:{W.forEach((v,t)=>{let r=t+1;h.#S[r]||(h.#s[r]=v,h.#e[r*p.cc+u[91]]=127)});for(let v=1;v<10;v++)h.dispatchEvent("voice",{part:v});break}}let $;switch(g){case m["?"]:case m.g2:{$=[52,4,52,18,0,0,0,0];break}case m.xg:{$=[1,0,65,0,5,0,0,0];break}case m.gm:case m.gs:case m.sc:{$=[40,4,40,18,40,32,32,0];break}case m.sd:{$=[58,0,60,0,61,0,61,0];break}case m["05rw"]:case m.x5d:case m.ns5r:{$=[44,1,44,19,44,0,44,0];break}case m.k11:case m.sg:{$=[24,0,0,0,0,0,0,0];break}case m.mt32:{$=[40,4,0,0,0,0,0,0];break}case m.doc:{$=[24,16,0,0,0,0,0,0];break}case m.motif:case m.s90es:{$=[113,0,117,0,114,0,0,0];break}default:$=[0,0,0,0,0,0,0,0]}for(let v=0;v{h.dispatchEvent("voice",{part:v})})}}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(`${le[e.type]?le[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 ne){let r=m[t];r==null?console.debug(`SubDB build error: "${t}" does not exist`):e.#l[r]=new Uint8Array(ne[t])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let a=e.split(",");K[a[0]]=a[1]});var ae=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},re=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"],se=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ie=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var $e={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},ve={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 $e[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ce=function(e,a,l){let h=(e[0]-32<<16)+(e[1]<<8)+a,g=ve[h]||{},E=g[0];if(E?.length)return E+=`: ${(g[1]||function(){})(l)||l}`,E},Q=[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,v=e[g];v+=$,g%8!=0?(a(v,l,e),l++):h=e[g]}};var G=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"],ke={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"},we=["melodic","drum","menu"],ne={"?":[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:[121,0,120],s90es:[0,0,127],motif:[0,0,127],trin:[0,0,127]},oe=[9,25,41,57,73,89,105,121],xe=[0,3,81,84,88],le={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},de={0:0,1:1,2:3,5:4},fe={0:0,1:1,2:2,5:3},he=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],ue=[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],pe={26:127,29:0,30:0,31:0,52:12,53:54},B=[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],Se=[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],Ce=[33,99,100,32,102,8,9,10],be=[0,16,25,40,32,64,26,48],m={};S.forEach((e,a)=>{m[e]=a});var p={length:B.length};B.forEach((e,a)=>{p[e]=a});var R={length:X.length};X.forEach((e,a)=>{R[e]=a});var Te={};we.forEach((e,a)=>{Te[e]=a});var Me=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 ge=8,u={port:ge,ch:ge<<4,cc:B.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},A={bank0:128},et=class extends Y{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;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;#H=new Array(11);get#$(){return this.#H[this.#g]}set#$(e){this.#H[this.#g]=e}#C=new Uint8Array(u.ch);#h=new Uint8Array(u.ch);#r=new Uint8Array(u.ch);#e=new Uint8Array(u.ch*u.cc);#E=new Uint8Array(u.ch*u.ace);#s=new Uint8Array(u.ch);#u=new Uint8Array(u.ch*u.nn);#v=new Uint8Array(u.ch);#p=new Uint16Array(u.pl);#b=new Uint8Array(u.pl);#N=new Int16Array(u.ch);#O=new Uint8Array(u.ch);#K=new Uint8Array(u.ch);#k=new Uint8Array(u.ch*u.ext);#a=new Uint8Array(u.ch*u.rpn);#i=new Uint8Array(u.ch*u.rpnt);#te=new Int8Array(u.ch*ue.length);#m=new Uint8Array(u.drm*u.dpn*u.dnc);#R=new Uint8Array(u.drm*2);#w=new Uint8Array(u.efx*3);#ae=new Uint8Array(u.ch);#z=new Uint8Array(u.ch*u.redir);#d=new Uint8Array(u.port);#G=new Uint8Array(u.ch);#D=new Uint8Array(u.ch);#ne=new Uint8Array(u.ch*u.cvn);#B=new Uint8Array(128);#P=new Uint8Array(u.cmt*8);#re=new Uint8Array(1024);#_=new Uint8Array(u.cmt*64);#o={};#c;#A;#oe;#n=100;#q=0;#se=500;#ie=0;#X="";#V=0;#le=0;#ce=0;#L=!0;#l=!1;#he=1;#de;#Q=new Array(u.ch);#x=[];#I=new Uint8Array(u.ch);#F=new Uint8Array(u.tr);baseBank=new F("gm","gm2","xg","gs","ns5r","sd","gmega","plg-vl","plg-pf","plg-dx","plg-an","plg-dr","plg-sg","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.#p.lastIndexOf(l);if(h>-1)if(this.#e[u.cc*e+p[64]]>63)this.#b[h]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:a,velo:this.#u[l],state:this.NOTE_HELD});else if(this.#e[u.cc*e+p[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.#u[l],state:this.NOTE_SOSTENUTO_HELD});else{this.#p[h]=0,this.#u[l]=0,this.#b[h]=this.NOTE_IDLE;let g=this.getExt(e)[1];(g==this.VLBC_VELOINIT||g==this.VLBC_VELOALL)&&(this.#e[u.cc*e+p[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.#v[e]&&this.#f.ano(e);this.#b[g]>0&&this.#p[g]!=h;)g++;if(g{},cAt:(e,a)=>{},hoOf:e=>{this.#b.forEach((a,l)=>{if(a==this.NOTE_HELD){let h=this.#p[l],g=h>>7;e==g&&(this.#b[l]=this.NOTE_IDLE,this.#p[l]=0,this.#u[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.#p[l];this.dispatchEvent("note",{part:e,note:g&127,velo:this.#u[g],state:h})}})},soOf:e=>{this.#b.forEach((a,l)=>{if(a==this.NOTE_SOSTENUTO_HELD){let h=this.#p[l],g=h>>7;e==g&&(this.#b[l]=this.NOTE_IDLE,this.#p[l]=0,this.#u[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#p.forEach((a,l,h)=>{let g=a>>7,E=a&127;a==0&&this.#u[0]==0||g==e&&this.#f.nOff(g,E)})}};#fe={8:function(e){let a=e.channel,l=e.data[0];this.#f.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]!=u.invalidCh&&!l.#C[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.#f.nOn(a,h,g):l.#f.nOff(a,h)},10:function(e){let a=e.channel,l=a*128+e.data[0];this.#p.indexOf(l)>-1&&(this.#u[l]=data[1],this.getExt(a)[1]==this.VLBC_VELOALL&&(this.#e[u.cc*a+p[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.#Q[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*u.cc,$=a*u.ext,v=this.getChModeId(a);switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#f.ano(a),this.#N[a]=0,this.#e[E+p[1]]=0,this.#e[E+p[5]]=0,this.#e[E+p[64]]=0,this.#e[E+p[65]]=0,this.#e[E+p[66]]=0,this.#e[E+p[67]]=0,this.#e[E+p[11]]=127,this.#e[E+p[101]]=127,this.#e[E+p[100]]=127,this.#e[E+p[99]]=127,this.#e[E+p[98]]=127;return}case 123:{this.#f.ano(a);return}case 124:{this.#f.ano(a);return}case 125:{this.#f.ano(a);return}case 126:{this.#v[a]=1,this.#f.ano(a);return}case 127:{this.#v[a]=0,this.#f.ano(a);return}}if(p[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Se.indexOf(e.data[0])>-1&&this.allocateAce(a,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.#k[$]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?this.#k[$]=this.EXT_DX:this.#k[$]=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+p[129]]=e.data[1]);break}case 6:{if(this.#K[a]){[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 t=this.#e[E+p[99]],r=this.#e[E+p[98]];if(t==1){let f=Ce.indexOf(r);if(f>-1)this.#e[E+p[71+f]]=e.data[1],w()&&console.debug(`Redirected NRPN 1 ${r} to cc${71+f}.`),this.dispatchEvent("cc",{part:a,cc:71+f,data:e.data[1]});else{let s=ue.indexOf(r);s>-1?this.#te[a*10+s]=e.data[1]-64:console.warn(`NRPN 0x01${r.toString(16).padStart(2,"0")} is not supported.`),w()&&console.debug(`CH${a+1} voice NRPN ${r} commit`)}}else{if(X.indexOf(t)<0){let s=`NRPN 0x${t.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")} `;t==127?console.warn(`${s}is not necessary. Consider removing it.`):console.warn(`${s}is not supported.`)}else{let s=this.#r[a]-2;s<0?console.warn(`CH${a+1} cannot accept drum NRPN as type ${I[this.#r[a]]}.`):this.#m[(s*u.dpn+R[t])*u.dnc+r]=e.data[1]}w()&&console.debug(`CH${a+1} (${I[this.#r[a]]}) drum NRPN ${t} commit`)}}else{let t=de[this.#e[E+p[100]]],r=fe[this.#e[E+p[100]]];if(this.#e[E+p[101]]==0&&t!=null)switch(w()&&console.debug(`CH${a+1} RPN 0 ${this.#e[E+p[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],he[t][0]),he[t][1]),this.#a[a*u.rpn+t]=e.data[1],this.#i[a*u.rpnt+r]=1,v){case m.xg:case m.gs:case m.sc:case m.mt32:case m.s90es:case m.motif:{switch(this.#e[E+p[100]]){case 1:case 2:{this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)});break}}break}default: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[a]){let t=de[this.#e[E+100]],r=fe[this.#e[E+100]];this.#e[E+101]==0&&t!=null&&(this.#a[a*u.rpn+t+1]=e.data[1],this.#i[a*u.rpnt+r]=1)}break}case 64:{e.data[1]<64&&this.#f.hoOf(a);break}case 66:{e.data[1]>>6?this.#f.soOn(a):this.#f.soOf(a);break}case 98:case 99:{this.#K[a]=1;break}case 100:case 101:{this.#K[a]=0;break}}this.#e[E+p[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=u.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.#p.forEach(function(h){let g=h>>7;l==g&&(a.#u[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.#N[a]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)})},15:function(e){Me(e.data).forEach(a=>{let 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.#y[e.meta]||function(l,h,g){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#q=0);let a=xe.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.#S.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;#S;#T;#U;#J;#Z;#ee;buildRchTree(){let e=[];this.#h.forEach((a,l)=>{a{a&&(e.#Q[Math.floor(l/u.redir)][a]=l%u.redir|128)}),w()&&console.debug(e.#Q)}getActive(){return this.#C}getCc(e){let a=this,l=e*u.cc,h=a.#e.subarray(l,l+u.cc);return h[p[0]]=h[p[0]]||a.#o[a.getChModeId(e)][0],h[p[32]]=h[p[32]]||a.#o[a.getChModeId(e)][1],h[p[0]]==A.bank0&&(h[p[0]]=0),h}getCcCh(e,a){let l=this;if(B.indexOf(a)<0)throw new Error("CC number not accepted");let h=l.#e[u.cc*e+p[a]];switch(a){case 0:{h=h||l.#o[l.getChModeId(e)][0],h==A.bank0&&(h=0);break}case 32:{h=h||l.#o[l.getChModeId(e)][1];break}}return h}getCcAll(){let e=this,a=e.#e.slice();for(let l=0;l0&&!h&&(g.#e[e*u.cc+p[0]]=g.#o[l][2])}setChActive(e,a=0){this.#C[e]!=a&&this.dispatchEvent("channeltoggle",{part:e,active:a}),this.#C[e]=a}getExt(e){let a=u.ext*e,l=this.#k.subarray(a,a+u.ext),h=new Uint8Array(l.length);return h.set(l),h[1]=h[1]||this.#he,h}getPitch(){return this.#N}getProgram(){return this.#s}getTexts(){return this.#x.slice()}getVel(e){let a=new Map,l=this;return l.#p.forEach(function(h,g){let E=Math.floor(h/128),$=h%128;e==E&&l.#u[h]>0&&a.set($,{v:l.#u[h],s:l.#b[g]})}),a}getBitmap(){return{bitmap:this.#$,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.#p.forEach(function(a){let l=Math.floor(a/128);e.#u[a]>e.#O[l]&&(e.#O[l]=e.#u[a])}),this.#O}getStrength(){let e=[],a=this;return this.getRawStrength().forEach(function(l,h){e[h]=Math.floor(l*a.#e[h*u.cc+p[7]]*a.#e[h*u.cc+p[11]]*a.#n/803288)}),e}getRpn(){return this.#a}getNrpn(){return this.#te}getSubDb(){return self?.structuredClone(this.#o)}getVoice(e,a,l,h="?"){let g=this;m[h]?.constructor||(h="?");let E=m[h],$=e||g.#o[E][0],v=a,t=l||g.#o[E][1];$==A.bank0&&($=0),t==A.bank0&&(t=0),h=="ns5r"&&$>0&&$<56&&(t=3);let r=g.userBank.get($,v,t,h);if(h=="mt32"&&r.name.indexOf("MT-m:")==0){let f=parseInt(r.name.slice(5)),s=f*u.cmt,i="";g.#_.subarray(s,s+10).forEach(c=>{c>31&&(i+=String.fromCharCode(c))});let n=`MSB LSB PRG NME +0 127 ${v} ${i}`;g.userBank.load(n,!0),r.name=i,r.ending=" "}return(r.ending!=" "||!r.name.length)&&(r=g.baseBank.get($,v,t,h)),r}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(u.cmt*(e-1),u.cmt*(e-1)+10).forEach(g=>{h+=String.fromCharCode(Math.max(g,32))}),h=h.trimRight();break}default:{let g=u.cvn*e;a.#ne.subarray(g,g+u.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.#N}getPitchShift(e){let a=this,l=e*u.rpn,h=a.#a[l];return a.#i[e*u.rpnt]||a.#t==m.mt32&&(h=12),a.#N[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.#w.subarray(a,a+2)}setEffectTypeRaw(e=0,a,l){let h=3*e;this.#w[h]=1,this.#w[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($=>{g.#X+=String.fromCharCode($>31?$:32),$<32&&(E=E||new Set,E.add($))}),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(ke[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.#o[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.#A.dumpLimit=e}allocateAce(e=0,a){let l=this;if(!a||a<128&&a>95){console.warn(`cc${a} cannot be allocated as an active custom effect.`);return}let h=!0,g=0,E=u.ace*e;for(;h&&g=u.ace&&console.warn(`ACE slots are full in CH${e+1}.`)}allocateAceAll(e){let a=this;if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}for(let l=0;l=u.ace&&console.warn(`ACE slots are full in CH${l+1}.`)}}releaseAce(e=0,a){let l=!0,h=u.ace*e,g=h+u.ace;for(;l&&h=u.ace)throw new RangeError("No such ACE slot");let l=this.#E[u.ace*e+a];if(l){if(B.indexOf(l)>=0)return this.#e[e*u.cc+p[l]];throw new Error(`Invalid ACE source in CH${e+1}: ${l}`)}else return 0}initDrums(){let e=this;e.#m.fill(64);for(let a=0;a{a.#e[u.cc*l]=a.#o[a.getChModeId(l)][2]}),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=u.ch)throw new RangeError(`Invalid CH${e+1}`);if(port<0||a>=S.length)throw new RangeError(`Invalid mode ID ${a}`);l.#G[e]=a,l.dispatchEvent("voice",{part:e})}getChMode(e,a){return S[this.getChModeId(e,a)]}getChModeId(e,a){return a?this.#G[e]||this.#d[e>>4]:this.#G[e]||this.#d[e>>4]||this.#t}setPortMode(e,a,l){let h=this;if(e<0||e>=u.ch>>4)throw new RangeError(`Invalid port ${e+1}`);if(a<1)throw new RangeError("Range must be a positive integer");if(e+a>=u.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 v=0;v0&&h.#G[v]==0&&(h.#e[v*u.cc]=h.#o[g][2]);switch(g){case m.mt32:{Q.forEach((v,t)=>{let r=t+1;h.#C[r]||(h.#s[r]=v,h.#e[r*u.cc+p[91]]=127)});for(let v=1;v<10;v++)h.dispatchEvent("voice",{part:v});break}}let $;switch(g){case m["?"]:case m.g2:{$=[52,4,52,18,0,0,0,0];break}case m.xg:{$=[1,0,65,0,5,0,0,0];break}case m.gm:case m.gs:case m.sc:{$=[40,4,40,18,40,32,32,0];break}case m.sd:{$=[58,0,60,0,61,0,61,0];break}case m["05rw"]:case m.x5d:case m.ns5r:{$=[44,1,44,19,44,0,44,0];break}case m.k11:case m.sg:{$=[24,0,0,0,0,0,0,0];break}case m.mt32:{$=[40,4,0,0,0,0,0,0];break}case m.doc:{$=[24,16,0,0,0,0,0,0];break}case m.motif:case m.s90es:{$=[113,0,117,0,114,0,0,0];break}default:$=[0,0,0,0,0,0,0,0]}for(let v=0;v{h.dispatchEvent("voice",{part:v})})}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#O.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#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(`${le[e.type]?le[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.#x.length>100&&this.#x.splice(100,this.#x.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":{H.context=this,await l.userBank.load(await H.read(e,a),!1);break}}l.forceVoiceRefresh()}constructor(){super();let e=this;e.#$=new Uint8Array(256),e.#H[10]=new Uint8Array(512),e.#W=new T,e.#c={x5:82,ds:m.krs,smotif:m.s90es,gs:4,sc:3},e.#A={dumpLimit:e.DUMP_MODE},e.#oe=new Proxy(e.#A,{set:()=>{}});for(let t in ne){let r=m[t];r==null?console.debug(`SubDB build error: "${t}" does not exist`):e.#o[r]=new Uint8Array(ne[t])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -150,23 +150,23 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -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 +122 006 000 `),e.addEventListener("metacommit",function(t){let{data:r}=t;e.#x[0]?.type==r.type&&e.#x[0]?.amend?(e.#x[0].amend=r.amend,e.#x[0].data+=r.data):e.#x.unshift(r)}),e.#y[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,P)=>{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: ${Z(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: ${J[c]}Hz`)},c=>{},c=>{console.debug(`${s}feedback: ${c}`)},c=>{console.debug(`${s}delay offset: ${ee(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.#h[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: ${re(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.#l[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+=te[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:`${ae(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.#l=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:t.slice(2)?.trimLeft()});break}case"@K":{this.#l=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:t.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#l=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:t.slice(2)?.trimLeft()});break}case"@T":{this.#l=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:t.slice(2)?.trimLeft()});break}case"@V":{this.#l=!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.#l?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.#y[2]=function(t){this.dispatchEvent("metacommit",{type:"Copyrite",data:t})},e.#y[3]=function(t,r){r<1&&this.#q<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:t})},e.#y[4]=function(t,r){this.dispatchEvent("metacommit",{type:"Instrmnt",data:t})},e.#y[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.#y[6]=function(t){this.dispatchEvent("metacommit",{type:"C.Marker",data:t})},e.#y[7]=function(t){this.dispatchEvent("metacommit",{type:"CuePoint",data:t})},e.#y[32]=function(t){this.#q=t[0]+1},e.#y[33]=function(t,r){w()&&console.debug(`Track ${r} requests to get assigned to output ${t}.`),e.#F[r]=t+1},e.#y[81]=function(t,r){e.#se=t/1e3},e.#y[127]=function(t,r){e.#W.run(t,r)},e.#W.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},e.#W.add([67,0,1],function(t,r){w()&&console.debug(`XGworks requests assigning track ${r} to output ${t[0]}.`),e.#F[r]=t[0]+1}),e.#Y=new T("universal non-realtime"),e.#j=new T("universal realtime"),e.#S=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.#S.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.#l=e.#l||!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,P)=>{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.#l=!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: ${N[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: ${Z(c)}s`)},c=>{console.debug(`${s}diffusion: ${c}`)},c=>{console.debug(`${s}initial delay: ${c}`)},c=>{console.debug(`${s}HPF cutoff: ${L[c]}Hz`)},c=>{console.debug(`${s}LPF cutoff: ${L[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: ${N[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: ${J[c]}Hz`)},c=>{},c=>{console.debug(`${s}feedback: ${c}`)},c=>{console.debug(`${s}delay offset: ${ee(c)}ms`)},c=>{},c=>{console.debug(`${s}low: ${L[c]}Hz`)},c=>{console.debug(`${s}low: ${c-64}dB`)},c=>{console.debug(`${s}high: ${L[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: ${N[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: ${N[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.#$.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=u.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+p[0]]=o,e.dispatchEvent("voice",{part:f})},()=>{e.#e[i+p[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.#h[f]=y,f!=y&&(e.buildRchTree(),console.info(`${n}receives from CH${y+1}`)),e.#C[f]||(e.copyChSetup(y,f,!0),console.debug(`${n}copied from CH${y+1}.`),e.setChActive(f,1),e.dispatchEvent("voice",{part:f}))},()=>{e.#v[f]=+!o},()=>{},()=>{d=!1,e.setChType(f,o,m.xg),console.debug(`${n}type: ${I[o]||o}`),e.dispatchEvent("voice",{part:f})},()=>{e.#a[u.rpn*f+3]=o,e.#i[u.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},!1,!1,()=>{e.#e[i+p[7]]=o},!1,!1,()=>{e.#e[i+p[10]]=o||128},!1,!1,()=>{e.#e[i+p[128]]=o,e.allocateAce(f,128)},()=>{e.#e[i+p[93]]=o},()=>{e.#e[i+p[91]]=o},()=>{e.#e[i+p[94]]=o},()=>{e.#e[i+p[76]]=o},()=>{e.#e[i+p[77]]=o},()=>{e.#e[i+p[78]]=o},()=>{e.#e[i+p[74]]=o},()=>{e.#e[i+p[71]]=o},()=>{e.#e[i+p[73]]=o},()=>{e.#e[i+p[75]]=o},()=>{e.#e[i+p[72]]=o}][s+b-1]||(()=>{}))():s<48?console.debug(c):s<111?s>102&&s<105&&(e.#e[i+p[[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=u.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: ${re(c)}`),c&&c<96&&e.allocateAce(f,130+b),e.#z[u.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+p[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.#k[u.ext*t[2]]=e.EXT_VL;break}case 2:{e.#k[u.ext*t[2]]=e.EXT_DX;break}default:e.#k[u.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.#o[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.#L=!!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.#L?"":" (ignored)"}: `;if(f<16)switch(f){case 2:{let i=e.chRedir(0,r,!0);e.#L&&(e.dispatchEvent("portrange",4),e.dispatchEvent("portstart",i)),console.info(`${s}Show CH${i+1}~CH${i+64}`);break}case 3:{let i=e.chRedir(t[1]<<5,r,!0);e.#L&&(e.dispatchEvent("portrange",2),e.dispatchEvent("portstart",i)),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.#L){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.#L&&(e.dispatchEvent("portrange",1),e.dispatchEvent("portstart",i>>4),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-SG CH${f+1} `,i=Date.now();if(t[1]==0){let n="",c=0;t.subarray(2).forEach((d,o)=>{o%2==0?n+=te[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:`${ae(n)}`,amend:!0}),e.#ie=i+Math.ceil(c/2)+e.#se,w()&&console.debug(`${s}vocals: ${n}`)}else console.warn(`Unknown PLG-SG 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.#S.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=u.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(i,y),e.#e[n+p[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);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)}}).add([1,20],(t,r,f)=>{f==115?(e.switchMode("doc",!0),e.setPortMode(e.getTrackPort(r),1,m.doc),console.info("MIDI reset: DOC")):console.debug(`Unknown Yamaha SysEx: 67, ${f}, ${t.join(", ")}`)}).add([1,17,15,89],(t,r,f)=>{f==115?(e.setEffectType(0,24,t[0]|16),e.dispatchEvent("efxreverb",e.getEffectType(0))):console.debug(`Unknown Yamaha SysEx: 67, ${f}, ${t.join(", ")}`)}).add([1,24],(t,r,f)=>{if(f==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, ${f}, ${t.join(", ")}`)}),a.add([14,31],(t,r,f)=>{e.#e[p.cc*t[0]+u[64]]=0,e.#f.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.#h[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.#l[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.#l[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: ${se[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: ${ie[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=ce(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,P=5,G=0;for(x-=k*4,y==3&&(P=1);G>4-G&1,G++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let $=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.#h[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}`))},v=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)=>{$(t,e.chRedir(9,r,!0),r)}).add([66,18,64,17],(t,r)=>{$(t,e.chRedir(0,r,!0),r)}).add([66,18,64,18],(t,r)=>{$(t,e.chRedir(1,r,!0),r)}).add([66,18,64,19],(t,r)=>{$(t,e.chRedir(2,r,!0),r)}).add([66,18,64,20],(t,r)=>{$(t,e.chRedir(3,r,!0),r)}).add([66,18,64,21],(t,r)=>{$(t,e.chRedir(4,r,!0),r)}).add([66,18,64,22],(t,r)=>{$(t,e.chRedir(5,r,!0),r)}).add([66,18,64,23],(t,r)=>{$(t,e.chRedir(6,r,!0),r)}).add([66,18,64,24],(t,r)=>{$(t,e.chRedir(7,r,!0),r)}).add([66,18,64,25],(t,r)=>{$(t,e.chRedir(8,r,!0),r)}).add([66,18,64,26],(t,r)=>{$(t,e.chRedir(10,r,!0),r)}).add([66,18,64,27],(t,r)=>{$(t,e.chRedir(11,r,!0),r)}).add([66,18,64,28],(t,r)=>{$(t,e.chRedir(12,r,!0),r)}).add([66,18,64,29],(t,r)=>{$(t,e.chRedir(13,r,!0),r)}).add([66,18,64,30],(t,r)=>{$(t,e.chRedir(14,r,!0),r)}).add([66,18,64,31],(t,r)=>{$(t,e.chRedir(15,r,!0),r)}).add([66,18,64,64],(t,r)=>{v(t,e.chRedir(9,r,!0))}).add([66,18,64,65],(t,r)=>{v(t,e.chRedir(0,r,!0))}).add([66,18,64,66],(t,r)=>{v(t,e.chRedir(1,r,!0))}).add([66,18,64,67],(t,r)=>{v(t,e.chRedir(2,r,!0))}).add([66,18,64,68],(t,r)=>{v(t,e.chRedir(3,r,!0))}).add([66,18,64,69],(t,r)=>{v(t,e.chRedir(4,r,!0))}).add([66,18,64,70],(t,r)=>{v(t,e.chRedir(5,r,!0))}).add([66,18,64,71],(t,r)=>{v(t,e.chRedir(6,r,!0))}).add([66,18,64,72],(t,r)=>{v(t,e.chRedir(7,r,!0))}).add([66,18,64,73],(t,r)=>{v(t,e.chRedir(8,r,!0))}).add([66,18,64,74],(t,r)=>{v(t,e.chRedir(10,r,!0))}).add([66,18,64,75],(t,r)=>{v(t,e.chRedir(11,r,!0))}).add([66,18,64,76],(t,r)=>{v(t,e.chRedir(12,r,!0))}).add([66,18,64,77],(t,r)=>{v(t,e.chRedir(13,r,!0))}).add([66,18,64,78],(t,r)=>{v(t,e.chRedir(14,r,!0))}).add([66,18,64,79],(t,r)=>{v(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]=be[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+=` +`,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=u.cc*c;t.subarray(2).forEach((o,b)=>{let y=b+n;if(!(y<7)){if(y<23){let k=y+135;e.allocateAce(c,k),e.#e[d+p[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,f)=>{f==115?(e.switchMode("doc",!0),e.setPortMode(e.getTrackPort(r),1,m.doc),console.info("MIDI reset: DOC")):console.debug(`Unknown Yamaha SysEx: 67, ${f}, ${t.join(", ")}`)}).add([1,17,15,89],(t,r,f)=>{f==115?(e.setEffectType(0,24,t[0]|16),e.dispatchEvent("efxreverb",e.getEffectType(0))):console.debug(`Unknown Yamaha SysEx: 67, ${f}, ${t.join(", ")}`)}).add([1,24],(t,r,f)=>{if(f==115){for(let s=0;s<16;s++){let i=e.chRedir(s,r,!0);e.#e[i*u.cc+p[91]]=127}console.info("DOC Global Reverb: on")}else console.debug(`Unknown Yamaha SysEx: 67, ${f}, ${t.join(", ")}`)}),a.add([14,31],(t,r,f)=>{e.#e[u.cc*t[0]+p[64]]=0,e.#f.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=u.cc*r,s=u.ext*r,i=u.cvn*r;e.#k[s]=e.EXT_DX,e.#D[r]=1;let n=e.#ne.subarray(i,i+u.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+p[o]]=c,e.dispatchEvent("cc",{part:r,cc:o,data:c})}}}),e.#s[r]=r&127,e.#e[u.cc*r+p[0]]=35,e.#e[u.cc*r+p[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*u.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.#m[(f+R[o])*u.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*u.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.#m[(s+R[y])*u.dnc+o]=n):w()&&console.debug(`GS-style drum param ${b} has no writes.`)})};this.#S.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.#S.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.#S.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=u.cc*s,c=`TG300 CH${s+1} `;t.subarray(2).forEach((d,o)=>{o<5?([()=>{},()=>{e.#e[n+p[0]]=d,e.dispatchEvent("voice",{part:s})},()=>{e.#e[n+p[32]]=d,e.dispatchEvent("voice",{part:s})},()=>{e.#s[s]=d,e.dispatchEvent("voice",{part:s})},()=>{let b=e.chRedir(d,r,!0);e.#h[s]=b,s!=b&&(e.buildRchTree(),console.info(`${c}receives from CH${b+1}`))}][o+i]||(()=>{}))(d,o+i):o<21||(o<47?([()=>{e.#v[s]=+!d},()=>{},()=>{},()=>{e.#a[u.rpn*s+3]=d,e.#i[u.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{},()=>{e.#e[n+p[7]]=d},!1,!1,()=>{e.#e[n+p[10]]=d||128},!1,!1,()=>{console.debug(`${c} AC1 at cc${d}`)},()=>{console.debug(`${c} AC2 at cc${d}`)},()=>{e.#e[n+p[128]]=d,e.allocateAce(s,128)},()=>{e.#e[n+p[93]]=d},()=>{e.#e[n+p[91]]=d},()=>{e.#e[n+p[94]]=d},()=>{e.#e[n+p[76]]=d},()=>{e.#e[n+p[77]]=d},()=>{e.#e[n+p[74]]=d},()=>{e.#e[n+p[71]]=d},()=>{e.#e[n+p[73]]=d},()=>{e.#e[n+p[75]]=d},()=>{e.#e[n+p[72]]=d},()=>{e.#e[n+p[78]]=d}][o+i-21]||(()=>{}))(d,o+i):o<95||([()=>{e.#e[n+p[65]]=d},()=>{e.#e[n+p[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.#$.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[u.cc*9]=120,e.#e[u.cc*25]=120,e.#e[u.cc*41]=120,e.#e[u.cc*57]=120,e.#o[m.sc][1]=e.#c.sc,e.#l=!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.#o[m.gs][1]=e.#c.gs,e.#e[u.cc*9]=120,e.#e[u.cc*25]=120,e.#e[u.cc*41]=120,e.#e[u.cc*57]=120,e.#l=!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: ${se[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: ${ie[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=ce(e.#w.subarray(10,12),c,n);d&&console.debug(`${s}${q(e.#w.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.#w.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.allocateAceAll(n)},()=>{console.debug(`${s}1 depth: ${n-64}`)},()=>{console.debug(`${s}2 source: ${n}`),n&&n<96&&e.allocateAceAll(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.#H[s]?.length||(e.#H[s]=new Uint8Array(256));let i=e.#H[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,P=5,_=0;for(x-=k*4,y==3&&(P=1);_>4-_&1,_++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let $=function(t,r,f){e.dispatchEvent("mupromptex");let s=t[0],i=u.cc*r,n=u.rpn*r,c=`GS CH${r+1} `;s<3?(t.subarray(1).forEach((d,o)=>{[()=>{e.#e[i+p[0]]=d},()=>{e.#s[r]=d},()=>{let b=0;d<16?b=e.chRedir(d,f,!0):b=u.ch,e.#h[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.#v[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[u.rpnt*r+2]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},!1,()=>{e.#e[i+p[7]]=d},!1,!1,()=>{e.#e[i+p[10]]=d||128},!1,!1,()=>{console.debug(`${c}CC 1: cc${d}`)},()=>{console.debug(`${c}CC 2: cc${d}`)},()=>{e.#e[i+p[93]]=d},()=>{e.#e[i+p[91]]=d},!1,!1,()=>{e.#a[n+1]=d,e.#i[u.rpnt*r+1]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{e.#a[n+2]=d,e.#i[u.rpnt*r+1]=1,e.dispatchEvent("pitch",{part:r,pitch:e.getPitchShift(r)})},()=>{e.#e[i+p[94]]=d}][s+o-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},v=function(t,r){let f=t[0],s=`GS CH${r+1} `;f<2?t.subarray(1).forEach((i,n)=>{[()=>{e.#e[u.cc*r+p[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)=>{$(t,e.chRedir(9,r,!0),r)}).add([66,18,64,17],(t,r)=>{$(t,e.chRedir(0,r,!0),r)}).add([66,18,64,18],(t,r)=>{$(t,e.chRedir(1,r,!0),r)}).add([66,18,64,19],(t,r)=>{$(t,e.chRedir(2,r,!0),r)}).add([66,18,64,20],(t,r)=>{$(t,e.chRedir(3,r,!0),r)}).add([66,18,64,21],(t,r)=>{$(t,e.chRedir(4,r,!0),r)}).add([66,18,64,22],(t,r)=>{$(t,e.chRedir(5,r,!0),r)}).add([66,18,64,23],(t,r)=>{$(t,e.chRedir(6,r,!0),r)}).add([66,18,64,24],(t,r)=>{$(t,e.chRedir(7,r,!0),r)}).add([66,18,64,25],(t,r)=>{$(t,e.chRedir(8,r,!0),r)}).add([66,18,64,26],(t,r)=>{$(t,e.chRedir(10,r,!0),r)}).add([66,18,64,27],(t,r)=>{$(t,e.chRedir(11,r,!0),r)}).add([66,18,64,28],(t,r)=>{$(t,e.chRedir(12,r,!0),r)}).add([66,18,64,29],(t,r)=>{$(t,e.chRedir(13,r,!0),r)}).add([66,18,64,30],(t,r)=>{$(t,e.chRedir(14,r,!0),r)}).add([66,18,64,31],(t,r)=>{$(t,e.chRedir(15,r,!0),r)}).add([66,18,64,64],(t,r)=>{v(t,e.chRedir(9,r,!0))}).add([66,18,64,65],(t,r)=>{v(t,e.chRedir(0,r,!0))}).add([66,18,64,66],(t,r)=>{v(t,e.chRedir(1,r,!0))}).add([66,18,64,67],(t,r)=>{v(t,e.chRedir(2,r,!0))}).add([66,18,64,68],(t,r)=>{v(t,e.chRedir(3,r,!0))}).add([66,18,64,69],(t,r)=>{v(t,e.chRedir(4,r,!0))}).add([66,18,64,70],(t,r)=>{v(t,e.chRedir(5,r,!0))}).add([66,18,64,71],(t,r)=>{v(t,e.chRedir(6,r,!0))}).add([66,18,64,72],(t,r)=>{v(t,e.chRedir(7,r,!0))}).add([66,18,64,73],(t,r)=>{v(t,e.chRedir(8,r,!0))}).add([66,18,64,74],(t,r)=>{v(t,e.chRedir(10,r,!0))}).add([66,18,64,75],(t,r)=>{v(t,e.chRedir(11,r,!0))}).add([66,18,64,76],(t,r)=>{v(t,e.chRedir(12,r,!0))}).add([66,18,64,77],(t,r)=>{v(t,e.chRedir(13,r,!0))}).add([66,18,64,78],(t,r)=>{v(t,e.chRedir(14,r,!0))}).add([66,18,64,79],(t,r)=>{v(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=u.cc*o;[()=>{d<1||(d<101?(e.setChType(o,e.CH_MELODIC,m.x5d),e.#s[o]=d-1,e.#e[b+p[0]]=e.#c.x5):d<229?(e.setChType(o,e.CH_MELODIC,m.x5d),e.#s[o]=d-101,e.#e[b+p[0]]=56):(e.setChType(o,e.CH_DRUMS,m.x5d),e.#s[o]=be[d-229]||0,e.#e[b+p[0]]=62)),e.dispatchEvent("voice",{part:o})},()=>{e.#e[b+p[7]]=d},()=>{d<31&&(e.#e[b+p[10]]=Math.round((d-15)*4.2+64))},()=>{e.#e[b+p[93]]=G(d)},()=>{e.#e[b+p[91]]=G(d)},()=>{e.#a[o*u.rpn+3]=d>8191?d-16320:64+d,e.#i[u.rpnt*o+2]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)})},()=>{e.#a[o*u.rpn+1]=d>8191?d-16320:64+d,e.#i[u.rpnt*o+1]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)})},()=>{d>0&&(e.#a[o*u.rpn]=d,e.#i[u.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.#d[s]&&e.#d[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.#d[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]=be[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.#h[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 P=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.#h[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.#f.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.#h[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,P=b0;)e.#m[y*32+b*7+(P-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.#d[c]&&e.#d[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.#d[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.#h[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+=` +${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.#d[s]&&e.#d[s]!=m[f])if(e.#A.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${r}. Port ${String.fromCharCode(65+s)} mode "${S[e.#d[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*u.cc;switch(n%12){case 0:{i<128?(e.setChType(o,e.CH_MELODIC,m.x5d),e.#e[b+p[0]]=e.#c.x5,e.#s[o]=i):(e.setChType(o,e.CH_DRUMS,m.x5d),e.#e[b+p[0]]=62,e.#s[o]=be[i-128]),i>0&&e.setChActive(o,1),e.dispatchEvent("voice",{part:o});break}case 1:{e.#e[b+p[7]]=i;break}case 2:{e.#a[o*u.rpn+3]=i>127?i-192:64+i,e.#i[u.rpnt*o+2]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)});break}case 3:{e.#a[o*u.rpn+1]=i>127?i-192:64+i,e.#i[u.rpnt*o+1]=1,e.dispatchEvent("pitch",{part:o,pitch:e.getPitchShift(o)});break}case 4:{i<31&&(e.#e[b+p[10]]=Math.round((i-15)*4.2+64));break}case 5:{let y=i>>4,k=i&15;e.#e[b+p[91]]=G(k),e.#e[b+p[93]]=G(y);break}case 10:break;case 11:{let y=e.chRedir(i&15,r,!0),k=i>>4;e.#h[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.#l=!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.#B[d+(s-1)*16]=n,([!1,()=>{let o=e.#B[s-1<<4];if(o<3){if(e.#D[s]=1,o==2)for(let b=0;b{e.#a[s*u.rpn+3]=n+40,e.#i[u.rpnt*s+2]=1},()=>{e.#a[s*u.rpn+1]=n+14,e.#i[u.rpnt*s+1]=1},()=>{e.#a[s*u.rpn]=n,e.#i[u.rpnt*s]=1},!1,()=>{e.#e[u.cc*s+p[91]]=n?127:0},!1,()=>{e.#e[u.cc*s+p[7]]=n},()=>{e.#e[u.cc*s+p[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*u.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.#m[(y+R[26])*u.dnc+o]=Math.round(n*1.27)},()=>{e.#m[(y+R[26])*u.dnc+o]=n*9+1&127},()=>{e.#m[(y+R[26])*u.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)*u.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*u.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.#m[(y+R[26])*u.dnc+o]=Math.round(n*1.27)},()=>{e.#m[(y+R[26])*u.dnc+o]=n*9+1&127},()=>{e.#m[(y+R[26])*u.dnc+o]=n?127:0}][b]()})}else{let i=t[1];t.subarray(2).forEach((n,c)=>{let d=c+i;e.#B[d]=n;let o=e.chRedir(1+(d>>4),r,!0),b=d&15;([!1,()=>{let y=e.#B[o-1<<4];if(y<3)if(e.#D[o]=1,y==2)for(let k=0;k{e.#a[o*u.rpn+3]=n+40,e.#i[u.rpnt*o+2]=1},()=>{e.#a[o*u.rpn+1]=n+14,e.#i[u.rpnt*o+1]=1},()=>{e.#a[o*u.rpn]=n,e.#i[u.rpnt*o]=1},!1,()=>{e.#e[u.cc*o+p[91]]=n?127:0},!1,()=>{e.#e[u.cc*o+p[7]]=n},()=>{e.#e[u.cc*o+p[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)*u.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 P=u.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.#h[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.#f.ano(f+s),s&&s<10&&(e.#s[f+s]=Q[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.#l=!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.#l=!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.#l=!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*u.cc,i=t[1],n=`NS5R CH${f+1} `;t.subarray(2).forEach((c,d)=>{let o=i+d;o<3?([()=>{e.#e[s+p[0]]=c||A.bank0},()=>{e.#e[s+p[32]]=c},()=>{e.#s[f]=c}][o](),e.dispatchEvent("voice",{part:f})):o<8||(o<14?[()=>{let b=e.chRedir(c,r,!0);e.#h[f]=b,f!=b&&(e.buildRchTree(),console.info(`${n}receives from CH${b+1}`))},()=>{e.#v[f]=+!c},()=>{e.setChType(f,c,m.ns5r),console.debug(`${n}type: ${I[c]}`)},()=>{e.#a[u.rpn*f+3]=c,e.#i[u.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{},()=>{}][o-8]():o<16||(o<33?[()=>{e.#e[s+p[7]]=c},()=>{e.#e[s+p[11]]=c},()=>{},()=>{},()=>{e.#e[s+p[10]]=c||128},()=>{},()=>{},()=>{e.#e[s+p[93]]=c},()=>{e.#e[s+p[91]]=c},()=>{e.#e[s+p[76]]=c},()=>{e.#e[s+p[77]]=c},()=>{e.#e[s+p[78]]=c},()=>{e.#e[s+p[74]]=c},()=>{e.#e[s+p[71]]=c},()=>{e.#e[s+p[73]]=c},()=>{e.#e[s+p[75]]=c},()=>{e.#e[s+p[72]]=c}][o-16]():o<112||o<114&&[()=>{e.#e[s+p[5]]=c},()=>{e.#e[s+p[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.#$.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,P=b0;)e.#$[y*32+b*7+(P-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.#l=!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.#l=!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.#d[c]&&e.#d[c]!=m.ns5r)if(e.#A.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${r}. Port ${String.fromCharCode(65+c)} mode "${S[e.#d[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*u.cc;switch(o%92){case 0:{e.#e[y+p[0]]=d,e.dispatchEvent("voice",{part:b});break}case 1:{e.#e[y+p[32]]=d,!d&&!e.#e[y+p[0]]&&(e.#e[y+p[0]]=A.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.#h[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*u.rpn+3]=d<40||d>88?d+(d>63?-192:64):d,e.#i[u.rpnt*b+2]=1,e.dispatchEvent("pitch",{part:b,pitch:e.getPitchShift(b)});break}case 9:case 10:{e.#e[y+p[7]]=d;break}case 11:{e.#e[y+p[11]]=d;break}case 14:{e.#e[y+p[10]]=d||128;break}case 19:{e.#e[y+p[93]]=d;break}case 20:{e.#e[y+p[91]]=d;break}case 84:{e.#e[y+p[65]]=d;break}case 85:{e.#e[y+p[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.#l[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.#h[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.#h[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.#h[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.#d[s]&&e.#d[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.#d[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.#h[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: +${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.#l=!1,e.#o[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=u.cc*s,n=u.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+p[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.#h[s]=o,s!=o&&(e.buildRchTree(),console.info(`${d}receives from CH${o+1}`))},()=>{e.#e[i+p[7]]=c},()=>{uupThis.setChActive(s,c)},()=>{e.#e[i+p[10]]=c},()=>{e.#a[n+3]=c+40,e.#i[u.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[u.rpnt*s+1]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{e.#e[i+p[91]]=c?127:0},()=>{},()=>{e.#e[i+p[74]]=c},()=>{e.#e[i+p[73]]=c},()=>{e.#e[i+p[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*u.cc;[()=>{s<128?(e.setChType(i,e.CH_MELODIC,m.k11),e.#e[n+p[0]]=0,e.#e[n+p[32]]=0,e.#s[i]=s):s<160?(e.setChType(i,e.CH_MELODIC,m.k11),e.#e[n+p[0]]=0,e.#e[n+p[32]]=7,e.#s[i]=s-100):(e.setChType(i,e.CH_DRUMS,m.k11),e.#e[n+p[0]]=122,e.#e[n+p[32]]=0,e.#s[i]=s-160),e.dispatchEvent("voice",{part:i})},()=>{let c=e.chRedir(s,r,!0);e.#h[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*u.cc,c=i*u.rpn,d=`GMLX CH${i+1} `;[()=>{e.setChActive(i,s)},()=>{e.#e[n+p[7]]=s},()=>{e.#e[n+p[10]]=s},()=>{e.#e[n+p[91]]=s?127:0},()=>{e.#a[c+3]=s+40,e.#i[u.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{e.#a[c+1]=s,e.#i[u.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{e.#a[c]=s,e.#i[u.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.#h[i]=n,i!=n&&(e.buildRchTree(),console.info(`SG CH${i+1} receives from CH${n+1}`))}else t[1]==19&&(e.#e[u.cc*i+p[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.#S.add([127,0],(t,r,f)=>{e.switchMode("motif");let s=new Uint8Array([127,1,...t]);e.#S.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.#d[s]&&e.#d[s]!=e.#c.smotif)if(e.#A.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${r}. Port ${String.fromCharCode(65+s)} mode "${S[e.#d[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=u.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+p[0]]=o,e.dispatchEvent("voice",{part:i})},()=>{o&&e.setChActive(i,1),e.#e[n+p[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.#h[i]=y,i!=y&&(e.buildRchTree(),console.info(`${d}receives from CH${y+1}`))},()=>{e.#v[i]=o?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{o!=100&&e.setChActive(i,1),e.#e[n+p[7]]=o},()=>{o!=64&&e.setChActive(i,1),e.#e[n+p[10]]=o},!1,!1,!1,()=>{e.#e[n+p[91]]=o},()=>{o&&e.setChActive(i,1),e.#e[n+p[93]]=o},()=>{o&&e.setChActive(i,1),e.#e[n+p[94]]=o},()=>{o!=127&&e.setChActive(i,1),e.#e[n+p[128]]=o,e.allocateAce(i,128)},()=>{},()=>{o!=64&&e.setChActive(i,1),e.#e[n+p[74]]=o},()=>{o!=64&&e.setChActive(i,1),e.#e[n+p[71]]=o},!1,()=>{e.#e[n+p[65]]=o},()=>{e.#e[n+p[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=L[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: %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],d=n*u.cc;t.subarray(2).forEach((o,b)=>{let y=c+b;y<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[d+p[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+p[32]]=o,e.dispatchEvent("voice",{part:n})},()=>{e.#s[n]=o,e.dispatchEvent("voice",{part:n})},()=>{e.#e[d+p[7]]=o},()=>{e.#e[d+p[10]]=o},()=>{},()=>{},()=>{o<2&&(e.#v[n]=o)},()=>{o<2&&(e.#e[d+p[68]]=o?127:0)},()=>{},()=>{o<2&&(e.#e[d+p[65]]=o?127:0)},()=>{e.#e[d+p[5]]=o&15<<4|e.#e[d+p[5]]&15},()=>{e.#e[d+p[5]]=o&15|(e.#e[d+p[5]]&240)>>4},()=>{e.#e[d+p[74]]=o},()=>{e.#e[d+p[71]]=o},()=>{e.#e[d+p[73]]=o},()=>{e.#e[d+p[72]]=o},0,0,0,0,0,0,0,()=>{e.#e[d+p[128]]=o,e.allocateAce(128)},()=>{e.#e[d+p[93]]=o},()=>{e.#e[d+p[91]]=o},0,0,()=>{e.#e[d+p[75]]=o},()=>{e.#e[d+p[76]]=o},()=>{e.#e[d+p[77]]=o},()=>{e.#e[d+p[78]]=o}][y]||(()=>{}))():y<63||(y<64?(e.#r[n]?e.#e[d+p[0]]=104|o:e.#e[d+p[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.#d[s]&&e.#d[s]!=m.krs)if(e.#L.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+s)} mode "${S[e.#d[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.#h[b]=x,console.info(`${i}CH${b+1} receives from CH${x+1}`)},!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{et as OctaviaDevice,p as allocated,u as ccToPos,R as dnToPos}; +%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.#d[s]&&e.#d[s]!=m.krs)if(e.#A.dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+s)} mode "${S[e.#d[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=u.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+p[0]]=63,e.#e[k+p[32]]=c):c<20?(e.#e[k+p[0]]=121,e.#e[k+p[32]]=c-10):c<24&&(e.#e[k+p[0]]=[120,0,56,62][c-20],e.#e[k+p[32]]=0),e.dispatchEvent("voice",{part:b})},()=>{let x=e.chRedir(c&15,r,!0);e.#h[b]=x,console.info(`${i}CH${b+1} receives from CH${x+1}`)},!1,!1,()=>{e.#e[k+p[7]]=c},!1,()=>{},()=>{},!1,!1,!1,!1,!1,()=>{e.#e[k+p[10]]=c||128}][y]||(()=>{}))():y<36||([()=>{e.#e[k+p[74]]=(c+128&255)-64},()=>{e.#e[k+p[71]]=(c+128&255)-64},!1,!1,()=>{e.#e[k+p[73]]=(c+128&255)-64},()=>{e.#e[k+p[75]]=(c+128&255)-64},!1,()=>{e.#e[k+p[72]]=(c+128&255)-64}][y]||(()=>{}))()}}),n=n.trimRight(),e.dispatchEvent("metacommit",{type:"EORTitle",data:n})})}};export{et as OctaviaDevice,u as allocated,p as ccToPos,R as dnToPos,A as overrides}; diff --git a/dist/state_skim.mjs b/dist/state_skim.mjs index 7226e97d..d2b5b458 100644 --- a/dist/state_skim.mjs +++ b/dist/state_skim.mjs @@ -1,9 +1,9 @@ -var N=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=N(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&&N(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&&(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*, +var N=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 g=N(t,this.pool[c]);switch(g){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 ${g}.`)}}i=i>>1,l--}let u=!0;if(c>=this.pool.length)u=!1;else{let g=this;this.pool[c].forEach(function(s,o,n){u&&s!=t[o]&&(u=!1)}),!u&&N(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 D=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},T=function(e){let t=0;return e.forEach(a=>{t*=256,t+=a}),t},v=new TextDecoder,P=new B;P.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,g=[],s=0;for(;u;){let o=t.subarray(c);([()=>{v.decode(o.subarray(0,4))=="YSFC"?(c+=80,l=1):c++},()=>{if(z(o.subarray(0,4),r))g.forEach((n,b,y)=>{let p=T(t.subarray(n.start+4,n.start+8));n.length=p}),l=2;else{let n=v.decode(o.subarray(0,4)),b=T(o.subarray(4,8));g.push({type:n,start:b}),c+=8}},()=>{let n=g[s],b=t.subarray(n.start,n.start+n.length),y=32;switch(n.type){case"ENVC":{let p=i;for(;p=g.length&&(l=3,u=!1)}][l]||(()=>{u=!1}))()}return a});P.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=[],g=0;for(;l;){let s=t.subarray(r);([()=>{l=v.decode(s.subarray(0,4))=="INI2",c=s[15],r+=16,i=1},()=>{let o=v.decode(s.subarray(0,4)),n=s[5],b=s[7],y=s[11],p=T(s.subarray(12,16)),E=T(s.subarray(16,20)),m=T(s.subarray(36,40)),d=v.decode(s.subarray(44,44+y));u.push({type:o,tipMsb:n,tipLsb:b,nameLen:y,length:p,start:E,entryLen:m,name:d}),r+=64,c--,c<1&&(i=2)},()=>{let o=u[g],n=t.subarray(o.start,o.start+o.length);switch(o.type){case"PRG1":break;case"PBK1":{let b=63,y=(o.tipMsb?6:0)+o.tipLsb;for(let p=0;p<128;p++){let E=p*o.entryLen,m=n.subarray(E,E+o.entryLen),d=v.decode(m.subarray(0,24)).trimEnd().replace("InitProg","");d.length&&y>5&&(a+=` +${b.toString().padStart(3,"0")} ${y.toString().padStart(3,"0")} ${p.toString().padStart(3,"0")} ${d}`)}break}case"CBK1":{let b=63,y=(o.tipMsb?3:0)+o.tipLsb+10;for(let p=0;p<128;p++){let E=p*o.entryLen,m=n.subarray(E,E+o.entryLen),d=v.decode(m.subarray(0,24)).trimEnd().replace("InitCombi","");d.length&&y>12&&(a+=` +${b.toString().padStart(3,"0")} ${y.toString().padStart(3,"0")} ${p.toString().padStart(3,"0")} ${d}`)}break}}g++,g>=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 Q=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),W={};`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 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 I=r.#t[b];if(!I[n<<7|g]||t){let $={msb:n,prg:b,lsb:g,name:m,poly:E,type:f,drum:y};I[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 x=["?","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={};x.forEach((e,t)=>{v[e]=t});var d={length:L.length};L.forEach((e,t)=>{d[e]=t});var S=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)),S(),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);#S=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.#S[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(S()&&console.debug(`${x[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],S()&&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),S()&&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&&(S()&&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,S()&&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.#S[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;S()&&console.debug(e)}};#Y={64:(e,t,a)=>{this.#I.run(t,a,e)},65:(e,t,a)=>{if(t[0]<16)this.#x.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.#x.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.#N.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;#x;#D;#I;#N;#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 x[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;x[this.#t]=="ns5r"&&i>0&&i<56&&(l=3);let u=this.userBank.get(i,c,l,r);if(x[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]],x[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.#S.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 +`).forEach(e=>{let t=e.split(",");W[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 O=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var A=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,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:A.length};A.forEach((e,t)=>{j[e]=t});var ee={length:O.length};O.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:A.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:O.length,dnc:128,ext:3,efx:7,cvn:12,redir:32,invalidCh:255};var ae=["MSB","PRG","LSB","NME","ELC","DRM"],U=function(e){let t=Math.floor(e/10),a=e%10;return`${t.toString(16)}${a}`},R=class{#t;strictMode=!1;get(e=0,t=0,a=0,r){let i=[e,t,a],c,l=1,u=0,g,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="",y=0,p=0;switch(s[0]){case 0:{switch(s[2]){case 127:{r=="xg"?n="GM-a":(n="MT-a",b="C/M");break}case 126:{r=="xg"?n="GM-n":(n="MT-b",b="C/M");break}case 7:{n="GM-k",b="GLX";break}case 5:{n="SG-a",b="000";break}case 4:{r=="gs"||r=="sc"?(n="GM-a",b="000"):(n="SP-l",b="C/M");break}case 3:case 2:case 1:{(r=="gs"||r=="sc")&&(n="GM-a",b="000");break}case 0:{n="GM-a";break}default:n="y",y=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]}`,y=3);break}case 48:{b=`M${(s[2]>>3).toString().padStart(2,"0")}`,n=`y${b}`,y=1;break}case 56:{n="GM-b";break}case 57:n=["yDOC","QY10","QY20"][s[2]-112]||"yMxv",b=["DOC","QY1","QY2"][s[2]-112]||"057";case 61:case 120:{n="rDrm";break}case 62:{n="kDrm";break}case 63:{if(s[2]<17){let $=s[2];n=$<10?"kP:":"kC:",n+=$%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";y=1;break}case 64:{n="ySFX",b="SFX";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?p=63:s[2]>>4==1&&(p=16),y=3;break}case 97:{n=s[2]>>4==1?"SDa":"VL:",y=3,s[2]>>4==1?p=16:p=112;break}case 98:{n=s[2]>>4==1?"SDb":"SG-a",y=3,p=16;break}case 99:{n=s[2]>>4==1?"SDc":"DX",s[2]>63?p=63:s[2]>>4==1&&(p=16),y=3;break}case 100:{n="AN",s[2]>63?p=63:s[2]>>4==1&&(p=16),y=3;break}case 104:case 105:case 106:case 107:{n="SDd",p=104;break}case 121:{n=`GM-${s[2]?"":"a"}`,y=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]][y]-p}`.padStart(4-n.length,"0")),b.length<3&&(b+=`${[e,a,e,a][y]}`.padStart(3-b.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 E=[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 $=this.#t[s[1]||0][(s[0]<<7)+s[2]];l=$?.poly||l,u=$?.type||u,g=$?.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 $=this.#t[s[1]||0][(s[0]<<7)+s[2]];l=$?.poly||l,u=$?.type||u,g=$?.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 m=[s[0],s[1],s[2]];switch(o){case"^":{switch(r){case"gs":case"sc":case"ns5r":{o=" ";break}}e==127&&o=="^"&&(o=" ");break}}let d="??";switch(s[0]){case 0:{s[2]==0?d="GM":s[2]==5||s[2]==7?d="KG":s[2]<126?d="XG":s[2]==127&&(d="MT");break}case 32:case 33:case 35:case 36:{s[2]>4?d=["AP","VL","PF","DX","AN"][s[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:{s[2]<17?d="KR":s[2]<34?d="ES":d="DS";break}case 64:case 126:{d="XG";break}case 67:case 99:{d=s[2]>>4==1?"SD":"DX";break}case 81:{d="RW";break}case 95:{d=["DR","PC"][s[2]];break}case 96:{d=s[2]==106?"AP":s[2]>>4==1?"SD":"PF";break}case 97:{d=s[2]>>4==1?"SD":"VL";break}case 98:{d=s[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=s[2]?"G2":"GM";break}case 122:{d="KG";break}case 127:{d=s[2]==127?"MT":t==0?"GM":"XG";break}default:s[0]<48&&(s[0]==16&&r=="xg"?d="XG":d="GS")}return o!=" "&&(r=="krs"||self.debugMode)&&(c="",d="KR"),{name:c||`${U(e||0)} ${U(t||0)} ${U(a||0)}`,poly:l,type:u,drum:g,iid:E,eid:m,sid:i,ending:o,sect:n,bank:b,standard:d,mode:r}}async load(e,t,a="(internal)"){let r=this,i=[],c=0,l=0;e.split(` +`).forEach(function(u,g){let s=u.split(" "),o=[];if(g==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,y=0,p,E=1,m=0,d;s.forEach(async function(w,K){switch(K){case i[0]:{n=parseInt(w);break}case i[1]:{b=parseInt(w);break}case i[2]:{y=parseInt(w);break}case i[3]:{p=w;break}case i[4]:{w=parseInt(w),w<16?E=w+1:m=(w&15)+1;break}case i[5]:{d=w;break}}}),r.#t[b]=r.#t[b]||[];let $=r.#t[b];if(!$[n<<7|y]||t){let w={msb:n,prg:b,lsb:y,name:p,poly:E,type:m,drum:d};$[n<<7|y]=w,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 g=t[0];g<=t[1];g++)delete this.#t[g][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 x=["?","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]],M=[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"},L={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 I=[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 S={};x.forEach((e,t)=>{S[e]=t});var f={length:I.length};I.forEach((e,t)=>{f[e]=t});var C=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)),C(),t},F=function(e,t="",a="",r=2){return e?`${t}${e.toString().padStart(r,"0")}${a}`:""},h={ch:128,cc:I.length,nn:128,pl:512,tr:256,cmt:14,rpn:6},et=class extends D{#t=0;#w=0;#b=0;#g=new Array(11);get#h(){return this.#g[this.#w]}set#h(e){this.#g[this.#w]=e}#y=new Uint8Array(h.ch);#B=new Uint8Array(h.ch);#e=new Uint8ClampedArray(h.ch*h.cc);#E=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;#m=0;#_=500;#z=0;#s="";#p=0;#q=0;#Q=!0;#r=!1;#X;#W=new Uint8Array(2);#a=[];#$=new Uint8Array(h.ch);#v=new Uint8Array(h.tr);baseBank=new R("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new R("gm");initOnReset=!1;chRedir(e,t,a){if(this.#v[t])return(this.#v[t]-1)*16+e;if([S.gs,S.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+f[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.#y[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.#y[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+f[1]]=0,this.#e[r+f[5]]=0,this.#e[r+f[64]]=0,this.#e[r+f[65]]=0,this.#e[r+f[66]]=0,this.#e[r+f[67]]=0,this.#e[r+f[11]]=127,this.#e[r+f[101]]=127,this.#e[r+f[100]]=127,this.#e[r+f[99]]=127,this.#e[r+f[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(f[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(e.data[0]){case 0:{if(C()&&console.debug(`${x[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==S.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==S.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==S.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+f[99]],i=this.#e[a+f[98]];if(r==1){let c=se.indexOf(i);if(c>-1)this.#e[a+f[71+c]]=e.data[1],C()&&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),C()&&console.debug(`CH${t+1} voice NRPN ${i} commit`)}}}else{let r=L[this.#e[a+f[100]]];this.#e[a+f[101]]==0&&r!=null&&(C()&&console.debug(`CH${t+1} RPN 0 ${this.#e[a+f[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],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&&L[this.#e[a+100]]!=null&&(this.#l[t*h.rpn+L[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+f[e.data[0]]]=e.data[1]}},12:function(e){let t=e.channel;this.#y[t]=1,this.#E[t]=e.data,this.#A[t]=0,C()&&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.#m=0),re.indexOf(e.meta)>-1)return e.reply="meta",e;C()&&console.debug(e)}};#Y={64:(e,t,a)=>{this.#I.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.#N.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;#I;#N;#J;buildRchTree(){let e=[];this.#B.forEach((t,a)=>{e[t]?.constructor||(e[t]=[]),e[t].push(a)}),this.#X=e}getActive(){let e=this.#y.slice();return this.#t==S.mt32,e}getCc(e){let t=e*h.cc,a=this.#e.slice(t,t+h.cc);return a[f[0]]=a[f[0]]||this.#k,a[f[32]]=a[f[32]]||this.#u,a}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&t.set(l,{v:a.#o[r],s:a.#f[i]})}),t}getBitmap(){return{bitmap:this.#h,expire:this.#b}}getLetter(){return{text:this.#s,expire:this.#p}}getMode(){return x[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+f[7]]*t.#e[r*h.cc+f[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;x[this.#t]=="ns5r"&&i>0&&i<56&&(l=3);let u=this.userBank.get(i,c,l,r);if(x[this.#t]=="mt32"&&u.name.indexOf("MT-m:")==0){let g=parseInt(u.name.slice(5)),s=g*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+f[0]],this.#E[e],this.#e[e*h.cc+f[32]],x[this.#t]);if(this.#A[e])switch(this.#t){case S.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.#m=0,this.#y.fill(0),this.#e.fill(0),this.#E.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.#Q=!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]=M[0],this.#e[h.cc*25]=M[0],this.#e[h.cc*41]=M[0],this.#e[h.cc*57]=M[0],this.#W.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]=M[a]);switch(this.initOnReset,a){case S.mt32:{mt32DefProg.forEach((r,i)=>{let c=i+1;this.#y[c]||(this.#E[c]=r,this.#e[c*h.cc+f[91]]=127)});break}}this.dispatchEvent("mode",e)}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#d.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#V[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),a=!1;this.#X[t]?.forEach(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 k,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,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.#x=new w,this.#D=new w,this.#I=new w,this.#N=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.#x.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.#x.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.#I.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.#N.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}; +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.#m<1&&this.#a.unshift(`TrkTitle: ${t}`)},this.#n[4]=function(t,a){this.#a.unshift(`${F(this.#m,""," ")}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.#m,""," ")}C.Marker: ${t}`)},this.#n[7]=function(t){this.#a.unshift(`CuePoint: ${t}`)},this.#n[32]=function(t){this.#m=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 k,this.#L=new k,this.#R=new k,this.#S=new k,this.#D=new k,this.#I=new k,this.#N=new k,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,g=(u*3+l)*7,s=7,o=0;for(g-=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.#E[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.#I.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.#N.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,f as ccToPos}; diff --git a/dist/xp_basic.mjs b/dist/xp_basic.mjs index 5c246450..be0a380e 100644 --- a/dist/xp_basic.mjs +++ b/dist/xp_basic.mjs @@ -1,10 +1,10 @@ -var Mr=Object.create;var At=Object.defineProperty;var Pr=Object.getOwnPropertyDescriptor;var Rr=Object.getOwnPropertyNames;var Dr=Object.getPrototypeOf,Or=Object.prototype.hasOwnProperty;var Ar=(g,e,a)=>e in g?At(g,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):g[e]=a;var Kt=(g,e)=>()=>(g&&(e=g(g=0)),e);var Ir=(g,e)=>()=>(e||g((e={exports:{}}).exports,e),e.exports);var Lr=(g,e,a,h)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of Rr(e))!Or.call(g,c)&&c!==a&&At(g,c,{get:()=>e[c],enumerable:!(h=Pr(e,c))||h.enumerable});return g};var Ur=(g,e,a)=>(a=g!=null?Mr(Dr(g)):{},Lr(e||!g||!g.__esModule?At(a,"default",{value:g,enumerable:!0}):a,g));var P=(g,e,a)=>(Ar(g,typeof e!="symbol"?e+"":e,a),a),zt=(g,e,a)=>{if(!e.has(g))throw TypeError("Cannot "+a)};var t=(g,e,a)=>(zt(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)},k=(g,e,a,h)=>(zt(g,e,"write to private field"),h?h.call(g,a):e.set(g,a),a);var qt=Kt(()=>{"use strict";U();(function(){var g=function(v,S,r){var n,l;if(self.MessageEvent)switch(v){case"message":{l=new MessageEvent(v,{data:S,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=S,r.source&&Object.defineProperty(l,"source",{value:r.source}),(n=r.ports)!=null&&n.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={},c=function(v){var S,r=this;if((this==null?void 0:this.constructor)!=c)throw new TypeError("Illegal constructor");a.push(this),(S=h[v])!=null&&S.constructor||(h[v]=[]),h[v].push(this);var n=Math.floor(Math.random()*281474976710656),l=[],i=0,s=[],o=!0,d=!1;Object.defineProperty(this,"id",{get:function(){return n}}),Object.defineProperty(this,"name",{value:v}),this.close=function(){var f,$=a.indexOf(r);$>-1?(e.postMessage({t:"d",c:v,i:n}),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:n,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(o){for(e.postMessage({t:"r",c:v,i:n}),console.debug("[Snowy] ".concat(s.length," message(s) in cache."));s.length;){var f=s.shift();r.postMessage(f)}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(f){f.c==v?f.i!=n&&r.dispatchEvent(g("message",f.d,{source:r})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(n," 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=c,p=function(){if(e){e.addEventListener("message",function(S){var r=S.data,n=!1;switch(r.t){case"k":{n=!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";qt();{let g=function(e,a){let h=new FileReader;return new Promise((c,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",()=>{c(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,c=this,p=[];for(;a-1;){let y=c.lastIndexOf(g);p.unshift(c.slice(y+g.length)),c=c.slice(0,y),y==0&&p.unshift(""),a++}return c.length&&p.unshift(c),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,c){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,c);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(h,c){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(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;c=c||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){c(a.Uint8(new Uint8Array(v.target.result)))}})},Base64:function(h){let c=function(v){var S="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,n="",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 n}(h=String(h));var p=c.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 o||"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 o=1;o<=s.length;o++)l+=s[s.length-o]*Math.pow(128,o);l+=i}return l}};if(c.data=new DataView(y.buffer,y.byteOffset,y.byteLength),c.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;c.readInt(4);let p={};p.formatType=c.readInt(2),p.tracks=c.readInt(2),p.track=[];var y=c.readInt(1),v=c.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 S,r=c.readInt(4);if(r===-1)break;if(r!==1297379947)return!1;c.readInt(4);let i=0,s=!1,o,d;for(;!s&&(i++,p.track[l-1].event[i-1]={},p.track[l-1].event[i-1].deltaTime=c.readIntVLV(),(o=c.readInt(1))!==-1);)if(128<=o?d=o:(o=d,c.movePointer(-1)),o===255){p.track[l-1].event[i-1].type=255,p.track[l-1].event[i-1].metaType=c.readInt(1);var n=c.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=c.readStr(n);break;case 33:case 89:case 81:p.track[l-1].event[i-1].data=c.readInt(n);break;case 84:p.track[l-1].event[i-1].data=[],p.track[l-1].event[i-1].data[0]=c.readInt(1),p.track[l-1].event[i-1].data[1]=c.readInt(1),p.track[l-1].event[i-1].data[2]=c.readInt(1),p.track[l-1].event[i-1].data[3]=c.readInt(1),p.track[l-1].event[i-1].data[4]=c.readInt(1);break;case 88:p.track[l-1].event[i-1].data=[],p.track[l-1].event[i-1].data[0]=c.readInt(1),p.track[l-1].event[i-1].data[1]=c.readInt(1),p.track[l-1].event[i-1].data[2]=c.readInt(1),p.track[l-1].event[i-1].data[3]=c.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,c,n)),this.customInterpreter!==null&&p.track[l-1].event[i-1].data!==!1||(c.readInt(n),p.track[l-1].event[i-1].data=c.readInt(n),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[l-1].event[i-1].type=parseInt(o[0],16),p.track[l-1].event[i-1].channel=parseInt(o[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,c,!1)),this.customInterpreter!==null&&p.track[l-1].event[i-1].data!==!1||(S=c.readIntVLV(),p.track[l-1].event[i-1].data=c.readInt(S),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]=c.readInt(1),p.track[l-1].event[i-1].data[1]=c.readInt(1);break;case 12:case 13:p.track[l-1].event[i-1].data=c.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,c,!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 Gt<"u")Gt.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,Wt,Mt=(Wt=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 c;let a=new Event(g),h=this;a.data=e,((c=t(this,te)[g])==null?void 0:c.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,Wt);U();U();var Qt=function(g,e){let a=Math.min(g.length,e.length),h=g.slice(0,a),c=e.slice(0,a),p=0,y=0;for(;y0){let h=this.pool.length,c=1<=1&&y>=0;){if(y<=0)throw new Error("TTL reached.");if(p==h)p-=c;else{let S=Qt(e,this.pool[p]);switch(S){case 0:{y=0;break}case 1:{p+c<=h&&(p+=c);break}case-1:{p!=0&&(p-=c);break}default:console.warn(`Unexpected result ${S}.`)}}c=c>>1,y--}let v=!0;if(p>=this.pool.length)v=!1;else{let S=this;this.pool[p].forEach(function(r,n,l){v&&r!=e[n]&&(v=!1)}),!v&&Qt(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 Br=["MSB","PRG","LSB","NME","ELC","DRM"],It=function(g){let e=Math.floor(g/10),a=g%10;return`${e.toString(16)}${a}`},J,Yt,Lt=(Yt=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 c=[g,e,a],p,y=1,v=0,S,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 n=" ",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")}`,n=" "):g==35&&a>>1==2&&(p=`DXCH_${(((r[2]&1)<<7)+e+1).toString().padStart(3,"0")}`,n=" "));let o=[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,S=w==null?void 0:w.drum}else if(this.strictMode)p="",n="?";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,n="^"):r[2]<1?(r[0]=0,n="*"):(r[2]--,n="^");else if(g==48)r[0]=0,r[2]=0,n="!";else if(g==62)r[1]--,n=" ",r[1]<1&&!(p!=null&&p.length)&&(r[0]=0,n="!");else if(g<63)r[0]==0?(r[2]=0,n="^"):r[2]<1?(r[0]=0,n="*"):r[2]--;else if(g==80)p=`PrgU:${e.toString().padStart(3,"0")}`,n="!";else if(g==88)p=`CmbU:${e.toString().padStart(3,"0")}`,n="!";else if(g==121)p=`GM2Vox0${a}`,n="#";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){n=" ";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,S=w==null?void 0:w.drum}else p="",n="*";}else r[1]==0?(p=`${g.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${a.toString().padStart(3,"0")}`,n="!"):r[0]==0?(r[2]=0,n="^"):r[2]>0?r[2]--:r[1]>0?(r[1]=0,n="!"):(r[0]=0,n="?");let d=[r[0],r[1],r[2]];(h=="gs"||h=="sc"||h=="ns5r")&&n=="^"&&(n=" "),g==127&&n=="^"&&(n=" "),n!=" "&&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:S,iid:o,eid:d,sid:c,ending:n,sect:l,standard:u}}async load(g,e,a="(internal)"){let h=this,c=[],p=0,y=0;g.split(` -`).forEach(function(v,S){let r=v.split("\t"),n=[];if(S==0){if(r.forEach(function(l,i){c[Br.indexOf(l)]=i}),c.length<4){console.debug("Debugger launched.");debugger}}else{let l=0,i=0,s=0,o,d=1,u=0,f;r.forEach(async function(w,C){switch(C){case c[0]:{l=parseInt(w);break}case c[1]:{i=parseInt(w);break}case c[2]:{s=parseInt(w);break}case c[3]:{o=w;break}case c[4]:{w=parseInt(w),w<16?d=w+1:u=(w&15)+1;break}case c[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:o,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 c=a[0];c<=a[1];c++){let p=c<<7;for(let y=h[0];y<=h[1];y++){let v=p+y;for(let S=e[0];S<=e[1];S++)delete t(this,J)[S][v]}}}init(){k(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,Yt);U();U();var it,jt,Zt=(jt=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,jt);var Nr=function(g,e){let a=!0;return e.forEach((h,c)=>{a=a&&g[c]==h}),a},gt=function(g){let e=0;return g.forEach(a=>{e*=256,e+=a}),e},ve=new TextDecoder,bt=new Zt;bt.set("s7e",async function(g){let e=new Uint8Array(await g.slice(0,65536).arrayBuffer()),a="MSB\tLSB\tPRG\tNME",h=[0,0,0,0],c=32,p=0,y=0,v=!0,S=[],r=0;for(;v;){let n=e.subarray(p);([()=>{ve.decode(n.subarray(0,4))=="YSFC"?(p+=80,y=1):p++},()=>{if(Nr(n.subarray(0,4),h))S.forEach((l,i,s)=>{let o=gt(e.subarray(l.start+4,l.start+8));l.length=o}),y=2;else{let l=ve.decode(n.subarray(0,4)),i=gt(n.subarray(4,8));S.push({type:l,start:i}),p+=8}},()=>{let l=S[r],i=e.subarray(l.start,l.start+l.length),s=32;switch(l.type){case"ENVC":{let o=c;for(;o=S.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\tLSB\tPRG\tNME",h=100,c=0,p=0,y=!0,v=[],S=0;for(;y;){let r=e.subarray(h);([()=>{y=ve.decode(r.subarray(0,4))=="INI2",p=r[15],h+=16,c=1},()=>{let n=ve.decode(r.subarray(0,4)),l=r[5],i=r[7],s=r[11],o=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:n,tipMsb:l,tipLsb:i,nameLen:s,length:o,start:d,entryLen:u,name:f}),h+=64,p--,p<1&&(c=2)},()=>{let n=v[S],l=e.subarray(n.start,n.start+n.length);switch(n.type){case"PRG1":break;case"PBK1":{let i=63,s=(n.tipMsb?6:0)+n.tipLsb;for(let o=0;o<128;o++){let d=o*n.entryLen,u=l.subarray(d,d+n.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")} ${o.toString().padStart(3,"0")} ${f}`)}break}case"CBK1":{let i=63,s=(n.tipMsb?3:0)+n.tipLsb+10;for(let o=0;o<128;o++){let d=o*n.entryLen,u=l.subarray(d,d+n.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")} ${o.toString().padStart(3,"0")} ${f}`)}break}}S++,S>=v.length&&(c=3,y=!1)}][c]||(()=>{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"],Hr=[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],Jt=[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],er=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},tr=function(g){return g>105?Hr[g-106]:g>100?g*1.1-100:g/10},rr=",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 Ta=Object.create;var Ot=Object.defineProperty;var Ma=Object.getOwnPropertyDescriptor;var Pa=Object.getOwnPropertyNames;var Ra=Object.getPrototypeOf,Da=Object.prototype.hasOwnProperty;var Aa=(g,e,r)=>e in g?Ot(g,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):g[e]=r;var Ft=(g,e)=>()=>(g&&(e=g(g=0)),e);var Oa=(g,e)=>()=>(e||g((e={exports:{}}).exports,e),e.exports);var Ia=(g,e,r,h)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Pa(e))!Da.call(g,n)&&n!==r&&Ot(g,n,{get:()=>e[n],enumerable:!(h=Ma(e,n))||h.enumerable});return g};var La=(g,e,r)=>(r=g!=null?Ta(Ra(g)):{},Ia(e||!g||!g.__esModule?Ot(r,"default",{value:g,enumerable:!0}):r,g));var P=(g,e,r)=>(Aa(g,typeof e!="symbol"?e+"":e,r),r),Kt=(g,e,r)=>{if(!e.has(g))throw TypeError("Cannot "+r)};var t=(g,e,r)=>(Kt(g,e,"read from private field"),r?r.call(g):e.get(g)),T=(g,e,r)=>{if(e.has(g))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(g):e.set(g,r)},S=(g,e,r,h)=>(Kt(g,e,"write to private field"),h?h.call(g,r):e.set(g,r),r);var zt=Ft(()=>{"use strict";L();(function(){var g=function(v,x,a){var c,l;if(self.MessageEvent)switch(v){case"message":{l=new MessageEvent(v,{data:x,ports:a==null?void 0:a.ports}),Object.defineProperty(l,"source",{value:a==null?void 0:a.source});break}default:l=new Event(v)}else l=document.createEvent("Event"),l.initEvent(v,!1,!1),a&&v=="message"&&(l.data=x,a.source&&Object.defineProperty(l,"source",{value:a.source}),(c=a.ports)!=null&&c.length&&Object.defineProperty(l,"ports",{value:a.ports}));return l};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),r=[],h={},n=function(v){var x,a=this;if((this==null?void 0:this.constructor)!=n)throw new TypeError("Illegal constructor");r.push(this),(x=h[v])!=null&&x.constructor||(h[v]=[]),h[v].push(this);var c=Math.floor(Math.random()*281474976710656),l=[],s=0,i=[],o=!0,d=!1;Object.defineProperty(this,"id",{get:function(){return c}}),Object.defineProperty(this,"name",{value:v}),this.close=function(){var f,$=r.indexOf(a);$>-1?(e.postMessage({t:"d",c:v,i:c}),r.splice($,1),(f=h[v])!=null&&f.constructor&&($=h[v].indexOf(a),$>-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:s,d:f}),s++,s>4294967295&&(s=0)}else i.push(f),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(o){for(e.postMessage({t:"r",c:v,i:c}),console.debug("[Snowy] ".concat(i.length," message(s) in cache."));i.length;){var f=i.shift();a.postMessage(f)}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(f){f.c==v?f.i!=c&&a.dispatchEvent(g("message",f.d,{source:a})):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:a}),Object.defineProperty(f,"currentTarget",{value:a}),($=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(x){var a=x.data,c=!1;switch(a.t){case"k":{c=!1,e.postMessage({t:"k"});break}case"m":{var l=h[a.c];if(l!=null&&l.length)for(var s=0;s{"use strict";zt();{let g=function(e,r){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)}),r.toLowerCase()){case"arraybuffer":case"buffer":{h.readAsArrayBuffer(e);break}case"string":case"text":{h.readAsText(e);break}default:p(new Error(`Unknown target ${r}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return g(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return g(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(g,e){let r=0,h=16,n=this,p=[];for(;r-1;){let y=n.lastIndexOf(g);p.unshift(n.slice(y+g.length)),n=n.slice(0,y),y==0&&p.unshift(""),r++}return n.length&&p.unshift(n),p.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(g,e){if(e){let r=this;for(;r.length{L();(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")],r={debug:!1,parse:function(h,n){if(h instanceof Uint8Array)return r.Uint8(h);if(typeof h=="string")return r.Base64(h);if(h instanceof HTMLElement&&h.type==="file")return r.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(r.Uint8(new Uint8Array(v.target.result)))}})},Base64:function(h){let n=function(v){var x="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(v=v.replace(/^.*?base64,/,""),v=String(v).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(v))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");v+="==".slice(2-(3&v.length));let a,c="",l,s,i=0;for(;i>16&255):s===64?String.fromCharCode(a>>16&255,a>>8&255):String.fromCharCode(a>>16&255,a>>8&255,255&a);return c}(h=String(h));var p=n.length;let y=new Uint8Array(new ArrayBuffer(p));for(let v=0;v{s[u]=this.readInt(1)});for(let d=0;d191||f>127&&f<160)throw new RangeError(`Invalid code point: ${f}`)}i=!0,console.debug(`String byte sequence in ${e[d].encoding}`)}catch(u){console.debug(`SMF string ${u}`)}return o||"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 i=[];for(;128<=this.data.getUint8(this.pointer);)i.push(this.readInt(1)-128);var s=this.readInt(1);for(let o=1;o<=i.length;o++)l+=i[i.length-o]*Math.pow(128,o);l+=s}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 x,a=n.readInt(4);if(a===-1)break;if(a!==1297379947)return!1;n.readInt(4);let s=0,i=!1,o,d;for(;!i&&(s++,p.track[l-1].event[s-1]={},p.track[l-1].event[s-1].deltaTime=n.readIntVLV(),(o=n.readInt(1))!==-1);)if(128<=o?d=o:(o=d,n.movePointer(-1)),o===255){p.track[l-1].event[s-1].type=255,p.track[l-1].event[s-1].metaType=n.readInt(1);var c=n.readIntVLV();switch(p.track[l-1].event[s-1].metaType){case 47:case-1:i=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:p.track[l-1].event[s-1].data=n.readStr(c);break;case 33:case 89:case 81:p.track[l-1].event[s-1].data=n.readInt(c);break;case 84:p.track[l-1].event[s-1].data=[],p.track[l-1].event[s-1].data[0]=n.readInt(1),p.track[l-1].event[s-1].data[1]=n.readInt(1),p.track[l-1].event[s-1].data[2]=n.readInt(1),p.track[l-1].event[s-1].data[3]=n.readInt(1),p.track[l-1].event[s-1].data[4]=n.readInt(1);break;case 88:p.track[l-1].event[s-1].data=[],p.track[l-1].event[s-1].data[0]=n.readInt(1),p.track[l-1].event[s-1].data[1]=n.readInt(1),p.track[l-1].event[s-1].data[2]=n.readInt(1),p.track[l-1].event[s-1].data[3]=n.readInt(1);break;default:this.customInterpreter!==null&&(p.track[l-1].event[s-1].data=this.customInterpreter(p.track[l-1].event[s-1].metaType,n,c)),this.customInterpreter!==null&&p.track[l-1].event[s-1].data!==!1||(n.readInt(c),p.track[l-1].event[s-1].data=n.readInt(c),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((o=o.toString(16).split(""))[1]||o.unshift("0"),p.track[l-1].event[s-1].type=parseInt(o[0],16),p.track[l-1].event[s-1].channel=parseInt(o[1],16),p.track[l-1].event[s-1].type){case 15:this.customInterpreter!==null&&(p.track[l-1].event[s-1].data=this.customInterpreter(p.track[l-1].event[s-1].type,n,!1)),this.customInterpreter!==null&&p.track[l-1].event[s-1].data!==!1||(x=n.readIntVLV(),p.track[l-1].event[s-1].data=n.readInt(x),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[s-1].data=[],p.track[l-1].event[s-1].data[0]=n.readInt(1),p.track[l-1].event[s-1].data[1]=n.readInt(1);break;case 12:case 13:p.track[l-1].event[s-1].data=n.readInt(1);break;case-1:i=!0;break;default:if(this.customInterpreter!==null&&(p.track[l-1].event[s-1].data=this.customInterpreter(p.track[l-1].event[s-1].metaType,n,!1)),this.customInterpreter===null||p.track[l-1].event[s-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return p},customInterpreter:null};if(typeof _t<"u")_t.exports=r;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=r}})()});L();L();var ae,qt,Mt=(qt=class{constructor(){T(this,ae,{})}addEventListener(g,e){t(this,ae)[g]||(t(this,ae)[g]=[]),t(this,ae)[g].unshift(e)}removeEventListener(g,e){if(t(this,ae)[g]){let r=t(this,ae)[g].indexOf(e);r>-1&&t(this,ae)[g].splice(r,1),t(this,ae)[g].length<1&&delete t(this,ae)[g]}}dispatchEvent(g,e){var n;let r=new Event(g),h=this;r.data=e,((n=t(this,ae)[g])==null?void 0:n.length)>0&&t(this,ae)[g].forEach(function(p){try{p==null||p.call(h,r)}catch(y){console.error(y)}}),this[`on${g}`]&&this[`on${g}`](r)}},ae=new WeakMap,qt);L();L();var Wt=function(g,e){let r=Math.min(g.length,e.length),h=g.slice(0,r),n=e.slice(0,r),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 x=Wt(e,this.pool[p]);switch(x){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 ${x}.`)}}n=n>>1,y--}let v=!0;if(p>=this.pool.length)v=!1;else{let x=this;this.pool[p].forEach(function(a,c,l){v&&a!=e[c]&&(v=!1)}),!v&&Wt(e,this.pool[p])>0&&p++}return v||r?p:-1}else return r?0:-1},this.add=function(e,r){return e.data=r,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match in "${this.name||"(unknown)"}" for "${e}". Default action not defined.`)},this.get=function(e){let r=this.point(e);if(r>-1)return this.pool[r].data;this.default(e)},this.run=function(e,...r){let 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)}};L();var Ua=["MSB","PRG","LSB","NME","ELC","DRM"],It=function(g){let e=Math.floor(g/10),r=g%10;return`${e.toString(16)}${r}`},ee,Qt,Lt=(Qt=class{constructor(...g){T(this,ee,void 0);P(this,"strictMode",!1);this.loadFiles(...g)}get(g=0,e=0,r=0,h){var $,w;let n=[g,e,r],p,y=1,v=0,x,a=Array.from(arguments);switch(h){case"xg":{switch(g){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":{g==0&&r<5?a[2]=0:g>125&&r<5&&r!=2&&(a[2]=g,a[0]=0);break}case"g2":case"sd":{g>>1==40?a[2]|=16:g>95&&g<100&&(a[2]|=16,e>>4==7&&(a[0]=96));break}case"sg":{g==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=" ",l="M",s="",i=0,o=0;switch(a[0]){case 0:{switch(a[2]){case 127:{h=="xg"?l="GM-a":(l="MT-a",s="C/M");break}case 126:{h=="xg"?l="GM-n":(l="MT-b",s="C/M");break}case 7:{l="GM-k",s="GLX";break}case 5:{l="SG-a",s="000";break}case 4:{h=="gs"||h=="sc"?(l="GM-a",s="000"):(l="SP-l",s="C/M");break}case 3:case 2:case 1:{(h=="gs"||h=="sc")&&(l="GM-a",s="000");break}case 0:{l="GM-a";break}default: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"[r]}`,i=3);break}case 48:{s=`M${(a[2]>>3).toString().padStart(2,"0")}`,l=`y${s}`,i=1;break}case 56:{l="GM-b";break}case 57:l=["yDOC","QY10","QY20"][a[2]-112]||"yMxv",s=["DOC","QY1","QY2"][a[2]-112]||"057";case 61:case 120:{l="rDrm";break}case 62:{l="kDrm";break}case 63:{if(a[2]<17){let C=a[2];l=C<10?"kP:":"kC:",l+=C%10}else a[2]<34?l=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][a[2]-17]:l="Ds";i=1;break}case 64:{l="ySFX",s="SFX";break}case 67:{l="DX:S";break}case 80:case 81:case 82:case 83:{l=`Prg${"UABC"[a[0]-80]}`;break}case 88:case 89:case 90:case 91:{l=`Cmb${"UABC"[a[0]-88]}`;break}case 95:{l=`${["DR","PC"][a[2]]}-d`;break}case 96:{l=a[2]==106?"AP-a":a[2]>>4==1?"SDg":"PF",a[2]>63?o=63:a[2]>>4==1&&(o=16),i=3;break}case 97:{l=a[2]>>4==1?"SDa":"VL:",i=3,a[2]>>4==1?o=16:o=112;break}case 98:{l=a[2]>>4==1?"SDb":"SG-a",i=3,o=16;break}case 99:{l=a[2]>>4==1?"SDc":"DX",a[2]>63?o=63:a[2]>>4==1&&(o=16),i=3;break}case 100:{l="AN",a[2]>63?o=63:a[2]>>4==1&&(o=16),i=3;break}case 104:case 105:case 106:case 107:{l="SDd",o=104;break}case 121:{l=`GM-${a[2]?"":"a"}`,i=3;break}case 122:{l="lDrm";break}case 126:{l="yDrS";break}case 127:{a[2]==127?l="rDrm":l="yDrm";break}default:a[0]<48?l="r:":l="M"}l.length<4&&(l+=`${[g,r,a[0],a[2]][i]-o}`.padStart(4-l.length,"0")),s.length<3&&(s+=`${[g,r,g,r][i]}`.padStart(3-s.length,"0")),h=="xg"&&(g==0?a[2]<100?l=l.replace("y0","y:"):a[2]==125&&(l="y126"):g==16?(p=`Voice${((a[2]<<7)+a[1]+1).toString().padStart(3,"0")}`,c=" "):g==35&&r>>1==2&&(p=`DXCH_${(((a[2]&1)<<7)+e+1).toString().padStart(3,"0")}`,c=" "));let d=[a[0],a[1],a[2]];for(;!((p==null?void 0:p.length)>=0);)if(p=($=t(this,ee)[a[1]||0][(a[0]<<7)+a[2]])==null?void 0:$.name,p){let C=t(this,ee)[a[1]||0][(a[0]<<7)+a[2]];y=(C==null?void 0:C.poly)||y,v=(C==null?void 0:C.type)||v,x=C==null?void 0:C.drum}else if(this.strictMode)p="",c="?";else if(a[0]==0&&a[1]==0&&a[2]==0)p="Unloaded";else if(t(this,ee)[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(g==48)a[0]=0,a[2]=0,c="!";else if(g==62)a[1]--,c=" ",a[1]<1&&!(p!=null&&p.length)&&(a[0]=0,c="!");else if(g<63)a[0]==0?(a[2]=0,c="^"):a[2]<1?(a[0]=0,c="*"):a[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${r}`,c="#";else if(g==122){if(a[1]==32?a[1]==0:a[1]%=7,p=(w=t(this,ee)[a[1]||0][(a[0]<<7)+a[2]])==null?void 0:w.name,p){c=" ";let C=t(this,ee)[a[1]||0][(a[0]<<7)+a[2]];y=(C==null?void 0:C.poly)||y,v=(C==null?void 0:C.type)||v,x=C==null?void 0:C.drum}else p="",c="*";}else a[1]==0?(p=`${g.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 u=[a[0],a[1],a[2]];switch(c){case"^":{switch(h){case"gs":case"sc":case"ns5r":{c=" ";break}}g==127&&c=="^"&&(c=" ");break}}let f="??";switch(a[0]){case 0:{a[2]==0?f="GM":a[2]==5||a[2]==7?f="KG":a[2]<126?f="XG":a[2]==127&&(f="MT");break}case 32:case 33:case 35:case 36:{a[2]>4?f=["AP","VL","PF","DX","AN"][a[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:{a[2]<17?f="KR":a[2]<34?f="ES":f="DS";break}case 64:case 126:{f="XG";break}case 67:case 99:{f=a[2]>>4==1?"SD":"DX";break}case 81:{f="RW";break}case 95:{f=["DR","PC"][a[2]];break}case 96:{f=a[2]==106?"AP":a[2]>>4==1?"SD":"PF";break}case 97:{f=a[2]>>4==1?"SD":"VL";break}case 98:{f=a[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=a[2]?"G2":"GM";break}case 122:{f="KG";break}case 127:{f=a[2]==127?"MT":e==0?"GM":"XG";break}default:a[0]<48&&(a[0]==16&&h=="xg"?f="XG":f="GS")}return c!=" "&&(h=="krs"||self.debugMode)&&(p="",f="KR"),{name:p||`${It(g||0)} ${It(e||0)} ${It(r||0)}`,poly:y,type:v,drum:x,iid:d,eid:u,sid:n,ending:c,sect:l,bank:s,standard:f,mode:h}}async load(g,e,r="(internal)"){let h=this,n=[],p=0,y=0;g.split(` +`).forEach(function(v,x){let a=v.split("\t"),c=[];if(x==0){if(a.forEach(function(l,s){n[Ua.indexOf(l)]=s}),n.length<4){console.debug("Debugger launched.");debugger}}else{let l=0,s=0,i=0,o,d=1,u=0,f;a.forEach(async function(w,C){switch(C){case n[0]:{l=parseInt(w);break}case n[1]:{s=parseInt(w);break}case n[2]:{i=parseInt(w);break}case n[3]:{o=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,ee)[s]=t(h,ee)[s]||[];let $=t(h,ee)[s];if(!$[l<<7|i]||e){let w={msb:l,prg:s,lsb:i,name:o,poly:d,type:u,drum:f};$[l<<7|i]=w,p++}y++}}),e||console.debug(`Map "${r}": ${y} total, ${p} loaded.`)}clearRange(g){let e=g.prg!=null?g.prg.constructor==Array?g.prg:[g.prg,g.prg]:[0,127],r=g.msb!=null?g.msb.constructor==Array?g.msb:[g.msb,g.msb]:[0,127],h=g.lsb!=null?g.lsb.constructor==Array?g.lsb:[g.lsb,g.lsb]:[0,127];for(let n=r[0];n<=r[1];n++){let p=n<<7;for(let y=h[0];y<=h[1];y++){let v=p+y;for(let x=e[0];x<=e[1];x++)delete t(this,ee)[x][v]}}}init(){S(this,ee,[]);for(let g=0;g<128;g++)t(this,ee).push([""])}async loadFiles(...g){this.init();let e=this;g.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".`)}})}},ee=new WeakMap,Qt);L();L();var it,Yt,Zt=(Yt=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,Yt);var Ba=function(g,e){let r=!0;return e.forEach((h,n)=>{r=r&&g[n]==h}),r},gt=function(g){let e=0;return g.forEach(r=>{e*=256,e+=r}),e},ve=new TextDecoder,bt=new Zt;bt.set("s7e",async function(g){let e=new Uint8Array(await g.slice(0,65536).arrayBuffer()),r="MSB\tLSB\tPRG\tNME",h=[0,0,0,0],n=32,p=0,y=0,v=!0,x=[],a=0;for(;v;){let c=e.subarray(p);([()=>{ve.decode(c.subarray(0,4))=="YSFC"?(p+=80,y=1):p++},()=>{if(Ba(c.subarray(0,4),h))x.forEach((l,s,i)=>{let o=gt(e.subarray(l.start+4,l.start+8));l.length=o}),y=2;else{let l=ve.decode(c.subarray(0,4)),s=gt(c.subarray(4,8));x.push({type:l,start:s}),p+=8}},()=>{let l=x[a],s=e.subarray(l.start,l.start+l.length),i=32;switch(l.type){case"ENVC":{let o=n;for(;o=x.length&&(y=3,v=!1)}][y]||(()=>{v=!1}))()}return r});bt.set("pcg",async function(g){let e=new Uint8Array(await g.arrayBuffer()),r="MSB\tLSB\tPRG\tNME",h=100,n=0,p=0,y=!0,v=[],x=0;for(;y;){let a=e.subarray(h);([()=>{y=ve.decode(a.subarray(0,4))=="INI2",p=a[15],h+=16,n=1},()=>{let c=ve.decode(a.subarray(0,4)),l=a[5],s=a[7],i=a[11],o=gt(a.subarray(12,16)),d=gt(a.subarray(16,20)),u=gt(a.subarray(36,40)),f=ve.decode(a.subarray(44,44+i));v.push({type:c,tipMsb:l,tipLsb:s,nameLen:i,length:o,start:d,entryLen:u,name:f}),h+=64,p--,p<1&&(n=2)},()=>{let c=v[x],l=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 d=o*c.entryLen,u=l.subarray(d,d+c.entryLen),f=ve.decode(u.subarray(0,24)).trimEnd().replace("InitProg","");f.length&&i>5&&(r+=` +${s.toString().padStart(3,"0")} ${i.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")} ${f}`)}break}case"CBK1":{let s=63,i=(c.tipMsb?3:0)+c.tipLsb+10;for(let o=0;o<128;o++){let d=o*c.entryLen,u=l.subarray(d,d+c.entryLen),f=ve.decode(u.subarray(0,24)).trimEnd().replace("InitCombi","");f.length&&i>12&&(r+=` +${s.toString().padStart(3,"0")} ${i.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")} ${f}`)}break}}x++,x>=v.length&&(n=3,y=!1)}][n]||(()=>{y=!1}))()}return r});L();var mt=["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"],Na=[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],nt=[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],Jt=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],jt=function(g){let e=.1,r=-.3;return g>66?(e=5,r=315):g>56?(e=1,r=47):g>46&&(e=.5,r=18.5),e*g-r},ea=function(g){return g>105?Na[g-106]:g>100?g*1.1-100:g/10},ta=",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 ar=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("\u3093")==0&&e.length>1&&(e=e.slice(1));let a=e.indexOf("!");return a>-1&&e.length>1&&(e=e.slice(a+1)),e},ir=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"],sr=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],nr=["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 _r={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"},Gr={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 _r[(g[0]-32<<8)+g[1]]||`0x${g[0].toString(16).padStart(2,"0")}${g[1].toString(16).padStart(2,"0")}`},cr=function(g,e,a){let h=(g[0]-32<<16)+(g[1]<<8)+e,c=Gr[h]||{},p=c[0];if(p!=null&&p.length)return p+=`: ${(c[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},or=function(g,e,a){let h=[],c=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 c=0;c>p&1)<<7,v=g[c];v+=y,c%8!=0?(e(v,a,g),a++):h=g[c]}};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"],Xr={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"},Vr=["melodic","drum","menu"],lr={"?":[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 dr=[9,25,41,57,73,89,105,121],Fr=[0,3,81,84,88],fr={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},hr={0:0,1:1,2:3,5:4},ur={0:0,1:1,2:2,5:3},pr=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],gr=[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],br={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],Kr=[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],zr=[33,99,100,32,102,8,9,10],Er=[0,16,25,40,32,64,26,48],x={};W.forEach((g,e)=>{x[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 qr={};Vr.forEach((g,e)=>{qr[g]=e});var Wr=function(g){let e=[],a=0;return g==null||g.forEach(function(h,c){h==247?e.push(g.subarray(a,c)):h==240&&(a=c+1)}),e.length||e.push(g.subarray(0)),O()&&console.debug(e),e};var mr=8,m={port:mr,ch:mr<<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,vr,de,K,D,b,fe,I,z,ae,q,Q,Te,$e,Ge,ie,R,L,ct,ee,be,se,ot,Xe,V,Oe,Ee,$t,Ae,me,lt,Ie,X,B,we,wt,H,Ve,dt,ft,Le,Ue,kt,ht,ye,_,Pt,xt,Fe,_t,ne,Ce,Be,j,Ke,F,St,Rt,ze,qe,ce,he,ke,We,Qe,Ye,yr,La=(yr=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,K,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,z,new Uint8Array(m.ch*m.nn));T(this,ae,new Uint8Array(m.ch));T(this,q,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*gr.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,V,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,X,{});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,_,!1);T(this,Pt,1);T(this,xt,void 0);T(this,Fe,new Array(m.ch));T(this,_t,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,F,{nOff:(e,a)=>{let h=e*128+a,c=t(this,q).lastIndexOf(h);if(c>-1)if(t(this,b)[m.cc*e+E[64]]>63)t(this,Q)[c]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:a,velo:t(this,z)[h],state:this.NOTE_HELD});else if(t(this,b)[m.cc*e+E[66]]>63&&t(this,Q)[c]==this.NOTE_SOSTENUTO_SUSTAIN)t(this,Q)[c]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:a,velo:t(this,z)[h],state:this.NOTE_SOSTENUTO_HELD});else{t(this,q)[c]=0,t(this,z)[h]=0,t(this,Q)[c]=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 c=e*128+a,p=0;for(t(this,ae)[e]&&t(this,F).ano(e);t(this,Q)[p]>0&&t(this,q)[p]!=c;)p++;if(p{},cAt:(e,a)=>{},hoOf:e=>{t(this,Q).forEach((a,h)=>{if(a==this.NOTE_HELD){let c=t(this,q)[h],p=c>>7;e==p&&(t(this,Q)[h]=this.NOTE_IDLE,t(this,q)[h]=0,t(this,z)[c]=0,this.dispatchEvent("note",{part:e,note:c&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,Q).forEach((a,h)=>{let c;switch(a){case this.NOTE_ATTACK:{c=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{c=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{c=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(c){t(this,Q)[h]=c;let p=t(this,q)[h];this.dispatchEvent("note",{part:e,note:p&127,velo:t(this,z)[p],state:c})}})},soOf:e=>{t(this,Q).forEach((a,h)=>{if(a==this.NOTE_SOSTENUTO_HELD){let c=t(this,q)[h],p=c>>7;e==p&&(t(this,Q)[h]=this.NOTE_IDLE,t(this,q)[h]=0,t(this,z)[c]=0,this.dispatchEvent("note",{part:e,note:c&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,q).forEach((a,h,c)=>{let p=a>>7,y=a&127;a==0&&t(this,z)[0]==0||p==e&&t(this,F).nOff(p,y)})}});T(this,St,{8:function(e){let a=e.channel,h=e.data[0];t(this,F).nOff(a,h)},9:function(e){let a=e.channel,h=this;if(h.getChModeId(a)==x.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 c=e.data[0],p=e.data[1];p>0?t(h,F).nOn(a,c,p):t(h,F).nOff(a,c)},10:function(e){let a=e.channel,h=a*128+e.data[0];t(this,q).indexOf(h)>-1&&(t(this,z)[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,c=t(this,Fe)[a],p=c[e.data[0]];p&&(e.data[0]=p),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,A)){case x.s90es:case x.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,S=this.getChModeId(a);switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,F).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,F).ano(a);return}case 124:{t(this,F).ano(a);return}case 125:{t(this,F).ano(a);return}case 126:{t(this,ae)[a]=1,t(this,F).ano(a);return}case 127:{t(this,ae)[a]=0,t(this,F).ano(a);return}}if(E[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Kr.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)==x.gs||t(this,A)==x.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)==x.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 x.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 x["05rw"]:case x.x5d:case x.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 x.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 x.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)){[x.xg,x.gs,x.sc,x.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 r=t(this,b)[y+E[99]],n=t(this,b)[y+E[98]];if(r==1){let l=zr.indexOf(n);if(l>-1)t(this,b)[y+E[71+l]]=e.data[1],O()&&console.debug(`Redirected NRPN 1 ${n} to cc${71+l}.`),this.dispatchEvent("cc",{part:a,cc:71+l,data:e.data[1]});else{let i=gr.indexOf(n);i>-1?t(this,ct)[a*10+i]=e.data[1]-64:console.warn(`NRPN 0x01${n.toString(16).padStart(2,"0")} is not supported.`),O()&&console.debug(`CH${a+1} voice NRPN ${n} commit`)}}else{if(Dt.indexOf(r)<0){let i=`NRPN 0x${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")} `;r==127?console.warn(`${i}is not necessary. Consider removing it.`):console.warn(`${i}is not supported.`)}else{let i=t(this,D)[a]-2;i<0?console.warn(`CH${a+1} cannot accept drum NRPN as type ${mt[t(this,D)[a]]}.`):t(this,ee)[(i*m.dpn+le[r])*m.dnc+n]=e.data[1]}O()&&console.debug(`CH${a+1} (${mt[t(this,D)[a]]}) drum NRPN ${r} commit`)}}else{let r=hr[t(this,b)[y+E[100]]],n=ur[t(this,b)[y+E[100]]];if(t(this,b)[y+E[101]]==0&&r!=null)switch(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],pr[r][0]),pr[r][1]),t(this,R)[a*m.rpn+r]=e.data[1],t(this,L)[a*m.rpnt+n]=1,S){case x.xg:case x.gs:case x.sc:case x.mt32:case x.s90es:case x.motif:{switch(t(this,b)[y+E[100]]){case 1:case 2:{this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)});break}}break}default: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 x.s90es:case x.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 r=hr[t(this,b)[y+100]],n=ur[t(this,b)[y+100]];t(this,b)[y+101]==0&&r!=null&&(t(this,R)[a*m.rpn+r+1]=e.data[1],t(this,L)[a*m.rpnt+n]=1)}break}case 64:{e.data[1]<64&&t(this,F).hoOf(a);break}case 66:{e.data[1]>>6?t(this,F).soOn(a):t(this,F).soOf(a);break}case 98:case 99:{k(this,Ge,1);break}case 100:case 101:{k(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)==x.xg&&t(h,D)[a]&&h.setDrumFirstWrite(a)},12:function(e){let a=e.channel,h=this;switch(t(h,A)){case x.s90es:case x.motif:{e.data&&h.setChActive(a,1);break}default:h.setChActive(a,1)}if(h.getExt(a)[0]==h.EXT_DX){let c=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)==x.xg&&t(h,D)[a]&&h.setDrumFirstWrite(a)},13:function(e){let a=this,h=e.channel;t(this,q).forEach(function(c){let p=c>>7;h==p&&(t(a,z)[c]=e.data,a.dispatchEvent("note",{part:h,note:c&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){Wr(e.data).forEach(a=>{let h=a[0],c=a[1];(t(this,Rt)[h]||function(){console.debug(`Unknown manufacturer ${h}.`)})(c,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,c,p){}).call(this,e.data,e.track,e.meta),e.meta!=32&&k(this,Ve,0);let a=Fr.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 c=a[a.length-1],p=De(a.subarray(3,a.length-1));c==p?t(this,he).run(a.subarray(0,a.length-1),h,e):console.warn(`Bad SD checksum ${c} - should be ${p}.`)}else t(this,he).run(a,h,e);}else{let c=a[a.length-1],p=De(a.subarray(2,a.length-1));c==p?t(this,he).run(a.subarray(0,a.length-1),h,e):console.warn(`Bad GS checksum ${c} - 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;k(e,oe,new Uint8Array(256),vr),t(e,Se)[10]=new Uint8Array(512),k(e,Ke,new ue),k(e,B,{x5:82,ds:x.krs,smotif:x.s90es,gs:4,sc:3}),k(e,we,{dumpLimit:e.DUMP_MODE}),k(e,wt,new Proxy(t(e,we),{set:()=>{}}));for(let r in lr){let n=x[r];n==null?console.debug(`SubDB build error: "${r}" does not exist`):t(e,X)[n]=new Uint8Array(lr[r])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME +`).forEach(g=>{let e=g.split(",");Ut[e[0]]=e[1]});var aa=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("\u3093")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},ra=function(g){return g?g<96?`cc${g}`:["aftertouch","velocity","pitch bend"][g-96]:"off"};L();var Bt=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],sa=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ia=["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 Ha={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},_a={66307:["drive"],66309:["vowel",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 Ha[(g[0]-32<<8)+g[1]]||`0x${g[0].toString(16).padStart(2,"0")}${g[1].toString(16).padStart(2,"0")}`},na=function(g,e,r){let h=(g[0]-32<<16)+(g[1]<<8)+e,n=_a[h]||{},p=n[0];if(p!=null&&p.length)return p+=`: ${(n[1]||function(){})(r)||r}`,p},Ht=[68,48,95,78,41,3,110,122,0];L();var re=function(g=64){return Math.round(2e3*Math.log10(g/64))/100},ca=function(g,e,r){let h=[],n=r==!1?e.readIntVLV():r;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)},Ae=function(g){let e=0;return g.forEach(r=>{e+=r,e=e&127}),~e+1&127},ge=function(g,e){let r=0,h=0;for(let n=0;n>p&1)<<7,v=g[n];v+=y,n%8!=0?(e(v,r,g),r++):h=g[n]}};var yt=function(g){let e=Math.floor(g*14.2);return e<128?e:0},A=function(){return!!self.Bun||self.debugMode||!1};var Q=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"],Ga={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"},Xa=["melodic","drum","menu"],oa={"?":[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:[121,0,120],s90es:[0,0,127],motif:[0,0,127],trin:[0,0,127]},la=[9,25,41,57,73,89,105,121],Va=[0,3,81,84,88],da={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},fa={0:0,1:1,2:3,5:4},ha={0:0,1:1,2:2,5:3},ua=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],pa=[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],ga={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],Fa=[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],Ka=[33,99,100,32,102,8,9,10],ba=[0,16,25,40,32,64,26,48],k={};Q.forEach((g,e)=>{k[g]=e});var m={length:vt.length};vt.forEach((g,e)=>{m[g]=e});var fe={length:Dt.length};Dt.forEach((g,e)=>{fe[g]=e});var za={};Xa.forEach((g,e)=>{za[g]=e});var qa=function(g){let e=[],r=0;return g==null||g.forEach(function(h,n){h==247?e.push(g.subarray(r,n)):h==240&&(r=n+1)}),e.length||e.push(g.subarray(0)),A()&&console.debug(e),e};var ma=8,E={port:ma,ch:ma<<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},de={bank0:128},B,Y,be,Ce,le,Se,ya,he,K,D,b,Z,O,z,se,q,W,Te,$e,Xe,ie,R,I,ct,te,me,ne,ot,Ve,V,Oe,Ee,$t,Ie,ye,lt,Le,_,U,we,wt,H,Fe,dt,ft,Ue,Be,kt,ht,ke,G,Pt,xt,Ke,ce,Me,Ne,J,ze,F,St,Rt,qe,We,oe,ue,xe,Qe,Ye,Ze,Ea,Ir=(Ea=class extends Mt{constructor(){super();T(this,le);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,B,0);T(this,Y,0);T(this,be,0);T(this,Ce,new Array(11));T(this,he,new Uint8Array(E.ch));T(this,K,new Uint8Array(E.ch));T(this,D,new Uint8Array(E.ch));T(this,b,new Uint8Array(E.ch*E.cc));T(this,Z,new Uint8Array(E.ch*E.ace));T(this,O,new Uint8Array(E.ch));T(this,z,new Uint8Array(E.ch*E.nn));T(this,se,new Uint8Array(E.ch));T(this,q,new Uint16Array(E.pl));T(this,W,new Uint8Array(E.pl));T(this,Te,new Int16Array(E.ch));T(this,$e,new Uint8Array(E.ch));T(this,Xe,new Uint8Array(E.ch));T(this,ie,new Uint8Array(E.ch*E.ext));T(this,R,new Uint8Array(E.ch*E.rpn));T(this,I,new Uint8Array(E.ch*E.rpnt));T(this,ct,new Int8Array(E.ch*pa.length));T(this,te,new Uint8Array(E.drm*E.dpn*E.dnc));T(this,me,new Uint8Array(E.drm*2));T(this,ne,new Uint8Array(E.efx*3));T(this,ot,new Uint8Array(E.ch));T(this,Ve,new Uint8Array(E.ch*E.redir));T(this,V,new Uint8Array(E.port));T(this,Oe,new Uint8Array(E.ch));T(this,Ee,new Uint8Array(E.ch));T(this,$t,new Uint8Array(E.ch*E.cvn));T(this,Ie,new Uint8Array(128));T(this,ye,new Uint8Array(E.cmt*8));T(this,lt,new Uint8Array(1024));T(this,Le,new Uint8Array(E.cmt*64));T(this,_,{});T(this,U,void 0);T(this,we,void 0);T(this,wt,void 0);T(this,H,100);T(this,Fe,0);T(this,dt,500);T(this,ft,0);T(this,Ue,"");T(this,Be,0);T(this,kt,0);T(this,ht,0);T(this,ke,!0);T(this,G,!1);T(this,Pt,1);T(this,xt,void 0);T(this,Ke,new Array(E.ch));T(this,ce,[]);T(this,Me,new Uint8Array(E.ch));T(this,Ne,new Uint8Array(E.tr));P(this,"baseBank",new Lt("gm","gm2","xg","gs","ns5r","sd","gmega","plg-vl","plg-pf","plg-dx","plg-an","plg-dr","plg-sg","kross","s90es"));P(this,"userBank",new Lt("gm"));P(this,"initOnReset",!1);P(this,"aiEfxName","");T(this,J,[]);T(this,ze,void 0);T(this,F,{nOff:(e,r)=>{let h=e*128+r,n=t(this,q).lastIndexOf(h);if(n>-1)if(t(this,b)[E.cc*e+m[64]]>63)t(this,W)[n]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,z)[h],state:this.NOTE_HELD});else if(t(this,b)[E.cc*e+m[66]]>63&&t(this,W)[n]==this.NOTE_SOSTENUTO_SUSTAIN)t(this,W)[n]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,z)[h],state:this.NOTE_SOSTENUTO_HELD});else{t(this,q)[n]=0,t(this,z)[h]=0,t(this,W)[n]=this.NOTE_IDLE;let p=this.getExt(e)[1];(p==this.VLBC_VELOINIT||p==this.VLBC_VELOALL)&&(t(this,b)[E.cc*e+m[129]]=0),this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})}},nOn:(e,r,h)=>{let n=e*128+r,p=0;for(t(this,se)[e]&&t(this,F).ano(e);t(this,W)[p]>0&&t(this,q)[p]!=n;)p++;if(p{},cAt:(e,r)=>{},hoOf:e=>{t(this,W).forEach((r,h)=>{if(r==this.NOTE_HELD){let n=t(this,q)[h],p=n>>7;e==p&&(t(this,W)[h]=this.NOTE_IDLE,t(this,q)[h]=0,t(this,z)[n]=0,this.dispatchEvent("note",{part:e,note:n&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,W).forEach((r,h)=>{let n;switch(r){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,W)[h]=n;let p=t(this,q)[h];this.dispatchEvent("note",{part:e,note:p&127,velo:t(this,z)[p],state:n})}})},soOf:e=>{t(this,W).forEach((r,h)=>{if(r==this.NOTE_SOSTENUTO_HELD){let n=t(this,q)[h],p=n>>7;e==p&&(t(this,W)[h]=this.NOTE_IDLE,t(this,q)[h]=0,t(this,z)[n]=0,this.dispatchEvent("note",{part:e,note:n&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,q).forEach((r,h,n)=>{let p=r>>7,y=r&127;r==0&&t(this,z)[0]==0||p==e&&t(this,F).nOff(p,y)})}});T(this,St,{8:function(e){let r=e.channel,h=e.data[0];t(this,F).nOff(r,h)},9:function(e){let r=e.channel,h=this;if(h.getChModeId(r)==k.xg&&t(h,D)[r]>1){let y=h.getChDrumFirstWrite(r);y[0]&&y[1]!=E.invalidCh&&!t(h,he)[r]&&(h.copyChSetup(y[1],r),h.dispatchEvent("voice",{part:r}),console.debug(`Part CH${r+1} copied from CH${y[1]}.`))}h.setChActive(r,1);let n=e.data[0],p=e.data[1];p>0?t(h,F).nOn(r,n,p):t(h,F).nOff(r,n)},10:function(e){let r=e.channel,h=r*128+e.data[0];t(this,q).indexOf(h)>-1&&(t(this,z)[h]=data[1],this.getExt(r)[1]==this.VLBC_VELOALL&&(t(this,b)[E.cc*r+m[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,n=t(this,Ke)[r],p=n[e.data[0]];p&&(e.data[0]=p),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,B)){case k.s90es:case k.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(r,1);break}e.data[1]&&this.setChActive(r,1);break}default:{this.setChActive(r,1);break}}})();let y=r*E.cc,v=r*E.ext,x=this.getChModeId(r);switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,F).ano(r),t(this,Te)[r]=0,t(this,b)[y+m[1]]=0,t(this,b)[y+m[5]]=0,t(this,b)[y+m[64]]=0,t(this,b)[y+m[65]]=0,t(this,b)[y+m[66]]=0,t(this,b)[y+m[67]]=0,t(this,b)[y+m[11]]=127,t(this,b)[y+m[101]]=127,t(this,b)[y+m[100]]=127,t(this,b)[y+m[99]]=127,t(this,b)[y+m[98]]=127;return}case 123:{t(this,F).ano(r);return}case 124:{t(this,F).ano(r);return}case 125:{t(this,F).ano(r);return}case 126:{t(this,se)[r]=1,t(this,F).ano(r);return}case 127:{t(this,se)[r]=0,t(this,F).ano(r);return}}if(m[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Fa.indexOf(e.data[0])>-1&&this.allocateAce(r,e.data[0]),e.data[0]){case 0:{switch(A()&&console.debug(`${Q[t(this,B)]}, CH${r+1}: ${e.data[1]}`),t(this,B)==0?e.data[1]<48?(t(this,D)[r]>0&&(e.data[1]=t(this,b)[y],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==56?this.switchMode(t(this,U).x5==82?"x5d":"05rw"):e.data[1]==62?this.switchMode(t(this,U).x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(Q[t(this,U).ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,B)==k.gs||t(this,B)==k.sc?e.data[1]<56&&t(this,D)[r]>0&&(e.data[1]=t(this,b)[y],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):t(this,B)==k.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,B)){case k.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,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 k["05rw"]:case k.x5d:case k.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 k.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 k.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,b)[y+m[129]]=e.data[1]);break}case 6:{if(t(this,Xe)[r]){[k.xg,k.gs,k.sc,k.ns5r].indexOf(t(this,B))<0&&console.warn(`NRPN commits are not available under "${Q[t(this,B)]}" mode, even when they are supported in Octavia.`);let a=t(this,b)[y+m[99]],c=t(this,b)[y+m[98]];if(a==1){let l=Ka.indexOf(c);if(l>-1)t(this,b)[y+m[71+l]]=e.data[1],A()&&console.debug(`Redirected NRPN 1 ${c} to cc${71+l}.`),this.dispatchEvent("cc",{part:r,cc:71+l,data:e.data[1]});else{let s=pa.indexOf(c);s>-1?t(this,ct)[r*10+s]=e.data[1]-64:console.warn(`NRPN 0x01${c.toString(16).padStart(2,"0")} is not supported.`),A()&&console.debug(`CH${r+1} voice NRPN ${c} commit`)}}else{if(Dt.indexOf(a)<0){let s=`NRPN 0x${a.toString(16).padStart(2,"0")}${c.toString(16).padStart(2,"0")} `;a==127?console.warn(`${s}is not necessary. Consider removing it.`):console.warn(`${s}is not supported.`)}else{let s=t(this,D)[r]-2;s<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${Et[t(this,D)[r]]}.`):t(this,te)[(s*E.dpn+fe[a])*E.dnc+c]=e.data[1]}A()&&console.debug(`CH${r+1} (${Et[t(this,D)[r]]}) drum NRPN ${a} commit`)}}else{let a=fa[t(this,b)[y+m[100]]],c=ha[t(this,b)[y+m[100]]];if(t(this,b)[y+m[101]]==0&&a!=null)switch(A()&&console.debug(`CH${r+1} RPN 0 ${t(this,b)[y+m[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],ua[a][0]),ua[a][1]),t(this,R)[r*E.rpn+a]=e.data[1],t(this,I)[r*E.rpnt+c]=1,x){case k.xg:case k.gs:case k.sc:case k.mt32:case k.s90es:case k.motif:{switch(t(this,b)[y+m[100]]){case 1:case 2:{this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)});break}}break}default:this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})}}break}case 32:{switch(A()&&console.debug(`${Q[t(this,B)]}, CH${r+1} LSB: ${e.data[1]}`),t(this,B)){case k.s90es:case k.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,B),!0);break}}this.getExt(r)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:r});break}case 38:{if(!t(this,Xe)[r]){let a=fa[t(this,b)[y+100]],c=ha[t(this,b)[y+100]];t(this,b)[y+101]==0&&a!=null&&(t(this,R)[r*E.rpn+a+1]=e.data[1],t(this,I)[r*E.rpnt+c]=1)}break}case 64:{e.data[1]<64&&t(this,F).hoOf(r);break}case 66:{e.data[1]>>6?t(this,F).soOn(r):t(this,F).soOf(r);break}case 98:case 99:{t(this,Xe)[r]=1;break}case 100:case 101:{t(this,Xe)[r]=0;break}}t(this,b)[y+m[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:r,cc:e.data[0],data:e.data[1]})}h.getChModeId(r)==k.xg&&t(h,D)[r]&&h.setDrumFirstWrite(r)},12:function(e){let r=e.channel,h=this;switch(t(h,B)){case k.s90es:case k.motif:{e.data&&h.setChActive(r,1);break}default:h.setChActive(r,1)}if(h.getExt(r)[0]==h.EXT_DX){let n=E.cc*r}t(h,O)[r]=e.data,t(h,Ee)[r]=0,A()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),h.dispatchEvent("voice",{part:r}),h.getChModeId(r)==k.xg&&t(h,D)[r]&&h.setDrumFirstWrite(r)},13:function(e){let r=this,h=e.channel;t(this,q).forEach(function(n){let p=n>>7;h==p&&(t(r,z)[n]=e.data,r.dispatchEvent("note",{part:h,note:n&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;t(this,Te)[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){qa(e.data).forEach(r=>{let h=r[0],n=r[1];(t(this,Rt)[h]||function(){console.debug(`Unknown manufacturer ${h}.`)})(n,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,J)[e.meta]||function(h,n,p){}).call(this,e.data,e.track,e.meta),e.meta!=32&&S(this,Fe,0);let r=Va.indexOf(e.meta)>-1;if(A()&&console.debug(e),r)return e.reply="meta",e}});T(this,Rt,{64:(e,r,h)=>{t(this,Qe).run(r,h,e)},65:(e,r,h)=>{if(r[0]<16){if(r[1]==72){let n=r[r.length-1],p=Ae(r.subarray(3,r.length-1));n==p?t(this,ue).run(r.subarray(0,r.length-1),h,e):console.warn(`Bad SD checksum ${n} - should be ${p}.`)}else t(this,ue).run(r,h,e);}else{let n=r[r.length-1],p=Ae(r.subarray(2,r.length-1));n==p?t(this,ue).run(r.subarray(0,r.length-1),h,e):console.warn(`Bad GS checksum ${n} - should be ${p}.`)}},66:(e,r,h)=>{t(this,xe).run(r,h,e)},67:(e,r,h)=>{t(this,oe).run(r,h,e)},68:(e,r,h)=>{t(this,Ze).run(r,h,e)},71:(e,r,h)=>{t(this,Ye).run(r,h,e)},126:(e,r,h)=>{t(this,qe).run(r,h,e)},127:(e,r,h)=>{this.switchMode("gm"),t(this,We).run(r,h,e)}});T(this,qe,void 0);T(this,We,void 0);T(this,oe,void 0);T(this,ue,void 0);T(this,xe,void 0);T(this,Qe,void 0);T(this,Ye,void 0);T(this,Ze,void 0);let e=this;S(e,le,new Uint8Array(256),ya),t(e,Ce)[10]=new Uint8Array(512),S(e,ze,new pe),S(e,U,{x5:82,ds:k.krs,smotif:k.s90es,gs:4,sc:3}),S(e,we,{dumpLimit:e.DUMP_MODE}),S(e,wt,new Proxy(t(e,we),{set:()=>{}}));for(let a in oa){let c=k[a];c==null?console.debug(`SubDB build error: "${a}" does not exist`):t(e,_)[c]=new Uint8Array(oa[a])}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:n}=r;((l=t(e,ne)[0])==null?void 0:l.type)==n.type&&(i=t(e,ne)[0])!=null&&i.amend?(t(e,ne)[0].amend=n.amend,t(e,ne)[0].data+=n.data):t(e,ne).unshift(n)}),t(e,j)[1]=function(r){var n,l,i,s,o;switch(r=r.replaceAll(`\r +122 006 000 `),e.addEventListener("metacommit",function(a){var l,s;let{data:c}=a;((l=t(e,ce)[0])==null?void 0:l.type)==c.type&&(s=t(e,ce)[0])!=null&&s.amend?(t(e,ce)[0].amend=c.amend,t(e,ce)[0].data+=c.data):t(e,ce).unshift(c)}),t(e,J)[1]=function(a){var c,l,s,i,o;switch(a=a.replaceAll(`\r `,` `).replaceAll("\r",` -`),r.slice(0,2)){case"@I":{k(this,_,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(n=r.slice(2))==null?void 0:n.trimLeft()});break}case"@K":{k(this,_,!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":{k(this,_,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(i=r.slice(2))==null?void 0:i.trimLeft()});break}case"@T":{k(this,_,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(s=r.slice(2))==null?void 0:s.trimLeft()});break}case"@V":{k(this,_,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(o=r.slice(2))==null?void 0:o.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,_)?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,n){n<1&&t(this,Ve)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:r})},t(e,j)[4]=function(r,n){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){k(this,Ve,r[0]+1)},t(e,j)[33]=function(r,n){O()&&console.debug(`Track ${n} requests to get assigned to output ${r}.`),t(e,Be)[n]=r+1},t(e,j)[81]=function(r,n){k(e,dt,r/1e3)},t(e,j)[127]=function(r,n){t(e,Ke).run(r,n)},t(e,Ke).default=function(r){console.warn(`Unrecognized sequencer-specific byte sequence: ${r}`)},t(e,Ke).add([67,0,1],function(r,n){t(e,Be)[n]=r[0]+1}),k(e,ze,new ue("universal non-realtime")),k(e,qe,new ue("universal realtime")),k(e,ce,new ue("Yamaha")),k(e,he,new ue("Roland")),k(e,ke,new ue("Korg")),k(e,We,new ue("Kawai")),k(e,Qe,new ue("Akai")),k(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,n,l)=>{e.switchMode(["gm","?","g2"][r[0]-1],!0),e.setPortMode(e.getTrackPort(n),1,x[["gm","?","g2"][r[0]-1]]),k(e,_,t(e,_)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][r[0]-1]}`),r[0]==2&&e.init()}),t(e,qe).add([4,1],(r,n,l)=>{e.dispatchEvent("mupromptex"),k(e,H,((r[1]<<7)+r[0])/16383*100),e.dispatchEvent("mastervolume",t(e,H))}).add([4,3],(r,n,l)=>((r[1]<<7)+r[0]-8192)/8192).add([4,4],(r,n,l)=>r[1]-64).add([4,5],(r,n,l)=>{e.dispatchEvent("mupromptex");let i=r[0],s=r[1],o=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,G)=>{w|=M<{C|=M<{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(n),4,x.xg),k(e,_,!1),console.info("MIDI reset: XG");break}default:{e.dispatchEvent("mupromptex");let i=[0,0,0,0],s=(o,d)=>{i[d]=o};if(r.subarray(1).forEach((o,d)=>{let u=d+r[0];([s,s,s,s,f=>{k(this,H,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},f=>{},f=>{}][u]||(()=>{}))(o,d)}),r[0]<4){let o=0;i.forEach(d=>{o=o<<4,o+=d}),o-=1024}}}}).add([76,2,1],(r,n,l)=>{e.dispatchEvent("mupromptex");let i="XG ";r[0]<32?(i+="reverb ",r.subarray(1).forEach((s,o)=>{([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: ${er(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]+o]||function(){console.warn(`Unknown XG reverb address: ${r[0]}.`)})(s)})):r[0]<64?(i+="chorus ",r.subarray(1).forEach((s,o)=>{([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: ${Jt[d]}Hz`)},d=>{},d=>{console.debug(`${i}feedback: ${d}`)},d=>{console.debug(`${i}delay offset: ${tr(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+o]||function(){console.warn(`Unknown XG chorus address: ${r[0]}.`)})(s)})):r[0]<86?(i+="variation ",r.subarray(1).forEach((s,o)=>{([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+o]||function(){})(s)})):r[0]<97?(i+="variation ",r.subarray(1).forEach((s,o)=>{[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+o](s)})):r[0]>111&&r[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${r[0]}`)}).add([76,2,64],(r,n,l)=>{r.subarray(1).forEach((i,s)=>{let o=s+r[0];if(o==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let d=o-1>>2,u=o-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,n,l)=>{e.dispatchEvent("mupromptex");let i=r[0],s=r[1],o=`XG Insertion ${r[0]+1} `;r.subarray(2).forEach((d,u)=>{([f=>{e.setEffectTypeRaw(3+i,!1,f),console.info(`${o}main type: ${Et[f]}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))},f=>{e.setEffectTypeRaw(3+i,!0,f),console.debug(`${o}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))}][s+u]||function(){})(d)})}).add([76,6,0],(r,n,l)=>{let i=r[0];i<64?e.setLetterDisplay(r.subarray(1),"XG letter display",i):k(e,Ue,Date.now())}).add([76,7,0],(r,n,l)=>{let i=r[0];k(e,Y,0),k(e,ge,Date.now()+3200),t(e,oe,xe).fill(0);let s=r.subarray(1);for(let o=0;o>6-C&1,C++})}).add([76,8],(r,n)=>{e.dispatchEvent("mupromptex");let l=e.chRedir(r[0],n,!0),i=r[1],s=m.cc*l,o=`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,n,!0);t(e,K)[l]=w,l!=w&&(e.buildRchTree(),console.info(`${o}receives from CH${w+1}`)),t(e,de)[l]||(e.copyChSetup(w,l,!0),console.debug(`${o}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,x.xg),console.debug(`${o}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(`${o}EQ ${["bass","treble"][i&1]} gain: ${f-64}dB`):i<118?console.debug(d):i<120?console.debug(`${o}EQ ${["bass","treble"][i&1]} freq: ${f}`):console.debug(d)}),u&&t(e,D)[l]>1&&e.setDrumFirstWrite(l)}).add([76,9],(r,n)=>{let l=e.chRedir(r[0],n,!0),i=r[1],s=m.cc*l,o=`PLG-VL CH${l+1} `;r.subarray(2).forEach((d,u)=>{let f=u+i;switch(f){case 1:{console.info(`${o}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(`${o}${w} control source: ${ir(d)}`),d&&d<96&&e.allocateAce(130+$),t(e,Xe)[m.redir*l+$+2]=d,e.buildRccMap()):console.debug(`${o}${w} scale break point: ${d}`):(console.debug(`${o}${w} depth: ${d-64}`),t(e,b)[s+E[130+$]]=d)}}})}).add([76,10],(r,n,l)=>{}).add([76,16],(r,n,l)=>{}).add([76,17,0,0],(r,n,l)=>{}).add([76,112],(r,n,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,n)=>{let l=r[0],i="MU1000 System - ";r.subarray(1).forEach((s,o)=>{let d=l+o;d==8?console.debug(`${i}LCD contrast: ${s}.`):d==18?(t(e,X)[x.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")},()=>{k(e,ye,!!s),console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][d-64]()})}).add([73,10,0],(r,n)=>{let l=r[0],i=`MU1000 RS${t(e,ye)?"":" (ignored)"}: `;if(l<16)switch(l){case 2:{let s=e.chRedir(0,n,!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,n,!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),n,!0);e.dispatchEvent("channelactive",s)}}else if(l<36){let s=e.chRedir(l-32<<4,n,!0);t(e,ye)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),k(e,ht,l-32)),console.info(`${i}Show CH${s+1}~CH${s+16}`)}}).add([73,11,0],(r,n)=>{let l="MU1000 System - channel ",i="Octavia System - channel ",s=r[0];r.subarray(1).forEach((o,d)=>{let u=s+d;([()=>{e.setChActive(o,1),e.dispatchEvent("channelactive",o),O()&&console.debug(`${l}current part: CH${o+1}`)},()=>{o<5?(e.dispatchEvent("portrange",1<{o<16?(e.dispatchEvent("portstart",o),console.debug(`${i}start port: ${"ABCDEFGHIJKLMNOP"[o]}`)):(e.dispatchEvent("portstart",255),console.debug(`${i}start port: reset`))}][u]||(()=>{console.debug(`${l}unknown address: ${u}`)}))()})}).add([93,3],(r,n)=>{let l=e.chRedir(r[0],n,!0),i=`PLG-100SG CH${l+1} `,s=Date.now();if(r[1]==0){let o="",d=0;r.subarray(2).forEach((u,f)=>{f%2==0?o+=rr[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:`${ar(o)}`,amend:!0}),k(e,ft,s+Math.ceil(d/2)+t(e,dt)),O()&&console.debug(`${i}vocals: ${o}`)}else console.warn(`Unknown PLG-100SG data: ${r}`)}).add([98,0],(r,n,l)=>{e.dispatchEvent("mupromptex");let i=r[0],s=r.length-5,o=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,o));if(d!=r[o]){console.info(`Bad PLG-DX checksum ${r[o]} - should be ${d}.`);return}r[0]=98,t(e,ce).run(r.subarray(0,o),n,l,{noAce:!0})}).add([98,96],(r,n,l,i)=>{let s=e.chRedir(r[0],n,!0),o=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)[o+E[w]]=u,e.dispatchEvent("cc",{part:s,cc:w,data:u})}}})}).add([100,0],(r,n,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),o=r[r.length-1];if(s!=o){console.warn(`Yamaha DX7+ dump SysEx checksum mismatch! Expected ${s}, but got ${o}: -`,r);return}a.run(i.subarray(1))}).add([100,76],(r,n,l)=>{let i=r[0]>>4,s=r[0]&15,o=r[1];switch(i){case 2:{let d=e.chRedir(s,n,!0),u=m.cc*d;r.subarray(2).forEach((f,$)=>{let w=$+o;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,n,l)=>{l==115?(e.switchMode("doc",!0),e.setPortMode(e.getTrackPort(n),1,x.doc),console.info("MIDI reset: DOC")):console.debug(`Unknown Yamaha SysEx: 67, ${l}, ${r.join(", ")}`)}).add([1,17,15,89],(r,n,l)=>{l==115?(e.setEffectType(0,24,r[0]|16),e.dispatchEvent("efxreverb",e.getEffectType(0))):console.debug(`Unknown Yamaha SysEx: 67, ${l}, ${r.join(", ")}`)}).add([1,24],(r,n,l)=>{if(l==115){for(let i=0;i<16;i++){let s=e.chRedir(i,n,!0);t(e,b)[s*m.cc+E[91]]=127}console.info("DOC Global Reverb: on")}else console.debug(`Unknown Yamaha SysEx: 67, ${l}, ${r.join(", ")}`)}),a.add([14,31],(r,n,l)=>{t(e,b)[m.cc*r[0]+E[64]]=0,t(e,F).ano(r[0]),e.switchMode("xg"),e.setPortMode(e.getTrackPort(n),1,x.xg),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${r[0]+1}.`)}).add([76,112],async r=>{let n=r[0],l=m.cc*n,i=m.ext*n,s=m.cvn*n;t(e,ie)[i]=e.EXT_DX,t(e,Ee)[n]=1;let o=t(e,$t).subarray(s,s+m.cvn);o.fill(32),r.subarray(1).forEach((d,u)=>{if(u<10)o[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:n,cc:f,data:d})}}}),t(e,I)[n]=n&127,t(e,b)[m.cc*n+E[0]]=35,t(e,b)[m.cc*n+E[32]]=n>>7|4,e.dispatchEvent("voice",{part:n}),console.debug(`DX7+ CH${n+1} dump: %o`,r)});let c=function(r,n,l,i){},p=function(r,n){e.dispatchEvent("mupromptex");let l=r*m.dpn,i=n[0],s=n[1];n.subarray(2).forEach((o,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,o),t(e,ee)[(l+le[f])*m.dnc+i]=o):O()&&console.debug(`XG-style drum param ${u} has no writes.`)})},y=function(r,n,l){e.dispatchEvent("mupromptex");let i=r*m.dpn,s=(n<<7)+l[0];l.subarray(1).forEach((o,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,o),t(e,ee)[(i+le[w])*m.dnc+f]=o):O()&&console.debug(`GS-style drum param ${$} has no writes.`)})};t(this,ce).add([76,48],(r,n,l)=>{p(0,r)}).add([76,49],(r,n,l)=>{p(1,r)}).add([76,50],(r,n,l)=>{p(2,r)}).add([76,51],(r,n,l)=>{p(3,r)}).add([76,52],(r,n,l)=>{p(4,r)}).add([76,53],(r,n,l)=>{p(5,r)}).add([76,54],(r,n,l)=>{p(6,r)}).add([76,55],(r,n,l)=>{p(7,r)}),t(this,ce).add([89,0],(r,n,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 o=e.eprom.data;r.subarray(4).forEach((d,u)=>{let f=u>>3,$=u&7;if($==7)for(let w=0;w<7;w++)o[s+7*f+w]+=(d>>6-w&1)<<7;else o[s+7*f+$]=d})}}).add([89,1],(r,n,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,n,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((o,d)=>{let u=d>>3,f=d&7;if(f==7)for(let $=0;$<7;$++)s[i+7*u+$]+=(o>>6-$&1)<<7;else s[i+7*u+f]=o})}}).add([89,3],(r,n,l)=>{}),t(this,ce).add([39,48],(r,n,l)=>{}).add([43,0,0],(r,n,l)=>{e.dispatchEvent("mupromptex");let i=[0,0,0,0],s=(o,d)=>{i[d]=o};if(r.subarray(1).forEach((o,d)=>{let u=d+r[0];[s,s,s,s,()=>{k(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}.`)}][u](o,u)}),r[0]<4){let o=0;i.forEach(d=>{o=o<<4,o+=d}),o-=1024}}).add([43,1,0],(r,n,l)=>{e.dispatchEvent("mupromptex")}).add([43,2],(r,n,l)=>{e.dispatchEvent("mupromptex");let i=e.chRedir(r[0],n,!0),s=r[1],o=m.cc*i,d=`TG300 CH${i+1} `;r.subarray(2).forEach((u,f)=>{f<5?([()=>{},()=>{t(e,b)[o+E[0]]=u,e.dispatchEvent("voice",{part:i})},()=>{t(e,b)[o+E[32]]=u,e.dispatchEvent("voice",{part:i})},()=>{t(e,I)[i]=u,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(u,n,!0);t(e,K)[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)[o+E[7]]=u},!1,!1,()=>{t(e,b)[o+E[10]]=u||128},!1,!1,()=>{console.debug(`${d} AC1 at cc${u}`)},()=>{console.debug(`${d} AC2 at cc${u}`)},()=>{t(e,b)[o+E[128]]=u,e.allocateAce(128)},()=>{t(e,b)[o+E[93]]=u},()=>{t(e,b)[o+E[91]]=u},()=>{t(e,b)[o+E[94]]=u},()=>{t(e,b)[o+E[76]]=u},()=>{t(e,b)[o+E[77]]=u},()=>{t(e,b)[o+E[74]]=u},()=>{t(e,b)[o+E[71]]=u},()=>{t(e,b)[o+E[73]]=u},()=>{t(e,b)[o+E[75]]=u},()=>{t(e,b)[o+E[72]]=u},()=>{t(e,b)[o+E[78]]=u}][f+s-21]||(()=>{}))(u,f+s):f<95||([()=>{t(e,b)[o+E[65]]=u},()=>{t(e,b)[o+E[5]]=u}][f+s-95]||(()=>{}))(u,f+s))})}).add([43,7,0],(r,n,l)=>{let i=r[0];e.setLetterDisplay(r.subarray(1),"TG300 letter display",i)}).add([43,7,1],(r,n,l)=>{k(e,Y,0),k(e,ge,Date.now()+3200),t(e,oe,xe).fill(0),r.forEach(function(i,s){let o=Math.floor(s/16),d=s%16,u=(d*3+o)*7,f=7,$=0;for(u-=d*5,o==2&&(f=2);$>6-$&1,$++})}),t(this,he).add([66,18,0,0,127],(r,n,l)=>{e.switchMode("sc",!0),e.setPortMode(e.getTrackPort(n),2,x.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,X)[x.sc][1]=t(e,B).sc,k(e,_,!1),t(e,Ce).fill(0),console.info(`GS system to ${["single","dual"][r[0]]} mode.`)}).add([66,18,64,0],(r,n,l)=>{switch(r[0]){case 127:{e.switchMode("gs",!0),e.setPortMode(e.getTrackPort(n),2,x.gs),t(e,X)[x.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,k(e,_,!1),t(e,Ce).fill(0),console.info("MIDI reset: GS");break}default:{e.dispatchEvent("mupromptex");let i=[0,0,0,0],s=(o,d)=>{i[d]=o};if(r.subarray(1).forEach((o,d)=>{let u=d+r[0];[s,s,s,s,f=>{k(this,H,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},f=>{},f=>{}][u](o,d)}),r[0]<4){let o=0;i.forEach(d=>{o=o<<4,o+=d}),o-=1024}}}}).add([66,18,64,1],(r,n,l)=>{e.dispatchEvent("mupromptex");let i=r[0];if(i<16){let s="".padStart(i," ");r.subarray(1).forEach((o,d)=>{s+=String.fromCharCode(Math.max(32,o))}),s=s.padEnd(16," "),console.debug(`GS patch name: ${s}`)}else i<48||(i<65?r.subarray(1).forEach((s,o)=>{let d=`GS ${i+o>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: ${sr[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+o-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?r.subarray(1).forEach((s,o)=>{let d="GS delay ";([()=>{console.info(`${d}type: ${nr[s]}`),e.setEffectType(2,40,32+s),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${d}to reverb: ${re(s)}`)}][i+o-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],(r,n,l)=>{let i="GS EQ ";r.subarray(1).forEach((s,o)=>{([()=>{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]+o]||function(){console.warn(`Unknown GS EQ address: ${r[0]+o}`)})()})}).add([66,18,64,3],(r,n,l)=>{e.dispatchEvent("mupromptex");let i="GS EFX ",s=function(o,d){let u=cr(t(e,se).subarray(10,12),d,o);u&&console.debug(`${i}${Nt(t(e,se).subarray(10,12))} ${u}`)};r.subarray(1).forEach((o,d)=>{([()=>{e.setEffectTypeRaw(3,!1,32+o),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,o),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(o)}dB`)},()=>{console.debug(`${i}to chorus: ${re(o)}dB`)},()=>{console.debug(`${i}to delay: ${re(o)}dB`)},!1,()=>{console.debug(`${i}1 source: ${o}`),o&&o<96&&e.allocateAce(o)},()=>{console.debug(`${i}1 depth: ${o-64}`)},()=>{console.debug(`${i}2 source: ${o}`),o&&o<96&&e.allocateAce(o)},()=>{console.debug(`${i}2 depth: ${o-64}`)},()=>{console.debug(`${i}to EQ: ${o?"ON":"OFF"}`)}][r[0]+d]||function(u,f){console.warn(`Unknown GS EFX address: ${f}`)})(o,r[0]+d)})}).add([66,18,65],(r,n,l)=>{y((r[0]>>4)+1<<1,r[0]&15,r.subarray(1))}).add([69,18,16],(r,n,l)=>{var i;switch(r[0]){case 0:{let s=r[1];e.setLetterDisplay(r.subarray(2),"GS display text",s);break}case 32:{k(e,ge,Date.now()+3200),r[1]==0&&(r[2]?(k(e,Y,Math.max(Math.min(r[2]-1,9),0)),O()&&console.debug(`GS switch display page ${r[2]-1}.`)):(k(e,Y,0),k(e,ge,Date.now()),O()&&console.debug("GS disable display page.")));break}default:if(r[0]<6){t(e,Y)>9&&k(e,Y,0);let s=r[0]-1<<1|r[1]>>6;t(e,Y)==s&&k(e,ge,Date.now()+3200),(i=t(e,Se)[s])!=null&&i.length||(t(e,Se)[s]=new Uint8Array(256));let o=t(e,Se)[s];O()&&console.debug(`GS frame draw page ${s}.`);let d=r[1]&63;o.fill(0),r.subarray(2).forEach(function(f,$){let w=$+d,C=Math.floor(w/16),M=w%16,G=(M*4+C)*5,Re=5,_e=0;for(G-=M*4,C==3&&(Re=1);_e>4-_e&1,_e++})}else console.warn(`Unknown GS display section: ${r[0]}`)}});let v=function(r,n,l){e.dispatchEvent("mupromptex");let i=r[0],s=m.cc*n,o=m.rpn*n,d=`GS CH${n+1} `;i<3?(r.subarray(1).forEach((u,f)=>{[()=>{t(e,b)[s+E[0]]=u},()=>{t(e,I)[n]=u},()=>{let $=0;u<16?$=e.chRedir(u,l,!0):$=m.ch,t(e,K)[n]=$,n!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))}][i+f]()}),e.dispatchEvent("voice",{part:n})):i<19||(i<44?r.subarray(1).forEach((u,f)=>{([()=>{t(e,ae)[n]=+!u},!1,()=>{e.setChType(n,u<<1,x.gs),console.debug(`${d}type: ${u?"drum ":"melodic"}${u||""}`)},()=>{t(e,R)[o+3]=u,t(e,L)[m.rpnt*n+2]=1,e.dispatchEvent("pitch",{part:n,pitch:e.getPitchShift(n)})},!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)[o+1]=u,t(e,L)[m.rpnt*n+1]=1,e.dispatchEvent("pitch",{part:n,pitch:e.getPitchShift(n)})},()=>{t(e,R)[o+2]=u,t(e,L)[m.rpnt*n+1]=1,e.dispatchEvent("pitch",{part:n,pitch:e.getPitchShift(n)})},()=>{t(e,b)[s+E[94]]=u}][i+f-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},S=function(r,n){let l=r[0],i=`GS CH${n+1} `;l<2?r.subarray(1).forEach((s,o)=>{[()=>{t(e,b)[m.cc*n+E[32]]=s},()=>{}][l+o]()}):l<32?console.warn(`Unknown GS misc address: ${l}`):l<35?r.subarray(1).forEach((s,o)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][s]}`),t(e,ot)[n]=s,e.dispatchEvent("partefxtoggle",{part:n,active:s})}][l+o-32]()}):console.warn(`Unknown GS misc address: ${l}`)};t(this,he).add([66,18,64,16],(r,n)=>{v(r,e.chRedir(9,n,!0),n)}).add([66,18,64,17],(r,n)=>{v(r,e.chRedir(0,n,!0),n)}).add([66,18,64,18],(r,n)=>{v(r,e.chRedir(1,n,!0),n)}).add([66,18,64,19],(r,n)=>{v(r,e.chRedir(2,n,!0),n)}).add([66,18,64,20],(r,n)=>{v(r,e.chRedir(3,n,!0),n)}).add([66,18,64,21],(r,n)=>{v(r,e.chRedir(4,n,!0),n)}).add([66,18,64,22],(r,n)=>{v(r,e.chRedir(5,n,!0),n)}).add([66,18,64,23],(r,n)=>{v(r,e.chRedir(6,n,!0),n)}).add([66,18,64,24],(r,n)=>{v(r,e.chRedir(7,n,!0),n)}).add([66,18,64,25],(r,n)=>{v(r,e.chRedir(8,n,!0),n)}).add([66,18,64,26],(r,n)=>{v(r,e.chRedir(10,n,!0),n)}).add([66,18,64,27],(r,n)=>{v(r,e.chRedir(11,n,!0),n)}).add([66,18,64,28],(r,n)=>{v(r,e.chRedir(12,n,!0),n)}).add([66,18,64,29],(r,n)=>{v(r,e.chRedir(13,n,!0),n)}).add([66,18,64,30],(r,n)=>{v(r,e.chRedir(14,n,!0),n)}).add([66,18,64,31],(r,n)=>{v(r,e.chRedir(15,n,!0),n)}).add([66,18,64,64],(r,n)=>{S(r,e.chRedir(9,n,!0))}).add([66,18,64,65],(r,n)=>{S(r,e.chRedir(0,n,!0))}).add([66,18,64,66],(r,n)=>{S(r,e.chRedir(1,n,!0))}).add([66,18,64,67],(r,n)=>{S(r,e.chRedir(2,n,!0))}).add([66,18,64,68],(r,n)=>{S(r,e.chRedir(3,n,!0))}).add([66,18,64,69],(r,n)=>{S(r,e.chRedir(4,n,!0))}).add([66,18,64,70],(r,n)=>{S(r,e.chRedir(5,n,!0))}).add([66,18,64,71],(r,n)=>{S(r,e.chRedir(6,n,!0))}).add([66,18,64,72],(r,n)=>{S(r,e.chRedir(7,n,!0))}).add([66,18,64,73],(r,n)=>{S(r,e.chRedir(8,n,!0))}).add([66,18,64,74],(r,n)=>{S(r,e.chRedir(10,n,!0))}).add([66,18,64,75],(r,n)=>{S(r,e.chRedir(11,n,!0))}).add([66,18,64,76],(r,n)=>{S(r,e.chRedir(12,n,!0))}).add([66,18,64,77],(r,n)=>{S(r,e.chRedir(13,n,!0))}).add([66,18,64,78],(r,n)=>{S(r,e.chRedir(14,n,!0))}).add([66,18,64,79],(r,n)=>{S(r,e.chRedir(15,n,!0))}),t(this,ke).add([54,65],(r,n)=>{let l=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(l,!0),e.setPortMode(e.getTrackPort(n),1,x[l]);let i=r[r.length-1],s=r.subarray(0,r.length-1),o=De(s);o!=i&&(console.info(`X5D multi parameters checksum mismatch! Expected ${o}, got ${i}.`),console.debug(r));let d=(r[1]<<7)+r[0],u=(r[3]<<7)+r[2],f=e.chRedir(d&15,n,!0),$=m.cc*f;[()=>{u<1||(u<101?(e.setChType(f,e.CH_MELODIC,x.x5d),t(e,I)[f]=u-1,t(e,b)[$+E[0]]=t(e,B).x5):u<229?(e.setChType(f,e.CH_MELODIC,x.x5d),t(e,I)[f]=u-101,t(e,b)[$+E[0]]=56):(e.setChType(f,e.CH_DRUMS,x.x5d),t(e,I)[f]=Er[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,n)=>{e.dispatchEvent("mupromptex");let l=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(l),e.setPortMode(e.getTrackPort(n),1,x[l]);let i="",s=t(e,B).x5,o=0,d=0,u="MSB\tPRG\tLSB\tNME";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} ${o} ${d} ${i.trim().replace("Init Voice","")}`,o++,i="";break}}o>99&&(s=90,o=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,n)=>{e.dispatchEvent("mupromptex");let l=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(l),e.setPortMode(e.getTrackPort(n),1,x[l]);let i="",s=90,o=0,d=0,u="MSB\tPRG\tLSB\tNME";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} ${o} ${d} ${i.trim().replace("Init Combi","")}`,o++,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,n)=>{let l=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(l),e.setPortMode(e.getTrackPort(n),1,x[l]),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][r[0]]} mode.`)}).add([54,85],(r,n)=>{e.dispatchEvent("mupromptex");let l=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(l),e.setPortMode(e.getTrackPort(n),1,x[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,n)=>{e.dispatchEvent("mupromptex");let l=t(e,B).x5=="81"?"05rw":"x5d";e.switchMode(l,!0);let i=e.getTrackPort(n);if(t(e,V)[i]&&t(e,V)[i]!=x[l])if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${n}. Port ${String.fromCharCode(65+i)} mode "${W[t(e,V)[i]]}" mismatch, should be "${l}".`);return}else console.info(`Track ${n} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+i)}.`);e.setPortMode(i,1,x[l]),pe(r,function(s,o,d,u){if(o<192){let f=e.chRedir(Math.floor(o/12),n,!0),$=f*m.cc;switch(o%12){case 0:{s<128?(e.setChType(f,e.CH_MELODIC,x.x5d),t(e,b)[$+E[0]]=t(e,B).x5,t(e,I)[f]=s):(e.setChType(f,e.CH_DRUMS,x.x5d),t(e,b)[$+E[0]]=62,t(e,I)[f]=Er[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,n,!0),C=s>>4;t(e,K)[f]=s,(w!=f||C)&&(console.info(`X5D Part CH${f+1} receives from CH${w+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(o-192,n,!0)}})}),t(this,he).add([22,18,127],(r,n,l)=>{e.switchMode("mt32",!0),e.setPortMode(e.getTrackPort(n),1,x.mt32),k(e,_,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(r,n,l)=>{e.switchMode("mt32");let i=e.chRedir(l,n,!0),s=r[1];r.subarray(2).forEach((o,d)=>{let u=d+s;t(e,Ae)[u+(i-1)*16]=o,([!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]=o+40,t(e,L)[m.rpnt*i+2]=1},()=>{t(e,R)[i*m.rpn+1]=o+14,t(e,L)[m.rpnt*i+1]=1},()=>{t(e,R)[i*m.rpn]=o,t(e,L)[m.rpnt*i]=1},!1,()=>{t(e,b)[m.cc*i+E[91]]=o?127:0},!1,()=>{t(e,b)[m.cc*i+E[7]]=o},()=>{t(e,b)[m.cc*i+E[10]]=Math.ceil(o*9.05)}][u]||(()=>{}))()})}).add([22,18,1],(r,n,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((o,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 ${$}: ${o}`),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(o*1.27)},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=o*9+1&127},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=o?127:0}][$]()})}).add([22,18,2],(r,n,l)=>{e.switchMode("mt32");let i=e.chRedir(l,n,!0),s=r[1]+(r[0]<<7);s<10&&(t(e,Ee)[i]=1),r.subarray(2).forEach((o,d)=>{let u=d+s;u<14&&(t(e,me)[(i-1)*m.cmt+u]=o)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(r,n,l)=>{e.switchMode("mt32");let i=l&7;if(r[0]){let s=(r[0]-1<<7)+r[1]-16;r.subarray(2).forEach((o,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 ${$}: ${o}`),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(o*1.27)},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=o*9+1&127},()=>{t(e,ee)[(w+le[26])*m.dnc+f]=o?127:0}][$]()})}else{let s=r[1];r.subarray(2).forEach((o,d)=>{let u=d+s;t(e,Ae)[u]=o;let f=e.chRedir(1+(u>>4),n,!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]=o+40,t(e,L)[m.rpnt*f+2]=1},()=>{t(e,R)[f*m.rpn+1]=o+14,t(e,L)[m.rpnt*f+1]=1},()=>{t(e,R)[f*m.rpn]=o,t(e,L)[m.rpnt*f]=1},!1,()=>{t(e,b)[m.cc*f+E[91]]=o?127:0},!1,()=>{t(e,b)[m.cc*f+E[7]]=o},()=>{t(e,b)[m.cc*f+E[10]]=Math.ceil(o*9.05)}][$]||(()=>{}))()})}}).add([22,18,4],(r,n,l)=>{e.switchMode("mt32");let i=r[1]+(r[0]<<7),s=[];r.subarray(2).forEach((o,d)=>{let u=d+i,f=e.chRedir(Math.floor(u/246+1),n,!0),$=u%246;$<14&&(t(e,me)[(f-1)*m.cmt+$]=o),$<10&&(t(e,Ee)[f]=1),s.indexOf(f)<0&&s.push(f)}),s.forEach(o=>{e.dispatchEvent("voice",{part:o})})}).add([22,18,5],(r,n,l)=>{e.switchMode("mt32");let i=(r[0]<<7)+r[1];r.subarray(2).forEach((s,o)=>{let d=i+o,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 G=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,n,l)=>{e.switchMode("mt32");let i=((r[0]&1)<<7)+r[1],s=r[0]>>1,o=!1;if(r.subarray(2).forEach((d,u)=>{let f=i+u;f{e.switchMode("mt32");let i=r[1],s=!1,o=function(d,u){t(e,K)[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,o,o,o,o,o,o,o,o,o,()=>{k(e,H,d),e.dispatchEvent("mastervolume",t(e,H))}][f]||(()=>{}))(d,u)}),s&&e.buildRchTree()}).add([22,18,32],(r,n,l)=>{e.switchMode("mt32");let i=r[1],s=" ".repeat(i);r.subarray(2).forEach(o=>{o>31?s+=String.fromCharCode(o):s+=" "}),k(e,Le,s.padStart(20," ")),k(e,Ue,Date.now()+3200)}).add([22,18,82],(r,n)=>{let l=e.chRedir(0,n,!0);for(let i=0;i<16;i++)t(e,F).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,n)=>{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(n),2,x.ns5r),k(e,_,!1),console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][r[0]]} mode.`)}).add([66,1],(r,n)=>{let l=["ns5r","05rw"][r[0]];e.switchMode(l,!0),e.setPortMode(e.getTrackPort(n),2,x[l]),k(e,_,!1)}).add([66,18,0,0],(r,n)=>{let l=r[0];switch(l){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(n),2,x.ns5r),k(e,_,!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=(o,d)=>{i[d]=o};if(r.subarray(1).forEach((o,d)=>{[s,s,s,s,()=>{k(e,H,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][l+d]()}),r[0]<4){let o=0;i.forEach(d=>{o=o<<4,o+=d}),o-=1024}}}}).add([66,18,0,1],(r,n)=>{}).add([66,18,0,2],(r,n)=>{}).add([66,18,1],(r,n)=>{e.dispatchEvent("mupromptex");let l=e.chRedir(r[0],n,!0),i=l*m.cc,s=r[1],o=`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,n,!0);t(e,K)[l]=$,l!=$&&(e.buildRchTree(),console.info(`${o}receives from CH${$+1}`))},()=>{t(e,ae)[l]=+!d},()=>{e.setChType(l,d,x.ns5r),console.debug(`${o}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,n)=>{let l=r[0];if(l<32)e.setLetterDisplay(r.subarray(1,33),"NS5R letter display");else{let i=l-32;k(e,ge,Date.now()+3200),k(e,Y,10),t(e,oe,xe).fill(0);let s=r.subarray(1),o=4;s.forEach(function(d,u){let f=u+i,$=f>>4,w=f&15;if(f<80){let C=$>3,M=0,G=$0;)t(e,oe,xe)[w*32+$*7+(G-M)]=C&1,C=C>>1,M++}})}}).add([66,18,48],(r,n,l)=>{p(0,r)}).add([66,18,49],(r,n,l)=>{p(1,r)}).add([66,18,50],(r,n,l)=>{p(2,r)}).add([66,18,51],(r,n,l)=>{p(3,r)}).add([66,18,52],(r,n,l)=>{p(4,r)}).add([66,18,53],(r,n,l)=>{p(5,r)}).add([66,18,54],(r,n,l)=>{p(6,r)}).add([66,18,55],(r,n,l)=>{p(7,r)}).add([66,52],(r,n)=>{e.switchMode("ns5r"),k(e,_,!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,n)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r"),k(e,_,!1);let l="",i=r[r.length-1],s=r.subarray(0,r.length-1),o=De(s);o!=i&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${o}, got ${i}.`),console.debug(r));let d=e.getTrackPort(n);if(t(e,V)[d]&&t(e,V)[d]!=x.ns5r)if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${n}. Port ${String.fromCharCode(65+d)} mode "${W[t(e,V)[d]]}" mismatch, should be "ns5r".`);return}else console.info(`Track ${n} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+d)}.`);e.setPortMode(d,2,x.ns5r),pe(s,function(u,f){switch(!0){case f<2944:{let $=e.chRedir(Math.floor(f/92),n,!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,n,!0);t(e,K)[$]=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,n)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let l="",i=80,s=0,o=0,d="MSB\tPRG\tLSB\tNME";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:{o=u&127;break}case $==13:{d+=` -${i} ${s} ${o} ${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,n)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let l="",i=88,s=0,o=0,d="MSB\tPRG\tLSB\tNME";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} ${o} ${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,n,l)=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][r[0]]||"white")}).add([66,127],(r,n,l)=>{let i=r[r.length-1],s=r.subarray(0,r.length-1),o=De(s);o!=i&&(console.info(`NS5R screen dump checksum mismatch! Expected ${o}, 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,n,l)=>{t(e,ke).run([66,...r],n,l)}),t(this,We).add([16,0,8,0],(r,n,l)=>{let i=(r[2]<<4)+r[3],s="K11 ";([()=>{e.switchMode("k11",!0),e.setPortMode(e.getTrackPort(n),2,x.k11),k(e,_,!1),t(e,X)[x.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,n,l)=>{e.dispatchEvent("mupromptex");let i=e.chRedir(r[1],n,!0),s=m.cc*i,o=m.rpn*i,d=(r[3]<<4)+r[4],u=`K11 CH${i+1} `;([()=>{d<128?(e.setChType(i,e.CH_MELODIC,x.k11),t(e,b)[s+E[0]]=0,t(e,I)[i]=d):(e.setChType(i,e.CH_DRUMS,x.k11),t(e,I)[i]=d-128),e.dispatchEvent("voice",{part:i})},()=>{let f=e.chRedir(d,n,!0);t(e,K)[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)[o+3]=d+40,t(e,L)[m.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,R)[o+1]=d>>1,t(e,R)[o+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,n,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,n,l)=>{e.dispatchEvent("mupromptex");let i=(r[2]<<4)+r[3],s=e.chRedir(r[1],n,!0),o=s*m.cc;[()=>{i<128?(e.setChType(s,e.CH_MELODIC,x.k11),t(e,b)[o+E[0]]=0,t(e,b)[o+E[32]]=0,t(e,I)[s]=i):i<160?(e.setChType(s,e.CH_MELODIC,x.k11),t(e,b)[o+E[0]]=0,t(e,b)[o+E[32]]=7,t(e,I)[s]=i-100):(e.setChType(s,e.CH_DRUMS,x.k11),t(e,b)[o+E[0]]=122,t(e,b)[o+E[32]]=0,t(e,I)[s]=i-160),e.dispatchEvent("voice",{part:s})},()=>{let d=e.chRedir(i,n,!0);t(e,K)[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,n,l)=>{e.dispatchEvent("mupromptex");let i=(r[2]<<4)+r[3],s=e.chRedir(r[1],n,!0),o=s*m.cc,d=s*m.rpn,u=`GMLX CH${s+1} `;[()=>{e.setChActive(s,i)},()=>{t(e,b)[o+E[7]]=i},()=>{t(e,b)[o+E[10]]=i},()=>{t(e,b)[o+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,n,l)=>{let i=r[2];switch(r[0]){case 0:{switch(r[1]){case 4:{e.dispatchEvent("mupromptex"),k(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(n),1,x.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,n,!0);if(r[1]==2){let o=e.chRedir(i,n,!0);t(e,K)[s]=o,s!=o&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${o+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,n,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,n,l)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...r]);t(e,ce).run(i,n,l)}).add([127,1,0,0],(r,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES system ",s=r[0];r.subarray(1).forEach((o,d)=>{([()=>{k(e,H,o*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,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES reverb ",s=r[0];r.subarray(1).forEach((o,d)=>{([()=>{e.setEffectTypeRaw(0,!1,o&15|112)},()=>{e.setEffectTypeRaw(0,!0,o)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxreverb",e.getEffectType(0))}).add([127,1,0,37,54,2],(r,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES chorus ",s=r[0];r.subarray(1).forEach((o,d)=>{([()=>{e.setEffectTypeRaw(1,!1,o&15|112)},()=>{e.setEffectTypeRaw(1,!0,o)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxchorus",e.getEffectType(1))}).add([127,1,0,34,54,3],(r,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES insert 1 ",s=r[0];r.subarray(1).forEach((o,d)=>{([()=>{e.setEffectTypeRaw(3,!1,o&15|112)},()=>{e.setEffectTypeRaw(3,!0,o)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxinsert0",e.getEffectType(3))}).add([127,1,0,34,54,4],(r,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES insert 2 ",s=r[0];r.subarray(1).forEach((o,d)=>{([()=>{e.setEffectTypeRaw(4,!1,o&15|112)},()=>{e.setEffectTypeRaw(4,!0,o)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxinsert1",e.getEffectType(4))}).add([127,1,0,35,54,17],(r,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES variation ",s=r[0];r.subarray(1).forEach((o,d)=>{([()=>{e.setEffectTypeRaw(2,!1,o&15|112)},()=>{e.setEffectTypeRaw(2,!0,o)}][s+d]||(()=>{}))()}),e.dispatchEvent("efxdelay",e.getEffectType(2))}).add([127,1,0,58,55],(r,n,l)=>{e.dispatchEvent("mupromptex"),e.switchMode("s90es");let i=e.getTrackPort(n);if(t(e,V)[i]&&t(e,V)[i]!=t(e,B).smotif)if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${n}. Port ${String.fromCharCode(65+i)} mode "${W[t(e,V)[i]]}" mismatch, should be "${W[t(e,B).smotif]}".`);return}else console.info(`Track ${n} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+i)}.`);let s=e.chRedir(r[0],n,!0),o=m.cc*s,d=r[1];r[0]>15&&(s=r[0]+32);let u=`Track ${n} 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)[o+E[0]]=f,e.dispatchEvent("voice",{part:s})},()=>{f&&e.setChActive(s,1),t(e,b)[o+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,n,!0);t(e,K)[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)[o+E[7]]=f},()=>{f!=64&&e.setChActive(s,1),t(e,b)[o+E[10]]=f},!1,!1,!1,()=>{t(e,b)[o+E[91]]=f},()=>{f&&e.setChActive(s,1),t(e,b)[o+E[93]]=f},()=>{f&&e.setChActive(s,1),t(e,b)[o+E[94]]=f},()=>{f!=127&&e.setChActive(s,1),t(e,b)[o+E[128]]=f,e.allocateAce(128)},()=>{},()=>{f!=64&&e.setChActive(s,1),t(e,b)[o+E[74]]=f},()=>{f!=64&&e.setChActive(s,1),t(e,b)[o+E[71]]=f},!1,()=>{t(e,b)[o+E[65]]=f},()=>{t(e,b)[o+E[5]]=f},()=>{}][d+$]||(()=>{}))()})}).add([127,1,54,16],(r,n,l)=>{e.switchMode("s90es");let i=r[0];r.subarray(1).forEach((s,o)=>{let u=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let f=s-64},()=>{let f=st[s]},()=>{let f=s/10},()=>{let f=s}][i+o&3]||(()=>{}))()})}),t(this,he).add([0,72,18,0,0,0,0],(r,n,l)=>{e.switchMode("sd",!0),e.setPortMode(e.getTrackPort(n),2,x.sd),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(r,n,l)=>{e.dispatchEvent("mupromptex");let i=r[0]>>5,s=r[0]&31;switch(i){case 0:{let o=r[0]>>1,d=r[1];switch(o){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=o-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 o=e.chRedir(s,n,!0),d=r[1],u=o*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)[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,b)[u+E[32]]=f,e.dispatchEvent("voice",{part:o})},()=>{t(e,I)[o]=f,e.dispatchEvent("voice",{part:o})},()=>{t(e,b)[u+E[7]]=f},()=>{t(e,b)[u+E[10]]=f},()=>{},()=>{},()=>{f<2&&(t(e,ae)[o]=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)[o]?t(e,b)[u+E[0]]=104|f:t(e,b)[u+E[0]]=96|f,e.dispatchEvent("voice",{part:o})):console.debug(`Unknown SD-90 global CH${o+1} param setup message: -%o`,r))});break}case 2:{let o=e.chRedir(s,n,!0),d=r[1];console.debug(`Unknown SD-90 global CH${o+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,n,l)=>{e.switchMode("krs"),e.setPortMode(e.getTrackPort(n),1,x.krs),console.debug("Might be KORG KROSS 2 mode reset... Not sure.")}).add([0,1,73,117,2,37],(r,n,l)=>{e.switchMode("krs");let i=e.getTrackPort(n);if(t(e,V)[i]&&t(e,V)[i]!=x.krs)if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+i)} mode "${W[t(e,V)[i]]}" mismatch, should be "krs".`);return}else console.info(`Track ${n} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+i)}.`);e.setPortMode(e.getTrackPort(n),1,x.krs);let s="KROSS 2 BMT1 ",o="";pe(r,(d,u)=>{if(u<24)o+=String.fromCharCode(Math.max(32,d));else if(!(u<1276)){let f=u-1276,$=e.chRedir(Math.floor(f/44),n,!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,n,!0);t(e,K)[$]=M,console.info(`${s}CH${$+1} receives from CH${M+1}`)},!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]||(()=>{}))()}}),o=o.trimRight(),e.dispatchEvent("metacommit",{type:"EORTitle",data:o})})}chRedir(e,a,h){let c=this;if(t(c,Be)[a])return(t(c,Be)[a]-1)*16+e;if(t(c,A)==x.sc){if(h==1)return e;let p=0,y=!0;for(;y;)t(c,Ce)[e+p]==0?(t(c,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 c;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,c=t(a,b).subarray(h,h+m.cc);return c[E[0]]=c[E[0]]||t(a,X)[a.getChModeId(e)][0],c[E[32]]=c[E[32]]||t(a,X)[a.getChModeId(e)][1],c[E[0]]==nt.bank0&&(c[E[0]]=0),c}getCcCh(e,a){let h=this;if(vt.indexOf(a)<0)throw new Error("CC number not accepted");let c=t(h,b)[m.cc*e+E[a]];switch(a){case 0:{c=c||t(h,X)[h.getChModeId(e)][0],c==nt.bank0&&(c=0);break}case 32:{c=c||t(h,X)[h.getChModeId(e)][1];break}}return c}getCcAll(){let e=this,a=t(e,b).slice();for(let h=0;h0&&!c&&(t(p,b)[e*m.cc+E[0]]=t(p,X)[h][2])}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),c=new Uint8Array(h.length);return c.set(h),c[1]=c[1]||t(this,Pt),c}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,q).forEach(function(c,p){let y=Math.floor(c/128),v=c%128;e==y&&t(h,z)[c]>0&&a.set(v,{v:t(h,z)[c],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,q).forEach(function(a){let h=Math.floor(a/128);t(e,z)[a]>t(e,$e)[h]&&(t(e,$e)[h]=t(e,z)[a])}),t(this,$e)}getStrength(){let e=[],a=this;return this.getRawStrength().forEach(function(h,c){e[c]=Math.floor(h*t(a,b)[c*m.cc+E[7]]*t(a,b)[c*m.cc+E[11]]*t(a,H)/803288)}),e}getRpn(){return t(this,R)}getNrpn(){return t(this,ct)}getVoice(e,a,h,c){let p=this,y=e||t(p,X)[t(p,A)][0],v=a,S=h||t(p,X)[t(p,A)][1];y==nt.bank0&&(y=0),W[t(p,A)]=="ns5r"&&y>0&&y<56&&(S=3);let r=p.userBank.get(y,v,S,c);if(W[t(p,A)]=="mt32"&&r.name.indexOf("MT-m:")==0){let n=parseInt(r.name.slice(5)),l=n*m.cmt,i="";t(p,Ie).subarray(l,l+10).forEach(o=>{o>31&&(i+=String.fromCharCode(o))});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,S,c)),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 c="";switch(t(a,A)){case x.mt32:{t(a,me).subarray(m.cmt*(e-1),m.cmt*(e-1)+10).forEach(p=>{c+=String.fromCharCode(Math.max(p,32))}),c=c.trimRight();break}default:{let p=m.cvn*e;t(a,$t).subarray(p,p+m.cvn).forEach(y=>{c+=String.fromCharCode(Math.max(y,32))}),c=c.trimRight()}}c.length&&(h.ending="~",h.name=c)}return h}getRawPitch(){return t(this,Te)}getPitchShift(e){let a=this,h=e*m.rpn,c=t(a,R)[h];return t(a,L)[e*m.rpnt]||t(a,A)==x.mt32&&(c=12),t(a,Te)[e]/8192*c+(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 c=3*e;t(this,se)[c]=1,t(this,se)[c+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,c=3200){let p=this,y;k(p,Le," ".repeat(h)),e.forEach(v=>{k(p,Le,t(p,Le)+String.fromCharCode(v>31?v:32)),v<32&&(y=y||new Set,y.add(v))}),k(p,kt,Date.now()),k(p,Ue,Date.now()+c),y&&(y=Array.from(y),y.forEach((v,S,r)=>{r[S]=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,c=-1;switch(e.replaceAll(", ",",").split(",").forEach(p=>{p=p.toLowerCase();let y=W.indexOf(Xr[p]||p);O()&&console.debug(`Mapped mode "${p}" to ID "${y}".`),y>-1&&(c=y)}),O()&&console.debug(`Set detection target to ID "${c}".`),c>0&&(t(h,B).x5=82,t(h,B).ds=x.krs),c){case x["05rw"]:{t(h,B).x5=81;break}case x.s90es:t(h,B).ds=x.s90es,t(h,B).smotif=x.s90es;case x.motif:t(h,B).ds=x.motif,t(h,B).smotif=x.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,X)[x[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(a,X)[a.getChModeId(h)][2]}),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,V)[e>>4]:t(this,Oe)[e]||t(this,V)[e>>4]||t(this,A)}setPortMode(e,a,h){let c=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(c,A)==0||a){let v=t(c,A);c.initOnReset&&a&&(this.init(1),v=x["?"]),k(c,A,p),k(c,Y,0);for(let r=0;r0&&t(c,Oe)[r]==0&&(t(c,b)[r*m.cc]=t(c,X)[p][2]);switch(p){case x.mt32:{Ht.forEach((r,n)=>{let l=n+1;t(c,de)[l]||(t(c,I)[l]=r,t(c,b)[l*m.cc+E[91]]=127)});for(let r=1;r<10;r++)c.dispatchEvent("voice",{part:r});break}}let S;switch(p){case x["?"]:case x.g2:{S=[52,4,52,18,0,0,0,0];break}case x.xg:{S=[1,0,65,0,5,0,0,0];break}case x.gm:case x.gs:case x.sc:{S=[40,4,40,18,40,32,32,0];break}case x.sd:{S=[58,0,60,0,61,0,61,0];break}case x["05rw"]:case x.x5d:case x.ns5r:{S=[44,1,44,19,44,0,44,0];break}case x.k11:case x.sg:{S=[24,0,0,0,0,0,0,0];break}case x.mt32:{S=[40,4,0,0,0,0,0,0];break}case x.doc:{S=[24,16,0,0,0,0,0,0];break}case x.motif:case x.s90es:{S=[113,0,117,0,114,0,0,0];break}default:S=[0,0,0,0,0,0,0,0]}for(let r=0;r{c.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),c=!1;(a=t(this,xt)[h])==null||a.forEach(p=>{e.channel=p,c=!0,t(this,St)[e.type].call(this,e)}),c||console.warn(`${fr[e.type]?fr[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)]},vr=function(e){t(this,Se)[t(this,Y)]=e},de=new WeakMap,K=new WeakMap,D=new WeakMap,b=new WeakMap,fe=new WeakMap,I=new WeakMap,z=new WeakMap,ae=new WeakMap,q=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,V=new WeakMap,Oe=new WeakMap,Ee=new WeakMap,$t=new WeakMap,Ae=new WeakMap,me=new WeakMap,lt=new WeakMap,Ie=new WeakMap,X=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,_=new WeakMap,Pt=new WeakMap,xt=new WeakMap,Fe=new WeakMap,_t=new WeakMap,ne=new WeakMap,Ce=new WeakMap,Be=new WeakMap,j=new WeakMap,Ke=new WeakMap,F=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,yr);var Ft=Ur($r(),1);U();U();var Tt,wr,xr=(wr=class{constructor(g,e,a,h){T(this,Tt,!1);k(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,wr),Xt=class extends xr{constructor(g,e,a){super(!0,g,e,a)}},Sr=class extends xr{constructor(g,e){super(!1,g,g,e)}},je,kr,Vt=(kr=class extends Array{constructor(){super(...arguments);T(this,je,-1)}resetIndex(e){k(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 c=0;ce);c++){if(this[c].endt(p,je)&&(h.push(y),k(p,je,y.index))})}return h}getRange(e,a){var v;e>a&&([e,a]=[a,e]);let h=[],c=-1,p=Math.ceil(Math.sqrt(this.length)),y=!0;for(let S=0;S=e&&(c=S):c=c<0?S:c;for(;y;)((v=this[c])==null?void 0:v.end)=e&&h.push(this[c]):y=!1,c++;return h}},je=new WeakMap,kr);var Qr=0xffffffffffff,Tr=function(g){let e=new Vt,a=this,h=g.timeDivision,c=120,p=new Vt,y=0,v=0;p.push(new Xt(0,Qr,[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&&(c=6e7/i.data,p[p.length-1]&&p.push(new Xt(y,0xffffffffffff,[c,0])))})}),p.fresh(),p.forEach(function(l,i,s){i>0&&(s[i-1].end=l.start)});let S=120;p.forEach(function(l,i,s){i>0&&(l.end==l.start?s.splice(s.indexOf(l),1):S==l.data[0]&&(s[i-1].end=l.end,s.splice(s.indexOf(l),1)),S=l.data[0])});let r=0,n=120;return p.forEach(function(l){let i=l.start,s=i/n/h*60+r;n=l.data[0],r=s-i/n/h*60,l.data[1]=r}),console.debug("All tempo changes: ",p),c=120,y=0,v=0,g.track.forEach(function(l,i){y=0,v=0;let s=i+1;l.event.forEach(function(o,d){y+=o.deltaTime;let u=p.step(y,!0)[0];u&&(c=u.data[0],v=u.data[1]);let f={type:o.type,data:o.data,track:s,part:0};o.type>14?f.meta=o.metaType:f.part=o.channel,e.push(new Sr(y/c/h*60+v,f))})}),e.fresh(),self.midiEvents=e,console.debug(`Parsed a type ${g.formatType} MIDI sequence.`),e};Ft.default.customInterpreter=or;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,Cr,ri=(Cr=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 c=this;c.smoothingAtk=a,c.smoothingDcy=h,c.device=e,c.addEventListener("meta",function(p){var y;(y=p==null?void 0:p.data)==null||y.forEach(function(v){(t(c,et)[v.meta]||console.debug).call(c,v.meta,v.data)})}),N(c.device,c,"mode"),N(c.device,c,"mastervolume"),N(c.device,c,"channelactive"),N(c.device,c,"channelmin"),N(c.device,c,"channelmax"),N(c.device,c,"portrange"),N(c.device,c,"portstart"),N(c.device,c,"channelreset"),N(c.device,c,"channeltoggle"),N(c.device,c,"screen"),N(c.device,c,"metacommit"),N(c.device,c,"voice"),N(c.device,c,"pitch"),N(c.device,c,"note"),N(c.device,c,"reset"),N(c.device,c,"banklevel"),N(c.device,c,"efxreverb"),N(c.device,c,"efxchorus"),N(c.device,c,"efxdelay"),N(c.device,c,"efxinsert0"),N(c.device,c,"efxinsert1"),N(c.device,c,"efxinsert2"),N(c.device,c,"efxinsert3"),N(c.device,c,"partefxtoggle"),c.addEventListener("note",function({data:p}){t(c,pt).push(p)}),t(c,et)[3]=function(p,y){var v;((v=t(c,Me))==null?void 0:v.length)<1&&(k(c,Me,y),c.dispatchEvent("title",t(c,Me)))},t(c,et)[81]=function(p,y){let v=c.noteProgress,S=t(c,Ne)||.5;k(c,He,6e7/y),k(c,Ne,y/1e6),k(c,Pe,t(c,Pe)+(v*(S/t(c,Ne))-v)),c.dispatchEvent("tempo",t(c,He))},t(c,et)[88]=function(p,y){let v=c.noteProgress,S=c.noteOverall,r=c.noteBar,n=c.noteBeat,l=t(c,Z),i=t(c,rt);k(c,Z,y[0]),k(c,rt,1<=l&&(l{if(!r)return;let l=r.split("\t");if(n){if(!y)return;let i="",s="";l.forEach((o,d)=>{switch(d){case v:{i=o;break}case S:{s=o;break}}}),!t(h,Je)[i]||a?(t(h,Je)[i]=s,c++):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":{S=s,y++;break}default:console.debug(`Unknown map field: ${i}`)}})}),console.debug(`Voice names: ${p} total, ${c} loaded.`),h==null||h.device.forceVoiceRefresh()}async loadEfx(e,a){let h=this,c=0,p=0,y,v,S;e.split(` -`).forEach((r,n)=>{if(r)if(n){let l=0,i;r.split("\t").forEach((s,o)=>{switch(o){case y:{l|=parseInt(s,16)<<8;break}case v:{l|=parseInt(s,16);break}case S:{i=s;break}}}),!t(h,ut)[l]||a?(t(h,ut)[l]=i,c++):self.debugMode&&console.debug(`EFX ID 0x${l.toString(16).padStart(4,"0")} (${i}) seems to be in conflict.`),p++}else r.split("\t").forEach((l,i)=>{switch(l){case"MSB":{y=i;break}case"LSB":{v=i;break}case"Name":{S=i;break}default:console.debug(`Unknown EFX field: ${l}`)}})}),console.debug(`EFX: ${p} total, ${c} 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)&&k(this,at,e);let a=((w=t(this,Ze))==null?void 0:w.step(e))||[],h=0,c=new Set,p={},y=[],v=this,S=[];for(v.device.getStrength().forEach((C,M)=>{t(v,Ct)[M]=C}),v.device.newStrength(),a.forEach(function(C){let M=C.data,G=v.device.runJson(M);switch(G==null?void 0:G.reply){case"meta":{S.push(G);break}}G!=null&&G.reply&&delete G.reply});t(v,pt).length>0;){let C=t(v,pt).shift(),M=C.part<<7|C.note;C.state?(c.add(M),p[M]=C.velo):c.has(M)&&(y.push({part:C.part,note:C.note,velo:p[M],state:v.device.NOTE_SUSTAIN}),h++)}(S==null?void 0:S.length)>0&&v.dispatchEvent("meta",S);let r=v.device.getActive(),n=[],l=v.device.getPitch(),i=v.device.getCcAll(),s=v.device.getProgram(),o=v.device.getChType(),d=[],u=v.device.getStrength();u.forEach(function(C,M,G){G[M]=Math.max(t(v,Ct)[M],C);let Re=G[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&&(n[M]=v.device.getVel(M),d[M]=v.device.getExt(M),f+=n[M].size)}),{extraPoly:h,extraNotes:y,curPoly:f,chInUse:r,chKeyPr:n,chPitch:l,chProgr:s,chContr:i,chType:o,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,Cr);export{ri as RootDisplay,m as allocated,E as ccToPos,le as dnToPos}; \ No newline at end of file +`),a.slice(0,2)){case"@I":{S(this,G,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(c=a.slice(2))==null?void 0:c.trimLeft()});break}case"@K":{S(this,G,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(l=a.slice(2))==null?void 0:l.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{S(this,G,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(s=a.slice(2))==null?void 0:s.trimLeft()});break}case"@T":{S(this,G,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(i=a.slice(2))==null?void 0:i.trimLeft()});break}case"@V":{S(this,G,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(o=a.slice(2))==null?void 0:o.trimLeft()});break}case"XF":{let d=a.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:a})}break}default:t(this,G)?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((d,u)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:d,mask:u!=0})})}},t(e,J)[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},t(e,J)[3]=function(a,c){c<1&&t(this,Fe)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},t(e,J)[4]=function(a,c){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},t(e,J)[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,J)[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},t(e,J)[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},t(e,J)[32]=function(a){S(this,Fe,a[0]+1)},t(e,J)[33]=function(a,c){A()&&console.debug(`Track ${c} requests to get assigned to output ${a}.`),t(e,Ne)[c]=a+1},t(e,J)[81]=function(a,c){S(e,dt,a/1e3)},t(e,J)[127]=function(a,c){t(e,ze).run(a,c)},t(e,ze).default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},t(e,ze).add([67,0,1],function(a,c){A()&&console.debug(`XGworks requests assigning track ${c} to output ${a[0]}.`),t(e,Ne)[c]=a[0]+1}),S(e,qe,new pe("universal non-realtime")),S(e,We,new pe("universal realtime")),S(e,oe,new pe("Yamaha")),S(e,ue,new pe("Roland")),S(e,xe,new pe("Korg")),S(e,Qe,new pe("Kawai")),S(e,Ye,new pe("Akai")),S(e,Ze,new pe("Casio"));let r=new pe("DX7+ Dump"),h=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,a)};t(e,qe).default=h,t(e,We).default=h,t(e,oe).default=h,t(e,ue).default=h,t(e,xe).default=h,t(e,Qe).default=h,t(e,Ye).default=h,t(e,Ze).default=h,r.default=h,t(e,qe).add([9],(a,c,l)=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),e.setPortMode(e.getTrackPort(c),1,k[["gm","?","g2"][a[0]-1]]),S(e,G,t(e,G)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),t(e,We).add([4,1],(a,c,l)=>{e.dispatchEvent("mupromptex"),S(e,H,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,H))}).add([4,3],(a,c,l)=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],(a,c,l)=>a[1]-64).add([4,5],(a,c,l)=>{e.dispatchEvent("mupromptex");let s=a[0],i=a[1],o=a[2],d=3,u=d+(s<<1),f=u+i;if(s!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${s})! +`,a);return}let $=0,w=0,C=0;switch(a.subarray(d,u).forEach(M=>{$=$<<7,$|=M}),a.subarray(u,f).forEach((M,X)=>{w|=M<{C|=M<{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,k.xg),S(e,G,!1),console.info("MIDI reset: XG");break}default:{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(o,d)=>{s[d]=o};if(a.subarray(1).forEach((o,d)=>{let u=d+a[0];([i,i,i,i,f=>{S(this,H,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},f=>{},f=>{}][u]||(()=>{}))(o,d)}),a[0]<4){let o=0;s.forEach(d=>{o=o<<4,o+=d}),o-=1024}}}}).add([76,2,1],(a,c,l)=>{e.dispatchEvent("mupromptex");let s="XG ";a[0]<32?(s+="reverb ",a.subarray(1).forEach((i,o)=>{([d=>{e.setEffectTypeRaw(0,!1,d),console.info(`${s}main type: ${mt[d]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},d=>{e.setEffectTypeRaw(0,!0,d),console.debug(`${s}sub type: ${d+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},d=>{console.debug(`${s}time: ${jt(d)}s`)},d=>{console.debug(`${s}diffusion: ${d}`)},d=>{console.debug(`${s}initial delay: ${d}`)},d=>{console.debug(`${s}HPF cutoff: ${nt[d]}Hz`)},d=>{console.debug(`${s}LPF cutoff: ${nt[d]}Hz`)},d=>{console.debug(`${s}width: ${d}`)},d=>{console.debug(`${s}height: ${d}`)},d=>{console.debug(`${s}depth: ${d}`)},d=>{console.debug(`${s}wall type: ${d}`)},d=>{console.debug(`${s}dry/wet: ${d}`)},d=>{console.debug(`${s}send: ${re(d)}dB`)},d=>{console.debug(`${s}pan: ${d-64}`)},!1,!1,d=>{console.debug(`${s}delay: ${d}`)},d=>{console.debug(`${s}density: ${d}`)},d=>{console.debug(`${s}balance: ${d}`)},d=>{},d=>{console.debug(`${s}feedback: ${d}`)},d=>{}][a[0]+o]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(i)})):a[0]<64?(s+="chorus ",a.subarray(1).forEach((i,o)=>{([d=>{e.setEffectTypeRaw(1,!1,d),console.info(`${s}main type: ${mt[d]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},d=>{e.setEffectTypeRaw(1,!0,d),console.debug(`${s}sub type: ${d+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},d=>{console.debug(`${s}LFO: ${Jt[d]}Hz`)},d=>{},d=>{console.debug(`${s}feedback: ${d}`)},d=>{console.debug(`${s}delay offset: ${ea(d)}ms`)},d=>{},d=>{console.debug(`${s}low: ${nt[d]}Hz`)},d=>{console.debug(`${s}low: ${d-64}dB`)},d=>{console.debug(`${s}high: ${nt[d]}Hz`)},d=>{console.debug(`${s}high: ${d-64}dB`)},d=>{console.debug(`${s}dry/wet: ${d}`)},d=>{console.debug(`${s}send: ${re(d)}dB`)},d=>{console.debug(`${s}pan: ${d-64}`)},d=>{console.debug(`${s}to reverb: ${re(d)}dB`)},!1,d=>{},d=>{},d=>{},d=>{console.debug(`${s}LFO phase diff: ${(d-64)*3}deg`)},d=>{console.debug(`${s}input mode: ${d?"stereo":"mono"}`)},d=>{}][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)=>{([d=>{e.setEffectTypeRaw(2,!1,d),console.info(`${s}main type: ${mt[d]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},d=>{e.setEffectTypeRaw(2,!0,d),console.debug(`${s}sub type: ${d+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+o]||function(){})(i)})):a[0]<97?(s+="variation ",a.subarray(1).forEach((i,o)=>{[d=>{console.debug(`${s}send: ${re(d)}dB`)},d=>{console.debug(`${s}pan: ${d-64}`)},d=>{console.debug(`${s}to reverb: ${re(d)}dB`)},d=>{console.debug(`${s}to chorus: ${re(d)}dB`)},d=>{console.debug(`${s}connection: ${d?"system":"insertion"}`)},d=>{console.debug(`${s}channel: CH${d+1}`)},d=>{console.debug(`${s}mod wheel: ${d-64}`)},d=>{console.debug(`${s}bend wheel: ${d-64}`)},d=>{console.debug(`${s}channel after touch: ${d-64}`)},d=>{console.debug(`${s}AC1: ${d-64}`)},d=>{console.debug(`${s}AC2: ${d-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,l)=>{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 d=o-1>>2,u=o-1&3,f=`XG EQ ${d} ${["gain","freq","Q","shape"][u]}: `;[()=>{console.debug(`${f}${s-64}dB`)},()=>{console.debug(`${f}${s} (raw)`)},()=>{console.debug(`${f}${s/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!s]}`)}][u]()}})}).add([76,3],(a,c,l)=>{e.dispatchEvent("mupromptex");let s=a[0],i=a[1],o=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((d,u)=>{([f=>{e.setEffectTypeRaw(3+s,!1,f),console.info(`${o}main type: ${mt[f]}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))},f=>{e.setEffectTypeRaw(3+s,!0,f),console.debug(`${o}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))}][i+u]||function(){})(d)})}).add([76,6,0],(a,c,l)=>{let s=a[0];s<64?e.setLetterDisplay(a.subarray(1),"XG letter display",s):S(e,Be,Date.now())}).add([76,7,0],(a,c,l)=>{let s=a[0];S(e,Y,0),S(e,be,Date.now()+3200),t(e,le,Se).fill(0);let i=a.subarray(1);for(let o=0;o>6-C&1,C++})}).add([76,8],(a,c)=>{e.dispatchEvent("mupromptex");let l=e.chRedir(a[0],c,!0),s=a[1],i=E.cc*l,o=`XG CH${l+1} `,d=`Unknown XG part address ${s}.`,u=!0;a.subarray(2).forEach((f,$)=>{u=!0,s<1?console.debug(d):s<41?([()=>{t(e,b)[i+m[0]]=f,e.dispatchEvent("voice",{part:l})},()=>{t(e,b)[i+m[32]]=f,e.dispatchEvent("voice",{part:l})},()=>{t(e,O)[l]=f,e.dispatchEvent("voice",{part:l})},()=>{u=!1;let w=e.chRedir(f,c,!0);t(e,K)[l]=w,l!=w&&(e.buildRchTree(),console.info(`${o}receives from CH${w+1}`)),t(e,he)[l]||(e.copyChSetup(w,l,!0),console.debug(`${o}copied from CH${w+1}.`),e.setChActive(l,1),e.dispatchEvent("voice",{part:l}))},()=>{t(e,se)[l]=+!f},()=>{},()=>{u=!1,e.setChType(l,f,k.xg),console.debug(`${o}type: ${Et[f]||f}`),e.dispatchEvent("voice",{part:l})},()=>{t(e,R)[E.rpn*l+3]=f,t(e,I)[E.rpnt*l+2]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)})},!1,!1,()=>{t(e,b)[i+m[7]]=f},!1,!1,()=>{t(e,b)[i+m[10]]=f||128},!1,!1,()=>{t(e,b)[i+m[128]]=f,e.allocateAce(l,128)},()=>{t(e,b)[i+m[93]]=f},()=>{t(e,b)[i+m[91]]=f},()=>{t(e,b)[i+m[94]]=f},()=>{t(e,b)[i+m[76]]=f},()=>{t(e,b)[i+m[77]]=f},()=>{t(e,b)[i+m[78]]=f},()=>{t(e,b)[i+m[74]]=f},()=>{t(e,b)[i+m[71]]=f},()=>{t(e,b)[i+m[73]]=f},()=>{t(e,b)[i+m[75]]=f},()=>{t(e,b)[i+m[72]]=f}][s+$-1]||(()=>{}))():s<48?console.debug(d):s<111?s>102&&s<105&&(t(e,b)[i+m[[5,65][s&1]]]=f):s<114?console.debug(d):s<116?console.debug(`${o}EQ ${["bass","treble"][s&1]} gain: ${f-64}dB`):s<118?console.debug(d):s<120?console.debug(`${o}EQ ${["bass","treble"][s&1]} freq: ${f}`):console.debug(d)}),u&&t(e,D)[l]>1&&e.setDrumFirstWrite(l)}).add([76,9],(a,c)=>{let l=e.chRedir(a[0],c,!0),s=a[1],i=E.cc*l,o=`PLG-VL CH${l+1} `;a.subarray(2).forEach((d,u)=>{let f=u+s;switch(f){case 1:{console.info(`${o}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(`${o}${w} control source: ${ra(d)}`),d&&d<96&&e.allocateAce(l,130+$),t(e,Ve)[E.redir*l+$+2]=d,e.buildRccMap()):console.debug(`${o}${w} scale break point: ${d}`):(console.debug(`${o}${w} depth: ${d-64}`),t(e,b)[i+m[130+$]]=d)}}})}).add([76,10],(a,c,l)=>{}).add([76,16],(a,c,l)=>{}).add([76,17,0,0],(a,c,l)=>{}).add([76,112],(a,c,l)=>{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,ie)[E.ext*a[2]]=e.EXT_VL;break}case 2:{t(e,ie)[E.ext*a[2]]=e.EXT_DX;break}default:t(e,ie)[E.ext*a[2]]=e.EXT_NONE}}).add([73,0,0],(a,c)=>{let l=a[0],s="MU1000 System - ";a.subarray(1).forEach((i,o)=>{let d=l+o;d==8?console.debug(`${s}LCD contrast: ${i}.`):d==18?(t(e,_)[k.xg][1]=i?126:0,console.debug(`${s}default bank: ${i?"MU100 Native":"MU Basic"}.`),e.dispatchEvent("banklevel",{mode:"xg",data:+!!i}),e.forceVoiceRefresh()):d>=64&&d<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")},()=>{S(e,ke,!!i),console.info(`Octavia System: RS receiving ${["dis","en"][i]}abled.`)}][d-64]()})}).add([73,10,0],(a,c)=>{let l=a[0],s=`MU1000 RS${t(e,ke)?"":" (ignored)"}: `;if(l<16)switch(l){case 2:{let i=e.chRedir(0,c,!0);t(e,ke)&&(e.dispatchEvent("portrange",4),e.dispatchEvent("portstart",i)),console.info(`${s}Show CH${i+1}~CH${i+64}`);break}case 3:{let i=e.chRedir(a[1]<<5,c,!0);t(e,ke)&&(e.dispatchEvent("portrange",2),e.dispatchEvent("portstart",i)),console.info(`${s}Show CH${i+1}~CH${i+32}`);break}default:console.debug(`${s}unknown switch ${l} invoked.`)}else if(l<32){if(t(e,ke)){let i=e.chRedir(l-16+(t(e,ht)<<4),c,!0);e.dispatchEvent("channelactive",i)}}else if(l<36){let i=e.chRedir(l-32<<4,c,!0);t(e,ke)&&(e.dispatchEvent("portrange",1),e.dispatchEvent("portstart",i>>4),S(e,ht,l-32)),console.info(`${s}Show CH${i+1}~CH${i+16}`)}}).add([73,11,0],(a,c)=>{let l="MU1000 System - channel ",s="Octavia System - channel ",i=a[0];a.subarray(1).forEach((o,d)=>{let u=i+d;([()=>{e.setChActive(o,1),e.dispatchEvent("channelactive",o),A()&&console.debug(`${l}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`))}][u]||(()=>{console.debug(`${l}unknown address: ${u}`)}))()})}).add([93,3],(a,c)=>{let l=e.chRedir(a[0],c,!0),s=`PLG-SG CH${l+1} `,i=Date.now();if(a[1]==0){let o="",d=0;a.subarray(2).forEach((u,f)=>{f%2==0?o+=ta[u]||u.toString().padStart("0"):d+=u*13}),i>=t(e,ft)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${aa(o)}`,amend:!0}),S(e,ft,i+Math.ceil(d/2)+t(e,dt)),A()&&console.debug(`${s}vocals: ${o}`)}else console.warn(`Unknown PLG-SG data: ${a}`)}).add([98,0],(a,c,l)=>{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 d=Ae(a.subarray(4,o));if(d!=a[o]){console.info(`Bad PLG-DX checksum ${a[o]} - should be ${d}.`);return}a[0]=98,t(e,oe).run(a.subarray(0,o),c,l,{noAce:!0})}).add([98,96],(a,c,l,s)=>{let i=e.chRedir(a[0],c,!0),o=E.cc*i,d=a[1];a.subarray(2).forEach((u,f)=>{let $=d+f;if(!($<10)){if($==10)e.resetAce();else if($<27){let w=$+131;s!=null&&s.noAce||e.allocateAce(i,w),t(e,b)[o+m[w]]=u,e.dispatchEvent("cc",{part:i,cc:w,data:u})}}})}).add([100,0],(a,c,l)=>{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=Ae(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,l)=>{let s=a[0]>>4,i=a[0]&15,o=a[1];switch(s){case 2:{let d=e.chRedir(i,c,!0),u=E.cc*d;a.subarray(2).forEach((f,$)=>{let w=$+o;if(!(w<7)){if(w<23){let C=w+135;e.allocateAce(d,C),t(e,b)[u+m[C]]=f,e.dispatchEvent("cc",{part:d,cc:C,data:f})}}});break}default:console.info("Unknown DX7+ multipart: %o",a)}}).add([1,20],(a,c,l)=>{l==115?(e.switchMode("doc",!0),e.setPortMode(e.getTrackPort(c),1,k.doc),console.info("MIDI reset: DOC")):console.debug(`Unknown Yamaha SysEx: 67, ${l}, ${a.join(", ")}`)}).add([1,17,15,89],(a,c,l)=>{l==115?(e.setEffectType(0,24,a[0]|16),e.dispatchEvent("efxreverb",e.getEffectType(0))):console.debug(`Unknown Yamaha SysEx: 67, ${l}, ${a.join(", ")}`)}).add([1,24],(a,c,l)=>{if(l==115){for(let s=0;s<16;s++){let i=e.chRedir(s,c,!0);t(e,b)[i*E.cc+m[91]]=127}console.info("DOC Global Reverb: on")}else console.debug(`Unknown Yamaha SysEx: 67, ${l}, ${a.join(", ")}`)}),r.add([14,31],(a,c,l)=>{t(e,b)[E.cc*a[0]+m[64]]=0,t(e,F).ano(a[0]),e.switchMode("xg"),e.setPortMode(e.getTrackPort(c),1,k.xg),e.resetAce(),console.debug(`Yamaha DX7+ reset CH${a[0]+1}.`)}).add([76,112],async a=>{let c=a[0],l=E.cc*c,s=E.ext*c,i=E.cvn*c;t(e,ie)[s]=e.EXT_DX,t(e,Ee)[c]=1;let o=t(e,$t).subarray(i,i+E.cvn);o.fill(32),a.subarray(1).forEach((d,u)=>{if(u<10)o[u]=Math.max(d,32);else if(!(u<40)){if(u<56){let f=u+102;t(e,b)[l+m[f]]=d,e.dispatchEvent("cc",{part:c,cc:f,data:d})}}}),t(e,O)[c]=c&127,t(e,b)[E.cc*c+m[0]]=35,t(e,b)[E.cc*c+m[32]]=c>>7|4,e.dispatchEvent("voice",{part:c}),console.debug(`DX7+ CH${c+1} dump: %o`,a)});let n=function(a,c,l,s){},p=function(a,c){e.dispatchEvent("mupromptex");let l=a*E.dpn,s=c[0],i=c[1];c.subarray(2).forEach((o,d)=>{let u=d+i,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?(A()&&console.debug(l,f,s,o),t(e,te)[(l+fe[f])*E.dnc+s]=o):A()&&console.debug(`XG-style drum param ${u} has no writes.`)})},y=function(a,c,l){e.dispatchEvent("mupromptex");let s=a*E.dpn,i=(c<<7)+l[0];l.subarray(1).forEach((o,d)=>{let u=d+i,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 ${a+1}.`)}))(),w>-1?(A()&&console.debug(s,w,f,o),t(e,te)[(s+fe[w])*E.dnc+f]=o):A()&&console.debug(`GS-style drum param ${$} has no writes.`)})};t(this,oe).add([76,48],(a,c,l)=>{p(0,a)}).add([76,49],(a,c,l)=>{p(1,a)}).add([76,50],(a,c,l)=>{p(2,a)}).add([76,51],(a,c,l)=>{p(3,a)}).add([76,52],(a,c,l)=>{p(4,a)}).add([76,53],(a,c,l)=>{p(5,a)}).add([76,54],(a,c,l)=>{p(6,a)}).add([76,55],(a,c,l)=>{p(7,a)}),t(this,oe).add([89,0],(a,c,l)=>{if(e.eprom){let s=a[0],i=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);A()&&console.debug(`MU1000 EPROM trail to 0x${i.toString(16).padStart(6,"0")}, ${s} bytes.`);let o=e.eprom.data;a.subarray(4).forEach((d,u)=>{let f=u>>3,$=u&7;if($==7)for(let w=0;w<7;w++)o[i+7*f+w]+=(d>>6-w&1)<<7;else o[i+7*f+$]=d})}}).add([89,1],(a,c,l)=>{let s=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];A()&&console.debug(`MU1000 EPROM jump to 0x${s.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=s)}).add([89,2],(a,c,l)=>{if(e.eprom){let s=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);A()&&console.debug(`MU1000 EPROM write to 0x${s.toString(16).padStart(6,"0")}.`);let i=e.eprom.data;a.subarray(4).forEach((o,d)=>{let u=d>>3,f=d&7;if(f==7)for(let $=0;$<7;$++)i[s+7*u+$]+=(o>>6-$&1)<<7;else i[s+7*u+f]=o})}}).add([89,3],(a,c,l)=>{}),t(this,oe).add([39,48],(a,c,l)=>{}).add([43,0,0],(a,c,l)=>{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(o,d)=>{s[d]=o};if(a.subarray(1).forEach((o,d)=>{let u=d+a[0];[i,i,i,i,()=>{S(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}.`)}][u](o,u)}),a[0]<4){let o=0;s.forEach(d=>{o=o<<4,o+=d}),o-=1024}}).add([43,1,0],(a,c,l)=>{e.dispatchEvent("mupromptex")}).add([43,2],(a,c,l)=>{e.dispatchEvent("mupromptex");let s=e.chRedir(a[0],c,!0),i=a[1],o=E.cc*s,d=`TG300 CH${s+1} `;a.subarray(2).forEach((u,f)=>{f<5?([()=>{},()=>{t(e,b)[o+m[0]]=u,e.dispatchEvent("voice",{part:s})},()=>{t(e,b)[o+m[32]]=u,e.dispatchEvent("voice",{part:s})},()=>{t(e,O)[s]=u,e.dispatchEvent("voice",{part:s})},()=>{let $=e.chRedir(u,c,!0);t(e,K)[s]=$,s!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))}][f+i]||(()=>{}))(u,f+i):f<21||(f<47?([()=>{t(e,se)[s]=+!u},()=>{},()=>{},()=>{t(e,R)[E.rpn*s+3]=u,t(e,I)[E.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{},()=>{t(e,b)[o+m[7]]=u},!1,!1,()=>{t(e,b)[o+m[10]]=u||128},!1,!1,()=>{console.debug(`${d} AC1 at cc${u}`)},()=>{console.debug(`${d} AC2 at cc${u}`)},()=>{t(e,b)[o+m[128]]=u,e.allocateAce(s,128)},()=>{t(e,b)[o+m[93]]=u},()=>{t(e,b)[o+m[91]]=u},()=>{t(e,b)[o+m[94]]=u},()=>{t(e,b)[o+m[76]]=u},()=>{t(e,b)[o+m[77]]=u},()=>{t(e,b)[o+m[74]]=u},()=>{t(e,b)[o+m[71]]=u},()=>{t(e,b)[o+m[73]]=u},()=>{t(e,b)[o+m[75]]=u},()=>{t(e,b)[o+m[72]]=u},()=>{t(e,b)[o+m[78]]=u}][f+i-21]||(()=>{}))(u,f+i):f<95||([()=>{t(e,b)[o+m[65]]=u},()=>{t(e,b)[o+m[5]]=u}][f+i-95]||(()=>{}))(u,f+i))})}).add([43,7,0],(a,c,l)=>{let s=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",s)}).add([43,7,1],(a,c,l)=>{S(e,Y,0),S(e,be,Date.now()+3200),t(e,le,Se).fill(0),a.forEach(function(s,i){let o=Math.floor(i/16),d=i%16,u=(d*3+o)*7,f=7,$=0;for(u-=d*5,o==2&&(f=2);$>6-$&1,$++})}),t(this,ue).add([66,18,0,0,127],(a,c,l)=>{e.switchMode("sc",!0),e.setPortMode(e.getTrackPort(c),2,k.sc),t(e,b)[E.cc*9]=120,t(e,b)[E.cc*25]=120,t(e,b)[E.cc*41]=120,t(e,b)[E.cc*57]=120,t(e,_)[k.sc][1]=t(e,U).sc,S(e,G,!1),t(e,Me).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,c,l)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),e.setPortMode(e.getTrackPort(c),2,k.gs),t(e,_)[k.gs][1]=t(e,U).gs,t(e,b)[E.cc*9]=120,t(e,b)[E.cc*25]=120,t(e,b)[E.cc*41]=120,t(e,b)[E.cc*57]=120,S(e,G,!1),t(e,Me).fill(0),console.info("MIDI reset: GS");break}default:{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(o,d)=>{s[d]=o};if(a.subarray(1).forEach((o,d)=>{let u=d+a[0];[i,i,i,i,f=>{S(this,H,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},f=>{},f=>{}][u](o,d)}),a[0]<4){let o=0;s.forEach(d=>{o=o<<4,o+=d}),o-=1024}}}}).add([66,18,64,1],(a,c,l)=>{e.dispatchEvent("mupromptex");let s=a[0];if(s<16){let i="".padStart(s," ");a.subarray(1).forEach((o,d)=>{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 d=`GS ${s+o>55?"chorus":"reverb"} `;([()=>{console.info(`${d}type: ${Bt[i]}`),e.setEffectType(0,40,i),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${d}predelay: ${i}ms`)},()=>{console.info(`${d}type: ${sa[i]}`),e.setEffectType(1,40,16+i),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${d}to reverb: ${re(i)}`)},()=>{console.debug(`${d}to delay: ${re(i)}`)}][s+o-48]||(()=>{}))()}):s<80?console.debug(`Unknown GS patch address: ${s}`):s<91?a.subarray(1).forEach((i,o)=>{let d="GS delay ";([()=>{console.info(`${d}type: ${ia[i]}`),e.setEffectType(2,40,32+i),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${d}to reverb: ${re(i)}`)}][s+o-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${s}`))}).add([66,18,64,2],(a,c,l)=>{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,l)=>{e.dispatchEvent("mupromptex");let s="GS EFX ",i=function(o,d){let u=na(t(e,ne).subarray(10,12),d,o);u&&console.debug(`${s}${Nt(t(e,ne).subarray(10,12))} ${u}`)};a.subarray(1).forEach((o,d)=>{([()=>{e.setEffectTypeRaw(3,!1,32+o),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,o),console.info(`${s}type: ${Nt(t(e,ne).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: ${re(o)}dB`)},()=>{console.debug(`${s}to chorus: ${re(o)}dB`)},()=>{console.debug(`${s}to delay: ${re(o)}dB`)},!1,()=>{console.debug(`${s}1 source: ${o}`),o&&o<96&&e.allocateAceAll(o)},()=>{console.debug(`${s}1 depth: ${o-64}`)},()=>{console.debug(`${s}2 source: ${o}`),o&&o<96&&e.allocateAceAll(o)},()=>{console.debug(`${s}2 depth: ${o-64}`)},()=>{console.debug(`${s}to EQ: ${o?"ON":"OFF"}`)}][a[0]+d]||function(u,f){console.warn(`Unknown GS EFX address: ${f}`)})(o,a[0]+d)})}).add([66,18,65],(a,c,l)=>{y((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],(a,c,l)=>{var s;switch(a[0]){case 0:{let i=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",i);break}case 32:{S(e,be,Date.now()+3200),a[1]==0&&(a[2]?(S(e,Y,Math.max(Math.min(a[2]-1,9),0)),A()&&console.debug(`GS switch display page ${a[2]-1}.`)):(S(e,Y,0),S(e,be,Date.now()),A()&&console.debug("GS disable display page.")));break}default:if(a[0]<6){t(e,Y)>9&&S(e,Y,0);let i=a[0]-1<<1|a[1]>>6;t(e,Y)==i&&S(e,be,Date.now()+3200),(s=t(e,Ce)[i])!=null&&s.length||(t(e,Ce)[i]=new Uint8Array(256));let o=t(e,Ce)[i];A()&&console.debug(`GS frame draw page ${i}.`);let d=a[1]&63;o.fill(0),a.subarray(2).forEach(function(f,$){let w=$+d,C=Math.floor(w/16),M=w%16,X=(M*4+C)*5,De=5,Ge=0;for(X-=M*4,C==3&&(De=1);Ge>4-Ge&1,Ge++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let v=function(a,c,l){e.dispatchEvent("mupromptex");let s=a[0],i=E.cc*c,o=E.rpn*c,d=`GS CH${c+1} `;s<3?(a.subarray(1).forEach((u,f)=>{[()=>{t(e,b)[i+m[0]]=u},()=>{t(e,O)[c]=u},()=>{let $=0;u<16?$=e.chRedir(u,l,!0):$=E.ch,t(e,K)[c]=$,c!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))}][s+f]()}),e.dispatchEvent("voice",{part:c})):s<19||(s<44?a.subarray(1).forEach((u,f)=>{([()=>{t(e,se)[c]=+!u},!1,()=>{e.setChType(c,u<<1,k.gs),console.debug(`${d}type: ${u?"drum ":"melodic"}${u||""}`)},()=>{t(e,R)[o+3]=u,t(e,I)[E.rpnt*c+2]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},!1,()=>{t(e,b)[i+m[7]]=u},!1,!1,()=>{t(e,b)[i+m[10]]=u||128},!1,!1,()=>{console.debug(`${d}CC 1: cc${u}`)},()=>{console.debug(`${d}CC 2: cc${u}`)},()=>{t(e,b)[i+m[93]]=u},()=>{t(e,b)[i+m[91]]=u},!1,!1,()=>{t(e,R)[o+1]=u,t(e,I)[E.rpnt*c+1]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},()=>{t(e,R)[o+2]=u,t(e,I)[E.rpnt*c+1]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},()=>{t(e,b)[i+m[94]]=u}][s+f-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},x=function(a,c){let l=a[0],s=`GS CH${c+1} `;l<2?a.subarray(1).forEach((i,o)=>{[()=>{t(e,b)[E.cc*c+m[32]]=i},()=>{}][l+o]()}):l<32?console.warn(`Unknown GS misc address: ${l}`):l<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,ot)[c]=i,e.dispatchEvent("partefxtoggle",{part:c,active:i})}][l+o-32]()}):console.warn(`Unknown GS misc address: ${l}`)};t(this,ue).add([66,18,64,16],(a,c)=>{v(a,e.chRedir(9,c,!0),c)}).add([66,18,64,17],(a,c)=>{v(a,e.chRedir(0,c,!0),c)}).add([66,18,64,18],(a,c)=>{v(a,e.chRedir(1,c,!0),c)}).add([66,18,64,19],(a,c)=>{v(a,e.chRedir(2,c,!0),c)}).add([66,18,64,20],(a,c)=>{v(a,e.chRedir(3,c,!0),c)}).add([66,18,64,21],(a,c)=>{v(a,e.chRedir(4,c,!0),c)}).add([66,18,64,22],(a,c)=>{v(a,e.chRedir(5,c,!0),c)}).add([66,18,64,23],(a,c)=>{v(a,e.chRedir(6,c,!0),c)}).add([66,18,64,24],(a,c)=>{v(a,e.chRedir(7,c,!0),c)}).add([66,18,64,25],(a,c)=>{v(a,e.chRedir(8,c,!0),c)}).add([66,18,64,26],(a,c)=>{v(a,e.chRedir(10,c,!0),c)}).add([66,18,64,27],(a,c)=>{v(a,e.chRedir(11,c,!0),c)}).add([66,18,64,28],(a,c)=>{v(a,e.chRedir(12,c,!0),c)}).add([66,18,64,29],(a,c)=>{v(a,e.chRedir(13,c,!0),c)}).add([66,18,64,30],(a,c)=>{v(a,e.chRedir(14,c,!0),c)}).add([66,18,64,31],(a,c)=>{v(a,e.chRedir(15,c,!0),c)}).add([66,18,64,64],(a,c)=>{x(a,e.chRedir(9,c,!0))}).add([66,18,64,65],(a,c)=>{x(a,e.chRedir(0,c,!0))}).add([66,18,64,66],(a,c)=>{x(a,e.chRedir(1,c,!0))}).add([66,18,64,67],(a,c)=>{x(a,e.chRedir(2,c,!0))}).add([66,18,64,68],(a,c)=>{x(a,e.chRedir(3,c,!0))}).add([66,18,64,69],(a,c)=>{x(a,e.chRedir(4,c,!0))}).add([66,18,64,70],(a,c)=>{x(a,e.chRedir(5,c,!0))}).add([66,18,64,71],(a,c)=>{x(a,e.chRedir(6,c,!0))}).add([66,18,64,72],(a,c)=>{x(a,e.chRedir(7,c,!0))}).add([66,18,64,73],(a,c)=>{x(a,e.chRedir(8,c,!0))}).add([66,18,64,74],(a,c)=>{x(a,e.chRedir(10,c,!0))}).add([66,18,64,75],(a,c)=>{x(a,e.chRedir(11,c,!0))}).add([66,18,64,76],(a,c)=>{x(a,e.chRedir(12,c,!0))}).add([66,18,64,77],(a,c)=>{x(a,e.chRedir(13,c,!0))}).add([66,18,64,78],(a,c)=>{x(a,e.chRedir(14,c,!0))}).add([66,18,64,79],(a,c)=>{x(a,e.chRedir(15,c,!0))}),t(this,xe).add([54,65],(a,c)=>{let l=t(e,U).x5=="81"?"05rw":"x5d";e.switchMode(l,!0),e.setPortMode(e.getTrackPort(c),1,k[l]);let s=a[a.length-1],i=a.subarray(0,a.length-1),o=Ae(i);o!=s&&(console.info(`X5D multi parameters checksum mismatch! Expected ${o}, got ${s}.`),console.debug(a));let d=(a[1]<<7)+a[0],u=(a[3]<<7)+a[2],f=e.chRedir(d&15,c,!0),$=E.cc*f;[()=>{u<1||(u<101?(e.setChType(f,e.CH_MELODIC,k.x5d),t(e,O)[f]=u-1,t(e,b)[$+m[0]]=t(e,U).x5):u<229?(e.setChType(f,e.CH_MELODIC,k.x5d),t(e,O)[f]=u-101,t(e,b)[$+m[0]]=56):(e.setChType(f,e.CH_DRUMS,k.x5d),t(e,O)[f]=ba[u-229]||0,t(e,b)[$+m[0]]=62)),e.dispatchEvent("voice",{part:f})},()=>{t(e,b)[$+m[7]]=u},()=>{u<31&&(t(e,b)[$+m[10]]=Math.round((u-15)*4.2+64))},()=>{t(e,b)[$+m[93]]=yt(u)},()=>{t(e,b)[$+m[91]]=yt(u)},()=>{t(e,R)[f*E.rpn+3]=u>8191?u-16320:64+u,t(e,I)[E.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{t(e,R)[f*E.rpn+1]=u>8191?u-16320:64+u,t(e,I)[E.rpnt*f+1]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)})},()=>{u>0&&(t(e,R)[f*E.rpn]=u,t(e,I)[E.rpnt*f]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)}))},()=>{}][d>>4]()}).add([54,76,0],(a,c)=>{e.dispatchEvent("mupromptex");let l=t(e,U).x5=="81"?"05rw":"x5d";e.switchMode(l),e.setPortMode(e.getTrackPort(c),1,k[l]);let s="",i=t(e,U).x5,o=0,d=0,u="MSB\tPRG\tLSB\tNME";ge(a,function(f,$){if($<16400){let w=$%164;switch(!0){case w<10:{f>31&&(s+=String.fromCharCode(f));break}case w==10:break;case w==11:{u+=` +${i} ${o} ${d} ${s.trim().replace("Init Voice","")}`,o++,s="";break}}o>99&&(i=90,o=0)}}),e.userBank.clearRange({msb:t(e,U).x5,prg:[0,99],lsb:0}),e.userBank.load(u),A()&&console.debug(u),e.forceVoiceRefresh()}).add([54,77,0],(a,c)=>{e.dispatchEvent("mupromptex");let l=t(e,U).x5=="81"?"05rw":"x5d";e.switchMode(l),e.setPortMode(e.getTrackPort(c),1,k[l]);let s="",i=90,o=0,d=0,u="MSB\tPRG\tLSB\tNME";ge(a,function(f,$){if($<13600){let w=$%136;switch(!0){case w<10:{f>31&&(s+=String.fromCharCode(f));break}case w==11:{u+=` +${i} ${o} ${d} ${s.trim().replace("Init Combi","")}`,o++,s="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(u),A()&&console.debug(u),e.forceVoiceRefresh()}).add([54,78],(a,c)=>{let l=t(e,U).x5=="81"?"05rw":"x5d";e.switchMode(l),e.setPortMode(e.getTrackPort(c),1,k[l]),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 l=t(e,U).x5=="81"?"05rw":"x5d";e.switchMode(l),e.setPortMode(e.getTrackPort(c),1,k[l]),ge(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 l=t(e,U).x5=="81"?"05rw":"x5d";e.switchMode(l,!0);let s=e.getTrackPort(c);if(t(e,V)[s]&&t(e,V)[s]!=k[l])if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+s)} mode "${Q[t(e,V)[s]]}" mismatch, should be "${l}".`);return}else console.info(`Track ${c} is trying to perform a mismached mode dump on port ${String.fromCharCode(65+s)}.`);e.setPortMode(s,1,k[l]),ge(a,function(i,o,d,u){if(o<192){let f=e.chRedir(Math.floor(o/12),c,!0),$=f*E.cc;switch(o%12){case 0:{i<128?(e.setChType(f,e.CH_MELODIC,k.x5d),t(e,b)[$+m[0]]=t(e,U).x5,t(e,O)[f]=i):(e.setChType(f,e.CH_DRUMS,k.x5d),t(e,b)[$+m[0]]=62,t(e,O)[f]=ba[i-128]),i>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{t(e,b)[$+m[7]]=i;break}case 2:{t(e,R)[f*E.rpn+3]=i>127?i-192:64+i,t(e,I)[E.rpnt*f+2]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)});break}case 3:{t(e,R)[f*E.rpn+1]=i>127?i-192:64+i,t(e,I)[E.rpnt*f+1]=1,e.dispatchEvent("pitch",{part:f,pitch:e.getPitchShift(f)});break}case 4:{i<31&&(t(e,b)[$+m[10]]=Math.round((i-15)*4.2+64));break}case 5:{let w=i>>4,C=i&15;t(e,b)[$+m[91]]=yt(C),t(e,b)[$+m[93]]=yt(w);break}case 10:break;case 11:{let w=e.chRedir(i&15,c,!0),C=i>>4;t(e,K)[f]=i,(w!=f||C)&&(console.info(`X5D Part CH${f+1} receives from CH${w+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(o-192,c,!0)}})}),t(this,ue).add([22,18,127],(a,c,l)=>{e.switchMode("mt32",!0),e.setPortMode(e.getTrackPort(c),1,k.mt32),S(e,G,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,c,l)=>{e.switchMode("mt32");let s=e.chRedir(l,c,!0),i=a[1];a.subarray(2).forEach((o,d)=>{let u=d+i;t(e,Ie)[u+(s-1)*16]=o,([!1,()=>{let f=t(e,Ie)[s-1<<4];if(f<3){if(t(e,Ee)[s]=1,f==2)for(let $=0;${t(e,R)[s*E.rpn+3]=o+40,t(e,I)[E.rpnt*s+2]=1},()=>{t(e,R)[s*E.rpn+1]=o+14,t(e,I)[E.rpnt*s+1]=1},()=>{t(e,R)[s*E.rpn]=o,t(e,I)[E.rpnt*s]=1},!1,()=>{t(e,b)[E.cc*s+m[91]]=o?127:0},!1,()=>{t(e,b)[E.cc*s+m[7]]=o},()=>{t(e,b)[E.cc*s+m[10]]=Math.ceil(o*9.05)}][u]||(()=>{}))()})}).add([22,18,1],(a,c,l)=>{e.switchMode("mt32");let s=l&7;console.debug(`MT-32 slot #${l+1} Drum: ${a}`);let i=a[0]<<7|a[1];a.subarray(2).forEach((o,d)=>{let u=d+i,f=(u>>2)+24,$=u&3,w=s*E.dpn;if(A()&&console.debug(`MT-32 temp drum note ${f} param ${$}: ${o}`),f<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${f}`);return}[()=>{},()=>{t(e,te)[(w+fe[26])*E.dnc+f]=Math.round(o*1.27)},()=>{t(e,te)[(w+fe[26])*E.dnc+f]=o*9+1&127},()=>{t(e,te)[(w+fe[26])*E.dnc+f]=o?127:0}][$]()})}).add([22,18,2],(a,c,l)=>{e.switchMode("mt32");let s=e.chRedir(l,c,!0),i=a[1]+(a[0]<<7);i<10&&(t(e,Ee)[s]=1),a.subarray(2).forEach((o,d)=>{let u=d+i;u<14&&(t(e,ye)[(s-1)*E.cmt+u]=o)}),e.dispatchEvent("voice",{part:s})}).add([22,18,3],(a,c,l)=>{e.switchMode("mt32");let s=l&7;if(a[0]){let i=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((o,d)=>{let u=d+i,f=(u>>2)+24,$=u&3,w=s*E.dpn;if(A()&&console.debug(`MT-32 dev drum note ${f} param ${$}: ${o}`),f<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${f}`);return}[()=>{},()=>{t(e,te)[(w+fe[26])*E.dnc+f]=Math.round(o*1.27)},()=>{t(e,te)[(w+fe[26])*E.dnc+f]=o*9+1&127},()=>{t(e,te)[(w+fe[26])*E.dnc+f]=o?127:0}][$]()})}else{let i=a[1];a.subarray(2).forEach((o,d)=>{let u=d+i;t(e,Ie)[u]=o;let f=e.chRedir(1+(u>>4),c,!0),$=u&15;([!1,()=>{let w=t(e,Ie)[f-1<<4];if(w<3)if(t(e,Ee)[f]=1,w==2)for(let C=0;C{t(e,R)[f*E.rpn+3]=o+40,t(e,I)[E.rpnt*f+2]=1},()=>{t(e,R)[f*E.rpn+1]=o+14,t(e,I)[E.rpnt*f+1]=1},()=>{t(e,R)[f*E.rpn]=o,t(e,I)[E.rpnt*f]=1},!1,()=>{t(e,b)[E.cc*f+m[91]]=o?127:0},!1,()=>{t(e,b)[E.cc*f+m[7]]=o},()=>{t(e,b)[E.cc*f+m[10]]=Math.ceil(o*9.05)}][$]||(()=>{}))()})}}).add([22,18,4],(a,c,l)=>{e.switchMode("mt32");let s=a[1]+(a[0]<<7),i=[];a.subarray(2).forEach((o,d)=>{let u=d+s,f=e.chRedir(Math.floor(u/246+1),c,!0),$=u%246;$<14&&(t(e,ye)[(f-1)*E.cmt+$]=o),$<10&&(t(e,Ee)[f]=1),i.indexOf(f)<0&&i.push(f)}),i.forEach(o=>{e.dispatchEvent("voice",{part:o})})}).add([22,18,5],(a,c,l)=>{e.switchMode("mt32");let s=(a[0]<<7)+a[1];a.subarray(2).forEach((i,o)=>{let d=s+o,u=Math.floor(d/8),f=d&7,$=u*8;t(e,lt)[d]=i,([!1,()=>{let w=t(e,lt)[$];if(w<3){let C="";if(w==2){let X=E.cmt*u;C=`MT-m:${i.toString().padStart(3,"0")}`}else C=e.baseBank.get(0,i+(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],(a,c,l)=>{e.switchMode("mt32");let s=((a[0]&1)<<7)+a[1],i=a[0]>>1,o=!1;if(a.subarray(2).forEach((d,u)=>{let f=s+u;f{e.switchMode("mt32");let s=a[1],i=!1,o=function(d,u){t(e,K)[u-12]=d,i=!0};a.subarray(2).forEach((d,u)=>{let f=u+s;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,o,o,o,o,o,o,o,o,o,()=>{S(e,H,d),e.dispatchEvent("mastervolume",t(e,H))}][f]||(()=>{}))(d,u)}),i&&e.buildRchTree()}).add([22,18,32],(a,c,l)=>{e.switchMode("mt32");let s=a[1],i=" ".repeat(s);a.subarray(2).forEach(o=>{o>31?i+=String.fromCharCode(o):i+=" "}),S(e,Ue,i.padStart(20," ")),S(e,Be,Date.now()+3200)}).add([22,18,82],(a,c)=>{let l=e.chRedir(0,c,!0);for(let s=0;s<16;s++)t(e,F).ano(l+s),s&&s<10&&(t(e,O)[l+s]=Ht[s-1]);console.info("MT-32 alt reset complete.")}),t(this,xe).add([66,0],(a,c)=>{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(c),2,k.ns5r),S(e,G,!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 l=["ns5r","05rw"][a[0]];e.switchMode(l,!0),e.setPortMode(e.getTrackPort(c),2,k[l]),S(e,G,!1)}).add([66,18,0,0],(a,c)=>{let l=a[0];switch(l){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.setPortMode(e.getTrackPort(c),2,k.ns5r),S(e,G,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(l<10){let s=[0,0,0,0],i=(o,d)=>{s[d]=o};if(a.subarray(1).forEach((o,d)=>{[i,i,i,i,()=>{S(e,H,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,H))},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][l+d]()}),a[0]<4){let o=0;s.forEach(d=>{o=o<<4,o+=d}),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 l=e.chRedir(a[0],c,!0),s=l*E.cc,i=a[1],o=`NS5R CH${l+1} `;a.subarray(2).forEach((d,u)=>{let f=i+u;f<3?([()=>{t(e,b)[s+m[0]]=d||de.bank0},()=>{t(e,b)[s+m[32]]=d},()=>{t(e,O)[l]=d}][f](),e.dispatchEvent("voice",{part:l})):f<8||(f<14?[()=>{let $=e.chRedir(d,c,!0);t(e,K)[l]=$,l!=$&&(e.buildRchTree(),console.info(`${o}receives from CH${$+1}`))},()=>{t(e,se)[l]=+!d},()=>{e.setChType(l,d,k.ns5r),console.debug(`${o}type: ${Et[d]}`)},()=>{t(e,R)[E.rpn*l+3]=d,t(e,I)[E.rpnt*l+2]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)})},()=>{},()=>{}][f-8]():f<16||(f<33?[()=>{t(e,b)[s+m[7]]=d},()=>{t(e,b)[s+m[11]]=d},()=>{},()=>{},()=>{t(e,b)[s+m[10]]=d||128},()=>{},()=>{},()=>{t(e,b)[s+m[93]]=d},()=>{t(e,b)[s+m[91]]=d},()=>{t(e,b)[s+m[76]]=d},()=>{t(e,b)[s+m[77]]=d},()=>{t(e,b)[s+m[78]]=d},()=>{t(e,b)[s+m[74]]=d},()=>{t(e,b)[s+m[71]]=d},()=>{t(e,b)[s+m[73]]=d},()=>{t(e,b)[s+m[75]]=d},()=>{t(e,b)[s+m[72]]=d}][f-16]():f<112||f<114&&[()=>{t(e,b)[s+m[5]]=d},()=>{t(e,b)[s+m[65]]=d}][f-112]()))})}).add([66,18,8,0],(a,c)=>{let l=a[0];if(l<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let s=l-32;S(e,be,Date.now()+3200),S(e,Y,10),t(e,le,Se).fill(0);let i=a.subarray(1),o=4;i.forEach(function(d,u){let f=u+s,$=f>>4,w=f&15;if(f<80){let C=$>3,M=0,X=$0;)t(e,le,Se)[w*32+$*7+(X-M)]=C&1,C=C>>1,M++}})}}).add([66,18,48],(a,c,l)=>{p(0,a)}).add([66,18,49],(a,c,l)=>{p(1,a)}).add([66,18,50],(a,c,l)=>{p(2,a)}).add([66,18,51],(a,c,l)=>{p(3,a)}).add([66,18,52],(a,c,l)=>{p(4,a)}).add([66,18,53],(a,c,l)=>{p(5,a)}).add([66,18,54],(a,c,l)=>{p(6,a)}).add([66,18,55],(a,c,l)=>{p(7,a)}).add([66,52],(a,c)=>{e.switchMode("ns5r"),S(e,G,!1);let l="";ge(a,(s,i)=>{i<8?(s>31&&(l+=String.fromCharCode(s)),i==7&&(e.aiEfxName=l)):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"),S(e,G,!1);let l="",s=a[a.length-1],i=a.subarray(0,a.length-1),o=Ae(i);o!=s&&(console.info(`NS5R current multi dump checksum mismatch! Expected ${o}, got ${s}.`),console.debug(a));let d=e.getTrackPort(c);if(t(e,V)[d]&&t(e,V)[d]!=k.ns5r)if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+d)} mode "${Q[t(e,V)[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,k.ns5r),ge(i,function(u,f){switch(!0){case f<2944:{let $=e.chRedir(Math.floor(f/92),c,!0),w=$*E.cc;switch(f%92){case 0:{t(e,b)[w+m[0]]=u,e.dispatchEvent("voice",{part:$});break}case 1:{t(e,b)[w+m[32]]=u,!u&&!t(e,b)[w+m[0]]&&(t(e,b)[w+m[0]]=de.bank0),e.dispatchEvent("voice",{part:$});break}case 2:{t(e,O)[$]=u,u>0&&e.setChActive($,1),e.dispatchEvent("voice",{part:$});break}case 3:{let C=e.chRedir(u,c,!0);t(e,K)[$]=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)[$*E.rpn+3]=u<40||u>88?u+(u>63?-192:64):u,t(e,I)[E.rpnt*$+2]=1,e.dispatchEvent("pitch",{part:$,pitch:e.getPitchShift($)});break}case 9:case 10:{t(e,b)[w+m[7]]=u;break}case 11:{t(e,b)[w+m[11]]=u;break}case 14:{t(e,b)[w+m[10]]=u||128;break}case 19:{t(e,b)[w+m[93]]=u;break}case 20:{t(e,b)[w+m[91]]=u;break}case 84:{t(e,b)[w+m[65]]=u;break}case 85:{t(e,b)[w+m[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],(a,c)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let l="",s=80,i=0,o=0,d="MSB\tPRG\tLSB\tNME";ge(a,function(u,f){let $=f%158;switch(!0){case $<10:{u>31&&(l+=String.fromCharCode(u));break}case $==10:break;case $==11:{s=u&127;break}case $==12:{o=u&127;break}case $==13:{d+=` +${s} ${i} ${o} ${l.trim().replace("Init Voice","")}`,i++,l="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(d),A()&&console.debug(d),e.forceVoiceRefresh()}).add([66,55],(a,c)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r");let l="",s=88,i=0,o=0,d="MSB\tPRG\tLSB\tNME";ge(a,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+=` +${s} ${i} ${o} ${l.trim().replace("Init Combi","")}`,i++,l="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(d),A()&&console.debug(d),e.forceVoiceRefresh()}).add([66,125],(a,c,l)=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],(a,c,l)=>{let s=a[a.length-1],i=a.subarray(0,a.length-1),o=Ae(i);o!=s&&(console.info(`NS5R screen dump checksum mismatch! Expected ${o}, got ${s}.`),console.debug(a));let d=new Uint8Array(5760);ge(a,(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],(a,c,l)=>{t(e,xe).run([66,...a],c,l)}),t(this,Qe).add([16,0,8,0],(a,c,l)=>{let s=(a[2]<<4)+a[3],i="K11 ";([()=>{e.switchMode("k11",!0),e.setPortMode(e.getTrackPort(c),2,k.k11),S(e,G,!1),t(e,_)[k.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,l)=>{e.dispatchEvent("mupromptex");let s=e.chRedir(a[1],c,!0),i=E.cc*s,o=E.rpn*s,d=(a[3]<<4)+a[4],u=`K11 CH${s+1} `;([()=>{d<128?(e.setChType(s,e.CH_MELODIC,k.k11),t(e,b)[i+m[0]]=0,t(e,O)[s]=d):(e.setChType(s,e.CH_DRUMS,k.k11),t(e,O)[s]=d-128),e.dispatchEvent("voice",{part:s})},()=>{let f=e.chRedir(d,c,!0);t(e,K)[s]=f,s!=f&&(e.buildRchTree(),console.info(`${u}receives from CH${f+1}`))},()=>{t(e,b)[i+m[7]]=d},()=>{uupThis.setChActive(s,d)},()=>{t(e,b)[i+m[10]]=d},()=>{t(e,R)[o+3]=d+40,t(e,I)[E.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{t(e,R)[o+1]=d>>1,t(e,R)[o+2]=d&1,t(e,I)[E.rpnt*s+1]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{t(e,b)[i+m[91]]=d?127:0},()=>{},()=>{t(e,b)[i+m[74]]=d},()=>{t(e,b)[i+m[73]]=d},()=>{t(e,b)[i+m[72]]=d}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,c,l)=>{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,l)=>{e.dispatchEvent("mupromptex");let s=(a[2]<<4)+a[3],i=e.chRedir(a[1],c,!0),o=i*E.cc;[()=>{s<128?(e.setChType(i,e.CH_MELODIC,k.k11),t(e,b)[o+m[0]]=0,t(e,b)[o+m[32]]=0,t(e,O)[i]=s):s<160?(e.setChType(i,e.CH_MELODIC,k.k11),t(e,b)[o+m[0]]=0,t(e,b)[o+m[32]]=7,t(e,O)[i]=s-100):(e.setChType(i,e.CH_DRUMS,k.k11),t(e,b)[o+m[0]]=122,t(e,b)[o+m[32]]=0,t(e,O)[i]=s-160),e.dispatchEvent("voice",{part:i})},()=>{let d=e.chRedir(s,c,!0);t(e,K)[i]=d,i!=d&&(e.buildRchTree(),console.info(`GMLX CH${i+1} receives from CH${d+1}`))}][a[0]]()}).add([16,0,9,4],(a,c,l)=>{e.dispatchEvent("mupromptex");let s=(a[2]<<4)+a[3],i=e.chRedir(a[1],c,!0),o=i*E.cc,d=i*E.rpn,u=`GMLX CH${i+1} `;[()=>{e.setChActive(i,s)},()=>{t(e,b)[o+m[7]]=s},()=>{t(e,b)[o+m[10]]=s},()=>{t(e,b)[o+m[91]]=s?127:0},()=>{t(e,R)[d+3]=s+40,t(e,I)[E.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,R)[d+1]=s,t(e,I)[E.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,R)[d]=s,t(e,I)[E.rpnt*i]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{}][a[0]]()}),t(this,Ye).add([66,93,64],(a,c,l)=>{let s=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{e.dispatchEvent("mupromptex"),S(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,k.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,K)[i]=o,i!=o&&(e.buildRchTree(),console.info(`SG CH${i+1} receives from CH${o+1}`))}else a[1]==19&&(t(e,b)[E.cc*i+m[7]]=s)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,Ze).add([9],(a,c,l)=>{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,oe).add([127,0],(a,c,l)=>{e.switchMode("motif");let s=new Uint8Array([127,1,...a]);t(e,oe).run(s,c,l)}).add([127,1,0,0],(a,c,l)=>{e.switchMode("s90es");let s="S90/Motif ES system ",i=a[0];a.subarray(1).forEach((o,d)=>{([()=>{S(e,H,o*12900/16383),e.dispatchEvent("mastervolume",t(e,H))}][i+d]||(()=>{console.info(`Unrecognized ${s}ID: ${i+d}`)}))()})}).add([127,1,0,36,54,1],(a,c,l)=>{e.switchMode("s90es");let s="S90/Motif ES reverb ",i=a[0];a.subarray(1).forEach((o,d)=>{([()=>{e.setEffectTypeRaw(0,!1,o&15|112)},()=>{e.setEffectTypeRaw(0,!0,o)}][i+d]||(()=>{}))()}),e.dispatchEvent("efxreverb",e.getEffectType(0))}).add([127,1,0,37,54,2],(a,c,l)=>{e.switchMode("s90es");let s="S90/Motif ES chorus ",i=a[0];a.subarray(1).forEach((o,d)=>{([()=>{e.setEffectTypeRaw(1,!1,o&15|112)},()=>{e.setEffectTypeRaw(1,!0,o)}][i+d]||(()=>{}))()}),e.dispatchEvent("efxchorus",e.getEffectType(1))}).add([127,1,0,34,54,3],(a,c,l)=>{e.switchMode("s90es");let s="S90/Motif ES insert 1 ",i=a[0];a.subarray(1).forEach((o,d)=>{([()=>{e.setEffectTypeRaw(3,!1,o&15|112)},()=>{e.setEffectTypeRaw(3,!0,o)}][i+d]||(()=>{}))()}),e.dispatchEvent("efxinsert0",e.getEffectType(3))}).add([127,1,0,34,54,4],(a,c,l)=>{e.switchMode("s90es");let s="S90/Motif ES insert 2 ",i=a[0];a.subarray(1).forEach((o,d)=>{([()=>{e.setEffectTypeRaw(4,!1,o&15|112)},()=>{e.setEffectTypeRaw(4,!0,o)}][i+d]||(()=>{}))()}),e.dispatchEvent("efxinsert1",e.getEffectType(4))}).add([127,1,0,35,54,17],(a,c,l)=>{e.switchMode("s90es");let s="S90/Motif ES variation ",i=a[0];a.subarray(1).forEach((o,d)=>{([()=>{e.setEffectTypeRaw(2,!1,o&15|112)},()=>{e.setEffectTypeRaw(2,!0,o)}][i+d]||(()=>{}))()}),e.dispatchEvent("efxdelay",e.getEffectType(2))}).add([127,1,0,58,55],(a,c,l)=>{e.dispatchEvent("mupromptex"),e.switchMode("s90es");let s=e.getTrackPort(c);if(t(e,V)[s]&&t(e,V)[s]!=t(e,U).smotif)if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+s)} mode "${Q[t(e,V)[s]]}" mismatch, should be "${Q[t(e,U).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=E.cc*i,d=a[1];a[0]>15&&(i=a[0]+32);let u=`Track ${c} S90/Motif ES bulk CH${i<128?i+1:"U"+(i-127)} `;console.debug(u,a),!(a[0]>15)&&a.subarray(2).forEach((f,$)=>{([()=>{t(e,b)[o+m[0]]=f,e.dispatchEvent("voice",{part:i})},()=>{f&&e.setChActive(i,1),t(e,b)[o+m[32]]=f,e.setChType(i,[32,40].indexOf(f)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,B),!0),e.dispatchEvent("voice",{part:i})},()=>{f&&e.setChActive(i,1),t(e,O)[i]=f,e.dispatchEvent("voice",{part:i})},()=>{let w=e.chRedir(f,c,!0);t(e,K)[i]=w,i!=w&&(e.buildRchTree(),console.info(`${u}receives from CH${w+1}`))},()=>{t(e,se)[i]=f?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{f!=100&&e.setChActive(i,1),t(e,b)[o+m[7]]=f},()=>{f!=64&&e.setChActive(i,1),t(e,b)[o+m[10]]=f},!1,!1,!1,()=>{t(e,b)[o+m[91]]=f},()=>{f&&e.setChActive(i,1),t(e,b)[o+m[93]]=f},()=>{f&&e.setChActive(i,1),t(e,b)[o+m[94]]=f},()=>{f!=127&&e.setChActive(i,1),t(e,b)[o+m[128]]=f,e.allocateAce(i,128)},()=>{},()=>{f!=64&&e.setChActive(i,1),t(e,b)[o+m[74]]=f},()=>{f!=64&&e.setChActive(i,1),t(e,b)[o+m[71]]=f},!1,()=>{t(e,b)[o+m[65]]=f},()=>{t(e,b)[o+m[5]]=f},()=>{}][d+$]||(()=>{}))()})}).add([127,1,54,16],(a,c,l)=>{e.switchMode("s90es");let s=a[0];a.subarray(1).forEach((i,o)=>{let u=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let f=i-64},()=>{let f=nt[i]},()=>{let f=i/10},()=>{let f=i}][s+o&3]||(()=>{}))()})}),t(this,ue).add([0,72,18,0,0,0,0],(a,c,l)=>{e.switchMode("sd",!0),e.setPortMode(e.getTrackPort(c),2,k.sd),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,c,l)=>{e.dispatchEvent("mupromptex");let s=a[0]>>5,i=a[0]&31;switch(s){case 0:{let o=a[0]>>1,d=a[1];switch(o){case 1:{a.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:{a.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=o-1;a.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`,a);break}default:console.debug(`Unknown SD-90 global effects message: +%o`,a)}break}case 1:{let o=e.chRedir(i,c,!0),d=a[1],u=o*E.cc;a.subarray(2).forEach((f,$)=>{let w=d+$;w<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,b)[u+m[0]]=f,f){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,b)[u+m[32]]=f,e.dispatchEvent("voice",{part:o})},()=>{t(e,O)[o]=f,e.dispatchEvent("voice",{part:o})},()=>{t(e,b)[u+m[7]]=f},()=>{t(e,b)[u+m[10]]=f},()=>{},()=>{},()=>{f<2&&(t(e,se)[o]=f)},()=>{f<2&&(t(e,b)[u+m[68]]=f?127:0)},()=>{},()=>{f<2&&(t(e,b)[u+m[65]]=f?127:0)},()=>{t(e,b)[u+m[5]]=f&15<<4|t(e,b)[u+m[5]]&15},()=>{t(e,b)[u+m[5]]=f&15|(t(e,b)[u+m[5]]&240)>>4},()=>{t(e,b)[u+m[74]]=f},()=>{t(e,b)[u+m[71]]=f},()=>{t(e,b)[u+m[73]]=f},()=>{t(e,b)[u+m[72]]=f},0,0,0,0,0,0,0,()=>{t(e,b)[u+m[128]]=f,e.allocateAce(128)},()=>{t(e,b)[u+m[93]]=f},()=>{t(e,b)[u+m[91]]=f},0,0,()=>{t(e,b)[u+m[75]]=f},()=>{t(e,b)[u+m[76]]=f},()=>{t(e,b)[u+m[77]]=f},()=>{t(e,b)[u+m[78]]=f}][w]||(()=>{}))():w<63||(w<64?(t(e,D)[o]?t(e,b)[u+m[0]]=104|f:t(e,b)[u+m[0]]=96|f,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),d=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,xe).add([0,1,73,78],(a,c,l)=>{e.switchMode("krs"),e.setPortMode(e.getTrackPort(c),1,k.krs),console.debug("Might be KORG KROSS 2 mode reset... Not sure.")}).add([0,1,73,117,2,37],(a,c,l)=>{e.switchMode("krs");let s=e.getTrackPort(c);if(t(e,V)[s]&&t(e,V)[s]!=k.krs)if(t(e,we).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+s)} mode "${Q[t(e,V)[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,k.krs);let i="KROSS 2 BMT1 ",o="";ge(a,(d,u)=>{if(u<24)o+=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=E.cc*$;w<15?([()=>{d&&e.setChActive($,1),t(e,O)[$]=d,e.dispatchEvent("voice",{part:$})},()=>{d&&e.setChActive($,1),d<10?(t(e,b)[C+m[0]]=63,t(e,b)[C+m[32]]=d):d<20?(t(e,b)[C+m[0]]=121,t(e,b)[C+m[32]]=d-10):d<24&&(t(e,b)[C+m[0]]=[120,0,56,62][d-20],t(e,b)[C+m[32]]=0),e.dispatchEvent("voice",{part:$})},()=>{let M=e.chRedir(d&15,c,!0);t(e,K)[$]=M,console.info(`${i}CH${$+1} receives from CH${M+1}`)},!1,!1,()=>{t(e,b)[C+m[7]]=d},!1,()=>{},()=>{},!1,!1,!1,!1,!1,()=>{t(e,b)[C+m[10]]=d||128}][w]||(()=>{}))():w<36||([()=>{t(e,b)[C+m[74]]=(d+128&255)-64},()=>{t(e,b)[C+m[71]]=(d+128&255)-64},!1,!1,()=>{t(e,b)[C+m[73]]=(d+128&255)-64},()=>{t(e,b)[C+m[75]]=(d+128&255)-64},!1,()=>{t(e,b)[C+m[72]]=(d+128&255)-64}][w]||(()=>{}))()}}),o=o.trimRight(),e.dispatchEvent("metacommit",{type:"EORTitle",data:o})})}chRedir(e,r,h){let n=this;if(t(n,Ne)[r])return(t(n,Ne)[r]-1)*16+e;if(t(n,B)==k.sc){if(h==1)return e;let p=0,y=!0;for(;y;)t(n,Me)[e+p]==0?(t(n,Me)[e+p]=r,console.debug(`Assign track ${r} to channel ${e+p+1}.`),y=!1):t(this,Me)[e+p]==r?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;r{r&&(t(e,Ke)[Math.floor(h/E.redir)][r]=h%E.redir|128)}),A()&&console.debug(t(e,Ke))}getActive(){return t(this,he)}getCc(e){let r=this,h=e*E.cc,n=t(r,b).subarray(h,h+E.cc);return n[m[0]]=n[m[0]]||t(r,_)[r.getChModeId(e)][0],n[m[32]]=n[m[32]]||t(r,_)[r.getChModeId(e)][1],n[m[0]]==de.bank0&&(n[m[0]]=0),n}getCcCh(e,r){let h=this;if(vt.indexOf(r)<0)throw new Error("CC number not accepted");let n=t(h,b)[E.cc*e+m[r]];switch(r){case 0:{n=n||t(h,_)[h.getChModeId(e)][0],n==de.bank0&&(n=0);break}case 32:{n=n||t(h,_)[h.getChModeId(e)][1];break}}return n}getCcAll(){let e=this,r=t(e,b).slice();for(let h=0;h0&&!n&&(t(p,b)[e*E.cc+m[0]]=t(p,_)[h][2])}setChActive(e,r=0){t(this,he)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),t(this,he)[e]=r}getExt(e){let r=E.ext*e,h=t(this,ie).subarray(r,r+E.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,O)}getTexts(){return t(this,ce).slice()}getVel(e){let r=new Map,h=this;return t(h,q).forEach(function(n,p){let y=Math.floor(n/128),v=n%128;e==y&&t(h,z)[n]>0&&r.set(v,{v:t(h,z)[n],s:t(h,W)[p]})}),r}getBitmap(){return{bitmap:t(this,le,Se),expire:t(this,be)}}getLetter(){return{text:t(this,Ue),set:t(this,kt),expire:t(this,Be)}}getMode(){return Q[t(this,B)]}getMaster(){return{volume:t(this,H)}}getRawStrength(){let e=this;return t(this,q).forEach(function(r){let h=Math.floor(r/128);t(e,z)[r]>t(e,$e)[h]&&(t(e,$e)[h]=t(e,z)[r])}),t(this,$e)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(h,n){e[n]=Math.floor(h*t(r,b)[n*E.cc+m[7]]*t(r,b)[n*E.cc+m[11]]*t(r,H)/803288)}),e}getRpn(){return t(this,R)}getNrpn(){return t(this,ct)}getSubDb(){return self==null?void 0:self.structuredClone(t(this,_))}getVoice(e,r,h,n="?"){var l;let p=this;(l=k[n])!=null&&l.constructor||(n="?");let y=k[n],v=e||t(p,_)[y][0],x=r,a=h||t(p,_)[y][1];v==de.bank0&&(v=0),a==de.bank0&&(a=0),n=="ns5r"&&v>0&&v<56&&(a=3);let c=p.userBank.get(v,x,a,n);if(n=="mt32"&&c.name.indexOf("MT-m:")==0){let s=parseInt(c.name.slice(5)),i=s*E.cmt,o="";t(p,Le).subarray(i,i+10).forEach(u=>{u>31&&(o+=String.fromCharCode(u))});let d=`MSB LSB PRG NME +0 127 ${x} ${o}`;p.userBank.load(d,!0),c.name=o,c.ending=" "}return(c.ending!=" "||!c.name.length)&&(c=p.baseBank.get(v,x,a,n)),c}getChVoice(e){let r=this,h=r.getVoice(r.getCcCh(e,0),t(r,O)[e],r.getCcCh(e,32),r.getChMode(e));if(t(r,Ee)[e]){let n="";switch(t(r,B)){case k.mt32:{t(r,ye).subarray(E.cmt*(e-1),E.cmt*(e-1)+10).forEach(p=>{n+=String.fromCharCode(Math.max(p,32))}),n=n.trimRight();break}default:{let p=E.cvn*e;t(r,$t).subarray(p,p+E.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 r=this,h=e*E.rpn,n=t(r,R)[h];return t(r,I)[e*E.rpnt]||t(r,B)==k.mt32&&(n=12),t(r,Te)[e]/8192*n+(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,ne).subarray(r,r+2)}setEffectTypeRaw(e=0,r,h){let n=3*e;t(this,ne)[n]=1,t(this,ne)[n+1+ +r]=h}setEffectType(e=0,r,h){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,h)}getEffectSink(){return t(this,ot)}setLetterDisplay(e,r,h=0,n=3200){let p=this,y;S(p,Ue," ".repeat(h)),e.forEach(v=>{S(p,Ue,t(p,Ue)+String.fromCharCode(v>31?v:32)),v<32&&(y=y||new Set,y.add(v))}),S(p,kt,Date.now()),S(p,Be,Date.now()+n),y&&(y=Array.from(y),y.forEach((v,x,a)=>{a[x]=v.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${y.length>1?"s":""}: 0x${y.join(", 0x")}`))}setDetectionTargets(e="?",r=0){let h=this,n=-1;switch(e.replaceAll(", ",",").split(",").forEach(p=>{p=p.toLowerCase();let y=Q.indexOf(Ga[p]||p);A()&&console.debug(`Mapped mode "${p}" to ID "${y}".`),y>-1&&(n=y)}),A()&&console.debug(`Set detection target to ID "${n}".`),n>0&&(t(h,U).x5=82,t(h,U).ds=k.krs),n){case k["05rw"]:{t(h,U).x5=81;break}case k.s90es:t(h,U).ds=k.s90es,t(h,U).smotif=k.s90es;case k.motif:t(h,U).ds=k.motif,t(h,U).smotif=k.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,U)[e?"sc":"gs"]=r,t(h,_)[k[e?"sc":"gs"]][1]=r,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=0,r){let h=this;if(!r||r<128&&r>95){console.warn(`cc${r} cannot be allocated as an active custom effect.`);return}let n=!0,p=0,y=E.ace*e;for(;n&&p=E.ace&&console.warn(`ACE slots are full in CH${e+1}.`)}allocateAceAll(e){let r=this;if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}for(let h=0;h=E.ace&&console.warn(`ACE slots are full in CH${h+1}.`)}}releaseAce(e=0,r){let h=!0,n=E.ace*e,p=n+E.ace;for(;h&&n=E.ace)throw new RangeError("No such ACE slot");let h=t(this,Z)[E.ace*e+r];if(h){if(vt.indexOf(h)>=0)return t(this,b)[e*E.cc+m[h]];throw new Error(`Invalid ACE source in CH${e+1}: ${h}`)}else return 0}initDrums(){let e=this;t(e,te).fill(64);for(let r=0;r{t(r,b)[E.cc*h]=t(r,_)[r.getChModeId(h)][2]}),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=E.ch)throw new RangeError(`Invalid CH${e+1}`);if(port<0||r>=Q.length)throw new RangeError(`Invalid mode ID ${r}`);t(h,Oe)[e]=r,h.dispatchEvent("voice",{part:e})}getChMode(e,r){return Q[this.getChModeId(e,r)]}getChModeId(e,r){return r?t(this,Oe)[e]||t(this,V)[e>>4]:t(this,Oe)[e]||t(this,V)[e>>4]||t(this,B)}setPortMode(e,r,h){let n=this;if(e<0||e>=E.ch>>4)throw new RangeError(`Invalid port ${e+1}`);if(r<1)throw new RangeError("Range must be a positive integer");if(e+r>=E.ch>>4)throw new RangeError("Range must be in bound");if(e<0||h>=Q.length)throw new RangeError(`Invalid mode ID ${h}`);for(let p=e;p=0&&e-1){if(t(n,B)==0||r){let v=t(n,B);n.initOnReset&&r&&(this.init(1),v=k["?"]),S(n,B,p),S(n,Y,0);for(let a=0;a0&&t(n,Oe)[a]==0&&(t(n,b)[a*E.cc]=t(n,_)[p][2]);switch(p){case k.mt32:{Ht.forEach((a,c)=>{let l=c+1;t(n,he)[l]||(t(n,O)[l]=a,t(n,b)[l*E.cc+m[91]]=127)});for(let a=1;a<10;a++)n.dispatchEvent("voice",{part:a});break}}let x;switch(p){case k["?"]:case k.g2:{x=[52,4,52,18,0,0,0,0];break}case k.xg:{x=[1,0,65,0,5,0,0,0];break}case k.gm:case k.gs:case k.sc:{x=[40,4,40,18,40,32,32,0];break}case k.sd:{x=[58,0,60,0,61,0,61,0];break}case k["05rw"]:case k.x5d:case k.ns5r:{x=[44,1,44,19,44,0,44,0];break}case k.k11:case k.sg:{x=[24,0,0,0,0,0,0,0];break}case k.mt32:{x=[40,4,0,0,0,0,0,0];break}case k.doc:{x=[24,16,0,0,0,0,0,0];break}case k.motif:case k.s90es:{x=[113,0,117,0,114,0,0,0];break}default:x=[0,0,0,0,0,0,0,0]}for(let a=0;a{n.dispatchEvent("voice",{part:a})})}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,$e).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,St)[e.type].call(this,e);{let h=this.chRedir(e.part,e.track),n=!1;(r=t(this,xt)[h])==null||r.forEach(p=>{e.channel=p,n=!0,t(this,St)[e.type].call(this,e)}),n||console.warn(`${da[e.type]?da[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,ce).length>100&&t(this,ce).splice(100,t(this,ce).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":{bt.context=this,await h.userBank.load(await bt.read(e,r),!1);break}}h.forceVoiceRefresh()}},B=new WeakMap,Y=new WeakMap,be=new WeakMap,Ce=new WeakMap,le=new WeakSet,Se=function(){return t(this,Ce)[t(this,Y)]},ya=function(e){t(this,Ce)[t(this,Y)]=e},he=new WeakMap,K=new WeakMap,D=new WeakMap,b=new WeakMap,Z=new WeakMap,O=new WeakMap,z=new WeakMap,se=new WeakMap,q=new WeakMap,W=new WeakMap,Te=new WeakMap,$e=new WeakMap,Xe=new WeakMap,ie=new WeakMap,R=new WeakMap,I=new WeakMap,ct=new WeakMap,te=new WeakMap,me=new WeakMap,ne=new WeakMap,ot=new WeakMap,Ve=new WeakMap,V=new WeakMap,Oe=new WeakMap,Ee=new WeakMap,$t=new WeakMap,Ie=new WeakMap,ye=new WeakMap,lt=new WeakMap,Le=new WeakMap,_=new WeakMap,U=new WeakMap,we=new WeakMap,wt=new WeakMap,H=new WeakMap,Fe=new WeakMap,dt=new WeakMap,ft=new WeakMap,Ue=new WeakMap,Be=new WeakMap,kt=new WeakMap,ht=new WeakMap,ke=new WeakMap,G=new WeakMap,Pt=new WeakMap,xt=new WeakMap,Ke=new WeakMap,ce=new WeakMap,Me=new WeakMap,Ne=new WeakMap,J=new WeakMap,ze=new WeakMap,F=new WeakMap,St=new WeakMap,Rt=new WeakMap,qe=new WeakMap,We=new WeakMap,oe=new WeakMap,ue=new WeakMap,xe=new WeakMap,Qe=new WeakMap,Ye=new WeakMap,Ze=new WeakMap,Ea);var Vt=La(va(),1);L();L();var Ct,$a,ka=($a=class{constructor(g,e,r,h){T(this,Ct,!1);S(this,Ct,g),this.start=e,this.end=r,this.data=h}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return t(this,Ct)}},Ct=new WeakMap,$a),Gt=class extends ka{constructor(g,e,r){super(!0,g,e,r)}},xa=class extends ka{constructor(g,e){super(!1,g,g,e)}},Je,wa,Xt=(wa=class extends Array{constructor(){super(...arguments);T(this,Je,-1)}resetIndex(e){S(this,Je,-1)}fresh(){this.sort(function(e,r){return e.start==r.start?0:(+(e.start>r.start)<<1)-1}),this.forEach(function(e,r){e.index=r})}step(e,r=!1){let h=[];if(r)for(let n=0;ne);n++){if(this[n].endt(p,Je)&&(h.push(y),S(p,Je,y.index))})}return h}getRange(e,r){var v;e>r&&([e,r]=[r,e]);let h=[],n=-1,p=Math.ceil(Math.sqrt(this.length)),y=!0;for(let x=0;x=e&&(n=x):n=n<0?x:n;for(;y;)((v=this[n])==null?void 0:v.end)=e&&h.push(this[n]):y=!1,n++;return h}},Je=new WeakMap,wa);var Wa=0xffffffffffff,Sa=function(g){let e=new Xt,r=this,h=g.timeDivision,n=120,p=new Xt,y=0,v=0;p.push(new Gt(0,Wa,[120,0])),g.track.forEach(function(l){y=0,l.event.forEach(function(s){y+=s.deltaTime,s.type==255&&(s==null?void 0:s.metaType)==81&&(n=6e7/s.data,p[p.length-1]&&p.push(new Gt(y,0xffffffffffff,[n,0])))})}),p.fresh(),p.forEach(function(l,s,i){s>0&&(i[s-1].end=l.start)});let x=120;p.forEach(function(l,s,i){s>0&&(l.end==l.start?i.splice(i.indexOf(l),1):x==l.data[0]&&(i[s-1].end=l.end,i.splice(i.indexOf(l),1)),x=l.data[0])});let a=0,c=120;return p.forEach(function(l){let s=l.start,i=s/c/h*60+a;c=l.data[0],a=i-s/c/h*60,l.data[1]=a}),console.debug("All tempo changes: ",p),n=120,y=0,v=0,g.track.forEach(function(l,s){y=0,v=0;let i=s+1;l.event.forEach(function(o,d){y+=o.deltaTime;let u=p.step(y,!0)[0];u&&(n=u.data[0],v=u.data[1]);let f={type:o.type,data:o.data,track:i,part:0};o.type>14?f.meta=o.metaType:f.part=o.channel,e.push(new xa(y/n/h*60+v,f))})}),e.fresh(),self.midiEvents=e,console.debug(`Parsed a type ${g.formatType} MIDI sequence.`),e};Vt.default.customInterpreter=ca;var N=function(g,e,r){g.addEventListener(r,h=>{e.dispatchEvent(r,h.data)})},je,et,ut,Pe,tt,pt,at,Tt,He,_e,j,rt,Re,st,Ca,ts=(Ca=class extends Mt{constructor(e,r=.5,h=.5){super();P(this,"device");T(this,je,void 0);T(this,et,{});T(this,ut,[]);T(this,Pe,"");T(this,tt,[]);T(this,pt,[]);T(this,at,new Uint8ClampedArray(128));T(this,Tt,new Uint8ClampedArray(128));T(this,He,.5);T(this,_e,120);T(this,j,4);T(this,rt,4);T(this,Re,0);T(this,st,0);P(this,"smoothingAtk",0);P(this,"smoothingDcy",0);let n=this;n.smoothingAtk=r,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,tt)[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,tt)[3]=function(p,y){var v;((v=t(n,Pe))==null?void 0:v.length)<1&&(S(n,Pe,y),n.dispatchEvent("title",t(n,Pe)))},t(n,tt)[81]=function(p,y){let v=n.noteProgress,x=t(n,He)||.5;S(n,_e,6e7/y),S(n,He,y/1e6),S(n,Re,t(n,Re)+(v*(x/t(n,He))-v)),n.dispatchEvent("tempo",t(n,_e))},t(n,tt)[88]=function(p,y){let v=n.noteProgress,x=n.noteOverall,a=n.noteBar,c=n.noteBeat,l=t(n,j),s=t(n,rt);S(n,j,y[0]),S(n,rt,1<=l&&(l{if(!a)return;let l=a.split("\t");if(c){if(!y)return;let s="",i="";l.forEach((o,d)=>{switch(d){case v:{s=o;break}case x:{i=o;break}}}),!t(h,et)[s]||r?(t(h,et)[s]=i,n++):self.debugMode&&console.debug(`Voice "${i}" (${s}) seems to be in conflict with (${t(h,et)[s]}).`),p++}else l.forEach((s,i)=>{switch(s){case"ID":{v=i,y++;break}case"Name":{x=i,y++;break}default:console.debug(`Unknown map field: ${s}`)}})}),console.debug(`Voice names: ${p} total, ${n} loaded.`),h==null||h.device.forceVoiceRefresh()}async loadEfx(e,r){let h=this,n=0,p=0,y,v,x;e.split(` +`).forEach((a,c)=>{if(a)if(c){let l=0,s;a.split("\t").forEach((i,o)=>{switch(o){case y:{l|=parseInt(i,16)<<8;break}case v:{l|=parseInt(i,16);break}case x:{s=i;break}}}),!t(h,ut)[l]||r?(t(h,ut)[l]=s,n++):self.debugMode&&console.debug(`EFX ID 0x${l.toString(16).padStart(4,"0")} (${s}) seems to be in conflict.`),p++}else a.split("\t").forEach((l,s)=>{switch(l){case"MSB":{y=s;break}case"LSB":{v=s;break}case"Name":{x=s;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,r=!1){this.device.switchMode(e,r)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}getMapped(e){return t(this,et)[e]||e}getEfx([e,r]){let h=e<<8|r;return t(this,ut)[h]||`0x${h.toString(16).padStart(4,"0")}`}getVoxBm(e){if(!e)throw new Error("Voice object must be valid");let r=this;if(!r.voxBm)throw new Error("Voice bitmap repository isn't yet initialized");let h=r.voxBm.getBm(e.name);if(!h)switch(e.mode){case"xg":{switch(e.sid[0]){case 0:case 80:case 81:case 83:case 84:case 96:case 97:case 99:case 100:{h=r.voxBm.getBm(r.getVoice(de.bank0,e.sid[1],de.bank0,e.mode).name);break}}break}case"g2":case"sd":{switch(e.sid[0]){case 96:case 97:case 98:case 99:{h=r.voxBm.getBm(r.getVoice(de.bank0,e.sid[1],de.bank0,e.mode).name);break}case 104:case 105:case 106:case 107:{h=r.voxBm.getBm(r.getVoice(120,e.sid[1],de.bank0,e.mode).name);break}}break}case"gs":case"sc":case"k11":case"sg":case"gm":{switch(e.sid[0]){case 120:break;case 122:case 127:{h=r.voxBm.getBm(r.getVoice(120,e.sid[1],0,e.mode).name);break}default:h=r.voxBm.getBm(r.getVoice(0,e.sid[1],0,e.mode).name)}break}default:switch(e.sid[0]){case 56:{h=r.voxBm.getBm(r.getVoice(0,e.sid[1],0,e.mode).name);break}}}return h||(h=r.voxBm.getBm(r.getVoice(e.sid[0],e.sid[1],0,e.mode).name)),h}getChBm(e,r){let h=this;return r=r||h.getChVoice(e),h.getVoxBm(r)}get noteProgress(){return t(this,st)/t(this,He)}get noteOverall(){return this.noteProgress-t(this,Re)}get noteBar(){return Math.floor(this.noteOverall/t(this,j))}get noteBeat(){let e=this.noteOverall%t(this,j);return e<0&&(e+=t(this,j)),e}getTimeSig(){return[t(this,j),t(this,rt)]}getTempo(){return t(this,_e)}sendCmd(e){this.device.runJson(e)}render(e){var w;e>t(this,st)&&S(this,st,e);let r=((w=t(this,je))==null?void 0:w.step(e))||[],h=0,n=new Set,p={},y=[],v=this,x=[];for(v.device.getStrength().forEach((C,M)=>{t(v,Tt)[M]=C}),v.device.newStrength(),r.forEach(function(C){let M=C.data,X=v.device.runJson(M);switch(X==null?void 0:X.reply){case"meta":{x.push(X);break}}X!=null&&X.reply&&delete X.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++)}(x==null?void 0:x.length)>0&&v.dispatchEvent("meta",x);let a=v.device.getActive(),c=[],l=v.device.getPitch(),s=v.device.getCcAll(),i=v.device.getProgram(),o=v.device.getChType(),d=[],u=v.device.getStrength();u.forEach(function(C,M,X){X[M]=Math.max(t(v,Tt)[M],C);let De=X[M]-t(v,at)[M],Ge=m.length*M;if(De>=0){let At=4*.25**(s[Ge+m[73]]/64);t(v,at)[M]+=Math.ceil(De-De*v.smoothingAtk**At)}else{let At=4*.25**(s[Ge+m[72]]/64);t(v,at)[M]+=Math.floor(De-De*v.smoothingDcy**At)}});let f=0;return a.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:a,chKeyPr:c,chPitch:l,chProgr:i,chContr:s,chType:o,chExt:d,eventCount:r.length,title:t(v,Pe),bitmap:v.device.getBitmap(),letter:v.device.getLetter(),texts:v.device.getTexts(),master:v.device.getMaster(),mode:v.device.getMode(),strength:t(v,at).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()}}},je=new WeakMap,et=new WeakMap,ut=new WeakMap,Pe=new WeakMap,tt=new WeakMap,pt=new WeakMap,at=new WeakMap,Tt=new WeakMap,He=new WeakMap,_e=new WeakMap,j=new WeakMap,rt=new WeakMap,Re=new WeakMap,st=new WeakMap,Ca);export{ts as RootDisplay,E as allocated,m as ccToPos,fe as dnToPos}; \ No newline at end of file diff --git a/dist/xp_state.mjs b/dist/xp_state.mjs index a26c804b..dabb5777 100644 --- a/dist/xp_state.mjs +++ b/dist/xp_state.mjs @@ -1,10 +1,10 @@ -var qt=Object.defineProperty;var Qt=(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)=>(Qt(y,typeof e!="symbol"?e+"":e,r),r),$t=(y,e,r)=>{if(!e.has(y))throw TypeError("Cannot "+r)};var t=(y,e,r)=>($t(y,e,"read from private field"),r?r.call(y):e.get(y)),S=(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)=>($t(y,e,"write to private field"),h?h.call(y,r):e.set(y,r),r);(function(){var y=function(k,C,a){var c,f;if(self.MessageEvent)switch(k){case"message":{f=new MessageEvent(k,{data:C,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=C,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 C,a=this;if((this==null?void 0:this.constructor)!=u)throw new TypeError("Illegal constructor");r.push(this),(C=h[k])!=null&&C.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(C){var a=C.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 C=vt(e,this.pool[E]);switch(C){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 ${C}.`)}}u=u>>1,v--}let k=!0;if(E>=this.pool.length)k=!1;else{let C=this;this.pool[E].forEach(function(a,c,f){k&&a!=e[c]&&(k=!1)}),!k&&vt(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,wt,kt=(wt=class{constructor(){S(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,wt);var Yt=["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){S(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,C,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,C=$==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,C=$==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:C,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,C){let a=k.split("\t"),c=[];if(C==0){if(a.forEach(function(f,s){u[Yt.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 C=e[0];C<=e[1];C++)delete t(this,Q)[C][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,St,Ct=(St=class{constructor(){S(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,St);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},ge=new TextDecoder,Je=new Ct;Je.set("s7e",async function(y){let e=new Uint8Array(await y.slice(0,65536).arrayBuffer()),r="MSB\tLSB\tPRG\tNME",h=[0,0,0,0],u=32,E=0,v=0,k=!0,C=[],a=0;for(;k;){let c=e.subarray(E);([()=>{ge.decode(c.subarray(0,4))=="YSFC"?(E+=80,v=1):E++},()=>{if(jt(c.subarray(0,4),h))C.forEach((f,s,i)=>{let o=je(e.subarray(f.start+4,f.start+8));f.length=o}),v=2;else{let f=ge.decode(c.subarray(0,4)),s=je(c.subarray(4,8));C.push({type:f,start:s}),E+=8}},()=>{let f=C[a],s=e.subarray(f.start,f.start+f.length),i=32;switch(f.type){case"ENVC":{let o=u;for(;o=C.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\tLSB\tPRG\tNME",h=100,u=0,E=0,v=!0,k=[],C=0;for(;v;){let a=e.subarray(h);([()=>{v=ge.decode(a.subarray(0,4))=="INI2",E=a[15],h+=16,u=1},()=>{let c=ge.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=ge.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[C],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=ge.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=ge.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}}C++,C>=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"],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],Mt=[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],Tt=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},Rt=function(y){return y>105?Jt[y-106]:y>100?y*1.1-100:y/10},Dt=",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*, +var Wt=Object.defineProperty;var qt=(y,e,r)=>e in y?Wt(y,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):y[e]=r;var T=(y,e,r)=>(qt(y,typeof e!="symbol"?e+"":e,r),r),mt=(y,e,r)=>{if(!e.has(y))throw TypeError("Cannot "+r)};var t=(y,e,r)=>(mt(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)=>(mt(y,e,"write to private field"),h?h.call(y,r):e.set(y,r),r);(function(){var y=function(k,M,a){var c,d;if(self.MessageEvent)switch(k){case"message":{d=new MessageEvent(k,{data:M,ports:a==null?void 0:a.ports}),Object.defineProperty(d,"source",{value:a==null?void 0:a.source});break}default:d=new Event(k)}else d=document.createEvent("Event"),d.initEvent(k,!1,!1),a&&k=="message"&&(d.data=M,a.source&&Object.defineProperty(d,"source",{value:a.source}),(c=a.ports)!=null&&c.length&&Object.defineProperty(d,"ports",{value:a.ports}));return d};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 M,a=this;if((this==null?void 0:this.constructor)!=u)throw new TypeError("Illegal constructor");r.push(this),(M=h[k])!=null&&M.constructor||(h[k]=[]),h[k].push(this);var c=Math.floor(Math.random()*281474976710656),d=[],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 f={};this.dispatchEvent=function(l){var m,$;if(Object.defineProperty(l,"target",{value:a}),Object.defineProperty(l,"currentTarget",{value:a}),(m=f[l.type])!=null&&m.length)for(var S=f[l.type],L=0;L-1&&f[l].splice(L,1)}!((S=f[l])!=null&&S.length)&&f[l].constructor&&delete f[l]}},self.BroadcastChannel=u,b=function(){if(e){e.addEventListener("message",function(M){var a=M.data,c=!1;switch(a.t){case"k":{c=!1,e.postMessage({t:"k"});break}case"m":{var d=h[a.c];if(d!=null&&d.length)for(var s=0;s{switch(h.addEventListener("abort",()=>{b(new Error("Blob read aborted"))}),h.addEventListener("error",v=>{b(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:b(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,b=[];for(;r-1;){let v=u.lastIndexOf(y);b.unshift(u.slice(v+y.length)),u=u.slice(0,v),v==0&&b.unshift(""),r++}return u.length&&b.unshift(u),b.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(b==h)b-=u;else{let M=$t(e,this.pool[b]);switch(M){case 0:{v=0;break}case 1:{b+u<=h&&(b+=u);break}case-1:{b!=0&&(b-=u);break}default:console.warn(`Unexpected result ${M}.`)}}u=u>>1,v--}let k=!0;if(b>=this.pool.length)k=!1;else{let M=this;this.pool[b].forEach(function(a,c,d){k&&a!=e[c]&&(k=!1)}),!k&&$t(e,this.pool[b])>0&&b++}return k||r?b:-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,vt,wt=(vt=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(b){try{b==null||b.call(h,r)}catch(v){console.error(v)}}),this[`on${y}`]&&this[`on${y}`](r)}},J=new WeakMap,vt);var Qt=["MSB","PRG","LSB","NME","ELC","DRM"],ht=function(y){let e=Math.floor(y/10),r=y%10;return`${e.toString(16)}${r}`},Y,kt,ut=(kt=class{constructor(...y){C(this,Y,void 0);T(this,"strictMode",!1);this.loadFiles(...y)}get(y=0,e=0,r=0,h){var m,$;let u=[y,e,r],b,v=1,k=0,M,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=" ",d="M",s="",i=0,o=0;switch(a[0]){case 0:{switch(a[2]){case 127:{h=="xg"?d="GM-a":(d="MT-a",s="C/M");break}case 126:{h=="xg"?d="GM-n":(d="MT-b",s="C/M");break}case 7:{d="GM-k",s="GLX";break}case 5:{d="SG-a",s="000";break}case 4:{h=="gs"||h=="sc"?(d="GM-a",s="000"):(d="SP-l",s="C/M");break}case 3:case 2:case 1:{(h=="gs"||h=="sc")&&(d="GM-a",s="000");break}case 0:{d="GM-a";break}default:d="y",i=3}break}case 8:{h=="sg"?d="GM-s":d="r:";break}case 32:case 33:case 34:case 35:case 36:{h=="xg"&&(d=`${["AP","VL","PF","DX","AN"][y&7]}-${"abcdefgh"[r]}`,i=3);break}case 48:{s=`M${(a[2]>>3).toString().padStart(2,"0")}`,d=`y${s}`,i=1;break}case 56:{d="GM-b";break}case 57:d=["yDOC","QY10","QY20"][a[2]-112]||"yMxv",s=["DOC","QY1","QY2"][a[2]-112]||"057";case 61:case 120:{d="rDrm";break}case 62:{d="kDrm";break}case 63:{if(a[2]<17){let S=a[2];d=S<10?"kP:":"kC:",d+=S%10}else a[2]<34?d=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][a[2]-17]:d="Ds";i=1;break}case 64:{d="ySFX",s="SFX";break}case 67:{d="DX:S";break}case 80:case 81:case 82:case 83:{d=`Prg${"UABC"[a[0]-80]}`;break}case 88:case 89:case 90:case 91:{d=`Cmb${"UABC"[a[0]-88]}`;break}case 95:{d=`${["DR","PC"][a[2]]}-d`;break}case 96:{d=a[2]==106?"AP-a":a[2]>>4==1?"SDg":"PF",a[2]>63?o=63:a[2]>>4==1&&(o=16),i=3;break}case 97:{d=a[2]>>4==1?"SDa":"VL:",i=3,a[2]>>4==1?o=16:o=112;break}case 98:{d=a[2]>>4==1?"SDb":"SG-a",i=3,o=16;break}case 99:{d=a[2]>>4==1?"SDc":"DX",a[2]>63?o=63:a[2]>>4==1&&(o=16),i=3;break}case 100:{d="AN",a[2]>63?o=63:a[2]>>4==1&&(o=16),i=3;break}case 104:case 105:case 106:case 107:{d="SDd",o=104;break}case 121:{d=`GM-${a[2]?"":"a"}`,i=3;break}case 122:{d="lDrm";break}case 126:{d="yDrS";break}case 127:{a[2]==127?d="rDrm":d="yDrm";break}default:a[0]<48?d="r:":d="M"}d.length<4&&(d+=`${[y,r,a[0],a[2]][i]-o}`.padStart(4-d.length,"0")),s.length<3&&(s+=`${[y,r,y,r][i]}`.padStart(3-s.length,"0")),h=="xg"&&(y==0?a[2]<100?d=d.replace("y0","y:"):a[2]==125&&(d="y126"):y==16?(b=`Voice${((a[2]<<7)+a[1]+1).toString().padStart(3,"0")}`,c=" "):y==35&&r>>1==2&&(b=`DXCH_${(((a[2]&1)<<7)+e+1).toString().padStart(3,"0")}`,c=" "));let n=[a[0],a[1],a[2]];for(;!((b==null?void 0:b.length)>=0);)if(b=(m=t(this,Y)[a[1]||0][(a[0]<<7)+a[2]])==null?void 0:m.name,b){let S=t(this,Y)[a[1]||0][(a[0]<<7)+a[2]];v=(S==null?void 0:S.poly)||v,k=(S==null?void 0:S.type)||k,M=S==null?void 0:S.drum}else if(this.strictMode)b="",c="?";else if(a[0]==0&&a[1]==0&&a[2]==0)b="Unloaded";else if(t(this,Y)[a[1]||0][a[0]<<7])a[0]==0?(a[2]=0,c="^"):a[2]<1?(a[0]=0,c="*"):(a[2]--,c="^");else if(y==48)a[0]=0,a[2]=0,c="!";else if(y==62)a[1]--,c=" ",a[1]<1&&!(b!=null&&b.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)b=`PrgU:${e.toString().padStart(3,"0")}`,c="!";else if(y==88)b=`CmbU:${e.toString().padStart(3,"0")}`,c="!";else if(y==121)b=`GM2Vox0${r}`,c="#";else if(y==122){if(a[1]==32?a[1]==0:a[1]%=7,b=($=t(this,Y)[a[1]||0][(a[0]<<7)+a[2]])==null?void 0:$.name,b){c=" ";let S=t(this,Y)[a[1]||0][(a[0]<<7)+a[2]];v=(S==null?void 0:S.poly)||v,k=(S==null?void 0:S.type)||k,M=S==null?void 0:S.drum}else b="",c="*";}else a[1]==0?(b=`${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 f=[a[0],a[1],a[2]];switch(c){case"^":{switch(h){case"gs":case"sc":case"ns5r":{c=" ";break}}y==127&&c=="^"&&(c=" ");break}}let l="??";switch(a[0]){case 0:{a[2]==0?l="GM":a[2]==5||a[2]==7?l="KG":a[2]<126?l="XG":a[2]==127&&(l="MT");break}case 32:case 33:case 35:case 36:{a[2]>4?l=["AP","VL","PF","DX","AN"][a[0]-32]:l="GS";break}case 48:{l="MU";break}case 56:{l="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{l="AI";break}case 62:case 82:case 90:{l="XD";break}case 63:{a[2]<17?l="KR":a[2]<34?l="ES":l="DS";break}case 64:case 126:{l="XG";break}case 67:case 99:{l=a[2]>>4==1?"SD":"DX";break}case 81:{l="RW";break}case 95:{l=["DR","PC"][a[2]];break}case 96:{l=a[2]==106?"AP":a[2]>>4==1?"SD":"PF";break}case 97:{l=a[2]>>4==1?"SD":"VL";break}case 98:{l=a[2]>>4==1?"SD":"SG";break}case 100:{l="AN";break}case 104:case 105:case 106:case 107:{l="SD";break}case 120:{l="GS";break}case 121:{l=a[2]?"G2":"GM";break}case 122:{l="KG";break}case 127:{l=a[2]==127?"MT":e==0?"GM":"XG";break}default:a[0]<48&&(a[0]==16&&h=="xg"?l="XG":l="GS")}return c!=" "&&(h=="krs"||self.debugMode)&&(b="",l="KR"),{name:b||`${ht(y||0)} ${ht(e||0)} ${ht(r||0)}`,poly:v,type:k,drum:M,iid:n,eid:f,sid:u,ending:c,sect:d,bank:s,standard:l,mode:h}}async load(y,e,r="(internal)"){let h=this,u=[],b=0,v=0;y.split(` +`).forEach(function(k,M){let a=k.split("\t"),c=[];if(M==0){if(a.forEach(function(d,s){u[Qt.indexOf(d)]=s}),u.length<4){console.debug("Debugger launched.");debugger}}else{let d=0,s=0,i=0,o,n=1,f=0,l;a.forEach(async function($,S){switch(S){case u[0]:{d=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:f=($&15)+1;break}case u[5]:{l=$;break}}}),t(h,Y)[s]=t(h,Y)[s]||[];let m=t(h,Y)[s];if(!m[d<<7|i]||e){let $={msb:d,prg:s,lsb:i,name:o,poly:n,type:f,drum:l};m[d<<7|i]=$,b++}v++}}),e||console.debug(`Map "${r}": ${v} total, ${b} 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 b=u<<7;for(let v=h[0];v<=h[1];v++){let k=b+v;for(let M=e[0];M<=e[1];M++)delete t(this,Y)[M][k]}}}init(){x(this,Y,[]);for(let y=0;y<128;y++)t(this,Y).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".`)}})}},Y=new WeakMap,kt);var Ve,St,xt=(St=class{constructor(){C(this,Ve,{});T(this,"context")}set(y,e){t(this,Ve)[y]=e}has(y){return!!t(this,Ve)[y]}async read(y,e){if(!this.has(y))throw new Error(`No decoder registered for "${y}"`);return await t(this,Ve)[y].call(this.context||this,e)}},Ve=new WeakMap,St);var Yt=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},be=new TextDecoder,Je=new xt;Je.set("s7e",async function(y){let e=new Uint8Array(await y.slice(0,65536).arrayBuffer()),r="MSB\tLSB\tPRG\tNME",h=[0,0,0,0],u=32,b=0,v=0,k=!0,M=[],a=0;for(;k;){let c=e.subarray(b);([()=>{be.decode(c.subarray(0,4))=="YSFC"?(b+=80,v=1):b++},()=>{if(Yt(c.subarray(0,4),h))M.forEach((d,s,i)=>{let o=je(e.subarray(d.start+4,d.start+8));d.length=o}),v=2;else{let d=be.decode(c.subarray(0,4)),s=je(c.subarray(4,8));M.push({type:d,start:s}),b+=8}},()=>{let d=M[a],s=e.subarray(d.start,d.start+d.length),i=32;switch(d.type){case"ENVC":{let o=u;for(;o=M.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\tLSB\tPRG\tNME",h=100,u=0,b=0,v=!0,k=[],M=0;for(;v;){let a=e.subarray(h);([()=>{v=be.decode(a.subarray(0,4))=="INI2",b=a[15],h+=16,u=1},()=>{let c=be.decode(a.subarray(0,4)),d=a[5],s=a[7],i=a[11],o=je(a.subarray(12,16)),n=je(a.subarray(16,20)),f=je(a.subarray(36,40)),l=be.decode(a.subarray(44,44+i));k.push({type:c,tipMsb:d,tipLsb:s,nameLen:i,length:o,start:n,entryLen:f,name:l}),h+=64,b--,b<1&&(u=2)},()=>{let c=k[M],d=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,f=d.subarray(n,n+c.entryLen),l=be.decode(f.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,f=d.subarray(n,n+c.entryLen),l=be.decode(f.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}}M++,M>=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"],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],Fe=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],Ct=[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],Mt=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},Tt=function(y){return y>105?jt[y-106]:y>100?y*1.1-100:y/10},Rt=",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 Pt=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("\u3093")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},Ot=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"],At=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],Lt=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var Zt={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},ea={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 Zt[(y[0]-32<<8)+y[1]]||`0x${y[0].toString(16).padStart(2,"0")}${y[1].toString(16).padStart(2,"0")}`},Ut=function(y,e,r){let h=(y[0]-32<<16)+(y[1]<<8)+e,u=ea[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 Se=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"],ta={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"},aa=["melodic","drum","menu"],Bt={"?":[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 It=[9,25,41,57,73,89,105,121],ra=[0,3,81,84,88],Nt={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Ht={0:0,1:1,2:3,5:4},_t={0:0,1:1,2:2,5:3},Gt=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Xt=[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],Vt={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],sa=[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],ia=[33,99,100,32,102,8,9,10],Ft=[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 ca={};aa.forEach((y,e)=>{ca[y]=e});var na=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 Kt=8,g={port:Kt,ch:Kt<<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,Wt,ie,X,D,p,ce,A,V,Z,F,z,ke,Ee,Oe,ee,R,L,Ke,Y,he,te,ze,Ae,_,Ce,ue,rt,Me,pe,We,Te,H,B,ye,st,I,Le,qe,Qe,Re,De,it,Ye,be,N,lt,ct,Ue,yt,ae,xe,Pe,q,Be,G,nt,dt,Ie,Ne,re,ne,me,He,_e,Ge,zt,Wa=(zt=class extends kt{constructor(){super();S(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);S(this,O,0);S(this,W,0);S(this,fe,0);S(this,we,new Array(11));S(this,ie,new Uint8Array(g.ch));S(this,X,new Uint8Array(g.ch));S(this,D,new Uint8Array(g.ch));S(this,p,new Uint8Array(g.ch*g.cc));S(this,ce,new Uint8Array(g.ace));S(this,A,new Uint8Array(g.ch));S(this,V,new Uint8Array(g.ch*g.nn));S(this,Z,new Uint8Array(g.ch));S(this,F,new Uint16Array(g.pl));S(this,z,new Uint8Array(g.pl));S(this,ke,new Int16Array(g.ch));S(this,Ee,new Uint8Array(g.ch));S(this,Oe,0);S(this,ee,new Uint8Array(g.ch*g.ext));S(this,R,new Uint8Array(g.ch*g.rpn));S(this,L,new Uint8Array(g.ch*g.rpnt));S(this,Ke,new Int8Array(g.ch*Xt.length));S(this,Y,new Uint8Array(g.drm*g.dpn*g.dnc));S(this,he,new Uint8Array(g.drm*2));S(this,te,new Uint8Array(g.efx*3));S(this,ze,new Uint8Array(g.ch));S(this,Ae,new Uint8Array(g.ch*g.redir));S(this,_,new Uint8Array(g.port));S(this,Ce,new Uint8Array(g.ch));S(this,ue,new Uint8Array(g.ch));S(this,rt,new Uint8Array(g.ch*g.cvn));S(this,Me,new Uint8Array(128));S(this,pe,new Uint8Array(g.cmt*8));S(this,We,new Uint8Array(1024));S(this,Te,new Uint8Array(g.cmt*64));S(this,H,{});S(this,B,void 0);S(this,ye,void 0);S(this,st,void 0);S(this,I,100);S(this,Le,0);S(this,qe,500);S(this,Qe,0);S(this,Re,"");S(this,De,0);S(this,it,0);S(this,Ye,0);S(this,be,!0);S(this,N,!1);S(this,lt,1);S(this,ct,void 0);S(this,Ue,new Array(g.ch));S(this,yt,new Uint8Array(2));S(this,ae,[]);S(this,xe,new Uint8Array(g.ch));S(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","");S(this,q,[]);S(this,Be,void 0);S(this,G,{nOff:(e,r)=>{let h=e*128+r,u=t(this,F).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,V)[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,V)[h],state:this.NOTE_SOSTENUTO_HELD});else{t(this,F)[u]=0,t(this,V)[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,G).ano(e);t(this,z)[E]>0&&t(this,F)[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,F)[h],E=u>>7;e==E&&(t(this,z)[h]=this.NOTE_IDLE,t(this,F)[h]=0,t(this,V)[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,F)[h];this.dispatchEvent("note",{part:e,note:E&127,velo:t(this,V)[E],state:u})}})},soOf:e=>{t(this,z).forEach((r,h)=>{if(r==this.NOTE_SOSTENUTO_HELD){let u=t(this,F)[h],E=u>>7;e==E&&(t(this,z)[h]=this.NOTE_IDLE,t(this,F)[h]=0,t(this,V)[u]=0,this.dispatchEvent("note",{part:e,note:u&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,F).forEach((r,h,u)=>{let E=r>>7,v=r&127;r==0&&t(this,V)[0]==0||E==e&&t(this,G).nOff(E,v)})}});S(this,nt,{8:function(e){let r=e.channel,h=e.data[0];t(this,G).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,G).nOn(r,u,E):t(h,G).nOff(r,u)},10:function(e){let r=e.channel,h=r*128+e.data[0];t(this,F).indexOf(h)>-1&&(t(this,V)[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,C=this.getChModeId(r);switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,G).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,G).ano(r);return}case 124:{t(this,G).ano(r);return}case 125:{t(this,G).ano(r);return}case 126:{t(this,Z)[r]=1,t(this,G).ano(r);return}case 127:{t(this,Z)[r]=0,t(this,G).ano(r);return}}if(b[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(sa.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(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 a=t(this,p)[v+b[99]],c=t(this,p)[v+b[98]];if(a==1){let f=ia.indexOf(c);if(f>-1)t(this,p)[v+b[71+f]]=e.data[1],P()&&console.debug(`Redirected NRPN 1 ${c} to cc${71+f}.`),this.dispatchEvent("cc",{part:r,cc:71+f,data:e.data[1]});else{let s=Xt.indexOf(c);s>-1?t(this,Ke)[r*10+s]=e.data[1]-64:console.warn(`NRPN 0x01${c.toString(16).padStart(2,"0")} is not supported.`),P()&&console.debug(`CH${r+1} voice NRPN ${c} commit`)}}else{if(ft.indexOf(a)<0){let s=`NRPN 0x${a.toString(16).padStart(2,"0")}${c.toString(16).padStart(2,"0")} `;a==127?console.warn(`${s}is not necessary. Consider removing it.`):console.warn(`${s}is not supported.`)}else{let s=t(this,D)[r]-2;s<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${et[t(this,D)[r]]}.`):t(this,Y)[(s*g.dpn+de[a])*g.dnc+c]=e.data[1]}P()&&console.debug(`CH${r+1} (${et[t(this,D)[r]]}) drum NRPN ${a} commit`)}}else{let a=Ht[t(this,p)[v+b[100]]],c=_t[t(this,p)[v+b[100]]];if(t(this,p)[v+b[101]]==0&&a!=null)switch(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],Gt[a][0]),Gt[a][1]),t(this,R)[r*g.rpn+a]=e.data[1],t(this,L)[r*g.rpnt+c]=1,C){case w.xg:case w.gs:case w.sc:case w.mt32:case w.s90es:case w.motif:{switch(t(this,p)[v+b[100]]){case 1:case 2:{this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)});break}}break}default: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 a=Ht[t(this,p)[v+100]],c=_t[t(this,p)[v+100]];t(this,p)[v+101]==0&&a!=null&&(t(this,R)[r*g.rpn+a+1]=e.data[1],t(this,L)[r*g.rpnt+c]=1)}break}case 64:{e.data[1]<64&&t(this,G).hoOf(r);break}case 66:{e.data[1]>>6?t(this,G).soOn(r):t(this,G).soOf(r);break}case 98:case 99:{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,F).forEach(function(u){let E=u>>7;h==E&&(t(r,V)[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){na(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=ra.indexOf(e.meta)>-1;if(P()&&console.debug(e),r)return e.reply="meta",e}});S(this,dt,{64:(e,r,h)=>{t(this,He).run(r,h,e)},65:(e,r,h)=>{if(r[0]<16){if(r[1]==72){let u=r[r.length-1],E=Se(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=Se(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,me).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,Ie).run(r,h,e)},127:(e,r,h)=>{this.switchMode("gm"),t(this,Ne).run(r,h,e)}});S(this,Ie,void 0);S(this,Ne,void 0);S(this,re,void 0);S(this,ne,void 0);S(this,me,void 0);S(this,He,void 0);S(this,_e,void 0);S(this,Ge,void 0);let e=this;x(e,se,new Uint8Array(256),Wt),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,ye,{dumpLimit:e.DUMP_MODE}),x(e,st,new Proxy(t(e,ye),{set:()=>{}}));for(let a in Bt){let c=w[a];c==null?console.debug(`SubDB build error: "${a}" does not exist`):t(e,H)[c]=new Uint8Array(Bt[a])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME +`).forEach(y=>{let e=y.split(",");pt[e[0]]=e[1]});var Dt=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("\u3093")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},Pt=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"],Ot=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],At=["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 Jt={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},Zt={66307:["drive"],66309:["vowel",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 Jt[(y[0]-32<<8)+y[1]]||`0x${y[0].toString(16).padStart(2,"0")}${y[1].toString(16).padStart(2,"0")}`},Lt=function(y,e,r){let h=(y[0]-32<<16)+(y[1]<<8)+e,u=Zt[h]||{},b=u[0];if(b!=null&&b.length)return b+=`: ${(u[1]||function(){})(r)||r}`,b},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>b&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 z=["?","gm","gs","sc","xg","g2","mt32","doc","qy10","qy20","ns5r","x5d","05rw","k11","sg","sd","krs","s90es","motif","trin"],ea={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"},ta=["melodic","drum","menu"],Ut={"?":[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:[121,0,120],s90es:[0,0,127],motif:[0,0,127],trin:[0,0,127]},Ht=[9,25,41,57,73,89,105,121],aa=[0,3,81,84,88],Bt={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},It={0:0,1:1,2:3,5:4},Nt={0:0,1:1,2:2,5:3},Gt=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],_t=[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],Xt={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],ra=[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],sa=[33,99,100,32,102,8,9,10],Vt=[0,16,25,40,32,64,26,48],w={};z.forEach((y,e)=>{w[y]=e});var E={length:at.length};at.forEach((y,e)=>{E[y]=e});var de={length:ft.length};ft.forEach((y,e)=>{de[y]=e});var ia={};ta.forEach((y,e)=>{ia[y]=e});var ca=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 Ft=8,g={port:Ft,ch:Ft<<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},Oe={bank0:128},H,W,fe,we,ie,ve,zt,ce,X,D,p,q,O,V,ee,F,K,ke,ge,Ae,te,R,A,Ke,j,he,ae,ze,Le,G,Ce,ue,rt,Me,pe,We,Te,I,U,Ee,st,B,Ue,qe,Qe,Re,De,it,Ye,ye,N,lt,ct,He,re,Se,Pe,Q,Be,_,nt,dt,Ie,Ne,se,ne,me,Ge,_e,Xe,Kt,za=(Kt=class extends wt{constructor(){super();C(this,ie);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,H,0);C(this,W,0);C(this,fe,0);C(this,we,new Array(11));C(this,ce,new Uint8Array(g.ch));C(this,X,new Uint8Array(g.ch));C(this,D,new Uint8Array(g.ch));C(this,p,new Uint8Array(g.ch*g.cc));C(this,q,new Uint8Array(g.ch*g.ace));C(this,O,new Uint8Array(g.ch));C(this,V,new Uint8Array(g.ch*g.nn));C(this,ee,new Uint8Array(g.ch));C(this,F,new Uint16Array(g.pl));C(this,K,new Uint8Array(g.pl));C(this,ke,new Int16Array(g.ch));C(this,ge,new Uint8Array(g.ch));C(this,Ae,new Uint8Array(g.ch));C(this,te,new Uint8Array(g.ch*g.ext));C(this,R,new Uint8Array(g.ch*g.rpn));C(this,A,new Uint8Array(g.ch*g.rpnt));C(this,Ke,new Int8Array(g.ch*_t.length));C(this,j,new Uint8Array(g.drm*g.dpn*g.dnc));C(this,he,new Uint8Array(g.drm*2));C(this,ae,new Uint8Array(g.efx*3));C(this,ze,new Uint8Array(g.ch));C(this,Le,new Uint8Array(g.ch*g.redir));C(this,G,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,I,{});C(this,U,void 0);C(this,Ee,void 0);C(this,st,void 0);C(this,B,100);C(this,Ue,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,ye,!0);C(this,N,!1);C(this,lt,1);C(this,ct,void 0);C(this,He,new Array(g.ch));C(this,re,[]);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-vl","plg-pf","plg-dx","plg-an","plg-dr","plg-sg","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,F).lastIndexOf(h);if(u>-1)if(t(this,p)[g.cc*e+E[64]]>63)t(this,K)[u]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,V)[h],state:this.NOTE_HELD});else if(t(this,p)[g.cc*e+E[66]]>63&&t(this,K)[u]==this.NOTE_SOSTENUTO_SUSTAIN)t(this,K)[u]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,V)[h],state:this.NOTE_SOSTENUTO_HELD});else{t(this,F)[u]=0,t(this,V)[h]=0,t(this,K)[u]=this.NOTE_IDLE;let b=this.getExt(e)[1];(b==this.VLBC_VELOINIT||b==this.VLBC_VELOALL)&&(t(this,p)[g.cc*e+E[129]]=0),this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})}},nOn:(e,r,h)=>{let u=e*128+r,b=0;for(t(this,ee)[e]&&t(this,_).ano(e);t(this,K)[b]>0&&t(this,F)[b]!=u;)b++;if(b{},cAt:(e,r)=>{},hoOf:e=>{t(this,K).forEach((r,h)=>{if(r==this.NOTE_HELD){let u=t(this,F)[h],b=u>>7;e==b&&(t(this,K)[h]=this.NOTE_IDLE,t(this,F)[h]=0,t(this,V)[u]=0,this.dispatchEvent("note",{part:e,note:u&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,K).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,K)[h]=u;let b=t(this,F)[h];this.dispatchEvent("note",{part:e,note:b&127,velo:t(this,V)[b],state:u})}})},soOf:e=>{t(this,K).forEach((r,h)=>{if(r==this.NOTE_SOSTENUTO_HELD){let u=t(this,F)[h],b=u>>7;e==b&&(t(this,K)[h]=this.NOTE_IDLE,t(this,F)[h]=0,t(this,V)[u]=0,this.dispatchEvent("note",{part:e,note:u&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,F).forEach((r,h,u)=>{let b=r>>7,v=r&127;r==0&&t(this,V)[0]==0||b==e&&t(this,_).nOff(b,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,ce)[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],b=e.data[1];b>0?t(h,_).nOn(r,u,b):t(h,_).nOff(r,u)},10:function(e){let r=e.channel,h=r*128+e.data[0];t(this,F).indexOf(h)>-1&&(t(this,V)[h]=data[1],this.getExt(r)[1]==this.VLBC_VELOALL&&(t(this,p)[g.cc*r+E[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,He)[r],b=u[e.data[0]];b&&(e.data[0]=b),[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,H)){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,M=this.getChModeId(r);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+E[1]]=0,t(this,p)[v+E[5]]=0,t(this,p)[v+E[64]]=0,t(this,p)[v+E[65]]=0,t(this,p)[v+E[66]]=0,t(this,p)[v+E[67]]=0,t(this,p)[v+E[11]]=127,t(this,p)[v+E[101]]=127,t(this,p)[v+E[100]]=127,t(this,p)[v+E[99]]=127,t(this,p)[v+E[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,ee)[r]=1,t(this,_).ano(r);return}case 127:{t(this,ee)[r]=0,t(this,_).ano(r);return}}if(E[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(ra.indexOf(e.data[0])>-1&&this.allocateAce(r,e.data[0]),e.data[0]){case 0:{switch(P()&&console.debug(`${z[t(this,H)]}, CH${r+1}: ${e.data[1]}`),t(this,H)==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,U).x5==82?"x5d":"05rw"):e.data[1]==62?this.switchMode(t(this,U).x5==82?"x5d":"05rw"):e.data[1]==63?this.switchMode(z[t(this,U).ds]):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,H)==w.gs||t(this,H)==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,H)==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,H)){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,te)[k]=this.EXT_VL:[35,67,83,99].indexOf(e.data[1])>-1?t(this,te)[k]=this.EXT_DX:t(this,te)[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+E[129]]=e.data[1]);break}case 6:{if(t(this,Ae)[r]){[w.xg,w.gs,w.sc,w.ns5r].indexOf(t(this,H))<0&&console.warn(`NRPN commits are not available under "${z[t(this,H)]}" mode, even when they are supported in Octavia.`);let a=t(this,p)[v+E[99]],c=t(this,p)[v+E[98]];if(a==1){let d=sa.indexOf(c);if(d>-1)t(this,p)[v+E[71+d]]=e.data[1],P()&&console.debug(`Redirected NRPN 1 ${c} to cc${71+d}.`),this.dispatchEvent("cc",{part:r,cc:71+d,data:e.data[1]});else{let s=_t.indexOf(c);s>-1?t(this,Ke)[r*10+s]=e.data[1]-64:console.warn(`NRPN 0x01${c.toString(16).padStart(2,"0")} is not supported.`),P()&&console.debug(`CH${r+1} voice NRPN ${c} commit`)}}else{if(ft.indexOf(a)<0){let s=`NRPN 0x${a.toString(16).padStart(2,"0")}${c.toString(16).padStart(2,"0")} `;a==127?console.warn(`${s}is not necessary. Consider removing it.`):console.warn(`${s}is not supported.`)}else{let s=t(this,D)[r]-2;s<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${et[t(this,D)[r]]}.`):t(this,j)[(s*g.dpn+de[a])*g.dnc+c]=e.data[1]}P()&&console.debug(`CH${r+1} (${et[t(this,D)[r]]}) drum NRPN ${a} commit`)}}else{let a=It[t(this,p)[v+E[100]]],c=Nt[t(this,p)[v+E[100]]];if(t(this,p)[v+E[101]]==0&&a!=null)switch(P()&&console.debug(`CH${r+1} RPN 0 ${t(this,p)[v+E[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Gt[a][0]),Gt[a][1]),t(this,R)[r*g.rpn+a]=e.data[1],t(this,A)[r*g.rpnt+c]=1,M){case w.xg:case w.gs:case w.sc:case w.mt32:case w.s90es:case w.motif:{switch(t(this,p)[v+E[100]]){case 1:case 2:{this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)});break}}break}default:this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})}}break}case 32:{switch(P()&&console.debug(`${z[t(this,H)]}, CH${r+1} LSB: ${e.data[1]}`),t(this,H)){case w.s90es:case w.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,H),!0);break}}this.getExt(r)[0]==this.EXT_DX,this.dispatchEvent("voice",{part:r});break}case 38:{if(!t(this,Ae)[r]){let a=It[t(this,p)[v+100]],c=Nt[t(this,p)[v+100]];t(this,p)[v+101]==0&&a!=null&&(t(this,R)[r*g.rpn+a+1]=e.data[1],t(this,A)[r*g.rpnt+c]=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:{t(this,Ae)[r]=1;break}case 100:case 101:{t(this,Ae)[r]=0;break}}t(this,p)[v+E[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,H)){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,O)[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,F).forEach(function(u){let b=u>>7;h==b&&(t(r,V)[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){ca(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,b){}).call(this,e.data,e.track,e.meta),e.meta!=32&&x(this,Ue,0);let r=aa.indexOf(e.meta)>-1;if(P()&&console.debug(e),r)return e.reply="meta",e}});C(this,dt,{64:(e,r,h)=>{t(this,Ge).run(r,h,e)},65:(e,r,h)=>{if(r[0]<16){if(r[1]==72){let u=r[r.length-1],b=xe(r.subarray(3,r.length-1));u==b?t(this,ne).run(r.subarray(0,r.length-1),h,e):console.warn(`Bad SD checksum ${u} - should be ${b}.`)}else t(this,ne).run(r,h,e);}else{let u=r[r.length-1],b=xe(r.subarray(2,r.length-1));u==b?t(this,ne).run(r.subarray(0,r.length-1),h,e):console.warn(`Bad GS checksum ${u} - should be ${b}.`)}},66:(e,r,h)=>{t(this,me).run(r,h,e)},67:(e,r,h)=>{t(this,se).run(r,h,e)},68:(e,r,h)=>{t(this,Xe).run(r,h,e)},71:(e,r,h)=>{t(this,_e).run(r,h,e)},126:(e,r,h)=>{t(this,Ie).run(r,h,e)},127:(e,r,h)=>{this.switchMode("gm"),t(this,Ne).run(r,h,e)}});C(this,Ie,void 0);C(this,Ne,void 0);C(this,se,void 0);C(this,ne,void 0);C(this,me,void 0);C(this,Ge,void 0);C(this,_e,void 0);C(this,Xe,void 0);let e=this;x(e,ie,new Uint8Array(256),zt),t(e,we)[10]=new Uint8Array(512),x(e,Be,new oe),x(e,U,{x5:82,ds:w.krs,smotif:w.s90es,gs:4,sc:3}),x(e,Ee,{dumpLimit:e.DUMP_MODE}),x(e,st,new Proxy(t(e,Ee),{set:()=>{}}));for(let a in Ut){let c=w[a];c==null?console.debug(`SubDB build error: "${a}" does not exist`):t(e,I)[c]=new Uint8Array(Ut[a])}e.userBank.strictMode=!0,e.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -149,24 +149,24 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),e.addEventListener("metacommit",function(a){var f,s;let{data:c}=a;((f=t(e,ae)[0])==null?void 0:f.type)==c.type&&(s=t(e,ae)[0])!=null&&s.amend?(t(e,ae)[0].amend=c.amend,t(e,ae)[0].data+=c.data):t(e,ae).unshift(c)}),t(e,q)[1]=function(a){var c,f,s,i,o;switch(a=a.replaceAll(`\r +122 006 000 `),e.addEventListener("metacommit",function(a){var d,s;let{data:c}=a;((d=t(e,re)[0])==null?void 0:d.type)==c.type&&(s=t(e,re)[0])!=null&&s.amend?(t(e,re)[0].amend=c.amend,t(e,re)[0].data+=c.data):t(e,re).unshift(c)}),t(e,Q)[1]=function(a){var c,d,s,i,o;switch(a=a.replaceAll(`\r `,` `).replaceAll("\r",` -`),a.slice(0,2)){case"@I":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(c=a.slice(2))==null?void 0:c.trimLeft()});break}case"@K":{x(this,N,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(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,Ie,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,me,new oe("Korg")),x(e,He,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,Ie).default=h,t(e,Ne).default=h,t(e,re).default=h,t(e,ne).default=h,t(e,me).default=h,t(e,He).default=h,t(e,_e).default=h,t(e,Ge).default=h,r.default=h,t(e,Ie).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,I,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,I))}).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,$e)=>{$|=U<<$e*7}),a.subarray(l).forEach((U,$e)=>{M|=U<<$e*7}),P()&&console.debug(`GM2 global parameter: (${a.subarray(3,d)}; p: ${$}, v: ${M})`),m){case 129:{$==0&&(e.setEffectType(0,52,M),e.dispatchEvent("efxreverb",e.getEffectType(0)));break}case 130:{$==0&&(e.setEffectType(1,52,M|16),e.dispatchEvent("efxchorus",e.getEffectType(1)));break}default:P()&&console.debug("GM2 global paramater slot path unknown.")}}),t(this,re).add([76,0,0],(a,c,f)=>{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,I,l*129/16383*100),e.dispatchEvent("mastervolume",t(e,I))},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: ${Tt(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: ${Mt[n]}Hz`)},n=>{},n=>{console.debug(`${s}feedback: ${n}`)},n=>{console.debug(`${s}delay offset: ${Rt(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,X)[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: ${Ot(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,H)[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+=Dt[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:`${Pt(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=Se(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=Se(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)}}).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,G).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,I,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,I))},()=>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,X)[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,H)[w.sc][1]=t(e,B).sc,x(e,N,!1),t(e,xe).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,H)[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,xe).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,I,l*129/16383*100),e.dispatchEvent("mastervolume",t(e,I))},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: ${At[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: ${Lt[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=Ut(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,$e=(U*4+M)*5,mt=5,ot=0;for($e-=U*4,M==3&&(mt=1);ot>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,X)[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}`))},C=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)=>{C(a,e.chRedir(9,c,!0))}).add([66,18,64,65],(a,c)=>{C(a,e.chRedir(0,c,!0))}).add([66,18,64,66],(a,c)=>{C(a,e.chRedir(1,c,!0))}).add([66,18,64,67],(a,c)=>{C(a,e.chRedir(2,c,!0))}).add([66,18,64,68],(a,c)=>{C(a,e.chRedir(3,c,!0))}).add([66,18,64,69],(a,c)=>{C(a,e.chRedir(4,c,!0))}).add([66,18,64,70],(a,c)=>{C(a,e.chRedir(5,c,!0))}).add([66,18,64,71],(a,c)=>{C(a,e.chRedir(6,c,!0))}).add([66,18,64,72],(a,c)=>{C(a,e.chRedir(7,c,!0))}).add([66,18,64,73],(a,c)=>{C(a,e.chRedir(8,c,!0))}).add([66,18,64,74],(a,c)=>{C(a,e.chRedir(10,c,!0))}).add([66,18,64,75],(a,c)=>{C(a,e.chRedir(11,c,!0))}).add([66,18,64,76],(a,c)=>{C(a,e.chRedir(12,c,!0))}).add([66,18,64,77],(a,c)=>{C(a,e.chRedir(13,c,!0))}).add([66,18,64,78],(a,c)=>{C(a,e.chRedir(14,c,!0))}).add([66,18,64,79],(a,c)=>{C(a,e.chRedir(15,c,!0))}),t(this,me).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=Se(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]=Ft[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\tPRG\tLSB\tNME";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\tPRG\tLSB\tNME";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,_)[s]&&t(e,_)[s]!=w[f])if(t(e,ye).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+s)} mode "${K[t(e,_)[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]=Ft[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,X)[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 $e=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,X)[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,I,n),e.dispatchEvent("mastervolume",t(e,I))}][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,G).ano(f+s),s&&s<10&&(t(e,A)[f+s]=Et[s-1]);console.info("MT-32 alt reset complete.")}),t(this,me).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,I,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,I))},()=>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,X)[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,$e=m0;)t(e,se,ve)[$*32+m*7+($e-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=Se(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,_)[n]&&t(e,_)[n]!=w.ns5r)if(t(e,ye).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+n)} mode "${K[t(e,_)[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,X)[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\tPRG\tLSB\tNME";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\tPRG\tLSB\tNME";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=Se(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,me).run([66,...a],c,f)}),t(this,He).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,H)[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,X)[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,X)[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,I,s*129/16383*100),e.dispatchEvent("mastervolume",t(e,I));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,X)[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,I,o*12900/16383),e.dispatchEvent("mastervolume",t(e,I))}][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,_)[s]&&t(e,_)[s]!=t(e,B).smotif)if(t(e,ye).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+s)} mode "${K[t(e,_)[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,X)[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: +`),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:(d=a.slice(2))==null?void 0:d.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((f,l)=>{f.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][l],data:f})});break}case"ln":{n.slice(1).forEach((f,l)=>{f.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][l],data:f})});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,f)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:n,mask:f!=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,Ue)<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,Ue,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){P()&&console.debug(`XGworks requests assigning track ${c} to output ${a[0]}.`),t(e,Pe)[c]=a[0]+1}),x(e,Ie,new oe("universal non-realtime")),x(e,Ne,new oe("universal realtime")),x(e,se,new oe("Yamaha")),x(e,ne,new oe("Roland")),x(e,me,new oe("Korg")),x(e,Ge,new oe("Kawai")),x(e,_e,new oe("Akai")),x(e,Xe,new oe("Casio"));let r=new oe("DX7+ Dump"),h=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,a)};t(e,Ie).default=h,t(e,Ne).default=h,t(e,se).default=h,t(e,ne).default=h,t(e,me).default=h,t(e,Ge).default=h,t(e,_e).default=h,t(e,Xe).default=h,r.default=h,t(e,Ie).add([9],(a,c,d)=>{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,d)=>{e.dispatchEvent("mupromptex"),x(e,B,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,B))}).add([4,3],(a,c,d)=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],(a,c,d)=>a[1]-64).add([4,5],(a,c,d)=>{e.dispatchEvent("mupromptex");let s=a[0],i=a[1],o=a[2],n=3,f=n+(s<<1),l=f+i;if(s!=1){console.error(`Unsupported GM2 global parameter set: slotpath length too long (${s})! +`,a);return}let m=0,$=0,S=0;switch(a.subarray(n,f).forEach(L=>{m=m<<7,m|=L}),a.subarray(f,l).forEach((L,$e)=>{$|=L<<$e*7}),a.subarray(l).forEach((L,$e)=>{S|=L<<$e*7}),P()&&console.debug(`GM2 global parameter: (${a.subarray(3,f)}; p: ${$}, v: ${S})`),m){case 129:{$==0&&(e.setEffectType(0,52,S),e.dispatchEvent("efxreverb",e.getEffectType(0)));break}case 130:{$==0&&(e.setEffectType(1,52,S|16),e.dispatchEvent("efxchorus",e.getEffectType(1)));break}default:P()&&console.debug("GM2 global paramater slot path unknown.")}}),t(this,se).add([76,0,0],(a,c,d)=>{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 f=n+a[0];([i,i,i,i,l=>{x(this,B,l*129/16383*100),e.dispatchEvent("mastervolume",t(e,B))},l=>{},l=>{}][f]||(()=>{}))(o,n)}),a[0]<4){let o=0;s.forEach(n=>{o=o<<4,o+=n}),o-=1024}}}}).add([76,2,1],(a,c,d)=>{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: ${Mt(n)}s`)},n=>{console.debug(`${s}diffusion: ${n}`)},n=>{console.debug(`${s}initial delay: ${n}`)},n=>{console.debug(`${s}HPF cutoff: ${Fe[n]}Hz`)},n=>{console.debug(`${s}LPF cutoff: ${Fe[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: ${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: ${Ct[n]}Hz`)},n=>{},n=>{console.debug(`${s}feedback: ${n}`)},n=>{console.debug(`${s}delay offset: ${Tt(n)}ms`)},n=>{},n=>{console.debug(`${s}low: ${Fe[n]}Hz`)},n=>{console.debug(`${s}low: ${n-64}dB`)},n=>{console.debug(`${s}high: ${Fe[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: ${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: ${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,d)=>{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,f=o-1&3,l=`XG EQ ${n} ${["gain","freq","Q","shape"][f]}: `;[()=>{console.debug(`${l}${s-64}dB`)},()=>{console.debug(`${l}${s} (raw)`)},()=>{console.debug(`${l}${s/10}`)},()=>{console.debug(`${l}${["shelf","peak"][+!!s]}`)}][f]()}})}).add([76,3],(a,c,d)=>{e.dispatchEvent("mupromptex");let s=a[0],i=a[1],o=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((n,f)=>{([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+f]||function(){})(n)})}).add([76,6,0],(a,c,d)=>{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,d)=>{let s=a[0];x(e,W,0),x(e,fe,Date.now()+3200),t(e,ie,ve).fill(0);let i=a.subarray(1);for(let o=0;o>6-S&1,S++})}).add([76,8],(a,c)=>{e.dispatchEvent("mupromptex");let d=e.chRedir(a[0],c,!0),s=a[1],i=g.cc*d,o=`XG CH${d+1} `,n=`Unknown XG part address ${s}.`,f=!0;a.subarray(2).forEach((l,m)=>{f=!0,s<1?console.debug(n):s<41?([()=>{t(e,p)[i+E[0]]=l,e.dispatchEvent("voice",{part:d})},()=>{t(e,p)[i+E[32]]=l,e.dispatchEvent("voice",{part:d})},()=>{t(e,O)[d]=l,e.dispatchEvent("voice",{part:d})},()=>{f=!1;let $=e.chRedir(l,c,!0);t(e,X)[d]=$,d!=$&&(e.buildRchTree(),console.info(`${o}receives from CH${$+1}`)),t(e,ce)[d]||(e.copyChSetup($,d,!0),console.debug(`${o}copied from CH${$+1}.`),e.setChActive(d,1),e.dispatchEvent("voice",{part:d}))},()=>{t(e,ee)[d]=+!l},()=>{},()=>{f=!1,e.setChType(d,l,w.xg),console.debug(`${o}type: ${et[l]||l}`),e.dispatchEvent("voice",{part:d})},()=>{t(e,R)[g.rpn*d+3]=l,t(e,A)[g.rpnt*d+2]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)})},!1,!1,()=>{t(e,p)[i+E[7]]=l},!1,!1,()=>{t(e,p)[i+E[10]]=l||128},!1,!1,()=>{t(e,p)[i+E[128]]=l,e.allocateAce(d,128)},()=>{t(e,p)[i+E[93]]=l},()=>{t(e,p)[i+E[91]]=l},()=>{t(e,p)[i+E[94]]=l},()=>{t(e,p)[i+E[76]]=l},()=>{t(e,p)[i+E[77]]=l},()=>{t(e,p)[i+E[78]]=l},()=>{t(e,p)[i+E[74]]=l},()=>{t(e,p)[i+E[71]]=l},()=>{t(e,p)[i+E[73]]=l},()=>{t(e,p)[i+E[75]]=l},()=>{t(e,p)[i+E[72]]=l}][s+m-1]||(()=>{}))():s<48?console.debug(n):s<111?s>102&&s<105&&(t(e,p)[i+E[[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)}),f&&t(e,D)[d]>1&&e.setDrumFirstWrite(d)}).add([76,9],(a,c)=>{let d=e.chRedir(a[0],c,!0),s=a[1],i=g.cc*d,o=`PLG-VL CH${d+1} `;a.subarray(2).forEach((n,f)=>{let l=f+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: ${Pt(n)}`),n&&n<96&&e.allocateAce(d,130+m),t(e,Le)[g.redir*d+m+2]=n,e.buildRccMap()):console.debug(`${o}${$} scale break point: ${n}`):(console.debug(`${o}${$} depth: ${n-64}`),t(e,p)[i+E[130+m]]=n)}}})}).add([76,10],(a,c,d)=>{}).add([76,16],(a,c,d)=>{}).add([76,17,0,0],(a,c,d)=>{}).add([76,112],(a,c,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:{t(e,te)[g.ext*a[2]]=e.EXT_VL;break}case 2:{t(e,te)[g.ext*a[2]]=e.EXT_DX;break}default:t(e,te)[g.ext*a[2]]=e.EXT_NONE}}).add([73,0,0],(a,c)=>{let d=a[0],s="MU1000 System - ";a.subarray(1).forEach((i,o)=>{let n=d+o;n==8?console.debug(`${s}LCD contrast: ${i}.`):n==18?(t(e,I)[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,ye,!!i),console.info(`Octavia System: RS receiving ${["dis","en"][i]}abled.`)}][n-64]()})}).add([73,10,0],(a,c)=>{let d=a[0],s=`MU1000 RS${t(e,ye)?"":" (ignored)"}: `;if(d<16)switch(d){case 2:{let i=e.chRedir(0,c,!0);t(e,ye)&&(e.dispatchEvent("portrange",4),e.dispatchEvent("portstart",i)),console.info(`${s}Show CH${i+1}~CH${i+64}`);break}case 3:{let i=e.chRedir(a[1]<<5,c,!0);t(e,ye)&&(e.dispatchEvent("portrange",2),e.dispatchEvent("portstart",i)),console.info(`${s}Show CH${i+1}~CH${i+32}`);break}default:console.debug(`${s}unknown switch ${d} invoked.`)}else if(d<32){if(t(e,ye)){let i=e.chRedir(d-16+(t(e,Ye)<<4),c,!0);e.dispatchEvent("channelactive",i)}}else if(d<36){let i=e.chRedir(d-32<<4,c,!0);t(e,ye)&&(e.dispatchEvent("portrange",1),e.dispatchEvent("portstart",i>>4),x(e,Ye,d-32)),console.info(`${s}Show CH${i+1}~CH${i+16}`)}}).add([73,11,0],(a,c)=>{let d="MU1000 System - channel ",s="Octavia System - channel ",i=a[0];a.subarray(1).forEach((o,n)=>{let f=i+n;([()=>{e.setChActive(o,1),e.dispatchEvent("channelactive",o),P()&&console.debug(`${d}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`))}][f]||(()=>{console.debug(`${d}unknown address: ${f}`)}))()})}).add([93,3],(a,c)=>{let d=e.chRedir(a[0],c,!0),s=`PLG-SG CH${d+1} `,i=Date.now();if(a[1]==0){let o="",n=0;a.subarray(2).forEach((f,l)=>{l%2==0?o+=Rt[f]||f.toString().padStart("0"):n+=f*13}),i>=t(e,Qe)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${Dt(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-SG data: ${a}`)}).add([98,0],(a,c,d)=>{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,se).run(a.subarray(0,o),c,d,{noAce:!0})}).add([98,96],(a,c,d,s)=>{let i=e.chRedir(a[0],c,!0),o=g.cc*i,n=a[1];a.subarray(2).forEach((f,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(i,$),t(e,p)[o+E[$]]=f,e.dispatchEvent("cc",{part:i,cc:$,data:f})}}})}).add([100,0],(a,c,d)=>{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,d)=>{let s=a[0]>>4,i=a[0]&15,o=a[1];switch(s){case 2:{let n=e.chRedir(i,c,!0),f=g.cc*n;a.subarray(2).forEach((l,m)=>{let $=m+o;if(!($<7)){if($<23){let S=$+135;e.allocateAce(n,S),t(e,p)[f+E[S]]=l,e.dispatchEvent("cc",{part:n,cc:S,data:l})}}});break}default:console.info("Unknown DX7+ multipart: %o",a)}}).add([1,20],(a,c,d)=>{d==115?(e.switchMode("doc",!0),e.setPortMode(e.getTrackPort(c),1,w.doc),console.info("MIDI reset: DOC")):console.debug(`Unknown Yamaha SysEx: 67, ${d}, ${a.join(", ")}`)}).add([1,17,15,89],(a,c,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,c,d)=>{if(d==115){for(let s=0;s<16;s++){let i=e.chRedir(s,c,!0);t(e,p)[i*g.cc+E[91]]=127}console.info("DOC Global Reverb: on")}else console.debug(`Unknown Yamaha SysEx: 67, ${d}, ${a.join(", ")}`)}),r.add([14,31],(a,c,d)=>{t(e,p)[g.cc*a[0]+E[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],d=g.cc*c,s=g.ext*c,i=g.cvn*c;t(e,te)[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,f)=>{if(f<10)o[f]=Math.max(n,32);else if(!(f<40)){if(f<56){let l=f+102;t(e,p)[d+E[l]]=n,e.dispatchEvent("cc",{part:c,cc:l,data:n})}}}),t(e,O)[c]=c&127,t(e,p)[g.cc*c+E[0]]=35,t(e,p)[g.cc*c+E[32]]=c>>7|4,e.dispatchEvent("voice",{part:c}),console.debug(`DX7+ CH${c+1} dump: %o`,a)});let u=function(a,c,d,s){},b=function(a,c){e.dispatchEvent("mupromptex");let d=a*g.dpn,s=c[0],i=c[1];c.subarray(2).forEach((o,n)=>{let f=n+i,l=-1;f<16?([()=>{l=24},()=>{l=25},()=>{l=26},()=>{},()=>{l=28},()=>{l=29},()=>{l=30},()=>{l=31},()=>{},()=>{},()=>{},()=>{l=20},()=>{l=21},()=>{l=22},()=>{l=23},()=>{}][f]||(()=>{console.debug(`Unknown XG-style drum param ${f} on set ${a+1}.`)}))():f<32||(f<40?([()=>{l=48},()=>{l=49},!1,!1,()=>{l=52},()=>{l=53}][f-32]||(()=>{console.debug(`Unknown XG-style drum param ${f} on set ${a+1}.`)}))():f<80||([()=>{l=36}][f-80]||(()=>{console.debug(`Unknown XG-style drum param ${f} on set ${a+1}.`)}))()),l>=0?(P()&&console.debug(d,l,s,o),t(e,j)[(d+de[l])*g.dnc+s]=o):P()&&console.debug(`XG-style drum param ${f} has no writes.`)})},v=function(a,c,d){e.dispatchEvent("mupromptex");let s=a*g.dpn,i=(c<<7)+d[0];d.subarray(1).forEach((o,n)=>{let f=n+i,l=f&127,m=f>>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,j)[(s+de[$])*g.dnc+l]=o):P()&&console.debug(`GS-style drum param ${m} has no writes.`)})};t(this,se).add([76,48],(a,c,d)=>{b(0,a)}).add([76,49],(a,c,d)=>{b(1,a)}).add([76,50],(a,c,d)=>{b(2,a)}).add([76,51],(a,c,d)=>{b(3,a)}).add([76,52],(a,c,d)=>{b(4,a)}).add([76,53],(a,c,d)=>{b(5,a)}).add([76,54],(a,c,d)=>{b(6,a)}).add([76,55],(a,c,d)=>{b(7,a)}),t(this,se).add([89,0],(a,c,d)=>{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,f)=>{let l=f>>3,m=f&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,d)=>{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,d)=>{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 f=n>>3,l=n&7;if(l==7)for(let m=0;m<7;m++)i[s+7*f+m]+=(o>>6-m&1)<<7;else i[s+7*f+l]=o})}}).add([89,3],(a,c,d)=>{}),t(this,se).add([39,48],(a,c,d)=>{}).add([43,0,0],(a,c,d)=>{e.dispatchEvent("mupromptex");let s=[0,0,0,0],i=(o,n)=>{s[n]=o};if(a.subarray(1).forEach((o,n)=>{let f=n+a[0];[i,i,i,i,()=>{x(this,B,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,B))},()=>o-64,()=>o||128,()=>o,()=>o,()=>{console.debug(`TG300 variation on cc${o}.`)}][f](o,f)}),a[0]<4){let o=0;s.forEach(n=>{o=o<<4,o+=n}),o-=1024}}).add([43,1,0],(a,c,d)=>{e.dispatchEvent("mupromptex")}).add([43,2],(a,c,d)=>{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((f,l)=>{l<5?([()=>{},()=>{t(e,p)[o+E[0]]=f,e.dispatchEvent("voice",{part:s})},()=>{t(e,p)[o+E[32]]=f,e.dispatchEvent("voice",{part:s})},()=>{t(e,O)[s]=f,e.dispatchEvent("voice",{part:s})},()=>{let m=e.chRedir(f,c,!0);t(e,X)[s]=m,s!=m&&(e.buildRchTree(),console.info(`${n}receives from CH${m+1}`))}][l+i]||(()=>{}))(f,l+i):l<21||(l<47?([()=>{t(e,ee)[s]=+!f},()=>{},()=>{},()=>{t(e,R)[g.rpn*s+3]=f,t(e,A)[g.rpnt*s+2]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{},()=>{t(e,p)[o+E[7]]=f},!1,!1,()=>{t(e,p)[o+E[10]]=f||128},!1,!1,()=>{console.debug(`${n} AC1 at cc${f}`)},()=>{console.debug(`${n} AC2 at cc${f}`)},()=>{t(e,p)[o+E[128]]=f,e.allocateAce(s,128)},()=>{t(e,p)[o+E[93]]=f},()=>{t(e,p)[o+E[91]]=f},()=>{t(e,p)[o+E[94]]=f},()=>{t(e,p)[o+E[76]]=f},()=>{t(e,p)[o+E[77]]=f},()=>{t(e,p)[o+E[74]]=f},()=>{t(e,p)[o+E[71]]=f},()=>{t(e,p)[o+E[73]]=f},()=>{t(e,p)[o+E[75]]=f},()=>{t(e,p)[o+E[72]]=f},()=>{t(e,p)[o+E[78]]=f}][l+i-21]||(()=>{}))(f,l+i):l<95||([()=>{t(e,p)[o+E[65]]=f},()=>{t(e,p)[o+E[5]]=f}][l+i-95]||(()=>{}))(f,l+i))})}).add([43,7,0],(a,c,d)=>{let s=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",s)}).add([43,7,1],(a,c,d)=>{x(e,W,0),x(e,fe,Date.now()+3200),t(e,ie,ve).fill(0),a.forEach(function(s,i){let o=Math.floor(i/16),n=i%16,f=(n*3+o)*7,l=7,m=0;for(f-=n*5,o==2&&(l=2);m>6-m&1,m++})}),t(this,ne).add([66,18,0,0,127],(a,c,d)=>{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,I)[w.sc][1]=t(e,U).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,d)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),e.setPortMode(e.getTrackPort(c),2,w.gs),t(e,I)[w.gs][1]=t(e,U).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 f=n+a[0];[i,i,i,i,l=>{x(this,B,l*129/16383*100),e.dispatchEvent("mastervolume",t(e,B))},l=>{},l=>{}][f](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,d)=>{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: ${Ot[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: ${At[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,d)=>{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,d)=>{e.dispatchEvent("mupromptex");let s="GS EFX ",i=function(o,n){let f=Lt(t(e,ae).subarray(10,12),n,o);f&&console.debug(`${s}${gt(t(e,ae).subarray(10,12))} ${f}`)};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,ae).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.allocateAceAll(o)},()=>{console.debug(`${s}1 depth: ${o-64}`)},()=>{console.debug(`${s}2 source: ${o}`),o&&o<96&&e.allocateAceAll(o)},()=>{console.debug(`${s}2 depth: ${o-64}`)},()=>{console.debug(`${s}to EQ: ${o?"ON":"OFF"}`)}][a[0]+n]||function(f,l){console.warn(`Unknown GS EFX address: ${l}`)})(o,a[0]+n)})}).add([66,18,65],(a,c,d)=>{v((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],(a,c,d)=>{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,S=Math.floor($/16),L=$%16,$e=(L*4+S)*5,yt=5,ot=0;for($e-=L*4,S==3&&(yt=1);ot>4-ot&1,ot++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let k=function(a,c,d){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((f,l)=>{[()=>{t(e,p)[i+E[0]]=f},()=>{t(e,O)[c]=f},()=>{let m=0;f<16?m=e.chRedir(f,d,!0):m=g.ch,t(e,X)[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((f,l)=>{([()=>{t(e,ee)[c]=+!f},!1,()=>{e.setChType(c,f<<1,w.gs),console.debug(`${n}type: ${f?"drum ":"melodic"}${f||""}`)},()=>{t(e,R)[o+3]=f,t(e,A)[g.rpnt*c+2]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},!1,()=>{t(e,p)[i+E[7]]=f},!1,!1,()=>{t(e,p)[i+E[10]]=f||128},!1,!1,()=>{console.debug(`${n}CC 1: cc${f}`)},()=>{console.debug(`${n}CC 2: cc${f}`)},()=>{t(e,p)[i+E[93]]=f},()=>{t(e,p)[i+E[91]]=f},!1,!1,()=>{t(e,R)[o+1]=f,t(e,A)[g.rpnt*c+1]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},()=>{t(e,R)[o+2]=f,t(e,A)[g.rpnt*c+1]=1,e.dispatchEvent("pitch",{part:c,pitch:e.getPitchShift(c)})},()=>{t(e,p)[i+E[94]]=f}][s+l-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},M=function(a,c){let d=a[0],s=`GS CH${c+1} `;d<2?a.subarray(1).forEach((i,o)=>{[()=>{t(e,p)[g.cc*c+E[32]]=i},()=>{}][d+o]()}):d<32?console.warn(`Unknown GS misc address: ${d}`):d<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})}][d+o-32]()}):console.warn(`Unknown GS misc address: ${d}`)};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)=>{M(a,e.chRedir(9,c,!0))}).add([66,18,64,65],(a,c)=>{M(a,e.chRedir(0,c,!0))}).add([66,18,64,66],(a,c)=>{M(a,e.chRedir(1,c,!0))}).add([66,18,64,67],(a,c)=>{M(a,e.chRedir(2,c,!0))}).add([66,18,64,68],(a,c)=>{M(a,e.chRedir(3,c,!0))}).add([66,18,64,69],(a,c)=>{M(a,e.chRedir(4,c,!0))}).add([66,18,64,70],(a,c)=>{M(a,e.chRedir(5,c,!0))}).add([66,18,64,71],(a,c)=>{M(a,e.chRedir(6,c,!0))}).add([66,18,64,72],(a,c)=>{M(a,e.chRedir(7,c,!0))}).add([66,18,64,73],(a,c)=>{M(a,e.chRedir(8,c,!0))}).add([66,18,64,74],(a,c)=>{M(a,e.chRedir(10,c,!0))}).add([66,18,64,75],(a,c)=>{M(a,e.chRedir(11,c,!0))}).add([66,18,64,76],(a,c)=>{M(a,e.chRedir(12,c,!0))}).add([66,18,64,77],(a,c)=>{M(a,e.chRedir(13,c,!0))}).add([66,18,64,78],(a,c)=>{M(a,e.chRedir(14,c,!0))}).add([66,18,64,79],(a,c)=>{M(a,e.chRedir(15,c,!0))}),t(this,me).add([54,65],(a,c)=>{let d=t(e,U).x5=="81"?"05rw":"x5d";e.switchMode(d,!0),e.setPortMode(e.getTrackPort(c),1,w[d]);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],f=(a[3]<<7)+a[2],l=e.chRedir(n&15,c,!0),m=g.cc*l;[()=>{f<1||(f<101?(e.setChType(l,e.CH_MELODIC,w.x5d),t(e,O)[l]=f-1,t(e,p)[m+E[0]]=t(e,U).x5):f<229?(e.setChType(l,e.CH_MELODIC,w.x5d),t(e,O)[l]=f-101,t(e,p)[m+E[0]]=56):(e.setChType(l,e.CH_DRUMS,w.x5d),t(e,O)[l]=Vt[f-229]||0,t(e,p)[m+E[0]]=62)),e.dispatchEvent("voice",{part:l})},()=>{t(e,p)[m+E[7]]=f},()=>{f<31&&(t(e,p)[m+E[10]]=Math.round((f-15)*4.2+64))},()=>{t(e,p)[m+E[93]]=tt(f)},()=>{t(e,p)[m+E[91]]=tt(f)},()=>{t(e,R)[l*g.rpn+3]=f>8191?f-16320:64+f,t(e,A)[g.rpnt*l+2]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)})},()=>{t(e,R)[l*g.rpn+1]=f>8191?f-16320:64+f,t(e,A)[g.rpnt*l+1]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)})},()=>{f>0&&(t(e,R)[l*g.rpn]=f,t(e,A)[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 d=t(e,U).x5=="81"?"05rw":"x5d";e.switchMode(d),e.setPortMode(e.getTrackPort(c),1,w[d]);let s="",i=t(e,U).x5,o=0,n=0,f="MSB\tPRG\tLSB\tNME";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:{f+=` +${i} ${o} ${n} ${s.trim().replace("Init Voice","")}`,o++,s="";break}}o>99&&(i=90,o=0)}}),e.userBank.clearRange({msb:t(e,U).x5,prg:[0,99],lsb:0}),e.userBank.load(f),P()&&console.debug(f),e.forceVoiceRefresh()}).add([54,77,0],(a,c)=>{e.dispatchEvent("mupromptex");let d=t(e,U).x5=="81"?"05rw":"x5d";e.switchMode(d),e.setPortMode(e.getTrackPort(c),1,w[d]);let s="",i=90,o=0,n=0,f="MSB\tPRG\tLSB\tNME";le(a,function(l,m){if(m<13600){let $=m%136;switch(!0){case $<10:{l>31&&(s+=String.fromCharCode(l));break}case $==11:{f+=` +${i} ${o} ${n} ${s.trim().replace("Init Combi","")}`,o++,s="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f),P()&&console.debug(f),e.forceVoiceRefresh()}).add([54,78],(a,c)=>{let d=t(e,U).x5=="81"?"05rw":"x5d";e.switchMode(d),e.setPortMode(e.getTrackPort(c),1,w[d]),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 d=t(e,U).x5=="81"?"05rw":"x5d";e.switchMode(d),e.setPortMode(e.getTrackPort(c),1,w[d]),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 d=t(e,U).x5=="81"?"05rw":"x5d";e.switchMode(d,!0);let s=e.getTrackPort(c);if(t(e,G)[s]&&t(e,G)[s]!=w[d])if(t(e,Ee).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+s)} mode "${z[t(e,G)[s]]}" mismatch, should be "${d}".`);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[d]),le(a,function(i,o,n,f){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+E[0]]=t(e,U).x5,t(e,O)[l]=i):(e.setChType(l,e.CH_DRUMS,w.x5d),t(e,p)[m+E[0]]=62,t(e,O)[l]=Vt[i-128]),i>0&&e.setChActive(l,1),e.dispatchEvent("voice",{part:l});break}case 1:{t(e,p)[m+E[7]]=i;break}case 2:{t(e,R)[l*g.rpn+3]=i>127?i-192:64+i,t(e,A)[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,A)[g.rpnt*l+1]=1,e.dispatchEvent("pitch",{part:l,pitch:e.getPitchShift(l)});break}case 4:{i<31&&(t(e,p)[m+E[10]]=Math.round((i-15)*4.2+64));break}case 5:{let $=i>>4,S=i&15;t(e,p)[m+E[91]]=tt(S),t(e,p)[m+E[93]]=tt($);break}case 10:break;case 11:{let $=e.chRedir(i&15,c,!0),S=i>>4;t(e,X)[l]=i,($!=l||S)&&(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,d)=>{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,d)=>{e.switchMode("mt32");let s=e.chRedir(d,c,!0),i=a[1];a.subarray(2).forEach((o,n)=>{let f=n+i;t(e,Me)[f+(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,A)[g.rpnt*s+2]=1},()=>{t(e,R)[s*g.rpn+1]=o+14,t(e,A)[g.rpnt*s+1]=1},()=>{t(e,R)[s*g.rpn]=o,t(e,A)[g.rpnt*s]=1},!1,()=>{t(e,p)[g.cc*s+E[91]]=o?127:0},!1,()=>{t(e,p)[g.cc*s+E[7]]=o},()=>{t(e,p)[g.cc*s+E[10]]=Math.ceil(o*9.05)}][f]||(()=>{}))()})}).add([22,18,1],(a,c,d)=>{e.switchMode("mt32");let s=d&7;console.debug(`MT-32 slot #${d+1} Drum: ${a}`);let i=a[0]<<7|a[1];a.subarray(2).forEach((o,n)=>{let f=n+i,l=(f>>2)+24,m=f&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,j)[($+de[26])*g.dnc+l]=Math.round(o*1.27)},()=>{t(e,j)[($+de[26])*g.dnc+l]=o*9+1&127},()=>{t(e,j)[($+de[26])*g.dnc+l]=o?127:0}][m]()})}).add([22,18,2],(a,c,d)=>{e.switchMode("mt32");let s=e.chRedir(d,c,!0),i=a[1]+(a[0]<<7);i<10&&(t(e,ue)[s]=1),a.subarray(2).forEach((o,n)=>{let f=n+i;f<14&&(t(e,pe)[(s-1)*g.cmt+f]=o)}),e.dispatchEvent("voice",{part:s})}).add([22,18,3],(a,c,d)=>{e.switchMode("mt32");let s=d&7;if(a[0]){let i=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((o,n)=>{let f=n+i,l=(f>>2)+24,m=f&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,j)[($+de[26])*g.dnc+l]=Math.round(o*1.27)},()=>{t(e,j)[($+de[26])*g.dnc+l]=o*9+1&127},()=>{t(e,j)[($+de[26])*g.dnc+l]=o?127:0}][m]()})}else{let i=a[1];a.subarray(2).forEach((o,n)=>{let f=n+i;t(e,Me)[f]=o;let l=e.chRedir(1+(f>>4),c,!0),m=f&15;([!1,()=>{let $=t(e,Me)[l-1<<4];if($<3)if(t(e,ue)[l]=1,$==2)for(let S=0;S{t(e,R)[l*g.rpn+3]=o+40,t(e,A)[g.rpnt*l+2]=1},()=>{t(e,R)[l*g.rpn+1]=o+14,t(e,A)[g.rpnt*l+1]=1},()=>{t(e,R)[l*g.rpn]=o,t(e,A)[g.rpnt*l]=1},!1,()=>{t(e,p)[g.cc*l+E[91]]=o?127:0},!1,()=>{t(e,p)[g.cc*l+E[7]]=o},()=>{t(e,p)[g.cc*l+E[10]]=Math.ceil(o*9.05)}][m]||(()=>{}))()})}}).add([22,18,4],(a,c,d)=>{e.switchMode("mt32");let s=a[1]+(a[0]<<7),i=[];a.subarray(2).forEach((o,n)=>{let f=n+s,l=e.chRedir(Math.floor(f/246+1),c,!0),m=f%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,d)=>{e.switchMode("mt32");let s=(a[0]<<7)+a[1];a.subarray(2).forEach((i,o)=>{let n=s+o,f=Math.floor(n/8),l=n&7,m=f*8;t(e,We)[n]=i,([!1,()=>{let $=t(e,We)[m];if($<3){let S="";if($==2){let $e=g.cmt*f;S=`MT-m:${i.toString().padStart(3,"0")}`}else S=e.baseBank.get(0,i+($<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:f});let L=`MSB LSB PRG NME +000 127 ${f} ${S}`;e.userBank.load(L,!0)}}][l]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,c,d)=>{e.switchMode("mt32");let s=((a[0]&1)<<7)+a[1],i=a[0]>>1,o=!1;if(a.subarray(2).forEach((n,f)=>{let l=s+f;l{e.switchMode("mt32");let s=a[1],i=!1,o=function(n,f){t(e,X)[f-12]=n,i=!0};a.subarray(2).forEach((n,f)=>{let l=f+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,B,n),e.dispatchEvent("mastervolume",t(e,B))}][l]||(()=>{}))(n,f)}),i&&e.buildRchTree()}).add([22,18,32],(a,c,d)=>{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 d=e.chRedir(0,c,!0);for(let s=0;s<16;s++)t(e,_).ano(d+s),s&&s<10&&(t(e,O)[d+s]=Et[s-1]);console.info("MT-32 alt reset complete.")}),t(this,me).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 d=["ns5r","05rw"][a[0]];e.switchMode(d,!0),e.setPortMode(e.getTrackPort(c),2,w[d]),x(e,N,!1)}).add([66,18,0,0],(a,c)=>{let d=a[0];switch(d){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(d<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,B,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,B))},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][d+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 d=e.chRedir(a[0],c,!0),s=d*g.cc,i=a[1],o=`NS5R CH${d+1} `;a.subarray(2).forEach((n,f)=>{let l=i+f;l<3?([()=>{t(e,p)[s+E[0]]=n||Oe.bank0},()=>{t(e,p)[s+E[32]]=n},()=>{t(e,O)[d]=n}][l](),e.dispatchEvent("voice",{part:d})):l<8||(l<14?[()=>{let m=e.chRedir(n,c,!0);t(e,X)[d]=m,d!=m&&(e.buildRchTree(),console.info(`${o}receives from CH${m+1}`))},()=>{t(e,ee)[d]=+!n},()=>{e.setChType(d,n,w.ns5r),console.debug(`${o}type: ${et[n]}`)},()=>{t(e,R)[g.rpn*d+3]=n,t(e,A)[g.rpnt*d+2]=1,e.dispatchEvent("pitch",{part:d,pitch:e.getPitchShift(d)})},()=>{},()=>{}][l-8]():l<16||(l<33?[()=>{t(e,p)[s+E[7]]=n},()=>{t(e,p)[s+E[11]]=n},()=>{},()=>{},()=>{t(e,p)[s+E[10]]=n||128},()=>{},()=>{},()=>{t(e,p)[s+E[93]]=n},()=>{t(e,p)[s+E[91]]=n},()=>{t(e,p)[s+E[76]]=n},()=>{t(e,p)[s+E[77]]=n},()=>{t(e,p)[s+E[78]]=n},()=>{t(e,p)[s+E[74]]=n},()=>{t(e,p)[s+E[71]]=n},()=>{t(e,p)[s+E[73]]=n},()=>{t(e,p)[s+E[75]]=n},()=>{t(e,p)[s+E[72]]=n}][l-16]():l<112||l<114&&[()=>{t(e,p)[s+E[5]]=n},()=>{t(e,p)[s+E[65]]=n}][l-112]()))})}).add([66,18,8,0],(a,c)=>{let d=a[0];if(d<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let s=d-32;x(e,fe,Date.now()+3200),x(e,W,10),t(e,ie,ve).fill(0);let i=a.subarray(1),o=4;i.forEach(function(n,f){let l=f+s,m=l>>4,$=l&15;if(l<80){let S=m>3,L=0,$e=m0;)t(e,ie,ve)[$*32+m*7+($e-L)]=S&1,S=S>>1,L++}})}}).add([66,18,48],(a,c,d)=>{b(0,a)}).add([66,18,49],(a,c,d)=>{b(1,a)}).add([66,18,50],(a,c,d)=>{b(2,a)}).add([66,18,51],(a,c,d)=>{b(3,a)}).add([66,18,52],(a,c,d)=>{b(4,a)}).add([66,18,53],(a,c,d)=>{b(5,a)}).add([66,18,54],(a,c,d)=>{b(6,a)}).add([66,18,55],(a,c,d)=>{b(7,a)}).add([66,52],(a,c)=>{e.switchMode("ns5r"),x(e,N,!1);let d="";le(a,(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],(a,c)=>{e.dispatchEvent("mupromptex"),e.switchMode("ns5r"),x(e,N,!1);let d="",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,G)[n]&&t(e,G)[n]!=w.ns5r)if(t(e,Ee).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+n)} mode "${z[t(e,G)[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(f,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)[$+E[0]]=f,e.dispatchEvent("voice",{part:m});break}case 1:{t(e,p)[$+E[32]]=f,!f&&!t(e,p)[$+E[0]]&&(t(e,p)[$+E[0]]=Oe.bank0),e.dispatchEvent("voice",{part:m});break}case 2:{t(e,O)[m]=f,f>0&&e.setChActive(m,1),e.dispatchEvent("voice",{part:m});break}case 3:{let S=e.chRedir(f,c,!0);t(e,X)[m]=S,m!=S&&(console.info(`NS5R CH${m+1} receives from CH${S+1}.`),e.buildRchTree());break}case 7:{t(e,D)[m]=f,e.dispatchEvent("voice",{part:m});break}case 8:{t(e,R)[m*g.rpn+3]=f<40||f>88?f+(f>63?-192:64):f,t(e,A)[g.rpnt*m+2]=1,e.dispatchEvent("pitch",{part:m,pitch:e.getPitchShift(m)});break}case 9:case 10:{t(e,p)[$+E[7]]=f;break}case 11:{t(e,p)[$+E[11]]=f;break}case 14:{t(e,p)[$+E[10]]=f||128;break}case 19:{t(e,p)[$+E[93]]=f;break}case 20:{t(e,p)[$+E[91]]=f;break}case 84:{t(e,p)[$+E[65]]=f;break}case 85:{t(e,p)[$+E[5]]=f;break}}break}case l<3096:break;case l<3134:{let m=l-3096;m<8?(f>31&&(d+=String.fromCharCode(f)),m==7&&(e.aiEfxName=d)):m<10&&(e.setEffectType(m-8,44,f),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 d="",s=80,i=0,o=0,n="MSB\tPRG\tLSB\tNME";le(a,function(f,l){let m=l%158;switch(!0){case m<10:{f>31&&(d+=String.fromCharCode(f));break}case m==10:break;case m==11:{s=f&127;break}case m==12:{o=f&127;break}case m==13:{n+=` +${s} ${i} ${o} ${d.trim().replace("Init Voice","")}`,i++,d="";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 d="",s=88,i=0,o=0,n="MSB\tPRG\tLSB\tNME";le(a,function(f,l){let m=l%126;switch(!0){case m<10:{f>31&&(d+=String.fromCharCode(f));break}case m==11:break;case m==12:break;case m==13:{n+=` +${s} ${i} ${o} ${d.trim().replace("Init Combi","")}`,i++,d="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(n),P()&&console.debug(n),e.forceVoiceRefresh()}).add([66,125],(a,c,d)=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],(a,c,d)=>{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,(f,l,m)=>{if(l<720)for(let $=0;$<8;$++)n[l*8+$]=f>>7-$&1}),e.dispatchEvent("screen",{type:"ns5r",data:n})}).add([76],(a,c,d)=>{t(e,me).run([66,...a],c,d)}),t(this,Ge).add([16,0,8,0],(a,c,d)=>{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,I)[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,d)=>{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],f=`K11 CH${s+1} `;([()=>{n<128?(e.setChType(s,e.CH_MELODIC,w.k11),t(e,p)[i+E[0]]=0,t(e,O)[s]=n):(e.setChType(s,e.CH_DRUMS,w.k11),t(e,O)[s]=n-128),e.dispatchEvent("voice",{part:s})},()=>{let l=e.chRedir(n,c,!0);t(e,X)[s]=l,s!=l&&(e.buildRchTree(),console.info(`${f}receives from CH${l+1}`))},()=>{t(e,p)[i+E[7]]=n},()=>{uupThis.setChActive(s,n)},()=>{t(e,p)[i+E[10]]=n},()=>{t(e,R)[o+3]=n+40,t(e,A)[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,A)[g.rpnt*s+1]=1,e.dispatchEvent("pitch",{part:s,pitch:e.getPitchShift(s)})},()=>{t(e,p)[i+E[91]]=n?127:0},()=>{},()=>{t(e,p)[i+E[74]]=n},()=>{t(e,p)[i+E[73]]=n},()=>{t(e,p)[i+E[72]]=n}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,c,d)=>{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,d)=>{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+E[0]]=0,t(e,p)[o+E[32]]=0,t(e,O)[i]=s):s<160?(e.setChType(i,e.CH_MELODIC,w.k11),t(e,p)[o+E[0]]=0,t(e,p)[o+E[32]]=7,t(e,O)[i]=s-100):(e.setChType(i,e.CH_DRUMS,w.k11),t(e,p)[o+E[0]]=122,t(e,p)[o+E[32]]=0,t(e,O)[i]=s-160),e.dispatchEvent("voice",{part:i})},()=>{let n=e.chRedir(s,c,!0);t(e,X)[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,d)=>{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,f=`GMLX CH${i+1} `;[()=>{e.setChActive(i,s)},()=>{t(e,p)[o+E[7]]=s},()=>{t(e,p)[o+E[10]]=s},()=>{t(e,p)[o+E[91]]=s?127:0},()=>{t(e,R)[n+3]=s+40,t(e,A)[g.rpnt*i+2]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,R)[n+1]=s,t(e,A)[g.rpnt*i+1]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{t(e,R)[n]=s,t(e,A)[g.rpnt*i]=1,e.dispatchEvent("pitch",{part:i,pitch:e.getPitchShift(i)})},()=>{}][a[0]]()}),t(this,_e).add([66,93,64],(a,c,d)=>{let s=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{e.dispatchEvent("mupromptex"),x(e,B,s*129/16383*100),e.dispatchEvent("mastervolume",t(e,B));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,X)[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+E[7]]=s)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,Xe).add([9],(a,c,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"}`)}),t(this,se).add([127,0],(a,c,d)=>{e.switchMode("motif");let s=new Uint8Array([127,1,...a]);t(e,se).run(s,c,d)}).add([127,1,0,0],(a,c,d)=>{e.switchMode("s90es");let s="S90/Motif ES system ",i=a[0];a.subarray(1).forEach((o,n)=>{([()=>{x(e,B,o*12900/16383),e.dispatchEvent("mastervolume",t(e,B))}][i+n]||(()=>{console.info(`Unrecognized ${s}ID: ${i+n}`)}))()})}).add([127,1,0,36,54,1],(a,c,d)=>{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,d)=>{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,d)=>{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,d)=>{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,d)=>{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,d)=>{e.dispatchEvent("mupromptex"),e.switchMode("s90es");let s=e.getTrackPort(c);if(t(e,G)[s]&&t(e,G)[s]!=t(e,U).smotif)if(t(e,Ee).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled for track ${c}. Port ${String.fromCharCode(65+s)} mode "${z[t(e,G)[s]]}" mismatch, should be "${z[t(e,U).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 f=`Track ${c} S90/Motif ES bulk CH${i<128?i+1:"U"+(i-127)} `;console.debug(f,a),!(a[0]>15)&&a.subarray(2).forEach((l,m)=>{([()=>{t(e,p)[o+E[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),t(e,p)[o+E[32]]=l,e.setChType(i,[32,40].indexOf(l)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,H),!0),e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),t(e,O)[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(l,c,!0);t(e,X)[i]=$,i!=$&&(e.buildRchTree(),console.info(`${f}receives from CH${$+1}`))},()=>{t(e,ee)[i]=l?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{l!=100&&e.setChActive(i,1),t(e,p)[o+E[7]]=l},()=>{l!=64&&e.setChActive(i,1),t(e,p)[o+E[10]]=l},!1,!1,!1,()=>{t(e,p)[o+E[91]]=l},()=>{l&&e.setChActive(i,1),t(e,p)[o+E[93]]=l},()=>{l&&e.setChActive(i,1),t(e,p)[o+E[94]]=l},()=>{l!=127&&e.setChActive(i,1),t(e,p)[o+E[128]]=l,e.allocateAce(i,128)},()=>{},()=>{l!=64&&e.setChActive(i,1),t(e,p)[o+E[74]]=l},()=>{l!=64&&e.setChActive(i,1),t(e,p)[o+E[71]]=l},!1,()=>{t(e,p)[o+E[65]]=l},()=>{t(e,p)[o+E[5]]=l},()=>{}][n+m]||(()=>{}))()})}).add([127,1,54,16],(a,c,d)=>{e.switchMode("s90es");let s=a[0];a.subarray(1).forEach((i,o)=>{let f=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let l=i-64},()=>{let l=Fe[i]},()=>{let l=i/10},()=>{let l=i}][s+o&3]||(()=>{}))()})}),t(this,ne).add([0,72,18,0,0,0,0],(a,c,d)=>{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,d)=>{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((f,l,m)=>{let $=l+n;switch($){case 0:{f&&(e.setEffectType(1,60,f-1),e.dispatchEvent("efxchorus",e.getEffectType(1)),console.debug(`SD MFX Cho: ${$} - ${f}`));break}}});break}case 2:{a.subarray(2).forEach((f,l)=>{let m=l+n;switch(m){case 0:{f&&(e.setEffectType(0,55+f,0),e.dispatchEvent("efxreverb",e.getEffectType(0)),console.debug(`SD MFX Rev: ${m} - ${f}`));break}}});break}case 3:case 4:case 5:{let f=o-1;a.subarray(2).forEach((l,m)=>{let $=m+n;switch(console.debug(`SD MFX ${f-2}: ${$} - ${l}`),$){case 0:{e.setEffectTypeRaw(f,62,l),e.dispatchEvent(`efx${f>2?"delay":"insert"+(f-4)}`,e.getEffectType(f));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,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 1:{let o=e.chRedir(i,c,!0),n=a[1],f=o*g.cc;a.subarray(2).forEach((l,m)=>{let $=n+m;$<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,p)[f+E[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)[f+E[32]]=l,e.dispatchEvent("voice",{part:o})},()=>{t(e,O)[o]=l,e.dispatchEvent("voice",{part:o})},()=>{t(e,p)[f+E[7]]=l},()=>{t(e,p)[f+E[10]]=l},()=>{},()=>{},()=>{l<2&&(t(e,ee)[o]=l)},()=>{l<2&&(t(e,p)[f+E[68]]=l?127:0)},()=>{},()=>{l<2&&(t(e,p)[f+E[65]]=l?127:0)},()=>{t(e,p)[f+E[5]]=l&15<<4|t(e,p)[f+E[5]]&15},()=>{t(e,p)[f+E[5]]=l&15|(t(e,p)[f+E[5]]&240)>>4},()=>{t(e,p)[f+E[74]]=l},()=>{t(e,p)[f+E[71]]=l},()=>{t(e,p)[f+E[73]]=l},()=>{t(e,p)[f+E[72]]=l},0,0,0,0,0,0,0,()=>{t(e,p)[f+E[128]]=l,e.allocateAce(128)},()=>{t(e,p)[f+E[93]]=l},()=>{t(e,p)[f+E[91]]=l},0,0,()=>{t(e,p)[f+E[75]]=l},()=>{t(e,p)[f+E[76]]=l},()=>{t(e,p)[f+E[77]]=l},()=>{t(e,p)[f+E[78]]=l}][$]||(()=>{}))():$<63||($<64?(t(e,D)[o]?t(e,p)[f+E[0]]=104|l:t(e,p)[f+E[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,me).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,_)[s]&&t(e,_)[s]!=w.krs)if(t(e,ye).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+s)} mode "${K[t(e,_)[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,X)[m]=U,console.info(`${i}CH${m+1} receives from CH${U+1}`)},!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,xe)[e+E]==0?(t(u,xe)[e+E]=r,console.debug(`Assign track ${r} to channel ${e+E+1}.`),v=!1):t(this,xe)[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,H)[r.getChModeId(e)][0],u[b[32]]=u[b[32]]||t(r,H)[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,H)[h.getChModeId(e)][0],u==Fe.bank0&&(u=0);break}case 32:{u=u||t(h,H)[h.getChModeId(e)][1];break}}return u}getCcAll(){let e=this,r=t(e,p).slice();for(let h=0;h0&&!u&&(t(E,p)[e*g.cc+b[0]]=t(E,H)[h][2])}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,F).forEach(function(u,E){let v=Math.floor(u/128),k=u%128;e==v&&t(h,V)[u]>0&&r.set(k,{v:t(h,V)[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,I)}}getRawStrength(){let e=this;return t(this,F).forEach(function(r){let h=Math.floor(r/128);t(e,V)[r]>t(e,Ee)[h]&&(t(e,Ee)[h]=t(e,V)[r])}),t(this,Ee)}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,I)/803288)}),e}getRpn(){return t(this,R)}getNrpn(){return t(this,Ke)}getVoice(e,r,h,u){let E=this,v=e||t(E,H)[t(E,O)][0],k=r,C=h||t(E,H)[t(E,O)][1];v==Fe.bank0&&(v=0),K[t(E,O)]=="ns5r"&&v>0&&v<56&&(C=3);let a=E.userBank.get(v,k,C,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,C,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,C,a)=>{a[C]=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(ta[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,H)[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,ye).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]=t(r,H)[r.getChModeId(h)][2]}),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,_)[e>>4]:t(this,Ce)[e]||t(this,_)[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]=t(u,H)[E][2]);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 C;switch(E){case w["?"]:case w.g2:{C=[52,4,52,18,0,0,0,0];break}case w.xg:{C=[1,0,65,0,5,0,0,0];break}case w.gm:case w.gs:case w.sc:{C=[40,4,40,18,40,32,32,0];break}case w.sd:{C=[58,0,60,0,61,0,61,0];break}case w["05rw"]:case w.x5d:case w.ns5r:{C=[44,1,44,19,44,0,44,0];break}case w.k11:case w.sg:{C=[24,0,0,0,0,0,0,0];break}case w.mt32:{C=[40,4,0,0,0,0,0,0];break}case w.doc:{C=[24,16,0,0,0,0,0,0];break}case w.motif:case w.s90es:{C=[113,0,117,0,114,0,0,0];break}default:C=[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,Ee).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(`${Nt[e.type]?Nt[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)]},Wt=function(e){t(this,we)[t(this,W)]=e},ie=new WeakMap,X=new WeakMap,D=new WeakMap,p=new WeakMap,ce=new WeakMap,A=new WeakMap,V=new WeakMap,Z=new WeakMap,F=new WeakMap,z=new WeakMap,ke=new WeakMap,Ee=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,_=new WeakMap,Ce=new WeakMap,ue=new WeakMap,rt=new WeakMap,Me=new WeakMap,pe=new WeakMap,We=new WeakMap,Te=new WeakMap,H=new WeakMap,B=new WeakMap,ye=new WeakMap,st=new WeakMap,I=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,yt=new WeakMap,ae=new WeakMap,xe=new WeakMap,Pe=new WeakMap,q=new WeakMap,Be=new WeakMap,G=new WeakMap,nt=new WeakMap,dt=new WeakMap,Ie=new WeakMap,Ne=new WeakMap,re=new WeakMap,ne=new WeakMap,me=new WeakMap,He=new WeakMap,_e=new WeakMap,Ge=new WeakMap,zt);export{Wa as OctaviaDevice,g as allocated,b as ccToPos,de as dnToPos}; \ No newline at end of file +%o`,a)}}),t(e,me).add([0,1,73,78],(a,c,d)=>{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,d)=>{e.switchMode("krs");let s=e.getTrackPort(c);if(t(e,G)[s]&&t(e,G)[s]!=w.krs)if(t(e,Ee).dumpLimit==e.DUMP_MODE){console.warn(`Dump cancelled. Port ${String.fromCharCode(65+s)} mode "${z[t(e,G)[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,f)=>{if(f<24)o+=String.fromCharCode(Math.max(32,n));else if(!(f<1276)){let l=f-1276,m=e.chRedir(Math.floor(l/44),c,!0),$=l%44,S=g.cc*m;$<15?([()=>{n&&e.setChActive(m,1),t(e,O)[m]=n,e.dispatchEvent("voice",{part:m})},()=>{n&&e.setChActive(m,1),n<10?(t(e,p)[S+E[0]]=63,t(e,p)[S+E[32]]=n):n<20?(t(e,p)[S+E[0]]=121,t(e,p)[S+E[32]]=n-10):n<24&&(t(e,p)[S+E[0]]=[120,0,56,62][n-20],t(e,p)[S+E[32]]=0),e.dispatchEvent("voice",{part:m})},()=>{let L=e.chRedir(n&15,c,!0);t(e,X)[m]=L,console.info(`${i}CH${m+1} receives from CH${L+1}`)},!1,!1,()=>{t(e,p)[S+E[7]]=n},!1,()=>{},()=>{},!1,!1,!1,!1,!1,()=>{t(e,p)[S+E[10]]=n||128}][$]||(()=>{}))():$<36||([()=>{t(e,p)[S+E[74]]=(n+128&255)-64},()=>{t(e,p)[S+E[71]]=(n+128&255)-64},!1,!1,()=>{t(e,p)[S+E[73]]=(n+128&255)-64},()=>{t(e,p)[S+E[75]]=(n+128&255)-64},!1,()=>{t(e,p)[S+E[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,H)==w.sc){if(h==1)return e;let b=0,v=!0;for(;v;)t(u,Se)[e+b]==0?(t(u,Se)[e+b]=r,console.debug(`Assign track ${r} to channel ${e+b+1}.`),v=!1):t(this,Se)[e+b]==r?v=!1:(b+=16,b>=128&&(b=0,v=!1));return e+b}else return e}getTrackPort(e){return this.chRedir(0,e,!0)>>4}forceVoiceRefresh(){for(let e=0;e{var u;r{r&&(t(e,He)[Math.floor(h/g.redir)][r]=h%g.redir|128)}),P()&&console.debug(t(e,He))}getActive(){return t(this,ce)}getCc(e){let r=this,h=e*g.cc,u=t(r,p).subarray(h,h+g.cc);return u[E[0]]=u[E[0]]||t(r,I)[r.getChModeId(e)][0],u[E[32]]=u[E[32]]||t(r,I)[r.getChModeId(e)][1],u[E[0]]==Oe.bank0&&(u[E[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+E[r]];switch(r){case 0:{u=u||t(h,I)[h.getChModeId(e)][0],u==Oe.bank0&&(u=0);break}case 32:{u=u||t(h,I)[h.getChModeId(e)][1];break}}return u}getCcAll(){let e=this,r=t(e,p).slice();for(let h=0;h0&&!u&&(t(b,p)[e*g.cc+E[0]]=t(b,I)[h][2])}setChActive(e,r=0){t(this,ce)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),t(this,ce)[e]=r}getExt(e){let r=g.ext*e,h=t(this,te).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,O)}getTexts(){return t(this,re).slice()}getVel(e){let r=new Map,h=this;return t(h,F).forEach(function(u,b){let v=Math.floor(u/128),k=u%128;e==v&&t(h,V)[u]>0&&r.set(k,{v:t(h,V)[u],s:t(h,K)[b]})}),r}getBitmap(){return{bitmap:t(this,ie,ve),expire:t(this,fe)}}getLetter(){return{text:t(this,Re),set:t(this,it),expire:t(this,De)}}getMode(){return z[t(this,H)]}getMaster(){return{volume:t(this,B)}}getRawStrength(){let e=this;return t(this,F).forEach(function(r){let h=Math.floor(r/128);t(e,V)[r]>t(e,ge)[h]&&(t(e,ge)[h]=t(e,V)[r])}),t(this,ge)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(h,u){e[u]=Math.floor(h*t(r,p)[u*g.cc+E[7]]*t(r,p)[u*g.cc+E[11]]*t(r,B)/803288)}),e}getRpn(){return t(this,R)}getNrpn(){return t(this,Ke)}getSubDb(){return self==null?void 0:self.structuredClone(t(this,I))}getVoice(e,r,h,u="?"){var d;let b=this;(d=w[u])!=null&&d.constructor||(u="?");let v=w[u],k=e||t(b,I)[v][0],M=r,a=h||t(b,I)[v][1];k==Oe.bank0&&(k=0),a==Oe.bank0&&(a=0),u=="ns5r"&&k>0&&k<56&&(a=3);let c=b.userBank.get(k,M,a,u);if(u=="mt32"&&c.name.indexOf("MT-m:")==0){let s=parseInt(c.name.slice(5)),i=s*g.cmt,o="";t(b,Te).subarray(i,i+10).forEach(f=>{f>31&&(o+=String.fromCharCode(f))});let n=`MSB LSB PRG NME +0 127 ${M} ${o}`;b.userBank.load(n,!0),c.name=o,c.ending=" "}return(c.ending!=" "||!c.name.length)&&(c=b.baseBank.get(k,M,a,u)),c}getChVoice(e){let r=this,h=r.getVoice(r.getCcCh(e,0),t(r,O)[e],r.getCcCh(e,32),r.getChMode(e));if(t(r,ue)[e]){let u="";switch(t(r,H)){case w.mt32:{t(r,pe).subarray(g.cmt*(e-1),g.cmt*(e-1)+10).forEach(b=>{u+=String.fromCharCode(Math.max(b,32))}),u=u.trimRight();break}default:{let b=g.cvn*e;t(r,rt).subarray(b,b+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,A)[e*g.rpnt]||t(r,H)==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,ae).subarray(r,r+2)}setEffectTypeRaw(e=0,r,h){let u=3*e;t(this,ae)[u]=1,t(this,ae)[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 b=this,v;x(b,Re," ".repeat(h)),e.forEach(k=>{x(b,Re,t(b,Re)+String.fromCharCode(k>31?k:32)),k<32&&(v=v||new Set,v.add(k))}),x(b,it,Date.now()),x(b,De,Date.now()+u),v&&(v=Array.from(v),v.forEach((k,M,a)=>{a[M]=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(b=>{b=b.toLowerCase();let v=z.indexOf(ea[b]||b);P()&&console.debug(`Mapped mode "${b}" to ID "${v}".`),v>-1&&(u=v)}),P()&&console.debug(`Set detection target to ID "${u}".`),u>0&&(t(h,U).x5=82,t(h,U).ds=w.krs),u){case w["05rw"]:{t(h,U).x5=81;break}case w.s90es:t(h,U).ds=w.s90es,t(h,U).smotif=w.s90es;case w.motif:t(h,U).ds=w.motif,t(h,U).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,U)[e?"sc":"gs"]=r,t(h,I)[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,Ee).dumpLimit=e}allocateAce(e=0,r){let h=this;if(!r||r<128&&r>95){console.warn(`cc${r} cannot be allocated as an active custom effect.`);return}let u=!0,b=0,v=g.ace*e;for(;u&&b=g.ace&&console.warn(`ACE slots are full in CH${e+1}.`)}allocateAceAll(e){let r=this;if(!e||e<128&&e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}for(let h=0;h=g.ace&&console.warn(`ACE slots are full in CH${h+1}.`)}}releaseAce(e=0,r){let h=!0,u=g.ace*e,b=u+g.ace;for(;h&&u=g.ace)throw new RangeError("No such ACE slot");let h=t(this,q)[g.ace*e+r];if(h){if(at.indexOf(h)>=0)return t(this,p)[e*g.cc+E[h]];throw new Error(`Invalid ACE source in CH${e+1}: ${h}`)}else return 0}initDrums(){let e=this;t(e,j).fill(64);for(let r=0;r{t(r,p)[g.cc*h]=t(r,I)[r.getChModeId(h)][2]}),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>=z.length)throw new RangeError(`Invalid mode ID ${r}`);t(h,Ce)[e]=r,h.dispatchEvent("voice",{part:e})}getChMode(e,r){return z[this.getChModeId(e,r)]}getChModeId(e,r){return r?t(this,Ce)[e]||t(this,G)[e>>4]:t(this,Ce)[e]||t(this,G)[e>>4]||t(this,H)}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>=z.length)throw new RangeError(`Invalid mode ID ${h}`);for(let b=e;b=0&&e-1){if(t(u,H)==0||r){let k=t(u,H);u.initOnReset&&r&&(this.init(1),k=w["?"]),x(u,H,b),x(u,W,0);for(let a=0;a0&&t(u,Ce)[a]==0&&(t(u,p)[a*g.cc]=t(u,I)[b][2]);switch(b){case w.mt32:{Et.forEach((a,c)=>{let d=c+1;t(u,ce)[d]||(t(u,O)[d]=a,t(u,p)[d*g.cc+E[91]]=127)});for(let a=1;a<10;a++)u.dispatchEvent("voice",{part:a});break}}let M;switch(b){case w["?"]:case w.g2:{M=[52,4,52,18,0,0,0,0];break}case w.xg:{M=[1,0,65,0,5,0,0,0];break}case w.gm:case w.gs:case w.sc:{M=[40,4,40,18,40,32,32,0];break}case w.sd:{M=[58,0,60,0,61,0,61,0];break}case w["05rw"]:case w.x5d:case w.ns5r:{M=[44,1,44,19,44,0,44,0];break}case w.k11:case w.sg:{M=[24,0,0,0,0,0,0,0];break}case w.mt32:{M=[40,4,0,0,0,0,0,0];break}case w.doc:{M=[24,16,0,0,0,0,0,0];break}case w.motif:case w.s90es:{M=[113,0,117,0,114,0,0,0];break}default:M=[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,ge).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(b=>{e.channel=b,u=!0,t(this,nt)[e.type].call(this,e)}),u||console.warn(`${Bt[e.type]?Bt[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,re).length>100&&t(this,re).splice(100,t(this,re).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()}},H=new WeakMap,W=new WeakMap,fe=new WeakMap,we=new WeakMap,ie=new WeakSet,ve=function(){return t(this,we)[t(this,W)]},zt=function(e){t(this,we)[t(this,W)]=e},ce=new WeakMap,X=new WeakMap,D=new WeakMap,p=new WeakMap,q=new WeakMap,O=new WeakMap,V=new WeakMap,ee=new WeakMap,F=new WeakMap,K=new WeakMap,ke=new WeakMap,ge=new WeakMap,Ae=new WeakMap,te=new WeakMap,R=new WeakMap,A=new WeakMap,Ke=new WeakMap,j=new WeakMap,he=new WeakMap,ae=new WeakMap,ze=new WeakMap,Le=new WeakMap,G=new WeakMap,Ce=new WeakMap,ue=new WeakMap,rt=new WeakMap,Me=new WeakMap,pe=new WeakMap,We=new WeakMap,Te=new WeakMap,I=new WeakMap,U=new WeakMap,Ee=new WeakMap,st=new WeakMap,B=new WeakMap,Ue=new WeakMap,qe=new WeakMap,Qe=new WeakMap,Re=new WeakMap,De=new WeakMap,it=new WeakMap,Ye=new WeakMap,ye=new WeakMap,N=new WeakMap,lt=new WeakMap,ct=new WeakMap,He=new WeakMap,re=new WeakMap,Se=new WeakMap,Pe=new WeakMap,Q=new WeakMap,Be=new WeakMap,_=new WeakMap,nt=new WeakMap,dt=new WeakMap,Ie=new WeakMap,Ne=new WeakMap,se=new WeakMap,ne=new WeakMap,me=new WeakMap,Ge=new WeakMap,_e=new WeakMap,Xe=new WeakMap,Kt);export{za as OctaviaDevice,g as allocated,E as ccToPos,de as dnToPos,Oe as overrides}; \ No newline at end of file diff --git a/src/bridge/index.mjs b/src/bridge/index.mjs index d65bd1cc..cda76982 100644 --- a/src/bridge/index.mjs +++ b/src/bridge/index.mjs @@ -1,67 +1,13 @@ // Middleware! "use strict"; -import {CustomEventSource} from "../../libs/lightfelt@ltgcgo/ext/customEvents.js"; +import {allocated} from "../state/index.mjs"; import MidiParser from "../../libs/midi-parser@colxi/main.min.js"; import {rawToPool} from "../basic/transform.js"; import {customInterpreter} from "../state/utils.js"; MidiParser.customInterpreter = customInterpreter; -// Use track 240 to 255 for middleware. -let toJson = function (data, track = 0) { - let type = data[0] >> 4, part = data[0] & 15; - let replyObj = { - track: (track & 15) + 240, - type, - data: data.slice(1) - }; - if (type < 15) { - replyObj.part = part; - return replyObj; - } if (type == 12) { - replyObj.data = data[1]; - } else { - if (part == 0) { - // SysEx - return replyObj; - } else { - console.warn(`Unknown special event channel ${part}.`) - }; - }; -}; -let fromJson = function (json) { - let type = json.type, part = json.part; - if (type == 255) { - // Directly reject sending meta events - return; - }; - let binLength = 3; - if (type == 12) { - binLength = 2; - } else if (type == 15) { - binLength = json.data.length + 1; - }; - let newInstr = new Uint8Array(binLength); - if (type != 15) { - newInstr[0] = json.type * 16 + json.part; - } else { - newInstr[0] = 240; - }; - if (type == 12) { - newInstr[1] = json.data; - } else { - if (json.data.forEach) { - json.data.forEach((e, i) => { - newInstr[i + 1] = e; - }); - } else { - console.debug(`Type ${type} value ${json.data.constructor.name} cannot be iterated.`); - }; - }; - return newInstr; -}; - let getBridge = function () { return new BroadcastChannel("cc.ltgc.octavia:MainInput"); }; @@ -69,76 +15,7 @@ let getBridgeOut = function () { return new BroadcastChannel("cc.ltgc.octavia:MainOutput"); }; -let SimpleMidiEventEmitter = class extends CustomEventSource { - #pool; - #paused = true; - #currentTime = 0; - #lastEventTs = 0; - #threadId = -1; - get currentTime() { - return this.#currentTime / 1000; - }; - get duration() { - if (!this.#pool) { - return 0; - } else { - return this.#pool[this.#pool.length - 1].end + 4; - }; - }; - async load(blob) { - if (blob) { - this.#pool = rawToPool(MidiParser.parse(new Uint8Array(await blob.arrayBuffer()))); - } else { - this.pause(); - this.#currentTime = 0; - }; - }; - pause() { - if (this.#threadId > -1) { - clearInterval(this.#threadId); - // All notes off - for (let part = 0; part < 16; part ++) { - this.dispatchEvent("midi", { - delay: 0, - data: {part, "type": 11, "data": [123, 0]} - }); - }; - this.dispatchEvent("pause"); - this.#threadId = -1; - }; - }; - async play() { - if (this.#threadId < 0) { - this.#lastEventTs = Date.now(); - this.#threadId = setInterval(() => { - let timeNow = Date.now(), - timeLast = this.#currentTime, - timeDiff = timeNow - this.#lastEventTs; - this.#currentTime += timeDiff; - let events = this.#pool.step(this.currentTime); - events?.forEach((e) => { - this.dispatchEvent("midi", { - delay: Math.round(e.start * 1000 - timeLast), - data: e.data - }); - }); - this.#lastEventTs = timeNow; - }, 12.5); - this.dispatchEvent("play"); - }; - }; - constructor(pool) { - super(); - if (pool) { - this.load(pool); - }; - }; -}; - export { - toJson, - fromJson, getBridge, - getBridgeOut, - SimpleMidiEventEmitter + getBridgeOut }; diff --git a/src/bridge/index.old.mjs b/src/bridge/index.old.mjs new file mode 100644 index 00000000..23a3d921 --- /dev/null +++ b/src/bridge/index.old.mjs @@ -0,0 +1,77 @@ +// Middleware! +"use strict"; + +import {allocated} from "../state/index.mjs"; +import MidiParser from "../../libs/midi-parser@colxi/main.min.js"; +import {rawToPool} from "../basic/transform.js"; +import {customInterpreter} from "../state/utils.js"; + +MidiParser.customInterpreter = customInterpreter; + +// Use track 240 to 255 for middleware. +let toJson = function (data, track = 0) { + let type = data[0] >> 4, part = data[0] & 15; + let replyObj = { + track: (track & 15) + 240, + type, + data: data.slice(1) + }; + if (type < 15) { + replyObj.part = part; + return replyObj; + } if (type == 12) { + replyObj.data = data[1]; + } else { + if (part == 0) { + // SysEx + return replyObj; + } else { + console.warn(`Unknown special event channel ${part}.`) + }; + }; +}; +let fromJson = function (json) { + let type = json.type, part = json.part; + if (type == 255) { + // Directly reject sending meta events + return; + }; + let binLength = 3; + if (type == 12) { + binLength = 2; + } else if (type == 15) { + binLength = json.data.length + 1; + }; + let newInstr = new Uint8Array(binLength); + if (type != 15) { + newInstr[0] = json.type * 16 + json.part; + } else { + newInstr[0] = 240; + }; + if (type == 12) { + newInstr[1] = json.data; + } else { + if (json.data.forEach) { + json.data.forEach((e, i) => { + newInstr[i + 1] = e; + }); + } else { + console.debug(`Type ${type} value ${json.data.constructor.name} cannot be iterated.`); + }; + }; + return newInstr; +}; + +let getBridge = function () { + return new BroadcastChannel("cc.ltgc.octavia:MainInput"); +}; +let getBridgeOut = function () { + return new BroadcastChannel("cc.ltgc.octavia:MainOutput"); +}; + +export { + toJson, + fromJson, + getBridge, + getBridgeOut +}; diff --git a/src/demoMw/index.js b/src/demoMw/index.js index f55fe157..8eb4ac88 100644 --- a/src/demoMw/index.js +++ b/src/demoMw/index.js @@ -6,9 +6,8 @@ import {fileOpen} from "../../libs/browser-fs-access@GoogleChromeLabs/browser_fs import { toJson, fromJson, - getBridge, - SimpleMidiEventEmitter -} from "../bridge/index.mjs"; + getBridge +} from "../bridge/index.old.mjs"; let globalAudioCtx; let getGAC = function () { @@ -97,7 +96,6 @@ midiInSel.forEach((e, i) => { self.midiAccess = await navigator.requestMIDIAccess({"sysex": true, "software": true}); self.fromJson = fromJson; self.toJson = toJson; - self.MEE = SimpleMidiEventEmitter; midiAccess.addEventListener("statechange", (ev) => { console.debug(ev.port); });