From d43c2f352e7029b1a9c18913a679873dbe9b617d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lumi=C3=A8re=20=C3=89lev=C3=A9?= <88174309+PoneyClairDeLune@users.noreply.github.com> Date: Sat, 28 Oct 2023 20:52:50 +0000 Subject: [PATCH] Octavia SC MIDI CH display is now fixed. --- data/bank/gs.tsv | 4 ++-- data/map/gs.10.tsv | 15 ++++++++++++++- data/map/gs.12.tsv | 17 +++++++++++++++-- data/map/gs.24.tsv | 19 +++++++++++++++++-- dist/basic.mjs | 4 ++-- dist/cambiare.mjs | 44 ++++++++++++++++++++++---------------------- dist/state.mjs | 34 +++++++++++++++++----------------- dist/state_skim.mjs | 2 +- dist/xp_basic.mjs | 40 ++++++++++++++++++++-------------------- dist/xp_state.mjs | 32 ++++++++++++++++---------------- src/disp/disp_sc.mjs | 8 +++++++- 11 files changed, 133 insertions(+), 86 deletions(-) diff --git a/data/bank/gs.tsv b/data/bank/gs.tsv index 0aaa94cd..ca949293 100644 --- a/data/bank/gs.tsv +++ b/data/bank/gs.tsv @@ -807,7 +807,7 @@ LSB PRG MSB NME 002 087 002 Fat&Prky 003 087 003 JUNORave 003 087 004 JP8BaLd1 -003 087 005 JBPBaLd2 +003 087 005 JP8BaLd2 003 087 006 SH-5BaLd 004 087 007 Delay.Ld 000 088 000 NewAgePd @@ -1044,7 +1044,7 @@ LSB PRG MSB NME 000 114 000 SteelDrm 003 114 001 IslndMlt 000 115 000 Woodblok -000 115 008 Cascanet +000 115 008 Castanet 003 115 016 Angklung 003 115 017 AngkRthm 003 115 024 FngrSnap diff --git a/data/map/gs.10.tsv b/data/map/gs.10.tsv index fdc7c662..fe83d741 100644 --- a/data/map/gs.10.tsv +++ b/data/map/gs.10.tsv @@ -470,11 +470,24 @@ ThickSaw Fat Saw Ld D-50 Fat D-50 FatLd WaspySyn WaspySynth CS SawLd CS Saw Ld +MG Saw MG SawWave +MG Saw 2 MG SawLd 2 +OB Saw OB SawWave OB Saw 2 OB SawLd 2 -P5 SawLd P5 Saw Ld +D-50 Saw D-50 SawLd +SH101Saw SH-101 Saw +CS Saw CS SawLead +MG SawLd MG SawLead +OB SawLd OB SawLead +P5 SawLd P5 SawLead MGUnison MG Unison +OctSawLd OctSawLead Seq.Saw. Seq. Saw. +Seq.Saw2 Seq.Saw. 2 Reso Saw Reso. Saw +CheezSaw Cheese Saw +ChzSaw 2 CheeseSaw2 +Rthm Saw Rhythm Saw VentLead Vent Synth Pure Pan Pure PanLd FatGR Ld Fat GR Ld diff --git a/data/map/gs.12.tsv b/data/map/gs.12.tsv index 12aa4e55..9a1e65e6 100644 --- a/data/map/gs.12.tsv +++ b/data/map/gs.12.tsv @@ -340,11 +340,24 @@ Dr. Lead Doctor Solo ThickSaw Fat Saw Lead D-50 Fat D-50 FatLead WaspySyn Waspy Synth -CS SawLd CS Saw Lead -OB Saw 2 OB SawLead 2 +CS SawLd CS Saw +MG Saw MG Saw 1 +MG Saw 2 MG Saw 2 +OB Saw OB Saw 1 +OB Saw 2 OB Saw 2 +D-50 Saw D-50 Saw +CS Saw CS Saw +MG SawLd MG Saw Lead +OB SawLd OB Saw Lead P5 SawLd P5 Saw Lead +P5 SawLd P5 Saw Lead +OctSawLd Oct Saw Lead Seq.Saw. SequencedSaw +Seq.Saw2 SequenceSaw2 Reso Saw Resonant Saw +CheezSaw Cheese Saw 1 +ChzSaw 2 Cheese Saw 2 +Rthm Saw Rhythmic Saw Pure Pan Pure PanLead FatGR Ld Fat GR Lead Acid Gtr Acid Guitar diff --git a/data/map/gs.24.tsv b/data/map/gs.24.tsv index b8b0381b..45b766e9 100644 --- a/data/map/gs.24.tsv +++ b/data/map/gs.24.tsv @@ -265,11 +265,26 @@ JP8Puls2 JP8 Pulse Lead 2 MGRezPls MG Resonant Pulse PulseSaw Pulse Sawtooth Lead Dr. Lead Doctor Lead -ThickSaw Fat Sawtooth Lead +ThickSaw Thick Sawtooth Lead D-50 Fat D-50 Fat Lead -OB Saw 2 OB Saw Lead 2 +CS SawLd CS Sawtooth Lead +MG Saw MG Sawtooth 1 +MG Saw 2 MG Sawtooth 2 +OB Saw OB Sawtooth +OB Saw 2 OB Sawtooth 2 +D-50 Saw D-50 Sawtooth +SH101Saw SH-101 Sawtooth +CS Saw CS Sawtooth Lead +MG SawLd MG Sawtooth Lead +OB SawLd OB Sawtooth Lead +P5 SawLd P5 Sawtooth Lead +OctSawLd Octave Sawtooth Lead Seq.Saw. Sequenced Sawtooth +Seq.Saw2 Sequenced Sawtooth 2 Reso Saw Resonant Sawtooth +CheezSaw Cheesy Sawtooth +ChzSaw 2 Cheesy Sawtooth 2 +Rthm Saw Rhythmic Sawtooth VentLead Vent Synth Lead Pure Pan Pure Pan Lead DistLead Distortion Lead diff --git a/dist/basic.mjs b/dist/basic.mjs index a89dc234..a3fc66c7 100644 --- a/dist/basic.mjs +++ b/dist/basic.mjs @@ -1,4 +1,4 @@ -var _=Object.create;var O=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var z=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports);var q=(t,n,c,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of V(n))!K.call(t,s)&&s!==c&&O(t,s,{get:()=>n[s],enumerable:!(e=X(n,s))||e.enumerable});return t};var Q=(t,n,c)=>(c=t!=null?_(F(t)):{},q(n||!t||!t.__esModule?O(c,"default",{value:t,enumerable:!0}):c,t));var N=z((ze,T)=>{(function(){"use strict";let t={fatal:!0},n=[new TextDecoder("iso-8859-15",t),new TextDecoder("sjis",t),new TextDecoder("euc-jp",t),new TextDecoder("utf-8",t),new TextDecoder("utf-16",t),new TextDecoder("ascii")],c={debug:!1,parse:function(e,s){if(e instanceof Uint8Array)return c.Uint8(e);if(typeof e=="string")return c.Base64(e);if(e instanceof HTMLElement&&e.type==="file")return c.addListener(e,s);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(e,s){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(e===void 0||!(e instanceof HTMLElement)||e.tagName!=="INPUT"||e.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;s=s||function(){},e.addEventListener("change",function(r){if(!r.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let o=new FileReader;o.readAsArrayBuffer(r.target.files[0]),o.onload=function(h){s(c.Uint8(new Uint8Array(h.target.result)))}})},Base64:function(e){let s=function(h){var g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(h=h.replace(/^.*?base64,/,""),h=String(h).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(h))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");h+="==".slice(2-(3&h.length));let b,u="",a,i,l=0;for(;l>16&255):i===64?String.fromCharCode(b>>16&255,b>>8&255):String.fromCharCode(b>>16&255,b>>8&255,255&b);return u}(e=String(e));var r=s.length;let o=new Uint8Array(new ArrayBuffer(r));for(let h=0;h{i[d]=this.readInt(1)});for(let p=0;p191||y>127&&y<160)throw new RangeError(`Invalid code point: ${y}`)}l=!0,console.debug(`String byte sequence in ${n[p].encoding}`)}catch(d){console.debug(`SMF string ${d}`)}return f||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let a=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)a=this.readInt(1);else{let l=[];for(;128<=this.data.getUint8(this.pointer);)l.push(this.readInt(1)-128);var i=this.readInt(1);for(let f=1;f<=l.length;f++)a+=l[l.length-f]*Math.pow(128,f);a+=i}return a}};if(s.data=new DataView(o.buffer,o.byteOffset,o.byteLength),s.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;s.readInt(4);let r={};r.formatType=s.readInt(2),r.tracks=s.readInt(2),r.track=[];var o=s.readInt(1),h=s.readInt(1);128<=o?(r.timeDivision=[],r.timeDivision[0]=o-128,r.timeDivision[1]=h):r.timeDivision=256*o+h;for(let a=1;a<=r.tracks;a++){r.track[a-1]={event:[]};var g,b=s.readInt(4);if(b===-1)break;if(b!==1297379947)return!1;s.readInt(4);let i=0,l=!1,f,p;for(;!l&&(i++,r.track[a-1].event[i-1]={},r.track[a-1].event[i-1].deltaTime=s.readIntVLV(),(f=s.readInt(1))!==-1);)if(128<=f?p=f:(f=p,s.movePointer(-1)),f===255){r.track[a-1].event[i-1].type=255,r.track[a-1].event[i-1].metaType=s.readInt(1);var u=s.readIntVLV();switch(r.track[a-1].event[i-1].metaType){case 47:case-1:l=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:r.track[a-1].event[i-1].data=s.readStr(u);break;case 33:case 89:case 81:r.track[a-1].event[i-1].data=s.readInt(u);break;case 84:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=s.readInt(1),r.track[a-1].event[i-1].data[1]=s.readInt(1),r.track[a-1].event[i-1].data[2]=s.readInt(1),r.track[a-1].event[i-1].data[3]=s.readInt(1),r.track[a-1].event[i-1].data[4]=s.readInt(1);break;case 88:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=s.readInt(1),r.track[a-1].event[i-1].data[1]=s.readInt(1),r.track[a-1].event[i-1].data[2]=s.readInt(1),r.track[a-1].event[i-1].data[3]=s.readInt(1);break;default:this.customInterpreter!==null&&(r.track[a-1].event[i-1].data=this.customInterpreter(r.track[a-1].event[i-1].metaType,s,u)),this.customInterpreter!==null&&r.track[a-1].event[i-1].data!==!1||(s.readInt(u),r.track[a-1].event[i-1].data=s.readInt(u),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((f=f.toString(16).split(""))[1]||f.unshift("0"),r.track[a-1].event[i-1].type=parseInt(f[0],16),r.track[a-1].event[i-1].channel=parseInt(f[1],16),r.track[a-1].event[i-1].type){case 15:this.customInterpreter!==null&&(r.track[a-1].event[i-1].data=this.customInterpreter(r.track[a-1].event[i-1].type,s,!1)),this.customInterpreter!==null&&r.track[a-1].event[i-1].data!==!1||(g=s.readIntVLV(),r.track[a-1].event[i-1].data=s.readInt(g),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=s.readInt(1),r.track[a-1].event[i-1].data[1]=s.readInt(1);break;case 12:case 13:r.track[a-1].event[i-1].data=s.readInt(1);break;case-1:l=!0;break;default:if(this.customInterpreter!==null&&(r.track[a-1].event[i-1].data=this.customInterpreter(r.track[a-1].event[i-1].metaType,s,!1)),this.customInterpreter===null||r.track[a-1].event[i-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return r},customInterpreter:null};if(typeof T<"u")T.exports=c;else{let e=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;e.MidiParser=c}})()});var w=class{#e={};addEventListener(t,n){this.#e[t]||(this.#e[t]=[]),this.#e[t].unshift(n)}removeEventListener(t,n){if(this.#e[t]){let c=this.#e[t].indexOf(n);c>-1&&this.#e[t].splice(c,1),this.#e[t].length<1&&delete this.#e[t]}}dispatchEvent(t,n){let c=new Event(t),e=this;c.data=n,this.#e[t]?.length>0&&this.#e[t].forEach(function(s){try{s?.call(e,c)}catch(r){console.error(r)}}),this[`on${t}`]&&this[`on${t}`](c)}};var I=class{#e={};context;set(t,n){this.#e[t]=n}has(t){return!!this.#e[t]}async read(t,n){if(!this.has(t))throw new Error(`No decoder registered for "${t}"`);return await this.#e[t].call(this.context||this,n)}};var Y=function(t,n){let c=!0;return n.forEach((e,s)=>{c=c&&t[s]==e}),c},A=function(t){let n=0;return t.forEach(c=>{n*=256,n+=c}),n},v=new TextDecoder,U=new I;U.set("s7e",async function(t){let n=new Uint8Array(await t.slice(0,65536).arrayBuffer()),c="MSB LSB PRG NME",e=[0,0,0,0],s=32,r=0,o=0,h=!0,g=[],b=0;for(;h;){let u=n.subarray(r);([()=>{v.decode(u.subarray(0,4))=="YSFC"?(r+=80,o=1):r++},()=>{if(Y(u.subarray(0,4),e))g.forEach((a,i,l)=>{let f=A(n.subarray(a.start+4,a.start+8));a.length=f}),o=2;else{let a=v.decode(u.subarray(0,4)),i=A(u.subarray(4,8));g.push({type:a,start:i}),r+=8}},()=>{let a=g[b],i=n.subarray(a.start,a.start+a.length),l=32;switch(a.type){case"ENVC":{let f=s;for(;f()=>(n||t((n={exports:{}}).exports,n),n.exports);var q=(t,n,c,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of V(n))!K.call(t,s)&&s!==c&&O(t,s,{get:()=>n[s],enumerable:!(e=X(n,s))||e.enumerable});return t};var Q=(t,n,c)=>(c=t!=null?_(F(t)):{},q(n||!t||!t.__esModule?O(c,"default",{value:t,enumerable:!0}):c,t));var N=z((ze,T)=>{(function(){"use strict";let t={fatal:!0},n=[new TextDecoder("iso-8859-15",t),new TextDecoder("sjis",t),new TextDecoder("euc-jp",t),new TextDecoder("utf-8",t),new TextDecoder("utf-16",t),new TextDecoder("ascii")],c={debug:!1,parse:function(e,s){if(e instanceof Uint8Array)return c.Uint8(e);if(typeof e=="string")return c.Base64(e);if(e instanceof HTMLElement&&e.type==="file")return c.addListener(e,s);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(e,s){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(e===void 0||!(e instanceof HTMLElement)||e.tagName!=="INPUT"||e.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;s=s||function(){},e.addEventListener("change",function(r){if(!r.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let o=new FileReader;o.readAsArrayBuffer(r.target.files[0]),o.onload=function(h){s(c.Uint8(new Uint8Array(h.target.result)))}})},Base64:function(e){let s=function(h){var g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(h=h.replace(/^.*?base64,/,""),h=String(h).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(h))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");h+="==".slice(2-(3&h.length));let b,u="",a,i,l=0;for(;l>16&255):i===64?String.fromCharCode(b>>16&255,b>>8&255):String.fromCharCode(b>>16&255,b>>8&255,255&b);return u}(e=String(e));var r=s.length;let o=new Uint8Array(new ArrayBuffer(r));for(let h=0;h{i[d]=this.readInt(1)});for(let p=0;p191||y>127&&y<160)throw new RangeError(`Invalid code point: ${y}`)}l=!0,console.debug(`String byte sequence in ${n[p].encoding}`)}catch(d){console.debug(`SMF string ${d}`)}return f||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let a=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)a=this.readInt(1);else{let l=[];for(;128<=this.data.getUint8(this.pointer);)l.push(this.readInt(1)-128);var i=this.readInt(1);for(let f=1;f<=l.length;f++)a+=l[l.length-f]*Math.pow(128,f);a+=i}return a}};if(s.data=new DataView(o.buffer,o.byteOffset,o.byteLength),s.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;s.readInt(4);let r={};r.formatType=s.readInt(2),r.tracks=s.readInt(2),r.track=[];var o=s.readInt(1),h=s.readInt(1);128<=o?(r.timeDivision=[],r.timeDivision[0]=o-128,r.timeDivision[1]=h):r.timeDivision=256*o+h;for(let a=1;a<=r.tracks;a++){r.track[a-1]={event:[]};var g,b=s.readInt(4);if(b===-1)break;if(b!==1297379947)return!1;s.readInt(4);let i=0,l=!1,f,p;for(;!l&&(i++,r.track[a-1].event[i-1]={},r.track[a-1].event[i-1].deltaTime=s.readIntVLV(),(f=s.readInt(1))!==-1);)if(128<=f?p=f:(f=p,s.movePointer(-1)),f===255){r.track[a-1].event[i-1].type=255,r.track[a-1].event[i-1].metaType=s.readInt(1);var u=s.readIntVLV();switch(r.track[a-1].event[i-1].metaType){case 47:case-1:l=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:r.track[a-1].event[i-1].data=s.readStr(u);break;case 33:case 89:case 81:r.track[a-1].event[i-1].data=s.readInt(u);break;case 84:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=s.readInt(1),r.track[a-1].event[i-1].data[1]=s.readInt(1),r.track[a-1].event[i-1].data[2]=s.readInt(1),r.track[a-1].event[i-1].data[3]=s.readInt(1),r.track[a-1].event[i-1].data[4]=s.readInt(1);break;case 88:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=s.readInt(1),r.track[a-1].event[i-1].data[1]=s.readInt(1),r.track[a-1].event[i-1].data[2]=s.readInt(1),r.track[a-1].event[i-1].data[3]=s.readInt(1);break;default:this.customInterpreter!==null&&(r.track[a-1].event[i-1].data=this.customInterpreter(r.track[a-1].event[i-1].metaType,s,u)),this.customInterpreter!==null&&r.track[a-1].event[i-1].data!==!1||(s.readInt(u),r.track[a-1].event[i-1].data=s.readInt(u),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((f=f.toString(16).split(""))[1]||f.unshift("0"),r.track[a-1].event[i-1].type=parseInt(f[0],16),r.track[a-1].event[i-1].channel=parseInt(f[1],16),r.track[a-1].event[i-1].type){case 15:this.customInterpreter!==null&&(r.track[a-1].event[i-1].data=this.customInterpreter(r.track[a-1].event[i-1].type,s,!1)),this.customInterpreter!==null&&r.track[a-1].event[i-1].data!==!1||(g=s.readIntVLV(),r.track[a-1].event[i-1].data=s.readInt(g),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:r.track[a-1].event[i-1].data=[],r.track[a-1].event[i-1].data[0]=s.readInt(1),r.track[a-1].event[i-1].data[1]=s.readInt(1);break;case 12:case 13:r.track[a-1].event[i-1].data=s.readInt(1);break;case-1:l=!0;break;default:if(this.customInterpreter!==null&&(r.track[a-1].event[i-1].data=this.customInterpreter(r.track[a-1].event[i-1].metaType,s,!1)),this.customInterpreter===null||r.track[a-1].event[i-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return r},customInterpreter:null};if(typeof T<"u")T.exports=c;else{let e=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;e.MidiParser=c}})()});var w=class{#e={};addEventListener(t,n){this.#e[t]||(this.#e[t]=[]),this.#e[t].unshift(n)}removeEventListener(t,n){if(this.#e[t]){let c=this.#e[t].indexOf(n);c>-1&&this.#e[t].splice(c,1),this.#e[t].length<1&&delete this.#e[t]}}dispatchEvent(t,n){let c=new Event(t),e=this;c.data=n,this.#e[t]?.length>0&&this.#e[t].forEach(function(s){try{s?.call(e,c)}catch(r){console.error(r)}}),this[`on${t}`]&&this[`on${t}`](c)}};var A=class{#e={};context;set(t,n){this.#e[t]=n}has(t){return!!this.#e[t]}async read(t,n){if(!this.has(t))throw new Error(`No decoder registered for "${t}"`);return await this.#e[t].call(this.context||this,n)}};var Y=function(t,n){let c=!0;return n.forEach((e,s)=>{c=c&&t[s]==e}),c},I=function(t){let n=0;return t.forEach(c=>{n*=256,n+=c}),n},v=new TextDecoder,U=new A;U.set("s7e",async function(t){let n=new Uint8Array(await t.slice(0,65536).arrayBuffer()),c="MSB LSB PRG NME",e=[0,0,0,0],s=32,r=0,o=0,h=!0,g=[],b=0;for(;h;){let u=n.subarray(r);([()=>{v.decode(u.subarray(0,4))=="YSFC"?(r+=80,o=1):r++},()=>{if(Y(u.subarray(0,4),e))g.forEach((a,i,l)=>{let f=I(n.subarray(a.start+4,a.start+8));a.length=f}),o=2;else{let a=v.decode(u.subarray(0,4)),i=I(u.subarray(4,8));g.push({type:a,start:i}),r+=8}},()=>{let a=g[b],i=n.subarray(a.start,a.start+a.length),l=32;switch(a.type){case"ENVC":{let f=s;for(;f=g.length&&(o=3,h=!1)}][o]||(()=>{h=!1}))()}return c});var j=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]);var W=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),Z={};`hi*, @@ -138,6 +138,6 @@ o,お ~, ^, _,`.split(` -`).forEach(t=>{let n=t.split(",");Z[n[0]]=n[1]});var P=function(t,n,c){let e=[],s=c==!1?n.readIntVLV():c;t==0||t==127;for(let r=0;r127)return console.debug(`Early termination: ${e}`),e.pop(),n.backOne(),n.backOne(),new Uint8Array(e)}}}return new Uint8Array(e)};var J=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"];var S=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var x=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19];var ee={};J.forEach((t,n)=>{ee[t]=n});var $={length:x.length};x.forEach((t,n)=>{$[t]=n});var L={length:S.length};S.forEach((t,n)=>{L[t]=n});var Fe={ch:128,cc:x.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:S.length,dnc:128,efx:7};var R=Q(N(),1);var B=class{#e=!1;constructor(t,n,c,e){this.#e=t,this.start=n,this.end=c,this.data=e}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#e}},C=class extends B{constructor(t,n,c){super(!0,t,n,c)}},H=class extends B{constructor(t,n){super(!1,t,t,n)}},M=class extends Array{#e=-1;constructor(){super(...arguments)}resetIndex(t){this.#e=-1}fresh(){this.sort(function(t,n){return t.start==n.start?0:(+(t.start>n.start)<<1)-1}),this.forEach(function(t,n){t.index=n})}step(t,n=!1){let c=[];if(n)for(let e=0;et);e++){if(this[e].ends.#e&&(c.push(r),s.#e=r.index)})}return c}getRange(t,n){t>n&&([t,n]=[n,t]);let c=[],e=-1,s=Math.ceil(Math.sqrt(this.length)),r=!0;for(let o=0;o=t&&(e=o):e=e<0?o:e;for(;r;)this[e]?.end=t&&c.push(this[e]):r=!1,e++;return c}};var te=0xffffffffffff,G=function(t){let n=new M,c=this,e=t.timeDivision,s=120,r=new M,o=0,h=0;r.push(new C(0,te,[120,0])),t.track.forEach(function(a){o=0,a.event.forEach(function(i){o+=i.deltaTime,i.type==255&&i?.metaType==81&&(s=6e7/i.data,r[r.length-1]&&r.push(new C(o,0xffffffffffff,[s,0])))})}),r.fresh(),r.forEach(function(a,i,l){i>0&&(l[i-1].end=a.start)});let g=120;r.forEach(function(a,i,l){i>0&&(a.end==a.start?l.splice(l.indexOf(a),1):g==a.data[0]&&(l[i-1].end=a.end,l.splice(l.indexOf(a),1)),g=a.data[0])});let b=0,u=120;return r.forEach(function(a){let i=a.start,l=i/u/e*60+b;u=a.data[0],b=l-i/u/e*60,a.data[1]=b}),console.debug("All tempo changes: ",r),s=120,o=0,h=0,t.track.forEach(function(a,i){o=0,h=0;let l=i+1;a.event.forEach(function(f,p){o+=f.deltaTime;let d=r.step(o,!0)[0];d&&(s=d.data[0],h=d.data[1]);let y={type:f.type,data:f.data,track:l,part:0};f.type>14?y.meta=f.metaType:y.part=f.channel,n.push(new H(o/s/e*60+h,y))})}),n.fresh(),self.midiEvents=n,console.debug(`Parsed a type ${t.formatType} MIDI sequence.`),n};R.default.customInterpreter=P;var m=function(t,n,c){t.addEventListener(c,e=>{n.dispatchEvent(c,e.data)})},st=class extends w{device;#e;#n={};#f=[];#a="";#c=[];#o=new Uint8ClampedArray(128);#h=new Uint8ClampedArray(128);#s=.5;#i=120;#t=4;#l=4;#r=0;#d=0;smoothingAtk=0;smoothingDcy=0;reset(){let t=this;t.dispatchEvent("reset"),t.#e?.resetIndex(),t.device.init(),t.#a="",t.#s=.5,t.#i=120,t.#t=4,t.#l=4,t.#r=0,t.#d=0,t.dispatchEvent("tempo",t.#i),t.dispatchEvent("title",t.#a)}init(){this.reset(),this.#e=void 0}async loadFile(t){this.#e=G(R.default.parse(new Uint8Array(await t.arrayBuffer())))}async loadMap(t,n){let c=this,e=0,s=0,r=0,o,h;t.split(` +`).forEach(t=>{let n=t.split(",");Z[n[0]]=n[1]});var P=function(t,n,c){let e=[],s=c==!1?n.readIntVLV():c;t==0||t==127;for(let r=0;r127)return console.debug(`Early termination: ${e}`),e.pop(),n.backOne(),n.backOne(),new Uint8Array(e)}}}return new Uint8Array(e)};var J=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"];var S=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var x=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19,14,15,20,21];var ee={};J.forEach((t,n)=>{ee[t]=n});var $={length:x.length};x.forEach((t,n)=>{$[t]=n});var L={length:S.length};S.forEach((t,n)=>{L[t]=n});var Fe={ch:128,cc:x.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:S.length,dnc:128,efx:7};var R=Q(N(),1);var B=class{#e=!1;constructor(t,n,c,e){this.#e=t,this.start=n,this.end=c,this.data=e}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#e}},C=class extends B{constructor(t,n,c){super(!0,t,n,c)}},H=class extends B{constructor(t,n){super(!1,t,t,n)}},M=class extends Array{#e=-1;constructor(){super(...arguments)}resetIndex(t){this.#e=-1}fresh(){this.sort(function(t,n){return t.start==n.start?0:(+(t.start>n.start)<<1)-1}),this.forEach(function(t,n){t.index=n})}step(t,n=!1){let c=[];if(n)for(let e=0;et);e++){if(this[e].ends.#e&&(c.push(r),s.#e=r.index)})}return c}getRange(t,n){t>n&&([t,n]=[n,t]);let c=[],e=-1,s=Math.ceil(Math.sqrt(this.length)),r=!0;for(let o=0;o=t&&(e=o):e=e<0?o:e;for(;r;)this[e]?.end=t&&c.push(this[e]):r=!1,e++;return c}};var te=0xffffffffffff,G=function(t){let n=new M,c=this,e=t.timeDivision,s=120,r=new M,o=0,h=0;r.push(new C(0,te,[120,0])),t.track.forEach(function(a){o=0,a.event.forEach(function(i){o+=i.deltaTime,i.type==255&&i?.metaType==81&&(s=6e7/i.data,r[r.length-1]&&r.push(new C(o,0xffffffffffff,[s,0])))})}),r.fresh(),r.forEach(function(a,i,l){i>0&&(l[i-1].end=a.start)});let g=120;r.forEach(function(a,i,l){i>0&&(a.end==a.start?l.splice(l.indexOf(a),1):g==a.data[0]&&(l[i-1].end=a.end,l.splice(l.indexOf(a),1)),g=a.data[0])});let b=0,u=120;return r.forEach(function(a){let i=a.start,l=i/u/e*60+b;u=a.data[0],b=l-i/u/e*60,a.data[1]=b}),console.debug("All tempo changes: ",r),s=120,o=0,h=0,t.track.forEach(function(a,i){o=0,h=0;let l=i+1;a.event.forEach(function(f,p){o+=f.deltaTime;let d=r.step(o,!0)[0];d&&(s=d.data[0],h=d.data[1]);let y={type:f.type,data:f.data,track:l,part:0};f.type>14?y.meta=f.metaType:y.part=f.channel,n.push(new H(o/s/e*60+h,y))})}),n.fresh(),self.midiEvents=n,console.debug(`Parsed a type ${t.formatType} MIDI sequence.`),n};R.default.customInterpreter=P;var m=function(t,n,c){t.addEventListener(c,e=>{n.dispatchEvent(c,e.data)})},st=class extends w{device;#e;#n={};#f=[];#a="";#c=[];#o=new Uint8ClampedArray(128);#h=new Uint8ClampedArray(128);#s=.5;#i=120;#t=4;#l=4;#r=0;#d=0;smoothingAtk=0;smoothingDcy=0;reset(){let t=this;t.dispatchEvent("reset"),t.#e?.resetIndex(),t.device.init(),t.#a="",t.#s=.5,t.#i=120,t.#t=4,t.#l=4,t.#r=0,t.#d=0,t.dispatchEvent("tempo",t.#i),t.dispatchEvent("title",t.#a)}init(){this.reset(),this.#e=void 0}async loadFile(t){this.#e=G(R.default.parse(new Uint8Array(await t.arrayBuffer())))}async loadMap(t,n){let c=this,e=0,s=0,r=0,o,h;t.split(` `).forEach((g,b)=>{if(!g)return;let u=g.split(" ");if(b){if(!r)return;let a="",i="";u.forEach((l,f)=>{switch(f){case o:{a=l;break}case h:{i=l;break}}}),!c.#n[a]||n?(c.#n[a]=i,e++):self.debugMode&&console.debug(`Voice "${i}" (${a}) seems to be in conflict with (${c.#n[a]}).`),s++}else u.forEach((a,i)=>{switch(a){case"ID":{o=i,r++;break}case"Name":{h=i,r++;break}default:console.debug(`Unknown map field: ${a}`)}})}),console.debug(`Map: ${s} total, ${e} loaded.`),c?.device.forceVoiceRefresh()}async loadEfx(t,n){let c=this,e=0,s=0,r,o,h;t.split(` `).forEach((g,b)=>{if(g)if(b){let u=0,a;g.split(" ").forEach((i,l)=>{switch(l){case r:{u|=parseInt(i,16)<<8;break}case o:{u|=parseInt(i,16);break}case h:{a=i;break}}}),!c.#f[u]||n?(c.#f[u]=a,e++):self.debugMode&&console.debug(`EFX ID 0x${u.toString(16).padStart(4,"0")} (${a}) seems to be in conflict.`),s++}else g.split(" ").forEach((u,a)=>{switch(u){case"MSB":{r=a;break}case"LSB":{o=a;break}case"Name":{h=a;break}default:console.debug(`Unknown EFX field: ${u}`)}})}),console.debug(`EFX: ${s} total, ${e} loaded.`),c.dispatchEvent("efxreverb",c.device.getEffectType(0)),c.dispatchEvent("efxchorus",c.device.getEffectType(1)),c.dispatchEvent("efxdelay",c.device.getEffectType(2)),c.dispatchEvent("efxinsert0",c.device.getEffectType(3)),c.dispatchEvent("efxinsert1",c.device.getEffectType(4)),c.dispatchEvent("efxinsert2",c.device.getEffectType(5)),c.dispatchEvent("efxinsert3",c.device.getEffectType(6))}switchMode(t,n=!1){this.device.switchMode(t,n)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(t){return this.device.getChVoice(t)}getMapped(t){return this.#n[t]||t}getEfx([t,n]){let c=t<<8|n;return this.#f[c]||`0x${c.toString(16).padStart(4,"0")}`}get noteProgress(){return this.#d/this.#s}get noteOverall(){return this.noteProgress-this.#r}get noteBar(){return Math.floor(this.noteOverall/this.#t)}get noteBeat(){let t=this.noteOverall%this.#t;return t<0&&(t+=this.#t),t}getTimeSig(){return[this.#t,this.#l]}getTempo(){return this.#i}sendCmd(t){this.device.runJson(t)}render(t){t>this.#d&&(this.#d=t);let n=this.#e?.step(t)||[],c=0,e=new Set,s=this,r=[];this.device.getStrength().forEach((p,d)=>{this.#h[d]=p}),s.device.newStrength(),n.forEach(function(p){let d=p.data;d.type==9&&(d.data[1]>0?e.add(d.part*128+d.data[0]):e.has(d.part*128+d.data[0])&&c++),p.data.type==8&&e.has(d.part*128+d.data[0])&&c++;let y=s.device.runJson(d);switch(y?.reply){case"meta":{r.push(y);break}}y?.reply&&delete y.reply}),r?.length>0&&this.dispatchEvent("meta",r);let o=this.device.getActive(),h=[],g=s.device.getPitch(),b=s.device.getCcAll(),u=s.device.getProgram(),a=s.device.getChType(),i=this.device.getStrength();i.forEach(function(p,d,y){y[d]=Math.max(s.#h[d],p);let E=y[d]-s.#o[d],D=$.length*d;if(E>=0){let k=4*.25**(b[D+$[73]]/64);s.#o[d]+=Math.ceil(E-E*s.smoothingAtk**k)}else{let k=4*.25**(b[D+$[72]]/64);s.#o[d]+=Math.floor(E-E*s.smoothingDcy**k)}});let l=0;return o.forEach(function(p,d){p&&(h[d]=s.device.getVel(d),l+=h[d].size)}),{extraPoly:c,curPoly:l,chInUse:o,chKeyPr:h,chPitch:g,chProgr:u,chContr:b,chType:a,eventCount:n.length,title:this.#a,bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:this.#o.slice(),velo:i,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce(),efxSink:this.device.getEffectSink()}}constructor(t,n=.5,c=.5){super();let e=this;e.smoothingAtk=n,e.smoothingDcy=c,e.device=t,e.addEventListener("meta",function(s){s?.data?.forEach(function(r){(e.#c[r.meta]||console.debug).call(e,r.meta,r.data)})}),m(e.device,e,"mode"),m(e.device,e,"mastervolume"),m(e.device,e,"channelactive"),m(e.device,e,"channelmin"),m(e.device,e,"channelmax"),m(e.device,e,"channelreset"),m(e.device,e,"channeltoggle"),m(e.device,e,"screen"),m(e.device,e,"metacommit"),m(e.device,e,"voice"),m(e.device,e,"pitch"),m(e.device,e,"note"),m(e.device,e,"reset"),m(e.device,e,"efxreverb"),m(e.device,e,"efxchorus"),m(e.device,e,"efxdelay"),m(e.device,e,"efxinsert0"),m(e.device,e,"efxinsert1"),m(e.device,e,"efxinsert2"),m(e.device,e,"efxinsert3"),m(e.device,e,"partefxtoggle"),e.#c[3]=function(s,r){e.#a?.length<1&&(e.#a=r,e.dispatchEvent("title",e.#a))},e.#c[81]=function(s,r){let o=e.noteProgress,h=e.#s||.5;e.#i=6e7/r,e.#s=r/1e6,e.#r+=o*(h/e.#s)-o,e.dispatchEvent("tempo",e.#i)},e.#c[88]=function(s,r){let o=e.noteProgress,h=e.noteOverall,g=e.noteBar,b=e.noteBeat,u=e.#t,a=e.#l;e.#t=r[0],e.#l=1<=u&&(u()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ye=(e,t,n,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of ze(t))!We.call(e,u)&&u!==n&&fe(e,u,{get:()=>t[u],enumerable:!(c=Ve(t,u))||c.enumerable});return e};var je=(e,t,n)=>(n=e!=null?Ke(qe(e)):{},Ye(t||!e||!e.__esModule?fe(n,"default",{value:e,enumerable:!0}):n,e));var Le=Qe((Xt,re)=>{(function(){"use strict";let e={fatal:!0},t=[new TextDecoder("iso-8859-15",e),new TextDecoder("sjis",e),new TextDecoder("euc-jp",e),new TextDecoder("utf-8",e),new TextDecoder("utf-16",e),new TextDecoder("ascii")],n={debug:!1,parse:function(c,u){if(c instanceof Uint8Array)return n.Uint8(c);if(typeof c=="string")return n.Base64(c);if(c instanceof HTMLElement&&c.type==="file")return n.addListener(c,u);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(c,u){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(c===void 0||!(c instanceof HTMLElement)||c.tagName!=="INPUT"||c.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;u=u||function(){},c.addEventListener("change",function(p){if(!p.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let h=new FileReader;h.readAsArrayBuffer(p.target.files[0]),h.onload=function(a){u(n.Uint8(new Uint8Array(a.target.result)))}})},Base64:function(c){let u=function(a){var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(a=a.replace(/^.*?base64,/,""),a=String(a).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(a))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");a+="==".slice(2-(3&a.length));let d,s="",r,l,f=0;for(;f>16&255):l===64?String.fromCharCode(d>>16&255,d>>8&255):String.fromCharCode(d>>16&255,d>>8&255,255&d);return s}(c=String(c));var p=u.length;let h=new Uint8Array(new ArrayBuffer(p));for(let a=0;a{l[y]=this.readInt(1)});for(let b=0;b191||E>127&&E<160)throw new RangeError(`Invalid code point: ${E}`)}f=!0,console.debug(`String byte sequence in ${t[b].encoding}`)}catch(y){console.debug(`SMF string ${y}`)}return o||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let r=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)r=this.readInt(1);else{let f=[];for(;128<=this.data.getUint8(this.pointer);)f.push(this.readInt(1)-128);var l=this.readInt(1);for(let o=1;o<=f.length;o++)r+=f[f.length-o]*Math.pow(128,o);r+=l}return r}};if(u.data=new DataView(h.buffer,h.byteOffset,h.byteLength),u.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;u.readInt(4);let p={};p.formatType=u.readInt(2),p.tracks=u.readInt(2),p.track=[];var h=u.readInt(1),a=u.readInt(1);128<=h?(p.timeDivision=[],p.timeDivision[0]=h-128,p.timeDivision[1]=a):p.timeDivision=256*h+a;for(let r=1;r<=p.tracks;r++){p.track[r-1]={event:[]};var i,d=u.readInt(4);if(d===-1)break;if(d!==1297379947)return!1;u.readInt(4);let l=0,f=!1,o,b;for(;!f&&(l++,p.track[r-1].event[l-1]={},p.track[r-1].event[l-1].deltaTime=u.readIntVLV(),(o=u.readInt(1))!==-1);)if(128<=o?b=o:(o=b,u.movePointer(-1)),o===255){p.track[r-1].event[l-1].type=255,p.track[r-1].event[l-1].metaType=u.readInt(1);var s=u.readIntVLV();switch(p.track[r-1].event[l-1].metaType){case 47:case-1:f=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:p.track[r-1].event[l-1].data=u.readStr(s);break;case 33:case 89:case 81:p.track[r-1].event[l-1].data=u.readInt(s);break;case 84:p.track[r-1].event[l-1].data=[],p.track[r-1].event[l-1].data[0]=u.readInt(1),p.track[r-1].event[l-1].data[1]=u.readInt(1),p.track[r-1].event[l-1].data[2]=u.readInt(1),p.track[r-1].event[l-1].data[3]=u.readInt(1),p.track[r-1].event[l-1].data[4]=u.readInt(1);break;case 88:p.track[r-1].event[l-1].data=[],p.track[r-1].event[l-1].data[0]=u.readInt(1),p.track[r-1].event[l-1].data[1]=u.readInt(1),p.track[r-1].event[l-1].data[2]=u.readInt(1),p.track[r-1].event[l-1].data[3]=u.readInt(1);break;default:this.customInterpreter!==null&&(p.track[r-1].event[l-1].data=this.customInterpreter(p.track[r-1].event[l-1].metaType,u,s)),this.customInterpreter!==null&&p.track[r-1].event[l-1].data!==!1||(u.readInt(s),p.track[r-1].event[l-1].data=u.readInt(s),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((o=o.toString(16).split(""))[1]||o.unshift("0"),p.track[r-1].event[l-1].type=parseInt(o[0],16),p.track[r-1].event[l-1].channel=parseInt(o[1],16),p.track[r-1].event[l-1].type){case 15:this.customInterpreter!==null&&(p.track[r-1].event[l-1].data=this.customInterpreter(p.track[r-1].event[l-1].type,u,!1)),this.customInterpreter!==null&&p.track[r-1].event[l-1].data!==!1||(i=u.readIntVLV(),p.track[r-1].event[l-1].data=u.readInt(i),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:p.track[r-1].event[l-1].data=[],p.track[r-1].event[l-1].data[0]=u.readInt(1),p.track[r-1].event[l-1].data[1]=u.readInt(1);break;case 12:case 13:p.track[r-1].event[l-1].data=u.readInt(1);break;case-1:f=!0;break;default:if(this.customInterpreter!==null&&(p.track[r-1].event[l-1].data=this.customInterpreter(p.track[r-1].event[l-1].metaType,u,!1)),this.customInterpreter===null||p.track[r-1].event[l-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return p},customInterpreter:null};if(typeof re<"u")re.exports=n;else{let c=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;c.MidiParser=n}})()});var he=function(e,t){let n=Math.min(e.length,t.length),c=e.slice(0,n),u=t.slice(0,n),p=0,h=0;for(;h0){let c=this.pool.length,u=1<=1&&h>=0;){if(h<=0)throw new Error("TTL reached.");if(p==c)p-=u;else{let i=he(t,this.pool[p]);switch(i){case 0:{h=0;break}case 1:{p+u<=c&&(p+=u);break}case-1:{p!=0&&(p-=u);break}default:console.warn(`Unexpected result ${i}.`)}}u=u>>1,h--}let a=!0;if(p>=this.pool.length)a=!1;else{let i=this;this.pool[p].forEach(function(d,s,r){a&&d!=t[s]&&(a=!1)}),!a&&he(t,this.pool[p])>0&&p++}return a||n?p:-1}else return n?0:-1},this.add=function(t,n){return t.data=n,this.pool.splice(this.point(t,!0),0,t),this},this.default=function(t){console.warn(`No match in "${this.name||"(unknown)"}" for "${t}". Default action not defined.`)},this.get=function(t){let n=this.point(t);if(n>-1)return this.pool[n].data;this.default(t)},this.run=function(t,...n){let c=this.point(t);c>-1?t.subarray?this.pool[c].data(t.subarray(this.pool[c].length),...n):this.pool[c].data(t.slice(this.pool[c].length),...n):this.default(t,...n)}};var V=class{#t={};addEventListener(e,t){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(t)}removeEventListener(e,t){if(this.#t[e]){let n=this.#t[e].indexOf(t);n>-1&&this.#t[e].splice(n,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,t){let n=new Event(e),c=this;n.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(u){try{u?.call(c,n)}catch(p){console.error(p)}}),this[`on${e}`]&&this[`on${e}`](n)}};var Ze=["MSB","PRG","LSB"],Y=function(e){let t=Math.floor(e/10),n=e%10;return`${t.toString(16)}${n}`},j=class{#t;strictMode=!1;get(e=0,t=0,n=0,c){let u=[e,t,n],p,h=Array.from(arguments);switch(c){case"xg":{switch(e){case 0:{n==126?h[2]=125:n==127&&(h[2]=0);break}case 16:{n==126&&(h[2]=0);break}case 32:{h[2]+=4;break}case 33:case 35:case 36:{h[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:h[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{n==126&&(h[2]=0);break}case 48:case 64:case 126:case 127:{n==126&&(h[2]=0);break}}break}case"gs":{e==0&&n<5?h[2]=0:e>125&&n<5&&n!=2&&(h[2]=e,h[0]=0);break}case"g2":case"sd":{(e>>1==40||e>95&&e<100)&&(h[2]|=16);break}case"sg":{e==8&&n==0&&(h[2]=5);break}case"s90es":{n<8?h[2]+=17:n<32?h[2]+=13:h[2]=(h[2]>>3)+19;break}case"motif":{n<8?h[2]+=28:n<32?h[2]+=13:h[2]=(h[2]>>3)+19;break}}let a=" ",i="M",d=0,s=0;switch(h[0]){case 0:{h[2]==127?i="MT-a":h[2]==126?i="MT-b":h[2]==7?i="GM-k":h[2]==5?i="SG-a":h[2]==4?i="SP-l":h[2]==0||c=="gs"&&h[2]<5?i="GM-a":(i="y",d=3);break}case 8:{c=="sg"?i="GM-s":i="r:";break}case 48:{i=`yM${(h[2]>>3).toString().padStart(2,"0")}`,d=1;break}case 56:{i="GM-b";break}case 61:case 120:{i="rDrm";break}case 62:{i="kDrm";break}case 63:{if(h[2]<17){let o=h[2];i=o<10?"kP:":"kC:",i+=o%10}else h[2]<34?i=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][h[2]-17]:i="Ds";break}case 64:{i="ySFX";break}case 67:{i="DX:S";break}case 80:case 81:case 82:case 83:{i=`Prg${"UABC"[h[0]-80]}`;break}case 88:case 89:case 90:case 91:{i=`Cmb${"UABC"[h[0]-88]}`;break}case 95:{i=`${["DR","PC"][h[2]]}-d`;break}case 96:{i=h[2]==106?"AP-a":h[2]>>4==1?"SDg":"PF",h[2]>63?s=63:h[2]>>4==1&&(s=16),d=3;break}case 97:{i=h[2]>>4==1?"SDa":"VL:",d=3,h[2]>>4==1?s=16:s=112;break}case 98:{i=h[2]>>4==1?"SDb":"SG-a",d=3,s=16;break}case 99:{i=h[2]>>4==1?"SDc":"DX",h[2]>63?s=63:h[2]>>4==1&&(s=16),d=3;break}case 100:{i="AN",h[2]>63?s=63:h[2]>>4==1&&(s=16),d=3;break}case 104:case 105:case 106:case 107:{i="SDd",s=104;break}case 121:{i=`GM-${h[2]?"":"a"}`,d=3;break}case 122:{i="lDrm";break}case 126:{i="yDrS";break}case 127:{h[2]==127?i="rDrm":i="yDrm";break}default:h[0]<48?i="r:":i="M"}i.length<4&&(i+=`${[e,n,h[0],h[2]][d]-s}`.padStart(4-i.length,"0")),c=="xg"&&(e==0?h[2]<100?i=i.replace("y0","y:"):h[2]==125&&(i="y126"):e==16&&(p=`Voice${(h[2]*128+h[1]+1).toString().padStart(3,"0")}`,a=" "));let r=[h[0],h[1],h[2]];for(;!(p?.length>=0);)p=this.#t[h[1]||0][(h[0]<<7)+h[2]],p||(this.strictMode?(p="",a="?"):this.#t[h[1]||0][h[0]<<7]?h[0]==0?(h[2]=0,a="^"):h[2]<1?(h[0]=0,a="*"):(h[2]--,a="^"):e==48?(h[0]=0,h[2]=0,a="!"):e==62?(h[1]--,a=" ",h[1]<1&&!p?.length&&(h[0]=0,a="!")):e<63?h[0]==0?(h[2]=0,a="^"):h[2]<1?(h[0]=0,a="*"):h[2]--:e==80?(p=`PrgU:${t.toString().padStart(3,"0")}`,a="!"):e==88?(p=`CmbU:${t.toString().padStart(3,"0")}`,a="!"):e==121?(p=`GM2Vox0${n}`,a="#"):e==122?(h[1]==32?h[1]==0:h[1]%=7,p=this.#t[h[1]||0][(h[0]<<7)+h[2]],p?a=" ":(p="",a="*")):h[1]==0?(p=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")}`,a="!"):h[0]==0?(h[2]=0,a="^"):h[2]>0?h[2]--:h[1]>0?(h[1]=0,a="!"):(h[0]=0,a="?"));let l=[h[0],h[1],h[2]];(c=="gs"||c=="ns5r")&&a=="^"&&(a=" "),e==127&&a=="^"&&(a=" "),a!=" "&&self.debugMode&&(p="");let f="??";switch(h[0]){case 0:{h[2]==0?f="GM":h[2]==5||h[2]==7?f="KG":h[2]<126?f="XG":h[2]==127&&(f="MT");break}case 48:{f="MU";break}case 56:{f="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{f="AI";break}case 62:case 82:case 90:{f="XD";break}case 63:{h[2]<17?f="KR":h[2]<34?f="ES":f="DS";break}case 64:case 126:{f="XG";break}case 67:case 99:{f=h[2]>>4==1?"SD":"DX";break}case 81:{f="RW";break}case 95:{f=["DR","PC"][h[2]];break}case 96:{f=h[2]==106?"AP":h[2]>>4==1?"SD":"PF";break}case 97:{f=h[2]>>4==1?"SD":"VL";break}case 98:{f=h[2]>>4==1?"SD":"SG";break}case 100:{f="AN";break}case 104:case 105:case 106:case 107:{f="SD";break}case 120:{f="GS";break}case 121:{f=h[2]?"G2":"GM";break}case 122:{f="KG";break}case 127:{f=h[2]==127?"MT":t==0?"GM":"XG";break}default:h[0]<48&&(h[0]==16&&c=="xg"?f="XG":f="GS")}return{name:p||`${Y(e||0)} ${Y(t||0)} ${Y(n||0)}`,iid:r,eid:l,sid:u,ending:a,sect:i,standard:f}}async load(e,t,n){let c=this,u=[],p=0,h=0;e.split(` -`).forEach(function(a,i){let d=a.split(" "),s=[];i==0?d.forEach(function(r,l){u[Ze.indexOf(r)]=l}):d.forEach(async function(r,l){l>2?(c.#t[s[u[1]]]=c.#t[s[u[1]]]||[],(!c.#t[s[u[1]]][(s[u[0]]<<7)+s[u[2]]]?.length||t)&&(c.#t[s[u[1]]][(s[u[0]]<<7)+s[u[2]]]=d[3],p++),h++):s.push(parseInt(d[l]))})}),t||console.debug(`Map "${n||"(internal)"}": ${h} total, ${p} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],n=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],c=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let u=n[0];u<=n[1];u++){let p=u<<7;for(let h=c[0];h<=c[1];h++){let a=p+h;for(let i=t[0];i<=t[1];i++)delete this.#t[i][a]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let t=this;e.forEach(async function(n,c){try{await fetch(`./data/bank/${n}.tsv`).then(function(u){return u.text()}).then(u=>{t.load(u,!1,n)})}catch{console.error(`Failed loading "${n}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var ue=class{#t={};context;set(e,t){this.#t[e]=t}has(e){return!!this.#t[e]}async read(e,t){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,t)}};var Je=function(e,t){let n=!0;return t.forEach((c,u)=>{n=n&&e[u]==c}),n},pe=function(e){let t=0;return e.forEach(n=>{t*=256,t+=n}),t},H=new TextDecoder,z=new ue;z.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),n="MSB LSB PRG NME",c=[0,0,0,0],u=32,p=0,h=0,a=!0,i=[],d=0;for(;a;){let s=t.subarray(p);([()=>{H.decode(s.subarray(0,4))=="YSFC"?(p+=80,h=1):p++},()=>{if(Je(s.subarray(0,4),c))i.forEach((r,l,f)=>{let o=pe(t.subarray(r.start+4,r.start+8));r.length=o}),h=2;else{let r=H.decode(s.subarray(0,4)),l=pe(s.subarray(4,8));i.push({type:r,start:l}),p+=8}},()=>{let r=i[d],l=t.subarray(r.start,r.start+r.length),f=32;switch(r.type){case"ENVC":{let o=u;for(;o=i.length&&(h=3,a=!1)}][h]||(()=>{a=!1}))()}return n});var G=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),X=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],et=[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],N=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],be=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],ge=function(e){let t=.1,n=-.3;return e>66?(t=5,n=315):e>56?(t=1,n=47):e>46&&(t=.5,n=18.5),t*e-n},me=function(e){return e>105?et[e-106]:e>100?e*1.1-100:e/10},ye=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),Z={};`hi*, +var Ve=Object.create;var fe=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var We=Object.getPrototypeOf,Qe=Object.prototype.hasOwnProperty;var Ye=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var je=(e,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of qe(t))!Qe.call(e,u)&&u!==n&&fe(e,u,{get:()=>t[u],enumerable:!(l=ze(t,u))||l.enumerable});return e};var Ze=(e,t,n)=>(n=e!=null?Ve(We(e)):{},je(t||!e||!e.__esModule?fe(n,"default",{value:e,enumerable:!0}):n,e));var Le=Ye((_t,re)=>{(function(){"use strict";let e={fatal:!0},t=[new TextDecoder("iso-8859-15",e),new TextDecoder("sjis",e),new TextDecoder("euc-jp",e),new TextDecoder("utf-8",e),new TextDecoder("utf-16",e),new TextDecoder("ascii")],n={debug:!1,parse:function(l,u){if(l instanceof Uint8Array)return n.Uint8(l);if(typeof l=="string")return n.Base64(l);if(l instanceof HTMLElement&&l.type==="file")return n.addListener(l,u);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(l,u){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(l===void 0||!(l instanceof HTMLElement)||l.tagName!=="INPUT"||l.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;u=u||function(){},l.addEventListener("change",function(p){if(!p.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let h=new FileReader;h.readAsArrayBuffer(p.target.files[0]),h.onload=function(a){u(n.Uint8(new Uint8Array(a.target.result)))}})},Base64:function(l){let u=function(a){var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(a=a.replace(/^.*?base64,/,""),a=String(a).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(a))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");a+="==".slice(2-(3&a.length));let d,s="",r,c,f=0;for(;f>16&255):c===64?String.fromCharCode(d>>16&255,d>>8&255):String.fromCharCode(d>>16&255,d>>8&255,255&d);return s}(l=String(l));var p=u.length;let h=new Uint8Array(new ArrayBuffer(p));for(let a=0;a{c[y]=this.readInt(1)});for(let b=0;b191||E>127&&E<160)throw new RangeError(`Invalid code point: ${E}`)}f=!0,console.debug(`String byte sequence in ${t[b].encoding}`)}catch(y){console.debug(`SMF string ${y}`)}return o||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let r=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)r=this.readInt(1);else{let f=[];for(;128<=this.data.getUint8(this.pointer);)f.push(this.readInt(1)-128);var c=this.readInt(1);for(let o=1;o<=f.length;o++)r+=f[f.length-o]*Math.pow(128,o);r+=c}return r}};if(u.data=new DataView(h.buffer,h.byteOffset,h.byteLength),u.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;u.readInt(4);let p={};p.formatType=u.readInt(2),p.tracks=u.readInt(2),p.track=[];var h=u.readInt(1),a=u.readInt(1);128<=h?(p.timeDivision=[],p.timeDivision[0]=h-128,p.timeDivision[1]=a):p.timeDivision=256*h+a;for(let r=1;r<=p.tracks;r++){p.track[r-1]={event:[]};var i,d=u.readInt(4);if(d===-1)break;if(d!==1297379947)return!1;u.readInt(4);let c=0,f=!1,o,b;for(;!f&&(c++,p.track[r-1].event[c-1]={},p.track[r-1].event[c-1].deltaTime=u.readIntVLV(),(o=u.readInt(1))!==-1);)if(128<=o?b=o:(o=b,u.movePointer(-1)),o===255){p.track[r-1].event[c-1].type=255,p.track[r-1].event[c-1].metaType=u.readInt(1);var s=u.readIntVLV();switch(p.track[r-1].event[c-1].metaType){case 47:case-1:f=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:p.track[r-1].event[c-1].data=u.readStr(s);break;case 33:case 89:case 81:p.track[r-1].event[c-1].data=u.readInt(s);break;case 84:p.track[r-1].event[c-1].data=[],p.track[r-1].event[c-1].data[0]=u.readInt(1),p.track[r-1].event[c-1].data[1]=u.readInt(1),p.track[r-1].event[c-1].data[2]=u.readInt(1),p.track[r-1].event[c-1].data[3]=u.readInt(1),p.track[r-1].event[c-1].data[4]=u.readInt(1);break;case 88:p.track[r-1].event[c-1].data=[],p.track[r-1].event[c-1].data[0]=u.readInt(1),p.track[r-1].event[c-1].data[1]=u.readInt(1),p.track[r-1].event[c-1].data[2]=u.readInt(1),p.track[r-1].event[c-1].data[3]=u.readInt(1);break;default:this.customInterpreter!==null&&(p.track[r-1].event[c-1].data=this.customInterpreter(p.track[r-1].event[c-1].metaType,u,s)),this.customInterpreter!==null&&p.track[r-1].event[c-1].data!==!1||(u.readInt(s),p.track[r-1].event[c-1].data=u.readInt(s),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((o=o.toString(16).split(""))[1]||o.unshift("0"),p.track[r-1].event[c-1].type=parseInt(o[0],16),p.track[r-1].event[c-1].channel=parseInt(o[1],16),p.track[r-1].event[c-1].type){case 15:this.customInterpreter!==null&&(p.track[r-1].event[c-1].data=this.customInterpreter(p.track[r-1].event[c-1].type,u,!1)),this.customInterpreter!==null&&p.track[r-1].event[c-1].data!==!1||(i=u.readIntVLV(),p.track[r-1].event[c-1].data=u.readInt(i),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:p.track[r-1].event[c-1].data=[],p.track[r-1].event[c-1].data[0]=u.readInt(1),p.track[r-1].event[c-1].data[1]=u.readInt(1);break;case 12:case 13:p.track[r-1].event[c-1].data=u.readInt(1);break;case-1:f=!0;break;default:if(this.customInterpreter!==null&&(p.track[r-1].event[c-1].data=this.customInterpreter(p.track[r-1].event[c-1].metaType,u,!1)),this.customInterpreter===null||p.track[r-1].event[c-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return p},customInterpreter:null};if(typeof re<"u")re.exports=n;else{let l=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;l.MidiParser=n}})()});var he=function(e,t){let n=Math.min(e.length,t.length),l=e.slice(0,n),u=t.slice(0,n),p=0,h=0;for(;h0){let l=this.pool.length,u=1<=1&&h>=0;){if(h<=0)throw new Error("TTL reached.");if(p==l)p-=u;else{let i=he(t,this.pool[p]);switch(i){case 0:{h=0;break}case 1:{p+u<=l&&(p+=u);break}case-1:{p!=0&&(p-=u);break}default:console.warn(`Unexpected result ${i}.`)}}u=u>>1,h--}let a=!0;if(p>=this.pool.length)a=!1;else{let i=this;this.pool[p].forEach(function(d,s,r){a&&d!=t[s]&&(a=!1)}),!a&&he(t,this.pool[p])>0&&p++}return a||n?p:-1}else return n?0:-1},this.add=function(t,n){return t.data=n,this.pool.splice(this.point(t,!0),0,t),this},this.default=function(t){console.warn(`No match in "${this.name||"(unknown)"}" for "${t}". Default action not defined.`)},this.get=function(t){let n=this.point(t);if(n>-1)return this.pool[n].data;this.default(t)},this.run=function(t,...n){let l=this.point(t);l>-1?t.subarray?this.pool[l].data(t.subarray(this.pool[l].length),...n):this.pool[l].data(t.slice(this.pool[l].length),...n):this.default(t,...n)}};var V=class{#t={};addEventListener(e,t){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(t)}removeEventListener(e,t){if(this.#t[e]){let n=this.#t[e].indexOf(t);n>-1&&this.#t[e].splice(n,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,t){let n=new Event(e),l=this;n.data=t,this.#t[e]?.length>0&&this.#t[e].forEach(function(u){try{u?.call(l,n)}catch(p){console.error(p)}}),this[`on${e}`]&&this[`on${e}`](n)}};var Je=["MSB","PRG","LSB"],Y=function(e){let t=Math.floor(e/10),n=e%10;return`${t.toString(16)}${n}`},j=class{#t;strictMode=!1;get(e=0,t=0,n=0,l){let u=[e,t,n],p,h=Array.from(arguments);switch(l){case"xg":{switch(e){case 0:{n==126?h[2]=125:n==127&&(h[2]=0);break}case 16:{n==126&&(h[2]=0);break}case 32:{n>125&&(h[2]=0),h[2]+=4;break}case 33:case 35:case 36:{n>125&&(h[2]=0),h[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:h[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{n==126&&(h[2]=0);break}case 48:case 64:case 126:case 127:{n==126&&(h[2]=0);break}}break}case"gs":{e==0&&n<5?h[2]=0:e>125&&n<5&&n!=2&&(h[2]=e,h[0]=0);break}case"g2":case"sd":{(e>>1==40||e>95&&e<100)&&(h[2]|=16);break}case"sg":{e==8&&n==0&&(h[2]=5);break}case"s90es":{n<8?h[2]+=17:n<32?h[2]+=13:h[2]=(h[2]>>3)+19;break}case"motif":{n<8?h[2]+=28:n<32?h[2]+=13:h[2]=(h[2]>>3)+19;break}}let a=" ",i="M",d=0,s=0;switch(h[0]){case 0:{h[2]==127?i="MT-a":h[2]==126?i="MT-b":h[2]==7?i="GM-k":h[2]==5?i="SG-a":h[2]==4?i="SP-l":h[2]==0||l=="gs"&&h[2]<5?i="GM-a":(i="y",d=3);break}case 8:{l=="sg"?i="GM-s":i="r:";break}case 48:{i=`yM${(h[2]>>3).toString().padStart(2,"0")}`,d=1;break}case 56:{i="GM-b";break}case 61:case 120:{i="rDrm";break}case 62:{i="kDrm";break}case 63:{if(h[2]<17){let o=h[2];i=o<10?"kP:":"kC:",i+=o%10}else h[2]<34?i=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][h[2]-17]:i="Ds";break}case 64:{i="ySFX";break}case 67:{i="DX:S";break}case 80:case 81:case 82:case 83:{i=`Prg${"UABC"[h[0]-80]}`;break}case 88:case 89:case 90:case 91:{i=`Cmb${"UABC"[h[0]-88]}`;break}case 95:{i=`${["DR","PC"][h[2]]}-d`;break}case 96:{i=h[2]==106?"AP-a":h[2]>>4==1?"SDg":"PF",h[2]>63?s=63:h[2]>>4==1&&(s=16),d=3;break}case 97:{i=h[2]>>4==1?"SDa":"VL:",d=3,h[2]>>4==1?s=16:s=112;break}case 98:{i=h[2]>>4==1?"SDb":"SG-a",d=3,s=16;break}case 99:{i=h[2]>>4==1?"SDc":"DX",h[2]>63?s=63:h[2]>>4==1&&(s=16),d=3;break}case 100:{i="AN",h[2]>63?s=63:h[2]>>4==1&&(s=16),d=3;break}case 104:case 105:case 106:case 107:{i="SDd",s=104;break}case 121:{i=`GM-${h[2]?"":"a"}`,d=3;break}case 122:{i="lDrm";break}case 126:{i="yDrS";break}case 127:{h[2]==127?i="rDrm":i="yDrm";break}default:h[0]<48?i="r:":i="M"}i.length<4&&(i+=`${[e,n,h[0],h[2]][d]-s}`.padStart(4-i.length,"0")),l=="xg"&&(e==0?h[2]<100?i=i.replace("y0","y:"):h[2]==125&&(i="y126"):e==16&&(p=`Voice${(h[2]*128+h[1]+1).toString().padStart(3,"0")}`,a=" "));let r=[h[0],h[1],h[2]];for(;!(p?.length>=0);)p=this.#t[h[1]||0][(h[0]<<7)+h[2]],p||(this.strictMode?(p="",a="?"):this.#t[h[1]||0][h[0]<<7]?h[0]==0?(h[2]=0,a="^"):h[2]<1?(h[0]=0,a="*"):(h[2]--,a="^"):e==48?(h[0]=0,h[2]=0,a="!"):e==62?(h[1]--,a=" ",h[1]<1&&!p?.length&&(h[0]=0,a="!")):e<63?h[0]==0?(h[2]=0,a="^"):h[2]<1?(h[0]=0,a="*"):h[2]--:e==80?(p=`PrgU:${t.toString().padStart(3,"0")}`,a="!"):e==88?(p=`CmbU:${t.toString().padStart(3,"0")}`,a="!"):e==121?(p=`GM2Vox0${n}`,a="#"):e==122?(h[1]==32?h[1]==0:h[1]%=7,p=this.#t[h[1]||0][(h[0]<<7)+h[2]],p?a=" ":(p="",a="*")):h[1]==0?(p=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${n.toString().padStart(3,"0")}`,a="!"):h[0]==0?(h[2]=0,a="^"):h[2]>0?h[2]--:h[1]>0?(h[1]=0,a="!"):(h[0]=0,a="?"));let c=[h[0],h[1],h[2]];(l=="gs"||l=="ns5r")&&a=="^"&&(a=" "),e==127&&a=="^"&&(a=" "),a!=" "&&self.debugMode&&(p="");let f="??";switch(h[0]){case 0:{h[2]==0?f="GM":h[2]==5||h[2]==7?f="KG":h[2]<126?f="XG":h[2]==127&&(f="MT");break}case 32:case 33:case 35:case 36:{h[2]>4?f=["AP","VL","PF","DX","AN"][h[0]-32]:f="GS";break}case 48:{f="MU";break}case 56:{f="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{f="AI";break}case 62:case 82:case 90:{f="XD";break}case 63:{h[2]<17?f="KR":h[2]<34?f="ES":f="DS";break}case 64:case 126:{f="XG";break}case 67:case 99:{f=h[2]>>4==1?"SD":"DX";break}case 81:{f="RW";break}case 95:{f=["DR","PC"][h[2]];break}case 96:{f=h[2]==106?"AP":h[2]>>4==1?"SD":"PF";break}case 97:{f=h[2]>>4==1?"SD":"VL";break}case 98:{f=h[2]>>4==1?"SD":"SG";break}case 100:{f="AN";break}case 104:case 105:case 106:case 107:{f="SD";break}case 120:{f="GS";break}case 121:{f=h[2]?"G2":"GM";break}case 122:{f="KG";break}case 127:{f=h[2]==127?"MT":t==0?"GM":"XG";break}default:h[0]<48&&(h[0]==16&&l=="xg"?f="XG":f="GS")}return{name:p||`${Y(e||0)} ${Y(t||0)} ${Y(n||0)}`,iid:r,eid:c,sid:u,ending:a,sect:i,standard:f}}async load(e,t,n){let l=this,u=[],p=0,h=0;e.split(` +`).forEach(function(a,i){let d=a.split(" "),s=[];i==0?d.forEach(function(r,c){u[Je.indexOf(r)]=c}):d.forEach(async function(r,c){c>2?(l.#t[s[u[1]]]=l.#t[s[u[1]]]||[],(!l.#t[s[u[1]]][(s[u[0]]<<7)+s[u[2]]]?.length||t)&&(l.#t[s[u[1]]][(s[u[0]]<<7)+s[u[2]]]=d[3],p++),h++):s.push(parseInt(d[c]))})}),t||console.debug(`Map "${n||"(internal)"}": ${h} total, ${p} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],n=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],l=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let u=n[0];u<=n[1];u++){let p=u<<7;for(let h=l[0];h<=l[1];h++){let a=p+h;for(let i=t[0];i<=t[1];i++)delete this.#t[i][a]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let t=this;e.forEach(async function(n,l){try{await fetch(`./data/bank/${n}.tsv`).then(function(u){return u.text()}).then(u=>{t.load(u,!1,n)})}catch{console.error(`Failed loading "${n}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var ue=class{#t={};context;set(e,t){this.#t[e]=t}has(e){return!!this.#t[e]}async read(e,t){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,t)}};var et=function(e,t){let n=!0;return t.forEach((l,u)=>{n=n&&e[u]==l}),n},pe=function(e){let t=0;return e.forEach(n=>{t*=256,t+=n}),t},H=new TextDecoder,z=new ue;z.set("s7e",async function(e){let t=new Uint8Array(await e.slice(0,65536).arrayBuffer()),n="MSB LSB PRG NME",l=[0,0,0,0],u=32,p=0,h=0,a=!0,i=[],d=0;for(;a;){let s=t.subarray(p);([()=>{H.decode(s.subarray(0,4))=="YSFC"?(p+=80,h=1):p++},()=>{if(et(s.subarray(0,4),l))i.forEach((r,c,f)=>{let o=pe(t.subarray(r.start+4,r.start+8));r.length=o}),h=2;else{let r=H.decode(s.subarray(0,4)),c=pe(s.subarray(4,8));i.push({type:r,start:c}),p+=8}},()=>{let r=i[d],c=t.subarray(r.start,r.start+r.length),f=32;switch(r.type){case"ENVC":{let o=u;for(;o=i.length&&(h=3,a=!1)}][h]||(()=>{a=!1}))()}return n});var G=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),X=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],tt=[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],N=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],be=[0,.04,.08,.13,.17,.21,.25,.29,.34,.38,.42,.46,.51,.55,.59,.63,.67,.72,.76,.8,.84,.88,.93,.97,1.01,1.05,1.09,1.14,1.18,1.22,1.26,1.3,1.35,1.39,1.43,1.47,1.51,1.56,1.6,1.64,1.68,1.72,1.77,1.81,1.85,1.89,1.94,1.98,2.02,2.06,2.1,2.15,2.19,2.23,2.27,2.31,2.36,2.4,2.44,2.48,2.52,2.57,2.61,2.65,2.69,2.78,2.86,2.94,3.03,3.11,3.2,3.28,3.37,3.45,3.53,3.62,3.7,3.87,4.04,4.21,4,37,4.54,4.71,4.88,5.05,5.22,5.38,5.55,5.72,6.06,6.39,6.73,7.07,7.4,7.74,8.08,8.41,8.75,9.08,9.42,9.76,10.1,10.8,11.4,12.1,12.8,13.5,14.1,14.8,15.5,16.2,16.8,17.5,18.2,19.5,20.9,22.2,23.6,24.9,26.2,27.6,28.9,30.3,31.6,33,34.3,37,39.7],ge=function(e){let t=.1,n=-.3;return e>66?(t=5,n=315):e>56?(t=1,n=47):e>46&&(t=.5,n=18.5),t*e-n},me=function(e){return e>105?tt[e-106]:e>100?e*1.1-100:e/10},ye=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),Z={};`hi*, ka,か ki,き ku,く @@ -139,8 +139,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let t=e.split(",");Z[t[0]]=t[1]});var ve=function(e){let t=e;e[0]=="*"&&(t=t.slice(1)),["aa","ii","uu","ee","oo"].forEach(c=>{for(;t.indexOf(c)>-1;)t=t.replace(c,c[0])});for(let c in Z)t=t.replaceAll(c,Z[c]);t.indexOf("ん")==0&&t.length>1&&(t=t.slice(1));let n=t.indexOf("!");return n>-1&&t.length>1&&(t=t.slice(n+1)),t},Ee=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var J=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],we=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],$e=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var tt={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"},at={66307:["drive"],66309:["vowel",e=>"aiueo"[e]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",e=>["off","LPF","HPF"][e]],94984:["noise type",e=>["white","pink"][e]],94987:["disc type",e=>["LP","SP","EP","RND"]],94990:["hum type",e=>`${e+5}0Hz`],94993:["M/S",e=>["mono","stereo"][e]]},ee=function(e){return tt[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ke=function(e,t,n){let c=(e[0]-32<<16)+(e[1]<<8)+t,u=at[c]||{},p=u[0];if(p?.length)return p+=`: ${(u[1]||function(){})(n)||n}`,p},te=[68,48,95,78,41,3,110,122,0];var C=function(e=64){return Math.round(2e3*Math.log10(e/64))/100},xe=function(e,t,n){let c=[],u=n==!1?t.readIntVLV():n;e==0||e==127;for(let p=0;p127)return console.debug(`Early termination: ${c}`),c.pop(),t.backOne(),t.backOne(),new Uint8Array(c)}}}return new Uint8Array(c)},ae=function(e){let t=0;return e.forEach(n=>{t+=n,t=t&127}),~t+1&127},O=function(e,t){let n=0,c=0;for(let u=0;u>p&1)<<7,a=e[u];a+=h,u%8!=0?(t(a,n,e),n++):c=e[u]}},_=function(e){let t=Math.floor(e*14.2);return t<128?t:0};var A=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],Se=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],I=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],rt=[0,3,81,84,88],Te={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Ce={0:0,1:1,2:3,5:4},Me={0:0,1:1,2:2,5:3},Re=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],De=[36,37,48,49,52,53],q=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Oe={26:127,29:0,30:0,31:0,52:12,53:54},F=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19],it=[12,13,16,17,18,19],st=[33,99,100,32,102,8,9,10],Pe=[0,16,25,40,32,64,26,48],w={};A.forEach((e,t)=>{w[e]=t});var g={length:F.length};F.forEach((e,t)=>{g[e]=t});var R={length:q.length};q.forEach((e,t)=>{R[e]=t});var k=function(){return!!self.Bun||self.debugMode||!1},nt=function(e){let t=[],n=0;return e?.forEach(function(c,u){c==247?t.push(e.subarray(n,u)):c==240&&(n=u+1)}),t.length||t.push(e.subarray(0)),k()&&console.debug(t),t};var m={ch:128,cc:F.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:q.length,dnc:128,efx:7},Ae=class extends V{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#u=0;#w=0;#o=new Array(11);get#y(){return this.#o[this.#u]}set#y(e){this.#o[this.#u]=e}#$=new Uint8Array(m.ch);#p=new Uint8Array(m.ch);#i=new Uint8Array(m.ch);#e=new Uint8Array(m.ch*m.cc);#d=new Uint8Array(m.ace);#n=new Uint8Array(m.ch);#c=new Uint8Array(m.ch*m.nn);#b=new Uint8Array(m.ch);#g=new Uint16Array(m.pl);#E=new Uint8Array(m.pl);#R=new Int16Array(m.ch);#S=new Uint8Array(m.ch);#G=0;#r=new Uint8Array(m.ch*m.rpn);#s=new Uint8Array(m.ch*m.rpnt);#X=new Int8Array(m.ch*De.length);#a=new Uint8Array(m.drm*m.dpn*m.dnc);#v=new Uint8Array(m.ch);#l=new Uint8Array(128);#h=new Uint8Array(m.cmt*8);#T=new Uint8Array(1024);#O=new Uint8Array(m.cmt*64);#x=new Uint8Array(m.efx*3);#P=new Uint8Array(m.ch);#I=0;#C=0;#f=100;#_=0;#U=500;#z=0;#N="";#B=0;#F=0;#ee=0;#H=!0;#m=!1;#te;#ie=new Uint8Array(2);#D=[];#K=new Uint8Array(m.ch);#q=new Uint8Array(m.tr);baseBank=new j("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es");userBank=new j("gm");initOnReset=!1;aiEfxName="";chRedir(e,t,n){if(this.#q[t])return(this.#q[t]-1)*16+e;if([2,3].indexOf(this.#C)>-1){if(n==1)return e;let c=0,u=!0;for(;u;)this.#K[e+c]==0?(this.#K[e+c]=t,console.debug(`Assign track ${t} to channel ${e+c+1}.`),u=!1):this.#K[e+c]==t?u=!1:(c+=16,c>=128&&(c=0,u=!1));return e+c}else return e}forceVoiceRefresh(){for(let e=0;e{let n=e*128+t,c=this.#g.lastIndexOf(n);c>-1&&(this.#e[m.cc*e+g[64]]>63?(this.#E[c]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#c[n],state:this.NOTE_HELD})):this.#e[m.cc*e+g[66]]>63&&this.#E[c]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#E[c]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#c[n],state:this.NOTE_SOSTENUTO_HELD})):(this.#g[c]=0,this.#c[n]=0,this.#E[c]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:t,velo:0,state:this.NOTE_IDLE})))},nOn:(e,t,n)=>{let c=e*128+t,u=0;for(this.#b[e]&&this.#k.ano(e);this.#E[u]>0&&this.#g[u]!=c;)u++;u{},cAt:(e,t)=>{},hoOf:e=>{this.#E.forEach((t,n)=>{if(t==this.NOTE_HELD){let c=this.#g[n],u=c>>7;e==u&&(this.#E[n]=this.NOTE_IDLE,this.#g[n]=0,this.#c[c]=0,this.dispatchEvent("note",{part:e,note:c&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#E.forEach((t,n)=>{let c;switch(t){case this.NOTE_ATTACK:{c=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{c=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{c=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(c){this.#E[n]=c;let u=this.#g[n];this.dispatchEvent("note",{part:e,note:u&127,velo:this.#c[u],state:c})}})},soOf:e=>{this.#E.forEach((t,n)=>{if(t==this.NOTE_SOSTENUTO_HELD){let c=this.#g[n],u=c>>7;e==u&&(this.#E[n]=this.NOTE_IDLE,this.#g[n]=0,this.#c[c]=0,this.dispatchEvent("note",{part:e,note:c&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#g.forEach((t,n,c)=>{let u=t>>7,p=t&127;t==0&&this.#c[0]==0||u==e&&this.#k.nOff(u,p)})}};#ae={8:function(e){let t=e.channel,n=e.data[0];this.#k.nOff(t,n)},9:function(e){let t=e.channel;this.setChActive(t,1);let n=e.data[0],c=e.data[1];c>0?this.#k.nOn(t,n,c):this.#k.nOff(t,n)},10:function(e){let t=e.channel,n=t*128+e.data[0];this.#g.indexOf(n)>-1&&(this.#c[n]=data[1],this.dispatchEvent("note",{part:t,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let t=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case w.s90es:case w.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(t,1);break}e.data[1]&&this.setChActive(t,1);break}default:{this.setChActive(t,1);break}}})();let n=t*m.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#k.ano(t),this.#R[t]=0;let c=t*m.cc;this.#e[c+g[1]]=0,this.#e[c+g[5]]=0,this.#e[c+g[64]]=0,this.#e[c+g[65]]=0,this.#e[c+g[66]]=0,this.#e[c+g[67]]=0,this.#e[c+g[11]]=127,this.#e[c+g[101]]=127,this.#e[c+g[100]]=127,this.#e[c+g[99]]=127,this.#e[c+g[98]]=127;return}case 123:{this.#k.ano(t);return}case 124:{this.#k.ano(t);return}case 125:{this.#k.ano(t);return}case 126:{this.#b[t]=1,this.#k.ano(t);return}case 127:{this.#b[t]=0,this.#k.ano(t);return}}if(g[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(it.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(k()&&console.debug(`${A[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#i[t]>0&&(e.data[1]=this.#e[n],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==w.gs?e.data[1]<56&&this.#i[t]>0&&(e.data[1]=this.#e[n],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)):this.#t==w.gm?e.data[1]<48?this.#i[t]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${t+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):this.#t==w.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),this.#t){case w.xg:{[126,127].indexOf(e.data[1])>-1?this.#i[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case w["05rw"]:case w.x5d:case w.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#i[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case w.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#i[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case w.g2:{e.data[1]==120?this.#i[t]==0&&(this.setChType(t,this.CH_DRUMS),console.debug(`CH${t+1} set to drums by MSB.`)):this.#i[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:t});break}case 6:{if(this.#G){[w.xg,w.gs,w.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${A[this.#t]}" mode, even when they are supported in Octavia.`);let c=this.#e[n+g[99]],u=this.#e[n+g[98]];if(c==1){let p=st.indexOf(u);if(p>-1)this.#e[n+g[71+p]]=e.data[1],k()&&console.debug(`Redirected NRPN 1 ${u} to cc${71+p}.`),this.dispatchEvent("cc",{part:t,cc:71+p,data:e.data[1]});else{let h=De.indexOf(u);h>-1?this.#X[t*10+h]=e.data[1]-64:console.warn(`NRPN 0x01${u.toString(16).padStart(2,"0")} is not supported.`),k()&&console.debug(`CH${t+1} voice NRPN ${u} commit`)}}else{if(q.indexOf(c)<0){let h=`NRPN 0x${c.toString(16).padStart(2,"0")}${u.toString(16).padStart(2,"0")} `;c==127?console.warn(`${h}is not necessary. Consider removing it.`):console.warn(`${h}is not supported.`)}else{let h=this.#i[t]-2;h<0?console.warn(`CH${t+1} cannot accept drum NRPN as type ${X[this.#i[t]]}.`):this.#a[(h*m.dpn+R[c])*m.dnc+u]=e.data[1]}k()&&console.debug(`CH${t+1} (${X[this.#i[t]]}) drum NRPN ${c} commit`)}}else{let c=Ce[this.#e[n+g[100]]],u=Me[this.#e[n+g[100]]];this.#e[n+g[101]]==0&&c!=null&&(k()&&console.debug(`CH${t+1} RPN 0 ${this.#e[n+g[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Re[c][0]),Re[c][1]),this.#r[t*m.rpn+c]=e.data[1],this.#s[t*m.rpnt+u]=1)}break}case 32:{switch(k()&&console.debug(`${A[this.#t]}, CH${t+1} LSB: ${e.data[1]}`),this.#t){case w.s90es:case w.motif:{this.setChType(t,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.dispatchEvent("voice",{part:t});break}case 38:{if(!this.#G){let c=Ce[this.#e[n+100]],u=Me[this.#e[n+100]];this.#e[n+101]==0&&c!=null&&(this.#r[t*m.rpn+c+1]=e.data[1],this.#s[t*m.rpnt+u]=1)}break}case 64:{e.data[1]<64&&this.#k.hoOf(t);break}case 66:{e.data[1]>>6?this.#k.soOn(t):this.#k.soOf(t);break}case 98:case 99:{this.#G=1;break}case 100:case 101:{this.#G=0;break}}this.#e[n+g[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:t,cc:e.data[0],data:e.data[1]})}},12:function(e){let t=e.channel;switch(this.#t){case w.s90es:case w.motif:{e.data&&this.setChActive(t,1);break}default:this.setChActive(t,1)}this.#n[t]=e.data,this.#v[t]=0,k()&&console.debug(`T:${e.track} C:${t} P:${e.data}`),this.dispatchEvent("voice",{part:t})},13:function(e){let t=this,n=e.channel;this.#g.forEach(function(c){let u=c>>7;n==u&&(t.#c[c]=e.data,t.dispatchEvent("note",{part:n,note:c&127,velo:e.data,state:t.NOTE_SUSTAIN}))})},14:function(e){let t=e.channel;this.#R[t]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)})},15:function(e){nt(e.data).forEach(t=>{let n=t[0],c=t[1];(this.#re[n]||function(){console.debug(`Unknown manufacturer ${n}.`)})(c,t.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#M[e.meta]||function(n,c,u){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#_=0);let t=rt.indexOf(e.meta)>-1;if(k()&&console.debug(e),t)return e.reply="meta",e}};#re={64:(e,t,n)=>{this.#j.run(t,n,e)},65:(e,t,n)=>{if(t[0]<16)if(t[1]==72){let c=t[t.length-1],u=ae(t.subarray(3,t.length-1));c==u?this.#L.run(t.subarray(0,t.length-1),n,e):console.warn(`Bad SD checksum ${c}. Should be ${u}.`)}else this.#L.run(t,n,e);else{let c=t[t.length-1],u=ae(t.subarray(2,t.length-1));c==u?this.#L.run(t.subarray(0,t.length-1),n,e):console.warn(`Bad GS checksum ${c}. Should be ${u}.`)}},66:(e,t,n)=>{this.#V.run(t,n,e)},67:(e,t,n)=>{this.#A.run(t,n,e)},68:(e,t,n)=>{this.#J.run(t,n,e)},71:(e,t,n)=>{this.#Z.run(t,n,e)},126:(e,t,n)=>{this.#Q.run(t,n,e)},127:(e,t,n)=>{this.switchMode("gm"),this.#Y.run(t,n,e)}};#Q;#Y;#A;#L;#V;#j;#Z;#J;buildRchTree(){let e=[];this.#p.forEach((t,n)=>{t0&&!c&&(this.#e[e*m.cc+g[0]]=I[n])}setChActive(e,t=0){this.#$[e]!=t&&this.dispatchEvent("channeltoggle",{part:e,active:t}),this.#$[e]=t}getPitch(){return this.#R}getProgram(){return this.#n}getTexts(){return this.#D.slice()}getVel(e){let t=new Map,n=this;return n.#g.forEach(function(c,u){let p=Math.floor(c/128),h=c%128;e==p&&n.#c[c]>0&&t.set(h,{v:n.#c[c],s:n.#E[u]})}),t}getBitmap(){return{bitmap:this.#y,expire:this.#w}}getLetter(){return{text:this.#N,set:this.#F,expire:this.#B}}getMode(){return A[this.#t]}getMaster(){return{volume:this.#f}}getRawStrength(){let e=this;return this.#g.forEach(function(t){let n=Math.floor(t/128);e.#c[t]>e.#S[n]&&(e.#S[n]=e.#c[t])}),this.#S}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(n,c){e[c]=Math.floor(n*t.#e[c*m.cc+g[7]]*t.#e[c*m.cc+g[11]]*t.#f/803288)}),e}getRpn(){return this.#r}getNrpn(){return this.#X}getVoice(e,t,n,c){let u=e||this.#I,p=t,h=n||this.#C;A[this.#t]=="ns5r"&&u>0&&u<56&&(h=3);let a=this.userBank.get(u,p,h,c);if(A[this.#t]=="mt32"&&a.name.indexOf("MT-m:")==0){let i=parseInt(a.name.slice(5)),d=i*m.cmt,s="";this.#O.subarray(d,d+10).forEach(r=>{r>31&&(s+=String.fromCharCode(r))}),this.userBank.load(`MSB LSB PRG -0 127 ${p} ${s}`,!0),a.name=s,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(u,p,h,c)),a}getChVoice(e){let t=this.getVoice(this.#e[e*m.cc+g[0]],this.#n[e],this.#e[e*m.cc+g[32]],A[this.#t]);if(this.#v[e])switch(this.#t){case w.mt32:t.ending="~",t.name="",this.#h.subarray(14*(e-1),14*(e-1)+10).forEach(n=>{n>31&&(t.name+=String.fromCharCode(n))})}return t}getPitchShift(e){let t=this,n=e*m.rpn,c=t.#r[n];return t.#s[e*m.rpnt]||t.#t==w.mt32&&(c=12),t.#R[e]/8192*c+(t.#r[n+3]-64)+((t.#r[n+1]<<7)+t.#r[n+2]-8192)/8192}getEffectType(e=0){let t=3*e+1;return this.#x.subarray(t,t+2)}setEffectTypeRaw(e=0,t,n){let c=3*e;this.#x[c]=1,this.#x[c+1+ +t]=n}setEffectType(e=0,t,n){this.setEffectTypeRaw(e,!1,t),this.setEffectTypeRaw(e,!0,n)}getEffectSink(){return this.#P}setLetterDisplay(e,t,n=0,c=3200){let u=this,p;u.#N=" ".repeat(n),e.forEach(h=>{u.#N+=String.fromCharCode(h>31?h:32),h<32&&(p=p||new Set,p.add(h))}),u.#F=Date.now(),u.#B=Date.now()+c,p&&(p=Array.from(p),p.forEach((h,a,i)=>{i[a]=h.toString(16).padStart(2,"0")}),console.warn(`${t}${t?" ":""}invalid code point${p.length>1?"s":""}: 0x${p.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let t=!0,n=0;for(;t&&n=m.ace&&console.warn("ACE slots are full.")}getAce(){return this.#d}getChAce(e,t){if(t<0||t>=m.ace)throw new RangeError("No such ACE slot");let n=this.#d[t];if(n){if(F.indexOf(n)>=0)return this.#e[e*m.cc+g[n]];throw new Error(`Invalid ACE source: ${n}`)}else return 0}initDrums(){let e=this;e.#a.fill(64);for(let t=0;t-1){if(n.#t==0||t){let u=n.#t;n.initOnReset&&t&&(this.init(1),u=w["?"]),n.#t=c,n.#u=0,n.#I=Se[0][c],n.#C=Se[1][c];for(let h=0;h0&&n.#e[h*m.cc+g[0]]==I[u]&&(n.#e[h*m.cc]=I[c]);switch(c){case w.mt32:{te.forEach((h,a)=>{let i=a+1;n.#$[i]||(n.#n[i]=h,n.#e[i*m.cc+g[91]]=127)});for(let h=1;h<10;h++)n.dispatchEvent("voice",{part:h});break}}let p;switch(c){case w["?"]:case w.xg:{p=[1,0,65,0,5,0,0,0];break}case w.gm:case w.gs:case w.g2:case w.sd:{p=[40,4,40,18,40,32,32,0];break}case w["05rw"]:case w.x5d:case w.ns5r:{p=[44,1,44,19,44,0,44,0];break}case w.k11:case w.sg:{p=[24,0,0,0,0,0,0,0];break}case w.mt32:{p=[40,4,0,0,0,0,0,0];break}default:p=[0,0,0,0,0,0,0,0]}for(let h=0;h<4;h++)n.#x[3*h]||(n.#x[3*h+1]=p[2*h],n.#x[3*h+2]=p[2*h+1],n.dispatchEvent(`efx${["reverb","chorus","delay","insert"][h]}`,n.getEffectType(h)));n.dispatchEvent("mode",e),n.forceVoiceRefresh()}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#S.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#ae[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),n=!1;this.#te[t]?.forEach(c=>{e.channel=c,n=!0,this.#ae[e.type].call(this,e)}),n||console.warn(`${Te[e.type]?Te[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${t+1} without any recipient.`)}this.#D.length>100&&this.#D.splice(100,this.#D.length-99)}runRaw(e){}async loadBank(e,t){let n=this;switch(e=e.toLowerCase(),e){case"s7e":{n.userBank.clearRange({msb:63,lsb:[21,22]}),n.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{z.context=this,n.userBank.load(await z.read(e,t));break}}n.forceVoiceRefresh()}constructor(){super();let e=this;this.#y=new Uint8Array(256),this.#o[10]=new Uint8Array(512),this.#W=new D,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let t=e.split(",");Z[t[0]]=t[1]});var ve=function(e){let t=e;e[0]=="*"&&(t=t.slice(1)),["aa","ii","uu","ee","oo"].forEach(l=>{for(;t.indexOf(l)>-1;)t=t.replace(l,l[0])});for(let l in Z)t=t.replaceAll(l,Z[l]);t.indexOf("ん")==0&&t.length>1&&(t=t.slice(1));let n=t.indexOf("!");return n>-1&&t.length>1&&(t=t.slice(n+1)),t},Ee=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var J=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],we=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],$e=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var at={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},rt={66307:["drive"],66309:["vowel",e=>"aiueo"[e]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",e=>["off","LPF","HPF"][e]],94984:["noise type",e=>["white","pink"][e]],94987:["disc type",e=>["LP","SP","EP","RND"]],94990:["hum type",e=>`${e+5}0Hz`],94993:["M/S",e=>["mono","stereo"][e]]},ee=function(e){return at[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},ke=function(e,t,n){let l=(e[0]-32<<16)+(e[1]<<8)+t,u=rt[l]||{},p=u[0];if(p?.length)return p+=`: ${(u[1]||function(){})(n)||n}`,p},te=[68,48,95,78,41,3,110,122,0];var C=function(e=64){return Math.round(2e3*Math.log10(e/64))/100},xe=function(e,t,n){let l=[],u=n==!1?t.readIntVLV():n;e==0||e==127;for(let p=0;p127)return console.debug(`Early termination: ${l}`),l.pop(),t.backOne(),t.backOne(),new Uint8Array(l)}}}return new Uint8Array(l)},ae=function(e){let t=0;return e.forEach(n=>{t+=n,t=t&127}),~t+1&127},O=function(e,t){let n=0,l=0;for(let u=0;u>p&1)<<7,a=e[u];a+=h,u%8!=0?(t(a,n,e),n++):l=e[u]}},_=function(e){let t=Math.floor(e*14.2);return t<128?t:0};var A=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],Se=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],I=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],it=[0,3,81,84,88],Te={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Ce={0:0,1:1,2:3,5:4},Me={0:0,1:1,2:2,5:3},Re=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],De=[36,37,48,49,52,53],q=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Oe={26:127,29:0,30:0,31:0,52:12,53:54},F=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19,14,15,20,21],st=[12,13,14,15,16,17,18,19,20,21],nt=[33,99,100,32,102,8,9,10],Pe=[0,16,25,40,32,64,26,48],w={};A.forEach((e,t)=>{w[e]=t});var g={length:F.length};F.forEach((e,t)=>{g[e]=t});var R={length:q.length};q.forEach((e,t)=>{R[e]=t});var k=function(){return!!self.Bun||self.debugMode||!1},ct=function(e){let t=[],n=0;return e?.forEach(function(l,u){l==247?t.push(e.subarray(n,u)):l==240&&(n=u+1)}),t.length||t.push(e.subarray(0)),k()&&console.debug(t),t};var m={ch:128,cc:F.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:q.length,dnc:128,efx:7},Ae=class extends V{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#h=0;#E=0;#o=new Array(11);get#m(){return this.#o[this.#h]}set#m(e){this.#o[this.#h]=e}#w=new Uint8Array(m.ch);#u=new Uint8Array(m.ch);#s=new Uint8Array(m.ch);#e=new Uint8Array(m.ch*m.cc);#d=new Uint8Array(m.ace);#n=new Uint8Array(m.ch);#l=new Uint8Array(m.ch*m.nn);#p=new Uint8Array(m.ch);#b=new Uint16Array(m.pl);#v=new Uint8Array(m.pl);#D=new Int16Array(m.ch);#C=new Uint8Array(m.ch);#H=0;#r=new Uint8Array(m.ch*m.rpn);#i=new Uint8Array(m.ch*m.rpnt);#I=new Int8Array(m.ch*De.length);#x=new Uint8Array(m.drm*m.dpn*m.dnc);#a=new Uint8Array(m.ch);#$=new Uint8Array(128);#c=new Uint8Array(m.cmt*8);#y=new Uint8Array(1024);#S=new Uint8Array(m.cmt*64);#T=new Uint8Array(m.efx*3);#G=new Uint8Array(m.ch);#O=0;#M=0;#f=100;#X=0;#z=500;#U=0;#_="";#N=0;#q=0;#F=0;#B=!0;#g=!1;#te;#ie=new Uint8Array(2);#P=[];#K=new Uint8Array(m.ch);#W=new Uint8Array(m.tr);baseBank=new j("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es");userBank=new j("gm");initOnReset=!1;aiEfxName="";chRedir(e,t,n){if(this.#W[t])return(this.#W[t]-1)*16+e;if([2,3].indexOf(this.#M)>-1){if(n==1)return e;let l=0,u=!0;for(;u;)this.#K[e+l]==0?(this.#K[e+l]=t,console.debug(`Assign track ${t} to channel ${e+l+1}.`),u=!1):this.#K[e+l]==t?u=!1:(l+=16,l>=128&&(l=0,u=!1));return e+l}else return e}forceVoiceRefresh(){for(let e=0;e{let n=e*128+t,l=this.#b.lastIndexOf(n);l>-1&&(this.#e[m.cc*e+g[64]]>63?(this.#v[l]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#l[n],state:this.NOTE_HELD})):this.#e[m.cc*e+g[66]]>63&&this.#v[l]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#v[l]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:t,velo:this.#l[n],state:this.NOTE_SOSTENUTO_HELD})):(this.#b[l]=0,this.#l[n]=0,this.#v[l]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:t,velo:0,state:this.NOTE_IDLE})))},nOn:(e,t,n)=>{let l=e*128+t,u=0;for(this.#p[e]&&this.#k.ano(e);this.#v[u]>0&&this.#b[u]!=l;)u++;u{},cAt:(e,t)=>{},hoOf:e=>{this.#v.forEach((t,n)=>{if(t==this.NOTE_HELD){let l=this.#b[n],u=l>>7;e==u&&(this.#v[n]=this.NOTE_IDLE,this.#b[n]=0,this.#l[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#v.forEach((t,n)=>{let l;switch(t){case this.NOTE_ATTACK:{l=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{l=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{l=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(l){this.#v[n]=l;let u=this.#b[n];this.dispatchEvent("note",{part:e,note:u&127,velo:this.#l[u],state:l})}})},soOf:e=>{this.#v.forEach((t,n)=>{if(t==this.NOTE_SOSTENUTO_HELD){let l=this.#b[n],u=l>>7;e==u&&(this.#v[n]=this.NOTE_IDLE,this.#b[n]=0,this.#l[l]=0,this.dispatchEvent("note",{part:e,note:l&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#b.forEach((t,n,l)=>{let u=t>>7,p=t&127;t==0&&this.#l[0]==0||u==e&&this.#k.nOff(u,p)})}};#ae={8:function(e){let t=e.channel,n=e.data[0];this.#k.nOff(t,n)},9:function(e){let t=e.channel;this.setChActive(t,1);let n=e.data[0],l=e.data[1];l>0?this.#k.nOn(t,n,l):this.#k.nOff(t,n)},10:function(e){let t=e.channel,n=t*128+e.data[0];this.#b.indexOf(n)>-1&&(this.#l[n]=data[1],this.dispatchEvent("note",{part:t,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let t=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case w.s90es:case w.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(t,1);break}e.data[1]&&this.setChActive(t,1);break}default:{this.setChActive(t,1);break}}})();let n=t*m.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#k.ano(t),this.#D[t]=0;let l=t*m.cc;this.#e[l+g[1]]=0,this.#e[l+g[5]]=0,this.#e[l+g[64]]=0,this.#e[l+g[65]]=0,this.#e[l+g[66]]=0,this.#e[l+g[67]]=0,this.#e[l+g[11]]=127,this.#e[l+g[101]]=127,this.#e[l+g[100]]=127,this.#e[l+g[99]]=127,this.#e[l+g[98]]=127;return}case 123:{this.#k.ano(t);return}case 124:{this.#k.ano(t);return}case 125:{this.#k.ano(t);return}case 126:{this.#p[t]=1,this.#k.ano(t);return}case 127:{this.#p[t]=0,this.#k.ano(t);return}}if(g[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(st.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(k()&&console.debug(`${A[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#s[t]>0&&(e.data[1]=this.#e[n],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==w.gs?e.data[1]<56&&this.#s[t]>0&&(e.data[1]=this.#e[n],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)):this.#t==w.gm?e.data[1]<48?this.#s[t]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${t+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):this.#t==w.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),this.#t){case w.xg:{[126,127].indexOf(e.data[1])>-1?this.#s[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#s[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case w["05rw"]:case w.x5d:case w.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#s[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#s[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case w.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#s[t]==0&&(this.setChType(t,this.CH_DRUM2),console.debug(`CH${t+1} set to drums by MSB.`)):this.#s[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}case w.g2:{e.data[1]==120?this.#s[t]==0&&(this.setChType(t,this.CH_DRUMS),console.debug(`CH${t+1} set to drums by MSB.`)):this.#s[t]>0&&(this.setChType(t,this.CH_MELODIC),console.debug(`CH${t+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:t});break}case 6:{if(this.#H){[w.xg,w.gs,w.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${A[this.#t]}" mode, even when they are supported in Octavia.`);let l=this.#e[n+g[99]],u=this.#e[n+g[98]];if(l==1){let p=nt.indexOf(u);if(p>-1)this.#e[n+g[71+p]]=e.data[1],k()&&console.debug(`Redirected NRPN 1 ${u} to cc${71+p}.`),this.dispatchEvent("cc",{part:t,cc:71+p,data:e.data[1]});else{let h=De.indexOf(u);h>-1?this.#I[t*10+h]=e.data[1]-64:console.warn(`NRPN 0x01${u.toString(16).padStart(2,"0")} is not supported.`),k()&&console.debug(`CH${t+1} voice NRPN ${u} commit`)}}else{if(q.indexOf(l)<0){let h=`NRPN 0x${l.toString(16).padStart(2,"0")}${u.toString(16).padStart(2,"0")} `;l==127?console.warn(`${h}is not necessary. Consider removing it.`):console.warn(`${h}is not supported.`)}else{let h=this.#s[t]-2;h<0?console.warn(`CH${t+1} cannot accept drum NRPN as type ${X[this.#s[t]]}.`):this.#x[(h*m.dpn+R[l])*m.dnc+u]=e.data[1]}k()&&console.debug(`CH${t+1} (${X[this.#s[t]]}) drum NRPN ${l} commit`)}}else{let l=Ce[this.#e[n+g[100]]],u=Me[this.#e[n+g[100]]];this.#e[n+g[101]]==0&&l!=null&&(k()&&console.debug(`CH${t+1} RPN 0 ${this.#e[n+g[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Re[l][0]),Re[l][1]),this.#r[t*m.rpn+l]=e.data[1],this.#i[t*m.rpnt+u]=1)}break}case 32:{switch(k()&&console.debug(`${A[this.#t]}, CH${t+1} LSB: ${e.data[1]}`),this.#t){case w.s90es:case w.motif:{this.setChType(t,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.dispatchEvent("voice",{part:t});break}case 38:{if(!this.#H){let l=Ce[this.#e[n+100]],u=Me[this.#e[n+100]];this.#e[n+101]==0&&l!=null&&(this.#r[t*m.rpn+l+1]=e.data[1],this.#i[t*m.rpnt+u]=1)}break}case 64:{e.data[1]<64&&this.#k.hoOf(t);break}case 66:{e.data[1]>>6?this.#k.soOn(t):this.#k.soOf(t);break}case 98:case 99:{this.#H=1;break}case 100:case 101:{this.#H=0;break}}this.#e[n+g[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:t,cc:e.data[0],data:e.data[1]})}},12:function(e){let t=e.channel;switch(this.#t){case w.s90es:case w.motif:{e.data&&this.setChActive(t,1);break}default:this.setChActive(t,1)}this.#n[t]=e.data,this.#a[t]=0,k()&&console.debug(`T:${e.track} C:${t} P:${e.data}`),this.dispatchEvent("voice",{part:t})},13:function(e){let t=this,n=e.channel;this.#b.forEach(function(l){let u=l>>7;n==u&&(t.#l[l]=e.data,t.dispatchEvent("note",{part:n,note:l&127,velo:e.data,state:t.NOTE_SUSTAIN}))})},14:function(e){let t=e.channel;this.#D[t]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:t,pitch:this.getPitchShift(t)})},15:function(e){ct(e.data).forEach(t=>{let n=t[0],l=t[1];(this.#re[n]||function(){console.debug(`Unknown manufacturer ${n}.`)})(l,t.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#R[e.meta]||function(n,l,u){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#X=0);let t=it.indexOf(e.meta)>-1;if(k()&&console.debug(e),t)return e.reply="meta",e}};#re={64:(e,t,n)=>{this.#Z.run(t,n,e)},65:(e,t,n)=>{if(t[0]<16)if(t[1]==72){let l=t[t.length-1],u=ae(t.subarray(3,t.length-1));l==u?this.#L.run(t.subarray(0,t.length-1),n,e):console.warn(`Bad SD checksum ${l}. Should be ${u}.`)}else this.#L.run(t,n,e);else{let l=t[t.length-1],u=ae(t.subarray(2,t.length-1));l==u?this.#L.run(t.subarray(0,t.length-1),n,e):console.warn(`Bad GS checksum ${l}. Should be ${u}.`)}},66:(e,t,n)=>{this.#V.run(t,n,e)},67:(e,t,n)=>{this.#A.run(t,n,e)},68:(e,t,n)=>{this.#ee.run(t,n,e)},71:(e,t,n)=>{this.#J.run(t,n,e)},126:(e,t,n)=>{this.#Y.run(t,n,e)},127:(e,t,n)=>{this.switchMode("gm"),this.#j.run(t,n,e)}};#Y;#j;#A;#L;#V;#Z;#J;#ee;buildRchTree(){let e=[];this.#u.forEach((t,n)=>{t0&&!l&&(this.#e[e*m.cc+g[0]]=I[n])}setChActive(e,t=0){this.#w[e]!=t&&this.dispatchEvent("channeltoggle",{part:e,active:t}),this.#w[e]=t}getPitch(){return this.#D}getProgram(){return this.#n}getTexts(){return this.#P.slice()}getVel(e){let t=new Map,n=this;return n.#b.forEach(function(l,u){let p=Math.floor(l/128),h=l%128;e==p&&n.#l[l]>0&&t.set(h,{v:n.#l[l],s:n.#v[u]})}),t}getBitmap(){return{bitmap:this.#m,expire:this.#E}}getLetter(){return{text:this.#_,set:this.#q,expire:this.#N}}getMode(){return A[this.#t]}getMaster(){return{volume:this.#f}}getRawStrength(){let e=this;return this.#b.forEach(function(t){let n=Math.floor(t/128);e.#l[t]>e.#C[n]&&(e.#C[n]=e.#l[t])}),this.#C}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(n,l){e[l]=Math.floor(n*t.#e[l*m.cc+g[7]]*t.#e[l*m.cc+g[11]]*t.#f/803288)}),e}getRpn(){return this.#r}getNrpn(){return this.#I}getVoice(e,t,n,l){let u=e||this.#O,p=t,h=n||this.#M;A[this.#t]=="ns5r"&&u>0&&u<56&&(h=3);let a=this.userBank.get(u,p,h,l);if(A[this.#t]=="mt32"&&a.name.indexOf("MT-m:")==0){let i=parseInt(a.name.slice(5)),d=i*m.cmt,s="";this.#S.subarray(d,d+10).forEach(r=>{r>31&&(s+=String.fromCharCode(r))}),this.userBank.load(`MSB LSB PRG +0 127 ${p} ${s}`,!0),a.name=s,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(u,p,h,l)),a}getChVoice(e){let t=this.getVoice(this.#e[e*m.cc+g[0]],this.#n[e],this.#e[e*m.cc+g[32]],A[this.#t]);if(this.#a[e])switch(this.#t){case w.mt32:t.ending="~",t.name="",this.#c.subarray(14*(e-1),14*(e-1)+10).forEach(n=>{n>31&&(t.name+=String.fromCharCode(n))})}return t}getPitchShift(e){let t=this,n=e*m.rpn,l=t.#r[n];return t.#i[e*m.rpnt]||t.#t==w.mt32&&(l=12),t.#D[e]/8192*l+(t.#r[n+3]-64)+((t.#r[n+1]<<7)+t.#r[n+2]-8192)/8192}getEffectType(e=0){let t=3*e+1;return this.#T.subarray(t,t+2)}setEffectTypeRaw(e=0,t,n){let l=3*e;this.#T[l]=1,this.#T[l+1+ +t]=n}setEffectType(e=0,t,n){this.setEffectTypeRaw(e,!1,t),this.setEffectTypeRaw(e,!0,n)}getEffectSink(){return this.#G}setLetterDisplay(e,t,n=0,l=3200){let u=this,p;u.#_=" ".repeat(n),e.forEach(h=>{u.#_+=String.fromCharCode(h>31?h:32),h<32&&(p=p||new Set,p.add(h))}),u.#q=Date.now(),u.#N=Date.now()+l,p&&(p=Array.from(p),p.forEach((h,a,i)=>{i[a]=h.toString(16).padStart(2,"0")}),console.warn(`${t}${t?" ":""}invalid code point${p.length>1?"s":""}: 0x${p.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let t=!0,n=0;for(;t&&n=m.ace&&console.warn("ACE slots are full.")}getAce(){return this.#d}getChAce(e,t){if(t<0||t>=m.ace)throw new RangeError("No such ACE slot");let n=this.#d[t];if(n){if(F.indexOf(n)>=0)return this.#e[e*m.cc+g[n]];throw new Error(`Invalid ACE source: ${n}`)}else return 0}initDrums(){let e=this;e.#x.fill(64);for(let t=0;t-1){if(n.#t==0||t){let u=n.#t;n.initOnReset&&t&&(this.init(1),u=w["?"]),n.#t=l,n.#h=0,n.#O=Se[0][l],n.#M=Se[1][l];for(let h=0;h0&&n.#e[h*m.cc+g[0]]==I[u]&&(n.#e[h*m.cc]=I[l]);switch(l){case w.mt32:{te.forEach((h,a)=>{let i=a+1;n.#w[i]||(n.#n[i]=h,n.#e[i*m.cc+g[91]]=127)});for(let h=1;h<10;h++)n.dispatchEvent("voice",{part:h});break}}let p;switch(l){case w["?"]:case w.xg:{p=[1,0,65,0,5,0,0,0];break}case w.gm:case w.gs:case w.g2:case w.sd:{p=[40,4,40,18,40,32,32,0];break}case w["05rw"]:case w.x5d:case w.ns5r:{p=[44,1,44,19,44,0,44,0];break}case w.k11:case w.sg:{p=[24,0,0,0,0,0,0,0];break}case w.mt32:{p=[40,4,0,0,0,0,0,0];break}default:p=[0,0,0,0,0,0,0,0]}for(let h=0;h<4;h++)n.#T[3*h]||(n.#T[3*h+1]=p[2*h],n.#T[3*h+2]=p[2*h+1],n.dispatchEvent(`efx${["reverb","chorus","delay","insert"][h]}`,n.getEffectType(h)));n.dispatchEvent("mode",e),n.forceVoiceRefresh()}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#C.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#ae[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),n=!1;this.#te[t]?.forEach(l=>{e.channel=l,n=!0,this.#ae[e.type].call(this,e)}),n||console.warn(`${Te[e.type]?Te[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${t+1} without any recipient.`)}this.#P.length>100&&this.#P.splice(100,this.#P.length-99)}runRaw(e){}async loadBank(e,t){let n=this;switch(e=e.toLowerCase(),e){case"s7e":{n.userBank.clearRange({msb:63,lsb:[21,22]}),n.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{z.context=this,n.userBank.load(await z.read(e,t));break}}n.forceVoiceRefresh()}constructor(){super();let e=this;this.#m=new Uint8Array(256),this.#o[10]=new Uint8Array(512),this.#Q=new D,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -148,21 +148,21 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),this.addEventListener("metacommit",function(a){let{data:i}=a;e.#D[0]?.type==i.type&&e.#D[0]?.amend?(e.#D[0].amend=i.amend,e.#D[0].data+=i.data):e.#D.unshift(i)}),this.#M[1]=function(a){switch(a=a.replaceAll(`\r +122 006 000 `),this.addEventListener("metacommit",function(a){let{data:i}=a;e.#P[0]?.type==i.type&&e.#P[0]?.amend?(e.#P[0].amend=i.amend,e.#P[0].data+=i.data):e.#P.unshift(i)}),this.#R[1]=function(a){switch(a=a.replaceAll(`\r `,` `).replaceAll("\r",` -`),a.slice(0,2)){case"@I":{this.#m=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:a.slice(2)?.trimLeft()});break}case"@K":{this.#m=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:a.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{this.#m=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:a.slice(2)?.trimLeft()});break}case"@T":{this.#m=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:a.slice(2)?.trimLeft()});break}case"@V":{this.#m=!0,this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:a.slice(2)?.trimLeft()});break}case"XF":{let i=a.slice(2).split(":");switch(i[0]){case"hd":{i.slice(1).forEach((d,s)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][s],data:d})});break}case"ln":{i.slice(1).forEach((d,s)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][s],data:d})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:this.#m?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` -`).forEach((i,d)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:i,mask:d!=0})})}},this.#M[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},this.#M[3]=function(a,i){i<1&&this.#_<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},this.#M[4]=function(a,i){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},this.#M[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},this.#M[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},this.#M[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},this.#M[32]=function(a){this.#_=a[0]+1},this.#M[33]=function(a,i){e.#q[i]=a+1},this.#M[81]=function(a,i){e.#U=a/1e3},this.#M[127]=function(a,i){e.#W.run(a,i)},this.#W.default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},this.#W.add([67,0,1],function(a,i){e.#q[i]=a[0]+1}),this.#Q=new D("universal non-realtime"),this.#Y=new D("universal realtime"),this.#A=new D("Yamaha"),this.#L=new D("Roland"),this.#V=new D("Korg"),this.#j=new D("Kawai"),this.#Z=new D("Akai"),this.#J=new D("Casio");let t=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,a)};this.#Q.default=t,this.#Y.default=t,this.#A.default=t,this.#L.default=t,this.#V.default=t,this.#j.default=t,this.#Z.default=t,this.#J.default=t,this.#Q.add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),e.#m=e.#m||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),this.#Y.add([4,1],a=>{e.#f=((a[1]<<7)+a[0])/16383*100,e.dispatchEvent("mastervolume",e.#f)}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64),this.#A.add([76,0,0],a=>{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),e.#m=!1,console.info("MIDI reset: XG");break}default:{let i=[0,0,0,0],d=(s,r)=>{i[r]=s};if(a.subarray(1).forEach((s,r)=>{let l=r+a[0];([d,d,d,d,f=>{this.#f=f*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},f=>{},f=>{}][l]||(()=>{}))(s,r)}),a[0]<4){let s=0;i.forEach(r=>{s=s<<4,s+=r}),s-=1024}}}}).add([76,2,1],a=>{let i="XG ";a[0]<32?(i+="reverb ",a.subarray(1).forEach((d,s)=>{([r=>{e.setEffectTypeRaw(0,!1,r),console.info(`${i}main type: ${G[r]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},r=>{e.setEffectTypeRaw(0,!0,r),console.debug(`${i}sub type: ${r+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},r=>{console.debug(`${i}time: ${ge(r)}s`)},r=>{console.debug(`${i}diffusion: ${r}`)},r=>{console.debug(`${i}initial delay: ${r}`)},r=>{console.debug(`${i}HPF cutoff: ${N[r]}Hz`)},r=>{console.debug(`${i}LPF cutoff: ${N[r]}Hz`)},r=>{console.debug(`${i}width: ${r}`)},r=>{console.debug(`${i}height: ${r}`)},r=>{console.debug(`${i}depth: ${r}`)},r=>{console.debug(`${i}wall type: ${r}`)},r=>{console.debug(`${i}dry/wet: ${r}`)},r=>{console.debug(`${i}send: ${C(r)}dB`)},r=>{console.debug(`${i}pan: ${r-64}`)},!1,!1,r=>{console.debug(`${i}delay: ${r}`)},r=>{console.debug(`${i}density: ${r}`)},r=>{console.debug(`${i}balance: ${r}`)},r=>{},r=>{console.debug(`${i}feedback: ${r}`)},r=>{}][a[0]+s]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(d)})):a[0]<64?(i+="chorus ",a.subarray(1).forEach((d,s)=>{([r=>{e.setEffectTypeRaw(1,!1,r),console.info(`${i}main type: ${G[r]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},r=>{e.setEffectTypeRaw(1,!0,r),console.debug(`${i}sub type: ${r+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},r=>{console.debug(`${i}LFO: ${be[r]}Hz`)},r=>{},r=>{console.debug(`${i}feedback: ${r}`)},r=>{console.debug(`${i}delay offset: ${me(r)}ms`)},r=>{},r=>{console.debug(`${i}low: ${N[r]}Hz`)},r=>{console.debug(`${i}low: ${r-64}dB`)},r=>{console.debug(`${i}high: ${N[r]}Hz`)},r=>{console.debug(`${i}high: ${r-64}dB`)},r=>{console.debug(`${i}dry/wet: ${r}`)},r=>{console.debug(`${i}send: ${C(r)}dB`)},r=>{console.debug(`${i}pan: ${r-64}`)},r=>{console.debug(`${i}to reverb: ${C(r)}dB`)},!1,r=>{},r=>{},r=>{},r=>{console.debug(`${i}LFO phase diff: ${(r-64)*3}deg`)},r=>{console.debug(`${i}input mode: ${r?"stereo":"mono"}`)},r=>{}][a[0]-32+s]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(d)})):a[0]<86?(i+="variation ",a.subarray(1).forEach((d,s)=>{([r=>{e.setEffectTypeRaw(2,!1,r),console.info(`${i}main type: ${G[r]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},r=>{e.setEffectTypeRaw(2,!0,r),console.debug(`${i}sub type: ${r+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+s]||function(){})(d)})):a[0]<97?(i+="variation ",a.subarray(1).forEach((d,s)=>{[r=>{console.debug(`${i}send: ${C(r)}dB`)},r=>{console.debug(`${i}pan: ${r-64}`)},r=>{console.debug(`${i}to reverb: ${C(r)}dB`)},r=>{console.debug(`${i}to chorus: ${C(r)}dB`)},r=>{console.debug(`${i}connection: ${r?"system":"insertion"}`)},r=>{console.debug(`${i}channel: CH${r+1}`)},r=>{console.debug(`${i}mod wheel: ${r-64}`)},r=>{console.debug(`${i}bend wheel: ${r-64}`)},r=>{console.debug(`${i}channel after touch: ${r-64}`)},r=>{console.debug(`${i}AC1: ${r-64}`)},r=>{console.debug(`${i}AC2: ${r-64}`)}][a[0]-86+s](d)})):a[0]>111&&a[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((i,d)=>{let s=d+a[0];if(s==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let r=s-1>>2,l=s-1&3,f=`XG EQ ${r} ${["gain","freq","Q","shape"][l]}: `;[()=>{console.debug(`${f}${i-64}dB`)},()=>{console.debug(`${f}${i} (raw)`)},()=>{console.debug(`${f}${i/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!i]}`)}][l]()}})}).add([76,3],a=>{let i=a[0],d=a[1],s=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((r,l)=>{([f=>{e.setEffectTypeRaw(3+i,!1,f),console.info(`${s}main type: ${G[f]}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))},f=>{e.setEffectTypeRaw(3+i,!0,f),console.debug(`${s}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))}][d+l]||function(){})(r)})}).add([76,6,0],a=>{let i=a[0];i<64?e.setLetterDisplay(a.subarray(1),"XG letter display",i):e.#B=Date.now()}).add([76,7,0],a=>{let i=a[0];e.#u=0,e.#w=Date.now()+3200,e.#y.fill(0);let d=a.subarray(1);for(let s=0;s>6-y&1,y++})}).add([76,8],(a,i)=>{let d=e.chRedir(a[0],i,!0),s=a[1],r=m.cc*d,l=`XG CH${d+1} `,f=`Unknown XG part address ${s}.`;a.subarray(2).forEach((o,b)=>{s<1?console.debug(f):s<41?([()=>{e.#e[r+g[0]]=o,e.dispatchEvent("voice",{part:d})},()=>{e.#e[r+g[32]]=o,e.dispatchEvent("voice",{part:d})},()=>{e.#n[d]=o,e.dispatchEvent("voice",{part:d})},()=>{let y=e.chRedir(o,i,!0);e.#p[d]=y,d!=y&&(e.buildRchTree(),console.info(`${l}receives from CH${y+1}`))},()=>{e.#b[d]=+!o},()=>{},()=>{e.setChType(d,o,w.xg),console.debug(`${l}type: ${X[o]||o}`)},()=>{e.#r[m.rpn*d+3]=o,e.#s[m.rpnt*d+2]=1},!1,!1,()=>{e.#e[r+g[7]]=o},!1,!1,()=>{e.#e[r+g[10]]=o||128},!1,!1,()=>{e.#e[r+g[128]]=o},()=>{e.#e[r+g[93]]=o},()=>{e.#e[r+g[91]]=o},()=>{e.#e[r+g[94]]=o},()=>{e.#e[r+g[76]]=o},()=>{e.#e[r+g[77]]=o},()=>{e.#e[r+g[78]]=o},()=>{e.#e[r+g[74]]=o},()=>{e.#e[r+g[71]]=o},()=>{e.#e[r+g[73]]=o},()=>{e.#e[r+g[75]]=o},()=>{e.#e[r+g[72]]=o}][s+b-1]||(()=>{}))():s<48?console.debug(f):s<111?s>102&&s<105&&(e.#e[r+g[[5,65][s&1]]]=o):s<114?console.debug(f):s<116?console.debug(`${l}EQ ${["bass","treble"][s&1]} gain: ${o-64}dB`):s<118?console.debug(f):s<120?console.debug(`${l}EQ ${["bass","treble"][s&1]} freq: ${o}`):console.debug(f)})}).add([76,9],(a,i)=>{let d=e.chRedir(a[0],i,!0),s=a[1],r=`PLG-150VL CH${d+1} `;a.subarray(2).forEach((l,f)=>{let o=f+s;switch(o){case 1:{console.info(`${r}breath mode: ${["system","breath","velocity","touch EG"][l]}`);break}case 0:case 27:case 28:break;default:if(o<27){let b=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][o-3>>1];o&1?o<23?(console.debug(`${r}${b} control source: ${Ee(l)}`),l&&l<96&&e.allocateAce(l)):console.debug(`${r}${b} scale break point: ${l}`):console.debug(`${r}${b} depth: ${l-64}`)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][a[0]]} for CH${a[2]+1}.`)}).add([73,0,0],(a,i)=>{let d=a[0],s="MU1000 System: ";a.subarray(1).forEach((r,l)=>{let f=d+l;f==8?console.debug(`${s}LCD contrast set to ${r}.`):f==18?(e.#C=r?126:0,console.debug(`${s}bank defaults to ${r?"MU100 Native":"MU Basic"}.`)):f>=64&&f<69&&[()=>{e.dispatchEvent("channelactive",r)},()=>{r<8?(e.dispatchEvent("channelmin",r<<4),console.debug(`Octavia System: Minimum CH${(r<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{r<8?(e.dispatchEvent("channelmax",(r<<4)+15),console.debug(`Octavia System: Maximum CH${(r<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#H=!!r,console.info(`Octavia System: RS receiving ${["dis","en"][r]}abled.`)}][f-64]()})}).add([73,10,0],(a,i)=>{let d=a[0],s=`MU1000 RS${e.#H?"":" (ignored)"}: `;if(d<16)switch(d){case 2:{let r=e.chRedir(0,i,!0);e.#H&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+63)),console.info(`${s}Show CH1~64`);break}case 3:{let r=e.chRedir(a[1]<<5,i,!0);e.#H&&e.dispatchEvent("channelmin",r),e.#H&&e.dispatchEvent("channelmax",r+31),console.info(`${s}Show CH${r+1}~CH${r+32}`);break}default:console.debug(`${s}unknown switch ${d} invoked.`)}else if(d<32){if(e.#H){let r=e.chRedir(d-16+(e.#ee<<4),i,!0);e.dispatchEvent("channelactive",r)}}else if(d<36){let r=e.chRedir(d-32<<4,i,!0);e.#H&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+15),e.#ee=d-32),console.info(`${s}Show CH${r+1}~CH${r+16}`)}}).add([93,3],(a,i)=>{let d=e.chRedir(a[0],i,!0),s=`PLG-100SG CH${d+1} `,r=Date.now();if(a[1]==0){let l="",f=0;a.subarray(2).forEach((o,b)=>{b%2==0?l+=ye[o]||o.toString().padStart("0"):f+=o*13}),r>=e.#z&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${ve(l)}`,amend:!0}),e.#z=r+Math.ceil(f/2)+e.#U,k()&&console.debug(`${s}vocals: ${l}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)});let n=function(a,i,d,s){},c=function(a,i){let d=a*m.dpn,s=i[0],r=i[1];i.subarray(2).forEach((l,f)=>{let o=f+r,b=-1;o<16?([()=>{b=24},()=>{b=25},()=>{b=26},()=>{},()=>{b=28},()=>{b=29},()=>{b=30},()=>{b=31},()=>{},()=>{},()=>{},()=>{b=20},()=>{b=21},()=>{b=22},()=>{b=23},()=>{}][o]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${a+1}.`)}))():o<32||(o<40?([()=>{b=48},()=>{b=49},!1,!1,()=>{b=52},()=>{b=53}][o-32]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${a+1}.`)}))():o<80||([()=>{b=36}][o-80]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${a+1}.`)}))()),b>=0?(k()&&console.debug(d,b,s,l),e.#a[(d+R[b])*m.dnc+s]=l):k()&&console.debug(`XG-style drum param ${o} has no writes.`)})},u=function(a,i,d){let s=a*m.dpn,r=(i<<7)+d[0];d.subarray(1).forEach((l,f)=>{let o=f+r,b=o&127,y=o>>7,E=-1;y>1&&([()=>{E=26},()=>{},()=>{E=28},()=>{E=29},()=>{E=30},()=>{},()=>{},()=>{E=31}][y-2]||(()=>{console.debug(`Unknown GS-style drum param ${y} on set ${a+1}.`)}))(),E>-1?(k()&&console.debug(s,E,b,l),e.#a[(s+R[E])*m.dnc+b]=l):k()&&console.debug(`GS-style drum param ${y} has no writes.`)})};this.#A.add([76,48],(a,i,d)=>{c(0,a)}).add([76,49],(a,i,d)=>{c(1,a)}).add([76,50],(a,i,d)=>{c(2,a)}).add([76,51],(a,i,d)=>{c(3,a)}).add([76,52],(a,i,d)=>{c(4,a)}).add([76,53],(a,i,d)=>{c(5,a)}).add([76,54],(a,i,d)=>{c(6,a)}).add([76,55],(a,i,d)=>{c(7,a)}),this.#A.add([89,0],(a,i,d)=>{if(e.eprom){let s=a[0],r=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);k()&&console.debug(`MU1000 EPROM trail to 0x${r.toString(16).padStart(6,"0")}, ${s} bytes.`);let l=e.eprom.data;a.subarray(4).forEach((f,o)=>{let b=o>>3,y=o&7;if(y==7)for(let E=0;E<7;E++)l[r+7*b+E]+=(f>>6-E&1)<<7;else l[r+7*b+y]=f})}}).add([89,1],(a,i,d)=>{let s=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];k()&&console.debug(`MU1000 EPROM jump to 0x${s.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=s)}).add([89,2],(a,i,d)=>{if(e.eprom){let s=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);k()&&console.debug(`MU1000 EPROM write to 0x${s.toString(16).padStart(6,"0")}.`);let r=e.eprom.data;a.subarray(4).forEach((l,f)=>{let o=f>>3,b=f&7;if(b==7)for(let y=0;y<7;y++)r[s+7*o+y]+=(l>>6-y&1)<<7;else r[s+7*o+b]=l})}}).add([89,3],(a,i,d)=>{}),this.#A.add([39,48],(a,i,d)=>{}).add([43,0,0],(a,i,d)=>{let s=[0,0,0,0],r=(l,f)=>{s[f]=l};if(a.subarray(1).forEach((l,f)=>{let o=f+a[0];[r,r,r,r,()=>{this.#f=l*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},()=>l-64,()=>l||128,()=>l,()=>l,()=>{console.debug(`TG300 variation on cc${l}.`)}][o](l,o)}),a[0]<4){let l=0;s.forEach(f=>{l=l<<4,l+=f}),l-=1024}}).add([43,1,0],(a,i,d)=>{}).add([43,2],(a,i,d)=>{let s=e.chRedir(a[0],i,!0),r=a[1],l=m.cc*s,f=`TG300 CH${s+1} `;a.subarray(2).forEach((o,b)=>{b<5?([()=>{},()=>{e.#e[l+g[0]]=o,e.dispatchEvent("voice",{part:s})},()=>{e.#e[l+g[32]]=o,e.dispatchEvent("voice",{part:s})},()=>{e.#n[s]=o,e.dispatchEvent("voice",{part:s})},()=>{let y=e.chRedir(o,i,!0);e.#p[s]=y,s!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))}][b+r]||(()=>{}))(o,b+r):b<21||(b<47?([()=>{e.#b[s]=+!o},()=>{},()=>{},()=>{e.#r[m.rpn*s+3]=o,e.#s[m.rpnt*s+2]=1},()=>{},()=>{e.#e[l+g[7]]=o},!1,!1,()=>{e.#e[l+g[10]]=o||128},!1,!1,()=>{console.debug(`${f} AC1 at cc${o}`)},()=>{console.debug(`${f} AC2 at cc${o}`)},()=>{e.#e[l+g[128]]=o},()=>{e.#e[l+g[93]]=o},()=>{e.#e[l+g[91]]=o},()=>{e.#e[l+g[94]]=o},()=>{e.#e[l+g[76]]=o},()=>{e.#e[l+g[77]]=o},()=>{e.#e[l+g[74]]=o},()=>{e.#e[l+g[71]]=o},()=>{e.#e[l+g[73]]=o},()=>{e.#e[l+g[75]]=o},()=>{e.#e[l+g[72]]=o},()=>{e.#e[l+g[78]]=o}][b+r-21]||(()=>{}))(o,b+r):b<95||([()=>{e.#e[l+g[65]]=o},()=>{e.#e[l+g[5]]=o}][b+r-95]||(()=>{}))(o,b+r))})}).add([43,7,0],(a,i,d)=>{let s=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",s)}).add([43,7,1],(a,i,d)=>{e.#u=0,e.#w=Date.now()+3200,e.#y.fill(0),a.forEach(function(s,r){let l=Math.floor(r/16),f=r%16,o=(f*3+l)*7,b=7,y=0;for(o-=f*5,l==2&&(b=2);y>6-y&1,y++})}),this.#L.add([66,18,0,0,127],(a,i,d)=>{e.switchMode("gs",!0),e.#e[m.cc*9]=120,e.#e[m.cc*25]=120,e.#e[m.cc*41]=120,e.#e[m.cc*57]=120,e.#C=3,e.#m=!1,e.#K.fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,i,d)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),e.#e[m.cc*9]=120,e.#e[m.cc*25]=120,e.#e[m.cc*41]=120,e.#e[m.cc*57]=120,e.#m=!1,e.#K.fill(0),console.info("MIDI reset: GS");break}default:{let s=[0,0,0,0],r=(l,f)=>{s[f]=l};if(a.subarray(1).forEach((l,f)=>{let o=f+a[0];[r,r,r,r,b=>{this.#f=b*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},b=>{},b=>{}][o](l,f)}),a[0]<4){let l=0;s.forEach(f=>{l=l<<4,l+=f}),l-=1024}}}}).add([66,18,64,1],a=>{let i=a[0];if(i<16){let d="".padStart(i," ");a.subarray(1).forEach((s,r)=>{d+=String.fromCharCode(Math.max(32,s))}),d=d.padEnd(16," "),console.debug(`GS patch name: ${d}`)}else i<48||(i<65?a.subarray(1).forEach((d,s)=>{let r=`GS ${i+s>55?"chorus":"reverb"} `;([()=>{console.info(`${r}type: ${J[d]}`),e.setEffectType(0,40,d),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${r}predelay: ${d}ms`)},()=>{console.info(`${r}type: ${we[d]}`),e.setEffectType(1,40,16+d),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${C(d)}`)},()=>{console.debug(`${r}to delay: ${C(d)}`)}][i+s-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?a.subarray(1).forEach((d,s)=>{let r="GS delay ";([()=>{console.info(`${r}type: ${$e[d]}`),e.setEffectType(2,40,32+d),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${C(d)}`)}][i+s-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],a=>{let i="GS EQ ";a.subarray(1).forEach((d,s)=>{([()=>{console.debug(`${i}low freq: ${[200,400][d]}Hz`)},()=>{console.debug(`${i}low gain: ${d-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][d]}Hz`)},()=>{console.debug(`${i}high gain: ${d-64}dB`)}][a[0]+s]||function(){console.warn(`Unknown GS EQ address: ${a[0]+s}`)})()})}).add([66,18,64,3],a=>{let i="GS EFX ",d=function(s,r){let l=ke(e.#x.subarray(10,12),r,s);l&&console.debug(`${i}${ee(e.#x.subarray(10,12))} ${l}`)};a.subarray(1).forEach((s,r)=>{([()=>{e.setEffectTypeRaw(3,!1,32+s),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,s),console.info(`${i}type: ${ee(e.#x.subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,()=>{console.debug(`${i}to reverb: ${C(s)}dB`)},()=>{console.debug(`${i}to chorus: ${C(s)}dB`)},()=>{console.debug(`${i}to delay: ${C(s)}dB`)},!1,()=>{console.debug(`${i}1 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}1 depth: ${s-64}`)},()=>{console.debug(`${i}2 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}2 depth: ${s-64}`)},()=>{console.debug(`${i}to EQ: ${s?"ON":"OFF"}`)}][a[0]+r]||function(l,f){console.warn(`Unknown GS EFX address: ${f}`)})(s,a[0]+r)})}).add([66,18,65],a=>{u((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],a=>{switch(a[0]){case 0:{let i=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",i);break}case 32:{e.#w=Date.now()+3200,a[1]==0&&(e.#u=Math.max(Math.min(a[2]-1,9),0),k()&&console.debug(`GS switch display page ${a[2]-1}.`));break}default:if(a[0]<6){e.#u>9&&(e.#u=0);let i=a[0]-1<<1|a[1]>>6;e.#u==i&&(e.#w=Date.now()+3200),e.#o[i]?.length||(e.#o[i]=new Uint8Array(256));let d=e.#o[i];k()&&console.debug(`GS frame draw page ${i}.`);let s=a[1]&63;d.fill(0),a.subarray(2).forEach(function(l,f){let o=f+s,b=Math.floor(o/16),y=o%16,E=(y*4+b)*5,$=5,x=0;for(E-=y*4,b==3&&($=1);x<$;)d[E+x]=l>>4-x&1,x++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let p=function(a,i,d){let s=a[0],r=m.cc*i,l=m.rpn*i,f=`GS CH${i+1} `;s<3?(a.subarray(1).forEach((o,b)=>{[()=>{e.#e[r+g[0]]=o},()=>{e.#n[i]=o},()=>{let y=0;o<16?y=e.chRedir(o,d,!0):y=m.ch,e.#p[i]=y,i!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))}][s+b]()}),e.dispatchEvent("voice",{part:i})):s<19||(s<44?a.subarray(1).forEach((o,b)=>{([()=>{e.#b[i]=+!o},!1,()=>{e.setChType(i,o<<1,w.gs),console.debug(`${f}type: ${o?"drum ":"melodic"}${o||""}`)},()=>{e.#r[l+3]=o,e.#s[m.rpnt*i+2]=1},!1,()=>{e.#e[r+g[7]]=o},!1,!1,()=>{e.#e[r+g[10]]=o||128},!1,!1,()=>{console.debug(`${f}CC 1: cc${o}`)},()=>{console.debug(`${f}CC 2: cc${o}`)},()=>{e.#e[r+g[93]]=o},()=>{e.#e[r+g[91]]=o},!1,!1,()=>{e.#r[l+1]=o,e.#s[m.rpnt*i+1]=1},()=>{e.#r[l+2]=o,e.#s[m.rpnt*i+1]=1},()=>{e.#e[r+g[94]]=o}][s+b-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},h=function(a,i){let d=a[0],s=`GS CH${i+1} `;d<2?a.subarray(1).forEach((r,l)=>{[()=>{e.#e[m.cc*i+g[32]]=r},()=>{}][d+l]()}):d<32?console.warn(`Unknown GS misc address: ${d}`):d<35?a.subarray(1).forEach((r,l)=>{[()=>{console.debug(`${s}EQ: o${["ff","n"][r]}`)},()=>{},()=>{console.debug(`${s}EFX: o${["ff","n"][r]}`),e.#P[i]=r,e.dispatchEvent("partefxtoggle",{part:i,active:r})}][d+l-32]()}):console.warn(`Unknown GS misc address: ${d}`)};this.#L.add([66,18,64,16],(a,i)=>{p(a,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(a,i)=>{p(a,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(a,i)=>{p(a,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(a,i)=>{p(a,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(a,i)=>{p(a,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(a,i)=>{p(a,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(a,i)=>{p(a,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(a,i)=>{p(a,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(a,i)=>{p(a,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(a,i)=>{p(a,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(a,i)=>{p(a,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(a,i)=>{p(a,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(a,i)=>{p(a,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(a,i)=>{p(a,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(a,i)=>{p(a,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(a,i)=>{p(a,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(a,i)=>{h(a,e.chRedir(9,i,!0))}).add([66,18,64,65],(a,i)=>{h(a,e.chRedir(0,i,!0))}).add([66,18,64,66],(a,i)=>{h(a,e.chRedir(1,i,!0))}).add([66,18,64,67],(a,i)=>{h(a,e.chRedir(2,i,!0))}).add([66,18,64,68],(a,i)=>{h(a,e.chRedir(3,i,!0))}).add([66,18,64,69],(a,i)=>{h(a,e.chRedir(4,i,!0))}).add([66,18,64,70],(a,i)=>{h(a,e.chRedir(5,i,!0))}).add([66,18,64,71],(a,i)=>{h(a,e.chRedir(6,i,!0))}).add([66,18,64,72],(a,i)=>{h(a,e.chRedir(7,i,!0))}).add([66,18,64,73],(a,i)=>{h(a,e.chRedir(8,i,!0))}).add([66,18,64,74],(a,i)=>{h(a,e.chRedir(10,i,!0))}).add([66,18,64,75],(a,i)=>{h(a,e.chRedir(11,i,!0))}).add([66,18,64,76],(a,i)=>{h(a,e.chRedir(12,i,!0))}).add([66,18,64,77],(a,i)=>{h(a,e.chRedir(13,i,!0))}).add([66,18,64,78],(a,i)=>{h(a,e.chRedir(14,i,!0))}).add([66,18,64,79],(a,i)=>{h(a,e.chRedir(15,i,!0))}),this.#V.add([54,65],(a,i)=>{e.switchMode("x5d");let d=(a[1]<<7)+a[0],s=(a[3]<<7)+a[2],r=e.chRedir(d&15,i,!0),l=m.cc*r;[()=>{s<1||(s<101?(e.setChType(r,e.CH_MELODIC,w.x5d),e.#n[r]=s-1,e.#e[l+g[0]]=82):s<229?(e.setChType(r,e.CH_MELODIC,w.x5d),e.#n[r]=s-101,e.#e[l+g[0]]=56):(e.setChType(r,e.CH_DRUMS,w.x5d),e.#n[r]=Pe[s-229]||0,e.#e[l+g[0]]=62)),e.dispatchEvent("voice",{part:r})},()=>{e.#e[l+g[7]]=s},()=>{s<31&&(e.#e[l+g[10]]=Math.round((s-15)*4.2+64))},()=>{e.#e[l+g[93]]=_(s)},()=>{e.#e[l+g[91]]=_(s)},()=>{e.#r[r*m.rpn+3]=s>8191?s-16320:64+s,e.#s[m.rpnt*r+2]=1},()=>{e.#r[r*m.rpn+1]=s>8191?s-16320:64+s,e.#s[m.rpnt*r+1]=1},()=>{s>0&&(e.#r[r*m.rpn]=s,e.#s[m.rpnt*r]=1)},()=>{}][d>>4]()}).add([54,76,0],(a,i)=>{e.switchMode("x5d",!0);let d="",s=82,r=0,l=0,f="MSB PRG LSB NME";O(a,function(o,b){if(b<16400){let y=b%164;switch(!0){case y<10:{o>31&&(d+=String.fromCharCode(o));break}case y==11:{f+=` -${s} ${r} ${l} ${d.trim().replace("Init Voice","")}`,r++,d="";break}}r>99&&(s=90,r=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([54,77,0],(a,i)=>{e.switchMode("x5d",!0);let d="",s=90,r=0,l=0,f="MSB PRG LSB NME";O(a,function(o,b){if(b<13600){let y=b%136;switch(!0){case y<10:{o>31&&(d+=String.fromCharCode(o));break}case y==11:{f+=` -${s} ${r} ${l} ${d.trim().replace("Init Combi","")}`,r++,d="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([54,78],(a,i)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,i)=>{e.switchMode("x5d",!0),O(a,(d,s)=>{s>0&&s<3&&(e.setEffectType(s-1,44,d),e.dispatchEvent(`efx${["reverb","chorus"][s-1]}`,e.getEffectType(s-1)))})}).add([54,104],(a,i)=>{e.switchMode("x5d",!0),O(a,function(d,s,r,l){if(s<192){let f=e.chRedir(Math.floor(s/12),i,!0),o=f*m.cc;switch(s%12){case 0:{d<128?(e.setChType(f,e.CH_MELODIC,w.x5d),e.#e[o+g[0]]=82,e.#n[f]=d):(e.setChType(f,e.CH_DRUMS,w.x5d),e.#e[o+g[0]]=62,e.#n[f]=Pe[d-128]),d>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{e.#e[o+g[7]]=d;break}case 2:{e.#r[f*m.rpn+3]=d>127?d-192:64+d,e.#s[m.rpnt*f+2]=1;break}case 3:{e.#r[f*m.rpn+1]=d>127?d-192:64+d,e.#s[m.rpnt*f+1]=1;break}case 4:{d<31&&(e.#e[o+g[10]]=Math.round((d-15)*4.2+64));break}case 5:{let b=d>>4,y=d&15;e.#e[o+g[91]]=_(y),e.#e[o+g[93]]=_(b);break}case 10:break;case 11:{let b=e.chRedir(d&15,i,!0),y=d>>4;e.#p[f]=d,(b!=f||y)&&(console.info(`X5D Part CH${f+1} receives from CH${b+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(s-192,i,!0)}})}),this.#L.add([22,18,127],a=>{e.switchMode("mt32",!0),e.#m=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,i,d)=>{e.switchMode("mt32");let s=e.chRedir(d,i,!0),r=a[1];a.subarray(2).forEach((l,f)=>{let o=f+r;e.#l[o+(s-1)*16]=l,([!1,()=>{let b=e.#l[s-1<<4];if(b<3){if(e.#v[s]=1,b==2)for(let y=0;y{e.#r[s*m.rpn+3]=l+40,e.#s[m.rpnt*s+2]=1},()=>{e.#r[s*m.rpn+1]=l+14,e.#s[m.rpnt*s+1]=1},()=>{e.#r[s*m.rpn]=l,e.#s[m.rpnt*s]=1},!1,()=>{e.#e[m.cc*s+g[91]]=l?127:0},!1,()=>{e.#e[m.cc*s+g[7]]=l},()=>{e.#e[m.cc*s+g[10]]=Math.ceil(l*9.05)}][o]||(()=>{}))()})}).add([22,18,1],(a,i,d)=>{e.switchMode("mt32");let s=d&7;console.debug(`MT-32 slot #${d+1} Drum: ${a}`);let r=a[0]<<7|a[1];a.subarray(2).forEach((l,f)=>{let o=f+r,b=(o>>2)+24,y=o&3,E=s*m.dpn;if(k()&&console.debug(`MT-32 temp drum note ${b} param ${y}: ${l}`),b<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${b}`);return}[()=>{},()=>{e.#a[(E+R[26])*m.dnc+b]=Math.round(l*1.27)},()=>{e.#a[(E+R[26])*m.dnc+b]=l*9+1&127},()=>{e.#a[(E+R[26])*m.dnc+b]=l?127:0}][y]()})}).add([22,18,2],(a,i,d)=>{e.switchMode("mt32");let s=e.chRedir(d,i,!0),r=a[1]+(a[0]<<7);r<10&&(e.#v[s]=1),a.subarray(2).forEach((l,f)=>{let o=f+r;o<14&&(e.#h[(s-1)*m.cmt+o]=l)}),e.dispatchEvent("voice",{part:s})}).add([22,18,3],(a,i,d)=>{e.switchMode("mt32");let s=d&7;if(a[0]){let r=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((l,f)=>{let o=f+r,b=(o>>2)+24,y=o&3,E=s*m.dpn;if(k()&&console.debug(`MT-32 dev drum note ${b} param ${y}: ${l}`),b<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${b}`);return}[()=>{},()=>{e.#a[(E+R[26])*m.dnc+b]=Math.round(l*1.27)},()=>{e.#a[(E+R[26])*m.dnc+b]=l*9+1&127},()=>{e.#a[(E+R[26])*m.dnc+b]=l?127:0}][y]()})}else{let r=a[1];a.subarray(2).forEach((l,f)=>{let o=f+r;e.#l[o]=l;let b=e.chRedir(1+(o>>4),i,!0),y=o&15;([!1,()=>{let E=e.#l[b-1<<4];if(E<3)if(e.#v[b]=1,E==2)for(let $=0;${e.#r[b*m.rpn+3]=l+40,e.#s[m.rpnt*b+2]=1},()=>{e.#r[b*m.rpn+1]=l+14,e.#s[m.rpnt*b+1]=1},()=>{e.#r[b*m.rpn]=l,e.#s[m.rpnt*b]=1},!1,()=>{e.#e[m.cc*b+g[91]]=l?127:0},!1,()=>{e.#e[m.cc*b+g[7]]=l},()=>{e.#e[m.cc*b+g[10]]=Math.ceil(l*9.05)}][y]||(()=>{}))()})}}).add([22,18,4],(a,i,d)=>{e.switchMode("mt32");let s=a[1]+(a[0]<<7),r=[];a.subarray(2).forEach((l,f)=>{let o=f+s,b=e.chRedir(Math.floor(o/246+1),i,!0),y=o%246;y<14&&(e.#h[(b-1)*m.cmt+y]=l),y<10&&(e.#v[b]=1),r.indexOf(b)<0&&r.push(b)}),r.forEach(l=>{e.dispatchEvent("voice",{part:l})})}).add([22,18,5],(a,i,d)=>{e.switchMode("mt32");let s=(a[0]<<7)+a[1];a.subarray(2).forEach((r,l)=>{let f=s+l,o=Math.floor(f/8),b=f&7,y=o*8;e.#T[f]=r,([!1,()=>{let E=e.#T[y];if(E<3){let $="";if(E==2){let x=m.cmt*o;$=`MT-m:${r.toString().padStart(3,"0")}`}else $=e.baseBank.get(0,r+(E<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:o}),e.userBank.load(`MSB LSB PRG NME -000 127 ${o} ${$}`,!0)}}][b]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,i,d)=>{e.switchMode("mt32");let s=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((r,l)=>{let f=s+l;f>1)*m.cmt+f]=r)}),e.forceVoiceRefresh()}).add([22,18,16],(a,i,d)=>{e.switchMode("mt32");let s=a[1],r=!1,l=function(f,o){e.#p[o-12]=f,r=!0};a.subarray(2).forEach((f,o)=>{let b=o+s;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,l,l,l,l,l,l,l,l,l,()=>{e.#f=f,e.dispatchEvent("mastervolume",e.#f)}][b]||(()=>{}))(f,o)}),r&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let i=a[1],d=" ".repeat(i);a.subarray(2).forEach(s=>{s>31?d+=String.fromCharCode(s):d+=" "}),e.#N=d.padStart(20," "),e.#B=Date.now()+3200}).add([22,18,82],(a,i)=>{let d=e.chRedir(0,i,!0);for(let s=0;s<16;s++)e.#k.ano(d+s),s&&s<10&&(e.#n[d+s]=te[s-1]);console.info("MT-32 alt reset complete.")}),this.#V.add([66,0],(a,i)=>{e.switchMode("ns5r",!0),e.#m=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,i)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),e.#m=!1}).add([66,18,0,0],(a,i)=>{let d=a[0];switch(d){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#m=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(d<10){let s=[0,0,0,0],r=(l,f)=>{s[f]=l};if(a.subarray(1).forEach((l,f)=>{[r,r,r,r,()=>{e.#f=l*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},()=>l-64,()=>l-64,()=>{},()=>{},()=>{}][d+f]()}),a[0]<4){let l=0;s.forEach(f=>{l=l<<4,l+=f}),l-=1024}}}}).add([66,18,0,1],(a,i)=>{}).add([66,18,0,2],(a,i)=>{}).add([66,18,1],(a,i)=>{let d=e.chRedir(a[0],i,!0),s=d*m.cc,r=a[1],l=`NS5R CH${d+1} `;a.subarray(2).forEach((f,o)=>{let b=r+o;b<3?([()=>{e.#e[s+g[0]]=f||121},()=>{e.#e[s+g[32]]=f},()=>{e.#n[d]=f}][b](),e.dispatchEvent("voice",{part:d})):b<8||(b<14?[()=>{let y=e.chRedir(f,i,!0);e.#p[d]=y,d!=y&&(e.buildRchTree(),console.info(`${l}receives from CH${y+1}`))},()=>{e.#b[d]=+!f},()=>{e.setChType(d,f,w.ns5r),console.debug(`${l}type: ${X[f]}`)},()=>{e.#r[m.rpn*d+3]=f,e.#s[m.rpnt*d+2]=1},()=>{},()=>{}][b-8]():b<16||(b<33?[()=>{e.#e[s+g[7]]=f},()=>{e.#e[s+g[11]]=f},()=>{},()=>{},()=>{e.#e[s+g[10]]=f||128},()=>{},()=>{},()=>{e.#e[s+g[93]]=f},()=>{e.#e[s+g[91]]=f},()=>{e.#e[s+g[76]]=f},()=>{e.#e[s+g[77]]=f},()=>{e.#e[s+g[78]]=f},()=>{e.#e[s+g[74]]=f},()=>{e.#e[s+g[71]]=f},()=>{e.#e[s+g[73]]=f},()=>{e.#e[s+g[75]]=f},()=>{e.#e[s+g[72]]=f}][b-16]():b<112||b<114&&[()=>{e.#e[s+g[5]]=f},()=>{e.#e[s+g[65]]=f}][b-112]()))})}).add([66,18,8,0],(a,i)=>{let d=a[0];if(d<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let s=d-32;e.#w=Date.now()+3200,e.#u=10,e.#y.fill(0);let r=a.subarray(1),l=4;r.forEach(function(f,o){let b=o+s,y=b>>4,E=b&15;if(b<80){let $=y>3,x=0,B=y0;)e.#y[E*32+y*7+(B-x)]=$&1,$=$>>1,x++}})}}).add([66,18,48],(a,i,d)=>{c(0,a)}).add([66,18,49],(a,i,d)=>{c(1,a)}).add([66,18,50],(a,i,d)=>{c(2,a)}).add([66,18,51],(a,i,d)=>{c(3,a)}).add([66,18,52],(a,i,d)=>{c(4,a)}).add([66,18,53],(a,i,d)=>{c(5,a)}).add([66,18,54],(a,i,d)=>{c(6,a)}).add([66,18,55],(a,i,d)=>{c(7,a)}).add([66,52],(a,i)=>{e.switchMode("ns5r",!0),e.#m=!1;let d="";O(a,(s,r)=>{r<8?(s>31&&(d+=String.fromCharCode(s)),r==7&&(e.aiEfxName=d)):r<10&&(e.setEffectType(r-8,44,s),e.dispatchEvent(`efx${["reverb","chorus"][r-8]}`,e.getEffectType(r-8)))})}).add([66,53],(a,i)=>{e.switchMode("ns5r",!0),e.#m=!1,O(a,function(d,s){switch(!0){case s<2944:{let r=e.chRedir(Math.floor(s/92),i,!0),l=r*m.cc;switch(s%92){case 0:{e.#e[l+g[0]]=d||121,e.dispatchEvent("voice",{part:r});break}case 1:{e.#e[l+g[32]]=d,e.dispatchEvent("voice",{part:r});break}case 2:{e.#n[r]=d,d>0&&e.setChActive(r,1),e.dispatchEvent("voice",{part:r});break}case 3:{let f=e.chRedir(d,i,!0);e.#p[r]=f,r!=f&&(console.info(`NS5R CH${r+1} receives from CH${f+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#r[r*m.rpn+3]=d<40||d>88?d+(d>63?-192:64):d,e.#s[m.rpnt*r+2]=1;break}case 9:case 10:{e.#e[l+g[7]]=d;break}case 11:{e.#e[l+g[11]]=d;break}case 14:{e.#e[l+g[10]]=d||128;break}case 19:{e.#e[l+g[93]]=d;break}case 20:{e.#e[l+g[91]]=d;break}case 84:{e.#e[l+g[65]]=d;break}case 85:{e.#e[l+g[5]]=d;break}}break}case s<3096:break;case s<3134:break;case s<8566:break}})}).add([66,54],(a,i)=>{e.switchMode("ns5r",!0);let d="",s=80,r=0,l=0,f="MSB PRG LSB NME";O(a,function(o,b){let y=b%158;switch(!0){case y<10:{o>31&&(d+=String.fromCharCode(o));break}case y==11:{s=o&127;break}case y==12:{l=o&127;break}case y==13:{f+=` -${s} ${r} ${l} ${d.trim().replace("Init Voice","")}`,r++,d="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([66,55],(a,i)=>{e.switchMode("ns5r",!0);let d="",s=88,r=0,l=0,f="MSB PRG LSB NME";O(a,function(o,b){let y=b%126;switch(!0){case y<10:{o>31&&(d+=String.fromCharCode(o));break}case y==11:break;case y==12:break;case y==13:{f+=` -${s} ${r} ${l} ${d.trim().replace("Init Combi","")}`,r++,d="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let i=new Uint8Array(5760);O(a,(d,s,r)=>{if(s<720)for(let l=0;l<8;l++)i[s*8+l]=d>>7-l&1}),e.dispatchEvent("screen",{type:"ns5r",data:i})}).add([76],(a,i,d)=>{e.#V.run([66,...a],i,d)}),this.#j.add([16,0,8,0],(a,i,d)=>{let s=(a[2]<<4)+a[3],r="K11 ";([()=>{e.switchMode("k11",!0),e.#m=!1,e.#C=s?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,s),console.debug(`${r}reverb type: ${s}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${r}reverb time: ${s}`)},()=>{console.debug(`${r}reverb time: ${s}`)},()=>{console.debug(`${r}reverb predelay: ${s}`)},()=>{console.debug(`${r}reverb predelay: ${s}`)},()=>{console.debug(`${r}depth high: ${s}`)},()=>{console.debug(`${r}depth high: ${s}`)},()=>{console.debug(`${r}depth low: ${s}`)},()=>{console.debug(`${r}depth low: ${s}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,i,d)=>{let s=e.chRedir(a[1],i,!0),r=m.cc*s,l=m.rpn*s,f=(a[3]<<4)+a[4],o=`K11 CH${s+1} `;([()=>{f<128?(e.setChType(s,e.CH_MELODIC,w.k11),e.#e[r+g[0]]=0,e.#n[s]=f):(e.setChType(s,e.CH_DRUMS,w.k11),e.#n[s]=f-128),e.dispatchEvent("voice",{part:s})},()=>{let b=e.chRedir(f,i,!0);e.#p[s]=b,s!=b&&(e.buildRchTree(),console.info(`${o}receives from CH${b+1}`))},()=>{e.#e[r+g[7]]=f},()=>{uupThis.setChActive(s,f)},()=>{e.#e[r+g[10]]=f},()=>{e.#r[l+3]=f+40,e.#s[m.rpnt*s+2]=1},()=>{e.#r[l+1]=f>>1,e.#r[l+2]=f&1,e.#s[m.rpnt*s+1]=1},()=>{e.#e[r+g[91]]=f?127:0},()=>{},()=>{e.#e[r+g[74]]=f},()=>{e.#e[r+g[73]]=f},()=>{e.#e[r+g[72]]=f}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,i,d)=>{let s=(a[2]<<4)+a[3],r="GMLX ";([()=>{console.debug(`${r}reverb type: ${s}`)},()=>{console.debug(`${r}reverb time: ${s}`)},()=>{console.debug(`${r}reverb predelay: ${s}`)},()=>{console.debug(`${r}depth high: ${s}`)},()=>{console.debug(`${r}depth low: ${s}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,i,d)=>{let s=(a[2]<<4)+a[3],r=e.chRedir(a[1],i,!0),l=r*m.cc;[()=>{s<128?(e.setChType(r,e.CH_MELODIC,w.k11),e.#e[l+g[0]]=0,e.#e[l+g[32]]=0,e.#n[r]=s):s<160?(e.setChType(r,e.CH_MELODIC,w.k11),e.#e[l+g[0]]=0,e.#e[l+g[32]]=7,e.#n[r]=s-100):(e.setChType(r,e.CH_DRUMS,w.k11),e.#e[l+g[0]]=122,e.#e[l+g[32]]=0,e.#n[r]=s-160),e.dispatchEvent("voice",{part:r})},()=>{let f=e.chRedir(s,i,!0);e.#p[r]=f,r!=f&&(e.buildRchTree(),console.info(`GMLX CH${r+1} receives from CH${f+1}`))}][a[0]]()}).add([16,0,9,4],(a,i,d)=>{let s=(a[2]<<4)+a[3],r=e.chRedir(a[1],i,!0),l=r*m.cc,f=r*m.rpn,o=`GMLX CH${r+1} `;[()=>{e.setChActive(r,s)},()=>{e.#e[l+g[7]]=s},()=>{e.#e[l+g[10]]=s},()=>{e.#e[l+g[91]]=s?127:0},()=>{e.#r[f+3]=s+40,e.#s[m.rpnt*r+2]=1},()=>{e.#r[f+1]=s,e.#s[m.rpnt*r+1]=1},()=>{e.#r[f]=s,e.#s[m.rpnt*r]=1},()=>{}][a[0]]()}),this.#Z.add([66,93,64],(a,i,d)=>{let s=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{e.#f=s*129/16383*100,e.dispatchEvent("mastervolume",e.#f);break}case 5:{s-64;break}case 6:{console.debug(`SG global reverb: ${s?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(a[1]){case 48:{console.debug(`SG reverb type: ${J[s]}`);break}}break}default:if(a[0]>>4==1){let r=e.chRedir(a[0]&15,i,!0);if(a[1]==2){let l=e.chRedir(s,i,!0);e.#p[r]=l,r!=l&&(e.buildRchTree(),console.info(`SG CH${r+1} receives from CH${l+1}`))}else a[1]==19&&(e.#e[m.cc*r+g[7]]=s)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),this.#J.add([9],(a,i,d)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),this.#A.add([127,0],(a,i,d)=>{e.switchMode("motif");let s=new Uint8Array([127,1,...a]);e.#A.run(s,i,d)}).add([127,1,0,0],(a,i,d)=>{e.switchMode("s90es");let s="S90/Motif ES system ",r=a[0];a.subarray(1).forEach((l,f)=>{([()=>{e.#f=l*12900/16383,e.dispatchEvent("mastervolume",e.#f)}][r+f]||(()=>{console.info(`Unrecognized ${s}ID: ${r+f}`)}))()})}).add([127,1,0,0,14],(a,i,d)=>{e.switchMode("s90es");let s="S90/Motif ES bulk header ",r=[];r[95]=(l,f,o)=>{console.debug(`${s}multi edit buffer: ${l[1]}`)},(r[a[0]]||(()=>{console.info(`Unrecognized ${s}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,i,d)=>{e.switchMode("s90es");let s="S90/Motif ES bulk footer ",r=[];r[95]=(l,f,o)=>{console.debug(`${s}multi edit buffer: ${l[1]}`)},(r[a[0]]||(()=>{console.info(`Unrecognized ${s}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,i,d)=>{e.switchMode("s90es");let s=e.chRedir(a[0],i,!0),r=m.cc*s,l=a[1],f=`S90/Motif ES bulk CH${s<16?s+1:"U"+(s-95)} `;console.debug(f,a),!(a[0]>15)&&a.subarray(2).forEach((o,b)=>{([()=>{e.#e[r+g[0]]=o,e.dispatchEvent("voice",{part:s})},()=>{o&&e.setChActive(s,1),e.#e[r+g[32]]=o,e.setChType(s,[32,40].indexOf(o)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:s})},()=>{o&&e.setChActive(s,1),e.#n[s]=o,e.dispatchEvent("voice",{part:s})},()=>{let y=e.chRedir(o,i,!0);e.#p[s]=y,s!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))},()=>{e.#b[s]=o?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{e.#e[r+g[7]]=o},()=>{e.#e[r+g[10]]=o},!1,!1,!1,()=>{e.#e[r+g[91]]=o},()=>{e.#e[r+g[93]]=o},()=>{e.#e[r+g[94]]=o},()=>{e.#e[r+g[128]]=o},()=>{},()=>{e.#e[r+g[74]]=o},()=>{e.#e[r+g[71]]=o},!1,()=>{e.#e[r+g[65]]=o},()=>{e.#e[r+g[5]]=o},()=>{}][l+b]||(()=>{}))()})}).add([127,1,54,16],(a,i,d)=>{e.switchMode("s90es");let s=a[0];a.subarray(1).forEach((r,l)=>{let o=`S90/Motif ES EQ${(l>>2)+1} `;([()=>{let b=r-64},()=>{let b=N[r]},()=>{let b=r/10},()=>{let b=r}][s+l&3]||(()=>{}))()})}),this.#L.add([0,72,18,0,0,0,0],(a,i,d)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,i,d)=>{let s=a[0]>>5,r=a[0]&31;switch(s){case 0:{console.debug(`Unknown SD-90 global effects message: -%o`,a);break}case 1:{let l=e.chRedir(r,i,!0),f=a[1],o=l*m.cc;a.subarray(2).forEach((b,y)=>{let E=f+y;E<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[o+g[0]]=b,b){case 104:case 105:case 106:case 107:case 120:{e.#i[l]||e.setChType(l,e.CH_DRUMS);break}default:e.#i[l]&&e.setChType(l,e.CH_MELODIC)}e.dispatchEvent("voice",{part:l})},()=>{e.#e[o+g[32]]=b,e.dispatchEvent("voice",{part:l})},()=>{e.#n[l]=b,e.dispatchEvent("voice",{part:l})},()=>{e.#e[o+g[7]]=b},()=>{e.#e[o+g[10]]=b},()=>{},()=>{},()=>{b<2&&(e.#b[l]=b)},()=>{b<2&&(e.#e[o+g[68]]=b?127:0)},()=>{},()=>{b<2&&(e.#e[o+g[65]]=b?127:0)},()=>{e.#e[o+g[5]]=b&15<<4|e.#e[o+g[5]]&15},()=>{e.#e[o+g[5]]=b&15|(e.#e[o+g[5]]&240)>>4},()=>{e.#e[o+g[74]]=b},()=>{e.#e[o+g[71]]=b},()=>{e.#e[o+g[73]]=b},()=>{e.#e[o+g[72]]=b},0,0,0,0,0,0,0,()=>{e.#e[o+g[128]]=b},()=>{e.#e[o+g[93]]=b},()=>{e.#e[o+g[91]]=b},0,0,()=>{e.#e[o+g[75]]=b},()=>{e.#e[o+g[76]]=b},()=>{e.#e[o+g[77]]=b},()=>{e.#e[o+g[78]]=b}][E]||(()=>{}))():E<63||(E<64?e.#i[l]?e.#e[o+g[0]]=104|b:e.#e[o+g[0]]=96|b:console.debug(`Unknown SD-90 global CH${l+1} param setup message: -%o`,a))});break}case 2:{let l=e.chRedir(r,i,!0),f=a[1];console.debug(`Unknown SD-90 global CH${l+1} MIDI setup message: +`),a.slice(0,2)){case"@I":{this.#g=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:a.slice(2)?.trimLeft()});break}case"@K":{this.#g=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:a.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{this.#g=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:a.slice(2)?.trimLeft()});break}case"@T":{this.#g=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:a.slice(2)?.trimLeft()});break}case"@V":{this.#g=!0,this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:a.slice(2)?.trimLeft()});break}case"XF":{let i=a.slice(2).split(":");switch(i[0]){case"hd":{i.slice(1).forEach((d,s)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][s],data:d})});break}case"ln":{i.slice(1).forEach((d,s)=>{d.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][s],data:d})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:this.#g?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` +`).forEach((i,d)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:i,mask:d!=0})})}},this.#R[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},this.#R[3]=function(a,i){i<1&&this.#X<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},this.#R[4]=function(a,i){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},this.#R[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},this.#R[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},this.#R[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},this.#R[32]=function(a){this.#X=a[0]+1},this.#R[33]=function(a,i){e.#W[i]=a+1},this.#R[81]=function(a,i){e.#z=a/1e3},this.#R[127]=function(a,i){e.#Q.run(a,i)},this.#Q.default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},this.#Q.add([67,0,1],function(a,i){e.#W[i]=a[0]+1}),this.#Y=new D("universal non-realtime"),this.#j=new D("universal realtime"),this.#A=new D("Yamaha"),this.#L=new D("Roland"),this.#V=new D("Korg"),this.#Z=new D("Kawai"),this.#J=new D("Akai"),this.#ee=new D("Casio");let t=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,a)};this.#Y.default=t,this.#j.default=t,this.#A.default=t,this.#L.default=t,this.#V.default=t,this.#Z.default=t,this.#J.default=t,this.#ee.default=t,this.#Y.add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),e.#g=e.#g||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),this.#j.add([4,1],a=>{e.#f=((a[1]<<7)+a[0])/16383*100,e.dispatchEvent("mastervolume",e.#f)}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64),this.#A.add([76,0,0],a=>{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),e.#g=!1,console.info("MIDI reset: XG");break}default:{let i=[0,0,0,0],d=(s,r)=>{i[r]=s};if(a.subarray(1).forEach((s,r)=>{let c=r+a[0];([d,d,d,d,f=>{this.#f=f*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},f=>{},f=>{}][c]||(()=>{}))(s,r)}),a[0]<4){let s=0;i.forEach(r=>{s=s<<4,s+=r}),s-=1024}}}}).add([76,2,1],a=>{let i="XG ";a[0]<32?(i+="reverb ",a.subarray(1).forEach((d,s)=>{([r=>{e.setEffectTypeRaw(0,!1,r),console.info(`${i}main type: ${G[r]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},r=>{e.setEffectTypeRaw(0,!0,r),console.debug(`${i}sub type: ${r+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},r=>{console.debug(`${i}time: ${ge(r)}s`)},r=>{console.debug(`${i}diffusion: ${r}`)},r=>{console.debug(`${i}initial delay: ${r}`)},r=>{console.debug(`${i}HPF cutoff: ${N[r]}Hz`)},r=>{console.debug(`${i}LPF cutoff: ${N[r]}Hz`)},r=>{console.debug(`${i}width: ${r}`)},r=>{console.debug(`${i}height: ${r}`)},r=>{console.debug(`${i}depth: ${r}`)},r=>{console.debug(`${i}wall type: ${r}`)},r=>{console.debug(`${i}dry/wet: ${r}`)},r=>{console.debug(`${i}send: ${C(r)}dB`)},r=>{console.debug(`${i}pan: ${r-64}`)},!1,!1,r=>{console.debug(`${i}delay: ${r}`)},r=>{console.debug(`${i}density: ${r}`)},r=>{console.debug(`${i}balance: ${r}`)},r=>{},r=>{console.debug(`${i}feedback: ${r}`)},r=>{}][a[0]+s]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(d)})):a[0]<64?(i+="chorus ",a.subarray(1).forEach((d,s)=>{([r=>{e.setEffectTypeRaw(1,!1,r),console.info(`${i}main type: ${G[r]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},r=>{e.setEffectTypeRaw(1,!0,r),console.debug(`${i}sub type: ${r+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},r=>{console.debug(`${i}LFO: ${be[r]}Hz`)},r=>{},r=>{console.debug(`${i}feedback: ${r}`)},r=>{console.debug(`${i}delay offset: ${me(r)}ms`)},r=>{},r=>{console.debug(`${i}low: ${N[r]}Hz`)},r=>{console.debug(`${i}low: ${r-64}dB`)},r=>{console.debug(`${i}high: ${N[r]}Hz`)},r=>{console.debug(`${i}high: ${r-64}dB`)},r=>{console.debug(`${i}dry/wet: ${r}`)},r=>{console.debug(`${i}send: ${C(r)}dB`)},r=>{console.debug(`${i}pan: ${r-64}`)},r=>{console.debug(`${i}to reverb: ${C(r)}dB`)},!1,r=>{},r=>{},r=>{},r=>{console.debug(`${i}LFO phase diff: ${(r-64)*3}deg`)},r=>{console.debug(`${i}input mode: ${r?"stereo":"mono"}`)},r=>{}][a[0]-32+s]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(d)})):a[0]<86?(i+="variation ",a.subarray(1).forEach((d,s)=>{([r=>{e.setEffectTypeRaw(2,!1,r),console.info(`${i}main type: ${G[r]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},r=>{e.setEffectTypeRaw(2,!0,r),console.debug(`${i}sub type: ${r+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+s]||function(){})(d)})):a[0]<97?(i+="variation ",a.subarray(1).forEach((d,s)=>{[r=>{console.debug(`${i}send: ${C(r)}dB`)},r=>{console.debug(`${i}pan: ${r-64}`)},r=>{console.debug(`${i}to reverb: ${C(r)}dB`)},r=>{console.debug(`${i}to chorus: ${C(r)}dB`)},r=>{console.debug(`${i}connection: ${r?"system":"insertion"}`)},r=>{console.debug(`${i}channel: CH${r+1}`)},r=>{console.debug(`${i}mod wheel: ${r-64}`)},r=>{console.debug(`${i}bend wheel: ${r-64}`)},r=>{console.debug(`${i}channel after touch: ${r-64}`)},r=>{console.debug(`${i}AC1: ${r-64}`)},r=>{console.debug(`${i}AC2: ${r-64}`)}][a[0]-86+s](d)})):a[0]>111&&a[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((i,d)=>{let s=d+a[0];if(s==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let r=s-1>>2,c=s-1&3,f=`XG EQ ${r} ${["gain","freq","Q","shape"][c]}: `;[()=>{console.debug(`${f}${i-64}dB`)},()=>{console.debug(`${f}${i} (raw)`)},()=>{console.debug(`${f}${i/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!i]}`)}][c]()}})}).add([76,3],a=>{let i=a[0],d=a[1],s=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((r,c)=>{([f=>{e.setEffectTypeRaw(3+i,!1,f),console.info(`${s}main type: ${G[f]}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))},f=>{e.setEffectTypeRaw(3+i,!0,f),console.debug(`${s}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))}][d+c]||function(){})(r)})}).add([76,6,0],a=>{let i=a[0];i<64?e.setLetterDisplay(a.subarray(1),"XG letter display",i):e.#N=Date.now()}).add([76,7,0],a=>{let i=a[0];e.#h=0,e.#E=Date.now()+3200,e.#m.fill(0);let d=a.subarray(1);for(let s=0;s>6-y&1,y++})}).add([76,8],(a,i)=>{let d=e.chRedir(a[0],i,!0),s=a[1],r=m.cc*d,c=`XG CH${d+1} `,f=`Unknown XG part address ${s}.`;a.subarray(2).forEach((o,b)=>{s<1?console.debug(f):s<41?([()=>{e.#e[r+g[0]]=o,e.dispatchEvent("voice",{part:d})},()=>{e.#e[r+g[32]]=o,e.dispatchEvent("voice",{part:d})},()=>{e.#n[d]=o,e.dispatchEvent("voice",{part:d})},()=>{let y=e.chRedir(o,i,!0);e.#u[d]=y,d!=y&&(e.buildRchTree(),console.info(`${c}receives from CH${y+1}`))},()=>{e.#p[d]=+!o},()=>{},()=>{e.setChType(d,o,w.xg),console.debug(`${c}type: ${X[o]||o}`)},()=>{e.#r[m.rpn*d+3]=o,e.#i[m.rpnt*d+2]=1},!1,!1,()=>{e.#e[r+g[7]]=o},!1,!1,()=>{e.#e[r+g[10]]=o||128},!1,!1,()=>{e.#e[r+g[128]]=o},()=>{e.#e[r+g[93]]=o},()=>{e.#e[r+g[91]]=o},()=>{e.#e[r+g[94]]=o},()=>{e.#e[r+g[76]]=o},()=>{e.#e[r+g[77]]=o},()=>{e.#e[r+g[78]]=o},()=>{e.#e[r+g[74]]=o},()=>{e.#e[r+g[71]]=o},()=>{e.#e[r+g[73]]=o},()=>{e.#e[r+g[75]]=o},()=>{e.#e[r+g[72]]=o}][s+b-1]||(()=>{}))():s<48?console.debug(f):s<111?s>102&&s<105&&(e.#e[r+g[[5,65][s&1]]]=o):s<114?console.debug(f):s<116?console.debug(`${c}EQ ${["bass","treble"][s&1]} gain: ${o-64}dB`):s<118?console.debug(f):s<120?console.debug(`${c}EQ ${["bass","treble"][s&1]} freq: ${o}`):console.debug(f)})}).add([76,9],(a,i)=>{let d=e.chRedir(a[0],i,!0),s=a[1],r=`PLG-150VL CH${d+1} `;a.subarray(2).forEach((c,f)=>{let o=f+s;switch(o){case 1:{console.info(`${r}breath mode: ${["system","breath","velocity","touch EG"][c]}`);break}case 0:case 27:case 28:break;default:if(o<27){let b=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][o-3>>1];o&1?o<23?(console.debug(`${r}${b} control source: ${Ee(c)}`),c&&c<96&&e.allocateAce(c)):console.debug(`${r}${b} scale break point: ${c}`):console.debug(`${r}${b} depth: ${c-64}`)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][a[0]]} for CH${a[2]+1}.`)}).add([73,0,0],(a,i)=>{let d=a[0],s="MU1000 System: ";a.subarray(1).forEach((r,c)=>{let f=d+c;f==8?console.debug(`${s}LCD contrast set to ${r}.`):f==18?(e.#M=r?126:0,console.debug(`${s}bank defaults to ${r?"MU100 Native":"MU Basic"}.`)):f>=64&&f<69&&[()=>{e.dispatchEvent("channelactive",r)},()=>{r<8?(e.dispatchEvent("channelmin",r<<4),console.debug(`Octavia System: Minimum CH${(r<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{r<8?(e.dispatchEvent("channelmax",(r<<4)+15),console.debug(`Octavia System: Maximum CH${(r<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#B=!!r,console.info(`Octavia System: RS receiving ${["dis","en"][r]}abled.`)}][f-64]()})}).add([73,10,0],(a,i)=>{let d=a[0],s=`MU1000 RS${e.#B?"":" (ignored)"}: `;if(d<16)switch(d){case 2:{let r=e.chRedir(0,i,!0);e.#B&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+63)),console.info(`${s}Show CH1~64`);break}case 3:{let r=e.chRedir(a[1]<<5,i,!0);e.#B&&e.dispatchEvent("channelmin",r),e.#B&&e.dispatchEvent("channelmax",r+31),console.info(`${s}Show CH${r+1}~CH${r+32}`);break}default:console.debug(`${s}unknown switch ${d} invoked.`)}else if(d<32){if(e.#B){let r=e.chRedir(d-16+(e.#F<<4),i,!0);e.dispatchEvent("channelactive",r)}}else if(d<36){let r=e.chRedir(d-32<<4,i,!0);e.#B&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+15),e.#F=d-32),console.info(`${s}Show CH${r+1}~CH${r+16}`)}}).add([93,3],(a,i)=>{let d=e.chRedir(a[0],i,!0),s=`PLG-100SG CH${d+1} `,r=Date.now();if(a[1]==0){let c="",f=0;a.subarray(2).forEach((o,b)=>{b%2==0?c+=ye[o]||o.toString().padStart("0"):f+=o*13}),r>=e.#U&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${ve(c)}`,amend:!0}),e.#U=r+Math.ceil(f/2)+e.#z,k()&&console.debug(`${s}vocals: ${c}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)});let n=function(a,i,d,s){},l=function(a,i){let d=a*m.dpn,s=i[0],r=i[1];i.subarray(2).forEach((c,f)=>{let o=f+r,b=-1;o<16?([()=>{b=24},()=>{b=25},()=>{b=26},()=>{},()=>{b=28},()=>{b=29},()=>{b=30},()=>{b=31},()=>{},()=>{},()=>{},()=>{b=20},()=>{b=21},()=>{b=22},()=>{b=23},()=>{}][o]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${a+1}.`)}))():o<32||(o<40?([()=>{b=48},()=>{b=49},!1,!1,()=>{b=52},()=>{b=53}][o-32]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${a+1}.`)}))():o<80||([()=>{b=36}][o-80]||(()=>{console.debug(`Unknown XG-style drum param ${o} on set ${a+1}.`)}))()),b>=0?(k()&&console.debug(d,b,s,c),e.#x[(d+R[b])*m.dnc+s]=c):k()&&console.debug(`XG-style drum param ${o} has no writes.`)})},u=function(a,i,d){let s=a*m.dpn,r=(i<<7)+d[0];d.subarray(1).forEach((c,f)=>{let o=f+r,b=o&127,y=o>>7,E=-1;y>1&&([()=>{E=26},()=>{},()=>{E=28},()=>{E=29},()=>{E=30},()=>{},()=>{},()=>{E=31}][y-2]||(()=>{console.debug(`Unknown GS-style drum param ${y} on set ${a+1}.`)}))(),E>-1?(k()&&console.debug(s,E,b,c),e.#x[(s+R[E])*m.dnc+b]=c):k()&&console.debug(`GS-style drum param ${y} has no writes.`)})};this.#A.add([76,48],(a,i,d)=>{l(0,a)}).add([76,49],(a,i,d)=>{l(1,a)}).add([76,50],(a,i,d)=>{l(2,a)}).add([76,51],(a,i,d)=>{l(3,a)}).add([76,52],(a,i,d)=>{l(4,a)}).add([76,53],(a,i,d)=>{l(5,a)}).add([76,54],(a,i,d)=>{l(6,a)}).add([76,55],(a,i,d)=>{l(7,a)}),this.#A.add([89,0],(a,i,d)=>{if(e.eprom){let s=a[0],r=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);k()&&console.debug(`MU1000 EPROM trail to 0x${r.toString(16).padStart(6,"0")}, ${s} bytes.`);let c=e.eprom.data;a.subarray(4).forEach((f,o)=>{let b=o>>3,y=o&7;if(y==7)for(let E=0;E<7;E++)c[r+7*b+E]+=(f>>6-E&1)<<7;else c[r+7*b+y]=f})}}).add([89,1],(a,i,d)=>{let s=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];k()&&console.debug(`MU1000 EPROM jump to 0x${s.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=s)}).add([89,2],(a,i,d)=>{if(e.eprom){let s=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);k()&&console.debug(`MU1000 EPROM write to 0x${s.toString(16).padStart(6,"0")}.`);let r=e.eprom.data;a.subarray(4).forEach((c,f)=>{let o=f>>3,b=f&7;if(b==7)for(let y=0;y<7;y++)r[s+7*o+y]+=(c>>6-y&1)<<7;else r[s+7*o+b]=c})}}).add([89,3],(a,i,d)=>{}),this.#A.add([39,48],(a,i,d)=>{}).add([43,0,0],(a,i,d)=>{let s=[0,0,0,0],r=(c,f)=>{s[f]=c};if(a.subarray(1).forEach((c,f)=>{let o=f+a[0];[r,r,r,r,()=>{this.#f=c*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},()=>c-64,()=>c||128,()=>c,()=>c,()=>{console.debug(`TG300 variation on cc${c}.`)}][o](c,o)}),a[0]<4){let c=0;s.forEach(f=>{c=c<<4,c+=f}),c-=1024}}).add([43,1,0],(a,i,d)=>{}).add([43,2],(a,i,d)=>{let s=e.chRedir(a[0],i,!0),r=a[1],c=m.cc*s,f=`TG300 CH${s+1} `;a.subarray(2).forEach((o,b)=>{b<5?([()=>{},()=>{e.#e[c+g[0]]=o,e.dispatchEvent("voice",{part:s})},()=>{e.#e[c+g[32]]=o,e.dispatchEvent("voice",{part:s})},()=>{e.#n[s]=o,e.dispatchEvent("voice",{part:s})},()=>{let y=e.chRedir(o,i,!0);e.#u[s]=y,s!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))}][b+r]||(()=>{}))(o,b+r):b<21||(b<47?([()=>{e.#p[s]=+!o},()=>{},()=>{},()=>{e.#r[m.rpn*s+3]=o,e.#i[m.rpnt*s+2]=1},()=>{},()=>{e.#e[c+g[7]]=o},!1,!1,()=>{e.#e[c+g[10]]=o||128},!1,!1,()=>{console.debug(`${f} AC1 at cc${o}`)},()=>{console.debug(`${f} AC2 at cc${o}`)},()=>{e.#e[c+g[128]]=o},()=>{e.#e[c+g[93]]=o},()=>{e.#e[c+g[91]]=o},()=>{e.#e[c+g[94]]=o},()=>{e.#e[c+g[76]]=o},()=>{e.#e[c+g[77]]=o},()=>{e.#e[c+g[74]]=o},()=>{e.#e[c+g[71]]=o},()=>{e.#e[c+g[73]]=o},()=>{e.#e[c+g[75]]=o},()=>{e.#e[c+g[72]]=o},()=>{e.#e[c+g[78]]=o}][b+r-21]||(()=>{}))(o,b+r):b<95||([()=>{e.#e[c+g[65]]=o},()=>{e.#e[c+g[5]]=o}][b+r-95]||(()=>{}))(o,b+r))})}).add([43,7,0],(a,i,d)=>{let s=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",s)}).add([43,7,1],(a,i,d)=>{e.#h=0,e.#E=Date.now()+3200,e.#m.fill(0),a.forEach(function(s,r){let c=Math.floor(r/16),f=r%16,o=(f*3+c)*7,b=7,y=0;for(o-=f*5,c==2&&(b=2);y>6-y&1,y++})}),this.#L.add([66,18,0,0,127],(a,i,d)=>{e.switchMode("gs",!0),e.#e[m.cc*9]=120,e.#e[m.cc*25]=120,e.#e[m.cc*41]=120,e.#e[m.cc*57]=120,e.#M=3,e.#g=!1,e.#K.fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,i,d)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),e.#e[m.cc*9]=120,e.#e[m.cc*25]=120,e.#e[m.cc*41]=120,e.#e[m.cc*57]=120,e.#g=!1,e.#K.fill(0),console.info("MIDI reset: GS");break}default:{let s=[0,0,0,0],r=(c,f)=>{s[f]=c};if(a.subarray(1).forEach((c,f)=>{let o=f+a[0];[r,r,r,r,b=>{this.#f=b*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},b=>{},b=>{}][o](c,f)}),a[0]<4){let c=0;s.forEach(f=>{c=c<<4,c+=f}),c-=1024}}}}).add([66,18,64,1],a=>{let i=a[0];if(i<16){let d="".padStart(i," ");a.subarray(1).forEach((s,r)=>{d+=String.fromCharCode(Math.max(32,s))}),d=d.padEnd(16," "),console.debug(`GS patch name: ${d}`)}else i<48||(i<65?a.subarray(1).forEach((d,s)=>{let r=`GS ${i+s>55?"chorus":"reverb"} `;([()=>{console.info(`${r}type: ${J[d]}`),e.setEffectType(0,40,d),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${r}predelay: ${d}ms`)},()=>{console.info(`${r}type: ${we[d]}`),e.setEffectType(1,40,16+d),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${C(d)}`)},()=>{console.debug(`${r}to delay: ${C(d)}`)}][i+s-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?a.subarray(1).forEach((d,s)=>{let r="GS delay ";([()=>{console.info(`${r}type: ${$e[d]}`),e.setEffectType(2,40,32+d),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${C(d)}`)}][i+s-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],a=>{let i="GS EQ ";a.subarray(1).forEach((d,s)=>{([()=>{console.debug(`${i}low freq: ${[200,400][d]}Hz`)},()=>{console.debug(`${i}low gain: ${d-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][d]}Hz`)},()=>{console.debug(`${i}high gain: ${d-64}dB`)}][a[0]+s]||function(){console.warn(`Unknown GS EQ address: ${a[0]+s}`)})()})}).add([66,18,64,3],a=>{let i="GS EFX ",d=function(s,r){let c=ke(e.#T.subarray(10,12),r,s);c&&console.debug(`${i}${ee(e.#T.subarray(10,12))} ${c}`)};a.subarray(1).forEach((s,r)=>{([()=>{e.setEffectTypeRaw(3,!1,32+s),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,s),console.info(`${i}type: ${ee(e.#T.subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,()=>{console.debug(`${i}to reverb: ${C(s)}dB`)},()=>{console.debug(`${i}to chorus: ${C(s)}dB`)},()=>{console.debug(`${i}to delay: ${C(s)}dB`)},!1,()=>{console.debug(`${i}1 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}1 depth: ${s-64}`)},()=>{console.debug(`${i}2 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}2 depth: ${s-64}`)},()=>{console.debug(`${i}to EQ: ${s?"ON":"OFF"}`)}][a[0]+r]||function(c,f){console.warn(`Unknown GS EFX address: ${f}`)})(s,a[0]+r)})}).add([66,18,65],a=>{u((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],a=>{switch(a[0]){case 0:{let i=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",i);break}case 32:{e.#E=Date.now()+3200,a[1]==0&&(e.#h=Math.max(Math.min(a[2]-1,9),0),k()&&console.debug(`GS switch display page ${a[2]-1}.`));break}default:if(a[0]<6){e.#h>9&&(e.#h=0);let i=a[0]-1<<1|a[1]>>6;e.#h==i&&(e.#E=Date.now()+3200),e.#o[i]?.length||(e.#o[i]=new Uint8Array(256));let d=e.#o[i];k()&&console.debug(`GS frame draw page ${i}.`);let s=a[1]&63;d.fill(0),a.subarray(2).forEach(function(c,f){let o=f+s,b=Math.floor(o/16),y=o%16,E=(y*4+b)*5,$=5,x=0;for(E-=y*4,b==3&&($=1);x<$;)d[E+x]=c>>4-x&1,x++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let p=function(a,i,d){let s=a[0],r=m.cc*i,c=m.rpn*i,f=`GS CH${i+1} `;s<3?(a.subarray(1).forEach((o,b)=>{[()=>{e.#e[r+g[0]]=o},()=>{e.#n[i]=o},()=>{let y=0;o<16?y=e.chRedir(o,d,!0):y=m.ch,e.#u[i]=y,i!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))}][s+b]()}),e.dispatchEvent("voice",{part:i})):s<19||(s<44?a.subarray(1).forEach((o,b)=>{([()=>{e.#p[i]=+!o},!1,()=>{e.setChType(i,o<<1,w.gs),console.debug(`${f}type: ${o?"drum ":"melodic"}${o||""}`)},()=>{e.#r[c+3]=o,e.#i[m.rpnt*i+2]=1},!1,()=>{e.#e[r+g[7]]=o},!1,!1,()=>{e.#e[r+g[10]]=o||128},!1,!1,()=>{console.debug(`${f}CC 1: cc${o}`)},()=>{console.debug(`${f}CC 2: cc${o}`)},()=>{e.#e[r+g[93]]=o},()=>{e.#e[r+g[91]]=o},!1,!1,()=>{e.#r[c+1]=o,e.#i[m.rpnt*i+1]=1},()=>{e.#r[c+2]=o,e.#i[m.rpnt*i+1]=1},()=>{e.#e[r+g[94]]=o}][s+b-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},h=function(a,i){let d=a[0],s=`GS CH${i+1} `;d<2?a.subarray(1).forEach((r,c)=>{[()=>{e.#e[m.cc*i+g[32]]=r},()=>{}][d+c]()}):d<32?console.warn(`Unknown GS misc address: ${d}`):d<35?a.subarray(1).forEach((r,c)=>{[()=>{console.debug(`${s}EQ: o${["ff","n"][r]}`)},()=>{},()=>{console.debug(`${s}EFX: o${["ff","n"][r]}`),e.#G[i]=r,e.dispatchEvent("partefxtoggle",{part:i,active:r})}][d+c-32]()}):console.warn(`Unknown GS misc address: ${d}`)};this.#L.add([66,18,64,16],(a,i)=>{p(a,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(a,i)=>{p(a,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(a,i)=>{p(a,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(a,i)=>{p(a,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(a,i)=>{p(a,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(a,i)=>{p(a,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(a,i)=>{p(a,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(a,i)=>{p(a,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(a,i)=>{p(a,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(a,i)=>{p(a,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(a,i)=>{p(a,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(a,i)=>{p(a,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(a,i)=>{p(a,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(a,i)=>{p(a,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(a,i)=>{p(a,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(a,i)=>{p(a,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(a,i)=>{h(a,e.chRedir(9,i,!0))}).add([66,18,64,65],(a,i)=>{h(a,e.chRedir(0,i,!0))}).add([66,18,64,66],(a,i)=>{h(a,e.chRedir(1,i,!0))}).add([66,18,64,67],(a,i)=>{h(a,e.chRedir(2,i,!0))}).add([66,18,64,68],(a,i)=>{h(a,e.chRedir(3,i,!0))}).add([66,18,64,69],(a,i)=>{h(a,e.chRedir(4,i,!0))}).add([66,18,64,70],(a,i)=>{h(a,e.chRedir(5,i,!0))}).add([66,18,64,71],(a,i)=>{h(a,e.chRedir(6,i,!0))}).add([66,18,64,72],(a,i)=>{h(a,e.chRedir(7,i,!0))}).add([66,18,64,73],(a,i)=>{h(a,e.chRedir(8,i,!0))}).add([66,18,64,74],(a,i)=>{h(a,e.chRedir(10,i,!0))}).add([66,18,64,75],(a,i)=>{h(a,e.chRedir(11,i,!0))}).add([66,18,64,76],(a,i)=>{h(a,e.chRedir(12,i,!0))}).add([66,18,64,77],(a,i)=>{h(a,e.chRedir(13,i,!0))}).add([66,18,64,78],(a,i)=>{h(a,e.chRedir(14,i,!0))}).add([66,18,64,79],(a,i)=>{h(a,e.chRedir(15,i,!0))}),this.#V.add([54,65],(a,i)=>{e.switchMode("x5d");let d=(a[1]<<7)+a[0],s=(a[3]<<7)+a[2],r=e.chRedir(d&15,i,!0),c=m.cc*r;[()=>{s<1||(s<101?(e.setChType(r,e.CH_MELODIC,w.x5d),e.#n[r]=s-1,e.#e[c+g[0]]=82):s<229?(e.setChType(r,e.CH_MELODIC,w.x5d),e.#n[r]=s-101,e.#e[c+g[0]]=56):(e.setChType(r,e.CH_DRUMS,w.x5d),e.#n[r]=Pe[s-229]||0,e.#e[c+g[0]]=62)),e.dispatchEvent("voice",{part:r})},()=>{e.#e[c+g[7]]=s},()=>{s<31&&(e.#e[c+g[10]]=Math.round((s-15)*4.2+64))},()=>{e.#e[c+g[93]]=_(s)},()=>{e.#e[c+g[91]]=_(s)},()=>{e.#r[r*m.rpn+3]=s>8191?s-16320:64+s,e.#i[m.rpnt*r+2]=1},()=>{e.#r[r*m.rpn+1]=s>8191?s-16320:64+s,e.#i[m.rpnt*r+1]=1},()=>{s>0&&(e.#r[r*m.rpn]=s,e.#i[m.rpnt*r]=1)},()=>{}][d>>4]()}).add([54,76,0],(a,i)=>{e.switchMode("x5d",!0);let d="",s=82,r=0,c=0,f="MSB PRG LSB NME";O(a,function(o,b){if(b<16400){let y=b%164;switch(!0){case y<10:{o>31&&(d+=String.fromCharCode(o));break}case y==11:{f+=` +${s} ${r} ${c} ${d.trim().replace("Init Voice","")}`,r++,d="";break}}r>99&&(s=90,r=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([54,77,0],(a,i)=>{e.switchMode("x5d",!0);let d="",s=90,r=0,c=0,f="MSB PRG LSB NME";O(a,function(o,b){if(b<13600){let y=b%136;switch(!0){case y<10:{o>31&&(d+=String.fromCharCode(o));break}case y==11:{f+=` +${s} ${r} ${c} ${d.trim().replace("Init Combi","")}`,r++,d="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([54,78],(a,i)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,i)=>{e.switchMode("x5d",!0),O(a,(d,s)=>{s>0&&s<3&&(e.setEffectType(s-1,44,d),e.dispatchEvent(`efx${["reverb","chorus"][s-1]}`,e.getEffectType(s-1)))})}).add([54,104],(a,i)=>{e.switchMode("x5d",!0),O(a,function(d,s,r,c){if(s<192){let f=e.chRedir(Math.floor(s/12),i,!0),o=f*m.cc;switch(s%12){case 0:{d<128?(e.setChType(f,e.CH_MELODIC,w.x5d),e.#e[o+g[0]]=82,e.#n[f]=d):(e.setChType(f,e.CH_DRUMS,w.x5d),e.#e[o+g[0]]=62,e.#n[f]=Pe[d-128]),d>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{e.#e[o+g[7]]=d;break}case 2:{e.#r[f*m.rpn+3]=d>127?d-192:64+d,e.#i[m.rpnt*f+2]=1;break}case 3:{e.#r[f*m.rpn+1]=d>127?d-192:64+d,e.#i[m.rpnt*f+1]=1;break}case 4:{d<31&&(e.#e[o+g[10]]=Math.round((d-15)*4.2+64));break}case 5:{let b=d>>4,y=d&15;e.#e[o+g[91]]=_(y),e.#e[o+g[93]]=_(b);break}case 10:break;case 11:{let b=e.chRedir(d&15,i,!0),y=d>>4;e.#u[f]=d,(b!=f||y)&&(console.info(`X5D Part CH${f+1} receives from CH${b+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(s-192,i,!0)}})}),this.#L.add([22,18,127],a=>{e.switchMode("mt32",!0),e.#g=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,i,d)=>{e.switchMode("mt32");let s=e.chRedir(d,i,!0),r=a[1];a.subarray(2).forEach((c,f)=>{let o=f+r;e.#$[o+(s-1)*16]=c,([!1,()=>{let b=e.#$[s-1<<4];if(b<3){if(e.#a[s]=1,b==2)for(let y=0;y{e.#r[s*m.rpn+3]=c+40,e.#i[m.rpnt*s+2]=1},()=>{e.#r[s*m.rpn+1]=c+14,e.#i[m.rpnt*s+1]=1},()=>{e.#r[s*m.rpn]=c,e.#i[m.rpnt*s]=1},!1,()=>{e.#e[m.cc*s+g[91]]=c?127:0},!1,()=>{e.#e[m.cc*s+g[7]]=c},()=>{e.#e[m.cc*s+g[10]]=Math.ceil(c*9.05)}][o]||(()=>{}))()})}).add([22,18,1],(a,i,d)=>{e.switchMode("mt32");let s=d&7;console.debug(`MT-32 slot #${d+1} Drum: ${a}`);let r=a[0]<<7|a[1];a.subarray(2).forEach((c,f)=>{let o=f+r,b=(o>>2)+24,y=o&3,E=s*m.dpn;if(k()&&console.debug(`MT-32 temp drum note ${b} param ${y}: ${c}`),b<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${b}`);return}[()=>{},()=>{e.#x[(E+R[26])*m.dnc+b]=Math.round(c*1.27)},()=>{e.#x[(E+R[26])*m.dnc+b]=c*9+1&127},()=>{e.#x[(E+R[26])*m.dnc+b]=c?127:0}][y]()})}).add([22,18,2],(a,i,d)=>{e.switchMode("mt32");let s=e.chRedir(d,i,!0),r=a[1]+(a[0]<<7);r<10&&(e.#a[s]=1),a.subarray(2).forEach((c,f)=>{let o=f+r;o<14&&(e.#c[(s-1)*m.cmt+o]=c)}),e.dispatchEvent("voice",{part:s})}).add([22,18,3],(a,i,d)=>{e.switchMode("mt32");let s=d&7;if(a[0]){let r=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((c,f)=>{let o=f+r,b=(o>>2)+24,y=o&3,E=s*m.dpn;if(k()&&console.debug(`MT-32 dev drum note ${b} param ${y}: ${c}`),b<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${b}`);return}[()=>{},()=>{e.#x[(E+R[26])*m.dnc+b]=Math.round(c*1.27)},()=>{e.#x[(E+R[26])*m.dnc+b]=c*9+1&127},()=>{e.#x[(E+R[26])*m.dnc+b]=c?127:0}][y]()})}else{let r=a[1];a.subarray(2).forEach((c,f)=>{let o=f+r;e.#$[o]=c;let b=e.chRedir(1+(o>>4),i,!0),y=o&15;([!1,()=>{let E=e.#$[b-1<<4];if(E<3)if(e.#a[b]=1,E==2)for(let $=0;${e.#r[b*m.rpn+3]=c+40,e.#i[m.rpnt*b+2]=1},()=>{e.#r[b*m.rpn+1]=c+14,e.#i[m.rpnt*b+1]=1},()=>{e.#r[b*m.rpn]=c,e.#i[m.rpnt*b]=1},!1,()=>{e.#e[m.cc*b+g[91]]=c?127:0},!1,()=>{e.#e[m.cc*b+g[7]]=c},()=>{e.#e[m.cc*b+g[10]]=Math.ceil(c*9.05)}][y]||(()=>{}))()})}}).add([22,18,4],(a,i,d)=>{e.switchMode("mt32");let s=a[1]+(a[0]<<7),r=[];a.subarray(2).forEach((c,f)=>{let o=f+s,b=e.chRedir(Math.floor(o/246+1),i,!0),y=o%246;y<14&&(e.#c[(b-1)*m.cmt+y]=c),y<10&&(e.#a[b]=1),r.indexOf(b)<0&&r.push(b)}),r.forEach(c=>{e.dispatchEvent("voice",{part:c})})}).add([22,18,5],(a,i,d)=>{e.switchMode("mt32");let s=(a[0]<<7)+a[1];a.subarray(2).forEach((r,c)=>{let f=s+c,o=Math.floor(f/8),b=f&7,y=o*8;e.#y[f]=r,([!1,()=>{let E=e.#y[y];if(E<3){let $="";if(E==2){let x=m.cmt*o;$=`MT-m:${r.toString().padStart(3,"0")}`}else $=e.baseBank.get(0,r+(E<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:o}),e.userBank.load(`MSB LSB PRG NME +000 127 ${o} ${$}`,!0)}}][b]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,i,d)=>{e.switchMode("mt32");let s=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((r,c)=>{let f=s+c;f>1)*m.cmt+f]=r)}),e.forceVoiceRefresh()}).add([22,18,16],(a,i,d)=>{e.switchMode("mt32");let s=a[1],r=!1,c=function(f,o){e.#u[o-12]=f,r=!0};a.subarray(2).forEach((f,o)=>{let b=o+s;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,c,c,c,c,c,c,c,c,c,()=>{e.#f=f,e.dispatchEvent("mastervolume",e.#f)}][b]||(()=>{}))(f,o)}),r&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let i=a[1],d=" ".repeat(i);a.subarray(2).forEach(s=>{s>31?d+=String.fromCharCode(s):d+=" "}),e.#_=d.padStart(20," "),e.#N=Date.now()+3200}).add([22,18,82],(a,i)=>{let d=e.chRedir(0,i,!0);for(let s=0;s<16;s++)e.#k.ano(d+s),s&&s<10&&(e.#n[d+s]=te[s-1]);console.info("MT-32 alt reset complete.")}),this.#V.add([66,0],(a,i)=>{e.switchMode("ns5r",!0),e.#g=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,i)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),e.#g=!1}).add([66,18,0,0],(a,i)=>{let d=a[0];switch(d){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#g=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(d<10){let s=[0,0,0,0],r=(c,f)=>{s[f]=c};if(a.subarray(1).forEach((c,f)=>{[r,r,r,r,()=>{e.#f=c*129/16383*100,e.dispatchEvent("mastervolume",e.#f)},()=>c-64,()=>c-64,()=>{},()=>{},()=>{}][d+f]()}),a[0]<4){let c=0;s.forEach(f=>{c=c<<4,c+=f}),c-=1024}}}}).add([66,18,0,1],(a,i)=>{}).add([66,18,0,2],(a,i)=>{}).add([66,18,1],(a,i)=>{let d=e.chRedir(a[0],i,!0),s=d*m.cc,r=a[1],c=`NS5R CH${d+1} `;a.subarray(2).forEach((f,o)=>{let b=r+o;b<3?([()=>{e.#e[s+g[0]]=f||121},()=>{e.#e[s+g[32]]=f},()=>{e.#n[d]=f}][b](),e.dispatchEvent("voice",{part:d})):b<8||(b<14?[()=>{let y=e.chRedir(f,i,!0);e.#u[d]=y,d!=y&&(e.buildRchTree(),console.info(`${c}receives from CH${y+1}`))},()=>{e.#p[d]=+!f},()=>{e.setChType(d,f,w.ns5r),console.debug(`${c}type: ${X[f]}`)},()=>{e.#r[m.rpn*d+3]=f,e.#i[m.rpnt*d+2]=1},()=>{},()=>{}][b-8]():b<16||(b<33?[()=>{e.#e[s+g[7]]=f},()=>{e.#e[s+g[11]]=f},()=>{},()=>{},()=>{e.#e[s+g[10]]=f||128},()=>{},()=>{},()=>{e.#e[s+g[93]]=f},()=>{e.#e[s+g[91]]=f},()=>{e.#e[s+g[76]]=f},()=>{e.#e[s+g[77]]=f},()=>{e.#e[s+g[78]]=f},()=>{e.#e[s+g[74]]=f},()=>{e.#e[s+g[71]]=f},()=>{e.#e[s+g[73]]=f},()=>{e.#e[s+g[75]]=f},()=>{e.#e[s+g[72]]=f}][b-16]():b<112||b<114&&[()=>{e.#e[s+g[5]]=f},()=>{e.#e[s+g[65]]=f}][b-112]()))})}).add([66,18,8,0],(a,i)=>{let d=a[0];if(d<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let s=d-32;e.#E=Date.now()+3200,e.#h=10,e.#m.fill(0);let r=a.subarray(1),c=4;r.forEach(function(f,o){let b=o+s,y=b>>4,E=b&15;if(b<80){let $=y>3,x=0,B=y0;)e.#m[E*32+y*7+(B-x)]=$&1,$=$>>1,x++}})}}).add([66,18,48],(a,i,d)=>{l(0,a)}).add([66,18,49],(a,i,d)=>{l(1,a)}).add([66,18,50],(a,i,d)=>{l(2,a)}).add([66,18,51],(a,i,d)=>{l(3,a)}).add([66,18,52],(a,i,d)=>{l(4,a)}).add([66,18,53],(a,i,d)=>{l(5,a)}).add([66,18,54],(a,i,d)=>{l(6,a)}).add([66,18,55],(a,i,d)=>{l(7,a)}).add([66,52],(a,i)=>{e.switchMode("ns5r",!0),e.#g=!1;let d="";O(a,(s,r)=>{r<8?(s>31&&(d+=String.fromCharCode(s)),r==7&&(e.aiEfxName=d)):r<10&&(e.setEffectType(r-8,44,s),e.dispatchEvent(`efx${["reverb","chorus"][r-8]}`,e.getEffectType(r-8)))})}).add([66,53],(a,i)=>{e.switchMode("ns5r",!0),e.#g=!1,O(a,function(d,s){switch(!0){case s<2944:{let r=e.chRedir(Math.floor(s/92),i,!0),c=r*m.cc;switch(s%92){case 0:{e.#e[c+g[0]]=d||121,e.dispatchEvent("voice",{part:r});break}case 1:{e.#e[c+g[32]]=d,e.dispatchEvent("voice",{part:r});break}case 2:{e.#n[r]=d,d>0&&e.setChActive(r,1),e.dispatchEvent("voice",{part:r});break}case 3:{let f=e.chRedir(d,i,!0);e.#u[r]=f,r!=f&&(console.info(`NS5R CH${r+1} receives from CH${f+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#r[r*m.rpn+3]=d<40||d>88?d+(d>63?-192:64):d,e.#i[m.rpnt*r+2]=1;break}case 9:case 10:{e.#e[c+g[7]]=d;break}case 11:{e.#e[c+g[11]]=d;break}case 14:{e.#e[c+g[10]]=d||128;break}case 19:{e.#e[c+g[93]]=d;break}case 20:{e.#e[c+g[91]]=d;break}case 84:{e.#e[c+g[65]]=d;break}case 85:{e.#e[c+g[5]]=d;break}}break}case s<3096:break;case s<3134:break;case s<8566:break}})}).add([66,54],(a,i)=>{e.switchMode("ns5r",!0);let d="",s=80,r=0,c=0,f="MSB PRG LSB NME";O(a,function(o,b){let y=b%158;switch(!0){case y<10:{o>31&&(d+=String.fromCharCode(o));break}case y==11:{s=o&127;break}case y==12:{c=o&127;break}case y==13:{f+=` +${s} ${r} ${c} ${d.trim().replace("Init Voice","")}`,r++,d="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([66,55],(a,i)=>{e.switchMode("ns5r",!0);let d="",s=88,r=0,c=0,f="MSB PRG LSB NME";O(a,function(o,b){let y=b%126;switch(!0){case y<10:{o>31&&(d+=String.fromCharCode(o));break}case y==11:break;case y==12:break;case y==13:{f+=` +${s} ${r} ${c} ${d.trim().replace("Init Combi","")}`,r++,d="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let i=new Uint8Array(5760);O(a,(d,s,r)=>{if(s<720)for(let c=0;c<8;c++)i[s*8+c]=d>>7-c&1}),e.dispatchEvent("screen",{type:"ns5r",data:i})}).add([76],(a,i,d)=>{e.#V.run([66,...a],i,d)}),this.#Z.add([16,0,8,0],(a,i,d)=>{let s=(a[2]<<4)+a[3],r="K11 ";([()=>{e.switchMode("k11",!0),e.#g=!1,e.#M=s?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,s),console.debug(`${r}reverb type: ${s}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${r}reverb time: ${s}`)},()=>{console.debug(`${r}reverb time: ${s}`)},()=>{console.debug(`${r}reverb predelay: ${s}`)},()=>{console.debug(`${r}reverb predelay: ${s}`)},()=>{console.debug(`${r}depth high: ${s}`)},()=>{console.debug(`${r}depth high: ${s}`)},()=>{console.debug(`${r}depth low: ${s}`)},()=>{console.debug(`${r}depth low: ${s}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,i,d)=>{let s=e.chRedir(a[1],i,!0),r=m.cc*s,c=m.rpn*s,f=(a[3]<<4)+a[4],o=`K11 CH${s+1} `;([()=>{f<128?(e.setChType(s,e.CH_MELODIC,w.k11),e.#e[r+g[0]]=0,e.#n[s]=f):(e.setChType(s,e.CH_DRUMS,w.k11),e.#n[s]=f-128),e.dispatchEvent("voice",{part:s})},()=>{let b=e.chRedir(f,i,!0);e.#u[s]=b,s!=b&&(e.buildRchTree(),console.info(`${o}receives from CH${b+1}`))},()=>{e.#e[r+g[7]]=f},()=>{uupThis.setChActive(s,f)},()=>{e.#e[r+g[10]]=f},()=>{e.#r[c+3]=f+40,e.#i[m.rpnt*s+2]=1},()=>{e.#r[c+1]=f>>1,e.#r[c+2]=f&1,e.#i[m.rpnt*s+1]=1},()=>{e.#e[r+g[91]]=f?127:0},()=>{},()=>{e.#e[r+g[74]]=f},()=>{e.#e[r+g[73]]=f},()=>{e.#e[r+g[72]]=f}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,i,d)=>{let s=(a[2]<<4)+a[3],r="GMLX ";([()=>{console.debug(`${r}reverb type: ${s}`)},()=>{console.debug(`${r}reverb time: ${s}`)},()=>{console.debug(`${r}reverb predelay: ${s}`)},()=>{console.debug(`${r}depth high: ${s}`)},()=>{console.debug(`${r}depth low: ${s}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,i,d)=>{let s=(a[2]<<4)+a[3],r=e.chRedir(a[1],i,!0),c=r*m.cc;[()=>{s<128?(e.setChType(r,e.CH_MELODIC,w.k11),e.#e[c+g[0]]=0,e.#e[c+g[32]]=0,e.#n[r]=s):s<160?(e.setChType(r,e.CH_MELODIC,w.k11),e.#e[c+g[0]]=0,e.#e[c+g[32]]=7,e.#n[r]=s-100):(e.setChType(r,e.CH_DRUMS,w.k11),e.#e[c+g[0]]=122,e.#e[c+g[32]]=0,e.#n[r]=s-160),e.dispatchEvent("voice",{part:r})},()=>{let f=e.chRedir(s,i,!0);e.#u[r]=f,r!=f&&(e.buildRchTree(),console.info(`GMLX CH${r+1} receives from CH${f+1}`))}][a[0]]()}).add([16,0,9,4],(a,i,d)=>{let s=(a[2]<<4)+a[3],r=e.chRedir(a[1],i,!0),c=r*m.cc,f=r*m.rpn,o=`GMLX CH${r+1} `;[()=>{e.setChActive(r,s)},()=>{e.#e[c+g[7]]=s},()=>{e.#e[c+g[10]]=s},()=>{e.#e[c+g[91]]=s?127:0},()=>{e.#r[f+3]=s+40,e.#i[m.rpnt*r+2]=1},()=>{e.#r[f+1]=s,e.#i[m.rpnt*r+1]=1},()=>{e.#r[f]=s,e.#i[m.rpnt*r]=1},()=>{}][a[0]]()}),this.#J.add([66,93,64],(a,i,d)=>{let s=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{e.#f=s*129/16383*100,e.dispatchEvent("mastervolume",e.#f);break}case 5:{s-64;break}case 6:{console.debug(`SG global reverb: ${s?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(a[1]){case 48:{console.debug(`SG reverb type: ${J[s]}`);break}}break}default:if(a[0]>>4==1){let r=e.chRedir(a[0]&15,i,!0);if(a[1]==2){let c=e.chRedir(s,i,!0);e.#u[r]=c,r!=c&&(e.buildRchTree(),console.info(`SG CH${r+1} receives from CH${c+1}`))}else a[1]==19&&(e.#e[m.cc*r+g[7]]=s)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),this.#ee.add([9],(a,i,d)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),this.#A.add([127,0],(a,i,d)=>{e.switchMode("motif");let s=new Uint8Array([127,1,...a]);e.#A.run(s,i,d)}).add([127,1,0,0],(a,i,d)=>{e.switchMode("s90es");let s="S90/Motif ES system ",r=a[0];a.subarray(1).forEach((c,f)=>{([()=>{e.#f=c*12900/16383,e.dispatchEvent("mastervolume",e.#f)}][r+f]||(()=>{console.info(`Unrecognized ${s}ID: ${r+f}`)}))()})}).add([127,1,0,0,14],(a,i,d)=>{e.switchMode("s90es");let s="S90/Motif ES bulk header ",r=[];r[95]=(c,f,o)=>{console.debug(`${s}multi edit buffer: ${c[1]}`)},(r[a[0]]||(()=>{console.info(`Unrecognized ${s}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,i,d)=>{e.switchMode("s90es");let s="S90/Motif ES bulk footer ",r=[];r[95]=(c,f,o)=>{console.debug(`${s}multi edit buffer: ${c[1]}`)},(r[a[0]]||(()=>{console.info(`Unrecognized ${s}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,i,d)=>{e.switchMode("s90es");let s=e.chRedir(a[0],i,!0),r=m.cc*s,c=a[1],f=`S90/Motif ES bulk CH${s<16?s+1:"U"+(s-95)} `;console.debug(f,a),!(a[0]>15)&&a.subarray(2).forEach((o,b)=>{([()=>{e.#e[r+g[0]]=o,e.dispatchEvent("voice",{part:s})},()=>{o&&e.setChActive(s,1),e.#e[r+g[32]]=o,e.setChType(s,[32,40].indexOf(o)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:s})},()=>{o&&e.setChActive(s,1),e.#n[s]=o,e.dispatchEvent("voice",{part:s})},()=>{let y=e.chRedir(o,i,!0);e.#u[s]=y,s!=y&&(e.buildRchTree(),console.info(`${f}receives from CH${y+1}`))},()=>{e.#p[s]=o?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{e.#e[r+g[7]]=o},()=>{e.#e[r+g[10]]=o},!1,!1,!1,()=>{e.#e[r+g[91]]=o},()=>{e.#e[r+g[93]]=o},()=>{e.#e[r+g[94]]=o},()=>{e.#e[r+g[128]]=o},()=>{},()=>{e.#e[r+g[74]]=o},()=>{e.#e[r+g[71]]=o},!1,()=>{e.#e[r+g[65]]=o},()=>{e.#e[r+g[5]]=o},()=>{}][c+b]||(()=>{}))()})}).add([127,1,54,16],(a,i,d)=>{e.switchMode("s90es");let s=a[0];a.subarray(1).forEach((r,c)=>{let o=`S90/Motif ES EQ${(c>>2)+1} `;([()=>{let b=r-64},()=>{let b=N[r]},()=>{let b=r/10},()=>{let b=r}][s+c&3]||(()=>{}))()})}),this.#L.add([0,72,18,0,0,0,0],(a,i,d)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,i,d)=>{let s=a[0]>>5,r=a[0]&31;switch(s){case 0:{console.debug(`Unknown SD-90 global effects message: +%o`,a);break}case 1:{let c=e.chRedir(r,i,!0),f=a[1],o=c*m.cc;a.subarray(2).forEach((b,y)=>{let E=f+y;E<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[o+g[0]]=b,b){case 104:case 105:case 106:case 107:case 120:{e.#s[c]||e.setChType(c,e.CH_DRUMS);break}default:e.#s[c]&&e.setChType(c,e.CH_MELODIC)}e.dispatchEvent("voice",{part:c})},()=>{e.#e[o+g[32]]=b,e.dispatchEvent("voice",{part:c})},()=>{e.#n[c]=b,e.dispatchEvent("voice",{part:c})},()=>{e.#e[o+g[7]]=b},()=>{e.#e[o+g[10]]=b},()=>{},()=>{},()=>{b<2&&(e.#p[c]=b)},()=>{b<2&&(e.#e[o+g[68]]=b?127:0)},()=>{},()=>{b<2&&(e.#e[o+g[65]]=b?127:0)},()=>{e.#e[o+g[5]]=b&15<<4|e.#e[o+g[5]]&15},()=>{e.#e[o+g[5]]=b&15|(e.#e[o+g[5]]&240)>>4},()=>{e.#e[o+g[74]]=b},()=>{e.#e[o+g[71]]=b},()=>{e.#e[o+g[73]]=b},()=>{e.#e[o+g[72]]=b},0,0,0,0,0,0,0,()=>{e.#e[o+g[128]]=b},()=>{e.#e[o+g[93]]=b},()=>{e.#e[o+g[91]]=b},0,0,()=>{e.#e[o+g[75]]=b},()=>{e.#e[o+g[76]]=b},()=>{e.#e[o+g[77]]=b},()=>{e.#e[o+g[78]]=b}][E]||(()=>{}))():E<63||(E<64?e.#s[c]?e.#e[o+g[0]]=104|b:e.#e[o+g[0]]=96|b:console.debug(`Unknown SD-90 global CH${c+1} param setup message: +%o`,a))});break}case 2:{let c=e.chRedir(r,i,!0),f=a[1];console.debug(`Unknown SD-90 global CH${c+1} MIDI setup message: %o`,a.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,a)}})}};var ne=je(Le(),1);var Ie=class{#t=!1;constructor(e,t,n,c){this.#t=e,this.start=t,this.end=n,this.data=c}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#t}},ie=class extends Ie{constructor(e,t,n){super(!0,e,t,n)}},Ue=class extends Ie{constructor(e,t){super(!1,e,e,t)}},se=class extends Array{#t=-1;constructor(){super(...arguments)}resetIndex(e){this.#t=-1}fresh(){this.sort(function(e,t){return e.start==t.start?0:(+(e.start>t.start)<<1)-1}),this.forEach(function(e,t){e.index=t})}step(e,t=!1){let n=[];if(t)for(let c=0;ce);c++){if(this[c].endu.#t&&(n.push(p),u.#t=p.index)})}return n}getRange(e,t){e>t&&([e,t]=[t,e]);let n=[],c=-1,u=Math.ceil(Math.sqrt(this.length)),p=!0;for(let h=0;h=e&&(c=h):c=c<0?h:c;for(;p;)this[c]?.end=e&&n.push(this[c]):p=!1,c++;return n}};var lt=0xffffffffffff,Ne=function(e){let t=new se,n=this,c=e.timeDivision,u=120,p=new se,h=0,a=0;p.push(new ie(0,lt,[120,0])),e.track.forEach(function(r){h=0,r.event.forEach(function(l){h+=l.deltaTime,l.type==255&&l?.metaType==81&&(u=6e7/l.data,p[p.length-1]&&p.push(new ie(h,0xffffffffffff,[u,0])))})}),p.fresh(),p.forEach(function(r,l,f){l>0&&(f[l-1].end=r.start)});let i=120;p.forEach(function(r,l,f){l>0&&(r.end==r.start?f.splice(f.indexOf(r),1):i==r.data[0]&&(f[l-1].end=r.end,f.splice(f.indexOf(r),1)),i=r.data[0])});let d=0,s=120;return p.forEach(function(r){let l=r.start,f=l/s/c*60+d;s=r.data[0],d=f-l/s/c*60,r.data[1]=d}),console.debug("All tempo changes: ",p),u=120,h=0,a=0,e.track.forEach(function(r,l){h=0,a=0;let f=l+1;r.event.forEach(function(o,b){h+=o.deltaTime;let y=p.step(h,!0)[0];y&&(u=y.data[0],a=y.data[1]);let E={type:o.type,data:o.data,track:f,part:0};o.type>14?E.meta=o.metaType:E.part=o.channel,t.push(new Ue(h/u/c*60+a,E))})}),t.fresh(),self.midiEvents=t,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),t};ne.default.customInterpreter=xe;var S=function(e,t,n){e.addEventListener(n,c=>{t.dispatchEvent(n,c.data)})},Be=class extends V{device;#t;#u={};#w=[];#o="";#y=[];#$=new Uint8ClampedArray(128);#p=new Uint8ClampedArray(128);#i=.5;#e=120;#d=4;#n=4;#c=0;#b=0;smoothingAtk=0;smoothingDcy=0;reset(){let e=this;e.dispatchEvent("reset"),e.#t?.resetIndex(),e.device.init(),e.#o="",e.#i=.5,e.#e=120,e.#d=4,e.#n=4,e.#c=0,e.#b=0,e.dispatchEvent("tempo",e.#e),e.dispatchEvent("title",e.#o)}init(){this.reset(),this.#t=void 0}async loadFile(e){this.#t=Ne(ne.default.parse(new Uint8Array(await e.arrayBuffer())))}async loadMap(e,t){let n=this,c=0,u=0,p=0,h,a;e.split(` -`).forEach((i,d)=>{if(!i)return;let s=i.split(" ");if(d){if(!p)return;let r="",l="";s.forEach((f,o)=>{switch(o){case h:{r=f;break}case a:{l=f;break}}}),!n.#u[r]||t?(n.#u[r]=l,c++):self.debugMode&&console.debug(`Voice "${l}" (${r}) seems to be in conflict with (${n.#u[r]}).`),u++}else s.forEach((r,l)=>{switch(r){case"ID":{h=l,p++;break}case"Name":{a=l,p++;break}default:console.debug(`Unknown map field: ${r}`)}})}),console.debug(`Map: ${u} total, ${c} loaded.`),n?.device.forceVoiceRefresh()}async loadEfx(e,t){let n=this,c=0,u=0,p,h,a;e.split(` -`).forEach((i,d)=>{if(i)if(d){let s=0,r;i.split(" ").forEach((l,f)=>{switch(f){case p:{s|=parseInt(l,16)<<8;break}case h:{s|=parseInt(l,16);break}case a:{r=l;break}}}),!n.#w[s]||t?(n.#w[s]=r,c++):self.debugMode&&console.debug(`EFX ID 0x${s.toString(16).padStart(4,"0")} (${r}) seems to be in conflict.`),u++}else i.split(" ").forEach((s,r)=>{switch(s){case"MSB":{p=r;break}case"LSB":{h=r;break}case"Name":{a=r;break}default:console.debug(`Unknown EFX field: ${s}`)}})}),console.debug(`EFX: ${u} total, ${c} loaded.`),n.dispatchEvent("efxreverb",n.device.getEffectType(0)),n.dispatchEvent("efxchorus",n.device.getEffectType(1)),n.dispatchEvent("efxdelay",n.device.getEffectType(2)),n.dispatchEvent("efxinsert0",n.device.getEffectType(3)),n.dispatchEvent("efxinsert1",n.device.getEffectType(4)),n.dispatchEvent("efxinsert2",n.device.getEffectType(5)),n.dispatchEvent("efxinsert3",n.device.getEffectType(6))}switchMode(e,t=!1){this.device.switchMode(e,t)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}getMapped(e){return this.#u[e]||e}getEfx([e,t]){let n=e<<8|t;return this.#w[n]||`0x${n.toString(16).padStart(4,"0")}`}get noteProgress(){return this.#b/this.#i}get noteOverall(){return this.noteProgress-this.#c}get noteBar(){return Math.floor(this.noteOverall/this.#d)}get noteBeat(){let e=this.noteOverall%this.#d;return e<0&&(e+=this.#d),e}getTimeSig(){return[this.#d,this.#n]}getTempo(){return this.#e}sendCmd(e){this.device.runJson(e)}render(e){e>this.#b&&(this.#b=e);let t=this.#t?.step(e)||[],n=0,c=new Set,u=this,p=[];this.device.getStrength().forEach((b,y)=>{this.#p[y]=b}),u.device.newStrength(),t.forEach(function(b){let y=b.data;y.type==9&&(y.data[1]>0?c.add(y.part*128+y.data[0]):c.has(y.part*128+y.data[0])&&n++),b.data.type==8&&c.has(y.part*128+y.data[0])&&n++;let E=u.device.runJson(y);switch(E?.reply){case"meta":{p.push(E);break}}E?.reply&&delete E.reply}),p?.length>0&&this.dispatchEvent("meta",p);let h=this.device.getActive(),a=[],i=u.device.getPitch(),d=u.device.getCcAll(),s=u.device.getProgram(),r=u.device.getChType(),l=this.device.getStrength();l.forEach(function(b,y,E){E[y]=Math.max(u.#p[y],b);let $=E[y]-u.#$[y],x=g.length*y;if($>=0){let B=4*.25**(d[x+g[73]]/64);u.#$[y]+=Math.ceil($-$*u.smoothingAtk**B)}else{let B=4*.25**(d[x+g[72]]/64);u.#$[y]+=Math.floor($-$*u.smoothingDcy**B)}});let f=0;return h.forEach(function(b,y){b&&(a[y]=u.device.getVel(y),f+=a[y].size)}),{extraPoly:n,curPoly:f,chInUse:h,chKeyPr:a,chPitch:i,chProgr:s,chContr:d,chType:r,eventCount:t.length,title:this.#o,bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:this.#$.slice(),velo:l,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce(),efxSink:this.device.getEffectSink()}}constructor(e,t=.5,n=.5){super();let c=this;c.smoothingAtk=t,c.smoothingDcy=n,c.device=e,c.addEventListener("meta",function(u){u?.data?.forEach(function(p){(c.#y[p.meta]||console.debug).call(c,p.meta,p.data)})}),S(c.device,c,"mode"),S(c.device,c,"mastervolume"),S(c.device,c,"channelactive"),S(c.device,c,"channelmin"),S(c.device,c,"channelmax"),S(c.device,c,"channelreset"),S(c.device,c,"channeltoggle"),S(c.device,c,"screen"),S(c.device,c,"metacommit"),S(c.device,c,"voice"),S(c.device,c,"pitch"),S(c.device,c,"note"),S(c.device,c,"reset"),S(c.device,c,"efxreverb"),S(c.device,c,"efxchorus"),S(c.device,c,"efxdelay"),S(c.device,c,"efxinsert0"),S(c.device,c,"efxinsert1"),S(c.device,c,"efxinsert2"),S(c.device,c,"efxinsert3"),S(c.device,c,"partefxtoggle"),c.#y[3]=function(u,p){c.#o?.length<1&&(c.#o=p,c.dispatchEvent("title",c.#o))},c.#y[81]=function(u,p){let h=c.noteProgress,a=c.#i||.5;c.#e=6e7/p,c.#i=p/1e6,c.#c+=h*(a/c.#i)-h,c.dispatchEvent("tempo",c.#e)},c.#y[88]=function(u,p){let h=c.noteProgress,a=c.noteOverall,i=c.noteBar,d=c.noteBeat,s=c.#d,r=c.#n;c.#d=p[0],c.#n=1<=s&&(s{ce&&(le[K]=!le[K],K++,K>34&&(K=0))},1e3/50);Uint8Array.prototype.render=function(e){let t=0,n=0,c=this.width||5,u=this.height||8;for(let p=0;p=c&&(t=0,n++)};var He=class{#t=[];async load(e,t=!1,n="(internal)"){let c=this,u=0,p=0;console.debug(`Font "${n||"(internal)"}": loading started.`),e.split(` -`).forEach(function(h,a){if(a>0&&h?.length>0){let i=h.split(" "),d=parseInt(i[0],16);if(p++,c.#t[d]&&!t)return;let s=new Uint8Array(40);Array.from(i[1]).forEach(async function(r,l){let f=l%2?4:0,o=Math.floor(l/2),b=parseInt(r,16),y=3;for(;b>0||y>=0;){let E=(f+y)*5+o;s[E]=b&1,b=b>>1,y--}}),c.#t[d]=s,u++}}),console.debug(`Font "${n||"(internal)"}": ${p} total, ${u} loaded.`)}async loadFile(e,t=!1){let n=this;console.debug(`Requested font file from "${e}".`),await n.load(await(await fetch(e)).text(),t,e),ce=!1}constructor(...e){ce=!0,(async()=>{for(let t=0;t{c.classList.add(s)});let{t:u,l:p,w:h,h:a,i,a:d}=n;return u?.constructor&&(c.style.top=u?.length?u:`${u}px`),p?.constructor&&(c.style.left=p?.length?p:`${p}px`),h?.constructor&&(c.style.width=h?.length?h:`${h}px`),a?.constructor&&(c.style.height=a?.length?a:`${a}px`),i?.constructor&&c.appendChild(document.createTextNode(i)),d?.constructor&&(c.style.textAlign=d),c},M=function(e,t){let n=document.createElementNS("http://www.w3.org/2000/svg",e);for(let c in t)n.setAttribute(c,t[c]);return n},T=function(e,t){t?.forEach(n=>{e.appendChild(n)})},L=function(e,t){t.forEach(n=>{e.classList.contains(n)&&e.classList.remove(n)})},U=function(e,t){t.forEach(n=>{e.classList.contains(n)||e.classList.add(n)})},_e=new Array(128).fill(0);_e.forEach((e,t,n)=>{n[t]=Math.floor(24*t/12.7)/10});var de=new Array(128).fill(0);de.forEach((e,t,n)=>{n[t]=Math.abs(Math.round(48*(t-64)/12.7)/10)});var Fe=new Array(11).fill(null);Fe.forEach((e,t,n)=>{n[t]=`${Math.round(t*12/.0128)/100}%`});var pt=new Array(128).fill(null);pt.forEach((e,t,n)=>{n[t]=`${Math.round(t/1.27)/100}`});var P=function(e,t){let n=_e[t];e.setAttribute("height",n),e.setAttribute("y",24-n)},Xe=function(e,t){e.innerText=t,e.rNew=!0;let n=e.measureText(t);e.rWidth=n.width},la=class extends Be{#t=128;#u=!1;#w="";#o;#y=0;#$=0;#p=0;#i=0;#e=1;#d=0;#n=new Uint8Array(1280);#c=new Uint8Array(1280);#b=new Uint8Array(1280);#g=new Uint8Array(512);#E=new Uint8Array(512);#R=new Uint8Array(512);#S;#G;#r;#s;#X="fcdaff";#a={};#v={};#l=[];#h={};#T={};#O=[];#x=[];#P="block";glyphs=new He;#I(e,t,n,c=0,u=0){let p=this,{width:h,height:a}=e.canvas,i,d,s,r,l=p.#e,f=c>3,o=ot.indexOf(t%12)>-1;switch(p.#P){case"block":case"comb":{i=Math.round(t*h/128),d=Math.round((t+1)*h/128),s=d-i,r=l==1?2:1;break}case"piano":{i=Math.round((Math.floor(t/12)*7+Ge[t%12])*h/75*1.0044642857142856),d=Math.round((Math.floor(t/12)*7+Ge[t%12]+1)*h/75*1.0044642857142856)-1,s=d-i,r=l==1?3:1;break}case"line":{let b=t-u;Math.abs(u)>2&&(b=t-Math.sign(u)*2),d=Math.round((t+.5)*h/128),i=Math.round((b+.5)*h/128)}default:}switch(e.fillStyle=`#${o?p.#X:"ffffff"}${(n<<1|n>>6).toString(16).padStart(2,"0")}`,e.strokeStyle=e.fillStyle,e.lineWidth=l==1?4:2,e.lineDashOffset=0,p.#P){case"block":{let b=e.canvas.height-1;e.fillRect(i,1,s,b),f&&e.clearRect(i+r,r+1,s-(r<<1),b-(r<<1));break}case"comb":{let b=(o?Math.round((e.canvas.height<<1)/3):e.canvas.height)-1;e.fillRect(i,1,s,b),f&&e.clearRect(i+r,r+1,s-(r<<1),b-(r<<1));break}case"piano":{let b=(o?0:e.canvas.height>>1)+1,y=(e.canvas.height>>1)-1;e.fillRect(i,b,s,y),f&&e.clearRect(i+r,b+r,s-(r<<1),y-(r<<1));break}case"line":{if(f)switch(l){case 4:{e.setLineDash(oe[2]);break}default:e.setLineDash(oe[1])}else e.setLineDash(oe[0]),l!=4&&self?.document?.mozFullScreen&&(i+=.5,d+=.5);e.beginPath(),e.moveTo(i,(l==4||!f)&&self?.document?.mozFullScreen?2:1),e.lineTo(d,(a>>1)+2),e.lineTo(i,a+2),e.stroke();break}default:}}#C(e,t){let n=this;(e?.chInUse||t).forEach((c,u)=>{if(c){let p=n.#l[u>>4][u&15].cxt;p.clearRect(0,0,p.canvas.width,p.canvas.height),e.chKeyPr[u].forEach(({v:h,s:a},i)=>{n.#I(p,i,h,a,n.device.getPitchShift(u))})}})}#f(e){let t=this;Date.now()-t.#y>4e3&&(t.#$=0,t.#p=142-t.#h.view.clientHeight,(t.#o?.clientWidth||0)>840&&(t.#$=840-t.#o.clientWidth),t.#h.view.style.transform=`translateX(${t.#$}px) translateY(${t.#p}px)`,e&&(t.#y=0))}#_(){let e=self.innerWidth/self.innerHeight,t=1,n=self.innerWidth,c=self.innerHeight;e>=W?(t=Math.round(self.innerHeight/1080*1e4)/1e4,n=Math.ceil(self.innerHeight*W)):e>4,f=r*m.cc,o=e.#l[l][r&15];if(n.chInUse[r]&&l>=e.#d&&lo.metre.canvas.width){o.metre.rNew&&(o.metre.rNew=!1,o.metre.rOffset=t);let y=t-(o.metre.rOffset||0),E=32,$=o.metre.rWidth-o.metre.canvas.width+E,x=y*-25%(o.metre.rWidth+E+48)+48;x>0&&(x=0),o.metre.fillText(o.metre.innerText,x,3),Math.abs(x)>$&&o.metre.fillText(o.metre.innerText,x+o.metre.rWidth+E,3)}else o.metre.fillText(o.metre.innerText,0,3);o.metre.globalCompositeOperation="xor",o.metre.fillRect(0,0,n.strength[r]*121/255,25);let b=n.chContr[f+g[10]];o.pan.setAttribute("width",`${de[b]||0}`),b<64?o.pan.setAttribute("x",`${84-de[b]}`):b>127?(o.pan.setAttribute("x","60"),o.pan.setAttribute("width","48")):o.pan.setAttribute("x","84")}}let h=new Set,a=new Set,i=new Array(m.ch),d={};if(e.#l.forEach((r,l)=>{r.forEach((f,o)=>{f.refresh&&(f.refresh=!1,i[l<<7|o]=!0)})}),["line"].indexOf(e.#P)>-1)for(;e.#x.length>0;){let r=e.#x.shift();i[r.part]=!0}for(;e.#O.length>0;){let r=e.#O.shift(),{part:l,note:f,velo:o,state:b}=r,y=l<<7|f;i[l]=!0,b==0?h.has(y)&&(a.add(y),e.#l[l>>4][l&15].refresh=!0):(h.add(y),d[y]=r)}e.#C(n,i),a.forEach(r=>{let{part:l,note:f,velo:o,state:b}=d[r],y=e.#l[l>>4][l&15].cxt;e.#I(y,f,o,b,e.device.getPitchShift(l))});let s=e.#T.cxt;c>n.bitmap.expire?e.#R.fill(0):n.bitmap.bitmap.length>256?n.bitmap.bitmap.forEach((r,l)=>{e.#R[l]=r?255:0}):n.bitmap.bitmap.forEach((r,l)=>{e.#R[l<<1]=r?255:0,e.#R[l<<1|1]=r?255:0}),e.#b.fill(0),c<=n.letter.expire&&e.glyphs.getStr(n.letter.text).forEach((r,l)=>{let f=(l&15)*5,o=l>>4<<3;r.forEach((b,y)=>{let E=f+y%5,$=o+Math.floor(y/5);e.#b[$*80+E]=b?255:0})}),e.#g.forEach((r,l,f)=>{let o=e.#R[l];o>r?f[l]+=Math.min(o-r,Q):o{let o=e.#b[l];o>r?f[l]+=Math.min(o-r,Q):o{let f=l>>5,o=l&31;e.#E[l]!=r?(s.clearRect(252+(o<<2),f<<2,3,3),r&&(s.fillStyle=`#ffffff${r.toString(16).padStart(2,"0")}`,s.fillRect(252+(o<<2),f<<2,3,3))):self.debugMode&&(s.clearRect(252+(o<<2),f<<2,3,3),r&&(s.fillStyle=`#ff0000${r.toString(16).padStart(2,"0")}`,s.fillRect(252+(o<<2),f<<2,3,3)))}),e.#n.forEach((r,l)=>{let f=Math.floor(l/80),o=l%80;o+=Math.floor(o/5),e.#c[l]!=r?(s.clearRect(o<<2,(f|16)<<2,3,3),r&&(s.fillStyle=`#ffffff${r.toString(16).padStart(2,"0")}`,s.fillRect(o<<2,(f|16)<<2,3,3))):self.debugMode&&(s.clearRect(o<<2,(f|16)<<2,3,3),r&&(s.fillStyle=`#ff0000${r.toString(16).padStart(2,"0")}`,s.fillRect(o<<2,(f|16)<<2,3,3)))}),e.#E.forEach((r,l,f)=>{f[l]=e.#g[l]}),e.#c.forEach((r,l,f)=>{f[l]=e.#n[l]})}#N;#B;get style(){return this.#P}set style(e){let t=this;t.#P=e,t.#C(t.render(t.#S?.currentTime||0)),L(t.#s,["cambiare-style-block","cambiare-style-comb","cambiare-style-piano","cambiare-style-line"]),U(t.#s,[`cambiare-style-${e}`])}setClockSource(e){this.#S=e}setMode(e){let t=this;L(t.#s,["cambiare-mode-gm","cambiare-mode-xg","cambiare-mode-gs","cambiare-mode-ns5r","cambiare-mode-05rw","cambiare-mode-x5d","cambiare-mode-k11","cambiare-mode-sg","cambiare-mode-g2","cambiare-mode-mt32","cambiare-mode-sd","cambiare-mode-krs","cambiare-mode-s90es","cambiare-mode-motif"]),e!="?"&&U(t.#s,[`cambiare-mode-${e}`]),t.#X={xg:"9efaa0",ns5r:"9efaa0",x5d:"9efaa0","05rw":"9efaa0",k11:"9efaa0",s90es:"9efaa0",motif:"9efaa0",gm:"a1f3ff",g2:"a1f3ff",krs:"a1f3ff",gs:"ffe1a5",mt32:"ffe1a5",sd:"ffe1a5",sg:"ffdddd"}[e]||"fcdaff"}#F(e){let t=this,n=t.#e,c=t.#d;t.#l.forEach((u,p)=>{if(p>=c&&p{d.root.style.top=`${s*(n>2?26:52)}px`})}else L(u.root,["port-active"]),u.root.style.top="",u.root.style.left="",u.forEach((h,a)=>{h.root.style.top=""});e&&u.forEach((h,a)=>{h.cxt.canvas.width=t.#e==1?1193:495,h.cxt.canvas.height=t.#e==4?26:52})})}setPort(e){let t=this;L(t.#s,["cambiare-start0","cambiare-start1","cambiare-start2","cambiare-start3","cambiare-start4","cambiare-start5","cambiare-start6","cambiare-start7"]),U(t.#s,[`cambiare-start${e}`]),t.#d=e,t.#F(!1)}setRange(e){let t=this;L(t.#s,["cambiare-port1","cambiare-port2","cambiare-port4","cambiare-compact"]),U(t.#s,[`cambiare-${e}`]),t.#e=parseInt(e.slice(4))||1,t.#F(!0)}attach(e){let t=this;t.#G=e;let n=v("div",["cambiare-container"]);e.appendChild(n),t.#r=n;let c=v("div",["cambiare-canvas","cambiare-port1","cambiare-start0","cambiare-style-block"]);n.appendChild(c),t.#s=c,self.addEventListener("resize",t.#U),t.#U(),t.#B=setInterval(t.#N,20),t.#a.root=v("div",["sect-info"]),t.#a.events=v("span",["field"],{t:1,l:0,w:35,h:33}),t.#a.curPoly=v("span",["field"],{t:1,l:52,w:35,h:33}),t.#a.maxPoly=v("span",["field"],{t:1,l:98,w:35,h:33}),t.#a.sigN=v("span",["field"],{t:1,l:194,w:23,h:33,a:"right"}),t.#a.sigD=v("span",["field"],{t:1,l:232,w:23,h:33}),t.#a.barCount=v("span",["field"],{t:1,l:304,w:35,h:33,a:"right"}),t.#a.barNote=v("span",["field"],{t:1,l:354,w:23,h:33}),t.#a.tempo=v("span",["field"],{t:1,l:454,w:64,h:33,a:"right"}),t.#a.volume=v("span",["field"],{t:1,l:562,w:63,h:33,a:"right"}),t.#a.mode=v("span",["field"],{t:1,l:708,w:152,h:33}),t.#a.reverb=v("span",["field"],{t:1,l:1e3,w:190,h:33}),t.#a.chorus=v("span",["field"],{t:1,l:1240,w:190,h:33}),t.#a.delay=v("span",["field"],{t:1,l:1475,w:190,h:33}),t.#a.insert=v("span",["field"],{t:1,l:1706,w:190,h:33}),t.#a.title=v("span",["field"],{t:35,l:50,w:810,h:33}),c.appendChild(t.#a.root),T(t.#a.root,[t.#a.events,t.#a.curPoly,v("span",["field","field-label"],{t:1,l:89,w:5,h:33,i:":"}),t.#a.maxPoly,v("span",["field","field-key"],{t:1,l:148,w:41,h:33,i:"TSig"}),t.#a.sigN,v("span",["field","field-label"],{t:0,l:221,w:8,h:33,i:"/"}),t.#a.sigD,v("span",["field","field-key"],{t:1,l:268,w:30,h:33,i:"Bar"}),t.#a.barCount,v("span",["field","field-label"],{t:0,l:343,w:8,h:33,i:"/"}),t.#a.barNote,v("span",["field","field-key"],{t:1,l:390,w:61,h:33,i:"Tempo",a:"right"}),t.#a.tempo,v("span",["field","field-key"],{t:1,l:528,w:29,h:33,i:"Vol"}),t.#a.volume,v("span",["field","field-label"],{t:1,l:626,w:17,h:33,i:"%"}),v("span",["field","field-key"],{t:1,l:652,w:52,h:33,i:"Mode"}),t.#a.mode,v("span",["field","field-key"],{t:1,l:960,w:34,h:33,i:"Rev"}),t.#a.reverb,v("span",["field","field-key"],{t:1,l:1198,w:36,h:33,i:"Cho"}),t.#a.chorus,v("span",["field","field-key"],{t:1,l:1438,w:31,h:33,i:"Var"}),t.#a.delay,v("span",["field","field-key"],{t:1,l:1673,w:27,h:33,i:"Ins"}),t.#a.insert,v("span",["field","field-key"],{t:35,l:0,w:44,h:33,i:"Title"}),t.#a.title]),t.#v.root=v("div",["sect-mark"]),t.#v.left=v("div",["sect-mark-left","boundary"],{t:0,l:0}),t.#v.right=v("div",["sect-mark-right","boundary"],{t:0,l:960}),c.appendChild(t.#v.root),T(t.#v.root,[t.#v.left,t.#v.right]),T(t.#v.left,[v("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),v("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),v("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),v("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),v("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),v("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),T(t.#v.right,[v("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),v("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),v("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),v("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),v("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),v("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),t.#l.root=v("div",["sect-part"]);for(let u=0;u>4;u++){let p=u<<4;t.#l[u]=[],t.#l[u].root=v("div",["boundary",`part-port-${u}`]);for(let h=0;h<16;h++){let a=(p|h)+1;a>=100?a=`${Math.floor(a/10).toString(16)}${a%10}`:a=`${a}`.padStart(2,"0"),t.#l[u][h]={root:v("div",["boundary","part-channel"]),major:v("div",["boundary","part-info-major"]),minor:v("div",["boundary","part-info-minor"],{t:26}),keys:v("div",["boundary","part-keys"]),notes:v("div",["boundary","part-keyboard"]),cxt:v("canvas",["field"]).getContext("2d"),number:v("span",["field","field-label"],{t:1,w:18,h:25,i:a}),voice:v("span",["field"],{l:22,t:1,w:121,h:25}),metre:v("canvas",["field"]).getContext("2d"),type:v("span",["field","field-label"],{t:1,w:18,h:25}),std:v("span",["field"],{l:22,t:1,w:20,h:25,a:"center"}),msb:v("span",["field"],{l:48,t:1,w:27,h:25}),prg:v("span",["field"],{l:81,t:1,w:27,h:25}),lsb:v("span",["field"],{l:114,t:1,w:27,h:25}),cc:M("svg",{viewBox:"0 0 108 24",width:108,style:"left: 146px; top: 1px; position: absolute;"}),vol:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:0}),exp:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:6}),mod:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:12}),rev:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:18}),cho:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:24}),var:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:30}),brt:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:36}),por:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:42}),cea:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:48}),ceb:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:54}),pan:M("rect",{fill:"var(--accent-color)",width:0,height:24,x:84})};let i=t.#l[u][h];Fe.forEach(d=>{i.notes.appendChild(v("span",["field","part-csplit"],{l:d}))}),i.notes.appendChild(v("span",["field","part-csplit","part-cdive"],{l:0,w:"100%",h:1})),i.metre.canvas.width=121,i.metre.canvas.height=25,i.metre.fillStyle="#fff",i.metre.textBaseline="top",i.metre.font="20px 'PT Sans Narrow'",T(i.notes,[i.cxt.canvas]),T(i.keys,[i.notes]),T(i.voice,[i.metre.canvas]),T(i.cc,[i.vol,i.exp,i.mod,i.rev,i.cho,i.var,i.brt,i.por,i.cea,i.ceb,i.pan,M("rect",{x:83,y:0,width:1,height:24,fill:"var(--foreground-color)"})]),T(i.major,[i.number,i.voice,i.cc]),T(i.minor,[i.type,i.std,i.msb,i.prg,i.lsb]),T(i.root,[i.major,i.minor,i.keys]),T(t.#l[u].root,[i.root])}t.#l.root.appendChild(t.#l[u].root)}c.appendChild(t.#l.root),t.#h.root=v("div",["sect-meta"]),t.#h.view=v("div",["boundary"]),c.appendChild(t.#h.root),T(t.#h.root,[t.#h.view]),t.#T.root=v("div",["sect-pix","boundary"],{l:1529,t:950,w:379,h:127}),t.#T.cxt=v("canvas",["field"]).getContext("2d"),t.#T.cxt.canvas.width=379,t.#T.cxt.canvas.height=127,T(t.#T.root,[t.#T.cxt.canvas]),c.appendChild(t.#T.root),t.addEventListener("mode",u=>{t.#a.mode.innerText=`${dt[u.data]}`,t.setMode(u.data)}),t.addEventListener("mastervolume",u=>{let p=Math.round(u.data*100)/100;t.#a.volume.innerText=`${Math.floor(p)}.${`${Math.floor(p%1*100)}`.padStart(2,"0")}`}),t.addEventListener("tempo",u=>{let p=Math.round(u.data*100);t.#a.tempo.innerText=`${Math.floor(p/100)}.${`${Math.floor(p%100)}`.padStart(2,"0")}`}),t.addEventListener("tsig",u=>{[t.#a.sigN.innerText,t.#a.sigD.innerText]=u.data}),t.addEventListener("title",u=>{t.#a.title.innerText=u.data||"No Title"}),t.addEventListener("voice",({data:u})=>{let p=t.getChVoice(u.part),h=t.#l[u.part>>4][u.part&15];Xe(h.metre,t.getMapped(p.name)),h.type.innerText=ct[t.device.getChType()[u.part]],h.std.innerText=p.standard,h.msb.innerText=`${p.sid[0]}`.padStart(3,"0"),h.prg.innerText=`${p.sid[1]}`.padStart(3,"0"),h.lsb.innerText=`${p.sid[2]}`.padStart(3,"0")}),t.addEventListener("pitch",u=>{let{part:p,pitch:h}=u.data;t.#l[p>>4][p&15].notes.style.transform=`translateX(${h/1.28}%)`}),t.addEventListener("efxreverb",u=>{t.#a.reverb.innerText=t.getEfx(u.data)}),t.addEventListener("efxchorus",u=>{t.#a.chorus.innerText=t.getEfx(u.data)}),t.addEventListener("efxdelay",u=>{t.#a.delay.innerText=t.getEfx(u.data)}),t.addEventListener("efxinsert0",u=>{t.#a.insert.innerText=t.getEfx(u.data)}),t.addEventListener("partefxtoggle",u=>{let{part:p,active:h}=u.data;[L,U][h](t.#l[p>>4][p&15].number,["part-efx"])}),t.addEventListener("channeltoggle",u=>{let{part:p,active:h}=u.data;[L,U][h](t.#l[p>>4][p&15].root,["part-active"])}),t.addEventListener("metacommit",u=>{let p=u.data;if(t.#u&&p.type==t.#w&&t.#o)switch(p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{T(t.#o,[v("span",["meta-slice"],{i:p.data})]);break}default:t.#o.childNodes[0].data+=p.data}else if(p.data?.length&&ht.indexOf(p.type)==-1){let h=v("div",["meta-line"]),a=v("span",["field","field-key","meta-type"],{i:ft[p.type]||p.type});switch(p.mask&&(a.style.display="none"),p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{t.#o=v("span",["field","meta-data"]),T(t.#o,[v("span",["meta-slice"],{i:p.data})]);break}default:t.#o=v("span",["field","meta-data"],{i:p.data})}for(t.#h.view.appendChild(h),T(h,[a,t.#o]);t.#h.view.children.length>t.#t;)t.#h.view.children[0].remove()}t.#u=p.amend||!1,t.#w=p.type||"",t.#f()}),t.#h.view.style.transform="translateX(0px) translateY(140px)",t.dispatchEvent("mode","?"),t.dispatchEvent("mastervolume",100),t.dispatchEvent("tempo",120),t.dispatchEvent("tsig",[4,4]),t.dispatchEvent("title",""),t.dispatchEvent("efxreverb",t.device.getEffectType(0)),t.dispatchEvent("efxchorus",t.device.getEffectType(1)),t.dispatchEvent("efxdelay",t.device.getEffectType(2)),t.dispatchEvent("efxinsert0",t.device.getEffectType(3)),t.#F(!0)}detach(e){let t=this;self.removeEventListener("resize",t.#U),t.#s.remove(),t.#s=void 0,t.#r.remove(),t.#r=void 0,t.#G=void 0,clearInterval(t.#B)}constructor(e,t){super(new Ae,.1,.75);let n=this;n.#U=n.#_.bind(this),n.#N=n.#z.bind(this),e&&n.attach(e),t&&n.setClockSource(t),n.addEventListener("reset",()=>{n.#i=0,n.#u=!1,n.#w="",n.#o=null;try{let c=n.#h.view.children;for(let u=c.length-1;u>=0;u--)c[u].remove();n.#h.view.style.transform="translateX(0px) translateY(140px)";for(let u=0;u>4][u&15];L(p.root,["part-active"]),L(p.number,["part-efx"]),Xe(p.metre,""),p.type.innerText="",p.std.innerText="",p.msb.innerText="",p.prg.innerText="",p.lsb.innerText="",p.notes.style.transform=""}}catch{}}),n.addEventListener("note",({data:c})=>{n.#O.push(c)}),n.addEventListener("pitch",({data:c})=>{n.#x.push(c)})}};export{la as Cambiare}; +%o`,a)}})}};var ne=Ze(Le(),1);var Ie=class{#t=!1;constructor(e,t,n,l){this.#t=e,this.start=t,this.end=n,this.data=l}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return this.#t}},ie=class extends Ie{constructor(e,t,n){super(!0,e,t,n)}},Ue=class extends Ie{constructor(e,t){super(!1,e,e,t)}},se=class extends Array{#t=-1;constructor(){super(...arguments)}resetIndex(e){this.#t=-1}fresh(){this.sort(function(e,t){return e.start==t.start?0:(+(e.start>t.start)<<1)-1}),this.forEach(function(e,t){e.index=t})}step(e,t=!1){let n=[];if(t)for(let l=0;le);l++){if(this[l].endu.#t&&(n.push(p),u.#t=p.index)})}return n}getRange(e,t){e>t&&([e,t]=[t,e]);let n=[],l=-1,u=Math.ceil(Math.sqrt(this.length)),p=!0;for(let h=0;h=e&&(l=h):l=l<0?h:l;for(;p;)this[l]?.end=e&&n.push(this[l]):p=!1,l++;return n}};var lt=0xffffffffffff,Ne=function(e){let t=new se,n=this,l=e.timeDivision,u=120,p=new se,h=0,a=0;p.push(new ie(0,lt,[120,0])),e.track.forEach(function(r){h=0,r.event.forEach(function(c){h+=c.deltaTime,c.type==255&&c?.metaType==81&&(u=6e7/c.data,p[p.length-1]&&p.push(new ie(h,0xffffffffffff,[u,0])))})}),p.fresh(),p.forEach(function(r,c,f){c>0&&(f[c-1].end=r.start)});let i=120;p.forEach(function(r,c,f){c>0&&(r.end==r.start?f.splice(f.indexOf(r),1):i==r.data[0]&&(f[c-1].end=r.end,f.splice(f.indexOf(r),1)),i=r.data[0])});let d=0,s=120;return p.forEach(function(r){let c=r.start,f=c/s/l*60+d;s=r.data[0],d=f-c/s/l*60,r.data[1]=d}),console.debug("All tempo changes: ",p),u=120,h=0,a=0,e.track.forEach(function(r,c){h=0,a=0;let f=c+1;r.event.forEach(function(o,b){h+=o.deltaTime;let y=p.step(h,!0)[0];y&&(u=y.data[0],a=y.data[1]);let E={type:o.type,data:o.data,track:f,part:0};o.type>14?E.meta=o.metaType:E.part=o.channel,t.push(new Ue(h/u/l*60+a,E))})}),t.fresh(),self.midiEvents=t,console.debug(`Parsed a type ${e.formatType} MIDI sequence.`),t};ne.default.customInterpreter=xe;var S=function(e,t,n){e.addEventListener(n,l=>{t.dispatchEvent(n,l.data)})},Be=class extends V{device;#t;#h={};#E=[];#o="";#m=[];#w=new Uint8ClampedArray(128);#u=new Uint8ClampedArray(128);#s=.5;#e=120;#d=4;#n=4;#l=0;#p=0;smoothingAtk=0;smoothingDcy=0;reset(){let e=this;e.dispatchEvent("reset"),e.#t?.resetIndex(),e.device.init(),e.#o="",e.#s=.5,e.#e=120,e.#d=4,e.#n=4,e.#l=0,e.#p=0,e.dispatchEvent("tempo",e.#e),e.dispatchEvent("title",e.#o)}init(){this.reset(),this.#t=void 0}async loadFile(e){this.#t=Ne(ne.default.parse(new Uint8Array(await e.arrayBuffer())))}async loadMap(e,t){let n=this,l=0,u=0,p=0,h,a;e.split(` +`).forEach((i,d)=>{if(!i)return;let s=i.split(" ");if(d){if(!p)return;let r="",c="";s.forEach((f,o)=>{switch(o){case h:{r=f;break}case a:{c=f;break}}}),!n.#h[r]||t?(n.#h[r]=c,l++):self.debugMode&&console.debug(`Voice "${c}" (${r}) seems to be in conflict with (${n.#h[r]}).`),u++}else s.forEach((r,c)=>{switch(r){case"ID":{h=c,p++;break}case"Name":{a=c,p++;break}default:console.debug(`Unknown map field: ${r}`)}})}),console.debug(`Map: ${u} total, ${l} loaded.`),n?.device.forceVoiceRefresh()}async loadEfx(e,t){let n=this,l=0,u=0,p,h,a;e.split(` +`).forEach((i,d)=>{if(i)if(d){let s=0,r;i.split(" ").forEach((c,f)=>{switch(f){case p:{s|=parseInt(c,16)<<8;break}case h:{s|=parseInt(c,16);break}case a:{r=c;break}}}),!n.#E[s]||t?(n.#E[s]=r,l++):self.debugMode&&console.debug(`EFX ID 0x${s.toString(16).padStart(4,"0")} (${r}) seems to be in conflict.`),u++}else i.split(" ").forEach((s,r)=>{switch(s){case"MSB":{p=r;break}case"LSB":{h=r;break}case"Name":{a=r;break}default:console.debug(`Unknown EFX field: ${s}`)}})}),console.debug(`EFX: ${u} total, ${l} loaded.`),n.dispatchEvent("efxreverb",n.device.getEffectType(0)),n.dispatchEvent("efxchorus",n.device.getEffectType(1)),n.dispatchEvent("efxdelay",n.device.getEffectType(2)),n.dispatchEvent("efxinsert0",n.device.getEffectType(3)),n.dispatchEvent("efxinsert1",n.device.getEffectType(4)),n.dispatchEvent("efxinsert2",n.device.getEffectType(5)),n.dispatchEvent("efxinsert3",n.device.getEffectType(6))}switchMode(e,t=!1){this.device.switchMode(e,t)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}getMapped(e){return this.#h[e]||e}getEfx([e,t]){let n=e<<8|t;return this.#E[n]||`0x${n.toString(16).padStart(4,"0")}`}get noteProgress(){return this.#p/this.#s}get noteOverall(){return this.noteProgress-this.#l}get noteBar(){return Math.floor(this.noteOverall/this.#d)}get noteBeat(){let e=this.noteOverall%this.#d;return e<0&&(e+=this.#d),e}getTimeSig(){return[this.#d,this.#n]}getTempo(){return this.#e}sendCmd(e){this.device.runJson(e)}render(e){e>this.#p&&(this.#p=e);let t=this.#t?.step(e)||[],n=0,l=new Set,u=this,p=[];this.device.getStrength().forEach((b,y)=>{this.#u[y]=b}),u.device.newStrength(),t.forEach(function(b){let y=b.data;y.type==9&&(y.data[1]>0?l.add(y.part*128+y.data[0]):l.has(y.part*128+y.data[0])&&n++),b.data.type==8&&l.has(y.part*128+y.data[0])&&n++;let E=u.device.runJson(y);switch(E?.reply){case"meta":{p.push(E);break}}E?.reply&&delete E.reply}),p?.length>0&&this.dispatchEvent("meta",p);let h=this.device.getActive(),a=[],i=u.device.getPitch(),d=u.device.getCcAll(),s=u.device.getProgram(),r=u.device.getChType(),c=this.device.getStrength();c.forEach(function(b,y,E){E[y]=Math.max(u.#u[y],b);let $=E[y]-u.#w[y],x=g.length*y;if($>=0){let B=4*.25**(d[x+g[73]]/64);u.#w[y]+=Math.ceil($-$*u.smoothingAtk**B)}else{let B=4*.25**(d[x+g[72]]/64);u.#w[y]+=Math.floor($-$*u.smoothingDcy**B)}});let f=0;return h.forEach(function(b,y){b&&(a[y]=u.device.getVel(y),f+=a[y].size)}),{extraPoly:n,curPoly:f,chInUse:h,chKeyPr:a,chPitch:i,chProgr:s,chContr:d,chType:r,eventCount:t.length,title:this.#o,bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:this.#w.slice(),velo:c,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce(),efxSink:this.device.getEffectSink()}}constructor(e,t=.5,n=.5){super();let l=this;l.smoothingAtk=t,l.smoothingDcy=n,l.device=e,l.addEventListener("meta",function(u){u?.data?.forEach(function(p){(l.#m[p.meta]||console.debug).call(l,p.meta,p.data)})}),S(l.device,l,"mode"),S(l.device,l,"mastervolume"),S(l.device,l,"channelactive"),S(l.device,l,"channelmin"),S(l.device,l,"channelmax"),S(l.device,l,"channelreset"),S(l.device,l,"channeltoggle"),S(l.device,l,"screen"),S(l.device,l,"metacommit"),S(l.device,l,"voice"),S(l.device,l,"pitch"),S(l.device,l,"note"),S(l.device,l,"reset"),S(l.device,l,"efxreverb"),S(l.device,l,"efxchorus"),S(l.device,l,"efxdelay"),S(l.device,l,"efxinsert0"),S(l.device,l,"efxinsert1"),S(l.device,l,"efxinsert2"),S(l.device,l,"efxinsert3"),S(l.device,l,"partefxtoggle"),l.#m[3]=function(u,p){l.#o?.length<1&&(l.#o=p,l.dispatchEvent("title",l.#o))},l.#m[81]=function(u,p){let h=l.noteProgress,a=l.#s||.5;l.#e=6e7/p,l.#s=p/1e6,l.#l+=h*(a/l.#s)-h,l.dispatchEvent("tempo",l.#e)},l.#m[88]=function(u,p){let h=l.noteProgress,a=l.noteOverall,i=l.noteBar,d=l.noteBeat,s=l.#d,r=l.#n;l.#d=p[0],l.#n=1<=s&&(s{le&&(ce[K]=!ce[K],K++,K>34&&(K=0))},1e3/50);Uint8Array.prototype.render=function(e){let t=0,n=0,l=this.width||5,u=this.height||8;for(let p=0;p=l&&(t=0,n++)};var He=class{#t=[];async load(e,t=!1,n="(internal)"){let l=this,u=0,p=0;console.debug(`Font "${n||"(internal)"}": loading started.`),e.split(` +`).forEach(function(h,a){if(a>0&&h?.length>0){let i=h.split(" "),d=parseInt(i[0],16);if(p++,l.#t[d]&&!t)return;let s=new Uint8Array(40);Array.from(i[1]).forEach(async function(r,c){let f=c%2?4:0,o=Math.floor(c/2),b=parseInt(r,16),y=3;for(;b>0||y>=0;){let E=(f+y)*5+o;s[E]=b&1,b=b>>1,y--}}),l.#t[d]=s,u++}}),console.debug(`Font "${n||"(internal)"}": ${p} total, ${u} loaded.`)}async loadFile(e,t=!1){let n=this;console.debug(`Requested font file from "${e}".`),await n.load(await(await fetch(e)).text(),t,e),le=!1}constructor(...e){le=!0,(async()=>{for(let t=0;t{l.classList.add(s)});let{t:u,l:p,w:h,h:a,i,a:d}=n;return u?.constructor&&(l.style.top=u?.length?u:`${u}px`),p?.constructor&&(l.style.left=p?.length?p:`${p}px`),h?.constructor&&(l.style.width=h?.length?h:`${h}px`),a?.constructor&&(l.style.height=a?.length?a:`${a}px`),i?.constructor&&l.appendChild(document.createTextNode(i)),d?.constructor&&(l.style.textAlign=d),l},M=function(e,t){let n=document.createElementNS("http://www.w3.org/2000/svg",e);for(let l in t)n.setAttribute(l,t[l]);return n},T=function(e,t){t?.forEach(n=>{e.appendChild(n)})},L=function(e,t){t.forEach(n=>{e.classList.contains(n)&&e.classList.remove(n)})},U=function(e,t){t.forEach(n=>{e.classList.contains(n)||e.classList.add(n)})},Fe=new Array(128).fill(0);Fe.forEach((e,t,n)=>{n[t]=Math.floor(24*t/12.7)/10});var de=new Array(128).fill(0);de.forEach((e,t,n)=>{n[t]=Math.abs(Math.round(48*(t-64)/12.7)/10)});var Ke=new Array(11).fill(null);Ke.forEach((e,t,n)=>{n[t]=`${Math.round(t*12/.0128)/100}%`});var bt=new Array(128).fill(null);bt.forEach((e,t,n)=>{n[t]=`${Math.round(t/1.27)/100}`});var P=function(e,t){let n=Fe[t];e.setAttribute("height",n),e.setAttribute("y",24-n)},_e=function(e,t){e.innerText=t,e.rNew=!0;let n=e.measureText(t);e.rWidth=n.width},la=class extends Be{#t=128;#h=!1;#E="";#o;#m=0;#w=0;#u=0;#s=0;#e=1;#d=0;#n=new Uint8Array(1280);#l=new Uint8Array(1280);#p=new Uint8Array(1280);#b=new Uint8Array(512);#v=new Uint8Array(512);#D=new Uint8Array(512);#C;#H;#r;#i;#I;#x="fcdaff";#a={};#$={};#c=[];#y={};#S={};#T=[];#G=[];#O="block";glyphs=new He;#M(e,t,n,l=0,u=0){let p=this,{width:h,height:a}=e.canvas,i,d,s,r,c=p.#e,f=l>3,o=dt.indexOf(t%12)>-1;switch(p.#O){case"block":case"comb":{i=Math.round(t*h/128),d=Math.round((t+1)*h/128),s=d-i,r=c==1?2:1;break}case"piano":{i=Math.round((Math.floor(t/12)*7+Ge[t%12])*h/75*1.0044642857142856),d=Math.round((Math.floor(t/12)*7+Ge[t%12]+1)*h/75*1.0044642857142856)-1,s=d-i,r=c==1?3:1;break}case"line":{let b=t-u;Math.abs(u)>2&&(b=t-Math.sign(u)*2),d=Math.round((t+.5)*h/128),i=Math.round((b+.5)*h/128)}default:}switch(e.fillStyle=`#${o?p.#x:"ffffff"}${(n<<1|n>>6).toString(16).padStart(2,"0")}`,e.strokeStyle=e.fillStyle,e.lineWidth=c==1?4:2,e.lineDashOffset=0,p.#O){case"block":{let b=e.canvas.height-1;e.fillRect(i,1,s,b),f&&e.clearRect(i+r,r+1,s-(r<<1),b-(r<<1));break}case"comb":{let b=(o?Math.round((e.canvas.height<<1)/3):e.canvas.height)-1;e.fillRect(i,1,s,b),f&&e.clearRect(i+r,r+1,s-(r<<1),b-(r<<1));break}case"piano":{let b=(o?0:e.canvas.height>>1)+1,y=(e.canvas.height>>1)-1;e.fillRect(i,b,s,y),f&&e.clearRect(i+r,b+r,s-(r<<1),y-(r<<1));break}case"line":{if(f)switch(c){case 4:{e.setLineDash(oe[2]);break}default:e.setLineDash(oe[1])}else e.setLineDash(oe[0]),c!=4&&self?.document?.mozFullScreen&&(i+=.5,d+=.5);e.beginPath(),e.moveTo(i,(c==4||!f)&&self?.document?.mozFullScreen?2:1),e.lineTo(d,(a>>1)+2),e.lineTo(i,a+2),e.stroke();break}default:}}#f(e,t){let n=this;(e?.chInUse||t).forEach((l,u)=>{if(l){let p=n.#c[u>>4][u&15].cxt;p.clearRect(0,0,p.canvas.width,p.canvas.height),e.chKeyPr[u].forEach(({v:h,s:a},i)=>{n.#M(p,i,h,a,n.device.getPitchShift(u))})}})}#X(e){let t=this;Date.now()-t.#m>4e3&&(t.#w=0,t.#u=142-t.#y.view.clientHeight,(t.#o?.clientWidth||0)>840&&(t.#w=840-t.#o.clientWidth),t.#y.view.style.transform=`translateX(${t.#w}px) translateY(${t.#u}px)`,e&&(t.#m=0))}#z(){let e=self.innerWidth/self.innerHeight,t=1,n=self.innerWidth,l=self.innerHeight;e>=W?(t=Math.round(self.innerHeight/1080*1e4)/1e4,n=Math.ceil(self.innerHeight*W)):e>4,f=r*m.cc,o=e.#c[c][r&15];if(n.chInUse[r]&&c>=e.#d&&co.metre.canvas.width){o.metre.rNew&&(o.metre.rNew=!1,o.metre.rOffset=t);let y=t-(o.metre.rOffset||0),E=32,$=o.metre.rWidth-o.metre.canvas.width+E,x=y*-25%(o.metre.rWidth+E+48)+48;x>0&&(x=0),o.metre.fillText(o.metre.innerText,x,3+e.#I.font4[0]),Math.abs(x)>$&&o.metre.fillText(o.metre.innerText,x+o.metre.rWidth+E,3+e.#I.font4[0])}else o.metre.fillText(o.metre.innerText,0,3+e.#I.font4[0]);o.metre.globalCompositeOperation="xor",o.metre.fillRect(0,0,n.strength[r]*121/255,25);let b=n.chContr[f+g[10]];o.pan.setAttribute("width",`${de[b]||0}`),b<64?o.pan.setAttribute("x",`${84-de[b]}`):b>127?(o.pan.setAttribute("x","60"),o.pan.setAttribute("width","48")):o.pan.setAttribute("x","84")}}let h=new Set,a=new Set,i=new Array(m.ch),d={};if(e.#c.forEach((r,c)=>{r.forEach((f,o)=>{f.refresh&&(f.refresh=!1,i[c<<7|o]=!0)})}),["line"].indexOf(e.#O)>-1)for(;e.#G.length>0;){let r=e.#G.shift();i[r.part]=!0}for(;e.#T.length>0;){let r=e.#T.shift(),{part:c,note:f,velo:o,state:b}=r,y=c<<7|f;i[c]=!0,b==0?h.has(y)&&(a.add(y),e.#c[c>>4][c&15].refresh=!0):(h.add(y),d[y]=r)}e.#f(n,i),a.forEach(r=>{let{part:c,note:f,velo:o,state:b}=d[r],y=e.#c[c>>4][c&15].cxt;e.#M(y,f,o,b,e.device.getPitchShift(c))});let s=e.#S.cxt;l>n.bitmap.expire?e.#D.fill(0):n.bitmap.bitmap.length>256?n.bitmap.bitmap.forEach((r,c)=>{e.#D[c]=r?255:0}):n.bitmap.bitmap.forEach((r,c)=>{e.#D[c<<1]=r?255:0,e.#D[c<<1|1]=r?255:0}),e.#p.fill(0),l<=n.letter.expire&&e.glyphs.getStr(n.letter.text).forEach((r,c)=>{let f=(c&15)*5,o=c>>4<<3;r.forEach((b,y)=>{let E=f+y%5,$=o+Math.floor(y/5);e.#p[$*80+E]=b?255:0})}),e.#b.forEach((r,c,f)=>{let o=e.#D[c];o>r?f[c]+=Math.min(o-r,Q):o{let o=e.#p[c];o>r?f[c]+=Math.min(o-r,Q):o{let f=c>>5,o=c&31;e.#v[c]!=r?(s.clearRect(252+(o<<2),f<<2,3,3),r&&(s.fillStyle=`#ffffff${r.toString(16).padStart(2,"0")}`,s.fillRect(252+(o<<2),f<<2,3,3))):self.debugMode&&(s.clearRect(252+(o<<2),f<<2,3,3),r&&(s.fillStyle=`#ff0000${r.toString(16).padStart(2,"0")}`,s.fillRect(252+(o<<2),f<<2,3,3)))}),e.#n.forEach((r,c)=>{let f=Math.floor(c/80),o=c%80;o+=Math.floor(o/5),e.#l[c]!=r?(s.clearRect(o<<2,(f|16)<<2,3,3),r&&(s.fillStyle=`#ffffff${r.toString(16).padStart(2,"0")}`,s.fillRect(o<<2,(f|16)<<2,3,3))):self.debugMode&&(s.clearRect(o<<2,(f|16)<<2,3,3),r&&(s.fillStyle=`#ff0000${r.toString(16).padStart(2,"0")}`,s.fillRect(o<<2,(f|16)<<2,3,3)))}),e.#v.forEach((r,c,f)=>{f[c]=e.#b[c]}),e.#l.forEach((r,c,f)=>{f[c]=e.#n[c]})}#N;#q;get style(){return this.#O}set style(e){let t=this;t.#O=e,t.#f(t.render(t.#C?.currentTime||0)),L(t.#i,["cambiare-style-block","cambiare-style-comb","cambiare-style-piano","cambiare-style-line"]),U(t.#i,[`cambiare-style-${e}`])}setClockSource(e){this.#C=e}setPixelProfile(e){let t=this;if(Xe[e]){let n=Xe[e];t.#I=n,t.#i&&(t.#i.style.setProperty("--pcp-font4",`translate(${n.font4[1]}px, ${n.font4[0]}px)`),t.#i.style.setProperty("--pcp-font7",`translate(${n.font7[1]}px, ${n.font7[0]}px)`))}else throw new Error(`"${e}" is not a valid pixel correction profile`)}setMode(e){let t=this;L(t.#i,["cambiare-mode-gm","cambiare-mode-xg","cambiare-mode-gs","cambiare-mode-ns5r","cambiare-mode-05rw","cambiare-mode-x5d","cambiare-mode-k11","cambiare-mode-sg","cambiare-mode-g2","cambiare-mode-mt32","cambiare-mode-sd","cambiare-mode-krs","cambiare-mode-s90es","cambiare-mode-motif"]),e!="?"&&U(t.#i,[`cambiare-mode-${e}`]),t.#x={xg:"9efaa0",ns5r:"9efaa0",x5d:"9efaa0","05rw":"9efaa0",k11:"9efaa0",s90es:"9efaa0",motif:"9efaa0",gm:"a1f3ff",g2:"a1f3ff",krs:"a1f3ff",gs:"ffe1a5",mt32:"ffe1a5",sd:"ffe1a5",sg:"ffdddd"}[e]||"fcdaff"}#F(e){let t=this,n=t.#e,l=t.#d;t.#c.forEach((u,p)=>{if(p>=l&&p{d.root.style.top=`${s*(n>2?26:52)}px`})}else L(u.root,["port-active"]),u.root.style.top="",u.root.style.left="",u.forEach((h,a)=>{h.root.style.top=""});e&&u.forEach((h,a)=>{h.cxt.canvas.width=t.#e==1?1193:495,h.cxt.canvas.height=t.#e==4?26:52})})}setPort(e){let t=this;L(t.#i,["cambiare-start0","cambiare-start1","cambiare-start2","cambiare-start3","cambiare-start4","cambiare-start5","cambiare-start6","cambiare-start7"]),U(t.#i,[`cambiare-start${e}`]),t.#d=e,t.#F(!1)}setRange(e){let t=this;L(t.#i,["cambiare-port1","cambiare-port2","cambiare-port4","cambiare-compact"]),U(t.#i,[`cambiare-${e}`]),t.#e=parseInt(e.slice(4))||1,t.#F(!0)}attach(e){let t=this;t.#H=e;let n=v("div",["cambiare-container"]);e.appendChild(n),t.#r=n;let l=v("div",["cambiare-canvas","cambiare-port1","cambiare-start0","cambiare-style-block"]);n.appendChild(l),t.#i=l,self.addEventListener("resize",t.#U),t.#U(),t.#q=setInterval(t.#N,20),t.#a.root=v("div",["sect-info"]),t.#a.events=v("span",["field","pcp-font4"],{t:1,l:0,w:35,h:33}),t.#a.curPoly=v("span",["field","pcp-font4"],{t:1,l:52,w:35,h:33}),t.#a.maxPoly=v("span",["field","pcp-font4"],{t:1,l:98,w:35,h:33}),t.#a.sigN=v("span",["field","pcp-font4"],{t:1,l:194,w:23,h:33,a:"right"}),t.#a.sigD=v("span",["field","pcp-font4"],{t:1,l:232,w:23,h:33}),t.#a.barCount=v("span",["field","pcp-font4"],{t:1,l:304,w:35,h:33,a:"right"}),t.#a.barNote=v("span",["field","pcp-font4"],{t:1,l:354,w:23,h:33}),t.#a.tempo=v("span",["field","pcp-font4"],{t:1,l:454,w:64,h:33,a:"right"}),t.#a.volume=v("span",["field","pcp-font4"],{t:1,l:562,w:63,h:33,a:"right"}),t.#a.mode=v("span",["field","pcp-font4"],{t:1,l:708,w:152,h:33}),t.#a.reverb=v("span",["field","pcp-font4"],{t:1,l:1e3,w:190,h:33}),t.#a.chorus=v("span",["field","pcp-font4"],{t:1,l:1240,w:190,h:33}),t.#a.delay=v("span",["field","pcp-font4"],{t:1,l:1475,w:190,h:33}),t.#a.insert=v("span",["field","pcp-font4"],{t:1,l:1706,w:190,h:33}),t.#a.title=v("span",["field","pcp-font4"],{t:35,l:50,w:810,h:33}),l.appendChild(t.#a.root),T(t.#a.root,[t.#a.events,t.#a.curPoly,v("span",["field","field-label","pcp-font4"],{t:1,l:89,w:5,h:33,i:":"}),t.#a.maxPoly,v("span",["field","field-key","pcp-font7"],{t:1,l:148,w:41,h:33,i:"TSig"}),t.#a.sigN,v("span",["field","field-label","pcp-font4"],{t:0,l:221,w:8,h:33,i:"/"}),t.#a.sigD,v("span",["field","field-key","pcp-font7"],{t:1,l:268,w:30,h:33,i:"Bar"}),t.#a.barCount,v("span",["field","field-label","pcp-font4"],{t:0,l:343,w:8,h:33,i:"/"}),t.#a.barNote,v("span",["field","field-key","pcp-font7"],{t:1,l:390,w:61,h:33,i:"Tempo",a:"right"}),t.#a.tempo,v("span",["field","field-key","pcp-font7"],{t:1,l:528,w:29,h:33,i:"Vol"}),t.#a.volume,v("span",["field","field-label","pcp-font4"],{t:1,l:626,w:17,h:33,i:"%"}),v("span",["field","field-key","pcp-font7"],{t:1,l:652,w:52,h:33,i:"Mode"}),t.#a.mode,v("span",["field","field-key","pcp-font7"],{t:1,l:960,w:34,h:33,i:"Rev"}),t.#a.reverb,v("span",["field","field-key","pcp-font7"],{t:1,l:1198,w:36,h:33,i:"Cho"}),t.#a.chorus,v("span",["field","field-key","pcp-font7"],{t:1,l:1438,w:31,h:33,i:"Var"}),t.#a.delay,v("span",["field","field-key","pcp-font7"],{t:1,l:1673,w:27,h:33,i:"Ins"}),t.#a.insert,v("span",["field","field-key","pcp-font7"],{t:35,l:0,w:44,h:33,i:"Title"}),t.#a.title]),t.#$.root=v("div",["sect-mark"]),t.#$.left=v("div",["sect-mark-left","boundary"],{t:0,l:0}),t.#$.right=v("div",["sect-mark-right","boundary"],{t:0,l:960}),l.appendChild(t.#$.root),T(t.#$.root,[t.#$.left,t.#$.right]),T(t.#$.left,[v("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),v("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),v("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),v("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),v("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),v("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),T(t.#$.right,[v("span",["field","field-key"],{t:0,l:0,w:26,h:33,i:"CH"}),v("span",["field","field-key"],{t:0,l:30,w:49,h:33,i:"Voice"}),v("span",["field","field-key","mark-send-title"],{t:2,l:164,w:25,h:18,i:"Send"}),v("span",["field","field-label","mark-send-param"],{t:16,l:146,w:58,h:16,i:"VEMRCDBP12",a:"center"}),v("span",["field","field-key"],{t:0,l:212,w:35,h:33,i:"Pan"}),v("span",["field","field-key"],{t:0,l:256,w:45,h:33,i:"Note"})]),t.#c.root=v("div",["sect-part"]);for(let u=0;u>4;u++){let p=u<<4;t.#c[u]=[],t.#c[u].root=v("div",["boundary",`part-port-${u}`]);for(let h=0;h<16;h++){let a=(p|h)+1;a>=100?a=`${Math.floor(a/10).toString(16)}${a%10}`:a=`${a}`.padStart(2,"0"),t.#c[u][h]={root:v("div",["boundary","part-channel"]),major:v("div",["boundary","part-info-major"]),minor:v("div",["boundary","part-info-minor"],{t:26}),keys:v("div",["boundary","part-keys"]),notes:v("div",["boundary","part-keyboard"]),cxt:v("canvas",["field"]).getContext("2d"),number:v("span",["field","field-label","pcp-font4"],{t:1,w:18,h:25,i:a}),voice:v("span",["field"],{l:22,t:1,w:121,h:25}),metre:v("canvas",["field"]).getContext("2d"),type:v("span",["field","field-label","pcp-font4"],{t:1,w:18,h:25}),std:v("span",["field","pcp-font4"],{l:22,t:1,w:20,h:25,a:"center"}),msb:v("span",["field","pcp-font4"],{l:48,t:1,w:27,h:25}),prg:v("span",["field","pcp-font4"],{l:81,t:1,w:27,h:25}),lsb:v("span",["field","pcp-font4"],{l:114,t:1,w:27,h:25}),cc:M("svg",{viewBox:"0 0 108 24",width:108,style:"left: 146px; top: 1px; position: absolute;"}),vol:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:0}),exp:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:6}),mod:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:12}),rev:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:18}),cho:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:24}),var:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:30}),brt:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:36}),por:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:42}),cea:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:48}),ceb:M("rect",{fill:"var(--accent-color)",width:4,height:24,x:54}),pan:M("rect",{fill:"var(--accent-color)",width:0,height:24,x:84})};let i=t.#c[u][h];Ke.forEach(d=>{i.notes.appendChild(v("span",["field","part-csplit"],{l:d}))}),i.notes.appendChild(v("span",["field","part-csplit","part-cdive"],{l:0,w:"100%",h:1})),i.metre.canvas.width=121,i.metre.canvas.height=25,i.metre.fillStyle="#fff",i.metre.textBaseline="top",i.metre.font="20px 'PT Sans Narrow'",T(i.notes,[i.cxt.canvas]),T(i.keys,[i.notes]),T(i.voice,[i.metre.canvas]),T(i.cc,[i.vol,i.exp,i.mod,i.rev,i.cho,i.var,i.brt,i.por,i.cea,i.ceb,i.pan,M("rect",{x:83,y:0,width:1,height:24,fill:"var(--foreground-color)"})]),T(i.major,[i.number,i.voice,i.cc]),T(i.minor,[i.type,i.std,i.msb,i.prg,i.lsb]),T(i.root,[i.major,i.minor,i.keys]),T(t.#c[u].root,[i.root])}t.#c.root.appendChild(t.#c[u].root)}l.appendChild(t.#c.root),t.#y.root=v("div",["sect-meta"]),t.#y.view=v("div",["boundary"]),l.appendChild(t.#y.root),T(t.#y.root,[t.#y.view]),t.#S.root=v("div",["sect-pix","boundary"],{l:1529,t:950,w:379,h:127}),t.#S.cxt=v("canvas",["field"]).getContext("2d"),t.#S.cxt.canvas.width=379,t.#S.cxt.canvas.height=127,T(t.#S.root,[t.#S.cxt.canvas]),l.appendChild(t.#S.root),t.addEventListener("mode",u=>{t.#a.mode.innerText=`${ft[u.data]}`,t.setMode(u.data)}),t.addEventListener("mastervolume",u=>{let p=Math.round(u.data*100)/100;t.#a.volume.innerText=`${Math.floor(p)}.${`${Math.floor(p%1*100)}`.padStart(2,"0")}`}),t.addEventListener("tempo",u=>{let p=Math.round(u.data*100);t.#a.tempo.innerText=`${Math.floor(p/100)}.${`${Math.floor(p%100)}`.padStart(2,"0")}`}),t.addEventListener("tsig",u=>{[t.#a.sigN.innerText,t.#a.sigD.innerText]=u.data}),t.addEventListener("title",u=>{t.#a.title.innerText=u.data||"No Title"}),t.addEventListener("voice",({data:u})=>{let p=t.getChVoice(u.part),h=t.#c[u.part>>4][u.part&15];_e(h.metre,t.getMapped(p.name)),h.type.innerText=ot[t.device.getChType()[u.part]],h.std.innerText=p.standard,h.msb.innerText=`${p.sid[0]}`.padStart(3,"0"),h.prg.innerText=`${p.sid[1]}`.padStart(3,"0"),h.lsb.innerText=`${p.sid[2]}`.padStart(3,"0")}),t.addEventListener("pitch",u=>{let{part:p,pitch:h}=u.data;t.#c[p>>4][p&15].notes.style.transform=`translateX(${h/1.28}%)`}),t.addEventListener("efxreverb",u=>{t.#a.reverb.innerText=t.getEfx(u.data)}),t.addEventListener("efxchorus",u=>{t.#a.chorus.innerText=t.getEfx(u.data)}),t.addEventListener("efxdelay",u=>{t.#a.delay.innerText=t.getEfx(u.data)}),t.addEventListener("efxinsert0",u=>{t.#a.insert.innerText=t.getEfx(u.data)}),t.addEventListener("partefxtoggle",u=>{let{part:p,active:h}=u.data;[L,U][h](t.#c[p>>4][p&15].number,["part-efx"])}),t.addEventListener("channeltoggle",u=>{let{part:p,active:h}=u.data;[L,U][h](t.#c[p>>4][p&15].root,["part-active"])}),t.addEventListener("metacommit",u=>{let p=u.data;if(t.#h&&p.type==t.#E&&t.#o)switch(p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{T(t.#o,[v("span",["meta-slice"],{i:p.data})]);break}default:t.#o.childNodes[0].data+=p.data}else if(p.data?.length&&ut.indexOf(p.type)==-1){let h=v("div",["meta-line"]),a=v("span",["field","field-key","meta-type"],{i:ht[p.type]||p.type});switch(p.mask&&(a.style.display="none"),p.type){case"C.Lyrics":case"KarLyric":case"SGLyrics":{t.#o=v("span",["field","meta-data"]),T(t.#o,[v("span",["meta-slice"],{i:p.data})]);break}default:t.#o=v("span",["field","meta-data"],{i:p.data})}for(t.#y.view.appendChild(h),T(h,[a,t.#o]);t.#y.view.children.length>t.#t;)t.#y.view.children[0].remove()}t.#h=p.amend||!1,t.#E=p.type||"",t.#X()}),t.#y.view.style.transform="translateX(0px) translateY(140px)",t.dispatchEvent("mode","?"),t.dispatchEvent("mastervolume",100),t.dispatchEvent("tempo",120),t.dispatchEvent("tsig",[4,4]),t.dispatchEvent("title",""),t.dispatchEvent("efxreverb",t.device.getEffectType(0)),t.dispatchEvent("efxchorus",t.device.getEffectType(1)),t.dispatchEvent("efxdelay",t.device.getEffectType(2)),t.dispatchEvent("efxinsert0",t.device.getEffectType(3)),t.#F(!0)}detach(e){let t=this;self.removeEventListener("resize",t.#U),t.#i.remove(),t.#i=void 0,t.#r.remove(),t.#r=void 0,t.#H=void 0,clearInterval(t.#q)}constructor(e,t){super(new Ae,.1,.75);let n=this;n.#U=n.#z.bind(this),n.#N=n.#_.bind(this),e&&n.attach(e),t&&n.setClockSource(t),n.setPixelProfile("none"),n.addEventListener("reset",()=>{n.#s=0,n.#h=!1,n.#E="",n.#o=null;try{let l=n.#y.view.children;for(let u=l.length-1;u>=0;u--)l[u].remove();n.#y.view.style.transform="translateX(0px) translateY(140px)";for(let u=0;u>4][u&15];L(p.root,["part-active"]),L(p.number,["part-efx"]),_e(p.metre,""),p.type.innerText="",p.std.innerText="",p.msb.innerText="",p.prg.innerText="",p.lsb.innerText="",p.notes.style.transform=""}}catch{}}),n.addEventListener("note",({data:l})=>{n.#T.push(l)}),n.addEventListener("pitch",({data:l})=>{n.#G.push(l)})}};export{la as Cambiare}; diff --git a/dist/state.mjs b/dist/state.mjs index e90d25fb..368c16f7 100644 --- a/dist/state.mjs +++ b/dist/state.mjs @@ -1,8 +1,8 @@ -var F=function(e,a){let o=Math.min(e.length,a.length),h=e.slice(0,o),y=a.slice(0,o),g=0,f=0;for(;f0){let h=this.pool.length,y=1<=1&&f>=0;){if(f<=0)throw new Error("TTL reached.");if(g==h)g-=y;else{let s=F(a,this.pool[g]);switch(s){case 0:{f=0;break}case 1:{g+y<=h&&(g+=y);break}case-1:{g!=0&&(g-=y);break}default:console.warn(`Unexpected result ${s}.`)}}y=y>>1,f--}let t=!0;if(g>=this.pool.length)t=!1;else{let s=this;this.pool[g].forEach(function(n,i,r){t&&n!=a[i]&&(t=!1)}),!t&&F(a,this.pool[g])>0&&g++}return t||o?g:-1}else return o?0:-1},this.add=function(a,o){return a.data=o,this.pool.splice(this.point(a,!0),0,a),this},this.default=function(a){console.warn(`No match in "${this.name||"(unknown)"}" for "${a}". Default action not defined.`)},this.get=function(a){let o=this.point(a);if(o>-1)return this.pool[o].data;this.default(a)},this.run=function(a,...o){let h=this.point(a);h>-1?a.subarray?this.pool[h].data(a.subarray(this.pool[h].length),...o):this.pool[h].data(a.slice(this.pool[h].length),...o):this.default(a,...o)}};var z=class{#t={};addEventListener(e,a){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(a)}removeEventListener(e,a){if(this.#t[e]){let o=this.#t[e].indexOf(a);o>-1&&this.#t[e].splice(o,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,a){let o=new Event(e),h=this;o.data=a,this.#t[e]?.length>0&&this.#t[e].forEach(function(y){try{y?.call(h,o)}catch(g){console.error(g)}}),this[`on${e}`]&&this[`on${e}`](o)}};var ue=["MSB","PRG","LSB"],G=function(e){let a=Math.floor(e/10),o=e%10;return`${a.toString(16)}${o}`},B=class{#t;strictMode=!1;get(e=0,a=0,o=0,h){let y=[e,a,o],g,f=Array.from(arguments);switch(h){case"xg":{switch(e){case 0:{o==126?f[2]=125:o==127&&(f[2]=0);break}case 16:{o==126&&(f[2]=0);break}case 32:{f[2]+=4;break}case 33:case 35:case 36:{f[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:f[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{o==126&&(f[2]=0);break}case 48:case 64:case 126:case 127:{o==126&&(f[2]=0);break}}break}case"gs":{e==0&&o<5?f[2]=0:e>125&&o<5&&o!=2&&(f[2]=e,f[0]=0);break}case"g2":case"sd":{(e>>1==40||e>95&&e<100)&&(f[2]|=16);break}case"sg":{e==8&&o==0&&(f[2]=5);break}case"s90es":{o<8?f[2]+=17:o<32?f[2]+=13:f[2]=(f[2]>>3)+19;break}case"motif":{o<8?f[2]+=28:o<32?f[2]+=13:f[2]=(f[2]>>3)+19;break}}let t=" ",s="M",n=0,i=0;switch(f[0]){case 0:{f[2]==127?s="MT-a":f[2]==126?s="MT-b":f[2]==7?s="GM-k":f[2]==5?s="SG-a":f[2]==4?s="SP-l":f[2]==0||h=="gs"&&f[2]<5?s="GM-a":(s="y",n=3);break}case 8:{h=="sg"?s="GM-s":s="r:";break}case 48:{s=`yM${(f[2]>>3).toString().padStart(2,"0")}`,n=1;break}case 56:{s="GM-b";break}case 61:case 120:{s="rDrm";break}case 62:{s="kDrm";break}case 63:{if(f[2]<17){let l=f[2];s=l<10?"kP:":"kC:",s+=l%10}else f[2]<34?s=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][f[2]-17]:s="Ds";break}case 64:{s="ySFX";break}case 67:{s="DX:S";break}case 80:case 81:case 82:case 83:{s=`Prg${"UABC"[f[0]-80]}`;break}case 88:case 89:case 90:case 91:{s=`Cmb${"UABC"[f[0]-88]}`;break}case 95:{s=`${["DR","PC"][f[2]]}-d`;break}case 96:{s=f[2]==106?"AP-a":f[2]>>4==1?"SDg":"PF",f[2]>63?i=63:f[2]>>4==1&&(i=16),n=3;break}case 97:{s=f[2]>>4==1?"SDa":"VL:",n=3,f[2]>>4==1?i=16:i=112;break}case 98:{s=f[2]>>4==1?"SDb":"SG-a",n=3,i=16;break}case 99:{s=f[2]>>4==1?"SDc":"DX",f[2]>63?i=63:f[2]>>4==1&&(i=16),n=3;break}case 100:{s="AN",f[2]>63?i=63:f[2]>>4==1&&(i=16),n=3;break}case 104:case 105:case 106:case 107:{s="SDd",i=104;break}case 121:{s=`GM-${f[2]?"":"a"}`,n=3;break}case 122:{s="lDrm";break}case 126:{s="yDrS";break}case 127:{f[2]==127?s="rDrm":s="yDrm";break}default:f[0]<48?s="r:":s="M"}s.length<4&&(s+=`${[e,o,f[0],f[2]][n]-i}`.padStart(4-s.length,"0")),h=="xg"&&(e==0?f[2]<100?s=s.replace("y0","y:"):f[2]==125&&(s="y126"):e==16&&(g=`Voice${(f[2]*128+f[1]+1).toString().padStart(3,"0")}`,t=" "));let r=[f[0],f[1],f[2]];for(;!(g?.length>=0);)g=this.#t[f[1]||0][(f[0]<<7)+f[2]],g||(this.strictMode?(g="",t="?"):this.#t[f[1]||0][f[0]<<7]?f[0]==0?(f[2]=0,t="^"):f[2]<1?(f[0]=0,t="*"):(f[2]--,t="^"):e==48?(f[0]=0,f[2]=0,t="!"):e==62?(f[1]--,t=" ",f[1]<1&&!g?.length&&(f[0]=0,t="!")):e<63?f[0]==0?(f[2]=0,t="^"):f[2]<1?(f[0]=0,t="*"):f[2]--:e==80?(g=`PrgU:${a.toString().padStart(3,"0")}`,t="!"):e==88?(g=`CmbU:${a.toString().padStart(3,"0")}`,t="!"):e==121?(g=`GM2Vox0${o}`,t="#"):e==122?(f[1]==32?f[1]==0:f[1]%=7,g=this.#t[f[1]||0][(f[0]<<7)+f[2]],g?t=" ":(g="",t="*")):f[1]==0?(g=`${e.toString().padStart(3,"0")} ${a.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")}`,t="!"):f[0]==0?(f[2]=0,t="^"):f[2]>0?f[2]--:f[1]>0?(f[1]=0,t="!"):(f[0]=0,t="?"));let c=[f[0],f[1],f[2]];(h=="gs"||h=="ns5r")&&t=="^"&&(t=" "),e==127&&t=="^"&&(t=" "),t!=" "&&self.debugMode&&(g="");let d="??";switch(f[0]){case 0:{f[2]==0?d="GM":f[2]==5||f[2]==7?d="KG":f[2]<126?d="XG":f[2]==127&&(d="MT");break}case 48:{d="MU";break}case 56:{d="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{d="AI";break}case 62:case 82:case 90:{d="XD";break}case 63:{f[2]<17?d="KR":f[2]<34?d="ES":d="DS";break}case 64:case 126:{d="XG";break}case 67:case 99:{d=f[2]>>4==1?"SD":"DX";break}case 81:{d="RW";break}case 95:{d=["DR","PC"][f[2]];break}case 96:{d=f[2]==106?"AP":f[2]>>4==1?"SD":"PF";break}case 97:{d=f[2]>>4==1?"SD":"VL";break}case 98:{d=f[2]>>4==1?"SD":"SG";break}case 100:{d="AN";break}case 104:case 105:case 106:case 107:{d="SD";break}case 120:{d="GS";break}case 121:{d=f[2]?"G2":"GM";break}case 122:{d="KG";break}case 127:{d=f[2]==127?"MT":a==0?"GM":"XG";break}default:f[0]<48&&(f[0]==16&&h=="xg"?d="XG":d="GS")}return{name:g||`${G(e||0)} ${G(a||0)} ${G(o||0)}`,iid:r,eid:c,sid:y,ending:t,sect:s,standard:d}}async load(e,a,o){let h=this,y=[],g=0,f=0;e.split(` -`).forEach(function(t,s){let n=t.split(" "),i=[];s==0?n.forEach(function(r,c){y[ue.indexOf(r)]=c}):n.forEach(async function(r,c){c>2?(h.#t[i[y[1]]]=h.#t[i[y[1]]]||[],(!h.#t[i[y[1]]][(i[y[0]]<<7)+i[y[2]]]?.length||a)&&(h.#t[i[y[1]]][(i[y[0]]<<7)+i[y[2]]]=n[3],g++),f++):i.push(parseInt(n[c]))})}),a||console.debug(`Map "${o||"(internal)"}": ${f} total, ${g} loaded.`)}clearRange(e){let a=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],o=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],h=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let y=o[0];y<=o[1];y++){let g=y<<7;for(let f=h[0];f<=h[1];f++){let t=g+f;for(let s=a[0];s<=a[1];s++)delete this.#t[s][t]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let a=this;e.forEach(async function(o,h){try{await fetch(`./data/bank/${o}.tsv`).then(function(y){return y.text()}).then(y=>{a.load(y,!1,o)})}catch{console.error(`Failed loading "${o}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var q=class{#t={};context;set(e,a){this.#t[e]=a}has(e){return!!this.#t[e]}async read(e,a){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,a)}};var pe=function(e,a){let o=!0;return a.forEach((h,y)=>{o=o&&e[y]==h}),o},Q=function(e){let a=0;return e.forEach(o=>{a*=256,a+=o}),a},O=new TextDecoder,N=new q;N.set("s7e",async function(e){let a=new Uint8Array(await e.slice(0,65536).arrayBuffer()),o="MSB LSB PRG NME",h=[0,0,0,0],y=32,g=0,f=0,t=!0,s=[],n=0;for(;t;){let i=a.subarray(g);([()=>{O.decode(i.subarray(0,4))=="YSFC"?(g+=80,f=1):g++},()=>{if(pe(i.subarray(0,4),h))s.forEach((r,c,d)=>{let l=Q(a.subarray(r.start+4,r.start+8));r.length=l}),f=2;else{let r=O.decode(i.subarray(0,4)),c=Q(i.subarray(4,8));s.push({type:r,start:c}),g+=8}},()=>{let r=s[n],c=a.subarray(r.start,r.start+r.length),d=32;switch(r.type){case"ENVC":{let l=y;for(;l=s.length&&(f=3,t=!1)}][f]||(()=>{t=!1}))()}return o});var U=["off","hall","room","stage","plate","delay LCR","delay LR","echo","cross delay","early reflections","gate reverb","reverse gate"].concat(new Array(4),["white room","tunnel","canyon","basement","karaoke"],new Array(43),["pass through","chorus","celeste","flanger","symphonic","rotary speaker","tremelo","auto pan","phaser","distortion","overdrive","amplifier","3-band EQ","2-band EQ","auto wah"],new Array(1),["pitch change","harmonic","touch wah","compressor","noise gate","voice channel","2-way rotary speaker","ensemble detune","ambience"],new Array(4),["talking mod","Lo-Fi","dist + delay","comp + dist + delay","wah + dist + delay","V dist","dual rotor speaker"]),A=["melodic","drums","drum set 1","drum set 2","drum set 3","drum set 4","drum set 5","drum set 6","drum set 7","drum set 8"],be=[17.1,18.6,20.2,21.8,23.3,24.9,26.5,28,29.6,31.2,32.8,34.3,35.9,37.5,39,40.6,42.2,43.7,45.3,46.9,48.4,50],D=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],Y=[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],W=function(e){let a=.1,o=-.3;return e>66?(a=5,o=315):e>56?(a=1,o=47):e>46&&(a=.5,o=18.5),a*e-o},J=function(e){return e>105?be[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(","),_={};`hi*, +var K=function(e,a){let o=Math.min(e.length,a.length),h=e.slice(0,o),y=a.slice(0,o),g=0,d=0;for(;d0){let h=this.pool.length,y=1<=1&&d>=0;){if(d<=0)throw new Error("TTL reached.");if(g==h)g-=y;else{let s=K(a,this.pool[g]);switch(s){case 0:{d=0;break}case 1:{g+y<=h&&(g+=y);break}case-1:{g!=0&&(g-=y);break}default:console.warn(`Unexpected result ${s}.`)}}y=y>>1,d--}let t=!0;if(g>=this.pool.length)t=!1;else{let s=this;this.pool[g].forEach(function(n,i,r){t&&n!=a[i]&&(t=!1)}),!t&&K(a,this.pool[g])>0&&g++}return t||o?g:-1}else return o?0:-1},this.add=function(a,o){return a.data=o,this.pool.splice(this.point(a,!0),0,a),this},this.default=function(a){console.warn(`No match in "${this.name||"(unknown)"}" for "${a}". Default action not defined.`)},this.get=function(a){let o=this.point(a);if(o>-1)return this.pool[o].data;this.default(a)},this.run=function(a,...o){let h=this.point(a);h>-1?a.subarray?this.pool[h].data(a.subarray(this.pool[h].length),...o):this.pool[h].data(a.slice(this.pool[h].length),...o):this.default(a,...o)}};var z=class{#t={};addEventListener(e,a){this.#t[e]||(this.#t[e]=[]),this.#t[e].unshift(a)}removeEventListener(e,a){if(this.#t[e]){let o=this.#t[e].indexOf(a);o>-1&&this.#t[e].splice(o,1),this.#t[e].length<1&&delete this.#t[e]}}dispatchEvent(e,a){let o=new Event(e),h=this;o.data=a,this.#t[e]?.length>0&&this.#t[e].forEach(function(y){try{y?.call(h,o)}catch(g){console.error(g)}}),this[`on${e}`]&&this[`on${e}`](o)}};var ue=["MSB","PRG","LSB"],G=function(e){let a=Math.floor(e/10),o=e%10;return`${a.toString(16)}${o}`},B=class{#t;strictMode=!1;get(e=0,a=0,o=0,h){let y=[e,a,o],g,d=Array.from(arguments);switch(h){case"xg":{switch(e){case 0:{o==126?d[2]=125:o==127&&(d[2]=0);break}case 16:{o==126&&(d[2]=0);break}case 32:{o>125&&(d[2]=0),d[2]+=4;break}case 33:case 35:case 36:{o>125&&(d[2]=0),d[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:d[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{o==126&&(d[2]=0);break}case 48:case 64:case 126:case 127:{o==126&&(d[2]=0);break}}break}case"gs":{e==0&&o<5?d[2]=0:e>125&&o<5&&o!=2&&(d[2]=e,d[0]=0);break}case"g2":case"sd":{(e>>1==40||e>95&&e<100)&&(d[2]|=16);break}case"sg":{e==8&&o==0&&(d[2]=5);break}case"s90es":{o<8?d[2]+=17:o<32?d[2]+=13:d[2]=(d[2]>>3)+19;break}case"motif":{o<8?d[2]+=28:o<32?d[2]+=13:d[2]=(d[2]>>3)+19;break}}let t=" ",s="M",n=0,i=0;switch(d[0]){case 0:{d[2]==127?s="MT-a":d[2]==126?s="MT-b":d[2]==7?s="GM-k":d[2]==5?s="SG-a":d[2]==4?s="SP-l":d[2]==0||h=="gs"&&d[2]<5?s="GM-a":(s="y",n=3);break}case 8:{h=="sg"?s="GM-s":s="r:";break}case 48:{s=`yM${(d[2]>>3).toString().padStart(2,"0")}`,n=1;break}case 56:{s="GM-b";break}case 61:case 120:{s="rDrm";break}case 62:{s="kDrm";break}case 63:{if(d[2]<17){let l=d[2];s=l<10?"kP:":"kC:",s+=l%10}else d[2]<34?s=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][d[2]-17]:s="Ds";break}case 64:{s="ySFX";break}case 67:{s="DX:S";break}case 80:case 81:case 82:case 83:{s=`Prg${"UABC"[d[0]-80]}`;break}case 88:case 89:case 90:case 91:{s=`Cmb${"UABC"[d[0]-88]}`;break}case 95:{s=`${["DR","PC"][d[2]]}-d`;break}case 96:{s=d[2]==106?"AP-a":d[2]>>4==1?"SDg":"PF",d[2]>63?i=63:d[2]>>4==1&&(i=16),n=3;break}case 97:{s=d[2]>>4==1?"SDa":"VL:",n=3,d[2]>>4==1?i=16:i=112;break}case 98:{s=d[2]>>4==1?"SDb":"SG-a",n=3,i=16;break}case 99:{s=d[2]>>4==1?"SDc":"DX",d[2]>63?i=63:d[2]>>4==1&&(i=16),n=3;break}case 100:{s="AN",d[2]>63?i=63:d[2]>>4==1&&(i=16),n=3;break}case 104:case 105:case 106:case 107:{s="SDd",i=104;break}case 121:{s=`GM-${d[2]?"":"a"}`,n=3;break}case 122:{s="lDrm";break}case 126:{s="yDrS";break}case 127:{d[2]==127?s="rDrm":s="yDrm";break}default:d[0]<48?s="r:":s="M"}s.length<4&&(s+=`${[e,o,d[0],d[2]][n]-i}`.padStart(4-s.length,"0")),h=="xg"&&(e==0?d[2]<100?s=s.replace("y0","y:"):d[2]==125&&(s="y126"):e==16&&(g=`Voice${(d[2]*128+d[1]+1).toString().padStart(3,"0")}`,t=" "));let r=[d[0],d[1],d[2]];for(;!(g?.length>=0);)g=this.#t[d[1]||0][(d[0]<<7)+d[2]],g||(this.strictMode?(g="",t="?"):this.#t[d[1]||0][d[0]<<7]?d[0]==0?(d[2]=0,t="^"):d[2]<1?(d[0]=0,t="*"):(d[2]--,t="^"):e==48?(d[0]=0,d[2]=0,t="!"):e==62?(d[1]--,t=" ",d[1]<1&&!g?.length&&(d[0]=0,t="!")):e<63?d[0]==0?(d[2]=0,t="^"):d[2]<1?(d[0]=0,t="*"):d[2]--:e==80?(g=`PrgU:${a.toString().padStart(3,"0")}`,t="!"):e==88?(g=`CmbU:${a.toString().padStart(3,"0")}`,t="!"):e==121?(g=`GM2Vox0${o}`,t="#"):e==122?(d[1]==32?d[1]==0:d[1]%=7,g=this.#t[d[1]||0][(d[0]<<7)+d[2]],g?t=" ":(g="",t="*")):d[1]==0?(g=`${e.toString().padStart(3,"0")} ${a.toString().padStart(3,"0")} ${o.toString().padStart(3,"0")}`,t="!"):d[0]==0?(d[2]=0,t="^"):d[2]>0?d[2]--:d[1]>0?(d[1]=0,t="!"):(d[0]=0,t="?"));let c=[d[0],d[1],d[2]];(h=="gs"||h=="ns5r")&&t=="^"&&(t=" "),e==127&&t=="^"&&(t=" "),t!=" "&&self.debugMode&&(g="");let f="??";switch(d[0]){case 0:{d[2]==0?f="GM":d[2]==5||d[2]==7?f="KG":d[2]<126?f="XG":d[2]==127&&(f="MT");break}case 32:case 33:case 35:case 36:{d[2]>4?f=["AP","VL","PF","DX","AN"][d[0]-32]:f="GS";break}case 48:{f="MU";break}case 56:{f="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{f="AI";break}case 62:case 82:case 90:{f="XD";break}case 63:{d[2]<17?f="KR":d[2]<34?f="ES":f="DS";break}case 64:case 126:{f="XG";break}case 67:case 99:{f=d[2]>>4==1?"SD":"DX";break}case 81:{f="RW";break}case 95:{f=["DR","PC"][d[2]];break}case 96:{f=d[2]==106?"AP":d[2]>>4==1?"SD":"PF";break}case 97:{f=d[2]>>4==1?"SD":"VL";break}case 98:{f=d[2]>>4==1?"SD":"SG";break}case 100:{f="AN";break}case 104:case 105:case 106:case 107:{f="SD";break}case 120:{f="GS";break}case 121:{f=d[2]?"G2":"GM";break}case 122:{f="KG";break}case 127:{f=d[2]==127?"MT":a==0?"GM":"XG";break}default:d[0]<48&&(d[0]==16&&h=="xg"?f="XG":f="GS")}return{name:g||`${G(e||0)} ${G(a||0)} ${G(o||0)}`,iid:r,eid:c,sid:y,ending:t,sect:s,standard:f}}async load(e,a,o){let h=this,y=[],g=0,d=0;e.split(` +`).forEach(function(t,s){let n=t.split(" "),i=[];s==0?n.forEach(function(r,c){y[ue.indexOf(r)]=c}):n.forEach(async function(r,c){c>2?(h.#t[i[y[1]]]=h.#t[i[y[1]]]||[],(!h.#t[i[y[1]]][(i[y[0]]<<7)+i[y[2]]]?.length||a)&&(h.#t[i[y[1]]][(i[y[0]]<<7)+i[y[2]]]=n[3],g++),d++):i.push(parseInt(n[c]))})}),a||console.debug(`Map "${o||"(internal)"}": ${d} total, ${g} loaded.`)}clearRange(e){let a=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],o=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],h=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let y=o[0];y<=o[1];y++){let g=y<<7;for(let d=h[0];d<=h[1];d++){let t=g+d;for(let s=a[0];s<=a[1];s++)delete this.#t[s][t]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let a=this;e.forEach(async function(o,h){try{await fetch(`./data/bank/${o}.tsv`).then(function(y){return y.text()}).then(y=>{a.load(y,!1,o)})}catch{console.error(`Failed loading "${o}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var q=class{#t={};context;set(e,a){this.#t[e]=a}has(e){return!!this.#t[e]}async read(e,a){if(!this.has(e))throw new Error(`No decoder registered for "${e}"`);return await this.#t[e].call(this.context||this,a)}};var pe=function(e,a){let o=!0;return a.forEach((h,y)=>{o=o&&e[y]==h}),o},Q=function(e){let a=0;return e.forEach(o=>{a*=256,a+=o}),a},O=new TextDecoder,H=new q;H.set("s7e",async function(e){let a=new Uint8Array(await e.slice(0,65536).arrayBuffer()),o="MSB LSB PRG NME",h=[0,0,0,0],y=32,g=0,d=0,t=!0,s=[],n=0;for(;t;){let i=a.subarray(g);([()=>{O.decode(i.subarray(0,4))=="YSFC"?(g+=80,d=1):g++},()=>{if(pe(i.subarray(0,4),h))s.forEach((r,c,f)=>{let l=Q(a.subarray(r.start+4,r.start+8));r.length=l}),d=2;else{let r=O.decode(i.subarray(0,4)),c=Q(i.subarray(4,8));s.push({type:r,start:c}),g+=8}},()=>{let r=s[n],c=a.subarray(r.start,r.start+r.length),f=32;switch(r.type){case"ENVC":{let l=y;for(;l=s.length&&(d=3,t=!1)}][d]||(()=>{t=!1}))()}return o});var A=["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"]),U=["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"],be=[17.1,18.6,20.2,21.8,23.3,24.9,26.5,28,29.6,31.2,32.8,34.3,35.9,37.5,39,40.6,42.2,43.7,45.3,46.9,48.4,50],D=[20,22,25,28,32,36,40,45,50,56,63,70,80,90,100,110,125,140,160,180,200,225,250,280,315,355,400,450,500,560,630,700,800,900,1e3,1100,1200,1400,1600,1800,2e3,2200,2500,2800,3200,3600,4e3,4500,5e3,5600,6300,7e3,8e3,9e3,1e4,11e3,12e3,14e3,16e3,18e3,2e4],Y=[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],W=function(e){let a=.1,o=-.3;return e>66?(a=5,o=315):e>56?(a=1,o=47):e>46&&(a=.5,o=18.5),a*e-o},J=function(e){return e>105?be[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(","),_={};`hi*, ka,か ki,き ku,く @@ -139,8 +139,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let a=e.split(",");_[a[0]]=a[1]});var j=function(e){let a=e;e[0]=="*"&&(a=a.slice(1)),["aa","ii","uu","ee","oo"].forEach(h=>{for(;a.indexOf(h)>-1;)a=a.replace(h,h[0])});for(let h in _)a=a.replaceAll(h,_[h]);a.indexOf("ん")==0&&a.length>1&&(a=a.slice(1));let o=a.indexOf("!");return o>-1&&a.length>1&&(a=a.slice(o+1)),a},ee=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var I=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],te=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ae=["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 ye={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},$e={66307:["drive"],66309:["vowel",e=>"aiueo"[e]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",e=>["off","LPF","HPF"][e]],94984:["noise type",e=>["white","pink"][e]],94987:["disc type",e=>["LP","SP","EP","RND"]],94990:["hum type",e=>`${e+5}0Hz`],94993:["M/S",e=>["mono","stereo"][e]]},X=function(e){return ye[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},se=function(e,a,o){let h=(e[0]-32<<16)+(e[1]<<8)+a,y=$e[h]||{},g=y[0];if(g?.length)return g+=`: ${(y[1]||function(){})(o)||o}`,g},V=[68,48,95,78,41,3,110,122,0];var S=function(e=64){return Math.round(2e3*Math.log10(e/64))/100};var K=function(e){let a=0;return e.forEach(o=>{a+=o,a=a&127}),~a+1&127},T=function(e,a){let o=0,h=0;for(let y=0;y>g&1)<<7,t=e[y];t+=f,y%8!=0?(a(t,o,e),o++):h=e[y]}},P=function(e){let a=Math.floor(e*14.2);return a<128?a:0};var M=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],re=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],R=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],ge=[0,3,81,84,88],ie={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},ne={0:0,1:1,2:3,5:4},ce={0:0,1:1,2:2,5:3},oe=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],le=[36,37,48,49,52,53],L=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],de={26:127,29:0,30:0,31:0,52:12,53:54},H=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19],Ee=[12,13,16,17,18,19],me=[33,99,100,32,102,8,9,10],fe=[0,16,25,40,32,64,26,48],m={};M.forEach((e,a)=>{m[e]=a});var u={length:H.length};H.forEach((e,a)=>{u[e]=a});var C={length:L.length};L.forEach((e,a)=>{C[e]=a});var w=function(){return!!self.Bun||self.debugMode||!1},we=function(e){let a=[],o=0;return e?.forEach(function(h,y){h==247?a.push(e.subarray(o,y)):h==240&&(o=y+1)}),a.length||a.push(e.subarray(0)),w()&&console.debug(a),a};var b={ch:128,cc:H.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:L.length,dnc:128,efx:7},Fe=class extends z{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;#p=0;#C=0;#M=new Array(11);get#y(){return this.#M[this.#p]}set#y(e){this.#M[this.#p]=e}#R=new Uint8Array(b.ch);#f=new Uint8Array(b.ch);#s=new Uint8Array(b.ch);#e=new Uint8Array(b.ch*b.cc);#D=new Uint8Array(b.ace);#i=new Uint8Array(b.ch);#o=new Uint8Array(b.ch*b.nn);#$=new Uint8Array(b.ch);#l=new Uint16Array(b.pl);#h=new Uint8Array(b.pl);#A=new Int16Array(b.ch);#x=new Uint8Array(b.ch);#_=0;#a=new Uint8Array(b.ch*b.rpn);#r=new Uint8Array(b.ch*b.rpnt);#Q=new Int8Array(b.ch*le.length);#b=new Uint8Array(b.drm*b.dpn*b.dnc);#T=new Uint8Array(b.ch);#P=new Uint8Array(128);#v=new Uint8Array(b.cmt*8);#Y=new Uint8Array(1024);#H=new Uint8Array(b.cmt*64);#g=new Uint8Array(b.efx*3);#W=new Uint8Array(b.ch);#N=0;#m=0;#n=100;#I=0;#J=500;#Z=0;#L="";#G=0;#ee=0;#j=0;#S=!0;#c=!1;#te;#re=new Uint8Array(2);#E=[];#O=new Uint8Array(b.ch);#B=new Uint8Array(b.tr);baseBank=new B("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es");userBank=new B("gm");initOnReset=!1;aiEfxName="";chRedir(e,a,o){if(this.#B[a])return(this.#B[a]-1)*16+e;if([2,3].indexOf(this.#m)>-1){if(o==1)return e;let h=0,y=!0;for(;y;)this.#O[e+h]==0?(this.#O[e+h]=a,console.debug(`Assign track ${a} to channel ${e+h+1}.`),y=!1):this.#O[e+h]==a?y=!1:(h+=16,h>=128&&(h=0,y=!1));return e+h}else return e}forceVoiceRefresh(){for(let e=0;e{let o=e*128+a,h=this.#l.lastIndexOf(o);h>-1&&(this.#e[b.cc*e+u[64]]>63?(this.#h[h]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:a,velo:this.#o[o],state:this.NOTE_HELD})):this.#e[b.cc*e+u[66]]>63&&this.#h[h]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#h[h]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:a,velo:this.#o[o],state:this.NOTE_SOSTENUTO_HELD})):(this.#l[h]=0,this.#o[o]=0,this.#h[h]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:a,velo:0,state:this.NOTE_IDLE})))},nOn:(e,a,o)=>{let h=e*128+a,y=0;for(this.#$[e]&&this.#d.ano(e);this.#h[y]>0&&this.#l[y]!=h;)y++;y{},cAt:(e,a)=>{},hoOf:e=>{this.#h.forEach((a,o)=>{if(a==this.NOTE_HELD){let h=this.#l[o],y=h>>7;e==y&&(this.#h[o]=this.NOTE_IDLE,this.#l[o]=0,this.#o[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#h.forEach((a,o)=>{let h;switch(a){case this.NOTE_ATTACK:{h=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{h=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{h=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(h){this.#h[o]=h;let y=this.#l[o];this.dispatchEvent("note",{part:e,note:y&127,velo:this.#o[y],state:h})}})},soOf:e=>{this.#h.forEach((a,o)=>{if(a==this.NOTE_SOSTENUTO_HELD){let h=this.#l[o],y=h>>7;e==y&&(this.#h[o]=this.NOTE_IDLE,this.#l[o]=0,this.#o[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#l.forEach((a,o,h)=>{let y=a>>7,g=a&127;a==0&&this.#o[0]==0||y==e&&this.#d.nOff(y,g)})}};#ae={8:function(e){let a=e.channel,o=e.data[0];this.#d.nOff(a,o)},9:function(e){let a=e.channel;this.setChActive(a,1);let o=e.data[0],h=e.data[1];h>0?this.#d.nOn(a,o,h):this.#d.nOff(a,o)},10:function(e){let a=e.channel,o=a*128+e.data[0];this.#l.indexOf(o)>-1&&(this.#o[o]=data[1],this.dispatchEvent("note",{part:a,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let a=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case m.s90es:case m.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(a,1);break}e.data[1]&&this.setChActive(a,1);break}default:{this.setChActive(a,1);break}}})();let o=a*b.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#d.ano(a),this.#A[a]=0;let h=a*b.cc;this.#e[h+u[1]]=0,this.#e[h+u[5]]=0,this.#e[h+u[64]]=0,this.#e[h+u[65]]=0,this.#e[h+u[66]]=0,this.#e[h+u[67]]=0,this.#e[h+u[11]]=127,this.#e[h+u[101]]=127,this.#e[h+u[100]]=127,this.#e[h+u[99]]=127,this.#e[h+u[98]]=127;return}case 123:{this.#d.ano(a);return}case 124:{this.#d.ano(a);return}case 125:{this.#d.ano(a);return}case 126:{this.#$[a]=1,this.#d.ano(a);return}case 127:{this.#$[a]=0,this.#d.ano(a);return}}if(u[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Ee.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(w()&&console.debug(`${M[this.#t]}, CH${a+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#s[a]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==m.gs?e.data[1]<56&&this.#s[a]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)):this.#t==m.gm?e.data[1]<48?this.#s[a]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${a+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):this.#t==m.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),this.#t){case m.xg:{[126,127].indexOf(e.data[1])>-1?this.#s[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#s[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m["05rw"]:case m.x5d:case m.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#s[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#s[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#s[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#s[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m.g2:{e.data[1]==120?this.#s[a]==0&&(this.setChType(a,this.CH_DRUMS),console.debug(`CH${a+1} set to drums by MSB.`)):this.#s[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:a});break}case 6:{if(this.#_){[m.xg,m.gs,m.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${M[this.#t]}" mode, even when they are supported in Octavia.`);let h=this.#e[o+u[99]],y=this.#e[o+u[98]];if(h==1){let g=me.indexOf(y);if(g>-1)this.#e[o+u[71+g]]=e.data[1],w()&&console.debug(`Redirected NRPN 1 ${y} to cc${71+g}.`),this.dispatchEvent("cc",{part:a,cc:71+g,data:e.data[1]});else{let f=le.indexOf(y);f>-1?this.#Q[a*10+f]=e.data[1]-64:console.warn(`NRPN 0x01${y.toString(16).padStart(2,"0")} is not supported.`),w()&&console.debug(`CH${a+1} voice NRPN ${y} commit`)}}else{if(L.indexOf(h)<0){let f=`NRPN 0x${h.toString(16).padStart(2,"0")}${y.toString(16).padStart(2,"0")} `;h==127?console.warn(`${f}is not necessary. Consider removing it.`):console.warn(`${f}is not supported.`)}else{let f=this.#s[a]-2;f<0?console.warn(`CH${a+1} cannot accept drum NRPN as type ${A[this.#s[a]]}.`):this.#b[(f*b.dpn+C[h])*b.dnc+y]=e.data[1]}w()&&console.debug(`CH${a+1} (${A[this.#s[a]]}) drum NRPN ${h} commit`)}}else{let h=ne[this.#e[o+u[100]]],y=ce[this.#e[o+u[100]]];this.#e[o+u[101]]==0&&h!=null&&(w()&&console.debug(`CH${a+1} RPN 0 ${this.#e[o+u[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],oe[h][0]),oe[h][1]),this.#a[a*b.rpn+h]=e.data[1],this.#r[a*b.rpnt+y]=1)}break}case 32:{switch(w()&&console.debug(`${M[this.#t]}, CH${a+1} LSB: ${e.data[1]}`),this.#t){case m.s90es:case m.motif:{this.setChType(a,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.dispatchEvent("voice",{part:a});break}case 38:{if(!this.#_){let h=ne[this.#e[o+100]],y=ce[this.#e[o+100]];this.#e[o+101]==0&&h!=null&&(this.#a[a*b.rpn+h+1]=e.data[1],this.#r[a*b.rpnt+y]=1)}break}case 64:{e.data[1]<64&&this.#d.hoOf(a);break}case 66:{e.data[1]>>6?this.#d.soOn(a):this.#d.soOf(a);break}case 98:case 99:{this.#_=1;break}case 100:case 101:{this.#_=0;break}}this.#e[o+u[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:a,cc:e.data[0],data:e.data[1]})}},12:function(e){let a=e.channel;switch(this.#t){case m.s90es:case m.motif:{e.data&&this.setChActive(a,1);break}default:this.setChActive(a,1)}this.#i[a]=e.data,this.#T[a]=0,w()&&console.debug(`T:${e.track} C:${a} P:${e.data}`),this.dispatchEvent("voice",{part:a})},13:function(e){let a=this,o=e.channel;this.#l.forEach(function(h){let y=h>>7;o==y&&(a.#o[h]=e.data,a.dispatchEvent("note",{part:o,note:h&127,velo:e.data,state:a.NOTE_SUSTAIN}))})},14:function(e){let a=e.channel;this.#A[a]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)})},15:function(e){we(e.data).forEach(a=>{let o=a[0],h=a[1];(this.#se[o]||function(){console.debug(`Unknown manufacturer ${o}.`)})(h,a.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#u[e.meta]||function(o,h,y){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#I=0);let a=ge.indexOf(e.meta)>-1;if(w()&&console.debug(e),a)return e.reply="meta",e}};#se={64:(e,a,o)=>{this.#F.run(a,o,e)},65:(e,a,o)=>{if(a[0]<16)if(a[1]==72){let h=a[a.length-1],y=K(a.subarray(3,a.length-1));h==y?this.#k.run(a.subarray(0,a.length-1),o,e):console.warn(`Bad SD checksum ${h}. Should be ${y}.`)}else this.#k.run(a,o,e);else{let h=a[a.length-1],y=K(a.subarray(2,a.length-1));h==y?this.#k.run(a.subarray(0,a.length-1),o,e):console.warn(`Bad GS checksum ${h}. Should be ${y}.`)}},66:(e,a,o)=>{this.#U.run(a,o,e)},67:(e,a,o)=>{this.#w.run(a,o,e)},68:(e,a,o)=>{this.#q.run(a,o,e)},71:(e,a,o)=>{this.#z.run(a,o,e)},126:(e,a,o)=>{this.#V.run(a,o,e)},127:(e,a,o)=>{this.switchMode("gm"),this.#K.run(a,o,e)}};#V;#K;#w;#k;#U;#F;#z;#q;buildRchTree(){let e=[];this.#f.forEach((a,o)=>{a0&&!h&&(this.#e[e*b.cc+u[0]]=R[o])}setChActive(e,a=0){this.#R[e]!=a&&this.dispatchEvent("channeltoggle",{part:e,active:a}),this.#R[e]=a}getPitch(){return this.#A}getProgram(){return this.#i}getTexts(){return this.#E.slice()}getVel(e){let a=new Map,o=this;return o.#l.forEach(function(h,y){let g=Math.floor(h/128),f=h%128;e==g&&o.#o[h]>0&&a.set(f,{v:o.#o[h],s:o.#h[y]})}),a}getBitmap(){return{bitmap:this.#y,expire:this.#C}}getLetter(){return{text:this.#L,set:this.#ee,expire:this.#G}}getMode(){return M[this.#t]}getMaster(){return{volume:this.#n}}getRawStrength(){let e=this;return this.#l.forEach(function(a){let o=Math.floor(a/128);e.#o[a]>e.#x[o]&&(e.#x[o]=e.#o[a])}),this.#x}getStrength(){let e=[],a=this;return this.getRawStrength().forEach(function(o,h){e[h]=Math.floor(o*a.#e[h*b.cc+u[7]]*a.#e[h*b.cc+u[11]]*a.#n/803288)}),e}getRpn(){return this.#a}getNrpn(){return this.#Q}getVoice(e,a,o,h){let y=e||this.#N,g=a,f=o||this.#m;M[this.#t]=="ns5r"&&y>0&&y<56&&(f=3);let t=this.userBank.get(y,g,f,h);if(M[this.#t]=="mt32"&&t.name.indexOf("MT-m:")==0){let s=parseInt(t.name.slice(5)),n=s*b.cmt,i="";this.#H.subarray(n,n+10).forEach(r=>{r>31&&(i+=String.fromCharCode(r))}),this.userBank.load(`MSB LSB PRG -0 127 ${g} ${i}`,!0),t.name=i,t.ending=" "}return(t.ending!=" "||!t.name.length)&&(t=this.baseBank.get(y,g,f,h)),t}getChVoice(e){let a=this.getVoice(this.#e[e*b.cc+u[0]],this.#i[e],this.#e[e*b.cc+u[32]],M[this.#t]);if(this.#T[e])switch(this.#t){case m.mt32:a.ending="~",a.name="",this.#v.subarray(14*(e-1),14*(e-1)+10).forEach(o=>{o>31&&(a.name+=String.fromCharCode(o))})}return a}getPitchShift(e){let a=this,o=e*b.rpn,h=a.#a[o];return a.#r[e*b.rpnt]||a.#t==m.mt32&&(h=12),a.#A[e]/8192*h+(a.#a[o+3]-64)+((a.#a[o+1]<<7)+a.#a[o+2]-8192)/8192}getEffectType(e=0){let a=3*e+1;return this.#g.subarray(a,a+2)}setEffectTypeRaw(e=0,a,o){let h=3*e;this.#g[h]=1,this.#g[h+1+ +a]=o}setEffectType(e=0,a,o){this.setEffectTypeRaw(e,!1,a),this.setEffectTypeRaw(e,!0,o)}getEffectSink(){return this.#W}setLetterDisplay(e,a,o=0,h=3200){let y=this,g;y.#L=" ".repeat(o),e.forEach(f=>{y.#L+=String.fromCharCode(f>31?f:32),f<32&&(g=g||new Set,g.add(f))}),y.#ee=Date.now(),y.#G=Date.now()+h,g&&(g=Array.from(g),g.forEach((f,t,s)=>{s[t]=f.toString(16).padStart(2,"0")}),console.warn(`${a}${a?" ":""}invalid code point${g.length>1?"s":""}: 0x${g.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let a=!0,o=0;for(;a&&o=b.ace&&console.warn("ACE slots are full.")}getAce(){return this.#D}getChAce(e,a){if(a<0||a>=b.ace)throw new RangeError("No such ACE slot");let o=this.#D[a];if(o){if(H.indexOf(o)>=0)return this.#e[e*b.cc+u[o]];throw new Error(`Invalid ACE source: ${o}`)}else return 0}initDrums(){let e=this;e.#b.fill(64);for(let a=0;a-1){if(o.#t==0||a){let y=o.#t;o.initOnReset&&a&&(this.init(1),y=m["?"]),o.#t=h,o.#p=0,o.#N=re[0][h],o.#m=re[1][h];for(let f=0;f0&&o.#e[f*b.cc+u[0]]==R[y]&&(o.#e[f*b.cc]=R[h]);switch(h){case m.mt32:{V.forEach((f,t)=>{let s=t+1;o.#R[s]||(o.#i[s]=f,o.#e[s*b.cc+u[91]]=127)});for(let f=1;f<10;f++)o.dispatchEvent("voice",{part:f});break}}let g;switch(h){case m["?"]:case m.xg:{g=[1,0,65,0,5,0,0,0];break}case m.gm:case m.gs:case m.g2:case m.sd:{g=[40,4,40,18,40,32,32,0];break}case m["05rw"]:case m.x5d:case m.ns5r:{g=[44,1,44,19,44,0,44,0];break}case m.k11:case m.sg:{g=[24,0,0,0,0,0,0,0];break}case m.mt32:{g=[40,4,0,0,0,0,0,0];break}default:g=[0,0,0,0,0,0,0,0]}for(let f=0;f<4;f++)o.#g[3*f]||(o.#g[3*f+1]=g[2*f],o.#g[3*f+2]=g[2*f+1],o.dispatchEvent(`efx${["reverb","chorus","delay","insert"][f]}`,o.getEffectType(f)));o.dispatchEvent("mode",e),o.forceVoiceRefresh()}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#x.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#ae[e.type].call(this,e);{let a=this.chRedir(e.part,e.track),o=!1;this.#te[a]?.forEach(h=>{e.channel=h,o=!0,this.#ae[e.type].call(this,e)}),o||console.warn(`${ie[e.type]?ie[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${a+1} without any recipient.`)}this.#E.length>100&&this.#E.splice(100,this.#E.length-99)}runRaw(e){}async loadBank(e,a){let o=this;switch(e=e.toLowerCase(),e){case"s7e":{o.userBank.clearRange({msb:63,lsb:[21,22]}),o.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{N.context=this,o.userBank.load(await N.read(e,a));break}}o.forceVoiceRefresh()}constructor(){super();let e=this;this.#y=new Uint8Array(256),this.#M[10]=new Uint8Array(512),this.#X=new x,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let a=e.split(",");_[a[0]]=a[1]});var j=function(e){let a=e;e[0]=="*"&&(a=a.slice(1)),["aa","ii","uu","ee","oo"].forEach(h=>{for(;a.indexOf(h)>-1;)a=a.replace(h,h[0])});for(let h in _)a=a.replaceAll(h,_[h]);a.indexOf("ん")==0&&a.length>1&&(a=a.slice(1));let o=a.indexOf("!");return o>-1&&a.length>1&&(a=a.slice(o+1)),a},ee=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var I=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],te=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ae=["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 ye={0:"thru",256:"stereo EQ",257:"spectrum",258:"enhancer",259:"humanizer",272:"overdrive",273:"distortion",288:"phaser",289:"auto wah",290:"rotary",291:"stereo flanger",292:"step flanger",293:"tremelo",294:"auto pan",304:"compressor",305:"limiter",320:"hexa chorus",321:"tremelo chorus",322:"stereo chorus",323:"space D",324:"3D chorus",336:"stereo delay",337:"modulated delay",338:"3-tap delay",339:"4-tap delay",340:"tremelo control delay",341:"reverb",342:"gate reverb",343:"3D delay",352:"2-pitch shifter",353:"feedback pitch shifter",368:"3D auto",369:"3D manual",370:"Lo-Fi 1",371:"Lo-Fi 2",512:"overdrive - chorus",513:"overdrive - flanger",514:"overdrive - delay",515:"distortion - chorus",516:"distortion - flanger",517:"distortion - delay",518:"enhancer - chorus",519:"enhancer - flanger",520:"enhancer - delay",521:"chorus - delay",522:"flanger - delay",523:"chorus - flanger",524:"rotary multi",1024:"guitar multi 1",1025:"guitar multi 2",1026:"guitar multi 3",1027:"clean guitar multi 1",1028:"clean guitar multi 2",1029:"bass multi",1030:"rhodes multi",1280:"keyboard multi",4352:"chorus / delay",4353:"flanger / delay",4354:"chorus / flanger",4355:"overdrive / distortion",4356:"overdrive / rotary",4357:"overdrive / phaser",4358:"overdrive / auto wah",4359:"phaser / rotary",4360:"phaser / auto wah"},$e={66307:["drive"],66309:["vowel",e=>"aiueo"[e]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",e=>["off","LPF","HPF"][e]],94984:["noise type",e=>["white","pink"][e]],94987:["disc type",e=>["LP","SP","EP","RND"]],94990:["hum type",e=>`${e+5}0Hz`],94993:["M/S",e=>["mono","stereo"][e]]},X=function(e){return ye[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},se=function(e,a,o){let h=(e[0]-32<<16)+(e[1]<<8)+a,y=$e[h]||{},g=y[0];if(g?.length)return g+=`: ${(y[1]||function(){})(o)||o}`,g},V=[68,48,95,78,41,3,110,122,0];var S=function(e=64){return Math.round(2e3*Math.log10(e/64))/100};var F=function(e){let a=0;return e.forEach(o=>{a+=o,a=a&127}),~a+1&127},T=function(e,a){let o=0,h=0;for(let y=0;y>g&1)<<7,t=e[y];t+=d,y%8!=0?(a(t,o,e),o++):h=e[y]}},P=function(e){let a=Math.floor(e*14.2);return a<128?a:0};var M=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],re=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],R=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],ge=[0,3,81,84,88],ie={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},ne={0:0,1:1,2:3,5:4},ce={0:0,1:1,2:2,5:3},oe=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],le=[36,37,48,49,52,53],L=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],fe={26:127,29:0,30:0,31:0,52:12,53:54},N=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19,14,15,20,21],Ee=[12,13,14,15,16,17,18,19,20,21],me=[33,99,100,32,102,8,9,10],de=[0,16,25,40,32,64,26,48],m={};M.forEach((e,a)=>{m[e]=a});var u={length:N.length};N.forEach((e,a)=>{u[e]=a});var C={length:L.length};L.forEach((e,a)=>{C[e]=a});var k=function(){return!!self.Bun||self.debugMode||!1},ke=function(e){let a=[],o=0;return e?.forEach(function(h,y){h==247?a.push(e.subarray(o,y)):h==240&&(o=y+1)}),a.length||a.push(e.subarray(0)),k()&&console.debug(a),a};var b={ch:128,cc:N.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:L.length,dnc:128,efx:7},Ke=class extends z{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;#p=0;#C=0;#M=new Array(11);get#y(){return this.#M[this.#p]}set#y(e){this.#M[this.#p]=e}#R=new Uint8Array(b.ch);#d=new Uint8Array(b.ch);#s=new Uint8Array(b.ch);#e=new Uint8Array(b.ch*b.cc);#D=new Uint8Array(b.ace);#i=new Uint8Array(b.ch);#o=new Uint8Array(b.ch*b.nn);#$=new Uint8Array(b.ch);#l=new Uint16Array(b.pl);#h=new Uint8Array(b.pl);#U=new Int16Array(b.ch);#x=new Uint8Array(b.ch);#_=0;#a=new Uint8Array(b.ch*b.rpn);#r=new Uint8Array(b.ch*b.rpnt);#Q=new Int8Array(b.ch*le.length);#b=new Uint8Array(b.drm*b.dpn*b.dnc);#T=new Uint8Array(b.ch);#P=new Uint8Array(128);#v=new Uint8Array(b.cmt*8);#Y=new Uint8Array(1024);#N=new Uint8Array(b.cmt*64);#g=new Uint8Array(b.efx*3);#W=new Uint8Array(b.ch);#H=0;#m=0;#n=100;#I=0;#J=500;#Z=0;#L="";#G=0;#ee=0;#j=0;#S=!0;#c=!1;#te;#re=new Uint8Array(2);#E=[];#O=new Uint8Array(b.ch);#B=new Uint8Array(b.tr);baseBank=new B("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es");userBank=new B("gm");initOnReset=!1;aiEfxName="";chRedir(e,a,o){if(this.#B[a])return(this.#B[a]-1)*16+e;if([2,3].indexOf(this.#m)>-1){if(o==1)return e;let h=0,y=!0;for(;y;)this.#O[e+h]==0?(this.#O[e+h]=a,console.debug(`Assign track ${a} to channel ${e+h+1}.`),y=!1):this.#O[e+h]==a?y=!1:(h+=16,h>=128&&(h=0,y=!1));return e+h}else return e}forceVoiceRefresh(){for(let e=0;e{let o=e*128+a,h=this.#l.lastIndexOf(o);h>-1&&(this.#e[b.cc*e+u[64]]>63?(this.#h[h]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:a,velo:this.#o[o],state:this.NOTE_HELD})):this.#e[b.cc*e+u[66]]>63&&this.#h[h]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#h[h]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:a,velo:this.#o[o],state:this.NOTE_SOSTENUTO_HELD})):(this.#l[h]=0,this.#o[o]=0,this.#h[h]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:a,velo:0,state:this.NOTE_IDLE})))},nOn:(e,a,o)=>{let h=e*128+a,y=0;for(this.#$[e]&&this.#f.ano(e);this.#h[y]>0&&this.#l[y]!=h;)y++;y{},cAt:(e,a)=>{},hoOf:e=>{this.#h.forEach((a,o)=>{if(a==this.NOTE_HELD){let h=this.#l[o],y=h>>7;e==y&&(this.#h[o]=this.NOTE_IDLE,this.#l[o]=0,this.#o[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#h.forEach((a,o)=>{let h;switch(a){case this.NOTE_ATTACK:{h=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{h=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{h=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(h){this.#h[o]=h;let y=this.#l[o];this.dispatchEvent("note",{part:e,note:y&127,velo:this.#o[y],state:h})}})},soOf:e=>{this.#h.forEach((a,o)=>{if(a==this.NOTE_SOSTENUTO_HELD){let h=this.#l[o],y=h>>7;e==y&&(this.#h[o]=this.NOTE_IDLE,this.#l[o]=0,this.#o[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#l.forEach((a,o,h)=>{let y=a>>7,g=a&127;a==0&&this.#o[0]==0||y==e&&this.#f.nOff(y,g)})}};#ae={8:function(e){let a=e.channel,o=e.data[0];this.#f.nOff(a,o)},9:function(e){let a=e.channel;this.setChActive(a,1);let o=e.data[0],h=e.data[1];h>0?this.#f.nOn(a,o,h):this.#f.nOff(a,o)},10:function(e){let a=e.channel,o=a*128+e.data[0];this.#l.indexOf(o)>-1&&(this.#o[o]=data[1],this.dispatchEvent("note",{part:a,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let a=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(this.#t){case m.s90es:case m.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(a,1);break}e.data[1]&&this.setChActive(a,1);break}default:{this.setChActive(a,1);break}}})();let o=a*b.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#f.ano(a),this.#U[a]=0;let h=a*b.cc;this.#e[h+u[1]]=0,this.#e[h+u[5]]=0,this.#e[h+u[64]]=0,this.#e[h+u[65]]=0,this.#e[h+u[66]]=0,this.#e[h+u[67]]=0,this.#e[h+u[11]]=127,this.#e[h+u[101]]=127,this.#e[h+u[100]]=127,this.#e[h+u[99]]=127,this.#e[h+u[98]]=127;return}case 123:{this.#f.ano(a);return}case 124:{this.#f.ano(a);return}case 125:{this.#f.ano(a);return}case 126:{this.#$[a]=1,this.#f.ano(a);return}case 127:{this.#$[a]=0,this.#f.ano(a);return}}if(u[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Ee.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(k()&&console.debug(`${M[this.#t]}, CH${a+1}: ${e.data[1]}`),this.#t==0?e.data[1]<48?(this.#s[a]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):this.#t==m.gs?e.data[1]<56&&this.#s[a]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${a+1} to stay drums.`)):this.#t==m.gm?e.data[1]<48?this.#s[a]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${a+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):this.#t==m.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),this.#t){case m.xg:{[126,127].indexOf(e.data[1])>-1?this.#s[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#s[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m["05rw"]:case m.x5d:case m.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#s[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#s[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m.sd:{[104,105,106,107].indexOf(e.data[1])>-1?this.#s[a]==0&&(this.setChType(a,this.CH_DRUM2),console.debug(`CH${a+1} set to drums by MSB.`)):this.#s[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}case m.g2:{e.data[1]==120?this.#s[a]==0&&(this.setChType(a,this.CH_DRUMS),console.debug(`CH${a+1} set to drums by MSB.`)):this.#s[a]>0&&(this.setChType(a,this.CH_MELODIC),console.debug(`CH${a+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:a});break}case 6:{if(this.#_){[m.xg,m.gs,m.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${M[this.#t]}" mode, even when they are supported in Octavia.`);let h=this.#e[o+u[99]],y=this.#e[o+u[98]];if(h==1){let g=me.indexOf(y);if(g>-1)this.#e[o+u[71+g]]=e.data[1],k()&&console.debug(`Redirected NRPN 1 ${y} to cc${71+g}.`),this.dispatchEvent("cc",{part:a,cc:71+g,data:e.data[1]});else{let d=le.indexOf(y);d>-1?this.#Q[a*10+d]=e.data[1]-64:console.warn(`NRPN 0x01${y.toString(16).padStart(2,"0")} is not supported.`),k()&&console.debug(`CH${a+1} voice NRPN ${y} commit`)}}else{if(L.indexOf(h)<0){let d=`NRPN 0x${h.toString(16).padStart(2,"0")}${y.toString(16).padStart(2,"0")} `;h==127?console.warn(`${d}is not necessary. Consider removing it.`):console.warn(`${d}is not supported.`)}else{let d=this.#s[a]-2;d<0?console.warn(`CH${a+1} cannot accept drum NRPN as type ${U[this.#s[a]]}.`):this.#b[(d*b.dpn+C[h])*b.dnc+y]=e.data[1]}k()&&console.debug(`CH${a+1} (${U[this.#s[a]]}) drum NRPN ${h} commit`)}}else{let h=ne[this.#e[o+u[100]]],y=ce[this.#e[o+u[100]]];this.#e[o+u[101]]==0&&h!=null&&(k()&&console.debug(`CH${a+1} RPN 0 ${this.#e[o+u[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],oe[h][0]),oe[h][1]),this.#a[a*b.rpn+h]=e.data[1],this.#r[a*b.rpnt+y]=1)}break}case 32:{switch(k()&&console.debug(`${M[this.#t]}, CH${a+1} LSB: ${e.data[1]}`),this.#t){case m.s90es:case m.motif:{this.setChType(a,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,this.#t,!0);break}}this.dispatchEvent("voice",{part:a});break}case 38:{if(!this.#_){let h=ne[this.#e[o+100]],y=ce[this.#e[o+100]];this.#e[o+101]==0&&h!=null&&(this.#a[a*b.rpn+h+1]=e.data[1],this.#r[a*b.rpnt+y]=1)}break}case 64:{e.data[1]<64&&this.#f.hoOf(a);break}case 66:{e.data[1]>>6?this.#f.soOn(a):this.#f.soOf(a);break}case 98:case 99:{this.#_=1;break}case 100:case 101:{this.#_=0;break}}this.#e[o+u[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:a,cc:e.data[0],data:e.data[1]})}},12:function(e){let a=e.channel;switch(this.#t){case m.s90es:case m.motif:{e.data&&this.setChActive(a,1);break}default:this.setChActive(a,1)}this.#i[a]=e.data,this.#T[a]=0,k()&&console.debug(`T:${e.track} C:${a} P:${e.data}`),this.dispatchEvent("voice",{part:a})},13:function(e){let a=this,o=e.channel;this.#l.forEach(function(h){let y=h>>7;o==y&&(a.#o[h]=e.data,a.dispatchEvent("note",{part:o,note:h&127,velo:e.data,state:a.NOTE_SUSTAIN}))})},14:function(e){let a=e.channel;this.#U[a]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:a,pitch:this.getPitchShift(a)})},15:function(e){ke(e.data).forEach(a=>{let o=a[0],h=a[1];(this.#se[o]||function(){console.debug(`Unknown manufacturer ${o}.`)})(h,a.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#u[e.meta]||function(o,h,y){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#I=0);let a=ge.indexOf(e.meta)>-1;if(k()&&console.debug(e),a)return e.reply="meta",e}};#se={64:(e,a,o)=>{this.#K.run(a,o,e)},65:(e,a,o)=>{if(a[0]<16)if(a[1]==72){let h=a[a.length-1],y=F(a.subarray(3,a.length-1));h==y?this.#w.run(a.subarray(0,a.length-1),o,e):console.warn(`Bad SD checksum ${h}. Should be ${y}.`)}else this.#w.run(a,o,e);else{let h=a[a.length-1],y=F(a.subarray(2,a.length-1));h==y?this.#w.run(a.subarray(0,a.length-1),o,e):console.warn(`Bad GS checksum ${h}. Should be ${y}.`)}},66:(e,a,o)=>{this.#A.run(a,o,e)},67:(e,a,o)=>{this.#k.run(a,o,e)},68:(e,a,o)=>{this.#q.run(a,o,e)},71:(e,a,o)=>{this.#z.run(a,o,e)},126:(e,a,o)=>{this.#V.run(a,o,e)},127:(e,a,o)=>{this.switchMode("gm"),this.#F.run(a,o,e)}};#V;#F;#k;#w;#A;#K;#z;#q;buildRchTree(){let e=[];this.#d.forEach((a,o)=>{a0&&!h&&(this.#e[e*b.cc+u[0]]=R[o])}setChActive(e,a=0){this.#R[e]!=a&&this.dispatchEvent("channeltoggle",{part:e,active:a}),this.#R[e]=a}getPitch(){return this.#U}getProgram(){return this.#i}getTexts(){return this.#E.slice()}getVel(e){let a=new Map,o=this;return o.#l.forEach(function(h,y){let g=Math.floor(h/128),d=h%128;e==g&&o.#o[h]>0&&a.set(d,{v:o.#o[h],s:o.#h[y]})}),a}getBitmap(){return{bitmap:this.#y,expire:this.#C}}getLetter(){return{text:this.#L,set:this.#ee,expire:this.#G}}getMode(){return M[this.#t]}getMaster(){return{volume:this.#n}}getRawStrength(){let e=this;return this.#l.forEach(function(a){let o=Math.floor(a/128);e.#o[a]>e.#x[o]&&(e.#x[o]=e.#o[a])}),this.#x}getStrength(){let e=[],a=this;return this.getRawStrength().forEach(function(o,h){e[h]=Math.floor(o*a.#e[h*b.cc+u[7]]*a.#e[h*b.cc+u[11]]*a.#n/803288)}),e}getRpn(){return this.#a}getNrpn(){return this.#Q}getVoice(e,a,o,h){let y=e||this.#H,g=a,d=o||this.#m;M[this.#t]=="ns5r"&&y>0&&y<56&&(d=3);let t=this.userBank.get(y,g,d,h);if(M[this.#t]=="mt32"&&t.name.indexOf("MT-m:")==0){let s=parseInt(t.name.slice(5)),n=s*b.cmt,i="";this.#N.subarray(n,n+10).forEach(r=>{r>31&&(i+=String.fromCharCode(r))}),this.userBank.load(`MSB LSB PRG +0 127 ${g} ${i}`,!0),t.name=i,t.ending=" "}return(t.ending!=" "||!t.name.length)&&(t=this.baseBank.get(y,g,d,h)),t}getChVoice(e){let a=this.getVoice(this.#e[e*b.cc+u[0]],this.#i[e],this.#e[e*b.cc+u[32]],M[this.#t]);if(this.#T[e])switch(this.#t){case m.mt32:a.ending="~",a.name="",this.#v.subarray(14*(e-1),14*(e-1)+10).forEach(o=>{o>31&&(a.name+=String.fromCharCode(o))})}return a}getPitchShift(e){let a=this,o=e*b.rpn,h=a.#a[o];return a.#r[e*b.rpnt]||a.#t==m.mt32&&(h=12),a.#U[e]/8192*h+(a.#a[o+3]-64)+((a.#a[o+1]<<7)+a.#a[o+2]-8192)/8192}getEffectType(e=0){let a=3*e+1;return this.#g.subarray(a,a+2)}setEffectTypeRaw(e=0,a,o){let h=3*e;this.#g[h]=1,this.#g[h+1+ +a]=o}setEffectType(e=0,a,o){this.setEffectTypeRaw(e,!1,a),this.setEffectTypeRaw(e,!0,o)}getEffectSink(){return this.#W}setLetterDisplay(e,a,o=0,h=3200){let y=this,g;y.#L=" ".repeat(o),e.forEach(d=>{y.#L+=String.fromCharCode(d>31?d:32),d<32&&(g=g||new Set,g.add(d))}),y.#ee=Date.now(),y.#G=Date.now()+h,g&&(g=Array.from(g),g.forEach((d,t,s)=>{s[t]=d.toString(16).padStart(2,"0")}),console.warn(`${a}${a?" ":""}invalid code point${g.length>1?"s":""}: 0x${g.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let a=!0,o=0;for(;a&&o=b.ace&&console.warn("ACE slots are full.")}getAce(){return this.#D}getChAce(e,a){if(a<0||a>=b.ace)throw new RangeError("No such ACE slot");let o=this.#D[a];if(o){if(N.indexOf(o)>=0)return this.#e[e*b.cc+u[o]];throw new Error(`Invalid ACE source: ${o}`)}else return 0}initDrums(){let e=this;e.#b.fill(64);for(let a=0;a-1){if(o.#t==0||a){let y=o.#t;o.initOnReset&&a&&(this.init(1),y=m["?"]),o.#t=h,o.#p=0,o.#H=re[0][h],o.#m=re[1][h];for(let d=0;d0&&o.#e[d*b.cc+u[0]]==R[y]&&(o.#e[d*b.cc]=R[h]);switch(h){case m.mt32:{V.forEach((d,t)=>{let s=t+1;o.#R[s]||(o.#i[s]=d,o.#e[s*b.cc+u[91]]=127)});for(let d=1;d<10;d++)o.dispatchEvent("voice",{part:d});break}}let g;switch(h){case m["?"]:case m.xg:{g=[1,0,65,0,5,0,0,0];break}case m.gm:case m.gs:case m.g2:case m.sd:{g=[40,4,40,18,40,32,32,0];break}case m["05rw"]:case m.x5d:case m.ns5r:{g=[44,1,44,19,44,0,44,0];break}case m.k11:case m.sg:{g=[24,0,0,0,0,0,0,0];break}case m.mt32:{g=[40,4,0,0,0,0,0,0];break}default:g=[0,0,0,0,0,0,0,0]}for(let d=0;d<4;d++)o.#g[3*d]||(o.#g[3*d+1]=g[2*d],o.#g[3*d+2]=g[2*d+1],o.dispatchEvent(`efx${["reverb","chorus","delay","insert"][d]}`,o.getEffectType(d)));o.dispatchEvent("mode",e),o.forceVoiceRefresh()}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#x.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#ae[e.type].call(this,e);{let a=this.chRedir(e.part,e.track),o=!1;this.#te[a]?.forEach(h=>{e.channel=h,o=!0,this.#ae[e.type].call(this,e)}),o||console.warn(`${ie[e.type]?ie[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${a+1} without any recipient.`)}this.#E.length>100&&this.#E.splice(100,this.#E.length-99)}runRaw(e){}async loadBank(e,a){let o=this;switch(e=e.toLowerCase(),e){case"s7e":{o.userBank.clearRange({msb:63,lsb:[21,22]}),o.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{H.context=this,o.userBank.load(await H.read(e,a));break}}o.forceVoiceRefresh()}constructor(){super();let e=this;this.#y=new Uint8Array(256),this.#M[10]=new Uint8Array(512),this.#X=new x,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -152,14 +152,14 @@ _,`.split(` `,` `).replaceAll("\r",` `),t.slice(0,2)){case"@I":{this.#c=!0,this.dispatchEvent("metacommit",{type:"Kar.Info",data:t.slice(2)?.trimLeft()});break}case"@K":{this.#c=!0,this.dispatchEvent("metacommit",{type:"Kar.Mode",data:t.slice(2)?.trimLeft()}),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#c=!0,this.dispatchEvent("metacommit",{type:"Kar.Lang",data:t.slice(2)?.trimLeft()});break}case"@T":{this.#c=!0,this.dispatchEvent("metacommit",{type:"KarTitle",data:t.slice(2)?.trimLeft()});break}case"@V":{this.#c=!0,this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:t.slice(2)?.trimLeft()});break}case"XF":{let s=t.slice(2).split(":");switch(s[0]){case"hd":{s.slice(1).forEach((n,i)=>{n.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][i],data:n})});break}case"ln":{s.slice(1).forEach((n,i)=>{n.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][i],data:n})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:t})}break}default:this.#c?t[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:t.slice(1),amend:!0})):t[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:t.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:t,amend:!0}):t.split(` -`).forEach((s,n)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:s,mask:n!=0})})}},this.#u[2]=function(t){this.dispatchEvent("metacommit",{type:"Copyrite",data:t})},this.#u[3]=function(t,s){s<1&&this.#I<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:t})},this.#u[4]=function(t,s){this.dispatchEvent("metacommit",{type:"Instrmnt",data:t})},this.#u[5]=function(t){t.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:t,amend:!0})},this.#u[6]=function(t){this.dispatchEvent("metacommit",{type:"C.Marker",data:t})},this.#u[7]=function(t){this.dispatchEvent("metacommit",{type:"CuePoint",data:t})},this.#u[32]=function(t){this.#I=t[0]+1},this.#u[33]=function(t,s){e.#B[s]=t+1},this.#u[81]=function(t,s){e.#J=t/1e3},this.#u[127]=function(t,s){e.#X.run(t,s)},this.#X.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#X.add([67,0,1],function(t,s){e.#B[s]=t[0]+1}),this.#V=new x("universal non-realtime"),this.#K=new x("universal realtime"),this.#w=new x("Yamaha"),this.#k=new x("Roland"),this.#U=new x("Korg"),this.#F=new x("Kawai"),this.#z=new x("Akai"),this.#q=new x("Casio");let a=function(t){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,t)};this.#V.default=a,this.#K.default=a,this.#w.default=a,this.#k.default=a,this.#U.default=a,this.#F.default=a,this.#z.default=a,this.#q.default=a,this.#V.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#c=e.#c||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#K.add([4,1],t=>{e.#n=((t[1]<<7)+t[0])/16383*100,e.dispatchEvent("mastervolume",e.#n)}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#w.add([76,0,0],t=>{switch(t[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${t}`);break}case 126:{e.switchMode("xg",!0),e.#c=!1,console.info("MIDI reset: XG");break}default:{let s=[0,0,0,0],n=(i,r)=>{s[r]=i};if(t.subarray(1).forEach((i,r)=>{let c=r+t[0];([n,n,n,n,d=>{this.#n=d*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},d=>{},d=>{}][c]||(()=>{}))(i,r)}),t[0]<4){let i=0;s.forEach(r=>{i=i<<4,i+=r}),i-=1024}}}}).add([76,2,1],t=>{let s="XG ";t[0]<32?(s+="reverb ",t.subarray(1).forEach((n,i)=>{([r=>{e.setEffectTypeRaw(0,!1,r),console.info(`${s}main type: ${U[r]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},r=>{e.setEffectTypeRaw(0,!0,r),console.debug(`${s}sub type: ${r+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},r=>{console.debug(`${s}time: ${W(r)}s`)},r=>{console.debug(`${s}diffusion: ${r}`)},r=>{console.debug(`${s}initial delay: ${r}`)},r=>{console.debug(`${s}HPF cutoff: ${D[r]}Hz`)},r=>{console.debug(`${s}LPF cutoff: ${D[r]}Hz`)},r=>{console.debug(`${s}width: ${r}`)},r=>{console.debug(`${s}height: ${r}`)},r=>{console.debug(`${s}depth: ${r}`)},r=>{console.debug(`${s}wall type: ${r}`)},r=>{console.debug(`${s}dry/wet: ${r}`)},r=>{console.debug(`${s}send: ${S(r)}dB`)},r=>{console.debug(`${s}pan: ${r-64}`)},!1,!1,r=>{console.debug(`${s}delay: ${r}`)},r=>{console.debug(`${s}density: ${r}`)},r=>{console.debug(`${s}balance: ${r}`)},r=>{},r=>{console.debug(`${s}feedback: ${r}`)},r=>{}][t[0]+i]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(n)})):t[0]<64?(s+="chorus ",t.subarray(1).forEach((n,i)=>{([r=>{e.setEffectTypeRaw(1,!1,r),console.info(`${s}main type: ${U[r]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},r=>{e.setEffectTypeRaw(1,!0,r),console.debug(`${s}sub type: ${r+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},r=>{console.debug(`${s}LFO: ${Y[r]}Hz`)},r=>{},r=>{console.debug(`${s}feedback: ${r}`)},r=>{console.debug(`${s}delay offset: ${J(r)}ms`)},r=>{},r=>{console.debug(`${s}low: ${D[r]}Hz`)},r=>{console.debug(`${s}low: ${r-64}dB`)},r=>{console.debug(`${s}high: ${D[r]}Hz`)},r=>{console.debug(`${s}high: ${r-64}dB`)},r=>{console.debug(`${s}dry/wet: ${r}`)},r=>{console.debug(`${s}send: ${S(r)}dB`)},r=>{console.debug(`${s}pan: ${r-64}`)},r=>{console.debug(`${s}to reverb: ${S(r)}dB`)},!1,r=>{},r=>{},r=>{},r=>{console.debug(`${s}LFO phase diff: ${(r-64)*3}deg`)},r=>{console.debug(`${s}input mode: ${r?"stereo":"mono"}`)},r=>{}][t[0]-32+i]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(n)})):t[0]<86?(s+="variation ",t.subarray(1).forEach((n,i)=>{([r=>{e.setEffectTypeRaw(2,!1,r),console.info(`${s}main type: ${U[r]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},r=>{e.setEffectTypeRaw(2,!0,r),console.debug(`${s}sub type: ${r+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][t[0]-64+i]||function(){})(n)})):t[0]<97?(s+="variation ",t.subarray(1).forEach((n,i)=>{[r=>{console.debug(`${s}send: ${S(r)}dB`)},r=>{console.debug(`${s}pan: ${r-64}`)},r=>{console.debug(`${s}to reverb: ${S(r)}dB`)},r=>{console.debug(`${s}to chorus: ${S(r)}dB`)},r=>{console.debug(`${s}connection: ${r?"system":"insertion"}`)},r=>{console.debug(`${s}channel: CH${r+1}`)},r=>{console.debug(`${s}mod wheel: ${r-64}`)},r=>{console.debug(`${s}bend wheel: ${r-64}`)},r=>{console.debug(`${s}channel after touch: ${r-64}`)},r=>{console.debug(`${s}AC1: ${r-64}`)},r=>{console.debug(`${s}AC2: ${r-64}`)}][t[0]-86+i](n)})):t[0]>111&&t[0]<118?s+="variation ":console.warn(`Unknown XG variation address: ${t[0]}`)}).add([76,2,64],t=>{t.subarray(1).forEach((s,n)=>{let i=n+t[0];if(i==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][s]}`);else{let r=i-1>>2,c=i-1&3,d=`XG EQ ${r} ${["gain","freq","Q","shape"][c]}: `;[()=>{console.debug(`${d}${s-64}dB`)},()=>{console.debug(`${d}${s} (raw)`)},()=>{console.debug(`${d}${s/10}`)},()=>{console.debug(`${d}${["shelf","peak"][+!!s]}`)}][c]()}})}).add([76,3],t=>{let s=t[0],n=t[1],i=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((r,c)=>{([d=>{e.setEffectTypeRaw(3+s,!1,d),console.info(`${i}main type: ${U[d]}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))},d=>{e.setEffectTypeRaw(3+s,!0,d),console.debug(`${i}sub type: ${d+1}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))}][n+c]||function(){})(r)})}).add([76,6,0],t=>{let s=t[0];s<64?e.setLetterDisplay(t.subarray(1),"XG letter display",s):e.#G=Date.now()}).add([76,7,0],t=>{let s=t[0];e.#p=0,e.#C=Date.now()+3200,e.#y.fill(0);let n=t.subarray(1);for(let i=0;i>6-$&1,$++})}).add([76,8],(t,s)=>{let n=e.chRedir(t[0],s,!0),i=t[1],r=b.cc*n,c=`XG CH${n+1} `,d=`Unknown XG part address ${i}.`;t.subarray(2).forEach((l,p)=>{i<1?console.debug(d):i<41?([()=>{e.#e[r+u[0]]=l,e.dispatchEvent("voice",{part:n})},()=>{e.#e[r+u[32]]=l,e.dispatchEvent("voice",{part:n})},()=>{e.#i[n]=l,e.dispatchEvent("voice",{part:n})},()=>{let $=e.chRedir(l,s,!0);e.#f[n]=$,n!=$&&(e.buildRchTree(),console.info(`${c}receives from CH${$+1}`))},()=>{e.#$[n]=+!l},()=>{},()=>{e.setChType(n,l,m.xg),console.debug(`${c}type: ${A[l]||l}`)},()=>{e.#a[b.rpn*n+3]=l,e.#r[b.rpnt*n+2]=1},!1,!1,()=>{e.#e[r+u[7]]=l},!1,!1,()=>{e.#e[r+u[10]]=l||128},!1,!1,()=>{e.#e[r+u[128]]=l},()=>{e.#e[r+u[93]]=l},()=>{e.#e[r+u[91]]=l},()=>{e.#e[r+u[94]]=l},()=>{e.#e[r+u[76]]=l},()=>{e.#e[r+u[77]]=l},()=>{e.#e[r+u[78]]=l},()=>{e.#e[r+u[74]]=l},()=>{e.#e[r+u[71]]=l},()=>{e.#e[r+u[73]]=l},()=>{e.#e[r+u[75]]=l},()=>{e.#e[r+u[72]]=l}][i+p-1]||(()=>{}))():i<48?console.debug(d):i<111?i>102&&i<105&&(e.#e[r+u[[5,65][i&1]]]=l):i<114?console.debug(d):i<116?console.debug(`${c}EQ ${["bass","treble"][i&1]} gain: ${l-64}dB`):i<118?console.debug(d):i<120?console.debug(`${c}EQ ${["bass","treble"][i&1]} freq: ${l}`):console.debug(d)})}).add([76,9],(t,s)=>{let n=e.chRedir(t[0],s,!0),i=t[1],r=`PLG-150VL CH${n+1} `;t.subarray(2).forEach((c,d)=>{let l=d+i;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 p=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${r}${p} control source: ${ee(c)}`),c&&c<96&&e.allocateAce(c)):console.debug(`${r}${p} scale break point: ${c}`):console.debug(`${r}${p} 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,s)=>{let n=t[0],i="MU1000 System: ";t.subarray(1).forEach((r,c)=>{let d=n+c;d==8?console.debug(`${i}LCD contrast set to ${r}.`):d==18?(e.#m=r?126:0,console.debug(`${i}bank defaults to ${r?"MU100 Native":"MU Basic"}.`)):d>=64&&d<69&&[()=>{e.dispatchEvent("channelactive",r)},()=>{r<8?(e.dispatchEvent("channelmin",r<<4),console.debug(`Octavia System: Minimum CH${(r<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{r<8?(e.dispatchEvent("channelmax",(r<<4)+15),console.debug(`Octavia System: Maximum CH${(r<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#S=!!r,console.info(`Octavia System: RS receiving ${["dis","en"][r]}abled.`)}][d-64]()})}).add([73,10,0],(t,s)=>{let n=t[0],i=`MU1000 RS${e.#S?"":" (ignored)"}: `;if(n<16)switch(n){case 2:{let r=e.chRedir(0,s,!0);e.#S&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+63)),console.info(`${i}Show CH1~64`);break}case 3:{let r=e.chRedir(t[1]<<5,s,!0);e.#S&&e.dispatchEvent("channelmin",r),e.#S&&e.dispatchEvent("channelmax",r+31),console.info(`${i}Show CH${r+1}~CH${r+32}`);break}default:console.debug(`${i}unknown switch ${n} invoked.`)}else if(n<32){if(e.#S){let r=e.chRedir(n-16+(e.#j<<4),s,!0);e.dispatchEvent("channelactive",r)}}else if(n<36){let r=e.chRedir(n-32<<4,s,!0);e.#S&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+15),e.#j=n-32),console.info(`${i}Show CH${r+1}~CH${r+16}`)}}).add([93,3],(t,s)=>{let n=e.chRedir(t[0],s,!0),i=`PLG-100SG CH${n+1} `,r=Date.now();if(t[1]==0){let c="",d=0;t.subarray(2).forEach((l,p)=>{p%2==0?c+=Z[l]||l.toString().padStart("0"):d+=l*13}),r>=e.#Z&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${j(c)}`,amend:!0}),e.#Z=r+Math.ceil(d/2)+e.#J,w()&&console.debug(`${i}vocals: ${c}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)});let o=function(t,s,n,i){},h=function(t,s){let n=t*b.dpn,i=s[0],r=s[1];s.subarray(2).forEach((c,d)=>{let l=d+r,p=-1;l<16?([()=>{p=24},()=>{p=25},()=>{p=26},()=>{},()=>{p=28},()=>{p=29},()=>{p=30},()=>{p=31},()=>{},()=>{},()=>{},()=>{p=20},()=>{p=21},()=>{p=22},()=>{p=23},()=>{}][l]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${t+1}.`)}))():l<32||(l<40?([()=>{p=48},()=>{p=49},!1,!1,()=>{p=52},()=>{p=53}][l-32]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${t+1}.`)}))():l<80||([()=>{p=36}][l-80]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${t+1}.`)}))()),p>=0?(w()&&console.debug(n,p,i,c),e.#b[(n+C[p])*b.dnc+i]=c):w()&&console.debug(`XG-style drum param ${l} has no writes.`)})},y=function(t,s,n){let i=t*b.dpn,r=(s<<7)+n[0];n.subarray(1).forEach((c,d)=>{let l=d+r,p=l&127,$=l>>7,E=-1;$>1&&([()=>{E=26},()=>{},()=>{E=28},()=>{E=29},()=>{E=30},()=>{},()=>{},()=>{E=31}][$-2]||(()=>{console.debug(`Unknown GS-style drum param ${$} on set ${t+1}.`)}))(),E>-1?(w()&&console.debug(i,E,p,c),e.#b[(i+C[E])*b.dnc+p]=c):w()&&console.debug(`GS-style drum param ${$} has no writes.`)})};this.#w.add([76,48],(t,s,n)=>{h(0,t)}).add([76,49],(t,s,n)=>{h(1,t)}).add([76,50],(t,s,n)=>{h(2,t)}).add([76,51],(t,s,n)=>{h(3,t)}).add([76,52],(t,s,n)=>{h(4,t)}).add([76,53],(t,s,n)=>{h(5,t)}).add([76,54],(t,s,n)=>{h(6,t)}).add([76,55],(t,s,n)=>{h(7,t)}),this.#w.add([89,0],(t,s,n)=>{if(e.eprom){let i=t[0],r=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);w()&&console.debug(`MU1000 EPROM trail to 0x${r.toString(16).padStart(6,"0")}, ${i} bytes.`);let c=e.eprom.data;t.subarray(4).forEach((d,l)=>{let p=l>>3,$=l&7;if($==7)for(let E=0;E<7;E++)c[r+7*p+E]+=(d>>6-E&1)<<7;else c[r+7*p+$]=d})}}).add([89,1],(t,s,n)=>{let i=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];w()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(t,s,n)=>{if(e.eprom){let i=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);w()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let r=e.eprom.data;t.subarray(4).forEach((c,d)=>{let l=d>>3,p=d&7;if(p==7)for(let $=0;$<7;$++)r[i+7*l+$]+=(c>>6-$&1)<<7;else r[i+7*l+p]=c})}}).add([89,3],(t,s,n)=>{}),this.#w.add([39,48],(t,s,n)=>{}).add([43,0,0],(t,s,n)=>{let i=[0,0,0,0],r=(c,d)=>{i[d]=c};if(t.subarray(1).forEach((c,d)=>{let l=d+t[0];[r,r,r,r,()=>{this.#n=c*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},()=>c-64,()=>c||128,()=>c,()=>c,()=>{console.debug(`TG300 variation on cc${c}.`)}][l](c,l)}),t[0]<4){let c=0;i.forEach(d=>{c=c<<4,c+=d}),c-=1024}}).add([43,1,0],(t,s,n)=>{}).add([43,2],(t,s,n)=>{let i=e.chRedir(t[0],s,!0),r=t[1],c=b.cc*i,d=`TG300 CH${i+1} `;t.subarray(2).forEach((l,p)=>{p<5?([()=>{},()=>{e.#e[c+u[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{e.#e[c+u[32]]=l,e.dispatchEvent("voice",{part:i})},()=>{e.#i[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(l,s,!0);e.#f[i]=$,i!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))}][p+r]||(()=>{}))(l,p+r):p<21||(p<47?([()=>{e.#$[i]=+!l},()=>{},()=>{},()=>{e.#a[b.rpn*i+3]=l,e.#r[b.rpnt*i+2]=1},()=>{},()=>{e.#e[c+u[7]]=l},!1,!1,()=>{e.#e[c+u[10]]=l||128},!1,!1,()=>{console.debug(`${d} AC1 at cc${l}`)},()=>{console.debug(`${d} AC2 at cc${l}`)},()=>{e.#e[c+u[128]]=l},()=>{e.#e[c+u[93]]=l},()=>{e.#e[c+u[91]]=l},()=>{e.#e[c+u[94]]=l},()=>{e.#e[c+u[76]]=l},()=>{e.#e[c+u[77]]=l},()=>{e.#e[c+u[74]]=l},()=>{e.#e[c+u[71]]=l},()=>{e.#e[c+u[73]]=l},()=>{e.#e[c+u[75]]=l},()=>{e.#e[c+u[72]]=l},()=>{e.#e[c+u[78]]=l}][p+r-21]||(()=>{}))(l,p+r):p<95||([()=>{e.#e[c+u[65]]=l},()=>{e.#e[c+u[5]]=l}][p+r-95]||(()=>{}))(l,p+r))})}).add([43,7,0],(t,s,n)=>{let i=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",i)}).add([43,7,1],(t,s,n)=>{e.#p=0,e.#C=Date.now()+3200,e.#y.fill(0),t.forEach(function(i,r){let c=Math.floor(r/16),d=r%16,l=(d*3+c)*7,p=7,$=0;for(l-=d*5,c==2&&(p=2);$>6-$&1,$++})}),this.#k.add([66,18,0,0,127],(t,s,n)=>{e.switchMode("gs",!0),e.#e[b.cc*9]=120,e.#e[b.cc*25]=120,e.#e[b.cc*41]=120,e.#e[b.cc*57]=120,e.#m=3,e.#c=!1,e.#O.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,s,n)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[b.cc*9]=120,e.#e[b.cc*25]=120,e.#e[b.cc*41]=120,e.#e[b.cc*57]=120,e.#c=!1,e.#O.fill(0),console.info("MIDI reset: GS");break}default:{let i=[0,0,0,0],r=(c,d)=>{i[d]=c};if(t.subarray(1).forEach((c,d)=>{let l=d+t[0];[r,r,r,r,p=>{this.#n=p*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},p=>{},p=>{}][l](c,d)}),t[0]<4){let c=0;i.forEach(d=>{c=c<<4,c+=d}),c-=1024}}}}).add([66,18,64,1],t=>{let s=t[0];if(s<16){let n="".padStart(s," ");t.subarray(1).forEach((i,r)=>{n+=String.fromCharCode(Math.max(32,i))}),n=n.padEnd(16," "),console.debug(`GS patch name: ${n}`)}else s<48||(s<65?t.subarray(1).forEach((n,i)=>{let r=`GS ${s+i>55?"chorus":"reverb"} `;([()=>{console.info(`${r}type: ${I[n]}`),e.setEffectType(0,40,n),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${r}predelay: ${n}ms`)},()=>{console.info(`${r}type: ${te[n]}`),e.setEffectType(1,40,16+n),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${S(n)}`)},()=>{console.debug(`${r}to delay: ${S(n)}`)}][s+i-48]||(()=>{}))()}):s<80?console.debug(`Unknown GS patch address: ${s}`):s<91?t.subarray(1).forEach((n,i)=>{let r="GS delay ";([()=>{console.info(`${r}type: ${ae[n]}`),e.setEffectType(2,40,32+n),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${S(n)}`)}][s+i-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${s}`))}).add([66,18,64,2],t=>{let s="GS EQ ";t.subarray(1).forEach((n,i)=>{([()=>{console.debug(`${s}low freq: ${[200,400][n]}Hz`)},()=>{console.debug(`${s}low gain: ${n-64}dB`)},()=>{console.debug(`${s}high freq: ${[3e3,6e3][n]}Hz`)},()=>{console.debug(`${s}high gain: ${n-64}dB`)}][t[0]+i]||function(){console.warn(`Unknown GS EQ address: ${t[0]+i}`)})()})}).add([66,18,64,3],t=>{let s="GS EFX ",n=function(i,r){let c=se(e.#g.subarray(10,12),r,i);c&&console.debug(`${s}${X(e.#g.subarray(10,12))} ${c}`)};t.subarray(1).forEach((i,r)=>{([()=>{e.setEffectTypeRaw(3,!1,32+i),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,i),console.info(`${s}type: ${X(e.#g.subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,()=>{console.debug(`${s}to reverb: ${S(i)}dB`)},()=>{console.debug(`${s}to chorus: ${S(i)}dB`)},()=>{console.debug(`${s}to delay: ${S(i)}dB`)},!1,()=>{console.debug(`${s}1 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${s}1 depth: ${i-64}`)},()=>{console.debug(`${s}2 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${s}2 depth: ${i-64}`)},()=>{console.debug(`${s}to EQ: ${i?"ON":"OFF"}`)}][t[0]+r]||function(c,d){console.warn(`Unknown GS EFX address: ${d}`)})(i,t[0]+r)})}).add([66,18,65],t=>{y((t[0]>>4)+1<<1,t[0]&15,t.subarray(1))}).add([69,18,16],t=>{switch(t[0]){case 0:{let s=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",s);break}case 32:{e.#C=Date.now()+3200,t[1]==0&&(e.#p=Math.max(Math.min(t[2]-1,9),0),w()&&console.debug(`GS switch display page ${t[2]-1}.`));break}default:if(t[0]<6){e.#p>9&&(e.#p=0);let s=t[0]-1<<1|t[1]>>6;e.#p==s&&(e.#C=Date.now()+3200),e.#M[s]?.length||(e.#M[s]=new Uint8Array(256));let n=e.#M[s];w()&&console.debug(`GS frame draw page ${s}.`);let i=t[1]&63;n.fill(0),t.subarray(2).forEach(function(c,d){let l=d+i,p=Math.floor(l/16),$=l%16,E=($*4+p)*5,k=5,v=0;for(E-=$*4,p==3&&(k=1);v>4-v&1,v++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let g=function(t,s,n){let i=t[0],r=b.cc*s,c=b.rpn*s,d=`GS CH${s+1} `;i<3?(t.subarray(1).forEach((l,p)=>{[()=>{e.#e[r+u[0]]=l},()=>{e.#i[s]=l},()=>{let $=0;l<16?$=e.chRedir(l,n,!0):$=b.ch,e.#f[s]=$,s!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))}][i+p]()}),e.dispatchEvent("voice",{part:s})):i<19||(i<44?t.subarray(1).forEach((l,p)=>{([()=>{e.#$[s]=+!l},!1,()=>{e.setChType(s,l<<1,m.gs),console.debug(`${d}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{e.#a[c+3]=l,e.#r[b.rpnt*s+2]=1},!1,()=>{e.#e[r+u[7]]=l},!1,!1,()=>{e.#e[r+u[10]]=l||128},!1,!1,()=>{console.debug(`${d}CC 1: cc${l}`)},()=>{console.debug(`${d}CC 2: cc${l}`)},()=>{e.#e[r+u[93]]=l},()=>{e.#e[r+u[91]]=l},!1,!1,()=>{e.#a[c+1]=l,e.#r[b.rpnt*s+1]=1},()=>{e.#a[c+2]=l,e.#r[b.rpnt*s+1]=1},()=>{e.#e[r+u[94]]=l}][i+p-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},f=function(t,s){let n=t[0],i=`GS CH${s+1} `;n<2?t.subarray(1).forEach((r,c)=>{[()=>{e.#e[b.cc*s+u[32]]=r},()=>{}][n+c]()}):n<32?console.warn(`Unknown GS misc address: ${n}`):n<35?t.subarray(1).forEach((r,c)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][r]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][r]}`),e.#W[s]=r,e.dispatchEvent("partefxtoggle",{part:s,active:r})}][n+c-32]()}):console.warn(`Unknown GS misc address: ${n}`)};this.#k.add([66,18,64,16],(t,s)=>{g(t,e.chRedir(9,s,!0),s)}).add([66,18,64,17],(t,s)=>{g(t,e.chRedir(0,s,!0),s)}).add([66,18,64,18],(t,s)=>{g(t,e.chRedir(1,s,!0),s)}).add([66,18,64,19],(t,s)=>{g(t,e.chRedir(2,s,!0),s)}).add([66,18,64,20],(t,s)=>{g(t,e.chRedir(3,s,!0),s)}).add([66,18,64,21],(t,s)=>{g(t,e.chRedir(4,s,!0),s)}).add([66,18,64,22],(t,s)=>{g(t,e.chRedir(5,s,!0),s)}).add([66,18,64,23],(t,s)=>{g(t,e.chRedir(6,s,!0),s)}).add([66,18,64,24],(t,s)=>{g(t,e.chRedir(7,s,!0),s)}).add([66,18,64,25],(t,s)=>{g(t,e.chRedir(8,s,!0),s)}).add([66,18,64,26],(t,s)=>{g(t,e.chRedir(10,s,!0),s)}).add([66,18,64,27],(t,s)=>{g(t,e.chRedir(11,s,!0),s)}).add([66,18,64,28],(t,s)=>{g(t,e.chRedir(12,s,!0),s)}).add([66,18,64,29],(t,s)=>{g(t,e.chRedir(13,s,!0),s)}).add([66,18,64,30],(t,s)=>{g(t,e.chRedir(14,s,!0),s)}).add([66,18,64,31],(t,s)=>{g(t,e.chRedir(15,s,!0),s)}).add([66,18,64,64],(t,s)=>{f(t,e.chRedir(9,s,!0))}).add([66,18,64,65],(t,s)=>{f(t,e.chRedir(0,s,!0))}).add([66,18,64,66],(t,s)=>{f(t,e.chRedir(1,s,!0))}).add([66,18,64,67],(t,s)=>{f(t,e.chRedir(2,s,!0))}).add([66,18,64,68],(t,s)=>{f(t,e.chRedir(3,s,!0))}).add([66,18,64,69],(t,s)=>{f(t,e.chRedir(4,s,!0))}).add([66,18,64,70],(t,s)=>{f(t,e.chRedir(5,s,!0))}).add([66,18,64,71],(t,s)=>{f(t,e.chRedir(6,s,!0))}).add([66,18,64,72],(t,s)=>{f(t,e.chRedir(7,s,!0))}).add([66,18,64,73],(t,s)=>{f(t,e.chRedir(8,s,!0))}).add([66,18,64,74],(t,s)=>{f(t,e.chRedir(10,s,!0))}).add([66,18,64,75],(t,s)=>{f(t,e.chRedir(11,s,!0))}).add([66,18,64,76],(t,s)=>{f(t,e.chRedir(12,s,!0))}).add([66,18,64,77],(t,s)=>{f(t,e.chRedir(13,s,!0))}).add([66,18,64,78],(t,s)=>{f(t,e.chRedir(14,s,!0))}).add([66,18,64,79],(t,s)=>{f(t,e.chRedir(15,s,!0))}),this.#U.add([54,65],(t,s)=>{e.switchMode("x5d");let n=(t[1]<<7)+t[0],i=(t[3]<<7)+t[2],r=e.chRedir(n&15,s,!0),c=b.cc*r;[()=>{i<1||(i<101?(e.setChType(r,e.CH_MELODIC,m.x5d),e.#i[r]=i-1,e.#e[c+u[0]]=82):i<229?(e.setChType(r,e.CH_MELODIC,m.x5d),e.#i[r]=i-101,e.#e[c+u[0]]=56):(e.setChType(r,e.CH_DRUMS,m.x5d),e.#i[r]=fe[i-229]||0,e.#e[c+u[0]]=62)),e.dispatchEvent("voice",{part:r})},()=>{e.#e[c+u[7]]=i},()=>{i<31&&(e.#e[c+u[10]]=Math.round((i-15)*4.2+64))},()=>{e.#e[c+u[93]]=P(i)},()=>{e.#e[c+u[91]]=P(i)},()=>{e.#a[r*b.rpn+3]=i>8191?i-16320:64+i,e.#r[b.rpnt*r+2]=1},()=>{e.#a[r*b.rpn+1]=i>8191?i-16320:64+i,e.#r[b.rpnt*r+1]=1},()=>{i>0&&(e.#a[r*b.rpn]=i,e.#r[b.rpnt*r]=1)},()=>{}][n>>4]()}).add([54,76,0],(t,s)=>{e.switchMode("x5d",!0);let n="",i=82,r=0,c=0,d="MSB PRG LSB NME";T(t,function(l,p){if(p<16400){let $=p%164;switch(!0){case $<10:{l>31&&(n+=String.fromCharCode(l));break}case $==11:{d+=` -${i} ${r} ${c} ${n.trim().replace("Init Voice","")}`,r++,n="";break}}r>99&&(i=90,r=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(d),w()&&console.debug(d),e.forceVoiceRefresh()}).add([54,77,0],(t,s)=>{e.switchMode("x5d",!0);let n="",i=90,r=0,c=0,d="MSB PRG LSB NME";T(t,function(l,p){if(p<13600){let $=p%136;switch(!0){case $<10:{l>31&&(n+=String.fromCharCode(l));break}case $==11:{d+=` -${i} ${r} ${c} ${n.trim().replace("Init Combi","")}`,r++,n="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(d),w()&&console.debug(d),e.forceVoiceRefresh()}).add([54,78],(t,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),T(t,(n,i)=>{i>0&&i<3&&(e.setEffectType(i-1,44,n),e.dispatchEvent(`efx${["reverb","chorus"][i-1]}`,e.getEffectType(i-1)))})}).add([54,104],(t,s)=>{e.switchMode("x5d",!0),T(t,function(n,i,r,c){if(i<192){let d=e.chRedir(Math.floor(i/12),s,!0),l=d*b.cc;switch(i%12){case 0:{n<128?(e.setChType(d,e.CH_MELODIC,m.x5d),e.#e[l+u[0]]=82,e.#i[d]=n):(e.setChType(d,e.CH_DRUMS,m.x5d),e.#e[l+u[0]]=62,e.#i[d]=fe[n-128]),n>0&&e.setChActive(d,1),e.dispatchEvent("voice",{part:d});break}case 1:{e.#e[l+u[7]]=n;break}case 2:{e.#a[d*b.rpn+3]=n>127?n-192:64+n,e.#r[b.rpnt*d+2]=1;break}case 3:{e.#a[d*b.rpn+1]=n>127?n-192:64+n,e.#r[b.rpnt*d+1]=1;break}case 4:{n<31&&(e.#e[l+u[10]]=Math.round((n-15)*4.2+64));break}case 5:{let p=n>>4,$=n&15;e.#e[l+u[91]]=P($),e.#e[l+u[93]]=P(p);break}case 10:break;case 11:{let p=e.chRedir(n&15,s,!0),$=n>>4;e.#f[d]=n,(p!=d||$)&&(console.info(`X5D Part CH${d+1} receives from CH${p+1}.`),e.buildRchTree())}}}else{let d=e.chRedir(i-192,s,!0)}})}),this.#k.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#c=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(t,s,n)=>{e.switchMode("mt32");let i=e.chRedir(n,s,!0),r=t[1];t.subarray(2).forEach((c,d)=>{let l=d+r;e.#P[l+(i-1)*16]=c,([!1,()=>{let p=e.#P[i-1<<4];if(p<3){if(e.#T[i]=1,p==2)for(let $=0;${e.#a[i*b.rpn+3]=c+40,e.#r[b.rpnt*i+2]=1},()=>{e.#a[i*b.rpn+1]=c+14,e.#r[b.rpnt*i+1]=1},()=>{e.#a[i*b.rpn]=c,e.#r[b.rpnt*i]=1},!1,()=>{e.#e[b.cc*i+u[91]]=c?127:0},!1,()=>{e.#e[b.cc*i+u[7]]=c},()=>{e.#e[b.cc*i+u[10]]=Math.ceil(c*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(t,s,n)=>{e.switchMode("mt32");let i=n&7;console.debug(`MT-32 slot #${n+1} Drum: ${t}`);let r=t[0]<<7|t[1];t.subarray(2).forEach((c,d)=>{let l=d+r,p=(l>>2)+24,$=l&3,E=i*b.dpn;if(w()&&console.debug(`MT-32 temp drum note ${p} param ${$}: ${c}`),p<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${p}`);return}[()=>{},()=>{e.#b[(E+C[26])*b.dnc+p]=Math.round(c*1.27)},()=>{e.#b[(E+C[26])*b.dnc+p]=c*9+1&127},()=>{e.#b[(E+C[26])*b.dnc+p]=c?127:0}][$]()})}).add([22,18,2],(t,s,n)=>{e.switchMode("mt32");let i=e.chRedir(n,s,!0),r=t[1]+(t[0]<<7);r<10&&(e.#T[i]=1),t.subarray(2).forEach((c,d)=>{let l=d+r;l<14&&(e.#v[(i-1)*b.cmt+l]=c)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(t,s,n)=>{e.switchMode("mt32");let i=n&7;if(t[0]){let r=(t[0]-1<<7)+t[1]-16;t.subarray(2).forEach((c,d)=>{let l=d+r,p=(l>>2)+24,$=l&3,E=i*b.dpn;if(w()&&console.debug(`MT-32 dev drum note ${p} param ${$}: ${c}`),p<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${p}`);return}[()=>{},()=>{e.#b[(E+C[26])*b.dnc+p]=Math.round(c*1.27)},()=>{e.#b[(E+C[26])*b.dnc+p]=c*9+1&127},()=>{e.#b[(E+C[26])*b.dnc+p]=c?127:0}][$]()})}else{let r=t[1];t.subarray(2).forEach((c,d)=>{let l=d+r;e.#P[l]=c;let p=e.chRedir(1+(l>>4),s,!0),$=l&15;([!1,()=>{let E=e.#P[p-1<<4];if(E<3)if(e.#T[p]=1,E==2)for(let k=0;k{e.#a[p*b.rpn+3]=c+40,e.#r[b.rpnt*p+2]=1},()=>{e.#a[p*b.rpn+1]=c+14,e.#r[b.rpnt*p+1]=1},()=>{e.#a[p*b.rpn]=c,e.#r[b.rpnt*p]=1},!1,()=>{e.#e[b.cc*p+u[91]]=c?127:0},!1,()=>{e.#e[b.cc*p+u[7]]=c},()=>{e.#e[b.cc*p+u[10]]=Math.ceil(c*9.05)}][$]||(()=>{}))()})}}).add([22,18,4],(t,s,n)=>{e.switchMode("mt32");let i=t[1]+(t[0]<<7),r=[];t.subarray(2).forEach((c,d)=>{let l=d+i,p=e.chRedir(Math.floor(l/246+1),s,!0),$=l%246;$<14&&(e.#v[(p-1)*b.cmt+$]=c),$<10&&(e.#T[p]=1),r.indexOf(p)<0&&r.push(p)}),r.forEach(c=>{e.dispatchEvent("voice",{part:c})})}).add([22,18,5],(t,s,n)=>{e.switchMode("mt32");let i=(t[0]<<7)+t[1];t.subarray(2).forEach((r,c)=>{let d=i+c,l=Math.floor(d/8),p=d&7,$=l*8;e.#Y[d]=r,([!1,()=>{let E=e.#Y[$];if(E<3){let k="";if(E==2){let v=b.cmt*l;k=`MT-m:${r.toString().padStart(3,"0")}`}else k=e.baseBank.get(0,r+(E<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l}),e.userBank.load(`MSB LSB PRG NME -000 127 ${l} ${k}`,!0)}}][p]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(t,s,n)=>{e.switchMode("mt32");let i=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((r,c)=>{let d=i+c;d>1)*b.cmt+d]=r)}),e.forceVoiceRefresh()}).add([22,18,16],(t,s,n)=>{e.switchMode("mt32");let i=t[1],r=!1,c=function(d,l){e.#f[l-12]=d,r=!0};t.subarray(2).forEach((d,l)=>{let p=l+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,c,c,c,c,c,c,c,c,c,()=>{e.#n=d,e.dispatchEvent("mastervolume",e.#n)}][p]||(()=>{}))(d,l)}),r&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let s=t[1],n=" ".repeat(s);t.subarray(2).forEach(i=>{i>31?n+=String.fromCharCode(i):n+=" "}),e.#L=n.padStart(20," "),e.#G=Date.now()+3200}).add([22,18,82],(t,s)=>{let n=e.chRedir(0,s,!0);for(let i=0;i<16;i++)e.#d.ano(n+i),i&&i<10&&(e.#i[n+i]=V[i-1]);console.info("MT-32 alt reset complete.")}),this.#U.add([66,0],(t,s)=>{e.switchMode("ns5r",!0),e.#c=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,s)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#c=!1}).add([66,18,0,0],(t,s)=>{let n=t[0];switch(n){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#c=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${t}`);break}default:if(n<10){let i=[0,0,0,0],r=(c,d)=>{i[d]=c};if(t.subarray(1).forEach((c,d)=>{[r,r,r,r,()=>{e.#n=c*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},()=>c-64,()=>c-64,()=>{},()=>{},()=>{}][n+d]()}),t[0]<4){let c=0;i.forEach(d=>{c=c<<4,c+=d}),c-=1024}}}}).add([66,18,0,1],(t,s)=>{}).add([66,18,0,2],(t,s)=>{}).add([66,18,1],(t,s)=>{let n=e.chRedir(t[0],s,!0),i=n*b.cc,r=t[1],c=`NS5R CH${n+1} `;t.subarray(2).forEach((d,l)=>{let p=r+l;p<3?([()=>{e.#e[i+u[0]]=d||121},()=>{e.#e[i+u[32]]=d},()=>{e.#i[n]=d}][p](),e.dispatchEvent("voice",{part:n})):p<8||(p<14?[()=>{let $=e.chRedir(d,s,!0);e.#f[n]=$,n!=$&&(e.buildRchTree(),console.info(`${c}receives from CH${$+1}`))},()=>{e.#$[n]=+!d},()=>{e.setChType(n,d,m.ns5r),console.debug(`${c}type: ${A[d]}`)},()=>{e.#a[b.rpn*n+3]=d,e.#r[b.rpnt*n+2]=1},()=>{},()=>{}][p-8]():p<16||(p<33?[()=>{e.#e[i+u[7]]=d},()=>{e.#e[i+u[11]]=d},()=>{},()=>{},()=>{e.#e[i+u[10]]=d||128},()=>{},()=>{},()=>{e.#e[i+u[93]]=d},()=>{e.#e[i+u[91]]=d},()=>{e.#e[i+u[76]]=d},()=>{e.#e[i+u[77]]=d},()=>{e.#e[i+u[78]]=d},()=>{e.#e[i+u[74]]=d},()=>{e.#e[i+u[71]]=d},()=>{e.#e[i+u[73]]=d},()=>{e.#e[i+u[75]]=d},()=>{e.#e[i+u[72]]=d}][p-16]():p<112||p<114&&[()=>{e.#e[i+u[5]]=d},()=>{e.#e[i+u[65]]=d}][p-112]()))})}).add([66,18,8,0],(t,s)=>{let n=t[0];if(n<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let i=n-32;e.#C=Date.now()+3200,e.#p=10,e.#y.fill(0);let r=t.subarray(1),c=4;r.forEach(function(d,l){let p=l+i,$=p>>4,E=p&15;if(p<80){let k=$>3,v=0,he=$0;)e.#y[E*32+$*7+(he-v)]=k&1,k=k>>1,v++}})}}).add([66,18,48],(t,s,n)=>{h(0,t)}).add([66,18,49],(t,s,n)=>{h(1,t)}).add([66,18,50],(t,s,n)=>{h(2,t)}).add([66,18,51],(t,s,n)=>{h(3,t)}).add([66,18,52],(t,s,n)=>{h(4,t)}).add([66,18,53],(t,s,n)=>{h(5,t)}).add([66,18,54],(t,s,n)=>{h(6,t)}).add([66,18,55],(t,s,n)=>{h(7,t)}).add([66,52],(t,s)=>{e.switchMode("ns5r",!0),e.#c=!1;let n="";T(t,(i,r)=>{r<8?(i>31&&(n+=String.fromCharCode(i)),r==7&&(e.aiEfxName=n)):r<10&&(e.setEffectType(r-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][r-8]}`,e.getEffectType(r-8)))})}).add([66,53],(t,s)=>{e.switchMode("ns5r",!0),e.#c=!1,T(t,function(n,i){switch(!0){case i<2944:{let r=e.chRedir(Math.floor(i/92),s,!0),c=r*b.cc;switch(i%92){case 0:{e.#e[c+u[0]]=n||121,e.dispatchEvent("voice",{part:r});break}case 1:{e.#e[c+u[32]]=n,e.dispatchEvent("voice",{part:r});break}case 2:{e.#i[r]=n,n>0&&e.setChActive(r,1),e.dispatchEvent("voice",{part:r});break}case 3:{let d=e.chRedir(n,s,!0);e.#f[r]=d,r!=d&&(console.info(`NS5R CH${r+1} receives from CH${d+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#a[r*b.rpn+3]=n<40||n>88?n+(n>63?-192:64):n,e.#r[b.rpnt*r+2]=1;break}case 9:case 10:{e.#e[c+u[7]]=n;break}case 11:{e.#e[c+u[11]]=n;break}case 14:{e.#e[c+u[10]]=n||128;break}case 19:{e.#e[c+u[93]]=n;break}case 20:{e.#e[c+u[91]]=n;break}case 84:{e.#e[c+u[65]]=n;break}case 85:{e.#e[c+u[5]]=n;break}}break}case i<3096:break;case i<3134:break;case i<8566:break}})}).add([66,54],(t,s)=>{e.switchMode("ns5r",!0);let n="",i=80,r=0,c=0,d="MSB PRG LSB NME";T(t,function(l,p){let $=p%158;switch(!0){case $<10:{l>31&&(n+=String.fromCharCode(l));break}case $==11:{i=l&127;break}case $==12:{c=l&127;break}case $==13:{d+=` -${i} ${r} ${c} ${n.trim().replace("Init Voice","")}`,r++,n="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(d),w()&&console.debug(d),e.forceVoiceRefresh()}).add([66,55],(t,s)=>{e.switchMode("ns5r",!0);let n="",i=88,r=0,c=0,d="MSB PRG LSB NME";T(t,function(l,p){let $=p%126;switch(!0){case $<10:{l>31&&(n+=String.fromCharCode(l));break}case $==11:break;case $==12:break;case $==13:{d+=` -${i} ${r} ${c} ${n.trim().replace("Init Combi","")}`,r++,n="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(d),w()&&console.debug(d),e.forceVoiceRefresh()}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let s=new Uint8Array(5760);T(t,(n,i,r)=>{if(i<720)for(let c=0;c<8;c++)s[i*8+c]=n>>7-c&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(t,s,n)=>{e.#U.run([66,...t],s,n)}),this.#F.add([16,0,8,0],(t,s,n)=>{let i=(t[2]<<4)+t[3],r="K11 ";([()=>{e.switchMode("k11",!0),e.#c=!1,e.#m=i?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,i),console.debug(`${r}reverb type: ${i}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${r}reverb time: ${i}`)},()=>{console.debug(`${r}reverb time: ${i}`)},()=>{console.debug(`${r}reverb predelay: ${i}`)},()=>{console.debug(`${r}reverb predelay: ${i}`)},()=>{console.debug(`${r}depth high: ${i}`)},()=>{console.debug(`${r}depth high: ${i}`)},()=>{console.debug(`${r}depth low: ${i}`)},()=>{console.debug(`${r}depth low: ${i}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,s,n)=>{let i=e.chRedir(t[1],s,!0),r=b.cc*i,c=b.rpn*i,d=(t[3]<<4)+t[4],l=`K11 CH${i+1} `;([()=>{d<128?(e.setChType(i,e.CH_MELODIC,m.k11),e.#e[r+u[0]]=0,e.#i[i]=d):(e.setChType(i,e.CH_DRUMS,m.k11),e.#i[i]=d-128),e.dispatchEvent("voice",{part:i})},()=>{let p=e.chRedir(d,s,!0);e.#f[i]=p,i!=p&&(e.buildRchTree(),console.info(`${l}receives from CH${p+1}`))},()=>{e.#e[r+u[7]]=d},()=>{uupThis.setChActive(i,d)},()=>{e.#e[r+u[10]]=d},()=>{e.#a[c+3]=d+40,e.#r[b.rpnt*i+2]=1},()=>{e.#a[c+1]=d>>1,e.#a[c+2]=d&1,e.#r[b.rpnt*i+1]=1},()=>{e.#e[r+u[91]]=d?127:0},()=>{},()=>{e.#e[r+u[74]]=d},()=>{e.#e[r+u[73]]=d},()=>{e.#e[r+u[72]]=d}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,s,n)=>{let i=(t[2]<<4)+t[3],r="GMLX ";([()=>{console.debug(`${r}reverb type: ${i}`)},()=>{console.debug(`${r}reverb time: ${i}`)},()=>{console.debug(`${r}reverb predelay: ${i}`)},()=>{console.debug(`${r}depth high: ${i}`)},()=>{console.debug(`${r}depth low: ${i}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,s,n)=>{let i=(t[2]<<4)+t[3],r=e.chRedir(t[1],s,!0),c=r*b.cc;[()=>{i<128?(e.setChType(r,e.CH_MELODIC,m.k11),e.#e[c+u[0]]=0,e.#e[c+u[32]]=0,e.#i[r]=i):i<160?(e.setChType(r,e.CH_MELODIC,m.k11),e.#e[c+u[0]]=0,e.#e[c+u[32]]=7,e.#i[r]=i-100):(e.setChType(r,e.CH_DRUMS,m.k11),e.#e[c+u[0]]=122,e.#e[c+u[32]]=0,e.#i[r]=i-160),e.dispatchEvent("voice",{part:r})},()=>{let d=e.chRedir(i,s,!0);e.#f[r]=d,r!=d&&(e.buildRchTree(),console.info(`GMLX CH${r+1} receives from CH${d+1}`))}][t[0]]()}).add([16,0,9,4],(t,s,n)=>{let i=(t[2]<<4)+t[3],r=e.chRedir(t[1],s,!0),c=r*b.cc,d=r*b.rpn,l=`GMLX CH${r+1} `;[()=>{e.setChActive(r,i)},()=>{e.#e[c+u[7]]=i},()=>{e.#e[c+u[10]]=i},()=>{e.#e[c+u[91]]=i?127:0},()=>{e.#a[d+3]=i+40,e.#r[b.rpnt*r+2]=1},()=>{e.#a[d+1]=i,e.#r[b.rpnt*r+1]=1},()=>{e.#a[d]=i,e.#r[b.rpnt*r]=1},()=>{}][t[0]]()}),this.#z.add([66,93,64],(t,s,n)=>{let i=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{e.#n=i*129/16383*100,e.dispatchEvent("mastervolume",e.#n);break}case 5:{i-64;break}case 6:{console.debug(`SG global reverb: ${i?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(t[1]){case 48:{console.debug(`SG reverb type: ${I[i]}`);break}}break}default:if(t[0]>>4==1){let r=e.chRedir(t[0]&15,s,!0);if(t[1]==2){let c=e.chRedir(i,s,!0);e.#f[r]=c,r!=c&&(e.buildRchTree(),console.info(`SG CH${r+1} receives from CH${c+1}`))}else t[1]==19&&(e.#e[b.cc*r+u[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),this.#q.add([9],(t,s,n)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)}),this.#w.add([127,0],(t,s,n)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...t]);e.#w.run(i,s,n)}).add([127,1,0,0],(t,s,n)=>{e.switchMode("s90es");let i="S90/Motif ES system ",r=t[0];t.subarray(1).forEach((c,d)=>{([()=>{e.#n=c*12900/16383,e.dispatchEvent("mastervolume",e.#n)}][r+d]||(()=>{console.info(`Unrecognized ${i}ID: ${r+d}`)}))()})}).add([127,1,0,0,14],(t,s,n)=>{e.switchMode("s90es");let i="S90/Motif ES bulk header ",r=[];r[95]=(c,d,l)=>{console.debug(`${i}multi edit buffer: ${c[1]}`)},(r[t[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,0,15],(t,s,n)=>{e.switchMode("s90es");let i="S90/Motif ES bulk footer ",r=[];r[95]=(c,d,l)=>{console.debug(`${i}multi edit buffer: ${c[1]}`)},(r[t[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,58,55],(t,s,n)=>{e.switchMode("s90es");let i=e.chRedir(t[0],s,!0),r=b.cc*i,c=t[1],d=`S90/Motif ES bulk CH${i<16?i+1:"U"+(i-95)} `;console.debug(d,t),!(t[0]>15)&&t.subarray(2).forEach((l,p)=>{([()=>{e.#e[r+u[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),e.#e[r+u[32]]=l,e.setChType(i,[32,40].indexOf(l)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),e.#i[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(l,s,!0);e.#f[i]=$,i!=$&&(e.buildRchTree(),console.info(`${d}receives from CH${$+1}`))},()=>{e.#$[i]=l?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{e.#e[r+u[7]]=l},()=>{e.#e[r+u[10]]=l},!1,!1,!1,()=>{e.#e[r+u[91]]=l},()=>{e.#e[r+u[93]]=l},()=>{e.#e[r+u[94]]=l},()=>{e.#e[r+u[128]]=l},()=>{},()=>{e.#e[r+u[74]]=l},()=>{e.#e[r+u[71]]=l},!1,()=>{e.#e[r+u[65]]=l},()=>{e.#e[r+u[5]]=l},()=>{}][c+p]||(()=>{}))()})}).add([127,1,54,16],(t,s,n)=>{e.switchMode("s90es");let i=t[0];t.subarray(1).forEach((r,c)=>{let l=`S90/Motif ES EQ${(c>>2)+1} `;([()=>{let p=r-64},()=>{let p=D[r]},()=>{let p=r/10},()=>{let p=r}][i+c&3]||(()=>{}))()})}),this.#k.add([0,72,18,0,0,0,0],(t,s,n)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(t,s,n)=>{let i=t[0]>>5,r=t[0]&31;switch(i){case 0:{console.debug(`Unknown SD-90 global effects message: -%o`,t);break}case 1:{let c=e.chRedir(r,s,!0),d=t[1],l=c*b.cc;t.subarray(2).forEach((p,$)=>{let E=d+$;E<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[l+u[0]]=p,p){case 104:case 105:case 106:case 107:case 120:{e.#s[c]||e.setChType(c,e.CH_DRUMS);break}default:e.#s[c]&&e.setChType(c,e.CH_MELODIC)}e.dispatchEvent("voice",{part:c})},()=>{e.#e[l+u[32]]=p,e.dispatchEvent("voice",{part:c})},()=>{e.#i[c]=p,e.dispatchEvent("voice",{part:c})},()=>{e.#e[l+u[7]]=p},()=>{e.#e[l+u[10]]=p},()=>{},()=>{},()=>{p<2&&(e.#$[c]=p)},()=>{p<2&&(e.#e[l+u[68]]=p?127:0)},()=>{},()=>{p<2&&(e.#e[l+u[65]]=p?127:0)},()=>{e.#e[l+u[5]]=p&15<<4|e.#e[l+u[5]]&15},()=>{e.#e[l+u[5]]=p&15|(e.#e[l+u[5]]&240)>>4},()=>{e.#e[l+u[74]]=p},()=>{e.#e[l+u[71]]=p},()=>{e.#e[l+u[73]]=p},()=>{e.#e[l+u[72]]=p},0,0,0,0,0,0,0,()=>{e.#e[l+u[128]]=p},()=>{e.#e[l+u[93]]=p},()=>{e.#e[l+u[91]]=p},0,0,()=>{e.#e[l+u[75]]=p},()=>{e.#e[l+u[76]]=p},()=>{e.#e[l+u[77]]=p},()=>{e.#e[l+u[78]]=p}][E]||(()=>{}))():E<63||(E<64?e.#s[c]?e.#e[l+u[0]]=104|p:e.#e[l+u[0]]=96|p:console.debug(`Unknown SD-90 global CH${c+1} param setup message: -%o`,t))});break}case 2:{let c=e.chRedir(r,s,!0),d=t[1];console.debug(`Unknown SD-90 global CH${c+1} MIDI setup message: +`).forEach((s,n)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:s,mask:n!=0})})}},this.#u[2]=function(t){this.dispatchEvent("metacommit",{type:"Copyrite",data:t})},this.#u[3]=function(t,s){s<1&&this.#I<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:t})},this.#u[4]=function(t,s){this.dispatchEvent("metacommit",{type:"Instrmnt",data:t})},this.#u[5]=function(t){t.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:t,amend:!0})},this.#u[6]=function(t){this.dispatchEvent("metacommit",{type:"C.Marker",data:t})},this.#u[7]=function(t){this.dispatchEvent("metacommit",{type:"CuePoint",data:t})},this.#u[32]=function(t){this.#I=t[0]+1},this.#u[33]=function(t,s){e.#B[s]=t+1},this.#u[81]=function(t,s){e.#J=t/1e3},this.#u[127]=function(t,s){e.#X.run(t,s)},this.#X.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#X.add([67,0,1],function(t,s){e.#B[s]=t[0]+1}),this.#V=new x("universal non-realtime"),this.#F=new x("universal realtime"),this.#k=new x("Yamaha"),this.#w=new x("Roland"),this.#A=new x("Korg"),this.#K=new x("Kawai"),this.#z=new x("Akai"),this.#q=new x("Casio");let a=function(t){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,t)};this.#V.default=a,this.#F.default=a,this.#k.default=a,this.#w.default=a,this.#A.default=a,this.#K.default=a,this.#z.default=a,this.#q.default=a,this.#V.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#c=e.#c||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#F.add([4,1],t=>{e.#n=((t[1]<<7)+t[0])/16383*100,e.dispatchEvent("mastervolume",e.#n)}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#k.add([76,0,0],t=>{switch(t[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${t}`);break}case 126:{e.switchMode("xg",!0),e.#c=!1,console.info("MIDI reset: XG");break}default:{let s=[0,0,0,0],n=(i,r)=>{s[r]=i};if(t.subarray(1).forEach((i,r)=>{let c=r+t[0];([n,n,n,n,f=>{this.#n=f*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},f=>{},f=>{}][c]||(()=>{}))(i,r)}),t[0]<4){let i=0;s.forEach(r=>{i=i<<4,i+=r}),i-=1024}}}}).add([76,2,1],t=>{let s="XG ";t[0]<32?(s+="reverb ",t.subarray(1).forEach((n,i)=>{([r=>{e.setEffectTypeRaw(0,!1,r),console.info(`${s}main type: ${A[r]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},r=>{e.setEffectTypeRaw(0,!0,r),console.debug(`${s}sub type: ${r+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},r=>{console.debug(`${s}time: ${W(r)}s`)},r=>{console.debug(`${s}diffusion: ${r}`)},r=>{console.debug(`${s}initial delay: ${r}`)},r=>{console.debug(`${s}HPF cutoff: ${D[r]}Hz`)},r=>{console.debug(`${s}LPF cutoff: ${D[r]}Hz`)},r=>{console.debug(`${s}width: ${r}`)},r=>{console.debug(`${s}height: ${r}`)},r=>{console.debug(`${s}depth: ${r}`)},r=>{console.debug(`${s}wall type: ${r}`)},r=>{console.debug(`${s}dry/wet: ${r}`)},r=>{console.debug(`${s}send: ${S(r)}dB`)},r=>{console.debug(`${s}pan: ${r-64}`)},!1,!1,r=>{console.debug(`${s}delay: ${r}`)},r=>{console.debug(`${s}density: ${r}`)},r=>{console.debug(`${s}balance: ${r}`)},r=>{},r=>{console.debug(`${s}feedback: ${r}`)},r=>{}][t[0]+i]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(n)})):t[0]<64?(s+="chorus ",t.subarray(1).forEach((n,i)=>{([r=>{e.setEffectTypeRaw(1,!1,r),console.info(`${s}main type: ${A[r]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},r=>{e.setEffectTypeRaw(1,!0,r),console.debug(`${s}sub type: ${r+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},r=>{console.debug(`${s}LFO: ${Y[r]}Hz`)},r=>{},r=>{console.debug(`${s}feedback: ${r}`)},r=>{console.debug(`${s}delay offset: ${J(r)}ms`)},r=>{},r=>{console.debug(`${s}low: ${D[r]}Hz`)},r=>{console.debug(`${s}low: ${r-64}dB`)},r=>{console.debug(`${s}high: ${D[r]}Hz`)},r=>{console.debug(`${s}high: ${r-64}dB`)},r=>{console.debug(`${s}dry/wet: ${r}`)},r=>{console.debug(`${s}send: ${S(r)}dB`)},r=>{console.debug(`${s}pan: ${r-64}`)},r=>{console.debug(`${s}to reverb: ${S(r)}dB`)},!1,r=>{},r=>{},r=>{},r=>{console.debug(`${s}LFO phase diff: ${(r-64)*3}deg`)},r=>{console.debug(`${s}input mode: ${r?"stereo":"mono"}`)},r=>{}][t[0]-32+i]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(n)})):t[0]<86?(s+="variation ",t.subarray(1).forEach((n,i)=>{([r=>{e.setEffectTypeRaw(2,!1,r),console.info(`${s}main type: ${A[r]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},r=>{e.setEffectTypeRaw(2,!0,r),console.debug(`${s}sub type: ${r+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][t[0]-64+i]||function(){})(n)})):t[0]<97?(s+="variation ",t.subarray(1).forEach((n,i)=>{[r=>{console.debug(`${s}send: ${S(r)}dB`)},r=>{console.debug(`${s}pan: ${r-64}`)},r=>{console.debug(`${s}to reverb: ${S(r)}dB`)},r=>{console.debug(`${s}to chorus: ${S(r)}dB`)},r=>{console.debug(`${s}connection: ${r?"system":"insertion"}`)},r=>{console.debug(`${s}channel: CH${r+1}`)},r=>{console.debug(`${s}mod wheel: ${r-64}`)},r=>{console.debug(`${s}bend wheel: ${r-64}`)},r=>{console.debug(`${s}channel after touch: ${r-64}`)},r=>{console.debug(`${s}AC1: ${r-64}`)},r=>{console.debug(`${s}AC2: ${r-64}`)}][t[0]-86+i](n)})):t[0]>111&&t[0]<118?s+="variation ":console.warn(`Unknown XG variation address: ${t[0]}`)}).add([76,2,64],t=>{t.subarray(1).forEach((s,n)=>{let i=n+t[0];if(i==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][s]}`);else{let r=i-1>>2,c=i-1&3,f=`XG EQ ${r} ${["gain","freq","Q","shape"][c]}: `;[()=>{console.debug(`${f}${s-64}dB`)},()=>{console.debug(`${f}${s} (raw)`)},()=>{console.debug(`${f}${s/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!s]}`)}][c]()}})}).add([76,3],t=>{let s=t[0],n=t[1],i=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((r,c)=>{([f=>{e.setEffectTypeRaw(3+s,!1,f),console.info(`${i}main type: ${A[f]}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))},f=>{e.setEffectTypeRaw(3+s,!0,f),console.debug(`${i}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${s}`,e.getEffectType(3+s))}][n+c]||function(){})(r)})}).add([76,6,0],t=>{let s=t[0];s<64?e.setLetterDisplay(t.subarray(1),"XG letter display",s):e.#G=Date.now()}).add([76,7,0],t=>{let s=t[0];e.#p=0,e.#C=Date.now()+3200,e.#y.fill(0);let n=t.subarray(1);for(let i=0;i>6-$&1,$++})}).add([76,8],(t,s)=>{let n=e.chRedir(t[0],s,!0),i=t[1],r=b.cc*n,c=`XG CH${n+1} `,f=`Unknown XG part address ${i}.`;t.subarray(2).forEach((l,p)=>{i<1?console.debug(f):i<41?([()=>{e.#e[r+u[0]]=l,e.dispatchEvent("voice",{part:n})},()=>{e.#e[r+u[32]]=l,e.dispatchEvent("voice",{part:n})},()=>{e.#i[n]=l,e.dispatchEvent("voice",{part:n})},()=>{let $=e.chRedir(l,s,!0);e.#d[n]=$,n!=$&&(e.buildRchTree(),console.info(`${c}receives from CH${$+1}`))},()=>{e.#$[n]=+!l},()=>{},()=>{e.setChType(n,l,m.xg),console.debug(`${c}type: ${U[l]||l}`)},()=>{e.#a[b.rpn*n+3]=l,e.#r[b.rpnt*n+2]=1},!1,!1,()=>{e.#e[r+u[7]]=l},!1,!1,()=>{e.#e[r+u[10]]=l||128},!1,!1,()=>{e.#e[r+u[128]]=l},()=>{e.#e[r+u[93]]=l},()=>{e.#e[r+u[91]]=l},()=>{e.#e[r+u[94]]=l},()=>{e.#e[r+u[76]]=l},()=>{e.#e[r+u[77]]=l},()=>{e.#e[r+u[78]]=l},()=>{e.#e[r+u[74]]=l},()=>{e.#e[r+u[71]]=l},()=>{e.#e[r+u[73]]=l},()=>{e.#e[r+u[75]]=l},()=>{e.#e[r+u[72]]=l}][i+p-1]||(()=>{}))():i<48?console.debug(f):i<111?i>102&&i<105&&(e.#e[r+u[[5,65][i&1]]]=l):i<114?console.debug(f):i<116?console.debug(`${c}EQ ${["bass","treble"][i&1]} gain: ${l-64}dB`):i<118?console.debug(f):i<120?console.debug(`${c}EQ ${["bass","treble"][i&1]} freq: ${l}`):console.debug(f)})}).add([76,9],(t,s)=>{let n=e.chRedir(t[0],s,!0),i=t[1],r=`PLG-150VL CH${n+1} `;t.subarray(2).forEach((c,f)=>{let l=f+i;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 p=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${r}${p} control source: ${ee(c)}`),c&&c<96&&e.allocateAce(c)):console.debug(`${r}${p} scale break point: ${c}`):console.debug(`${r}${p} 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,s)=>{let n=t[0],i="MU1000 System: ";t.subarray(1).forEach((r,c)=>{let f=n+c;f==8?console.debug(`${i}LCD contrast set to ${r}.`):f==18?(e.#m=r?126:0,console.debug(`${i}bank defaults to ${r?"MU100 Native":"MU Basic"}.`)):f>=64&&f<69&&[()=>{e.dispatchEvent("channelactive",r)},()=>{r<8?(e.dispatchEvent("channelmin",r<<4),console.debug(`Octavia System: Minimum CH${(r<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{r<8?(e.dispatchEvent("channelmax",(r<<4)+15),console.debug(`Octavia System: Maximum CH${(r<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#S=!!r,console.info(`Octavia System: RS receiving ${["dis","en"][r]}abled.`)}][f-64]()})}).add([73,10,0],(t,s)=>{let n=t[0],i=`MU1000 RS${e.#S?"":" (ignored)"}: `;if(n<16)switch(n){case 2:{let r=e.chRedir(0,s,!0);e.#S&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+63)),console.info(`${i}Show CH1~64`);break}case 3:{let r=e.chRedir(t[1]<<5,s,!0);e.#S&&e.dispatchEvent("channelmin",r),e.#S&&e.dispatchEvent("channelmax",r+31),console.info(`${i}Show CH${r+1}~CH${r+32}`);break}default:console.debug(`${i}unknown switch ${n} invoked.`)}else if(n<32){if(e.#S){let r=e.chRedir(n-16+(e.#j<<4),s,!0);e.dispatchEvent("channelactive",r)}}else if(n<36){let r=e.chRedir(n-32<<4,s,!0);e.#S&&(e.dispatchEvent("channelmin",r),e.dispatchEvent("channelmax",r+15),e.#j=n-32),console.info(`${i}Show CH${r+1}~CH${r+16}`)}}).add([93,3],(t,s)=>{let n=e.chRedir(t[0],s,!0),i=`PLG-100SG CH${n+1} `,r=Date.now();if(t[1]==0){let c="",f=0;t.subarray(2).forEach((l,p)=>{p%2==0?c+=Z[l]||l.toString().padStart("0"):f+=l*13}),r>=e.#Z&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${j(c)}`,amend:!0}),e.#Z=r+Math.ceil(f/2)+e.#J,k()&&console.debug(`${i}vocals: ${c}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)});let o=function(t,s,n,i){},h=function(t,s){let n=t*b.dpn,i=s[0],r=s[1];s.subarray(2).forEach((c,f)=>{let l=f+r,p=-1;l<16?([()=>{p=24},()=>{p=25},()=>{p=26},()=>{},()=>{p=28},()=>{p=29},()=>{p=30},()=>{p=31},()=>{},()=>{},()=>{},()=>{p=20},()=>{p=21},()=>{p=22},()=>{p=23},()=>{}][l]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${t+1}.`)}))():l<32||(l<40?([()=>{p=48},()=>{p=49},!1,!1,()=>{p=52},()=>{p=53}][l-32]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${t+1}.`)}))():l<80||([()=>{p=36}][l-80]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${t+1}.`)}))()),p>=0?(k()&&console.debug(n,p,i,c),e.#b[(n+C[p])*b.dnc+i]=c):k()&&console.debug(`XG-style drum param ${l} has no writes.`)})},y=function(t,s,n){let i=t*b.dpn,r=(s<<7)+n[0];n.subarray(1).forEach((c,f)=>{let l=f+r,p=l&127,$=l>>7,E=-1;$>1&&([()=>{E=26},()=>{},()=>{E=28},()=>{E=29},()=>{E=30},()=>{},()=>{},()=>{E=31}][$-2]||(()=>{console.debug(`Unknown GS-style drum param ${$} on set ${t+1}.`)}))(),E>-1?(k()&&console.debug(i,E,p,c),e.#b[(i+C[E])*b.dnc+p]=c):k()&&console.debug(`GS-style drum param ${$} has no writes.`)})};this.#k.add([76,48],(t,s,n)=>{h(0,t)}).add([76,49],(t,s,n)=>{h(1,t)}).add([76,50],(t,s,n)=>{h(2,t)}).add([76,51],(t,s,n)=>{h(3,t)}).add([76,52],(t,s,n)=>{h(4,t)}).add([76,53],(t,s,n)=>{h(5,t)}).add([76,54],(t,s,n)=>{h(6,t)}).add([76,55],(t,s,n)=>{h(7,t)}),this.#k.add([89,0],(t,s,n)=>{if(e.eprom){let i=t[0],r=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);k()&&console.debug(`MU1000 EPROM trail to 0x${r.toString(16).padStart(6,"0")}, ${i} bytes.`);let c=e.eprom.data;t.subarray(4).forEach((f,l)=>{let p=l>>3,$=l&7;if($==7)for(let E=0;E<7;E++)c[r+7*p+E]+=(f>>6-E&1)<<7;else c[r+7*p+$]=f})}}).add([89,1],(t,s,n)=>{let i=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];k()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(t,s,n)=>{if(e.eprom){let i=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);k()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let r=e.eprom.data;t.subarray(4).forEach((c,f)=>{let l=f>>3,p=f&7;if(p==7)for(let $=0;$<7;$++)r[i+7*l+$]+=(c>>6-$&1)<<7;else r[i+7*l+p]=c})}}).add([89,3],(t,s,n)=>{}),this.#k.add([39,48],(t,s,n)=>{}).add([43,0,0],(t,s,n)=>{let i=[0,0,0,0],r=(c,f)=>{i[f]=c};if(t.subarray(1).forEach((c,f)=>{let l=f+t[0];[r,r,r,r,()=>{this.#n=c*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},()=>c-64,()=>c||128,()=>c,()=>c,()=>{console.debug(`TG300 variation on cc${c}.`)}][l](c,l)}),t[0]<4){let c=0;i.forEach(f=>{c=c<<4,c+=f}),c-=1024}}).add([43,1,0],(t,s,n)=>{}).add([43,2],(t,s,n)=>{let i=e.chRedir(t[0],s,!0),r=t[1],c=b.cc*i,f=`TG300 CH${i+1} `;t.subarray(2).forEach((l,p)=>{p<5?([()=>{},()=>{e.#e[c+u[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{e.#e[c+u[32]]=l,e.dispatchEvent("voice",{part:i})},()=>{e.#i[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(l,s,!0);e.#d[i]=$,i!=$&&(e.buildRchTree(),console.info(`${f}receives from CH${$+1}`))}][p+r]||(()=>{}))(l,p+r):p<21||(p<47?([()=>{e.#$[i]=+!l},()=>{},()=>{},()=>{e.#a[b.rpn*i+3]=l,e.#r[b.rpnt*i+2]=1},()=>{},()=>{e.#e[c+u[7]]=l},!1,!1,()=>{e.#e[c+u[10]]=l||128},!1,!1,()=>{console.debug(`${f} AC1 at cc${l}`)},()=>{console.debug(`${f} AC2 at cc${l}`)},()=>{e.#e[c+u[128]]=l},()=>{e.#e[c+u[93]]=l},()=>{e.#e[c+u[91]]=l},()=>{e.#e[c+u[94]]=l},()=>{e.#e[c+u[76]]=l},()=>{e.#e[c+u[77]]=l},()=>{e.#e[c+u[74]]=l},()=>{e.#e[c+u[71]]=l},()=>{e.#e[c+u[73]]=l},()=>{e.#e[c+u[75]]=l},()=>{e.#e[c+u[72]]=l},()=>{e.#e[c+u[78]]=l}][p+r-21]||(()=>{}))(l,p+r):p<95||([()=>{e.#e[c+u[65]]=l},()=>{e.#e[c+u[5]]=l}][p+r-95]||(()=>{}))(l,p+r))})}).add([43,7,0],(t,s,n)=>{let i=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",i)}).add([43,7,1],(t,s,n)=>{e.#p=0,e.#C=Date.now()+3200,e.#y.fill(0),t.forEach(function(i,r){let c=Math.floor(r/16),f=r%16,l=(f*3+c)*7,p=7,$=0;for(l-=f*5,c==2&&(p=2);$>6-$&1,$++})}),this.#w.add([66,18,0,0,127],(t,s,n)=>{e.switchMode("gs",!0),e.#e[b.cc*9]=120,e.#e[b.cc*25]=120,e.#e[b.cc*41]=120,e.#e[b.cc*57]=120,e.#m=3,e.#c=!1,e.#O.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,s,n)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[b.cc*9]=120,e.#e[b.cc*25]=120,e.#e[b.cc*41]=120,e.#e[b.cc*57]=120,e.#c=!1,e.#O.fill(0),console.info("MIDI reset: GS");break}default:{let i=[0,0,0,0],r=(c,f)=>{i[f]=c};if(t.subarray(1).forEach((c,f)=>{let l=f+t[0];[r,r,r,r,p=>{this.#n=p*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},p=>{},p=>{}][l](c,f)}),t[0]<4){let c=0;i.forEach(f=>{c=c<<4,c+=f}),c-=1024}}}}).add([66,18,64,1],t=>{let s=t[0];if(s<16){let n="".padStart(s," ");t.subarray(1).forEach((i,r)=>{n+=String.fromCharCode(Math.max(32,i))}),n=n.padEnd(16," "),console.debug(`GS patch name: ${n}`)}else s<48||(s<65?t.subarray(1).forEach((n,i)=>{let r=`GS ${s+i>55?"chorus":"reverb"} `;([()=>{console.info(`${r}type: ${I[n]}`),e.setEffectType(0,40,n),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${r}predelay: ${n}ms`)},()=>{console.info(`${r}type: ${te[n]}`),e.setEffectType(1,40,16+n),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${S(n)}`)},()=>{console.debug(`${r}to delay: ${S(n)}`)}][s+i-48]||(()=>{}))()}):s<80?console.debug(`Unknown GS patch address: ${s}`):s<91?t.subarray(1).forEach((n,i)=>{let r="GS delay ";([()=>{console.info(`${r}type: ${ae[n]}`),e.setEffectType(2,40,32+n),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${r}to reverb: ${S(n)}`)}][s+i-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${s}`))}).add([66,18,64,2],t=>{let s="GS EQ ";t.subarray(1).forEach((n,i)=>{([()=>{console.debug(`${s}low freq: ${[200,400][n]}Hz`)},()=>{console.debug(`${s}low gain: ${n-64}dB`)},()=>{console.debug(`${s}high freq: ${[3e3,6e3][n]}Hz`)},()=>{console.debug(`${s}high gain: ${n-64}dB`)}][t[0]+i]||function(){console.warn(`Unknown GS EQ address: ${t[0]+i}`)})()})}).add([66,18,64,3],t=>{let s="GS EFX ",n=function(i,r){let c=se(e.#g.subarray(10,12),r,i);c&&console.debug(`${s}${X(e.#g.subarray(10,12))} ${c}`)};t.subarray(1).forEach((i,r)=>{([()=>{e.setEffectTypeRaw(3,!1,32+i),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,i),console.info(`${s}type: ${X(e.#g.subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,()=>{console.debug(`${s}to reverb: ${S(i)}dB`)},()=>{console.debug(`${s}to chorus: ${S(i)}dB`)},()=>{console.debug(`${s}to delay: ${S(i)}dB`)},!1,()=>{console.debug(`${s}1 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${s}1 depth: ${i-64}`)},()=>{console.debug(`${s}2 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${s}2 depth: ${i-64}`)},()=>{console.debug(`${s}to EQ: ${i?"ON":"OFF"}`)}][t[0]+r]||function(c,f){console.warn(`Unknown GS EFX address: ${f}`)})(i,t[0]+r)})}).add([66,18,65],t=>{y((t[0]>>4)+1<<1,t[0]&15,t.subarray(1))}).add([69,18,16],t=>{switch(t[0]){case 0:{let s=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",s);break}case 32:{e.#C=Date.now()+3200,t[1]==0&&(e.#p=Math.max(Math.min(t[2]-1,9),0),k()&&console.debug(`GS switch display page ${t[2]-1}.`));break}default:if(t[0]<6){e.#p>9&&(e.#p=0);let s=t[0]-1<<1|t[1]>>6;e.#p==s&&(e.#C=Date.now()+3200),e.#M[s]?.length||(e.#M[s]=new Uint8Array(256));let n=e.#M[s];k()&&console.debug(`GS frame draw page ${s}.`);let i=t[1]&63;n.fill(0),t.subarray(2).forEach(function(c,f){let l=f+i,p=Math.floor(l/16),$=l%16,E=($*4+p)*5,w=5,v=0;for(E-=$*4,p==3&&(w=1);v>4-v&1,v++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let g=function(t,s,n){let i=t[0],r=b.cc*s,c=b.rpn*s,f=`GS CH${s+1} `;i<3?(t.subarray(1).forEach((l,p)=>{[()=>{e.#e[r+u[0]]=l},()=>{e.#i[s]=l},()=>{let $=0;l<16?$=e.chRedir(l,n,!0):$=b.ch,e.#d[s]=$,s!=$&&(e.buildRchTree(),console.info(`${f}receives from CH${$+1}`))}][i+p]()}),e.dispatchEvent("voice",{part:s})):i<19||(i<44?t.subarray(1).forEach((l,p)=>{([()=>{e.#$[s]=+!l},!1,()=>{e.setChType(s,l<<1,m.gs),console.debug(`${f}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{e.#a[c+3]=l,e.#r[b.rpnt*s+2]=1},!1,()=>{e.#e[r+u[7]]=l},!1,!1,()=>{e.#e[r+u[10]]=l||128},!1,!1,()=>{console.debug(`${f}CC 1: cc${l}`)},()=>{console.debug(`${f}CC 2: cc${l}`)},()=>{e.#e[r+u[93]]=l},()=>{e.#e[r+u[91]]=l},!1,!1,()=>{e.#a[c+1]=l,e.#r[b.rpnt*s+1]=1},()=>{e.#a[c+2]=l,e.#r[b.rpnt*s+1]=1},()=>{e.#e[r+u[94]]=l}][i+p-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},d=function(t,s){let n=t[0],i=`GS CH${s+1} `;n<2?t.subarray(1).forEach((r,c)=>{[()=>{e.#e[b.cc*s+u[32]]=r},()=>{}][n+c]()}):n<32?console.warn(`Unknown GS misc address: ${n}`):n<35?t.subarray(1).forEach((r,c)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][r]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][r]}`),e.#W[s]=r,e.dispatchEvent("partefxtoggle",{part:s,active:r})}][n+c-32]()}):console.warn(`Unknown GS misc address: ${n}`)};this.#w.add([66,18,64,16],(t,s)=>{g(t,e.chRedir(9,s,!0),s)}).add([66,18,64,17],(t,s)=>{g(t,e.chRedir(0,s,!0),s)}).add([66,18,64,18],(t,s)=>{g(t,e.chRedir(1,s,!0),s)}).add([66,18,64,19],(t,s)=>{g(t,e.chRedir(2,s,!0),s)}).add([66,18,64,20],(t,s)=>{g(t,e.chRedir(3,s,!0),s)}).add([66,18,64,21],(t,s)=>{g(t,e.chRedir(4,s,!0),s)}).add([66,18,64,22],(t,s)=>{g(t,e.chRedir(5,s,!0),s)}).add([66,18,64,23],(t,s)=>{g(t,e.chRedir(6,s,!0),s)}).add([66,18,64,24],(t,s)=>{g(t,e.chRedir(7,s,!0),s)}).add([66,18,64,25],(t,s)=>{g(t,e.chRedir(8,s,!0),s)}).add([66,18,64,26],(t,s)=>{g(t,e.chRedir(10,s,!0),s)}).add([66,18,64,27],(t,s)=>{g(t,e.chRedir(11,s,!0),s)}).add([66,18,64,28],(t,s)=>{g(t,e.chRedir(12,s,!0),s)}).add([66,18,64,29],(t,s)=>{g(t,e.chRedir(13,s,!0),s)}).add([66,18,64,30],(t,s)=>{g(t,e.chRedir(14,s,!0),s)}).add([66,18,64,31],(t,s)=>{g(t,e.chRedir(15,s,!0),s)}).add([66,18,64,64],(t,s)=>{d(t,e.chRedir(9,s,!0))}).add([66,18,64,65],(t,s)=>{d(t,e.chRedir(0,s,!0))}).add([66,18,64,66],(t,s)=>{d(t,e.chRedir(1,s,!0))}).add([66,18,64,67],(t,s)=>{d(t,e.chRedir(2,s,!0))}).add([66,18,64,68],(t,s)=>{d(t,e.chRedir(3,s,!0))}).add([66,18,64,69],(t,s)=>{d(t,e.chRedir(4,s,!0))}).add([66,18,64,70],(t,s)=>{d(t,e.chRedir(5,s,!0))}).add([66,18,64,71],(t,s)=>{d(t,e.chRedir(6,s,!0))}).add([66,18,64,72],(t,s)=>{d(t,e.chRedir(7,s,!0))}).add([66,18,64,73],(t,s)=>{d(t,e.chRedir(8,s,!0))}).add([66,18,64,74],(t,s)=>{d(t,e.chRedir(10,s,!0))}).add([66,18,64,75],(t,s)=>{d(t,e.chRedir(11,s,!0))}).add([66,18,64,76],(t,s)=>{d(t,e.chRedir(12,s,!0))}).add([66,18,64,77],(t,s)=>{d(t,e.chRedir(13,s,!0))}).add([66,18,64,78],(t,s)=>{d(t,e.chRedir(14,s,!0))}).add([66,18,64,79],(t,s)=>{d(t,e.chRedir(15,s,!0))}),this.#A.add([54,65],(t,s)=>{e.switchMode("x5d");let n=(t[1]<<7)+t[0],i=(t[3]<<7)+t[2],r=e.chRedir(n&15,s,!0),c=b.cc*r;[()=>{i<1||(i<101?(e.setChType(r,e.CH_MELODIC,m.x5d),e.#i[r]=i-1,e.#e[c+u[0]]=82):i<229?(e.setChType(r,e.CH_MELODIC,m.x5d),e.#i[r]=i-101,e.#e[c+u[0]]=56):(e.setChType(r,e.CH_DRUMS,m.x5d),e.#i[r]=de[i-229]||0,e.#e[c+u[0]]=62)),e.dispatchEvent("voice",{part:r})},()=>{e.#e[c+u[7]]=i},()=>{i<31&&(e.#e[c+u[10]]=Math.round((i-15)*4.2+64))},()=>{e.#e[c+u[93]]=P(i)},()=>{e.#e[c+u[91]]=P(i)},()=>{e.#a[r*b.rpn+3]=i>8191?i-16320:64+i,e.#r[b.rpnt*r+2]=1},()=>{e.#a[r*b.rpn+1]=i>8191?i-16320:64+i,e.#r[b.rpnt*r+1]=1},()=>{i>0&&(e.#a[r*b.rpn]=i,e.#r[b.rpnt*r]=1)},()=>{}][n>>4]()}).add([54,76,0],(t,s)=>{e.switchMode("x5d",!0);let n="",i=82,r=0,c=0,f="MSB PRG LSB NME";T(t,function(l,p){if(p<16400){let $=p%164;switch(!0){case $<10:{l>31&&(n+=String.fromCharCode(l));break}case $==11:{f+=` +${i} ${r} ${c} ${n.trim().replace("Init Voice","")}`,r++,n="";break}}r>99&&(i=90,r=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([54,77,0],(t,s)=>{e.switchMode("x5d",!0);let n="",i=90,r=0,c=0,f="MSB PRG LSB NME";T(t,function(l,p){if(p<13600){let $=p%136;switch(!0){case $<10:{l>31&&(n+=String.fromCharCode(l));break}case $==11:{f+=` +${i} ${r} ${c} ${n.trim().replace("Init Combi","")}`,r++,n="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([54,78],(t,s)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][t[0]]} mode.`)}).add([54,85],(t,s)=>{e.switchMode("x5d",!0),T(t,(n,i)=>{i>0&&i<3&&(e.setEffectType(i-1,44,n),e.dispatchEvent(`efx${["reverb","chorus"][i-1]}`,e.getEffectType(i-1)))})}).add([54,104],(t,s)=>{e.switchMode("x5d",!0),T(t,function(n,i,r,c){if(i<192){let f=e.chRedir(Math.floor(i/12),s,!0),l=f*b.cc;switch(i%12){case 0:{n<128?(e.setChType(f,e.CH_MELODIC,m.x5d),e.#e[l+u[0]]=82,e.#i[f]=n):(e.setChType(f,e.CH_DRUMS,m.x5d),e.#e[l+u[0]]=62,e.#i[f]=de[n-128]),n>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{e.#e[l+u[7]]=n;break}case 2:{e.#a[f*b.rpn+3]=n>127?n-192:64+n,e.#r[b.rpnt*f+2]=1;break}case 3:{e.#a[f*b.rpn+1]=n>127?n-192:64+n,e.#r[b.rpnt*f+1]=1;break}case 4:{n<31&&(e.#e[l+u[10]]=Math.round((n-15)*4.2+64));break}case 5:{let p=n>>4,$=n&15;e.#e[l+u[91]]=P($),e.#e[l+u[93]]=P(p);break}case 10:break;case 11:{let p=e.chRedir(n&15,s,!0),$=n>>4;e.#d[f]=n,(p!=f||$)&&(console.info(`X5D Part CH${f+1} receives from CH${p+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(i-192,s,!0)}})}),this.#w.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#c=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(t,s,n)=>{e.switchMode("mt32");let i=e.chRedir(n,s,!0),r=t[1];t.subarray(2).forEach((c,f)=>{let l=f+r;e.#P[l+(i-1)*16]=c,([!1,()=>{let p=e.#P[i-1<<4];if(p<3){if(e.#T[i]=1,p==2)for(let $=0;${e.#a[i*b.rpn+3]=c+40,e.#r[b.rpnt*i+2]=1},()=>{e.#a[i*b.rpn+1]=c+14,e.#r[b.rpnt*i+1]=1},()=>{e.#a[i*b.rpn]=c,e.#r[b.rpnt*i]=1},!1,()=>{e.#e[b.cc*i+u[91]]=c?127:0},!1,()=>{e.#e[b.cc*i+u[7]]=c},()=>{e.#e[b.cc*i+u[10]]=Math.ceil(c*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(t,s,n)=>{e.switchMode("mt32");let i=n&7;console.debug(`MT-32 slot #${n+1} Drum: ${t}`);let r=t[0]<<7|t[1];t.subarray(2).forEach((c,f)=>{let l=f+r,p=(l>>2)+24,$=l&3,E=i*b.dpn;if(k()&&console.debug(`MT-32 temp drum note ${p} param ${$}: ${c}`),p<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${p}`);return}[()=>{},()=>{e.#b[(E+C[26])*b.dnc+p]=Math.round(c*1.27)},()=>{e.#b[(E+C[26])*b.dnc+p]=c*9+1&127},()=>{e.#b[(E+C[26])*b.dnc+p]=c?127:0}][$]()})}).add([22,18,2],(t,s,n)=>{e.switchMode("mt32");let i=e.chRedir(n,s,!0),r=t[1]+(t[0]<<7);r<10&&(e.#T[i]=1),t.subarray(2).forEach((c,f)=>{let l=f+r;l<14&&(e.#v[(i-1)*b.cmt+l]=c)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(t,s,n)=>{e.switchMode("mt32");let i=n&7;if(t[0]){let r=(t[0]-1<<7)+t[1]-16;t.subarray(2).forEach((c,f)=>{let l=f+r,p=(l>>2)+24,$=l&3,E=i*b.dpn;if(k()&&console.debug(`MT-32 dev drum note ${p} param ${$}: ${c}`),p<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${p}`);return}[()=>{},()=>{e.#b[(E+C[26])*b.dnc+p]=Math.round(c*1.27)},()=>{e.#b[(E+C[26])*b.dnc+p]=c*9+1&127},()=>{e.#b[(E+C[26])*b.dnc+p]=c?127:0}][$]()})}else{let r=t[1];t.subarray(2).forEach((c,f)=>{let l=f+r;e.#P[l]=c;let p=e.chRedir(1+(l>>4),s,!0),$=l&15;([!1,()=>{let E=e.#P[p-1<<4];if(E<3)if(e.#T[p]=1,E==2)for(let w=0;w{e.#a[p*b.rpn+3]=c+40,e.#r[b.rpnt*p+2]=1},()=>{e.#a[p*b.rpn+1]=c+14,e.#r[b.rpnt*p+1]=1},()=>{e.#a[p*b.rpn]=c,e.#r[b.rpnt*p]=1},!1,()=>{e.#e[b.cc*p+u[91]]=c?127:0},!1,()=>{e.#e[b.cc*p+u[7]]=c},()=>{e.#e[b.cc*p+u[10]]=Math.ceil(c*9.05)}][$]||(()=>{}))()})}}).add([22,18,4],(t,s,n)=>{e.switchMode("mt32");let i=t[1]+(t[0]<<7),r=[];t.subarray(2).forEach((c,f)=>{let l=f+i,p=e.chRedir(Math.floor(l/246+1),s,!0),$=l%246;$<14&&(e.#v[(p-1)*b.cmt+$]=c),$<10&&(e.#T[p]=1),r.indexOf(p)<0&&r.push(p)}),r.forEach(c=>{e.dispatchEvent("voice",{part:c})})}).add([22,18,5],(t,s,n)=>{e.switchMode("mt32");let i=(t[0]<<7)+t[1];t.subarray(2).forEach((r,c)=>{let f=i+c,l=Math.floor(f/8),p=f&7,$=l*8;e.#Y[f]=r,([!1,()=>{let E=e.#Y[$];if(E<3){let w="";if(E==2){let v=b.cmt*l;w=`MT-m:${r.toString().padStart(3,"0")}`}else w=e.baseBank.get(0,r+(E<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l}),e.userBank.load(`MSB LSB PRG NME +000 127 ${l} ${w}`,!0)}}][p]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(t,s,n)=>{e.switchMode("mt32");let i=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((r,c)=>{let f=i+c;f>1)*b.cmt+f]=r)}),e.forceVoiceRefresh()}).add([22,18,16],(t,s,n)=>{e.switchMode("mt32");let i=t[1],r=!1,c=function(f,l){e.#d[l-12]=f,r=!0};t.subarray(2).forEach((f,l)=>{let p=l+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,c,c,c,c,c,c,c,c,c,()=>{e.#n=f,e.dispatchEvent("mastervolume",e.#n)}][p]||(()=>{}))(f,l)}),r&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let s=t[1],n=" ".repeat(s);t.subarray(2).forEach(i=>{i>31?n+=String.fromCharCode(i):n+=" "}),e.#L=n.padStart(20," "),e.#G=Date.now()+3200}).add([22,18,82],(t,s)=>{let n=e.chRedir(0,s,!0);for(let i=0;i<16;i++)e.#f.ano(n+i),i&&i<10&&(e.#i[n+i]=V[i-1]);console.info("MT-32 alt reset complete.")}),this.#A.add([66,0],(t,s)=>{e.switchMode("ns5r",!0),e.#c=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,s)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#c=!1}).add([66,18,0,0],(t,s)=>{let n=t[0];switch(n){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#c=!1;break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${t}`);break}default:if(n<10){let i=[0,0,0,0],r=(c,f)=>{i[f]=c};if(t.subarray(1).forEach((c,f)=>{[r,r,r,r,()=>{e.#n=c*129/16383*100,e.dispatchEvent("mastervolume",e.#n)},()=>c-64,()=>c-64,()=>{},()=>{},()=>{}][n+f]()}),t[0]<4){let c=0;i.forEach(f=>{c=c<<4,c+=f}),c-=1024}}}}).add([66,18,0,1],(t,s)=>{}).add([66,18,0,2],(t,s)=>{}).add([66,18,1],(t,s)=>{let n=e.chRedir(t[0],s,!0),i=n*b.cc,r=t[1],c=`NS5R CH${n+1} `;t.subarray(2).forEach((f,l)=>{let p=r+l;p<3?([()=>{e.#e[i+u[0]]=f||121},()=>{e.#e[i+u[32]]=f},()=>{e.#i[n]=f}][p](),e.dispatchEvent("voice",{part:n})):p<8||(p<14?[()=>{let $=e.chRedir(f,s,!0);e.#d[n]=$,n!=$&&(e.buildRchTree(),console.info(`${c}receives from CH${$+1}`))},()=>{e.#$[n]=+!f},()=>{e.setChType(n,f,m.ns5r),console.debug(`${c}type: ${U[f]}`)},()=>{e.#a[b.rpn*n+3]=f,e.#r[b.rpnt*n+2]=1},()=>{},()=>{}][p-8]():p<16||(p<33?[()=>{e.#e[i+u[7]]=f},()=>{e.#e[i+u[11]]=f},()=>{},()=>{},()=>{e.#e[i+u[10]]=f||128},()=>{},()=>{},()=>{e.#e[i+u[93]]=f},()=>{e.#e[i+u[91]]=f},()=>{e.#e[i+u[76]]=f},()=>{e.#e[i+u[77]]=f},()=>{e.#e[i+u[78]]=f},()=>{e.#e[i+u[74]]=f},()=>{e.#e[i+u[71]]=f},()=>{e.#e[i+u[73]]=f},()=>{e.#e[i+u[75]]=f},()=>{e.#e[i+u[72]]=f}][p-16]():p<112||p<114&&[()=>{e.#e[i+u[5]]=f},()=>{e.#e[i+u[65]]=f}][p-112]()))})}).add([66,18,8,0],(t,s)=>{let n=t[0];if(n<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let i=n-32;e.#C=Date.now()+3200,e.#p=10,e.#y.fill(0);let r=t.subarray(1),c=4;r.forEach(function(f,l){let p=l+i,$=p>>4,E=p&15;if(p<80){let w=$>3,v=0,he=$0;)e.#y[E*32+$*7+(he-v)]=w&1,w=w>>1,v++}})}}).add([66,18,48],(t,s,n)=>{h(0,t)}).add([66,18,49],(t,s,n)=>{h(1,t)}).add([66,18,50],(t,s,n)=>{h(2,t)}).add([66,18,51],(t,s,n)=>{h(3,t)}).add([66,18,52],(t,s,n)=>{h(4,t)}).add([66,18,53],(t,s,n)=>{h(5,t)}).add([66,18,54],(t,s,n)=>{h(6,t)}).add([66,18,55],(t,s,n)=>{h(7,t)}).add([66,52],(t,s)=>{e.switchMode("ns5r",!0),e.#c=!1;let n="";T(t,(i,r)=>{r<8?(i>31&&(n+=String.fromCharCode(i)),r==7&&(e.aiEfxName=n)):r<10&&(e.setEffectType(r-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][r-8]}`,e.getEffectType(r-8)))})}).add([66,53],(t,s)=>{e.switchMode("ns5r",!0),e.#c=!1,T(t,function(n,i){switch(!0){case i<2944:{let r=e.chRedir(Math.floor(i/92),s,!0),c=r*b.cc;switch(i%92){case 0:{e.#e[c+u[0]]=n||121,e.dispatchEvent("voice",{part:r});break}case 1:{e.#e[c+u[32]]=n,e.dispatchEvent("voice",{part:r});break}case 2:{e.#i[r]=n,n>0&&e.setChActive(r,1),e.dispatchEvent("voice",{part:r});break}case 3:{let f=e.chRedir(n,s,!0);e.#d[r]=f,r!=f&&(console.info(`NS5R CH${r+1} receives from CH${f+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#a[r*b.rpn+3]=n<40||n>88?n+(n>63?-192:64):n,e.#r[b.rpnt*r+2]=1;break}case 9:case 10:{e.#e[c+u[7]]=n;break}case 11:{e.#e[c+u[11]]=n;break}case 14:{e.#e[c+u[10]]=n||128;break}case 19:{e.#e[c+u[93]]=n;break}case 20:{e.#e[c+u[91]]=n;break}case 84:{e.#e[c+u[65]]=n;break}case 85:{e.#e[c+u[5]]=n;break}}break}case i<3096:break;case i<3134:break;case i<8566:break}})}).add([66,54],(t,s)=>{e.switchMode("ns5r",!0);let n="",i=80,r=0,c=0,f="MSB PRG LSB NME";T(t,function(l,p){let $=p%158;switch(!0){case $<10:{l>31&&(n+=String.fromCharCode(l));break}case $==11:{i=l&127;break}case $==12:{c=l&127;break}case $==13:{f+=` +${i} ${r} ${c} ${n.trim().replace("Init Voice","")}`,r++,n="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([66,55],(t,s)=>{e.switchMode("ns5r",!0);let n="",i=88,r=0,c=0,f="MSB PRG LSB NME";T(t,function(l,p){let $=p%126;switch(!0){case $<10:{l>31&&(n+=String.fromCharCode(l));break}case $==11:break;case $==12:break;case $==13:{f+=` +${i} ${r} ${c} ${n.trim().replace("Init Combi","")}`,r++,n="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(f),k()&&console.debug(f),e.forceVoiceRefresh()}).add([66,125],t=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][t[0]]||"white")}).add([66,127],t=>{let s=new Uint8Array(5760);T(t,(n,i,r)=>{if(i<720)for(let c=0;c<8;c++)s[i*8+c]=n>>7-c&1}),e.dispatchEvent("screen",{type:"ns5r",data:s})}).add([76],(t,s,n)=>{e.#A.run([66,...t],s,n)}),this.#K.add([16,0,8,0],(t,s,n)=>{let i=(t[2]<<4)+t[3],r="K11 ";([()=>{e.switchMode("k11",!0),e.#c=!1,e.#m=i?4:0,console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,i),console.debug(`${r}reverb type: ${i}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${r}reverb time: ${i}`)},()=>{console.debug(`${r}reverb time: ${i}`)},()=>{console.debug(`${r}reverb predelay: ${i}`)},()=>{console.debug(`${r}reverb predelay: ${i}`)},()=>{console.debug(`${r}depth high: ${i}`)},()=>{console.debug(`${r}depth high: ${i}`)},()=>{console.debug(`${r}depth low: ${i}`)},()=>{console.debug(`${r}depth low: ${i}`)}][t[0]]||(()=>{}))()}).add([16,0,8,1],(t,s,n)=>{let i=e.chRedir(t[1],s,!0),r=b.cc*i,c=b.rpn*i,f=(t[3]<<4)+t[4],l=`K11 CH${i+1} `;([()=>{f<128?(e.setChType(i,e.CH_MELODIC,m.k11),e.#e[r+u[0]]=0,e.#i[i]=f):(e.setChType(i,e.CH_DRUMS,m.k11),e.#i[i]=f-128),e.dispatchEvent("voice",{part:i})},()=>{let p=e.chRedir(f,s,!0);e.#d[i]=p,i!=p&&(e.buildRchTree(),console.info(`${l}receives from CH${p+1}`))},()=>{e.#e[r+u[7]]=f},()=>{uupThis.setChActive(i,f)},()=>{e.#e[r+u[10]]=f},()=>{e.#a[c+3]=f+40,e.#r[b.rpnt*i+2]=1},()=>{e.#a[c+1]=f>>1,e.#a[c+2]=f&1,e.#r[b.rpnt*i+1]=1},()=>{e.#e[r+u[91]]=f?127:0},()=>{},()=>{e.#e[r+u[74]]=f},()=>{e.#e[r+u[73]]=f},()=>{e.#e[r+u[72]]=f}][t[0]]||(()=>{}))()}).add([16,0,9,0],(t,s,n)=>{let i=(t[2]<<4)+t[3],r="GMLX ";([()=>{console.debug(`${r}reverb type: ${i}`)},()=>{console.debug(`${r}reverb time: ${i}`)},()=>{console.debug(`${r}reverb predelay: ${i}`)},()=>{console.debug(`${r}depth high: ${i}`)},()=>{console.debug(`${r}depth low: ${i}`)}][t[0]]||(()=>{}))()}).add([16,0,9,3],(t,s,n)=>{let i=(t[2]<<4)+t[3],r=e.chRedir(t[1],s,!0),c=r*b.cc;[()=>{i<128?(e.setChType(r,e.CH_MELODIC,m.k11),e.#e[c+u[0]]=0,e.#e[c+u[32]]=0,e.#i[r]=i):i<160?(e.setChType(r,e.CH_MELODIC,m.k11),e.#e[c+u[0]]=0,e.#e[c+u[32]]=7,e.#i[r]=i-100):(e.setChType(r,e.CH_DRUMS,m.k11),e.#e[c+u[0]]=122,e.#e[c+u[32]]=0,e.#i[r]=i-160),e.dispatchEvent("voice",{part:r})},()=>{let f=e.chRedir(i,s,!0);e.#d[r]=f,r!=f&&(e.buildRchTree(),console.info(`GMLX CH${r+1} receives from CH${f+1}`))}][t[0]]()}).add([16,0,9,4],(t,s,n)=>{let i=(t[2]<<4)+t[3],r=e.chRedir(t[1],s,!0),c=r*b.cc,f=r*b.rpn,l=`GMLX CH${r+1} `;[()=>{e.setChActive(r,i)},()=>{e.#e[c+u[7]]=i},()=>{e.#e[c+u[10]]=i},()=>{e.#e[c+u[91]]=i?127:0},()=>{e.#a[f+3]=i+40,e.#r[b.rpnt*r+2]=1},()=>{e.#a[f+1]=i,e.#r[b.rpnt*r+1]=1},()=>{e.#a[f]=i,e.#r[b.rpnt*r]=1},()=>{}][t[0]]()}),this.#z.add([66,93,64],(t,s,n)=>{let i=t[2];switch(t[0]){case 0:{switch(t[1]){case 4:{e.#n=i*129/16383*100,e.dispatchEvent("mastervolume",e.#n);break}case 5:{i-64;break}case 6:{console.debug(`SG global reverb: ${i?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(t[1]){case 48:{console.debug(`SG reverb type: ${I[i]}`);break}}break}default:if(t[0]>>4==1){let r=e.chRedir(t[0]&15,s,!0);if(t[1]==2){let c=e.chRedir(i,s,!0);e.#d[r]=c,r!=c&&(e.buildRchTree(),console.info(`SG CH${r+1} receives from CH${c+1}`))}else t[1]==19&&(e.#e[b.cc*r+u[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${t}`)}}),this.#q.add([9],(t,s,n)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][t[0]]||"off"}`)}),this.#k.add([127,0],(t,s,n)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...t]);e.#k.run(i,s,n)}).add([127,1,0,0],(t,s,n)=>{e.switchMode("s90es");let i="S90/Motif ES system ",r=t[0];t.subarray(1).forEach((c,f)=>{([()=>{e.#n=c*12900/16383,e.dispatchEvent("mastervolume",e.#n)}][r+f]||(()=>{console.info(`Unrecognized ${i}ID: ${r+f}`)}))()})}).add([127,1,0,0,14],(t,s,n)=>{e.switchMode("s90es");let i="S90/Motif ES bulk header ",r=[];r[95]=(c,f,l)=>{console.debug(`${i}multi edit buffer: ${c[1]}`)},(r[t[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,0,15],(t,s,n)=>{e.switchMode("s90es");let i="S90/Motif ES bulk footer ",r=[];r[95]=(c,f,l)=>{console.debug(`${i}multi edit buffer: ${c[1]}`)},(r[t[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${t[0]}.`)}))(t.subarray(1))}).add([127,1,0,58,55],(t,s,n)=>{e.switchMode("s90es");let i=e.chRedir(t[0],s,!0),r=b.cc*i,c=t[1],f=`S90/Motif ES bulk CH${i<16?i+1:"U"+(i-95)} `;console.debug(f,t),!(t[0]>15)&&t.subarray(2).forEach((l,p)=>{([()=>{e.#e[r+u[0]]=l,e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),e.#e[r+u[32]]=l,e.setChType(i,[32,40].indexOf(l)>-1?e.CH_DRUMS:e.CH_MELODIC,e.#t,!0),e.dispatchEvent("voice",{part:i})},()=>{l&&e.setChActive(i,1),e.#i[i]=l,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(l,s,!0);e.#d[i]=$,i!=$&&(e.buildRchTree(),console.info(`${f}receives from CH${$+1}`))},()=>{e.#$[i]=l?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{e.#e[r+u[7]]=l},()=>{e.#e[r+u[10]]=l},!1,!1,!1,()=>{e.#e[r+u[91]]=l},()=>{e.#e[r+u[93]]=l},()=>{e.#e[r+u[94]]=l},()=>{e.#e[r+u[128]]=l},()=>{},()=>{e.#e[r+u[74]]=l},()=>{e.#e[r+u[71]]=l},!1,()=>{e.#e[r+u[65]]=l},()=>{e.#e[r+u[5]]=l},()=>{}][c+p]||(()=>{}))()})}).add([127,1,54,16],(t,s,n)=>{e.switchMode("s90es");let i=t[0];t.subarray(1).forEach((r,c)=>{let l=`S90/Motif ES EQ${(c>>2)+1} `;([()=>{let p=r-64},()=>{let p=D[r]},()=>{let p=r/10},()=>{let p=r}][i+c&3]||(()=>{}))()})}),this.#w.add([0,72,18,0,0,0,0],(t,s,n)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(t,s,n)=>{let i=t[0]>>5,r=t[0]&31;switch(i){case 0:{console.debug(`Unknown SD-90 global effects message: +%o`,t);break}case 1:{let c=e.chRedir(r,s,!0),f=t[1],l=c*b.cc;t.subarray(2).forEach((p,$)=>{let E=f+$;E<37?([()=>{},()=>{},0,()=>{},()=>{switch(e.#e[l+u[0]]=p,p){case 104:case 105:case 106:case 107:case 120:{e.#s[c]||e.setChType(c,e.CH_DRUMS);break}default:e.#s[c]&&e.setChType(c,e.CH_MELODIC)}e.dispatchEvent("voice",{part:c})},()=>{e.#e[l+u[32]]=p,e.dispatchEvent("voice",{part:c})},()=>{e.#i[c]=p,e.dispatchEvent("voice",{part:c})},()=>{e.#e[l+u[7]]=p},()=>{e.#e[l+u[10]]=p},()=>{},()=>{},()=>{p<2&&(e.#$[c]=p)},()=>{p<2&&(e.#e[l+u[68]]=p?127:0)},()=>{},()=>{p<2&&(e.#e[l+u[65]]=p?127:0)},()=>{e.#e[l+u[5]]=p&15<<4|e.#e[l+u[5]]&15},()=>{e.#e[l+u[5]]=p&15|(e.#e[l+u[5]]&240)>>4},()=>{e.#e[l+u[74]]=p},()=>{e.#e[l+u[71]]=p},()=>{e.#e[l+u[73]]=p},()=>{e.#e[l+u[72]]=p},0,0,0,0,0,0,0,()=>{e.#e[l+u[128]]=p},()=>{e.#e[l+u[93]]=p},()=>{e.#e[l+u[91]]=p},0,0,()=>{e.#e[l+u[75]]=p},()=>{e.#e[l+u[76]]=p},()=>{e.#e[l+u[77]]=p},()=>{e.#e[l+u[78]]=p}][E]||(()=>{}))():E<63||(E<64?e.#s[c]?e.#e[l+u[0]]=104|p:e.#e[l+u[0]]=96|p:console.debug(`Unknown SD-90 global CH${c+1} param setup message: +%o`,t))});break}case 2:{let c=e.chRedir(r,s,!0),f=t[1];console.debug(`Unknown SD-90 global CH${c+1} MIDI setup message: %o`,t.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,t)}})}};export{Fe as OctaviaDevice,b as allocated,u as ccToPos,C as dnToPos}; +%o`,t)}})}};export{Ke as OctaviaDevice,b as allocated,u as ccToPos,C as dnToPos}; diff --git a/dist/state_skim.mjs b/dist/state_skim.mjs index 2f9dff00..6dc54ff8 100644 --- a/dist/state_skim.mjs +++ b/dist/state_skim.mjs @@ -138,7 +138,7 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let t=e.split(",");F[t[0]]=t[1]});var z=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"];var T=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var R=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19];var q={};z.forEach((e,t)=>{q[e]=t});var Q={length:R.length};R.forEach((e,t)=>{Q[e]=t});var Y={length:T.length};T.forEach((e,t)=>{Y[e]=t});var Le={ch:128,cc:R.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:T.length,dnc:128,efx:7};var W=["MSB","PRG","LSB"],O=function(e){let t=Math.floor(e/10),s=e%10;return`${t.toString(16)}${s}`},x=class{#t;strictMode=!1;get(e=0,t=0,s=0,i){let r=[e,t,s],n,a=Array.from(arguments);switch(i){case"xg":{switch(e){case 0:{s==126?a[2]=125:s==127&&(a[2]=0);break}case 16:{s==126&&(a[2]=0);break}case 32:{a[2]+=4;break}case 33:case 35:case 36:{a[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:a[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{s==126&&(a[2]=0);break}case 48:case 64:case 126:case 127:{s==126&&(a[2]=0);break}}break}case"gs":{e==0&&s<5?a[2]=0:e>125&&s<5&&s!=2&&(a[2]=e,a[0]=0);break}case"g2":case"sd":{(e>>1==40||e>95&&e<100)&&(a[2]|=16);break}case"sg":{e==8&&s==0&&(a[2]=5);break}case"s90es":{s<8?a[2]+=17:s<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}case"motif":{s<8?a[2]+=28:s<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}}let o=" ",c="M",u=0,f=0;switch(a[0]){case 0:{a[2]==127?c="MT-a":a[2]==126?c="MT-b":a[2]==7?c="GM-k":a[2]==5?c="SG-a":a[2]==4?c="SP-l":a[2]==0||i=="gs"&&a[2]<5?c="GM-a":(c="y",u=3);break}case 8:{i=="sg"?c="GM-s":c="r:";break}case 48:{c=`yM${(a[2]>>3).toString().padStart(2,"0")}`,u=1;break}case 56:{c="GM-b";break}case 61:case 120:{c="rDrm";break}case 62:{c="kDrm";break}case 63:{if(a[2]<17){let b=a[2];c=b<10?"kP:":"kC:",c+=b%10}else a[2]<34?c=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][a[2]-17]:c="Ds";break}case 64:{c="ySFX";break}case 67:{c="DX:S";break}case 80:case 81:case 82:case 83:{c=`Prg${"UABC"[a[0]-80]}`;break}case 88:case 89:case 90:case 91:{c=`Cmb${"UABC"[a[0]-88]}`;break}case 95:{c=`${["DR","PC"][a[2]]}-d`;break}case 96:{c=a[2]==106?"AP-a":a[2]>>4==1?"SDg":"PF",a[2]>63?f=63:a[2]>>4==1&&(f=16),u=3;break}case 97:{c=a[2]>>4==1?"SDa":"VL:",u=3,a[2]>>4==1?f=16:f=112;break}case 98:{c=a[2]>>4==1?"SDb":"SG-a",u=3,f=16;break}case 99:{c=a[2]>>4==1?"SDc":"DX",a[2]>63?f=63:a[2]>>4==1&&(f=16),u=3;break}case 100:{c="AN",a[2]>63?f=63:a[2]>>4==1&&(f=16),u=3;break}case 104:case 105:case 106:case 107:{c="SDd",f=104;break}case 121:{c=`GM-${a[2]?"":"a"}`,u=3;break}case 122:{c="lDrm";break}case 126:{c="yDrS";break}case 127:{a[2]==127?c="rDrm":c="yDrm";break}default:a[0]<48?c="r:":c="M"}c.length<4&&(c+=`${[e,s,a[0],a[2]][u]-f}`.padStart(4-c.length,"0")),i=="xg"&&(e==0?a[2]<100?c=c.replace("y0","y:"):a[2]==125&&(c="y126"):e==16&&(n=`Voice${(a[2]*128+a[1]+1).toString().padStart(3,"0")}`,o=" "));let p=[a[0],a[1],a[2]];for(;!(n?.length>=0);)n=this.#t[a[1]||0][(a[0]<<7)+a[2]],n||(this.strictMode?(n="",o="?"):this.#t[a[1]||0][a[0]<<7]?a[0]==0?(a[2]=0,o="^"):a[2]<1?(a[0]=0,o="*"):(a[2]--,o="^"):e==48?(a[0]=0,a[2]=0,o="!"):e==62?(a[1]--,o=" ",a[1]<1&&!n?.length&&(a[0]=0,o="!")):e<63?a[0]==0?(a[2]=0,o="^"):a[2]<1?(a[0]=0,o="*"):a[2]--:e==80?(n=`PrgU:${t.toString().padStart(3,"0")}`,o="!"):e==88?(n=`CmbU:${t.toString().padStart(3,"0")}`,o="!"):e==121?(n=`GM2Vox0${s}`,o="#"):e==122?(a[1]==32?a[1]==0:a[1]%=7,n=this.#t[a[1]||0][(a[0]<<7)+a[2]],n?o=" ":(n="",o="*")):a[1]==0?(n=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${s.toString().padStart(3,"0")}`,o="!"):a[0]==0?(a[2]=0,o="^"):a[2]>0?a[2]--:a[1]>0?(a[1]=0,o="!"):(a[0]=0,o="?"));let g=[a[0],a[1],a[2]];(i=="gs"||i=="ns5r")&&o=="^"&&(o=" "),e==127&&o=="^"&&(o=" "),o!=" "&&self.debugMode&&(n="");let d="??";switch(a[0]){case 0:{a[2]==0?d="GM":a[2]==5||a[2]==7?d="KG":a[2]<126?d="XG":a[2]==127&&(d="MT");break}case 48:{d="MU";break}case 56:{d="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{d="AI";break}case 62:case 82:case 90:{d="XD";break}case 63:{a[2]<17?d="KR":a[2]<34?d="ES":d="DS";break}case 64:case 126:{d="XG";break}case 67:case 99:{d=a[2]>>4==1?"SD":"DX";break}case 81:{d="RW";break}case 95:{d=["DR","PC"][a[2]];break}case 96:{d=a[2]==106?"AP":a[2]>>4==1?"SD":"PF";break}case 97:{d=a[2]>>4==1?"SD":"VL";break}case 98:{d=a[2]>>4==1?"SD":"SG";break}case 100:{d="AN";break}case 104:case 105:case 106:case 107:{d="SD";break}case 120:{d="GS";break}case 121:{d=a[2]?"G2":"GM";break}case 122:{d="KG";break}case 127:{d=a[2]==127?"MT":t==0?"GM":"XG";break}default:a[0]<48&&(a[0]==16&&i=="xg"?d="XG":d="GS")}return{name:n||`${O(e||0)} ${O(t||0)} ${O(s||0)}`,iid:p,eid:g,sid:r,ending:o,sect:c,standard:d}}async load(e,t,s){let i=this,r=[],n=0,a=0;e.split(` +`).forEach(e=>{let t=e.split(",");F[t[0]]=t[1]});var z=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"];var T=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65];var R=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19,14,15,20,21];var q={};z.forEach((e,t)=>{q[e]=t});var Q={length:R.length};R.forEach((e,t)=>{Q[e]=t});var Y={length:T.length};T.forEach((e,t)=>{Y[e]=t});var Le={ch:128,cc:R.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:T.length,dnc:128,efx:7};var W=["MSB","PRG","LSB"],O=function(e){let t=Math.floor(e/10),s=e%10;return`${t.toString(16)}${s}`},x=class{#t;strictMode=!1;get(e=0,t=0,s=0,i){let r=[e,t,s],n,a=Array.from(arguments);switch(i){case"xg":{switch(e){case 0:{s==126?a[2]=125:s==127&&(a[2]=0);break}case 16:{s==126&&(a[2]=0);break}case 32:{s>125&&(a[2]=0),a[2]+=4;break}case 33:case 35:case 36:{s>125&&(a[2]=0),a[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:a[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{s==126&&(a[2]=0);break}case 48:case 64:case 126:case 127:{s==126&&(a[2]=0);break}}break}case"gs":{e==0&&s<5?a[2]=0:e>125&&s<5&&s!=2&&(a[2]=e,a[0]=0);break}case"g2":case"sd":{(e>>1==40||e>95&&e<100)&&(a[2]|=16);break}case"sg":{e==8&&s==0&&(a[2]=5);break}case"s90es":{s<8?a[2]+=17:s<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}case"motif":{s<8?a[2]+=28:s<32?a[2]+=13:a[2]=(a[2]>>3)+19;break}}let o=" ",c="M",u=0,f=0;switch(a[0]){case 0:{a[2]==127?c="MT-a":a[2]==126?c="MT-b":a[2]==7?c="GM-k":a[2]==5?c="SG-a":a[2]==4?c="SP-l":a[2]==0||i=="gs"&&a[2]<5?c="GM-a":(c="y",u=3);break}case 8:{i=="sg"?c="GM-s":c="r:";break}case 48:{c=`yM${(a[2]>>3).toString().padStart(2,"0")}`,u=1;break}case 56:{c="GM-b";break}case 61:case 120:{c="rDrm";break}case 62:{c="kDrm";break}case 63:{if(a[2]<17){let b=a[2];c=b<10?"kP:":"kC:",c+=b%10}else a[2]<34?c=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][a[2]-17]:c="Ds";break}case 64:{c="ySFX";break}case 67:{c="DX:S";break}case 80:case 81:case 82:case 83:{c=`Prg${"UABC"[a[0]-80]}`;break}case 88:case 89:case 90:case 91:{c=`Cmb${"UABC"[a[0]-88]}`;break}case 95:{c=`${["DR","PC"][a[2]]}-d`;break}case 96:{c=a[2]==106?"AP-a":a[2]>>4==1?"SDg":"PF",a[2]>63?f=63:a[2]>>4==1&&(f=16),u=3;break}case 97:{c=a[2]>>4==1?"SDa":"VL:",u=3,a[2]>>4==1?f=16:f=112;break}case 98:{c=a[2]>>4==1?"SDb":"SG-a",u=3,f=16;break}case 99:{c=a[2]>>4==1?"SDc":"DX",a[2]>63?f=63:a[2]>>4==1&&(f=16),u=3;break}case 100:{c="AN",a[2]>63?f=63:a[2]>>4==1&&(f=16),u=3;break}case 104:case 105:case 106:case 107:{c="SDd",f=104;break}case 121:{c=`GM-${a[2]?"":"a"}`,u=3;break}case 122:{c="lDrm";break}case 126:{c="yDrS";break}case 127:{a[2]==127?c="rDrm":c="yDrm";break}default:a[0]<48?c="r:":c="M"}c.length<4&&(c+=`${[e,s,a[0],a[2]][u]-f}`.padStart(4-c.length,"0")),i=="xg"&&(e==0?a[2]<100?c=c.replace("y0","y:"):a[2]==125&&(c="y126"):e==16&&(n=`Voice${(a[2]*128+a[1]+1).toString().padStart(3,"0")}`,o=" "));let p=[a[0],a[1],a[2]];for(;!(n?.length>=0);)n=this.#t[a[1]||0][(a[0]<<7)+a[2]],n||(this.strictMode?(n="",o="?"):this.#t[a[1]||0][a[0]<<7]?a[0]==0?(a[2]=0,o="^"):a[2]<1?(a[0]=0,o="*"):(a[2]--,o="^"):e==48?(a[0]=0,a[2]=0,o="!"):e==62?(a[1]--,o=" ",a[1]<1&&!n?.length&&(a[0]=0,o="!")):e<63?a[0]==0?(a[2]=0,o="^"):a[2]<1?(a[0]=0,o="*"):a[2]--:e==80?(n=`PrgU:${t.toString().padStart(3,"0")}`,o="!"):e==88?(n=`CmbU:${t.toString().padStart(3,"0")}`,o="!"):e==121?(n=`GM2Vox0${s}`,o="#"):e==122?(a[1]==32?a[1]==0:a[1]%=7,n=this.#t[a[1]||0][(a[0]<<7)+a[2]],n?o=" ":(n="",o="*")):a[1]==0?(n=`${e.toString().padStart(3,"0")} ${t.toString().padStart(3,"0")} ${s.toString().padStart(3,"0")}`,o="!"):a[0]==0?(a[2]=0,o="^"):a[2]>0?a[2]--:a[1]>0?(a[1]=0,o="!"):(a[0]=0,o="?"));let g=[a[0],a[1],a[2]];(i=="gs"||i=="ns5r")&&o=="^"&&(o=" "),e==127&&o=="^"&&(o=" "),o!=" "&&self.debugMode&&(n="");let d="??";switch(a[0]){case 0:{a[2]==0?d="GM":a[2]==5||a[2]==7?d="KG":a[2]<126?d="XG":a[2]==127&&(d="MT");break}case 32:case 33:case 35:case 36:{a[2]>4?d=["AP","VL","PF","DX","AN"][a[0]-32]:d="GS";break}case 48:{d="MU";break}case 56:{d="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{d="AI";break}case 62:case 82:case 90:{d="XD";break}case 63:{a[2]<17?d="KR":a[2]<34?d="ES":d="DS";break}case 64:case 126:{d="XG";break}case 67:case 99:{d=a[2]>>4==1?"SD":"DX";break}case 81:{d="RW";break}case 95:{d=["DR","PC"][a[2]];break}case 96:{d=a[2]==106?"AP":a[2]>>4==1?"SD":"PF";break}case 97:{d=a[2]>>4==1?"SD":"VL";break}case 98:{d=a[2]>>4==1?"SD":"SG";break}case 100:{d="AN";break}case 104:case 105:case 106:case 107:{d="SD";break}case 120:{d="GS";break}case 121:{d=a[2]?"G2":"GM";break}case 122:{d="KG";break}case 127:{d=a[2]==127?"MT":t==0?"GM":"XG";break}default:a[0]<48&&(a[0]==16&&i=="xg"?d="XG":d="GS")}return{name:n||`${O(e||0)} ${O(t||0)} ${O(s||0)}`,iid:p,eid:g,sid:r,ending:o,sect:c,standard:d}}async load(e,t,s){let i=this,r=[],n=0,a=0;e.split(` `).forEach(function(o,c){let u=o.split(" "),f=[];c==0?u.forEach(function(p,g){r[W.indexOf(p)]=g}):u.forEach(async function(p,g){g>2?(i.#t[f[r[1]]]=i.#t[f[r[1]]]||[],(!i.#t[f[r[1]]][(f[r[0]]<<7)+f[r[2]]]?.length||t)&&(i.#t[f[r[1]]][(f[r[0]]<<7)+f[r[2]]]=u[3],n++),a++):f.push(parseInt(u[g]))})}),t||console.debug(`Map "${s||"(internal)"}": ${a} total, ${n} loaded.`)}clearRange(e){let t=e.prg!=null?e.prg.constructor==Array?e.prg:[e.prg,e.prg]:[0,127],s=e.msb!=null?e.msb.constructor==Array?e.msb:[e.msb,e.msb]:[0,127],i=e.lsb!=null?e.lsb.constructor==Array?e.lsb:[e.lsb,e.lsb]:[0,127];for(let r=s[0];r<=s[1];r++){let n=r<<7;for(let a=i[0];a<=i[1];a++){let o=n+a;for(let c=t[0];c<=t[1];c++)delete this.#t[c][o]}}}init(){this.#t=[];for(let e=0;e<128;e++)this.#t.push([""])}async loadFiles(...e){this.init();let t=this;e.forEach(async function(s,i){try{await fetch(`./data/bank/${s}.tsv`).then(function(r){return r.text()}).then(r=>{t.load(r,!1,s)})}catch{console.error(`Failed loading "${s}.tsv".`)}})}constructor(...e){this.loadFiles(...e)}};var w=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],G=[[0,0,0,0,121,0,0,56,82,81,63,0,0],[0,0,4,0,0,127,0,0,0,0,0,0,0]],v=[120,127,120,127,120,127,61,62,62,62,120,122,122],J=[0,3,81,84,88],B={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},D={0:0,1:1,2:3,5:4},H=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],I=[36,37];var A=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,12,13,16,17,18,19],Z=[33,99,100,32,102,8,9,10];var E={};w.forEach((e,t)=>{E[e]=t});var h={length:A.length};A.forEach((e,t)=>{h[e]=t});var k=function(){return!!self.Bun||self.debugMode||!1},j=function(e){let t=[],s=0;return e?.forEach(function(i,r){i==247?t.push(e.subarray(s,r)):i==240&&(s=r+1)}),t.length||t.push(e.subarray(0)),k(),t},_=function(e,t="",s="",i=2){return e?`${t}${e.toString().padStart(i,"0")}${s}`:""},l={ch:128,cc:A.length,nn:128,pl:512,tr:256,cmt:14,rpn:6},Fe=class extends M{#t=0;#w=0;#b=0;#g=new Array(11);get#h(){return this.#g[this.#w]}set#h(e){this.#g[this.#w]=e}#y=new Uint8Array(l.ch);#B=new Uint8Array(l.ch);#e=new Uint8ClampedArray(l.ch*l.cc);#$=new Uint8ClampedArray(l.ch);#o=new Uint8ClampedArray(l.ch*l.nn);#D=new Uint8Array(l.ch);#n=new Uint16Array(l.pl);#f=new Uint8Array(l.pl);#C=new Int16Array(l.ch);#d=new Uint8Array(l.ch);#x=0;#l=new Uint8Array(l.ch*l.rpn);#A=new Int8Array(l.ch*I.length);#U=new Uint8Array(l.ch);#V=new Uint8Array(128);#H=new Uint8Array(l.cmt*8);#F=new Uint8Array(1024);#I=new Uint8Array(l.cmt*64);#k=0;#u=0;#M=100;#m=0;#_=500;#z=0;#i="";#p=0;#q=0;#Q=!0;#a=!1;#X;#Y=new Uint8Array(2);#s=[];#E=new Uint8Array(l.ch);#v=new Uint8Array(l.tr);baseBank=new x("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new x("gm");initOnReset=!1;chRedir(e,t,s){if(this.#v[t])return(this.#v[t]-1)*16+e;if([E.gs,E.ns5r].indexOf(this.#t)>-1){if(s==1)return e;let i=0,r=!0;for(;r;)this.#E[e+i]==0?(this.#E[e+i]=t,console.debug(`Assign track ${t} to channel ${e+i+1}.`),r=!1):this.#E[e+i]==t?r=!1:(i+=16,i>=128&&(i=0,r=!1));return e+i}else return e}#c=[];#T;#r={nOff:(e,t)=>{let s=e*128+t,i=this.#n.lastIndexOf(s);i>-1&&(this.#e[l.cc*e+h[64]]>63&&!this.config?.disableCc64?this.#f[i]=4:(this.#n[i]=0,this.#o[s]=0,this.#f[i]=0))},nOn:(e,t,s)=>{let i=e*128+t,r=0;for(this.#D[e]&&this.#r.ano(e);this.#f[r]>0&&this.#n[r]!=i;)r++;r{},cAt:(e,t)=>{},hoOf:e=>{this.#f.forEach((t,s)=>{if(t==4){let i=this.#n[s],r=i>>7;e==r&&(this.#f[s]=0,this.#n[s]=0,this.#o[i]=0)}})},soOf:e=>{},ano:e=>{this.#n.forEach((t,s,i)=>{let r=t>>7,n=t&127;t==0&&this.#o[0]==0||r==e&&this.#r.nOff(r,n)})}};#K={8:function(e){let t=e.channel,s=e.data[0];this.#r.nOff(t,s)},9:function(e){let t=e.channel;this.#y[t]=1;let s=e.data[0],i=e.data[1];i>0?this.#r.nOn(t,s,i):this.#r.nOff(t,s)},10:function(e){let s=e.channel*128+e.data[0];this.#n.indexOf(s)>-1&&(this.#o[s]=data[1])},11:function(e){let t=e.channel;this.#y[t]=1;let s=t*l.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#r.ano(t),this.#C[t]=0;let i=t*l.cc;this.#e[i+h[1]]=0,this.#e[i+h[5]]=0,this.#e[i+h[64]]=0,this.#e[i+h[65]]=0,this.#e[i+h[66]]=0,this.#e[i+h[67]]=0,this.#e[i+h[11]]=127,this.#e[i+h[101]]=127,this.#e[i+h[100]]=127,this.#e[i+h[99]]=127,this.#e[i+h[98]]=127;return}case 123:{this.#r.ano(t);return}case 124:{this.#r.ano(t);return}case 125:{this.#r.ano(t);return}case 126:{this.#D[t]=1,this.#r.ano(t);return}case 127:{this.#D[t]=0,this.#r.ano(t);return}}if(h[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(e.data[0]){case 0:{if(k()&&console.debug(`${w[this.#t]}, CH${t+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#e[s]>119&&(e.data[1]=this.#e[s],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg");else if(this.#t==E.gs)e.data[1]<56&&this.#e[s]>119&&(e.data[1]=this.#e[s],e.data[1]=120,console.debug(`Forced channel ${t+1} to stay drums.`));else if(this.#t==E.gm)e.data[1]<48?this.#e[s]>119&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${t+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0);else if(this.#t==E.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let i=0;for(let r=0;r<16;r++){let n=this.#e[l.cc*r];(n==56||n==62)&&i++}i>14&&this.switchMode("ag10",!0)}}break}case 6:{if(this.#x){let i=this.#e[s+h[99]],r=this.#e[s+h[98]];if(i==1){let n=Z.indexOf(r);if(n>-1)this.#e[s+h[71+n]]=e.data[1],k()&&console.debug(`Redirected NRPN 1 ${r} to cc${71+n}.`);else{let a=I.indexOf(r);a>-1&&(this.#A[t*10+a]=e.data[1]-64),k()&&console.debug(`CH${t+1} voice NRPN ${r} commit`)}}}else{let i=D[this.#e[s+h[100]]];this.#e[s+h[101]]==0&&i!=null&&(k()&&console.debug(`CH${t+1} RPN 0 ${this.#e[s+h[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],H[i][0]),H[i][1]),this.#l[t*l.rpn+i]=e.data[1])}break}case 38:{this.#x||this.#e[s+101]==0&&D[this.#e[s+100]]!=null&&(this.#l[t*l.rpn+D[this.#e[s+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#r.hoOf(t);break}case 66:{console.debug(`Sostenuto pedal: ${e.data[1]}`);break}case 98:case 99:{this.#x=1;break}case 100:case 101:{this.#x=0;break}}this.#e[s+h[e.data[0]]]=e.data[1]}},12:function(e){let t=e.channel;this.#y[t]=1,this.#$[t]=e.data,this.#U[t]=0,k()&&console.debug(`T:${e.track} C:${t} P:${e.data}`)},13:function(e){let t=this,s=e.channel;this.#n.forEach(function(i){let r=i>>7;s==r&&(t.#o[i]=e.data)})},14:function(e){let t=e.channel;this.#C[t]=e.data[1]*128+e.data[0]-8192},15:function(e){j(e.data).forEach(t=>{let s=t[0],i=t[1];(this.#W[s]||function(){console.debug(`Unknown manufacturer ${s}.`)})(i,t.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){if((this.#c[e.meta]||function(s,i,r){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#m=0),J.indexOf(e.meta)>-1)return e.reply="meta",e;k()&&console.debug(e)}};#W={64:(e,t,s)=>{this.#L.run(t,s,e)},65:(e,t,s)=>{if(t[0]<16)this.#S.run(t,s,e),console.warn("Unknown device SysEx!");else{let i=t[t.length-1],r=gsChecksum(t.subarray(2,t.length-1));i==r?this.#S.run(t.subarray(0,t.length-1),s,e):console.warn(`Bad GS checksum ${i}. Should be ${r}.`)}},66:(e,t,s)=>{this.#O.run(t,s,e)},67:(e,t,s)=>{this.#R.run(t,s,e)},68:(e,t,s)=>{this.#J.run(t,s,e)},71:(e,t,s)=>{this.#G.run(t,s,e)},126:(e,t,s)=>{this.#P.run(t,s,e)},127:(e,t,s)=>{this.switchMode("gm"),this.#N.run(t,s,e)}};#P;#N;#R;#S;#O;#L;#G;#J;buildRchTree(){let e=[];this.#B.forEach((t,s)=>{e[t]?.constructor||(e[t]=[]),e[t].push(s)}),this.#X=e}getActive(){let e=this.#y.slice();return this.#t==E.mt32,e}getCc(e){let t=e*l.cc,s=this.#e.slice(t,t+l.cc);return s[h[0]]=s[h[0]]||this.#k,s[h[32]]=s[h[32]]||this.#u,s}getCcAll(){let e=this.#e.slice();for(let t=0;t0&&t.set(a,{v:s.#o[i],s:s.#f[r]})}),t}getBitmap(){return{bitmap:this.#h,expire:this.#b}}getLetter(){return{text:this.#i,expire:this.#p}}getMode(){return w[this.#t]}getMaster(){return{volume:this.#M}}getRawStrength(){let e=this;return this.#n.forEach(function(t){let s=Math.floor(t/128);e.#o[t]>e.#d[s]&&(e.#d[s]=e.#o[t])}),this.#d}getStrength(){let e=[],t=this;return this.getRawStrength().forEach(function(s,i){e[i]=Math.floor(s*t.#e[i*l.cc+h[7]]*t.#e[i*l.cc+h[11]]*t.#M/803288)}),e}getRpn(){return this.#l}getNrpn(){return this.#A}getVoice(e,t,s,i){let r=e||this.#k,n=t,a=s||this.#u;w[this.#t]=="ns5r"&&r>0&&r<56&&(a=3);let o=this.userBank.get(r,n,a,i);if(w[this.#t]=="mt32"&&o.name.indexOf("MT-m:")==0){let c=parseInt(o.name.slice(5)),u=c*l.cmt,f="";this.#I.subarray(u,u+10).forEach(p=>{p>31&&(f+=String.fromCharCode(p))}),this.userBank.load(`MSB LSB PRG 0 127 ${n} ${f}`,!0),o.name=f,o.ending=" "}return(o.ending!=" "||!o.name.length)&&(o=this.baseBank.get(r,n,a,i)),o}getChVoice(e){let t=this.getVoice(this.#e[e*l.cc+h[0]],this.#$[e],this.#e[e*l.cc+h[32]],w[this.#t]);if(this.#U[e])switch(this.#t){case E.mt32:t.ending="~",t.name="",this.#H.subarray(14*(e-1),14*(e-1)+10).forEach(s=>{s>31&&(t.name+=String.fromCharCode(s))})}return t}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#k=0,this.#u=0,this.#m=0,this.#y.fill(0),this.#e.fill(0),this.#$.fill(0),this.#o.fill(0),this.#n.fill(0),this.#d.fill(0),this.#C.fill(0),this.#A.fill(0),this.#M=100,this.#s=[],this.#_=500,this.#z=0,this.#p=0,this.#i="",this.#b=0,this.#w=0,this.#h.fill(0),this.#a=!1,this.#q=0,this.#Q=!0,this.#B.forEach(function(t,s,i){i[s]=s}),this.buildRchTree(),e==0&&(this.#E.fill(0),this.#v.fill(0)),this.#e[l.cc*9]=v[0],this.#e[l.cc*25]=v[0],this.#e[l.cc*41]=v[0],this.#e[l.cc*57]=v[0],this.#Y.fill(0),this.#F.fill(0),this.#I.fill(0),this.#V.fill(0),this.#H.fill(0),this.#U.fill(0),this.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let t=0;t-1){if(this.#t==0||t){this.#t=s,this.#w=0,this.#k=G[0][s],this.#u=G[1][s];for(let i=0;i-1&&(this.#e[i*l.cc]=v[s]);switch(this.initOnReset,s){case E.mt32:{mt32DefProg.forEach((i,r)=>{let n=r+1;this.#y[n]||(this.#$[n]=i,this.#e[n*l.cc+h[91]]=127)});break}}this.dispatchEvent("mode",e)}}else throw new Error(`Unknown mode ${e}`)}newStrength(){this.#d.fill(0)}runJson(e){if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#K[e.type].call(this,e);{let t=this.chRedir(e.part,e.track),s=!1;this.#X[t]?.forEach(i=>{e.channel=i,s=!0,this.#K[e.type].call(this,e)}),s||console.warn(`${B[e.type]?B[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${t+1} without any recipient.`)}this.#s.length>100&&this.#s.splice(100,this.#s.length-99)}runRaw(e){}constructor(){super();let e=this;this.#h=new Uint8Array(256),this.#g[10]=new Uint8Array(512),this.#T=new m,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 diff --git a/dist/xp_basic.mjs b/dist/xp_basic.mjs index 021ed699..d758b401 100644 --- a/dist/xp_basic.mjs +++ b/dist/xp_basic.mjs @@ -1,8 +1,8 @@ -var ha=Object.create;var yt=Object.defineProperty;var ua=Object.getOwnPropertyDescriptor;var pa=Object.getOwnPropertyNames;var ba=Object.getPrototypeOf,ga=Object.prototype.hasOwnProperty;var ya=(b,e,r)=>e in b?yt(b,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):b[e]=r;var Ot=(b,e)=>()=>(b&&(e=b(b=0)),e);var va=(b,e)=>()=>(e||b((e={exports:{}}).exports,e),e.exports);var ma=(b,e,r,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of pa(e))!ga.call(b,c)&&c!==r&&yt(b,c,{get:()=>e[c],enumerable:!(d=ua(e,c))||d.enumerable});return b};var Ea=(b,e,r)=>(r=b!=null?ha(ba(b)):{},ma(e||!b||!b.__esModule?yt(r,"default",{value:b,enumerable:!0}):r,b));var M=(b,e,r)=>(ya(b,typeof e!="symbol"?e+"":e,r),r),Dt=(b,e,r)=>{if(!e.has(b))throw TypeError("Cannot "+r)};var t=(b,e,r)=>(Dt(b,e,"read from private field"),r?r.call(b):e.get(b)),k=(b,e,r)=>{if(e.has(b))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(b):e.set(b,r)},w=(b,e,r,d)=>(Dt(b,e,"write to private field"),d?d.call(b,r):e.set(b,r),r);var At=Ot(()=>{"use strict";D();(function(){var b=function(m,a,n){var l,i;if(self.MessageEvent)switch(m){case"message":{i=new MessageEvent(m,{data:a,ports:n==null?void 0:n.ports}),Object.defineProperty(i,"source",{value:n==null?void 0:n.source});break}default:i=new Event(m)}else i=document.createEvent("Event"),i.initEvent(m,!1,!1),n&&m=="message"&&(i.data=a,n.source&&Object.defineProperty(i,"source",{value:n.source}),(l=n.ports)!=null&&l.length&&Object.defineProperty(i,"ports",{value:n.ports}));return i};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),r=[],d={},c=function(m){var a,n=this;if((this==null?void 0:this.constructor)!=c)throw new TypeError("Illegal constructor");r.push(this),(a=d[m])!=null&&a.constructor||(d[m]=[]),d[m].push(this);var l=Math.floor(Math.random()*281474976710656),i=[],s=0,o=[],f=!0,u=!1;Object.defineProperty(this,"id",{get:function(){return l}}),Object.defineProperty(this,"name",{value:m}),this.close=function(){var $,S=r.indexOf(n);S>-1?(e.postMessage({t:"d",c:m,i:l}),r.splice(S,1),($=d[m])!=null&&$.constructor&&(S=d[m].indexOf(n),S>-1&&d[m].splice(S,1)),d[m].length||delete d[m],console.debug("[Snowy] BroadcastChannel closed."),u=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function($){if(e){if(u)throw new Error("Channel already closed");e.postMessage({t:"m",c:m,i:l,m:s,d:$}),s++,s>4294967295&&(s=0)}else o.push($),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(f){for(e.postMessage({t:"r",c:m,i:l}),console.debug("[Snowy] ".concat(o.length," message(s) in cache."));o.length;){var $=o.shift();n.postMessage($)}f=!1,console.debug("[Snowy] All cached messages are flushed away.")}}else throw new Error("Tried to flush when the ports are not ready")},this.receiveMessage=function($){$.c==m?$.i!=l&&n.dispatchEvent(b("message",$.d,{source:n})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(l," receives from ").concat(m,", not ").concat($.c,"."))};var g={};this.dispatchEvent=function($){var S,C;if(Object.defineProperty($,"target",{value:n}),Object.defineProperty($,"currentTarget",{value:n}),(S=g[$.type])!=null&&S.length)for(var P=g[$.type],X=0;X-1&&g[$].splice(X,1)}!((P=g[$])!=null&&P.length)&&g[$].constructor&&delete g[$]}},self.BroadcastChannel=c,p=function(){if(e){e.addEventListener("message",function(a){var n=a.data,l=!1;switch(n.t){case"k":{l=!1,e.postMessage({t:"k"});break}case"m":{var i=d[n.c];if(i!=null&&i.length)for(var s=0;s{"use strict";At();{let b=function(e,r){let d=new FileReader;return new Promise((c,p)=>{switch(d.addEventListener("abort",()=>{p(new Error("Blob read aborted"))}),d.addEventListener("error",h=>{p(d.error||h.data||new Error("Blob read error"))}),d.addEventListener("load",()=>{c(d.result)}),r.toLowerCase()){case"arraybuffer":case"buffer":{d.readAsArrayBuffer(e);break}case"string":case"text":{d.readAsText(e);break}default:p(new Error(`Unknown target ${r}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return b(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return b(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(b,e){let r=0,d=16,c=this,p=[];for(;r-1;){let h=c.lastIndexOf(b);p.unshift(c.slice(h+b.length)),c=c.slice(0,h),h==0&&p.unshift(""),r++}return c.length&&p.unshift(c),p.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(b,e){if(e){let r=this;for(;r.length{D();(function(){"use strict";let b={fatal:!0},e=[new TextDecoder("iso-8859-15",b),new TextDecoder("sjis",b),new TextDecoder("euc-jp",b),new TextDecoder("utf-8",b),new TextDecoder("utf-16",b),new TextDecoder("ascii")],r={debug:!1,parse:function(d,c){if(d instanceof Uint8Array)return r.Uint8(d);if(typeof d=="string")return r.Base64(d);if(d instanceof HTMLElement&&d.type==="file")return r.addListener(d,c);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(d,c){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(d===void 0||!(d instanceof HTMLElement)||d.tagName!=="INPUT"||d.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;c=c||function(){},d.addEventListener("change",function(p){if(!p.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let h=new FileReader;h.readAsArrayBuffer(p.target.files[0]),h.onload=function(m){c(r.Uint8(new Uint8Array(m.target.result)))}})},Base64:function(d){let c=function(m){var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(m=m.replace(/^.*?base64,/,""),m=String(m).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(m))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");m+="==".slice(2-(3&m.length));let n,l="",i,s,o=0;for(;o>16&255):s===64?String.fromCharCode(n>>16&255,n>>8&255):String.fromCharCode(n>>16&255,n>>8&255,255&n);return l}(d=String(d));var p=c.length;let h=new Uint8Array(new ArrayBuffer(p));for(let m=0;m{s[g]=this.readInt(1)});for(let u=0;u191||$>127&&$<160)throw new RangeError(`Invalid code point: ${$}`)}o=!0,console.debug(`String byte sequence in ${e[u].encoding}`)}catch(g){console.debug(`SMF string ${g}`)}return f||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let i=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)i=this.readInt(1);else{let o=[];for(;128<=this.data.getUint8(this.pointer);)o.push(this.readInt(1)-128);var s=this.readInt(1);for(let f=1;f<=o.length;f++)i+=o[o.length-f]*Math.pow(128,f);i+=s}return i}};if(c.data=new DataView(h.buffer,h.byteOffset,h.byteLength),c.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;c.readInt(4);let p={};p.formatType=c.readInt(2),p.tracks=c.readInt(2),p.track=[];var h=c.readInt(1),m=c.readInt(1);128<=h?(p.timeDivision=[],p.timeDivision[0]=h-128,p.timeDivision[1]=m):p.timeDivision=256*h+m;for(let i=1;i<=p.tracks;i++){p.track[i-1]={event:[]};var a,n=c.readInt(4);if(n===-1)break;if(n!==1297379947)return!1;c.readInt(4);let s=0,o=!1,f,u;for(;!o&&(s++,p.track[i-1].event[s-1]={},p.track[i-1].event[s-1].deltaTime=c.readIntVLV(),(f=c.readInt(1))!==-1);)if(128<=f?u=f:(f=u,c.movePointer(-1)),f===255){p.track[i-1].event[s-1].type=255,p.track[i-1].event[s-1].metaType=c.readInt(1);var l=c.readIntVLV();switch(p.track[i-1].event[s-1].metaType){case 47:case-1:o=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:p.track[i-1].event[s-1].data=c.readStr(l);break;case 33:case 89:case 81:p.track[i-1].event[s-1].data=c.readInt(l);break;case 84:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=c.readInt(1),p.track[i-1].event[s-1].data[1]=c.readInt(1),p.track[i-1].event[s-1].data[2]=c.readInt(1),p.track[i-1].event[s-1].data[3]=c.readInt(1),p.track[i-1].event[s-1].data[4]=c.readInt(1);break;case 88:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=c.readInt(1),p.track[i-1].event[s-1].data[1]=c.readInt(1),p.track[i-1].event[s-1].data[2]=c.readInt(1),p.track[i-1].event[s-1].data[3]=c.readInt(1);break;default:this.customInterpreter!==null&&(p.track[i-1].event[s-1].data=this.customInterpreter(p.track[i-1].event[s-1].metaType,c,l)),this.customInterpreter!==null&&p.track[i-1].event[s-1].data!==!1||(c.readInt(l),p.track[i-1].event[s-1].data=c.readInt(l),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((f=f.toString(16).split(""))[1]||f.unshift("0"),p.track[i-1].event[s-1].type=parseInt(f[0],16),p.track[i-1].event[s-1].channel=parseInt(f[1],16),p.track[i-1].event[s-1].type){case 15:this.customInterpreter!==null&&(p.track[i-1].event[s-1].data=this.customInterpreter(p.track[i-1].event[s-1].type,c,!1)),this.customInterpreter!==null&&p.track[i-1].event[s-1].data!==!1||(a=c.readIntVLV(),p.track[i-1].event[s-1].data=c.readInt(a),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=c.readInt(1),p.track[i-1].event[s-1].data[1]=c.readInt(1);break;case 12:case 13:p.track[i-1].event[s-1].data=c.readInt(1);break;case-1:o=!0;break;default:if(this.customInterpreter!==null&&(p.track[i-1].event[s-1].data=this.customInterpreter(p.track[i-1].event[s-1].metaType,c,!1)),this.customInterpreter===null||p.track[i-1].event[s-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return p},customInterpreter:null};if(typeof Ct<"u")Ct.exports=r;else{let d=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;d.MidiParser=r}})()});D();D();var Q,Pt,ht=(Pt=class{constructor(){k(this,Q,{})}addEventListener(b,e){t(this,Q)[b]||(t(this,Q)[b]=[]),t(this,Q)[b].unshift(e)}removeEventListener(b,e){if(t(this,Q)[b]){let r=t(this,Q)[b].indexOf(e);r>-1&&t(this,Q)[b].splice(r,1),t(this,Q)[b].length<1&&delete t(this,Q)[b]}}dispatchEvent(b,e){var c;let r=new Event(b),d=this;r.data=e,((c=t(this,Q)[b])==null?void 0:c.length)>0&&t(this,Q)[b].forEach(function(p){try{p==null||p.call(d,r)}catch(h){console.error(h)}}),this[`on${b}`]&&this[`on${b}`](r)}},Q=new WeakMap,Pt);D();D();var It=function(b,e){let r=Math.min(b.length,e.length),d=b.slice(0,r),c=e.slice(0,r),p=0,h=0;for(;h0){let d=this.pool.length,c=1<=1&&h>=0;){if(h<=0)throw new Error("TTL reached.");if(p==d)p-=c;else{let a=It(e,this.pool[p]);switch(a){case 0:{h=0;break}case 1:{p+c<=d&&(p+=c);break}case-1:{p!=0&&(p-=c);break}default:console.warn(`Unexpected result ${a}.`)}}c=c>>1,h--}let m=!0;if(p>=this.pool.length)m=!1;else{let a=this;this.pool[p].forEach(function(n,l,i){m&&n!=e[l]&&(m=!1)}),!m&&It(e,this.pool[p])>0&&p++}return m||r?p:-1}else return r?0:-1},this.add=function(e,r){return e.data=r,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match in "${this.name||"(unknown)"}" for "${e}". Default action not defined.`)},this.get=function(e){let r=this.point(e);if(r>-1)return this.pool[r].data;this.default(e)},this.run=function(e,...r){let d=this.point(e);d>-1?e.subarray?this.pool[d].data(e.subarray(this.pool[d].length),...r):this.pool[d].data(e.slice(this.pool[d].length),...r):this.default(e,...r)}};D();var $a=["MSB","PRG","LSB"],vt=function(b){let e=Math.floor(b/10),r=b%10;return`${e.toString(16)}${r}`},W,Ut,mt=(Ut=class{constructor(...b){k(this,W,void 0);M(this,"strictMode",!1);this.loadFiles(...b)}get(b=0,e=0,r=0,d){let c=[b,e,r],p,h=Array.from(arguments);switch(d){case"xg":{switch(b){case 0:{r==126?h[2]=125:r==127&&(h[2]=0);break}case 16:{r==126&&(h[2]=0);break}case 32:{h[2]+=4;break}case 33:case 35:case 36:{h[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:h[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{r==126&&(h[2]=0);break}case 48:case 64:case 126:case 127:{r==126&&(h[2]=0);break}}break}case"gs":{b==0&&r<5?h[2]=0:b>125&&r<5&&r!=2&&(h[2]=b,h[0]=0);break}case"g2":case"sd":{(b>>1==40||b>95&&b<100)&&(h[2]|=16);break}case"sg":{b==8&&r==0&&(h[2]=5);break}case"s90es":{r<8?h[2]+=17:r<32?h[2]+=13:h[2]=(h[2]>>3)+19;break}case"motif":{r<8?h[2]+=28:r<32?h[2]+=13:h[2]=(h[2]>>3)+19;break}}let m=" ",a="M",n=0,l=0;switch(h[0]){case 0:{h[2]==127?a="MT-a":h[2]==126?a="MT-b":h[2]==7?a="GM-k":h[2]==5?a="SG-a":h[2]==4?a="SP-l":h[2]==0||d=="gs"&&h[2]<5?a="GM-a":(a="y",n=3);break}case 8:{d=="sg"?a="GM-s":a="r:";break}case 48:{a=`yM${(h[2]>>3).toString().padStart(2,"0")}`,n=1;break}case 56:{a="GM-b";break}case 61:case 120:{a="rDrm";break}case 62:{a="kDrm";break}case 63:{if(h[2]<17){let f=h[2];a=f<10?"kP:":"kC:",a+=f%10}else h[2]<34?a=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][h[2]-17]:a="Ds";break}case 64:{a="ySFX";break}case 67:{a="DX:S";break}case 80:case 81:case 82:case 83:{a=`Prg${"UABC"[h[0]-80]}`;break}case 88:case 89:case 90:case 91:{a=`Cmb${"UABC"[h[0]-88]}`;break}case 95:{a=`${["DR","PC"][h[2]]}-d`;break}case 96:{a=h[2]==106?"AP-a":h[2]>>4==1?"SDg":"PF",h[2]>63?l=63:h[2]>>4==1&&(l=16),n=3;break}case 97:{a=h[2]>>4==1?"SDa":"VL:",n=3,h[2]>>4==1?l=16:l=112;break}case 98:{a=h[2]>>4==1?"SDb":"SG-a",n=3,l=16;break}case 99:{a=h[2]>>4==1?"SDc":"DX",h[2]>63?l=63:h[2]>>4==1&&(l=16),n=3;break}case 100:{a="AN",h[2]>63?l=63:h[2]>>4==1&&(l=16),n=3;break}case 104:case 105:case 106:case 107:{a="SDd",l=104;break}case 121:{a=`GM-${h[2]?"":"a"}`,n=3;break}case 122:{a="lDrm";break}case 126:{a="yDrS";break}case 127:{h[2]==127?a="rDrm":a="yDrm";break}default:h[0]<48?a="r:":a="M"}a.length<4&&(a+=`${[b,r,h[0],h[2]][n]-l}`.padStart(4-a.length,"0")),d=="xg"&&(b==0?h[2]<100?a=a.replace("y0","y:"):h[2]==125&&(a="y126"):b==16&&(p=`Voice${(h[2]*128+h[1]+1).toString().padStart(3,"0")}`,m=" "));let i=[h[0],h[1],h[2]];for(;!((p==null?void 0:p.length)>=0);)p=t(this,W)[h[1]||0][(h[0]<<7)+h[2]],p||(this.strictMode?(p="",m="?"):t(this,W)[h[1]||0][h[0]<<7]?h[0]==0?(h[2]=0,m="^"):h[2]<1?(h[0]=0,m="*"):(h[2]--,m="^"):b==48?(h[0]=0,h[2]=0,m="!"):b==62?(h[1]--,m=" ",h[1]<1&&!(p!=null&&p.length)&&(h[0]=0,m="!")):b<63?h[0]==0?(h[2]=0,m="^"):h[2]<1?(h[0]=0,m="*"):h[2]--:b==80?(p=`PrgU:${e.toString().padStart(3,"0")}`,m="!"):b==88?(p=`CmbU:${e.toString().padStart(3,"0")}`,m="!"):b==121?(p=`GM2Vox0${r}`,m="#"):b==122?(h[1]==32?h[1]==0:h[1]%=7,p=t(this,W)[h[1]||0][(h[0]<<7)+h[2]],p?m=" ":(p="",m="*")):h[1]==0?(p=`${b.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${r.toString().padStart(3,"0")}`,m="!"):h[0]==0?(h[2]=0,m="^"):h[2]>0?h[2]--:h[1]>0?(h[1]=0,m="!"):(h[0]=0,m="?"));let s=[h[0],h[1],h[2]];(d=="gs"||d=="ns5r")&&m=="^"&&(m=" "),b==127&&m=="^"&&(m=" "),m!=" "&&self.debugMode&&(p="");let o="??";switch(h[0]){case 0:{h[2]==0?o="GM":h[2]==5||h[2]==7?o="KG":h[2]<126?o="XG":h[2]==127&&(o="MT");break}case 48:{o="MU";break}case 56:{o="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{o="AI";break}case 62:case 82:case 90:{o="XD";break}case 63:{h[2]<17?o="KR":h[2]<34?o="ES":o="DS";break}case 64:case 126:{o="XG";break}case 67:case 99:{o=h[2]>>4==1?"SD":"DX";break}case 81:{o="RW";break}case 95:{o=["DR","PC"][h[2]];break}case 96:{o=h[2]==106?"AP":h[2]>>4==1?"SD":"PF";break}case 97:{o=h[2]>>4==1?"SD":"VL";break}case 98:{o=h[2]>>4==1?"SD":"SG";break}case 100:{o="AN";break}case 104:case 105:case 106:case 107:{o="SD";break}case 120:{o="GS";break}case 121:{o=h[2]?"G2":"GM";break}case 122:{o="KG";break}case 127:{o=h[2]==127?"MT":e==0?"GM":"XG";break}default:h[0]<48&&(h[0]==16&&d=="xg"?o="XG":o="GS")}return{name:p||`${vt(b||0)} ${vt(e||0)} ${vt(r||0)}`,iid:i,eid:s,sid:c,ending:m,sect:a,standard:o}}async load(b,e,r){let d=this,c=[],p=0,h=0;b.split(` -`).forEach(function(m,a){let n=m.split(" "),l=[];a==0?n.forEach(function(i,s){c[$a.indexOf(i)]=s}):n.forEach(async function(i,s){var o;s>2?(t(d,W)[l[c[1]]]=t(d,W)[l[c[1]]]||[],(!((o=t(d,W)[l[c[1]]][(l[c[0]]<<7)+l[c[2]]])!=null&&o.length)||e)&&(t(d,W)[l[c[1]]][(l[c[0]]<<7)+l[c[2]]]=n[3],p++),h++):l.push(parseInt(n[s]))})}),e||console.debug(`Map "${r||"(internal)"}": ${h} total, ${p} loaded.`)}clearRange(b){let e=b.prg!=null?b.prg.constructor==Array?b.prg:[b.prg,b.prg]:[0,127],r=b.msb!=null?b.msb.constructor==Array?b.msb:[b.msb,b.msb]:[0,127],d=b.lsb!=null?b.lsb.constructor==Array?b.lsb:[b.lsb,b.lsb]:[0,127];for(let c=r[0];c<=r[1];c++){let p=c<<7;for(let h=d[0];h<=d[1];h++){let m=p+h;for(let a=e[0];a<=e[1];a++)delete t(this,W)[a][m]}}}init(){w(this,W,[]);for(let b=0;b<128;b++)t(this,W).push([""])}async loadFiles(...b){this.init();let e=this;b.forEach(async function(r,d){try{await fetch(`./data/bank/${r}.tsv`).then(function(c){return c.text()}).then(c=>{e.load(c,!1,r)})}catch(c){console.error(`Failed loading "${r}.tsv".`)}})}},W=new WeakMap,Ut);D();D();var qe,Lt,Bt=(Lt=class{constructor(){k(this,qe,{});M(this,"context")}set(b,e){t(this,qe)[b]=e}has(b){return!!t(this,qe)[b]}async read(b,e){if(!this.has(b))throw new Error(`No decoder registered for "${b}"`);return await t(this,qe)[b].call(this.context||this,e)}},qe=new WeakMap,Lt);var wa=function(b,e){let r=!0;return e.forEach((d,c)=>{r=r&&b[c]==d}),r},Nt=function(b){let e=0;return b.forEach(r=>{e*=256,e+=r}),e},at=new TextDecoder,ut=new Bt;ut.set("s7e",async function(b){let e=new Uint8Array(await b.slice(0,65536).arrayBuffer()),r="MSB LSB PRG NME",d=[0,0,0,0],c=32,p=0,h=0,m=!0,a=[],n=0;for(;m;){let l=e.subarray(p);([()=>{at.decode(l.subarray(0,4))=="YSFC"?(p+=80,h=1):p++},()=>{if(wa(l.subarray(0,4),d))a.forEach((i,s,o)=>{let f=Nt(e.subarray(i.start+4,i.start+8));i.length=f}),h=2;else{let i=at.decode(l.subarray(0,4)),s=Nt(l.subarray(4,8));a.push({type:i,start:s}),p+=8}},()=>{let i=a[n],s=e.subarray(i.start,i.start+i.length),o=32;switch(i.type){case"ENVC":{let f=c;for(;f=a.length&&(h=3,m=!1)}][h]||(()=>{m=!1}))()}return r});D();var rt=["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"]),st=["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"],ka=[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],je=[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],Ht=[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],Gt=function(b){let e=.1,r=-.3;return b>66?(e=5,r=315):b>56?(e=1,r=47):b>46&&(e=.5,r=18.5),e*b-r},_t=function(b){return b>105?ka[b-106]:b>100?b*1.1-100:b/10},Xt=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),Et={};`hi*, +var ha=Object.create;var yt=Object.defineProperty;var ua=Object.getOwnPropertyDescriptor;var pa=Object.getOwnPropertyNames;var ba=Object.getPrototypeOf,ga=Object.prototype.hasOwnProperty;var ya=(b,e,r)=>e in b?yt(b,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):b[e]=r;var Ot=(b,e)=>()=>(b&&(e=b(b=0)),e);var va=(b,e)=>()=>(e||b((e={exports:{}}).exports,e),e.exports);var ma=(b,e,r,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of pa(e))!ga.call(b,c)&&c!==r&&yt(b,c,{get:()=>e[c],enumerable:!(d=ua(e,c))||d.enumerable});return b};var Ea=(b,e,r)=>(r=b!=null?ha(ba(b)):{},ma(e||!b||!b.__esModule?yt(r,"default",{value:b,enumerable:!0}):r,b));var M=(b,e,r)=>(ya(b,typeof e!="symbol"?e+"":e,r),r),Dt=(b,e,r)=>{if(!e.has(b))throw TypeError("Cannot "+r)};var t=(b,e,r)=>(Dt(b,e,"read from private field"),r?r.call(b):e.get(b)),k=(b,e,r)=>{if(e.has(b))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(b):e.set(b,r)},w=(b,e,r,d)=>(Dt(b,e,"write to private field"),d?d.call(b,r):e.set(b,r),r);var At=Ot(()=>{"use strict";D();(function(){var b=function(m,a,n){var l,i;if(self.MessageEvent)switch(m){case"message":{i=new MessageEvent(m,{data:a,ports:n==null?void 0:n.ports}),Object.defineProperty(i,"source",{value:n==null?void 0:n.source});break}default:i=new Event(m)}else i=document.createEvent("Event"),i.initEvent(m,!1,!1),n&&m=="message"&&(i.data=a,n.source&&Object.defineProperty(i,"source",{value:n.source}),(l=n.ports)!=null&&l.length&&Object.defineProperty(i,"ports",{value:n.ports}));return i};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),r=[],d={},c=function(m){var a,n=this;if((this==null?void 0:this.constructor)!=c)throw new TypeError("Illegal constructor");r.push(this),(a=d[m])!=null&&a.constructor||(d[m]=[]),d[m].push(this);var l=Math.floor(Math.random()*281474976710656),i=[],s=0,o=[],h=!0,u=!1;Object.defineProperty(this,"id",{get:function(){return l}}),Object.defineProperty(this,"name",{value:m}),this.close=function(){var $,S=r.indexOf(n);S>-1?(e.postMessage({t:"d",c:m,i:l}),r.splice(S,1),($=d[m])!=null&&$.constructor&&(S=d[m].indexOf(n),S>-1&&d[m].splice(S,1)),d[m].length||delete d[m],console.debug("[Snowy] BroadcastChannel closed."),u=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function($){if(e){if(u)throw new Error("Channel already closed");e.postMessage({t:"m",c:m,i:l,m:s,d:$}),s++,s>4294967295&&(s=0)}else o.push($),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(h){for(e.postMessage({t:"r",c:m,i:l}),console.debug("[Snowy] ".concat(o.length," message(s) in cache."));o.length;){var $=o.shift();n.postMessage($)}h=!1,console.debug("[Snowy] All cached messages are flushed away.")}}else throw new Error("Tried to flush when the ports are not ready")},this.receiveMessage=function($){$.c==m?$.i!=l&&n.dispatchEvent(b("message",$.d,{source:n})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(l," receives from ").concat(m,", not ").concat($.c,"."))};var g={};this.dispatchEvent=function($){var S,C;if(Object.defineProperty($,"target",{value:n}),Object.defineProperty($,"currentTarget",{value:n}),(S=g[$.type])!=null&&S.length)for(var P=g[$.type],X=0;X-1&&g[$].splice(X,1)}!((P=g[$])!=null&&P.length)&&g[$].constructor&&delete g[$]}},self.BroadcastChannel=c,p=function(){if(e){e.addEventListener("message",function(a){var n=a.data,l=!1;switch(n.t){case"k":{l=!1,e.postMessage({t:"k"});break}case"m":{var i=d[n.c];if(i!=null&&i.length)for(var s=0;s{"use strict";At();{let b=function(e,r){let d=new FileReader;return new Promise((c,p)=>{switch(d.addEventListener("abort",()=>{p(new Error("Blob read aborted"))}),d.addEventListener("error",f=>{p(d.error||f.data||new Error("Blob read error"))}),d.addEventListener("load",()=>{c(d.result)}),r.toLowerCase()){case"arraybuffer":case"buffer":{d.readAsArrayBuffer(e);break}case"string":case"text":{d.readAsText(e);break}default:p(new Error(`Unknown target ${r}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return b(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return b(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(b,e){let r=0,d=16,c=this,p=[];for(;r-1;){let f=c.lastIndexOf(b);p.unshift(c.slice(f+b.length)),c=c.slice(0,f),f==0&&p.unshift(""),r++}return c.length&&p.unshift(c),p.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(b,e){if(e){let r=this;for(;r.length{D();(function(){"use strict";let b={fatal:!0},e=[new TextDecoder("iso-8859-15",b),new TextDecoder("sjis",b),new TextDecoder("euc-jp",b),new TextDecoder("utf-8",b),new TextDecoder("utf-16",b),new TextDecoder("ascii")],r={debug:!1,parse:function(d,c){if(d instanceof Uint8Array)return r.Uint8(d);if(typeof d=="string")return r.Base64(d);if(d instanceof HTMLElement&&d.type==="file")return r.addListener(d,c);throw new Error("MidiParser.parse() : Invalid input provided")},addListener:function(d,c){if(!File||!FileReader)throw new Error("The File|FileReader APIs are not supported in this browser. Use instead MidiParser.Base64() or MidiParser.Uint8()");if(d===void 0||!(d instanceof HTMLElement)||d.tagName!=="INPUT"||d.type.toLowerCase()!=="file")return console.warn("MidiParser.addListener() : Provided element is not a valid FILE INPUT element"),!1;c=c||function(){},d.addEventListener("change",function(p){if(!p.target.files.length)return!1;console.log("MidiParser.addListener() : File detected in INPUT ELEMENT processing data..");let f=new FileReader;f.readAsArrayBuffer(p.target.files[0]),f.onload=function(m){c(r.Uint8(new Uint8Array(m.target.result)))}})},Base64:function(d){let c=function(m){var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";if(m=m.replace(/^.*?base64,/,""),m=String(m).replace(/[\t\n\f\r ]+/g,""),!/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/.test(m))throw new TypeError("Failed to execute _atob() : The string to be decoded is not correctly encoded.");m+="==".slice(2-(3&m.length));let n,l="",i,s,o=0;for(;o>16&255):s===64?String.fromCharCode(n>>16&255,n>>8&255):String.fromCharCode(n>>16&255,n>>8&255,255&n);return l}(d=String(d));var p=c.length;let f=new Uint8Array(new ArrayBuffer(p));for(let m=0;m{s[g]=this.readInt(1)});for(let u=0;u191||$>127&&$<160)throw new RangeError(`Invalid code point: ${$}`)}o=!0,console.debug(`String byte sequence in ${e[u].encoding}`)}catch(g){console.debug(`SMF string ${g}`)}return h||"String byte sequence read failed."},backOne:function(){this.pointer--},readIntVLV:function(){let i=0;if(this.pointer>=this.data.byteLength)return-1;if(this.data.getUint8(this.pointer)<128)i=this.readInt(1);else{let o=[];for(;128<=this.data.getUint8(this.pointer);)o.push(this.readInt(1)-128);var s=this.readInt(1);for(let h=1;h<=o.length;h++)i+=o[o.length-h]*Math.pow(128,h);i+=s}return i}};if(c.data=new DataView(f.buffer,f.byteOffset,f.byteLength),c.readInt(4)!==1297377380)return console.warn("Header validation failed (not MIDI standard or file corrupt.)"),!1;c.readInt(4);let p={};p.formatType=c.readInt(2),p.tracks=c.readInt(2),p.track=[];var f=c.readInt(1),m=c.readInt(1);128<=f?(p.timeDivision=[],p.timeDivision[0]=f-128,p.timeDivision[1]=m):p.timeDivision=256*f+m;for(let i=1;i<=p.tracks;i++){p.track[i-1]={event:[]};var a,n=c.readInt(4);if(n===-1)break;if(n!==1297379947)return!1;c.readInt(4);let s=0,o=!1,h,u;for(;!o&&(s++,p.track[i-1].event[s-1]={},p.track[i-1].event[s-1].deltaTime=c.readIntVLV(),(h=c.readInt(1))!==-1);)if(128<=h?u=h:(h=u,c.movePointer(-1)),h===255){p.track[i-1].event[s-1].type=255,p.track[i-1].event[s-1].metaType=c.readInt(1);var l=c.readIntVLV();switch(p.track[i-1].event[s-1].metaType){case 47:case-1:o=!0;break;case 1:case 2:case 3:case 4:case 5:case 7:case 6:p.track[i-1].event[s-1].data=c.readStr(l);break;case 33:case 89:case 81:p.track[i-1].event[s-1].data=c.readInt(l);break;case 84:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=c.readInt(1),p.track[i-1].event[s-1].data[1]=c.readInt(1),p.track[i-1].event[s-1].data[2]=c.readInt(1),p.track[i-1].event[s-1].data[3]=c.readInt(1),p.track[i-1].event[s-1].data[4]=c.readInt(1);break;case 88:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=c.readInt(1),p.track[i-1].event[s-1].data[1]=c.readInt(1),p.track[i-1].event[s-1].data[2]=c.readInt(1),p.track[i-1].event[s-1].data[3]=c.readInt(1);break;default:this.customInterpreter!==null&&(p.track[i-1].event[s-1].data=this.customInterpreter(p.track[i-1].event[s-1].metaType,c,l)),this.customInterpreter!==null&&p.track[i-1].event[s-1].data!==!1||(c.readInt(l),p.track[i-1].event[s-1].data=c.readInt(l),this.debug&&console.info("Unimplemented 0xFF meta event! data block readed as Integer"))}}else switch((h=h.toString(16).split(""))[1]||h.unshift("0"),p.track[i-1].event[s-1].type=parseInt(h[0],16),p.track[i-1].event[s-1].channel=parseInt(h[1],16),p.track[i-1].event[s-1].type){case 15:this.customInterpreter!==null&&(p.track[i-1].event[s-1].data=this.customInterpreter(p.track[i-1].event[s-1].type,c,!1)),this.customInterpreter!==null&&p.track[i-1].event[s-1].data!==!1||(a=c.readIntVLV(),p.track[i-1].event[s-1].data=c.readInt(a),this.debug&&console.info("Unimplemented 0xF exclusive events! data block readed as Integer"));break;case 10:case 11:case 14:case 8:case 9:p.track[i-1].event[s-1].data=[],p.track[i-1].event[s-1].data[0]=c.readInt(1),p.track[i-1].event[s-1].data[1]=c.readInt(1);break;case 12:case 13:p.track[i-1].event[s-1].data=c.readInt(1);break;case-1:o=!0;break;default:if(this.customInterpreter!==null&&(p.track[i-1].event[s-1].data=this.customInterpreter(p.track[i-1].event[s-1].metaType,c,!1)),this.customInterpreter===null||p.track[i-1].event[s-1].data===!1)return console.log("Unknown EVENT detected... reading cancelled!"),!1}}return p},customInterpreter:null};if(typeof Ct<"u")Ct.exports=r;else{let d=typeof window=="object"&&window.self===window&&window||typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global;d.MidiParser=r}})()});D();D();var Q,Pt,ht=(Pt=class{constructor(){k(this,Q,{})}addEventListener(b,e){t(this,Q)[b]||(t(this,Q)[b]=[]),t(this,Q)[b].unshift(e)}removeEventListener(b,e){if(t(this,Q)[b]){let r=t(this,Q)[b].indexOf(e);r>-1&&t(this,Q)[b].splice(r,1),t(this,Q)[b].length<1&&delete t(this,Q)[b]}}dispatchEvent(b,e){var c;let r=new Event(b),d=this;r.data=e,((c=t(this,Q)[b])==null?void 0:c.length)>0&&t(this,Q)[b].forEach(function(p){try{p==null||p.call(d,r)}catch(f){console.error(f)}}),this[`on${b}`]&&this[`on${b}`](r)}},Q=new WeakMap,Pt);D();D();var It=function(b,e){let r=Math.min(b.length,e.length),d=b.slice(0,r),c=e.slice(0,r),p=0,f=0;for(;f0){let d=this.pool.length,c=1<=1&&f>=0;){if(f<=0)throw new Error("TTL reached.");if(p==d)p-=c;else{let a=It(e,this.pool[p]);switch(a){case 0:{f=0;break}case 1:{p+c<=d&&(p+=c);break}case-1:{p!=0&&(p-=c);break}default:console.warn(`Unexpected result ${a}.`)}}c=c>>1,f--}let m=!0;if(p>=this.pool.length)m=!1;else{let a=this;this.pool[p].forEach(function(n,l,i){m&&n!=e[l]&&(m=!1)}),!m&&It(e,this.pool[p])>0&&p++}return m||r?p:-1}else return r?0:-1},this.add=function(e,r){return e.data=r,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match in "${this.name||"(unknown)"}" for "${e}". Default action not defined.`)},this.get=function(e){let r=this.point(e);if(r>-1)return this.pool[r].data;this.default(e)},this.run=function(e,...r){let d=this.point(e);d>-1?e.subarray?this.pool[d].data(e.subarray(this.pool[d].length),...r):this.pool[d].data(e.slice(this.pool[d].length),...r):this.default(e,...r)}};D();var $a=["MSB","PRG","LSB"],vt=function(b){let e=Math.floor(b/10),r=b%10;return`${e.toString(16)}${r}`},W,Ut,mt=(Ut=class{constructor(...b){k(this,W,void 0);M(this,"strictMode",!1);this.loadFiles(...b)}get(b=0,e=0,r=0,d){let c=[b,e,r],p,f=Array.from(arguments);switch(d){case"xg":{switch(b){case 0:{r==126?f[2]=125:r==127&&(f[2]=0);break}case 16:{r==126&&(f[2]=0);break}case 32:{r>125&&(f[2]=0),f[2]+=4;break}case 33:case 35:case 36:{r>125&&(f[2]=0),f[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:f[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{r==126&&(f[2]=0);break}case 48:case 64:case 126:case 127:{r==126&&(f[2]=0);break}}break}case"gs":{b==0&&r<5?f[2]=0:b>125&&r<5&&r!=2&&(f[2]=b,f[0]=0);break}case"g2":case"sd":{(b>>1==40||b>95&&b<100)&&(f[2]|=16);break}case"sg":{b==8&&r==0&&(f[2]=5);break}case"s90es":{r<8?f[2]+=17:r<32?f[2]+=13:f[2]=(f[2]>>3)+19;break}case"motif":{r<8?f[2]+=28:r<32?f[2]+=13:f[2]=(f[2]>>3)+19;break}}let m=" ",a="M",n=0,l=0;switch(f[0]){case 0:{f[2]==127?a="MT-a":f[2]==126?a="MT-b":f[2]==7?a="GM-k":f[2]==5?a="SG-a":f[2]==4?a="SP-l":f[2]==0||d=="gs"&&f[2]<5?a="GM-a":(a="y",n=3);break}case 8:{d=="sg"?a="GM-s":a="r:";break}case 48:{a=`yM${(f[2]>>3).toString().padStart(2,"0")}`,n=1;break}case 56:{a="GM-b";break}case 61:case 120:{a="rDrm";break}case 62:{a="kDrm";break}case 63:{if(f[2]<17){let h=f[2];a=h<10?"kP:":"kC:",a+=h%10}else f[2]<34?a=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][f[2]-17]:a="Ds";break}case 64:{a="ySFX";break}case 67:{a="DX:S";break}case 80:case 81:case 82:case 83:{a=`Prg${"UABC"[f[0]-80]}`;break}case 88:case 89:case 90:case 91:{a=`Cmb${"UABC"[f[0]-88]}`;break}case 95:{a=`${["DR","PC"][f[2]]}-d`;break}case 96:{a=f[2]==106?"AP-a":f[2]>>4==1?"SDg":"PF",f[2]>63?l=63:f[2]>>4==1&&(l=16),n=3;break}case 97:{a=f[2]>>4==1?"SDa":"VL:",n=3,f[2]>>4==1?l=16:l=112;break}case 98:{a=f[2]>>4==1?"SDb":"SG-a",n=3,l=16;break}case 99:{a=f[2]>>4==1?"SDc":"DX",f[2]>63?l=63:f[2]>>4==1&&(l=16),n=3;break}case 100:{a="AN",f[2]>63?l=63:f[2]>>4==1&&(l=16),n=3;break}case 104:case 105:case 106:case 107:{a="SDd",l=104;break}case 121:{a=`GM-${f[2]?"":"a"}`,n=3;break}case 122:{a="lDrm";break}case 126:{a="yDrS";break}case 127:{f[2]==127?a="rDrm":a="yDrm";break}default:f[0]<48?a="r:":a="M"}a.length<4&&(a+=`${[b,r,f[0],f[2]][n]-l}`.padStart(4-a.length,"0")),d=="xg"&&(b==0?f[2]<100?a=a.replace("y0","y:"):f[2]==125&&(a="y126"):b==16&&(p=`Voice${(f[2]*128+f[1]+1).toString().padStart(3,"0")}`,m=" "));let i=[f[0],f[1],f[2]];for(;!((p==null?void 0:p.length)>=0);)p=t(this,W)[f[1]||0][(f[0]<<7)+f[2]],p||(this.strictMode?(p="",m="?"):t(this,W)[f[1]||0][f[0]<<7]?f[0]==0?(f[2]=0,m="^"):f[2]<1?(f[0]=0,m="*"):(f[2]--,m="^"):b==48?(f[0]=0,f[2]=0,m="!"):b==62?(f[1]--,m=" ",f[1]<1&&!(p!=null&&p.length)&&(f[0]=0,m="!")):b<63?f[0]==0?(f[2]=0,m="^"):f[2]<1?(f[0]=0,m="*"):f[2]--:b==80?(p=`PrgU:${e.toString().padStart(3,"0")}`,m="!"):b==88?(p=`CmbU:${e.toString().padStart(3,"0")}`,m="!"):b==121?(p=`GM2Vox0${r}`,m="#"):b==122?(f[1]==32?f[1]==0:f[1]%=7,p=t(this,W)[f[1]||0][(f[0]<<7)+f[2]],p?m=" ":(p="",m="*")):f[1]==0?(p=`${b.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${r.toString().padStart(3,"0")}`,m="!"):f[0]==0?(f[2]=0,m="^"):f[2]>0?f[2]--:f[1]>0?(f[1]=0,m="!"):(f[0]=0,m="?"));let s=[f[0],f[1],f[2]];(d=="gs"||d=="ns5r")&&m=="^"&&(m=" "),b==127&&m=="^"&&(m=" "),m!=" "&&self.debugMode&&(p="");let o="??";switch(f[0]){case 0:{f[2]==0?o="GM":f[2]==5||f[2]==7?o="KG":f[2]<126?o="XG":f[2]==127&&(o="MT");break}case 32:case 33:case 35:case 36:{f[2]>4?o=["AP","VL","PF","DX","AN"][f[0]-32]:o="GS";break}case 48:{o="MU";break}case 56:{o="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{o="AI";break}case 62:case 82:case 90:{o="XD";break}case 63:{f[2]<17?o="KR":f[2]<34?o="ES":o="DS";break}case 64:case 126:{o="XG";break}case 67:case 99:{o=f[2]>>4==1?"SD":"DX";break}case 81:{o="RW";break}case 95:{o=["DR","PC"][f[2]];break}case 96:{o=f[2]==106?"AP":f[2]>>4==1?"SD":"PF";break}case 97:{o=f[2]>>4==1?"SD":"VL";break}case 98:{o=f[2]>>4==1?"SD":"SG";break}case 100:{o="AN";break}case 104:case 105:case 106:case 107:{o="SD";break}case 120:{o="GS";break}case 121:{o=f[2]?"G2":"GM";break}case 122:{o="KG";break}case 127:{o=f[2]==127?"MT":e==0?"GM":"XG";break}default:f[0]<48&&(f[0]==16&&d=="xg"?o="XG":o="GS")}return{name:p||`${vt(b||0)} ${vt(e||0)} ${vt(r||0)}`,iid:i,eid:s,sid:c,ending:m,sect:a,standard:o}}async load(b,e,r){let d=this,c=[],p=0,f=0;b.split(` +`).forEach(function(m,a){let n=m.split(" "),l=[];a==0?n.forEach(function(i,s){c[$a.indexOf(i)]=s}):n.forEach(async function(i,s){var o;s>2?(t(d,W)[l[c[1]]]=t(d,W)[l[c[1]]]||[],(!((o=t(d,W)[l[c[1]]][(l[c[0]]<<7)+l[c[2]]])!=null&&o.length)||e)&&(t(d,W)[l[c[1]]][(l[c[0]]<<7)+l[c[2]]]=n[3],p++),f++):l.push(parseInt(n[s]))})}),e||console.debug(`Map "${r||"(internal)"}": ${f} total, ${p} loaded.`)}clearRange(b){let e=b.prg!=null?b.prg.constructor==Array?b.prg:[b.prg,b.prg]:[0,127],r=b.msb!=null?b.msb.constructor==Array?b.msb:[b.msb,b.msb]:[0,127],d=b.lsb!=null?b.lsb.constructor==Array?b.lsb:[b.lsb,b.lsb]:[0,127];for(let c=r[0];c<=r[1];c++){let p=c<<7;for(let f=d[0];f<=d[1];f++){let m=p+f;for(let a=e[0];a<=e[1];a++)delete t(this,W)[a][m]}}}init(){w(this,W,[]);for(let b=0;b<128;b++)t(this,W).push([""])}async loadFiles(...b){this.init();let e=this;b.forEach(async function(r,d){try{await fetch(`./data/bank/${r}.tsv`).then(function(c){return c.text()}).then(c=>{e.load(c,!1,r)})}catch(c){console.error(`Failed loading "${r}.tsv".`)}})}},W=new WeakMap,Ut);D();D();var qe,Lt,Bt=(Lt=class{constructor(){k(this,qe,{});M(this,"context")}set(b,e){t(this,qe)[b]=e}has(b){return!!t(this,qe)[b]}async read(b,e){if(!this.has(b))throw new Error(`No decoder registered for "${b}"`);return await t(this,qe)[b].call(this.context||this,e)}},qe=new WeakMap,Lt);var wa=function(b,e){let r=!0;return e.forEach((d,c)=>{r=r&&b[c]==d}),r},Nt=function(b){let e=0;return b.forEach(r=>{e*=256,e+=r}),e},at=new TextDecoder,ut=new Bt;ut.set("s7e",async function(b){let e=new Uint8Array(await b.slice(0,65536).arrayBuffer()),r="MSB LSB PRG NME",d=[0,0,0,0],c=32,p=0,f=0,m=!0,a=[],n=0;for(;m;){let l=e.subarray(p);([()=>{at.decode(l.subarray(0,4))=="YSFC"?(p+=80,f=1):p++},()=>{if(wa(l.subarray(0,4),d))a.forEach((i,s,o)=>{let h=Nt(e.subarray(i.start+4,i.start+8));i.length=h}),f=2;else{let i=at.decode(l.subarray(0,4)),s=Nt(l.subarray(4,8));a.push({type:i,start:s}),p+=8}},()=>{let i=a[n],s=e.subarray(i.start,i.start+i.length),o=32;switch(i.type){case"ENVC":{let h=c;for(;h=a.length&&(f=3,m=!1)}][f]||(()=>{m=!1}))()}return r});D();var rt=["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"]),st=["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"],ka=[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],je=[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],Ht=[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],Gt=function(b){let e=.1,r=-.3;return b>66?(e=5,r=315):b>56?(e=1,r=47):b>46&&(e=.5,r=18.5),e*b-r},_t=function(b){return b>105?ka[b-106]:b>100?b*1.1-100:b/10},Xt=",a,i,u,e,o,ka,ki,ku,ke,ko,ky,kw,sa,si,su,se,so,sh,ta,ti,tu,te,to,t,ch,t,s,na,ni,nu,ne,no,ny,nn,ha,hi,hu,he,ho,hy,fa,fi,fu,fe,fo,ma,mi,mu,me,mo,my,mm,ya,yu,ye,yo,ra,ri,ru,re,ro,ry,wa,wi,we,wo,ga,gi,gu,ge,go,gy,gw,za,zi,zu,ze,zo,ja,ji,ju,je,jo,jy,da,di,du,de,do,dy,ba,bi,bu,be,bo,by,va,vi,vu,ve,vo,pa,pi,pu,pe,po,py,nga,ngi,ngu,nge,ngo,ngy,ng,hha,hhi,hhu,hhe,hho,hhy,hhw,*,_,,,~,.".split(","),Et={};`hi*, ka,か ki,き ku,く @@ -139,7 +139,7 @@ o,お ~, ^, _,`.split(` -`).forEach(b=>{let e=b.split(",");Et[e[0]]=e[1]});var Ft=function(b){let e=b;b[0]=="*"&&(e=e.slice(1)),["aa","ii","uu","ee","oo"].forEach(d=>{for(;e.indexOf(d)>-1;)e=e.replace(d,d[0])});for(let d in Et)e=e.replaceAll(d,Et[d]);e.indexOf("ん")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},Vt=function(b){return b?b<96?`cc${b}`:["aftertouch","velocity","pitch bend"][b-96]:"off"};D();var $t=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],Kt=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],zt=["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 Sa={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"},xa={66307:["drive"],66309:["vowel",b=>"aiueo"[b]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",b=>["off","LPF","HPF"][b]],94984:["noise type",b=>["white","pink"][b]],94987:["disc type",b=>["LP","SP","EP","RND"]],94990:["hum type",b=>`${b+5}0Hz`],94993:["M/S",b=>["mono","stereo"][b]]},wt=function(b){return Sa[(b[0]-32<<8)+b[1]]||`0x${b[0].toString(16).padStart(2,"0")}${b[1].toString(16).padStart(2,"0")}`},qt=function(b,e,r){let d=(b[0]-32<<16)+(b[1]<<8)+e,c=xa[d]||{},p=c[0];if(p!=null&&p.length)return p+=`: ${(c[1]||function(){})(r)||r}`,p},kt=[68,48,95,78,41,3,110,122,0];D();var Y=function(b=64){return Math.round(2e3*Math.log10(b/64))/100},jt=function(b,e,r){let d=[],c=r==!1?e.readIntVLV():r;b==0||b==127;for(let p=0;p127)return console.debug(`Early termination: ${d}`),d.pop(),e.backOne(),e.backOne(),new Uint8Array(d)}}}return new Uint8Array(d)},St=function(b){let e=0;return b.forEach(r=>{e+=r,e=e&127}),~e+1&127},le=function(b,e){let r=0,d=0;for(let c=0;c>p&1)<<7,m=b[c];m+=h,c%8!=0?(e(m,r,b),r++):d=b[c]}},it=function(b){let e=Math.floor(b*14.2);return e<128?e:0};var ue=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],Qt=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],De=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],Ca=[0,3,81,84,88],Wt={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Yt={0:0,1:1,2:3,5:4},Zt={0:0,1:1,2:2,5:3},Jt=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],ea=[36,37,48,49,52,53],bt=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],ta={26:127,29:0,30:0,31:0,52:12,53:54},nt=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19],Ta=[12,13,16,17,18,19],Ma=[33,99,100,32,102,8,9,10],aa=[0,16,25,40,32,64,26,48],x={};ue.forEach((b,e)=>{x[b]=e});var v={length:nt.length};nt.forEach((b,e)=>{v[b]=e});var ae={length:bt.length};bt.forEach((b,e)=>{ae[b]=e});var U=function(){return!!self.Bun||self.debugMode||!1},Ra=function(b){let e=[],r=0;return b==null||b.forEach(function(d,c){d==247?e.push(b.subarray(r,c)):d==240&&(r=c+1)}),e.length||e.push(b.subarray(0)),U()&&console.debug(e),e};var E={ch:128,cc:nt.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:bt.length,dnc:128,efx:7},A,q,de,be,te,pe,sa,ge,F,R,y,ye,I,H,Z,G,V,we,fe,Ae,T,O,Qe,j,he,ke,ne,We,Se,J,Ye,xe,re,L,Pe,Ze,Je,Ce,Te,ct,et,ce,B,ot,xt,ee,ve,Me,K,Ie,_,lt,pt,Ue,Le,se,ie,me,Be,Ne,He,ra,pr=(ra=class extends ht{constructor(){super();k(this,te);M(this,"NOTE_IDLE",0);M(this,"NOTE_ATTACK",1);M(this,"NOTE_DECAY",2);M(this,"NOTE_SUSTAIN",3);M(this,"NOTE_HELD",4);M(this,"NOTE_RELEASE",5);M(this,"NOTE_SOSTENUTO_ATTACK",8);M(this,"NOTE_SOSTENUTO_DECAY",9);M(this,"NOTE_SOSTENUTO_SUSTAIN",10);M(this,"NOTE_SOSTENUTO_HELD",11);M(this,"CH_MELODIC",0);M(this,"CH_DRUMS",1);M(this,"CH_DRUM1",2);M(this,"CH_DRUM2",3);M(this,"CH_DRUM3",4);M(this,"CH_DRUM4",5);M(this,"CH_DRUM5",6);M(this,"CH_DRUM6",7);M(this,"CH_DRUM7",8);M(this,"CH_DRUM8",9);k(this,A,0);k(this,q,0);k(this,de,0);k(this,be,new Array(11));k(this,ge,new Uint8Array(E.ch));k(this,F,new Uint8Array(E.ch));k(this,R,new Uint8Array(E.ch));k(this,y,new Uint8Array(E.ch*E.cc));k(this,ye,new Uint8Array(E.ace));k(this,I,new Uint8Array(E.ch));k(this,H,new Uint8Array(E.ch*E.nn));k(this,Z,new Uint8Array(E.ch));k(this,G,new Uint16Array(E.pl));k(this,V,new Uint8Array(E.pl));k(this,we,new Int16Array(E.ch));k(this,fe,new Uint8Array(E.ch));k(this,Ae,0);k(this,T,new Uint8Array(E.ch*E.rpn));k(this,O,new Uint8Array(E.ch*E.rpnt));k(this,Qe,new Int8Array(E.ch*ea.length));k(this,j,new Uint8Array(E.drm*E.dpn*E.dnc));k(this,he,new Uint8Array(E.ch));k(this,ke,new Uint8Array(128));k(this,ne,new Uint8Array(E.cmt*8));k(this,We,new Uint8Array(1024));k(this,Se,new Uint8Array(E.cmt*64));k(this,J,new Uint8Array(E.efx*3));k(this,Ye,new Uint8Array(E.ch));k(this,xe,0);k(this,re,0);k(this,L,100);k(this,Pe,0);k(this,Ze,500);k(this,Je,0);k(this,Ce,"");k(this,Te,0);k(this,ct,0);k(this,et,0);k(this,ce,!0);k(this,B,!1);k(this,ot,void 0);k(this,xt,new Uint8Array(2));k(this,ee,[]);k(this,ve,new Uint8Array(E.ch));k(this,Me,new Uint8Array(E.tr));M(this,"baseBank",new mt("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es"));M(this,"userBank",new mt("gm"));M(this,"initOnReset",!1);M(this,"aiEfxName","");k(this,K,[]);k(this,Ie,void 0);k(this,_,{nOff:(e,r)=>{let d=e*128+r,c=t(this,G).lastIndexOf(d);c>-1&&(t(this,y)[E.cc*e+v[64]]>63?(t(this,V)[c]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,H)[d],state:this.NOTE_HELD})):t(this,y)[E.cc*e+v[66]]>63&&t(this,V)[c]==this.NOTE_SOSTENUTO_SUSTAIN?(t(this,V)[c]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,H)[d],state:this.NOTE_SOSTENUTO_HELD})):(t(this,G)[c]=0,t(this,H)[d]=0,t(this,V)[c]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})))},nOn:(e,r,d)=>{let c=e*128+r,p=0;for(t(this,Z)[e]&&t(this,_).ano(e);t(this,V)[p]>0&&t(this,G)[p]!=c;)p++;p{},cAt:(e,r)=>{},hoOf:e=>{t(this,V).forEach((r,d)=>{if(r==this.NOTE_HELD){let c=t(this,G)[d],p=c>>7;e==p&&(t(this,V)[d]=this.NOTE_IDLE,t(this,G)[d]=0,t(this,H)[c]=0,this.dispatchEvent("note",{part:e,note:c&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,V).forEach((r,d)=>{let c;switch(r){case this.NOTE_ATTACK:{c=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{c=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{c=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(c){t(this,V)[d]=c;let p=t(this,G)[d];this.dispatchEvent("note",{part:e,note:p&127,velo:t(this,H)[p],state:c})}})},soOf:e=>{t(this,V).forEach((r,d)=>{if(r==this.NOTE_SOSTENUTO_HELD){let c=t(this,G)[d],p=c>>7;e==p&&(t(this,V)[d]=this.NOTE_IDLE,t(this,G)[d]=0,t(this,H)[c]=0,this.dispatchEvent("note",{part:e,note:c&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,G).forEach((r,d,c)=>{let p=r>>7,h=r&127;r==0&&t(this,H)[0]==0||p==e&&t(this,_).nOff(p,h)})}});k(this,lt,{8:function(e){let r=e.channel,d=e.data[0];t(this,_).nOff(r,d)},9:function(e){let r=e.channel;this.setChActive(r,1);let d=e.data[0],c=e.data[1];c>0?t(this,_).nOn(r,d,c):t(this,_).nOff(r,d)},10:function(e){let r=e.channel,d=r*128+e.data[0];t(this,G).indexOf(d)>-1&&(t(this,H)[d]=data[1],this.dispatchEvent("note",{part:r,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let r=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,A)){case x.s90es:case x.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(r,1);break}e.data[1]&&this.setChActive(r,1);break}default:{this.setChActive(r,1);break}}})();let d=r*E.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,_).ano(r),t(this,we)[r]=0;let c=r*E.cc;t(this,y)[c+v[1]]=0,t(this,y)[c+v[5]]=0,t(this,y)[c+v[64]]=0,t(this,y)[c+v[65]]=0,t(this,y)[c+v[66]]=0,t(this,y)[c+v[67]]=0,t(this,y)[c+v[11]]=127,t(this,y)[c+v[101]]=127,t(this,y)[c+v[100]]=127,t(this,y)[c+v[99]]=127,t(this,y)[c+v[98]]=127;return}case 123:{t(this,_).ano(r);return}case 124:{t(this,_).ano(r);return}case 125:{t(this,_).ano(r);return}case 126:{t(this,Z)[r]=1,t(this,_).ano(r);return}case 127:{t(this,Z)[r]=0,t(this,_).ano(r);return}}if(v[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Ta.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(U()&&console.debug(`${ue[t(this,A)]}, CH${r+1}: ${e.data[1]}`),t(this,A)==0?e.data[1]<48?(t(this,R)[r]>0&&(e.data[1]=t(this,y)[d],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,A)==x.gs?e.data[1]<56&&t(this,R)[r]>0&&(e.data[1]=t(this,y)[d],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):t(this,A)==x.gm?e.data[1]<48?t(this,R)[r]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${r+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):t(this,A)==x.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),t(this,A)){case x.xg:{[126,127].indexOf(e.data[1])>-1?t(this,R)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,R)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x["05rw"]:case x.x5d:case x.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(this,R)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,R)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,R)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,R)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x.g2:{e.data[1]==120?t(this,R)[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,R)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:r});break}case 6:{if(t(this,Ae)){[x.xg,x.gs,x.ns5r].indexOf(t(this,A))<0&&console.warn(`NRPN commits are not available under "${ue[t(this,A)]}" mode, even when they are supported in Octavia.`);let c=t(this,y)[d+v[99]],p=t(this,y)[d+v[98]];if(c==1){let h=Ma.indexOf(p);if(h>-1)t(this,y)[d+v[71+h]]=e.data[1],U()&&console.debug(`Redirected NRPN 1 ${p} to cc${71+h}.`),this.dispatchEvent("cc",{part:r,cc:71+h,data:e.data[1]});else{let m=ea.indexOf(p);m>-1?t(this,Qe)[r*10+m]=e.data[1]-64:console.warn(`NRPN 0x01${p.toString(16).padStart(2,"0")} is not supported.`),U()&&console.debug(`CH${r+1} voice NRPN ${p} commit`)}}else{if(bt.indexOf(c)<0){let m=`NRPN 0x${c.toString(16).padStart(2,"0")}${p.toString(16).padStart(2,"0")} `;c==127?console.warn(`${m}is not necessary. Consider removing it.`):console.warn(`${m}is not supported.`)}else{let m=t(this,R)[r]-2;m<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${st[t(this,R)[r]]}.`):t(this,j)[(m*E.dpn+ae[c])*E.dnc+p]=e.data[1]}U()&&console.debug(`CH${r+1} (${st[t(this,R)[r]]}) drum NRPN ${c} commit`)}}else{let c=Yt[t(this,y)[d+v[100]]],p=Zt[t(this,y)[d+v[100]]];t(this,y)[d+v[101]]==0&&c!=null&&(U()&&console.debug(`CH${r+1} RPN 0 ${t(this,y)[d+v[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Jt[c][0]),Jt[c][1]),t(this,T)[r*E.rpn+c]=e.data[1],t(this,O)[r*E.rpnt+p]=1)}break}case 32:{switch(U()&&console.debug(`${ue[t(this,A)]}, CH${r+1} LSB: ${e.data[1]}`),t(this,A)){case x.s90es:case x.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,A),!0);break}}this.dispatchEvent("voice",{part:r});break}case 38:{if(!t(this,Ae)){let c=Yt[t(this,y)[d+100]],p=Zt[t(this,y)[d+100]];t(this,y)[d+101]==0&&c!=null&&(t(this,T)[r*E.rpn+c+1]=e.data[1],t(this,O)[r*E.rpnt+p]=1)}break}case 64:{e.data[1]<64&&t(this,_).hoOf(r);break}case 66:{e.data[1]>>6?t(this,_).soOn(r):t(this,_).soOf(r);break}case 98:case 99:{w(this,Ae,1);break}case 100:case 101:{w(this,Ae,0);break}}t(this,y)[d+v[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:r,cc:e.data[0],data:e.data[1]})}},12:function(e){let r=e.channel;switch(t(this,A)){case x.s90es:case x.motif:{e.data&&this.setChActive(r,1);break}default:this.setChActive(r,1)}t(this,I)[r]=e.data,t(this,he)[r]=0,U()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),this.dispatchEvent("voice",{part:r})},13:function(e){let r=this,d=e.channel;t(this,G).forEach(function(c){let p=c>>7;d==p&&(t(r,H)[c]=e.data,r.dispatchEvent("note",{part:d,note:c&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;t(this,we)[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){Ra(e.data).forEach(r=>{let d=r[0],c=r[1];(t(this,pt)[d]||function(){console.debug(`Unknown manufacturer ${d}.`)})(c,r.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(t(this,K)[e.meta]||function(d,c,p){}).call(this,e.data,e.track,e.meta),e.meta!=32&&w(this,Pe,0);let r=Ca.indexOf(e.meta)>-1;if(U()&&console.debug(e),r)return e.reply="meta",e}});k(this,pt,{64:(e,r,d)=>{t(this,Be).run(r,d,e)},65:(e,r,d)=>{if(r[0]<16)if(r[1]==72){let c=r[r.length-1],p=St(r.subarray(3,r.length-1));c==p?t(this,ie).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad SD checksum ${c}. Should be ${p}.`)}else t(this,ie).run(r,d,e);else{let c=r[r.length-1],p=St(r.subarray(2,r.length-1));c==p?t(this,ie).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad GS checksum ${c}. Should be ${p}.`)}},66:(e,r,d)=>{t(this,me).run(r,d,e)},67:(e,r,d)=>{t(this,se).run(r,d,e)},68:(e,r,d)=>{t(this,He).run(r,d,e)},71:(e,r,d)=>{t(this,Ne).run(r,d,e)},126:(e,r,d)=>{t(this,Ue).run(r,d,e)},127:(e,r,d)=>{this.switchMode("gm"),t(this,Le).run(r,d,e)}});k(this,Ue,void 0);k(this,Le,void 0);k(this,se,void 0);k(this,ie,void 0);k(this,me,void 0);k(this,Be,void 0);k(this,Ne,void 0);k(this,He,void 0);let e=this;w(this,te,new Uint8Array(256),sa),t(this,be)[10]=new Uint8Array(512),w(this,Ie,new oe),this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(b=>{let e=b.split(",");Et[e[0]]=e[1]});var Ft=function(b){let e=b;b[0]=="*"&&(e=e.slice(1)),["aa","ii","uu","ee","oo"].forEach(d=>{for(;e.indexOf(d)>-1;)e=e.replace(d,d[0])});for(let d in Et)e=e.replaceAll(d,Et[d]);e.indexOf("ん")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},Vt=function(b){return b?b<96?`cc${b}`:["aftertouch","velocity","pitch bend"][b-96]:"off"};D();var $t=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],Kt=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],zt=["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 Sa={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"},xa={66307:["drive"],66309:["vowel",b=>"aiueo"[b]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",b=>["off","LPF","HPF"][b]],94984:["noise type",b=>["white","pink"][b]],94987:["disc type",b=>["LP","SP","EP","RND"]],94990:["hum type",b=>`${b+5}0Hz`],94993:["M/S",b=>["mono","stereo"][b]]},wt=function(b){return Sa[(b[0]-32<<8)+b[1]]||`0x${b[0].toString(16).padStart(2,"0")}${b[1].toString(16).padStart(2,"0")}`},qt=function(b,e,r){let d=(b[0]-32<<16)+(b[1]<<8)+e,c=xa[d]||{},p=c[0];if(p!=null&&p.length)return p+=`: ${(c[1]||function(){})(r)||r}`,p},kt=[68,48,95,78,41,3,110,122,0];D();var Y=function(b=64){return Math.round(2e3*Math.log10(b/64))/100},jt=function(b,e,r){let d=[],c=r==!1?e.readIntVLV():r;b==0||b==127;for(let p=0;p127)return console.debug(`Early termination: ${d}`),d.pop(),e.backOne(),e.backOne(),new Uint8Array(d)}}}return new Uint8Array(d)},St=function(b){let e=0;return b.forEach(r=>{e+=r,e=e&127}),~e+1&127},le=function(b,e){let r=0,d=0;for(let c=0;c>p&1)<<7,m=b[c];m+=f,c%8!=0?(e(m,r,b),r++):d=b[c]}},it=function(b){let e=Math.floor(b*14.2);return e<128?e:0};var ue=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],Qt=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],De=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],Ca=[0,3,81,84,88],Wt={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},Yt={0:0,1:1,2:3,5:4},Zt={0:0,1:1,2:2,5:3},Jt=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],ea=[36,37,48,49,52,53],bt=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],ta={26:127,29:0,30:0,31:0,52:12,53:54},nt=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19,14,15,20,21],Ta=[12,13,14,15,16,17,18,19,20,21],Ma=[33,99,100,32,102,8,9,10],aa=[0,16,25,40,32,64,26,48],x={};ue.forEach((b,e)=>{x[b]=e});var v={length:nt.length};nt.forEach((b,e)=>{v[b]=e});var ae={length:bt.length};bt.forEach((b,e)=>{ae[b]=e});var U=function(){return!!self.Bun||self.debugMode||!1},Ra=function(b){let e=[],r=0;return b==null||b.forEach(function(d,c){d==247?e.push(b.subarray(r,c)):d==240&&(r=c+1)}),e.length||e.push(b.subarray(0)),U()&&console.debug(e),e};var E={ch:128,cc:nt.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:bt.length,dnc:128,efx:7},A,q,de,be,te,pe,sa,ge,F,R,y,ye,I,H,Z,G,V,we,fe,Ae,T,O,Qe,j,he,ke,ne,We,Se,J,Ye,xe,re,L,Pe,Ze,Je,Ce,Te,ct,et,ce,B,ot,xt,ee,ve,Me,K,Ie,_,lt,pt,Ue,Le,se,ie,me,Be,Ne,He,ra,pr=(ra=class extends ht{constructor(){super();k(this,te);M(this,"NOTE_IDLE",0);M(this,"NOTE_ATTACK",1);M(this,"NOTE_DECAY",2);M(this,"NOTE_SUSTAIN",3);M(this,"NOTE_HELD",4);M(this,"NOTE_RELEASE",5);M(this,"NOTE_SOSTENUTO_ATTACK",8);M(this,"NOTE_SOSTENUTO_DECAY",9);M(this,"NOTE_SOSTENUTO_SUSTAIN",10);M(this,"NOTE_SOSTENUTO_HELD",11);M(this,"CH_MELODIC",0);M(this,"CH_DRUMS",1);M(this,"CH_DRUM1",2);M(this,"CH_DRUM2",3);M(this,"CH_DRUM3",4);M(this,"CH_DRUM4",5);M(this,"CH_DRUM5",6);M(this,"CH_DRUM6",7);M(this,"CH_DRUM7",8);M(this,"CH_DRUM8",9);k(this,A,0);k(this,q,0);k(this,de,0);k(this,be,new Array(11));k(this,ge,new Uint8Array(E.ch));k(this,F,new Uint8Array(E.ch));k(this,R,new Uint8Array(E.ch));k(this,y,new Uint8Array(E.ch*E.cc));k(this,ye,new Uint8Array(E.ace));k(this,I,new Uint8Array(E.ch));k(this,H,new Uint8Array(E.ch*E.nn));k(this,Z,new Uint8Array(E.ch));k(this,G,new Uint16Array(E.pl));k(this,V,new Uint8Array(E.pl));k(this,we,new Int16Array(E.ch));k(this,fe,new Uint8Array(E.ch));k(this,Ae,0);k(this,T,new Uint8Array(E.ch*E.rpn));k(this,O,new Uint8Array(E.ch*E.rpnt));k(this,Qe,new Int8Array(E.ch*ea.length));k(this,j,new Uint8Array(E.drm*E.dpn*E.dnc));k(this,he,new Uint8Array(E.ch));k(this,ke,new Uint8Array(128));k(this,ne,new Uint8Array(E.cmt*8));k(this,We,new Uint8Array(1024));k(this,Se,new Uint8Array(E.cmt*64));k(this,J,new Uint8Array(E.efx*3));k(this,Ye,new Uint8Array(E.ch));k(this,xe,0);k(this,re,0);k(this,L,100);k(this,Pe,0);k(this,Ze,500);k(this,Je,0);k(this,Ce,"");k(this,Te,0);k(this,ct,0);k(this,et,0);k(this,ce,!0);k(this,B,!1);k(this,ot,void 0);k(this,xt,new Uint8Array(2));k(this,ee,[]);k(this,ve,new Uint8Array(E.ch));k(this,Me,new Uint8Array(E.tr));M(this,"baseBank",new mt("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es"));M(this,"userBank",new mt("gm"));M(this,"initOnReset",!1);M(this,"aiEfxName","");k(this,K,[]);k(this,Ie,void 0);k(this,_,{nOff:(e,r)=>{let d=e*128+r,c=t(this,G).lastIndexOf(d);c>-1&&(t(this,y)[E.cc*e+v[64]]>63?(t(this,V)[c]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,H)[d],state:this.NOTE_HELD})):t(this,y)[E.cc*e+v[66]]>63&&t(this,V)[c]==this.NOTE_SOSTENUTO_SUSTAIN?(t(this,V)[c]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,H)[d],state:this.NOTE_SOSTENUTO_HELD})):(t(this,G)[c]=0,t(this,H)[d]=0,t(this,V)[c]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})))},nOn:(e,r,d)=>{let c=e*128+r,p=0;for(t(this,Z)[e]&&t(this,_).ano(e);t(this,V)[p]>0&&t(this,G)[p]!=c;)p++;p{},cAt:(e,r)=>{},hoOf:e=>{t(this,V).forEach((r,d)=>{if(r==this.NOTE_HELD){let c=t(this,G)[d],p=c>>7;e==p&&(t(this,V)[d]=this.NOTE_IDLE,t(this,G)[d]=0,t(this,H)[c]=0,this.dispatchEvent("note",{part:e,note:c&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,V).forEach((r,d)=>{let c;switch(r){case this.NOTE_ATTACK:{c=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{c=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{c=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(c){t(this,V)[d]=c;let p=t(this,G)[d];this.dispatchEvent("note",{part:e,note:p&127,velo:t(this,H)[p],state:c})}})},soOf:e=>{t(this,V).forEach((r,d)=>{if(r==this.NOTE_SOSTENUTO_HELD){let c=t(this,G)[d],p=c>>7;e==p&&(t(this,V)[d]=this.NOTE_IDLE,t(this,G)[d]=0,t(this,H)[c]=0,this.dispatchEvent("note",{part:e,note:c&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,G).forEach((r,d,c)=>{let p=r>>7,f=r&127;r==0&&t(this,H)[0]==0||p==e&&t(this,_).nOff(p,f)})}});k(this,lt,{8:function(e){let r=e.channel,d=e.data[0];t(this,_).nOff(r,d)},9:function(e){let r=e.channel;this.setChActive(r,1);let d=e.data[0],c=e.data[1];c>0?t(this,_).nOn(r,d,c):t(this,_).nOff(r,d)},10:function(e){let r=e.channel,d=r*128+e.data[0];t(this,G).indexOf(d)>-1&&(t(this,H)[d]=data[1],this.dispatchEvent("note",{part:r,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let r=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,A)){case x.s90es:case x.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(r,1);break}e.data[1]&&this.setChActive(r,1);break}default:{this.setChActive(r,1);break}}})();let d=r*E.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,_).ano(r),t(this,we)[r]=0;let c=r*E.cc;t(this,y)[c+v[1]]=0,t(this,y)[c+v[5]]=0,t(this,y)[c+v[64]]=0,t(this,y)[c+v[65]]=0,t(this,y)[c+v[66]]=0,t(this,y)[c+v[67]]=0,t(this,y)[c+v[11]]=127,t(this,y)[c+v[101]]=127,t(this,y)[c+v[100]]=127,t(this,y)[c+v[99]]=127,t(this,y)[c+v[98]]=127;return}case 123:{t(this,_).ano(r);return}case 124:{t(this,_).ano(r);return}case 125:{t(this,_).ano(r);return}case 126:{t(this,Z)[r]=1,t(this,_).ano(r);return}case 127:{t(this,Z)[r]=0,t(this,_).ano(r);return}}if(v[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(Ta.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(U()&&console.debug(`${ue[t(this,A)]}, CH${r+1}: ${e.data[1]}`),t(this,A)==0?e.data[1]<48?(t(this,R)[r]>0&&(e.data[1]=t(this,y)[d],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,A)==x.gs?e.data[1]<56&&t(this,R)[r]>0&&(e.data[1]=t(this,y)[d],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):t(this,A)==x.gm?e.data[1]<48?t(this,R)[r]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${r+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):t(this,A)==x.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),t(this,A)){case x.xg:{[126,127].indexOf(e.data[1])>-1?t(this,R)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,R)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x["05rw"]:case x.x5d:case x.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(this,R)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,R)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,R)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,R)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x.g2:{e.data[1]==120?t(this,R)[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,R)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:r});break}case 6:{if(t(this,Ae)){[x.xg,x.gs,x.ns5r].indexOf(t(this,A))<0&&console.warn(`NRPN commits are not available under "${ue[t(this,A)]}" mode, even when they are supported in Octavia.`);let c=t(this,y)[d+v[99]],p=t(this,y)[d+v[98]];if(c==1){let f=Ma.indexOf(p);if(f>-1)t(this,y)[d+v[71+f]]=e.data[1],U()&&console.debug(`Redirected NRPN 1 ${p} to cc${71+f}.`),this.dispatchEvent("cc",{part:r,cc:71+f,data:e.data[1]});else{let m=ea.indexOf(p);m>-1?t(this,Qe)[r*10+m]=e.data[1]-64:console.warn(`NRPN 0x01${p.toString(16).padStart(2,"0")} is not supported.`),U()&&console.debug(`CH${r+1} voice NRPN ${p} commit`)}}else{if(bt.indexOf(c)<0){let m=`NRPN 0x${c.toString(16).padStart(2,"0")}${p.toString(16).padStart(2,"0")} `;c==127?console.warn(`${m}is not necessary. Consider removing it.`):console.warn(`${m}is not supported.`)}else{let m=t(this,R)[r]-2;m<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${st[t(this,R)[r]]}.`):t(this,j)[(m*E.dpn+ae[c])*E.dnc+p]=e.data[1]}U()&&console.debug(`CH${r+1} (${st[t(this,R)[r]]}) drum NRPN ${c} commit`)}}else{let c=Yt[t(this,y)[d+v[100]]],p=Zt[t(this,y)[d+v[100]]];t(this,y)[d+v[101]]==0&&c!=null&&(U()&&console.debug(`CH${r+1} RPN 0 ${t(this,y)[d+v[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Jt[c][0]),Jt[c][1]),t(this,T)[r*E.rpn+c]=e.data[1],t(this,O)[r*E.rpnt+p]=1)}break}case 32:{switch(U()&&console.debug(`${ue[t(this,A)]}, CH${r+1} LSB: ${e.data[1]}`),t(this,A)){case x.s90es:case x.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,A),!0);break}}this.dispatchEvent("voice",{part:r});break}case 38:{if(!t(this,Ae)){let c=Yt[t(this,y)[d+100]],p=Zt[t(this,y)[d+100]];t(this,y)[d+101]==0&&c!=null&&(t(this,T)[r*E.rpn+c+1]=e.data[1],t(this,O)[r*E.rpnt+p]=1)}break}case 64:{e.data[1]<64&&t(this,_).hoOf(r);break}case 66:{e.data[1]>>6?t(this,_).soOn(r):t(this,_).soOf(r);break}case 98:case 99:{w(this,Ae,1);break}case 100:case 101:{w(this,Ae,0);break}}t(this,y)[d+v[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:r,cc:e.data[0],data:e.data[1]})}},12:function(e){let r=e.channel;switch(t(this,A)){case x.s90es:case x.motif:{e.data&&this.setChActive(r,1);break}default:this.setChActive(r,1)}t(this,I)[r]=e.data,t(this,he)[r]=0,U()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),this.dispatchEvent("voice",{part:r})},13:function(e){let r=this,d=e.channel;t(this,G).forEach(function(c){let p=c>>7;d==p&&(t(r,H)[c]=e.data,r.dispatchEvent("note",{part:d,note:c&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;t(this,we)[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){Ra(e.data).forEach(r=>{let d=r[0],c=r[1];(t(this,pt)[d]||function(){console.debug(`Unknown manufacturer ${d}.`)})(c,r.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(t(this,K)[e.meta]||function(d,c,p){}).call(this,e.data,e.track,e.meta),e.meta!=32&&w(this,Pe,0);let r=Ca.indexOf(e.meta)>-1;if(U()&&console.debug(e),r)return e.reply="meta",e}});k(this,pt,{64:(e,r,d)=>{t(this,Be).run(r,d,e)},65:(e,r,d)=>{if(r[0]<16)if(r[1]==72){let c=r[r.length-1],p=St(r.subarray(3,r.length-1));c==p?t(this,ie).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad SD checksum ${c}. Should be ${p}.`)}else t(this,ie).run(r,d,e);else{let c=r[r.length-1],p=St(r.subarray(2,r.length-1));c==p?t(this,ie).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad GS checksum ${c}. Should be ${p}.`)}},66:(e,r,d)=>{t(this,me).run(r,d,e)},67:(e,r,d)=>{t(this,se).run(r,d,e)},68:(e,r,d)=>{t(this,He).run(r,d,e)},71:(e,r,d)=>{t(this,Ne).run(r,d,e)},126:(e,r,d)=>{t(this,Ue).run(r,d,e)},127:(e,r,d)=>{this.switchMode("gm"),t(this,Le).run(r,d,e)}});k(this,Ue,void 0);k(this,Le,void 0);k(this,se,void 0);k(this,ie,void 0);k(this,me,void 0);k(this,Be,void 0);k(this,Ne,void 0);k(this,He,void 0);let e=this;w(this,te,new Uint8Array(256),sa),t(this,be)[10]=new Uint8Array(512),w(this,Ie,new oe),this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -150,18 +150,18 @@ _,`.split(` 122 006 000 `),this.addEventListener("metacommit",function(a){var l,i;let{data:n}=a;((l=t(e,ee)[0])==null?void 0:l.type)==n.type&&((i=t(e,ee)[0])!=null&&i.amend)?(t(e,ee)[0].amend=n.amend,t(e,ee)[0].data+=n.data):t(e,ee).unshift(n)}),t(this,K)[1]=function(a){var n,l,i,s,o;switch(a=a.replaceAll(`\r `,` `).replaceAll("\r",` -`),a.slice(0,2)){case"@I":{w(this,B,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(n=a.slice(2))==null?void 0:n.trimLeft()});break}case"@K":{w(this,B,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(l=a.slice(2))==null?void 0:l.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{w(this,B,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(i=a.slice(2))==null?void 0:i.trimLeft()});break}case"@T":{w(this,B,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(s=a.slice(2))==null?void 0:s.trimLeft()});break}case"@V":{w(this,B,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(o=a.slice(2))==null?void 0:o.trimLeft()});break}case"XF":{let f=a.slice(2).split(":");switch(f[0]){case"hd":{f.slice(1).forEach((u,g)=>{u.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][g],data:u})});break}case"ln":{f.slice(1).forEach((u,g)=>{u.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][g],data:u})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:t(this,B)?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` -`).forEach((f,u)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:f,mask:u!=0})})}},t(this,K)[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},t(this,K)[3]=function(a,n){n<1&&t(this,Pe)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},t(this,K)[4]=function(a,n){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},t(this,K)[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},t(this,K)[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},t(this,K)[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},t(this,K)[32]=function(a){w(this,Pe,a[0]+1)},t(this,K)[33]=function(a,n){t(e,Me)[n]=a+1},t(this,K)[81]=function(a,n){w(e,Ze,a/1e3)},t(this,K)[127]=function(a,n){t(e,Ie).run(a,n)},t(this,Ie).default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},t(this,Ie).add([67,0,1],function(a,n){t(e,Me)[n]=a[0]+1}),w(this,Ue,new oe("universal non-realtime")),w(this,Le,new oe("universal realtime")),w(this,se,new oe("Yamaha")),w(this,ie,new oe("Roland")),w(this,me,new oe("Korg")),w(this,Be,new oe("Kawai")),w(this,Ne,new oe("Akai")),w(this,He,new oe("Casio"));let r=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,a)};t(this,Ue).default=r,t(this,Le).default=r,t(this,se).default=r,t(this,ie).default=r,t(this,me).default=r,t(this,Be).default=r,t(this,Ne).default=r,t(this,He).default=r,t(this,Ue).add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),w(e,B,t(e,B)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),t(this,Le).add([4,1],a=>{w(e,L,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,L))}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64),t(this,se).add([76,0,0],a=>{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),w(e,B,!1),console.info("MIDI reset: XG");break}default:{let n=[0,0,0,0],l=(i,s)=>{n[s]=i};if(a.subarray(1).forEach((i,s)=>{let o=s+a[0];([l,l,l,l,f=>{w(this,L,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,L))},f=>{},f=>{}][o]||(()=>{}))(i,s)}),a[0]<4){let i=0;n.forEach(s=>{i=i<<4,i+=s}),i-=1024}}}}).add([76,2,1],a=>{let n="XG ";a[0]<32?(n+="reverb ",a.subarray(1).forEach((l,i)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${n}main type: ${rt[s]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{e.setEffectTypeRaw(0,!0,s),console.debug(`${n}sub type: ${s+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{console.debug(`${n}time: ${Gt(s)}s`)},s=>{console.debug(`${n}diffusion: ${s}`)},s=>{console.debug(`${n}initial delay: ${s}`)},s=>{console.debug(`${n}HPF cutoff: ${je[s]}Hz`)},s=>{console.debug(`${n}LPF cutoff: ${je[s]}Hz`)},s=>{console.debug(`${n}width: ${s}`)},s=>{console.debug(`${n}height: ${s}`)},s=>{console.debug(`${n}depth: ${s}`)},s=>{console.debug(`${n}wall type: ${s}`)},s=>{console.debug(`${n}dry/wet: ${s}`)},s=>{console.debug(`${n}send: ${Y(s)}dB`)},s=>{console.debug(`${n}pan: ${s-64}`)},!1,!1,s=>{console.debug(`${n}delay: ${s}`)},s=>{console.debug(`${n}density: ${s}`)},s=>{console.debug(`${n}balance: ${s}`)},s=>{},s=>{console.debug(`${n}feedback: ${s}`)},s=>{}][a[0]+i]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(l)})):a[0]<64?(n+="chorus ",a.subarray(1).forEach((l,i)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${n}main type: ${rt[s]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{e.setEffectTypeRaw(1,!0,s),console.debug(`${n}sub type: ${s+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{console.debug(`${n}LFO: ${Ht[s]}Hz`)},s=>{},s=>{console.debug(`${n}feedback: ${s}`)},s=>{console.debug(`${n}delay offset: ${_t(s)}ms`)},s=>{},s=>{console.debug(`${n}low: ${je[s]}Hz`)},s=>{console.debug(`${n}low: ${s-64}dB`)},s=>{console.debug(`${n}high: ${je[s]}Hz`)},s=>{console.debug(`${n}high: ${s-64}dB`)},s=>{console.debug(`${n}dry/wet: ${s}`)},s=>{console.debug(`${n}send: ${Y(s)}dB`)},s=>{console.debug(`${n}pan: ${s-64}`)},s=>{console.debug(`${n}to reverb: ${Y(s)}dB`)},!1,s=>{},s=>{},s=>{},s=>{console.debug(`${n}LFO phase diff: ${(s-64)*3}deg`)},s=>{console.debug(`${n}input mode: ${s?"stereo":"mono"}`)},s=>{}][a[0]-32+i]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(l)})):a[0]<86?(n+="variation ",a.subarray(1).forEach((l,i)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${n}main type: ${rt[s]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},s=>{e.setEffectTypeRaw(2,!0,s),console.debug(`${n}sub type: ${s+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+i]||function(){})(l)})):a[0]<97?(n+="variation ",a.subarray(1).forEach((l,i)=>{[s=>{console.debug(`${n}send: ${Y(s)}dB`)},s=>{console.debug(`${n}pan: ${s-64}`)},s=>{console.debug(`${n}to reverb: ${Y(s)}dB`)},s=>{console.debug(`${n}to chorus: ${Y(s)}dB`)},s=>{console.debug(`${n}connection: ${s?"system":"insertion"}`)},s=>{console.debug(`${n}channel: CH${s+1}`)},s=>{console.debug(`${n}mod wheel: ${s-64}`)},s=>{console.debug(`${n}bend wheel: ${s-64}`)},s=>{console.debug(`${n}channel after touch: ${s-64}`)},s=>{console.debug(`${n}AC1: ${s-64}`)},s=>{console.debug(`${n}AC2: ${s-64}`)}][a[0]-86+i](l)})):a[0]>111&&a[0]<118?n+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((n,l)=>{let i=l+a[0];if(i==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][n]}`);else{let s=i-1>>2,o=i-1&3,f=`XG EQ ${s} ${["gain","freq","Q","shape"][o]}: `;[()=>{console.debug(`${f}${n-64}dB`)},()=>{console.debug(`${f}${n} (raw)`)},()=>{console.debug(`${f}${n/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!n]}`)}][o]()}})}).add([76,3],a=>{let n=a[0],l=a[1],i=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((s,o)=>{([f=>{e.setEffectTypeRaw(3+n,!1,f),console.info(`${i}main type: ${rt[f]}`),e.dispatchEvent(`efxinsert${n}`,e.getEffectType(3+n))},f=>{e.setEffectTypeRaw(3+n,!0,f),console.debug(`${i}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${n}`,e.getEffectType(3+n))}][l+o]||function(){})(s)})}).add([76,6,0],a=>{let n=a[0];n<64?e.setLetterDisplay(a.subarray(1),"XG letter display",n):w(e,Te,Date.now())}).add([76,7,0],a=>{let n=a[0];w(e,q,0),w(e,de,Date.now()+3200),t(e,te,pe).fill(0);let l=a.subarray(1);for(let i=0;i>6-$&1,$++})}).add([76,8],(a,n)=>{let l=e.chRedir(a[0],n,!0),i=a[1],s=E.cc*l,o=`XG CH${l+1} `,f=`Unknown XG part address ${i}.`;a.subarray(2).forEach((u,g)=>{i<1?console.debug(f):i<41?([()=>{t(e,y)[s+v[0]]=u,e.dispatchEvent("voice",{part:l})},()=>{t(e,y)[s+v[32]]=u,e.dispatchEvent("voice",{part:l})},()=>{t(e,I)[l]=u,e.dispatchEvent("voice",{part:l})},()=>{let $=e.chRedir(u,n,!0);t(e,F)[l]=$,l!=$&&(e.buildRchTree(),console.info(`${o}receives from CH${$+1}`))},()=>{t(e,Z)[l]=+!u},()=>{},()=>{e.setChType(l,u,x.xg),console.debug(`${o}type: ${st[u]||u}`)},()=>{t(e,T)[E.rpn*l+3]=u,t(e,O)[E.rpnt*l+2]=1},!1,!1,()=>{t(e,y)[s+v[7]]=u},!1,!1,()=>{t(e,y)[s+v[10]]=u||128},!1,!1,()=>{t(e,y)[s+v[128]]=u},()=>{t(e,y)[s+v[93]]=u},()=>{t(e,y)[s+v[91]]=u},()=>{t(e,y)[s+v[94]]=u},()=>{t(e,y)[s+v[76]]=u},()=>{t(e,y)[s+v[77]]=u},()=>{t(e,y)[s+v[78]]=u},()=>{t(e,y)[s+v[74]]=u},()=>{t(e,y)[s+v[71]]=u},()=>{t(e,y)[s+v[73]]=u},()=>{t(e,y)[s+v[75]]=u},()=>{t(e,y)[s+v[72]]=u}][i+g-1]||(()=>{}))():i<48?console.debug(f):i<111?i>102&&i<105&&(t(e,y)[s+v[[5,65][i&1]]]=u):i<114?console.debug(f):i<116?console.debug(`${o}EQ ${["bass","treble"][i&1]} gain: ${u-64}dB`):i<118?console.debug(f):i<120?console.debug(`${o}EQ ${["bass","treble"][i&1]} freq: ${u}`):console.debug(f)})}).add([76,9],(a,n)=>{let l=e.chRedir(a[0],n,!0),i=a[1],s=`PLG-150VL CH${l+1} `;a.subarray(2).forEach((o,f)=>{let u=f+i;switch(u){case 1:{console.info(`${s}breath mode: ${["system","breath","velocity","touch EG"][o]}`);break}case 0:case 27:case 28:break;default:if(u<27){let g=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][u-3>>1];u&1?u<23?(console.debug(`${s}${g} control source: ${Vt(o)}`),o&&o<96&&e.allocateAce(o)):console.debug(`${s}${g} scale break point: ${o}`):console.debug(`${s}${g} depth: ${o-64}`)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][a[0]]} for CH${a[2]+1}.`)}).add([73,0,0],(a,n)=>{let l=a[0],i="MU1000 System: ";a.subarray(1).forEach((s,o)=>{let f=l+o;f==8?console.debug(`${i}LCD contrast set to ${s}.`):f==18?(w(e,re,s?126:0),console.debug(`${i}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):f>=64&&f<69&&[()=>{e.dispatchEvent("channelactive",s)},()=>{s<8?(e.dispatchEvent("channelmin",s<<4),console.debug(`Octavia System: Minimum CH${(s<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{s<8?(e.dispatchEvent("channelmax",(s<<4)+15),console.debug(`Octavia System: Maximum CH${(s<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{w(e,ce,!!s),console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][f-64]()})}).add([73,10,0],(a,n)=>{let l=a[0],i=`MU1000 RS${t(e,ce)?"":" (ignored)"}: `;if(l<16)switch(l){case 2:{let s=e.chRedir(0,n,!0);t(e,ce)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${i}Show CH1~64`);break}case 3:{let s=e.chRedir(a[1]<<5,n,!0);t(e,ce)&&e.dispatchEvent("channelmin",s),t(e,ce)&&e.dispatchEvent("channelmax",s+31),console.info(`${i}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${i}unknown switch ${l} invoked.`)}else if(l<32){if(t(e,ce)){let s=e.chRedir(l-16+(t(e,et)<<4),n,!0);e.dispatchEvent("channelactive",s)}}else if(l<36){let s=e.chRedir(l-32<<4,n,!0);t(e,ce)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),w(e,et,l-32)),console.info(`${i}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(a,n)=>{let l=e.chRedir(a[0],n,!0),i=`PLG-100SG CH${l+1} `,s=Date.now();if(a[1]==0){let o="",f=0;a.subarray(2).forEach((u,g)=>{g%2==0?o+=Xt[u]||u.toString().padStart("0"):f+=u*13}),s>=t(e,Je)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${Ft(o)}`,amend:!0}),w(e,Je,s+Math.ceil(f/2)+t(e,Ze)),U()&&console.debug(`${i}vocals: ${o}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)});let d=function(a,n,l,i){},c=function(a,n){let l=a*E.dpn,i=n[0],s=n[1];n.subarray(2).forEach((o,f)=>{let u=f+s,g=-1;u<16?([()=>{g=24},()=>{g=25},()=>{g=26},()=>{},()=>{g=28},()=>{g=29},()=>{g=30},()=>{g=31},()=>{},()=>{},()=>{},()=>{g=20},()=>{g=21},()=>{g=22},()=>{g=23},()=>{}][u]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))():u<32||(u<40?([()=>{g=48},()=>{g=49},!1,!1,()=>{g=52},()=>{g=53}][u-32]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))():u<80||([()=>{g=36}][u-80]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))()),g>=0?(U()&&console.debug(l,g,i,o),t(e,j)[(l+ae[g])*E.dnc+i]=o):U()&&console.debug(`XG-style drum param ${u} has no writes.`)})},p=function(a,n,l){let i=a*E.dpn,s=(n<<7)+l[0];l.subarray(1).forEach((o,f)=>{let u=f+s,g=u&127,$=u>>7,S=-1;$>1&&([()=>{S=26},()=>{},()=>{S=28},()=>{S=29},()=>{S=30},()=>{},()=>{},()=>{S=31}][$-2]||(()=>{console.debug(`Unknown GS-style drum param ${$} on set ${a+1}.`)}))(),S>-1?(U()&&console.debug(i,S,g,o),t(e,j)[(i+ae[S])*E.dnc+g]=o):U()&&console.debug(`GS-style drum param ${$} has no writes.`)})};t(this,se).add([76,48],(a,n,l)=>{c(0,a)}).add([76,49],(a,n,l)=>{c(1,a)}).add([76,50],(a,n,l)=>{c(2,a)}).add([76,51],(a,n,l)=>{c(3,a)}).add([76,52],(a,n,l)=>{c(4,a)}).add([76,53],(a,n,l)=>{c(5,a)}).add([76,54],(a,n,l)=>{c(6,a)}).add([76,55],(a,n,l)=>{c(7,a)}),t(this,se).add([89,0],(a,n,l)=>{if(e.eprom){let i=a[0],s=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);U()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${i} bytes.`);let o=e.eprom.data;a.subarray(4).forEach((f,u)=>{let g=u>>3,$=u&7;if($==7)for(let S=0;S<7;S++)o[s+7*g+S]+=(f>>6-S&1)<<7;else o[s+7*g+$]=f})}}).add([89,1],(a,n,l)=>{let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];U()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(a,n,l)=>{if(e.eprom){let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);U()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;a.subarray(4).forEach((o,f)=>{let u=f>>3,g=f&7;if(g==7)for(let $=0;$<7;$++)s[i+7*u+$]+=(o>>6-$&1)<<7;else s[i+7*u+g]=o})}}).add([89,3],(a,n,l)=>{}),t(this,se).add([39,48],(a,n,l)=>{}).add([43,0,0],(a,n,l)=>{let i=[0,0,0,0],s=(o,f)=>{i[f]=o};if(a.subarray(1).forEach((o,f)=>{let u=f+a[0];[s,s,s,s,()=>{w(this,L,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,L))},()=>o-64,()=>o||128,()=>o,()=>o,()=>{console.debug(`TG300 variation on cc${o}.`)}][u](o,u)}),a[0]<4){let o=0;i.forEach(f=>{o=o<<4,o+=f}),o-=1024}}).add([43,1,0],(a,n,l)=>{}).add([43,2],(a,n,l)=>{let i=e.chRedir(a[0],n,!0),s=a[1],o=E.cc*i,f=`TG300 CH${i+1} `;a.subarray(2).forEach((u,g)=>{g<5?([()=>{},()=>{t(e,y)[o+v[0]]=u,e.dispatchEvent("voice",{part:i})},()=>{t(e,y)[o+v[32]]=u,e.dispatchEvent("voice",{part:i})},()=>{t(e,I)[i]=u,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(u,n,!0);t(e,F)[i]=$,i!=$&&(e.buildRchTree(),console.info(`${f}receives from CH${$+1}`))}][g+s]||(()=>{}))(u,g+s):g<21||(g<47?([()=>{t(e,Z)[i]=+!u},()=>{},()=>{},()=>{t(e,T)[E.rpn*i+3]=u,t(e,O)[E.rpnt*i+2]=1},()=>{},()=>{t(e,y)[o+v[7]]=u},!1,!1,()=>{t(e,y)[o+v[10]]=u||128},!1,!1,()=>{console.debug(`${f} AC1 at cc${u}`)},()=>{console.debug(`${f} AC2 at cc${u}`)},()=>{t(e,y)[o+v[128]]=u},()=>{t(e,y)[o+v[93]]=u},()=>{t(e,y)[o+v[91]]=u},()=>{t(e,y)[o+v[94]]=u},()=>{t(e,y)[o+v[76]]=u},()=>{t(e,y)[o+v[77]]=u},()=>{t(e,y)[o+v[74]]=u},()=>{t(e,y)[o+v[71]]=u},()=>{t(e,y)[o+v[73]]=u},()=>{t(e,y)[o+v[75]]=u},()=>{t(e,y)[o+v[72]]=u},()=>{t(e,y)[o+v[78]]=u}][g+s-21]||(()=>{}))(u,g+s):g<95||([()=>{t(e,y)[o+v[65]]=u},()=>{t(e,y)[o+v[5]]=u}][g+s-95]||(()=>{}))(u,g+s))})}).add([43,7,0],(a,n,l)=>{let i=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",i)}).add([43,7,1],(a,n,l)=>{w(e,q,0),w(e,de,Date.now()+3200),t(e,te,pe).fill(0),a.forEach(function(i,s){let o=Math.floor(s/16),f=s%16,u=(f*3+o)*7,g=7,$=0;for(u-=f*5,o==2&&(g=2);$>6-$&1,$++})}),t(this,ie).add([66,18,0,0,127],(a,n,l)=>{e.switchMode("gs",!0),t(e,y)[E.cc*9]=120,t(e,y)[E.cc*25]=120,t(e,y)[E.cc*41]=120,t(e,y)[E.cc*57]=120,w(e,re,3),w(e,B,!1),t(e,ve).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,n,l)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),t(e,y)[E.cc*9]=120,t(e,y)[E.cc*25]=120,t(e,y)[E.cc*41]=120,t(e,y)[E.cc*57]=120,w(e,B,!1),t(e,ve).fill(0),console.info("MIDI reset: GS");break}default:{let i=[0,0,0,0],s=(o,f)=>{i[f]=o};if(a.subarray(1).forEach((o,f)=>{let u=f+a[0];[s,s,s,s,g=>{w(this,L,g*129/16383*100),e.dispatchEvent("mastervolume",t(e,L))},g=>{},g=>{}][u](o,f)}),a[0]<4){let o=0;i.forEach(f=>{o=o<<4,o+=f}),o-=1024}}}}).add([66,18,64,1],a=>{let n=a[0];if(n<16){let l="".padStart(n," ");a.subarray(1).forEach((i,s)=>{l+=String.fromCharCode(Math.max(32,i))}),l=l.padEnd(16," "),console.debug(`GS patch name: ${l}`)}else n<48||(n<65?a.subarray(1).forEach((l,i)=>{let s=`GS ${n+i>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${$t[l]}`),e.setEffectType(0,40,l),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${l}ms`)},()=>{console.info(`${s}type: ${Kt[l]}`),e.setEffectType(1,40,16+l),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${Y(l)}`)},()=>{console.debug(`${s}to delay: ${Y(l)}`)}][n+i-48]||(()=>{}))()}):n<80?console.debug(`Unknown GS patch address: ${n}`):n<91?a.subarray(1).forEach((l,i)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${zt[l]}`),e.setEffectType(2,40,32+l),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${Y(l)}`)}][n+i-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${n}`))}).add([66,18,64,2],a=>{let n="GS EQ ";a.subarray(1).forEach((l,i)=>{([()=>{console.debug(`${n}low freq: ${[200,400][l]}Hz`)},()=>{console.debug(`${n}low gain: ${l-64}dB`)},()=>{console.debug(`${n}high freq: ${[3e3,6e3][l]}Hz`)},()=>{console.debug(`${n}high gain: ${l-64}dB`)}][a[0]+i]||function(){console.warn(`Unknown GS EQ address: ${a[0]+i}`)})()})}).add([66,18,64,3],a=>{let n="GS EFX ",l=function(i,s){let o=qt(t(e,J).subarray(10,12),s,i);o&&console.debug(`${n}${wt(t(e,J).subarray(10,12))} ${o}`)};a.subarray(1).forEach((i,s)=>{([()=>{e.setEffectTypeRaw(3,!1,32+i),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,i),console.info(`${n}type: ${wt(t(e,J).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,()=>{console.debug(`${n}to reverb: ${Y(i)}dB`)},()=>{console.debug(`${n}to chorus: ${Y(i)}dB`)},()=>{console.debug(`${n}to delay: ${Y(i)}dB`)},!1,()=>{console.debug(`${n}1 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${n}1 depth: ${i-64}`)},()=>{console.debug(`${n}2 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${n}2 depth: ${i-64}`)},()=>{console.debug(`${n}to EQ: ${i?"ON":"OFF"}`)}][a[0]+s]||function(o,f){console.warn(`Unknown GS EFX address: ${f}`)})(i,a[0]+s)})}).add([66,18,65],a=>{p((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],a=>{var n;switch(a[0]){case 0:{let l=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",l);break}case 32:{w(e,de,Date.now()+3200),a[1]==0&&(w(e,q,Math.max(Math.min(a[2]-1,9),0)),U()&&console.debug(`GS switch display page ${a[2]-1}.`));break}default:if(a[0]<6){t(e,q)>9&&w(e,q,0);let l=a[0]-1<<1|a[1]>>6;t(e,q)==l&&w(e,de,Date.now()+3200),(n=t(e,be)[l])!=null&&n.length||(t(e,be)[l]=new Uint8Array(256));let i=t(e,be)[l];U()&&console.debug(`GS frame draw page ${l}.`);let s=a[1]&63;i.fill(0),a.subarray(2).forEach(function(f,u){let g=u+s,$=Math.floor(g/16),S=g%16,C=(S*4+$)*5,P=5,X=0;for(C-=S*4,$==3&&(P=1);X>4-X&1,X++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let h=function(a,n,l){let i=a[0],s=E.cc*n,o=E.rpn*n,f=`GS CH${n+1} `;i<3?(a.subarray(1).forEach((u,g)=>{[()=>{t(e,y)[s+v[0]]=u},()=>{t(e,I)[n]=u},()=>{let $=0;u<16?$=e.chRedir(u,l,!0):$=E.ch,t(e,F)[n]=$,n!=$&&(e.buildRchTree(),console.info(`${f}receives from CH${$+1}`))}][i+g]()}),e.dispatchEvent("voice",{part:n})):i<19||(i<44?a.subarray(1).forEach((u,g)=>{([()=>{t(e,Z)[n]=+!u},!1,()=>{e.setChType(n,u<<1,x.gs),console.debug(`${f}type: ${u?"drum ":"melodic"}${u||""}`)},()=>{t(e,T)[o+3]=u,t(e,O)[E.rpnt*n+2]=1},!1,()=>{t(e,y)[s+v[7]]=u},!1,!1,()=>{t(e,y)[s+v[10]]=u||128},!1,!1,()=>{console.debug(`${f}CC 1: cc${u}`)},()=>{console.debug(`${f}CC 2: cc${u}`)},()=>{t(e,y)[s+v[93]]=u},()=>{t(e,y)[s+v[91]]=u},!1,!1,()=>{t(e,T)[o+1]=u,t(e,O)[E.rpnt*n+1]=1},()=>{t(e,T)[o+2]=u,t(e,O)[E.rpnt*n+1]=1},()=>{t(e,y)[s+v[94]]=u}][i+g-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},m=function(a,n){let l=a[0],i=`GS CH${n+1} `;l<2?a.subarray(1).forEach((s,o)=>{[()=>{t(e,y)[E.cc*n+v[32]]=s},()=>{}][l+o]()}):l<32?console.warn(`Unknown GS misc address: ${l}`):l<35?a.subarray(1).forEach((s,o)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][s]}`),t(e,Ye)[n]=s,e.dispatchEvent("partefxtoggle",{part:n,active:s})}][l+o-32]()}):console.warn(`Unknown GS misc address: ${l}`)};t(this,ie).add([66,18,64,16],(a,n)=>{h(a,e.chRedir(9,n,!0),n)}).add([66,18,64,17],(a,n)=>{h(a,e.chRedir(0,n,!0),n)}).add([66,18,64,18],(a,n)=>{h(a,e.chRedir(1,n,!0),n)}).add([66,18,64,19],(a,n)=>{h(a,e.chRedir(2,n,!0),n)}).add([66,18,64,20],(a,n)=>{h(a,e.chRedir(3,n,!0),n)}).add([66,18,64,21],(a,n)=>{h(a,e.chRedir(4,n,!0),n)}).add([66,18,64,22],(a,n)=>{h(a,e.chRedir(5,n,!0),n)}).add([66,18,64,23],(a,n)=>{h(a,e.chRedir(6,n,!0),n)}).add([66,18,64,24],(a,n)=>{h(a,e.chRedir(7,n,!0),n)}).add([66,18,64,25],(a,n)=>{h(a,e.chRedir(8,n,!0),n)}).add([66,18,64,26],(a,n)=>{h(a,e.chRedir(10,n,!0),n)}).add([66,18,64,27],(a,n)=>{h(a,e.chRedir(11,n,!0),n)}).add([66,18,64,28],(a,n)=>{h(a,e.chRedir(12,n,!0),n)}).add([66,18,64,29],(a,n)=>{h(a,e.chRedir(13,n,!0),n)}).add([66,18,64,30],(a,n)=>{h(a,e.chRedir(14,n,!0),n)}).add([66,18,64,31],(a,n)=>{h(a,e.chRedir(15,n,!0),n)}).add([66,18,64,64],(a,n)=>{m(a,e.chRedir(9,n,!0))}).add([66,18,64,65],(a,n)=>{m(a,e.chRedir(0,n,!0))}).add([66,18,64,66],(a,n)=>{m(a,e.chRedir(1,n,!0))}).add([66,18,64,67],(a,n)=>{m(a,e.chRedir(2,n,!0))}).add([66,18,64,68],(a,n)=>{m(a,e.chRedir(3,n,!0))}).add([66,18,64,69],(a,n)=>{m(a,e.chRedir(4,n,!0))}).add([66,18,64,70],(a,n)=>{m(a,e.chRedir(5,n,!0))}).add([66,18,64,71],(a,n)=>{m(a,e.chRedir(6,n,!0))}).add([66,18,64,72],(a,n)=>{m(a,e.chRedir(7,n,!0))}).add([66,18,64,73],(a,n)=>{m(a,e.chRedir(8,n,!0))}).add([66,18,64,74],(a,n)=>{m(a,e.chRedir(10,n,!0))}).add([66,18,64,75],(a,n)=>{m(a,e.chRedir(11,n,!0))}).add([66,18,64,76],(a,n)=>{m(a,e.chRedir(12,n,!0))}).add([66,18,64,77],(a,n)=>{m(a,e.chRedir(13,n,!0))}).add([66,18,64,78],(a,n)=>{m(a,e.chRedir(14,n,!0))}).add([66,18,64,79],(a,n)=>{m(a,e.chRedir(15,n,!0))}),t(this,me).add([54,65],(a,n)=>{e.switchMode("x5d");let l=(a[1]<<7)+a[0],i=(a[3]<<7)+a[2],s=e.chRedir(l&15,n,!0),o=E.cc*s;[()=>{i<1||(i<101?(e.setChType(s,e.CH_MELODIC,x.x5d),t(e,I)[s]=i-1,t(e,y)[o+v[0]]=82):i<229?(e.setChType(s,e.CH_MELODIC,x.x5d),t(e,I)[s]=i-101,t(e,y)[o+v[0]]=56):(e.setChType(s,e.CH_DRUMS,x.x5d),t(e,I)[s]=aa[i-229]||0,t(e,y)[o+v[0]]=62)),e.dispatchEvent("voice",{part:s})},()=>{t(e,y)[o+v[7]]=i},()=>{i<31&&(t(e,y)[o+v[10]]=Math.round((i-15)*4.2+64))},()=>{t(e,y)[o+v[93]]=it(i)},()=>{t(e,y)[o+v[91]]=it(i)},()=>{t(e,T)[s*E.rpn+3]=i>8191?i-16320:64+i,t(e,O)[E.rpnt*s+2]=1},()=>{t(e,T)[s*E.rpn+1]=i>8191?i-16320:64+i,t(e,O)[E.rpnt*s+1]=1},()=>{i>0&&(t(e,T)[s*E.rpn]=i,t(e,O)[E.rpnt*s]=1)},()=>{}][l>>4]()}).add([54,76,0],(a,n)=>{e.switchMode("x5d",!0);let l="",i=82,s=0,o=0,f="MSB PRG LSB NME";le(a,function(u,g){if(g<16400){let $=g%164;switch(!0){case $<10:{u>31&&(l+=String.fromCharCode(u));break}case $==11:{f+=` -${i} ${s} ${o} ${l.trim().replace("Init Voice","")}`,s++,l="";break}}s>99&&(i=90,s=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(f),U()&&console.debug(f),e.forceVoiceRefresh()}).add([54,77,0],(a,n)=>{e.switchMode("x5d",!0);let l="",i=90,s=0,o=0,f="MSB PRG LSB NME";le(a,function(u,g){if(g<13600){let $=g%136;switch(!0){case $<10:{u>31&&(l+=String.fromCharCode(u));break}case $==11:{f+=` -${i} ${s} ${o} ${l.trim().replace("Init Combi","")}`,s++,l="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f),U()&&console.debug(f),e.forceVoiceRefresh()}).add([54,78],(a,n)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,n)=>{e.switchMode("x5d",!0),le(a,(l,i)=>{i>0&&i<3&&(e.setEffectType(i-1,44,l),e.dispatchEvent(`efx${["reverb","chorus"][i-1]}`,e.getEffectType(i-1)))})}).add([54,104],(a,n)=>{e.switchMode("x5d",!0),le(a,function(l,i,s,o){if(i<192){let f=e.chRedir(Math.floor(i/12),n,!0),u=f*E.cc;switch(i%12){case 0:{l<128?(e.setChType(f,e.CH_MELODIC,x.x5d),t(e,y)[u+v[0]]=82,t(e,I)[f]=l):(e.setChType(f,e.CH_DRUMS,x.x5d),t(e,y)[u+v[0]]=62,t(e,I)[f]=aa[l-128]),l>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{t(e,y)[u+v[7]]=l;break}case 2:{t(e,T)[f*E.rpn+3]=l>127?l-192:64+l,t(e,O)[E.rpnt*f+2]=1;break}case 3:{t(e,T)[f*E.rpn+1]=l>127?l-192:64+l,t(e,O)[E.rpnt*f+1]=1;break}case 4:{l<31&&(t(e,y)[u+v[10]]=Math.round((l-15)*4.2+64));break}case 5:{let g=l>>4,$=l&15;t(e,y)[u+v[91]]=it($),t(e,y)[u+v[93]]=it(g);break}case 10:break;case 11:{let g=e.chRedir(l&15,n,!0),$=l>>4;t(e,F)[f]=l,(g!=f||$)&&(console.info(`X5D Part CH${f+1} receives from CH${g+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(i-192,n,!0)}})}),t(this,ie).add([22,18,127],a=>{e.switchMode("mt32",!0),w(e,B,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,n,l)=>{e.switchMode("mt32");let i=e.chRedir(l,n,!0),s=a[1];a.subarray(2).forEach((o,f)=>{let u=f+s;t(e,ke)[u+(i-1)*16]=o,([!1,()=>{let g=t(e,ke)[i-1<<4];if(g<3){if(t(e,he)[i]=1,g==2)for(let $=0;${t(e,T)[i*E.rpn+3]=o+40,t(e,O)[E.rpnt*i+2]=1},()=>{t(e,T)[i*E.rpn+1]=o+14,t(e,O)[E.rpnt*i+1]=1},()=>{t(e,T)[i*E.rpn]=o,t(e,O)[E.rpnt*i]=1},!1,()=>{t(e,y)[E.cc*i+v[91]]=o?127:0},!1,()=>{t(e,y)[E.cc*i+v[7]]=o},()=>{t(e,y)[E.cc*i+v[10]]=Math.ceil(o*9.05)}][u]||(()=>{}))()})}).add([22,18,1],(a,n,l)=>{e.switchMode("mt32");let i=l&7;console.debug(`MT-32 slot #${l+1} Drum: ${a}`);let s=a[0]<<7|a[1];a.subarray(2).forEach((o,f)=>{let u=f+s,g=(u>>2)+24,$=u&3,S=i*E.dpn;if(U()&&console.debug(`MT-32 temp drum note ${g} param ${$}: ${o}`),g<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${g}`);return}[()=>{},()=>{t(e,j)[(S+ae[26])*E.dnc+g]=Math.round(o*1.27)},()=>{t(e,j)[(S+ae[26])*E.dnc+g]=o*9+1&127},()=>{t(e,j)[(S+ae[26])*E.dnc+g]=o?127:0}][$]()})}).add([22,18,2],(a,n,l)=>{e.switchMode("mt32");let i=e.chRedir(l,n,!0),s=a[1]+(a[0]<<7);s<10&&(t(e,he)[i]=1),a.subarray(2).forEach((o,f)=>{let u=f+s;u<14&&(t(e,ne)[(i-1)*E.cmt+u]=o)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(a,n,l)=>{e.switchMode("mt32");let i=l&7;if(a[0]){let s=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((o,f)=>{let u=f+s,g=(u>>2)+24,$=u&3,S=i*E.dpn;if(U()&&console.debug(`MT-32 dev drum note ${g} param ${$}: ${o}`),g<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${g}`);return}[()=>{},()=>{t(e,j)[(S+ae[26])*E.dnc+g]=Math.round(o*1.27)},()=>{t(e,j)[(S+ae[26])*E.dnc+g]=o*9+1&127},()=>{t(e,j)[(S+ae[26])*E.dnc+g]=o?127:0}][$]()})}else{let s=a[1];a.subarray(2).forEach((o,f)=>{let u=f+s;t(e,ke)[u]=o;let g=e.chRedir(1+(u>>4),n,!0),$=u&15;([!1,()=>{let S=t(e,ke)[g-1<<4];if(S<3)if(t(e,he)[g]=1,S==2)for(let C=0;C{t(e,T)[g*E.rpn+3]=o+40,t(e,O)[E.rpnt*g+2]=1},()=>{t(e,T)[g*E.rpn+1]=o+14,t(e,O)[E.rpnt*g+1]=1},()=>{t(e,T)[g*E.rpn]=o,t(e,O)[E.rpnt*g]=1},!1,()=>{t(e,y)[E.cc*g+v[91]]=o?127:0},!1,()=>{t(e,y)[E.cc*g+v[7]]=o},()=>{t(e,y)[E.cc*g+v[10]]=Math.ceil(o*9.05)}][$]||(()=>{}))()})}}).add([22,18,4],(a,n,l)=>{e.switchMode("mt32");let i=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((o,f)=>{let u=f+i,g=e.chRedir(Math.floor(u/246+1),n,!0),$=u%246;$<14&&(t(e,ne)[(g-1)*E.cmt+$]=o),$<10&&(t(e,he)[g]=1),s.indexOf(g)<0&&s.push(g)}),s.forEach(o=>{e.dispatchEvent("voice",{part:o})})}).add([22,18,5],(a,n,l)=>{e.switchMode("mt32");let i=(a[0]<<7)+a[1];a.subarray(2).forEach((s,o)=>{let f=i+o,u=Math.floor(f/8),g=f&7,$=u*8;t(e,We)[f]=s,([!1,()=>{let S=t(e,We)[$];if(S<3){let C="";if(S==2){let P=E.cmt*u;C=`MT-m:${s.toString().padStart(3,"0")}`}else C=e.baseBank.get(0,s+(S<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:u}),e.userBank.load(`MSB LSB PRG NME -000 127 ${u} ${C}`,!0)}}][g]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,n,l)=>{e.switchMode("mt32");let i=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((s,o)=>{let f=i+o;f>1)*E.cmt+f]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(a,n,l)=>{e.switchMode("mt32");let i=a[1],s=!1,o=function(f,u){t(e,F)[u-12]=f,s=!0};a.subarray(2).forEach((f,u)=>{let g=u+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,o,o,o,o,o,o,o,o,o,()=>{w(e,L,f),e.dispatchEvent("mastervolume",t(e,L))}][g]||(()=>{}))(f,u)}),s&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let n=a[1],l=" ".repeat(n);a.subarray(2).forEach(i=>{i>31?l+=String.fromCharCode(i):l+=" "}),w(e,Ce,l.padStart(20," ")),w(e,Te,Date.now()+3200)}).add([22,18,82],(a,n)=>{let l=e.chRedir(0,n,!0);for(let i=0;i<16;i++)t(e,_).ano(l+i),i&&i<10&&(t(e,I)[l+i]=kt[i-1]);console.info("MT-32 alt reset complete.")}),t(this,me).add([66,0],(a,n)=>{e.switchMode("ns5r",!0),w(e,B,!1),console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,n)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),w(e,B,!1)}).add([66,18,0,0],(a,n)=>{let l=a[0];switch(l){case 124:case 126:case 127:{e.switchMode("ns5r",!0),w(e,B,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(l<10){let i=[0,0,0,0],s=(o,f)=>{i[f]=o};if(a.subarray(1).forEach((o,f)=>{[s,s,s,s,()=>{w(e,L,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,L))},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][l+f]()}),a[0]<4){let o=0;i.forEach(f=>{o=o<<4,o+=f}),o-=1024}}}}).add([66,18,0,1],(a,n)=>{}).add([66,18,0,2],(a,n)=>{}).add([66,18,1],(a,n)=>{let l=e.chRedir(a[0],n,!0),i=l*E.cc,s=a[1],o=`NS5R CH${l+1} `;a.subarray(2).forEach((f,u)=>{let g=s+u;g<3?([()=>{t(e,y)[i+v[0]]=f||121},()=>{t(e,y)[i+v[32]]=f},()=>{t(e,I)[l]=f}][g](),e.dispatchEvent("voice",{part:l})):g<8||(g<14?[()=>{let $=e.chRedir(f,n,!0);t(e,F)[l]=$,l!=$&&(e.buildRchTree(),console.info(`${o}receives from CH${$+1}`))},()=>{t(e,Z)[l]=+!f},()=>{e.setChType(l,f,x.ns5r),console.debug(`${o}type: ${st[f]}`)},()=>{t(e,T)[E.rpn*l+3]=f,t(e,O)[E.rpnt*l+2]=1},()=>{},()=>{}][g-8]():g<16||(g<33?[()=>{t(e,y)[i+v[7]]=f},()=>{t(e,y)[i+v[11]]=f},()=>{},()=>{},()=>{t(e,y)[i+v[10]]=f||128},()=>{},()=>{},()=>{t(e,y)[i+v[93]]=f},()=>{t(e,y)[i+v[91]]=f},()=>{t(e,y)[i+v[76]]=f},()=>{t(e,y)[i+v[77]]=f},()=>{t(e,y)[i+v[78]]=f},()=>{t(e,y)[i+v[74]]=f},()=>{t(e,y)[i+v[71]]=f},()=>{t(e,y)[i+v[73]]=f},()=>{t(e,y)[i+v[75]]=f},()=>{t(e,y)[i+v[72]]=f}][g-16]():g<112||g<114&&[()=>{t(e,y)[i+v[5]]=f},()=>{t(e,y)[i+v[65]]=f}][g-112]()))})}).add([66,18,8,0],(a,n)=>{let l=a[0];if(l<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let i=l-32;w(e,de,Date.now()+3200),w(e,q,10),t(e,te,pe).fill(0);let s=a.subarray(1),o=4;s.forEach(function(f,u){let g=u+i,$=g>>4,S=g&15;if(g<80){let C=$>3,P=0,X=$0;)t(e,te,pe)[S*32+$*7+(X-P)]=C&1,C=C>>1,P++}})}}).add([66,18,48],(a,n,l)=>{c(0,a)}).add([66,18,49],(a,n,l)=>{c(1,a)}).add([66,18,50],(a,n,l)=>{c(2,a)}).add([66,18,51],(a,n,l)=>{c(3,a)}).add([66,18,52],(a,n,l)=>{c(4,a)}).add([66,18,53],(a,n,l)=>{c(5,a)}).add([66,18,54],(a,n,l)=>{c(6,a)}).add([66,18,55],(a,n,l)=>{c(7,a)}).add([66,52],(a,n)=>{e.switchMode("ns5r",!0),w(e,B,!1);let l="";le(a,(i,s)=>{s<8?(i>31&&(l+=String.fromCharCode(i)),s==7&&(e.aiEfxName=l)):s<10&&(e.setEffectType(s-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(a,n)=>{e.switchMode("ns5r",!0),w(e,B,!1),le(a,function(l,i){switch(!0){case i<2944:{let s=e.chRedir(Math.floor(i/92),n,!0),o=s*E.cc;switch(i%92){case 0:{t(e,y)[o+v[0]]=l||121,e.dispatchEvent("voice",{part:s});break}case 1:{t(e,y)[o+v[32]]=l,e.dispatchEvent("voice",{part:s});break}case 2:{t(e,I)[s]=l,l>0&&e.setChActive(s,1),e.dispatchEvent("voice",{part:s});break}case 3:{let f=e.chRedir(l,n,!0);t(e,F)[s]=f,s!=f&&(console.info(`NS5R CH${s+1} receives from CH${f+1}.`),e.buildRchTree())}case 7:break;case 8:{t(e,T)[s*E.rpn+3]=l<40||l>88?l+(l>63?-192:64):l,t(e,O)[E.rpnt*s+2]=1;break}case 9:case 10:{t(e,y)[o+v[7]]=l;break}case 11:{t(e,y)[o+v[11]]=l;break}case 14:{t(e,y)[o+v[10]]=l||128;break}case 19:{t(e,y)[o+v[93]]=l;break}case 20:{t(e,y)[o+v[91]]=l;break}case 84:{t(e,y)[o+v[65]]=l;break}case 85:{t(e,y)[o+v[5]]=l;break}}break}case i<3096:break;case i<3134:break;case i<8566:break}})}).add([66,54],(a,n)=>{e.switchMode("ns5r",!0);let l="",i=80,s=0,o=0,f="MSB PRG LSB NME";le(a,function(u,g){let $=g%158;switch(!0){case $<10:{u>31&&(l+=String.fromCharCode(u));break}case $==11:{i=u&127;break}case $==12:{o=u&127;break}case $==13:{f+=` -${i} ${s} ${o} ${l.trim().replace("Init Voice","")}`,s++,l="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(f),U()&&console.debug(f),e.forceVoiceRefresh()}).add([66,55],(a,n)=>{e.switchMode("ns5r",!0);let l="",i=88,s=0,o=0,f="MSB PRG LSB NME";le(a,function(u,g){let $=g%126;switch(!0){case $<10:{u>31&&(l+=String.fromCharCode(u));break}case $==11:break;case $==12:break;case $==13:{f+=` -${i} ${s} ${o} ${l.trim().replace("Init Combi","")}`,s++,l="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(f),U()&&console.debug(f),e.forceVoiceRefresh()}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let n=new Uint8Array(5760);le(a,(l,i,s)=>{if(i<720)for(let o=0;o<8;o++)n[i*8+o]=l>>7-o&1}),e.dispatchEvent("screen",{type:"ns5r",data:n})}).add([76],(a,n,l)=>{t(e,me).run([66,...a],n,l)}),t(this,Be).add([16,0,8,0],(a,n,l)=>{let i=(a[2]<<4)+a[3],s="K11 ";([()=>{e.switchMode("k11",!0),w(e,B,!1),w(e,re,i?4:0),console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,i),console.debug(`${s}reverb type: ${i}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${s}reverb time: ${i}`)},()=>{console.debug(`${s}reverb time: ${i}`)},()=>{console.debug(`${s}reverb predelay: ${i}`)},()=>{console.debug(`${s}reverb predelay: ${i}`)},()=>{console.debug(`${s}depth high: ${i}`)},()=>{console.debug(`${s}depth high: ${i}`)},()=>{console.debug(`${s}depth low: ${i}`)},()=>{console.debug(`${s}depth low: ${i}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,n,l)=>{let i=e.chRedir(a[1],n,!0),s=E.cc*i,o=E.rpn*i,f=(a[3]<<4)+a[4],u=`K11 CH${i+1} `;([()=>{f<128?(e.setChType(i,e.CH_MELODIC,x.k11),t(e,y)[s+v[0]]=0,t(e,I)[i]=f):(e.setChType(i,e.CH_DRUMS,x.k11),t(e,I)[i]=f-128),e.dispatchEvent("voice",{part:i})},()=>{let g=e.chRedir(f,n,!0);t(e,F)[i]=g,i!=g&&(e.buildRchTree(),console.info(`${u}receives from CH${g+1}`))},()=>{t(e,y)[s+v[7]]=f},()=>{uupThis.setChActive(i,f)},()=>{t(e,y)[s+v[10]]=f},()=>{t(e,T)[o+3]=f+40,t(e,O)[E.rpnt*i+2]=1},()=>{t(e,T)[o+1]=f>>1,t(e,T)[o+2]=f&1,t(e,O)[E.rpnt*i+1]=1},()=>{t(e,y)[s+v[91]]=f?127:0},()=>{},()=>{t(e,y)[s+v[74]]=f},()=>{t(e,y)[s+v[73]]=f},()=>{t(e,y)[s+v[72]]=f}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,n,l)=>{let i=(a[2]<<4)+a[3],s="GMLX ";([()=>{console.debug(`${s}reverb type: ${i}`)},()=>{console.debug(`${s}reverb time: ${i}`)},()=>{console.debug(`${s}reverb predelay: ${i}`)},()=>{console.debug(`${s}depth high: ${i}`)},()=>{console.debug(`${s}depth low: ${i}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,n,l)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],n,!0),o=s*E.cc;[()=>{i<128?(e.setChType(s,e.CH_MELODIC,x.k11),t(e,y)[o+v[0]]=0,t(e,y)[o+v[32]]=0,t(e,I)[s]=i):i<160?(e.setChType(s,e.CH_MELODIC,x.k11),t(e,y)[o+v[0]]=0,t(e,y)[o+v[32]]=7,t(e,I)[s]=i-100):(e.setChType(s,e.CH_DRUMS,x.k11),t(e,y)[o+v[0]]=122,t(e,y)[o+v[32]]=0,t(e,I)[s]=i-160),e.dispatchEvent("voice",{part:s})},()=>{let f=e.chRedir(i,n,!0);t(e,F)[s]=f,s!=f&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${f+1}`))}][a[0]]()}).add([16,0,9,4],(a,n,l)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],n,!0),o=s*E.cc,f=s*E.rpn,u=`GMLX CH${s+1} `;[()=>{e.setChActive(s,i)},()=>{t(e,y)[o+v[7]]=i},()=>{t(e,y)[o+v[10]]=i},()=>{t(e,y)[o+v[91]]=i?127:0},()=>{t(e,T)[f+3]=i+40,t(e,O)[E.rpnt*s+2]=1},()=>{t(e,T)[f+1]=i,t(e,O)[E.rpnt*s+1]=1},()=>{t(e,T)[f]=i,t(e,O)[E.rpnt*s]=1},()=>{}][a[0]]()}),t(this,Ne).add([66,93,64],(a,n,l)=>{let i=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{w(e,L,i*129/16383*100),e.dispatchEvent("mastervolume",t(e,L));break}case 5:{i-64;break}case 6:{console.debug(`SG global reverb: ${i?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(a[1]){case 48:{console.debug(`SG reverb type: ${$t[i]}`);break}}break}default:if(a[0]>>4==1){let s=e.chRedir(a[0]&15,n,!0);if(a[1]==2){let o=e.chRedir(i,n,!0);t(e,F)[s]=o,s!=o&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${o+1}`))}else a[1]==19&&(t(e,y)[E.cc*s+v[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,He).add([9],(a,n,l)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),t(this,se).add([127,0],(a,n,l)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...a]);t(e,se).run(i,n,l)}).add([127,1,0,0],(a,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES system ",s=a[0];a.subarray(1).forEach((o,f)=>{([()=>{w(e,L,o*12900/16383),e.dispatchEvent("mastervolume",t(e,L))}][s+f]||(()=>{console.info(`Unrecognized ${i}ID: ${s+f}`)}))()})}).add([127,1,0,0,14],(a,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES bulk header ",s=[];s[95]=(o,f,u)=>{console.debug(`${i}multi edit buffer: ${o[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES bulk footer ",s=[];s[95]=(o,f,u)=>{console.debug(`${i}multi edit buffer: ${o[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,n,l)=>{e.switchMode("s90es");let i=e.chRedir(a[0],n,!0),s=E.cc*i,o=a[1],f=`S90/Motif ES bulk CH${i<16?i+1:"U"+(i-95)} `;console.debug(f,a),!(a[0]>15)&&a.subarray(2).forEach((u,g)=>{([()=>{t(e,y)[s+v[0]]=u,e.dispatchEvent("voice",{part:i})},()=>{u&&e.setChActive(i,1),t(e,y)[s+v[32]]=u,e.setChType(i,[32,40].indexOf(u)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,A),!0),e.dispatchEvent("voice",{part:i})},()=>{u&&e.setChActive(i,1),t(e,I)[i]=u,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(u,n,!0);t(e,F)[i]=$,i!=$&&(e.buildRchTree(),console.info(`${f}receives from CH${$+1}`))},()=>{t(e,Z)[i]=u?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{t(e,y)[s+v[7]]=u},()=>{t(e,y)[s+v[10]]=u},!1,!1,!1,()=>{t(e,y)[s+v[91]]=u},()=>{t(e,y)[s+v[93]]=u},()=>{t(e,y)[s+v[94]]=u},()=>{t(e,y)[s+v[128]]=u},()=>{},()=>{t(e,y)[s+v[74]]=u},()=>{t(e,y)[s+v[71]]=u},!1,()=>{t(e,y)[s+v[65]]=u},()=>{t(e,y)[s+v[5]]=u},()=>{}][o+g]||(()=>{}))()})}).add([127,1,54,16],(a,n,l)=>{e.switchMode("s90es");let i=a[0];a.subarray(1).forEach((s,o)=>{let u=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let g=s-64},()=>{let g=je[s]},()=>{let g=s/10},()=>{let g=s}][i+o&3]||(()=>{}))()})}),t(this,ie).add([0,72,18,0,0,0,0],(a,n,l)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,n,l)=>{let i=a[0]>>5,s=a[0]&31;switch(i){case 0:{console.debug(`Unknown SD-90 global effects message: -%o`,a);break}case 1:{let o=e.chRedir(s,n,!0),f=a[1],u=o*E.cc;a.subarray(2).forEach((g,$)=>{let S=f+$;S<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,y)[u+v[0]]=g,g){case 104:case 105:case 106:case 107:case 120:{t(e,R)[o]||e.setChType(o,e.CH_DRUMS);break}default:t(e,R)[o]&&e.setChType(o,e.CH_MELODIC)}e.dispatchEvent("voice",{part:o})},()=>{t(e,y)[u+v[32]]=g,e.dispatchEvent("voice",{part:o})},()=>{t(e,I)[o]=g,e.dispatchEvent("voice",{part:o})},()=>{t(e,y)[u+v[7]]=g},()=>{t(e,y)[u+v[10]]=g},()=>{},()=>{},()=>{g<2&&(t(e,Z)[o]=g)},()=>{g<2&&(t(e,y)[u+v[68]]=g?127:0)},()=>{},()=>{g<2&&(t(e,y)[u+v[65]]=g?127:0)},()=>{t(e,y)[u+v[5]]=g&15<<4|t(e,y)[u+v[5]]&15},()=>{t(e,y)[u+v[5]]=g&15|(t(e,y)[u+v[5]]&240)>>4},()=>{t(e,y)[u+v[74]]=g},()=>{t(e,y)[u+v[71]]=g},()=>{t(e,y)[u+v[73]]=g},()=>{t(e,y)[u+v[72]]=g},0,0,0,0,0,0,0,()=>{t(e,y)[u+v[128]]=g},()=>{t(e,y)[u+v[93]]=g},()=>{t(e,y)[u+v[91]]=g},0,0,()=>{t(e,y)[u+v[75]]=g},()=>{t(e,y)[u+v[76]]=g},()=>{t(e,y)[u+v[77]]=g},()=>{t(e,y)[u+v[78]]=g}][S]||(()=>{}))():S<63||(S<64?t(e,R)[o]?t(e,y)[u+v[0]]=104|g:t(e,y)[u+v[0]]=96|g:console.debug(`Unknown SD-90 global CH${o+1} param setup message: -%o`,a))});break}case 2:{let o=e.chRedir(s,n,!0),f=a[1];console.debug(`Unknown SD-90 global CH${o+1} MIDI setup message: +`),a.slice(0,2)){case"@I":{w(this,B,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(n=a.slice(2))==null?void 0:n.trimLeft()});break}case"@K":{w(this,B,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(l=a.slice(2))==null?void 0:l.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{w(this,B,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(i=a.slice(2))==null?void 0:i.trimLeft()});break}case"@T":{w(this,B,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(s=a.slice(2))==null?void 0:s.trimLeft()});break}case"@V":{w(this,B,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(o=a.slice(2))==null?void 0:o.trimLeft()});break}case"XF":{let h=a.slice(2).split(":");switch(h[0]){case"hd":{h.slice(1).forEach((u,g)=>{u.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][g],data:u})});break}case"ln":{h.slice(1).forEach((u,g)=>{u.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][g],data:u})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:t(this,B)?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` +`).forEach((h,u)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:h,mask:u!=0})})}},t(this,K)[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},t(this,K)[3]=function(a,n){n<1&&t(this,Pe)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},t(this,K)[4]=function(a,n){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},t(this,K)[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},t(this,K)[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},t(this,K)[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},t(this,K)[32]=function(a){w(this,Pe,a[0]+1)},t(this,K)[33]=function(a,n){t(e,Me)[n]=a+1},t(this,K)[81]=function(a,n){w(e,Ze,a/1e3)},t(this,K)[127]=function(a,n){t(e,Ie).run(a,n)},t(this,Ie).default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},t(this,Ie).add([67,0,1],function(a,n){t(e,Me)[n]=a[0]+1}),w(this,Ue,new oe("universal non-realtime")),w(this,Le,new oe("universal realtime")),w(this,se,new oe("Yamaha")),w(this,ie,new oe("Roland")),w(this,me,new oe("Korg")),w(this,Be,new oe("Kawai")),w(this,Ne,new oe("Akai")),w(this,He,new oe("Casio"));let r=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. +%o`,a)};t(this,Ue).default=r,t(this,Le).default=r,t(this,se).default=r,t(this,ie).default=r,t(this,me).default=r,t(this,Be).default=r,t(this,Ne).default=r,t(this,He).default=r,t(this,Ue).add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),w(e,B,t(e,B)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),t(this,Le).add([4,1],a=>{w(e,L,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,L))}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64),t(this,se).add([76,0,0],a=>{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),w(e,B,!1),console.info("MIDI reset: XG");break}default:{let n=[0,0,0,0],l=(i,s)=>{n[s]=i};if(a.subarray(1).forEach((i,s)=>{let o=s+a[0];([l,l,l,l,h=>{w(this,L,h*129/16383*100),e.dispatchEvent("mastervolume",t(e,L))},h=>{},h=>{}][o]||(()=>{}))(i,s)}),a[0]<4){let i=0;n.forEach(s=>{i=i<<4,i+=s}),i-=1024}}}}).add([76,2,1],a=>{let n="XG ";a[0]<32?(n+="reverb ",a.subarray(1).forEach((l,i)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${n}main type: ${rt[s]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{e.setEffectTypeRaw(0,!0,s),console.debug(`${n}sub type: ${s+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{console.debug(`${n}time: ${Gt(s)}s`)},s=>{console.debug(`${n}diffusion: ${s}`)},s=>{console.debug(`${n}initial delay: ${s}`)},s=>{console.debug(`${n}HPF cutoff: ${je[s]}Hz`)},s=>{console.debug(`${n}LPF cutoff: ${je[s]}Hz`)},s=>{console.debug(`${n}width: ${s}`)},s=>{console.debug(`${n}height: ${s}`)},s=>{console.debug(`${n}depth: ${s}`)},s=>{console.debug(`${n}wall type: ${s}`)},s=>{console.debug(`${n}dry/wet: ${s}`)},s=>{console.debug(`${n}send: ${Y(s)}dB`)},s=>{console.debug(`${n}pan: ${s-64}`)},!1,!1,s=>{console.debug(`${n}delay: ${s}`)},s=>{console.debug(`${n}density: ${s}`)},s=>{console.debug(`${n}balance: ${s}`)},s=>{},s=>{console.debug(`${n}feedback: ${s}`)},s=>{}][a[0]+i]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(l)})):a[0]<64?(n+="chorus ",a.subarray(1).forEach((l,i)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${n}main type: ${rt[s]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{e.setEffectTypeRaw(1,!0,s),console.debug(`${n}sub type: ${s+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{console.debug(`${n}LFO: ${Ht[s]}Hz`)},s=>{},s=>{console.debug(`${n}feedback: ${s}`)},s=>{console.debug(`${n}delay offset: ${_t(s)}ms`)},s=>{},s=>{console.debug(`${n}low: ${je[s]}Hz`)},s=>{console.debug(`${n}low: ${s-64}dB`)},s=>{console.debug(`${n}high: ${je[s]}Hz`)},s=>{console.debug(`${n}high: ${s-64}dB`)},s=>{console.debug(`${n}dry/wet: ${s}`)},s=>{console.debug(`${n}send: ${Y(s)}dB`)},s=>{console.debug(`${n}pan: ${s-64}`)},s=>{console.debug(`${n}to reverb: ${Y(s)}dB`)},!1,s=>{},s=>{},s=>{},s=>{console.debug(`${n}LFO phase diff: ${(s-64)*3}deg`)},s=>{console.debug(`${n}input mode: ${s?"stereo":"mono"}`)},s=>{}][a[0]-32+i]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(l)})):a[0]<86?(n+="variation ",a.subarray(1).forEach((l,i)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${n}main type: ${rt[s]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},s=>{e.setEffectTypeRaw(2,!0,s),console.debug(`${n}sub type: ${s+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+i]||function(){})(l)})):a[0]<97?(n+="variation ",a.subarray(1).forEach((l,i)=>{[s=>{console.debug(`${n}send: ${Y(s)}dB`)},s=>{console.debug(`${n}pan: ${s-64}`)},s=>{console.debug(`${n}to reverb: ${Y(s)}dB`)},s=>{console.debug(`${n}to chorus: ${Y(s)}dB`)},s=>{console.debug(`${n}connection: ${s?"system":"insertion"}`)},s=>{console.debug(`${n}channel: CH${s+1}`)},s=>{console.debug(`${n}mod wheel: ${s-64}`)},s=>{console.debug(`${n}bend wheel: ${s-64}`)},s=>{console.debug(`${n}channel after touch: ${s-64}`)},s=>{console.debug(`${n}AC1: ${s-64}`)},s=>{console.debug(`${n}AC2: ${s-64}`)}][a[0]-86+i](l)})):a[0]>111&&a[0]<118?n+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((n,l)=>{let i=l+a[0];if(i==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][n]}`);else{let s=i-1>>2,o=i-1&3,h=`XG EQ ${s} ${["gain","freq","Q","shape"][o]}: `;[()=>{console.debug(`${h}${n-64}dB`)},()=>{console.debug(`${h}${n} (raw)`)},()=>{console.debug(`${h}${n/10}`)},()=>{console.debug(`${h}${["shelf","peak"][+!!n]}`)}][o]()}})}).add([76,3],a=>{let n=a[0],l=a[1],i=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((s,o)=>{([h=>{e.setEffectTypeRaw(3+n,!1,h),console.info(`${i}main type: ${rt[h]}`),e.dispatchEvent(`efxinsert${n}`,e.getEffectType(3+n))},h=>{e.setEffectTypeRaw(3+n,!0,h),console.debug(`${i}sub type: ${h+1}`),e.dispatchEvent(`efxinsert${n}`,e.getEffectType(3+n))}][l+o]||function(){})(s)})}).add([76,6,0],a=>{let n=a[0];n<64?e.setLetterDisplay(a.subarray(1),"XG letter display",n):w(e,Te,Date.now())}).add([76,7,0],a=>{let n=a[0];w(e,q,0),w(e,de,Date.now()+3200),t(e,te,pe).fill(0);let l=a.subarray(1);for(let i=0;i>6-$&1,$++})}).add([76,8],(a,n)=>{let l=e.chRedir(a[0],n,!0),i=a[1],s=E.cc*l,o=`XG CH${l+1} `,h=`Unknown XG part address ${i}.`;a.subarray(2).forEach((u,g)=>{i<1?console.debug(h):i<41?([()=>{t(e,y)[s+v[0]]=u,e.dispatchEvent("voice",{part:l})},()=>{t(e,y)[s+v[32]]=u,e.dispatchEvent("voice",{part:l})},()=>{t(e,I)[l]=u,e.dispatchEvent("voice",{part:l})},()=>{let $=e.chRedir(u,n,!0);t(e,F)[l]=$,l!=$&&(e.buildRchTree(),console.info(`${o}receives from CH${$+1}`))},()=>{t(e,Z)[l]=+!u},()=>{},()=>{e.setChType(l,u,x.xg),console.debug(`${o}type: ${st[u]||u}`)},()=>{t(e,T)[E.rpn*l+3]=u,t(e,O)[E.rpnt*l+2]=1},!1,!1,()=>{t(e,y)[s+v[7]]=u},!1,!1,()=>{t(e,y)[s+v[10]]=u||128},!1,!1,()=>{t(e,y)[s+v[128]]=u},()=>{t(e,y)[s+v[93]]=u},()=>{t(e,y)[s+v[91]]=u},()=>{t(e,y)[s+v[94]]=u},()=>{t(e,y)[s+v[76]]=u},()=>{t(e,y)[s+v[77]]=u},()=>{t(e,y)[s+v[78]]=u},()=>{t(e,y)[s+v[74]]=u},()=>{t(e,y)[s+v[71]]=u},()=>{t(e,y)[s+v[73]]=u},()=>{t(e,y)[s+v[75]]=u},()=>{t(e,y)[s+v[72]]=u}][i+g-1]||(()=>{}))():i<48?console.debug(h):i<111?i>102&&i<105&&(t(e,y)[s+v[[5,65][i&1]]]=u):i<114?console.debug(h):i<116?console.debug(`${o}EQ ${["bass","treble"][i&1]} gain: ${u-64}dB`):i<118?console.debug(h):i<120?console.debug(`${o}EQ ${["bass","treble"][i&1]} freq: ${u}`):console.debug(h)})}).add([76,9],(a,n)=>{let l=e.chRedir(a[0],n,!0),i=a[1],s=`PLG-150VL CH${l+1} `;a.subarray(2).forEach((o,h)=>{let u=h+i;switch(u){case 1:{console.info(`${s}breath mode: ${["system","breath","velocity","touch EG"][o]}`);break}case 0:case 27:case 28:break;default:if(u<27){let g=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][u-3>>1];u&1?u<23?(console.debug(`${s}${g} control source: ${Vt(o)}`),o&&o<96&&e.allocateAce(o)):console.debug(`${s}${g} scale break point: ${o}`):console.debug(`${s}${g} depth: ${o-64}`)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][a[0]]} for CH${a[2]+1}.`)}).add([73,0,0],(a,n)=>{let l=a[0],i="MU1000 System: ";a.subarray(1).forEach((s,o)=>{let h=l+o;h==8?console.debug(`${i}LCD contrast set to ${s}.`):h==18?(w(e,re,s?126:0),console.debug(`${i}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):h>=64&&h<69&&[()=>{e.dispatchEvent("channelactive",s)},()=>{s<8?(e.dispatchEvent("channelmin",s<<4),console.debug(`Octavia System: Minimum CH${(s<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{s<8?(e.dispatchEvent("channelmax",(s<<4)+15),console.debug(`Octavia System: Maximum CH${(s<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{w(e,ce,!!s),console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][h-64]()})}).add([73,10,0],(a,n)=>{let l=a[0],i=`MU1000 RS${t(e,ce)?"":" (ignored)"}: `;if(l<16)switch(l){case 2:{let s=e.chRedir(0,n,!0);t(e,ce)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${i}Show CH1~64`);break}case 3:{let s=e.chRedir(a[1]<<5,n,!0);t(e,ce)&&e.dispatchEvent("channelmin",s),t(e,ce)&&e.dispatchEvent("channelmax",s+31),console.info(`${i}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${i}unknown switch ${l} invoked.`)}else if(l<32){if(t(e,ce)){let s=e.chRedir(l-16+(t(e,et)<<4),n,!0);e.dispatchEvent("channelactive",s)}}else if(l<36){let s=e.chRedir(l-32<<4,n,!0);t(e,ce)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),w(e,et,l-32)),console.info(`${i}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(a,n)=>{let l=e.chRedir(a[0],n,!0),i=`PLG-100SG CH${l+1} `,s=Date.now();if(a[1]==0){let o="",h=0;a.subarray(2).forEach((u,g)=>{g%2==0?o+=Xt[u]||u.toString().padStart("0"):h+=u*13}),s>=t(e,Je)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${Ft(o)}`,amend:!0}),w(e,Je,s+Math.ceil(h/2)+t(e,Ze)),U()&&console.debug(`${i}vocals: ${o}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)});let d=function(a,n,l,i){},c=function(a,n){let l=a*E.dpn,i=n[0],s=n[1];n.subarray(2).forEach((o,h)=>{let u=h+s,g=-1;u<16?([()=>{g=24},()=>{g=25},()=>{g=26},()=>{},()=>{g=28},()=>{g=29},()=>{g=30},()=>{g=31},()=>{},()=>{},()=>{},()=>{g=20},()=>{g=21},()=>{g=22},()=>{g=23},()=>{}][u]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))():u<32||(u<40?([()=>{g=48},()=>{g=49},!1,!1,()=>{g=52},()=>{g=53}][u-32]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))():u<80||([()=>{g=36}][u-80]||(()=>{console.debug(`Unknown XG-style drum param ${u} on set ${a+1}.`)}))()),g>=0?(U()&&console.debug(l,g,i,o),t(e,j)[(l+ae[g])*E.dnc+i]=o):U()&&console.debug(`XG-style drum param ${u} has no writes.`)})},p=function(a,n,l){let i=a*E.dpn,s=(n<<7)+l[0];l.subarray(1).forEach((o,h)=>{let u=h+s,g=u&127,$=u>>7,S=-1;$>1&&([()=>{S=26},()=>{},()=>{S=28},()=>{S=29},()=>{S=30},()=>{},()=>{},()=>{S=31}][$-2]||(()=>{console.debug(`Unknown GS-style drum param ${$} on set ${a+1}.`)}))(),S>-1?(U()&&console.debug(i,S,g,o),t(e,j)[(i+ae[S])*E.dnc+g]=o):U()&&console.debug(`GS-style drum param ${$} has no writes.`)})};t(this,se).add([76,48],(a,n,l)=>{c(0,a)}).add([76,49],(a,n,l)=>{c(1,a)}).add([76,50],(a,n,l)=>{c(2,a)}).add([76,51],(a,n,l)=>{c(3,a)}).add([76,52],(a,n,l)=>{c(4,a)}).add([76,53],(a,n,l)=>{c(5,a)}).add([76,54],(a,n,l)=>{c(6,a)}).add([76,55],(a,n,l)=>{c(7,a)}),t(this,se).add([89,0],(a,n,l)=>{if(e.eprom){let i=a[0],s=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);U()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${i} bytes.`);let o=e.eprom.data;a.subarray(4).forEach((h,u)=>{let g=u>>3,$=u&7;if($==7)for(let S=0;S<7;S++)o[s+7*g+S]+=(h>>6-S&1)<<7;else o[s+7*g+$]=h})}}).add([89,1],(a,n,l)=>{let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];U()&&console.debug(`MU1000 EPROM jump to 0x${i.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=i)}).add([89,2],(a,n,l)=>{if(e.eprom){let i=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);U()&&console.debug(`MU1000 EPROM write to 0x${i.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;a.subarray(4).forEach((o,h)=>{let u=h>>3,g=h&7;if(g==7)for(let $=0;$<7;$++)s[i+7*u+$]+=(o>>6-$&1)<<7;else s[i+7*u+g]=o})}}).add([89,3],(a,n,l)=>{}),t(this,se).add([39,48],(a,n,l)=>{}).add([43,0,0],(a,n,l)=>{let i=[0,0,0,0],s=(o,h)=>{i[h]=o};if(a.subarray(1).forEach((o,h)=>{let u=h+a[0];[s,s,s,s,()=>{w(this,L,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,L))},()=>o-64,()=>o||128,()=>o,()=>o,()=>{console.debug(`TG300 variation on cc${o}.`)}][u](o,u)}),a[0]<4){let o=0;i.forEach(h=>{o=o<<4,o+=h}),o-=1024}}).add([43,1,0],(a,n,l)=>{}).add([43,2],(a,n,l)=>{let i=e.chRedir(a[0],n,!0),s=a[1],o=E.cc*i,h=`TG300 CH${i+1} `;a.subarray(2).forEach((u,g)=>{g<5?([()=>{},()=>{t(e,y)[o+v[0]]=u,e.dispatchEvent("voice",{part:i})},()=>{t(e,y)[o+v[32]]=u,e.dispatchEvent("voice",{part:i})},()=>{t(e,I)[i]=u,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(u,n,!0);t(e,F)[i]=$,i!=$&&(e.buildRchTree(),console.info(`${h}receives from CH${$+1}`))}][g+s]||(()=>{}))(u,g+s):g<21||(g<47?([()=>{t(e,Z)[i]=+!u},()=>{},()=>{},()=>{t(e,T)[E.rpn*i+3]=u,t(e,O)[E.rpnt*i+2]=1},()=>{},()=>{t(e,y)[o+v[7]]=u},!1,!1,()=>{t(e,y)[o+v[10]]=u||128},!1,!1,()=>{console.debug(`${h} AC1 at cc${u}`)},()=>{console.debug(`${h} AC2 at cc${u}`)},()=>{t(e,y)[o+v[128]]=u},()=>{t(e,y)[o+v[93]]=u},()=>{t(e,y)[o+v[91]]=u},()=>{t(e,y)[o+v[94]]=u},()=>{t(e,y)[o+v[76]]=u},()=>{t(e,y)[o+v[77]]=u},()=>{t(e,y)[o+v[74]]=u},()=>{t(e,y)[o+v[71]]=u},()=>{t(e,y)[o+v[73]]=u},()=>{t(e,y)[o+v[75]]=u},()=>{t(e,y)[o+v[72]]=u},()=>{t(e,y)[o+v[78]]=u}][g+s-21]||(()=>{}))(u,g+s):g<95||([()=>{t(e,y)[o+v[65]]=u},()=>{t(e,y)[o+v[5]]=u}][g+s-95]||(()=>{}))(u,g+s))})}).add([43,7,0],(a,n,l)=>{let i=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",i)}).add([43,7,1],(a,n,l)=>{w(e,q,0),w(e,de,Date.now()+3200),t(e,te,pe).fill(0),a.forEach(function(i,s){let o=Math.floor(s/16),h=s%16,u=(h*3+o)*7,g=7,$=0;for(u-=h*5,o==2&&(g=2);$>6-$&1,$++})}),t(this,ie).add([66,18,0,0,127],(a,n,l)=>{e.switchMode("gs",!0),t(e,y)[E.cc*9]=120,t(e,y)[E.cc*25]=120,t(e,y)[E.cc*41]=120,t(e,y)[E.cc*57]=120,w(e,re,3),w(e,B,!1),t(e,ve).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,n,l)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),t(e,y)[E.cc*9]=120,t(e,y)[E.cc*25]=120,t(e,y)[E.cc*41]=120,t(e,y)[E.cc*57]=120,w(e,B,!1),t(e,ve).fill(0),console.info("MIDI reset: GS");break}default:{let i=[0,0,0,0],s=(o,h)=>{i[h]=o};if(a.subarray(1).forEach((o,h)=>{let u=h+a[0];[s,s,s,s,g=>{w(this,L,g*129/16383*100),e.dispatchEvent("mastervolume",t(e,L))},g=>{},g=>{}][u](o,h)}),a[0]<4){let o=0;i.forEach(h=>{o=o<<4,o+=h}),o-=1024}}}}).add([66,18,64,1],a=>{let n=a[0];if(n<16){let l="".padStart(n," ");a.subarray(1).forEach((i,s)=>{l+=String.fromCharCode(Math.max(32,i))}),l=l.padEnd(16," "),console.debug(`GS patch name: ${l}`)}else n<48||(n<65?a.subarray(1).forEach((l,i)=>{let s=`GS ${n+i>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${$t[l]}`),e.setEffectType(0,40,l),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${l}ms`)},()=>{console.info(`${s}type: ${Kt[l]}`),e.setEffectType(1,40,16+l),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${Y(l)}`)},()=>{console.debug(`${s}to delay: ${Y(l)}`)}][n+i-48]||(()=>{}))()}):n<80?console.debug(`Unknown GS patch address: ${n}`):n<91?a.subarray(1).forEach((l,i)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${zt[l]}`),e.setEffectType(2,40,32+l),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${Y(l)}`)}][n+i-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${n}`))}).add([66,18,64,2],a=>{let n="GS EQ ";a.subarray(1).forEach((l,i)=>{([()=>{console.debug(`${n}low freq: ${[200,400][l]}Hz`)},()=>{console.debug(`${n}low gain: ${l-64}dB`)},()=>{console.debug(`${n}high freq: ${[3e3,6e3][l]}Hz`)},()=>{console.debug(`${n}high gain: ${l-64}dB`)}][a[0]+i]||function(){console.warn(`Unknown GS EQ address: ${a[0]+i}`)})()})}).add([66,18,64,3],a=>{let n="GS EFX ",l=function(i,s){let o=qt(t(e,J).subarray(10,12),s,i);o&&console.debug(`${n}${wt(t(e,J).subarray(10,12))} ${o}`)};a.subarray(1).forEach((i,s)=>{([()=>{e.setEffectTypeRaw(3,!1,32+i),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,i),console.info(`${n}type: ${wt(t(e,J).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,()=>{console.debug(`${n}to reverb: ${Y(i)}dB`)},()=>{console.debug(`${n}to chorus: ${Y(i)}dB`)},()=>{console.debug(`${n}to delay: ${Y(i)}dB`)},!1,()=>{console.debug(`${n}1 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${n}1 depth: ${i-64}`)},()=>{console.debug(`${n}2 source: ${i}`),i&&i<96&&e.allocateAce(i)},()=>{console.debug(`${n}2 depth: ${i-64}`)},()=>{console.debug(`${n}to EQ: ${i?"ON":"OFF"}`)}][a[0]+s]||function(o,h){console.warn(`Unknown GS EFX address: ${h}`)})(i,a[0]+s)})}).add([66,18,65],a=>{p((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],a=>{var n;switch(a[0]){case 0:{let l=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",l);break}case 32:{w(e,de,Date.now()+3200),a[1]==0&&(w(e,q,Math.max(Math.min(a[2]-1,9),0)),U()&&console.debug(`GS switch display page ${a[2]-1}.`));break}default:if(a[0]<6){t(e,q)>9&&w(e,q,0);let l=a[0]-1<<1|a[1]>>6;t(e,q)==l&&w(e,de,Date.now()+3200),(n=t(e,be)[l])!=null&&n.length||(t(e,be)[l]=new Uint8Array(256));let i=t(e,be)[l];U()&&console.debug(`GS frame draw page ${l}.`);let s=a[1]&63;i.fill(0),a.subarray(2).forEach(function(h,u){let g=u+s,$=Math.floor(g/16),S=g%16,C=(S*4+$)*5,P=5,X=0;for(C-=S*4,$==3&&(P=1);X>4-X&1,X++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let f=function(a,n,l){let i=a[0],s=E.cc*n,o=E.rpn*n,h=`GS CH${n+1} `;i<3?(a.subarray(1).forEach((u,g)=>{[()=>{t(e,y)[s+v[0]]=u},()=>{t(e,I)[n]=u},()=>{let $=0;u<16?$=e.chRedir(u,l,!0):$=E.ch,t(e,F)[n]=$,n!=$&&(e.buildRchTree(),console.info(`${h}receives from CH${$+1}`))}][i+g]()}),e.dispatchEvent("voice",{part:n})):i<19||(i<44?a.subarray(1).forEach((u,g)=>{([()=>{t(e,Z)[n]=+!u},!1,()=>{e.setChType(n,u<<1,x.gs),console.debug(`${h}type: ${u?"drum ":"melodic"}${u||""}`)},()=>{t(e,T)[o+3]=u,t(e,O)[E.rpnt*n+2]=1},!1,()=>{t(e,y)[s+v[7]]=u},!1,!1,()=>{t(e,y)[s+v[10]]=u||128},!1,!1,()=>{console.debug(`${h}CC 1: cc${u}`)},()=>{console.debug(`${h}CC 2: cc${u}`)},()=>{t(e,y)[s+v[93]]=u},()=>{t(e,y)[s+v[91]]=u},!1,!1,()=>{t(e,T)[o+1]=u,t(e,O)[E.rpnt*n+1]=1},()=>{t(e,T)[o+2]=u,t(e,O)[E.rpnt*n+1]=1},()=>{t(e,y)[s+v[94]]=u}][i+g-19]||(()=>{}))()}):i<76||console.debug(`Unknown GS part address: ${i}`))},m=function(a,n){let l=a[0],i=`GS CH${n+1} `;l<2?a.subarray(1).forEach((s,o)=>{[()=>{t(e,y)[E.cc*n+v[32]]=s},()=>{}][l+o]()}):l<32?console.warn(`Unknown GS misc address: ${l}`):l<35?a.subarray(1).forEach((s,o)=>{[()=>{console.debug(`${i}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${i}EFX: o${["ff","n"][s]}`),t(e,Ye)[n]=s,e.dispatchEvent("partefxtoggle",{part:n,active:s})}][l+o-32]()}):console.warn(`Unknown GS misc address: ${l}`)};t(this,ie).add([66,18,64,16],(a,n)=>{f(a,e.chRedir(9,n,!0),n)}).add([66,18,64,17],(a,n)=>{f(a,e.chRedir(0,n,!0),n)}).add([66,18,64,18],(a,n)=>{f(a,e.chRedir(1,n,!0),n)}).add([66,18,64,19],(a,n)=>{f(a,e.chRedir(2,n,!0),n)}).add([66,18,64,20],(a,n)=>{f(a,e.chRedir(3,n,!0),n)}).add([66,18,64,21],(a,n)=>{f(a,e.chRedir(4,n,!0),n)}).add([66,18,64,22],(a,n)=>{f(a,e.chRedir(5,n,!0),n)}).add([66,18,64,23],(a,n)=>{f(a,e.chRedir(6,n,!0),n)}).add([66,18,64,24],(a,n)=>{f(a,e.chRedir(7,n,!0),n)}).add([66,18,64,25],(a,n)=>{f(a,e.chRedir(8,n,!0),n)}).add([66,18,64,26],(a,n)=>{f(a,e.chRedir(10,n,!0),n)}).add([66,18,64,27],(a,n)=>{f(a,e.chRedir(11,n,!0),n)}).add([66,18,64,28],(a,n)=>{f(a,e.chRedir(12,n,!0),n)}).add([66,18,64,29],(a,n)=>{f(a,e.chRedir(13,n,!0),n)}).add([66,18,64,30],(a,n)=>{f(a,e.chRedir(14,n,!0),n)}).add([66,18,64,31],(a,n)=>{f(a,e.chRedir(15,n,!0),n)}).add([66,18,64,64],(a,n)=>{m(a,e.chRedir(9,n,!0))}).add([66,18,64,65],(a,n)=>{m(a,e.chRedir(0,n,!0))}).add([66,18,64,66],(a,n)=>{m(a,e.chRedir(1,n,!0))}).add([66,18,64,67],(a,n)=>{m(a,e.chRedir(2,n,!0))}).add([66,18,64,68],(a,n)=>{m(a,e.chRedir(3,n,!0))}).add([66,18,64,69],(a,n)=>{m(a,e.chRedir(4,n,!0))}).add([66,18,64,70],(a,n)=>{m(a,e.chRedir(5,n,!0))}).add([66,18,64,71],(a,n)=>{m(a,e.chRedir(6,n,!0))}).add([66,18,64,72],(a,n)=>{m(a,e.chRedir(7,n,!0))}).add([66,18,64,73],(a,n)=>{m(a,e.chRedir(8,n,!0))}).add([66,18,64,74],(a,n)=>{m(a,e.chRedir(10,n,!0))}).add([66,18,64,75],(a,n)=>{m(a,e.chRedir(11,n,!0))}).add([66,18,64,76],(a,n)=>{m(a,e.chRedir(12,n,!0))}).add([66,18,64,77],(a,n)=>{m(a,e.chRedir(13,n,!0))}).add([66,18,64,78],(a,n)=>{m(a,e.chRedir(14,n,!0))}).add([66,18,64,79],(a,n)=>{m(a,e.chRedir(15,n,!0))}),t(this,me).add([54,65],(a,n)=>{e.switchMode("x5d");let l=(a[1]<<7)+a[0],i=(a[3]<<7)+a[2],s=e.chRedir(l&15,n,!0),o=E.cc*s;[()=>{i<1||(i<101?(e.setChType(s,e.CH_MELODIC,x.x5d),t(e,I)[s]=i-1,t(e,y)[o+v[0]]=82):i<229?(e.setChType(s,e.CH_MELODIC,x.x5d),t(e,I)[s]=i-101,t(e,y)[o+v[0]]=56):(e.setChType(s,e.CH_DRUMS,x.x5d),t(e,I)[s]=aa[i-229]||0,t(e,y)[o+v[0]]=62)),e.dispatchEvent("voice",{part:s})},()=>{t(e,y)[o+v[7]]=i},()=>{i<31&&(t(e,y)[o+v[10]]=Math.round((i-15)*4.2+64))},()=>{t(e,y)[o+v[93]]=it(i)},()=>{t(e,y)[o+v[91]]=it(i)},()=>{t(e,T)[s*E.rpn+3]=i>8191?i-16320:64+i,t(e,O)[E.rpnt*s+2]=1},()=>{t(e,T)[s*E.rpn+1]=i>8191?i-16320:64+i,t(e,O)[E.rpnt*s+1]=1},()=>{i>0&&(t(e,T)[s*E.rpn]=i,t(e,O)[E.rpnt*s]=1)},()=>{}][l>>4]()}).add([54,76,0],(a,n)=>{e.switchMode("x5d",!0);let l="",i=82,s=0,o=0,h="MSB PRG LSB NME";le(a,function(u,g){if(g<16400){let $=g%164;switch(!0){case $<10:{u>31&&(l+=String.fromCharCode(u));break}case $==11:{h+=` +${i} ${s} ${o} ${l.trim().replace("Init Voice","")}`,s++,l="";break}}s>99&&(i=90,s=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(h),U()&&console.debug(h),e.forceVoiceRefresh()}).add([54,77,0],(a,n)=>{e.switchMode("x5d",!0);let l="",i=90,s=0,o=0,h="MSB PRG LSB NME";le(a,function(u,g){if(g<13600){let $=g%136;switch(!0){case $<10:{u>31&&(l+=String.fromCharCode(u));break}case $==11:{h+=` +${i} ${s} ${o} ${l.trim().replace("Init Combi","")}`,s++,l="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(h),U()&&console.debug(h),e.forceVoiceRefresh()}).add([54,78],(a,n)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,n)=>{e.switchMode("x5d",!0),le(a,(l,i)=>{i>0&&i<3&&(e.setEffectType(i-1,44,l),e.dispatchEvent(`efx${["reverb","chorus"][i-1]}`,e.getEffectType(i-1)))})}).add([54,104],(a,n)=>{e.switchMode("x5d",!0),le(a,function(l,i,s,o){if(i<192){let h=e.chRedir(Math.floor(i/12),n,!0),u=h*E.cc;switch(i%12){case 0:{l<128?(e.setChType(h,e.CH_MELODIC,x.x5d),t(e,y)[u+v[0]]=82,t(e,I)[h]=l):(e.setChType(h,e.CH_DRUMS,x.x5d),t(e,y)[u+v[0]]=62,t(e,I)[h]=aa[l-128]),l>0&&e.setChActive(h,1),e.dispatchEvent("voice",{part:h});break}case 1:{t(e,y)[u+v[7]]=l;break}case 2:{t(e,T)[h*E.rpn+3]=l>127?l-192:64+l,t(e,O)[E.rpnt*h+2]=1;break}case 3:{t(e,T)[h*E.rpn+1]=l>127?l-192:64+l,t(e,O)[E.rpnt*h+1]=1;break}case 4:{l<31&&(t(e,y)[u+v[10]]=Math.round((l-15)*4.2+64));break}case 5:{let g=l>>4,$=l&15;t(e,y)[u+v[91]]=it($),t(e,y)[u+v[93]]=it(g);break}case 10:break;case 11:{let g=e.chRedir(l&15,n,!0),$=l>>4;t(e,F)[h]=l,(g!=h||$)&&(console.info(`X5D Part CH${h+1} receives from CH${g+1}.`),e.buildRchTree())}}}else{let h=e.chRedir(i-192,n,!0)}})}),t(this,ie).add([22,18,127],a=>{e.switchMode("mt32",!0),w(e,B,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,n,l)=>{e.switchMode("mt32");let i=e.chRedir(l,n,!0),s=a[1];a.subarray(2).forEach((o,h)=>{let u=h+s;t(e,ke)[u+(i-1)*16]=o,([!1,()=>{let g=t(e,ke)[i-1<<4];if(g<3){if(t(e,he)[i]=1,g==2)for(let $=0;${t(e,T)[i*E.rpn+3]=o+40,t(e,O)[E.rpnt*i+2]=1},()=>{t(e,T)[i*E.rpn+1]=o+14,t(e,O)[E.rpnt*i+1]=1},()=>{t(e,T)[i*E.rpn]=o,t(e,O)[E.rpnt*i]=1},!1,()=>{t(e,y)[E.cc*i+v[91]]=o?127:0},!1,()=>{t(e,y)[E.cc*i+v[7]]=o},()=>{t(e,y)[E.cc*i+v[10]]=Math.ceil(o*9.05)}][u]||(()=>{}))()})}).add([22,18,1],(a,n,l)=>{e.switchMode("mt32");let i=l&7;console.debug(`MT-32 slot #${l+1} Drum: ${a}`);let s=a[0]<<7|a[1];a.subarray(2).forEach((o,h)=>{let u=h+s,g=(u>>2)+24,$=u&3,S=i*E.dpn;if(U()&&console.debug(`MT-32 temp drum note ${g} param ${$}: ${o}`),g<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${g}`);return}[()=>{},()=>{t(e,j)[(S+ae[26])*E.dnc+g]=Math.round(o*1.27)},()=>{t(e,j)[(S+ae[26])*E.dnc+g]=o*9+1&127},()=>{t(e,j)[(S+ae[26])*E.dnc+g]=o?127:0}][$]()})}).add([22,18,2],(a,n,l)=>{e.switchMode("mt32");let i=e.chRedir(l,n,!0),s=a[1]+(a[0]<<7);s<10&&(t(e,he)[i]=1),a.subarray(2).forEach((o,h)=>{let u=h+s;u<14&&(t(e,ne)[(i-1)*E.cmt+u]=o)}),e.dispatchEvent("voice",{part:i})}).add([22,18,3],(a,n,l)=>{e.switchMode("mt32");let i=l&7;if(a[0]){let s=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((o,h)=>{let u=h+s,g=(u>>2)+24,$=u&3,S=i*E.dpn;if(U()&&console.debug(`MT-32 dev drum note ${g} param ${$}: ${o}`),g<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${g}`);return}[()=>{},()=>{t(e,j)[(S+ae[26])*E.dnc+g]=Math.round(o*1.27)},()=>{t(e,j)[(S+ae[26])*E.dnc+g]=o*9+1&127},()=>{t(e,j)[(S+ae[26])*E.dnc+g]=o?127:0}][$]()})}else{let s=a[1];a.subarray(2).forEach((o,h)=>{let u=h+s;t(e,ke)[u]=o;let g=e.chRedir(1+(u>>4),n,!0),$=u&15;([!1,()=>{let S=t(e,ke)[g-1<<4];if(S<3)if(t(e,he)[g]=1,S==2)for(let C=0;C{t(e,T)[g*E.rpn+3]=o+40,t(e,O)[E.rpnt*g+2]=1},()=>{t(e,T)[g*E.rpn+1]=o+14,t(e,O)[E.rpnt*g+1]=1},()=>{t(e,T)[g*E.rpn]=o,t(e,O)[E.rpnt*g]=1},!1,()=>{t(e,y)[E.cc*g+v[91]]=o?127:0},!1,()=>{t(e,y)[E.cc*g+v[7]]=o},()=>{t(e,y)[E.cc*g+v[10]]=Math.ceil(o*9.05)}][$]||(()=>{}))()})}}).add([22,18,4],(a,n,l)=>{e.switchMode("mt32");let i=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((o,h)=>{let u=h+i,g=e.chRedir(Math.floor(u/246+1),n,!0),$=u%246;$<14&&(t(e,ne)[(g-1)*E.cmt+$]=o),$<10&&(t(e,he)[g]=1),s.indexOf(g)<0&&s.push(g)}),s.forEach(o=>{e.dispatchEvent("voice",{part:o})})}).add([22,18,5],(a,n,l)=>{e.switchMode("mt32");let i=(a[0]<<7)+a[1];a.subarray(2).forEach((s,o)=>{let h=i+o,u=Math.floor(h/8),g=h&7,$=u*8;t(e,We)[h]=s,([!1,()=>{let S=t(e,We)[$];if(S<3){let C="";if(S==2){let P=E.cmt*u;C=`MT-m:${s.toString().padStart(3,"0")}`}else C=e.baseBank.get(0,s+(S<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:u}),e.userBank.load(`MSB LSB PRG NME +000 127 ${u} ${C}`,!0)}}][g]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,n,l)=>{e.switchMode("mt32");let i=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((s,o)=>{let h=i+o;h>1)*E.cmt+h]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(a,n,l)=>{e.switchMode("mt32");let i=a[1],s=!1,o=function(h,u){t(e,F)[u-12]=h,s=!0};a.subarray(2).forEach((h,u)=>{let g=u+i;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,o,o,o,o,o,o,o,o,o,()=>{w(e,L,h),e.dispatchEvent("mastervolume",t(e,L))}][g]||(()=>{}))(h,u)}),s&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let n=a[1],l=" ".repeat(n);a.subarray(2).forEach(i=>{i>31?l+=String.fromCharCode(i):l+=" "}),w(e,Ce,l.padStart(20," ")),w(e,Te,Date.now()+3200)}).add([22,18,82],(a,n)=>{let l=e.chRedir(0,n,!0);for(let i=0;i<16;i++)t(e,_).ano(l+i),i&&i<10&&(t(e,I)[l+i]=kt[i-1]);console.info("MT-32 alt reset complete.")}),t(this,me).add([66,0],(a,n)=>{e.switchMode("ns5r",!0),w(e,B,!1),console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,n)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),w(e,B,!1)}).add([66,18,0,0],(a,n)=>{let l=a[0];switch(l){case 124:case 126:case 127:{e.switchMode("ns5r",!0),w(e,B,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(l<10){let i=[0,0,0,0],s=(o,h)=>{i[h]=o};if(a.subarray(1).forEach((o,h)=>{[s,s,s,s,()=>{w(e,L,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,L))},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][l+h]()}),a[0]<4){let o=0;i.forEach(h=>{o=o<<4,o+=h}),o-=1024}}}}).add([66,18,0,1],(a,n)=>{}).add([66,18,0,2],(a,n)=>{}).add([66,18,1],(a,n)=>{let l=e.chRedir(a[0],n,!0),i=l*E.cc,s=a[1],o=`NS5R CH${l+1} `;a.subarray(2).forEach((h,u)=>{let g=s+u;g<3?([()=>{t(e,y)[i+v[0]]=h||121},()=>{t(e,y)[i+v[32]]=h},()=>{t(e,I)[l]=h}][g](),e.dispatchEvent("voice",{part:l})):g<8||(g<14?[()=>{let $=e.chRedir(h,n,!0);t(e,F)[l]=$,l!=$&&(e.buildRchTree(),console.info(`${o}receives from CH${$+1}`))},()=>{t(e,Z)[l]=+!h},()=>{e.setChType(l,h,x.ns5r),console.debug(`${o}type: ${st[h]}`)},()=>{t(e,T)[E.rpn*l+3]=h,t(e,O)[E.rpnt*l+2]=1},()=>{},()=>{}][g-8]():g<16||(g<33?[()=>{t(e,y)[i+v[7]]=h},()=>{t(e,y)[i+v[11]]=h},()=>{},()=>{},()=>{t(e,y)[i+v[10]]=h||128},()=>{},()=>{},()=>{t(e,y)[i+v[93]]=h},()=>{t(e,y)[i+v[91]]=h},()=>{t(e,y)[i+v[76]]=h},()=>{t(e,y)[i+v[77]]=h},()=>{t(e,y)[i+v[78]]=h},()=>{t(e,y)[i+v[74]]=h},()=>{t(e,y)[i+v[71]]=h},()=>{t(e,y)[i+v[73]]=h},()=>{t(e,y)[i+v[75]]=h},()=>{t(e,y)[i+v[72]]=h}][g-16]():g<112||g<114&&[()=>{t(e,y)[i+v[5]]=h},()=>{t(e,y)[i+v[65]]=h}][g-112]()))})}).add([66,18,8,0],(a,n)=>{let l=a[0];if(l<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let i=l-32;w(e,de,Date.now()+3200),w(e,q,10),t(e,te,pe).fill(0);let s=a.subarray(1),o=4;s.forEach(function(h,u){let g=u+i,$=g>>4,S=g&15;if(g<80){let C=$>3,P=0,X=$0;)t(e,te,pe)[S*32+$*7+(X-P)]=C&1,C=C>>1,P++}})}}).add([66,18,48],(a,n,l)=>{c(0,a)}).add([66,18,49],(a,n,l)=>{c(1,a)}).add([66,18,50],(a,n,l)=>{c(2,a)}).add([66,18,51],(a,n,l)=>{c(3,a)}).add([66,18,52],(a,n,l)=>{c(4,a)}).add([66,18,53],(a,n,l)=>{c(5,a)}).add([66,18,54],(a,n,l)=>{c(6,a)}).add([66,18,55],(a,n,l)=>{c(7,a)}).add([66,52],(a,n)=>{e.switchMode("ns5r",!0),w(e,B,!1);let l="";le(a,(i,s)=>{s<8?(i>31&&(l+=String.fromCharCode(i)),s==7&&(e.aiEfxName=l)):s<10&&(e.setEffectType(s-8,44,i),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(a,n)=>{e.switchMode("ns5r",!0),w(e,B,!1),le(a,function(l,i){switch(!0){case i<2944:{let s=e.chRedir(Math.floor(i/92),n,!0),o=s*E.cc;switch(i%92){case 0:{t(e,y)[o+v[0]]=l||121,e.dispatchEvent("voice",{part:s});break}case 1:{t(e,y)[o+v[32]]=l,e.dispatchEvent("voice",{part:s});break}case 2:{t(e,I)[s]=l,l>0&&e.setChActive(s,1),e.dispatchEvent("voice",{part:s});break}case 3:{let h=e.chRedir(l,n,!0);t(e,F)[s]=h,s!=h&&(console.info(`NS5R CH${s+1} receives from CH${h+1}.`),e.buildRchTree())}case 7:break;case 8:{t(e,T)[s*E.rpn+3]=l<40||l>88?l+(l>63?-192:64):l,t(e,O)[E.rpnt*s+2]=1;break}case 9:case 10:{t(e,y)[o+v[7]]=l;break}case 11:{t(e,y)[o+v[11]]=l;break}case 14:{t(e,y)[o+v[10]]=l||128;break}case 19:{t(e,y)[o+v[93]]=l;break}case 20:{t(e,y)[o+v[91]]=l;break}case 84:{t(e,y)[o+v[65]]=l;break}case 85:{t(e,y)[o+v[5]]=l;break}}break}case i<3096:break;case i<3134:break;case i<8566:break}})}).add([66,54],(a,n)=>{e.switchMode("ns5r",!0);let l="",i=80,s=0,o=0,h="MSB PRG LSB NME";le(a,function(u,g){let $=g%158;switch(!0){case $<10:{u>31&&(l+=String.fromCharCode(u));break}case $==11:{i=u&127;break}case $==12:{o=u&127;break}case $==13:{h+=` +${i} ${s} ${o} ${l.trim().replace("Init Voice","")}`,s++,l="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(h),U()&&console.debug(h),e.forceVoiceRefresh()}).add([66,55],(a,n)=>{e.switchMode("ns5r",!0);let l="",i=88,s=0,o=0,h="MSB PRG LSB NME";le(a,function(u,g){let $=g%126;switch(!0){case $<10:{u>31&&(l+=String.fromCharCode(u));break}case $==11:break;case $==12:break;case $==13:{h+=` +${i} ${s} ${o} ${l.trim().replace("Init Combi","")}`,s++,l="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(h),U()&&console.debug(h),e.forceVoiceRefresh()}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let n=new Uint8Array(5760);le(a,(l,i,s)=>{if(i<720)for(let o=0;o<8;o++)n[i*8+o]=l>>7-o&1}),e.dispatchEvent("screen",{type:"ns5r",data:n})}).add([76],(a,n,l)=>{t(e,me).run([66,...a],n,l)}),t(this,Be).add([16,0,8,0],(a,n,l)=>{let i=(a[2]<<4)+a[3],s="K11 ";([()=>{e.switchMode("k11",!0),w(e,B,!1),w(e,re,i?4:0),console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,i),console.debug(`${s}reverb type: ${i}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${s}reverb time: ${i}`)},()=>{console.debug(`${s}reverb time: ${i}`)},()=>{console.debug(`${s}reverb predelay: ${i}`)},()=>{console.debug(`${s}reverb predelay: ${i}`)},()=>{console.debug(`${s}depth high: ${i}`)},()=>{console.debug(`${s}depth high: ${i}`)},()=>{console.debug(`${s}depth low: ${i}`)},()=>{console.debug(`${s}depth low: ${i}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,n,l)=>{let i=e.chRedir(a[1],n,!0),s=E.cc*i,o=E.rpn*i,h=(a[3]<<4)+a[4],u=`K11 CH${i+1} `;([()=>{h<128?(e.setChType(i,e.CH_MELODIC,x.k11),t(e,y)[s+v[0]]=0,t(e,I)[i]=h):(e.setChType(i,e.CH_DRUMS,x.k11),t(e,I)[i]=h-128),e.dispatchEvent("voice",{part:i})},()=>{let g=e.chRedir(h,n,!0);t(e,F)[i]=g,i!=g&&(e.buildRchTree(),console.info(`${u}receives from CH${g+1}`))},()=>{t(e,y)[s+v[7]]=h},()=>{uupThis.setChActive(i,h)},()=>{t(e,y)[s+v[10]]=h},()=>{t(e,T)[o+3]=h+40,t(e,O)[E.rpnt*i+2]=1},()=>{t(e,T)[o+1]=h>>1,t(e,T)[o+2]=h&1,t(e,O)[E.rpnt*i+1]=1},()=>{t(e,y)[s+v[91]]=h?127:0},()=>{},()=>{t(e,y)[s+v[74]]=h},()=>{t(e,y)[s+v[73]]=h},()=>{t(e,y)[s+v[72]]=h}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,n,l)=>{let i=(a[2]<<4)+a[3],s="GMLX ";([()=>{console.debug(`${s}reverb type: ${i}`)},()=>{console.debug(`${s}reverb time: ${i}`)},()=>{console.debug(`${s}reverb predelay: ${i}`)},()=>{console.debug(`${s}depth high: ${i}`)},()=>{console.debug(`${s}depth low: ${i}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,n,l)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],n,!0),o=s*E.cc;[()=>{i<128?(e.setChType(s,e.CH_MELODIC,x.k11),t(e,y)[o+v[0]]=0,t(e,y)[o+v[32]]=0,t(e,I)[s]=i):i<160?(e.setChType(s,e.CH_MELODIC,x.k11),t(e,y)[o+v[0]]=0,t(e,y)[o+v[32]]=7,t(e,I)[s]=i-100):(e.setChType(s,e.CH_DRUMS,x.k11),t(e,y)[o+v[0]]=122,t(e,y)[o+v[32]]=0,t(e,I)[s]=i-160),e.dispatchEvent("voice",{part:s})},()=>{let h=e.chRedir(i,n,!0);t(e,F)[s]=h,s!=h&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${h+1}`))}][a[0]]()}).add([16,0,9,4],(a,n,l)=>{let i=(a[2]<<4)+a[3],s=e.chRedir(a[1],n,!0),o=s*E.cc,h=s*E.rpn,u=`GMLX CH${s+1} `;[()=>{e.setChActive(s,i)},()=>{t(e,y)[o+v[7]]=i},()=>{t(e,y)[o+v[10]]=i},()=>{t(e,y)[o+v[91]]=i?127:0},()=>{t(e,T)[h+3]=i+40,t(e,O)[E.rpnt*s+2]=1},()=>{t(e,T)[h+1]=i,t(e,O)[E.rpnt*s+1]=1},()=>{t(e,T)[h]=i,t(e,O)[E.rpnt*s]=1},()=>{}][a[0]]()}),t(this,Ne).add([66,93,64],(a,n,l)=>{let i=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{w(e,L,i*129/16383*100),e.dispatchEvent("mastervolume",t(e,L));break}case 5:{i-64;break}case 6:{console.debug(`SG global reverb: ${i?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(a[1]){case 48:{console.debug(`SG reverb type: ${$t[i]}`);break}}break}default:if(a[0]>>4==1){let s=e.chRedir(a[0]&15,n,!0);if(a[1]==2){let o=e.chRedir(i,n,!0);t(e,F)[s]=o,s!=o&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${o+1}`))}else a[1]==19&&(t(e,y)[E.cc*s+v[7]]=i)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,He).add([9],(a,n,l)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),t(this,se).add([127,0],(a,n,l)=>{e.switchMode("motif");let i=new Uint8Array([127,1,...a]);t(e,se).run(i,n,l)}).add([127,1,0,0],(a,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES system ",s=a[0];a.subarray(1).forEach((o,h)=>{([()=>{w(e,L,o*12900/16383),e.dispatchEvent("mastervolume",t(e,L))}][s+h]||(()=>{console.info(`Unrecognized ${i}ID: ${s+h}`)}))()})}).add([127,1,0,0,14],(a,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES bulk header ",s=[];s[95]=(o,h,u)=>{console.debug(`${i}multi edit buffer: ${o[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,n,l)=>{e.switchMode("s90es");let i="S90/Motif ES bulk footer ",s=[];s[95]=(o,h,u)=>{console.debug(`${i}multi edit buffer: ${o[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${i}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,n,l)=>{e.switchMode("s90es");let i=e.chRedir(a[0],n,!0),s=E.cc*i,o=a[1],h=`S90/Motif ES bulk CH${i<16?i+1:"U"+(i-95)} `;console.debug(h,a),!(a[0]>15)&&a.subarray(2).forEach((u,g)=>{([()=>{t(e,y)[s+v[0]]=u,e.dispatchEvent("voice",{part:i})},()=>{u&&e.setChActive(i,1),t(e,y)[s+v[32]]=u,e.setChType(i,[32,40].indexOf(u)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,A),!0),e.dispatchEvent("voice",{part:i})},()=>{u&&e.setChActive(i,1),t(e,I)[i]=u,e.dispatchEvent("voice",{part:i})},()=>{let $=e.chRedir(u,n,!0);t(e,F)[i]=$,i!=$&&(e.buildRchTree(),console.info(`${h}receives from CH${$+1}`))},()=>{t(e,Z)[i]=u?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{t(e,y)[s+v[7]]=u},()=>{t(e,y)[s+v[10]]=u},!1,!1,!1,()=>{t(e,y)[s+v[91]]=u},()=>{t(e,y)[s+v[93]]=u},()=>{t(e,y)[s+v[94]]=u},()=>{t(e,y)[s+v[128]]=u},()=>{},()=>{t(e,y)[s+v[74]]=u},()=>{t(e,y)[s+v[71]]=u},!1,()=>{t(e,y)[s+v[65]]=u},()=>{t(e,y)[s+v[5]]=u},()=>{}][o+g]||(()=>{}))()})}).add([127,1,54,16],(a,n,l)=>{e.switchMode("s90es");let i=a[0];a.subarray(1).forEach((s,o)=>{let u=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let g=s-64},()=>{let g=je[s]},()=>{let g=s/10},()=>{let g=s}][i+o&3]||(()=>{}))()})}),t(this,ie).add([0,72,18,0,0,0,0],(a,n,l)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,n,l)=>{let i=a[0]>>5,s=a[0]&31;switch(i){case 0:{console.debug(`Unknown SD-90 global effects message: +%o`,a);break}case 1:{let o=e.chRedir(s,n,!0),h=a[1],u=o*E.cc;a.subarray(2).forEach((g,$)=>{let S=h+$;S<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,y)[u+v[0]]=g,g){case 104:case 105:case 106:case 107:case 120:{t(e,R)[o]||e.setChType(o,e.CH_DRUMS);break}default:t(e,R)[o]&&e.setChType(o,e.CH_MELODIC)}e.dispatchEvent("voice",{part:o})},()=>{t(e,y)[u+v[32]]=g,e.dispatchEvent("voice",{part:o})},()=>{t(e,I)[o]=g,e.dispatchEvent("voice",{part:o})},()=>{t(e,y)[u+v[7]]=g},()=>{t(e,y)[u+v[10]]=g},()=>{},()=>{},()=>{g<2&&(t(e,Z)[o]=g)},()=>{g<2&&(t(e,y)[u+v[68]]=g?127:0)},()=>{},()=>{g<2&&(t(e,y)[u+v[65]]=g?127:0)},()=>{t(e,y)[u+v[5]]=g&15<<4|t(e,y)[u+v[5]]&15},()=>{t(e,y)[u+v[5]]=g&15|(t(e,y)[u+v[5]]&240)>>4},()=>{t(e,y)[u+v[74]]=g},()=>{t(e,y)[u+v[71]]=g},()=>{t(e,y)[u+v[73]]=g},()=>{t(e,y)[u+v[72]]=g},0,0,0,0,0,0,0,()=>{t(e,y)[u+v[128]]=g},()=>{t(e,y)[u+v[93]]=g},()=>{t(e,y)[u+v[91]]=g},0,0,()=>{t(e,y)[u+v[75]]=g},()=>{t(e,y)[u+v[76]]=g},()=>{t(e,y)[u+v[77]]=g},()=>{t(e,y)[u+v[78]]=g}][S]||(()=>{}))():S<63||(S<64?t(e,R)[o]?t(e,y)[u+v[0]]=104|g:t(e,y)[u+v[0]]=96|g:console.debug(`Unknown SD-90 global CH${o+1} param setup message: +%o`,a))});break}case 2:{let o=e.chRedir(s,n,!0),h=a[1];console.debug(`Unknown SD-90 global CH${o+1} MIDI setup message: %o`,a.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,a)}})}chRedir(e,r,d){if(t(this,Me)[r])return(t(this,Me)[r]-1)*16+e;if([2,3].indexOf(t(this,re))>-1){if(d==1)return e;let c=0,p=!0;for(;p;)t(this,ve)[e+c]==0?(t(this,ve)[e+c]=r,console.debug(`Assign track ${r} to channel ${e+c+1}.`),p=!1):t(this,ve)[e+c]==r?p=!1:(c+=16,c>=128&&(c=0,p=!1));return e+c}else return e}forceVoiceRefresh(){for(let e=0;e{var c;r0&&!c&&(t(this,y)[e*E.cc+v[0]]=De[d])}setChActive(e,r=0){t(this,ge)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),t(this,ge)[e]=r}getPitch(){return t(this,we)}getProgram(){return t(this,I)}getTexts(){return t(this,ee).slice()}getVel(e){let r=new Map,d=this;return t(d,G).forEach(function(c,p){let h=Math.floor(c/128),m=c%128;e==h&&t(d,H)[c]>0&&r.set(m,{v:t(d,H)[c],s:t(d,V)[p]})}),r}getBitmap(){return{bitmap:t(this,te,pe),expire:t(this,de)}}getLetter(){return{text:t(this,Ce),set:t(this,ct),expire:t(this,Te)}}getMode(){return ue[t(this,A)]}getMaster(){return{volume:t(this,L)}}getRawStrength(){let e=this;return t(this,G).forEach(function(r){let d=Math.floor(r/128);t(e,H)[r]>t(e,fe)[d]&&(t(e,fe)[d]=t(e,H)[r])}),t(this,fe)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(d,c){e[c]=Math.floor(d*t(r,y)[c*E.cc+v[7]]*t(r,y)[c*E.cc+v[11]]*t(r,L)/803288)}),e}getRpn(){return t(this,T)}getNrpn(){return t(this,Qe)}getVoice(e,r,d,c){let p=e||t(this,xe),h=r,m=d||t(this,re);ue[t(this,A)]=="ns5r"&&p>0&&p<56&&(m=3);let a=this.userBank.get(p,h,m,c);if(ue[t(this,A)]=="mt32"&&a.name.indexOf("MT-m:")==0){let n=parseInt(a.name.slice(5)),l=n*E.cmt,i="";t(this,Se).subarray(l,l+10).forEach(s=>{s>31&&(i+=String.fromCharCode(s))}),this.userBank.load(`MSB LSB PRG -0 127 ${h} ${i}`,!0),a.name=i,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(p,h,m,c)),a}getChVoice(e){let r=this.getVoice(t(this,y)[e*E.cc+v[0]],t(this,I)[e],t(this,y)[e*E.cc+v[32]],ue[t(this,A)]);if(t(this,he)[e])switch(t(this,A)){case x.mt32:r.ending="~",r.name="",t(this,ne).subarray(14*(e-1),14*(e-1)+10).forEach(d=>{d>31&&(r.name+=String.fromCharCode(d))})}return r}getPitchShift(e){let r=this,d=e*E.rpn,c=t(r,T)[d];return t(r,O)[e*E.rpnt]||t(r,A)==x.mt32&&(c=12),t(r,we)[e]/8192*c+(t(r,T)[d+3]-64)+((t(r,T)[d+1]<<7)+t(r,T)[d+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return t(this,J).subarray(r,r+2)}setEffectTypeRaw(e=0,r,d){let c=3*e;t(this,J)[c]=1,t(this,J)[c+1+ +r]=d}setEffectType(e=0,r,d){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,d)}getEffectSink(){return t(this,Ye)}setLetterDisplay(e,r,d=0,c=3200){let p=this,h;w(p,Ce," ".repeat(d)),e.forEach(m=>{w(p,Ce,t(p,Ce)+String.fromCharCode(m>31?m:32)),m<32&&(h=h||new Set,h.add(m))}),w(p,ct,Date.now()),w(p,Te,Date.now()+c),h&&(h=Array.from(h),h.forEach((m,a,n)=>{n[a]=m.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${h.length>1?"s":""}: 0x${h.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let r=!0,d=0;for(;r&&d=E.ace&&console.warn("ACE slots are full.")}getAce(){return t(this,ye)}getChAce(e,r){if(r<0||r>=E.ace)throw new RangeError("No such ACE slot");let d=t(this,ye)[r];if(d){if(nt.indexOf(d)>=0)return t(this,y)[e*E.cc+v[d]];throw new Error(`Invalid ACE source: ${d}`)}else return 0}initDrums(){let e=this;t(e,j).fill(64);for(let r=0;r-1){if(t(d,A)==0||r){let p=t(d,A);d.initOnReset&&r&&(this.init(1),p=x["?"]),w(d,A,c),w(d,q,0),w(d,xe,Qt[0][c]),w(d,re,Qt[1][c]);for(let m=0;m0&&t(d,y)[m*E.cc+v[0]]==De[p]&&(t(d,y)[m*E.cc]=De[c]);switch(c){case x.mt32:{kt.forEach((m,a)=>{let n=a+1;t(d,ge)[n]||(t(d,I)[n]=m,t(d,y)[n*E.cc+v[91]]=127)});for(let m=1;m<10;m++)d.dispatchEvent("voice",{part:m});break}}let h;switch(c){case x["?"]:case x.xg:{h=[1,0,65,0,5,0,0,0];break}case x.gm:case x.gs:case x.g2:case x.sd:{h=[40,4,40,18,40,32,32,0];break}case x["05rw"]:case x.x5d:case x.ns5r:{h=[44,1,44,19,44,0,44,0];break}case x.k11:case x.sg:{h=[24,0,0,0,0,0,0,0];break}case x.mt32:{h=[40,4,0,0,0,0,0,0];break}default:h=[0,0,0,0,0,0,0,0]}for(let m=0;m<4;m++)t(d,J)[3*m]||(t(d,J)[3*m+1]=h[2*m],t(d,J)[3*m+2]=h[2*m+1],d.dispatchEvent(`efx${["reverb","chorus","delay","insert"][m]}`,d.getEffectType(m)));d.dispatchEvent("mode",e),d.forceVoiceRefresh()}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,fe).fill(0)}runJson(e){var r;if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,lt)[e.type].call(this,e);{let d=this.chRedir(e.part,e.track),c=!1;(r=t(this,ot)[d])==null||r.forEach(p=>{e.channel=p,c=!0,t(this,lt)[e.type].call(this,e)}),c||console.warn(`${Wt[e.type]?Wt[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${d+1} without any recipient.`)}t(this,ee).length>100&&t(this,ee).splice(100,t(this,ee).length-99)}runRaw(e){}async loadBank(e,r){let d=this;switch(e=e.toLowerCase(),e){case"s7e":{d.userBank.clearRange({msb:63,lsb:[21,22]}),d.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{ut.context=this,d.userBank.load(await ut.read(e,r));break}}d.forceVoiceRefresh()}},A=new WeakMap,q=new WeakMap,de=new WeakMap,be=new WeakMap,te=new WeakSet,pe=function(){return t(this,be)[t(this,q)]},sa=function(e){t(this,be)[t(this,q)]=e},ge=new WeakMap,F=new WeakMap,R=new WeakMap,y=new WeakMap,ye=new WeakMap,I=new WeakMap,H=new WeakMap,Z=new WeakMap,G=new WeakMap,V=new WeakMap,we=new WeakMap,fe=new WeakMap,Ae=new WeakMap,T=new WeakMap,O=new WeakMap,Qe=new WeakMap,j=new WeakMap,he=new WeakMap,ke=new WeakMap,ne=new WeakMap,We=new WeakMap,Se=new WeakMap,J=new WeakMap,Ye=new WeakMap,xe=new WeakMap,re=new WeakMap,L=new WeakMap,Pe=new WeakMap,Ze=new WeakMap,Je=new WeakMap,Ce=new WeakMap,Te=new WeakMap,ct=new WeakMap,et=new WeakMap,ce=new WeakMap,B=new WeakMap,ot=new WeakMap,xt=new WeakMap,ee=new WeakMap,ve=new WeakMap,Me=new WeakMap,K=new WeakMap,Ie=new WeakMap,_=new WeakMap,lt=new WeakMap,pt=new WeakMap,Ue=new WeakMap,Le=new WeakMap,se=new WeakMap,ie=new WeakMap,me=new WeakMap,Be=new WeakMap,Ne=new WeakMap,He=new WeakMap,ra);var Rt=Ea(ia(),1);D();D();var dt,na,oa=(na=class{constructor(b,e,r,d){k(this,dt,!1);w(this,dt,b),this.start=e,this.end=r,this.data=d}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return t(this,dt)}},dt=new WeakMap,na),Tt=class extends oa{constructor(b,e,r){super(!0,b,e,r)}},la=class extends oa{constructor(b,e){super(!1,b,b,e)}},Ge,ca,Mt=(ca=class extends Array{constructor(){super(...arguments);k(this,Ge,-1)}resetIndex(e){w(this,Ge,-1)}fresh(){this.sort(function(e,r){return e.start==r.start?0:(+(e.start>r.start)<<1)-1}),this.forEach(function(e,r){e.index=r})}step(e,r=!1){let d=[];if(r)for(let c=0;ce);c++){if(this[c].endt(p,Ge)&&(d.push(h),w(p,Ge,h.index))})}return d}getRange(e,r){var m;e>r&&([e,r]=[r,e]);let d=[],c=-1,p=Math.ceil(Math.sqrt(this.length)),h=!0;for(let a=0;a=e&&(c=a):c=c<0?a:c;for(;h;)((m=this[c])==null?void 0:m.end)=e&&d.push(this[c]):h=!1,c++;return d}},Ge=new WeakMap,ca);var Oa=0xffffffffffff,da=function(b){let e=new Mt,r=this,d=b.timeDivision,c=120,p=new Mt,h=0,m=0;p.push(new Tt(0,Oa,[120,0])),b.track.forEach(function(i){h=0,i.event.forEach(function(s){h+=s.deltaTime,s.type==255&&(s==null?void 0:s.metaType)==81&&(c=6e7/s.data,p[p.length-1]&&p.push(new Tt(h,0xffffffffffff,[c,0])))})}),p.fresh(),p.forEach(function(i,s,o){s>0&&(o[s-1].end=i.start)});let a=120;p.forEach(function(i,s,o){s>0&&(i.end==i.start?o.splice(o.indexOf(i),1):a==i.data[0]&&(o[s-1].end=i.end,o.splice(o.indexOf(i),1)),a=i.data[0])});let n=0,l=120;return p.forEach(function(i){let s=i.start,o=s/l/d*60+n;l=i.data[0],n=o-s/l/d*60,i.data[1]=n}),console.debug("All tempo changes: ",p),c=120,h=0,m=0,b.track.forEach(function(i,s){h=0,m=0;let o=s+1;i.event.forEach(function(f,u){h+=f.deltaTime;let g=p.step(h,!0)[0];g&&(c=g.data[0],m=g.data[1]);let $={type:f.type,data:f.data,track:o,part:0};f.type>14?$.meta=f.metaType:$.part=f.channel,e.push(new la(h/c/d*60+m,$))})}),e.fresh(),self.midiEvents=e,console.debug(`Parsed a type ${b.formatType} MIDI sequence.`),e};Rt.default.customInterpreter=jt;var N=function(b,e,r){b.addEventListener(r,d=>{e.dispatchEvent(r,d.data)})},_e,Xe,tt,Ee,Fe,Ve,ft,Re,Oe,z,Ke,$e,ze,fa,Ur=(fa=class extends ht{constructor(e,r=.5,d=.5){super();M(this,"device");k(this,_e,void 0);k(this,Xe,{});k(this,tt,[]);k(this,Ee,"");k(this,Fe,[]);k(this,Ve,new Uint8ClampedArray(128));k(this,ft,new Uint8ClampedArray(128));k(this,Re,.5);k(this,Oe,120);k(this,z,4);k(this,Ke,4);k(this,$e,0);k(this,ze,0);M(this,"smoothingAtk",0);M(this,"smoothingDcy",0);let c=this;c.smoothingAtk=r,c.smoothingDcy=d,c.device=e,c.addEventListener("meta",function(p){var h;(h=p==null?void 0:p.data)==null||h.forEach(function(m){(t(c,Fe)[m.meta]||console.debug).call(c,m.meta,m.data)})}),N(c.device,c,"mode"),N(c.device,c,"mastervolume"),N(c.device,c,"channelactive"),N(c.device,c,"channelmin"),N(c.device,c,"channelmax"),N(c.device,c,"channelreset"),N(c.device,c,"channeltoggle"),N(c.device,c,"screen"),N(c.device,c,"metacommit"),N(c.device,c,"voice"),N(c.device,c,"pitch"),N(c.device,c,"note"),N(c.device,c,"reset"),N(c.device,c,"efxreverb"),N(c.device,c,"efxchorus"),N(c.device,c,"efxdelay"),N(c.device,c,"efxinsert0"),N(c.device,c,"efxinsert1"),N(c.device,c,"efxinsert2"),N(c.device,c,"efxinsert3"),N(c.device,c,"partefxtoggle"),t(c,Fe)[3]=function(p,h){var m;((m=t(c,Ee))==null?void 0:m.length)<1&&(w(c,Ee,h),c.dispatchEvent("title",t(c,Ee)))},t(c,Fe)[81]=function(p,h){let m=c.noteProgress,a=t(c,Re)||.5;w(c,Oe,6e7/h),w(c,Re,h/1e6),w(c,$e,t(c,$e)+(m*(a/t(c,Re))-m)),c.dispatchEvent("tempo",t(c,Oe))},t(c,Fe)[88]=function(p,h){let m=c.noteProgress,a=c.noteOverall,n=c.noteBar,l=c.noteBeat,i=t(c,z),s=t(c,Ke);w(c,z,h[0]),w(c,Ke,1<=i&&(i{if(!n)return;let i=n.split(" ");if(l){if(!h)return;let s="",o="";i.forEach((f,u)=>{switch(u){case m:{s=f;break}case a:{o=f;break}}}),!t(d,Xe)[s]||r?(t(d,Xe)[s]=o,c++):self.debugMode&&console.debug(`Voice "${o}" (${s}) seems to be in conflict with (${t(d,Xe)[s]}).`),p++}else i.forEach((s,o)=>{switch(s){case"ID":{m=o,h++;break}case"Name":{a=o,h++;break}default:console.debug(`Unknown map field: ${s}`)}})}),console.debug(`Map: ${p} total, ${c} loaded.`),d==null||d.device.forceVoiceRefresh()}async loadEfx(e,r){let d=this,c=0,p=0,h,m,a;e.split(` -`).forEach((n,l)=>{if(n)if(l){let i=0,s;n.split(" ").forEach((o,f)=>{switch(f){case h:{i|=parseInt(o,16)<<8;break}case m:{i|=parseInt(o,16);break}case a:{s=o;break}}}),!t(d,tt)[i]||r?(t(d,tt)[i]=s,c++):self.debugMode&&console.debug(`EFX ID 0x${i.toString(16).padStart(4,"0")} (${s}) seems to be in conflict.`),p++}else n.split(" ").forEach((i,s)=>{switch(i){case"MSB":{h=s;break}case"LSB":{m=s;break}case"Name":{a=s;break}default:console.debug(`Unknown EFX field: ${i}`)}})}),console.debug(`EFX: ${p} total, ${c} loaded.`),d.dispatchEvent("efxreverb",d.device.getEffectType(0)),d.dispatchEvent("efxchorus",d.device.getEffectType(1)),d.dispatchEvent("efxdelay",d.device.getEffectType(2)),d.dispatchEvent("efxinsert0",d.device.getEffectType(3)),d.dispatchEvent("efxinsert1",d.device.getEffectType(4)),d.dispatchEvent("efxinsert2",d.device.getEffectType(5)),d.dispatchEvent("efxinsert3",d.device.getEffectType(6))}switchMode(e,r=!1){this.device.switchMode(e,r)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}getMapped(e){return t(this,Xe)[e]||e}getEfx([e,r]){let d=e<<8|r;return t(this,tt)[d]||`0x${d.toString(16).padStart(4,"0")}`}get noteProgress(){return t(this,ze)/t(this,Re)}get noteOverall(){return this.noteProgress-t(this,$e)}get noteBar(){return Math.floor(this.noteOverall/t(this,z))}get noteBeat(){let e=this.noteOverall%t(this,z);return e<0&&(e+=t(this,z)),e}getTimeSig(){return[t(this,z),t(this,Ke)]}getTempo(){return t(this,Oe)}sendCmd(e){this.device.runJson(e)}render(e){var g;e>t(this,ze)&&w(this,ze,e);let r=((g=t(this,_e))==null?void 0:g.step(e))||[],d=0,c=new Set,p=this,h=[];this.device.getStrength().forEach(($,S)=>{t(this,ft)[S]=$}),p.device.newStrength(),r.forEach(function($){let S=$.data;S.type==9&&(S.data[1]>0?c.add(S.part*128+S.data[0]):c.has(S.part*128+S.data[0])&&d++),$.data.type==8&&c.has(S.part*128+S.data[0])&&d++;let C=p.device.runJson(S);switch(C==null?void 0:C.reply){case"meta":{h.push(C);break}}C!=null&&C.reply&&delete C.reply}),(h==null?void 0:h.length)>0&&this.dispatchEvent("meta",h);let m=this.device.getActive(),a=[],n=p.device.getPitch(),l=p.device.getCcAll(),i=p.device.getProgram(),s=p.device.getChType(),o=this.device.getStrength();o.forEach(function($,S,C){C[S]=Math.max(t(p,ft)[S],$);let P=C[S]-t(p,Ve)[S],X=v.length*S;if(P>=0){let gt=4*.25**(l[X+v[73]]/64);t(p,Ve)[S]+=Math.ceil(P-P*p.smoothingAtk**gt)}else{let gt=4*.25**(l[X+v[72]]/64);t(p,Ve)[S]+=Math.floor(P-P*p.smoothingDcy**gt)}});let f=0;return m.forEach(function($,S){$&&(a[S]=p.device.getVel(S),f+=a[S].size)}),{extraPoly:d,curPoly:f,chInUse:m,chKeyPr:a,chPitch:n,chProgr:i,chContr:l,chType:s,eventCount:r.length,title:t(this,Ee),bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:t(this,Ve).slice(),velo:o,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce(),efxSink:this.device.getEffectSink()}}},_e=new WeakMap,Xe=new WeakMap,tt=new WeakMap,Ee=new WeakMap,Fe=new WeakMap,Ve=new WeakMap,ft=new WeakMap,Re=new WeakMap,Oe=new WeakMap,z=new WeakMap,Ke=new WeakMap,$e=new WeakMap,ze=new WeakMap,fa);export{Ur as RootDisplay,v as ccToPos,ae as dnToPos}; +%o`,a)}})}chRedir(e,r,d){if(t(this,Me)[r])return(t(this,Me)[r]-1)*16+e;if([2,3].indexOf(t(this,re))>-1){if(d==1)return e;let c=0,p=!0;for(;p;)t(this,ve)[e+c]==0?(t(this,ve)[e+c]=r,console.debug(`Assign track ${r} to channel ${e+c+1}.`),p=!1):t(this,ve)[e+c]==r?p=!1:(c+=16,c>=128&&(c=0,p=!1));return e+c}else return e}forceVoiceRefresh(){for(let e=0;e{var c;r0&&!c&&(t(this,y)[e*E.cc+v[0]]=De[d])}setChActive(e,r=0){t(this,ge)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),t(this,ge)[e]=r}getPitch(){return t(this,we)}getProgram(){return t(this,I)}getTexts(){return t(this,ee).slice()}getVel(e){let r=new Map,d=this;return t(d,G).forEach(function(c,p){let f=Math.floor(c/128),m=c%128;e==f&&t(d,H)[c]>0&&r.set(m,{v:t(d,H)[c],s:t(d,V)[p]})}),r}getBitmap(){return{bitmap:t(this,te,pe),expire:t(this,de)}}getLetter(){return{text:t(this,Ce),set:t(this,ct),expire:t(this,Te)}}getMode(){return ue[t(this,A)]}getMaster(){return{volume:t(this,L)}}getRawStrength(){let e=this;return t(this,G).forEach(function(r){let d=Math.floor(r/128);t(e,H)[r]>t(e,fe)[d]&&(t(e,fe)[d]=t(e,H)[r])}),t(this,fe)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(d,c){e[c]=Math.floor(d*t(r,y)[c*E.cc+v[7]]*t(r,y)[c*E.cc+v[11]]*t(r,L)/803288)}),e}getRpn(){return t(this,T)}getNrpn(){return t(this,Qe)}getVoice(e,r,d,c){let p=e||t(this,xe),f=r,m=d||t(this,re);ue[t(this,A)]=="ns5r"&&p>0&&p<56&&(m=3);let a=this.userBank.get(p,f,m,c);if(ue[t(this,A)]=="mt32"&&a.name.indexOf("MT-m:")==0){let n=parseInt(a.name.slice(5)),l=n*E.cmt,i="";t(this,Se).subarray(l,l+10).forEach(s=>{s>31&&(i+=String.fromCharCode(s))}),this.userBank.load(`MSB LSB PRG +0 127 ${f} ${i}`,!0),a.name=i,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(p,f,m,c)),a}getChVoice(e){let r=this.getVoice(t(this,y)[e*E.cc+v[0]],t(this,I)[e],t(this,y)[e*E.cc+v[32]],ue[t(this,A)]);if(t(this,he)[e])switch(t(this,A)){case x.mt32:r.ending="~",r.name="",t(this,ne).subarray(14*(e-1),14*(e-1)+10).forEach(d=>{d>31&&(r.name+=String.fromCharCode(d))})}return r}getPitchShift(e){let r=this,d=e*E.rpn,c=t(r,T)[d];return t(r,O)[e*E.rpnt]||t(r,A)==x.mt32&&(c=12),t(r,we)[e]/8192*c+(t(r,T)[d+3]-64)+((t(r,T)[d+1]<<7)+t(r,T)[d+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return t(this,J).subarray(r,r+2)}setEffectTypeRaw(e=0,r,d){let c=3*e;t(this,J)[c]=1,t(this,J)[c+1+ +r]=d}setEffectType(e=0,r,d){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,d)}getEffectSink(){return t(this,Ye)}setLetterDisplay(e,r,d=0,c=3200){let p=this,f;w(p,Ce," ".repeat(d)),e.forEach(m=>{w(p,Ce,t(p,Ce)+String.fromCharCode(m>31?m:32)),m<32&&(f=f||new Set,f.add(m))}),w(p,ct,Date.now()),w(p,Te,Date.now()+c),f&&(f=Array.from(f),f.forEach((m,a,n)=>{n[a]=m.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${f.length>1?"s":""}: 0x${f.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let r=!0,d=0;for(;r&&d=E.ace&&console.warn("ACE slots are full.")}getAce(){return t(this,ye)}getChAce(e,r){if(r<0||r>=E.ace)throw new RangeError("No such ACE slot");let d=t(this,ye)[r];if(d){if(nt.indexOf(d)>=0)return t(this,y)[e*E.cc+v[d]];throw new Error(`Invalid ACE source: ${d}`)}else return 0}initDrums(){let e=this;t(e,j).fill(64);for(let r=0;r-1){if(t(d,A)==0||r){let p=t(d,A);d.initOnReset&&r&&(this.init(1),p=x["?"]),w(d,A,c),w(d,q,0),w(d,xe,Qt[0][c]),w(d,re,Qt[1][c]);for(let m=0;m0&&t(d,y)[m*E.cc+v[0]]==De[p]&&(t(d,y)[m*E.cc]=De[c]);switch(c){case x.mt32:{kt.forEach((m,a)=>{let n=a+1;t(d,ge)[n]||(t(d,I)[n]=m,t(d,y)[n*E.cc+v[91]]=127)});for(let m=1;m<10;m++)d.dispatchEvent("voice",{part:m});break}}let f;switch(c){case x["?"]:case x.xg:{f=[1,0,65,0,5,0,0,0];break}case x.gm:case x.gs:case x.g2:case x.sd:{f=[40,4,40,18,40,32,32,0];break}case x["05rw"]:case x.x5d:case x.ns5r:{f=[44,1,44,19,44,0,44,0];break}case x.k11:case x.sg:{f=[24,0,0,0,0,0,0,0];break}case x.mt32:{f=[40,4,0,0,0,0,0,0];break}default:f=[0,0,0,0,0,0,0,0]}for(let m=0;m<4;m++)t(d,J)[3*m]||(t(d,J)[3*m+1]=f[2*m],t(d,J)[3*m+2]=f[2*m+1],d.dispatchEvent(`efx${["reverb","chorus","delay","insert"][m]}`,d.getEffectType(m)));d.dispatchEvent("mode",e),d.forceVoiceRefresh()}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,fe).fill(0)}runJson(e){var r;if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,lt)[e.type].call(this,e);{let d=this.chRedir(e.part,e.track),c=!1;(r=t(this,ot)[d])==null||r.forEach(p=>{e.channel=p,c=!0,t(this,lt)[e.type].call(this,e)}),c||console.warn(`${Wt[e.type]?Wt[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${d+1} without any recipient.`)}t(this,ee).length>100&&t(this,ee).splice(100,t(this,ee).length-99)}runRaw(e){}async loadBank(e,r){let d=this;switch(e=e.toLowerCase(),e){case"s7e":{d.userBank.clearRange({msb:63,lsb:[21,22]}),d.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{ut.context=this,d.userBank.load(await ut.read(e,r));break}}d.forceVoiceRefresh()}},A=new WeakMap,q=new WeakMap,de=new WeakMap,be=new WeakMap,te=new WeakSet,pe=function(){return t(this,be)[t(this,q)]},sa=function(e){t(this,be)[t(this,q)]=e},ge=new WeakMap,F=new WeakMap,R=new WeakMap,y=new WeakMap,ye=new WeakMap,I=new WeakMap,H=new WeakMap,Z=new WeakMap,G=new WeakMap,V=new WeakMap,we=new WeakMap,fe=new WeakMap,Ae=new WeakMap,T=new WeakMap,O=new WeakMap,Qe=new WeakMap,j=new WeakMap,he=new WeakMap,ke=new WeakMap,ne=new WeakMap,We=new WeakMap,Se=new WeakMap,J=new WeakMap,Ye=new WeakMap,xe=new WeakMap,re=new WeakMap,L=new WeakMap,Pe=new WeakMap,Ze=new WeakMap,Je=new WeakMap,Ce=new WeakMap,Te=new WeakMap,ct=new WeakMap,et=new WeakMap,ce=new WeakMap,B=new WeakMap,ot=new WeakMap,xt=new WeakMap,ee=new WeakMap,ve=new WeakMap,Me=new WeakMap,K=new WeakMap,Ie=new WeakMap,_=new WeakMap,lt=new WeakMap,pt=new WeakMap,Ue=new WeakMap,Le=new WeakMap,se=new WeakMap,ie=new WeakMap,me=new WeakMap,Be=new WeakMap,Ne=new WeakMap,He=new WeakMap,ra);var Rt=Ea(ia(),1);D();D();var dt,na,oa=(na=class{constructor(b,e,r,d){k(this,dt,!1);w(this,dt,b),this.start=e,this.end=r,this.data=d}get duration(){return this.ranged?this.end-this.start:0}get ranged(){return t(this,dt)}},dt=new WeakMap,na),Tt=class extends oa{constructor(b,e,r){super(!0,b,e,r)}},la=class extends oa{constructor(b,e){super(!1,b,b,e)}},Ge,ca,Mt=(ca=class extends Array{constructor(){super(...arguments);k(this,Ge,-1)}resetIndex(e){w(this,Ge,-1)}fresh(){this.sort(function(e,r){return e.start==r.start?0:(+(e.start>r.start)<<1)-1}),this.forEach(function(e,r){e.index=r})}step(e,r=!1){let d=[];if(r)for(let c=0;ce);c++){if(this[c].endt(p,Ge)&&(d.push(f),w(p,Ge,f.index))})}return d}getRange(e,r){var m;e>r&&([e,r]=[r,e]);let d=[],c=-1,p=Math.ceil(Math.sqrt(this.length)),f=!0;for(let a=0;a=e&&(c=a):c=c<0?a:c;for(;f;)((m=this[c])==null?void 0:m.end)=e&&d.push(this[c]):f=!1,c++;return d}},Ge=new WeakMap,ca);var Oa=0xffffffffffff,da=function(b){let e=new Mt,r=this,d=b.timeDivision,c=120,p=new Mt,f=0,m=0;p.push(new Tt(0,Oa,[120,0])),b.track.forEach(function(i){f=0,i.event.forEach(function(s){f+=s.deltaTime,s.type==255&&(s==null?void 0:s.metaType)==81&&(c=6e7/s.data,p[p.length-1]&&p.push(new Tt(f,0xffffffffffff,[c,0])))})}),p.fresh(),p.forEach(function(i,s,o){s>0&&(o[s-1].end=i.start)});let a=120;p.forEach(function(i,s,o){s>0&&(i.end==i.start?o.splice(o.indexOf(i),1):a==i.data[0]&&(o[s-1].end=i.end,o.splice(o.indexOf(i),1)),a=i.data[0])});let n=0,l=120;return p.forEach(function(i){let s=i.start,o=s/l/d*60+n;l=i.data[0],n=o-s/l/d*60,i.data[1]=n}),console.debug("All tempo changes: ",p),c=120,f=0,m=0,b.track.forEach(function(i,s){f=0,m=0;let o=s+1;i.event.forEach(function(h,u){f+=h.deltaTime;let g=p.step(f,!0)[0];g&&(c=g.data[0],m=g.data[1]);let $={type:h.type,data:h.data,track:o,part:0};h.type>14?$.meta=h.metaType:$.part=h.channel,e.push(new la(f/c/d*60+m,$))})}),e.fresh(),self.midiEvents=e,console.debug(`Parsed a type ${b.formatType} MIDI sequence.`),e};Rt.default.customInterpreter=jt;var N=function(b,e,r){b.addEventListener(r,d=>{e.dispatchEvent(r,d.data)})},_e,Xe,tt,Ee,Fe,Ve,ft,Re,Oe,z,Ke,$e,ze,fa,Ur=(fa=class extends ht{constructor(e,r=.5,d=.5){super();M(this,"device");k(this,_e,void 0);k(this,Xe,{});k(this,tt,[]);k(this,Ee,"");k(this,Fe,[]);k(this,Ve,new Uint8ClampedArray(128));k(this,ft,new Uint8ClampedArray(128));k(this,Re,.5);k(this,Oe,120);k(this,z,4);k(this,Ke,4);k(this,$e,0);k(this,ze,0);M(this,"smoothingAtk",0);M(this,"smoothingDcy",0);let c=this;c.smoothingAtk=r,c.smoothingDcy=d,c.device=e,c.addEventListener("meta",function(p){var f;(f=p==null?void 0:p.data)==null||f.forEach(function(m){(t(c,Fe)[m.meta]||console.debug).call(c,m.meta,m.data)})}),N(c.device,c,"mode"),N(c.device,c,"mastervolume"),N(c.device,c,"channelactive"),N(c.device,c,"channelmin"),N(c.device,c,"channelmax"),N(c.device,c,"channelreset"),N(c.device,c,"channeltoggle"),N(c.device,c,"screen"),N(c.device,c,"metacommit"),N(c.device,c,"voice"),N(c.device,c,"pitch"),N(c.device,c,"note"),N(c.device,c,"reset"),N(c.device,c,"efxreverb"),N(c.device,c,"efxchorus"),N(c.device,c,"efxdelay"),N(c.device,c,"efxinsert0"),N(c.device,c,"efxinsert1"),N(c.device,c,"efxinsert2"),N(c.device,c,"efxinsert3"),N(c.device,c,"partefxtoggle"),t(c,Fe)[3]=function(p,f){var m;((m=t(c,Ee))==null?void 0:m.length)<1&&(w(c,Ee,f),c.dispatchEvent("title",t(c,Ee)))},t(c,Fe)[81]=function(p,f){let m=c.noteProgress,a=t(c,Re)||.5;w(c,Oe,6e7/f),w(c,Re,f/1e6),w(c,$e,t(c,$e)+(m*(a/t(c,Re))-m)),c.dispatchEvent("tempo",t(c,Oe))},t(c,Fe)[88]=function(p,f){let m=c.noteProgress,a=c.noteOverall,n=c.noteBar,l=c.noteBeat,i=t(c,z),s=t(c,Ke);w(c,z,f[0]),w(c,Ke,1<=i&&(i{if(!n)return;let i=n.split(" ");if(l){if(!f)return;let s="",o="";i.forEach((h,u)=>{switch(u){case m:{s=h;break}case a:{o=h;break}}}),!t(d,Xe)[s]||r?(t(d,Xe)[s]=o,c++):self.debugMode&&console.debug(`Voice "${o}" (${s}) seems to be in conflict with (${t(d,Xe)[s]}).`),p++}else i.forEach((s,o)=>{switch(s){case"ID":{m=o,f++;break}case"Name":{a=o,f++;break}default:console.debug(`Unknown map field: ${s}`)}})}),console.debug(`Map: ${p} total, ${c} loaded.`),d==null||d.device.forceVoiceRefresh()}async loadEfx(e,r){let d=this,c=0,p=0,f,m,a;e.split(` +`).forEach((n,l)=>{if(n)if(l){let i=0,s;n.split(" ").forEach((o,h)=>{switch(h){case f:{i|=parseInt(o,16)<<8;break}case m:{i|=parseInt(o,16);break}case a:{s=o;break}}}),!t(d,tt)[i]||r?(t(d,tt)[i]=s,c++):self.debugMode&&console.debug(`EFX ID 0x${i.toString(16).padStart(4,"0")} (${s}) seems to be in conflict.`),p++}else n.split(" ").forEach((i,s)=>{switch(i){case"MSB":{f=s;break}case"LSB":{m=s;break}case"Name":{a=s;break}default:console.debug(`Unknown EFX field: ${i}`)}})}),console.debug(`EFX: ${p} total, ${c} loaded.`),d.dispatchEvent("efxreverb",d.device.getEffectType(0)),d.dispatchEvent("efxchorus",d.device.getEffectType(1)),d.dispatchEvent("efxdelay",d.device.getEffectType(2)),d.dispatchEvent("efxinsert0",d.device.getEffectType(3)),d.dispatchEvent("efxinsert1",d.device.getEffectType(4)),d.dispatchEvent("efxinsert2",d.device.getEffectType(5)),d.dispatchEvent("efxinsert3",d.device.getEffectType(6))}switchMode(e,r=!1){this.device.switchMode(e,r)}getMode(){return this.device.getMode()}getVoice(){return this.device.getVoice(...arguments)}getChVoice(e){return this.device.getChVoice(e)}getMapped(e){return t(this,Xe)[e]||e}getEfx([e,r]){let d=e<<8|r;return t(this,tt)[d]||`0x${d.toString(16).padStart(4,"0")}`}get noteProgress(){return t(this,ze)/t(this,Re)}get noteOverall(){return this.noteProgress-t(this,$e)}get noteBar(){return Math.floor(this.noteOverall/t(this,z))}get noteBeat(){let e=this.noteOverall%t(this,z);return e<0&&(e+=t(this,z)),e}getTimeSig(){return[t(this,z),t(this,Ke)]}getTempo(){return t(this,Oe)}sendCmd(e){this.device.runJson(e)}render(e){var g;e>t(this,ze)&&w(this,ze,e);let r=((g=t(this,_e))==null?void 0:g.step(e))||[],d=0,c=new Set,p=this,f=[];this.device.getStrength().forEach(($,S)=>{t(this,ft)[S]=$}),p.device.newStrength(),r.forEach(function($){let S=$.data;S.type==9&&(S.data[1]>0?c.add(S.part*128+S.data[0]):c.has(S.part*128+S.data[0])&&d++),$.data.type==8&&c.has(S.part*128+S.data[0])&&d++;let C=p.device.runJson(S);switch(C==null?void 0:C.reply){case"meta":{f.push(C);break}}C!=null&&C.reply&&delete C.reply}),(f==null?void 0:f.length)>0&&this.dispatchEvent("meta",f);let m=this.device.getActive(),a=[],n=p.device.getPitch(),l=p.device.getCcAll(),i=p.device.getProgram(),s=p.device.getChType(),o=this.device.getStrength();o.forEach(function($,S,C){C[S]=Math.max(t(p,ft)[S],$);let P=C[S]-t(p,Ve)[S],X=v.length*S;if(P>=0){let gt=4*.25**(l[X+v[73]]/64);t(p,Ve)[S]+=Math.ceil(P-P*p.smoothingAtk**gt)}else{let gt=4*.25**(l[X+v[72]]/64);t(p,Ve)[S]+=Math.floor(P-P*p.smoothingDcy**gt)}});let h=0;return m.forEach(function($,S){$&&(a[S]=p.device.getVel(S),h+=a[S].size)}),{extraPoly:d,curPoly:h,chInUse:m,chKeyPr:a,chPitch:n,chProgr:i,chContr:l,chType:s,eventCount:r.length,title:t(this,Ee),bitmap:this.device.getBitmap(),letter:this.device.getLetter(),texts:this.device.getTexts(),master:this.device.getMaster(),mode:this.device.getMode(),strength:t(this,Ve).slice(),velo:o,rpn:this.device.getRpn(),tSig:this.getTimeSig(),tempo:this.getTempo(),noteBar:this.noteBar,noteBeat:this.noteBeat,ace:this.device.getAce(),efxSink:this.device.getEffectSink()}}},_e=new WeakMap,Xe=new WeakMap,tt=new WeakMap,Ee=new WeakMap,Fe=new WeakMap,Ve=new WeakMap,ft=new WeakMap,Re=new WeakMap,Oe=new WeakMap,z=new WeakMap,Ke=new WeakMap,$e=new WeakMap,ze=new WeakMap,fa);export{Ur as RootDisplay,v as ccToPos,ae as dnToPos}; diff --git a/dist/xp_state.mjs b/dist/xp_state.mjs index 39ab8525..12bbf16a 100644 --- a/dist/xp_state.mjs +++ b/dist/xp_state.mjs @@ -1,8 +1,8 @@ -var Ut=Object.defineProperty;var Pt=(g,e,r)=>e in g?Ut(g,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):g[e]=r;var R=(g,e,r)=>(Pt(g,typeof e!="symbol"?e+"":e,r),r),nt=(g,e,r)=>{if(!e.has(g))throw TypeError("Cannot "+r)};var t=(g,e,r)=>(nt(g,e,"read from private field"),r?r.call(g):e.get(g)),k=(g,e,r)=>{if(e.has(g))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(g):e.set(g,r)},w=(g,e,r,d)=>(nt(g,e,"write to private field"),d?d.call(g,r):e.set(g,r),r);(function(){var g=function(v,a,i){var c,n;if(self.MessageEvent)switch(v){case"message":{n=new MessageEvent(v,{data:a,ports:i==null?void 0:i.ports}),Object.defineProperty(n,"source",{value:i==null?void 0:i.source});break}default:n=new Event(v)}else n=document.createEvent("Event"),n.initEvent(v,!1,!1),i&&v=="message"&&(n.data=a,i.source&&Object.defineProperty(n,"source",{value:i.source}),(c=i.ports)!=null&&c.length&&Object.defineProperty(n,"ports",{value:i.ports}));return n};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),r=[],d={},h=function(v){var a,i=this;if((this==null?void 0:this.constructor)!=h)throw new TypeError("Illegal constructor");r.push(this),(a=d[v])!=null&&a.constructor||(d[v]=[]),d[v].push(this);var c=Math.floor(Math.random()*281474976710656),n=[],s=0,o=[],f=!0,l=!1;Object.defineProperty(this,"id",{get:function(){return c}}),Object.defineProperty(this,"name",{value:v}),this.close=function(){var m,S=r.indexOf(i);S>-1?(e.postMessage({t:"d",c:v,i:c}),r.splice(S,1),(m=d[v])!=null&&m.constructor&&(S=d[v].indexOf(i),S>-1&&d[v].splice(S,1)),d[v].length||delete d[v],console.debug("[Snowy] BroadcastChannel closed."),l=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(m){if(e){if(l)throw new Error("Channel already closed");e.postMessage({t:"m",c:v,i:c,m:s,d:m}),s++,s>4294967295&&(s=0)}else o.push(m),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(f){for(e.postMessage({t:"r",c:v,i:c}),console.debug("[Snowy] ".concat(o.length," message(s) in cache."));o.length;){var m=o.shift();i.postMessage(m)}f=!1,console.debug("[Snowy] All cached messages are flushed away.")}}else throw new Error("Tried to flush when the ports are not ready")},this.receiveMessage=function(m){m.c==v?m.i!=c&&i.dispatchEvent(g("message",m.d,{source:i})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(c," receives from ").concat(v,", not ").concat(m.c,"."))};var p={};this.dispatchEvent=function(m){var S,O;if(Object.defineProperty(m,"target",{value:i}),Object.defineProperty(m,"currentTarget",{value:i}),(S=p[m.type])!=null&&S.length)for(var H=p[m.type],F=0;F-1&&p[m].splice(F,1)}!((H=p[m])!=null&&H.length)&&p[m].constructor&&delete p[m]}},self.BroadcastChannel=h,E=function(){if(e){e.addEventListener("message",function(a){var i=a.data,c=!1;switch(i.t){case"k":{c=!1,e.postMessage({t:"k"});break}case"m":{var n=d[i.c];if(n!=null&&n.length)for(var s=0;s{switch(d.addEventListener("abort",()=>{E(new Error("Blob read aborted"))}),d.addEventListener("error",b=>{E(d.error||b.data||new Error("Blob read error"))}),d.addEventListener("load",()=>{h(d.result)}),r.toLowerCase()){case"arraybuffer":case"buffer":{d.readAsArrayBuffer(e);break}case"string":case"text":{d.readAsText(e);break}default:E(new Error(`Unknown target ${r}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return g(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return g(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(g,e){let r=0,d=16,h=this,E=[];for(;r-1;){let b=h.lastIndexOf(g);E.unshift(h.slice(b+g.length)),h=h.slice(0,b),b==0&&E.unshift(""),r++}return h.length&&E.unshift(h),E.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(g,e){if(e){let r=this;for(;r.length0){let d=this.pool.length,h=1<=1&&b>=0;){if(b<=0)throw new Error("TTL reached.");if(E==d)E-=h;else{let a=ct(e,this.pool[E]);switch(a){case 0:{b=0;break}case 1:{E+h<=d&&(E+=h);break}case-1:{E!=0&&(E-=h);break}default:console.warn(`Unexpected result ${a}.`)}}h=h>>1,b--}let v=!0;if(E>=this.pool.length)v=!1;else{let a=this;this.pool[E].forEach(function(i,c,n){v&&i!=e[c]&&(v=!1)}),!v&&ct(e,this.pool[E])>0&&E++}return v||r?E:-1}else return r?0:-1},this.add=function(e,r){return e.data=r,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match in "${this.name||"(unknown)"}" for "${e}". Default action not defined.`)},this.get=function(e){let r=this.point(e);if(r>-1)return this.pool[r].data;this.default(e)},this.run=function(e,...r){let d=this.point(e);d>-1?e.subarray?this.pool[d].data(e.subarray(this.pool[d].length),...r):this.pool[d].data(e.slice(this.pool[d].length),...r):this.default(e,...r)}};var z,ot,lt=(ot=class{constructor(){k(this,z,{})}addEventListener(g,e){t(this,z)[g]||(t(this,z)[g]=[]),t(this,z)[g].unshift(e)}removeEventListener(g,e){if(t(this,z)[g]){let r=t(this,z)[g].indexOf(e);r>-1&&t(this,z)[g].splice(r,1),t(this,z)[g].length<1&&delete t(this,z)[g]}}dispatchEvent(g,e){var h;let r=new Event(g),d=this;r.data=e,((h=t(this,z)[g])==null?void 0:h.length)>0&&t(this,z)[g].forEach(function(E){try{E==null||E.call(d,r)}catch(b){console.error(b)}}),this[`on${g}`]&&this[`on${g}`](r)}},z=new WeakMap,ot);var Lt=["MSB","PRG","LSB"],Je=function(g){let e=Math.floor(g/10),r=g%10;return`${e.toString(16)}${r}`},Q,dt,Ze=(dt=class{constructor(...g){k(this,Q,void 0);R(this,"strictMode",!1);this.loadFiles(...g)}get(g=0,e=0,r=0,d){let h=[g,e,r],E,b=Array.from(arguments);switch(d){case"xg":{switch(g){case 0:{r==126?b[2]=125:r==127&&(b[2]=0);break}case 16:{r==126&&(b[2]=0);break}case 32:{b[2]+=4;break}case 33:case 35:case 36:{b[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:b[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{r==126&&(b[2]=0);break}case 48:case 64:case 126:case 127:{r==126&&(b[2]=0);break}}break}case"gs":{g==0&&r<5?b[2]=0:g>125&&r<5&&r!=2&&(b[2]=g,b[0]=0);break}case"g2":case"sd":{(g>>1==40||g>95&&g<100)&&(b[2]|=16);break}case"sg":{g==8&&r==0&&(b[2]=5);break}case"s90es":{r<8?b[2]+=17:r<32?b[2]+=13:b[2]=(b[2]>>3)+19;break}case"motif":{r<8?b[2]+=28:r<32?b[2]+=13:b[2]=(b[2]>>3)+19;break}}let v=" ",a="M",i=0,c=0;switch(b[0]){case 0:{b[2]==127?a="MT-a":b[2]==126?a="MT-b":b[2]==7?a="GM-k":b[2]==5?a="SG-a":b[2]==4?a="SP-l":b[2]==0||d=="gs"&&b[2]<5?a="GM-a":(a="y",i=3);break}case 8:{d=="sg"?a="GM-s":a="r:";break}case 48:{a=`yM${(b[2]>>3).toString().padStart(2,"0")}`,i=1;break}case 56:{a="GM-b";break}case 61:case 120:{a="rDrm";break}case 62:{a="kDrm";break}case 63:{if(b[2]<17){let f=b[2];a=f<10?"kP:":"kC:",a+=f%10}else b[2]<34?a=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][b[2]-17]:a="Ds";break}case 64:{a="ySFX";break}case 67:{a="DX:S";break}case 80:case 81:case 82:case 83:{a=`Prg${"UABC"[b[0]-80]}`;break}case 88:case 89:case 90:case 91:{a=`Cmb${"UABC"[b[0]-88]}`;break}case 95:{a=`${["DR","PC"][b[2]]}-d`;break}case 96:{a=b[2]==106?"AP-a":b[2]>>4==1?"SDg":"PF",b[2]>63?c=63:b[2]>>4==1&&(c=16),i=3;break}case 97:{a=b[2]>>4==1?"SDa":"VL:",i=3,b[2]>>4==1?c=16:c=112;break}case 98:{a=b[2]>>4==1?"SDb":"SG-a",i=3,c=16;break}case 99:{a=b[2]>>4==1?"SDc":"DX",b[2]>63?c=63:b[2]>>4==1&&(c=16),i=3;break}case 100:{a="AN",b[2]>63?c=63:b[2]>>4==1&&(c=16),i=3;break}case 104:case 105:case 106:case 107:{a="SDd",c=104;break}case 121:{a=`GM-${b[2]?"":"a"}`,i=3;break}case 122:{a="lDrm";break}case 126:{a="yDrS";break}case 127:{b[2]==127?a="rDrm":a="yDrm";break}default:b[0]<48?a="r:":a="M"}a.length<4&&(a+=`${[g,r,b[0],b[2]][i]-c}`.padStart(4-a.length,"0")),d=="xg"&&(g==0?b[2]<100?a=a.replace("y0","y:"):b[2]==125&&(a="y126"):g==16&&(E=`Voice${(b[2]*128+b[1]+1).toString().padStart(3,"0")}`,v=" "));let n=[b[0],b[1],b[2]];for(;!((E==null?void 0:E.length)>=0);)E=t(this,Q)[b[1]||0][(b[0]<<7)+b[2]],E||(this.strictMode?(E="",v="?"):t(this,Q)[b[1]||0][b[0]<<7]?b[0]==0?(b[2]=0,v="^"):b[2]<1?(b[0]=0,v="*"):(b[2]--,v="^"):g==48?(b[0]=0,b[2]=0,v="!"):g==62?(b[1]--,v=" ",b[1]<1&&!(E!=null&&E.length)&&(b[0]=0,v="!")):g<63?b[0]==0?(b[2]=0,v="^"):b[2]<1?(b[0]=0,v="*"):b[2]--:g==80?(E=`PrgU:${e.toString().padStart(3,"0")}`,v="!"):g==88?(E=`CmbU:${e.toString().padStart(3,"0")}`,v="!"):g==121?(E=`GM2Vox0${r}`,v="#"):g==122?(b[1]==32?b[1]==0:b[1]%=7,E=t(this,Q)[b[1]||0][(b[0]<<7)+b[2]],E?v=" ":(E="",v="*")):b[1]==0?(E=`${g.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${r.toString().padStart(3,"0")}`,v="!"):b[0]==0?(b[2]=0,v="^"):b[2]>0?b[2]--:b[1]>0?(b[1]=0,v="!"):(b[0]=0,v="?"));let s=[b[0],b[1],b[2]];(d=="gs"||d=="ns5r")&&v=="^"&&(v=" "),g==127&&v=="^"&&(v=" "),v!=" "&&self.debugMode&&(E="");let o="??";switch(b[0]){case 0:{b[2]==0?o="GM":b[2]==5||b[2]==7?o="KG":b[2]<126?o="XG":b[2]==127&&(o="MT");break}case 48:{o="MU";break}case 56:{o="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{o="AI";break}case 62:case 82:case 90:{o="XD";break}case 63:{b[2]<17?o="KR":b[2]<34?o="ES":o="DS";break}case 64:case 126:{o="XG";break}case 67:case 99:{o=b[2]>>4==1?"SD":"DX";break}case 81:{o="RW";break}case 95:{o=["DR","PC"][b[2]];break}case 96:{o=b[2]==106?"AP":b[2]>>4==1?"SD":"PF";break}case 97:{o=b[2]>>4==1?"SD":"VL";break}case 98:{o=b[2]>>4==1?"SD":"SG";break}case 100:{o="AN";break}case 104:case 105:case 106:case 107:{o="SD";break}case 120:{o="GS";break}case 121:{o=b[2]?"G2":"GM";break}case 122:{o="KG";break}case 127:{o=b[2]==127?"MT":e==0?"GM":"XG";break}default:b[0]<48&&(b[0]==16&&d=="xg"?o="XG":o="GS")}return{name:E||`${Je(g||0)} ${Je(e||0)} ${Je(r||0)}`,iid:n,eid:s,sid:h,ending:v,sect:a,standard:o}}async load(g,e,r){let d=this,h=[],E=0,b=0;g.split(` -`).forEach(function(v,a){let i=v.split(" "),c=[];a==0?i.forEach(function(n,s){h[Lt.indexOf(n)]=s}):i.forEach(async function(n,s){var o;s>2?(t(d,Q)[c[h[1]]]=t(d,Q)[c[h[1]]]||[],(!((o=t(d,Q)[c[h[1]]][(c[h[0]]<<7)+c[h[2]]])!=null&&o.length)||e)&&(t(d,Q)[c[h[1]]][(c[h[0]]<<7)+c[h[2]]]=i[3],E++),b++):c.push(parseInt(i[s]))})}),e||console.debug(`Map "${r||"(internal)"}": ${b} total, ${E} loaded.`)}clearRange(g){let e=g.prg!=null?g.prg.constructor==Array?g.prg:[g.prg,g.prg]:[0,127],r=g.msb!=null?g.msb.constructor==Array?g.msb:[g.msb,g.msb]:[0,127],d=g.lsb!=null?g.lsb.constructor==Array?g.lsb:[g.lsb,g.lsb]:[0,127];for(let h=r[0];h<=r[1];h++){let E=h<<7;for(let b=d[0];b<=d[1];b++){let v=E+b;for(let a=e[0];a<=e[1];a++)delete t(this,Q)[a][v]}}}init(){w(this,Q,[]);for(let g=0;g<128;g++)t(this,Q).push([""])}async loadFiles(...g){this.init();let e=this;g.forEach(async function(r,d){try{await fetch(`./data/bank/${r}.tsv`).then(function(h){return h.text()}).then(h=>{e.load(h,!1,r)})}catch(h){console.error(`Failed loading "${r}.tsv".`)}})}},Q=new WeakMap,dt);var Ue,ft,ht=(ft=class{constructor(){k(this,Ue,{});R(this,"context")}set(g,e){t(this,Ue)[g]=e}has(g){return!!t(this,Ue)[g]}async read(g,e){if(!this.has(g))throw new Error(`No decoder registered for "${g}"`);return await t(this,Ue)[g].call(this.context||this,e)}},Ue=new WeakMap,ft);var Ht=function(g,e){let r=!0;return e.forEach((d,h)=>{r=r&&g[h]==d}),r},ut=function(g){let e=0;return g.forEach(r=>{e*=256,e+=r}),e},_e=new TextDecoder,We=new ht;We.set("s7e",async function(g){let e=new Uint8Array(await g.slice(0,65536).arrayBuffer()),r="MSB LSB PRG NME",d=[0,0,0,0],h=32,E=0,b=0,v=!0,a=[],i=0;for(;v;){let c=e.subarray(E);([()=>{_e.decode(c.subarray(0,4))=="YSFC"?(E+=80,b=1):E++},()=>{if(Ht(c.subarray(0,4),d))a.forEach((n,s,o)=>{let f=ut(e.subarray(n.start+4,n.start+8));n.length=f}),b=2;else{let n=_e.decode(c.subarray(0,4)),s=ut(c.subarray(4,8));a.push({type:n,start:s}),E+=8}},()=>{let n=a[i],s=e.subarray(n.start,n.start+n.length),o=32;switch(n.type){case"ENVC":{let f=h;for(;f=a.length&&(b=3,v=!1)}][b]||(()=>{v=!1}))()}return r});var Xe=["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"]),Fe=["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"],Nt=[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],Pe=[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],pt=[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],bt=function(g){let e=.1,r=-.3;return g>66?(e=5,r=315):g>56?(e=1,r=47):g>46&&(e=.5,r=18.5),e*g-r},yt=function(g){return g>105?Nt[g-106]:g>100?g*1.1-100:g/10},gt=",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(","),et={};`hi*, +var Ut=Object.defineProperty;var Pt=(g,e,r)=>e in g?Ut(g,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):g[e]=r;var R=(g,e,r)=>(Pt(g,typeof e!="symbol"?e+"":e,r),r),nt=(g,e,r)=>{if(!e.has(g))throw TypeError("Cannot "+r)};var t=(g,e,r)=>(nt(g,e,"read from private field"),r?r.call(g):e.get(g)),k=(g,e,r)=>{if(e.has(g))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(g):e.set(g,r)},w=(g,e,r,d)=>(nt(g,e,"write to private field"),d?d.call(g,r):e.set(g,r),r);(function(){var g=function(v,a,i){var c,n;if(self.MessageEvent)switch(v){case"message":{n=new MessageEvent(v,{data:a,ports:i==null?void 0:i.ports}),Object.defineProperty(n,"source",{value:i==null?void 0:i.source});break}default:n=new Event(v)}else n=document.createEvent("Event"),n.initEvent(v,!1,!1),i&&v=="message"&&(n.data=a,i.source&&Object.defineProperty(n,"source",{value:i.source}),(c=i.ports)!=null&&c.length&&Object.defineProperty(n,"ports",{value:i.ports}));return n};self.BroadcastChannel?console.info("[Snowy] Snowy is disabled."):(console.info("[Snowy] Snowy is enabled. Path: ".concat(self.SNOWY_PATH||"/snowy.js")),r=[],d={},h=function(v){var a,i=this;if((this==null?void 0:this.constructor)!=h)throw new TypeError("Illegal constructor");r.push(this),(a=d[v])!=null&&a.constructor||(d[v]=[]),d[v].push(this);var c=Math.floor(Math.random()*281474976710656),n=[],s=0,o=[],f=!0,l=!1;Object.defineProperty(this,"id",{get:function(){return c}}),Object.defineProperty(this,"name",{value:v}),this.close=function(){var m,S=r.indexOf(i);S>-1?(e.postMessage({t:"d",c:v,i:c}),r.splice(S,1),(m=d[v])!=null&&m.constructor&&(S=d[v].indexOf(i),S>-1&&d[v].splice(S,1)),d[v].length||delete d[v],console.debug("[Snowy] BroadcastChannel closed."),l=!0):console.debug("[Snowy] BroadcastChannel already closed.")},this.postMessage=function(m){if(e){if(l)throw new Error("Channel already closed");e.postMessage({t:"m",c:v,i:c,m:s,d:m}),s++,s>4294967295&&(s=0)}else o.push(m),console.debug("[Snowy] Message is cached.")},this.flush=function(){if(e){if(f){for(e.postMessage({t:"r",c:v,i:c}),console.debug("[Snowy] ".concat(o.length," message(s) in cache."));o.length;){var m=o.shift();i.postMessage(m)}f=!1,console.debug("[Snowy] All cached messages are flushed away.")}}else throw new Error("Tried to flush when the ports are not ready")},this.receiveMessage=function(m){m.c==v?m.i!=c&&i.dispatchEvent(g("message",m.d,{source:i})):console.debug("[Snowy] Channel ID mismatch. Instance ".concat(c," receives from ").concat(v,", not ").concat(m.c,"."))};var b={};this.dispatchEvent=function(m){var S,O;if(Object.defineProperty(m,"target",{value:i}),Object.defineProperty(m,"currentTarget",{value:i}),(S=b[m.type])!=null&&S.length)for(var H=b[m.type],F=0;F-1&&b[m].splice(F,1)}!((H=b[m])!=null&&H.length)&&b[m].constructor&&delete b[m]}},self.BroadcastChannel=h,E=function(){if(e){e.addEventListener("message",function(a){var i=a.data,c=!1;switch(i.t){case"k":{c=!1,e.postMessage({t:"k"});break}case"m":{var n=d[i.c];if(n!=null&&n.length)for(var s=0;s{switch(d.addEventListener("abort",()=>{E(new Error("Blob read aborted"))}),d.addEventListener("error",u=>{E(d.error||u.data||new Error("Blob read error"))}),d.addEventListener("load",()=>{h(d.result)}),r.toLowerCase()){case"arraybuffer":case"buffer":{d.readAsArrayBuffer(e);break}case"string":case"text":{d.readAsText(e);break}default:E(new Error(`Unknown target ${r}`))}})};Blob.prototype.arrayBuffer=Blob.prototype.arrayBuffer||function(){return g(this,"buffer")},Blob.prototype.text=Blob.prototype.text||function(){return g(this,"text")}}String.prototype.replaceAll=String.prototype.replaceAll||function(g,e){let r=0,d=16,h=this,E=[];for(;r-1;){let u=h.lastIndexOf(g);E.unshift(h.slice(u+g.length)),h=h.slice(0,u),u==0&&E.unshift(""),r++}return h.length&&E.unshift(h),E.join(e)||""},String.prototype.padStart=String.prototype.padStart||function(g,e){if(e){let r=this;for(;r.length0){let d=this.pool.length,h=1<=1&&u>=0;){if(u<=0)throw new Error("TTL reached.");if(E==d)E-=h;else{let a=ct(e,this.pool[E]);switch(a){case 0:{u=0;break}case 1:{E+h<=d&&(E+=h);break}case-1:{E!=0&&(E-=h);break}default:console.warn(`Unexpected result ${a}.`)}}h=h>>1,u--}let v=!0;if(E>=this.pool.length)v=!1;else{let a=this;this.pool[E].forEach(function(i,c,n){v&&i!=e[c]&&(v=!1)}),!v&&ct(e,this.pool[E])>0&&E++}return v||r?E:-1}else return r?0:-1},this.add=function(e,r){return e.data=r,this.pool.splice(this.point(e,!0),0,e),this},this.default=function(e){console.warn(`No match in "${this.name||"(unknown)"}" for "${e}". Default action not defined.`)},this.get=function(e){let r=this.point(e);if(r>-1)return this.pool[r].data;this.default(e)},this.run=function(e,...r){let d=this.point(e);d>-1?e.subarray?this.pool[d].data(e.subarray(this.pool[d].length),...r):this.pool[d].data(e.slice(this.pool[d].length),...r):this.default(e,...r)}};var z,ot,lt=(ot=class{constructor(){k(this,z,{})}addEventListener(g,e){t(this,z)[g]||(t(this,z)[g]=[]),t(this,z)[g].unshift(e)}removeEventListener(g,e){if(t(this,z)[g]){let r=t(this,z)[g].indexOf(e);r>-1&&t(this,z)[g].splice(r,1),t(this,z)[g].length<1&&delete t(this,z)[g]}}dispatchEvent(g,e){var h;let r=new Event(g),d=this;r.data=e,((h=t(this,z)[g])==null?void 0:h.length)>0&&t(this,z)[g].forEach(function(E){try{E==null||E.call(d,r)}catch(u){console.error(u)}}),this[`on${g}`]&&this[`on${g}`](r)}},z=new WeakMap,ot);var Lt=["MSB","PRG","LSB"],Je=function(g){let e=Math.floor(g/10),r=g%10;return`${e.toString(16)}${r}`},Q,dt,Ze=(dt=class{constructor(...g){k(this,Q,void 0);R(this,"strictMode",!1);this.loadFiles(...g)}get(g=0,e=0,r=0,d){let h=[g,e,r],E,u=Array.from(arguments);switch(d){case"xg":{switch(g){case 0:{r==126?u[2]=125:r==127&&(u[2]=0);break}case 16:{r==126&&(u[2]=0);break}case 32:{r>125&&(u[2]=0),u[2]+=4;break}case 33:case 35:case 36:{r>125&&(u[2]=0),u[2]+=5;break}case 79:case 80:case 81:case 82:case 83:case 84:u[0]+=16;case 95:case 96:case 97:case 98:case 99:case 100:{r==126&&(u[2]=0);break}case 48:case 64:case 126:case 127:{r==126&&(u[2]=0);break}}break}case"gs":{g==0&&r<5?u[2]=0:g>125&&r<5&&r!=2&&(u[2]=g,u[0]=0);break}case"g2":case"sd":{(g>>1==40||g>95&&g<100)&&(u[2]|=16);break}case"sg":{g==8&&r==0&&(u[2]=5);break}case"s90es":{r<8?u[2]+=17:r<32?u[2]+=13:u[2]=(u[2]>>3)+19;break}case"motif":{r<8?u[2]+=28:r<32?u[2]+=13:u[2]=(u[2]>>3)+19;break}}let v=" ",a="M",i=0,c=0;switch(u[0]){case 0:{u[2]==127?a="MT-a":u[2]==126?a="MT-b":u[2]==7?a="GM-k":u[2]==5?a="SG-a":u[2]==4?a="SP-l":u[2]==0||d=="gs"&&u[2]<5?a="GM-a":(a="y",i=3);break}case 8:{d=="sg"?a="GM-s":a="r:";break}case 48:{a=`yM${(u[2]>>3).toString().padStart(2,"0")}`,i=1;break}case 56:{a="GM-b";break}case 61:case 120:{a="rDrm";break}case 62:{a="kDrm";break}case 63:{if(u[2]<17){let f=u[2];a=f<10?"kP:":"kC:",a+=f%10}else u[2]<34?a=["Pre1","Pre2","Pre3","Pre4","Usr1","Usr2","DrmP","DrmU","Plg1","Plg2","Plg3","Pre1","Pre2","Pre3","Pre4","Pre5","Pre6"][u[2]-17]:a="Ds";break}case 64:{a="ySFX";break}case 67:{a="DX:S";break}case 80:case 81:case 82:case 83:{a=`Prg${"UABC"[u[0]-80]}`;break}case 88:case 89:case 90:case 91:{a=`Cmb${"UABC"[u[0]-88]}`;break}case 95:{a=`${["DR","PC"][u[2]]}-d`;break}case 96:{a=u[2]==106?"AP-a":u[2]>>4==1?"SDg":"PF",u[2]>63?c=63:u[2]>>4==1&&(c=16),i=3;break}case 97:{a=u[2]>>4==1?"SDa":"VL:",i=3,u[2]>>4==1?c=16:c=112;break}case 98:{a=u[2]>>4==1?"SDb":"SG-a",i=3,c=16;break}case 99:{a=u[2]>>4==1?"SDc":"DX",u[2]>63?c=63:u[2]>>4==1&&(c=16),i=3;break}case 100:{a="AN",u[2]>63?c=63:u[2]>>4==1&&(c=16),i=3;break}case 104:case 105:case 106:case 107:{a="SDd",c=104;break}case 121:{a=`GM-${u[2]?"":"a"}`,i=3;break}case 122:{a="lDrm";break}case 126:{a="yDrS";break}case 127:{u[2]==127?a="rDrm":a="yDrm";break}default:u[0]<48?a="r:":a="M"}a.length<4&&(a+=`${[g,r,u[0],u[2]][i]-c}`.padStart(4-a.length,"0")),d=="xg"&&(g==0?u[2]<100?a=a.replace("y0","y:"):u[2]==125&&(a="y126"):g==16&&(E=`Voice${(u[2]*128+u[1]+1).toString().padStart(3,"0")}`,v=" "));let n=[u[0],u[1],u[2]];for(;!((E==null?void 0:E.length)>=0);)E=t(this,Q)[u[1]||0][(u[0]<<7)+u[2]],E||(this.strictMode?(E="",v="?"):t(this,Q)[u[1]||0][u[0]<<7]?u[0]==0?(u[2]=0,v="^"):u[2]<1?(u[0]=0,v="*"):(u[2]--,v="^"):g==48?(u[0]=0,u[2]=0,v="!"):g==62?(u[1]--,v=" ",u[1]<1&&!(E!=null&&E.length)&&(u[0]=0,v="!")):g<63?u[0]==0?(u[2]=0,v="^"):u[2]<1?(u[0]=0,v="*"):u[2]--:g==80?(E=`PrgU:${e.toString().padStart(3,"0")}`,v="!"):g==88?(E=`CmbU:${e.toString().padStart(3,"0")}`,v="!"):g==121?(E=`GM2Vox0${r}`,v="#"):g==122?(u[1]==32?u[1]==0:u[1]%=7,E=t(this,Q)[u[1]||0][(u[0]<<7)+u[2]],E?v=" ":(E="",v="*")):u[1]==0?(E=`${g.toString().padStart(3,"0")} ${e.toString().padStart(3,"0")} ${r.toString().padStart(3,"0")}`,v="!"):u[0]==0?(u[2]=0,v="^"):u[2]>0?u[2]--:u[1]>0?(u[1]=0,v="!"):(u[0]=0,v="?"));let s=[u[0],u[1],u[2]];(d=="gs"||d=="ns5r")&&v=="^"&&(v=" "),g==127&&v=="^"&&(v=" "),v!=" "&&self.debugMode&&(E="");let o="??";switch(u[0]){case 0:{u[2]==0?o="GM":u[2]==5||u[2]==7?o="KG":u[2]<126?o="XG":u[2]==127&&(o="MT");break}case 32:case 33:case 35:case 36:{u[2]>4?o=["AP","VL","PF","DX","AN"][u[0]-32]:o="GS";break}case 48:{o="MU";break}case 56:{o="AG";break}case 61:case 80:case 83:case 88:case 89:case 91:{o="AI";break}case 62:case 82:case 90:{o="XD";break}case 63:{u[2]<17?o="KR":u[2]<34?o="ES":o="DS";break}case 64:case 126:{o="XG";break}case 67:case 99:{o=u[2]>>4==1?"SD":"DX";break}case 81:{o="RW";break}case 95:{o=["DR","PC"][u[2]];break}case 96:{o=u[2]==106?"AP":u[2]>>4==1?"SD":"PF";break}case 97:{o=u[2]>>4==1?"SD":"VL";break}case 98:{o=u[2]>>4==1?"SD":"SG";break}case 100:{o="AN";break}case 104:case 105:case 106:case 107:{o="SD";break}case 120:{o="GS";break}case 121:{o=u[2]?"G2":"GM";break}case 122:{o="KG";break}case 127:{o=u[2]==127?"MT":e==0?"GM":"XG";break}default:u[0]<48&&(u[0]==16&&d=="xg"?o="XG":o="GS")}return{name:E||`${Je(g||0)} ${Je(e||0)} ${Je(r||0)}`,iid:n,eid:s,sid:h,ending:v,sect:a,standard:o}}async load(g,e,r){let d=this,h=[],E=0,u=0;g.split(` +`).forEach(function(v,a){let i=v.split(" "),c=[];a==0?i.forEach(function(n,s){h[Lt.indexOf(n)]=s}):i.forEach(async function(n,s){var o;s>2?(t(d,Q)[c[h[1]]]=t(d,Q)[c[h[1]]]||[],(!((o=t(d,Q)[c[h[1]]][(c[h[0]]<<7)+c[h[2]]])!=null&&o.length)||e)&&(t(d,Q)[c[h[1]]][(c[h[0]]<<7)+c[h[2]]]=i[3],E++),u++):c.push(parseInt(i[s]))})}),e||console.debug(`Map "${r||"(internal)"}": ${u} total, ${E} loaded.`)}clearRange(g){let e=g.prg!=null?g.prg.constructor==Array?g.prg:[g.prg,g.prg]:[0,127],r=g.msb!=null?g.msb.constructor==Array?g.msb:[g.msb,g.msb]:[0,127],d=g.lsb!=null?g.lsb.constructor==Array?g.lsb:[g.lsb,g.lsb]:[0,127];for(let h=r[0];h<=r[1];h++){let E=h<<7;for(let u=d[0];u<=d[1];u++){let v=E+u;for(let a=e[0];a<=e[1];a++)delete t(this,Q)[a][v]}}}init(){w(this,Q,[]);for(let g=0;g<128;g++)t(this,Q).push([""])}async loadFiles(...g){this.init();let e=this;g.forEach(async function(r,d){try{await fetch(`./data/bank/${r}.tsv`).then(function(h){return h.text()}).then(h=>{e.load(h,!1,r)})}catch(h){console.error(`Failed loading "${r}.tsv".`)}})}},Q=new WeakMap,dt);var Ue,ft,ht=(ft=class{constructor(){k(this,Ue,{});R(this,"context")}set(g,e){t(this,Ue)[g]=e}has(g){return!!t(this,Ue)[g]}async read(g,e){if(!this.has(g))throw new Error(`No decoder registered for "${g}"`);return await t(this,Ue)[g].call(this.context||this,e)}},Ue=new WeakMap,ft);var Ht=function(g,e){let r=!0;return e.forEach((d,h)=>{r=r&&g[h]==d}),r},ut=function(g){let e=0;return g.forEach(r=>{e*=256,e+=r}),e},_e=new TextDecoder,We=new ht;We.set("s7e",async function(g){let e=new Uint8Array(await g.slice(0,65536).arrayBuffer()),r="MSB LSB PRG NME",d=[0,0,0,0],h=32,E=0,u=0,v=!0,a=[],i=0;for(;v;){let c=e.subarray(E);([()=>{_e.decode(c.subarray(0,4))=="YSFC"?(E+=80,u=1):E++},()=>{if(Ht(c.subarray(0,4),d))a.forEach((n,s,o)=>{let f=ut(e.subarray(n.start+4,n.start+8));n.length=f}),u=2;else{let n=_e.decode(c.subarray(0,4)),s=ut(c.subarray(4,8));a.push({type:n,start:s}),E+=8}},()=>{let n=a[i],s=e.subarray(n.start,n.start+n.length),o=32;switch(n.type){case"ENVC":{let f=h;for(;f=a.length&&(u=3,v=!1)}][u]||(()=>{v=!1}))()}return r});var Xe=["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"]),Fe=["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"],Nt=[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],Pe=[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],pt=[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],bt=function(g){let e=.1,r=-.3;return g>66?(e=5,r=315):g>56?(e=1,r=47):g>46&&(e=.5,r=18.5),e*g-r},yt=function(g){return g>105?Nt[g-106]:g>100?g*1.1-100:g/10},gt=",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(","),et={};`hi*, ka,か ki,き ku,く @@ -139,7 +139,7 @@ o,お ~, ^, _,`.split(` -`).forEach(g=>{let e=g.split(",");et[e[0]]=e[1]});var $t=function(g){let e=g;g[0]=="*"&&(e=e.slice(1)),["aa","ii","uu","ee","oo"].forEach(d=>{for(;e.indexOf(d)>-1;)e=e.replace(d,d[0])});for(let d in et)e=e.replaceAll(d,et[d]);e.indexOf("ん")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},Et=function(g){return g?g<96?`cc${g}`:["aftertouch","velocity","pitch bend"][g-96]:"off"};var tt=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],mt=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],vt=["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 Bt={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"},Gt={66307:["drive"],66309:["vowel",g=>"aiueo"[g]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",g=>["off","LPF","HPF"][g]],94984:["noise type",g=>["white","pink"][g]],94987:["disc type",g=>["LP","SP","EP","RND"]],94990:["hum type",g=>`${g+5}0Hz`],94993:["M/S",g=>["mono","stereo"][g]]},at=function(g){return Bt[(g[0]-32<<8)+g[1]]||`0x${g[0].toString(16).padStart(2,"0")}${g[1].toString(16).padStart(2,"0")}`},wt=function(g,e,r){let d=(g[0]-32<<16)+(g[1]<<8)+e,h=Gt[d]||{},E=h[0];if(E!=null&&E.length)return E+=`: ${(h[1]||function(){})(r)||r}`,E},rt=[68,48,95,78,41,3,110,122,0];var q=function(g=64){return Math.round(2e3*Math.log10(g/64))/100};var st=function(g){let e=0;return g.forEach(r=>{e+=r,e=e&127}),~e+1&127},ne=function(g,e){let r=0,d=0;for(let h=0;h>E&1)<<7,v=g[h];v+=b,h%8!=0?(e(v,r,g),r++):d=g[h]}},Ve=function(g){let e=Math.floor(g*14.2);return e<128?e:0};var de=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],kt=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],Se=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],It=[0,3,81,84,88],St={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},xt={0:0,1:1,2:3,5:4},Ct={0:0,1:1,2:2,5:3},Mt=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Tt=[36,37,48,49,52,53],je=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Rt={26:127,29:0,30:0,31:0,52:12,53:54},Ke=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19],_t=[12,13,16,17,18,19],Xt=[33,99,100,32,102,8,9,10],Ot=[0,16,25,40,32,64,26,48],x={};de.forEach((g,e)=>{x[g]=e});var y={length:Ke.length};Ke.forEach((g,e)=>{y[g]=e});var ae={length:je.length};je.forEach((g,e)=>{ae[g]=e});var U=function(){return!!self.Bun||self.debugMode||!1},Ft=function(g){let e=[],r=0;return g==null||g.forEach(function(d,h){d==247?e.push(g.subarray(r,h)):d==240&&(r=h+1)}),e.length||e.push(g.subarray(0)),U()&&console.debug(e),e};var $={ch:128,cc:Ke.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:je.length,dnc:128,efx:7},D,V,ce,he,J,fe,At,ue,I,M,u,pe,A,N,W,B,_,ge,oe,xe,C,T,Le,K,le,$e,re,He,Ee,Y,Ne,me,Z,P,Ce,Be,Ge,ve,we,ze,Ie,se,L,Qe,it,j,be,ke,X,Me,G,qe,Ye,Te,Re,ee,te,ye,Oe,De,Ae,Dt,Ma=(Dt=class extends lt{constructor(){super();k(this,J);R(this,"NOTE_IDLE",0);R(this,"NOTE_ATTACK",1);R(this,"NOTE_DECAY",2);R(this,"NOTE_SUSTAIN",3);R(this,"NOTE_HELD",4);R(this,"NOTE_RELEASE",5);R(this,"NOTE_SOSTENUTO_ATTACK",8);R(this,"NOTE_SOSTENUTO_DECAY",9);R(this,"NOTE_SOSTENUTO_SUSTAIN",10);R(this,"NOTE_SOSTENUTO_HELD",11);R(this,"CH_MELODIC",0);R(this,"CH_DRUMS",1);R(this,"CH_DRUM1",2);R(this,"CH_DRUM2",3);R(this,"CH_DRUM3",4);R(this,"CH_DRUM4",5);R(this,"CH_DRUM5",6);R(this,"CH_DRUM6",7);R(this,"CH_DRUM7",8);R(this,"CH_DRUM8",9);k(this,D,0);k(this,V,0);k(this,ce,0);k(this,he,new Array(11));k(this,ue,new Uint8Array($.ch));k(this,I,new Uint8Array($.ch));k(this,M,new Uint8Array($.ch));k(this,u,new Uint8Array($.ch*$.cc));k(this,pe,new Uint8Array($.ace));k(this,A,new Uint8Array($.ch));k(this,N,new Uint8Array($.ch*$.nn));k(this,W,new Uint8Array($.ch));k(this,B,new Uint16Array($.pl));k(this,_,new Uint8Array($.pl));k(this,ge,new Int16Array($.ch));k(this,oe,new Uint8Array($.ch));k(this,xe,0);k(this,C,new Uint8Array($.ch*$.rpn));k(this,T,new Uint8Array($.ch*$.rpnt));k(this,Le,new Int8Array($.ch*Tt.length));k(this,K,new Uint8Array($.drm*$.dpn*$.dnc));k(this,le,new Uint8Array($.ch));k(this,$e,new Uint8Array(128));k(this,re,new Uint8Array($.cmt*8));k(this,He,new Uint8Array(1024));k(this,Ee,new Uint8Array($.cmt*64));k(this,Y,new Uint8Array($.efx*3));k(this,Ne,new Uint8Array($.ch));k(this,me,0);k(this,Z,0);k(this,P,100);k(this,Ce,0);k(this,Be,500);k(this,Ge,0);k(this,ve,"");k(this,we,0);k(this,ze,0);k(this,Ie,0);k(this,se,!0);k(this,L,!1);k(this,Qe,void 0);k(this,it,new Uint8Array(2));k(this,j,[]);k(this,be,new Uint8Array($.ch));k(this,ke,new Uint8Array($.tr));R(this,"baseBank",new Ze("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es"));R(this,"userBank",new Ze("gm"));R(this,"initOnReset",!1);R(this,"aiEfxName","");k(this,X,[]);k(this,Me,void 0);k(this,G,{nOff:(e,r)=>{let d=e*128+r,h=t(this,B).lastIndexOf(d);h>-1&&(t(this,u)[$.cc*e+y[64]]>63?(t(this,_)[h]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,N)[d],state:this.NOTE_HELD})):t(this,u)[$.cc*e+y[66]]>63&&t(this,_)[h]==this.NOTE_SOSTENUTO_SUSTAIN?(t(this,_)[h]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,N)[d],state:this.NOTE_SOSTENUTO_HELD})):(t(this,B)[h]=0,t(this,N)[d]=0,t(this,_)[h]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})))},nOn:(e,r,d)=>{let h=e*128+r,E=0;for(t(this,W)[e]&&t(this,G).ano(e);t(this,_)[E]>0&&t(this,B)[E]!=h;)E++;E<$.pl?(t(this,B)[E]=h,t(this,N)[h]=d,t(this,_)[E]=this.NOTE_SUSTAIN,t(this,oe)[e]{},cAt:(e,r)=>{},hoOf:e=>{t(this,_).forEach((r,d)=>{if(r==this.NOTE_HELD){let h=t(this,B)[d],E=h>>7;e==E&&(t(this,_)[d]=this.NOTE_IDLE,t(this,B)[d]=0,t(this,N)[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,_).forEach((r,d)=>{let h;switch(r){case this.NOTE_ATTACK:{h=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{h=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{h=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(h){t(this,_)[d]=h;let E=t(this,B)[d];this.dispatchEvent("note",{part:e,note:E&127,velo:t(this,N)[E],state:h})}})},soOf:e=>{t(this,_).forEach((r,d)=>{if(r==this.NOTE_SOSTENUTO_HELD){let h=t(this,B)[d],E=h>>7;e==E&&(t(this,_)[d]=this.NOTE_IDLE,t(this,B)[d]=0,t(this,N)[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,B).forEach((r,d,h)=>{let E=r>>7,b=r&127;r==0&&t(this,N)[0]==0||E==e&&t(this,G).nOff(E,b)})}});k(this,qe,{8:function(e){let r=e.channel,d=e.data[0];t(this,G).nOff(r,d)},9:function(e){let r=e.channel;this.setChActive(r,1);let d=e.data[0],h=e.data[1];h>0?t(this,G).nOn(r,d,h):t(this,G).nOff(r,d)},10:function(e){let r=e.channel,d=r*128+e.data[0];t(this,B).indexOf(d)>-1&&(t(this,N)[d]=data[1],this.dispatchEvent("note",{part:r,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let r=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,D)){case x.s90es:case x.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(r,1);break}e.data[1]&&this.setChActive(r,1);break}default:{this.setChActive(r,1);break}}})();let d=r*$.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,G).ano(r),t(this,ge)[r]=0;let h=r*$.cc;t(this,u)[h+y[1]]=0,t(this,u)[h+y[5]]=0,t(this,u)[h+y[64]]=0,t(this,u)[h+y[65]]=0,t(this,u)[h+y[66]]=0,t(this,u)[h+y[67]]=0,t(this,u)[h+y[11]]=127,t(this,u)[h+y[101]]=127,t(this,u)[h+y[100]]=127,t(this,u)[h+y[99]]=127,t(this,u)[h+y[98]]=127;return}case 123:{t(this,G).ano(r);return}case 124:{t(this,G).ano(r);return}case 125:{t(this,G).ano(r);return}case 126:{t(this,W)[r]=1,t(this,G).ano(r);return}case 127:{t(this,W)[r]=0,t(this,G).ano(r);return}}if(y[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(_t.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(U()&&console.debug(`${de[t(this,D)]}, CH${r+1}: ${e.data[1]}`),t(this,D)==0?e.data[1]<48?(t(this,M)[r]>0&&(e.data[1]=t(this,u)[d],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,D)==x.gs?e.data[1]<56&&t(this,M)[r]>0&&(e.data[1]=t(this,u)[d],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):t(this,D)==x.gm?e.data[1]<48?t(this,M)[r]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${r+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):t(this,D)==x.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),t(this,D)){case x.xg:{[126,127].indexOf(e.data[1])>-1?t(this,M)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,M)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x["05rw"]:case x.x5d:case x.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(this,M)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,M)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,M)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,M)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x.g2:{e.data[1]==120?t(this,M)[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,M)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:r});break}case 6:{if(t(this,xe)){[x.xg,x.gs,x.ns5r].indexOf(t(this,D))<0&&console.warn(`NRPN commits are not available under "${de[t(this,D)]}" mode, even when they are supported in Octavia.`);let h=t(this,u)[d+y[99]],E=t(this,u)[d+y[98]];if(h==1){let b=Xt.indexOf(E);if(b>-1)t(this,u)[d+y[71+b]]=e.data[1],U()&&console.debug(`Redirected NRPN 1 ${E} to cc${71+b}.`),this.dispatchEvent("cc",{part:r,cc:71+b,data:e.data[1]});else{let v=Tt.indexOf(E);v>-1?t(this,Le)[r*10+v]=e.data[1]-64:console.warn(`NRPN 0x01${E.toString(16).padStart(2,"0")} is not supported.`),U()&&console.debug(`CH${r+1} voice NRPN ${E} commit`)}}else{if(je.indexOf(h)<0){let v=`NRPN 0x${h.toString(16).padStart(2,"0")}${E.toString(16).padStart(2,"0")} `;h==127?console.warn(`${v}is not necessary. Consider removing it.`):console.warn(`${v}is not supported.`)}else{let v=t(this,M)[r]-2;v<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${Fe[t(this,M)[r]]}.`):t(this,K)[(v*$.dpn+ae[h])*$.dnc+E]=e.data[1]}U()&&console.debug(`CH${r+1} (${Fe[t(this,M)[r]]}) drum NRPN ${h} commit`)}}else{let h=xt[t(this,u)[d+y[100]]],E=Ct[t(this,u)[d+y[100]]];t(this,u)[d+y[101]]==0&&h!=null&&(U()&&console.debug(`CH${r+1} RPN 0 ${t(this,u)[d+y[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Mt[h][0]),Mt[h][1]),t(this,C)[r*$.rpn+h]=e.data[1],t(this,T)[r*$.rpnt+E]=1)}break}case 32:{switch(U()&&console.debug(`${de[t(this,D)]}, CH${r+1} LSB: ${e.data[1]}`),t(this,D)){case x.s90es:case x.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,D),!0);break}}this.dispatchEvent("voice",{part:r});break}case 38:{if(!t(this,xe)){let h=xt[t(this,u)[d+100]],E=Ct[t(this,u)[d+100]];t(this,u)[d+101]==0&&h!=null&&(t(this,C)[r*$.rpn+h+1]=e.data[1],t(this,T)[r*$.rpnt+E]=1)}break}case 64:{e.data[1]<64&&t(this,G).hoOf(r);break}case 66:{e.data[1]>>6?t(this,G).soOn(r):t(this,G).soOf(r);break}case 98:case 99:{w(this,xe,1);break}case 100:case 101:{w(this,xe,0);break}}t(this,u)[d+y[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:r,cc:e.data[0],data:e.data[1]})}},12:function(e){let r=e.channel;switch(t(this,D)){case x.s90es:case x.motif:{e.data&&this.setChActive(r,1);break}default:this.setChActive(r,1)}t(this,A)[r]=e.data,t(this,le)[r]=0,U()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),this.dispatchEvent("voice",{part:r})},13:function(e){let r=this,d=e.channel;t(this,B).forEach(function(h){let E=h>>7;d==E&&(t(r,N)[h]=e.data,r.dispatchEvent("note",{part:d,note:h&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;t(this,ge)[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){Ft(e.data).forEach(r=>{let d=r[0],h=r[1];(t(this,Ye)[d]||function(){console.debug(`Unknown manufacturer ${d}.`)})(h,r.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(t(this,X)[e.meta]||function(d,h,E){}).call(this,e.data,e.track,e.meta),e.meta!=32&&w(this,Ce,0);let r=It.indexOf(e.meta)>-1;if(U()&&console.debug(e),r)return e.reply="meta",e}});k(this,Ye,{64:(e,r,d)=>{t(this,Oe).run(r,d,e)},65:(e,r,d)=>{if(r[0]<16)if(r[1]==72){let h=r[r.length-1],E=st(r.subarray(3,r.length-1));h==E?t(this,te).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad SD checksum ${h}. Should be ${E}.`)}else t(this,te).run(r,d,e);else{let h=r[r.length-1],E=st(r.subarray(2,r.length-1));h==E?t(this,te).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad GS checksum ${h}. Should be ${E}.`)}},66:(e,r,d)=>{t(this,ye).run(r,d,e)},67:(e,r,d)=>{t(this,ee).run(r,d,e)},68:(e,r,d)=>{t(this,Ae).run(r,d,e)},71:(e,r,d)=>{t(this,De).run(r,d,e)},126:(e,r,d)=>{t(this,Te).run(r,d,e)},127:(e,r,d)=>{this.switchMode("gm"),t(this,Re).run(r,d,e)}});k(this,Te,void 0);k(this,Re,void 0);k(this,ee,void 0);k(this,te,void 0);k(this,ye,void 0);k(this,Oe,void 0);k(this,De,void 0);k(this,Ae,void 0);let e=this;w(this,J,new Uint8Array(256),At),t(this,he)[10]=new Uint8Array(512),w(this,Me,new ie),this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(g=>{let e=g.split(",");et[e[0]]=e[1]});var $t=function(g){let e=g;g[0]=="*"&&(e=e.slice(1)),["aa","ii","uu","ee","oo"].forEach(d=>{for(;e.indexOf(d)>-1;)e=e.replace(d,d[0])});for(let d in et)e=e.replaceAll(d,et[d]);e.indexOf("ん")==0&&e.length>1&&(e=e.slice(1));let r=e.indexOf("!");return r>-1&&e.length>1&&(e=e.slice(r+1)),e},Et=function(g){return g?g<96?`cc${g}`:["aftertouch","velocity","pitch bend"][g-96]:"off"};var tt=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],mt=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],vt=["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 Bt={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"},Gt={66307:["drive"],66309:["vowel",g=>"aiueo"[g]],94723:["pre-filter"],94724:["Lo-Fi type"],94725:["post-filter"],94979:["Lo-Fi type"],94980:["fill type",g=>["off","LPF","HPF"][g]],94984:["noise type",g=>["white","pink"][g]],94987:["disc type",g=>["LP","SP","EP","RND"]],94990:["hum type",g=>`${g+5}0Hz`],94993:["M/S",g=>["mono","stereo"][g]]},at=function(g){return Bt[(g[0]-32<<8)+g[1]]||`0x${g[0].toString(16).padStart(2,"0")}${g[1].toString(16).padStart(2,"0")}`},wt=function(g,e,r){let d=(g[0]-32<<16)+(g[1]<<8)+e,h=Gt[d]||{},E=h[0];if(E!=null&&E.length)return E+=`: ${(h[1]||function(){})(r)||r}`,E},rt=[68,48,95,78,41,3,110,122,0];var q=function(g=64){return Math.round(2e3*Math.log10(g/64))/100};var st=function(g){let e=0;return g.forEach(r=>{e+=r,e=e&127}),~e+1&127},ne=function(g,e){let r=0,d=0;for(let h=0;h>E&1)<<7,v=g[h];v+=u,h%8!=0?(e(v,r,g),r++):d=g[h]}},Ve=function(g){let e=Math.floor(g*14.2);return e<128?e:0};var de=["?","gm","gs","xg","g2","mt32","ns5r","x5d","05rw","sd","k11","sg","krs","s90es","motif"],kt=[[0,0,0,0,121,0,0,82,81,97,0,0,63,63,63],[0,0,4,0,0,127,0,0,0,0,0,0,0,0,0]],Se=[120,127,120,127,120,127,61,62,62,105,122,122,120,127,127],It=[0,3,81,84,88],St={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},xt={0:0,1:1,2:3,5:4},Ct={0:0,1:1,2:2,5:3},Mt=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Tt=[36,37,48,49,52,53],je=[20,21,22,23,24,25,26,28,29,30,31,36,37,48,49,52,53,64,65],Rt={26:127,29:0,30:0,31:0,52:12,53:54},Ke=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,128,12,13,16,17,18,19,14,15,20,21],_t=[12,13,14,15,16,17,18,19,20,21],Xt=[33,99,100,32,102,8,9,10],Ot=[0,16,25,40,32,64,26,48],x={};de.forEach((g,e)=>{x[g]=e});var y={length:Ke.length};Ke.forEach((g,e)=>{y[g]=e});var ae={length:je.length};je.forEach((g,e)=>{ae[g]=e});var U=function(){return!!self.Bun||self.debugMode||!1},Ft=function(g){let e=[],r=0;return g==null||g.forEach(function(d,h){d==247?e.push(g.subarray(r,h)):d==240&&(r=h+1)}),e.length||e.push(g.subarray(0)),U()&&console.debug(e),e};var $={ch:128,cc:Ke.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,rpnt:4,ace:8,drm:8,dpn:je.length,dnc:128,efx:7},D,V,ce,he,J,fe,At,ue,I,M,p,pe,A,N,W,B,_,ge,oe,xe,C,T,Le,K,le,$e,re,He,Ee,Y,Ne,me,Z,P,Ce,Be,Ge,ve,we,ze,Ie,se,L,Qe,it,j,be,ke,X,Me,G,qe,Ye,Te,Re,ee,te,ye,Oe,De,Ae,Dt,Ma=(Dt=class extends lt{constructor(){super();k(this,J);R(this,"NOTE_IDLE",0);R(this,"NOTE_ATTACK",1);R(this,"NOTE_DECAY",2);R(this,"NOTE_SUSTAIN",3);R(this,"NOTE_HELD",4);R(this,"NOTE_RELEASE",5);R(this,"NOTE_SOSTENUTO_ATTACK",8);R(this,"NOTE_SOSTENUTO_DECAY",9);R(this,"NOTE_SOSTENUTO_SUSTAIN",10);R(this,"NOTE_SOSTENUTO_HELD",11);R(this,"CH_MELODIC",0);R(this,"CH_DRUMS",1);R(this,"CH_DRUM1",2);R(this,"CH_DRUM2",3);R(this,"CH_DRUM3",4);R(this,"CH_DRUM4",5);R(this,"CH_DRUM5",6);R(this,"CH_DRUM6",7);R(this,"CH_DRUM7",8);R(this,"CH_DRUM8",9);k(this,D,0);k(this,V,0);k(this,ce,0);k(this,he,new Array(11));k(this,ue,new Uint8Array($.ch));k(this,I,new Uint8Array($.ch));k(this,M,new Uint8Array($.ch));k(this,p,new Uint8Array($.ch*$.cc));k(this,pe,new Uint8Array($.ace));k(this,A,new Uint8Array($.ch));k(this,N,new Uint8Array($.ch*$.nn));k(this,W,new Uint8Array($.ch));k(this,B,new Uint16Array($.pl));k(this,_,new Uint8Array($.pl));k(this,ge,new Int16Array($.ch));k(this,oe,new Uint8Array($.ch));k(this,xe,0);k(this,C,new Uint8Array($.ch*$.rpn));k(this,T,new Uint8Array($.ch*$.rpnt));k(this,Le,new Int8Array($.ch*Tt.length));k(this,K,new Uint8Array($.drm*$.dpn*$.dnc));k(this,le,new Uint8Array($.ch));k(this,$e,new Uint8Array(128));k(this,re,new Uint8Array($.cmt*8));k(this,He,new Uint8Array(1024));k(this,Ee,new Uint8Array($.cmt*64));k(this,Y,new Uint8Array($.efx*3));k(this,Ne,new Uint8Array($.ch));k(this,me,0);k(this,Z,0);k(this,P,100);k(this,Ce,0);k(this,Be,500);k(this,Ge,0);k(this,ve,"");k(this,we,0);k(this,ze,0);k(this,Ie,0);k(this,se,!0);k(this,L,!1);k(this,Qe,void 0);k(this,it,new Uint8Array(2));k(this,j,[]);k(this,be,new Uint8Array($.ch));k(this,ke,new Uint8Array($.tr));R(this,"baseBank",new Ze("gm","gm2","xg","gs","ns5r","sd","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross","s90es"));R(this,"userBank",new Ze("gm"));R(this,"initOnReset",!1);R(this,"aiEfxName","");k(this,X,[]);k(this,Me,void 0);k(this,G,{nOff:(e,r)=>{let d=e*128+r,h=t(this,B).lastIndexOf(d);h>-1&&(t(this,p)[$.cc*e+y[64]]>63?(t(this,_)[h]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,N)[d],state:this.NOTE_HELD})):t(this,p)[$.cc*e+y[66]]>63&&t(this,_)[h]==this.NOTE_SOSTENUTO_SUSTAIN?(t(this,_)[h]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:r,velo:t(this,N)[d],state:this.NOTE_SOSTENUTO_HELD})):(t(this,B)[h]=0,t(this,N)[d]=0,t(this,_)[h]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:r,velo:0,state:this.NOTE_IDLE})))},nOn:(e,r,d)=>{let h=e*128+r,E=0;for(t(this,W)[e]&&t(this,G).ano(e);t(this,_)[E]>0&&t(this,B)[E]!=h;)E++;E<$.pl?(t(this,B)[E]=h,t(this,N)[h]=d,t(this,_)[E]=this.NOTE_SUSTAIN,t(this,oe)[e]{},cAt:(e,r)=>{},hoOf:e=>{t(this,_).forEach((r,d)=>{if(r==this.NOTE_HELD){let h=t(this,B)[d],E=h>>7;e==E&&(t(this,_)[d]=this.NOTE_IDLE,t(this,B)[d]=0,t(this,N)[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{t(this,_).forEach((r,d)=>{let h;switch(r){case this.NOTE_ATTACK:{h=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{h=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{h=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(h){t(this,_)[d]=h;let E=t(this,B)[d];this.dispatchEvent("note",{part:e,note:E&127,velo:t(this,N)[E],state:h})}})},soOf:e=>{t(this,_).forEach((r,d)=>{if(r==this.NOTE_SOSTENUTO_HELD){let h=t(this,B)[d],E=h>>7;e==E&&(t(this,_)[d]=this.NOTE_IDLE,t(this,B)[d]=0,t(this,N)[h]=0,this.dispatchEvent("note",{part:e,note:h&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{t(this,B).forEach((r,d,h)=>{let E=r>>7,u=r&127;r==0&&t(this,N)[0]==0||E==e&&t(this,G).nOff(E,u)})}});k(this,qe,{8:function(e){let r=e.channel,d=e.data[0];t(this,G).nOff(r,d)},9:function(e){let r=e.channel;this.setChActive(r,1);let d=e.data[0],h=e.data[1];h>0?t(this,G).nOn(r,d,h):t(this,G).nOff(r,d)},10:function(e){let r=e.channel,d=r*128+e.data[0];t(this,B).indexOf(d)>-1&&(t(this,N)[d]=data[1],this.dispatchEvent("note",{part:r,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let r=e.channel;[0,32].indexOf(e.data[0])>-1&&(()=>{switch(t(this,D)){case x.s90es:case x.motif:{if(e.data[0]==0){[0,63].indexOf(e.data[1])>-1&&this.setChActive(r,1);break}e.data[1]&&this.setChActive(r,1);break}default:{this.setChActive(r,1);break}}})();let d=r*$.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{t(this,G).ano(r),t(this,ge)[r]=0;let h=r*$.cc;t(this,p)[h+y[1]]=0,t(this,p)[h+y[5]]=0,t(this,p)[h+y[64]]=0,t(this,p)[h+y[65]]=0,t(this,p)[h+y[66]]=0,t(this,p)[h+y[67]]=0,t(this,p)[h+y[11]]=127,t(this,p)[h+y[101]]=127,t(this,p)[h+y[100]]=127,t(this,p)[h+y[99]]=127,t(this,p)[h+y[98]]=127;return}case 123:{t(this,G).ano(r);return}case 124:{t(this,G).ano(r);return}case 125:{t(this,G).ano(r);return}case 126:{t(this,W)[r]=1,t(this,G).ano(r);return}case 127:{t(this,W)[r]=0,t(this,G).ano(r);return}}if(y[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(_t.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{switch(U()&&console.debug(`${de[t(this,D)]}, CH${r+1}: ${e.data[1]}`),t(this,D)==0?e.data[1]<48?(t(this,M)[r]>0&&(e.data[1]=t(this,p)[d],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg"):t(this,D)==x.gs?e.data[1]<56&&t(this,M)[r]>0&&(e.data[1]=t(this,p)[d],e.data[1]=120,console.debug(`Forced channel ${r+1} to stay drums.`)):t(this,D)==x.gm?e.data[1]<48?t(this,M)[r]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${r+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0):t(this,D)==x.x5d&&e.data[1]>0&&e.data[1]<8&&this.switchMode("05rw",!0),t(this,D)){case x.xg:{[126,127].indexOf(e.data[1])>-1?t(this,M)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,M)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x["05rw"]:case x.x5d:case x.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?t(this,M)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,M)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x.sd:{[104,105,106,107].indexOf(e.data[1])>-1?t(this,M)[r]==0&&(this.setChType(r,this.CH_DRUM2),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,M)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}case x.g2:{e.data[1]==120?t(this,M)[r]==0&&(this.setChType(r,this.CH_DRUMS),console.debug(`CH${r+1} set to drums by MSB.`)):t(this,M)[r]>0&&(this.setChType(r,this.CH_MELODIC),console.debug(`CH${r+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:r});break}case 6:{if(t(this,xe)){[x.xg,x.gs,x.ns5r].indexOf(t(this,D))<0&&console.warn(`NRPN commits are not available under "${de[t(this,D)]}" mode, even when they are supported in Octavia.`);let h=t(this,p)[d+y[99]],E=t(this,p)[d+y[98]];if(h==1){let u=Xt.indexOf(E);if(u>-1)t(this,p)[d+y[71+u]]=e.data[1],U()&&console.debug(`Redirected NRPN 1 ${E} to cc${71+u}.`),this.dispatchEvent("cc",{part:r,cc:71+u,data:e.data[1]});else{let v=Tt.indexOf(E);v>-1?t(this,Le)[r*10+v]=e.data[1]-64:console.warn(`NRPN 0x01${E.toString(16).padStart(2,"0")} is not supported.`),U()&&console.debug(`CH${r+1} voice NRPN ${E} commit`)}}else{if(je.indexOf(h)<0){let v=`NRPN 0x${h.toString(16).padStart(2,"0")}${E.toString(16).padStart(2,"0")} `;h==127?console.warn(`${v}is not necessary. Consider removing it.`):console.warn(`${v}is not supported.`)}else{let v=t(this,M)[r]-2;v<0?console.warn(`CH${r+1} cannot accept drum NRPN as type ${Fe[t(this,M)[r]]}.`):t(this,K)[(v*$.dpn+ae[h])*$.dnc+E]=e.data[1]}U()&&console.debug(`CH${r+1} (${Fe[t(this,M)[r]]}) drum NRPN ${h} commit`)}}else{let h=xt[t(this,p)[d+y[100]]],E=Ct[t(this,p)[d+y[100]]];t(this,p)[d+y[101]]==0&&h!=null&&(U()&&console.debug(`CH${r+1} RPN 0 ${t(this,p)[d+y[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],Mt[h][0]),Mt[h][1]),t(this,C)[r*$.rpn+h]=e.data[1],t(this,T)[r*$.rpnt+E]=1)}break}case 32:{switch(U()&&console.debug(`${de[t(this,D)]}, CH${r+1} LSB: ${e.data[1]}`),t(this,D)){case x.s90es:case x.motif:{this.setChType(r,[32,40].indexOf(e.data[1])>-1?this.CH_DRUMS:this.CH_MELODIC,t(this,D),!0);break}}this.dispatchEvent("voice",{part:r});break}case 38:{if(!t(this,xe)){let h=xt[t(this,p)[d+100]],E=Ct[t(this,p)[d+100]];t(this,p)[d+101]==0&&h!=null&&(t(this,C)[r*$.rpn+h+1]=e.data[1],t(this,T)[r*$.rpnt+E]=1)}break}case 64:{e.data[1]<64&&t(this,G).hoOf(r);break}case 66:{e.data[1]>>6?t(this,G).soOn(r):t(this,G).soOf(r);break}case 98:case 99:{w(this,xe,1);break}case 100:case 101:{w(this,xe,0);break}}t(this,p)[d+y[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:r,cc:e.data[0],data:e.data[1]})}},12:function(e){let r=e.channel;switch(t(this,D)){case x.s90es:case x.motif:{e.data&&this.setChActive(r,1);break}default:this.setChActive(r,1)}t(this,A)[r]=e.data,t(this,le)[r]=0,U()&&console.debug(`T:${e.track} C:${r} P:${e.data}`),this.dispatchEvent("voice",{part:r})},13:function(e){let r=this,d=e.channel;t(this,B).forEach(function(h){let E=h>>7;d==E&&(t(r,N)[h]=e.data,r.dispatchEvent("note",{part:d,note:h&127,velo:e.data,state:r.NOTE_SUSTAIN}))})},14:function(e){let r=e.channel;t(this,ge)[r]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:r,pitch:this.getPitchShift(r)})},15:function(e){Ft(e.data).forEach(r=>{let d=r[0],h=r[1];(t(this,Ye)[d]||function(){console.debug(`Unknown manufacturer ${d}.`)})(h,r.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(t(this,X)[e.meta]||function(d,h,E){}).call(this,e.data,e.track,e.meta),e.meta!=32&&w(this,Ce,0);let r=It.indexOf(e.meta)>-1;if(U()&&console.debug(e),r)return e.reply="meta",e}});k(this,Ye,{64:(e,r,d)=>{t(this,Oe).run(r,d,e)},65:(e,r,d)=>{if(r[0]<16)if(r[1]==72){let h=r[r.length-1],E=st(r.subarray(3,r.length-1));h==E?t(this,te).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad SD checksum ${h}. Should be ${E}.`)}else t(this,te).run(r,d,e);else{let h=r[r.length-1],E=st(r.subarray(2,r.length-1));h==E?t(this,te).run(r.subarray(0,r.length-1),d,e):console.warn(`Bad GS checksum ${h}. Should be ${E}.`)}},66:(e,r,d)=>{t(this,ye).run(r,d,e)},67:(e,r,d)=>{t(this,ee).run(r,d,e)},68:(e,r,d)=>{t(this,Ae).run(r,d,e)},71:(e,r,d)=>{t(this,De).run(r,d,e)},126:(e,r,d)=>{t(this,Te).run(r,d,e)},127:(e,r,d)=>{this.switchMode("gm"),t(this,Re).run(r,d,e)}});k(this,Te,void 0);k(this,Re,void 0);k(this,ee,void 0);k(this,te,void 0);k(this,ye,void 0);k(this,Oe,void 0);k(this,De,void 0);k(this,Ae,void 0);let e=this;w(this,J,new Uint8Array(256),At),t(this,he)[10]=new Uint8Array(512),w(this,Me,new ie),this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -150,16 +150,16 @@ _,`.split(` 122 006 000 `),this.addEventListener("metacommit",function(a){var c,n;let{data:i}=a;((c=t(e,j)[0])==null?void 0:c.type)==i.type&&((n=t(e,j)[0])!=null&&n.amend)?(t(e,j)[0].amend=i.amend,t(e,j)[0].data+=i.data):t(e,j).unshift(i)}),t(this,X)[1]=function(a){var i,c,n,s,o;switch(a=a.replaceAll(`\r `,` `).replaceAll("\r",` -`),a.slice(0,2)){case"@I":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(i=a.slice(2))==null?void 0:i.trimLeft()});break}case"@K":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(c=a.slice(2))==null?void 0:c.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(n=a.slice(2))==null?void 0:n.trimLeft()});break}case"@T":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(s=a.slice(2))==null?void 0:s.trimLeft()});break}case"@V":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(o=a.slice(2))==null?void 0:o.trimLeft()});break}case"XF":{let f=a.slice(2).split(":");switch(f[0]){case"hd":{f.slice(1).forEach((l,p)=>{l.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][p],data:l})});break}case"ln":{f.slice(1).forEach((l,p)=>{l.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][p],data:l})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:t(this,L)?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` +`),a.slice(0,2)){case"@I":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"Kar.Info",data:(i=a.slice(2))==null?void 0:i.trimLeft()});break}case"@K":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"Kar.Mode",data:(c=a.slice(2))==null?void 0:c.trimLeft()}),console.debug(`Karaoke mode active: ${a.slice(2)}`);break}case"@L":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"Kar.Lang",data:(n=a.slice(2))==null?void 0:n.trimLeft()});break}case"@T":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"KarTitle",data:(s=a.slice(2))==null?void 0:s.trimLeft()});break}case"@V":{w(this,L,!0),this.dispatchEvent("metacommit",{type:"Kar.Ver.",data:(o=a.slice(2))==null?void 0:o.trimLeft()});break}case"XF":{let f=a.slice(2).split(":");switch(f[0]){case"hd":{f.slice(1).forEach((l,b)=>{l.length&&this.dispatchEvent("metacommit",{type:["XfSngDte","XfSngRgn","XfSngCat","XfSongBt","XfSngIns","XfSngVoc","XfSngCmp","XfSngLrc","XfSngArr","XfSngPer","XfSngPrg","XfSngTag"][b],data:l})});break}case"ln":{f.slice(1).forEach((l,b)=>{l.length&&this.dispatchEvent("metacommit",{type:["XfKarLng","XfKarNme","XfKarCmp","XfKarLrc","XfKarArr","XfKarPer","XfKarPrg"][b],data:l})});break}default:this.dispatchEvent("metacommit",{type:"XfUnData",data:a})}break}default:t(this,L)?a[0]=="\\"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),amend:!0})):a[0]=="/"?(this.dispatchEvent("metacommit",{type:"KarLyric",data:"",mask:!0,amend:!1}),this.dispatchEvent("metacommit",{type:"KarLyric",data:a.slice(1),mask:!0,amend:!0})):this.dispatchEvent("metacommit",{type:"KarLyric",data:a,amend:!0}):a.split(` `).forEach((f,l)=>{this.dispatchEvent("metacommit",{type:"Cmn.Text",data:f,mask:l!=0})})}},t(this,X)[2]=function(a){this.dispatchEvent("metacommit",{type:"Copyrite",data:a})},t(this,X)[3]=function(a,i){i<1&&t(this,Ce)<1&&this.dispatchEvent("metacommit",{type:"TrkTitle",data:a})},t(this,X)[4]=function(a,i){this.dispatchEvent("metacommit",{type:"Instrmnt",data:a})},t(this,X)[5]=function(a){a.trim()==""?this.dispatchEvent("metacommit",{type:"C.Lyrics",data:"",amend:!1}):this.dispatchEvent("metacommit",{type:"C.Lyrics",data:a,amend:!0})},t(this,X)[6]=function(a){this.dispatchEvent("metacommit",{type:"C.Marker",data:a})},t(this,X)[7]=function(a){this.dispatchEvent("metacommit",{type:"CuePoint",data:a})},t(this,X)[32]=function(a){w(this,Ce,a[0]+1)},t(this,X)[33]=function(a,i){t(e,ke)[i]=a+1},t(this,X)[81]=function(a,i){w(e,Be,a/1e3)},t(this,X)[127]=function(a,i){t(e,Me).run(a,i)},t(this,Me).default=function(a){console.warn(`Unrecognized sequencer-specific byte sequence: ${a}`)},t(this,Me).add([67,0,1],function(a,i){t(e,ke)[i]=a[0]+1}),w(this,Te,new ie("universal non-realtime")),w(this,Re,new ie("universal realtime")),w(this,ee,new ie("Yamaha")),w(this,te,new ie("Roland")),w(this,ye,new ie("Korg")),w(this,Oe,new ie("Kawai")),w(this,De,new ie("Akai")),w(this,Ae,new ie("Casio"));let r=function(a){console.info(`Unrecognized SysEx in "${this.name}" set. -%o`,a)};t(this,Te).default=r,t(this,Re).default=r,t(this,ee).default=r,t(this,te).default=r,t(this,ye).default=r,t(this,Oe).default=r,t(this,De).default=r,t(this,Ae).default=r,t(this,Te).add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),w(e,L,t(e,L)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),t(this,Re).add([4,1],a=>{w(e,P,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,P))}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64),t(this,ee).add([76,0,0],a=>{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),w(e,L,!1),console.info("MIDI reset: XG");break}default:{let i=[0,0,0,0],c=(n,s)=>{i[s]=n};if(a.subarray(1).forEach((n,s)=>{let o=s+a[0];([c,c,c,c,f=>{w(this,P,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,P))},f=>{},f=>{}][o]||(()=>{}))(n,s)}),a[0]<4){let n=0;i.forEach(s=>{n=n<<4,n+=s}),n-=1024}}}}).add([76,2,1],a=>{let i="XG ";a[0]<32?(i+="reverb ",a.subarray(1).forEach((c,n)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${i}main type: ${Xe[s]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{e.setEffectTypeRaw(0,!0,s),console.debug(`${i}sub type: ${s+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{console.debug(`${i}time: ${bt(s)}s`)},s=>{console.debug(`${i}diffusion: ${s}`)},s=>{console.debug(`${i}initial delay: ${s}`)},s=>{console.debug(`${i}HPF cutoff: ${Pe[s]}Hz`)},s=>{console.debug(`${i}LPF cutoff: ${Pe[s]}Hz`)},s=>{console.debug(`${i}width: ${s}`)},s=>{console.debug(`${i}height: ${s}`)},s=>{console.debug(`${i}depth: ${s}`)},s=>{console.debug(`${i}wall type: ${s}`)},s=>{console.debug(`${i}dry/wet: ${s}`)},s=>{console.debug(`${i}send: ${q(s)}dB`)},s=>{console.debug(`${i}pan: ${s-64}`)},!1,!1,s=>{console.debug(`${i}delay: ${s}`)},s=>{console.debug(`${i}density: ${s}`)},s=>{console.debug(`${i}balance: ${s}`)},s=>{},s=>{console.debug(`${i}feedback: ${s}`)},s=>{}][a[0]+n]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(c)})):a[0]<64?(i+="chorus ",a.subarray(1).forEach((c,n)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${i}main type: ${Xe[s]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{e.setEffectTypeRaw(1,!0,s),console.debug(`${i}sub type: ${s+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{console.debug(`${i}LFO: ${pt[s]}Hz`)},s=>{},s=>{console.debug(`${i}feedback: ${s}`)},s=>{console.debug(`${i}delay offset: ${yt(s)}ms`)},s=>{},s=>{console.debug(`${i}low: ${Pe[s]}Hz`)},s=>{console.debug(`${i}low: ${s-64}dB`)},s=>{console.debug(`${i}high: ${Pe[s]}Hz`)},s=>{console.debug(`${i}high: ${s-64}dB`)},s=>{console.debug(`${i}dry/wet: ${s}`)},s=>{console.debug(`${i}send: ${q(s)}dB`)},s=>{console.debug(`${i}pan: ${s-64}`)},s=>{console.debug(`${i}to reverb: ${q(s)}dB`)},!1,s=>{},s=>{},s=>{},s=>{console.debug(`${i}LFO phase diff: ${(s-64)*3}deg`)},s=>{console.debug(`${i}input mode: ${s?"stereo":"mono"}`)},s=>{}][a[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(c)})):a[0]<86?(i+="variation ",a.subarray(1).forEach((c,n)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${i}main type: ${Xe[s]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},s=>{e.setEffectTypeRaw(2,!0,s),console.debug(`${i}sub type: ${s+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+n]||function(){})(c)})):a[0]<97?(i+="variation ",a.subarray(1).forEach((c,n)=>{[s=>{console.debug(`${i}send: ${q(s)}dB`)},s=>{console.debug(`${i}pan: ${s-64}`)},s=>{console.debug(`${i}to reverb: ${q(s)}dB`)},s=>{console.debug(`${i}to chorus: ${q(s)}dB`)},s=>{console.debug(`${i}connection: ${s?"system":"insertion"}`)},s=>{console.debug(`${i}channel: CH${s+1}`)},s=>{console.debug(`${i}mod wheel: ${s-64}`)},s=>{console.debug(`${i}bend wheel: ${s-64}`)},s=>{console.debug(`${i}channel after touch: ${s-64}`)},s=>{console.debug(`${i}AC1: ${s-64}`)},s=>{console.debug(`${i}AC2: ${s-64}`)}][a[0]-86+n](c)})):a[0]>111&&a[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((i,c)=>{let n=c+a[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let s=n-1>>2,o=n-1&3,f=`XG EQ ${s} ${["gain","freq","Q","shape"][o]}: `;[()=>{console.debug(`${f}${i-64}dB`)},()=>{console.debug(`${f}${i} (raw)`)},()=>{console.debug(`${f}${i/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!i]}`)}][o]()}})}).add([76,3],a=>{let i=a[0],c=a[1],n=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((s,o)=>{([f=>{e.setEffectTypeRaw(3+i,!1,f),console.info(`${n}main type: ${Xe[f]}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))},f=>{e.setEffectTypeRaw(3+i,!0,f),console.debug(`${n}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))}][c+o]||function(){})(s)})}).add([76,6,0],a=>{let i=a[0];i<64?e.setLetterDisplay(a.subarray(1),"XG letter display",i):w(e,we,Date.now())}).add([76,7,0],a=>{let i=a[0];w(e,V,0),w(e,ce,Date.now()+3200),t(e,J,fe).fill(0);let c=a.subarray(1);for(let n=0;n>6-m&1,m++})}).add([76,8],(a,i)=>{let c=e.chRedir(a[0],i,!0),n=a[1],s=$.cc*c,o=`XG CH${c+1} `,f=`Unknown XG part address ${n}.`;a.subarray(2).forEach((l,p)=>{n<1?console.debug(f):n<41?([()=>{t(e,u)[s+y[0]]=l,e.dispatchEvent("voice",{part:c})},()=>{t(e,u)[s+y[32]]=l,e.dispatchEvent("voice",{part:c})},()=>{t(e,A)[c]=l,e.dispatchEvent("voice",{part:c})},()=>{let m=e.chRedir(l,i,!0);t(e,I)[c]=m,c!=m&&(e.buildRchTree(),console.info(`${o}receives from CH${m+1}`))},()=>{t(e,W)[c]=+!l},()=>{},()=>{e.setChType(c,l,x.xg),console.debug(`${o}type: ${Fe[l]||l}`)},()=>{t(e,C)[$.rpn*c+3]=l,t(e,T)[$.rpnt*c+2]=1},!1,!1,()=>{t(e,u)[s+y[7]]=l},!1,!1,()=>{t(e,u)[s+y[10]]=l||128},!1,!1,()=>{t(e,u)[s+y[128]]=l},()=>{t(e,u)[s+y[93]]=l},()=>{t(e,u)[s+y[91]]=l},()=>{t(e,u)[s+y[94]]=l},()=>{t(e,u)[s+y[76]]=l},()=>{t(e,u)[s+y[77]]=l},()=>{t(e,u)[s+y[78]]=l},()=>{t(e,u)[s+y[74]]=l},()=>{t(e,u)[s+y[71]]=l},()=>{t(e,u)[s+y[73]]=l},()=>{t(e,u)[s+y[75]]=l},()=>{t(e,u)[s+y[72]]=l}][n+p-1]||(()=>{}))():n<48?console.debug(f):n<111?n>102&&n<105&&(t(e,u)[s+y[[5,65][n&1]]]=l):n<114?console.debug(f):n<116?console.debug(`${o}EQ ${["bass","treble"][n&1]} gain: ${l-64}dB`):n<118?console.debug(f):n<120?console.debug(`${o}EQ ${["bass","treble"][n&1]} freq: ${l}`):console.debug(f)})}).add([76,9],(a,i)=>{let c=e.chRedir(a[0],i,!0),n=a[1],s=`PLG-150VL CH${c+1} `;a.subarray(2).forEach((o,f)=>{let l=f+n;switch(l){case 1:{console.info(`${s}breath mode: ${["system","breath","velocity","touch EG"][o]}`);break}case 0:case 27:case 28:break;default:if(l<27){let p=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${s}${p} control source: ${Et(o)}`),o&&o<96&&e.allocateAce(o)):console.debug(`${s}${p} scale break point: ${o}`):console.debug(`${s}${p} depth: ${o-64}`)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][a[0]]} for CH${a[2]+1}.`)}).add([73,0,0],(a,i)=>{let c=a[0],n="MU1000 System: ";a.subarray(1).forEach((s,o)=>{let f=c+o;f==8?console.debug(`${n}LCD contrast set to ${s}.`):f==18?(w(e,Z,s?126:0),console.debug(`${n}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):f>=64&&f<69&&[()=>{e.dispatchEvent("channelactive",s)},()=>{s<8?(e.dispatchEvent("channelmin",s<<4),console.debug(`Octavia System: Minimum CH${(s<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{s<8?(e.dispatchEvent("channelmax",(s<<4)+15),console.debug(`Octavia System: Maximum CH${(s<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{w(e,se,!!s),console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][f-64]()})}).add([73,10,0],(a,i)=>{let c=a[0],n=`MU1000 RS${t(e,se)?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let s=e.chRedir(0,i,!0);t(e,se)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${n}Show CH1~64`);break}case 3:{let s=e.chRedir(a[1]<<5,i,!0);t(e,se)&&e.dispatchEvent("channelmin",s),t(e,se)&&e.dispatchEvent("channelmax",s+31),console.info(`${n}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${n}unknown switch ${c} invoked.`)}else if(c<32){if(t(e,se)){let s=e.chRedir(c-16+(t(e,Ie)<<4),i,!0);e.dispatchEvent("channelactive",s)}}else if(c<36){let s=e.chRedir(c-32<<4,i,!0);t(e,se)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),w(e,Ie,c-32)),console.info(`${n}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(a,i)=>{let c=e.chRedir(a[0],i,!0),n=`PLG-100SG CH${c+1} `,s=Date.now();if(a[1]==0){let o="",f=0;a.subarray(2).forEach((l,p)=>{p%2==0?o+=gt[l]||l.toString().padStart("0"):f+=l*13}),s>=t(e,Ge)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${$t(o)}`,amend:!0}),w(e,Ge,s+Math.ceil(f/2)+t(e,Be)),U()&&console.debug(`${n}vocals: ${o}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)});let d=function(a,i,c,n){},h=function(a,i){let c=a*$.dpn,n=i[0],s=i[1];i.subarray(2).forEach((o,f)=>{let l=f+s,p=-1;l<16?([()=>{p=24},()=>{p=25},()=>{p=26},()=>{},()=>{p=28},()=>{p=29},()=>{p=30},()=>{p=31},()=>{},()=>{},()=>{},()=>{p=20},()=>{p=21},()=>{p=22},()=>{p=23},()=>{}][l]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))():l<32||(l<40?([()=>{p=48},()=>{p=49},!1,!1,()=>{p=52},()=>{p=53}][l-32]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))():l<80||([()=>{p=36}][l-80]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))()),p>=0?(U()&&console.debug(c,p,n,o),t(e,K)[(c+ae[p])*$.dnc+n]=o):U()&&console.debug(`XG-style drum param ${l} has no writes.`)})},E=function(a,i,c){let n=a*$.dpn,s=(i<<7)+c[0];c.subarray(1).forEach((o,f)=>{let l=f+s,p=l&127,m=l>>7,S=-1;m>1&&([()=>{S=26},()=>{},()=>{S=28},()=>{S=29},()=>{S=30},()=>{},()=>{},()=>{S=31}][m-2]||(()=>{console.debug(`Unknown GS-style drum param ${m} on set ${a+1}.`)}))(),S>-1?(U()&&console.debug(n,S,p,o),t(e,K)[(n+ae[S])*$.dnc+p]=o):U()&&console.debug(`GS-style drum param ${m} has no writes.`)})};t(this,ee).add([76,48],(a,i,c)=>{h(0,a)}).add([76,49],(a,i,c)=>{h(1,a)}).add([76,50],(a,i,c)=>{h(2,a)}).add([76,51],(a,i,c)=>{h(3,a)}).add([76,52],(a,i,c)=>{h(4,a)}).add([76,53],(a,i,c)=>{h(5,a)}).add([76,54],(a,i,c)=>{h(6,a)}).add([76,55],(a,i,c)=>{h(7,a)}),t(this,ee).add([89,0],(a,i,c)=>{if(e.eprom){let n=a[0],s=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);U()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${n} bytes.`);let o=e.eprom.data;a.subarray(4).forEach((f,l)=>{let p=l>>3,m=l&7;if(m==7)for(let S=0;S<7;S++)o[s+7*p+S]+=(f>>6-S&1)<<7;else o[s+7*p+m]=f})}}).add([89,1],(a,i,c)=>{let n=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];U()&&console.debug(`MU1000 EPROM jump to 0x${n.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=n)}).add([89,2],(a,i,c)=>{if(e.eprom){let n=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);U()&&console.debug(`MU1000 EPROM write to 0x${n.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;a.subarray(4).forEach((o,f)=>{let l=f>>3,p=f&7;if(p==7)for(let m=0;m<7;m++)s[n+7*l+m]+=(o>>6-m&1)<<7;else s[n+7*l+p]=o})}}).add([89,3],(a,i,c)=>{}),t(this,ee).add([39,48],(a,i,c)=>{}).add([43,0,0],(a,i,c)=>{let n=[0,0,0,0],s=(o,f)=>{n[f]=o};if(a.subarray(1).forEach((o,f)=>{let l=f+a[0];[s,s,s,s,()=>{w(this,P,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,P))},()=>o-64,()=>o||128,()=>o,()=>o,()=>{console.debug(`TG300 variation on cc${o}.`)}][l](o,l)}),a[0]<4){let o=0;n.forEach(f=>{o=o<<4,o+=f}),o-=1024}}).add([43,1,0],(a,i,c)=>{}).add([43,2],(a,i,c)=>{let n=e.chRedir(a[0],i,!0),s=a[1],o=$.cc*n,f=`TG300 CH${n+1} `;a.subarray(2).forEach((l,p)=>{p<5?([()=>{},()=>{t(e,u)[o+y[0]]=l,e.dispatchEvent("voice",{part:n})},()=>{t(e,u)[o+y[32]]=l,e.dispatchEvent("voice",{part:n})},()=>{t(e,A)[n]=l,e.dispatchEvent("voice",{part:n})},()=>{let m=e.chRedir(l,i,!0);t(e,I)[n]=m,n!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))}][p+s]||(()=>{}))(l,p+s):p<21||(p<47?([()=>{t(e,W)[n]=+!l},()=>{},()=>{},()=>{t(e,C)[$.rpn*n+3]=l,t(e,T)[$.rpnt*n+2]=1},()=>{},()=>{t(e,u)[o+y[7]]=l},!1,!1,()=>{t(e,u)[o+y[10]]=l||128},!1,!1,()=>{console.debug(`${f} AC1 at cc${l}`)},()=>{console.debug(`${f} AC2 at cc${l}`)},()=>{t(e,u)[o+y[128]]=l},()=>{t(e,u)[o+y[93]]=l},()=>{t(e,u)[o+y[91]]=l},()=>{t(e,u)[o+y[94]]=l},()=>{t(e,u)[o+y[76]]=l},()=>{t(e,u)[o+y[77]]=l},()=>{t(e,u)[o+y[74]]=l},()=>{t(e,u)[o+y[71]]=l},()=>{t(e,u)[o+y[73]]=l},()=>{t(e,u)[o+y[75]]=l},()=>{t(e,u)[o+y[72]]=l},()=>{t(e,u)[o+y[78]]=l}][p+s-21]||(()=>{}))(l,p+s):p<95||([()=>{t(e,u)[o+y[65]]=l},()=>{t(e,u)[o+y[5]]=l}][p+s-95]||(()=>{}))(l,p+s))})}).add([43,7,0],(a,i,c)=>{let n=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",n)}).add([43,7,1],(a,i,c)=>{w(e,V,0),w(e,ce,Date.now()+3200),t(e,J,fe).fill(0),a.forEach(function(n,s){let o=Math.floor(s/16),f=s%16,l=(f*3+o)*7,p=7,m=0;for(l-=f*5,o==2&&(p=2);m>6-m&1,m++})}),t(this,te).add([66,18,0,0,127],(a,i,c)=>{e.switchMode("gs",!0),t(e,u)[$.cc*9]=120,t(e,u)[$.cc*25]=120,t(e,u)[$.cc*41]=120,t(e,u)[$.cc*57]=120,w(e,Z,3),w(e,L,!1),t(e,be).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,i,c)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),t(e,u)[$.cc*9]=120,t(e,u)[$.cc*25]=120,t(e,u)[$.cc*41]=120,t(e,u)[$.cc*57]=120,w(e,L,!1),t(e,be).fill(0),console.info("MIDI reset: GS");break}default:{let n=[0,0,0,0],s=(o,f)=>{n[f]=o};if(a.subarray(1).forEach((o,f)=>{let l=f+a[0];[s,s,s,s,p=>{w(this,P,p*129/16383*100),e.dispatchEvent("mastervolume",t(e,P))},p=>{},p=>{}][l](o,f)}),a[0]<4){let o=0;n.forEach(f=>{o=o<<4,o+=f}),o-=1024}}}}).add([66,18,64,1],a=>{let i=a[0];if(i<16){let c="".padStart(i," ");a.subarray(1).forEach((n,s)=>{c+=String.fromCharCode(Math.max(32,n))}),c=c.padEnd(16," "),console.debug(`GS patch name: ${c}`)}else i<48||(i<65?a.subarray(1).forEach((c,n)=>{let s=`GS ${i+n>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${tt[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${c}ms`)},()=>{console.info(`${s}type: ${mt[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${q(c)}`)},()=>{console.debug(`${s}to delay: ${q(c)}`)}][i+n-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?a.subarray(1).forEach((c,n)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${vt[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${q(c)}`)}][i+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],a=>{let i="GS EQ ";a.subarray(1).forEach((c,n)=>{([()=>{console.debug(`${i}low freq: ${[200,400][c]}Hz`)},()=>{console.debug(`${i}low gain: ${c-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][c]}Hz`)},()=>{console.debug(`${i}high gain: ${c-64}dB`)}][a[0]+n]||function(){console.warn(`Unknown GS EQ address: ${a[0]+n}`)})()})}).add([66,18,64,3],a=>{let i="GS EFX ",c=function(n,s){let o=wt(t(e,Y).subarray(10,12),s,n);o&&console.debug(`${i}${at(t(e,Y).subarray(10,12))} ${o}`)};a.subarray(1).forEach((n,s)=>{([()=>{e.setEffectTypeRaw(3,!1,32+n),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,n),console.info(`${i}type: ${at(t(e,Y).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,()=>{console.debug(`${i}to reverb: ${q(n)}dB`)},()=>{console.debug(`${i}to chorus: ${q(n)}dB`)},()=>{console.debug(`${i}to delay: ${q(n)}dB`)},!1,()=>{console.debug(`${i}1 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${i}1 depth: ${n-64}`)},()=>{console.debug(`${i}2 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${i}2 depth: ${n-64}`)},()=>{console.debug(`${i}to EQ: ${n?"ON":"OFF"}`)}][a[0]+s]||function(o,f){console.warn(`Unknown GS EFX address: ${f}`)})(n,a[0]+s)})}).add([66,18,65],a=>{E((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],a=>{var i;switch(a[0]){case 0:{let c=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",c);break}case 32:{w(e,ce,Date.now()+3200),a[1]==0&&(w(e,V,Math.max(Math.min(a[2]-1,9),0)),U()&&console.debug(`GS switch display page ${a[2]-1}.`));break}default:if(a[0]<6){t(e,V)>9&&w(e,V,0);let c=a[0]-1<<1|a[1]>>6;t(e,V)==c&&w(e,ce,Date.now()+3200),(i=t(e,he)[c])!=null&&i.length||(t(e,he)[c]=new Uint8Array(256));let n=t(e,he)[c];U()&&console.debug(`GS frame draw page ${c}.`);let s=a[1]&63;n.fill(0),a.subarray(2).forEach(function(f,l){let p=l+s,m=Math.floor(p/16),S=p%16,O=(S*4+m)*5,H=5,F=0;for(O-=S*4,m==3&&(H=1);F>4-F&1,F++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let b=function(a,i,c){let n=a[0],s=$.cc*i,o=$.rpn*i,f=`GS CH${i+1} `;n<3?(a.subarray(1).forEach((l,p)=>{[()=>{t(e,u)[s+y[0]]=l},()=>{t(e,A)[i]=l},()=>{let m=0;l<16?m=e.chRedir(l,c,!0):m=$.ch,t(e,I)[i]=m,i!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))}][n+p]()}),e.dispatchEvent("voice",{part:i})):n<19||(n<44?a.subarray(1).forEach((l,p)=>{([()=>{t(e,W)[i]=+!l},!1,()=>{e.setChType(i,l<<1,x.gs),console.debug(`${f}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{t(e,C)[o+3]=l,t(e,T)[$.rpnt*i+2]=1},!1,()=>{t(e,u)[s+y[7]]=l},!1,!1,()=>{t(e,u)[s+y[10]]=l||128},!1,!1,()=>{console.debug(`${f}CC 1: cc${l}`)},()=>{console.debug(`${f}CC 2: cc${l}`)},()=>{t(e,u)[s+y[93]]=l},()=>{t(e,u)[s+y[91]]=l},!1,!1,()=>{t(e,C)[o+1]=l,t(e,T)[$.rpnt*i+1]=1},()=>{t(e,C)[o+2]=l,t(e,T)[$.rpnt*i+1]=1},()=>{t(e,u)[s+y[94]]=l}][n+p-19]||(()=>{}))()}):n<76||console.debug(`Unknown GS part address: ${n}`))},v=function(a,i){let c=a[0],n=`GS CH${i+1} `;c<2?a.subarray(1).forEach((s,o)=>{[()=>{t(e,u)[$.cc*i+y[32]]=s},()=>{}][c+o]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?a.subarray(1).forEach((s,o)=>{[()=>{console.debug(`${n}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${n}EFX: o${["ff","n"][s]}`),t(e,Ne)[i]=s,e.dispatchEvent("partefxtoggle",{part:i,active:s})}][c+o-32]()}):console.warn(`Unknown GS misc address: ${c}`)};t(this,te).add([66,18,64,16],(a,i)=>{b(a,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(a,i)=>{b(a,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(a,i)=>{b(a,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(a,i)=>{b(a,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(a,i)=>{b(a,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(a,i)=>{b(a,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(a,i)=>{b(a,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(a,i)=>{b(a,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(a,i)=>{b(a,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(a,i)=>{b(a,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(a,i)=>{b(a,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(a,i)=>{b(a,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(a,i)=>{b(a,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(a,i)=>{b(a,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(a,i)=>{b(a,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(a,i)=>{b(a,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(a,i)=>{v(a,e.chRedir(9,i,!0))}).add([66,18,64,65],(a,i)=>{v(a,e.chRedir(0,i,!0))}).add([66,18,64,66],(a,i)=>{v(a,e.chRedir(1,i,!0))}).add([66,18,64,67],(a,i)=>{v(a,e.chRedir(2,i,!0))}).add([66,18,64,68],(a,i)=>{v(a,e.chRedir(3,i,!0))}).add([66,18,64,69],(a,i)=>{v(a,e.chRedir(4,i,!0))}).add([66,18,64,70],(a,i)=>{v(a,e.chRedir(5,i,!0))}).add([66,18,64,71],(a,i)=>{v(a,e.chRedir(6,i,!0))}).add([66,18,64,72],(a,i)=>{v(a,e.chRedir(7,i,!0))}).add([66,18,64,73],(a,i)=>{v(a,e.chRedir(8,i,!0))}).add([66,18,64,74],(a,i)=>{v(a,e.chRedir(10,i,!0))}).add([66,18,64,75],(a,i)=>{v(a,e.chRedir(11,i,!0))}).add([66,18,64,76],(a,i)=>{v(a,e.chRedir(12,i,!0))}).add([66,18,64,77],(a,i)=>{v(a,e.chRedir(13,i,!0))}).add([66,18,64,78],(a,i)=>{v(a,e.chRedir(14,i,!0))}).add([66,18,64,79],(a,i)=>{v(a,e.chRedir(15,i,!0))}),t(this,ye).add([54,65],(a,i)=>{e.switchMode("x5d");let c=(a[1]<<7)+a[0],n=(a[3]<<7)+a[2],s=e.chRedir(c&15,i,!0),o=$.cc*s;[()=>{n<1||(n<101?(e.setChType(s,e.CH_MELODIC,x.x5d),t(e,A)[s]=n-1,t(e,u)[o+y[0]]=82):n<229?(e.setChType(s,e.CH_MELODIC,x.x5d),t(e,A)[s]=n-101,t(e,u)[o+y[0]]=56):(e.setChType(s,e.CH_DRUMS,x.x5d),t(e,A)[s]=Ot[n-229]||0,t(e,u)[o+y[0]]=62)),e.dispatchEvent("voice",{part:s})},()=>{t(e,u)[o+y[7]]=n},()=>{n<31&&(t(e,u)[o+y[10]]=Math.round((n-15)*4.2+64))},()=>{t(e,u)[o+y[93]]=Ve(n)},()=>{t(e,u)[o+y[91]]=Ve(n)},()=>{t(e,C)[s*$.rpn+3]=n>8191?n-16320:64+n,t(e,T)[$.rpnt*s+2]=1},()=>{t(e,C)[s*$.rpn+1]=n>8191?n-16320:64+n,t(e,T)[$.rpnt*s+1]=1},()=>{n>0&&(t(e,C)[s*$.rpn]=n,t(e,T)[$.rpnt*s]=1)},()=>{}][c>>4]()}).add([54,76,0],(a,i)=>{e.switchMode("x5d",!0);let c="",n=82,s=0,o=0,f="MSB PRG LSB NME";ne(a,function(l,p){if(p<16400){let m=p%164;switch(!0){case m<10:{l>31&&(c+=String.fromCharCode(l));break}case m==11:{f+=` -${n} ${s} ${o} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}s>99&&(n=90,s=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(f),U()&&console.debug(f),e.forceVoiceRefresh()}).add([54,77,0],(a,i)=>{e.switchMode("x5d",!0);let c="",n=90,s=0,o=0,f="MSB PRG LSB NME";ne(a,function(l,p){if(p<13600){let m=p%136;switch(!0){case m<10:{l>31&&(c+=String.fromCharCode(l));break}case m==11:{f+=` -${n} ${s} ${o} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f),U()&&console.debug(f),e.forceVoiceRefresh()}).add([54,78],(a,i)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,i)=>{e.switchMode("x5d",!0),ne(a,(c,n)=>{n>0&&n<3&&(e.setEffectType(n-1,44,c),e.dispatchEvent(`efx${["reverb","chorus"][n-1]}`,e.getEffectType(n-1)))})}).add([54,104],(a,i)=>{e.switchMode("x5d",!0),ne(a,function(c,n,s,o){if(n<192){let f=e.chRedir(Math.floor(n/12),i,!0),l=f*$.cc;switch(n%12){case 0:{c<128?(e.setChType(f,e.CH_MELODIC,x.x5d),t(e,u)[l+y[0]]=82,t(e,A)[f]=c):(e.setChType(f,e.CH_DRUMS,x.x5d),t(e,u)[l+y[0]]=62,t(e,A)[f]=Ot[c-128]),c>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{t(e,u)[l+y[7]]=c;break}case 2:{t(e,C)[f*$.rpn+3]=c>127?c-192:64+c,t(e,T)[$.rpnt*f+2]=1;break}case 3:{t(e,C)[f*$.rpn+1]=c>127?c-192:64+c,t(e,T)[$.rpnt*f+1]=1;break}case 4:{c<31&&(t(e,u)[l+y[10]]=Math.round((c-15)*4.2+64));break}case 5:{let p=c>>4,m=c&15;t(e,u)[l+y[91]]=Ve(m),t(e,u)[l+y[93]]=Ve(p);break}case 10:break;case 11:{let p=e.chRedir(c&15,i,!0),m=c>>4;t(e,I)[f]=c,(p!=f||m)&&(console.info(`X5D Part CH${f+1} receives from CH${p+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(n-192,i,!0)}})}),t(this,te).add([22,18,127],a=>{e.switchMode("mt32",!0),w(e,L,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,i,c)=>{e.switchMode("mt32");let n=e.chRedir(c,i,!0),s=a[1];a.subarray(2).forEach((o,f)=>{let l=f+s;t(e,$e)[l+(n-1)*16]=o,([!1,()=>{let p=t(e,$e)[n-1<<4];if(p<3){if(t(e,le)[n]=1,p==2)for(let m=0;m{t(e,C)[n*$.rpn+3]=o+40,t(e,T)[$.rpnt*n+2]=1},()=>{t(e,C)[n*$.rpn+1]=o+14,t(e,T)[$.rpnt*n+1]=1},()=>{t(e,C)[n*$.rpn]=o,t(e,T)[$.rpnt*n]=1},!1,()=>{t(e,u)[$.cc*n+y[91]]=o?127:0},!1,()=>{t(e,u)[$.cc*n+y[7]]=o},()=>{t(e,u)[$.cc*n+y[10]]=Math.ceil(o*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(a,i,c)=>{e.switchMode("mt32");let n=c&7;console.debug(`MT-32 slot #${c+1} Drum: ${a}`);let s=a[0]<<7|a[1];a.subarray(2).forEach((o,f)=>{let l=f+s,p=(l>>2)+24,m=l&3,S=n*$.dpn;if(U()&&console.debug(`MT-32 temp drum note ${p} param ${m}: ${o}`),p<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${p}`);return}[()=>{},()=>{t(e,K)[(S+ae[26])*$.dnc+p]=Math.round(o*1.27)},()=>{t(e,K)[(S+ae[26])*$.dnc+p]=o*9+1&127},()=>{t(e,K)[(S+ae[26])*$.dnc+p]=o?127:0}][m]()})}).add([22,18,2],(a,i,c)=>{e.switchMode("mt32");let n=e.chRedir(c,i,!0),s=a[1]+(a[0]<<7);s<10&&(t(e,le)[n]=1),a.subarray(2).forEach((o,f)=>{let l=f+s;l<14&&(t(e,re)[(n-1)*$.cmt+l]=o)}),e.dispatchEvent("voice",{part:n})}).add([22,18,3],(a,i,c)=>{e.switchMode("mt32");let n=c&7;if(a[0]){let s=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((o,f)=>{let l=f+s,p=(l>>2)+24,m=l&3,S=n*$.dpn;if(U()&&console.debug(`MT-32 dev drum note ${p} param ${m}: ${o}`),p<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${p}`);return}[()=>{},()=>{t(e,K)[(S+ae[26])*$.dnc+p]=Math.round(o*1.27)},()=>{t(e,K)[(S+ae[26])*$.dnc+p]=o*9+1&127},()=>{t(e,K)[(S+ae[26])*$.dnc+p]=o?127:0}][m]()})}else{let s=a[1];a.subarray(2).forEach((o,f)=>{let l=f+s;t(e,$e)[l]=o;let p=e.chRedir(1+(l>>4),i,!0),m=l&15;([!1,()=>{let S=t(e,$e)[p-1<<4];if(S<3)if(t(e,le)[p]=1,S==2)for(let O=0;O{t(e,C)[p*$.rpn+3]=o+40,t(e,T)[$.rpnt*p+2]=1},()=>{t(e,C)[p*$.rpn+1]=o+14,t(e,T)[$.rpnt*p+1]=1},()=>{t(e,C)[p*$.rpn]=o,t(e,T)[$.rpnt*p]=1},!1,()=>{t(e,u)[$.cc*p+y[91]]=o?127:0},!1,()=>{t(e,u)[$.cc*p+y[7]]=o},()=>{t(e,u)[$.cc*p+y[10]]=Math.ceil(o*9.05)}][m]||(()=>{}))()})}}).add([22,18,4],(a,i,c)=>{e.switchMode("mt32");let n=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((o,f)=>{let l=f+n,p=e.chRedir(Math.floor(l/246+1),i,!0),m=l%246;m<14&&(t(e,re)[(p-1)*$.cmt+m]=o),m<10&&(t(e,le)[p]=1),s.indexOf(p)<0&&s.push(p)}),s.forEach(o=>{e.dispatchEvent("voice",{part:o})})}).add([22,18,5],(a,i,c)=>{e.switchMode("mt32");let n=(a[0]<<7)+a[1];a.subarray(2).forEach((s,o)=>{let f=n+o,l=Math.floor(f/8),p=f&7,m=l*8;t(e,He)[f]=s,([!1,()=>{let S=t(e,He)[m];if(S<3){let O="";if(S==2){let H=$.cmt*l;O=`MT-m:${s.toString().padStart(3,"0")}`}else O=e.baseBank.get(0,s+(S<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l}),e.userBank.load(`MSB LSB PRG NME -000 127 ${l} ${O}`,!0)}}][p]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,i,c)=>{e.switchMode("mt32");let n=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((s,o)=>{let f=n+o;f<$.cmt&&(t(e,Ee)[(a[0]>>1)*$.cmt+f]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(a,i,c)=>{e.switchMode("mt32");let n=a[1],s=!1,o=function(f,l){t(e,I)[l-12]=f,s=!0};a.subarray(2).forEach((f,l)=>{let p=l+n;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,o,o,o,o,o,o,o,o,o,()=>{w(e,P,f),e.dispatchEvent("mastervolume",t(e,P))}][p]||(()=>{}))(f,l)}),s&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let i=a[1],c=" ".repeat(i);a.subarray(2).forEach(n=>{n>31?c+=String.fromCharCode(n):c+=" "}),w(e,ve,c.padStart(20," ")),w(e,we,Date.now()+3200)}).add([22,18,82],(a,i)=>{let c=e.chRedir(0,i,!0);for(let n=0;n<16;n++)t(e,G).ano(c+n),n&&n<10&&(t(e,A)[c+n]=rt[n-1]);console.info("MT-32 alt reset complete.")}),t(this,ye).add([66,0],(a,i)=>{e.switchMode("ns5r",!0),w(e,L,!1),console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,i)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),w(e,L,!1)}).add([66,18,0,0],(a,i)=>{let c=a[0];switch(c){case 124:case 126:case 127:{e.switchMode("ns5r",!0),w(e,L,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(c<10){let n=[0,0,0,0],s=(o,f)=>{n[f]=o};if(a.subarray(1).forEach((o,f)=>{[s,s,s,s,()=>{w(e,P,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,P))},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][c+f]()}),a[0]<4){let o=0;n.forEach(f=>{o=o<<4,o+=f}),o-=1024}}}}).add([66,18,0,1],(a,i)=>{}).add([66,18,0,2],(a,i)=>{}).add([66,18,1],(a,i)=>{let c=e.chRedir(a[0],i,!0),n=c*$.cc,s=a[1],o=`NS5R CH${c+1} `;a.subarray(2).forEach((f,l)=>{let p=s+l;p<3?([()=>{t(e,u)[n+y[0]]=f||121},()=>{t(e,u)[n+y[32]]=f},()=>{t(e,A)[c]=f}][p](),e.dispatchEvent("voice",{part:c})):p<8||(p<14?[()=>{let m=e.chRedir(f,i,!0);t(e,I)[c]=m,c!=m&&(e.buildRchTree(),console.info(`${o}receives from CH${m+1}`))},()=>{t(e,W)[c]=+!f},()=>{e.setChType(c,f,x.ns5r),console.debug(`${o}type: ${Fe[f]}`)},()=>{t(e,C)[$.rpn*c+3]=f,t(e,T)[$.rpnt*c+2]=1},()=>{},()=>{}][p-8]():p<16||(p<33?[()=>{t(e,u)[n+y[7]]=f},()=>{t(e,u)[n+y[11]]=f},()=>{},()=>{},()=>{t(e,u)[n+y[10]]=f||128},()=>{},()=>{},()=>{t(e,u)[n+y[93]]=f},()=>{t(e,u)[n+y[91]]=f},()=>{t(e,u)[n+y[76]]=f},()=>{t(e,u)[n+y[77]]=f},()=>{t(e,u)[n+y[78]]=f},()=>{t(e,u)[n+y[74]]=f},()=>{t(e,u)[n+y[71]]=f},()=>{t(e,u)[n+y[73]]=f},()=>{t(e,u)[n+y[75]]=f},()=>{t(e,u)[n+y[72]]=f}][p-16]():p<112||p<114&&[()=>{t(e,u)[n+y[5]]=f},()=>{t(e,u)[n+y[65]]=f}][p-112]()))})}).add([66,18,8,0],(a,i)=>{let c=a[0];if(c<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let n=c-32;w(e,ce,Date.now()+3200),w(e,V,10),t(e,J,fe).fill(0);let s=a.subarray(1),o=4;s.forEach(function(f,l){let p=l+n,m=p>>4,S=p&15;if(p<80){let O=m>3,H=0,F=m0;)t(e,J,fe)[S*32+m*7+(F-H)]=O&1,O=O>>1,H++}})}}).add([66,18,48],(a,i,c)=>{h(0,a)}).add([66,18,49],(a,i,c)=>{h(1,a)}).add([66,18,50],(a,i,c)=>{h(2,a)}).add([66,18,51],(a,i,c)=>{h(3,a)}).add([66,18,52],(a,i,c)=>{h(4,a)}).add([66,18,53],(a,i,c)=>{h(5,a)}).add([66,18,54],(a,i,c)=>{h(6,a)}).add([66,18,55],(a,i,c)=>{h(7,a)}).add([66,52],(a,i)=>{e.switchMode("ns5r",!0),w(e,L,!1);let c="";ne(a,(n,s)=>{s<8?(n>31&&(c+=String.fromCharCode(n)),s==7&&(e.aiEfxName=c)):s<10&&(e.setEffectType(s-8,44,n),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(a,i)=>{e.switchMode("ns5r",!0),w(e,L,!1),ne(a,function(c,n){switch(!0){case n<2944:{let s=e.chRedir(Math.floor(n/92),i,!0),o=s*$.cc;switch(n%92){case 0:{t(e,u)[o+y[0]]=c||121,e.dispatchEvent("voice",{part:s});break}case 1:{t(e,u)[o+y[32]]=c,e.dispatchEvent("voice",{part:s});break}case 2:{t(e,A)[s]=c,c>0&&e.setChActive(s,1),e.dispatchEvent("voice",{part:s});break}case 3:{let f=e.chRedir(c,i,!0);t(e,I)[s]=f,s!=f&&(console.info(`NS5R CH${s+1} receives from CH${f+1}.`),e.buildRchTree())}case 7:break;case 8:{t(e,C)[s*$.rpn+3]=c<40||c>88?c+(c>63?-192:64):c,t(e,T)[$.rpnt*s+2]=1;break}case 9:case 10:{t(e,u)[o+y[7]]=c;break}case 11:{t(e,u)[o+y[11]]=c;break}case 14:{t(e,u)[o+y[10]]=c||128;break}case 19:{t(e,u)[o+y[93]]=c;break}case 20:{t(e,u)[o+y[91]]=c;break}case 84:{t(e,u)[o+y[65]]=c;break}case 85:{t(e,u)[o+y[5]]=c;break}}break}case n<3096:break;case n<3134:break;case n<8566:break}})}).add([66,54],(a,i)=>{e.switchMode("ns5r",!0);let c="",n=80,s=0,o=0,f="MSB PRG LSB NME";ne(a,function(l,p){let m=p%158;switch(!0){case m<10:{l>31&&(c+=String.fromCharCode(l));break}case m==11:{n=l&127;break}case m==12:{o=l&127;break}case m==13:{f+=` -${n} ${s} ${o} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(f),U()&&console.debug(f),e.forceVoiceRefresh()}).add([66,55],(a,i)=>{e.switchMode("ns5r",!0);let c="",n=88,s=0,o=0,f="MSB PRG LSB NME";ne(a,function(l,p){let m=p%126;switch(!0){case m<10:{l>31&&(c+=String.fromCharCode(l));break}case m==11:break;case m==12:break;case m==13:{f+=` -${n} ${s} ${o} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(f),U()&&console.debug(f),e.forceVoiceRefresh()}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let i=new Uint8Array(5760);ne(a,(c,n,s)=>{if(n<720)for(let o=0;o<8;o++)i[n*8+o]=c>>7-o&1}),e.dispatchEvent("screen",{type:"ns5r",data:i})}).add([76],(a,i,c)=>{t(e,ye).run([66,...a],i,c)}),t(this,Oe).add([16,0,8,0],(a,i,c)=>{let n=(a[2]<<4)+a[3],s="K11 ";([()=>{e.switchMode("k11",!0),w(e,L,!1),w(e,Z,n?4:0),console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,n),console.debug(`${s}reverb type: ${n}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${s}reverb time: ${n}`)},()=>{console.debug(`${s}reverb time: ${n}`)},()=>{console.debug(`${s}reverb predelay: ${n}`)},()=>{console.debug(`${s}reverb predelay: ${n}`)},()=>{console.debug(`${s}depth high: ${n}`)},()=>{console.debug(`${s}depth high: ${n}`)},()=>{console.debug(`${s}depth low: ${n}`)},()=>{console.debug(`${s}depth low: ${n}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,i,c)=>{let n=e.chRedir(a[1],i,!0),s=$.cc*n,o=$.rpn*n,f=(a[3]<<4)+a[4],l=`K11 CH${n+1} `;([()=>{f<128?(e.setChType(n,e.CH_MELODIC,x.k11),t(e,u)[s+y[0]]=0,t(e,A)[n]=f):(e.setChType(n,e.CH_DRUMS,x.k11),t(e,A)[n]=f-128),e.dispatchEvent("voice",{part:n})},()=>{let p=e.chRedir(f,i,!0);t(e,I)[n]=p,n!=p&&(e.buildRchTree(),console.info(`${l}receives from CH${p+1}`))},()=>{t(e,u)[s+y[7]]=f},()=>{uupThis.setChActive(n,f)},()=>{t(e,u)[s+y[10]]=f},()=>{t(e,C)[o+3]=f+40,t(e,T)[$.rpnt*n+2]=1},()=>{t(e,C)[o+1]=f>>1,t(e,C)[o+2]=f&1,t(e,T)[$.rpnt*n+1]=1},()=>{t(e,u)[s+y[91]]=f?127:0},()=>{},()=>{t(e,u)[s+y[74]]=f},()=>{t(e,u)[s+y[73]]=f},()=>{t(e,u)[s+y[72]]=f}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,i,c)=>{let n=(a[2]<<4)+a[3],s="GMLX ";([()=>{console.debug(`${s}reverb type: ${n}`)},()=>{console.debug(`${s}reverb time: ${n}`)},()=>{console.debug(`${s}reverb predelay: ${n}`)},()=>{console.debug(`${s}depth high: ${n}`)},()=>{console.debug(`${s}depth low: ${n}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,i,c)=>{let n=(a[2]<<4)+a[3],s=e.chRedir(a[1],i,!0),o=s*$.cc;[()=>{n<128?(e.setChType(s,e.CH_MELODIC,x.k11),t(e,u)[o+y[0]]=0,t(e,u)[o+y[32]]=0,t(e,A)[s]=n):n<160?(e.setChType(s,e.CH_MELODIC,x.k11),t(e,u)[o+y[0]]=0,t(e,u)[o+y[32]]=7,t(e,A)[s]=n-100):(e.setChType(s,e.CH_DRUMS,x.k11),t(e,u)[o+y[0]]=122,t(e,u)[o+y[32]]=0,t(e,A)[s]=n-160),e.dispatchEvent("voice",{part:s})},()=>{let f=e.chRedir(n,i,!0);t(e,I)[s]=f,s!=f&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${f+1}`))}][a[0]]()}).add([16,0,9,4],(a,i,c)=>{let n=(a[2]<<4)+a[3],s=e.chRedir(a[1],i,!0),o=s*$.cc,f=s*$.rpn,l=`GMLX CH${s+1} `;[()=>{e.setChActive(s,n)},()=>{t(e,u)[o+y[7]]=n},()=>{t(e,u)[o+y[10]]=n},()=>{t(e,u)[o+y[91]]=n?127:0},()=>{t(e,C)[f+3]=n+40,t(e,T)[$.rpnt*s+2]=1},()=>{t(e,C)[f+1]=n,t(e,T)[$.rpnt*s+1]=1},()=>{t(e,C)[f]=n,t(e,T)[$.rpnt*s]=1},()=>{}][a[0]]()}),t(this,De).add([66,93,64],(a,i,c)=>{let n=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{w(e,P,n*129/16383*100),e.dispatchEvent("mastervolume",t(e,P));break}case 5:{n-64;break}case 6:{console.debug(`SG global reverb: ${n?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(a[1]){case 48:{console.debug(`SG reverb type: ${tt[n]}`);break}}break}default:if(a[0]>>4==1){let s=e.chRedir(a[0]&15,i,!0);if(a[1]==2){let o=e.chRedir(n,i,!0);t(e,I)[s]=o,s!=o&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${o+1}`))}else a[1]==19&&(t(e,u)[$.cc*s+y[7]]=n)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,Ae).add([9],(a,i,c)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),t(this,ee).add([127,0],(a,i,c)=>{e.switchMode("motif");let n=new Uint8Array([127,1,...a]);t(e,ee).run(n,i,c)}).add([127,1,0,0],(a,i,c)=>{e.switchMode("s90es");let n="S90/Motif ES system ",s=a[0];a.subarray(1).forEach((o,f)=>{([()=>{w(e,P,o*12900/16383),e.dispatchEvent("mastervolume",t(e,P))}][s+f]||(()=>{console.info(`Unrecognized ${n}ID: ${s+f}`)}))()})}).add([127,1,0,0,14],(a,i,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk header ",s=[];s[95]=(o,f,l)=>{console.debug(`${n}multi edit buffer: ${o[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,i,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk footer ",s=[];s[95]=(o,f,l)=>{console.debug(`${n}multi edit buffer: ${o[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,i,c)=>{e.switchMode("s90es");let n=e.chRedir(a[0],i,!0),s=$.cc*n,o=a[1],f=`S90/Motif ES bulk CH${n<16?n+1:"U"+(n-95)} `;console.debug(f,a),!(a[0]>15)&&a.subarray(2).forEach((l,p)=>{([()=>{t(e,u)[s+y[0]]=l,e.dispatchEvent("voice",{part:n})},()=>{l&&e.setChActive(n,1),t(e,u)[s+y[32]]=l,e.setChType(n,[32,40].indexOf(l)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,D),!0),e.dispatchEvent("voice",{part:n})},()=>{l&&e.setChActive(n,1),t(e,A)[n]=l,e.dispatchEvent("voice",{part:n})},()=>{let m=e.chRedir(l,i,!0);t(e,I)[n]=m,n!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))},()=>{t(e,W)[n]=l?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{t(e,u)[s+y[7]]=l},()=>{t(e,u)[s+y[10]]=l},!1,!1,!1,()=>{t(e,u)[s+y[91]]=l},()=>{t(e,u)[s+y[93]]=l},()=>{t(e,u)[s+y[94]]=l},()=>{t(e,u)[s+y[128]]=l},()=>{},()=>{t(e,u)[s+y[74]]=l},()=>{t(e,u)[s+y[71]]=l},!1,()=>{t(e,u)[s+y[65]]=l},()=>{t(e,u)[s+y[5]]=l},()=>{}][o+p]||(()=>{}))()})}).add([127,1,54,16],(a,i,c)=>{e.switchMode("s90es");let n=a[0];a.subarray(1).forEach((s,o)=>{let l=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let p=s-64},()=>{let p=Pe[s]},()=>{let p=s/10},()=>{let p=s}][n+o&3]||(()=>{}))()})}),t(this,te).add([0,72,18,0,0,0,0],(a,i,c)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,i,c)=>{let n=a[0]>>5,s=a[0]&31;switch(n){case 0:{console.debug(`Unknown SD-90 global effects message: -%o`,a);break}case 1:{let o=e.chRedir(s,i,!0),f=a[1],l=o*$.cc;a.subarray(2).forEach((p,m)=>{let S=f+m;S<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,u)[l+y[0]]=p,p){case 104:case 105:case 106:case 107:case 120:{t(e,M)[o]||e.setChType(o,e.CH_DRUMS);break}default:t(e,M)[o]&&e.setChType(o,e.CH_MELODIC)}e.dispatchEvent("voice",{part:o})},()=>{t(e,u)[l+y[32]]=p,e.dispatchEvent("voice",{part:o})},()=>{t(e,A)[o]=p,e.dispatchEvent("voice",{part:o})},()=>{t(e,u)[l+y[7]]=p},()=>{t(e,u)[l+y[10]]=p},()=>{},()=>{},()=>{p<2&&(t(e,W)[o]=p)},()=>{p<2&&(t(e,u)[l+y[68]]=p?127:0)},()=>{},()=>{p<2&&(t(e,u)[l+y[65]]=p?127:0)},()=>{t(e,u)[l+y[5]]=p&15<<4|t(e,u)[l+y[5]]&15},()=>{t(e,u)[l+y[5]]=p&15|(t(e,u)[l+y[5]]&240)>>4},()=>{t(e,u)[l+y[74]]=p},()=>{t(e,u)[l+y[71]]=p},()=>{t(e,u)[l+y[73]]=p},()=>{t(e,u)[l+y[72]]=p},0,0,0,0,0,0,0,()=>{t(e,u)[l+y[128]]=p},()=>{t(e,u)[l+y[93]]=p},()=>{t(e,u)[l+y[91]]=p},0,0,()=>{t(e,u)[l+y[75]]=p},()=>{t(e,u)[l+y[76]]=p},()=>{t(e,u)[l+y[77]]=p},()=>{t(e,u)[l+y[78]]=p}][S]||(()=>{}))():S<63||(S<64?t(e,M)[o]?t(e,u)[l+y[0]]=104|p:t(e,u)[l+y[0]]=96|p:console.debug(`Unknown SD-90 global CH${o+1} param setup message: +%o`,a)};t(this,Te).default=r,t(this,Re).default=r,t(this,ee).default=r,t(this,te).default=r,t(this,ye).default=r,t(this,Oe).default=r,t(this,De).default=r,t(this,Ae).default=r,t(this,Te).add([9],a=>{e.switchMode(["gm","?","g2"][a[0]-1],!0),w(e,L,t(e,L)||!1),console.info(`MIDI reset: ${["GM","Init","GM2"][a[0]-1]}`),a[0]==2&&e.init()}),t(this,Re).add([4,1],a=>{w(e,P,((a[1]<<7)+a[0])/16383*100),e.dispatchEvent("mastervolume",t(e,P))}).add([4,3],a=>((a[1]<<7)+a[0]-8192)/8192).add([4,4],a=>a[1]-64),t(this,ee).add([76,0,0],a=>{switch(a[0]){case 125:{e.initDrums(),console.info(`XG drum setup reset: ${a}`);break}case 126:{e.switchMode("xg",!0),w(e,L,!1),console.info("MIDI reset: XG");break}default:{let i=[0,0,0,0],c=(n,s)=>{i[s]=n};if(a.subarray(1).forEach((n,s)=>{let o=s+a[0];([c,c,c,c,f=>{w(this,P,f*129/16383*100),e.dispatchEvent("mastervolume",t(e,P))},f=>{},f=>{}][o]||(()=>{}))(n,s)}),a[0]<4){let n=0;i.forEach(s=>{n=n<<4,n+=s}),n-=1024}}}}).add([76,2,1],a=>{let i="XG ";a[0]<32?(i+="reverb ",a.subarray(1).forEach((c,n)=>{([s=>{e.setEffectTypeRaw(0,!1,s),console.info(`${i}main type: ${Xe[s]}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{e.setEffectTypeRaw(0,!0,s),console.debug(`${i}sub type: ${s+1}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},s=>{console.debug(`${i}time: ${bt(s)}s`)},s=>{console.debug(`${i}diffusion: ${s}`)},s=>{console.debug(`${i}initial delay: ${s}`)},s=>{console.debug(`${i}HPF cutoff: ${Pe[s]}Hz`)},s=>{console.debug(`${i}LPF cutoff: ${Pe[s]}Hz`)},s=>{console.debug(`${i}width: ${s}`)},s=>{console.debug(`${i}height: ${s}`)},s=>{console.debug(`${i}depth: ${s}`)},s=>{console.debug(`${i}wall type: ${s}`)},s=>{console.debug(`${i}dry/wet: ${s}`)},s=>{console.debug(`${i}send: ${q(s)}dB`)},s=>{console.debug(`${i}pan: ${s-64}`)},!1,!1,s=>{console.debug(`${i}delay: ${s}`)},s=>{console.debug(`${i}density: ${s}`)},s=>{console.debug(`${i}balance: ${s}`)},s=>{},s=>{console.debug(`${i}feedback: ${s}`)},s=>{}][a[0]+n]||function(){console.warn(`Unknown XG reverb address: ${a[0]}.`)})(c)})):a[0]<64?(i+="chorus ",a.subarray(1).forEach((c,n)=>{([s=>{e.setEffectTypeRaw(1,!1,s),console.info(`${i}main type: ${Xe[s]}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{e.setEffectTypeRaw(1,!0,s),console.debug(`${i}sub type: ${s+1}`),e.dispatchEvent("efxchorus",e.getEffectType(1))},s=>{console.debug(`${i}LFO: ${pt[s]}Hz`)},s=>{},s=>{console.debug(`${i}feedback: ${s}`)},s=>{console.debug(`${i}delay offset: ${yt(s)}ms`)},s=>{},s=>{console.debug(`${i}low: ${Pe[s]}Hz`)},s=>{console.debug(`${i}low: ${s-64}dB`)},s=>{console.debug(`${i}high: ${Pe[s]}Hz`)},s=>{console.debug(`${i}high: ${s-64}dB`)},s=>{console.debug(`${i}dry/wet: ${s}`)},s=>{console.debug(`${i}send: ${q(s)}dB`)},s=>{console.debug(`${i}pan: ${s-64}`)},s=>{console.debug(`${i}to reverb: ${q(s)}dB`)},!1,s=>{},s=>{},s=>{},s=>{console.debug(`${i}LFO phase diff: ${(s-64)*3}deg`)},s=>{console.debug(`${i}input mode: ${s?"stereo":"mono"}`)},s=>{}][a[0]-32+n]||function(){console.warn(`Unknown XG chorus address: ${a[0]}.`)})(c)})):a[0]<86?(i+="variation ",a.subarray(1).forEach((c,n)=>{([s=>{e.setEffectTypeRaw(2,!1,s),console.info(`${i}main type: ${Xe[s]}`),e.dispatchEvent("efxdelay",e.getEffectType(2))},s=>{e.setEffectTypeRaw(2,!0,s),console.debug(`${i}sub type: ${s+1}`),e.dispatchEvent("efxdelay",e.getEffectType(2))}][a[0]-64+n]||function(){})(c)})):a[0]<97?(i+="variation ",a.subarray(1).forEach((c,n)=>{[s=>{console.debug(`${i}send: ${q(s)}dB`)},s=>{console.debug(`${i}pan: ${s-64}`)},s=>{console.debug(`${i}to reverb: ${q(s)}dB`)},s=>{console.debug(`${i}to chorus: ${q(s)}dB`)},s=>{console.debug(`${i}connection: ${s?"system":"insertion"}`)},s=>{console.debug(`${i}channel: CH${s+1}`)},s=>{console.debug(`${i}mod wheel: ${s-64}`)},s=>{console.debug(`${i}bend wheel: ${s-64}`)},s=>{console.debug(`${i}channel after touch: ${s-64}`)},s=>{console.debug(`${i}AC1: ${s-64}`)},s=>{console.debug(`${i}AC2: ${s-64}`)}][a[0]-86+n](c)})):a[0]>111&&a[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${a[0]}`)}).add([76,2,64],a=>{a.subarray(1).forEach((i,c)=>{let n=c+a[0];if(n==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let s=n-1>>2,o=n-1&3,f=`XG EQ ${s} ${["gain","freq","Q","shape"][o]}: `;[()=>{console.debug(`${f}${i-64}dB`)},()=>{console.debug(`${f}${i} (raw)`)},()=>{console.debug(`${f}${i/10}`)},()=>{console.debug(`${f}${["shelf","peak"][+!!i]}`)}][o]()}})}).add([76,3],a=>{let i=a[0],c=a[1],n=`XG Insertion ${a[0]+1} `;a.subarray(2).forEach((s,o)=>{([f=>{e.setEffectTypeRaw(3+i,!1,f),console.info(`${n}main type: ${Xe[f]}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))},f=>{e.setEffectTypeRaw(3+i,!0,f),console.debug(`${n}sub type: ${f+1}`),e.dispatchEvent(`efxinsert${i}`,e.getEffectType(3+i))}][c+o]||function(){})(s)})}).add([76,6,0],a=>{let i=a[0];i<64?e.setLetterDisplay(a.subarray(1),"XG letter display",i):w(e,we,Date.now())}).add([76,7,0],a=>{let i=a[0];w(e,V,0),w(e,ce,Date.now()+3200),t(e,J,fe).fill(0);let c=a.subarray(1);for(let n=0;n>6-m&1,m++})}).add([76,8],(a,i)=>{let c=e.chRedir(a[0],i,!0),n=a[1],s=$.cc*c,o=`XG CH${c+1} `,f=`Unknown XG part address ${n}.`;a.subarray(2).forEach((l,b)=>{n<1?console.debug(f):n<41?([()=>{t(e,p)[s+y[0]]=l,e.dispatchEvent("voice",{part:c})},()=>{t(e,p)[s+y[32]]=l,e.dispatchEvent("voice",{part:c})},()=>{t(e,A)[c]=l,e.dispatchEvent("voice",{part:c})},()=>{let m=e.chRedir(l,i,!0);t(e,I)[c]=m,c!=m&&(e.buildRchTree(),console.info(`${o}receives from CH${m+1}`))},()=>{t(e,W)[c]=+!l},()=>{},()=>{e.setChType(c,l,x.xg),console.debug(`${o}type: ${Fe[l]||l}`)},()=>{t(e,C)[$.rpn*c+3]=l,t(e,T)[$.rpnt*c+2]=1},!1,!1,()=>{t(e,p)[s+y[7]]=l},!1,!1,()=>{t(e,p)[s+y[10]]=l||128},!1,!1,()=>{t(e,p)[s+y[128]]=l},()=>{t(e,p)[s+y[93]]=l},()=>{t(e,p)[s+y[91]]=l},()=>{t(e,p)[s+y[94]]=l},()=>{t(e,p)[s+y[76]]=l},()=>{t(e,p)[s+y[77]]=l},()=>{t(e,p)[s+y[78]]=l},()=>{t(e,p)[s+y[74]]=l},()=>{t(e,p)[s+y[71]]=l},()=>{t(e,p)[s+y[73]]=l},()=>{t(e,p)[s+y[75]]=l},()=>{t(e,p)[s+y[72]]=l}][n+b-1]||(()=>{}))():n<48?console.debug(f):n<111?n>102&&n<105&&(t(e,p)[s+y[[5,65][n&1]]]=l):n<114?console.debug(f):n<116?console.debug(`${o}EQ ${["bass","treble"][n&1]} gain: ${l-64}dB`):n<118?console.debug(f):n<120?console.debug(`${o}EQ ${["bass","treble"][n&1]} freq: ${l}`):console.debug(f)})}).add([76,9],(a,i)=>{let c=e.chRedir(a[0],i,!0),n=a[1],s=`PLG-150VL CH${c+1} `;a.subarray(2).forEach((o,f)=>{let l=f+n;switch(l){case 1:{console.info(`${s}breath mode: ${["system","breath","velocity","touch EG"][o]}`);break}case 0:case 27:case 28:break;default:if(l<27){let b=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${s}${b} control source: ${Et(o)}`),o&&o<96&&e.allocateAce(o)):console.debug(`${s}${b} scale break point: ${o}`):console.debug(`${s}${b} depth: ${o-64}`)}}})}).add([76,10],a=>{}).add([76,16],a=>{}).add([76,17,0,0],a=>{}).add([76,112],a=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][a[0]]} for CH${a[2]+1}.`)}).add([73,0,0],(a,i)=>{let c=a[0],n="MU1000 System: ";a.subarray(1).forEach((s,o)=>{let f=c+o;f==8?console.debug(`${n}LCD contrast set to ${s}.`):f==18?(w(e,Z,s?126:0),console.debug(`${n}bank defaults to ${s?"MU100 Native":"MU Basic"}.`)):f>=64&&f<69&&[()=>{e.dispatchEvent("channelactive",s)},()=>{s<8?(e.dispatchEvent("channelmin",s<<4),console.debug(`Octavia System: Minimum CH${(s<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{s<8?(e.dispatchEvent("channelmax",(s<<4)+15),console.debug(`Octavia System: Maximum CH${(s<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{w(e,se,!!s),console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][f-64]()})}).add([73,10,0],(a,i)=>{let c=a[0],n=`MU1000 RS${t(e,se)?"":" (ignored)"}: `;if(c<16)switch(c){case 2:{let s=e.chRedir(0,i,!0);t(e,se)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+63)),console.info(`${n}Show CH1~64`);break}case 3:{let s=e.chRedir(a[1]<<5,i,!0);t(e,se)&&e.dispatchEvent("channelmin",s),t(e,se)&&e.dispatchEvent("channelmax",s+31),console.info(`${n}Show CH${s+1}~CH${s+32}`);break}default:console.debug(`${n}unknown switch ${c} invoked.`)}else if(c<32){if(t(e,se)){let s=e.chRedir(c-16+(t(e,Ie)<<4),i,!0);e.dispatchEvent("channelactive",s)}}else if(c<36){let s=e.chRedir(c-32<<4,i,!0);t(e,se)&&(e.dispatchEvent("channelmin",s),e.dispatchEvent("channelmax",s+15),w(e,Ie,c-32)),console.info(`${n}Show CH${s+1}~CH${s+16}`)}}).add([93,3],(a,i)=>{let c=e.chRedir(a[0],i,!0),n=`PLG-100SG CH${c+1} `,s=Date.now();if(a[1]==0){let o="",f=0;a.subarray(2).forEach((l,b)=>{b%2==0?o+=gt[l]||l.toString().padStart("0"):f+=l*13}),s>=t(e,Ge)&&this.dispatchEvent("metacommit",{type:"SGLyrics",data:"",amend:!1}),this.dispatchEvent("metacommit",{type:"SGLyrics",data:`${$t(o)}`,amend:!0}),w(e,Ge,s+Math.ceil(f/2)+t(e,Be)),U()&&console.debug(`${n}vocals: ${o}`)}else console.warn(`Unknown PLG-100SG data: ${a}`)});let d=function(a,i,c,n){},h=function(a,i){let c=a*$.dpn,n=i[0],s=i[1];i.subarray(2).forEach((o,f)=>{let l=f+s,b=-1;l<16?([()=>{b=24},()=>{b=25},()=>{b=26},()=>{},()=>{b=28},()=>{b=29},()=>{b=30},()=>{b=31},()=>{},()=>{},()=>{},()=>{b=20},()=>{b=21},()=>{b=22},()=>{b=23},()=>{}][l]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))():l<32||(l<40?([()=>{b=48},()=>{b=49},!1,!1,()=>{b=52},()=>{b=53}][l-32]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))():l<80||([()=>{b=36}][l-80]||(()=>{console.debug(`Unknown XG-style drum param ${l} on set ${a+1}.`)}))()),b>=0?(U()&&console.debug(c,b,n,o),t(e,K)[(c+ae[b])*$.dnc+n]=o):U()&&console.debug(`XG-style drum param ${l} has no writes.`)})},E=function(a,i,c){let n=a*$.dpn,s=(i<<7)+c[0];c.subarray(1).forEach((o,f)=>{let l=f+s,b=l&127,m=l>>7,S=-1;m>1&&([()=>{S=26},()=>{},()=>{S=28},()=>{S=29},()=>{S=30},()=>{},()=>{},()=>{S=31}][m-2]||(()=>{console.debug(`Unknown GS-style drum param ${m} on set ${a+1}.`)}))(),S>-1?(U()&&console.debug(n,S,b,o),t(e,K)[(n+ae[S])*$.dnc+b]=o):U()&&console.debug(`GS-style drum param ${m} has no writes.`)})};t(this,ee).add([76,48],(a,i,c)=>{h(0,a)}).add([76,49],(a,i,c)=>{h(1,a)}).add([76,50],(a,i,c)=>{h(2,a)}).add([76,51],(a,i,c)=>{h(3,a)}).add([76,52],(a,i,c)=>{h(4,a)}).add([76,53],(a,i,c)=>{h(5,a)}).add([76,54],(a,i,c)=>{h(6,a)}).add([76,55],(a,i,c)=>{h(7,a)}),t(this,ee).add([89,0],(a,i,c)=>{if(e.eprom){let n=a[0],s=(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);U()&&console.debug(`MU1000 EPROM trail to 0x${s.toString(16).padStart(6,"0")}, ${n} bytes.`);let o=e.eprom.data;a.subarray(4).forEach((f,l)=>{let b=l>>3,m=l&7;if(m==7)for(let S=0;S<7;S++)o[s+7*b+S]+=(f>>6-S&1)<<7;else o[s+7*b+m]=f})}}).add([89,1],(a,i,c)=>{let n=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3];U()&&console.debug(`MU1000 EPROM jump to 0x${n.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=n)}).add([89,2],(a,i,c)=>{if(e.eprom){let n=(a[0]<<21)+(a[1]<<14)+(a[2]<<7)+a[3]+(e.eprom.offset||0);U()&&console.debug(`MU1000 EPROM write to 0x${n.toString(16).padStart(6,"0")}.`);let s=e.eprom.data;a.subarray(4).forEach((o,f)=>{let l=f>>3,b=f&7;if(b==7)for(let m=0;m<7;m++)s[n+7*l+m]+=(o>>6-m&1)<<7;else s[n+7*l+b]=o})}}).add([89,3],(a,i,c)=>{}),t(this,ee).add([39,48],(a,i,c)=>{}).add([43,0,0],(a,i,c)=>{let n=[0,0,0,0],s=(o,f)=>{n[f]=o};if(a.subarray(1).forEach((o,f)=>{let l=f+a[0];[s,s,s,s,()=>{w(this,P,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,P))},()=>o-64,()=>o||128,()=>o,()=>o,()=>{console.debug(`TG300 variation on cc${o}.`)}][l](o,l)}),a[0]<4){let o=0;n.forEach(f=>{o=o<<4,o+=f}),o-=1024}}).add([43,1,0],(a,i,c)=>{}).add([43,2],(a,i,c)=>{let n=e.chRedir(a[0],i,!0),s=a[1],o=$.cc*n,f=`TG300 CH${n+1} `;a.subarray(2).forEach((l,b)=>{b<5?([()=>{},()=>{t(e,p)[o+y[0]]=l,e.dispatchEvent("voice",{part:n})},()=>{t(e,p)[o+y[32]]=l,e.dispatchEvent("voice",{part:n})},()=>{t(e,A)[n]=l,e.dispatchEvent("voice",{part:n})},()=>{let m=e.chRedir(l,i,!0);t(e,I)[n]=m,n!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))}][b+s]||(()=>{}))(l,b+s):b<21||(b<47?([()=>{t(e,W)[n]=+!l},()=>{},()=>{},()=>{t(e,C)[$.rpn*n+3]=l,t(e,T)[$.rpnt*n+2]=1},()=>{},()=>{t(e,p)[o+y[7]]=l},!1,!1,()=>{t(e,p)[o+y[10]]=l||128},!1,!1,()=>{console.debug(`${f} AC1 at cc${l}`)},()=>{console.debug(`${f} AC2 at cc${l}`)},()=>{t(e,p)[o+y[128]]=l},()=>{t(e,p)[o+y[93]]=l},()=>{t(e,p)[o+y[91]]=l},()=>{t(e,p)[o+y[94]]=l},()=>{t(e,p)[o+y[76]]=l},()=>{t(e,p)[o+y[77]]=l},()=>{t(e,p)[o+y[74]]=l},()=>{t(e,p)[o+y[71]]=l},()=>{t(e,p)[o+y[73]]=l},()=>{t(e,p)[o+y[75]]=l},()=>{t(e,p)[o+y[72]]=l},()=>{t(e,p)[o+y[78]]=l}][b+s-21]||(()=>{}))(l,b+s):b<95||([()=>{t(e,p)[o+y[65]]=l},()=>{t(e,p)[o+y[5]]=l}][b+s-95]||(()=>{}))(l,b+s))})}).add([43,7,0],(a,i,c)=>{let n=a[0];e.setLetterDisplay(a.subarray(1),"TG300 letter display",n)}).add([43,7,1],(a,i,c)=>{w(e,V,0),w(e,ce,Date.now()+3200),t(e,J,fe).fill(0),a.forEach(function(n,s){let o=Math.floor(s/16),f=s%16,l=(f*3+o)*7,b=7,m=0;for(l-=f*5,o==2&&(b=2);m>6-m&1,m++})}),t(this,te).add([66,18,0,0,127],(a,i,c)=>{e.switchMode("gs",!0),t(e,p)[$.cc*9]=120,t(e,p)[$.cc*25]=120,t(e,p)[$.cc*41]=120,t(e,p)[$.cc*57]=120,w(e,Z,3),w(e,L,!1),t(e,be).fill(0),console.info(`GS system to ${["single","dual"][a[0]]} mode.`)}).add([66,18,64,0],(a,i,c)=>{switch(a[0]){case 127:{e.switchMode("gs",!0),t(e,p)[$.cc*9]=120,t(e,p)[$.cc*25]=120,t(e,p)[$.cc*41]=120,t(e,p)[$.cc*57]=120,w(e,L,!1),t(e,be).fill(0),console.info("MIDI reset: GS");break}default:{let n=[0,0,0,0],s=(o,f)=>{n[f]=o};if(a.subarray(1).forEach((o,f)=>{let l=f+a[0];[s,s,s,s,b=>{w(this,P,b*129/16383*100),e.dispatchEvent("mastervolume",t(e,P))},b=>{},b=>{}][l](o,f)}),a[0]<4){let o=0;n.forEach(f=>{o=o<<4,o+=f}),o-=1024}}}}).add([66,18,64,1],a=>{let i=a[0];if(i<16){let c="".padStart(i," ");a.subarray(1).forEach((n,s)=>{c+=String.fromCharCode(Math.max(32,n))}),c=c.padEnd(16," "),console.debug(`GS patch name: ${c}`)}else i<48||(i<65?a.subarray(1).forEach((c,n)=>{let s=`GS ${i+n>55?"chorus":"reverb"} `;([()=>{console.info(`${s}type: ${tt[c]}`),e.setEffectType(0,40,c),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${s}predelay: ${c}ms`)},()=>{console.info(`${s}type: ${mt[c]}`),e.setEffectType(1,40,16+c),e.dispatchEvent("efxchorus",e.getEffectType(1))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${q(c)}`)},()=>{console.debug(`${s}to delay: ${q(c)}`)}][i+n-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?a.subarray(1).forEach((c,n)=>{let s="GS delay ";([()=>{console.info(`${s}type: ${vt[c]}`),e.setEffectType(2,40,32+c),e.dispatchEvent("efxdelay",e.getEffectType(2))},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${s}to reverb: ${q(c)}`)}][i+n-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],a=>{let i="GS EQ ";a.subarray(1).forEach((c,n)=>{([()=>{console.debug(`${i}low freq: ${[200,400][c]}Hz`)},()=>{console.debug(`${i}low gain: ${c-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][c]}Hz`)},()=>{console.debug(`${i}high gain: ${c-64}dB`)}][a[0]+n]||function(){console.warn(`Unknown GS EQ address: ${a[0]+n}`)})()})}).add([66,18,64,3],a=>{let i="GS EFX ",c=function(n,s){let o=wt(t(e,Y).subarray(10,12),s,n);o&&console.debug(`${i}${at(t(e,Y).subarray(10,12))} ${o}`)};a.subarray(1).forEach((n,s)=>{([()=>{e.setEffectTypeRaw(3,!1,32+n),e.dispatchEvent("efxinsert0",e.getEffectType(3))},()=>{e.setEffectTypeRaw(3,!0,n),console.info(`${i}type: ${at(t(e,Y).subarray(10,12))}`),e.dispatchEvent("efxinsert0",e.getEffectType(3))},!1,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,()=>{console.debug(`${i}to reverb: ${q(n)}dB`)},()=>{console.debug(`${i}to chorus: ${q(n)}dB`)},()=>{console.debug(`${i}to delay: ${q(n)}dB`)},!1,()=>{console.debug(`${i}1 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${i}1 depth: ${n-64}`)},()=>{console.debug(`${i}2 source: ${n}`),n&&n<96&&e.allocateAce(n)},()=>{console.debug(`${i}2 depth: ${n-64}`)},()=>{console.debug(`${i}to EQ: ${n?"ON":"OFF"}`)}][a[0]+s]||function(o,f){console.warn(`Unknown GS EFX address: ${f}`)})(n,a[0]+s)})}).add([66,18,65],a=>{E((a[0]>>4)+1<<1,a[0]&15,a.subarray(1))}).add([69,18,16],a=>{var i;switch(a[0]){case 0:{let c=a[1];e.setLetterDisplay(a.subarray(2),"GS display text",c);break}case 32:{w(e,ce,Date.now()+3200),a[1]==0&&(w(e,V,Math.max(Math.min(a[2]-1,9),0)),U()&&console.debug(`GS switch display page ${a[2]-1}.`));break}default:if(a[0]<6){t(e,V)>9&&w(e,V,0);let c=a[0]-1<<1|a[1]>>6;t(e,V)==c&&w(e,ce,Date.now()+3200),(i=t(e,he)[c])!=null&&i.length||(t(e,he)[c]=new Uint8Array(256));let n=t(e,he)[c];U()&&console.debug(`GS frame draw page ${c}.`);let s=a[1]&63;n.fill(0),a.subarray(2).forEach(function(f,l){let b=l+s,m=Math.floor(b/16),S=b%16,O=(S*4+m)*5,H=5,F=0;for(O-=S*4,m==3&&(H=1);F>4-F&1,F++})}else console.warn(`Unknown GS display section: ${a[0]}`)}});let u=function(a,i,c){let n=a[0],s=$.cc*i,o=$.rpn*i,f=`GS CH${i+1} `;n<3?(a.subarray(1).forEach((l,b)=>{[()=>{t(e,p)[s+y[0]]=l},()=>{t(e,A)[i]=l},()=>{let m=0;l<16?m=e.chRedir(l,c,!0):m=$.ch,t(e,I)[i]=m,i!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))}][n+b]()}),e.dispatchEvent("voice",{part:i})):n<19||(n<44?a.subarray(1).forEach((l,b)=>{([()=>{t(e,W)[i]=+!l},!1,()=>{e.setChType(i,l<<1,x.gs),console.debug(`${f}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{t(e,C)[o+3]=l,t(e,T)[$.rpnt*i+2]=1},!1,()=>{t(e,p)[s+y[7]]=l},!1,!1,()=>{t(e,p)[s+y[10]]=l||128},!1,!1,()=>{console.debug(`${f}CC 1: cc${l}`)},()=>{console.debug(`${f}CC 2: cc${l}`)},()=>{t(e,p)[s+y[93]]=l},()=>{t(e,p)[s+y[91]]=l},!1,!1,()=>{t(e,C)[o+1]=l,t(e,T)[$.rpnt*i+1]=1},()=>{t(e,C)[o+2]=l,t(e,T)[$.rpnt*i+1]=1},()=>{t(e,p)[s+y[94]]=l}][n+b-19]||(()=>{}))()}):n<76||console.debug(`Unknown GS part address: ${n}`))},v=function(a,i){let c=a[0],n=`GS CH${i+1} `;c<2?a.subarray(1).forEach((s,o)=>{[()=>{t(e,p)[$.cc*i+y[32]]=s},()=>{}][c+o]()}):c<32?console.warn(`Unknown GS misc address: ${c}`):c<35?a.subarray(1).forEach((s,o)=>{[()=>{console.debug(`${n}EQ: o${["ff","n"][s]}`)},()=>{},()=>{console.debug(`${n}EFX: o${["ff","n"][s]}`),t(e,Ne)[i]=s,e.dispatchEvent("partefxtoggle",{part:i,active:s})}][c+o-32]()}):console.warn(`Unknown GS misc address: ${c}`)};t(this,te).add([66,18,64,16],(a,i)=>{u(a,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(a,i)=>{u(a,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(a,i)=>{u(a,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(a,i)=>{u(a,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(a,i)=>{u(a,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(a,i)=>{u(a,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(a,i)=>{u(a,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(a,i)=>{u(a,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(a,i)=>{u(a,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(a,i)=>{u(a,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(a,i)=>{u(a,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(a,i)=>{u(a,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(a,i)=>{u(a,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(a,i)=>{u(a,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(a,i)=>{u(a,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(a,i)=>{u(a,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(a,i)=>{v(a,e.chRedir(9,i,!0))}).add([66,18,64,65],(a,i)=>{v(a,e.chRedir(0,i,!0))}).add([66,18,64,66],(a,i)=>{v(a,e.chRedir(1,i,!0))}).add([66,18,64,67],(a,i)=>{v(a,e.chRedir(2,i,!0))}).add([66,18,64,68],(a,i)=>{v(a,e.chRedir(3,i,!0))}).add([66,18,64,69],(a,i)=>{v(a,e.chRedir(4,i,!0))}).add([66,18,64,70],(a,i)=>{v(a,e.chRedir(5,i,!0))}).add([66,18,64,71],(a,i)=>{v(a,e.chRedir(6,i,!0))}).add([66,18,64,72],(a,i)=>{v(a,e.chRedir(7,i,!0))}).add([66,18,64,73],(a,i)=>{v(a,e.chRedir(8,i,!0))}).add([66,18,64,74],(a,i)=>{v(a,e.chRedir(10,i,!0))}).add([66,18,64,75],(a,i)=>{v(a,e.chRedir(11,i,!0))}).add([66,18,64,76],(a,i)=>{v(a,e.chRedir(12,i,!0))}).add([66,18,64,77],(a,i)=>{v(a,e.chRedir(13,i,!0))}).add([66,18,64,78],(a,i)=>{v(a,e.chRedir(14,i,!0))}).add([66,18,64,79],(a,i)=>{v(a,e.chRedir(15,i,!0))}),t(this,ye).add([54,65],(a,i)=>{e.switchMode("x5d");let c=(a[1]<<7)+a[0],n=(a[3]<<7)+a[2],s=e.chRedir(c&15,i,!0),o=$.cc*s;[()=>{n<1||(n<101?(e.setChType(s,e.CH_MELODIC,x.x5d),t(e,A)[s]=n-1,t(e,p)[o+y[0]]=82):n<229?(e.setChType(s,e.CH_MELODIC,x.x5d),t(e,A)[s]=n-101,t(e,p)[o+y[0]]=56):(e.setChType(s,e.CH_DRUMS,x.x5d),t(e,A)[s]=Ot[n-229]||0,t(e,p)[o+y[0]]=62)),e.dispatchEvent("voice",{part:s})},()=>{t(e,p)[o+y[7]]=n},()=>{n<31&&(t(e,p)[o+y[10]]=Math.round((n-15)*4.2+64))},()=>{t(e,p)[o+y[93]]=Ve(n)},()=>{t(e,p)[o+y[91]]=Ve(n)},()=>{t(e,C)[s*$.rpn+3]=n>8191?n-16320:64+n,t(e,T)[$.rpnt*s+2]=1},()=>{t(e,C)[s*$.rpn+1]=n>8191?n-16320:64+n,t(e,T)[$.rpnt*s+1]=1},()=>{n>0&&(t(e,C)[s*$.rpn]=n,t(e,T)[$.rpnt*s]=1)},()=>{}][c>>4]()}).add([54,76,0],(a,i)=>{e.switchMode("x5d",!0);let c="",n=82,s=0,o=0,f="MSB PRG LSB NME";ne(a,function(l,b){if(b<16400){let m=b%164;switch(!0){case m<10:{l>31&&(c+=String.fromCharCode(l));break}case m==11:{f+=` +${n} ${s} ${o} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}s>99&&(n=90,s=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(f),U()&&console.debug(f),e.forceVoiceRefresh()}).add([54,77,0],(a,i)=>{e.switchMode("x5d",!0);let c="",n=90,s=0,o=0,f="MSB PRG LSB NME";ne(a,function(l,b){if(b<13600){let m=b%136;switch(!0){case m<10:{l>31&&(c+=String.fromCharCode(l));break}case m==11:{f+=` +${n} ${s} ${o} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(f),U()&&console.debug(f),e.forceVoiceRefresh()}).add([54,78],(a,i)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][a[0]]} mode.`)}).add([54,85],(a,i)=>{e.switchMode("x5d",!0),ne(a,(c,n)=>{n>0&&n<3&&(e.setEffectType(n-1,44,c),e.dispatchEvent(`efx${["reverb","chorus"][n-1]}`,e.getEffectType(n-1)))})}).add([54,104],(a,i)=>{e.switchMode("x5d",!0),ne(a,function(c,n,s,o){if(n<192){let f=e.chRedir(Math.floor(n/12),i,!0),l=f*$.cc;switch(n%12){case 0:{c<128?(e.setChType(f,e.CH_MELODIC,x.x5d),t(e,p)[l+y[0]]=82,t(e,A)[f]=c):(e.setChType(f,e.CH_DRUMS,x.x5d),t(e,p)[l+y[0]]=62,t(e,A)[f]=Ot[c-128]),c>0&&e.setChActive(f,1),e.dispatchEvent("voice",{part:f});break}case 1:{t(e,p)[l+y[7]]=c;break}case 2:{t(e,C)[f*$.rpn+3]=c>127?c-192:64+c,t(e,T)[$.rpnt*f+2]=1;break}case 3:{t(e,C)[f*$.rpn+1]=c>127?c-192:64+c,t(e,T)[$.rpnt*f+1]=1;break}case 4:{c<31&&(t(e,p)[l+y[10]]=Math.round((c-15)*4.2+64));break}case 5:{let b=c>>4,m=c&15;t(e,p)[l+y[91]]=Ve(m),t(e,p)[l+y[93]]=Ve(b);break}case 10:break;case 11:{let b=e.chRedir(c&15,i,!0),m=c>>4;t(e,I)[f]=c,(b!=f||m)&&(console.info(`X5D Part CH${f+1} receives from CH${b+1}.`),e.buildRchTree())}}}else{let f=e.chRedir(n-192,i,!0)}})}),t(this,te).add([22,18,127],a=>{e.switchMode("mt32",!0),w(e,L,!1),e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(a,i,c)=>{e.switchMode("mt32");let n=e.chRedir(c,i,!0),s=a[1];a.subarray(2).forEach((o,f)=>{let l=f+s;t(e,$e)[l+(n-1)*16]=o,([!1,()=>{let b=t(e,$e)[n-1<<4];if(b<3){if(t(e,le)[n]=1,b==2)for(let m=0;m{t(e,C)[n*$.rpn+3]=o+40,t(e,T)[$.rpnt*n+2]=1},()=>{t(e,C)[n*$.rpn+1]=o+14,t(e,T)[$.rpnt*n+1]=1},()=>{t(e,C)[n*$.rpn]=o,t(e,T)[$.rpnt*n]=1},!1,()=>{t(e,p)[$.cc*n+y[91]]=o?127:0},!1,()=>{t(e,p)[$.cc*n+y[7]]=o},()=>{t(e,p)[$.cc*n+y[10]]=Math.ceil(o*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(a,i,c)=>{e.switchMode("mt32");let n=c&7;console.debug(`MT-32 slot #${c+1} Drum: ${a}`);let s=a[0]<<7|a[1];a.subarray(2).forEach((o,f)=>{let l=f+s,b=(l>>2)+24,m=l&3,S=n*$.dpn;if(U()&&console.debug(`MT-32 temp drum note ${b} param ${m}: ${o}`),b<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${b}`);return}[()=>{},()=>{t(e,K)[(S+ae[26])*$.dnc+b]=Math.round(o*1.27)},()=>{t(e,K)[(S+ae[26])*$.dnc+b]=o*9+1&127},()=>{t(e,K)[(S+ae[26])*$.dnc+b]=o?127:0}][m]()})}).add([22,18,2],(a,i,c)=>{e.switchMode("mt32");let n=e.chRedir(c,i,!0),s=a[1]+(a[0]<<7);s<10&&(t(e,le)[n]=1),a.subarray(2).forEach((o,f)=>{let l=f+s;l<14&&(t(e,re)[(n-1)*$.cmt+l]=o)}),e.dispatchEvent("voice",{part:n})}).add([22,18,3],(a,i,c)=>{e.switchMode("mt32");let n=c&7;if(a[0]){let s=(a[0]-1<<7)+a[1]-16;a.subarray(2).forEach((o,f)=>{let l=f+s,b=(l>>2)+24,m=l&3,S=n*$.dpn;if(U()&&console.debug(`MT-32 dev drum note ${b} param ${m}: ${o}`),b<24){console.warn(`MT-32 dev drum write attempted on an OOB note: ${b}`);return}[()=>{},()=>{t(e,K)[(S+ae[26])*$.dnc+b]=Math.round(o*1.27)},()=>{t(e,K)[(S+ae[26])*$.dnc+b]=o*9+1&127},()=>{t(e,K)[(S+ae[26])*$.dnc+b]=o?127:0}][m]()})}else{let s=a[1];a.subarray(2).forEach((o,f)=>{let l=f+s;t(e,$e)[l]=o;let b=e.chRedir(1+(l>>4),i,!0),m=l&15;([!1,()=>{let S=t(e,$e)[b-1<<4];if(S<3)if(t(e,le)[b]=1,S==2)for(let O=0;O{t(e,C)[b*$.rpn+3]=o+40,t(e,T)[$.rpnt*b+2]=1},()=>{t(e,C)[b*$.rpn+1]=o+14,t(e,T)[$.rpnt*b+1]=1},()=>{t(e,C)[b*$.rpn]=o,t(e,T)[$.rpnt*b]=1},!1,()=>{t(e,p)[$.cc*b+y[91]]=o?127:0},!1,()=>{t(e,p)[$.cc*b+y[7]]=o},()=>{t(e,p)[$.cc*b+y[10]]=Math.ceil(o*9.05)}][m]||(()=>{}))()})}}).add([22,18,4],(a,i,c)=>{e.switchMode("mt32");let n=a[1]+(a[0]<<7),s=[];a.subarray(2).forEach((o,f)=>{let l=f+n,b=e.chRedir(Math.floor(l/246+1),i,!0),m=l%246;m<14&&(t(e,re)[(b-1)*$.cmt+m]=o),m<10&&(t(e,le)[b]=1),s.indexOf(b)<0&&s.push(b)}),s.forEach(o=>{e.dispatchEvent("voice",{part:o})})}).add([22,18,5],(a,i,c)=>{e.switchMode("mt32");let n=(a[0]<<7)+a[1];a.subarray(2).forEach((s,o)=>{let f=n+o,l=Math.floor(f/8),b=f&7,m=l*8;t(e,He)[f]=s,([!1,()=>{let S=t(e,He)[m];if(S<3){let O="";if(S==2){let H=$.cmt*l;O=`MT-m:${s.toString().padStart(3,"0")}`}else O=e.baseBank.get(0,s+(S<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l}),e.userBank.load(`MSB LSB PRG NME +000 127 ${l} ${O}`,!0)}}][b]||(()=>{}))()}),e.forceVoiceRefresh()}).add([22,18,8],(a,i,c)=>{e.switchMode("mt32");let n=((a[0]&1)<<7)+a[1];a.subarray(2).forEach((s,o)=>{let f=n+o;f<$.cmt&&(t(e,Ee)[(a[0]>>1)*$.cmt+f]=s)}),e.forceVoiceRefresh()}).add([22,18,16],(a,i,c)=>{e.switchMode("mt32");let n=a[1],s=!1,o=function(f,l){t(e,I)[l-12]=f,s=!0};a.subarray(2).forEach((f,l)=>{let b=l+n;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,o,o,o,o,o,o,o,o,o,()=>{w(e,P,f),e.dispatchEvent("mastervolume",t(e,P))}][b]||(()=>{}))(f,l)}),s&&e.buildRchTree()}).add([22,18,32],a=>{e.switchMode("mt32");let i=a[1],c=" ".repeat(i);a.subarray(2).forEach(n=>{n>31?c+=String.fromCharCode(n):c+=" "}),w(e,ve,c.padStart(20," ")),w(e,we,Date.now()+3200)}).add([22,18,82],(a,i)=>{let c=e.chRedir(0,i,!0);for(let n=0;n<16;n++)t(e,G).ano(c+n),n&&n<10&&(t(e,A)[c+n]=rt[n-1]);console.info("MT-32 alt reset complete.")}),t(this,ye).add([66,0],(a,i)=>{e.switchMode("ns5r",!0),w(e,L,!1),console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][a[0]]} mode.`)}).add([66,1],(a,i)=>{e.switchMode(["ns5r","05rw"][a[0]],!0),w(e,L,!1)}).add([66,18,0,0],(a,i)=>{let c=a[0];switch(c){case 124:case 126:case 127:{e.switchMode("ns5r",!0),w(e,L,!1);break}case 125:{e.initDrums(),console.info(`NS5R drum setup reset: ${a}`);break}default:if(c<10){let n=[0,0,0,0],s=(o,f)=>{n[f]=o};if(a.subarray(1).forEach((o,f)=>{[s,s,s,s,()=>{w(e,P,o*129/16383*100),e.dispatchEvent("mastervolume",t(e,P))},()=>o-64,()=>o-64,()=>{},()=>{},()=>{}][c+f]()}),a[0]<4){let o=0;n.forEach(f=>{o=o<<4,o+=f}),o-=1024}}}}).add([66,18,0,1],(a,i)=>{}).add([66,18,0,2],(a,i)=>{}).add([66,18,1],(a,i)=>{let c=e.chRedir(a[0],i,!0),n=c*$.cc,s=a[1],o=`NS5R CH${c+1} `;a.subarray(2).forEach((f,l)=>{let b=s+l;b<3?([()=>{t(e,p)[n+y[0]]=f||121},()=>{t(e,p)[n+y[32]]=f},()=>{t(e,A)[c]=f}][b](),e.dispatchEvent("voice",{part:c})):b<8||(b<14?[()=>{let m=e.chRedir(f,i,!0);t(e,I)[c]=m,c!=m&&(e.buildRchTree(),console.info(`${o}receives from CH${m+1}`))},()=>{t(e,W)[c]=+!f},()=>{e.setChType(c,f,x.ns5r),console.debug(`${o}type: ${Fe[f]}`)},()=>{t(e,C)[$.rpn*c+3]=f,t(e,T)[$.rpnt*c+2]=1},()=>{},()=>{}][b-8]():b<16||(b<33?[()=>{t(e,p)[n+y[7]]=f},()=>{t(e,p)[n+y[11]]=f},()=>{},()=>{},()=>{t(e,p)[n+y[10]]=f||128},()=>{},()=>{},()=>{t(e,p)[n+y[93]]=f},()=>{t(e,p)[n+y[91]]=f},()=>{t(e,p)[n+y[76]]=f},()=>{t(e,p)[n+y[77]]=f},()=>{t(e,p)[n+y[78]]=f},()=>{t(e,p)[n+y[74]]=f},()=>{t(e,p)[n+y[71]]=f},()=>{t(e,p)[n+y[73]]=f},()=>{t(e,p)[n+y[75]]=f},()=>{t(e,p)[n+y[72]]=f}][b-16]():b<112||b<114&&[()=>{t(e,p)[n+y[5]]=f},()=>{t(e,p)[n+y[65]]=f}][b-112]()))})}).add([66,18,8,0],(a,i)=>{let c=a[0];if(c<32)e.setLetterDisplay(a.subarray(1,33),"NS5R letter display");else{let n=c-32;w(e,ce,Date.now()+3200),w(e,V,10),t(e,J,fe).fill(0);let s=a.subarray(1),o=4;s.forEach(function(f,l){let b=l+n,m=b>>4,S=b&15;if(b<80){let O=m>3,H=0,F=m0;)t(e,J,fe)[S*32+m*7+(F-H)]=O&1,O=O>>1,H++}})}}).add([66,18,48],(a,i,c)=>{h(0,a)}).add([66,18,49],(a,i,c)=>{h(1,a)}).add([66,18,50],(a,i,c)=>{h(2,a)}).add([66,18,51],(a,i,c)=>{h(3,a)}).add([66,18,52],(a,i,c)=>{h(4,a)}).add([66,18,53],(a,i,c)=>{h(5,a)}).add([66,18,54],(a,i,c)=>{h(6,a)}).add([66,18,55],(a,i,c)=>{h(7,a)}).add([66,52],(a,i)=>{e.switchMode("ns5r",!0),w(e,L,!1);let c="";ne(a,(n,s)=>{s<8?(n>31&&(c+=String.fromCharCode(n)),s==7&&(e.aiEfxName=c)):s<10&&(e.setEffectType(s-8,44,n),e.dispatchEvent(`efx${["reverb","chorus"][s-8]}`,e.getEffectType(s-8)))})}).add([66,53],(a,i)=>{e.switchMode("ns5r",!0),w(e,L,!1),ne(a,function(c,n){switch(!0){case n<2944:{let s=e.chRedir(Math.floor(n/92),i,!0),o=s*$.cc;switch(n%92){case 0:{t(e,p)[o+y[0]]=c||121,e.dispatchEvent("voice",{part:s});break}case 1:{t(e,p)[o+y[32]]=c,e.dispatchEvent("voice",{part:s});break}case 2:{t(e,A)[s]=c,c>0&&e.setChActive(s,1),e.dispatchEvent("voice",{part:s});break}case 3:{let f=e.chRedir(c,i,!0);t(e,I)[s]=f,s!=f&&(console.info(`NS5R CH${s+1} receives from CH${f+1}.`),e.buildRchTree())}case 7:break;case 8:{t(e,C)[s*$.rpn+3]=c<40||c>88?c+(c>63?-192:64):c,t(e,T)[$.rpnt*s+2]=1;break}case 9:case 10:{t(e,p)[o+y[7]]=c;break}case 11:{t(e,p)[o+y[11]]=c;break}case 14:{t(e,p)[o+y[10]]=c||128;break}case 19:{t(e,p)[o+y[93]]=c;break}case 20:{t(e,p)[o+y[91]]=c;break}case 84:{t(e,p)[o+y[65]]=c;break}case 85:{t(e,p)[o+y[5]]=c;break}}break}case n<3096:break;case n<3134:break;case n<8566:break}})}).add([66,54],(a,i)=>{e.switchMode("ns5r",!0);let c="",n=80,s=0,o=0,f="MSB PRG LSB NME";ne(a,function(l,b){let m=b%158;switch(!0){case m<10:{l>31&&(c+=String.fromCharCode(l));break}case m==11:{n=l&127;break}case m==12:{o=l&127;break}case m==13:{f+=` +${n} ${s} ${o} ${c.trim().replace("Init Voice","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:80,lsb:0}),e.userBank.load(f),U()&&console.debug(f),e.forceVoiceRefresh()}).add([66,55],(a,i)=>{e.switchMode("ns5r",!0);let c="",n=88,s=0,o=0,f="MSB PRG LSB NME";ne(a,function(l,b){let m=b%126;switch(!0){case m<10:{l>31&&(c+=String.fromCharCode(l));break}case m==11:break;case m==12:break;case m==13:{f+=` +${n} ${s} ${o} ${c.trim().replace("Init Combi","")}`,s++,c="";break}}}),e.userBank.clearRange({msb:88,lsb:0}),e.userBank.load(f),U()&&console.debug(f),e.forceVoiceRefresh()}).add([66,125],a=>{e.dispatchEvent("backlight",["green","orange","red",!1,"yellow","blue","purple"][a[0]]||"white")}).add([66,127],a=>{let i=new Uint8Array(5760);ne(a,(c,n,s)=>{if(n<720)for(let o=0;o<8;o++)i[n*8+o]=c>>7-o&1}),e.dispatchEvent("screen",{type:"ns5r",data:i})}).add([76],(a,i,c)=>{t(e,ye).run([66,...a],i,c)}),t(this,Oe).add([16,0,8,0],(a,i,c)=>{let n=(a[2]<<4)+a[3],s="K11 ";([()=>{e.switchMode("k11",!0),w(e,L,!1),w(e,Z,n?4:0),console.info("MIDI reset: GMega/K11")},()=>{e.setEffectType(0,24,n),console.debug(`${s}reverb type: ${n}`),e.dispatchEvent("efxreverb",e.getEffectType(0))},()=>{console.debug(`${s}reverb time: ${n}`)},()=>{console.debug(`${s}reverb time: ${n}`)},()=>{console.debug(`${s}reverb predelay: ${n}`)},()=>{console.debug(`${s}reverb predelay: ${n}`)},()=>{console.debug(`${s}depth high: ${n}`)},()=>{console.debug(`${s}depth high: ${n}`)},()=>{console.debug(`${s}depth low: ${n}`)},()=>{console.debug(`${s}depth low: ${n}`)}][a[0]]||(()=>{}))()}).add([16,0,8,1],(a,i,c)=>{let n=e.chRedir(a[1],i,!0),s=$.cc*n,o=$.rpn*n,f=(a[3]<<4)+a[4],l=`K11 CH${n+1} `;([()=>{f<128?(e.setChType(n,e.CH_MELODIC,x.k11),t(e,p)[s+y[0]]=0,t(e,A)[n]=f):(e.setChType(n,e.CH_DRUMS,x.k11),t(e,A)[n]=f-128),e.dispatchEvent("voice",{part:n})},()=>{let b=e.chRedir(f,i,!0);t(e,I)[n]=b,n!=b&&(e.buildRchTree(),console.info(`${l}receives from CH${b+1}`))},()=>{t(e,p)[s+y[7]]=f},()=>{uupThis.setChActive(n,f)},()=>{t(e,p)[s+y[10]]=f},()=>{t(e,C)[o+3]=f+40,t(e,T)[$.rpnt*n+2]=1},()=>{t(e,C)[o+1]=f>>1,t(e,C)[o+2]=f&1,t(e,T)[$.rpnt*n+1]=1},()=>{t(e,p)[s+y[91]]=f?127:0},()=>{},()=>{t(e,p)[s+y[74]]=f},()=>{t(e,p)[s+y[73]]=f},()=>{t(e,p)[s+y[72]]=f}][a[0]]||(()=>{}))()}).add([16,0,9,0],(a,i,c)=>{let n=(a[2]<<4)+a[3],s="GMLX ";([()=>{console.debug(`${s}reverb type: ${n}`)},()=>{console.debug(`${s}reverb time: ${n}`)},()=>{console.debug(`${s}reverb predelay: ${n}`)},()=>{console.debug(`${s}depth high: ${n}`)},()=>{console.debug(`${s}depth low: ${n}`)}][a[0]]||(()=>{}))()}).add([16,0,9,3],(a,i,c)=>{let n=(a[2]<<4)+a[3],s=e.chRedir(a[1],i,!0),o=s*$.cc;[()=>{n<128?(e.setChType(s,e.CH_MELODIC,x.k11),t(e,p)[o+y[0]]=0,t(e,p)[o+y[32]]=0,t(e,A)[s]=n):n<160?(e.setChType(s,e.CH_MELODIC,x.k11),t(e,p)[o+y[0]]=0,t(e,p)[o+y[32]]=7,t(e,A)[s]=n-100):(e.setChType(s,e.CH_DRUMS,x.k11),t(e,p)[o+y[0]]=122,t(e,p)[o+y[32]]=0,t(e,A)[s]=n-160),e.dispatchEvent("voice",{part:s})},()=>{let f=e.chRedir(n,i,!0);t(e,I)[s]=f,s!=f&&(e.buildRchTree(),console.info(`GMLX CH${s+1} receives from CH${f+1}`))}][a[0]]()}).add([16,0,9,4],(a,i,c)=>{let n=(a[2]<<4)+a[3],s=e.chRedir(a[1],i,!0),o=s*$.cc,f=s*$.rpn,l=`GMLX CH${s+1} `;[()=>{e.setChActive(s,n)},()=>{t(e,p)[o+y[7]]=n},()=>{t(e,p)[o+y[10]]=n},()=>{t(e,p)[o+y[91]]=n?127:0},()=>{t(e,C)[f+3]=n+40,t(e,T)[$.rpnt*s+2]=1},()=>{t(e,C)[f+1]=n,t(e,T)[$.rpnt*s+1]=1},()=>{t(e,C)[f]=n,t(e,T)[$.rpnt*s]=1},()=>{}][a[0]]()}),t(this,De).add([66,93,64],(a,i,c)=>{let n=a[2];switch(a[0]){case 0:{switch(a[1]){case 4:{w(e,P,n*129/16383*100),e.dispatchEvent("mastervolume",t(e,P));break}case 5:{n-64;break}case 6:{console.debug(`SG global reverb: ${n?"on":"off"}`);break}case 127:{e.switchMode("sg",!0);break}}break}case 1:{switch(a[1]){case 48:{console.debug(`SG reverb type: ${tt[n]}`);break}}break}default:if(a[0]>>4==1){let s=e.chRedir(a[0]&15,i,!0);if(a[1]==2){let o=e.chRedir(n,i,!0);t(e,I)[s]=o,s!=o&&(e.buildRchTree(),console.info(`SG CH${s+1} receives from CH${o+1}`))}else a[1]==19&&(t(e,p)[$.cc*s+y[7]]=n)}else console.warn(`Unknown AKAI SG SysEx: ${a}`)}}),t(this,Ae).add([9],(a,i,c)=>{console.debug(`GZ set effect: ${["stage reverb","hall reverb","room reverb","chorus","tremelo","phaser","rotary speaker","enhancer","flanger","EQ"][a[0]]||"off"}`)}),t(this,ee).add([127,0],(a,i,c)=>{e.switchMode("motif");let n=new Uint8Array([127,1,...a]);t(e,ee).run(n,i,c)}).add([127,1,0,0],(a,i,c)=>{e.switchMode("s90es");let n="S90/Motif ES system ",s=a[0];a.subarray(1).forEach((o,f)=>{([()=>{w(e,P,o*12900/16383),e.dispatchEvent("mastervolume",t(e,P))}][s+f]||(()=>{console.info(`Unrecognized ${n}ID: ${s+f}`)}))()})}).add([127,1,0,0,14],(a,i,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk header ",s=[];s[95]=(o,f,l)=>{console.debug(`${n}multi edit buffer: ${o[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,0,15],(a,i,c)=>{e.switchMode("s90es");let n="S90/Motif ES bulk footer ",s=[];s[95]=(o,f,l)=>{console.debug(`${n}multi edit buffer: ${o[1]}`)},(s[a[0]]||(()=>{console.info(`Unrecognized ${n}ID: ${a[0]}.`)}))(a.subarray(1))}).add([127,1,0,58,55],(a,i,c)=>{e.switchMode("s90es");let n=e.chRedir(a[0],i,!0),s=$.cc*n,o=a[1],f=`S90/Motif ES bulk CH${n<16?n+1:"U"+(n-95)} `;console.debug(f,a),!(a[0]>15)&&a.subarray(2).forEach((l,b)=>{([()=>{t(e,p)[s+y[0]]=l,e.dispatchEvent("voice",{part:n})},()=>{l&&e.setChActive(n,1),t(e,p)[s+y[32]]=l,e.setChType(n,[32,40].indexOf(l)>-1?e.CH_DRUMS:e.CH_MELODIC,t(e,D),!0),e.dispatchEvent("voice",{part:n})},()=>{l&&e.setChActive(n,1),t(e,A)[n]=l,e.dispatchEvent("voice",{part:n})},()=>{let m=e.chRedir(l,i,!0);t(e,I)[n]=m,n!=m&&(e.buildRchTree(),console.info(`${f}receives from CH${m+1}`))},()=>{t(e,W)[n]=l?0:1},!1,!1,!1,!1,!1,!1,!1,!1,()=>{t(e,p)[s+y[7]]=l},()=>{t(e,p)[s+y[10]]=l},!1,!1,!1,()=>{t(e,p)[s+y[91]]=l},()=>{t(e,p)[s+y[93]]=l},()=>{t(e,p)[s+y[94]]=l},()=>{t(e,p)[s+y[128]]=l},()=>{},()=>{t(e,p)[s+y[74]]=l},()=>{t(e,p)[s+y[71]]=l},!1,()=>{t(e,p)[s+y[65]]=l},()=>{t(e,p)[s+y[5]]=l},()=>{}][o+b]||(()=>{}))()})}).add([127,1,54,16],(a,i,c)=>{e.switchMode("s90es");let n=a[0];a.subarray(1).forEach((s,o)=>{let l=`S90/Motif ES EQ${(o>>2)+1} `;([()=>{let b=s-64},()=>{let b=Pe[s]},()=>{let b=s/10},()=>{let b=s}][n+o&3]||(()=>{}))()})}),t(this,te).add([0,72,18,0,0,0,0],(a,i,c)=>{e.switchMode("sd",!0),console.info("MIDI reset: SD")}).add([0,72,18,16,0],(a,i,c)=>{let n=a[0]>>5,s=a[0]&31;switch(n){case 0:{console.debug(`Unknown SD-90 global effects message: +%o`,a);break}case 1:{let o=e.chRedir(s,i,!0),f=a[1],l=o*$.cc;a.subarray(2).forEach((b,m)=>{let S=f+m;S<37?([()=>{},()=>{},0,()=>{},()=>{switch(t(e,p)[l+y[0]]=b,b){case 104:case 105:case 106:case 107:case 120:{t(e,M)[o]||e.setChType(o,e.CH_DRUMS);break}default:t(e,M)[o]&&e.setChType(o,e.CH_MELODIC)}e.dispatchEvent("voice",{part:o})},()=>{t(e,p)[l+y[32]]=b,e.dispatchEvent("voice",{part:o})},()=>{t(e,A)[o]=b,e.dispatchEvent("voice",{part:o})},()=>{t(e,p)[l+y[7]]=b},()=>{t(e,p)[l+y[10]]=b},()=>{},()=>{},()=>{b<2&&(t(e,W)[o]=b)},()=>{b<2&&(t(e,p)[l+y[68]]=b?127:0)},()=>{},()=>{b<2&&(t(e,p)[l+y[65]]=b?127:0)},()=>{t(e,p)[l+y[5]]=b&15<<4|t(e,p)[l+y[5]]&15},()=>{t(e,p)[l+y[5]]=b&15|(t(e,p)[l+y[5]]&240)>>4},()=>{t(e,p)[l+y[74]]=b},()=>{t(e,p)[l+y[71]]=b},()=>{t(e,p)[l+y[73]]=b},()=>{t(e,p)[l+y[72]]=b},0,0,0,0,0,0,0,()=>{t(e,p)[l+y[128]]=b},()=>{t(e,p)[l+y[93]]=b},()=>{t(e,p)[l+y[91]]=b},0,0,()=>{t(e,p)[l+y[75]]=b},()=>{t(e,p)[l+y[76]]=b},()=>{t(e,p)[l+y[77]]=b},()=>{t(e,p)[l+y[78]]=b}][S]||(()=>{}))():S<63||(S<64?t(e,M)[o]?t(e,p)[l+y[0]]=104|b:t(e,p)[l+y[0]]=96|b:console.debug(`Unknown SD-90 global CH${o+1} param setup message: %o`,a))});break}case 2:{let o=e.chRedir(s,i,!0),f=a[1];console.debug(`Unknown SD-90 global CH${o+1} MIDI setup message: %o`,a.subarray(2));break}default:console.warn(`Unknown SD-90 global part setup message: -%o`,a)}})}chRedir(e,r,d){if(t(this,ke)[r])return(t(this,ke)[r]-1)*16+e;if([2,3].indexOf(t(this,Z))>-1){if(d==1)return e;let h=0,E=!0;for(;E;)t(this,be)[e+h]==0?(t(this,be)[e+h]=r,console.debug(`Assign track ${r} to channel ${e+h+1}.`),E=!1):t(this,be)[e+h]==r?E=!1:(h+=16,h>=128&&(h=0,E=!1));return e+h}else return e}forceVoiceRefresh(){for(let e=0;e<$.ch;e++)t(this,ue)[e]&&this.dispatchEvent("voice",{part:e})}buildRchTree(){let e=[];t(this,I).forEach((r,d)=>{var h;r<$.ch&&((h=e[r])!=null&&h.constructor||(e[r]=[]),e[r].push(d))}),w(this,Qe,e)}getActive(){return t(this,ue)}getCc(e){let r=e*$.cc,d=t(this,u).subarray(r,r+$.cc);return d[y[0]]=d[y[0]]||t(this,me),d[y[32]]=d[y[32]]||t(this,Z),d}getCcCh(e,r){if(Ke.indexOf(r)<0)throw new Error("CC number not accepted");return t(this,u)[$.cc*e+y[r]]}getCcAll(){let e=t(this,u).slice();for(let r=0;r<$.ch;r++){let d=r*$.cc;e[d+y[0]]=e[d+y[0]]||t(this,me),e[d+y[32]]=e[d+y[32]]||t(this,Z)}return e}getChSource(){return t(this,I)}getChType(){return t(this,M)}setChType(e,r,d=t(this,D),h=!1){r&=15,t(this,M)[e]=r,r>0&&!h&&(t(this,u)[e*$.cc+y[0]]=Se[d])}setChActive(e,r=0){t(this,ue)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),t(this,ue)[e]=r}getPitch(){return t(this,ge)}getProgram(){return t(this,A)}getTexts(){return t(this,j).slice()}getVel(e){let r=new Map,d=this;return t(d,B).forEach(function(h,E){let b=Math.floor(h/128),v=h%128;e==b&&t(d,N)[h]>0&&r.set(v,{v:t(d,N)[h],s:t(d,_)[E]})}),r}getBitmap(){return{bitmap:t(this,J,fe),expire:t(this,ce)}}getLetter(){return{text:t(this,ve),set:t(this,ze),expire:t(this,we)}}getMode(){return de[t(this,D)]}getMaster(){return{volume:t(this,P)}}getRawStrength(){let e=this;return t(this,B).forEach(function(r){let d=Math.floor(r/128);t(e,N)[r]>t(e,oe)[d]&&(t(e,oe)[d]=t(e,N)[r])}),t(this,oe)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(d,h){e[h]=Math.floor(d*t(r,u)[h*$.cc+y[7]]*t(r,u)[h*$.cc+y[11]]*t(r,P)/803288)}),e}getRpn(){return t(this,C)}getNrpn(){return t(this,Le)}getVoice(e,r,d,h){let E=e||t(this,me),b=r,v=d||t(this,Z);de[t(this,D)]=="ns5r"&&E>0&&E<56&&(v=3);let a=this.userBank.get(E,b,v,h);if(de[t(this,D)]=="mt32"&&a.name.indexOf("MT-m:")==0){let i=parseInt(a.name.slice(5)),c=i*$.cmt,n="";t(this,Ee).subarray(c,c+10).forEach(s=>{s>31&&(n+=String.fromCharCode(s))}),this.userBank.load(`MSB LSB PRG -0 127 ${b} ${n}`,!0),a.name=n,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(E,b,v,h)),a}getChVoice(e){let r=this.getVoice(t(this,u)[e*$.cc+y[0]],t(this,A)[e],t(this,u)[e*$.cc+y[32]],de[t(this,D)]);if(t(this,le)[e])switch(t(this,D)){case x.mt32:r.ending="~",r.name="",t(this,re).subarray(14*(e-1),14*(e-1)+10).forEach(d=>{d>31&&(r.name+=String.fromCharCode(d))})}return r}getPitchShift(e){let r=this,d=e*$.rpn,h=t(r,C)[d];return t(r,T)[e*$.rpnt]||t(r,D)==x.mt32&&(h=12),t(r,ge)[e]/8192*h+(t(r,C)[d+3]-64)+((t(r,C)[d+1]<<7)+t(r,C)[d+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return t(this,Y).subarray(r,r+2)}setEffectTypeRaw(e=0,r,d){let h=3*e;t(this,Y)[h]=1,t(this,Y)[h+1+ +r]=d}setEffectType(e=0,r,d){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,d)}getEffectSink(){return t(this,Ne)}setLetterDisplay(e,r,d=0,h=3200){let E=this,b;w(E,ve," ".repeat(d)),e.forEach(v=>{w(E,ve,t(E,ve)+String.fromCharCode(v>31?v:32)),v<32&&(b=b||new Set,b.add(v))}),w(E,ze,Date.now()),w(E,we,Date.now()+h),b&&(b=Array.from(b),b.forEach((v,a,i)=>{i[a]=v.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${b.length>1?"s":""}: 0x${b.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let r=!0,d=0;for(;r&&d<$.ace;)t(this,pe)[d]==e?r=!1:t(this,pe)[d]||(r=!1,t(this,pe)[d]=e,console.info(`Allocated cc${e} to ACE slot ${d}.`)),d++;d>=$.ace&&console.warn("ACE slots are full.")}getAce(){return t(this,pe)}getChAce(e,r){if(r<0||r>=$.ace)throw new RangeError("No such ACE slot");let d=t(this,pe)[r];if(d){if(Ke.indexOf(d)>=0)return t(this,u)[e*$.cc+y[d]];throw new Error(`Invalid ACE source: ${d}`)}else return 0}initDrums(){let e=this;t(e,K).fill(64);for(let r=0;r<$.drm;r++){let d=r*$.dpn;for(let h in Rt){let E=Rt[h],b=(d+ae[h])*$.dnc;t(e,K).subarray(b,b+$.dnc).fill(E)}}}init(e=0){let r=this;w(r,me,0),w(r,Z,0),w(r,Ce,0),t(r,ue).fill(0),t(r,u).fill(0),t(r,pe).fill(0),t(r,A).fill(0),t(r,N).fill(0),t(r,B).fill(0),t(r,W).fill(0),t(r,oe).fill(0),t(r,ge).fill(0),t(r,Le).fill(0),t(r,T).fill(0),w(r,P,100),w(r,j,[]),w(r,Be,500),w(r,Ge,0),w(r,ce,0),w(r,V,0),t(r,J,fe).fill(0),w(r,L,!1),w(r,Ie,0),w(r,se,!0),r.initDrums(),t(r,I).forEach(function(d,h,E){E[h]=h}),r.buildRchTree(),e==0&&(r.dispatchEvent("mode","?"),w(r,D,0),t(r,be).fill(0),t(r,ke).fill(0),w(r,we,0),w(r,ve,"")),t(r,u)[$.cc*9]=Se[0],t(r,u)[$.cc*25]=Se[0],t(r,u)[$.cc*41]=Se[0],t(r,u)[$.cc*57]=Se[0],t(r,M).fill(r.CH_MELODIC),t(r,M)[9]=r.CH_DRUM1,t(r,M)[25]=r.CH_DRUM3,t(r,M)[41]=r.CH_DRUMS,t(r,M)[57]=r.CH_DRUMS,t(r,M)[73]=r.CH_DRUM5,t(r,M)[89]=r.CH_DRUM7,t(r,M)[105]=r.CH_DRUMS,t(r,M)[121]=r.CH_DRUMS,t(r,He).fill(0),t(r,Ee).fill(0),t(r,$e).fill(0),t(r,re).fill(0),t(r,le).fill(0),t(r,Y).fill(0),t(r,Ne).fill(0),r.aiEfxName="",r.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let d=0;d<$.ch;d++){let h=d*$.cc;t(r,u)[h+y[7]]=100,t(r,u)[h+y[11]]=127,t(r,u)[h+y[10]]=64,t(r,u)[h+y[71]]=64,t(r,u)[h+y[72]]=64,t(r,u)[h+y[73]]=64,t(r,u)[h+y[74]]=64,t(r,u)[h+y[75]]=64,t(r,u)[h+y[76]]=64,t(r,u)[h+y[77]]=64,t(r,u)[h+y[78]]=64,t(r,u)[h+y[91]]=40,t(r,u)[h+y[101]]=127,t(r,u)[h+y[100]]=127,t(r,u)[h+y[99]]=127,t(r,u)[h+y[98]]=127;let E=d*$.rpn;t(r,C)[E]=2,t(r,C)[E+1]=64,t(r,C)[E+2]=0,t(r,C)[E+3]=64,t(r,C)[E+4]=0,t(r,C)[E+5]=0}r.dispatchEvent("mastervolume",t(r,P)),r.dispatchEvent("efxreverb",r.getEffectType(0)),r.dispatchEvent("efxchorus",r.getEffectType(1)),r.dispatchEvent("efxdelay",r.getEffectType(2)),r.dispatchEvent("efxinsert0",r.getEffectType(3)),r.dispatchEvent("efxinsert1",r.getEffectType(4)),r.dispatchEvent("efxinsert2",r.getEffectType(5)),r.dispatchEvent("efxinsert3",r.getEffectType(6)),r.dispatchEvent("reset"),r.switchMode("?")}switchMode(e,r=!1){let d=this,h=de.indexOf(e);if(h>-1){if(t(d,D)==0||r){let E=t(d,D);d.initOnReset&&r&&(this.init(1),E=x["?"]),w(d,D,h),w(d,V,0),w(d,me,kt[0][h]),w(d,Z,kt[1][h]);for(let v=0;v<$.ch;v++)t(d,M)[v]>0&&t(d,u)[v*$.cc+y[0]]==Se[E]&&(t(d,u)[v*$.cc]=Se[h]);switch(h){case x.mt32:{rt.forEach((v,a)=>{let i=a+1;t(d,ue)[i]||(t(d,A)[i]=v,t(d,u)[i*$.cc+y[91]]=127)});for(let v=1;v<10;v++)d.dispatchEvent("voice",{part:v});break}}let b;switch(h){case x["?"]:case x.xg:{b=[1,0,65,0,5,0,0,0];break}case x.gm:case x.gs:case x.g2:case x.sd:{b=[40,4,40,18,40,32,32,0];break}case x["05rw"]:case x.x5d:case x.ns5r:{b=[44,1,44,19,44,0,44,0];break}case x.k11:case x.sg:{b=[24,0,0,0,0,0,0,0];break}case x.mt32:{b=[40,4,0,0,0,0,0,0];break}default:b=[0,0,0,0,0,0,0,0]}for(let v=0;v<4;v++)t(d,Y)[3*v]||(t(d,Y)[3*v+1]=b[2*v],t(d,Y)[3*v+2]=b[2*v+1],d.dispatchEvent(`efx${["reverb","chorus","delay","insert"][v]}`,d.getEffectType(v)));d.dispatchEvent("mode",e),d.forceVoiceRefresh()}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,oe).fill(0)}runJson(e){var r;if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,qe)[e.type].call(this,e);{let d=this.chRedir(e.part,e.track),h=!1;(r=t(this,Qe)[d])==null||r.forEach(E=>{e.channel=E,h=!0,t(this,qe)[e.type].call(this,e)}),h||console.warn(`${St[e.type]?St[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${d+1} without any recipient.`)}t(this,j).length>100&&t(this,j).splice(100,t(this,j).length-99)}runRaw(e){}async loadBank(e,r){let d=this;switch(e=e.toLowerCase(),e){case"s7e":{d.userBank.clearRange({msb:63,lsb:[21,22]}),d.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{We.context=this,d.userBank.load(await We.read(e,r));break}}d.forceVoiceRefresh()}},D=new WeakMap,V=new WeakMap,ce=new WeakMap,he=new WeakMap,J=new WeakSet,fe=function(){return t(this,he)[t(this,V)]},At=function(e){t(this,he)[t(this,V)]=e},ue=new WeakMap,I=new WeakMap,M=new WeakMap,u=new WeakMap,pe=new WeakMap,A=new WeakMap,N=new WeakMap,W=new WeakMap,B=new WeakMap,_=new WeakMap,ge=new WeakMap,oe=new WeakMap,xe=new WeakMap,C=new WeakMap,T=new WeakMap,Le=new WeakMap,K=new WeakMap,le=new WeakMap,$e=new WeakMap,re=new WeakMap,He=new WeakMap,Ee=new WeakMap,Y=new WeakMap,Ne=new WeakMap,me=new WeakMap,Z=new WeakMap,P=new WeakMap,Ce=new WeakMap,Be=new WeakMap,Ge=new WeakMap,ve=new WeakMap,we=new WeakMap,ze=new WeakMap,Ie=new WeakMap,se=new WeakMap,L=new WeakMap,Qe=new WeakMap,it=new WeakMap,j=new WeakMap,be=new WeakMap,ke=new WeakMap,X=new WeakMap,Me=new WeakMap,G=new WeakMap,qe=new WeakMap,Ye=new WeakMap,Te=new WeakMap,Re=new WeakMap,ee=new WeakMap,te=new WeakMap,ye=new WeakMap,Oe=new WeakMap,De=new WeakMap,Ae=new WeakMap,Dt);export{Ma as OctaviaDevice,$ as allocated,y as ccToPos,ae as dnToPos}; +%o`,a)}})}chRedir(e,r,d){if(t(this,ke)[r])return(t(this,ke)[r]-1)*16+e;if([2,3].indexOf(t(this,Z))>-1){if(d==1)return e;let h=0,E=!0;for(;E;)t(this,be)[e+h]==0?(t(this,be)[e+h]=r,console.debug(`Assign track ${r} to channel ${e+h+1}.`),E=!1):t(this,be)[e+h]==r?E=!1:(h+=16,h>=128&&(h=0,E=!1));return e+h}else return e}forceVoiceRefresh(){for(let e=0;e<$.ch;e++)t(this,ue)[e]&&this.dispatchEvent("voice",{part:e})}buildRchTree(){let e=[];t(this,I).forEach((r,d)=>{var h;r<$.ch&&((h=e[r])!=null&&h.constructor||(e[r]=[]),e[r].push(d))}),w(this,Qe,e)}getActive(){return t(this,ue)}getCc(e){let r=e*$.cc,d=t(this,p).subarray(r,r+$.cc);return d[y[0]]=d[y[0]]||t(this,me),d[y[32]]=d[y[32]]||t(this,Z),d}getCcCh(e,r){if(Ke.indexOf(r)<0)throw new Error("CC number not accepted");return t(this,p)[$.cc*e+y[r]]}getCcAll(){let e=t(this,p).slice();for(let r=0;r<$.ch;r++){let d=r*$.cc;e[d+y[0]]=e[d+y[0]]||t(this,me),e[d+y[32]]=e[d+y[32]]||t(this,Z)}return e}getChSource(){return t(this,I)}getChType(){return t(this,M)}setChType(e,r,d=t(this,D),h=!1){r&=15,t(this,M)[e]=r,r>0&&!h&&(t(this,p)[e*$.cc+y[0]]=Se[d])}setChActive(e,r=0){t(this,ue)[e]!=r&&this.dispatchEvent("channeltoggle",{part:e,active:r}),t(this,ue)[e]=r}getPitch(){return t(this,ge)}getProgram(){return t(this,A)}getTexts(){return t(this,j).slice()}getVel(e){let r=new Map,d=this;return t(d,B).forEach(function(h,E){let u=Math.floor(h/128),v=h%128;e==u&&t(d,N)[h]>0&&r.set(v,{v:t(d,N)[h],s:t(d,_)[E]})}),r}getBitmap(){return{bitmap:t(this,J,fe),expire:t(this,ce)}}getLetter(){return{text:t(this,ve),set:t(this,ze),expire:t(this,we)}}getMode(){return de[t(this,D)]}getMaster(){return{volume:t(this,P)}}getRawStrength(){let e=this;return t(this,B).forEach(function(r){let d=Math.floor(r/128);t(e,N)[r]>t(e,oe)[d]&&(t(e,oe)[d]=t(e,N)[r])}),t(this,oe)}getStrength(){let e=[],r=this;return this.getRawStrength().forEach(function(d,h){e[h]=Math.floor(d*t(r,p)[h*$.cc+y[7]]*t(r,p)[h*$.cc+y[11]]*t(r,P)/803288)}),e}getRpn(){return t(this,C)}getNrpn(){return t(this,Le)}getVoice(e,r,d,h){let E=e||t(this,me),u=r,v=d||t(this,Z);de[t(this,D)]=="ns5r"&&E>0&&E<56&&(v=3);let a=this.userBank.get(E,u,v,h);if(de[t(this,D)]=="mt32"&&a.name.indexOf("MT-m:")==0){let i=parseInt(a.name.slice(5)),c=i*$.cmt,n="";t(this,Ee).subarray(c,c+10).forEach(s=>{s>31&&(n+=String.fromCharCode(s))}),this.userBank.load(`MSB LSB PRG +0 127 ${u} ${n}`,!0),a.name=n,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(E,u,v,h)),a}getChVoice(e){let r=this.getVoice(t(this,p)[e*$.cc+y[0]],t(this,A)[e],t(this,p)[e*$.cc+y[32]],de[t(this,D)]);if(t(this,le)[e])switch(t(this,D)){case x.mt32:r.ending="~",r.name="",t(this,re).subarray(14*(e-1),14*(e-1)+10).forEach(d=>{d>31&&(r.name+=String.fromCharCode(d))})}return r}getPitchShift(e){let r=this,d=e*$.rpn,h=t(r,C)[d];return t(r,T)[e*$.rpnt]||t(r,D)==x.mt32&&(h=12),t(r,ge)[e]/8192*h+(t(r,C)[d+3]-64)+((t(r,C)[d+1]<<7)+t(r,C)[d+2]-8192)/8192}getEffectType(e=0){let r=3*e+1;return t(this,Y).subarray(r,r+2)}setEffectTypeRaw(e=0,r,d){let h=3*e;t(this,Y)[h]=1,t(this,Y)[h+1+ +r]=d}setEffectType(e=0,r,d){this.setEffectTypeRaw(e,!1,r),this.setEffectTypeRaw(e,!0,d)}getEffectSink(){return t(this,Ne)}setLetterDisplay(e,r,d=0,h=3200){let E=this,u;w(E,ve," ".repeat(d)),e.forEach(v=>{w(E,ve,t(E,ve)+String.fromCharCode(v>31?v:32)),v<32&&(u=u||new Set,u.add(v))}),w(E,ze,Date.now()),w(E,we,Date.now()+h),u&&(u=Array.from(u),u.forEach((v,a,i)=>{i[a]=v.toString(16).padStart(2,"0")}),console.warn(`${r}${r?" ":""}invalid code point${u.length>1?"s":""}: 0x${u.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let r=!0,d=0;for(;r&&d<$.ace;)t(this,pe)[d]==e?r=!1:t(this,pe)[d]||(r=!1,t(this,pe)[d]=e,console.info(`Allocated cc${e} to ACE slot ${d}.`)),d++;d>=$.ace&&console.warn("ACE slots are full.")}getAce(){return t(this,pe)}getChAce(e,r){if(r<0||r>=$.ace)throw new RangeError("No such ACE slot");let d=t(this,pe)[r];if(d){if(Ke.indexOf(d)>=0)return t(this,p)[e*$.cc+y[d]];throw new Error(`Invalid ACE source: ${d}`)}else return 0}initDrums(){let e=this;t(e,K).fill(64);for(let r=0;r<$.drm;r++){let d=r*$.dpn;for(let h in Rt){let E=Rt[h],u=(d+ae[h])*$.dnc;t(e,K).subarray(u,u+$.dnc).fill(E)}}}init(e=0){let r=this;w(r,me,0),w(r,Z,0),w(r,Ce,0),t(r,ue).fill(0),t(r,p).fill(0),t(r,pe).fill(0),t(r,A).fill(0),t(r,N).fill(0),t(r,B).fill(0),t(r,W).fill(0),t(r,oe).fill(0),t(r,ge).fill(0),t(r,Le).fill(0),t(r,T).fill(0),w(r,P,100),w(r,j,[]),w(r,Be,500),w(r,Ge,0),w(r,ce,0),w(r,V,0),t(r,J,fe).fill(0),w(r,L,!1),w(r,Ie,0),w(r,se,!0),r.initDrums(),t(r,I).forEach(function(d,h,E){E[h]=h}),r.buildRchTree(),e==0&&(r.dispatchEvent("mode","?"),w(r,D,0),t(r,be).fill(0),t(r,ke).fill(0),w(r,we,0),w(r,ve,"")),t(r,p)[$.cc*9]=Se[0],t(r,p)[$.cc*25]=Se[0],t(r,p)[$.cc*41]=Se[0],t(r,p)[$.cc*57]=Se[0],t(r,M).fill(r.CH_MELODIC),t(r,M)[9]=r.CH_DRUM1,t(r,M)[25]=r.CH_DRUM3,t(r,M)[41]=r.CH_DRUMS,t(r,M)[57]=r.CH_DRUMS,t(r,M)[73]=r.CH_DRUM5,t(r,M)[89]=r.CH_DRUM7,t(r,M)[105]=r.CH_DRUMS,t(r,M)[121]=r.CH_DRUMS,t(r,He).fill(0),t(r,Ee).fill(0),t(r,$e).fill(0),t(r,re).fill(0),t(r,le).fill(0),t(r,Y).fill(0),t(r,Ne).fill(0),r.aiEfxName="",r.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let d=0;d<$.ch;d++){let h=d*$.cc;t(r,p)[h+y[7]]=100,t(r,p)[h+y[11]]=127,t(r,p)[h+y[10]]=64,t(r,p)[h+y[71]]=64,t(r,p)[h+y[72]]=64,t(r,p)[h+y[73]]=64,t(r,p)[h+y[74]]=64,t(r,p)[h+y[75]]=64,t(r,p)[h+y[76]]=64,t(r,p)[h+y[77]]=64,t(r,p)[h+y[78]]=64,t(r,p)[h+y[91]]=40,t(r,p)[h+y[101]]=127,t(r,p)[h+y[100]]=127,t(r,p)[h+y[99]]=127,t(r,p)[h+y[98]]=127;let E=d*$.rpn;t(r,C)[E]=2,t(r,C)[E+1]=64,t(r,C)[E+2]=0,t(r,C)[E+3]=64,t(r,C)[E+4]=0,t(r,C)[E+5]=0}r.dispatchEvent("mastervolume",t(r,P)),r.dispatchEvent("efxreverb",r.getEffectType(0)),r.dispatchEvent("efxchorus",r.getEffectType(1)),r.dispatchEvent("efxdelay",r.getEffectType(2)),r.dispatchEvent("efxinsert0",r.getEffectType(3)),r.dispatchEvent("efxinsert1",r.getEffectType(4)),r.dispatchEvent("efxinsert2",r.getEffectType(5)),r.dispatchEvent("efxinsert3",r.getEffectType(6)),r.dispatchEvent("reset"),r.switchMode("?")}switchMode(e,r=!1){let d=this,h=de.indexOf(e);if(h>-1){if(t(d,D)==0||r){let E=t(d,D);d.initOnReset&&r&&(this.init(1),E=x["?"]),w(d,D,h),w(d,V,0),w(d,me,kt[0][h]),w(d,Z,kt[1][h]);for(let v=0;v<$.ch;v++)t(d,M)[v]>0&&t(d,p)[v*$.cc+y[0]]==Se[E]&&(t(d,p)[v*$.cc]=Se[h]);switch(h){case x.mt32:{rt.forEach((v,a)=>{let i=a+1;t(d,ue)[i]||(t(d,A)[i]=v,t(d,p)[i*$.cc+y[91]]=127)});for(let v=1;v<10;v++)d.dispatchEvent("voice",{part:v});break}}let u;switch(h){case x["?"]:case x.xg:{u=[1,0,65,0,5,0,0,0];break}case x.gm:case x.gs:case x.g2:case x.sd:{u=[40,4,40,18,40,32,32,0];break}case x["05rw"]:case x.x5d:case x.ns5r:{u=[44,1,44,19,44,0,44,0];break}case x.k11:case x.sg:{u=[24,0,0,0,0,0,0,0];break}case x.mt32:{u=[40,4,0,0,0,0,0,0];break}default:u=[0,0,0,0,0,0,0,0]}for(let v=0;v<4;v++)t(d,Y)[3*v]||(t(d,Y)[3*v+1]=u[2*v],t(d,Y)[3*v+2]=u[2*v+1],d.dispatchEvent(`efx${["reverb","chorus","delay","insert"][v]}`,d.getEffectType(v)));d.dispatchEvent("mode",e),d.forceVoiceRefresh()}}else throw new Error(`Unknown mode ${e}`)}newStrength(){t(this,oe).fill(0)}runJson(e){var r;if(e.type>14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),t(this,qe)[e.type].call(this,e);{let d=this.chRedir(e.part,e.track),h=!1;(r=t(this,Qe)[d])==null||r.forEach(E=>{e.channel=E,h=!0,t(this,qe)[e.type].call(this,e)}),h||console.warn(`${St[e.type]?St[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${d+1} without any recipient.`)}t(this,j).length>100&&t(this,j).splice(100,t(this,j).length-99)}runRaw(e){}async loadBank(e,r){let d=this;switch(e=e.toLowerCase(),e){case"s7e":{d.userBank.clearRange({msb:63,lsb:[21,22]}),d.userBank.clearRange({msb:63,lsb:[24,27]});break}default:throw new Error(`Unknown bank format ${e}`)}switch(e){case"s7e":{We.context=this,d.userBank.load(await We.read(e,r));break}}d.forceVoiceRefresh()}},D=new WeakMap,V=new WeakMap,ce=new WeakMap,he=new WeakMap,J=new WeakSet,fe=function(){return t(this,he)[t(this,V)]},At=function(e){t(this,he)[t(this,V)]=e},ue=new WeakMap,I=new WeakMap,M=new WeakMap,p=new WeakMap,pe=new WeakMap,A=new WeakMap,N=new WeakMap,W=new WeakMap,B=new WeakMap,_=new WeakMap,ge=new WeakMap,oe=new WeakMap,xe=new WeakMap,C=new WeakMap,T=new WeakMap,Le=new WeakMap,K=new WeakMap,le=new WeakMap,$e=new WeakMap,re=new WeakMap,He=new WeakMap,Ee=new WeakMap,Y=new WeakMap,Ne=new WeakMap,me=new WeakMap,Z=new WeakMap,P=new WeakMap,Ce=new WeakMap,Be=new WeakMap,Ge=new WeakMap,ve=new WeakMap,we=new WeakMap,ze=new WeakMap,Ie=new WeakMap,se=new WeakMap,L=new WeakMap,Qe=new WeakMap,it=new WeakMap,j=new WeakMap,be=new WeakMap,ke=new WeakMap,X=new WeakMap,Me=new WeakMap,G=new WeakMap,qe=new WeakMap,Ye=new WeakMap,Te=new WeakMap,Re=new WeakMap,ee=new WeakMap,te=new WeakMap,ye=new WeakMap,Oe=new WeakMap,De=new WeakMap,Ae=new WeakMap,Dt);export{Ma as OctaviaDevice,$ as allocated,y as ccToPos,ae as dnToPos}; diff --git a/src/disp/disp_sc.mjs b/src/disp/disp_sc.mjs index d49521eb..78e07ae4 100644 --- a/src/disp/disp_sc.mjs +++ b/src/disp/disp_sc.mjs @@ -281,7 +281,13 @@ let ScDisplay = class extends RootDisplay { paramText += Math.abs(cPan - 64).toString().padStart(2, " "); }; paramText += sum.chContr[chOff + ccToPos[93]].toString().padStart(3, " "); - paramText += (upThis.device.getChSource()[upThis.#ch] + 1).toString().padStart(3, "0"); + let chSource = upThis.device.getChSource()[upThis.#ch]; + if (chSource < 128) { + paramText += "ABCDEFGH"[chSource >> 4]; + paramText += ((chSource & 15) + 1).toString().padStart(2, "0"); + } else { + paramText += `${"ABCDEFGH"[upThis.#ch >> 4]}--`; + }; // Render fonts upThis.xgFont.getStr(paramText).forEach(function (e0, i0) { e0.forEach(function (e1, i1) {