diff --git a/dist/basic.mjs b/dist/basic.mjs index d95b9364..7ed785a1 100644 --- a/dist/basic.mjs +++ b/dist/basic.mjs @@ -1,4 +1,4 @@ -var U=Object.create;var C=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var B=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports);var H=(r,n,o,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of L(n))!G.call(r,e)&&e!==o&&C(r,e,{get:()=>n[e],enumerable:!(a=P(n,e))||a.enumerable});return r};var _=(r,n,o)=>(o=r!=null?U(N(r)):{},H(n||!r||!r.__esModule?C(o,"default",{value:r,enumerable:!0}):o,r));var O=B((De,v)=>{(function(){"use strict";let r={fatal:!0},n=[new TextDecoder("iso-8859-15",r),new TextDecoder("sjis",r),new TextDecoder("euc-jp",r),new TextDecoder("utf-8",r),new TextDecoder("utf-16",r),new TextDecoder("ascii")],o={debug:!1,parse:function(a,e){if(a instanceof Uint8Array)return o.Uint8(a);if(typeof a=="string")return o.Base64(a);if(a instanceof HTMLElement&&a.type==="file")return o.addListener(a,e);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(a,e){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(a===void 0||!(a instanceof HTMLElement)||a.tagName!=="INPUT"||a.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;e=e||function(){},a.addEventListener("change",function(t){if(!t.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let c=new FileReader;c.readAsArrayBuffer(t.target.files[0]),c.onload=function(d){e(o.Uint8(new Uint8Array(d.target.result)))}})},Base64:function(a){let e=function(d){var $="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 u,p="",i,s,l=0;for(;l>16&255):s===64?String.fromCharCode(u>>16&255,u>>8&255):String.fromCharCode(u>>16&255,u>>8&255,255&u);return p}(a=String(a));var t=e.length;let c=new Uint8Array(new ArrayBuffer(t));for(let d=0;d{s[h]=this.readInt(1)});for(let b=0;b191||g>127&&g<160)throw new RangeError(`Invalid code point: ${g}`)}l=!0,console.debug(`String byte sequence in ${n[b].encoding}`)}catch(h){console.debug(`SMF string ${h}`)}return f||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let i=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)i=this.readInt(1);else{let l=[];for(;128<=this.data.getUint8(this.pointer);)l.push(this.readInt(1)-128);var s=this.readInt(1);for(let f=1;f<=l.length;f++)i+=l[l.length-f]*Math.pow(128,f);i+=s}return i}};if(e.data=new DataView(c.buffer,c.byteOffset,c.byteLength),e.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;e.readInt(4);let t={};t.formatType=e.readInt(2),t.tracks=e.readInt(2),t.track=[];var c=e.readInt(1),d=e.readInt(1);128<=c?(t.timeDivision=[],t.timeDivision[0]=c-128,t.timeDivision[1]=d):t.timeDivision=256*c+d;for(let i=1;i<=t.tracks;i++){t.track[i-1]={event:[]};var $,u=e.readInt(4);if(u===-1)break;if(u!==1297379947)return!1;e.readInt(4);let s=0,l=!1,f,b;for(;!l&&(s++,t.track[i-1].event[s-1]={},t.track[i-1].event[s-1].deltaTime=e.readIntVLV(),(f=e.readInt(1))!==-1);)if(128<=f?b=f:(f=b,e.movePointer(-1)),f===255){t.track[i-1].event[s-1].type=255,t.track[i-1].event[s-1].metaType=e.readInt(1);var p=e.readIntVLV();switch(t.track[i-1].event[s-1].metaType){case 47:case-1:l=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:t.track[i-1].event[s-1].data=e.readStr(p);break;case 33:case 89:case 81:t.track[i-1].event[s-1].data=e.readInt(p);break;case 84:t.track[i-1].event[s-1].data=[],t.track[i-1].event[s-1].data[0]=e.readInt(1),t.track[i-1].event[s-1].data[1]=e.readInt(1),t.track[i-1].event[s-1].data[2]=e.readInt(1),t.track[i-1].event[s-1].data[3]=e.readInt(1),t.track[i-1].event[s-1].data[4]=e.readInt(1);break;case 88:t.track[i-1].event[s-1].data=[],t.track[i-1].event[s-1].data[0]=e.readInt(1),t.track[i-1].event[s-1].data[1]=e.readInt(1),t.track[i-1].event[s-1].data[2]=e.readInt(1),t.track[i-1].event[s-1].data[3]=e.readInt(1);break;default:this.customInterpreter!==null&&(t.track[i-1].event[s-1].data=this.customInterpreter(t.track[i-1].event[s-1].metaType,e,p)),this.customInterpreter!==null&&t.track[i-1].event[s-1].data!==!1||(e.readInt(p),t.track[i-1].event[s-1].data=e.readInt(p),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((f=f.toString(16).split(""))[1]||f.unshift("0"),t.track[i-1].event[s-1].type=parseInt(f[0],16),t.track[i-1].event[s-1].channel=parseInt(f[1],16),t.track[i-1].event[s-1].type){case 15:this.customInterpreter!==null&&(t.track[i-1].event[s-1].data=this.customInterpreter(t.track[i-1].event[s-1].type,e,!1)),this.customInterpreter!==null&&t.track[i-1].event[s-1].data!==!1||($=e.readIntVLV(),t.track[i-1].event[s-1].data=e.readInt($),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:t.track[i-1].event[s-1].data=[],t.track[i-1].event[s-1].data[0]=e.readInt(1),t.track[i-1].event[s-1].data[1]=e.readInt(1);break;case 12:case 13:t.track[i-1].event[s-1].data=e.readInt(1);break;case-1:l=!0;break;default:if(this.customInterpreter!==null&&(t.track[i-1].event[s-1].data=this.customInterpreter(t.track[i-1].event[s-1].metaType,e,!1)),this.customInterpreter===null||t.track[i-1].event[s-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return t},customInterpreter:null};if(typeof v<"u")v.exports=o;else{let a=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;a.MidiParser=o}})()});var E=class{#e={};addEventListener(r,n){this.#e[r]||(this.#e[r]=[]),this.#e[r].unshift(n)}removeEventListener(r,n){if(this.#e[r]){let o=this.#e[r].indexOf(n);o>-1&&this.#e[r].splice(o,1),this.#e[r].length<1&&delete this.#e[r]}}dispatchEvent(r,n){let o=new Event(r),a=this;o.data=n,this.#e[r]?.length>0&&this.#e[r].forEach(function(e){try{e?.call(a,o)}catch(t){console.error(t)}}),this[`on${r}`]&&this[`on${r}`](o)}};var F=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]);var V=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),X={};`hi*, +var U=Object.create;var C=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var B=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports);var H=(r,n,o,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of L(n))!G.call(r,e)&&e!==o&&C(r,e,{get:()=>n[e],enumerable:!(a=P(n,e))||a.enumerable});return r};var _=(r,n,o)=>(o=r!=null?U(N(r)):{},H(n||!r||!r.__esModule?C(o,"default",{value:r,enumerable:!0}):o,r));var O=B((Ue,v)=>{(function(){"use strict";let r={fatal:!0},n=[new TextDecoder("iso-8859-15",r),new TextDecoder("sjis",r),new TextDecoder("euc-jp",r),new TextDecoder("utf-8",r),new TextDecoder("utf-16",r),new TextDecoder("ascii")],o={debug:!1,parse:function(a,e){if(a instanceof Uint8Array)return o.Uint8(a);if(typeof a=="string")return o.Base64(a);if(a instanceof HTMLElement&&a.type==="file")return o.addListener(a,e);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(a,e){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(a===void 0||!(a instanceof HTMLElement)||a.tagName!=="INPUT"||a.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;e=e||function(){},a.addEventListener("change",function(t){if(!t.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let c=new FileReader;c.readAsArrayBuffer(t.target.files[0]),c.onload=function(d){e(o.Uint8(new Uint8Array(d.target.result)))}})},Base64:function(a){let e=function(d){var $="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 u,p="",i,s,l=0;for(;l>16&255):s===64?String.fromCharCode(u>>16&255,u>>8&255):String.fromCharCode(u>>16&255,u>>8&255,255&u);return p}(a=String(a));var t=e.length;let c=new Uint8Array(new ArrayBuffer(t));for(let d=0;d{s[h]=this.readInt(1)});for(let b=0;b191||g>127&&g<160)throw new RangeError(`Invalid code point: ${g}`)}l=!0,console.debug(`String byte sequence in ${n[b].encoding}`)}catch(h){console.debug(`SMF string ${h}`)}return f||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let i=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)i=this.readInt(1);else{let l=[];for(;128<=this.data.getUint8(this.pointer);)l.push(this.readInt(1)-128);var s=this.readInt(1);for(let f=1;f<=l.length;f++)i+=l[l.length-f]*Math.pow(128,f);i+=s}return i}};if(e.data=new DataView(c.buffer,c.byteOffset,c.byteLength),e.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;e.readInt(4);let t={};t.formatType=e.readInt(2),t.tracks=e.readInt(2),t.track=[];var c=e.readInt(1),d=e.readInt(1);128<=c?(t.timeDivision=[],t.timeDivision[0]=c-128,t.timeDivision[1]=d):t.timeDivision=256*c+d;for(let i=1;i<=t.tracks;i++){t.track[i-1]={event:[]};var $,u=e.readInt(4);if(u===-1)break;if(u!==1297379947)return!1;e.readInt(4);let s=0,l=!1,f,b;for(;!l&&(s++,t.track[i-1].event[s-1]={},t.track[i-1].event[s-1].deltaTime=e.readIntVLV(),(f=e.readInt(1))!==-1);)if(128<=f?b=f:(f=b,e.movePointer(-1)),f===255){t.track[i-1].event[s-1].type=255,t.track[i-1].event[s-1].metaType=e.readInt(1);var p=e.readIntVLV();switch(t.track[i-1].event[s-1].metaType){case 47:case-1:l=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:t.track[i-1].event[s-1].data=e.readStr(p);break;case 33:case 89:case 81:t.track[i-1].event[s-1].data=e.readInt(p);break;case 84:t.track[i-1].event[s-1].data=[],t.track[i-1].event[s-1].data[0]=e.readInt(1),t.track[i-1].event[s-1].data[1]=e.readInt(1),t.track[i-1].event[s-1].data[2]=e.readInt(1),t.track[i-1].event[s-1].data[3]=e.readInt(1),t.track[i-1].event[s-1].data[4]=e.readInt(1);break;case 88:t.track[i-1].event[s-1].data=[],t.track[i-1].event[s-1].data[0]=e.readInt(1),t.track[i-1].event[s-1].data[1]=e.readInt(1),t.track[i-1].event[s-1].data[2]=e.readInt(1),t.track[i-1].event[s-1].data[3]=e.readInt(1);break;default:this.customInterpreter!==null&&(t.track[i-1].event[s-1].data=this.customInterpreter(t.track[i-1].event[s-1].metaType,e,p)),this.customInterpreter!==null&&t.track[i-1].event[s-1].data!==!1||(e.readInt(p),t.track[i-1].event[s-1].data=e.readInt(p),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((f=f.toString(16).split(""))[1]||f.unshift("0"),t.track[i-1].event[s-1].type=parseInt(f[0],16),t.track[i-1].event[s-1].channel=parseInt(f[1],16),t.track[i-1].event[s-1].type){case 15:this.customInterpreter!==null&&(t.track[i-1].event[s-1].data=this.customInterpreter(t.track[i-1].event[s-1].type,e,!1)),this.customInterpreter!==null&&t.track[i-1].event[s-1].data!==!1||($=e.readIntVLV(),t.track[i-1].event[s-1].data=e.readInt($),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:t.track[i-1].event[s-1].data=[],t.track[i-1].event[s-1].data[0]=e.readInt(1),t.track[i-1].event[s-1].data[1]=e.readInt(1);break;case 12:case 13:t.track[i-1].event[s-1].data=e.readInt(1);break;case-1:l=!0;break;default:if(this.customInterpreter!==null&&(t.track[i-1].event[s-1].data=this.customInterpreter(t.track[i-1].event[s-1].metaType,e,!1)),this.customInterpreter===null||t.track[i-1].event[s-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return t},customInterpreter:null};if(typeof v<"u")v.exports=o;else{let a=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;a.MidiParser=o}})()});var E=class{#e={};addEventListener(r,n){this.#e[r]||(this.#e[r]=[]),this.#e[r].unshift(n)}removeEventListener(r,n){if(this.#e[r]){let o=this.#e[r].indexOf(n);o>-1&&this.#e[r].splice(o,1),this.#e[r].length<1&&delete this.#e[r]}}dispatchEvent(r,n){let o=new Event(r),a=this;o.data=n,this.#e[r]?.length>0&&this.#e[r].forEach(function(e){try{e?.call(a,o)}catch(t){console.error(t)}}),this[`on${r}`]&&this[`on${r}`](o)}};var F=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]);var V=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),X={};`hi*, ka,か ki,き ku,く @@ -135,4 +135,4 @@ o,お ~, ^, _,`.split(` -`).forEach(r=>{let n=r.split(",");X[n[0]]=n[1]});var R=function(r,n,o){let a=[],e=o==!1?n.readIntVLV():o;r==0||r==127;for(let t=0;t127)return console.debug(`Early termination: ${a}`),a.pop(),n.backOne(),n.backOne(),new Uint8Array(a)}}}return new Uint8Array(a)};var K=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"];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,12,13,16,17,18,19];var z={};K.forEach((r,n)=>{z[r]=n});var m={length:k.length};k.forEach((r,n)=>{m[r]=n});var Ae={ch:128,cc:k.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,efx:7};var T=_(O(),1);var A=class{#e=!1;constructor(r,n,o,a){this.#e=r,this.start=n,this.end=o,this.data=a}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#e}},x=class extends A{constructor(r,n,o){super(!0,r,n,o)}},I=class extends A{constructor(r,n){super(!1,r,r,n)}},S=class extends Array{#e=-1;constructor(){super(...arguments)}resetIndex(r){this.#e=-1}fresh(){this.sort(function(r,n){return r.start==n.start?0:(+(r.start>n.start)<<1)-1}),this.forEach(function(r,n){r.index=n})}step(r,n=!1){let o=[];if(n)for(let a=0;ar);a++){if(this[a].ende.#e&&(o.push(t),e.#e=t.index)})}return o}getRange(r,n){r>n&&([r,n]=[n,r]);let o=[],a=-1,e=Math.ceil(Math.sqrt(this.length)),t=!0;for(let c=0;c=r&&(a=c):a=a<0?c:a;for(;t;)this[a]?.end=r&&o.push(this[a]):t=!1,a++;return o}};var q=0xffffffffffff,D=function(r){let n=new S,o=this,a=r.timeDivision,e=120,t=new S,c=0,d=0;t.push(new x(0,q,[120,0])),r.track.forEach(function(i){c=0,i.event.forEach(function(s){c+=s.deltaTime,s.type==255&&s?.metaType==81&&(e=6e7/s.data,t[t.length-1]&&t.push(new x(c,0xffffffffffff,[e,0])))})}),t.fresh(),t.forEach(function(i,s,l){s>0&&(l[s-1].end=i.start)});let $=120;t.forEach(function(i,s,l){s>0&&(i.end==i.start?l.splice(l.indexOf(i),1):$==i.data[0]&&(l[s-1].end=i.end,l.splice(l.indexOf(i),1)),$=i.data[0])});let u=0,p=120;return t.forEach(function(i){let s=i.start,l=s/p/a*60+u;p=i.data[0],u=l-s/p/a*60,i.data[1]=u}),console.debug("All tempo changes: ",t),e=120,c=0,d=0,r.track.forEach(function(i,s){c=0,d=0;let l=s+1;i.event.forEach(function(f,b){c+=f.deltaTime;let h=t.step(c,!0)[0];h&&(e=h.data[0],d=h.data[1]);let g={type:f.type,data:f.data,track:l,part:0};f.type>14?g.meta=f.metaType:g.part=f.channel,n.push(new I(c/e/a*60+d,g))})}),n.fresh(),self.midiEvents=n,console.debug(`Parsed a type ${r.formatType} MIDI sequence.`),n};T.default.customInterpreter=R;var ze=class extends E{device;#e;#i="";#s=[];#n=new Uint8ClampedArray(128);#h=new Uint8ClampedArray(128);#a=.5;#l=120;#t=4;#o=4;#r=0;#c=0;smoothingAtk=0;smoothingDcy=0;reset(){this.dispatchEvent("reset"),this.#e?.resetIndex(),this.device.init(),this.#i="",this.#a=.5,this.#l=120,this.#t=4,this.#o=4,this.#r=0,this.#c=0}async loadFile(r){this.#e=D(T.default.parse(new Uint8Array(await r.arrayBuffer())))}switchMode(r,n=!1){this.device.switchMode(r,n)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(r){return this.device.getChVoice(r)}get noteProgress(){return this.#c/this.#a}get noteOverall(){return this.noteProgress-this.#r}get noteBar(){return Math.floor(this.noteOverall/this.#t)}get noteBeat(){let r=this.noteOverall%this.#t;return r<0&&(r+=this.#t),r}getTimeSig(){return[this.#t,this.#o]}getTempo(){return this.#l}sendCmd(r){this.device.runJson(r)}render(r){r>this.#c&&(this.#c=r);let n=this.#e?.step(r)||[],o=0,a=new Set,e=this,t=[];this.device.getStrength().forEach((b,h)=>{this.#h[h]=b}),e.device.newStrength(),n.forEach(function(b){let h=b.data;h.type==9&&(h.data[1]>0?a.add(h.part*128+h.data[0]):a.has(h.part*128+h.data[0])&&o++),b.data.type==8&&a.has(h.part*128+h.data[0])&&o++;let g=e.device.runJson(h);switch(g?.reply){case"meta":{t.push(g);break}}g?.reply&&delete g.reply}),t?.length>0&&this.dispatchEvent("meta",t);let c=this.device.getActive(),d=[],$=e.device.getPitch(),u=e.device.getCcAll(),p=e.device.getProgram(),i=e.device.getChType(),s=this.device.getStrength();s.forEach(function(b,h,g){g[h]=Math.max(e.#h[h],b);let y=g[h]-e.#n[h],M=m.length*h;if(y>=0){let w=4*.25**(u[M+m[73]]/64);e.#n[h]+=Math.ceil(y-y*e.smoothingAtk**w)}else{let w=4*.25**(u[M+m[72]]/64);e.#n[h]+=Math.floor(y-y*e.smoothingDcy**w)}});let l=0;return c.forEach(function(b,h){b&&(d[h]=e.device.getVel(h),l+=d[h].size)}),{extraPoly:o,curPoly:l,chInUse:c,chKeyPr:d,chPitch:$,chProgr:p,chContr:u,chType:i,eventCount:n.length,title:this.#i,bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:this.#n.slice(),velo:s,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce()}}constructor(r,n=.5,o=.5){super();let a=this;this.smoothingAtk=n,this.smoothingDcy=o,this.device=r,this.addEventListener("meta",function(e){e?.data?.forEach(function(t){(a.#s[t.meta]||console.debug).call(a,t.meta,t.data)})}),this.device.addEventListener("mode",function(e){a.dispatchEvent("mode",e.data)}),this.device.addEventListener("channelactive",function(e){a.dispatchEvent("channelactive",e.data)}),this.device.addEventListener("channelmin",function(e){a.dispatchEvent("channelmin",e.data)}),this.device.addEventListener("channelmax",function(e){a.dispatchEvent("channelmax",e.data)}),this.device.addEventListener("channelreset",function(e){a.dispatchEvent("channelreset")}),this.device.addEventListener("screen",function(e){a.dispatchEvent("screen",e.data)}),this.#s[3]=function(e,t){a.#i?.length<1&&(a.#i=t)},this.#s[81]=function(e,t){let c=a.noteProgress,d=a.#a||.5;a.#l=6e7/t,a.#a=t/1e6,a.#r+=c*(d/a.#a)-c},this.#s[88]=function(e,t){let c=a.noteProgress,d=a.noteOverall,$=a.noteBar,u=a.noteBeat,p=a.#t,i=a.#o;a.#t=t[0],a.#o=1<=p&&(p{let n=r.split(",");X[n[0]]=n[1]});var R=function(r,n,o){let a=[],e=o==!1?n.readIntVLV():o;r==0||r==127;for(let t=0;t127)return console.debug(`Early termination: ${a}`),a.pop(),n.backOne(),n.backOne(),new Uint8Array(a)}}}return new Uint8Array(a)};var K=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"];var z=[20,21,22,23,24,25,26,28,29,30,31,36,37,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,12,13,16,17,18,19];var q={};K.forEach((r,n)=>{q[r]=n});var m={length:k.length};k.forEach((r,n)=>{m[r]=n});var Ie={ch:128,cc:k.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:z.length,dnc:72,efx:7};var T=_(O(),1);var A=class{#e=!1;constructor(r,n,o,a){this.#e=r,this.start=n,this.end=o,this.data=a}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#e}},x=class extends A{constructor(r,n,o){super(!0,r,n,o)}},I=class extends A{constructor(r,n){super(!1,r,r,n)}},S=class extends Array{#e=-1;constructor(){super(...arguments)}resetIndex(r){this.#e=-1}fresh(){this.sort(function(r,n){return r.start==n.start?0:(+(r.start>n.start)<<1)-1}),this.forEach(function(r,n){r.index=n})}step(r,n=!1){let o=[];if(n)for(let a=0;ar);a++){if(this[a].ende.#e&&(o.push(t),e.#e=t.index)})}return o}getRange(r,n){r>n&&([r,n]=[n,r]);let o=[],a=-1,e=Math.ceil(Math.sqrt(this.length)),t=!0;for(let c=0;c=r&&(a=c):a=a<0?c:a;for(;t;)this[a]?.end=r&&o.push(this[a]):t=!1,a++;return o}};var Q=0xffffffffffff,D=function(r){let n=new S,o=this,a=r.timeDivision,e=120,t=new S,c=0,d=0;t.push(new x(0,Q,[120,0])),r.track.forEach(function(i){c=0,i.event.forEach(function(s){c+=s.deltaTime,s.type==255&&s?.metaType==81&&(e=6e7/s.data,t[t.length-1]&&t.push(new x(c,0xffffffffffff,[e,0])))})}),t.fresh(),t.forEach(function(i,s,l){s>0&&(l[s-1].end=i.start)});let $=120;t.forEach(function(i,s,l){s>0&&(i.end==i.start?l.splice(l.indexOf(i),1):$==i.data[0]&&(l[s-1].end=i.end,l.splice(l.indexOf(i),1)),$=i.data[0])});let u=0,p=120;return t.forEach(function(i){let s=i.start,l=s/p/a*60+u;p=i.data[0],u=l-s/p/a*60,i.data[1]=u}),console.debug("All tempo changes: ",t),e=120,c=0,d=0,r.track.forEach(function(i,s){c=0,d=0;let l=s+1;i.event.forEach(function(f,b){c+=f.deltaTime;let h=t.step(c,!0)[0];h&&(e=h.data[0],d=h.data[1]);let g={type:f.type,data:f.data,track:l,part:0};f.type>14?g.meta=f.metaType:g.part=f.channel,n.push(new I(c/e/a*60+d,g))})}),n.fresh(),self.midiEvents=n,console.debug(`Parsed a type ${r.formatType} MIDI sequence.`),n};T.default.customInterpreter=R;var qe=class extends E{device;#e;#i="";#s=[];#n=new Uint8ClampedArray(128);#h=new Uint8ClampedArray(128);#a=.5;#l=120;#t=4;#o=4;#r=0;#c=0;smoothingAtk=0;smoothingDcy=0;reset(){this.dispatchEvent("reset"),this.#e?.resetIndex(),this.device.init(),this.#i="",this.#a=.5,this.#l=120,this.#t=4,this.#o=4,this.#r=0,this.#c=0}async loadFile(r){this.#e=D(T.default.parse(new Uint8Array(await r.arrayBuffer())))}switchMode(r,n=!1){this.device.switchMode(r,n)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(r){return this.device.getChVoice(r)}get noteProgress(){return this.#c/this.#a}get noteOverall(){return this.noteProgress-this.#r}get noteBar(){return Math.floor(this.noteOverall/this.#t)}get noteBeat(){let r=this.noteOverall%this.#t;return r<0&&(r+=this.#t),r}getTimeSig(){return[this.#t,this.#o]}getTempo(){return this.#l}sendCmd(r){this.device.runJson(r)}render(r){r>this.#c&&(this.#c=r);let n=this.#e?.step(r)||[],o=0,a=new Set,e=this,t=[];this.device.getStrength().forEach((b,h)=>{this.#h[h]=b}),e.device.newStrength(),n.forEach(function(b){let h=b.data;h.type==9&&(h.data[1]>0?a.add(h.part*128+h.data[0]):a.has(h.part*128+h.data[0])&&o++),b.data.type==8&&a.has(h.part*128+h.data[0])&&o++;let g=e.device.runJson(h);switch(g?.reply){case"meta":{t.push(g);break}}g?.reply&&delete g.reply}),t?.length>0&&this.dispatchEvent("meta",t);let c=this.device.getActive(),d=[],$=e.device.getPitch(),u=e.device.getCcAll(),p=e.device.getProgram(),i=e.device.getChType(),s=this.device.getStrength();s.forEach(function(b,h,g){g[h]=Math.max(e.#h[h],b);let y=g[h]-e.#n[h],M=m.length*h;if(y>=0){let w=4*.25**(u[M+m[73]]/64);e.#n[h]+=Math.ceil(y-y*e.smoothingAtk**w)}else{let w=4*.25**(u[M+m[72]]/64);e.#n[h]+=Math.floor(y-y*e.smoothingDcy**w)}});let l=0;return c.forEach(function(b,h){b&&(d[h]=e.device.getVel(h),l+=d[h].size)}),{extraPoly:o,curPoly:l,chInUse:c,chKeyPr:d,chPitch:$,chProgr:p,chContr:u,chType:i,eventCount:n.length,title:this.#i,bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:this.#n.slice(),velo:s,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce()}}constructor(r,n=.5,o=.5){super();let a=this;this.smoothingAtk=n,this.smoothingDcy=o,this.device=r,this.addEventListener("meta",function(e){e?.data?.forEach(function(t){(a.#s[t.meta]||console.debug).call(a,t.meta,t.data)})}),this.device.addEventListener("mode",function(e){a.dispatchEvent("mode",e.data)}),this.device.addEventListener("channelactive",function(e){a.dispatchEvent("channelactive",e.data)}),this.device.addEventListener("channelmin",function(e){a.dispatchEvent("channelmin",e.data)}),this.device.addEventListener("channelmax",function(e){a.dispatchEvent("channelmax",e.data)}),this.device.addEventListener("channelreset",function(e){a.dispatchEvent("channelreset")}),this.device.addEventListener("screen",function(e){a.dispatchEvent("screen",e.data)}),this.#s[3]=function(e,t){a.#i?.length<1&&(a.#i=t)},this.#s[81]=function(e,t){let c=a.noteProgress,d=a.#a||.5;a.#l=6e7/t,a.#a=t/1e6,a.#r+=c*(d/a.#a)-c},this.#s[88]=function(e,t){let c=a.noteProgress,d=a.noteOverall,$=a.noteBar,u=a.noteBeat,p=a.#t,i=a.#o;a.#t=t[0],a.#o=1<=p&&(p()=>(n||e((n={exports:{}}).exports,n),n.exports);var Se=(e,n,o,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of ve(n))!Ee.call(e,i)&&i!==o&&Q(e,i,{get:()=>n[i],enumerable:!(t=me(n,i))||t.enumerable});return e};var xe=(e,n,o)=>(o=e!=null?ye(we(e)):{},Se(n||!e||!e.__esModule?Q(o,"default",{value:e,enumerable:!0}):o,e));var ue=ke((at,F)=>{(function(){"use strict";let e={fatal:!0},n=[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(t,i){if(t instanceof Uint8Array)return o.Uint8(t);if(typeof t=="string")return o.Base64(t);if(t instanceof HTMLElement&&t.type==="file")return o.addListener(t,i);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(t,i){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(t===void 0||!(t instanceof HTMLElement)||t.tagName!=="INPUT"||t.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;i=i||function(){},t.addEventListener("change",function(a){if(!a.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let s=new FileReader;s.readAsArrayBuffer(a.target.files[0]),s.onload=function(r){i(o.Uint8(new Uint8Array(r.target.result)))}})},Base64:function(t){let i=function(r){var c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(r=r.replace(/^.*?base64,/,""),r=String(r).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(r))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");r+="==".slice(2-(3&r.length));let h,l="",d,u,g=0;for(;g>16&255):u===64?String.fromCharCode(h>>16&255,h>>8&255):String.fromCharCode(h>>16&255,h>>8&255,255&h);return l}(t=String(t));var a=i.length;let s=new Uint8Array(new ArrayBuffer(a));for(let r=0;r{u[$]=this.readInt(1)});for(let m=0;m191||v>127&&v<160)throw new RangeError(`Invalid code point: ${v}`)}g=!0,console.debug(`String byte sequence in ${n[m].encoding}`)}catch($){console.debug(`SMF string ${$}`)}return b||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let d=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)d=this.readInt(1);else{let g=[];for(;128<=this.data.getUint8(this.pointer);)g.push(this.readInt(1)-128);var u=this.readInt(1);for(let b=1;b<=g.length;b++)d+=g[g.length-b]*Math.pow(128,b);d+=u}return d}};if(i.data=new DataView(s.buffer,s.byteOffset,s.byteLength),i.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;i.readInt(4);let a={};a.formatType=i.readInt(2),a.tracks=i.readInt(2),a.track=[];var s=i.readInt(1),r=i.readInt(1);128<=s?(a.timeDivision=[],a.timeDivision[0]=s-128,a.timeDivision[1]=r):a.timeDivision=256*s+r;for(let d=1;d<=a.tracks;d++){a.track[d-1]={event:[]};var c,h=i.readInt(4);if(h===-1)break;if(h!==1297379947)return!1;i.readInt(4);let u=0,g=!1,b,m;for(;!g&&(u++,a.track[d-1].event[u-1]={},a.track[d-1].event[u-1].deltaTime=i.readIntVLV(),(b=i.readInt(1))!==-1);)if(128<=b?m=b:(b=m,i.movePointer(-1)),b===255){a.track[d-1].event[u-1].type=255,a.track[d-1].event[u-1].metaType=i.readInt(1);var l=i.readIntVLV();switch(a.track[d-1].event[u-1].metaType){case 47:case-1:g=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:a.track[d-1].event[u-1].data=i.readStr(l);break;case 33:case 89:case 81:a.track[d-1].event[u-1].data=i.readInt(l);break;case 84:a.track[d-1].event[u-1].data=[],a.track[d-1].event[u-1].data[0]=i.readInt(1),a.track[d-1].event[u-1].data[1]=i.readInt(1),a.track[d-1].event[u-1].data[2]=i.readInt(1),a.track[d-1].event[u-1].data[3]=i.readInt(1),a.track[d-1].event[u-1].data[4]=i.readInt(1);break;case 88:a.track[d-1].event[u-1].data=[],a.track[d-1].event[u-1].data[0]=i.readInt(1),a.track[d-1].event[u-1].data[1]=i.readInt(1),a.track[d-1].event[u-1].data[2]=i.readInt(1),a.track[d-1].event[u-1].data[3]=i.readInt(1);break;default:this.customInterpreter!==null&&(a.track[d-1].event[u-1].data=this.customInterpreter(a.track[d-1].event[u-1].metaType,i,l)),this.customInterpreter!==null&&a.track[d-1].event[u-1].data!==!1||(i.readInt(l),a.track[d-1].event[u-1].data=i.readInt(l),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((b=b.toString(16).split(""))[1]||b.unshift("0"),a.track[d-1].event[u-1].type=parseInt(b[0],16),a.track[d-1].event[u-1].channel=parseInt(b[1],16),a.track[d-1].event[u-1].type){case 15:this.customInterpreter!==null&&(a.track[d-1].event[u-1].data=this.customInterpreter(a.track[d-1].event[u-1].type,i,!1)),this.customInterpreter!==null&&a.track[d-1].event[u-1].data!==!1||(c=i.readIntVLV(),a.track[d-1].event[u-1].data=i.readInt(c),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[d-1].event[u-1].data=[],a.track[d-1].event[u-1].data[0]=i.readInt(1),a.track[d-1].event[u-1].data[1]=i.readInt(1);break;case 12:case 13:a.track[d-1].event[u-1].data=i.readInt(1);break;case-1:g=!0;break;default:if(this.customInterpreter!==null&&(a.track[d-1].event[u-1].data=this.customInterpreter(a.track[d-1].event[u-1].metaType,i,!1)),this.customInterpreter===null||a.track[d-1].event[u-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return a},customInterpreter:null};if(typeof F<"u")F.exports=o;else{let t=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;t.MidiParser=o}})()});var A=class{#t={};addEventListener(e,n){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(n)}removeEventListener(e,n){if(this.#t[e]){let o=this.#t[e].indexOf(n);o>-1&&this.#t[e].splice(o,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,n){let o=new Event(e),t=this;o.data=n,this.#t[e]?.length>0&&this.#t[e].forEach(function(i){try{i?.call(t,o)}catch(a){console.error(a)}}),this[`on${e}`]&&this[`on${e}`](o)}};var W=function(e,n){let o=Math.min(e.length,n.length),t=e.slice(0,o),i=n.slice(0,o),a=0,s=0;for(;s0){let o=this.pool.length,t=1<=1&&a>=0;){if(a<=0)throw new Error("TTL reached.");if(i==o)i-=t;else{let r=W(e,this.pool[i]);switch(r){case 0:{a=0;break}case 1:{i+t<=o&&(i+=t);break}case-1:{i!=0&&(i-=t);break}default:console.warn(`Unexpected result ${r}.`)}}t=t>>1,a--}let s=!0;if(i>=this.pool.length)s=!1;else{let r=this;this.pool[i].forEach(function(c,h,l){s&&c!=e[h]&&(s=!1)}),!s&&W(e,this.pool[i])>0&&i++}return s||n?i:-1}else return n?0:-1},this.add=function(e,n){return e.data=n,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match for "${e}". Default action not defined.`)},this.get=function(e){let n=this.point(e);if(n>-1)return this.pool[n].data;this.default(e)},this.run=function(e,...n){let o=this.point(e);o>-1?this.pool[o].data(e.slice(this.pool[o].length),...n):this.default(e,...n)}};var Te=["MSB","PRG","LSB"];var I=function(e){let n=Math.floor(e/10),o=e%10;return`${n.toString(16)}${o}`},U=class{#t;strictMode=!1;get(e=0,n=0,o=0,t){let i,a=Array.from(arguments);switch(t){case"xg":{e==32?a[2]+=4:e==33||e==35||e==36?a[2]+=5:e==79?a[0]=95:e==80?a[0]=96:e==81?a[0]=97:e==82?a[0]=98:e==83?a[0]=99:e==84&&(a[0]=100);break}case"gs":{e==0&&o<5?a[2]=0:e>125&&o<5&&o!=2&&(a[2]=e,a[0]=0);break}case"sg":{e==8&&o==0&&(a[2]=5);break}}let s=" ",r="M",c=!1,h=0;switch(a[0]){case 0:{a[2]==127?r="MT-a":a[2]==126?r="MT-b":a[2]==7?r="GM-k":a[2]==5?r="SG-a":a[2]==4?r="SP-l":a[2]==0||t=="gs"&&a[2]<5?r="GM-a":(r="y",c=!0);break}case 8:{t=="sg"?r="GM-s":r="r:";break}case 48:{r=`yM${(a[2]>>3).toString().padStart(2,"0")}`,c=!0;break}case 56:{r="GM-b";break}case 61:case 120:{r="rDrm";break}case 62:{r="kDrm";break}case 63:{let d=a[2];r=d<10?"kP:":"kC:",r+=d%10;break}case 64:{r="ySFX";break}case 67:{r="DX:S";break}case 80:case 81:case 82:case 83:{r=`Prg${"UABC"[a[0]-80]}`;break}case 88:case 89:case 90:case 91:{r=`Cmb${"UABC"[a[0]-88]}`;break}case 95:{r=`${["DR","PC"][a[2]]}-d`;break}case 96:{r=a[2]==106?"AP-a":"PF",a[2]>63&&(h=63),c=!0;break}case 97:{r="VL:",c=!0,h=112;break}case 98:{r="SG-a";break}case 99:{r="DX",a[2]>63&&(h=63),c=!0;break}case 100:{r="AN",a[2]>63&&(h=63),c=!0;break}case 121:{r=`GM-${a[2]?"":"a"}`,c=!0;break}case 122:{r="lDrm";break}case 126:{r="yDrS";break}case 127:{a[2]==127?r="rDrm":r="yDrm";break}default:a[0]<48?r="r:":r="M"}for(r.length<4&&(r+=`${(c?o:e)-h}`.padStart(4-r.length,"0")),t=="xg"&&e==16&&(i=`Voice${(o*128+n+1).toString().padStart(3,"0")}`,s=" ");!(i?.length>=0);)i=this.#t[a[1]||0][(a[0]<<7)+a[2]],i||(this.strictMode?(i="",s="?"):this.#t[a[1]||0][a[0]<<7]?a[0]==0?(a[2]=0,s="^"):a[2]<1?(a[0]=0,s="*"):(a[2]--,s="^"):e==48?(a[0]=0,a[2]=0,s="!"):e==62?(a[1]--,s=" ",a[1]<1&&!i?.length&&(a[0]=0,s="!")):e<64?a[0]==0?(a[2]=0,s="^"):a[2]<1?(a[0]=0,s="*"):a[2]--:e==80?(i=`PrgU:${n.toString().padStart(3,"0")}`,s="!"):e==88?(i=`CmbU:${n.toString().padStart(3,"0")}`,s="!"):e==121?(i=`GM2Vox0${o}`,s="#"):e==122?(a[1]==32?a[1]==0:a[1]%=7,i=this.#t[a[1]||0][(a[0]<<7)+a[2]],i?s=" ":(i="",s="*")):a[1]==0?(i=`${e.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")}`,s="!"):a[0]==0?(a[2]=0,s="^"):a[2]>0?a[2]--:a[1]>0?(a[1]=0,s="!"):(a[0]=0,s="?"));(t=="gs"||t=="ns5r")&&s=="^"&&(s=" "),e==127&&s=="^"&&(s=" "),s!=" "&&self.debugMode&&(i="");let l="??";switch(a[0]){case 0:{a[2]==0?l="GM":a[2]==5||a[2]==7?l="KG":a[2]<120?l="XG":a[2]==127&&(l="MT");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:l="KR";case 64:case 126:{l="XG";break}case 67:case 99:{l="DX";break}case 81:{l="RW";break}case 95:{l=["DR","PC"][a[2]];break}case 96:{l=a[2]==106?"AP":"PF";break}case 97:{l="VL";break}case 98:{l="SG";break}case 100:{l="AN";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":n==0?"GM":"XG";break}default:a[0]<48&&(a[0]==16&&t=="xg"?l="XG":l="GS")}return{name:i||`${I(e||0)} ${I(n||0)} ${I(o||0)}`,ending:s,sect:r,standard:l}}async load(e,n,o){let t=this,i=[],a=0,s=0;e.split(` -`).forEach(function(r,c){let h=r.split(" "),l=[];c==0?h.forEach(function(d,u){i[Te.indexOf(d)]=u}):h.forEach(async function(d,u){u>2?(t.#t[l[i[1]]]=t.#t[l[i[1]]]||[],(!t.#t[l[i[1]]][(l[i[0]]<<7)+l[i[2]]]?.length||n)&&(t.#t[l[i[1]]][(l[i[0]]<<7)+l[i[2]]]=h[3],a++),s++):l.push(parseInt(h[u]))})}),n||console.debug(`Map "${o||"(internal)"}": ${s} total, ${a} loaded.`)}clearRange(e){let n=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],o=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],t=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let i=o[0];i<=o[1];i++){let a=i<<7;for(let s=t[0];s<=t[1];s++){let r=a+s;for(let c=n[0];c<=n[1];c++)delete this.#t[c][r]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let n=this;e.forEach(async function(o,t){try{await fetch(`./data/bank/${o}.tsv`).then(function(i){return i.text()}).then(i=>{n.load(i,!1,o)})}catch{console.error(`Failed loading "${o}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var C=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),N=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],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],R=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],q=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],j=function(e){let n=.1,o=-.3;return e>66?(n=5,o=315):e>56?(n=1,o=47):e>46&&(n=.5,o=18.5),n*e-o},Y=function(e){return e>105?Me[e-106]:e>100?e*1.1-100:e/10},Z=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),L={};`hi*, +var ye=Object.create;var Q=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var ve=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,Ee=Object.prototype.hasOwnProperty;var ke=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports);var Se=(e,n,o,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of ve(n))!Ee.call(e,i)&&i!==o&&Q(e,i,{get:()=>n[i],enumerable:!(t=me(n,i))||t.enumerable});return e};var xe=(e,n,o)=>(o=e!=null?ye(we(e)):{},Se(n||!e||!e.__esModule?Q(o,"default",{value:e,enumerable:!0}):o,e));var ue=ke((at,F)=>{(function(){"use strict";let e={fatal:!0},n=[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(t,i){if(t instanceof Uint8Array)return o.Uint8(t);if(typeof t=="string")return o.Base64(t);if(t instanceof HTMLElement&&t.type==="file")return o.addListener(t,i);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(t,i){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(t===void 0||!(t instanceof HTMLElement)||t.tagName!=="INPUT"||t.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;i=i||function(){},t.addEventListener("change",function(r){if(!r.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let s=new FileReader;s.readAsArrayBuffer(r.target.files[0]),s.onload=function(a){i(o.Uint8(new Uint8Array(a.target.result)))}})},Base64:function(t){let i=function(a){var c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(a=a.replace(/^.*?base64,/,""),a=String(a).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(a))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");a+="==".slice(2-(3&a.length));let h,l="",d,u,g=0;for(;g>16&255):u===64?String.fromCharCode(h>>16&255,h>>8&255):String.fromCharCode(h>>16&255,h>>8&255,255&h);return l}(t=String(t));var r=i.length;let s=new Uint8Array(new ArrayBuffer(r));for(let a=0;a{u[$]=this.readInt(1)});for(let m=0;m191||v>127&&v<160)throw new RangeError(`Invalid code point: ${v}`)}g=!0,console.debug(`String byte sequence in ${n[m].encoding}`)}catch($){console.debug(`SMF string ${$}`)}return b||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let d=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)d=this.readInt(1);else{let g=[];for(;128<=this.data.getUint8(this.pointer);)g.push(this.readInt(1)-128);var u=this.readInt(1);for(let b=1;b<=g.length;b++)d+=g[g.length-b]*Math.pow(128,b);d+=u}return d}};if(i.data=new DataView(s.buffer,s.byteOffset,s.byteLength),i.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;i.readInt(4);let r={};r.formatType=i.readInt(2),r.tracks=i.readInt(2),r.track=[];var s=i.readInt(1),a=i.readInt(1);128<=s?(r.timeDivision=[],r.timeDivision[0]=s-128,r.timeDivision[1]=a):r.timeDivision=256*s+a;for(let d=1;d<=r.tracks;d++){r.track[d-1]={event:[]};var c,h=i.readInt(4);if(h===-1)break;if(h!==1297379947)return!1;i.readInt(4);let u=0,g=!1,b,m;for(;!g&&(u++,r.track[d-1].event[u-1]={},r.track[d-1].event[u-1].deltaTime=i.readIntVLV(),(b=i.readInt(1))!==-1);)if(128<=b?m=b:(b=m,i.movePointer(-1)),b===255){r.track[d-1].event[u-1].type=255,r.track[d-1].event[u-1].metaType=i.readInt(1);var l=i.readIntVLV();switch(r.track[d-1].event[u-1].metaType){case 47:case-1:g=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:r.track[d-1].event[u-1].data=i.readStr(l);break;case 33:case 89:case 81:r.track[d-1].event[u-1].data=i.readInt(l);break;case 84:r.track[d-1].event[u-1].data=[],r.track[d-1].event[u-1].data[0]=i.readInt(1),r.track[d-1].event[u-1].data[1]=i.readInt(1),r.track[d-1].event[u-1].data[2]=i.readInt(1),r.track[d-1].event[u-1].data[3]=i.readInt(1),r.track[d-1].event[u-1].data[4]=i.readInt(1);break;case 88:r.track[d-1].event[u-1].data=[],r.track[d-1].event[u-1].data[0]=i.readInt(1),r.track[d-1].event[u-1].data[1]=i.readInt(1),r.track[d-1].event[u-1].data[2]=i.readInt(1),r.track[d-1].event[u-1].data[3]=i.readInt(1);break;default:this.customInterpreter!==null&&(r.track[d-1].event[u-1].data=this.customInterpreter(r.track[d-1].event[u-1].metaType,i,l)),this.customInterpreter!==null&&r.track[d-1].event[u-1].data!==!1||(i.readInt(l),r.track[d-1].event[u-1].data=i.readInt(l),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((b=b.toString(16).split(""))[1]||b.unshift("0"),r.track[d-1].event[u-1].type=parseInt(b[0],16),r.track[d-1].event[u-1].channel=parseInt(b[1],16),r.track[d-1].event[u-1].type){case 15:this.customInterpreter!==null&&(r.track[d-1].event[u-1].data=this.customInterpreter(r.track[d-1].event[u-1].type,i,!1)),this.customInterpreter!==null&&r.track[d-1].event[u-1].data!==!1||(c=i.readIntVLV(),r.track[d-1].event[u-1].data=i.readInt(c),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[d-1].event[u-1].data=[],r.track[d-1].event[u-1].data[0]=i.readInt(1),r.track[d-1].event[u-1].data[1]=i.readInt(1);break;case 12:case 13:r.track[d-1].event[u-1].data=i.readInt(1);break;case-1:g=!0;break;default:if(this.customInterpreter!==null&&(r.track[d-1].event[u-1].data=this.customInterpreter(r.track[d-1].event[u-1].metaType,i,!1)),this.customInterpreter===null||r.track[d-1].event[u-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return r},customInterpreter:null};if(typeof F<"u")F.exports=o;else{let t=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;t.MidiParser=o}})()});var A=class{#t={};addEventListener(e,n){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(n)}removeEventListener(e,n){if(this.#t[e]){let o=this.#t[e].indexOf(n);o>-1&&this.#t[e].splice(o,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,n){let o=new Event(e),t=this;o.data=n,this.#t[e]?.length>0&&this.#t[e].forEach(function(i){try{i?.call(t,o)}catch(r){console.error(r)}}),this[`on${e}`]&&this[`on${e}`](o)}};var W=function(e,n){let o=Math.min(e.length,n.length),t=e.slice(0,o),i=n.slice(0,o),r=0,s=0;for(;s0){let o=this.pool.length,t=1<=1&&r>=0;){if(r<=0)throw new Error("TTL reached.");if(i==o)i-=t;else{let a=W(e,this.pool[i]);switch(a){case 0:{r=0;break}case 1:{i+t<=o&&(i+=t);break}case-1:{i!=0&&(i-=t);break}default:console.warn(`Unexpected result ${a}.`)}}t=t>>1,r--}let s=!0;if(i>=this.pool.length)s=!1;else{let a=this;this.pool[i].forEach(function(c,h,l){s&&c!=e[h]&&(s=!1)}),!s&&W(e,this.pool[i])>0&&i++}return s||n?i:-1}else return n?0:-1},this.add=function(e,n){return e.data=n,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match for "${e}". Default action not defined.`)},this.get=function(e){let n=this.point(e);if(n>-1)return this.pool[n].data;this.default(e)},this.run=function(e,...n){let o=this.point(e);o>-1?this.pool[o].data(e.slice(this.pool[o].length),...n):this.default(e,...n)}};var Te=["MSB","PRG","LSB"];var I=function(e){let n=Math.floor(e/10),o=e%10;return`${n.toString(16)}${o}`},U=class{#t;strictMode=!1;get(e=0,n=0,o=0,t){let i,r=Array.from(arguments);switch(t){case"xg":{e==32?r[2]+=4:e==33||e==35||e==36?r[2]+=5:e==79?r[0]=95:e==80?r[0]=96:e==81?r[0]=97:e==82?r[0]=98:e==83?r[0]=99:e==84&&(r[0]=100);break}case"gs":{e==0&&o<5?r[2]=0:e>125&&o<5&&o!=2&&(r[2]=e,r[0]=0);break}case"sg":{e==8&&o==0&&(r[2]=5);break}}let s=" ",a="M",c=!1,h=0;switch(r[0]){case 0:{r[2]==127?a="MT-a":r[2]==126?a="MT-b":r[2]==7?a="GM-k":r[2]==5?a="SG-a":r[2]==4?a="SP-l":r[2]==0||t=="gs"&&r[2]<5?a="GM-a":(a="y",c=!0);break}case 8:{t=="sg"?a="GM-s":a="r:";break}case 48:{a=`yM${(r[2]>>3).toString().padStart(2,"0")}`,c=!0;break}case 56:{a="GM-b";break}case 61:case 120:{a="rDrm";break}case 62:{a="kDrm";break}case 63:{let d=r[2];a=d<10?"kP:":"kC:",a+=d%10;break}case 64:{a="ySFX";break}case 67:{a="DX:S";break}case 80:case 81:case 82:case 83:{a=`Prg${"UABC"[r[0]-80]}`;break}case 88:case 89:case 90:case 91:{a=`Cmb${"UABC"[r[0]-88]}`;break}case 95:{a=`${["DR","PC"][r[2]]}-d`;break}case 96:{a=r[2]==106?"AP-a":"PF",r[2]>63&&(h=63),c=!0;break}case 97:{a="VL:",c=!0,h=112;break}case 98:{a="SG-a";break}case 99:{a="DX",r[2]>63&&(h=63),c=!0;break}case 100:{a="AN",r[2]>63&&(h=63),c=!0;break}case 121:{a=`GM-${r[2]?"":"a"}`,c=!0;break}case 122:{a="lDrm";break}case 126:{a="yDrS";break}case 127:{r[2]==127?a="rDrm":a="yDrm";break}default:r[0]<48?a="r:":a="M"}for(a.length<4&&(a+=`${(c?o:e)-h}`.padStart(4-a.length,"0")),t=="xg"&&e==16&&(i=`Voice${(o*128+n+1).toString().padStart(3,"0")}`,s=" ");!(i?.length>=0);)i=this.#t[r[1]||0][(r[0]<<7)+r[2]],i||(this.strictMode?(i="",s="?"):this.#t[r[1]||0][r[0]<<7]?r[0]==0?(r[2]=0,s="^"):r[2]<1?(r[0]=0,s="*"):(r[2]--,s="^"):e==48?(r[0]=0,r[2]=0,s="!"):e==62?(r[1]--,s=" ",r[1]<1&&!i?.length&&(r[0]=0,s="!")):e<64?r[0]==0?(r[2]=0,s="^"):r[2]<1?(r[0]=0,s="*"):r[2]--:e==80?(i=`PrgU:${n.toString().padStart(3,"0")}`,s="!"):e==88?(i=`CmbU:${n.toString().padStart(3,"0")}`,s="!"):e==121?(i=`GM2Vox0${o}`,s="#"):e==122?(r[1]==32?r[1]==0:r[1]%=7,i=this.#t[r[1]||0][(r[0]<<7)+r[2]],i?s=" ":(i="",s="*")):r[1]==0?(i=`${e.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")}`,s="!"):r[0]==0?(r[2]=0,s="^"):r[2]>0?r[2]--:r[1]>0?(r[1]=0,s="!"):(r[0]=0,s="?"));(t=="gs"||t=="ns5r")&&s=="^"&&(s=" "),e==127&&s=="^"&&(s=" "),s!=" "&&self.debugMode&&(i="");let l="??";switch(r[0]){case 0:{r[2]==0?l="GM":r[2]==5||r[2]==7?l="KG":r[2]<120?l="XG":r[2]==127&&(l="MT");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:l="KR";case 64:case 126:{l="XG";break}case 67:case 99:{l="DX";break}case 81:{l="RW";break}case 95:{l=["DR","PC"][r[2]];break}case 96:{l=r[2]==106?"AP":"PF";break}case 97:{l="VL";break}case 98:{l="SG";break}case 100:{l="AN";break}case 120:{l="GS";break}case 121:{l=r[2]?"G2":"GM";break}case 122:{l="KG";break}case 127:{l=r[2]==127?"MT":n==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&t=="xg"?l="XG":l="GS")}return{name:i||`${I(e||0)} ${I(n||0)} ${I(o||0)}`,ending:s,sect:a,standard:l}}async load(e,n,o){let t=this,i=[],r=0,s=0;e.split(` +`).forEach(function(a,c){let h=a.split(" "),l=[];c==0?h.forEach(function(d,u){i[Te.indexOf(d)]=u}):h.forEach(async function(d,u){u>2?(t.#t[l[i[1]]]=t.#t[l[i[1]]]||[],(!t.#t[l[i[1]]][(l[i[0]]<<7)+l[i[2]]]?.length||n)&&(t.#t[l[i[1]]][(l[i[0]]<<7)+l[i[2]]]=h[3],r++),s++):l.push(parseInt(h[u]))})}),n||console.debug(`Map "${o||"(internal)"}": ${s} total, ${r} loaded.`)}clearRange(e){let n=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],o=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],t=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let i=o[0];i<=o[1];i++){let r=i<<7;for(let s=t[0];s<=t[1];s++){let a=r+s;for(let c=n[0];c<=n[1];c++)delete this.#t[c][a]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let n=this;e.forEach(async function(o,t){try{await fetch(`./data/bank/${o}.tsv`).then(function(i){return i.text()}).then(i=>{n.load(i,!1,o)})}catch{console.error(`Failed loading "${o}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var C=["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"]),L=["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],R=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],q=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],j=function(e){let n=.1,o=-.3;return e>66?(n=5,o=315):e>56?(n=1,o=47):e>46&&(n=.5,o=18.5),n*e-o},Y=function(e){return e>105?Me[e-106]:e>100?e*1.1-100:e/10},Z=",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(","),N={};`hi*, ka,か ki,き ku,く @@ -136,8 +136,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let n=e.split(",");L[n[0]]=n[1]});var J=function(e){let n=e;e[0]=="*"&&(n=n.slice(1)),["aa","ii","uu","ee","oo"].forEach(t=>{for(;n.indexOf(t)>-1;)n=n.replace(t,t[0])});for(let t in L)n=n.replaceAll(t,L[t]);n.indexOf("ん")==0&&n.length>1&&(n=n.slice(1));let o=n.indexOf("!");return o>-1&&n.length>1&&(n=n.slice(o+1)),n},ee=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var B=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],te=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],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 Ce={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"},Re={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]]},H=function(e){return Ce[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ae=function(e,n,o){let t=(e[0]-32<<16)+(e[1]<<8)+n,i=Re[t]||{},a=i[0];if(a?.length)return a+=`: ${(i[1]||function(){})(o)||o}`,a},G=[68,48,95,78,41,3,110,122,0];var w=function(e=64){return Math.round(2e3*Math.log10(e/64))/100},re=function(e,n,o){let t=[],i=o==!1?n.readIntVLV():o;e==0||e==127;for(let a=0;a127)return console.debug(`Early termination: ${t}`),t.pop(),n.backOne(),n.backOne(),new Uint8Array(t)}}}return new Uint8Array(t)},se=function(e){let n=0;return e.forEach(o=>{n+=o,n=n&127}),~n+1&127},S=function(e,n){let o=0,t=0;for(let i=0;i>a&1)<<7,r=e[i];r+=s,i%8!=0?(n(r,o,e),o++):t=e[i]}},O=function(e){let n=Math.floor(e*14.2);return n<128?n:0};var T=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],ne=[[0,0,0,0,121,0,0,56,82,81,63,0,0],[0,0,4,0,0,127,0,0,0,0,0,0,0]],x=[120,127,120,127,120,127,61,62,62,62,120,122,122],Oe=[0,3,81,84,88],oe={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},_={0:0,1:1,2:3,5:4},ce=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],le=[36,37];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,12,13,16,17,18,19],Pe=[12,13,16,17,18,19],Ae=[33,99,100,32,102,8,9,10],he=[0,16,25,40,32,64,26,48],y={};T.forEach((e,n)=>{y[e]=n});var f={length:P.length};P.forEach((e,n)=>{f[e]=n});var E=function(){return!!self.Bun||self.debugMode||!1},De=function(e){let n=[],o=0;return e?.forEach(function(t,i){t==247?n.push(e.subarray(o,i)):t==240&&(o=i+1)}),n.length||n.push(e.subarray(0)),E()&&console.debug(n),n},de=function(e,n="",o="",t=2){return e?`${n}${e.toString().padStart(t,"0")}${o}`:""},p={ch:128,cc:P.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,efx:7},fe=class extends A{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#n=0;#h=0;#p=new Array(11);get#g(){return this.#p[this.#n]}set#g(e){this.#p[this.#n]=e}#c=new Uint8Array(p.ch);#l=new Uint8Array(p.ch);#a=new Uint8Array(p.ch);#e=new Uint8Array(p.ch*p.cc);#b=new Uint8Array(p.ace);#s=new Uint8Array(p.ch);#d=new Uint8Array(p.ch*p.nn);#S=new Uint8Array(p.ch);#f=new Uint16Array(p.pl);#$=new Uint8Array(p.pl);#A=new Int16Array(p.ch);#x=new Uint8Array(p.ch);#H=0;#i=new Uint8Array(p.ch*p.rpn);#_=new Int8Array(p.ch*le.length);#T=new Uint8Array(p.ch);#D=new Uint8Array(128);#w=new Uint8Array(p.cmt*8);#F=new Uint8Array(1024);#I=new Uint8Array(p.cmt*64);#m=new Uint8Array(p.efx*3);#U=0;#E=0;#v=100;#C=0;#V=500;#X=0;#M="";#L=0;#K=0;#k=!0;#o=!1;#Y;#ee=new Uint8Array(2);#r=[];#R=new Uint8Array(p.ch);#N=new Uint8Array(p.tr);baseBank=new U("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new U("gm");initOnReset=!1;aiEfxName="";chRedir(e,n,o){if(this.#N[n])return(this.#N[n]-1)*16+e;if([2,3].indexOf(this.#E)>-1){if(o==1)return e;let t=0,i=!0;for(;i;)this.#R[e+t]==0?(this.#R[e+t]=n,console.debug(`Assign track ${n} to channel ${e+t+1}.`),i=!1):this.#R[e+t]==n?i=!1:(t+=16,t>=128&&(t=0,i=!1));return e+t}else return e}#y=[];#G;#u={nOff:(e,n)=>{let o=e*128+n,t=this.#f.lastIndexOf(o);t>-1&&(this.#e[p.cc*e+f[64]]>63?(this.#$[t]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#d[o],state:this.NOTE_HELD})):this.#e[p.cc*e+f[66]]>63&&this.#$[t]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#$[t]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#d[o],state:this.NOTE_SOSTENUTO_HELD})):(this.#f[t]=0,this.#d[o]=0,this.#$[t]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:n,velo:0,state:this.NOTE_IDLE})))},nOn:(e,n,o)=>{let t=e*128+n,i=0;for(this.#S[e]&&this.#u.ano(e);this.#$[i]>0&&this.#f[i]!=t;)i++;i{},cAt:(e,n)=>{},hoOf:e=>{this.#$.forEach((n,o)=>{if(n==this.NOTE_HELD){let t=this.#f[o],i=t>>7;e==i&&(this.#$[o]=this.NOTE_IDLE,this.#f[o]=0,this.#d[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#$.forEach((n,o)=>{let t;switch(n){case this.NOTE_ATTACK:{t=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{t=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{t=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(t){this.#$[o]=t;let i=this.#f[o];this.dispatchEvent("note",{part:e,note:i&127,velo:this.#d[i],state:t})}})},soOf:e=>{this.#$.forEach((n,o)=>{if(n==this.NOTE_SOSTENUTO_HELD){let t=this.#f[o],i=t>>7;e==i&&(this.#$[o]=this.NOTE_IDLE,this.#f[o]=0,this.#d[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#f.forEach((n,o,t)=>{let i=n>>7,a=n&127;n==0&&this.#d[0]==0||i==e&&this.#u.nOff(i,a)})}};#Z={8:function(e){let n=e.channel,o=e.data[0];this.#u.nOff(n,o)},9:function(e){let n=e.channel;this.#c[n]=1;let o=e.data[0],t=e.data[1];t>0?this.#u.nOn(n,o,t):this.#u.nOff(n,o)},10:function(e){let n=e.channel,o=n*128+e.data[0];this.#f.indexOf(o)>-1&&(this.#d[o]=data[1],this.dispatchEvent("note",{part:n,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let n=e.channel;this.#c[n]=1;let o=n*p.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#u.ano(n),this.#A[n]=0;let t=n*p.cc;this.#e[t+f[1]]=0,this.#e[t+f[5]]=0,this.#e[t+f[64]]=0,this.#e[t+f[65]]=0,this.#e[t+f[66]]=0,this.#e[t+f[67]]=0,this.#e[t+f[11]]=127,this.#e[t+f[101]]=127,this.#e[t+f[100]]=127,this.#e[t+f[99]]=127,this.#e[t+f[98]]=127;return}case 123:{this.#u.ano(n);return}case 124:{this.#u.ano(n);return}case 125:{this.#u.ano(n);return}case 126:{this.#S[n]=1,this.#u.ano(n);return}case 127:{this.#S[n]=0,this.#u.ano(n);return}}if(f[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Pe.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{if(E()&&console.debug(`${T[this.#t]}, CH${n+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#a[n]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${n+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==y.gs)e.data[1]<56&&this.#a[n]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${n+1} to stay drums.`));else if(this.#t==y.gm)e.data[1]<48?this.#a[n]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${n+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0);else if(this.#t==y.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let t=0;for(let i=0;i<16;i++){let a=this.#e[p.cc*i];(a==56||a==62)&&t++}t>14&&this.switchMode("ag10",!0)}}switch(this.#t){case y.xg:{[126,127].indexOf(e.data[1])>-1?this.#a[n]==0&&(this.setChType(n,1),console.debug(`CH${n+1} set to drums by MSB.`)):this.#a[n]>0&&(this.setChType(n,0),console.debug(`CH${n+1} set to melodic by MSB.`));break}case y["05rw"]:case y.x5d:case y.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#a[n]==0&&(this.setChType(n,1),console.debug(`CH${n+1} set to drums by MSB.`)):this.#a[n]>0&&(this.setChType(n,0),console.debug(`CH${n+1} set to melodic by MSB.`));break}case y.g2:{e.data[1]==120?this.#a[n]==0&&(this.setChType(n,1),console.debug(`CH${n+1} set to drums by MSB.`)):this.#a[n]>0&&(this.setChType(n,0),console.debug(`CH${n+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:n});break}case 6:{if(this.#H){let t=this.#e[o+f[99]],i=this.#e[o+f[98]];if(t==1){let a=Ae.indexOf(i);if(a>-1)this.#e[o+f[71+a]]=e.data[1],E()&&console.debug(`Redirected NRPN 1 ${i} to cc${71+a}.`),this.dispatchEvent("cc",{part:n,cc:71+a,data:e.data[1]});else{let s=le.indexOf(i);s>-1&&(this.#_[n*10+s]=e.data[1]-64),E()&&console.debug(`CH${n+1} voice NRPN ${i} commit`)}}}else{let t=_[this.#e[o+f[100]]];this.#e[o+f[101]]==0&&t!=null&&(E()&&console.debug(`CH${n+1} RPN 0 ${this.#e[o+f[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],ce[t][0]),ce[t][1]),this.#i[n*p.rpn+t]=e.data[1])}break}case 32:{this.dispatchEvent("voice",{part:n});break}case 38:{this.#H||this.#e[o+101]==0&&_[this.#e[o+100]]!=null&&(this.#i[n*p.rpn+_[this.#e[o+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#u.hoOf(n);break}case 66:{e.data[1]>>6?this.#u.soOn(n):this.#u.soOf(n);break}case 98:case 99:{this.#H=1;break}case 100:case 101:{this.#H=0;break}}this.#e[o+f[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:n,cc:e.data[0],data:e.data[1]})}},12:function(e){let n=e.channel;this.#c[n]=1,this.#s[n]=e.data,this.#T[n]=0,E()&&console.debug(`T:${e.track} C:${n} P:${e.data}`),this.dispatchEvent("voice",{part:n})},13:function(e){let n=this,o=e.channel;this.#f.forEach(function(t){let i=t>>7;o==i&&(n.#d[t]=e.data,n.dispatchEvent("note",{part:o,note:t&127,velo:e.data,state:n.NOTE_SUSTAIN}))})},14:function(e){let n=e.channel;this.#A[n]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:n,pitch:this.getPitchShift(n)})},15:function(e){De(e.data).forEach(n=>{let o=n[0],t=n[1];(this.#J[o]||function(){console.debug(`Unknown manufacturer ${o}.`)})(t,n.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(o,t,i){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#C=0);let n=Oe.indexOf(e.meta)>-1;if(E()&&console.debug(e),n)return e.reply="meta",e}};#J={64:(e,n,o)=>{this.#W.run(n,o,e)},65:(e,n,o)=>{if(n[0]<16)this.#P.run(n,o,e),console.warn("Unknown device SysEx!");else{let t=n[n.length-1],i=se(n.subarray(2,n.length-1));t==i?this.#P.run(n.subarray(0,n.length-1),o,e):console.warn(`Bad GS checksum ${t}. Should be ${i}.`)}},66:(e,n,o)=>{this.#B.run(n,o,e)},67:(e,n,o)=>{this.#O.run(n,o,e)},68:(e,n,o)=>{this.#j.run(n,o,e)},71:(e,n,o)=>{this.#q.run(n,o,e)},126:(e,n,o)=>{this.#z.run(n,o,e)},127:(e,n,o)=>{this.switchMode("gm"),this.#Q.run(n,o,e)}};#z;#Q;#O;#P;#B;#W;#q;#j;buildRchTree(){let e=[];this.#l.forEach((n,o)=>{e[n]?.constructor||(e[n]=[]),e[n].push(o)}),this.#Y=e}getActive(){let e=this.#c.slice();return this.#t==y.mt32,e}getCc(e){let n=e*p.cc,o=this.#e.subarray(n,n+p.cc);return o[f[0]]=o[f[0]]||this.#U,o[f[32]]=o[f[32]]||this.#E,o}getCcCh(e,n){if(P.indexOf(n)<0)throw new Error("CC number not accepted");return this.#e[p.cc*e+f[n]]}getCcAll(){let e=this.#e.slice();for(let n=0;n0&&(this.#e[e*p.cc+f[0]]=x[o])}getPitch(){return this.#A}getProgram(){return this.#s}getTexts(){return this.#r.slice()}getVel(e){let n=new Map,o=this;return o.#f.forEach(function(t,i){let a=Math.floor(t/128),s=t%128;e==a&&o.#d[t]>0&&n.set(s,{v:o.#d[t],s:o.#$[i]})}),n}getBitmap(){return{bitmap:this.#g,expire:this.#h}}getLetter(){return{text:this.#M,expire:this.#L}}getMode(){return T[this.#t]}getMaster(){return{volume:this.#v}}getRawStrength(){let e=this;return this.#f.forEach(function(n){let o=Math.floor(n/128);e.#d[n]>e.#x[o]&&(e.#x[o]=e.#d[n])}),this.#x}getStrength(){let e=[],n=this;return this.getRawStrength().forEach(function(o,t){e[t]=Math.floor(o*n.#e[t*p.cc+f[7]]*Math.max(n.#e[t*p.cc+f[11]],Math.floor(n.#e[t*p.cc+f[91]]*.5),Math.floor(n.#e[t*p.cc+f[92]]*.65),Math.floor(n.#e[t*p.cc+f[94]]*.8))*n.#v/803288)}),e}getRpn(){return this.#i}getNrpn(){return this.#_}getVoice(e,n,o,t){let i=e||this.#U,a=n,s=o||this.#E;T[this.#t]=="ns5r"&&i>0&&i<56&&(s=3);let r=this.userBank.get(i,a,s,t);if(T[this.#t]=="mt32"&&r.name.indexOf("MT-m:")==0){let c=parseInt(r.name.slice(5)),h=c*p.cmt,l="";this.#I.subarray(h,h+10).forEach(d=>{d>31&&(l+=String.fromCharCode(d))}),this.userBank.load(`MSB LSB PRG -0 127 ${a} ${l}`,!0),r.name=l,r.ending=" "}return(r.ending!=" "||!r.name.length)&&(r=this.baseBank.get(i,a,s,t)),r}getChVoice(e){let n=this.getVoice(this.#e[e*p.cc+f[0]],this.#s[e],this.#e[e*p.cc+f[32]],T[this.#t]);if(this.#T[e])switch(this.#t){case y.mt32:n.ending="~",n.name="",this.#w.subarray(14*(e-1),14*(e-1)+10).forEach(o=>{o>31&&(n.name+=String.fromCharCode(o))})}return n}getPitchShift(e){let n=e*p.rpn;return this.#A[e]/8192*this.#i[n]+(this.#i[n+3]-64)+((this.#i[n+1]<<7)+this.#i[n+2]-8192)/8192}getEffectType(e=0){let n=3*e+1;return this.#m.subarray(n,n+2)}setEffectTypeRaw(e=0,n,o){let t=3*e;this.#m[t]=1,this.#m[t+1+ +n]=o}setEffectType(e=0,n,o){this.setEffectTypeRaw(e,!1,n),this.setEffectTypeRaw(e,!0,o)}setLetterDisplay(e,n,o=0,t=3200){let i=this,a;i.#M=" ".repeat(o),e.forEach(s=>{i.#M+=String.fromCharCode(s>31?s:32),s<32&&(a=a||new Set,a.add(s))}),i.#L=Date.now()+3200,i.#M=i.#M.padEnd(32," "),a&&(a=Array.from(a),a.forEach((s,r,c)=>{c[r]=s.toString(16).padStart(2,"0")}),console.warn(`${n}${n?" ":""}invalid code point${a.length>1?"s":""}: 0x${a.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let n=!0,o=0;for(;n&&o=p.ace&&console.warn("ACE slots are full.")}getAce(){return this.#b}getChAce(e,n){if(n<0||n>=p.ace)throw new RangeError("No such ACE slot");let o=this.#b[n];if(o){if(P.indexOf(o)>=0)return this.#e[e*p.cc+f[o]];throw new Error(`Invalid ACE source: ${o}`)}else return 0}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#U=0,this.#E=0,this.#C=0,this.#c.fill(0),this.#e.fill(0),this.#b.fill(0),this.#s.fill(0),this.#d.fill(0),this.#f.fill(0),this.#x.fill(0),this.#A.fill(0),this.#_.fill(0),this.#v=100,this.#r=[],this.#V=500,this.#X=0,this.#L=0,this.#M="",this.#h=0,this.#n=0,this.#g.fill(0),this.#o=!1,this.#K=0,this.#k=!0,this.#l.forEach(function(n,o,t){t[o]=o}),this.buildRchTree(),e==0&&(this.#R.fill(0),this.#N.fill(0)),this.#e[p.cc*9]=x[0],this.#e[p.cc*25]=x[0],this.#e[p.cc*41]=x[0],this.#e[p.cc*57]=x[0],this.#a.fill(this.CH_MELODIC),this.#a[9]=this.CH_DRUM1,this.#a[25]=this.CH_DRUM2,this.#a[41]=this.CH_DRUMS,this.#a[41]=this.CH_DRUMS,this.#a[57]=this.CH_DRUMS,this.#a[73]=this.CH_DRUM5,this.#a[89]=this.CH_DRUM6,this.#a[105]=this.CH_DRUMS,this.#a[121]=this.CH_DRUMS,this.#F.fill(0),this.#I.fill(0),this.#D.fill(0),this.#w.fill(0),this.#T.fill(0),this.#m.fill(0),this.aiEfxName="",this.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let n=0;n-1){if(this.#t==0||n){let t=this.#t;this.#t=o,this.#n=0,this.#U=ne[0][o],this.#E=ne[1][o];for(let a=0;a0&&this.#e[a*p.cc+f[0]]==x[t]&&(this.#e[a*p.cc]=x[o]);switch(this.initOnReset,o){case y.mt32:{G.forEach((a,s)=>{let r=s+1;this.#c[r]||(this.#s[r]=a,this.#e[r*p.cc+f[91]]=127)});break}}let i;switch(o){case y.gs:{i=[40,4,40,18,40,32,32,0,0,0,0,0,0,0];break}case y.x5d:case y.ns5r:{i=[44,1,44,19,44,0,44,0,0,0,0,0,0,0];break}default:i=[1,0,65,0,5,0,0,0,0,0,0,0,0,0]}for(let a=0;a14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#Z[e.type].call(this,e);{let n=this.chRedir(e.part,e.track),o=!1;this.#Y[n]?.forEach(t=>{e.channel=t,o=!0,this.#Z[e.type].call(this,e)}),o||console.warn(`${oe[e.type]?oe[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${n+1} without any recipient.`)}this.#r.length>100&&this.#r.splice(100,this.#r.length-99)}runRaw(e){}constructor(){super();let e=this;this.#g=new Uint8Array(256),this.#p[10]=new Uint8Array(512),this.#G=new k,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let n=e.split(",");N[n[0]]=n[1]});var J=function(e){let n=e;e[0]=="*"&&(n=n.slice(1)),["aa","ii","uu","ee","oo"].forEach(t=>{for(;n.indexOf(t)>-1;)n=n.replace(t,t[0])});for(let t in N)n=n.replaceAll(t,N[t]);n.indexOf("ん")==0&&n.length>1&&(n=n.slice(1));let o=n.indexOf("!");return o>-1&&n.length>1&&(n=n.slice(o+1)),n},ee=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var B=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],te=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],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 Ce={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"},Re={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]]},H=function(e){return Ce[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},re=function(e,n,o){let t=(e[0]-32<<16)+(e[1]<<8)+n,i=Re[t]||{},r=i[0];if(r?.length)return r+=`: ${(i[1]||function(){})(o)||o}`,r},G=[68,48,95,78,41,3,110,122,0];var w=function(e=64){return Math.round(2e3*Math.log10(e/64))/100},ae=function(e,n,o){let t=[],i=o==!1?n.readIntVLV():o;e==0||e==127;for(let r=0;r127)return console.debug(`Early termination: ${t}`),t.pop(),n.backOne(),n.backOne(),new Uint8Array(t)}}}return new Uint8Array(t)},se=function(e){let n=0;return e.forEach(o=>{n+=o,n=n&127}),~n+1&127},S=function(e,n){let o=0,t=0;for(let i=0;i>r&1)<<7,a=e[i];a+=s,i%8!=0?(n(a,o,e),o++):t=e[i]}},O=function(e){let n=Math.floor(e*14.2);return n<128?n:0};var T=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],ne=[[0,0,0,0,121,0,0,56,82,81,63,0,0],[0,0,4,0,0,127,0,0,0,0,0,0,0]],x=[120,127,120,127,120,127,61,62,62,62,120,122,122],Oe=[0,3,81,84,88],oe={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},_={0:0,1:1,2:3,5:4},ce=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],le=[36,37],Pe=[20,21,22,23,24,25,26,28,29,30,31,36,37,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,12,13,16,17,18,19],Ae=[12,13,16,17,18,19],De=[33,99,100,32,102,8,9,10],he=[0,16,25,40,32,64,26,48],y={};T.forEach((e,n)=>{y[e]=n});var f={length:P.length};P.forEach((e,n)=>{f[e]=n});var E=function(){return!!self.Bun||self.debugMode||!1},Ie=function(e){let n=[],o=0;return e?.forEach(function(t,i){t==247?n.push(e.subarray(o,i)):t==240&&(o=i+1)}),n.length||n.push(e.subarray(0)),E()&&console.debug(n),n},de=function(e,n="",o="",t=2){return e?`${n}${e.toString().padStart(t,"0")}${o}`:""},p={ch:128,cc:P.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:Pe.length,dnc:72,efx:7},fe=class extends A{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#n=0;#h=0;#p=new Array(11);get#g(){return this.#p[this.#n]}set#g(e){this.#p[this.#n]=e}#c=new Uint8Array(p.ch);#l=new Uint8Array(p.ch);#r=new Uint8Array(p.ch);#e=new Uint8Array(p.ch*p.cc);#b=new Uint8Array(p.ace);#s=new Uint8Array(p.ch);#d=new Uint8Array(p.ch*p.nn);#S=new Uint8Array(p.ch);#f=new Uint16Array(p.pl);#$=new Uint8Array(p.pl);#A=new Int16Array(p.ch);#x=new Uint8Array(p.ch);#H=0;#i=new Uint8Array(p.ch*p.rpn);#_=new Int8Array(p.ch*le.length);#J=new Uint8Array(p.drm*p.dpn*p.dnc);#T=new Uint8Array(p.ch);#D=new Uint8Array(128);#w=new Uint8Array(p.cmt*8);#F=new Uint8Array(1024);#I=new Uint8Array(p.cmt*64);#m=new Uint8Array(p.efx*3);#U=0;#E=0;#v=100;#C=0;#V=500;#X=0;#M="";#N=0;#K=0;#k=!0;#o=!1;#Y;#te=new Uint8Array(2);#a=[];#R=new Uint8Array(p.ch);#L=new Uint8Array(p.tr);baseBank=new U("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new U("gm");initOnReset=!1;aiEfxName="";chRedir(e,n,o){if(this.#L[n])return(this.#L[n]-1)*16+e;if([2,3].indexOf(this.#E)>-1){if(o==1)return e;let t=0,i=!0;for(;i;)this.#R[e+t]==0?(this.#R[e+t]=n,console.debug(`Assign track ${n} to channel ${e+t+1}.`),i=!1):this.#R[e+t]==n?i=!1:(t+=16,t>=128&&(t=0,i=!1));return e+t}else return e}#y=[];#G;#u={nOff:(e,n)=>{let o=e*128+n,t=this.#f.lastIndexOf(o);t>-1&&(this.#e[p.cc*e+f[64]]>63?(this.#$[t]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#d[o],state:this.NOTE_HELD})):this.#e[p.cc*e+f[66]]>63&&this.#$[t]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#$[t]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#d[o],state:this.NOTE_SOSTENUTO_HELD})):(this.#f[t]=0,this.#d[o]=0,this.#$[t]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:n,velo:0,state:this.NOTE_IDLE})))},nOn:(e,n,o)=>{let t=e*128+n,i=0;for(this.#S[e]&&this.#u.ano(e);this.#$[i]>0&&this.#f[i]!=t;)i++;i{},cAt:(e,n)=>{},hoOf:e=>{this.#$.forEach((n,o)=>{if(n==this.NOTE_HELD){let t=this.#f[o],i=t>>7;e==i&&(this.#$[o]=this.NOTE_IDLE,this.#f[o]=0,this.#d[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#$.forEach((n,o)=>{let t;switch(n){case this.NOTE_ATTACK:{t=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{t=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{t=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(t){this.#$[o]=t;let i=this.#f[o];this.dispatchEvent("note",{part:e,note:i&127,velo:this.#d[i],state:t})}})},soOf:e=>{this.#$.forEach((n,o)=>{if(n==this.NOTE_SOSTENUTO_HELD){let t=this.#f[o],i=t>>7;e==i&&(this.#$[o]=this.NOTE_IDLE,this.#f[o]=0,this.#d[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#f.forEach((n,o,t)=>{let i=n>>7,r=n&127;n==0&&this.#d[0]==0||i==e&&this.#u.nOff(i,r)})}};#Z={8:function(e){let n=e.channel,o=e.data[0];this.#u.nOff(n,o)},9:function(e){let n=e.channel;this.#c[n]=1;let o=e.data[0],t=e.data[1];t>0?this.#u.nOn(n,o,t):this.#u.nOff(n,o)},10:function(e){let n=e.channel,o=n*128+e.data[0];this.#f.indexOf(o)>-1&&(this.#d[o]=data[1],this.dispatchEvent("note",{part:n,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let n=e.channel;this.#c[n]=1;let o=n*p.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#u.ano(n),this.#A[n]=0;let t=n*p.cc;this.#e[t+f[1]]=0,this.#e[t+f[5]]=0,this.#e[t+f[64]]=0,this.#e[t+f[65]]=0,this.#e[t+f[66]]=0,this.#e[t+f[67]]=0,this.#e[t+f[11]]=127,this.#e[t+f[101]]=127,this.#e[t+f[100]]=127,this.#e[t+f[99]]=127,this.#e[t+f[98]]=127;return}case 123:{this.#u.ano(n);return}case 124:{this.#u.ano(n);return}case 125:{this.#u.ano(n);return}case 126:{this.#S[n]=1,this.#u.ano(n);return}case 127:{this.#S[n]=0,this.#u.ano(n);return}}if(f[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Ae.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{if(E()&&console.debug(`${T[this.#t]}, CH${n+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#r[n]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${n+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==y.gs)e.data[1]<56&&this.#r[n]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${n+1} to stay drums.`));else if(this.#t==y.gm)e.data[1]<48?this.#r[n]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${n+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0);else if(this.#t==y.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let t=0;for(let i=0;i<16;i++){let r=this.#e[p.cc*i];(r==56||r==62)&&t++}t>14&&this.switchMode("ag10",!0)}}switch(this.#t){case y.xg:{[126,127].indexOf(e.data[1])>-1?this.#r[n]==0&&(this.setChType(n,1),console.debug(`CH${n+1} set to drums by MSB.`)):this.#r[n]>0&&(this.setChType(n,0),console.debug(`CH${n+1} set to melodic by MSB.`));break}case y["05rw"]:case y.x5d:case y.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#r[n]==0&&(this.setChType(n,1),console.debug(`CH${n+1} set to drums by MSB.`)):this.#r[n]>0&&(this.setChType(n,0),console.debug(`CH${n+1} set to melodic by MSB.`));break}case y.g2:{e.data[1]==120?this.#r[n]==0&&(this.setChType(n,1),console.debug(`CH${n+1} set to drums by MSB.`)):this.#r[n]>0&&(this.setChType(n,0),console.debug(`CH${n+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:n});break}case 6:{if(this.#H){let t=this.#e[o+f[99]],i=this.#e[o+f[98]];if(t==1){let r=De.indexOf(i);if(r>-1)this.#e[o+f[71+r]]=e.data[1],E()&&console.debug(`Redirected NRPN 1 ${i} to cc${71+r}.`),this.dispatchEvent("cc",{part:n,cc:71+r,data:e.data[1]});else{let s=le.indexOf(i);s>-1&&(this.#_[n*10+s]=e.data[1]-64),E()&&console.debug(`CH${n+1} voice NRPN ${i} commit`)}}}else{let t=_[this.#e[o+f[100]]];this.#e[o+f[101]]==0&&t!=null&&(E()&&console.debug(`CH${n+1} RPN 0 ${this.#e[o+f[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],ce[t][0]),ce[t][1]),this.#i[n*p.rpn+t]=e.data[1])}break}case 32:{this.dispatchEvent("voice",{part:n});break}case 38:{this.#H||this.#e[o+101]==0&&_[this.#e[o+100]]!=null&&(this.#i[n*p.rpn+_[this.#e[o+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#u.hoOf(n);break}case 66:{e.data[1]>>6?this.#u.soOn(n):this.#u.soOf(n);break}case 98:case 99:{this.#H=1;break}case 100:case 101:{this.#H=0;break}}this.#e[o+f[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:n,cc:e.data[0],data:e.data[1]})}},12:function(e){let n=e.channel;this.#c[n]=1,this.#s[n]=e.data,this.#T[n]=0,E()&&console.debug(`T:${e.track} C:${n} P:${e.data}`),this.dispatchEvent("voice",{part:n})},13:function(e){let n=this,o=e.channel;this.#f.forEach(function(t){let i=t>>7;o==i&&(n.#d[t]=e.data,n.dispatchEvent("note",{part:o,note:t&127,velo:e.data,state:n.NOTE_SUSTAIN}))})},14:function(e){let n=e.channel;this.#A[n]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:n,pitch:this.getPitchShift(n)})},15:function(e){Ie(e.data).forEach(n=>{let o=n[0],t=n[1];(this.#ee[o]||function(){console.debug(`Unknown manufacturer ${o}.`)})(t,n.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(o,t,i){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#C=0);let n=Oe.indexOf(e.meta)>-1;if(E()&&console.debug(e),n)return e.reply="meta",e}};#ee={64:(e,n,o)=>{this.#W.run(n,o,e)},65:(e,n,o)=>{if(n[0]<16)this.#P.run(n,o,e),console.warn("Unknown device SysEx!");else{let t=n[n.length-1],i=se(n.subarray(2,n.length-1));t==i?this.#P.run(n.subarray(0,n.length-1),o,e):console.warn(`Bad GS checksum ${t}. Should be ${i}.`)}},66:(e,n,o)=>{this.#B.run(n,o,e)},67:(e,n,o)=>{this.#O.run(n,o,e)},68:(e,n,o)=>{this.#j.run(n,o,e)},71:(e,n,o)=>{this.#q.run(n,o,e)},126:(e,n,o)=>{this.#z.run(n,o,e)},127:(e,n,o)=>{this.switchMode("gm"),this.#Q.run(n,o,e)}};#z;#Q;#O;#P;#B;#W;#q;#j;buildRchTree(){let e=[];this.#l.forEach((n,o)=>{e[n]?.constructor||(e[n]=[]),e[n].push(o)}),this.#Y=e}getActive(){let e=this.#c.slice();return this.#t==y.mt32,e}getCc(e){let n=e*p.cc,o=this.#e.subarray(n,n+p.cc);return o[f[0]]=o[f[0]]||this.#U,o[f[32]]=o[f[32]]||this.#E,o}getCcCh(e,n){if(P.indexOf(n)<0)throw new Error("CC number not accepted");return this.#e[p.cc*e+f[n]]}getCcAll(){let e=this.#e.slice();for(let n=0;n0&&(this.#e[e*p.cc+f[0]]=x[o])}getPitch(){return this.#A}getProgram(){return this.#s}getTexts(){return this.#a.slice()}getVel(e){let n=new Map,o=this;return o.#f.forEach(function(t,i){let r=Math.floor(t/128),s=t%128;e==r&&o.#d[t]>0&&n.set(s,{v:o.#d[t],s:o.#$[i]})}),n}getBitmap(){return{bitmap:this.#g,expire:this.#h}}getLetter(){return{text:this.#M,expire:this.#N}}getMode(){return T[this.#t]}getMaster(){return{volume:this.#v}}getRawStrength(){let e=this;return this.#f.forEach(function(n){let o=Math.floor(n/128);e.#d[n]>e.#x[o]&&(e.#x[o]=e.#d[n])}),this.#x}getStrength(){let e=[],n=this;return this.getRawStrength().forEach(function(o,t){e[t]=Math.floor(o*n.#e[t*p.cc+f[7]]*Math.max(n.#e[t*p.cc+f[11]],Math.floor(n.#e[t*p.cc+f[91]]*.5),Math.floor(n.#e[t*p.cc+f[92]]*.65),Math.floor(n.#e[t*p.cc+f[94]]*.8))*n.#v/803288)}),e}getRpn(){return this.#i}getNrpn(){return this.#_}getVoice(e,n,o,t){let i=e||this.#U,r=n,s=o||this.#E;T[this.#t]=="ns5r"&&i>0&&i<56&&(s=3);let a=this.userBank.get(i,r,s,t);if(T[this.#t]=="mt32"&&a.name.indexOf("MT-m:")==0){let c=parseInt(a.name.slice(5)),h=c*p.cmt,l="";this.#I.subarray(h,h+10).forEach(d=>{d>31&&(l+=String.fromCharCode(d))}),this.userBank.load(`MSB LSB PRG +0 127 ${r} ${l}`,!0),a.name=l,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(i,r,s,t)),a}getChVoice(e){let n=this.getVoice(this.#e[e*p.cc+f[0]],this.#s[e],this.#e[e*p.cc+f[32]],T[this.#t]);if(this.#T[e])switch(this.#t){case y.mt32:n.ending="~",n.name="",this.#w.subarray(14*(e-1),14*(e-1)+10).forEach(o=>{o>31&&(n.name+=String.fromCharCode(o))})}return n}getPitchShift(e){let n=e*p.rpn;return this.#A[e]/8192*this.#i[n]+(this.#i[n+3]-64)+((this.#i[n+1]<<7)+this.#i[n+2]-8192)/8192}getEffectType(e=0){let n=3*e+1;return this.#m.subarray(n,n+2)}setEffectTypeRaw(e=0,n,o){let t=3*e;this.#m[t]=1,this.#m[t+1+ +n]=o}setEffectType(e=0,n,o){this.setEffectTypeRaw(e,!1,n),this.setEffectTypeRaw(e,!0,o)}setLetterDisplay(e,n,o=0,t=3200){let i=this,r;i.#M=" ".repeat(o),e.forEach(s=>{i.#M+=String.fromCharCode(s>31?s:32),s<32&&(r=r||new Set,r.add(s))}),i.#N=Date.now()+3200,i.#M=i.#M.padEnd(32," "),r&&(r=Array.from(r),r.forEach((s,a,c)=>{c[a]=s.toString(16).padStart(2,"0")}),console.warn(`${n}${n?" ":""}invalid code point${r.length>1?"s":""}: 0x${r.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let n=!0,o=0;for(;n&&o=p.ace&&console.warn("ACE slots are full.")}getAce(){return this.#b}getChAce(e,n){if(n<0||n>=p.ace)throw new RangeError("No such ACE slot");let o=this.#b[n];if(o){if(P.indexOf(o)>=0)return this.#e[e*p.cc+f[o]];throw new Error(`Invalid ACE source: ${o}`)}else return 0}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#U=0,this.#E=0,this.#C=0,this.#c.fill(0),this.#e.fill(0),this.#b.fill(0),this.#s.fill(0),this.#d.fill(0),this.#f.fill(0),this.#x.fill(0),this.#A.fill(0),this.#_.fill(0),this.#J.fill(0),this.#v=100,this.#a=[],this.#V=500,this.#X=0,this.#N=0,this.#M="",this.#h=0,this.#n=0,this.#g.fill(0),this.#o=!1,this.#K=0,this.#k=!0,this.#l.forEach(function(n,o,t){t[o]=o}),this.buildRchTree(),e==0&&(this.#R.fill(0),this.#L.fill(0)),this.#e[p.cc*9]=x[0],this.#e[p.cc*25]=x[0],this.#e[p.cc*41]=x[0],this.#e[p.cc*57]=x[0],this.#r.fill(this.CH_MELODIC),this.#r[9]=this.CH_DRUM1,this.#r[25]=this.CH_DRUM2,this.#r[41]=this.CH_DRUMS,this.#r[41]=this.CH_DRUMS,this.#r[57]=this.CH_DRUMS,this.#r[73]=this.CH_DRUM5,this.#r[89]=this.CH_DRUM6,this.#r[105]=this.CH_DRUMS,this.#r[121]=this.CH_DRUMS,this.#F.fill(0),this.#I.fill(0),this.#D.fill(0),this.#w.fill(0),this.#T.fill(0),this.#m.fill(0),this.aiEfxName="",this.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let n=0;n-1){if(this.#t==0||n){let t=this.#t;this.#t=o,this.#n=0,this.#U=ne[0][o],this.#E=ne[1][o];for(let r=0;r0&&this.#e[r*p.cc+f[0]]==x[t]&&(this.#e[r*p.cc]=x[o]);switch(this.initOnReset,o){case y.mt32:{G.forEach((r,s)=>{let a=s+1;this.#c[a]||(this.#s[a]=r,this.#e[a*p.cc+f[91]]=127)});break}}let i;switch(o){case y.gs:{i=[40,4,40,18,40,32,32,0,0,0,0,0,0,0];break}case y.x5d:case y.ns5r:{i=[44,1,44,19,44,0,44,0,0,0,0,0,0,0];break}default:i=[1,0,65,0,5,0,0,0,0,0,0,0,0,0]}for(let r=0;r14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#Z[e.type].call(this,e);{let n=this.chRedir(e.part,e.track),o=!1;this.#Y[n]?.forEach(t=>{e.channel=t,o=!0,this.#Z[e.type].call(this,e)}),o||console.warn(`${oe[e.type]?oe[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${n+1} without any recipient.`)}this.#a.length>100&&this.#a.splice(100,this.#a.length-99)}runRaw(e){}constructor(){super();let e=this;this.#g=new Uint8Array(256),this.#p[10]=new Uint8Array(512),this.#G=new k,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -145,9 +145,9 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),this.#y[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#o=!0,this.#r.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#o=!0,this.#r.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#o=!0,this.#r.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#o=!0,this.#r.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#o=!0,this.#r.unshift(`Kara.Ver: ${t.slice(2)}`);break}case"XF":{let i=t.slice(2).split(":");switch(i[0]){case"hd":{i.slice(1).forEach((a,s)=>{a.length&&this.#r.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][s]}: ${a}`)});break}case"ln":{i.slice(1).forEach((a,s)=>{a.length&&this.#r.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][s]}: ${a}`)});break}default:this.#r.unshift(`XGF_Data: ${t}`)}break}default:this.#o?t[0]=="\\"?this.#r.unshift(`@ ${t.slice(1)}`):t[0]=="/"?this.#r.unshift(t.slice(1)):this.#r[0]+=t:(this.#r[0]=t,this.#r.unshift(""))}},this.#y[2]=function(t){this.#r.unshift(`Copyrite: ${t}`)},this.#y[3]=function(t,i){i<1&&this.#C<1&&this.#r.unshift(`TrkTitle: ${t}`)},this.#y[4]=function(t,i){this.#r.unshift(`${de(this.#C,""," ")}Instrmnt: ${t}`)},this.#y[5]=function(t){t.trim()==""?this.#r.unshift(""):this.#r[0]+=`${t}`},this.#y[6]=function(t){this.#r.unshift(`${de(this.#C,""," ")}C.Marker: ${t}`)},this.#y[7]=function(t){this.#r.unshift(`CuePoint: ${t}`)},this.#y[32]=function(t){this.#C=t[0]+1},this.#y[33]=function(t,i){console.debug(`Track ${i} requests to get assigned to output ${t}.`),e.#N[i]=t+1},this.#y[81]=function(t,i){e.#V=t/1e3},this.#y[127]=function(t,i){e.#G.run(t,i)},this.#G.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#G.add([67,0,1],function(t,i){e.#N[i]=t[0]+1}),this.#z=new k,this.#Q=new k,this.#O=new k,this.#P=new k,this.#B=new k,this.#W=new k,this.#q=new k,this.#j=new k,this.#z.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#o=e.#o||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#Q.add([4,1],t=>{e.#v=((t[1]<<7)+t[0])/16383*100}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#O.add([76,0,0],t=>{switch(t[0]){case 126:{e.switchMode("xg",!0),e.#o=!1,console.info("MIDI reset: XG");break}default:{let i=[0,0,0,0],a=(s,r)=>{i[r]=s};if(t.subarray(1).forEach((s,r)=>{let c=r+t[0];([a,a,a,a,h=>{this.#v=h*129/16383*100},h=>{},h=>{}][c]||(()=>{}))(s,r)}),t[0]<4){let s=0;i.forEach(r=>{s=s<<4,s+=r}),s-=1024}}}}).add([76,2,1],t=>{let i="XG ";t[0]<32?(i+="reverb ",t.subarray(1).forEach((a,s)=>{([r=>{e.setEffectTypeRaw(0,!1,r),console.info(`${i}main type: ${C[r]}`)},r=>{e.setEffectTypeRaw(0,!0,r),console.debug(`${i}sub type: ${r+1}`)},r=>{console.debug(`${i}time: ${j(r)}s`)},r=>{console.debug(`${i}diffusion: ${r}`)},r=>{console.debug(`${i}initial delay: ${r}`)},r=>{console.debug(`${i}HPF cutoff: ${R[r]}Hz`)},r=>{console.debug(`${i}LPF cutoff: ${R[r]}Hz`)},r=>{console.debug(`${i}width: ${r}`)},r=>{console.debug(`${i}height: ${r}`)},r=>{console.debug(`${i}depth: ${r}`)},r=>{console.debug(`${i}wall type: ${r}`)},r=>{console.debug(`${i}dry/wet: ${r}`)},r=>{console.debug(`${i}send: ${w(r)}dB`)},r=>{console.debug(`${i}pan: ${r-64}`)},!1,!1,r=>{console.debug(`${i}delay: ${r}`)},r=>{console.debug(`${i}density: ${r}`)},r=>{console.debug(`${i}balance: ${r}`)},r=>{},r=>{console.debug(`${i}feedback: ${r}`)},r=>{}][t[0]+s]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(a)})):t[0]<64?(i+="chorus ",t.subarray(1).forEach((a,s)=>{([r=>{e.setEffectTypeRaw(1,!1,r),console.info(`${i}main type: ${C[r]}`)},r=>{e.setEffectTypeRaw(1,!0,r),console.debug(`${i}sub type: ${r+1}`)},r=>{console.debug(`${i}LFO: ${q[r]}Hz`)},r=>{},r=>{console.debug(`${i}feedback: ${r}`)},r=>{console.debug(`${i}delay offset: ${Y(r)}ms`)},r=>{},r=>{console.debug(`${i}low: ${R[r]}Hz`)},r=>{console.debug(`${i}low: ${r-64}dB`)},r=>{console.debug(`${i}high: ${R[r]}Hz`)},r=>{console.debug(`${i}high: ${r-64}dB`)},r=>{console.debug(`${i}dry/wet: ${r}`)},r=>{console.debug(`${i}send: ${w(r)}dB`)},r=>{console.debug(`${i}pan: ${r-64}`)},r=>{console.debug(`${i}to reverb: ${w(r)}dB`)},!1,r=>{},r=>{},r=>{},r=>{console.debug(`${i}LFO phase diff: ${(r-64)*3}deg`)},r=>{console.debug(`${i}input mode: ${r?"stereo":"mono"}`)},r=>{}][t[0]-32+s]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(a)})):t[0]<86?(i+="variation ",t.subarray(1).forEach((a,s)=>{([r=>{e.setEffectTypeRaw(2,!1,r),console.info(`${i}main type: ${C[r]}`)},r=>{e.setEffectTypeRaw(2,!0,r),console.debug(`${i}sub type: ${r+1}`)}][t[0]-64+s]||function(){})(a)})):t[0]<97?(i+="variation ",t.subarray(1).forEach((a,s)=>{[r=>{console.debug(`${i}send: ${w(r)}dB`)},r=>{console.debug(`${i}pan: ${r-64}`)},r=>{console.debug(`${i}to reverb: ${w(r)}dB`)},r=>{console.debug(`${i}to chorus: ${w(r)}dB`)},r=>{console.debug(`${i}connection: ${r?"system":"insertion"}`)},r=>{console.debug(`${i}channel: CH${r+1}`)},r=>{console.debug(`${i}mod wheel: ${r-64}`)},r=>{console.debug(`${i}bend wheel: ${r-64}`)},r=>{console.debug(`${i}channel after touch: ${r-64}`)},r=>{console.debug(`${i}AC1: ${r-64}`)},r=>{console.debug(`${i}AC2: ${r-64}`)}][t[0]-86+s](a)})):t[0]>111&&t[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${t[0]}`)}).add([76,2,64],t=>{t.subarray(1).forEach((i,a)=>{let s=a+t[0];if(s==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let r=s-1>>2,c=s-1&3,h=`XG EQ ${r} ${["gain","freq","Q","shape"][c]}: `;[()=>{console.debug(`${h}${i-64}dB`)},()=>{console.debug(`${h}${i} (raw)`)},()=>{console.debug(`${h}${i/10}`)},()=>{console.debug(`${h}${["shelf","peak"][+!!i]}`)}][c]()}})}).add([76,3],t=>{let i=t[0],a=t[1],s=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((r,c)=>{([h=>{e.setEffectTypeRaw(3+i,!1,h),console.info(`${s}main type: ${C[h]}`)},h=>{e.setEffectTypeRaw(3+i,!0,h),console.debug(`${s}sub type: ${h+1}`)}][a+c]||function(){})(r)})}).add([76,6,0],t=>{let i=t[0];i<64?e.setLetterDisplay(t.subarray(1),"XG letter display",i):e.#L=Date.now()}).add([76,7,0],t=>{let i=t[0];e.#n=0,e.#h=Date.now()+3200,e.#g.fill(0);let a=t.subarray(1);for(let s=0;s>6-u&1,u++})}).add([76,8],(t,i)=>{let a=e.chRedir(t[0],i,!0),s=t[1],r=p.cc*a,c=`XG CH${a+1} `,h=`Unknown XG part address ${s}.`;t.subarray(2).forEach((l,d)=>{s<1?console.debug(h):s<41?([()=>{e.#e[r+f[0]]=l},()=>{e.#e[r+f[32]]=l},()=>{e.#s[a]=l},()=>{let u=e.chRedir(l,i,!0);e.#l[a]=u,a!=u&&(e.buildRchTree(),console.info(`${c}receives from CH${u+1}`))},()=>{e.#S[a]=+!l},()=>{},()=>{e.setChType(a,l,y.xg),console.debug(`${c}type: ${N[l]||l}`)},()=>{e.#i[p.rpn*a+3]=l},!1,!1,()=>{e.#e[r+f[7]]=l},!1,!1,()=>{e.#e[r+f[10]]=l||128},!1,!1,()=>{e.#e[r+f[11]]=l},()=>{e.#e[r+f[93]]=l},()=>{e.#e[r+f[91]]=l},()=>{e.#e[r+f[94]]=l},()=>{e.#e[r+f[76]]=l},()=>{e.#e[r+f[77]]=l},()=>{e.#e[r+f[78]]=l},()=>{e.#e[r+f[74]]=l},()=>{e.#e[r+f[71]]=l},()=>{e.#e[r+f[73]]=l},()=>{e.#e[r+f[75]]=l},()=>{e.#e[r+f[72]]=l}][s+d-1]||(()=>{}))():s<48?console.debug(h):s<111?s>102&&s<105&&(e.#e[r+f[[5,65][s&1]]]=l):s<114?console.debug(h):s<116?console.debug(`${c}EQ ${["bass","treble"][s&1]} gain: ${l-64}dB`):s<118?console.debug(h):s<120?console.debug(`${c}EQ ${["bass","treble"][s&1]} freq: ${l}`):console.debug(h)})}).add([76,9],(t,i)=>{let a=e.chRedir(t[0],i,!0),s=t[1],r=`PLG-150VL CH${a+1} `;t.subarray(2).forEach((c,h)=>{let l=h+s;switch(l){case 1:{console.info(`${r}breath mode: ${["system","breath","velocity","touch EG"][c]}`);break}case 0:case 27:case 28:break;default:if(l<27){let d=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${r}${d} control source: ${ee(c)}`),c&&c<96&&e.allocateAce(c)):console.debug(`${r}${d} scale break point: ${c}`):console.debug(`${r}${d} depth: ${c-64}`)}}})}).add([76,10],t=>{}).add([76,16],t=>{}).add([76,17,0,0],t=>{}).add([76,112],t=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][t[0]]} for CH${t[2]+1}.`)}).add([73,0,0],(t,i)=>{let a=t[0];t.subarray(1).forEach((s,r)=>{let c=a+r;c==8?console.debug(`MU1000 set LCD contrast to ${s}.`):c>9&&c<16&&[()=>{e.dispatchEvent("channelactive",s)},()=>{s<8?(e.dispatchEvent("channelmin",s<<4),console.info(`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.info(`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.#k=!!s,console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][c-10]()})}).add([73,10,0],(t,i)=>{let a=t[0],s=`MU1000 RS${e.#k?"":" (ignored)"}: `;if(a<16)switch(a){case 2:{let r=e.chRedir(0,i,!0);e.#k&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+63)),console.info(`${s}Show CH1~64`);break}case 3:{let r=e.chRedir(t[1]<<5,i,!0);e.#k&&e.dispatchEvent("channelmin",r),e.#k&&e.dispatchEvent("channelmax",r+31),console.info(`${s}Show CH${r+1}~CH${r+32}`);break}default:console.debug(`${s}unknown switch ${a} invoked.`)}else if(a<32){if(e.#k){let r=e.chRedir(a-16+(e.#K<<4),i,!0);e.dispatchEvent("channelactive",r)}}else if(a<36){let r=e.chRedir(a-32<<4,i,!0);e.#k&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+15),e.#K=a-32),console.info(`${s}Show CH${r+1}~CH${r+16}`)}}).add([93,3],(t,i)=>{let a=e.chRedir(t[0],i,!0),s=`PLG-100SG CH${a+1} `,r=Date.now();if(t[1]==0){let c="",h=0;t.subarray(2).forEach((l,d)=>{d%2==0?c+=Z[l]||l.toString().padStart("0"):h+=l*13}),r>=e.#X&&e.#r.unshift("SG Lyric: "),e.#r[0]+=`${J(c)}`,e.#X=r+Math.ceil(h/2)+e.#V,E()&&console.debug(`${s}vocals: ${c}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}),this.#O.add([76,48],t=>{}).add([76,49],t=>{}).add([76,50],t=>{}).add([76,51],t=>{}),this.#O.add([89,0],(t,i,a)=>{if(e.eprom){let s=t[0],r=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);E()&&console.debug(`MU1000 EPROM trail to 0x${r.toString(16).padStart(6,"0")}, ${s} bytes.`);let c=e.eprom.data;t.subarray(4).forEach((h,l)=>{let d=l>>3,u=l&7;if(u==7)for(let g=0;g<7;g++)c[r+7*d+g]+=(h>>6-g&1)<<7;else c[r+7*d+u]=h})}}).add([89,1],(t,i,a)=>{let s=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];E()&&console.debug(`MU1000 EPROM jump to 0x${s.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=s)}).add([89,2],(t,i,a)=>{if(e.eprom){let s=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);E()&&console.debug(`MU1000 EPROM write to 0x${s.toString(16).padStart(6,"0")}.`);let r=e.eprom.data;t.subarray(4).forEach((c,h)=>{let l=h>>3,d=h&7;if(d==7)for(let u=0;u<7;u++)r[s+7*l+u]+=(c>>6-u&1)<<7;else r[s+7*l+d]=c})}}).add([89,3],(t,i,a)=>{}),this.#O.add([39,48],(t,i,a)=>{}).add([43,0,0],(t,i,a)=>{let s=[0,0,0,0],r=(c,h)=>{s[h]=c};if(t.subarray(1).forEach((c,h)=>{let l=h+t[0];[r,r,r,r,()=>{this.#v=c*129/16383*100},()=>c-64,()=>c||128,()=>c,()=>c,()=>{console.debug(`TG300 variation on cc${c}.`)}][l](c,l)}),t[0]<4){let c=0;s.forEach(h=>{c=c<<4,c+=h}),c-=1024}}).add([43,1,0],(t,i,a)=>{}).add([43,2],(t,i,a)=>{let s=e.chRedir(t[0],i,!0),r=t[1],c=p.cc*s,h=`TG300 CH${s+1} `;t.subarray(2).forEach((l,d)=>{d<5?([()=>{},()=>{e.#e[c+f[0]]=l},()=>{e.#e[c+f[32]]=l},()=>{e.#s[s]=l},()=>{let u=e.chRedir(l,i,!0);e.#l[s]=u,s!=u&&(e.buildRchTree(),console.info(`${h}receives from CH${u+1}`))}][d+r]||(()=>{}))(l,d+r):d<21||(d<47?([()=>{e.#S[s]=+!l},()=>{},()=>{},()=>{e.#i[p.rpn*s+3]=l},()=>{},()=>{e.#e[c+f[7]]=l},!1,!1,()=>{e.#e[c+f[10]]=l||128},!1,!1,()=>{console.debug(`${h} AC1 at cc${l}`)},()=>{console.debug(`${h} AC2 at cc${l}`)},()=>{e.#e[c+f[11]]=l},()=>{e.#e[c+f[93]]=l},()=>{e.#e[c+f[91]]=l},()=>{e.#e[c+f[94]]=l},()=>{e.#e[c+f[76]]=l},()=>{e.#e[c+f[77]]=l},()=>{e.#e[c+f[74]]=l},()=>{e.#e[c+f[71]]=l},()=>{e.#e[c+f[73]]=l},()=>{e.#e[c+f[75]]=l},()=>{e.#e[c+f[72]]=l},()=>{e.#e[c+f[78]]=l}][d+r-21]||(()=>{}))(l,d+r):d<95||([()=>{e.#e[c+f[65]]=l},()=>{e.#e[c+f[5]]=l}][d+r-95]||(()=>{}))(l,d+r))})}).add([43,7,0],(t,i,a)=>{let s=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",s)}).add([43,7,1],(t,i,a)=>{e.#n=0,e.#h=Date.now()+3200,e.#g.fill(0),t.forEach(function(s,r){let c=Math.floor(r/16),h=r%16,l=(h*3+c)*7,d=7,u=0;for(l-=h*5,c==2&&(d=2);u>6-u&1,u++})}),this.#P.add([66,18,0,0,127],(t,i,a)=>{e.switchMode("gs",!0),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.#E=3,e.#o=!1,e.#R.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,i,a)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),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.#R.fill(0),console.info("MIDI reset: GS");break}default:{let s=[0,0,0,0],r=(c,h)=>{s[h]=c};if(t.subarray(1).forEach((c,h)=>{let l=h+t[0];[r,r,r,r,d=>{this.#v=d*129/16383*100},d=>{},d=>{}][l](c,h)}),t[0]<4){let c=0;s.forEach(h=>{c=c<<4,c+=h}),c-=1024}}}}).add([66,18,64,1],t=>{let i=t[0];if(i<16){let a="".padStart(i," ");t.subarray(1).forEach((s,r)=>{a+=String.fromCharCode(Math.max(32,s))}),a=a.padEnd(16," "),console.debug(`GS patch name: ${a}`)}else i<48||(i<65?t.subarray(1).forEach((a,s)=>{let r=`GS ${i+s>55?"chorus":"reverb"} `;([()=>{console.info(`${r}type: ${B[a]}`),e.setEffectType(0,40,a)},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${r}predelay: ${a}ms`)},()=>{console.info(`${r}type: ${te[a]}`),e.setEffectType(1,40,16+a)},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${w(a)}`)},()=>{console.debug(`${r}to delay: ${w(a)}`)}][i+s-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?t.subarray(1).forEach((a,s)=>{let r="GS delay ";([()=>{console.info(`${r}type: ${ie[a]}`),e.setEffectType(2,40,32+a)},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${w(a)}`)}][i+s-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],t=>{let i="GS EQ ";t.subarray(1).forEach((a,s)=>{([()=>{console.debug(`${i}low freq: ${[200,400][a]}Hz`)},()=>{console.debug(`${i}low gain: ${a-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][a]}Hz`)},()=>{console.debug(`${i}high gain: ${a-64}dB`)}][t[0]+s]||function(){console.warn(`Unknown GS EQ address: ${t[0]+s}`)})()})}).add([66,18,64,3],t=>{let i="GS EFX ",a=function(s,r){let c=ae(e.#m.subarray(10,12),r,s);c&&console.debug(`${i}${H(e.#m.subarray(10,12))} ${c}`)};t.subarray(1).forEach((s,r)=>{([()=>{e.setEffectTypeRaw(3,!1,32+s)},()=>{e.setEffectTypeRaw(3,!0,s),console.info(`${i}type: ${H(e.#m.subarray(10,12))}`)},!1,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,()=>{console.debug(`${i}to reverb: ${w(s)}dB`)},()=>{console.debug(`${i}to chorus: ${w(s)}dB`)},()=>{console.debug(`${i}to delay: ${w(s)}dB`)},!1,()=>{console.debug(`${i}1 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}1 depth: ${s-64}`)},()=>{console.debug(`${i}2 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}2 depth: ${s-64}`)},()=>{console.debug(`${i}to EQ: ${s?"ON":"OFF"}`)}][t[0]+r]||function(c,h){console.warn(`Unknown GS EFX address: ${h}`)})(s,t[0]+r)})}).add([66,18,65],t=>{}).add([69,18,16],t=>{switch(t[0]){case 0:{let i=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",i);break}case 32:{e.#h=Date.now()+3200,t[1]==0&&(e.#n=Math.max(Math.min(t[2]-1,9),0));break}default:if(t[0]<11){e.#n>9&&(e.#n=0),e.#h=Date.now()+3200,e.#p[t[0]-1]?.length||(e.#p[t[0]-1]=new Uint8Array(256));let i=e.#p[t[0]-1],a=t[1];i.fill(0);let s=t.subarray(2);for(let r=0;r>4-g&1,g++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let n=function(t,i,a){let s=t[0],r=p.cc*i,c=p.rpn*i,h=`GS CH${i+1} `;s<3?t.subarray(1).forEach((l,d)=>{[()=>{e.#e[r+f[0]]=l},()=>{e.#s[i]=l},()=>{let u=e.chRedir(l,a,!0);e.#l[i]=u,i!=u&&(e.buildRchTree(),console.info(`${h}receives from CH${u+1}`))}][s+d]()}):s<19||(s<44?t.subarray(1).forEach((l,d)=>{([()=>{e.#S[i]=+!l},!1,()=>{e.setChType(i,l?l+1:0,y.gs),console.debug(`${h}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{e.#i[c+3]=l},!1,()=>{e.#e[r+f[7]]=l},!1,!1,()=>{e.#e[r+f[10]]=l||128},!1,!1,()=>{console.debug(`${h}CC 1: cc${l}`)},()=>{console.debug(`${h}CC 2: cc${l}`)},()=>{e.#e[r+f[93]]=l},()=>{e.#e[r+f[91]]=l},!1,!1,()=>{e.#i[c+1]=l},()=>{e.#i[c+2]=l},()=>{e.#e[r+f[94]]=l}][s+d-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},o=function(t,i){let a=t[0],s=`GS CH${i+1} `;a<2?t.subarray(1).forEach((r,c)=>{[()=>{e.#e[p.cc*i+f[32]]=r},()=>{}][a+c]()}):a<32?console.warn(`Unknown GS misc address: ${a}`):a<35?t.subarray(1).forEach((r,c)=>{[()=>{console.debug(`${s}EQ: o${["ff","n"][r]}`)},()=>{},()=>{console.debug(`${s}EFX: o${["ff","n"][r]}`)}][a+c-32]()}):console.warn(`Unknown GS misc address: ${a}`)};this.#P.add([66,18,64,16],(t,i)=>{n(t,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(t,i)=>{n(t,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(t,i)=>{n(t,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(t,i)=>{n(t,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(t,i)=>{n(t,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(t,i)=>{n(t,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(t,i)=>{n(t,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(t,i)=>{n(t,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(t,i)=>{n(t,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(t,i)=>{n(t,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(t,i)=>{n(t,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(t,i)=>{n(t,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(t,i)=>{n(t,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(t,i)=>{n(t,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(t,i)=>{n(t,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(t,i)=>{n(t,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(t,i)=>{o(t,e.chRedir(9,i,!0))}).add([66,18,64,65],(t,i)=>{o(t,e.chRedir(0,i,!0))}).add([66,18,64,66],(t,i)=>{o(t,e.chRedir(1,i,!0))}).add([66,18,64,67],(t,i)=>{o(t,e.chRedir(2,i,!0))}).add([66,18,64,68],(t,i)=>{o(t,e.chRedir(3,i,!0))}).add([66,18,64,69],(t,i)=>{o(t,e.chRedir(4,i,!0))}).add([66,18,64,70],(t,i)=>{o(t,e.chRedir(5,i,!0))}).add([66,18,64,71],(t,i)=>{o(t,e.chRedir(6,i,!0))}).add([66,18,64,72],(t,i)=>{o(t,e.chRedir(7,i,!0))}).add([66,18,64,73],(t,i)=>{o(t,e.chRedir(8,i,!0))}).add([66,18,64,74],(t,i)=>{o(t,e.chRedir(10,i,!0))}).add([66,18,64,75],(t,i)=>{o(t,e.chRedir(11,i,!0))}).add([66,18,64,76],(t,i)=>{o(t,e.chRedir(12,i,!0))}).add([66,18,64,77],(t,i)=>{o(t,e.chRedir(13,i,!0))}).add([66,18,64,78],(t,i)=>{o(t,e.chRedir(14,i,!0))}).add([66,18,64,79],(t,i)=>{o(t,e.chRedir(15,i,!0))}),this.#B.add([54,65],(t,i)=>{e.switchMode("x5d");let a=(t[1]<<7)+t[0],s=(t[3]<<7)+t[2],r=e.chRedir(a&15,i,!0),c=p.cc*r;[()=>{s<1||(s<101?(e.setChType(r,0,y.x5d),e.#s[r]=s-1,e.#e[c+f[0]]=82):s<229?(e.setChType(r,0,y.x5d),e.#s[r]=s-101,e.#e[c+f[0]]=56):(e.setChType(r,1,y.x5d),e.#s[r]=he[s-229]||0,e.#e[c+f[0]]=62))},()=>{e.#e[c+f[7]]=s},()=>{s<31&&(e.#e[c+f[10]]=Math.round((s-15)*4.2+64))},()=>{e.#e[c+f[93]]=O(s)},()=>{e.#e[c+f[91]]=O(s)},()=>{e.#i[r*p.rpn+3]=s>8191?s-16320:64+s},()=>{e.#i[r*p.rpn+1]=s>8191?s-16320:64+s},()=>{s>0&&(e.#i[r*p.rpn]=s)},()=>{}][a>>4]()}).add([54,76,0],(t,i)=>{e.switchMode("x5d",!0);let a="",s=82,r=0,c=0,h="MSB PRG LSB NME";S(t,function(l,d){if(d<16400){let u=d%164;switch(!0){case u<10:{l>31&&(a+=String.fromCharCode(l));break}case u==11:{h+=` -${s} ${r} ${c} ${a.trim().replace("Init Voice","")}`,r++,a="";break}}r>99&&(s=90,r=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(h)}).add([54,77,0],(t,i)=>{e.switchMode("x5d",!0);let a="",s=90,r=0,c=0,h="MSB PRG LSB NME";S(t,function(l,d){if(d<13600){let u=d%136;switch(!0){case u<10:{l>31&&(a+=String.fromCharCode(l));break}case u==11:{h+=` -${s} ${r} ${c} ${a.trim().replace("Init Combi","")}`,r++,a="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(h)}).add([54,78],(t,i)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][t[0]]} mode.`)}).add([54,85],(t,i)=>{e.switchMode("x5d",!0),S(t,(a,s)=>{s>0&&s<3&&e.setEffectType(s-1,44,a)})}).add([54,104],(t,i)=>{e.switchMode("x5d",!0),S(t,function(a,s,r,c){if(s<192){let h=e.chRedir(Math.floor(s/12),i,!0),l=h*p.cc;switch(s%12){case 0:{a<128?(e.setChType(h,0,y.x5d),e.#e[l+f[0]]=82,e.#s[h]=a):(e.setChType(h,1,y.x5d),e.#e[l+f[0]]=62,e.#s[h]=he[a-128]),a>0&&(e.#c[h]=1);break}case 1:{e.#e[l+f[7]]=a;break}case 2:{e.#i[h*p.rpn+3]=a>127?a-192:64+a;break}case 3:{e.#i[h*p.rpn+1]=a>127?a-192:64+a;break}case 4:{a<31&&(e.#e[l+f[10]]=Math.round((a-15)*4.2+64));break}case 5:{let d=a>>4,u=a&15;e.#e[l+f[91]]=O(u),e.#e[l+f[93]]=O(d);break}case 10:break;case 11:{let d=e.chRedir(a&15,i,!0),u=a>>4;e.#l[h]=a,(d!=h||u)&&(console.info(`X5D Part CH${h+1} receives from CH${d+1}.`),e.buildRchTree())}}}else{let h=e.chRedir(s-192,i,!0)}})}),this.#P.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#o=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(t,i,a)=>{e.switchMode("mt32");let s=e.chRedir(a,i,!0),r=t[1];t.subarray(2).forEach((c,h)=>{let l=h+r;e.#D[l+(s-1)*16]=c,([!1,()=>{let d=e.#D[s-1<<4];if(d<3)if(e.#T[s]=1,d==2)for(let u=0;u{e.#i[s*p.rpn+3]=c+40},()=>{e.#i[s*p.rpn+1]=c+14},()=>{e.#i[s*p.rpn]=c},!1,()=>{e.#e[p.cc*s+f[91]]=c?127:0},!1,()=>{e.#e[p.cc*s+f[7]]=c},()=>{e.#e[p.cc*s+f[10]]=Math.ceil(c*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(t,i,a)=>{e.switchMode("mt32");let s=e.chRedir(a,i,!0)}).add([22,18,2],(t,i,a)=>{e.switchMode("mt32");let s=e.chRedir(a,i,!0),r=t[1]+(t[0]<<7);r<10&&(e.#T[s]=1),t.subarray(2).forEach((c,h)=>{let l=h+r;l<14&&(e.#w[(s-1)*p.cmt+l]=c)})}).add([22,18,3],(t,i,a)=>{if(e.switchMode("mt32"),t[0]){let s=t[1]-16}else{let s=t[1];t.subarray(2).forEach((r,c)=>{let h=c+s;e.#D[h]=r;let l=e.chRedir(1+h>>4,i,!0),d=h&15;([!1,()=>{let u=e.#D[l-1<<4];if(u<3)if(e.#T[l]=1,u==2)for(let g=0;g{e.#i[l*p.rpn+3]=r+40},()=>{e.#i[l*p.rpn+1]=r+14},()=>{e.#i[l*p.rpn]=r},!1,()=>{e.#e[p.cc*l+f[91]]=r?127:0},!1,()=>{e.#e[p.cc*l+f[7]]=r},()=>{e.#e[p.cc*l+f[10]]=Math.ceil(r*9.05)}][d]||(()=>{}))()})}}).add([22,18,4],(t,i,a)=>{e.switchMode("mt32");let s=t[1]+(t[0]<<7);t.subarray(2).forEach((r,c)=>{let h=c+s,l=e.chRedir(Math.floor(h/246+1),i,!0),d=h%246;d<14&&(e.#w[(l-1)*p.cmt+d]=r),d<10&&(e.#T[l]=1)})}).add([22,18,5],(t,i,a)=>{e.switchMode("mt32");let s=(t[0]<<7)+t[1];t.subarray(2).forEach((r,c)=>{let h=s+c,l=Math.floor(h/8),d=h&7,u=l*8;e.#F[h]=r,([!1,()=>{let g=e.#F[u];if(g<3){let b="";if(g==2){let m=p.cmt*l;b=`MT-m:${r.toString().padStart(3,"0")}`}else b=e.baseBank.get(0,r+(g<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l}),e.userBank.load(`MSB LSB PRG NME -000 127 ${l} ${b}`,!0)}}][d]||(()=>{}))()})}).add([22,18,8],(t,i,a)=>{e.switchMode("mt32");let s=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((r,c)=>{let h=s+c;h>1)*p.cmt+h]=r)})}).add([22,18,16],(t,i,a)=>{e.switchMode("mt32");let s=t[1],r=!1,c=function(h,l){e.#l[l-12]=h,r=!0};t.subarray(2).forEach((h,l)=>{let d=l+s;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,c,c,c,c,c,c,c,c,c,()=>{e.#v=h}][d]||(()=>{}))(h,l)}),r&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let i=t[1],a=" ".repeat(i);t.subarray(2).forEach(s=>{s>31&&(a+=String.fromCharCode(s))}),e.#M=a.padStart(20," "),e.#L=Date.now()+3200}).add([22,18,82],(t,i)=>{let a=e.chRedir(0,i,!0);for(let s=0;s<16;s++)e.#u.ano(a+s),s&&s<10&&(e.#s[a+s]=G[s-1]);console.info("MT-32 alt reset complete.")}),this.#B.add([66,0],(t,i)=>{e.switchMode("ns5r",!0),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,i)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#o=!1}).add([66,18,0,0],(t,i)=>{let a=t[0];switch(a){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#o=!1;break}case 125:break;default:if(a<10){let s=[0,0,0,0],r=(c,h)=>{s[h]=c};if(t.subarray(1).forEach((c,h)=>{[r,r,r,r,()=>{e.#v=c*129/16383*100},()=>c-64,()=>c-64,()=>{},()=>{},()=>{}][a+h]()}),t[0]<4){let c=0;s.forEach(h=>{c=c<<4,c+=h}),c-=1024}}}}).add([66,18,0,1],(t,i)=>{}).add([66,18,0,2],(t,i)=>{}).add([66,18,1],(t,i)=>{let a=e.chRedir(t[0],i,!0),s=a*p.cc,r=t[1],c=`NS5R CH${a+1}`;t.subarray(2).forEach((h,l)=>{let d=r+l;d<3?[()=>{e.#e[s+f[0]]=h||121},()=>{e.#e[s+f[32]]=h},()=>{e.#s[a]=h}][d]():d<8||(d<14?[()=>{let u=e.chRedir(h,i,!0);e.#l[a]=u,a!=u&&(e.buildRchTree(),console.info(`${c}receives from CH${u+1}`))},()=>{e.#S[a]=+!h},()=>{e.setChType(a,h,y.ns5r),console.debug(`${c}type: ${N[h]}`)},()=>{e.#i[p.rpn*a+3]=h},()=>{},()=>{}][d-8]():d<16||(d<33?[()=>{e.#e[s+f[7]]=h},()=>{e.#e[s+f[11]]=h},()=>{},()=>{},()=>{e.#e[s+f[10]]=h||128},()=>{},()=>{},()=>{e.#e[s+f[93]]=h},()=>{e.#e[s+f[91]]=h},()=>{e.#e[s+f[76]]=h},()=>{e.#e[s+f[77]]=h},()=>{e.#e[s+f[78]]=h},()=>{e.#e[s+f[74]]=h},()=>{e.#e[s+f[71]]=h},()=>{e.#e[s+f[73]]=h},()=>{e.#e[s+f[75]]=h},()=>{e.#e[s+f[72]]=h}][d-16]():d<112||d<114&&[()=>{e.#e[s+f[5]]=h},()=>{e.#e[s+f[65]]=h}][d-112]()))})}).add([66,18,8,0],(t,i)=>{let a=t[0];if(a<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let s=a-32;e.#h=Date.now()+3200,e.#n=10,e.#g.fill(0);let r=t.subarray(1),c=4;r.forEach(function(h,l){let d=l+s,u=d>>4,g=d&15;if(d<80){let b=u>3,m=0,$=u0;)e.#g[g*32+u*7+($-m)]=b&1,b=b>>1,m++}})}}).add([66,52],(t,i)=>{e.switchMode("ns5r",!0),e.#o=!1;let a="";S(t,(s,r)=>{r<8?(s>31&&(a+=String.fromCharCode(s)),r==7&&(e.aiEfxName=a)):r<10&&e.setEffectType(r-8,44,s)})}).add([66,53],(t,i)=>{e.switchMode("ns5r",!0),e.#o=!1,S(t,function(a,s){switch(!0){case s<2944:{let r=e.chRedir(Math.floor(s/92),i,!0),c=r*p.cc;switch(s%92){case 0:{e.#e[c+f[0]]=a||121;break}case 1:{e.#e[c+f[32]]=a;break}case 2:{e.#s[r]=a,a>0&&(e.#c[r]=1);break}case 3:{let h=e.chRedir(a,i,!0);e.#l[r]=h,r!=h&&(console.info(`NS5R CH${r+1} receives from CH${h+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#i[r*p.rpn+3]=a<40||a>88?a+(a>63?-192:64):a;break}case 9:case 10:{e.#e[c+f[7]]=a;break}case 11:{e.#e[c+f[11]]=a;break}case 14:{e.#e[c+f[10]]=a||128;break}case 19:{e.#e[c+f[93]]=a;break}case 20:{e.#e[c+f[91]]=a;break}case 84:{e.#e[c+f[65]]=a;break}case 85:{e.#e[c+f[5]]=a;break}}break}case s<3096:break;case s<3134:break;case s<8566:break}})}).add([66,54],(t,i)=>{e.switchMode("ns5r",!0);let a="",s=80,r=0,c=0,h="MSB PRG LSB NME";S(t,function(l,d){let u=d%158;switch(!0){case u<10:{l>31&&(a+=String.fromCharCode(l));break}case u==11:{s=l&127;break}case u==12:{c=l&127;break}case u==13:{h+=` -${s} ${r} ${c} ${a.trim().replace("Init Voice","")}`,r++,a="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(h)}).add([66,55],(t,i)=>{e.switchMode("ns5r",!0);let a="",s=88,r=0,c=0,h="MSB PRG LSB NME";S(t,function(l,d){let u=d%126;switch(!0){case u<10:{l>31&&(a+=String.fromCharCode(l));break}case u==11:break;case u==12:break;case u==13:{h+=` -${s} ${r} ${c} ${a.trim().replace("Init Combi","")}`,r++,a="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(h)}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let i=new Uint8Array(5760);S(t,(a,s,r)=>{if(s<720)for(let c=0;c<8;c++)i[s*8+c]=a>>7-c&1}),e.dispatchEvent("screen",{type:"ns5r",data:i})}).add([76],(t,i,a)=>{e.#B.run([66,...t],i,a)}),this.#W.add([16,0,8,0],(t,i,a)=>{let s=(t[2]<<4)+t[3],r="K11 ";([()=>{e.switchMode("k11",!0),e.#o=!1,e.#E=s?4:0,console.info("MIDI reset: GMega/K11")},()=>{console.debug(`${r}reverb type: ${s}`)},()=>{console.debug(`${r}reverb time: ${s}`)},()=>{console.debug(`${r}reverb time: ${s}`)},()=>{console.debug(`${r}reverb predelay: ${s}`)},()=>{console.debug(`${r}reverb predelay: ${s}`)},()=>{console.debug(`${r}depth high: ${s}`)},()=>{console.debug(`${r}depth high: ${s}`)},()=>{console.debug(`${r}depth low: ${s}`)},()=>{console.debug(`${r}depth low: ${s}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,i,a)=>{let s=e.chRedir(t[1],i,!0),r=p.cc*s,c=p.rpn*s,h=(t[3]<<4)+t[4],l=`K11 CH${s+1} `;([()=>{h<128?(e.setChType(s,0,y.k11),e.#e[r+f[0]]=0,e.#s[s]=h):(e.setChType(s,1,y.k11),e.#s[s]=h-128)},()=>{let d=e.chRedir(h,i,!0);e.#l[s]=d,s!=d&&(e.buildRchTree(),console.info(`${l}receives from CH${d+1}`))},()=>{e.#e[r+f[7]]=h},()=>{e.#c[s]=h},()=>{e.#e[r+f[10]]=h},()=>{e.#i[c+3]=h+40},()=>{e.#i[c+1]=h>>1,e.#i[c+2]=h&1},()=>{e.#e[r+f[91]]=h?127:0},()=>{},()=>{e.#e[r+f[74]]=h},()=>{e.#e[r+f[73]]=h},()=>{e.#e[r+f[72]]=h}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,i,a)=>{let s=(t[2]<<4)+t[3],r="GMLX ";([()=>{console.debug(`${r}reverb type: ${s}`)},()=>{console.debug(`${r}reverb time: ${s}`)},()=>{console.debug(`${r}reverb predelay: ${s}`)},()=>{console.debug(`${r}depth high: ${s}`)},()=>{console.debug(`${r}depth low: ${s}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,i,a)=>{let s=(t[2]<<4)+t[3],r=e.chRedir(t[1],i,!0),c=r*p.cc;[()=>{s<128?(e.setChType(r,0,y.k11),e.#e[c+f[0]]=0,e.#e[c+f[32]]=0,e.#s[r]=s):s<160?(e.setChType(r,0,y.k11),e.#e[c+f[0]]=0,e.#e[c+f[32]]=7,e.#s[r]=s-100):(e.setChType(r,1,y.k11),e.#e[c+f[0]]=122,e.#e[c+f[32]]=0,e.#s[r]=s-160)},()=>{let h=e.chRedir(s,i,!0);e.#l[r]=h,r!=h&&(e.buildRchTree(),console.info(`GMLX CH${r+1} receives from CH${h+1}`))}][t[0]]()}).add([16,0,9,4],(t,i,a)=>{let s=(t[2]<<4)+t[3],r=e.chRedir(t[1],i,!0),c=r*p.cc,h=r*p.rpn,l=`GMLX CH${r+1} `;[()=>{e.#c[r]=s},()=>{e.#e[c+f[7]]=s},()=>{e.#e[c+f[10]]=s},()=>{e.#e[c+f[91]]=s?127:0},()=>{e.#i[h+3]=s+40},()=>{e.#i[h+1]=s},()=>{e.#i[h]=s},()=>{}][t[0]]()}),this.#q.add([66,93,64],(t,i,a)=>{let s=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{e.#v=s*129/16383*100;break}case 5:{s-64;break}case 6:{console.debug(`SG global reverb: ${s?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(t[1]){case 48:{console.debug(`SG reverb type: ${B[s]}`);break}}break}default:if(t[0]>>4==1){let r=e.chRedir(t[0]&15,i,!0);if(t[1]==2){let c=e.chRedir(s,i,!0);e.#l[r]=c,r!=c&&(e.buildRchTree(),console.info(`SG CH${r+1} receives from CH${c+1}`))}else t[1]==19&&(e.#e[p.cc*r+f[7]]=s)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),this.#j.add([9],(t,i,a)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)})}};var K=xe(ue(),1);var pe=class{#t=!1;constructor(e,n,o,t){this.#t=e,this.start=n,this.end=o,this.data=t}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#t}},V=class extends pe{constructor(e,n,o){super(!0,e,n,o)}},ge=class extends pe{constructor(e,n){super(!1,e,e,n)}},X=class extends Array{#t=-1;constructor(){super(...arguments)}resetIndex(e){this.#t=-1}fresh(){this.sort(function(e,n){return e.start==n.start?0:(+(e.start>n.start)<<1)-1}),this.forEach(function(e,n){e.index=n})}step(e,n=!1){let o=[];if(n)for(let t=0;te);t++){if(this[t].endi.#t&&(o.push(a),i.#t=a.index)})}return o}getRange(e,n){e>n&&([e,n]=[n,e]);let o=[],t=-1,i=Math.ceil(Math.sqrt(this.length)),a=!0;for(let s=0;s=e&&(t=s):t=t<0?s:t;for(;a;)this[t]?.end=e&&o.push(this[t]):a=!1,t++;return o}};var Ie=0xffffffffffff,be=function(e){let n=new X,o=this,t=e.timeDivision,i=120,a=new X,s=0,r=0;a.push(new V(0,Ie,[120,0])),e.track.forEach(function(d){s=0,d.event.forEach(function(u){s+=u.deltaTime,u.type==255&&u?.metaType==81&&(i=6e7/u.data,a[a.length-1]&&a.push(new V(s,0xffffffffffff,[i,0])))})}),a.fresh(),a.forEach(function(d,u,g){u>0&&(g[u-1].end=d.start)});let c=120;a.forEach(function(d,u,g){u>0&&(d.end==d.start?g.splice(g.indexOf(d),1):c==d.data[0]&&(g[u-1].end=d.end,g.splice(g.indexOf(d),1)),c=d.data[0])});let h=0,l=120;return a.forEach(function(d){let u=d.start,g=u/l/t*60+h;l=d.data[0],h=g-u/l/t*60,d.data[1]=h}),console.debug("All tempo changes: ",a),i=120,s=0,r=0,e.track.forEach(function(d,u){s=0,r=0;let g=u+1;d.event.forEach(function(b,m){s+=b.deltaTime;let $=a.step(s,!0)[0];$&&(i=$.data[0],r=$.data[1]);let v={type:b.type,data:b.data,track:g,part:0};b.type>14?v.meta=b.metaType:v.part=b.channel,n.push(new ge(s/i/t*60+r,v))})}),n.fresh(),self.midiEvents=n,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),n};K.default.customInterpreter=re;var $e=class extends A{device;#t;#n="";#h=[];#p=new Uint8ClampedArray(128);#g=new Uint8ClampedArray(128);#c=.5;#l=120;#a=4;#e=4;#b=0;#s=0;smoothingAtk=0;smoothingDcy=0;reset(){this.dispatchEvent("reset"),this.#t?.resetIndex(),this.device.init(),this.#n="",this.#c=.5,this.#l=120,this.#a=4,this.#e=4,this.#b=0,this.#s=0}async loadFile(e){this.#t=be(K.default.parse(new Uint8Array(await e.arrayBuffer())))}switchMode(e,n=!1){this.device.switchMode(e,n)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}get noteProgress(){return this.#s/this.#c}get noteOverall(){return this.noteProgress-this.#b}get noteBar(){return Math.floor(this.noteOverall/this.#a)}get noteBeat(){let e=this.noteOverall%this.#a;return e<0&&(e+=this.#a),e}getTimeSig(){return[this.#a,this.#e]}getTempo(){return this.#l}sendCmd(e){this.device.runJson(e)}render(e){e>this.#s&&(this.#s=e);let n=this.#t?.step(e)||[],o=0,t=new Set,i=this,a=[];this.device.getStrength().forEach((m,$)=>{this.#g[$]=m}),i.device.newStrength(),n.forEach(function(m){let $=m.data;$.type==9&&($.data[1]>0?t.add($.part*128+$.data[0]):t.has($.part*128+$.data[0])&&o++),m.data.type==8&&t.has($.part*128+$.data[0])&&o++;let v=i.device.runJson($);switch(v?.reply){case"meta":{a.push(v);break}}v?.reply&&delete v.reply}),a?.length>0&&this.dispatchEvent("meta",a);let s=this.device.getActive(),r=[],c=i.device.getPitch(),h=i.device.getCcAll(),l=i.device.getProgram(),d=i.device.getChType(),u=this.device.getStrength();u.forEach(function(m,$,v){v[$]=Math.max(i.#g[$],m);let M=v[$]-i.#p[$],z=f.length*$;if(M>=0){let D=4*.25**(h[z+f[73]]/64);i.#p[$]+=Math.ceil(M-M*i.smoothingAtk**D)}else{let D=4*.25**(h[z+f[72]]/64);i.#p[$]+=Math.floor(M-M*i.smoothingDcy**D)}});let g=0;return s.forEach(function(m,$){m&&(r[$]=i.device.getVel($),g+=r[$].size)}),{extraPoly:o,curPoly:g,chInUse:s,chKeyPr:r,chPitch:c,chProgr:l,chContr:h,chType:d,eventCount:n.length,title:this.#n,bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:this.#p.slice(),velo:u,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce()}}constructor(e,n=.5,o=.5){super();let t=this;this.smoothingAtk=n,this.smoothingDcy=o,this.device=e,this.addEventListener("meta",function(i){i?.data?.forEach(function(a){(t.#h[a.meta]||console.debug).call(t,a.meta,a.data)})}),this.device.addEventListener("mode",function(i){t.dispatchEvent("mode",i.data)}),this.device.addEventListener("channelactive",function(i){t.dispatchEvent("channelactive",i.data)}),this.device.addEventListener("channelmin",function(i){t.dispatchEvent("channelmin",i.data)}),this.device.addEventListener("channelmax",function(i){t.dispatchEvent("channelmax",i.data)}),this.device.addEventListener("channelreset",function(i){t.dispatchEvent("channelreset")}),this.device.addEventListener("screen",function(i){t.dispatchEvent("screen",i.data)}),this.#h[3]=function(i,a){t.#n?.length<1&&(t.#n=a)},this.#h[81]=function(i,a){let s=t.noteProgress,r=t.#c||.5;t.#l=6e7/a,t.#c=a/1e6,t.#b+=s*(r/t.#c)-s},this.#h[88]=function(i,a){let s=t.noteProgress,r=t.noteOverall,c=t.noteBar,h=t.noteBeat,l=t.#a,d=t.#e;t.#a=a[0],t.#e=1<=l&&(l>1)*(n>>(this.mode>1?5:4))+this.device.getPitchShift(n)/12*this.noteRegW,r=(3+n%(this.mode>1?32:16))*this.lineHeight+this.noteTops[o%12]*this.noteHeight;if(t>0)switch(a.fillStyle=`#ffffff${(t*2).toString(16).padStart(2,"0")}`,a.fillRect(s+1,r+1,this.noteWidth-2,this.noteHeight-2),i){case this.device.NOTE_HELD:case this.device.NOTE_SOSTENUTO_HELD:{a.clearRect(s+1+this.noteOutline,r+1+this.noteOutline,this.noteWidth-2*(1+this.noteOutline),this.noteHeight-2*(1+this.noteOutline));break}}}render(n){let o=super.render(n),t=this,i=this.context,a=Date.now();i.globalCompositeOperation="source-over",i.clearRect(0,0,i.canvas.width,i.canvas.height),i.font=`${this.lineHeight-this.fontPadding*2}px "Noto Sans Mono", "Noto Sans Mono Web", mono`,self.metrics=i.measureText("Op");let s=metrics.actualBoundingBoxLeft,r=metrics.actualBoundingBoxAscent;i.fillStyle="#fff",i.fillText(`${o.eventCount.toString().padStart(3,"0")} ${(o.curPoly+o.extraPoly).toString().padStart(3,"0")}/512 ${o.tSig[0].toString().padStart(2," ")}/${o.tSig[1].toString().padEnd(2," ")} ${(o.noteBar+1).toString().padStart(3," ")}:${Math.floor(o.noteBeat+1).toString().padEnd(2," ")} ${Math.floor(o.tempo).toString().padStart(3," ")}.${Math.floor(o.tempo*100%100).toString().padStart(2,"0")}bpm ${Math.floor(o.master.volume).toString().padStart(3," ")}.${Math.floor(o.master.volume*100%100).toString().padStart(2,"0")}%`,t.fontPadding+s,r+t.fontPadding),i.fillText("Voices VEMRCDBP12",t.fontPadding+s,r+t.fontPadding+t.lineHeight*2),o.chKeyPr.forEach((c,h)=>{c.forEach((l,d)=>{let u=t.startPort<<4,g=(t.startPort<<4)+(16<=u&&h{let h=t.startPort<<4,l=(t.startPort<<4)+(16<=h&&c.part1?32:16)),d=t.device.getChVoice(h);i.fillText(`${h+1}`.padStart(2,"0"),t.fontPadding+s+(c>>(this.mode>1?5:4))*(i.canvas.width>>1),l,t.noteWidth*2.5),i.fillText(d.name,t.fontPadding+s+(c>>(this.mode>1?5:4))*(i.canvas.width>>1)+t.noteWidth*3,l,t.noteWidth*13);let u=f.length*h;[7,11,1,91,93,94,74,5,12,13].forEach((g,b)=>{i.fillRect(t.fontPadding*2+t.noteWidth*(16+b)+(c>>(this.mode>1?5:4))*(i.canvas.width>>1),t.lineHeight*(4+c%(this.mode>1?32:16)),t.noteWidth-t.noteOutline,(t.lineHeight-1)*(o.chContr[u+f[g]]/-127))})}}o.letter.expire<=a,i.globalCompositeOperation="xor",i.fillStyle="#fff";for(let c=0;c<16<>(this.mode>1?5:4))*(i.canvas.width>>1),t.lineHeight*(3+c%(this.mode>1?32:16)),t.noteWidth*16*(o.strength[h]/255),t.lineHeight-1)}for(let c in t.eventBuffer)delete t.eventBuffer[c];for(;t.eventQueue.length>0;)delete t.eventQueue[0],t.eventQueue.shift()}constructor(n){super(new fe,.1,.75);let o=this;this.context=n,this.resizeCanvas(1280,720),this.device.addEventListener("note",t=>{let i=t.data,a=i.part*128+i.note,s=this.eventBuffer[a];this.eventBuffer[a]=i,s?.velo>0&&i.velo==0&&this.eventQueue.push(s)})}},wt=Ue;export{wt as default}; +122 006 000 `),this.#y[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#o=!0,this.#a.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#o=!0,this.#a.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#o=!0,this.#a.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#o=!0,this.#a.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#o=!0,this.#a.unshift(`Kara.Ver: ${t.slice(2)}`);break}case"XF":{let i=t.slice(2).split(":");switch(i[0]){case"hd":{i.slice(1).forEach((r,s)=>{r.length&&this.#a.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][s]}: ${r}`)});break}case"ln":{i.slice(1).forEach((r,s)=>{r.length&&this.#a.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][s]}: ${r}`)});break}default:this.#a.unshift(`XGF_Data: ${t}`)}break}default:this.#o?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.#y[2]=function(t){this.#a.unshift(`Copyrite: ${t}`)},this.#y[3]=function(t,i){i<1&&this.#C<1&&this.#a.unshift(`TrkTitle: ${t}`)},this.#y[4]=function(t,i){this.#a.unshift(`${de(this.#C,""," ")}Instrmnt: ${t}`)},this.#y[5]=function(t){t.trim()==""?this.#a.unshift(""):this.#a[0]+=`${t}`},this.#y[6]=function(t){this.#a.unshift(`${de(this.#C,""," ")}C.Marker: ${t}`)},this.#y[7]=function(t){this.#a.unshift(`CuePoint: ${t}`)},this.#y[32]=function(t){this.#C=t[0]+1},this.#y[33]=function(t,i){console.debug(`Track ${i} requests to get assigned to output ${t}.`),e.#L[i]=t+1},this.#y[81]=function(t,i){e.#V=t/1e3},this.#y[127]=function(t,i){e.#G.run(t,i)},this.#G.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#G.add([67,0,1],function(t,i){e.#L[i]=t[0]+1}),this.#z=new k,this.#Q=new k,this.#O=new k,this.#P=new k,this.#B=new k,this.#W=new k,this.#q=new k,this.#j=new k,this.#z.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#o=e.#o||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#Q.add([4,1],t=>{e.#v=((t[1]<<7)+t[0])/16383*100}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#O.add([76,0,0],t=>{switch(t[0]){case 126:{e.switchMode("xg",!0),e.#o=!1,console.info("MIDI reset: XG");break}default:{let i=[0,0,0,0],r=(s,a)=>{i[a]=s};if(t.subarray(1).forEach((s,a)=>{let c=a+t[0];([r,r,r,r,h=>{this.#v=h*129/16383*100},h=>{},h=>{}][c]||(()=>{}))(s,a)}),t[0]<4){let s=0;i.forEach(a=>{s=s<<4,s+=a}),s-=1024}}}}).add([76,2,1],t=>{let i="XG ";t[0]<32?(i+="reverb ",t.subarray(1).forEach((r,s)=>{([a=>{e.setEffectTypeRaw(0,!1,a),console.info(`${i}main type: ${C[a]}`)},a=>{e.setEffectTypeRaw(0,!0,a),console.debug(`${i}sub type: ${a+1}`)},a=>{console.debug(`${i}time: ${j(a)}s`)},a=>{console.debug(`${i}diffusion: ${a}`)},a=>{console.debug(`${i}initial delay: ${a}`)},a=>{console.debug(`${i}HPF cutoff: ${R[a]}Hz`)},a=>{console.debug(`${i}LPF cutoff: ${R[a]}Hz`)},a=>{console.debug(`${i}width: ${a}`)},a=>{console.debug(`${i}height: ${a}`)},a=>{console.debug(`${i}depth: ${a}`)},a=>{console.debug(`${i}wall type: ${a}`)},a=>{console.debug(`${i}dry/wet: ${a}`)},a=>{console.debug(`${i}send: ${w(a)}dB`)},a=>{console.debug(`${i}pan: ${a-64}`)},!1,!1,a=>{console.debug(`${i}delay: ${a}`)},a=>{console.debug(`${i}density: ${a}`)},a=>{console.debug(`${i}balance: ${a}`)},a=>{},a=>{console.debug(`${i}feedback: ${a}`)},a=>{}][t[0]+s]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(r)})):t[0]<64?(i+="chorus ",t.subarray(1).forEach((r,s)=>{([a=>{e.setEffectTypeRaw(1,!1,a),console.info(`${i}main type: ${C[a]}`)},a=>{e.setEffectTypeRaw(1,!0,a),console.debug(`${i}sub type: ${a+1}`)},a=>{console.debug(`${i}LFO: ${q[a]}Hz`)},a=>{},a=>{console.debug(`${i}feedback: ${a}`)},a=>{console.debug(`${i}delay offset: ${Y(a)}ms`)},a=>{},a=>{console.debug(`${i}low: ${R[a]}Hz`)},a=>{console.debug(`${i}low: ${a-64}dB`)},a=>{console.debug(`${i}high: ${R[a]}Hz`)},a=>{console.debug(`${i}high: ${a-64}dB`)},a=>{console.debug(`${i}dry/wet: ${a}`)},a=>{console.debug(`${i}send: ${w(a)}dB`)},a=>{console.debug(`${i}pan: ${a-64}`)},a=>{console.debug(`${i}to reverb: ${w(a)}dB`)},!1,a=>{},a=>{},a=>{},a=>{console.debug(`${i}LFO phase diff: ${(a-64)*3}deg`)},a=>{console.debug(`${i}input mode: ${a?"stereo":"mono"}`)},a=>{}][t[0]-32+s]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(r)})):t[0]<86?(i+="variation ",t.subarray(1).forEach((r,s)=>{([a=>{e.setEffectTypeRaw(2,!1,a),console.info(`${i}main type: ${C[a]}`)},a=>{e.setEffectTypeRaw(2,!0,a),console.debug(`${i}sub type: ${a+1}`)}][t[0]-64+s]||function(){})(r)})):t[0]<97?(i+="variation ",t.subarray(1).forEach((r,s)=>{[a=>{console.debug(`${i}send: ${w(a)}dB`)},a=>{console.debug(`${i}pan: ${a-64}`)},a=>{console.debug(`${i}to reverb: ${w(a)}dB`)},a=>{console.debug(`${i}to chorus: ${w(a)}dB`)},a=>{console.debug(`${i}connection: ${a?"system":"insertion"}`)},a=>{console.debug(`${i}channel: CH${a+1}`)},a=>{console.debug(`${i}mod wheel: ${a-64}`)},a=>{console.debug(`${i}bend wheel: ${a-64}`)},a=>{console.debug(`${i}channel after touch: ${a-64}`)},a=>{console.debug(`${i}AC1: ${a-64}`)},a=>{console.debug(`${i}AC2: ${a-64}`)}][t[0]-86+s](r)})):t[0]>111&&t[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${t[0]}`)}).add([76,2,64],t=>{t.subarray(1).forEach((i,r)=>{let s=r+t[0];if(s==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let a=s-1>>2,c=s-1&3,h=`XG EQ ${a} ${["gain","freq","Q","shape"][c]}: `;[()=>{console.debug(`${h}${i-64}dB`)},()=>{console.debug(`${h}${i} (raw)`)},()=>{console.debug(`${h}${i/10}`)},()=>{console.debug(`${h}${["shelf","peak"][+!!i]}`)}][c]()}})}).add([76,3],t=>{let i=t[0],r=t[1],s=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((a,c)=>{([h=>{e.setEffectTypeRaw(3+i,!1,h),console.info(`${s}main type: ${C[h]}`)},h=>{e.setEffectTypeRaw(3+i,!0,h),console.debug(`${s}sub type: ${h+1}`)}][r+c]||function(){})(a)})}).add([76,6,0],t=>{let i=t[0];i<64?e.setLetterDisplay(t.subarray(1),"XG letter display",i):e.#N=Date.now()}).add([76,7,0],t=>{let i=t[0];e.#n=0,e.#h=Date.now()+3200,e.#g.fill(0);let r=t.subarray(1);for(let s=0;s>6-u&1,u++})}).add([76,8],(t,i)=>{let r=e.chRedir(t[0],i,!0),s=t[1],a=p.cc*r,c=`XG CH${r+1} `,h=`Unknown XG part address ${s}.`;t.subarray(2).forEach((l,d)=>{s<1?console.debug(h):s<41?([()=>{e.#e[a+f[0]]=l},()=>{e.#e[a+f[32]]=l},()=>{e.#s[r]=l},()=>{let u=e.chRedir(l,i,!0);e.#l[r]=u,r!=u&&(e.buildRchTree(),console.info(`${c}receives from CH${u+1}`))},()=>{e.#S[r]=+!l},()=>{},()=>{e.setChType(r,l,y.xg),console.debug(`${c}type: ${L[l]||l}`)},()=>{e.#i[p.rpn*r+3]=l},!1,!1,()=>{e.#e[a+f[7]]=l},!1,!1,()=>{e.#e[a+f[10]]=l||128},!1,!1,()=>{e.#e[a+f[11]]=l},()=>{e.#e[a+f[93]]=l},()=>{e.#e[a+f[91]]=l},()=>{e.#e[a+f[94]]=l},()=>{e.#e[a+f[76]]=l},()=>{e.#e[a+f[77]]=l},()=>{e.#e[a+f[78]]=l},()=>{e.#e[a+f[74]]=l},()=>{e.#e[a+f[71]]=l},()=>{e.#e[a+f[73]]=l},()=>{e.#e[a+f[75]]=l},()=>{e.#e[a+f[72]]=l}][s+d-1]||(()=>{}))():s<48?console.debug(h):s<111?s>102&&s<105&&(e.#e[a+f[[5,65][s&1]]]=l):s<114?console.debug(h):s<116?console.debug(`${c}EQ ${["bass","treble"][s&1]} gain: ${l-64}dB`):s<118?console.debug(h):s<120?console.debug(`${c}EQ ${["bass","treble"][s&1]} freq: ${l}`):console.debug(h)})}).add([76,9],(t,i)=>{let r=e.chRedir(t[0],i,!0),s=t[1],a=`PLG-150VL CH${r+1} `;t.subarray(2).forEach((c,h)=>{let l=h+s;switch(l){case 1:{console.info(`${a}breath mode: ${["system","breath","velocity","touch EG"][c]}`);break}case 0:case 27:case 28:break;default:if(l<27){let d=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${a}${d} control source: ${ee(c)}`),c&&c<96&&e.allocateAce(c)):console.debug(`${a}${d} scale break point: ${c}`):console.debug(`${a}${d} depth: ${c-64}`)}}})}).add([76,10],t=>{}).add([76,16],t=>{}).add([76,17,0,0],t=>{}).add([76,112],t=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][t[0]]} for CH${t[2]+1}.`)}).add([73,0,0],(t,i)=>{let r=t[0];t.subarray(1).forEach((s,a)=>{let c=r+a;c==8?console.debug(`MU1000 set LCD contrast to ${s}.`):c>9&&c<16&&[()=>{e.dispatchEvent("channelactive",s)},()=>{s<8?(e.dispatchEvent("channelmin",s<<4),console.info(`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.info(`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.#k=!!s,console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][c-10]()})}).add([73,10,0],(t,i)=>{let r=t[0],s=`MU1000 RS${e.#k?"":" (ignored)"}: `;if(r<16)switch(r){case 2:{let a=e.chRedir(0,i,!0);e.#k&&(e.dispatchEvent("channelmin",a),e.dispatchEvent("channelmax",a+63)),console.info(`${s}Show CH1~64`);break}case 3:{let a=e.chRedir(t[1]<<5,i,!0);e.#k&&e.dispatchEvent("channelmin",a),e.#k&&e.dispatchEvent("channelmax",a+31),console.info(`${s}Show CH${a+1}~CH${a+32}`);break}default:console.debug(`${s}unknown switch ${r} invoked.`)}else if(r<32){if(e.#k){let a=e.chRedir(r-16+(e.#K<<4),i,!0);e.dispatchEvent("channelactive",a)}}else if(r<36){let a=e.chRedir(r-32<<4,i,!0);e.#k&&(e.dispatchEvent("channelmin",a),e.dispatchEvent("channelmax",a+15),e.#K=r-32),console.info(`${s}Show CH${a+1}~CH${a+16}`)}}).add([93,3],(t,i)=>{let r=e.chRedir(t[0],i,!0),s=`PLG-100SG CH${r+1} `,a=Date.now();if(t[1]==0){let c="",h=0;t.subarray(2).forEach((l,d)=>{d%2==0?c+=Z[l]||l.toString().padStart("0"):h+=l*13}),a>=e.#X&&e.#a.unshift("SG Lyric: "),e.#a[0]+=`${J(c)}`,e.#X=a+Math.ceil(h/2)+e.#V,E()&&console.debug(`${s}vocals: ${c}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}),this.#O.add([76,48],t=>{}).add([76,49],t=>{}).add([76,50],t=>{}).add([76,51],t=>{}),this.#O.add([89,0],(t,i,r)=>{if(e.eprom){let s=t[0],a=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);E()&&console.debug(`MU1000 EPROM trail to 0x${a.toString(16).padStart(6,"0")}, ${s} bytes.`);let c=e.eprom.data;t.subarray(4).forEach((h,l)=>{let d=l>>3,u=l&7;if(u==7)for(let g=0;g<7;g++)c[a+7*d+g]+=(h>>6-g&1)<<7;else c[a+7*d+u]=h})}}).add([89,1],(t,i,r)=>{let s=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];E()&&console.debug(`MU1000 EPROM jump to 0x${s.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=s)}).add([89,2],(t,i,r)=>{if(e.eprom){let s=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);E()&&console.debug(`MU1000 EPROM write to 0x${s.toString(16).padStart(6,"0")}.`);let a=e.eprom.data;t.subarray(4).forEach((c,h)=>{let l=h>>3,d=h&7;if(d==7)for(let u=0;u<7;u++)a[s+7*l+u]+=(c>>6-u&1)<<7;else a[s+7*l+d]=c})}}).add([89,3],(t,i,r)=>{}),this.#O.add([39,48],(t,i,r)=>{}).add([43,0,0],(t,i,r)=>{let s=[0,0,0,0],a=(c,h)=>{s[h]=c};if(t.subarray(1).forEach((c,h)=>{let l=h+t[0];[a,a,a,a,()=>{this.#v=c*129/16383*100},()=>c-64,()=>c||128,()=>c,()=>c,()=>{console.debug(`TG300 variation on cc${c}.`)}][l](c,l)}),t[0]<4){let c=0;s.forEach(h=>{c=c<<4,c+=h}),c-=1024}}).add([43,1,0],(t,i,r)=>{}).add([43,2],(t,i,r)=>{let s=e.chRedir(t[0],i,!0),a=t[1],c=p.cc*s,h=`TG300 CH${s+1} `;t.subarray(2).forEach((l,d)=>{d<5?([()=>{},()=>{e.#e[c+f[0]]=l},()=>{e.#e[c+f[32]]=l},()=>{e.#s[s]=l},()=>{let u=e.chRedir(l,i,!0);e.#l[s]=u,s!=u&&(e.buildRchTree(),console.info(`${h}receives from CH${u+1}`))}][d+a]||(()=>{}))(l,d+a):d<21||(d<47?([()=>{e.#S[s]=+!l},()=>{},()=>{},()=>{e.#i[p.rpn*s+3]=l},()=>{},()=>{e.#e[c+f[7]]=l},!1,!1,()=>{e.#e[c+f[10]]=l||128},!1,!1,()=>{console.debug(`${h} AC1 at cc${l}`)},()=>{console.debug(`${h} AC2 at cc${l}`)},()=>{e.#e[c+f[11]]=l},()=>{e.#e[c+f[93]]=l},()=>{e.#e[c+f[91]]=l},()=>{e.#e[c+f[94]]=l},()=>{e.#e[c+f[76]]=l},()=>{e.#e[c+f[77]]=l},()=>{e.#e[c+f[74]]=l},()=>{e.#e[c+f[71]]=l},()=>{e.#e[c+f[73]]=l},()=>{e.#e[c+f[75]]=l},()=>{e.#e[c+f[72]]=l},()=>{e.#e[c+f[78]]=l}][d+a-21]||(()=>{}))(l,d+a):d<95||([()=>{e.#e[c+f[65]]=l},()=>{e.#e[c+f[5]]=l}][d+a-95]||(()=>{}))(l,d+a))})}).add([43,7,0],(t,i,r)=>{let s=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",s)}).add([43,7,1],(t,i,r)=>{e.#n=0,e.#h=Date.now()+3200,e.#g.fill(0),t.forEach(function(s,a){let c=Math.floor(a/16),h=a%16,l=(h*3+c)*7,d=7,u=0;for(l-=h*5,c==2&&(d=2);u>6-u&1,u++})}),this.#P.add([66,18,0,0,127],(t,i,r)=>{e.switchMode("gs",!0),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.#E=3,e.#o=!1,e.#R.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,i,r)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[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.#R.fill(0),console.info("MIDI reset: GS");break}default:{let s=[0,0,0,0],a=(c,h)=>{s[h]=c};if(t.subarray(1).forEach((c,h)=>{let l=h+t[0];[a,a,a,a,d=>{this.#v=d*129/16383*100},d=>{},d=>{}][l](c,h)}),t[0]<4){let c=0;s.forEach(h=>{c=c<<4,c+=h}),c-=1024}}}}).add([66,18,64,1],t=>{let i=t[0];if(i<16){let r="".padStart(i," ");t.subarray(1).forEach((s,a)=>{r+=String.fromCharCode(Math.max(32,s))}),r=r.padEnd(16," "),console.debug(`GS patch name: ${r}`)}else i<48||(i<65?t.subarray(1).forEach((r,s)=>{let a=`GS ${i+s>55?"chorus":"reverb"} `;([()=>{console.info(`${a}type: ${B[r]}`),e.setEffectType(0,40,r)},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${a}predelay: ${r}ms`)},()=>{console.info(`${a}type: ${te[r]}`),e.setEffectType(1,40,16+r)},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${a}to reverb: ${w(r)}`)},()=>{console.debug(`${a}to delay: ${w(r)}`)}][i+s-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?t.subarray(1).forEach((r,s)=>{let a="GS delay ";([()=>{console.info(`${a}type: ${ie[r]}`),e.setEffectType(2,40,32+r)},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${a}to reverb: ${w(r)}`)}][i+s-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],t=>{let i="GS EQ ";t.subarray(1).forEach((r,s)=>{([()=>{console.debug(`${i}low freq: ${[200,400][r]}Hz`)},()=>{console.debug(`${i}low gain: ${r-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][r]}Hz`)},()=>{console.debug(`${i}high gain: ${r-64}dB`)}][t[0]+s]||function(){console.warn(`Unknown GS EQ address: ${t[0]+s}`)})()})}).add([66,18,64,3],t=>{let i="GS EFX ",r=function(s,a){let c=re(e.#m.subarray(10,12),a,s);c&&console.debug(`${i}${H(e.#m.subarray(10,12))} ${c}`)};t.subarray(1).forEach((s,a)=>{([()=>{e.setEffectTypeRaw(3,!1,32+s)},()=>{e.setEffectTypeRaw(3,!0,s),console.info(`${i}type: ${H(e.#m.subarray(10,12))}`)},!1,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,()=>{console.debug(`${i}to reverb: ${w(s)}dB`)},()=>{console.debug(`${i}to chorus: ${w(s)}dB`)},()=>{console.debug(`${i}to delay: ${w(s)}dB`)},!1,()=>{console.debug(`${i}1 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}1 depth: ${s-64}`)},()=>{console.debug(`${i}2 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}2 depth: ${s-64}`)},()=>{console.debug(`${i}to EQ: ${s?"ON":"OFF"}`)}][t[0]+a]||function(c,h){console.warn(`Unknown GS EFX address: ${h}`)})(s,t[0]+a)})}).add([66,18,65],t=>{}).add([69,18,16],t=>{switch(t[0]){case 0:{let i=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",i);break}case 32:{e.#h=Date.now()+3200,t[1]==0&&(e.#n=Math.max(Math.min(t[2]-1,9),0));break}default:if(t[0]<11){e.#n>9&&(e.#n=0),e.#h=Date.now()+3200,e.#p[t[0]-1]?.length||(e.#p[t[0]-1]=new Uint8Array(256));let i=e.#p[t[0]-1],r=t[1];i.fill(0);let s=t.subarray(2);for(let a=0;a>4-g&1,g++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let n=function(t,i,r){let s=t[0],a=p.cc*i,c=p.rpn*i,h=`GS CH${i+1} `;s<3?t.subarray(1).forEach((l,d)=>{[()=>{e.#e[a+f[0]]=l},()=>{e.#s[i]=l},()=>{let u=e.chRedir(l,r,!0);e.#l[i]=u,i!=u&&(e.buildRchTree(),console.info(`${h}receives from CH${u+1}`))}][s+d]()}):s<19||(s<44?t.subarray(1).forEach((l,d)=>{([()=>{e.#S[i]=+!l},!1,()=>{e.setChType(i,l?l+1:0,y.gs),console.debug(`${h}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{e.#i[c+3]=l},!1,()=>{e.#e[a+f[7]]=l},!1,!1,()=>{e.#e[a+f[10]]=l||128},!1,!1,()=>{console.debug(`${h}CC 1: cc${l}`)},()=>{console.debug(`${h}CC 2: cc${l}`)},()=>{e.#e[a+f[93]]=l},()=>{e.#e[a+f[91]]=l},!1,!1,()=>{e.#i[c+1]=l},()=>{e.#i[c+2]=l},()=>{e.#e[a+f[94]]=l}][s+d-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},o=function(t,i){let r=t[0],s=`GS CH${i+1} `;r<2?t.subarray(1).forEach((a,c)=>{[()=>{e.#e[p.cc*i+f[32]]=a},()=>{}][r+c]()}):r<32?console.warn(`Unknown GS misc address: ${r}`):r<35?t.subarray(1).forEach((a,c)=>{[()=>{console.debug(`${s}EQ: o${["ff","n"][a]}`)},()=>{},()=>{console.debug(`${s}EFX: o${["ff","n"][a]}`)}][r+c-32]()}):console.warn(`Unknown GS misc address: ${r}`)};this.#P.add([66,18,64,16],(t,i)=>{n(t,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(t,i)=>{n(t,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(t,i)=>{n(t,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(t,i)=>{n(t,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(t,i)=>{n(t,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(t,i)=>{n(t,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(t,i)=>{n(t,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(t,i)=>{n(t,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(t,i)=>{n(t,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(t,i)=>{n(t,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(t,i)=>{n(t,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(t,i)=>{n(t,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(t,i)=>{n(t,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(t,i)=>{n(t,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(t,i)=>{n(t,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(t,i)=>{n(t,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(t,i)=>{o(t,e.chRedir(9,i,!0))}).add([66,18,64,65],(t,i)=>{o(t,e.chRedir(0,i,!0))}).add([66,18,64,66],(t,i)=>{o(t,e.chRedir(1,i,!0))}).add([66,18,64,67],(t,i)=>{o(t,e.chRedir(2,i,!0))}).add([66,18,64,68],(t,i)=>{o(t,e.chRedir(3,i,!0))}).add([66,18,64,69],(t,i)=>{o(t,e.chRedir(4,i,!0))}).add([66,18,64,70],(t,i)=>{o(t,e.chRedir(5,i,!0))}).add([66,18,64,71],(t,i)=>{o(t,e.chRedir(6,i,!0))}).add([66,18,64,72],(t,i)=>{o(t,e.chRedir(7,i,!0))}).add([66,18,64,73],(t,i)=>{o(t,e.chRedir(8,i,!0))}).add([66,18,64,74],(t,i)=>{o(t,e.chRedir(10,i,!0))}).add([66,18,64,75],(t,i)=>{o(t,e.chRedir(11,i,!0))}).add([66,18,64,76],(t,i)=>{o(t,e.chRedir(12,i,!0))}).add([66,18,64,77],(t,i)=>{o(t,e.chRedir(13,i,!0))}).add([66,18,64,78],(t,i)=>{o(t,e.chRedir(14,i,!0))}).add([66,18,64,79],(t,i)=>{o(t,e.chRedir(15,i,!0))}),this.#B.add([54,65],(t,i)=>{e.switchMode("x5d");let r=(t[1]<<7)+t[0],s=(t[3]<<7)+t[2],a=e.chRedir(r&15,i,!0),c=p.cc*a;[()=>{s<1||(s<101?(e.setChType(a,0,y.x5d),e.#s[a]=s-1,e.#e[c+f[0]]=82):s<229?(e.setChType(a,0,y.x5d),e.#s[a]=s-101,e.#e[c+f[0]]=56):(e.setChType(a,1,y.x5d),e.#s[a]=he[s-229]||0,e.#e[c+f[0]]=62))},()=>{e.#e[c+f[7]]=s},()=>{s<31&&(e.#e[c+f[10]]=Math.round((s-15)*4.2+64))},()=>{e.#e[c+f[93]]=O(s)},()=>{e.#e[c+f[91]]=O(s)},()=>{e.#i[a*p.rpn+3]=s>8191?s-16320:64+s},()=>{e.#i[a*p.rpn+1]=s>8191?s-16320:64+s},()=>{s>0&&(e.#i[a*p.rpn]=s)},()=>{}][r>>4]()}).add([54,76,0],(t,i)=>{e.switchMode("x5d",!0);let r="",s=82,a=0,c=0,h="MSB PRG LSB NME";S(t,function(l,d){if(d<16400){let u=d%164;switch(!0){case u<10:{l>31&&(r+=String.fromCharCode(l));break}case u==11:{h+=` +${s} ${a} ${c} ${r.trim().replace("Init Voice","")}`,a++,r="";break}}a>99&&(s=90,a=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(h)}).add([54,77,0],(t,i)=>{e.switchMode("x5d",!0);let r="",s=90,a=0,c=0,h="MSB PRG LSB NME";S(t,function(l,d){if(d<13600){let u=d%136;switch(!0){case u<10:{l>31&&(r+=String.fromCharCode(l));break}case u==11:{h+=` +${s} ${a} ${c} ${r.trim().replace("Init Combi","")}`,a++,r="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(h)}).add([54,78],(t,i)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][t[0]]} mode.`)}).add([54,85],(t,i)=>{e.switchMode("x5d",!0),S(t,(r,s)=>{s>0&&s<3&&e.setEffectType(s-1,44,r)})}).add([54,104],(t,i)=>{e.switchMode("x5d",!0),S(t,function(r,s,a,c){if(s<192){let h=e.chRedir(Math.floor(s/12),i,!0),l=h*p.cc;switch(s%12){case 0:{r<128?(e.setChType(h,0,y.x5d),e.#e[l+f[0]]=82,e.#s[h]=r):(e.setChType(h,1,y.x5d),e.#e[l+f[0]]=62,e.#s[h]=he[r-128]),r>0&&(e.#c[h]=1);break}case 1:{e.#e[l+f[7]]=r;break}case 2:{e.#i[h*p.rpn+3]=r>127?r-192:64+r;break}case 3:{e.#i[h*p.rpn+1]=r>127?r-192:64+r;break}case 4:{r<31&&(e.#e[l+f[10]]=Math.round((r-15)*4.2+64));break}case 5:{let d=r>>4,u=r&15;e.#e[l+f[91]]=O(u),e.#e[l+f[93]]=O(d);break}case 10:break;case 11:{let d=e.chRedir(r&15,i,!0),u=r>>4;e.#l[h]=r,(d!=h||u)&&(console.info(`X5D Part CH${h+1} receives from CH${d+1}.`),e.buildRchTree())}}}else{let h=e.chRedir(s-192,i,!0)}})}),this.#P.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#o=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(t,i,r)=>{e.switchMode("mt32");let s=e.chRedir(r,i,!0),a=t[1];t.subarray(2).forEach((c,h)=>{let l=h+a;e.#D[l+(s-1)*16]=c,([!1,()=>{let d=e.#D[s-1<<4];if(d<3)if(e.#T[s]=1,d==2)for(let u=0;u{e.#i[s*p.rpn+3]=c+40},()=>{e.#i[s*p.rpn+1]=c+14},()=>{e.#i[s*p.rpn]=c},!1,()=>{e.#e[p.cc*s+f[91]]=c?127:0},!1,()=>{e.#e[p.cc*s+f[7]]=c},()=>{e.#e[p.cc*s+f[10]]=Math.ceil(c*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(t,i,r)=>{e.switchMode("mt32");let s=e.chRedir(r,i,!0)}).add([22,18,2],(t,i,r)=>{e.switchMode("mt32");let s=e.chRedir(r,i,!0),a=t[1]+(t[0]<<7);a<10&&(e.#T[s]=1),t.subarray(2).forEach((c,h)=>{let l=h+a;l<14&&(e.#w[(s-1)*p.cmt+l]=c)})}).add([22,18,3],(t,i,r)=>{if(e.switchMode("mt32"),t[0]){let s=t[1]-16}else{let s=t[1];t.subarray(2).forEach((a,c)=>{let h=c+s;e.#D[h]=a;let l=e.chRedir(1+h>>4,i,!0),d=h&15;([!1,()=>{let u=e.#D[l-1<<4];if(u<3)if(e.#T[l]=1,u==2)for(let g=0;g{e.#i[l*p.rpn+3]=a+40},()=>{e.#i[l*p.rpn+1]=a+14},()=>{e.#i[l*p.rpn]=a},!1,()=>{e.#e[p.cc*l+f[91]]=a?127:0},!1,()=>{e.#e[p.cc*l+f[7]]=a},()=>{e.#e[p.cc*l+f[10]]=Math.ceil(a*9.05)}][d]||(()=>{}))()})}}).add([22,18,4],(t,i,r)=>{e.switchMode("mt32");let s=t[1]+(t[0]<<7);t.subarray(2).forEach((a,c)=>{let h=c+s,l=e.chRedir(Math.floor(h/246+1),i,!0),d=h%246;d<14&&(e.#w[(l-1)*p.cmt+d]=a),d<10&&(e.#T[l]=1)})}).add([22,18,5],(t,i,r)=>{e.switchMode("mt32");let s=(t[0]<<7)+t[1];t.subarray(2).forEach((a,c)=>{let h=s+c,l=Math.floor(h/8),d=h&7,u=l*8;e.#F[h]=a,([!1,()=>{let g=e.#F[u];if(g<3){let b="";if(g==2){let m=p.cmt*l;b=`MT-m:${a.toString().padStart(3,"0")}`}else b=e.baseBank.get(0,a+(g<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l}),e.userBank.load(`MSB LSB PRG NME +000 127 ${l} ${b}`,!0)}}][d]||(()=>{}))()})}).add([22,18,8],(t,i,r)=>{e.switchMode("mt32");let s=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((a,c)=>{let h=s+c;h>1)*p.cmt+h]=a)})}).add([22,18,16],(t,i,r)=>{e.switchMode("mt32");let s=t[1],a=!1,c=function(h,l){e.#l[l-12]=h,a=!0};t.subarray(2).forEach((h,l)=>{let d=l+s;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,c,c,c,c,c,c,c,c,c,()=>{e.#v=h}][d]||(()=>{}))(h,l)}),a&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let i=t[1],r=" ".repeat(i);t.subarray(2).forEach(s=>{s>31&&(r+=String.fromCharCode(s))}),e.#M=r.padStart(20," "),e.#N=Date.now()+3200}).add([22,18,82],(t,i)=>{let r=e.chRedir(0,i,!0);for(let s=0;s<16;s++)e.#u.ano(r+s),s&&s<10&&(e.#s[r+s]=G[s-1]);console.info("MT-32 alt reset complete.")}),this.#B.add([66,0],(t,i)=>{e.switchMode("ns5r",!0),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,i)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#o=!1}).add([66,18,0,0],(t,i)=>{let r=t[0];switch(r){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#o=!1;break}case 125:break;default:if(r<10){let s=[0,0,0,0],a=(c,h)=>{s[h]=c};if(t.subarray(1).forEach((c,h)=>{[a,a,a,a,()=>{e.#v=c*129/16383*100},()=>c-64,()=>c-64,()=>{},()=>{},()=>{}][r+h]()}),t[0]<4){let c=0;s.forEach(h=>{c=c<<4,c+=h}),c-=1024}}}}).add([66,18,0,1],(t,i)=>{}).add([66,18,0,2],(t,i)=>{}).add([66,18,1],(t,i)=>{let r=e.chRedir(t[0],i,!0),s=r*p.cc,a=t[1],c=`NS5R CH${r+1}`;t.subarray(2).forEach((h,l)=>{let d=a+l;d<3?[()=>{e.#e[s+f[0]]=h||121},()=>{e.#e[s+f[32]]=h},()=>{e.#s[r]=h}][d]():d<8||(d<14?[()=>{let u=e.chRedir(h,i,!0);e.#l[r]=u,r!=u&&(e.buildRchTree(),console.info(`${c}receives from CH${u+1}`))},()=>{e.#S[r]=+!h},()=>{e.setChType(r,h,y.ns5r),console.debug(`${c}type: ${L[h]}`)},()=>{e.#i[p.rpn*r+3]=h},()=>{},()=>{}][d-8]():d<16||(d<33?[()=>{e.#e[s+f[7]]=h},()=>{e.#e[s+f[11]]=h},()=>{},()=>{},()=>{e.#e[s+f[10]]=h||128},()=>{},()=>{},()=>{e.#e[s+f[93]]=h},()=>{e.#e[s+f[91]]=h},()=>{e.#e[s+f[76]]=h},()=>{e.#e[s+f[77]]=h},()=>{e.#e[s+f[78]]=h},()=>{e.#e[s+f[74]]=h},()=>{e.#e[s+f[71]]=h},()=>{e.#e[s+f[73]]=h},()=>{e.#e[s+f[75]]=h},()=>{e.#e[s+f[72]]=h}][d-16]():d<112||d<114&&[()=>{e.#e[s+f[5]]=h},()=>{e.#e[s+f[65]]=h}][d-112]()))})}).add([66,18,8,0],(t,i)=>{let r=t[0];if(r<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let s=r-32;e.#h=Date.now()+3200,e.#n=10,e.#g.fill(0);let a=t.subarray(1),c=4;a.forEach(function(h,l){let d=l+s,u=d>>4,g=d&15;if(d<80){let b=u>3,m=0,$=u0;)e.#g[g*32+u*7+($-m)]=b&1,b=b>>1,m++}})}}).add([66,52],(t,i)=>{e.switchMode("ns5r",!0),e.#o=!1;let r="";S(t,(s,a)=>{a<8?(s>31&&(r+=String.fromCharCode(s)),a==7&&(e.aiEfxName=r)):a<10&&e.setEffectType(a-8,44,s)})}).add([66,53],(t,i)=>{e.switchMode("ns5r",!0),e.#o=!1,S(t,function(r,s){switch(!0){case s<2944:{let a=e.chRedir(Math.floor(s/92),i,!0),c=a*p.cc;switch(s%92){case 0:{e.#e[c+f[0]]=r||121;break}case 1:{e.#e[c+f[32]]=r;break}case 2:{e.#s[a]=r,r>0&&(e.#c[a]=1);break}case 3:{let h=e.chRedir(r,i,!0);e.#l[a]=h,a!=h&&(console.info(`NS5R CH${a+1} receives from CH${h+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#i[a*p.rpn+3]=r<40||r>88?r+(r>63?-192:64):r;break}case 9:case 10:{e.#e[c+f[7]]=r;break}case 11:{e.#e[c+f[11]]=r;break}case 14:{e.#e[c+f[10]]=r||128;break}case 19:{e.#e[c+f[93]]=r;break}case 20:{e.#e[c+f[91]]=r;break}case 84:{e.#e[c+f[65]]=r;break}case 85:{e.#e[c+f[5]]=r;break}}break}case s<3096:break;case s<3134:break;case s<8566:break}})}).add([66,54],(t,i)=>{e.switchMode("ns5r",!0);let r="",s=80,a=0,c=0,h="MSB PRG LSB NME";S(t,function(l,d){let u=d%158;switch(!0){case u<10:{l>31&&(r+=String.fromCharCode(l));break}case u==11:{s=l&127;break}case u==12:{c=l&127;break}case u==13:{h+=` +${s} ${a} ${c} ${r.trim().replace("Init Voice","")}`,a++,r="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(h)}).add([66,55],(t,i)=>{e.switchMode("ns5r",!0);let r="",s=88,a=0,c=0,h="MSB PRG LSB NME";S(t,function(l,d){let u=d%126;switch(!0){case u<10:{l>31&&(r+=String.fromCharCode(l));break}case u==11:break;case u==12:break;case u==13:{h+=` +${s} ${a} ${c} ${r.trim().replace("Init Combi","")}`,a++,r="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(h)}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let i=new Uint8Array(5760);S(t,(r,s,a)=>{if(s<720)for(let c=0;c<8;c++)i[s*8+c]=r>>7-c&1}),e.dispatchEvent("screen",{type:"ns5r",data:i})}).add([76],(t,i,r)=>{e.#B.run([66,...t],i,r)}),this.#W.add([16,0,8,0],(t,i,r)=>{let s=(t[2]<<4)+t[3],a="K11 ";([()=>{e.switchMode("k11",!0),e.#o=!1,e.#E=s?4:0,console.info("MIDI reset: GMega/K11")},()=>{console.debug(`${a}reverb type: ${s}`)},()=>{console.debug(`${a}reverb time: ${s}`)},()=>{console.debug(`${a}reverb time: ${s}`)},()=>{console.debug(`${a}reverb predelay: ${s}`)},()=>{console.debug(`${a}reverb predelay: ${s}`)},()=>{console.debug(`${a}depth high: ${s}`)},()=>{console.debug(`${a}depth high: ${s}`)},()=>{console.debug(`${a}depth low: ${s}`)},()=>{console.debug(`${a}depth low: ${s}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,i,r)=>{let s=e.chRedir(t[1],i,!0),a=p.cc*s,c=p.rpn*s,h=(t[3]<<4)+t[4],l=`K11 CH${s+1} `;([()=>{h<128?(e.setChType(s,0,y.k11),e.#e[a+f[0]]=0,e.#s[s]=h):(e.setChType(s,1,y.k11),e.#s[s]=h-128)},()=>{let d=e.chRedir(h,i,!0);e.#l[s]=d,s!=d&&(e.buildRchTree(),console.info(`${l}receives from CH${d+1}`))},()=>{e.#e[a+f[7]]=h},()=>{e.#c[s]=h},()=>{e.#e[a+f[10]]=h},()=>{e.#i[c+3]=h+40},()=>{e.#i[c+1]=h>>1,e.#i[c+2]=h&1},()=>{e.#e[a+f[91]]=h?127:0},()=>{},()=>{e.#e[a+f[74]]=h},()=>{e.#e[a+f[73]]=h},()=>{e.#e[a+f[72]]=h}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,i,r)=>{let s=(t[2]<<4)+t[3],a="GMLX ";([()=>{console.debug(`${a}reverb type: ${s}`)},()=>{console.debug(`${a}reverb time: ${s}`)},()=>{console.debug(`${a}reverb predelay: ${s}`)},()=>{console.debug(`${a}depth high: ${s}`)},()=>{console.debug(`${a}depth low: ${s}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,i,r)=>{let s=(t[2]<<4)+t[3],a=e.chRedir(t[1],i,!0),c=a*p.cc;[()=>{s<128?(e.setChType(a,0,y.k11),e.#e[c+f[0]]=0,e.#e[c+f[32]]=0,e.#s[a]=s):s<160?(e.setChType(a,0,y.k11),e.#e[c+f[0]]=0,e.#e[c+f[32]]=7,e.#s[a]=s-100):(e.setChType(a,1,y.k11),e.#e[c+f[0]]=122,e.#e[c+f[32]]=0,e.#s[a]=s-160)},()=>{let h=e.chRedir(s,i,!0);e.#l[a]=h,a!=h&&(e.buildRchTree(),console.info(`GMLX CH${a+1} receives from CH${h+1}`))}][t[0]]()}).add([16,0,9,4],(t,i,r)=>{let s=(t[2]<<4)+t[3],a=e.chRedir(t[1],i,!0),c=a*p.cc,h=a*p.rpn,l=`GMLX CH${a+1} `;[()=>{e.#c[a]=s},()=>{e.#e[c+f[7]]=s},()=>{e.#e[c+f[10]]=s},()=>{e.#e[c+f[91]]=s?127:0},()=>{e.#i[h+3]=s+40},()=>{e.#i[h+1]=s},()=>{e.#i[h]=s},()=>{}][t[0]]()}),this.#q.add([66,93,64],(t,i,r)=>{let s=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{e.#v=s*129/16383*100;break}case 5:{s-64;break}case 6:{console.debug(`SG global reverb: ${s?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(t[1]){case 48:{console.debug(`SG reverb type: ${B[s]}`);break}}break}default:if(t[0]>>4==1){let a=e.chRedir(t[0]&15,i,!0);if(t[1]==2){let c=e.chRedir(s,i,!0);e.#l[a]=c,a!=c&&(e.buildRchTree(),console.info(`SG CH${a+1} receives from CH${c+1}`))}else t[1]==19&&(e.#e[p.cc*a+f[7]]=s)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),this.#j.add([9],(t,i,r)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)})}};var K=xe(ue(),1);var pe=class{#t=!1;constructor(e,n,o,t){this.#t=e,this.start=n,this.end=o,this.data=t}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#t}},V=class extends pe{constructor(e,n,o){super(!0,e,n,o)}},ge=class extends pe{constructor(e,n){super(!1,e,e,n)}},X=class extends Array{#t=-1;constructor(){super(...arguments)}resetIndex(e){this.#t=-1}fresh(){this.sort(function(e,n){return e.start==n.start?0:(+(e.start>n.start)<<1)-1}),this.forEach(function(e,n){e.index=n})}step(e,n=!1){let o=[];if(n)for(let t=0;te);t++){if(this[t].endi.#t&&(o.push(r),i.#t=r.index)})}return o}getRange(e,n){e>n&&([e,n]=[n,e]);let o=[],t=-1,i=Math.ceil(Math.sqrt(this.length)),r=!0;for(let s=0;s=e&&(t=s):t=t<0?s:t;for(;r;)this[t]?.end=e&&o.push(this[t]):r=!1,t++;return o}};var Ue=0xffffffffffff,be=function(e){let n=new X,o=this,t=e.timeDivision,i=120,r=new X,s=0,a=0;r.push(new V(0,Ue,[120,0])),e.track.forEach(function(d){s=0,d.event.forEach(function(u){s+=u.deltaTime,u.type==255&&u?.metaType==81&&(i=6e7/u.data,r[r.length-1]&&r.push(new V(s,0xffffffffffff,[i,0])))})}),r.fresh(),r.forEach(function(d,u,g){u>0&&(g[u-1].end=d.start)});let c=120;r.forEach(function(d,u,g){u>0&&(d.end==d.start?g.splice(g.indexOf(d),1):c==d.data[0]&&(g[u-1].end=d.end,g.splice(g.indexOf(d),1)),c=d.data[0])});let h=0,l=120;return r.forEach(function(d){let u=d.start,g=u/l/t*60+h;l=d.data[0],h=g-u/l/t*60,d.data[1]=h}),console.debug("All tempo changes: ",r),i=120,s=0,a=0,e.track.forEach(function(d,u){s=0,a=0;let g=u+1;d.event.forEach(function(b,m){s+=b.deltaTime;let $=r.step(s,!0)[0];$&&(i=$.data[0],a=$.data[1]);let v={type:b.type,data:b.data,track:g,part:0};b.type>14?v.meta=b.metaType:v.part=b.channel,n.push(new ge(s/i/t*60+a,v))})}),n.fresh(),self.midiEvents=n,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),n};K.default.customInterpreter=ae;var $e=class extends A{device;#t;#n="";#h=[];#p=new Uint8ClampedArray(128);#g=new Uint8ClampedArray(128);#c=.5;#l=120;#r=4;#e=4;#b=0;#s=0;smoothingAtk=0;smoothingDcy=0;reset(){this.dispatchEvent("reset"),this.#t?.resetIndex(),this.device.init(),this.#n="",this.#c=.5,this.#l=120,this.#r=4,this.#e=4,this.#b=0,this.#s=0}async loadFile(e){this.#t=be(K.default.parse(new Uint8Array(await e.arrayBuffer())))}switchMode(e,n=!1){this.device.switchMode(e,n)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}get noteProgress(){return this.#s/this.#c}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.#e]}getTempo(){return this.#l}sendCmd(e){this.device.runJson(e)}render(e){e>this.#s&&(this.#s=e);let n=this.#t?.step(e)||[],o=0,t=new Set,i=this,r=[];this.device.getStrength().forEach((m,$)=>{this.#g[$]=m}),i.device.newStrength(),n.forEach(function(m){let $=m.data;$.type==9&&($.data[1]>0?t.add($.part*128+$.data[0]):t.has($.part*128+$.data[0])&&o++),m.data.type==8&&t.has($.part*128+$.data[0])&&o++;let v=i.device.runJson($);switch(v?.reply){case"meta":{r.push(v);break}}v?.reply&&delete v.reply}),r?.length>0&&this.dispatchEvent("meta",r);let s=this.device.getActive(),a=[],c=i.device.getPitch(),h=i.device.getCcAll(),l=i.device.getProgram(),d=i.device.getChType(),u=this.device.getStrength();u.forEach(function(m,$,v){v[$]=Math.max(i.#g[$],m);let M=v[$]-i.#p[$],z=f.length*$;if(M>=0){let D=4*.25**(h[z+f[73]]/64);i.#p[$]+=Math.ceil(M-M*i.smoothingAtk**D)}else{let D=4*.25**(h[z+f[72]]/64);i.#p[$]+=Math.floor(M-M*i.smoothingDcy**D)}});let g=0;return s.forEach(function(m,$){m&&(a[$]=i.device.getVel($),g+=a[$].size)}),{extraPoly:o,curPoly:g,chInUse:s,chKeyPr:a,chPitch:c,chProgr:l,chContr:h,chType:d,eventCount:n.length,title:this.#n,bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:this.#p.slice(),velo:u,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce()}}constructor(e,n=.5,o=.5){super();let t=this;this.smoothingAtk=n,this.smoothingDcy=o,this.device=e,this.addEventListener("meta",function(i){i?.data?.forEach(function(r){(t.#h[r.meta]||console.debug).call(t,r.meta,r.data)})}),this.device.addEventListener("mode",function(i){t.dispatchEvent("mode",i.data)}),this.device.addEventListener("channelactive",function(i){t.dispatchEvent("channelactive",i.data)}),this.device.addEventListener("channelmin",function(i){t.dispatchEvent("channelmin",i.data)}),this.device.addEventListener("channelmax",function(i){t.dispatchEvent("channelmax",i.data)}),this.device.addEventListener("channelreset",function(i){t.dispatchEvent("channelreset")}),this.device.addEventListener("screen",function(i){t.dispatchEvent("screen",i.data)}),this.#h[3]=function(i,r){t.#n?.length<1&&(t.#n=r)},this.#h[81]=function(i,r){let s=t.noteProgress,a=t.#c||.5;t.#l=6e7/r,t.#c=r/1e6,t.#b+=s*(a/t.#c)-s},this.#h[88]=function(i,r){let s=t.noteProgress,a=t.noteOverall,c=t.noteBar,h=t.noteBeat,l=t.#r,d=t.#e;t.#r=r[0],t.#e=1<=l&&(l>1)*(n>>(this.mode>1?5:4))+this.device.getPitchShift(n)/12*this.noteRegW,a=(3+n%(this.mode>1?32:16))*this.lineHeight+this.noteTops[o%12]*this.noteHeight;if(t>0)switch(r.fillStyle=`#ffffff${(t*2).toString(16).padStart(2,"0")}`,r.fillRect(s+1,a+1,this.noteWidth-2,this.noteHeight-2),i){case this.device.NOTE_HELD:case this.device.NOTE_SOSTENUTO_HELD:{r.clearRect(s+1+this.noteOutline,a+1+this.noteOutline,this.noteWidth-2*(1+this.noteOutline),this.noteHeight-2*(1+this.noteOutline));break}}}render(n){let o=super.render(n),t=this,i=this.context,r=Date.now();i.globalCompositeOperation="source-over",i.clearRect(0,0,i.canvas.width,i.canvas.height),i.font=`${this.lineHeight-this.fontPadding*2}px "Noto Sans Mono", "Noto Sans Mono Web", mono`,self.metrics=i.measureText("Op");let s=metrics.actualBoundingBoxLeft,a=metrics.actualBoundingBoxAscent;i.fillStyle="#fff",i.fillText(`${o.eventCount.toString().padStart(3,"0")} ${(o.curPoly+o.extraPoly).toString().padStart(3,"0")}/512 ${o.tSig[0].toString().padStart(2," ")}/${o.tSig[1].toString().padEnd(2," ")} ${(o.noteBar+1).toString().padStart(3," ")}:${Math.floor(o.noteBeat+1).toString().padEnd(2," ")} ${Math.floor(o.tempo).toString().padStart(3," ")}.${Math.floor(o.tempo*100%100).toString().padStart(2,"0")}bpm ${Math.floor(o.master.volume).toString().padStart(3," ")}.${Math.floor(o.master.volume*100%100).toString().padStart(2,"0")}%`,t.fontPadding+s,a+t.fontPadding),i.fillText("Voices VEMRCDBP12",t.fontPadding+s,a+t.fontPadding+t.lineHeight*2),o.chKeyPr.forEach((c,h)=>{c.forEach((l,d)=>{let u=t.startPort<<4,g=(t.startPort<<4)+(16<=u&&h{let h=t.startPort<<4,l=(t.startPort<<4)+(16<=h&&c.part1?32:16)),d=t.device.getChVoice(h);i.fillText(`${h+1}`.padStart(2,"0"),t.fontPadding+s+(c>>(this.mode>1?5:4))*(i.canvas.width>>1),l,t.noteWidth*2.5),i.fillText(d.name,t.fontPadding+s+(c>>(this.mode>1?5:4))*(i.canvas.width>>1)+t.noteWidth*3,l,t.noteWidth*13);let u=f.length*h;[7,11,1,91,93,94,74,5,12,13].forEach((g,b)=>{i.fillRect(t.fontPadding*2+t.noteWidth*(16+b)+(c>>(this.mode>1?5:4))*(i.canvas.width>>1),t.lineHeight*(4+c%(this.mode>1?32:16)),t.noteWidth-t.noteOutline,(t.lineHeight-1)*(o.chContr[u+f[g]]/-127))})}}o.letter.expire<=r,i.globalCompositeOperation="xor",i.fillStyle="#fff";for(let c=0;c<16<>(this.mode>1?5:4))*(i.canvas.width>>1),t.lineHeight*(3+c%(this.mode>1?32:16)),t.noteWidth*16*(o.strength[h]/255),t.lineHeight-1)}for(let c in t.eventBuffer)delete t.eventBuffer[c];for(;t.eventQueue.length>0;)delete t.eventQueue[0],t.eventQueue.shift()}constructor(n){super(new fe,.1,.75);let o=this;this.context=n,this.resizeCanvas(1280,720),this.device.addEventListener("note",t=>{let i=t.data,r=i.part*128+i.note,s=this.eventBuffer[r];this.eventBuffer[r]=i,s?.velo>0&&i.velo==0&&this.eventQueue.push(s)})}},Et=Ne;export{Et as default}; diff --git a/dist/state.mjs b/dist/state.mjs index 62593db0..cdd18820 100644 --- a/dist/state.mjs +++ b/dist/state.mjs @@ -136,8 +136,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let n=e.split(",");A[n[0]]=n[1]});var F=function(e){let n=e;e[0]=="*"&&(n=n.slice(1)),["aa","ii","uu","ee","oo"].forEach(t=>{for(;n.indexOf(t)>-1;)n=n.replace(t,t[0])});for(let t in A)n=n.replaceAll(t,A[t]);n.indexOf("ん")==0&&n.length>1&&(n=n.slice(1));let c=n.indexOf("!");return c>-1&&n.length>1&&(n=n.slice(c+1)),n},K=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var G=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],V=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],z=["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 ie={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"},re={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]]},U=function(e){return ie[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},Q=function(e,n,c){let t=(e[0]-32<<16)+(e[1]<<8)+n,s=re[t]||{},r=s[0];if(r?.length)return r+=`: ${(s[1]||function(){})(c)||c}`,r},N=[68,48,95,78,41,3,110,122,0];var y=function(e=64){return Math.round(2e3*Math.log10(e/64))/100};var q=function(e){let n=0;return e.forEach(c=>{n+=c,n=n&127}),~n+1&127},k=function(e,n){let c=0,t=0;for(let s=0;s>r&1)<<7,a=e[s];a+=i,s%8!=0?(n(a,c,e),c++):t=e[s]}},M=function(e){let n=Math.floor(e*14.2);return n<128?n:0};var S=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],Y=[[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],ne=[0,3,81,84,88],W={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},P={0:0,1:1,2:3,5:4},J=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Z=[36,37];var C=[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],ce=[12,13,16,17,18,19],oe=[33,99,100,32,102,8,9,10],j=[0,16,25,40,32,64,26,48],$={};S.forEach((e,n)=>{$[e]=n});var f={length:C.length};C.forEach((e,n)=>{f[e]=n});var E=function(){return!!self.Bun||self.debugMode||!1},le=function(e){let n=[],c=0;return e?.forEach(function(t,s){t==247?n.push(e.subarray(c,s)):t==240&&(c=s+1)}),n.length||n.push(e.subarray(0)),E()&&console.debug(n),n},ee=function(e,n="",c="",t=2){return e?`${n}${e.toString().padStart(t,"0")}${c}`:""},d={ch:128,cc:C.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,efx:7},ve=class extends L{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#u=0;#k=0;#M=new Array(11);get#b(){return this.#M[this.#u]}set#b(e){this.#M[this.#u]=e}#p=new Uint8Array(d.ch);#f=new Uint8Array(d.ch);#i=new Uint8Array(d.ch);#e=new Uint8Array(d.ch*d.cc);#C=new Uint8Array(d.ace);#r=new Uint8Array(d.ch);#c=new Uint8Array(d.ch*d.nn);#m=new Uint8Array(d.ch);#o=new Uint16Array(d.pl);#h=new Uint8Array(d.pl);#D=new Int16Array(d.ch);#S=new Uint8Array(d.ch);#B=0;#s=new Uint8Array(d.ch*d.rpn);#I=new Int8Array(d.ch*Z.length);#x=new Uint8Array(d.ch);#G=new Uint8Array(128);#y=new Uint8Array(d.cmt*8);#X=new Uint8Array(1024);#U=new Uint8Array(d.cmt*64);#$=new Uint8Array(d.efx*3);#N=0;#E=0;#g=100;#v=0;#F=500;#K=0;#T="";#P=0;#V=0;#w=!0;#n=!1;#J;#ee=new Uint8Array(2);#a=[];#R=new Uint8Array(d.ch);#H=new Uint8Array(d.tr);baseBank=new O("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new O("gm");initOnReset=!1;aiEfxName="";chRedir(e,n,c){if(this.#H[n])return(this.#H[n]-1)*16+e;if([2,3].indexOf(this.#E)>-1){if(c==1)return e;let t=0,s=!0;for(;s;)this.#R[e+t]==0?(this.#R[e+t]=n,console.debug(`Assign track ${n} to channel ${e+t+1}.`),s=!1):this.#R[e+t]==n?s=!1:(t+=16,t>=128&&(t=0,s=!1));return e+t}else return e}#d=[];#_;#l={nOff:(e,n)=>{let c=e*128+n,t=this.#o.lastIndexOf(c);t>-1&&(this.#e[d.cc*e+f[64]]>63?(this.#h[t]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#c[c],state:this.NOTE_HELD})):this.#e[d.cc*e+f[66]]>63&&this.#h[t]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#h[t]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#c[c],state:this.NOTE_SOSTENUTO_HELD})):(this.#o[t]=0,this.#c[c]=0,this.#h[t]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:n,velo:0,state:this.NOTE_IDLE})))},nOn:(e,n,c)=>{let t=e*128+n,s=0;for(this.#m[e]&&this.#l.ano(e);this.#h[s]>0&&this.#o[s]!=t;)s++;s{},cAt:(e,n)=>{},hoOf:e=>{this.#h.forEach((n,c)=>{if(n==this.NOTE_HELD){let t=this.#o[c],s=t>>7;e==s&&(this.#h[c]=this.NOTE_IDLE,this.#o[c]=0,this.#c[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#h.forEach((n,c)=>{let t;switch(n){case this.NOTE_ATTACK:{t=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{t=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{t=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(t){this.#h[c]=t;let s=this.#o[c];this.dispatchEvent("note",{part:e,note:s&127,velo:this.#c[s],state:t})}})},soOf:e=>{this.#h.forEach((n,c)=>{if(n==this.NOTE_SOSTENUTO_HELD){let t=this.#o[c],s=t>>7;e==s&&(this.#h[c]=this.NOTE_IDLE,this.#o[c]=0,this.#c[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#o.forEach((n,c,t)=>{let s=n>>7,r=n&127;n==0&&this.#c[0]==0||s==e&&this.#l.nOff(s,r)})}};#Z={8:function(e){let n=e.channel,c=e.data[0];this.#l.nOff(n,c)},9:function(e){let n=e.channel;this.#p[n]=1;let c=e.data[0],t=e.data[1];t>0?this.#l.nOn(n,c,t):this.#l.nOff(n,c)},10:function(e){let n=e.channel,c=n*128+e.data[0];this.#o.indexOf(c)>-1&&(this.#c[c]=data[1],this.dispatchEvent("note",{part:n,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let n=e.channel;this.#p[n]=1;let c=n*d.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#l.ano(n),this.#D[n]=0;let t=n*d.cc;this.#e[t+f[1]]=0,this.#e[t+f[5]]=0,this.#e[t+f[64]]=0,this.#e[t+f[65]]=0,this.#e[t+f[66]]=0,this.#e[t+f[67]]=0,this.#e[t+f[11]]=127,this.#e[t+f[101]]=127,this.#e[t+f[100]]=127,this.#e[t+f[99]]=127,this.#e[t+f[98]]=127;return}case 123:{this.#l.ano(n);return}case 124:{this.#l.ano(n);return}case 125:{this.#l.ano(n);return}case 126:{this.#m[n]=1,this.#l.ano(n);return}case 127:{this.#m[n]=0,this.#l.ano(n);return}}if(f[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(ce.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{if(E()&&console.debug(`${S[this.#t]}, CH${n+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#i[n]>0&&(e.data[1]=this.#e[c],e.data[1]=120,console.debug(`Forced channel ${n+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==$.gs)e.data[1]<56&&this.#i[n]>0&&(e.data[1]=this.#e[c],e.data[1]=120,console.debug(`Forced channel ${n+1} to stay drums.`));else if(this.#t==$.gm)e.data[1]<48?this.#i[n]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${n+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0);else if(this.#t==$.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let t=0;for(let s=0;s<16;s++){let r=this.#e[d.cc*s];(r==56||r==62)&&t++}t>14&&this.switchMode("ag10",!0)}}switch(this.#t){case $.xg:{[126,127].indexOf(e.data[1])>-1?this.#i[n]==0&&(this.setChType(n,1),console.debug(`CH${n+1} set to drums by MSB.`)):this.#i[n]>0&&(this.setChType(n,0),console.debug(`CH${n+1} set to melodic by MSB.`));break}case $["05rw"]:case $.x5d:case $.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#i[n]==0&&(this.setChType(n,1),console.debug(`CH${n+1} set to drums by MSB.`)):this.#i[n]>0&&(this.setChType(n,0),console.debug(`CH${n+1} set to melodic by MSB.`));break}case $.g2:{e.data[1]==120?this.#i[n]==0&&(this.setChType(n,1),console.debug(`CH${n+1} set to drums by MSB.`)):this.#i[n]>0&&(this.setChType(n,0),console.debug(`CH${n+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:n});break}case 6:{if(this.#B){let t=this.#e[c+f[99]],s=this.#e[c+f[98]];if(t==1){let r=oe.indexOf(s);if(r>-1)this.#e[c+f[71+r]]=e.data[1],E()&&console.debug(`Redirected NRPN 1 ${s} to cc${71+r}.`),this.dispatchEvent("cc",{part:n,cc:71+r,data:e.data[1]});else{let i=Z.indexOf(s);i>-1&&(this.#I[n*10+i]=e.data[1]-64),E()&&console.debug(`CH${n+1} voice NRPN ${s} commit`)}}}else{let t=P[this.#e[c+f[100]]];this.#e[c+f[101]]==0&&t!=null&&(E()&&console.debug(`CH${n+1} RPN 0 ${this.#e[c+f[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],J[t][0]),J[t][1]),this.#s[n*d.rpn+t]=e.data[1])}break}case 32:{this.dispatchEvent("voice",{part:n});break}case 38:{this.#B||this.#e[c+101]==0&&P[this.#e[c+100]]!=null&&(this.#s[n*d.rpn+P[this.#e[c+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#l.hoOf(n);break}case 66:{e.data[1]>>6?this.#l.soOn(n):this.#l.soOf(n);break}case 98:case 99:{this.#B=1;break}case 100:case 101:{this.#B=0;break}}this.#e[c+f[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:n,cc:e.data[0],data:e.data[1]})}},12:function(e){let n=e.channel;this.#p[n]=1,this.#r[n]=e.data,this.#x[n]=0,E()&&console.debug(`T:${e.track} C:${n} P:${e.data}`),this.dispatchEvent("voice",{part:n})},13:function(e){let n=this,c=e.channel;this.#o.forEach(function(t){let s=t>>7;c==s&&(n.#c[t]=e.data,n.dispatchEvent("note",{part:c,note:t&127,velo:e.data,state:n.NOTE_SUSTAIN}))})},14:function(e){let n=e.channel;this.#D[n]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:n,pitch:this.getPitchShift(n)})},15:function(e){le(e.data).forEach(n=>{let c=n[0],t=n[1];(this.#j[c]||function(){console.debug(`Unknown manufacturer ${c}.`)})(t,n.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,t,s){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#v=0);let n=ne.indexOf(e.meta)>-1;if(E()&&console.debug(e),n)return e.reply="meta",e}};#j={64:(e,n,c)=>{this.#q.run(n,c,e)},65:(e,n,c)=>{if(n[0]<16)this.#A.run(n,c,e),console.warn("Unknown device SysEx!");else{let t=n[n.length-1],s=q(n.subarray(2,n.length-1));t==s?this.#A.run(n.subarray(0,n.length-1),c,e):console.warn(`Bad GS checksum ${t}. Should be ${s}.`)}},66:(e,n,c)=>{this.#L.run(n,c,e)},67:(e,n,c)=>{this.#O.run(n,c,e)},68:(e,n,c)=>{this.#W.run(n,c,e)},71:(e,n,c)=>{this.#Y.run(n,c,e)},126:(e,n,c)=>{this.#z.run(n,c,e)},127:(e,n,c)=>{this.switchMode("gm"),this.#Q.run(n,c,e)}};#z;#Q;#O;#A;#L;#q;#Y;#W;buildRchTree(){let e=[];this.#f.forEach((n,c)=>{e[n]?.constructor||(e[n]=[]),e[n].push(c)}),this.#J=e}getActive(){let e=this.#p.slice();return this.#t==$.mt32,e}getCc(e){let n=e*d.cc,c=this.#e.subarray(n,n+d.cc);return c[f[0]]=c[f[0]]||this.#N,c[f[32]]=c[f[32]]||this.#E,c}getCcCh(e,n){if(C.indexOf(n)<0)throw new Error("CC number not accepted");return this.#e[d.cc*e+f[n]]}getCcAll(){let e=this.#e.slice();for(let n=0;n0&&(this.#e[e*d.cc+f[0]]=m[c])}getPitch(){return this.#D}getProgram(){return this.#r}getTexts(){return this.#a.slice()}getVel(e){let n=new Map,c=this;return c.#o.forEach(function(t,s){let r=Math.floor(t/128),i=t%128;e==r&&c.#c[t]>0&&n.set(i,{v:c.#c[t],s:c.#h[s]})}),n}getBitmap(){return{bitmap:this.#b,expire:this.#k}}getLetter(){return{text:this.#T,expire:this.#P}}getMode(){return S[this.#t]}getMaster(){return{volume:this.#g}}getRawStrength(){let e=this;return this.#o.forEach(function(n){let c=Math.floor(n/128);e.#c[n]>e.#S[c]&&(e.#S[c]=e.#c[n])}),this.#S}getStrength(){let e=[],n=this;return this.getRawStrength().forEach(function(c,t){e[t]=Math.floor(c*n.#e[t*d.cc+f[7]]*Math.max(n.#e[t*d.cc+f[11]],Math.floor(n.#e[t*d.cc+f[91]]*.5),Math.floor(n.#e[t*d.cc+f[92]]*.65),Math.floor(n.#e[t*d.cc+f[94]]*.8))*n.#g/803288)}),e}getRpn(){return this.#s}getNrpn(){return this.#I}getVoice(e,n,c,t){let s=e||this.#N,r=n,i=c||this.#E;S[this.#t]=="ns5r"&&s>0&&s<56&&(i=3);let a=this.userBank.get(s,r,i,t);if(S[this.#t]=="mt32"&&a.name.indexOf("MT-m:")==0){let o=parseInt(a.name.slice(5)),h=o*d.cmt,l="";this.#U.subarray(h,h+10).forEach(u=>{u>31&&(l+=String.fromCharCode(u))}),this.userBank.load(`MSB LSB PRG -0 127 ${r} ${l}`,!0),a.name=l,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(s,r,i,t)),a}getChVoice(e){let n=this.getVoice(this.#e[e*d.cc+f[0]],this.#r[e],this.#e[e*d.cc+f[32]],S[this.#t]);if(this.#x[e])switch(this.#t){case $.mt32:n.ending="~",n.name="",this.#y.subarray(14*(e-1),14*(e-1)+10).forEach(c=>{c>31&&(n.name+=String.fromCharCode(c))})}return n}getPitchShift(e){let n=e*d.rpn;return this.#D[e]/8192*this.#s[n]+(this.#s[n+3]-64)+((this.#s[n+1]<<7)+this.#s[n+2]-8192)/8192}getEffectType(e=0){let n=3*e+1;return this.#$.subarray(n,n+2)}setEffectTypeRaw(e=0,n,c){let t=3*e;this.#$[t]=1,this.#$[t+1+ +n]=c}setEffectType(e=0,n,c){this.setEffectTypeRaw(e,!1,n),this.setEffectTypeRaw(e,!0,c)}setLetterDisplay(e,n,c=0,t=3200){let s=this,r;s.#T=" ".repeat(c),e.forEach(i=>{s.#T+=String.fromCharCode(i>31?i:32),i<32&&(r=r||new Set,r.add(i))}),s.#P=Date.now()+3200,s.#T=s.#T.padEnd(32," "),r&&(r=Array.from(r),r.forEach((i,a,o)=>{o[a]=i.toString(16).padStart(2,"0")}),console.warn(`${n}${n?" ":""}invalid code point${r.length>1?"s":""}: 0x${r.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let n=!0,c=0;for(;n&&c=d.ace&&console.warn("ACE slots are full.")}getAce(){return this.#C}getChAce(e,n){if(n<0||n>=d.ace)throw new RangeError("No such ACE slot");let c=this.#C[n];if(c){if(C.indexOf(c)>=0)return this.#e[e*d.cc+f[c]];throw new Error(`Invalid ACE source: ${c}`)}else return 0}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#N=0,this.#E=0,this.#v=0,this.#p.fill(0),this.#e.fill(0),this.#C.fill(0),this.#r.fill(0),this.#c.fill(0),this.#o.fill(0),this.#S.fill(0),this.#D.fill(0),this.#I.fill(0),this.#g=100,this.#a=[],this.#F=500,this.#K=0,this.#P=0,this.#T="",this.#k=0,this.#u=0,this.#b.fill(0),this.#n=!1,this.#V=0,this.#w=!0,this.#f.forEach(function(n,c,t){t[c]=c}),this.buildRchTree(),e==0&&(this.#R.fill(0),this.#H.fill(0)),this.#e[d.cc*9]=m[0],this.#e[d.cc*25]=m[0],this.#e[d.cc*41]=m[0],this.#e[d.cc*57]=m[0],this.#i.fill(this.CH_MELODIC),this.#i[9]=this.CH_DRUM1,this.#i[25]=this.CH_DRUM2,this.#i[41]=this.CH_DRUMS,this.#i[41]=this.CH_DRUMS,this.#i[57]=this.CH_DRUMS,this.#i[73]=this.CH_DRUM5,this.#i[89]=this.CH_DRUM6,this.#i[105]=this.CH_DRUMS,this.#i[121]=this.CH_DRUMS,this.#X.fill(0),this.#U.fill(0),this.#G.fill(0),this.#y.fill(0),this.#x.fill(0),this.#$.fill(0),this.aiEfxName="",this.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let n=0;n-1){if(this.#t==0||n){let t=this.#t;this.#t=c,this.#u=0,this.#N=Y[0][c],this.#E=Y[1][c];for(let r=0;r0&&this.#e[r*d.cc+f[0]]==m[t]&&(this.#e[r*d.cc]=m[c]);switch(this.initOnReset,c){case $.mt32:{N.forEach((r,i)=>{let a=i+1;this.#p[a]||(this.#r[a]=r,this.#e[a*d.cc+f[91]]=127)});break}}let s;switch(c){case $.gs:{s=[40,4,40,18,40,32,32,0,0,0,0,0,0,0];break}case $.x5d:case $.ns5r:{s=[44,1,44,19,44,0,44,0,0,0,0,0,0,0];break}default:s=[1,0,65,0,5,0,0,0,0,0,0,0,0,0]}for(let r=0;r14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#Z[e.type].call(this,e);{let n=this.chRedir(e.part,e.track),c=!1;this.#J[n]?.forEach(t=>{e.channel=t,c=!0,this.#Z[e.type].call(this,e)}),c||console.warn(`${W[e.type]?W[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${n+1} without any recipient.`)}this.#a.length>100&&this.#a.splice(100,this.#a.length-99)}runRaw(e){}constructor(){super();let e=this;this.#b=new Uint8Array(256),this.#M[10]=new Uint8Array(512),this.#_=new w,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let n=e.split(",");A[n[0]]=n[1]});var F=function(e){let n=e;e[0]=="*"&&(n=n.slice(1)),["aa","ii","uu","ee","oo"].forEach(t=>{for(;n.indexOf(t)>-1;)n=n.replace(t,t[0])});for(let t in A)n=n.replaceAll(t,A[t]);n.indexOf("ん")==0&&n.length>1&&(n=n.slice(1));let c=n.indexOf("!");return c>-1&&n.length>1&&(n=n.slice(c+1)),n},K=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var G=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],V=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],z=["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 ie={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"},re={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]]},U=function(e){return ie[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},Q=function(e,n,c){let t=(e[0]-32<<16)+(e[1]<<8)+n,s=re[t]||{},r=s[0];if(r?.length)return r+=`: ${(s[1]||function(){})(c)||c}`,r},N=[68,48,95,78,41,3,110,122,0];var y=function(e=64){return Math.round(2e3*Math.log10(e/64))/100};var q=function(e){let n=0;return e.forEach(c=>{n+=c,n=n&127}),~n+1&127},k=function(e,n){let c=0,t=0;for(let s=0;s>r&1)<<7,a=e[s];a+=i,s%8!=0?(n(a,c,e),c++):t=e[s]}},M=function(e){let n=Math.floor(e*14.2);return n<128?n:0};var S=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],Y=[[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],ne=[0,3,81,84,88],W={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},P={0:0,1:1,2:3,5:4},J=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Z=[36,37],ce=[20,21,22,23,24,25,26,28,29,30,31,36,37,64,65];var C=[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],oe=[12,13,16,17,18,19],le=[33,99,100,32,102,8,9,10],j=[0,16,25,40,32,64,26,48],$={};S.forEach((e,n)=>{$[e]=n});var f={length:C.length};C.forEach((e,n)=>{f[e]=n});var E=function(){return!!self.Bun||self.debugMode||!1},he=function(e){let n=[],c=0;return e?.forEach(function(t,s){t==247?n.push(e.subarray(c,s)):t==240&&(c=s+1)}),n.length||n.push(e.subarray(0)),E()&&console.debug(n),n},ee=function(e,n="",c="",t=2){return e?`${n}${e.toString().padStart(t,"0")}${c}`:""},d={ch:128,cc:C.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:ce.length,dnc:72,efx:7},Re=class extends L{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#u=0;#k=0;#M=new Array(11);get#b(){return this.#M[this.#u]}set#b(e){this.#M[this.#u]=e}#p=new Uint8Array(d.ch);#f=new Uint8Array(d.ch);#i=new Uint8Array(d.ch);#e=new Uint8Array(d.ch*d.cc);#C=new Uint8Array(d.ace);#r=new Uint8Array(d.ch);#c=new Uint8Array(d.ch*d.nn);#m=new Uint8Array(d.ch);#o=new Uint16Array(d.pl);#h=new Uint8Array(d.pl);#D=new Int16Array(d.ch);#S=new Uint8Array(d.ch);#B=0;#s=new Uint8Array(d.ch*d.rpn);#I=new Int8Array(d.ch*Z.length);#j=new Uint8Array(d.drm*d.dpn*d.dnc);#x=new Uint8Array(d.ch);#G=new Uint8Array(128);#y=new Uint8Array(d.cmt*8);#X=new Uint8Array(1024);#U=new Uint8Array(d.cmt*64);#$=new Uint8Array(d.efx*3);#N=0;#E=0;#g=100;#v=0;#F=500;#K=0;#T="";#P=0;#V=0;#w=!0;#n=!1;#J;#te=new Uint8Array(2);#a=[];#R=new Uint8Array(d.ch);#H=new Uint8Array(d.tr);baseBank=new O("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new O("gm");initOnReset=!1;aiEfxName="";chRedir(e,n,c){if(this.#H[n])return(this.#H[n]-1)*16+e;if([2,3].indexOf(this.#E)>-1){if(c==1)return e;let t=0,s=!0;for(;s;)this.#R[e+t]==0?(this.#R[e+t]=n,console.debug(`Assign track ${n} to channel ${e+t+1}.`),s=!1):this.#R[e+t]==n?s=!1:(t+=16,t>=128&&(t=0,s=!1));return e+t}else return e}#d=[];#_;#l={nOff:(e,n)=>{let c=e*128+n,t=this.#o.lastIndexOf(c);t>-1&&(this.#e[d.cc*e+f[64]]>63?(this.#h[t]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#c[c],state:this.NOTE_HELD})):this.#e[d.cc*e+f[66]]>63&&this.#h[t]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#h[t]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#c[c],state:this.NOTE_SOSTENUTO_HELD})):(this.#o[t]=0,this.#c[c]=0,this.#h[t]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:n,velo:0,state:this.NOTE_IDLE})))},nOn:(e,n,c)=>{let t=e*128+n,s=0;for(this.#m[e]&&this.#l.ano(e);this.#h[s]>0&&this.#o[s]!=t;)s++;s{},cAt:(e,n)=>{},hoOf:e=>{this.#h.forEach((n,c)=>{if(n==this.NOTE_HELD){let t=this.#o[c],s=t>>7;e==s&&(this.#h[c]=this.NOTE_IDLE,this.#o[c]=0,this.#c[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#h.forEach((n,c)=>{let t;switch(n){case this.NOTE_ATTACK:{t=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{t=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{t=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(t){this.#h[c]=t;let s=this.#o[c];this.dispatchEvent("note",{part:e,note:s&127,velo:this.#c[s],state:t})}})},soOf:e=>{this.#h.forEach((n,c)=>{if(n==this.NOTE_SOSTENUTO_HELD){let t=this.#o[c],s=t>>7;e==s&&(this.#h[c]=this.NOTE_IDLE,this.#o[c]=0,this.#c[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#o.forEach((n,c,t)=>{let s=n>>7,r=n&127;n==0&&this.#c[0]==0||s==e&&this.#l.nOff(s,r)})}};#Z={8:function(e){let n=e.channel,c=e.data[0];this.#l.nOff(n,c)},9:function(e){let n=e.channel;this.#p[n]=1;let c=e.data[0],t=e.data[1];t>0?this.#l.nOn(n,c,t):this.#l.nOff(n,c)},10:function(e){let n=e.channel,c=n*128+e.data[0];this.#o.indexOf(c)>-1&&(this.#c[c]=data[1],this.dispatchEvent("note",{part:n,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let n=e.channel;this.#p[n]=1;let c=n*d.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#l.ano(n),this.#D[n]=0;let t=n*d.cc;this.#e[t+f[1]]=0,this.#e[t+f[5]]=0,this.#e[t+f[64]]=0,this.#e[t+f[65]]=0,this.#e[t+f[66]]=0,this.#e[t+f[67]]=0,this.#e[t+f[11]]=127,this.#e[t+f[101]]=127,this.#e[t+f[100]]=127,this.#e[t+f[99]]=127,this.#e[t+f[98]]=127;return}case 123:{this.#l.ano(n);return}case 124:{this.#l.ano(n);return}case 125:{this.#l.ano(n);return}case 126:{this.#m[n]=1,this.#l.ano(n);return}case 127:{this.#m[n]=0,this.#l.ano(n);return}}if(f[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(oe.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{if(E()&&console.debug(`${S[this.#t]}, CH${n+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#i[n]>0&&(e.data[1]=this.#e[c],e.data[1]=120,console.debug(`Forced channel ${n+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==$.gs)e.data[1]<56&&this.#i[n]>0&&(e.data[1]=this.#e[c],e.data[1]=120,console.debug(`Forced channel ${n+1} to stay drums.`));else if(this.#t==$.gm)e.data[1]<48?this.#i[n]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${n+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0);else if(this.#t==$.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let t=0;for(let s=0;s<16;s++){let r=this.#e[d.cc*s];(r==56||r==62)&&t++}t>14&&this.switchMode("ag10",!0)}}switch(this.#t){case $.xg:{[126,127].indexOf(e.data[1])>-1?this.#i[n]==0&&(this.setChType(n,1),console.debug(`CH${n+1} set to drums by MSB.`)):this.#i[n]>0&&(this.setChType(n,0),console.debug(`CH${n+1} set to melodic by MSB.`));break}case $["05rw"]:case $.x5d:case $.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#i[n]==0&&(this.setChType(n,1),console.debug(`CH${n+1} set to drums by MSB.`)):this.#i[n]>0&&(this.setChType(n,0),console.debug(`CH${n+1} set to melodic by MSB.`));break}case $.g2:{e.data[1]==120?this.#i[n]==0&&(this.setChType(n,1),console.debug(`CH${n+1} set to drums by MSB.`)):this.#i[n]>0&&(this.setChType(n,0),console.debug(`CH${n+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:n});break}case 6:{if(this.#B){let t=this.#e[c+f[99]],s=this.#e[c+f[98]];if(t==1){let r=le.indexOf(s);if(r>-1)this.#e[c+f[71+r]]=e.data[1],E()&&console.debug(`Redirected NRPN 1 ${s} to cc${71+r}.`),this.dispatchEvent("cc",{part:n,cc:71+r,data:e.data[1]});else{let i=Z.indexOf(s);i>-1&&(this.#I[n*10+i]=e.data[1]-64),E()&&console.debug(`CH${n+1} voice NRPN ${s} commit`)}}}else{let t=P[this.#e[c+f[100]]];this.#e[c+f[101]]==0&&t!=null&&(E()&&console.debug(`CH${n+1} RPN 0 ${this.#e[c+f[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],J[t][0]),J[t][1]),this.#s[n*d.rpn+t]=e.data[1])}break}case 32:{this.dispatchEvent("voice",{part:n});break}case 38:{this.#B||this.#e[c+101]==0&&P[this.#e[c+100]]!=null&&(this.#s[n*d.rpn+P[this.#e[c+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#l.hoOf(n);break}case 66:{e.data[1]>>6?this.#l.soOn(n):this.#l.soOf(n);break}case 98:case 99:{this.#B=1;break}case 100:case 101:{this.#B=0;break}}this.#e[c+f[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:n,cc:e.data[0],data:e.data[1]})}},12:function(e){let n=e.channel;this.#p[n]=1,this.#r[n]=e.data,this.#x[n]=0,E()&&console.debug(`T:${e.track} C:${n} P:${e.data}`),this.dispatchEvent("voice",{part:n})},13:function(e){let n=this,c=e.channel;this.#o.forEach(function(t){let s=t>>7;c==s&&(n.#c[t]=e.data,n.dispatchEvent("note",{part:c,note:t&127,velo:e.data,state:n.NOTE_SUSTAIN}))})},14:function(e){let n=e.channel;this.#D[n]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:n,pitch:this.getPitchShift(n)})},15:function(e){he(e.data).forEach(n=>{let c=n[0],t=n[1];(this.#ee[c]||function(){console.debug(`Unknown manufacturer ${c}.`)})(t,n.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,t,s){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#v=0);let n=ne.indexOf(e.meta)>-1;if(E()&&console.debug(e),n)return e.reply="meta",e}};#ee={64:(e,n,c)=>{this.#q.run(n,c,e)},65:(e,n,c)=>{if(n[0]<16)this.#A.run(n,c,e),console.warn("Unknown device SysEx!");else{let t=n[n.length-1],s=q(n.subarray(2,n.length-1));t==s?this.#A.run(n.subarray(0,n.length-1),c,e):console.warn(`Bad GS checksum ${t}. Should be ${s}.`)}},66:(e,n,c)=>{this.#L.run(n,c,e)},67:(e,n,c)=>{this.#O.run(n,c,e)},68:(e,n,c)=>{this.#W.run(n,c,e)},71:(e,n,c)=>{this.#Y.run(n,c,e)},126:(e,n,c)=>{this.#z.run(n,c,e)},127:(e,n,c)=>{this.switchMode("gm"),this.#Q.run(n,c,e)}};#z;#Q;#O;#A;#L;#q;#Y;#W;buildRchTree(){let e=[];this.#f.forEach((n,c)=>{e[n]?.constructor||(e[n]=[]),e[n].push(c)}),this.#J=e}getActive(){let e=this.#p.slice();return this.#t==$.mt32,e}getCc(e){let n=e*d.cc,c=this.#e.subarray(n,n+d.cc);return c[f[0]]=c[f[0]]||this.#N,c[f[32]]=c[f[32]]||this.#E,c}getCcCh(e,n){if(C.indexOf(n)<0)throw new Error("CC number not accepted");return this.#e[d.cc*e+f[n]]}getCcAll(){let e=this.#e.slice();for(let n=0;n0&&(this.#e[e*d.cc+f[0]]=m[c])}getPitch(){return this.#D}getProgram(){return this.#r}getTexts(){return this.#a.slice()}getVel(e){let n=new Map,c=this;return c.#o.forEach(function(t,s){let r=Math.floor(t/128),i=t%128;e==r&&c.#c[t]>0&&n.set(i,{v:c.#c[t],s:c.#h[s]})}),n}getBitmap(){return{bitmap:this.#b,expire:this.#k}}getLetter(){return{text:this.#T,expire:this.#P}}getMode(){return S[this.#t]}getMaster(){return{volume:this.#g}}getRawStrength(){let e=this;return this.#o.forEach(function(n){let c=Math.floor(n/128);e.#c[n]>e.#S[c]&&(e.#S[c]=e.#c[n])}),this.#S}getStrength(){let e=[],n=this;return this.getRawStrength().forEach(function(c,t){e[t]=Math.floor(c*n.#e[t*d.cc+f[7]]*Math.max(n.#e[t*d.cc+f[11]],Math.floor(n.#e[t*d.cc+f[91]]*.5),Math.floor(n.#e[t*d.cc+f[92]]*.65),Math.floor(n.#e[t*d.cc+f[94]]*.8))*n.#g/803288)}),e}getRpn(){return this.#s}getNrpn(){return this.#I}getVoice(e,n,c,t){let s=e||this.#N,r=n,i=c||this.#E;S[this.#t]=="ns5r"&&s>0&&s<56&&(i=3);let a=this.userBank.get(s,r,i,t);if(S[this.#t]=="mt32"&&a.name.indexOf("MT-m:")==0){let o=parseInt(a.name.slice(5)),h=o*d.cmt,l="";this.#U.subarray(h,h+10).forEach(u=>{u>31&&(l+=String.fromCharCode(u))}),this.userBank.load(`MSB LSB PRG +0 127 ${r} ${l}`,!0),a.name=l,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(s,r,i,t)),a}getChVoice(e){let n=this.getVoice(this.#e[e*d.cc+f[0]],this.#r[e],this.#e[e*d.cc+f[32]],S[this.#t]);if(this.#x[e])switch(this.#t){case $.mt32:n.ending="~",n.name="",this.#y.subarray(14*(e-1),14*(e-1)+10).forEach(c=>{c>31&&(n.name+=String.fromCharCode(c))})}return n}getPitchShift(e){let n=e*d.rpn;return this.#D[e]/8192*this.#s[n]+(this.#s[n+3]-64)+((this.#s[n+1]<<7)+this.#s[n+2]-8192)/8192}getEffectType(e=0){let n=3*e+1;return this.#$.subarray(n,n+2)}setEffectTypeRaw(e=0,n,c){let t=3*e;this.#$[t]=1,this.#$[t+1+ +n]=c}setEffectType(e=0,n,c){this.setEffectTypeRaw(e,!1,n),this.setEffectTypeRaw(e,!0,c)}setLetterDisplay(e,n,c=0,t=3200){let s=this,r;s.#T=" ".repeat(c),e.forEach(i=>{s.#T+=String.fromCharCode(i>31?i:32),i<32&&(r=r||new Set,r.add(i))}),s.#P=Date.now()+3200,s.#T=s.#T.padEnd(32," "),r&&(r=Array.from(r),r.forEach((i,a,o)=>{o[a]=i.toString(16).padStart(2,"0")}),console.warn(`${n}${n?" ":""}invalid code point${r.length>1?"s":""}: 0x${r.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let n=!0,c=0;for(;n&&c=d.ace&&console.warn("ACE slots are full.")}getAce(){return this.#C}getChAce(e,n){if(n<0||n>=d.ace)throw new RangeError("No such ACE slot");let c=this.#C[n];if(c){if(C.indexOf(c)>=0)return this.#e[e*d.cc+f[c]];throw new Error(`Invalid ACE source: ${c}`)}else return 0}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#N=0,this.#E=0,this.#v=0,this.#p.fill(0),this.#e.fill(0),this.#C.fill(0),this.#r.fill(0),this.#c.fill(0),this.#o.fill(0),this.#S.fill(0),this.#D.fill(0),this.#I.fill(0),this.#j.fill(0),this.#g=100,this.#a=[],this.#F=500,this.#K=0,this.#P=0,this.#T="",this.#k=0,this.#u=0,this.#b.fill(0),this.#n=!1,this.#V=0,this.#w=!0,this.#f.forEach(function(n,c,t){t[c]=c}),this.buildRchTree(),e==0&&(this.#R.fill(0),this.#H.fill(0)),this.#e[d.cc*9]=m[0],this.#e[d.cc*25]=m[0],this.#e[d.cc*41]=m[0],this.#e[d.cc*57]=m[0],this.#i.fill(this.CH_MELODIC),this.#i[9]=this.CH_DRUM1,this.#i[25]=this.CH_DRUM2,this.#i[41]=this.CH_DRUMS,this.#i[41]=this.CH_DRUMS,this.#i[57]=this.CH_DRUMS,this.#i[73]=this.CH_DRUM5,this.#i[89]=this.CH_DRUM6,this.#i[105]=this.CH_DRUMS,this.#i[121]=this.CH_DRUMS,this.#X.fill(0),this.#U.fill(0),this.#G.fill(0),this.#y.fill(0),this.#x.fill(0),this.#$.fill(0),this.aiEfxName="",this.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let n=0;n-1){if(this.#t==0||n){let t=this.#t;this.#t=c,this.#u=0,this.#N=Y[0][c],this.#E=Y[1][c];for(let r=0;r0&&this.#e[r*d.cc+f[0]]==m[t]&&(this.#e[r*d.cc]=m[c]);switch(this.initOnReset,c){case $.mt32:{N.forEach((r,i)=>{let a=i+1;this.#p[a]||(this.#r[a]=r,this.#e[a*d.cc+f[91]]=127)});break}}let s;switch(c){case $.gs:{s=[40,4,40,18,40,32,32,0,0,0,0,0,0,0];break}case $.x5d:case $.ns5r:{s=[44,1,44,19,44,0,44,0,0,0,0,0,0,0];break}default:s=[1,0,65,0,5,0,0,0,0,0,0,0,0,0]}for(let r=0;r14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#Z[e.type].call(this,e);{let n=this.chRedir(e.part,e.track),c=!1;this.#J[n]?.forEach(t=>{e.channel=t,c=!0,this.#Z[e.type].call(this,e)}),c||console.warn(`${W[e.type]?W[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${n+1} without any recipient.`)}this.#a.length>100&&this.#a.splice(100,this.#a.length-99)}runRaw(e){}constructor(){super();let e=this;this.#b=new Uint8Array(256),this.#M[10]=new Uint8Array(512),this.#_=new w,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -150,4 +150,4 @@ ${i} ${a} ${o} ${r.trim().replace("Init Voice","")}`,a++,r="";break}}a>99&&(i=90 ${i} ${a} ${o} ${r.trim().replace("Init Combi","")}`,a++,r="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(h)}).add([54,78],(t,s)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][t[0]]} mode.`)}).add([54,85],(t,s)=>{e.switchMode("x5d",!0),k(t,(r,i)=>{i>0&&i<3&&e.setEffectType(i-1,44,r)})}).add([54,104],(t,s)=>{e.switchMode("x5d",!0),k(t,function(r,i,a,o){if(i<192){let h=e.chRedir(Math.floor(i/12),s,!0),l=h*d.cc;switch(i%12){case 0:{r<128?(e.setChType(h,0,$.x5d),e.#e[l+f[0]]=82,e.#r[h]=r):(e.setChType(h,1,$.x5d),e.#e[l+f[0]]=62,e.#r[h]=j[r-128]),r>0&&(e.#p[h]=1);break}case 1:{e.#e[l+f[7]]=r;break}case 2:{e.#s[h*d.rpn+3]=r>127?r-192:64+r;break}case 3:{e.#s[h*d.rpn+1]=r>127?r-192:64+r;break}case 4:{r<31&&(e.#e[l+f[10]]=Math.round((r-15)*4.2+64));break}case 5:{let u=r>>4,b=r&15;e.#e[l+f[91]]=M(b),e.#e[l+f[93]]=M(u);break}case 10:break;case 11:{let u=e.chRedir(r&15,s,!0),b=r>>4;e.#f[h]=r,(u!=h||b)&&(console.info(`X5D Part CH${h+1} receives from CH${u+1}.`),e.buildRchTree())}}}else{let h=e.chRedir(i-192,s,!0)}})}),this.#A.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#n=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(t,s,r)=>{e.switchMode("mt32");let i=e.chRedir(r,s,!0),a=t[1];t.subarray(2).forEach((o,h)=>{let l=h+a;e.#G[l+(i-1)*16]=o,([!1,()=>{let u=e.#G[i-1<<4];if(u<3)if(e.#x[i]=1,u==2)for(let b=0;b{e.#s[i*d.rpn+3]=o+40},()=>{e.#s[i*d.rpn+1]=o+14},()=>{e.#s[i*d.rpn]=o},!1,()=>{e.#e[d.cc*i+f[91]]=o?127:0},!1,()=>{e.#e[d.cc*i+f[7]]=o},()=>{e.#e[d.cc*i+f[10]]=Math.ceil(o*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(t,s,r)=>{e.switchMode("mt32");let i=e.chRedir(r,s,!0)}).add([22,18,2],(t,s,r)=>{e.switchMode("mt32");let i=e.chRedir(r,s,!0),a=t[1]+(t[0]<<7);a<10&&(e.#x[i]=1),t.subarray(2).forEach((o,h)=>{let l=h+a;l<14&&(e.#y[(i-1)*d.cmt+l]=o)})}).add([22,18,3],(t,s,r)=>{if(e.switchMode("mt32"),t[0]){let i=t[1]-16}else{let i=t[1];t.subarray(2).forEach((a,o)=>{let h=o+i;e.#G[h]=a;let l=e.chRedir(1+h>>4,s,!0),u=h&15;([!1,()=>{let b=e.#G[l-1<<4];if(b<3)if(e.#x[l]=1,b==2)for(let p=0;p{e.#s[l*d.rpn+3]=a+40},()=>{e.#s[l*d.rpn+1]=a+14},()=>{e.#s[l*d.rpn]=a},!1,()=>{e.#e[d.cc*l+f[91]]=a?127:0},!1,()=>{e.#e[d.cc*l+f[7]]=a},()=>{e.#e[d.cc*l+f[10]]=Math.ceil(a*9.05)}][u]||(()=>{}))()})}}).add([22,18,4],(t,s,r)=>{e.switchMode("mt32");let i=t[1]+(t[0]<<7);t.subarray(2).forEach((a,o)=>{let h=o+i,l=e.chRedir(Math.floor(h/246+1),s,!0),u=h%246;u<14&&(e.#y[(l-1)*d.cmt+u]=a),u<10&&(e.#x[l]=1)})}).add([22,18,5],(t,s,r)=>{e.switchMode("mt32");let i=(t[0]<<7)+t[1];t.subarray(2).forEach((a,o)=>{let h=i+o,l=Math.floor(h/8),u=h&7,b=l*8;e.#X[h]=a,([!1,()=>{let p=e.#X[b];if(p<3){let g="";if(p==2){let v=d.cmt*l;g=`MT-m:${a.toString().padStart(3,"0")}`}else g=e.baseBank.get(0,a+(p<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l}),e.userBank.load(`MSB LSB PRG NME 000 127 ${l} ${g}`,!0)}}][u]||(()=>{}))()})}).add([22,18,8],(t,s,r)=>{e.switchMode("mt32");let i=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((a,o)=>{let h=i+o;h>1)*d.cmt+h]=a)})}).add([22,18,16],(t,s,r)=>{e.switchMode("mt32");let i=t[1],a=!1,o=function(h,l){e.#f[l-12]=h,a=!0};t.subarray(2).forEach((h,l)=>{let u=l+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,o,o,o,o,o,o,o,o,o,()=>{e.#g=h}][u]||(()=>{}))(h,l)}),a&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let s=t[1],r=" ".repeat(s);t.subarray(2).forEach(i=>{i>31&&(r+=String.fromCharCode(i))}),e.#T=r.padStart(20," "),e.#P=Date.now()+3200}).add([22,18,82],(t,s)=>{let r=e.chRedir(0,s,!0);for(let i=0;i<16;i++)e.#l.ano(r+i),i&&i<10&&(e.#r[r+i]=N[i-1]);console.info("MT-32 alt reset complete.")}),this.#L.add([66,0],(t,s)=>{e.switchMode("ns5r",!0),e.#n=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,s)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#n=!1}).add([66,18,0,0],(t,s)=>{let r=t[0];switch(r){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#n=!1;break}case 125:break;default:if(r<10){let i=[0,0,0,0],a=(o,h)=>{i[h]=o};if(t.subarray(1).forEach((o,h)=>{[a,a,a,a,()=>{e.#g=o*129/16383*100},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][r+h]()}),t[0]<4){let o=0;i.forEach(h=>{o=o<<4,o+=h}),o-=1024}}}}).add([66,18,0,1],(t,s)=>{}).add([66,18,0,2],(t,s)=>{}).add([66,18,1],(t,s)=>{let r=e.chRedir(t[0],s,!0),i=r*d.cc,a=t[1],o=`NS5R CH${r+1}`;t.subarray(2).forEach((h,l)=>{let u=a+l;u<3?[()=>{e.#e[i+f[0]]=h||121},()=>{e.#e[i+f[32]]=h},()=>{e.#r[r]=h}][u]():u<8||(u<14?[()=>{let b=e.chRedir(h,s,!0);e.#f[r]=b,r!=b&&(e.buildRchTree(),console.info(`${o}receives from CH${b+1}`))},()=>{e.#m[r]=+!h},()=>{e.setChType(r,h,$.ns5r),console.debug(`${o}type: ${D[h]}`)},()=>{e.#s[d.rpn*r+3]=h},()=>{},()=>{}][u-8]():u<16||(u<33?[()=>{e.#e[i+f[7]]=h},()=>{e.#e[i+f[11]]=h},()=>{},()=>{},()=>{e.#e[i+f[10]]=h||128},()=>{},()=>{},()=>{e.#e[i+f[93]]=h},()=>{e.#e[i+f[91]]=h},()=>{e.#e[i+f[76]]=h},()=>{e.#e[i+f[77]]=h},()=>{e.#e[i+f[78]]=h},()=>{e.#e[i+f[74]]=h},()=>{e.#e[i+f[71]]=h},()=>{e.#e[i+f[73]]=h},()=>{e.#e[i+f[75]]=h},()=>{e.#e[i+f[72]]=h}][u-16]():u<112||u<114&&[()=>{e.#e[i+f[5]]=h},()=>{e.#e[i+f[65]]=h}][u-112]()))})}).add([66,18,8,0],(t,s)=>{let r=t[0];if(r<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let i=r-32;e.#k=Date.now()+3200,e.#u=10,e.#b.fill(0);let a=t.subarray(1),o=4;a.forEach(function(h,l){let u=l+i,b=u>>4,p=u&15;if(u<80){let g=b>3,v=0,te=b0;)e.#b[p*32+b*7+(te-v)]=g&1,g=g>>1,v++}})}}).add([66,52],(t,s)=>{e.switchMode("ns5r",!0),e.#n=!1;let r="";k(t,(i,a)=>{a<8?(i>31&&(r+=String.fromCharCode(i)),a==7&&(e.aiEfxName=r)):a<10&&e.setEffectType(a-8,44,i)})}).add([66,53],(t,s)=>{e.switchMode("ns5r",!0),e.#n=!1,k(t,function(r,i){switch(!0){case i<2944:{let a=e.chRedir(Math.floor(i/92),s,!0),o=a*d.cc;switch(i%92){case 0:{e.#e[o+f[0]]=r||121;break}case 1:{e.#e[o+f[32]]=r;break}case 2:{e.#r[a]=r,r>0&&(e.#p[a]=1);break}case 3:{let h=e.chRedir(r,s,!0);e.#f[a]=h,a!=h&&(console.info(`NS5R CH${a+1} receives from CH${h+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#s[a*d.rpn+3]=r<40||r>88?r+(r>63?-192:64):r;break}case 9:case 10:{e.#e[o+f[7]]=r;break}case 11:{e.#e[o+f[11]]=r;break}case 14:{e.#e[o+f[10]]=r||128;break}case 19:{e.#e[o+f[93]]=r;break}case 20:{e.#e[o+f[91]]=r;break}case 84:{e.#e[o+f[65]]=r;break}case 85:{e.#e[o+f[5]]=r;break}}break}case i<3096:break;case i<3134:break;case i<8566:break}})}).add([66,54],(t,s)=>{e.switchMode("ns5r",!0);let r="",i=80,a=0,o=0,h="MSB PRG LSB NME";k(t,function(l,u){let b=u%158;switch(!0){case b<10:{l>31&&(r+=String.fromCharCode(l));break}case b==11:{i=l&127;break}case b==12:{o=l&127;break}case b==13:{h+=` ${i} ${a} ${o} ${r.trim().replace("Init Voice","")}`,a++,r="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(h)}).add([66,55],(t,s)=>{e.switchMode("ns5r",!0);let r="",i=88,a=0,o=0,h="MSB PRG LSB NME";k(t,function(l,u){let b=u%126;switch(!0){case b<10:{l>31&&(r+=String.fromCharCode(l));break}case b==11:break;case b==12:break;case b==13:{h+=` -${i} ${a} ${o} ${r.trim().replace("Init Combi","")}`,a++,r="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(h)}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let s=new Uint8Array(5760);k(t,(r,i,a)=>{if(i<720)for(let o=0;o<8;o++)s[i*8+o]=r>>7-o&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(t,s,r)=>{e.#L.run([66,...t],s,r)}),this.#q.add([16,0,8,0],(t,s,r)=>{let i=(t[2]<<4)+t[3],a="K11 ";([()=>{e.switchMode("k11",!0),e.#n=!1,e.#E=i?4:0,console.info("MIDI reset: GMega/K11")},()=>{console.debug(`${a}reverb type: ${i}`)},()=>{console.debug(`${a}reverb time: ${i}`)},()=>{console.debug(`${a}reverb time: ${i}`)},()=>{console.debug(`${a}reverb predelay: ${i}`)},()=>{console.debug(`${a}reverb predelay: ${i}`)},()=>{console.debug(`${a}depth high: ${i}`)},()=>{console.debug(`${a}depth high: ${i}`)},()=>{console.debug(`${a}depth low: ${i}`)},()=>{console.debug(`${a}depth low: ${i}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,s,r)=>{let i=e.chRedir(t[1],s,!0),a=d.cc*i,o=d.rpn*i,h=(t[3]<<4)+t[4],l=`K11 CH${i+1} `;([()=>{h<128?(e.setChType(i,0,$.k11),e.#e[a+f[0]]=0,e.#r[i]=h):(e.setChType(i,1,$.k11),e.#r[i]=h-128)},()=>{let u=e.chRedir(h,s,!0);e.#f[i]=u,i!=u&&(e.buildRchTree(),console.info(`${l}receives from CH${u+1}`))},()=>{e.#e[a+f[7]]=h},()=>{e.#p[i]=h},()=>{e.#e[a+f[10]]=h},()=>{e.#s[o+3]=h+40},()=>{e.#s[o+1]=h>>1,e.#s[o+2]=h&1},()=>{e.#e[a+f[91]]=h?127:0},()=>{},()=>{e.#e[a+f[74]]=h},()=>{e.#e[a+f[73]]=h},()=>{e.#e[a+f[72]]=h}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,s,r)=>{let i=(t[2]<<4)+t[3],a="GMLX ";([()=>{console.debug(`${a}reverb type: ${i}`)},()=>{console.debug(`${a}reverb time: ${i}`)},()=>{console.debug(`${a}reverb predelay: ${i}`)},()=>{console.debug(`${a}depth high: ${i}`)},()=>{console.debug(`${a}depth low: ${i}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,s,r)=>{let i=(t[2]<<4)+t[3],a=e.chRedir(t[1],s,!0),o=a*d.cc;[()=>{i<128?(e.setChType(a,0,$.k11),e.#e[o+f[0]]=0,e.#e[o+f[32]]=0,e.#r[a]=i):i<160?(e.setChType(a,0,$.k11),e.#e[o+f[0]]=0,e.#e[o+f[32]]=7,e.#r[a]=i-100):(e.setChType(a,1,$.k11),e.#e[o+f[0]]=122,e.#e[o+f[32]]=0,e.#r[a]=i-160)},()=>{let h=e.chRedir(i,s,!0);e.#f[a]=h,a!=h&&(e.buildRchTree(),console.info(`GMLX CH${a+1} receives from CH${h+1}`))}][t[0]]()}).add([16,0,9,4],(t,s,r)=>{let i=(t[2]<<4)+t[3],a=e.chRedir(t[1],s,!0),o=a*d.cc,h=a*d.rpn,l=`GMLX CH${a+1} `;[()=>{e.#p[a]=i},()=>{e.#e[o+f[7]]=i},()=>{e.#e[o+f[10]]=i},()=>{e.#e[o+f[91]]=i?127:0},()=>{e.#s[h+3]=i+40},()=>{e.#s[h+1]=i},()=>{e.#s[h]=i},()=>{}][t[0]]()}),this.#Y.add([66,93,64],(t,s,r)=>{let i=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{e.#g=i*129/16383*100;break}case 5:{i-64;break}case 6:{console.debug(`SG global reverb: ${i?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(t[1]){case 48:{console.debug(`SG reverb type: ${G[i]}`);break}}break}default:if(t[0]>>4==1){let a=e.chRedir(t[0]&15,s,!0);if(t[1]==2){let o=e.chRedir(i,s,!0);e.#f[a]=o,a!=o&&(e.buildRchTree(),console.info(`SG CH${a+1} receives from CH${o+1}`))}else t[1]==19&&(e.#e[d.cc*a+f[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),this.#W.add([9],(t,s,r)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)})}};export{ve as OctaviaDevice,d as allocated,f as ccToPos}; +${i} ${a} ${o} ${r.trim().replace("Init Combi","")}`,a++,r="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(h)}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let s=new Uint8Array(5760);k(t,(r,i,a)=>{if(i<720)for(let o=0;o<8;o++)s[i*8+o]=r>>7-o&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(t,s,r)=>{e.#L.run([66,...t],s,r)}),this.#q.add([16,0,8,0],(t,s,r)=>{let i=(t[2]<<4)+t[3],a="K11 ";([()=>{e.switchMode("k11",!0),e.#n=!1,e.#E=i?4:0,console.info("MIDI reset: GMega/K11")},()=>{console.debug(`${a}reverb type: ${i}`)},()=>{console.debug(`${a}reverb time: ${i}`)},()=>{console.debug(`${a}reverb time: ${i}`)},()=>{console.debug(`${a}reverb predelay: ${i}`)},()=>{console.debug(`${a}reverb predelay: ${i}`)},()=>{console.debug(`${a}depth high: ${i}`)},()=>{console.debug(`${a}depth high: ${i}`)},()=>{console.debug(`${a}depth low: ${i}`)},()=>{console.debug(`${a}depth low: ${i}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,s,r)=>{let i=e.chRedir(t[1],s,!0),a=d.cc*i,o=d.rpn*i,h=(t[3]<<4)+t[4],l=`K11 CH${i+1} `;([()=>{h<128?(e.setChType(i,0,$.k11),e.#e[a+f[0]]=0,e.#r[i]=h):(e.setChType(i,1,$.k11),e.#r[i]=h-128)},()=>{let u=e.chRedir(h,s,!0);e.#f[i]=u,i!=u&&(e.buildRchTree(),console.info(`${l}receives from CH${u+1}`))},()=>{e.#e[a+f[7]]=h},()=>{e.#p[i]=h},()=>{e.#e[a+f[10]]=h},()=>{e.#s[o+3]=h+40},()=>{e.#s[o+1]=h>>1,e.#s[o+2]=h&1},()=>{e.#e[a+f[91]]=h?127:0},()=>{},()=>{e.#e[a+f[74]]=h},()=>{e.#e[a+f[73]]=h},()=>{e.#e[a+f[72]]=h}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,s,r)=>{let i=(t[2]<<4)+t[3],a="GMLX ";([()=>{console.debug(`${a}reverb type: ${i}`)},()=>{console.debug(`${a}reverb time: ${i}`)},()=>{console.debug(`${a}reverb predelay: ${i}`)},()=>{console.debug(`${a}depth high: ${i}`)},()=>{console.debug(`${a}depth low: ${i}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,s,r)=>{let i=(t[2]<<4)+t[3],a=e.chRedir(t[1],s,!0),o=a*d.cc;[()=>{i<128?(e.setChType(a,0,$.k11),e.#e[o+f[0]]=0,e.#e[o+f[32]]=0,e.#r[a]=i):i<160?(e.setChType(a,0,$.k11),e.#e[o+f[0]]=0,e.#e[o+f[32]]=7,e.#r[a]=i-100):(e.setChType(a,1,$.k11),e.#e[o+f[0]]=122,e.#e[o+f[32]]=0,e.#r[a]=i-160)},()=>{let h=e.chRedir(i,s,!0);e.#f[a]=h,a!=h&&(e.buildRchTree(),console.info(`GMLX CH${a+1} receives from CH${h+1}`))}][t[0]]()}).add([16,0,9,4],(t,s,r)=>{let i=(t[2]<<4)+t[3],a=e.chRedir(t[1],s,!0),o=a*d.cc,h=a*d.rpn,l=`GMLX CH${a+1} `;[()=>{e.#p[a]=i},()=>{e.#e[o+f[7]]=i},()=>{e.#e[o+f[10]]=i},()=>{e.#e[o+f[91]]=i?127:0},()=>{e.#s[h+3]=i+40},()=>{e.#s[h+1]=i},()=>{e.#s[h]=i},()=>{}][t[0]]()}),this.#Y.add([66,93,64],(t,s,r)=>{let i=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{e.#g=i*129/16383*100;break}case 5:{i-64;break}case 6:{console.debug(`SG global reverb: ${i?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(t[1]){case 48:{console.debug(`SG reverb type: ${G[i]}`);break}}break}default:if(t[0]>>4==1){let a=e.chRedir(t[0]&15,s,!0);if(t[1]==2){let o=e.chRedir(i,s,!0);e.#f[a]=o,a!=o&&(e.buildRchTree(),console.info(`SG CH${a+1} receives from CH${o+1}`))}else t[1]==19&&(e.#e[d.cc*a+f[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),this.#W.add([9],(t,s,r)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)})}};export{Re as OctaviaDevice,d as allocated,f as ccToPos}; diff --git a/dist/state_skim.mjs b/dist/state_skim.mjs index fa648474..e2550a36 100644 --- a/dist/state_skim.mjs +++ b/dist/state_skim.mjs @@ -1,4 +1,4 @@ -var C=function(e,t){let i=Math.min(e.length,t.length),s=e.slice(0,i),a=t.slice(0,i),r=0,n=0;for(;n0){let i=this.pool.length,s=1<=1&&r>=0;){if(r<=0)throw new Error("TTL reached.");if(a==i)a-=s;else{let c=C(e,this.pool[a]);switch(c){case 0:{r=0;break}case 1:{a+s<=i&&(a+=s);break}case-1:{a!=0&&(a-=s);break}default:console.warn(`Unexpected result ${c}.`)}}s=s>>1,r--}let n=!0;if(a>=this.pool.length)n=!1;else{let c=this;this.pool[a].forEach(function(f,d,l){n&&f!=e[d]&&(n=!1)}),!n&&C(e,this.pool[a])>0&&a++}return n||t?a:-1}else return t?0:-1},this.add=function(e,t){return e.data=t,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match for "${e}". Default action not defined.`)},this.get=function(e){let t=this.point(e);if(t>-1)return this.pool[t].data;this.default(e)},this.run=function(e,...t){let i=this.point(e);i>-1?this.pool[i].data(e.slice(this.pool[i].length),...t):this.default(e,...t)}};var m=class{#t={};addEventListener(e,t){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(t)}removeEventListener(e,t){if(this.#t[e]){let i=this.#t[e].indexOf(t);i>-1&&this.#t[e].splice(i,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,t){let i=new Event(e),s=this;i.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(a){try{a?.call(s,i)}catch(r){console.error(r)}}),this[`on${e}`]&&this[`on${e}`](i)}};var D=["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 U=",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(","),N={};`hi*, +var C=function(e,t){let i=Math.min(e.length,t.length),s=e.slice(0,i),a=t.slice(0,i),r=0,n=0;for(;n0){let i=this.pool.length,s=1<=1&&r>=0;){if(r<=0)throw new Error("TTL reached.");if(a==i)a-=s;else{let c=C(e,this.pool[a]);switch(c){case 0:{r=0;break}case 1:{a+s<=i&&(a+=s);break}case-1:{a!=0&&(a-=s);break}default:console.warn(`Unexpected result ${c}.`)}}s=s>>1,r--}let n=!0;if(a>=this.pool.length)n=!1;else{let c=this;this.pool[a].forEach(function(f,d,l){n&&f!=e[d]&&(n=!1)}),!n&&C(e,this.pool[a])>0&&a++}return n||t?a:-1}else return t?0:-1},this.add=function(e,t){return e.data=t,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match for "${e}". Default action not defined.`)},this.get=function(e){let t=this.point(e);if(t>-1)return this.pool[t].data;this.default(e)},this.run=function(e,...t){let i=this.point(e);i>-1?this.pool[i].data(e.slice(this.pool[i].length),...t):this.default(e,...t)}};var m=class{#t={};addEventListener(e,t){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(t)}removeEventListener(e,t){if(this.#t[e]){let i=this.#t[e].indexOf(t);i>-1&&this.#t[e].splice(i,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,t){let i=new Event(e),s=this;i.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(a){try{a?.call(s,i)}catch(r){console.error(r)}}),this[`on${e}`]&&this[`on${e}`](i)}};var U=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]);var D=",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(","),N={};`hi*, ka,か ki,き ku,く @@ -135,9 +135,9 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let t=e.split(",");N[t[0]]=t[1]});var G=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"];var E=[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];var P={};G.forEach((e,t)=>{P[e]=t});var B={length:E.length};E.forEach((e,t)=>{B[e]=t});var we={ch:128,cc:E.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,efx:7};var I=["MSB","PRG","LSB"];var S=function(e){let t=Math.floor(e/10),i=e%10;return`${t.toString(16)}${i}`},k=class{#t;strictMode=!1;get(e=0,t=0,i=0,s){let a,r=Array.from(arguments);switch(s){case"xg":{e==32?r[2]+=4:e==33||e==35||e==36?r[2]+=5:e==79?r[0]=95:e==80?r[0]=96:e==81?r[0]=97:e==82?r[0]=98:e==83?r[0]=99:e==84&&(r[0]=100);break}case"gs":{e==0&&i<5?r[2]=0:e>125&&i<5&&i!=2&&(r[2]=e,r[0]=0);break}case"sg":{e==8&&i==0&&(r[2]=5);break}}let n=" ",c="M",f=!1,d=0;switch(r[0]){case 0:{r[2]==127?c="MT-a":r[2]==126?c="MT-b":r[2]==7?c="GM-k":r[2]==5?c="SG-a":r[2]==4?c="SP-l":r[2]==0||s=="gs"&&r[2]<5?c="GM-a":(c="y",f=!0);break}case 8:{s=="sg"?c="GM-s":c="r:";break}case 48:{c=`yM${(r[2]>>3).toString().padStart(2,"0")}`,f=!0;break}case 56:{c="GM-b";break}case 61:case 120:{c="rDrm";break}case 62:{c="kDrm";break}case 63:{let u=r[2];c=u<10?"kP:":"kC:",c+=u%10;break}case 64:{c="ySFX";break}case 67:{c="DX:S";break}case 80:case 81:case 82:case 83:{c=`Prg${"UABC"[r[0]-80]}`;break}case 88:case 89:case 90:case 91:{c=`Cmb${"UABC"[r[0]-88]}`;break}case 95:{c=`${["DR","PC"][r[2]]}-d`;break}case 96:{c=r[2]==106?"AP-a":"PF",r[2]>63&&(d=63),f=!0;break}case 97:{c="VL:",f=!0,d=112;break}case 98:{c="SG-a";break}case 99:{c="DX",r[2]>63&&(d=63),f=!0;break}case 100:{c="AN",r[2]>63&&(d=63),f=!0;break}case 121:{c=`GM-${r[2]?"":"a"}`,f=!0;break}case 122:{c="lDrm";break}case 126:{c="yDrS";break}case 127:{r[2]==127?c="rDrm":c="yDrm";break}default:r[0]<48?c="r:":c="M"}for(c.length<4&&(c+=`${(f?i:e)-d}`.padStart(4-c.length,"0")),s=="xg"&&e==16&&(a=`Voice${(i*128+t+1).toString().padStart(3,"0")}`,n=" ");!(a?.length>=0);)a=this.#t[r[1]||0][(r[0]<<7)+r[2]],a||(this.strictMode?(a="",n="?"):this.#t[r[1]||0][r[0]<<7]?r[0]==0?(r[2]=0,n="^"):r[2]<1?(r[0]=0,n="*"):(r[2]--,n="^"):e==48?(r[0]=0,r[2]=0,n="!"):e==62?(r[1]--,n=" ",r[1]<1&&!a?.length&&(r[0]=0,n="!")):e<64?r[0]==0?(r[2]=0,n="^"):r[2]<1?(r[0]=0,n="*"):r[2]--:e==80?(a=`PrgU:${t.toString().padStart(3,"0")}`,n="!"):e==88?(a=`CmbU:${t.toString().padStart(3,"0")}`,n="!"):e==121?(a=`GM2Vox0${i}`,n="#"):e==122?(r[1]==32?r[1]==0:r[1]%=7,a=this.#t[r[1]||0][(r[0]<<7)+r[2]],a?n=" ":(a="",n="*")):r[1]==0?(a=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${i.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="?"));(s=="gs"||s=="ns5r")&&n=="^"&&(n=" "),e==127&&n=="^"&&(n=" "),n!=" "&&self.debugMode&&(a="");let l="??";switch(r[0]){case 0:{r[2]==0?l="GM":r[2]==5||r[2]==7?l="KG":r[2]<120?l="XG":r[2]==127&&(l="MT");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:l="KR";case 64:case 126:{l="XG";break}case 67:case 99:{l="DX";break}case 81:{l="RW";break}case 95:{l=["DR","PC"][r[2]];break}case 96:{l=r[2]==106?"AP":"PF";break}case 97:{l="VL";break}case 98:{l="SG";break}case 100:{l="AN";break}case 120:{l="GS";break}case 121:{l=r[2]?"G2":"GM";break}case 122:{l="KG";break}case 127:{l=r[2]==127?"MT":t==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&s=="xg"?l="XG":l="GS")}return{name:a||`${S(e||0)} ${S(t||0)} ${S(i||0)}`,ending:n,sect:c,standard:l}}async load(e,t,i){let s=this,a=[],r=0,n=0;e.split(` -`).forEach(function(c,f){let d=c.split(" "),l=[];f==0?d.forEach(function(u,w){a[I.indexOf(u)]=w}):d.forEach(async function(u,w){w>2?(s.#t[l[a[1]]]=s.#t[l[a[1]]]||[],(!s.#t[l[a[1]]][(l[a[0]]<<7)+l[a[2]]]?.length||t)&&(s.#t[l[a[1]]][(l[a[0]]<<7)+l[a[2]]]=d[3],r++),n++):l.push(parseInt(d[w]))})}),t||console.debug(`Map "${i||"(internal)"}": ${n} total, ${r} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],i=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],s=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let a=i[0];a<=i[1];a++){let r=a<<7;for(let n=s[0];n<=s[1];n++){let c=r+n;for(let f=t[0];f<=t[1];f++)delete this.#t[f][c]}}}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(i,s){try{await fetch(`./data/bank/${i}.tsv`).then(function(a){return a.text()}).then(a=>{t.load(a,!1,i)})}catch{console.error(`Failed loading "${i}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var g=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],T=[[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]],y=[120,127,120,127,120,127,61,62,62,62,120,122,122],L=[0,3,81,84,88],v={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},x={0:0,1:1,2:3,5:4},R=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],O=[36,37];var M=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,12,13,16,17,18,19],H=[33,99,100,32,102,8,9,10];var p={};g.forEach((e,t)=>{p[e]=t});var o={length:M.length};M.forEach((e,t)=>{o[e]=t});var $=function(){return!!self.Bun||self.debugMode||!1},_=function(e){let t=[],i=0;return e?.forEach(function(s,a){s==247?t.push(e.subarray(i,a)):s==240&&(i=a+1)}),t.length||t.push(e.subarray(0)),$(),t},A=function(e,t="",i="",s=2){return e?`${t}${e.toString().padStart(s,"0")}${i}`:""},h={ch:128,cc:M.length,nn:128,pl:512,tr:256,cmt:14,rpn:6},ve=class extends m{#t=0;#m=0;#p=0;#g=new Array(11);get#o(){return this.#g[this.#m]}set#o(e){this.#g[this.#m]=e}#$=new Uint8Array(h.ch);#I=new Uint8Array(h.ch);#e=new Uint8ClampedArray(h.ch*h.cc);#y=new Uint8ClampedArray(h.ch);#h=new Uint8ClampedArray(h.ch*h.nn);#A=new Uint8Array(h.ch);#n=new Uint16Array(h.pl);#f=new Uint8Array(h.pl);#M=new Int16Array(h.ch);#d=new Uint8Array(h.ch);#C=0;#l=new Uint8Array(h.ch*h.rpn);#D=new Int8Array(h.ch*O.length);#U=new Uint8Array(h.ch);#F=new Uint8Array(128);#L=new Uint8Array(h.cmt*8);#V=new Uint8Array(1024);#H=new Uint8Array(h.cmt*64);#E=0;#u=0;#T=100;#w=0;#_=500;#z=0;#a="";#b=0;#q=0;#Q=!0;#s=!1;#K;#Y=new Uint8Array(2);#i=[];#k=new Uint8Array(h.ch);#S=new Uint8Array(h.tr);baseBank=new k("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new k("gm");initOnReset=!1;chRedir(e,t,i){if(this.#S[t])return(this.#S[t]-1)*16+e;if([p.gs,p.ns5r].indexOf(this.#t)>-1){if(i==1)return e;let s=0,a=!0;for(;a;)this.#k[e+s]==0?(this.#k[e+s]=t,console.debug(`Assign track ${t} to channel ${e+s+1}.`),a=!1):this.#k[e+s]==t?a=!1:(s+=16,s>=128&&(s=0,a=!1));return e+s}else return e}#c=[];#v;#r={nOff:(e,t)=>{let i=e*128+t,s=this.#n.lastIndexOf(i);s>-1&&(this.#e[h.cc*e+o[64]]>63&&!this.config?.disableCc64?this.#f[s]=4:(this.#n[s]=0,this.#h[i]=0,this.#f[s]=0))},nOn:(e,t,i)=>{let s=e*128+t,a=0;for(this.#A[e]&&this.#r.ano(e);this.#f[a]>0&&this.#n[a]!=s;)a++;a{},cAt:(e,t)=>{},hoOf:e=>{this.#f.forEach((t,i)=>{if(t==4){let s=this.#n[i],a=s>>7;e==a&&(this.#f[i]=0,this.#n[i]=0,this.#h[s]=0)}})},soOf:e=>{},ano:e=>{this.#n.forEach((t,i,s)=>{let a=t>>7,r=t&127;t==0&&this.#h[0]==0||a==e&&this.#r.nOff(a,r)})}};#X={8:function(e){let t=e.channel,i=e.data[0];this.#r.nOff(t,i)},9:function(e){let t=e.channel;this.#$[t]=1;let i=e.data[0],s=e.data[1];s>0?this.#r.nOn(t,i,s):this.#r.nOff(t,i)},10:function(e){let i=e.channel*128+e.data[0];this.#n.indexOf(i)>-1&&(this.#h[i]=data[1])},11:function(e){let t=e.channel;this.#$[t]=1;let i=t*h.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#r.ano(t),this.#M[t]=0;let s=t*h.cc;this.#e[s+o[1]]=0,this.#e[s+o[5]]=0,this.#e[s+o[64]]=0,this.#e[s+o[65]]=0,this.#e[s+o[66]]=0,this.#e[s+o[67]]=0,this.#e[s+o[11]]=127,this.#e[s+o[101]]=127,this.#e[s+o[100]]=127,this.#e[s+o[99]]=127,this.#e[s+o[98]]=127;return}case 123:{this.#r.ano(t);return}case 124:{this.#r.ano(t);return}case 125:{this.#r.ano(t);return}case 126:{this.#A[t]=1,this.#r.ano(t);return}case 127:{this.#A[t]=0,this.#r.ano(t);return}}if(o[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(e.data[0]){case 0:{if($()&&console.debug(`${g[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#e[i]>119&&(e.data[1]=this.#e[i],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==p.gs)e.data[1]<56&&this.#e[i]>119&&(e.data[1]=this.#e[i],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`));else if(this.#t==p.gm)e.data[1]<48?this.#e[i]>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==p.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let s=0;for(let a=0;a<16;a++){let r=this.#e[h.cc*a];(r==56||r==62)&&s++}s>14&&this.switchMode("ag10",!0)}}break}case 6:{if(this.#C){let s=this.#e[i+o[99]],a=this.#e[i+o[98]];if(s==1){let r=H.indexOf(a);if(r>-1)this.#e[i+o[71+r]]=e.data[1],$()&&console.debug(`Redirected NRPN 1 ${a} to cc${71+r}.`);else{let n=O.indexOf(a);n>-1&&(this.#D[t*10+n]=e.data[1]-64),$()&&console.debug(`CH${t+1} voice NRPN ${a} commit`)}}}else{let s=x[this.#e[i+o[100]]];this.#e[i+o[101]]==0&&s!=null&&($()&&console.debug(`CH${t+1} RPN 0 ${this.#e[i+o[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],R[s][0]),R[s][1]),this.#l[t*h.rpn+s]=e.data[1])}break}case 38:{this.#C||this.#e[i+101]==0&&x[this.#e[i+100]]!=null&&(this.#l[t*h.rpn+x[this.#e[i+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#r.hoOf(t);break}case 66:{console.debug(`Sostenuto pedal: ${e.data[1]}`);break}case 98:case 99:{this.#C=1;break}case 100:case 101:{this.#C=0;break}}this.#e[i+o[e.data[0]]]=e.data[1]}},12:function(e){let t=e.channel;this.#$[t]=1,this.#y[t]=e.data,this.#U[t]=0,$()&&console.debug(`T:${e.track} C:${t} P:${e.data}`)},13:function(e){let t=this,i=e.channel;this.#n.forEach(function(s){let a=s>>7;i==a&&(t.#h[s]=e.data)})},14:function(e){let t=e.channel;this.#M[t]=e.data[1]*128+e.data[0]-8192},15:function(e){_(e.data).forEach(t=>{let i=t[0],s=t[1];(this.#J[i]||function(){console.debug(`Unknown manufacturer ${i}.`)})(s,t.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){if((this.#c[e.meta]||function(i,s,a){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#w=0),L.indexOf(e.meta)>-1)return e.reply="meta",e;$()&&console.debug(e)}};#J={64:(e,t,i)=>{this.#P.run(t,i,e)},65:(e,t,i)=>{if(t[0]<16)this.#x.run(t,i,e),console.warn("Unknown device SysEx!");else{let s=t[t.length-1],a=gsChecksum(t.subarray(2,t.length-1));s==a?this.#x.run(t.subarray(0,t.length-1),i,e):console.warn(`Bad GS checksum ${s}. Should be ${a}.`)}},66:(e,t,i)=>{this.#O.run(t,i,e)},67:(e,t,i)=>{this.#R.run(t,i,e)},68:(e,t,i)=>{this.#W.run(t,i,e)},71:(e,t,i)=>{this.#B.run(t,i,e)},126:(e,t,i)=>{this.#N.run(t,i,e)},127:(e,t,i)=>{this.switchMode("gm"),this.#G.run(t,i,e)}};#N;#G;#R;#x;#O;#P;#B;#W;buildRchTree(){let e=[];this.#I.forEach((t,i)=>{e[t]?.constructor||(e[t]=[]),e[t].push(i)}),this.#K=e}getActive(){let e=this.#$.slice();return this.#t==p.mt32,e}getCc(e){let t=e*h.cc,i=this.#e.slice(t,t+h.cc);return i[o[0]]=i[o[0]]||this.#E,i[o[32]]=i[o[32]]||this.#u,i}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&t.set(n,{v:i.#h[s],s:i.#f[a]})}),t}getBitmap(){return{bitmap:this.#o,expire:this.#p}}getLetter(){return{text:this.#a,expire:this.#b}}getMode(){return g[this.#t]}getMaster(){return{volume:this.#T}}getRawStrength(){let e=this;return this.#n.forEach(function(t){let i=Math.floor(t/128);e.#h[t]>e.#d[i]&&(e.#d[i]=e.#h[t])}),this.#d}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(i,s){e[s]=Math.floor(i*t.#e[s*h.cc+o[7]]*t.#e[s*h.cc+o[11]]*t.#T/803288)}),e}getRpn(){return this.#l}getNrpn(){return this.#D}getVoice(e,t,i,s){let a=e||this.#E,r=t,n=i||this.#u;g[this.#t]=="ns5r"&&a>0&&a<56&&(n=3);let c=this.userBank.get(a,r,n,s);if(g[this.#t]=="mt32"&&c.name.indexOf("MT-m:")==0){let f=parseInt(c.name.slice(5)),d=f*h.cmt,l="";this.#H.subarray(d,d+10).forEach(u=>{u>31&&(l+=String.fromCharCode(u))}),this.userBank.load(`MSB LSB PRG -0 127 ${r} ${l}`,!0),c.name=l,c.ending=" "}return(c.ending!=" "||!c.name.length)&&(c=this.baseBank.get(a,r,n,s)),c}getChVoice(e){let t=this.getVoice(this.#e[e*h.cc+o[0]],this.#y[e],this.#e[e*h.cc+o[32]],g[this.#t]);if(this.#U[e])switch(this.#t){case p.mt32:t.ending="~",t.name="",this.#L.subarray(14*(e-1),14*(e-1)+10).forEach(i=>{i>31&&(t.name+=String.fromCharCode(i))})}return t}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#E=0,this.#u=0,this.#w=0,this.#$.fill(0),this.#e.fill(0),this.#y.fill(0),this.#h.fill(0),this.#n.fill(0),this.#d.fill(0),this.#M.fill(0),this.#D.fill(0),this.#T=100,this.#i=[],this.#_=500,this.#z=0,this.#b=0,this.#a="",this.#p=0,this.#m=0,this.#o.fill(0),this.#s=!1,this.#q=0,this.#Q=!0,this.#I.forEach(function(t,i,s){s[i]=i}),this.buildRchTree(),e==0&&(this.#k.fill(0),this.#S.fill(0)),this.#e[h.cc*9]=y[0],this.#e[h.cc*25]=y[0],this.#e[h.cc*41]=y[0],this.#e[h.cc*57]=y[0],this.#Y.fill(0),this.#V.fill(0),this.#H.fill(0),this.#F.fill(0),this.#L.fill(0),this.#U.fill(0),this.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let t=0;t-1){if(this.#t==0||t){this.#t=i,this.#m=0,this.#E=T[0][i],this.#u=T[1][i];for(let s=0;s-1&&(this.#e[s*h.cc]=y[i]);switch(this.initOnReset,i){case p.mt32:{mt32DefProg.forEach((s,a)=>{let r=a+1;this.#$[r]||(this.#y[r]=s,this.#e[r*h.cc+o[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.#X[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),i=!1;this.#K[t]?.forEach(s=>{e.channel=s,i=!0,this.#X[e.type].call(this,e)}),i||console.warn(`${v[e.type]?v[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.#i.length>100&&this.#i.splice(100,this.#i.length-99)}runRaw(e){}constructor(){super();let e=this;this.#o=new Uint8Array(256),this.#g[10]=new Uint8Array(512),this.#v=new b,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let t=e.split(",");N[t[0]]=t[1]});var G=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"];var P=[20,21,22,23,24,25,26,28,29,30,31,36,37,64,65];var E=[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];var B={};G.forEach((e,t)=>{B[e]=t});var I={length:E.length};E.forEach((e,t)=>{I[e]=t});var ke={ch:128,cc:E.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:P.length,dnc:72,efx:7};var L=["MSB","PRG","LSB"];var S=function(e){let t=Math.floor(e/10),i=e%10;return`${t.toString(16)}${i}`},k=class{#t;strictMode=!1;get(e=0,t=0,i=0,s){let a,r=Array.from(arguments);switch(s){case"xg":{e==32?r[2]+=4:e==33||e==35||e==36?r[2]+=5:e==79?r[0]=95:e==80?r[0]=96:e==81?r[0]=97:e==82?r[0]=98:e==83?r[0]=99:e==84&&(r[0]=100);break}case"gs":{e==0&&i<5?r[2]=0:e>125&&i<5&&i!=2&&(r[2]=e,r[0]=0);break}case"sg":{e==8&&i==0&&(r[2]=5);break}}let n=" ",c="M",f=!1,d=0;switch(r[0]){case 0:{r[2]==127?c="MT-a":r[2]==126?c="MT-b":r[2]==7?c="GM-k":r[2]==5?c="SG-a":r[2]==4?c="SP-l":r[2]==0||s=="gs"&&r[2]<5?c="GM-a":(c="y",f=!0);break}case 8:{s=="sg"?c="GM-s":c="r:";break}case 48:{c=`yM${(r[2]>>3).toString().padStart(2,"0")}`,f=!0;break}case 56:{c="GM-b";break}case 61:case 120:{c="rDrm";break}case 62:{c="kDrm";break}case 63:{let u=r[2];c=u<10?"kP:":"kC:",c+=u%10;break}case 64:{c="ySFX";break}case 67:{c="DX:S";break}case 80:case 81:case 82:case 83:{c=`Prg${"UABC"[r[0]-80]}`;break}case 88:case 89:case 90:case 91:{c=`Cmb${"UABC"[r[0]-88]}`;break}case 95:{c=`${["DR","PC"][r[2]]}-d`;break}case 96:{c=r[2]==106?"AP-a":"PF",r[2]>63&&(d=63),f=!0;break}case 97:{c="VL:",f=!0,d=112;break}case 98:{c="SG-a";break}case 99:{c="DX",r[2]>63&&(d=63),f=!0;break}case 100:{c="AN",r[2]>63&&(d=63),f=!0;break}case 121:{c=`GM-${r[2]?"":"a"}`,f=!0;break}case 122:{c="lDrm";break}case 126:{c="yDrS";break}case 127:{r[2]==127?c="rDrm":c="yDrm";break}default:r[0]<48?c="r:":c="M"}for(c.length<4&&(c+=`${(f?i:e)-d}`.padStart(4-c.length,"0")),s=="xg"&&e==16&&(a=`Voice${(i*128+t+1).toString().padStart(3,"0")}`,n=" ");!(a?.length>=0);)a=this.#t[r[1]||0][(r[0]<<7)+r[2]],a||(this.strictMode?(a="",n="?"):this.#t[r[1]||0][r[0]<<7]?r[0]==0?(r[2]=0,n="^"):r[2]<1?(r[0]=0,n="*"):(r[2]--,n="^"):e==48?(r[0]=0,r[2]=0,n="!"):e==62?(r[1]--,n=" ",r[1]<1&&!a?.length&&(r[0]=0,n="!")):e<64?r[0]==0?(r[2]=0,n="^"):r[2]<1?(r[0]=0,n="*"):r[2]--:e==80?(a=`PrgU:${t.toString().padStart(3,"0")}`,n="!"):e==88?(a=`CmbU:${t.toString().padStart(3,"0")}`,n="!"):e==121?(a=`GM2Vox0${i}`,n="#"):e==122?(r[1]==32?r[1]==0:r[1]%=7,a=this.#t[r[1]||0][(r[0]<<7)+r[2]],a?n=" ":(a="",n="*")):r[1]==0?(a=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${i.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="?"));(s=="gs"||s=="ns5r")&&n=="^"&&(n=" "),e==127&&n=="^"&&(n=" "),n!=" "&&self.debugMode&&(a="");let l="??";switch(r[0]){case 0:{r[2]==0?l="GM":r[2]==5||r[2]==7?l="KG":r[2]<120?l="XG":r[2]==127&&(l="MT");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:l="KR";case 64:case 126:{l="XG";break}case 67:case 99:{l="DX";break}case 81:{l="RW";break}case 95:{l=["DR","PC"][r[2]];break}case 96:{l=r[2]==106?"AP":"PF";break}case 97:{l="VL";break}case 98:{l="SG";break}case 100:{l="AN";break}case 120:{l="GS";break}case 121:{l=r[2]?"G2":"GM";break}case 122:{l="KG";break}case 127:{l=r[2]==127?"MT":t==0?"GM":"XG";break}default:r[0]<48&&(r[0]==16&&s=="xg"?l="XG":l="GS")}return{name:a||`${S(e||0)} ${S(t||0)} ${S(i||0)}`,ending:n,sect:c,standard:l}}async load(e,t,i){let s=this,a=[],r=0,n=0;e.split(` +`).forEach(function(c,f){let d=c.split(" "),l=[];f==0?d.forEach(function(u,w){a[L.indexOf(u)]=w}):d.forEach(async function(u,w){w>2?(s.#t[l[a[1]]]=s.#t[l[a[1]]]||[],(!s.#t[l[a[1]]][(l[a[0]]<<7)+l[a[2]]]?.length||t)&&(s.#t[l[a[1]]][(l[a[0]]<<7)+l[a[2]]]=d[3],r++),n++):l.push(parseInt(d[w]))})}),t||console.debug(`Map "${i||"(internal)"}": ${n} total, ${r} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],i=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],s=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let a=i[0];a<=i[1];a++){let r=a<<7;for(let n=s[0];n<=s[1];n++){let c=r+n;for(let f=t[0];f<=t[1];f++)delete this.#t[f][c]}}}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(i,s){try{await fetch(`./data/bank/${i}.tsv`).then(function(a){return a.text()}).then(a=>{t.load(a,!1,i)})}catch{console.error(`Failed loading "${i}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var g=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],T=[[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]],y=[120,127,120,127,120,127,61,62,62,62,120,122,122],H=[0,3,81,84,88],v={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},x={0:0,1:1,2:3,5:4},R=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],O=[36,37];var M=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,12,13,16,17,18,19],_=[33,99,100,32,102,8,9,10];var p={};g.forEach((e,t)=>{p[e]=t});var o={length:M.length};M.forEach((e,t)=>{o[e]=t});var $=function(){return!!self.Bun||self.debugMode||!1},K=function(e){let t=[],i=0;return e?.forEach(function(s,a){s==247?t.push(e.subarray(i,a)):s==240&&(i=a+1)}),t.length||t.push(e.subarray(0)),$(),t},A=function(e,t="",i="",s=2){return e?`${t}${e.toString().padStart(s,"0")}${i}`:""},h={ch:128,cc:M.length,nn:128,pl:512,tr:256,cmt:14,rpn:6},Re=class extends m{#t=0;#m=0;#p=0;#g=new Array(11);get#o(){return this.#g[this.#m]}set#o(e){this.#g[this.#m]=e}#$=new Uint8Array(h.ch);#I=new Uint8Array(h.ch);#e=new Uint8ClampedArray(h.ch*h.cc);#y=new Uint8ClampedArray(h.ch);#h=new Uint8ClampedArray(h.ch*h.nn);#A=new Uint8Array(h.ch);#n=new Uint16Array(h.pl);#f=new Uint8Array(h.pl);#M=new Int16Array(h.ch);#d=new Uint8Array(h.ch);#C=0;#l=new Uint8Array(h.ch*h.rpn);#U=new Int8Array(h.ch*O.length);#D=new Uint8Array(h.ch);#F=new Uint8Array(128);#L=new Uint8Array(h.cmt*8);#V=new Uint8Array(1024);#H=new Uint8Array(h.cmt*64);#E=0;#u=0;#T=100;#w=0;#_=500;#z=0;#a="";#b=0;#q=0;#Q=!0;#s=!1;#K;#Y=new Uint8Array(2);#i=[];#k=new Uint8Array(h.ch);#S=new Uint8Array(h.tr);baseBank=new k("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new k("gm");initOnReset=!1;chRedir(e,t,i){if(this.#S[t])return(this.#S[t]-1)*16+e;if([p.gs,p.ns5r].indexOf(this.#t)>-1){if(i==1)return e;let s=0,a=!0;for(;a;)this.#k[e+s]==0?(this.#k[e+s]=t,console.debug(`Assign track ${t} to channel ${e+s+1}.`),a=!1):this.#k[e+s]==t?a=!1:(s+=16,s>=128&&(s=0,a=!1));return e+s}else return e}#c=[];#v;#r={nOff:(e,t)=>{let i=e*128+t,s=this.#n.lastIndexOf(i);s>-1&&(this.#e[h.cc*e+o[64]]>63&&!this.config?.disableCc64?this.#f[s]=4:(this.#n[s]=0,this.#h[i]=0,this.#f[s]=0))},nOn:(e,t,i)=>{let s=e*128+t,a=0;for(this.#A[e]&&this.#r.ano(e);this.#f[a]>0&&this.#n[a]!=s;)a++;a{},cAt:(e,t)=>{},hoOf:e=>{this.#f.forEach((t,i)=>{if(t==4){let s=this.#n[i],a=s>>7;e==a&&(this.#f[i]=0,this.#n[i]=0,this.#h[s]=0)}})},soOf:e=>{},ano:e=>{this.#n.forEach((t,i,s)=>{let a=t>>7,r=t&127;t==0&&this.#h[0]==0||a==e&&this.#r.nOff(a,r)})}};#X={8:function(e){let t=e.channel,i=e.data[0];this.#r.nOff(t,i)},9:function(e){let t=e.channel;this.#$[t]=1;let i=e.data[0],s=e.data[1];s>0?this.#r.nOn(t,i,s):this.#r.nOff(t,i)},10:function(e){let i=e.channel*128+e.data[0];this.#n.indexOf(i)>-1&&(this.#h[i]=data[1])},11:function(e){let t=e.channel;this.#$[t]=1;let i=t*h.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#r.ano(t),this.#M[t]=0;let s=t*h.cc;this.#e[s+o[1]]=0,this.#e[s+o[5]]=0,this.#e[s+o[64]]=0,this.#e[s+o[65]]=0,this.#e[s+o[66]]=0,this.#e[s+o[67]]=0,this.#e[s+o[11]]=127,this.#e[s+o[101]]=127,this.#e[s+o[100]]=127,this.#e[s+o[99]]=127,this.#e[s+o[98]]=127;return}case 123:{this.#r.ano(t);return}case 124:{this.#r.ano(t);return}case 125:{this.#r.ano(t);return}case 126:{this.#A[t]=1,this.#r.ano(t);return}case 127:{this.#A[t]=0,this.#r.ano(t);return}}if(o[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(e.data[0]){case 0:{if($()&&console.debug(`${g[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#e[i]>119&&(e.data[1]=this.#e[i],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==p.gs)e.data[1]<56&&this.#e[i]>119&&(e.data[1]=this.#e[i],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`));else if(this.#t==p.gm)e.data[1]<48?this.#e[i]>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==p.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let s=0;for(let a=0;a<16;a++){let r=this.#e[h.cc*a];(r==56||r==62)&&s++}s>14&&this.switchMode("ag10",!0)}}break}case 6:{if(this.#C){let s=this.#e[i+o[99]],a=this.#e[i+o[98]];if(s==1){let r=_.indexOf(a);if(r>-1)this.#e[i+o[71+r]]=e.data[1],$()&&console.debug(`Redirected NRPN 1 ${a} to cc${71+r}.`);else{let n=O.indexOf(a);n>-1&&(this.#U[t*10+n]=e.data[1]-64),$()&&console.debug(`CH${t+1} voice NRPN ${a} commit`)}}}else{let s=x[this.#e[i+o[100]]];this.#e[i+o[101]]==0&&s!=null&&($()&&console.debug(`CH${t+1} RPN 0 ${this.#e[i+o[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],R[s][0]),R[s][1]),this.#l[t*h.rpn+s]=e.data[1])}break}case 38:{this.#C||this.#e[i+101]==0&&x[this.#e[i+100]]!=null&&(this.#l[t*h.rpn+x[this.#e[i+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#r.hoOf(t);break}case 66:{console.debug(`Sostenuto pedal: ${e.data[1]}`);break}case 98:case 99:{this.#C=1;break}case 100:case 101:{this.#C=0;break}}this.#e[i+o[e.data[0]]]=e.data[1]}},12:function(e){let t=e.channel;this.#$[t]=1,this.#y[t]=e.data,this.#D[t]=0,$()&&console.debug(`T:${e.track} C:${t} P:${e.data}`)},13:function(e){let t=this,i=e.channel;this.#n.forEach(function(s){let a=s>>7;i==a&&(t.#h[s]=e.data)})},14:function(e){let t=e.channel;this.#M[t]=e.data[1]*128+e.data[0]-8192},15:function(e){K(e.data).forEach(t=>{let i=t[0],s=t[1];(this.#J[i]||function(){console.debug(`Unknown manufacturer ${i}.`)})(s,t.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){if((this.#c[e.meta]||function(i,s,a){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#w=0),H.indexOf(e.meta)>-1)return e.reply="meta",e;$()&&console.debug(e)}};#J={64:(e,t,i)=>{this.#P.run(t,i,e)},65:(e,t,i)=>{if(t[0]<16)this.#x.run(t,i,e),console.warn("Unknown device SysEx!");else{let s=t[t.length-1],a=gsChecksum(t.subarray(2,t.length-1));s==a?this.#x.run(t.subarray(0,t.length-1),i,e):console.warn(`Bad GS checksum ${s}. Should be ${a}.`)}},66:(e,t,i)=>{this.#O.run(t,i,e)},67:(e,t,i)=>{this.#R.run(t,i,e)},68:(e,t,i)=>{this.#W.run(t,i,e)},71:(e,t,i)=>{this.#B.run(t,i,e)},126:(e,t,i)=>{this.#N.run(t,i,e)},127:(e,t,i)=>{this.switchMode("gm"),this.#G.run(t,i,e)}};#N;#G;#R;#x;#O;#P;#B;#W;buildRchTree(){let e=[];this.#I.forEach((t,i)=>{e[t]?.constructor||(e[t]=[]),e[t].push(i)}),this.#K=e}getActive(){let e=this.#$.slice();return this.#t==p.mt32,e}getCc(e){let t=e*h.cc,i=this.#e.slice(t,t+h.cc);return i[o[0]]=i[o[0]]||this.#E,i[o[32]]=i[o[32]]||this.#u,i}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&t.set(n,{v:i.#h[s],s:i.#f[a]})}),t}getBitmap(){return{bitmap:this.#o,expire:this.#p}}getLetter(){return{text:this.#a,expire:this.#b}}getMode(){return g[this.#t]}getMaster(){return{volume:this.#T}}getRawStrength(){let e=this;return this.#n.forEach(function(t){let i=Math.floor(t/128);e.#h[t]>e.#d[i]&&(e.#d[i]=e.#h[t])}),this.#d}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(i,s){e[s]=Math.floor(i*t.#e[s*h.cc+o[7]]*t.#e[s*h.cc+o[11]]*t.#T/803288)}),e}getRpn(){return this.#l}getNrpn(){return this.#U}getVoice(e,t,i,s){let a=e||this.#E,r=t,n=i||this.#u;g[this.#t]=="ns5r"&&a>0&&a<56&&(n=3);let c=this.userBank.get(a,r,n,s);if(g[this.#t]=="mt32"&&c.name.indexOf("MT-m:")==0){let f=parseInt(c.name.slice(5)),d=f*h.cmt,l="";this.#H.subarray(d,d+10).forEach(u=>{u>31&&(l+=String.fromCharCode(u))}),this.userBank.load(`MSB LSB PRG +0 127 ${r} ${l}`,!0),c.name=l,c.ending=" "}return(c.ending!=" "||!c.name.length)&&(c=this.baseBank.get(a,r,n,s)),c}getChVoice(e){let t=this.getVoice(this.#e[e*h.cc+o[0]],this.#y[e],this.#e[e*h.cc+o[32]],g[this.#t]);if(this.#D[e])switch(this.#t){case p.mt32:t.ending="~",t.name="",this.#L.subarray(14*(e-1),14*(e-1)+10).forEach(i=>{i>31&&(t.name+=String.fromCharCode(i))})}return t}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#E=0,this.#u=0,this.#w=0,this.#$.fill(0),this.#e.fill(0),this.#y.fill(0),this.#h.fill(0),this.#n.fill(0),this.#d.fill(0),this.#M.fill(0),this.#U.fill(0),this.#T=100,this.#i=[],this.#_=500,this.#z=0,this.#b=0,this.#a="",this.#p=0,this.#m=0,this.#o.fill(0),this.#s=!1,this.#q=0,this.#Q=!0,this.#I.forEach(function(t,i,s){s[i]=i}),this.buildRchTree(),e==0&&(this.#k.fill(0),this.#S.fill(0)),this.#e[h.cc*9]=y[0],this.#e[h.cc*25]=y[0],this.#e[h.cc*41]=y[0],this.#e[h.cc*57]=y[0],this.#Y.fill(0),this.#V.fill(0),this.#H.fill(0),this.#F.fill(0),this.#L.fill(0),this.#D.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=i,this.#m=0,this.#E=T[0][i],this.#u=T[1][i];for(let s=0;s-1&&(this.#e[s*h.cc]=y[i]);switch(this.initOnReset,i){case p.mt32:{mt32DefProg.forEach((s,a)=>{let r=a+1;this.#$[r]||(this.#y[r]=s,this.#e[r*h.cc+o[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.#X[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),i=!1;this.#K[t]?.forEach(s=>{e.channel=s,i=!0,this.#X[e.type].call(this,e)}),i||console.warn(`${v[e.type]?v[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.#i.length>100&&this.#i.splice(100,this.#i.length-99)}runRaw(e){}constructor(){super();let e=this;this.#o=new Uint8Array(256),this.#g[10]=new Uint8Array(512),this.#v=new b,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -145,4 +145,4 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),this.#c[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#s=!0,this.#i.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#s=!0,this.#i.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#s=!0,this.#i.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#s=!0,this.#i.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#s=!0,this.#i.unshift(`Kara.Ver: ${t.slice(2)}`);break}case"XF":{let i=t.slice(2).split(":");switch(i[0]){case"hd":{i.slice(1).forEach((s,a)=>{s.length&&this.#i.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][a]}: ${s}`)});break}case"ln":{i.slice(1).forEach((s,a)=>{s.length&&this.#i.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][a]}: ${s}`)});break}default:this.#i.unshift(`XGF_Data: ${t}`)}break}default:this.#s?t[0]=="\\"?this.#i.unshift(`@ ${t.slice(1)}`):t[0]=="/"?this.#i.unshift(t.slice(1)):this.#i[0]+=t:(this.#i[0]=t,this.#i.unshift(""))}},this.#c[2]=function(t){this.#i.unshift(`Copyrite: ${t}`)},this.#c[3]=function(t,i){i<1&&this.#w<1&&this.#i.unshift(`TrkTitle: ${t}`)},this.#c[4]=function(t,i){this.#i.unshift(`${A(this.#w,""," ")}Instrmnt: ${t}`)},this.#c[5]=function(t){t.trim()==""?this.#i.unshift(""):this.#i[0]+=`${t}`},this.#c[6]=function(t){this.#i.unshift(`${A(this.#w,""," ")}C.Marker: ${t}`)},this.#c[7]=function(t){this.#i.unshift(`CuePoint: ${t}`)},this.#c[32]=function(t){this.#w=t[0]+1},this.#c[33]=function(t,i){console.debug(`Track ${i} requests to get assigned to output ${t}.`),e.#S[i]=t+1},this.#c[81]=function(t,i){e.#_=t/1e3},this.#c[127]=function(t,i){e.#v.run(t,i)},this.#v.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#v.add([67,0,1],function(t,i){e.#S[i]=t[0]+1}),this.#N=new b,this.#G=new b,this.#R=new b,this.#x=new b,this.#O=new b,this.#P=new b,this.#B=new b,this.#N.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#s=e.#s||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#G.add([4,1],t=>{e.#T=((t[1]<<7)+t[0])/16383*100}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#R.add([76,0,0],t=>{switch(t[0]){case 126:{e.switchMode("xg",!0),e.#s=!1,console.info("MIDI reset: XG");break}}}).add([76,6,0],t=>{let i=t[0];i<64?(e.#a=" ".repeat(i),e.#b=Date.now()+3200,t.subarray(1).forEach(function(s){e.#a+=String.fromCharCode(s)}),e.#a=e.#a.padEnd(32," ")):e.#b=Date.now()}).add([76,7,0],t=>{let i=t[0];e.#p=Date.now()+3200,e.#o.fill(0);let s=t.subarray(1);for(let a=0;a>6-l&1,l++})}),this.#R.add([43,7,0],(t,i,s)=>{e.#a=" ".repeat(offset),e.#b=Date.now()+3200,t.subarray(1).forEach(function(a){e.#a+=String.fromCharCode(a)}),e.#a=e.#a.padEnd(32," ")}).add([43,7,1],(t,i,s)=>{e.#p=Date.now()+3200,e.#o.fill(0),t.forEach(function(a,r){let n=Math.floor(r/16),c=r%16,f=(c*3+n)*7,d=7,l=0;for(f-=c*5,n==2&&(d=2);l>6-l&1,l++})}),this.#x.add([66,18,0,0,127],(t,i,s)=>{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.#s=!1,e.#k.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,i,s)=>{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.#s=!1,e.#k.fill(0),console.info("MIDI reset: GS");break}}}).add([69,18,16],t=>{switch(t[0]){case 0:{e.#b=Date.now()+3200;let i=t[1];e.#a=" ".repeat(i),t.subarray(2).forEach(function(s){s<128&&(e.#a+=String.fromCharCode(s))});break}case 32:{e.#p=Date.now()+3200,t[1]==0&&(e.#m=Math.max(Math.min(t[2]-1,9),0));break}default:if(t[0]<11){e.#p=Date.now()+3200,e.#g[t[0]-1]?.length||(e.#g[t[0]-1]=new Uint8Array(256));let i=e.#g[t[0]-1],s=t[1];i.fill(0);let a=t.subarray(2);for(let r=0;r>4-u&1,u++})}else console.warn(`Unknown GS display section: ${t[0]}`)}}),this.#x.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#s=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,32],t=>{e.switchMode("mt32");let i=t[1],s=" ".repeat(i);t.subarray(2).forEach(a=>{a>31&&(s+=String.fromCharCode(a))}),e.#a=s.padStart(20," "),e.#b=Date.now()+3200}).add([22,18,82],(t,i)=>{let s=e.chRedir(0,i,!0);for(let a=0;a<16;a++)e.#r.ano(s+a),a&&a<10&&(e.#y[s+a]=mt32DefProg[a-1]);console.info("MT-32 alt reset complete.")}),this.#O.add([66,0],(t,i)=>{e.switchMode("ns5r",!0),e.#s=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,i)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#s=!1}).add([66,18,0,0],(t,i)=>{switch(t[0]){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#s=!1;break}}}).add([66,18,8,0],(t,i)=>{}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let i=new Uint8Array(5760);korgFilter(t,(s,a,r)=>{if(a<720)for(let n=0;n<8;n++)i[a*8+n]=s>>7-n&1}),e.dispatchEvent("screen",{type:"ns5r",data:i})}).add([76],(t,i,s)=>{e.#O.run([66,...t],i,s)}),this.#P.add([16,0,8,0],(t,i,s)=>{let a=(t[2]<<4)+t[3],r="K11 ";([()=>{e.switchMode("k11",!0),e.#s=!1,e.#u=a?4:0,console.info("MIDI reset: GMega/K11")}][t[0]]||(()=>{}))()}),this.#B.add([66,93,64],(t,i,s)=>{let a=t[2];switch(t[0]){case 0:{switch(t[1]){case 127:{e.switchMode("sg",!0);break}}break}}})}};export{ve as OctaviaDevice,h as allocated,o as ccToPos}; +122 006 000 `),this.#c[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#s=!0,this.#i.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#s=!0,this.#i.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#s=!0,this.#i.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#s=!0,this.#i.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#s=!0,this.#i.unshift(`Kara.Ver: ${t.slice(2)}`);break}case"XF":{let i=t.slice(2).split(":");switch(i[0]){case"hd":{i.slice(1).forEach((s,a)=>{s.length&&this.#i.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][a]}: ${s}`)});break}case"ln":{i.slice(1).forEach((s,a)=>{s.length&&this.#i.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][a]}: ${s}`)});break}default:this.#i.unshift(`XGF_Data: ${t}`)}break}default:this.#s?t[0]=="\\"?this.#i.unshift(`@ ${t.slice(1)}`):t[0]=="/"?this.#i.unshift(t.slice(1)):this.#i[0]+=t:(this.#i[0]=t,this.#i.unshift(""))}},this.#c[2]=function(t){this.#i.unshift(`Copyrite: ${t}`)},this.#c[3]=function(t,i){i<1&&this.#w<1&&this.#i.unshift(`TrkTitle: ${t}`)},this.#c[4]=function(t,i){this.#i.unshift(`${A(this.#w,""," ")}Instrmnt: ${t}`)},this.#c[5]=function(t){t.trim()==""?this.#i.unshift(""):this.#i[0]+=`${t}`},this.#c[6]=function(t){this.#i.unshift(`${A(this.#w,""," ")}C.Marker: ${t}`)},this.#c[7]=function(t){this.#i.unshift(`CuePoint: ${t}`)},this.#c[32]=function(t){this.#w=t[0]+1},this.#c[33]=function(t,i){console.debug(`Track ${i} requests to get assigned to output ${t}.`),e.#S[i]=t+1},this.#c[81]=function(t,i){e.#_=t/1e3},this.#c[127]=function(t,i){e.#v.run(t,i)},this.#v.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#v.add([67,0,1],function(t,i){e.#S[i]=t[0]+1}),this.#N=new b,this.#G=new b,this.#R=new b,this.#x=new b,this.#O=new b,this.#P=new b,this.#B=new b,this.#N.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#s=e.#s||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#G.add([4,1],t=>{e.#T=((t[1]<<7)+t[0])/16383*100}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#R.add([76,0,0],t=>{switch(t[0]){case 126:{e.switchMode("xg",!0),e.#s=!1,console.info("MIDI reset: XG");break}}}).add([76,6,0],t=>{let i=t[0];i<64?(e.#a=" ".repeat(i),e.#b=Date.now()+3200,t.subarray(1).forEach(function(s){e.#a+=String.fromCharCode(s)}),e.#a=e.#a.padEnd(32," ")):e.#b=Date.now()}).add([76,7,0],t=>{let i=t[0];e.#p=Date.now()+3200,e.#o.fill(0);let s=t.subarray(1);for(let a=0;a>6-l&1,l++})}),this.#R.add([43,7,0],(t,i,s)=>{e.#a=" ".repeat(offset),e.#b=Date.now()+3200,t.subarray(1).forEach(function(a){e.#a+=String.fromCharCode(a)}),e.#a=e.#a.padEnd(32," ")}).add([43,7,1],(t,i,s)=>{e.#p=Date.now()+3200,e.#o.fill(0),t.forEach(function(a,r){let n=Math.floor(r/16),c=r%16,f=(c*3+n)*7,d=7,l=0;for(f-=c*5,n==2&&(d=2);l>6-l&1,l++})}),this.#x.add([66,18,0,0,127],(t,i,s)=>{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.#s=!1,e.#k.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,i,s)=>{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.#s=!1,e.#k.fill(0),console.info("MIDI reset: GS");break}}}).add([69,18,16],t=>{switch(t[0]){case 0:{e.#b=Date.now()+3200;let i=t[1];e.#a=" ".repeat(i),t.subarray(2).forEach(function(s){s<128&&(e.#a+=String.fromCharCode(s))});break}case 32:{e.#p=Date.now()+3200,t[1]==0&&(e.#m=Math.max(Math.min(t[2]-1,9),0));break}default:if(t[0]<11){e.#p=Date.now()+3200,e.#g[t[0]-1]?.length||(e.#g[t[0]-1]=new Uint8Array(256));let i=e.#g[t[0]-1],s=t[1];i.fill(0);let a=t.subarray(2);for(let r=0;r>4-u&1,u++})}else console.warn(`Unknown GS display section: ${t[0]}`)}}),this.#x.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#s=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,32],t=>{e.switchMode("mt32");let i=t[1],s=" ".repeat(i);t.subarray(2).forEach(a=>{a>31&&(s+=String.fromCharCode(a))}),e.#a=s.padStart(20," "),e.#b=Date.now()+3200}).add([22,18,82],(t,i)=>{let s=e.chRedir(0,i,!0);for(let a=0;a<16;a++)e.#r.ano(s+a),a&&a<10&&(e.#y[s+a]=mt32DefProg[a-1]);console.info("MT-32 alt reset complete.")}),this.#O.add([66,0],(t,i)=>{e.switchMode("ns5r",!0),e.#s=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,i)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#s=!1}).add([66,18,0,0],(t,i)=>{switch(t[0]){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#s=!1;break}}}).add([66,18,8,0],(t,i)=>{}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let i=new Uint8Array(5760);korgFilter(t,(s,a,r)=>{if(a<720)for(let n=0;n<8;n++)i[a*8+n]=s>>7-n&1}),e.dispatchEvent("screen",{type:"ns5r",data:i})}).add([76],(t,i,s)=>{e.#O.run([66,...t],i,s)}),this.#P.add([16,0,8,0],(t,i,s)=>{let a=(t[2]<<4)+t[3],r="K11 ";([()=>{e.switchMode("k11",!0),e.#s=!1,e.#u=a?4:0,console.info("MIDI reset: GMega/K11")}][t[0]]||(()=>{}))()}),this.#B.add([66,93,64],(t,i,s)=>{let a=t[2];switch(t[0]){case 0:{switch(t[1]){case 127:{e.switchMode("sg",!0);break}}break}}})}};export{Re as OctaviaDevice,h as allocated,o as ccToPos}; diff --git a/src/state/index.mjs b/src/state/index.mjs index 54ab9073..f8f7df2a 100644 --- a/src/state/index.mjs +++ b/src/state/index.mjs @@ -70,6 +70,7 @@ rpnCap = [ ], useNormNrpn = [36, 37], useDrumNrpn = [20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 36, 37, 64, 65], +drumNotes = [12, 83], ccAccepted = [ 0, 1, 2, 4, 5, 6, 7, 8, 10, 11, 32, 38, 64, 65, 66, 67, 68, 69, 70, 71, @@ -131,6 +132,9 @@ const allocated = { cmt: 14, // C/M timbre storage size rpn: 6, ace: 8, // active custom effect + drm: 8, // Drum setup slots + dpn: useDrumNrpn.length, // Drum setup params + dnc: 72, // note 83 to 12 efx: 7 }; @@ -182,6 +186,7 @@ let OctaviaDevice = class extends CustomEventSource { #dataCommit = 0; // 0 for RPN, 1 for NRPN #rpn = new Uint8Array(allocated.ch * allocated.rpn); // RPN registers (0 pitch MSB, 1 fine tune MSB, 2 fine tune LSB, 3 coarse tune MSB, 4 mod sensitivity MSB, 5 mod sensitivity LSB) #nrpn = new Int8Array(allocated.ch * useNormNrpn.length); // Normal section of NRPN registers + #drum = new Uint8Array(allocated.drm * allocated.dpn * allocated.dnc); // Drum setup #bnCustom = new Uint8Array(allocated.ch); // Custom name activation #cmTPatch = new Uint8Array(128); // C/M part patch storage #cmTTimbre = new Uint8Array(allocated.cmt * 8); // C/M part timbre storage @@ -1159,6 +1164,7 @@ let OctaviaDevice = class extends CustomEventSource { this.#rawStrength.fill(0); this.#pitch.fill(0); this.#nrpn.fill(0); + this.#drum.fill(0); this.#masterVol = 100; this.#metaTexts = []; this.#noteLength = 500;