From 2ea22998bcf7b1645430a05fe8ed974434986a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lumi=C3=A8re=20=C3=89lev=C3=A9?= <88174309+PoneyClairDeLune@users.noreply.github.com> Date: Mon, 24 Apr 2023 18:47:54 +0000 Subject: [PATCH] Drum NRPN is now supported. --- dist/cambiare.mjs | 6 +++--- dist/state.mjs | 6 +++--- src/state/index.mjs | 8 +++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/dist/cambiare.mjs b/dist/cambiare.mjs index b238fa18..f3bea04c 100644 --- a/dist/cambiare.mjs +++ b/dist/cambiare.mjs @@ -136,8 +136,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let n=e.split(",");L[n[0]]=n[1]});var J=function(e){let n=e;e[0]=="*"&&(n=n.slice(1)),["aa","ii","uu","ee","oo"].forEach(t=>{for(;n.indexOf(t)>-1;)n=n.replace(t,t[0])});for(let t in L)n=n.replaceAll(t,L[t]);n.indexOf("ん")==0&&n.length>1&&(n=n.slice(1));let o=n.indexOf("!");return o>-1&&n.length>1&&(n=n.slice(o+1)),n},ee=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var H=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],te=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ie=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var Re={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"},Oe={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]]},B=function(e){return Re[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},re=function(e,n,o){let t=(e[0]-32<<16)+(e[1]<<8)+n,i=Oe[t]||{},r=i[0];if(r?.length)return r+=`: ${(i[1]||function(){})(o)||o}`,r},G=[68,48,95,78,41,3,110,122,0];var w=function(e=64){return Math.round(2e3*Math.log10(e/64))/100},ae=function(e,n,o){let t=[],i=o==!1?n.readIntVLV():o;e==0||e==127;for(let r=0;r127)return console.debug(`Early termination: ${t}`),t.pop(),n.backOne(),n.backOne(),new Uint8Array(t)}}}return new Uint8Array(t)},se=function(e){let n=0;return e.forEach(o=>{n+=o,n=n&127}),~n+1&127},S=function(e,n){let o=0,t=0;for(let i=0;i>r&1)<<7,a=e[i];a+=s,i%8!=0?(n(a,o,e),o++):t=e[i]}},P=function(e){let n=Math.floor(e*14.2);return n<128?n:0};var x=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],ne=[[0,0,0,0,121,0,0,56,82,81,63,0,0],[0,0,4,0,0,127,0,0,0,0,0,0,0]],T=[120,127,120,127,120,127,61,62,62,62,120,122,122],Pe=[0,3,81,84,88],oe={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},_={0:0,1:1,2:3,5:4},ce=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],le=[36,37],fe=[20,21,22,23,24,25,26,28,29,30,31,36,37,64,65],D=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,12,13,16,17,18,19],De=[12,13,16,17,18,19],Ie=[33,99,100,32,102,8,9,10],he=[0,16,25,40,32,64,26,48],y={};x.forEach((e,n)=>{y[e]=n});var f={length:D.length};D.forEach((e,n)=>{f[e]=n});var E=function(){return!!self.Bun||self.debugMode||!1},Ae=function(e){let n=[],o=0;return e?.forEach(function(t,i){t==247?n.push(e.subarray(o,i)):t==240&&(o=i+1)}),n.length||n.push(e.subarray(0)),E()&&console.debug(n),n},de=function(e,n="",o="",t=2){return e?`${n}${e.toString().padStart(t,"0")}${o}`:""},p={ch:128,cc:D.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:fe.length,dnc:128,efx:7},ue=class extends I{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#n=0;#h=0;#p=new Array(11);get#g(){return this.#p[this.#n]}set#g(e){this.#p[this.#n]=e}#c=new Uint8Array(p.ch);#l=new Uint8Array(p.ch);#i=new Uint8Array(p.ch);#e=new Uint8Array(p.ch*p.cc);#b=new Uint8Array(p.ace);#s=new Uint8Array(p.ch);#d=new Uint8Array(p.ch*p.nn);#S=new Uint8Array(p.ch);#f=new Uint16Array(p.pl);#$=new Uint8Array(p.pl);#D=new Int16Array(p.ch);#x=new Uint8Array(p.ch);#B=0;#r=new Uint8Array(p.ch*p.rpn);#_=new Int8Array(p.ch*le.length);#J=new Uint8Array(p.drm*p.dpn*p.dnc);#T=new Uint8Array(p.ch);#I=new Uint8Array(128);#w=new Uint8Array(p.cmt*8);#F=new Uint8Array(1024);#A=new Uint8Array(p.cmt*64);#m=new Uint8Array(p.efx*3);#U=0;#E=0;#v=100;#C=0;#V=500;#X=0;#M="";#N=0;#K=0;#k=!0;#o=!1;#Y;#te=new Uint8Array(2);#a=[];#R=new Uint8Array(p.ch);#L=new Uint8Array(p.tr);baseBank=new N("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new N("gm");initOnReset=!1;aiEfxName="";chRedir(e,n,o){if(this.#L[n])return(this.#L[n]-1)*16+e;if([2,3].indexOf(this.#E)>-1){if(o==1)return e;let t=0,i=!0;for(;i;)this.#R[e+t]==0?(this.#R[e+t]=n,console.debug(`Assign track ${n} to channel ${e+t+1}.`),i=!1):this.#R[e+t]==n?i=!1:(t+=16,t>=128&&(t=0,i=!1));return e+t}else return e}#y=[];#G;#u={nOff:(e,n)=>{let o=e*128+n,t=this.#f.lastIndexOf(o);t>-1&&(this.#e[p.cc*e+f[64]]>63?(this.#$[t]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#d[o],state:this.NOTE_HELD})):this.#e[p.cc*e+f[66]]>63&&this.#$[t]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#$[t]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#d[o],state:this.NOTE_SOSTENUTO_HELD})):(this.#f[t]=0,this.#d[o]=0,this.#$[t]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:n,velo:0,state:this.NOTE_IDLE})))},nOn:(e,n,o)=>{let t=e*128+n,i=0;for(this.#S[e]&&this.#u.ano(e);this.#$[i]>0&&this.#f[i]!=t;)i++;i{},cAt:(e,n)=>{},hoOf:e=>{this.#$.forEach((n,o)=>{if(n==this.NOTE_HELD){let t=this.#f[o],i=t>>7;e==i&&(this.#$[o]=this.NOTE_IDLE,this.#f[o]=0,this.#d[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#$.forEach((n,o)=>{let t;switch(n){case this.NOTE_ATTACK:{t=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{t=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{t=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(t){this.#$[o]=t;let i=this.#f[o];this.dispatchEvent("note",{part:e,note:i&127,velo:this.#d[i],state:t})}})},soOf:e=>{this.#$.forEach((n,o)=>{if(n==this.NOTE_SOSTENUTO_HELD){let t=this.#f[o],i=t>>7;e==i&&(this.#$[o]=this.NOTE_IDLE,this.#f[o]=0,this.#d[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#f.forEach((n,o,t)=>{let i=n>>7,r=n&127;n==0&&this.#d[0]==0||i==e&&this.#u.nOff(i,r)})}};#Z={8:function(e){let n=e.channel,o=e.data[0];this.#u.nOff(n,o)},9:function(e){let n=e.channel;this.#c[n]=1;let o=e.data[0],t=e.data[1];t>0?this.#u.nOn(n,o,t):this.#u.nOff(n,o)},10:function(e){let n=e.channel,o=n*128+e.data[0];this.#f.indexOf(o)>-1&&(this.#d[o]=data[1],this.dispatchEvent("note",{part:n,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let n=e.channel;this.#c[n]=1;let o=n*p.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#u.ano(n),this.#D[n]=0;let t=n*p.cc;this.#e[t+f[1]]=0,this.#e[t+f[5]]=0,this.#e[t+f[64]]=0,this.#e[t+f[65]]=0,this.#e[t+f[66]]=0,this.#e[t+f[67]]=0,this.#e[t+f[11]]=127,this.#e[t+f[101]]=127,this.#e[t+f[100]]=127,this.#e[t+f[99]]=127,this.#e[t+f[98]]=127;return}case 123:{this.#u.ano(n);return}case 124:{this.#u.ano(n);return}case 125:{this.#u.ano(n);return}case 126:{this.#S[n]=1,this.#u.ano(n);return}case 127:{this.#S[n]=0,this.#u.ano(n);return}}if(f[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(De.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{if(E()&&console.debug(`${x[this.#t]}, CH${n+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#i[n]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${n+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg");else if(this.#t==y.gs)e.data[1]<56&&this.#i[n]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${n+1} to stay drums.`));else if(this.#t==y.gm)e.data[1]<48?this.#i[n]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${n+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0);else if(this.#t==y.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let t=0;for(let i=0;i<16;i++){let r=this.#e[p.cc*i];(r==56||r==62)&&t++}t>14&&this.switchMode("ag10",!0)}}switch(this.#t){case y.xg:{[126,127].indexOf(e.data[1])>-1?this.#i[n]==0&&(this.setChType(n,this.CH_DRUM2),console.debug(`CH${n+1} set to drums by MSB.`)):this.#i[n]>0&&(this.setChType(n,this.CH_MELODIC),console.debug(`CH${n+1} set to melodic by MSB.`));break}case y["05rw"]:case y.x5d:case y.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#i[n]==0&&(this.setChType(n,this.CH_DRUM2),console.debug(`CH${n+1} set to drums by MSB.`)):this.#i[n]>0&&(this.setChType(n,this.CH_MELODIC),console.debug(`CH${n+1} set to melodic by MSB.`));break}case y.g2:{e.data[1]==120?this.#i[n]==0&&(this.setChType(n,this.CH_DRUM2),console.debug(`CH${n+1} set to drums by MSB.`)):this.#i[n]>0&&(this.setChType(n,this.CH_MELODIC),console.debug(`CH${n+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:n});break}case 6:{if(this.#B){[y.xg,y.gs,y.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${x[this.#t]}" mode, even when they are supported in Octavia.`);let t=this.#e[o+f[99]],i=this.#e[o+f[98]];if(t==1){let r=Ie.indexOf(i);if(r>-1)this.#e[o+f[71+r]]=e.data[1],E()&&console.debug(`Redirected NRPN 1 ${i} to cc${71+r}.`),this.dispatchEvent("cc",{part:n,cc:71+r,data:e.data[1]});else{let s=le.indexOf(i);s>-1?this.#_[n*10+s]=e.data[1]-64:console.warn(`NRPN 0x01${i.toString(16).padStart(2,"0")} is not supported.`),E()&&console.debug(`CH${n+1} voice NRPN ${i} commit`)}}else{if(fe.indexOf(t)<0){let s=`NRPN 0x${t.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")} `;t==127?console.warn(`${s}is not necessary. Consider removing it.`):console.warn(`${s}is not supported.`)}else this.#i[n]-2<0&&console.warn(`CH${n+1} cannot accept drum NRPN as type ${R[this.#i[n]]}.`);E()&&console.debug(`CH${n+1} (${R[this.#i[n]]}) drum NRPN ${t} commit`)}}else{let t=_[this.#e[o+f[100]]];this.#e[o+f[101]]==0&&t!=null&&(E()&&console.debug(`CH${n+1} RPN 0 ${this.#e[o+f[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],ce[t][0]),ce[t][1]),this.#r[n*p.rpn+t]=e.data[1])}break}case 32:{this.dispatchEvent("voice",{part:n});break}case 38:{this.#B||this.#e[o+101]==0&&_[this.#e[o+100]]!=null&&(this.#r[n*p.rpn+_[this.#e[o+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#u.hoOf(n);break}case 66:{e.data[1]>>6?this.#u.soOn(n):this.#u.soOf(n);break}case 98:case 99:{this.#B=1;break}case 100:case 101:{this.#B=0;break}}this.#e[o+f[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:n,cc:e.data[0],data:e.data[1]})}},12:function(e){let n=e.channel;this.#c[n]=1,this.#s[n]=e.data,this.#T[n]=0,E()&&console.debug(`T:${e.track} C:${n} P:${e.data}`),this.dispatchEvent("voice",{part:n})},13:function(e){let n=this,o=e.channel;this.#f.forEach(function(t){let i=t>>7;o==i&&(n.#d[t]=e.data,n.dispatchEvent("note",{part:o,note:t&127,velo:e.data,state:n.NOTE_SUSTAIN}))})},14:function(e){let n=e.channel;this.#D[n]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:n,pitch:this.getPitchShift(n)})},15:function(e){Ae(e.data).forEach(n=>{let o=n[0],t=n[1];(this.#ee[o]||function(){console.debug(`Unknown manufacturer ${o}.`)})(t,n.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#y[e.meta]||function(o,t,i){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#C=0);let n=Pe.indexOf(e.meta)>-1;if(E()&&console.debug(e),n)return e.reply="meta",e}};#ee={64:(e,n,o)=>{this.#W.run(n,o,e)},65:(e,n,o)=>{if(n[0]<16)this.#P.run(n,o,e),console.warn("Unknown device SysEx!");else{let t=n[n.length-1],i=se(n.subarray(2,n.length-1));t==i?this.#P.run(n.subarray(0,n.length-1),o,e):console.warn(`Bad GS checksum ${t}. Should be ${i}.`)}},66:(e,n,o)=>{this.#H.run(n,o,e)},67:(e,n,o)=>{this.#O.run(n,o,e)},68:(e,n,o)=>{this.#j.run(n,o,e)},71:(e,n,o)=>{this.#q.run(n,o,e)},126:(e,n,o)=>{this.#z.run(n,o,e)},127:(e,n,o)=>{this.switchMode("gm"),this.#Q.run(n,o,e)}};#z;#Q;#O;#P;#H;#W;#q;#j;buildRchTree(){let e=[];this.#l.forEach((n,o)=>{e[n]?.constructor||(e[n]=[]),e[n].push(o)}),this.#Y=e}getActive(){let e=this.#c.slice();return this.#t==y.mt32,e}getCc(e){let n=e*p.cc,o=this.#e.subarray(n,n+p.cc);return o[f[0]]=o[f[0]]||this.#U,o[f[32]]=o[f[32]]||this.#E,o}getCcCh(e,n){if(D.indexOf(n)<0)throw new Error("CC number not accepted");return this.#e[p.cc*e+f[n]]}getCcAll(){let e=this.#e.slice();for(let n=0;n0&&(this.#e[e*p.cc+f[0]]=T[o])}getPitch(){return this.#D}getProgram(){return this.#s}getTexts(){return this.#a.slice()}getVel(e){let n=new Map,o=this;return o.#f.forEach(function(t,i){let r=Math.floor(t/128),s=t%128;e==r&&o.#d[t]>0&&n.set(s,{v:o.#d[t],s:o.#$[i]})}),n}getBitmap(){return{bitmap:this.#g,expire:this.#h}}getLetter(){return{text:this.#M,expire:this.#N}}getMode(){return x[this.#t]}getMaster(){return{volume:this.#v}}getRawStrength(){let e=this;return this.#f.forEach(function(n){let o=Math.floor(n/128);e.#d[n]>e.#x[o]&&(e.#x[o]=e.#d[n])}),this.#x}getStrength(){let e=[],n=this;return this.getRawStrength().forEach(function(o,t){e[t]=Math.floor(o*n.#e[t*p.cc+f[7]]*Math.max(n.#e[t*p.cc+f[11]],Math.floor(n.#e[t*p.cc+f[91]]*.5),Math.floor(n.#e[t*p.cc+f[92]]*.65),Math.floor(n.#e[t*p.cc+f[94]]*.8))*n.#v/803288)}),e}getRpn(){return this.#r}getNrpn(){return this.#_}getVoice(e,n,o,t){let i=e||this.#U,r=n,s=o||this.#E;x[this.#t]=="ns5r"&&i>0&&i<56&&(s=3);let a=this.userBank.get(i,r,s,t);if(x[this.#t]=="mt32"&&a.name.indexOf("MT-m:")==0){let c=parseInt(a.name.slice(5)),h=c*p.cmt,l="";this.#A.subarray(h,h+10).forEach(d=>{d>31&&(l+=String.fromCharCode(d))}),this.userBank.load(`MSB LSB PRG -0 127 ${r} ${l}`,!0),a.name=l,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(i,r,s,t)),a}getChVoice(e){let n=this.getVoice(this.#e[e*p.cc+f[0]],this.#s[e],this.#e[e*p.cc+f[32]],x[this.#t]);if(this.#T[e])switch(this.#t){case y.mt32:n.ending="~",n.name="",this.#w.subarray(14*(e-1),14*(e-1)+10).forEach(o=>{o>31&&(n.name+=String.fromCharCode(o))})}return n}getPitchShift(e){let n=e*p.rpn;return this.#D[e]/8192*this.#r[n]+(this.#r[n+3]-64)+((this.#r[n+1]<<7)+this.#r[n+2]-8192)/8192}getEffectType(e=0){let n=3*e+1;return this.#m.subarray(n,n+2)}setEffectTypeRaw(e=0,n,o){let t=3*e;this.#m[t]=1,this.#m[t+1+ +n]=o}setEffectType(e=0,n,o){this.setEffectTypeRaw(e,!1,n),this.setEffectTypeRaw(e,!0,o)}setLetterDisplay(e,n,o=0,t=3200){let i=this,r;i.#M=" ".repeat(o),e.forEach(s=>{i.#M+=String.fromCharCode(s>31?s:32),s<32&&(r=r||new Set,r.add(s))}),i.#N=Date.now()+3200,i.#M=i.#M.padEnd(32," "),r&&(r=Array.from(r),r.forEach((s,a,c)=>{c[a]=s.toString(16).padStart(2,"0")}),console.warn(`${n}${n?" ":""}invalid code point${r.length>1?"s":""}: 0x${r.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let n=!0,o=0;for(;n&&o=p.ace&&console.warn("ACE slots are full.")}getAce(){return this.#b}getChAce(e,n){if(n<0||n>=p.ace)throw new RangeError("No such ACE slot");let o=this.#b[n];if(o){if(D.indexOf(o)>=0)return this.#e[e*p.cc+f[o]];throw new Error(`Invalid ACE source: ${o}`)}else return 0}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#U=0,this.#E=0,this.#C=0,this.#c.fill(0),this.#e.fill(0),this.#b.fill(0),this.#s.fill(0),this.#d.fill(0),this.#f.fill(0),this.#x.fill(0),this.#D.fill(0),this.#_.fill(0),this.#J.fill(0),this.#v=100,this.#a=[],this.#V=500,this.#X=0,this.#N=0,this.#M="",this.#h=0,this.#n=0,this.#g.fill(0),this.#o=!1,this.#K=0,this.#k=!0,this.#l.forEach(function(n,o,t){t[o]=o}),this.buildRchTree(),e==0&&(this.#R.fill(0),this.#L.fill(0)),this.#e[p.cc*9]=T[0],this.#e[p.cc*25]=T[0],this.#e[p.cc*41]=T[0],this.#e[p.cc*57]=T[0],this.#i.fill(this.CH_MELODIC),this.#i[9]=this.CH_DRUM1,this.#i[25]=this.CH_DRUM3,this.#i[41]=this.CH_DRUMS,this.#i[57]=this.CH_DRUMS,this.#i[73]=this.CH_DRUM5,this.#i[89]=this.CH_DRUM7,this.#i[105]=this.CH_DRUMS,this.#i[121]=this.CH_DRUMS,this.#F.fill(0),this.#A.fill(0),this.#I.fill(0),this.#w.fill(0),this.#T.fill(0),this.#m.fill(0),this.aiEfxName="",this.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let n=0;n-1){if(this.#t==0||n){let t=this.#t;this.#t=o,this.#n=0,this.#U=ne[0][o],this.#E=ne[1][o];for(let r=0;r0&&this.#e[r*p.cc+f[0]]==T[t]&&(this.#e[r*p.cc]=T[o]);switch(this.initOnReset,o){case y.mt32:{G.forEach((r,s)=>{let a=s+1;this.#c[a]||(this.#s[a]=r,this.#e[a*p.cc+f[91]]=127)});break}}let i;switch(o){case y.gs:{i=[40,4,40,18,40,32,32,0,0,0,0,0,0,0];break}case y.x5d:case y.ns5r:{i=[44,1,44,19,44,0,44,0,0,0,0,0,0,0];break}default:i=[1,0,65,0,5,0,0,0,0,0,0,0,0,0]}for(let r=0;r14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#Z[e.type].call(this,e);{let n=this.chRedir(e.part,e.track),o=!1;this.#Y[n]?.forEach(t=>{e.channel=t,o=!0,this.#Z[e.type].call(this,e)}),o||console.warn(`${oe[e.type]?oe[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${n+1} without any recipient.`)}this.#a.length>100&&this.#a.splice(100,this.#a.length-99)}runRaw(e){}constructor(){super();let e=this;this.#g=new Uint8Array(256),this.#p[10]=new Uint8Array(512),this.#G=new k,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let n=e.split(",");L[n[0]]=n[1]});var J=function(e){let n=e;e[0]=="*"&&(n=n.slice(1)),["aa","ii","uu","ee","oo"].forEach(t=>{for(;n.indexOf(t)>-1;)n=n.replace(t,t[0])});for(let t in L)n=n.replaceAll(t,L[t]);n.indexOf("ん")==0&&n.length>1&&(n=n.slice(1));let o=n.indexOf("!");return o>-1&&n.length>1&&(n=n.slice(o+1)),n},ee=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var H=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],te=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],ie=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var Re={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"},Oe={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]]},B=function(e){return Re[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},re=function(e,n,o){let t=(e[0]-32<<16)+(e[1]<<8)+n,i=Oe[t]||{},r=i[0];if(r?.length)return r+=`: ${(i[1]||function(){})(o)||o}`,r},G=[68,48,95,78,41,3,110,122,0];var w=function(e=64){return Math.round(2e3*Math.log10(e/64))/100},ae=function(e,n,o){let t=[],i=o==!1?n.readIntVLV():o;e==0||e==127;for(let r=0;r127)return console.debug(`Early termination: ${t}`),t.pop(),n.backOne(),n.backOne(),new Uint8Array(t)}}}return new Uint8Array(t)},se=function(e){let n=0;return e.forEach(o=>{n+=o,n=n&127}),~n+1&127},S=function(e,n){let o=0,t=0;for(let i=0;i>r&1)<<7,a=e[i];a+=s,i%8!=0?(n(a,o,e),o++):t=e[i]}},P=function(e){let n=Math.floor(e*14.2);return n<128?n:0};var x=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],ne=[[0,0,0,0,121,0,0,56,82,81,63,0,0],[0,0,4,0,0,127,0,0,0,0,0,0,0]],T=[120,127,120,127,120,127,61,62,62,62,120,122,122],Pe=[0,3,81,84,88],oe={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},_={0:0,1:1,2:3,5:4},ce=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],le=[36,37],fe=[20,21,22,23,24,25,26,28,29,30,31,36,37,64,65],D=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,12,13,16,17,18,19],De=[12,13,16,17,18,19],Ie=[33,99,100,32,102,8,9,10],he=[0,16,25,40,32,64,26,48],y={};x.forEach((e,n)=>{y[e]=n});var f={length:D.length};D.forEach((e,n)=>{f[e]=n});var E=function(){return!!self.Bun||self.debugMode||!1},Ae=function(e){let n=[],o=0;return e?.forEach(function(t,i){t==247?n.push(e.subarray(o,i)):t==240&&(o=i+1)}),n.length||n.push(e.subarray(0)),E()&&console.debug(n),n},de=function(e,n="",o="",t=2){return e?`${n}${e.toString().padStart(t,"0")}${o}`:""},p={ch:128,cc:D.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:fe.length,dnc:128,efx:7},ue=class extends I{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#n=0;#h=0;#p=new Array(11);get#g(){return this.#p[this.#n]}set#g(e){this.#p[this.#n]=e}#c=new Uint8Array(p.ch);#l=new Uint8Array(p.ch);#i=new Uint8Array(p.ch);#e=new Uint8Array(p.ch*p.cc);#b=new Uint8Array(p.ace);#s=new Uint8Array(p.ch);#d=new Uint8Array(p.ch*p.nn);#S=new Uint8Array(p.ch);#f=new Uint16Array(p.pl);#$=new Uint8Array(p.pl);#D=new Int16Array(p.ch);#x=new Uint8Array(p.ch);#B=0;#r=new Uint8Array(p.ch*p.rpn);#_=new Int8Array(p.ch*le.length);#Y=new Uint8Array(p.drm*p.dpn*p.dnc);#T=new Uint8Array(p.ch);#I=new Uint8Array(128);#w=new Uint8Array(p.cmt*8);#F=new Uint8Array(1024);#A=new Uint8Array(p.cmt*64);#m=new Uint8Array(p.efx*3);#U=0;#E=0;#v=100;#C=0;#V=500;#X=0;#M="";#N=0;#K=0;#k=!0;#o=!1;#Z;#te=new Uint8Array(2);#a=[];#R=new Uint8Array(p.ch);#L=new Uint8Array(p.tr);baseBank=new N("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new N("gm");initOnReset=!1;aiEfxName="";chRedir(e,n,o){if(this.#L[n])return(this.#L[n]-1)*16+e;if([2,3].indexOf(this.#E)>-1){if(o==1)return e;let t=0,i=!0;for(;i;)this.#R[e+t]==0?(this.#R[e+t]=n,console.debug(`Assign track ${n} to channel ${e+t+1}.`),i=!1):this.#R[e+t]==n?i=!1:(t+=16,t>=128&&(t=0,i=!1));return e+t}else return e}#y=[];#G;#u={nOff:(e,n)=>{let o=e*128+n,t=this.#f.lastIndexOf(o);t>-1&&(this.#e[p.cc*e+f[64]]>63?(this.#$[t]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#d[o],state:this.NOTE_HELD})):this.#e[p.cc*e+f[66]]>63&&this.#$[t]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#$[t]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#d[o],state:this.NOTE_SOSTENUTO_HELD})):(this.#f[t]=0,this.#d[o]=0,this.#$[t]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:n,velo:0,state:this.NOTE_IDLE})))},nOn:(e,n,o)=>{let t=e*128+n,i=0;for(this.#S[e]&&this.#u.ano(e);this.#$[i]>0&&this.#f[i]!=t;)i++;i{},cAt:(e,n)=>{},hoOf:e=>{this.#$.forEach((n,o)=>{if(n==this.NOTE_HELD){let t=this.#f[o],i=t>>7;e==i&&(this.#$[o]=this.NOTE_IDLE,this.#f[o]=0,this.#d[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#$.forEach((n,o)=>{let t;switch(n){case this.NOTE_ATTACK:{t=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{t=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{t=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(t){this.#$[o]=t;let i=this.#f[o];this.dispatchEvent("note",{part:e,note:i&127,velo:this.#d[i],state:t})}})},soOf:e=>{this.#$.forEach((n,o)=>{if(n==this.NOTE_SOSTENUTO_HELD){let t=this.#f[o],i=t>>7;e==i&&(this.#$[o]=this.NOTE_IDLE,this.#f[o]=0,this.#d[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#f.forEach((n,o,t)=>{let i=n>>7,r=n&127;n==0&&this.#d[0]==0||i==e&&this.#u.nOff(i,r)})}};#J={8:function(e){let n=e.channel,o=e.data[0];this.#u.nOff(n,o)},9:function(e){let n=e.channel;this.#c[n]=1;let o=e.data[0],t=e.data[1];t>0?this.#u.nOn(n,o,t):this.#u.nOff(n,o)},10:function(e){let n=e.channel,o=n*128+e.data[0];this.#f.indexOf(o)>-1&&(this.#d[o]=data[1],this.dispatchEvent("note",{part:n,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let n=e.channel;this.#c[n]=1;let o=n*p.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#u.ano(n),this.#D[n]=0;let t=n*p.cc;this.#e[t+f[1]]=0,this.#e[t+f[5]]=0,this.#e[t+f[64]]=0,this.#e[t+f[65]]=0,this.#e[t+f[66]]=0,this.#e[t+f[67]]=0,this.#e[t+f[11]]=127,this.#e[t+f[101]]=127,this.#e[t+f[100]]=127,this.#e[t+f[99]]=127,this.#e[t+f[98]]=127;return}case 123:{this.#u.ano(n);return}case 124:{this.#u.ano(n);return}case 125:{this.#u.ano(n);return}case 126:{this.#S[n]=1,this.#u.ano(n);return}case 127:{this.#S[n]=0,this.#u.ano(n);return}}if(f[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(De.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{if(E()&&console.debug(`${x[this.#t]}, CH${n+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#i[n]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${n+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg");else if(this.#t==y.gs)e.data[1]<56&&this.#i[n]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${n+1} to stay drums.`));else if(this.#t==y.gm)e.data[1]<48?this.#i[n]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${n+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0);else if(this.#t==y.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let t=0;for(let i=0;i<16;i++){let r=this.#e[p.cc*i];(r==56||r==62)&&t++}t>14&&this.switchMode("ag10",!0)}}switch(this.#t){case y.xg:{[126,127].indexOf(e.data[1])>-1?this.#i[n]==0&&(this.setChType(n,this.CH_DRUM2),console.debug(`CH${n+1} set to drums by MSB.`)):this.#i[n]>0&&(this.setChType(n,this.CH_MELODIC),console.debug(`CH${n+1} set to melodic by MSB.`));break}case y["05rw"]:case y.x5d:case y.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#i[n]==0&&(this.setChType(n,this.CH_DRUM2),console.debug(`CH${n+1} set to drums by MSB.`)):this.#i[n]>0&&(this.setChType(n,this.CH_MELODIC),console.debug(`CH${n+1} set to melodic by MSB.`));break}case y.g2:{e.data[1]==120?this.#i[n]==0&&(this.setChType(n,this.CH_DRUMS),console.debug(`CH${n+1} set to drums by MSB.`)):this.#i[n]>0&&(this.setChType(n,this.CH_MELODIC),console.debug(`CH${n+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:n});break}case 6:{if(this.#B){[y.xg,y.gs,y.ns5r].indexOf(this.#t)<0&&console.warn(`NRPN commits are not available under "${x[this.#t]}" mode, even when they are supported in Octavia.`);let t=this.#e[o+f[99]],i=this.#e[o+f[98]];if(t==1){let r=Ie.indexOf(i);if(r>-1)this.#e[o+f[71+r]]=e.data[1],E()&&console.debug(`Redirected NRPN 1 ${i} to cc${71+r}.`),this.dispatchEvent("cc",{part:n,cc:71+r,data:e.data[1]});else{let s=le.indexOf(i);s>-1?this.#_[n*10+s]=e.data[1]-64:console.warn(`NRPN 0x01${i.toString(16).padStart(2,"0")} is not supported.`),E()&&console.debug(`CH${n+1} voice NRPN ${i} commit`)}}else{if(fe.indexOf(t)<0){let s=`NRPN 0x${t.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")} `;t==127?console.warn(`${s}is not necessary. Consider removing it.`):console.warn(`${s}is not supported.`)}else{let s=this.#i[n]-2;s<0?console.warn(`CH${n+1} cannot accept drum NRPN as type ${R[this.#i[n]]}.`):this.#Y[(s*p.dpn+t)*p.dnc+i]=e.data[1]-64}E()&&console.debug(`CH${n+1} (${R[this.#i[n]]}) drum NRPN ${t} commit`)}}else{let t=_[this.#e[o+f[100]]];this.#e[o+f[101]]==0&&t!=null&&(E()&&console.debug(`CH${n+1} RPN 0 ${this.#e[o+f[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],ce[t][0]),ce[t][1]),this.#r[n*p.rpn+t]=e.data[1])}break}case 32:{this.dispatchEvent("voice",{part:n});break}case 38:{this.#B||this.#e[o+101]==0&&_[this.#e[o+100]]!=null&&(this.#r[n*p.rpn+_[this.#e[o+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#u.hoOf(n);break}case 66:{e.data[1]>>6?this.#u.soOn(n):this.#u.soOf(n);break}case 98:case 99:{this.#B=1;break}case 100:case 101:{this.#B=0;break}}this.#e[o+f[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:n,cc:e.data[0],data:e.data[1]})}},12:function(e){let n=e.channel;this.#c[n]=1,this.#s[n]=e.data,this.#T[n]=0,E()&&console.debug(`T:${e.track} C:${n} P:${e.data}`),this.dispatchEvent("voice",{part:n})},13:function(e){let n=this,o=e.channel;this.#f.forEach(function(t){let i=t>>7;o==i&&(n.#d[t]=e.data,n.dispatchEvent("note",{part:o,note:t&127,velo:e.data,state:n.NOTE_SUSTAIN}))})},14:function(e){let n=e.channel;this.#D[n]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:n,pitch:this.getPitchShift(n)})},15:function(e){Ae(e.data).forEach(n=>{let o=n[0],t=n[1];(this.#ee[o]||function(){console.debug(`Unknown manufacturer ${o}.`)})(t,n.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#y[e.meta]||function(o,t,i){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#C=0);let n=Pe.indexOf(e.meta)>-1;if(E()&&console.debug(e),n)return e.reply="meta",e}};#ee={64:(e,n,o)=>{this.#W.run(n,o,e)},65:(e,n,o)=>{if(n[0]<16)this.#P.run(n,o,e),console.warn("Unknown device SysEx!");else{let t=n[n.length-1],i=se(n.subarray(2,n.length-1));t==i?this.#P.run(n.subarray(0,n.length-1),o,e):console.warn(`Bad GS checksum ${t}. Should be ${i}.`)}},66:(e,n,o)=>{this.#H.run(n,o,e)},67:(e,n,o)=>{this.#O.run(n,o,e)},68:(e,n,o)=>{this.#j.run(n,o,e)},71:(e,n,o)=>{this.#q.run(n,o,e)},126:(e,n,o)=>{this.#z.run(n,o,e)},127:(e,n,o)=>{this.switchMode("gm"),this.#Q.run(n,o,e)}};#z;#Q;#O;#P;#H;#W;#q;#j;buildRchTree(){let e=[];this.#l.forEach((n,o)=>{e[n]?.constructor||(e[n]=[]),e[n].push(o)}),this.#Z=e}getActive(){let e=this.#c.slice();return this.#t==y.mt32,e}getCc(e){let n=e*p.cc,o=this.#e.subarray(n,n+p.cc);return o[f[0]]=o[f[0]]||this.#U,o[f[32]]=o[f[32]]||this.#E,o}getCcCh(e,n){if(D.indexOf(n)<0)throw new Error("CC number not accepted");return this.#e[p.cc*e+f[n]]}getCcAll(){let e=this.#e.slice();for(let n=0;n0&&(this.#e[e*p.cc+f[0]]=T[o])}getPitch(){return this.#D}getProgram(){return this.#s}getTexts(){return this.#a.slice()}getVel(e){let n=new Map,o=this;return o.#f.forEach(function(t,i){let r=Math.floor(t/128),s=t%128;e==r&&o.#d[t]>0&&n.set(s,{v:o.#d[t],s:o.#$[i]})}),n}getBitmap(){return{bitmap:this.#g,expire:this.#h}}getLetter(){return{text:this.#M,expire:this.#N}}getMode(){return x[this.#t]}getMaster(){return{volume:this.#v}}getRawStrength(){let e=this;return this.#f.forEach(function(n){let o=Math.floor(n/128);e.#d[n]>e.#x[o]&&(e.#x[o]=e.#d[n])}),this.#x}getStrength(){let e=[],n=this;return this.getRawStrength().forEach(function(o,t){e[t]=Math.floor(o*n.#e[t*p.cc+f[7]]*Math.max(n.#e[t*p.cc+f[11]],Math.floor(n.#e[t*p.cc+f[91]]*.5),Math.floor(n.#e[t*p.cc+f[92]]*.65),Math.floor(n.#e[t*p.cc+f[94]]*.8))*n.#v/803288)}),e}getRpn(){return this.#r}getNrpn(){return this.#_}getVoice(e,n,o,t){let i=e||this.#U,r=n,s=o||this.#E;x[this.#t]=="ns5r"&&i>0&&i<56&&(s=3);let a=this.userBank.get(i,r,s,t);if(x[this.#t]=="mt32"&&a.name.indexOf("MT-m:")==0){let c=parseInt(a.name.slice(5)),h=c*p.cmt,l="";this.#A.subarray(h,h+10).forEach(d=>{d>31&&(l+=String.fromCharCode(d))}),this.userBank.load(`MSB LSB PRG +0 127 ${r} ${l}`,!0),a.name=l,a.ending=" "}return(a.ending!=" "||!a.name.length)&&(a=this.baseBank.get(i,r,s,t)),a}getChVoice(e){let n=this.getVoice(this.#e[e*p.cc+f[0]],this.#s[e],this.#e[e*p.cc+f[32]],x[this.#t]);if(this.#T[e])switch(this.#t){case y.mt32:n.ending="~",n.name="",this.#w.subarray(14*(e-1),14*(e-1)+10).forEach(o=>{o>31&&(n.name+=String.fromCharCode(o))})}return n}getPitchShift(e){let n=e*p.rpn;return this.#D[e]/8192*this.#r[n]+(this.#r[n+3]-64)+((this.#r[n+1]<<7)+this.#r[n+2]-8192)/8192}getEffectType(e=0){let n=3*e+1;return this.#m.subarray(n,n+2)}setEffectTypeRaw(e=0,n,o){let t=3*e;this.#m[t]=1,this.#m[t+1+ +n]=o}setEffectType(e=0,n,o){this.setEffectTypeRaw(e,!1,n),this.setEffectTypeRaw(e,!0,o)}setLetterDisplay(e,n,o=0,t=3200){let i=this,r;i.#M=" ".repeat(o),e.forEach(s=>{i.#M+=String.fromCharCode(s>31?s:32),s<32&&(r=r||new Set,r.add(s))}),i.#N=Date.now()+3200,i.#M=i.#M.padEnd(32," "),r&&(r=Array.from(r),r.forEach((s,a,c)=>{c[a]=s.toString(16).padStart(2,"0")}),console.warn(`${n}${n?" ":""}invalid code point${r.length>1?"s":""}: 0x${r.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let n=!0,o=0;for(;n&&o=p.ace&&console.warn("ACE slots are full.")}getAce(){return this.#b}getChAce(e,n){if(n<0||n>=p.ace)throw new RangeError("No such ACE slot");let o=this.#b[n];if(o){if(D.indexOf(o)>=0)return this.#e[e*p.cc+f[o]];throw new Error(`Invalid ACE source: ${o}`)}else return 0}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#U=0,this.#E=0,this.#C=0,this.#c.fill(0),this.#e.fill(0),this.#b.fill(0),this.#s.fill(0),this.#d.fill(0),this.#f.fill(0),this.#x.fill(0),this.#D.fill(0),this.#_.fill(0),this.#Y.fill(0),this.#v=100,this.#a=[],this.#V=500,this.#X=0,this.#N=0,this.#M="",this.#h=0,this.#n=0,this.#g.fill(0),this.#o=!1,this.#K=0,this.#k=!0,this.#l.forEach(function(n,o,t){t[o]=o}),this.buildRchTree(),e==0&&(this.#R.fill(0),this.#L.fill(0)),this.#e[p.cc*9]=T[0],this.#e[p.cc*25]=T[0],this.#e[p.cc*41]=T[0],this.#e[p.cc*57]=T[0],this.#i.fill(this.CH_MELODIC),this.#i[9]=this.CH_DRUM1,this.#i[25]=this.CH_DRUM3,this.#i[41]=this.CH_DRUMS,this.#i[57]=this.CH_DRUMS,this.#i[73]=this.CH_DRUM5,this.#i[89]=this.CH_DRUM7,this.#i[105]=this.CH_DRUMS,this.#i[121]=this.CH_DRUMS,this.#F.fill(0),this.#A.fill(0),this.#I.fill(0),this.#w.fill(0),this.#T.fill(0),this.#m.fill(0),this.aiEfxName="",this.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let n=0;n-1){if(this.#t==0||n){let t=this.#t;this.#t=o,this.#n=0,this.#U=ne[0][o],this.#E=ne[1][o];for(let r=0;r0&&this.#e[r*p.cc+f[0]]==T[t]&&(this.#e[r*p.cc]=T[o]);switch(this.initOnReset,o){case y.mt32:{G.forEach((r,s)=>{let a=s+1;this.#c[a]||(this.#s[a]=r,this.#e[a*p.cc+f[91]]=127)});break}}let i;switch(o){case y.gs:{i=[40,4,40,18,40,32,32,0,0,0,0,0,0,0];break}case y.x5d:case y.ns5r:{i=[44,1,44,19,44,0,44,0,0,0,0,0,0,0];break}default:i=[1,0,65,0,5,0,0,0,0,0,0,0,0,0]}for(let r=0;r14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#J[e.type].call(this,e);{let n=this.chRedir(e.part,e.track),o=!1;this.#Z[n]?.forEach(t=>{e.channel=t,o=!0,this.#J[e.type].call(this,e)}),o||console.warn(`${oe[e.type]?oe[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${n+1} without any recipient.`)}this.#a.length>100&&this.#a.splice(100,this.#a.length-99)}runRaw(e){}constructor(){super();let e=this;this.#g=new Uint8Array(256),this.#p[10]=new Uint8Array(512),this.#G=new k,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -145,7 +145,7 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),this.#y[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#o=!0,this.#a.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#o=!0,this.#a.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#o=!0,this.#a.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#o=!0,this.#a.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#o=!0,this.#a.unshift(`Kara.Ver: ${t.slice(2)}`);break}case"XF":{let i=t.slice(2).split(":");switch(i[0]){case"hd":{i.slice(1).forEach((r,s)=>{r.length&&this.#a.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][s]}: ${r}`)});break}case"ln":{i.slice(1).forEach((r,s)=>{r.length&&this.#a.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][s]}: ${r}`)});break}default:this.#a.unshift(`XGF_Data: ${t}`)}break}default:this.#o?t[0]=="\\"?this.#a.unshift(`@ ${t.slice(1)}`):t[0]=="/"?this.#a.unshift(t.slice(1)):this.#a[0]+=t:(this.#a[0]=t,this.#a.unshift(""))}},this.#y[2]=function(t){this.#a.unshift(`Copyrite: ${t}`)},this.#y[3]=function(t,i){i<1&&this.#C<1&&this.#a.unshift(`TrkTitle: ${t}`)},this.#y[4]=function(t,i){this.#a.unshift(`${de(this.#C,""," ")}Instrmnt: ${t}`)},this.#y[5]=function(t){t.trim()==""?this.#a.unshift(""):this.#a[0]+=`${t}`},this.#y[6]=function(t){this.#a.unshift(`${de(this.#C,""," ")}C.Marker: ${t}`)},this.#y[7]=function(t){this.#a.unshift(`CuePoint: ${t}`)},this.#y[32]=function(t){this.#C=t[0]+1},this.#y[33]=function(t,i){console.debug(`Track ${i} requests to get assigned to output ${t}.`),e.#L[i]=t+1},this.#y[81]=function(t,i){e.#V=t/1e3},this.#y[127]=function(t,i){e.#G.run(t,i)},this.#G.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#G.add([67,0,1],function(t,i){e.#L[i]=t[0]+1}),this.#z=new k,this.#Q=new k,this.#O=new k,this.#P=new k,this.#H=new k,this.#W=new k,this.#q=new k,this.#j=new k,this.#z.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#o=e.#o||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#Q.add([4,1],t=>{e.#v=((t[1]<<7)+t[0])/16383*100}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#O.add([76,0,0],t=>{switch(t[0]){case 126:{e.switchMode("xg",!0),e.#o=!1,console.info("MIDI reset: XG");break}default:{let i=[0,0,0,0],r=(s,a)=>{i[a]=s};if(t.subarray(1).forEach((s,a)=>{let c=a+t[0];([r,r,r,r,h=>{this.#v=h*129/16383*100},h=>{},h=>{}][c]||(()=>{}))(s,a)}),t[0]<4){let s=0;i.forEach(a=>{s=s<<4,s+=a}),s-=1024}}}}).add([76,2,1],t=>{let i="XG ";t[0]<32?(i+="reverb ",t.subarray(1).forEach((r,s)=>{([a=>{e.setEffectTypeRaw(0,!1,a),console.info(`${i}main type: ${C[a]}`)},a=>{e.setEffectTypeRaw(0,!0,a),console.debug(`${i}sub type: ${a+1}`)},a=>{console.debug(`${i}time: ${j(a)}s`)},a=>{console.debug(`${i}diffusion: ${a}`)},a=>{console.debug(`${i}initial delay: ${a}`)},a=>{console.debug(`${i}HPF cutoff: ${O[a]}Hz`)},a=>{console.debug(`${i}LPF cutoff: ${O[a]}Hz`)},a=>{console.debug(`${i}width: ${a}`)},a=>{console.debug(`${i}height: ${a}`)},a=>{console.debug(`${i}depth: ${a}`)},a=>{console.debug(`${i}wall type: ${a}`)},a=>{console.debug(`${i}dry/wet: ${a}`)},a=>{console.debug(`${i}send: ${w(a)}dB`)},a=>{console.debug(`${i}pan: ${a-64}`)},!1,!1,a=>{console.debug(`${i}delay: ${a}`)},a=>{console.debug(`${i}density: ${a}`)},a=>{console.debug(`${i}balance: ${a}`)},a=>{},a=>{console.debug(`${i}feedback: ${a}`)},a=>{}][t[0]+s]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(r)})):t[0]<64?(i+="chorus ",t.subarray(1).forEach((r,s)=>{([a=>{e.setEffectTypeRaw(1,!1,a),console.info(`${i}main type: ${C[a]}`)},a=>{e.setEffectTypeRaw(1,!0,a),console.debug(`${i}sub type: ${a+1}`)},a=>{console.debug(`${i}LFO: ${q[a]}Hz`)},a=>{},a=>{console.debug(`${i}feedback: ${a}`)},a=>{console.debug(`${i}delay offset: ${Y(a)}ms`)},a=>{},a=>{console.debug(`${i}low: ${O[a]}Hz`)},a=>{console.debug(`${i}low: ${a-64}dB`)},a=>{console.debug(`${i}high: ${O[a]}Hz`)},a=>{console.debug(`${i}high: ${a-64}dB`)},a=>{console.debug(`${i}dry/wet: ${a}`)},a=>{console.debug(`${i}send: ${w(a)}dB`)},a=>{console.debug(`${i}pan: ${a-64}`)},a=>{console.debug(`${i}to reverb: ${w(a)}dB`)},!1,a=>{},a=>{},a=>{},a=>{console.debug(`${i}LFO phase diff: ${(a-64)*3}deg`)},a=>{console.debug(`${i}input mode: ${a?"stereo":"mono"}`)},a=>{}][t[0]-32+s]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(r)})):t[0]<86?(i+="variation ",t.subarray(1).forEach((r,s)=>{([a=>{e.setEffectTypeRaw(2,!1,a),console.info(`${i}main type: ${C[a]}`)},a=>{e.setEffectTypeRaw(2,!0,a),console.debug(`${i}sub type: ${a+1}`)}][t[0]-64+s]||function(){})(r)})):t[0]<97?(i+="variation ",t.subarray(1).forEach((r,s)=>{[a=>{console.debug(`${i}send: ${w(a)}dB`)},a=>{console.debug(`${i}pan: ${a-64}`)},a=>{console.debug(`${i}to reverb: ${w(a)}dB`)},a=>{console.debug(`${i}to chorus: ${w(a)}dB`)},a=>{console.debug(`${i}connection: ${a?"system":"insertion"}`)},a=>{console.debug(`${i}channel: CH${a+1}`)},a=>{console.debug(`${i}mod wheel: ${a-64}`)},a=>{console.debug(`${i}bend wheel: ${a-64}`)},a=>{console.debug(`${i}channel after touch: ${a-64}`)},a=>{console.debug(`${i}AC1: ${a-64}`)},a=>{console.debug(`${i}AC2: ${a-64}`)}][t[0]-86+s](r)})):t[0]>111&&t[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${t[0]}`)}).add([76,2,64],t=>{t.subarray(1).forEach((i,r)=>{let s=r+t[0];if(s==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let a=s-1>>2,c=s-1&3,h=`XG EQ ${a} ${["gain","freq","Q","shape"][c]}: `;[()=>{console.debug(`${h}${i-64}dB`)},()=>{console.debug(`${h}${i} (raw)`)},()=>{console.debug(`${h}${i/10}`)},()=>{console.debug(`${h}${["shelf","peak"][+!!i]}`)}][c]()}})}).add([76,3],t=>{let i=t[0],r=t[1],s=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((a,c)=>{([h=>{e.setEffectTypeRaw(3+i,!1,h),console.info(`${s}main type: ${C[h]}`)},h=>{e.setEffectTypeRaw(3+i,!0,h),console.debug(`${s}sub type: ${h+1}`)}][r+c]||function(){})(a)})}).add([76,6,0],t=>{let i=t[0];i<64?e.setLetterDisplay(t.subarray(1),"XG letter display",i):e.#N=Date.now()}).add([76,7,0],t=>{let i=t[0];e.#n=0,e.#h=Date.now()+3200,e.#g.fill(0);let r=t.subarray(1);for(let s=0;s>6-u&1,u++})}).add([76,8],(t,i)=>{let r=e.chRedir(t[0],i,!0),s=t[1],a=p.cc*r,c=`XG CH${r+1} `,h=`Unknown XG part address ${s}.`;t.subarray(2).forEach((l,d)=>{s<1?console.debug(h):s<41?([()=>{e.#e[a+f[0]]=l},()=>{e.#e[a+f[32]]=l},()=>{e.#s[r]=l},()=>{let u=e.chRedir(l,i,!0);e.#l[r]=u,r!=u&&(e.buildRchTree(),console.info(`${c}receives from CH${u+1}`))},()=>{e.#S[r]=+!l},()=>{},()=>{e.setChType(r,l,y.xg),console.debug(`${c}type: ${R[l]||l}`)},()=>{e.#r[p.rpn*r+3]=l},!1,!1,()=>{e.#e[a+f[7]]=l},!1,!1,()=>{e.#e[a+f[10]]=l||128},!1,!1,()=>{e.#e[a+f[11]]=l},()=>{e.#e[a+f[93]]=l},()=>{e.#e[a+f[91]]=l},()=>{e.#e[a+f[94]]=l},()=>{e.#e[a+f[76]]=l},()=>{e.#e[a+f[77]]=l},()=>{e.#e[a+f[78]]=l},()=>{e.#e[a+f[74]]=l},()=>{e.#e[a+f[71]]=l},()=>{e.#e[a+f[73]]=l},()=>{e.#e[a+f[75]]=l},()=>{e.#e[a+f[72]]=l}][s+d-1]||(()=>{}))():s<48?console.debug(h):s<111?s>102&&s<105&&(e.#e[a+f[[5,65][s&1]]]=l):s<114?console.debug(h):s<116?console.debug(`${c}EQ ${["bass","treble"][s&1]} gain: ${l-64}dB`):s<118?console.debug(h):s<120?console.debug(`${c}EQ ${["bass","treble"][s&1]} freq: ${l}`):console.debug(h)})}).add([76,9],(t,i)=>{let r=e.chRedir(t[0],i,!0),s=t[1],a=`PLG-150VL CH${r+1} `;t.subarray(2).forEach((c,h)=>{let l=h+s;switch(l){case 1:{console.info(`${a}breath mode: ${["system","breath","velocity","touch EG"][c]}`);break}case 0:case 27:case 28:break;default:if(l<27){let d=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${a}${d} control source: ${ee(c)}`),c&&c<96&&e.allocateAce(c)):console.debug(`${a}${d} scale break point: ${c}`):console.debug(`${a}${d} depth: ${c-64}`)}}})}).add([76,10],t=>{}).add([76,16],t=>{}).add([76,17,0,0],t=>{}).add([76,112],t=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][t[0]]} for CH${t[2]+1}.`)}).add([73,0,0],(t,i)=>{let r=t[0];t.subarray(1).forEach((s,a)=>{let c=r+a;c==8?console.debug(`MU1000 set LCD contrast to ${s}.`):c>9&&c<16&&[()=>{e.dispatchEvent("channelactive",s)},()=>{s<8?(e.dispatchEvent("channelmin",s<<4),console.info(`Octavia System: Minimum CH${(s<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{s<8?(e.dispatchEvent("channelmax",(s<<4)+15),console.info(`Octavia System: Maximum CH${(s<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#k=!!s,console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][c-10]()})}).add([73,10,0],(t,i)=>{let r=t[0],s=`MU1000 RS${e.#k?"":" (ignored)"}: `;if(r<16)switch(r){case 2:{let a=e.chRedir(0,i,!0);e.#k&&(e.dispatchEvent("channelmin",a),e.dispatchEvent("channelmax",a+63)),console.info(`${s}Show CH1~64`);break}case 3:{let a=e.chRedir(t[1]<<5,i,!0);e.#k&&e.dispatchEvent("channelmin",a),e.#k&&e.dispatchEvent("channelmax",a+31),console.info(`${s}Show CH${a+1}~CH${a+32}`);break}default:console.debug(`${s}unknown switch ${r} invoked.`)}else if(r<32){if(e.#k){let a=e.chRedir(r-16+(e.#K<<4),i,!0);e.dispatchEvent("channelactive",a)}}else if(r<36){let a=e.chRedir(r-32<<4,i,!0);e.#k&&(e.dispatchEvent("channelmin",a),e.dispatchEvent("channelmax",a+15),e.#K=r-32),console.info(`${s}Show CH${a+1}~CH${a+16}`)}}).add([93,3],(t,i)=>{let r=e.chRedir(t[0],i,!0),s=`PLG-100SG CH${r+1} `,a=Date.now();if(t[1]==0){let c="",h=0;t.subarray(2).forEach((l,d)=>{d%2==0?c+=Z[l]||l.toString().padStart("0"):h+=l*13}),a>=e.#X&&e.#a.unshift("SG Lyric: "),e.#a[0]+=`${J(c)}`,e.#X=a+Math.ceil(h/2)+e.#V,E()&&console.debug(`${s}vocals: ${c}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}),this.#O.add([76,48],t=>{}).add([76,49],t=>{}).add([76,50],t=>{}).add([76,51],t=>{}),this.#O.add([89,0],(t,i,r)=>{if(e.eprom){let s=t[0],a=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);E()&&console.debug(`MU1000 EPROM trail to 0x${a.toString(16).padStart(6,"0")}, ${s} bytes.`);let c=e.eprom.data;t.subarray(4).forEach((h,l)=>{let d=l>>3,u=l&7;if(u==7)for(let g=0;g<7;g++)c[a+7*d+g]+=(h>>6-g&1)<<7;else c[a+7*d+u]=h})}}).add([89,1],(t,i,r)=>{let s=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];E()&&console.debug(`MU1000 EPROM jump to 0x${s.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=s)}).add([89,2],(t,i,r)=>{if(e.eprom){let s=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);E()&&console.debug(`MU1000 EPROM write to 0x${s.toString(16).padStart(6,"0")}.`);let a=e.eprom.data;t.subarray(4).forEach((c,h)=>{let l=h>>3,d=h&7;if(d==7)for(let u=0;u<7;u++)a[s+7*l+u]+=(c>>6-u&1)<<7;else a[s+7*l+d]=c})}}).add([89,3],(t,i,r)=>{}),this.#O.add([39,48],(t,i,r)=>{}).add([43,0,0],(t,i,r)=>{let s=[0,0,0,0],a=(c,h)=>{s[h]=c};if(t.subarray(1).forEach((c,h)=>{let l=h+t[0];[a,a,a,a,()=>{this.#v=c*129/16383*100},()=>c-64,()=>c||128,()=>c,()=>c,()=>{console.debug(`TG300 variation on cc${c}.`)}][l](c,l)}),t[0]<4){let c=0;s.forEach(h=>{c=c<<4,c+=h}),c-=1024}}).add([43,1,0],(t,i,r)=>{}).add([43,2],(t,i,r)=>{let s=e.chRedir(t[0],i,!0),a=t[1],c=p.cc*s,h=`TG300 CH${s+1} `;t.subarray(2).forEach((l,d)=>{d<5?([()=>{},()=>{e.#e[c+f[0]]=l},()=>{e.#e[c+f[32]]=l},()=>{e.#s[s]=l},()=>{let u=e.chRedir(l,i,!0);e.#l[s]=u,s!=u&&(e.buildRchTree(),console.info(`${h}receives from CH${u+1}`))}][d+a]||(()=>{}))(l,d+a):d<21||(d<47?([()=>{e.#S[s]=+!l},()=>{},()=>{},()=>{e.#r[p.rpn*s+3]=l},()=>{},()=>{e.#e[c+f[7]]=l},!1,!1,()=>{e.#e[c+f[10]]=l||128},!1,!1,()=>{console.debug(`${h} AC1 at cc${l}`)},()=>{console.debug(`${h} AC2 at cc${l}`)},()=>{e.#e[c+f[11]]=l},()=>{e.#e[c+f[93]]=l},()=>{e.#e[c+f[91]]=l},()=>{e.#e[c+f[94]]=l},()=>{e.#e[c+f[76]]=l},()=>{e.#e[c+f[77]]=l},()=>{e.#e[c+f[74]]=l},()=>{e.#e[c+f[71]]=l},()=>{e.#e[c+f[73]]=l},()=>{e.#e[c+f[75]]=l},()=>{e.#e[c+f[72]]=l},()=>{e.#e[c+f[78]]=l}][d+a-21]||(()=>{}))(l,d+a):d<95||([()=>{e.#e[c+f[65]]=l},()=>{e.#e[c+f[5]]=l}][d+a-95]||(()=>{}))(l,d+a))})}).add([43,7,0],(t,i,r)=>{let s=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",s)}).add([43,7,1],(t,i,r)=>{e.#n=0,e.#h=Date.now()+3200,e.#g.fill(0),t.forEach(function(s,a){let c=Math.floor(a/16),h=a%16,l=(h*3+c)*7,d=7,u=0;for(l-=h*5,c==2&&(d=2);u>6-u&1,u++})}),this.#P.add([66,18,0,0,127],(t,i,r)=>{e.switchMode("gs",!0),e.#e[p.cc*9]=120,e.#e[p.cc*25]=120,e.#e[p.cc*41]=120,e.#e[p.cc*57]=120,e.#E=3,e.#o=!1,e.#R.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,i,r)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[p.cc*9]=120,e.#e[p.cc*25]=120,e.#e[p.cc*41]=120,e.#e[p.cc*57]=120,e.#o=!1,e.#R.fill(0),console.info("MIDI reset: GS");break}default:{let s=[0,0,0,0],a=(c,h)=>{s[h]=c};if(t.subarray(1).forEach((c,h)=>{let l=h+t[0];[a,a,a,a,d=>{this.#v=d*129/16383*100},d=>{},d=>{}][l](c,h)}),t[0]<4){let c=0;s.forEach(h=>{c=c<<4,c+=h}),c-=1024}}}}).add([66,18,64,1],t=>{let i=t[0];if(i<16){let r="".padStart(i," ");t.subarray(1).forEach((s,a)=>{r+=String.fromCharCode(Math.max(32,s))}),r=r.padEnd(16," "),console.debug(`GS patch name: ${r}`)}else i<48||(i<65?t.subarray(1).forEach((r,s)=>{let a=`GS ${i+s>55?"chorus":"reverb"} `;([()=>{console.info(`${a}type: ${H[r]}`),e.setEffectType(0,40,r)},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${a}predelay: ${r}ms`)},()=>{console.info(`${a}type: ${te[r]}`),e.setEffectType(1,40,16+r)},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${a}to reverb: ${w(r)}`)},()=>{console.debug(`${a}to delay: ${w(r)}`)}][i+s-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?t.subarray(1).forEach((r,s)=>{let a="GS delay ";([()=>{console.info(`${a}type: ${ie[r]}`),e.setEffectType(2,40,32+r)},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${a}to reverb: ${w(r)}`)}][i+s-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],t=>{let i="GS EQ ";t.subarray(1).forEach((r,s)=>{([()=>{console.debug(`${i}low freq: ${[200,400][r]}Hz`)},()=>{console.debug(`${i}low gain: ${r-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][r]}Hz`)},()=>{console.debug(`${i}high gain: ${r-64}dB`)}][t[0]+s]||function(){console.warn(`Unknown GS EQ address: ${t[0]+s}`)})()})}).add([66,18,64,3],t=>{let i="GS EFX ",r=function(s,a){let c=re(e.#m.subarray(10,12),a,s);c&&console.debug(`${i}${B(e.#m.subarray(10,12))} ${c}`)};t.subarray(1).forEach((s,a)=>{([()=>{e.setEffectTypeRaw(3,!1,32+s)},()=>{e.setEffectTypeRaw(3,!0,s),console.info(`${i}type: ${B(e.#m.subarray(10,12))}`)},!1,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,()=>{console.debug(`${i}to reverb: ${w(s)}dB`)},()=>{console.debug(`${i}to chorus: ${w(s)}dB`)},()=>{console.debug(`${i}to delay: ${w(s)}dB`)},!1,()=>{console.debug(`${i}1 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}1 depth: ${s-64}`)},()=>{console.debug(`${i}2 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}2 depth: ${s-64}`)},()=>{console.debug(`${i}to EQ: ${s?"ON":"OFF"}`)}][t[0]+a]||function(c,h){console.warn(`Unknown GS EFX address: ${h}`)})(s,t[0]+a)})}).add([66,18,65],t=>{}).add([69,18,16],t=>{switch(t[0]){case 0:{let i=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",i);break}case 32:{e.#h=Date.now()+3200,t[1]==0&&(e.#n=Math.max(Math.min(t[2]-1,9),0));break}default:if(t[0]<11){e.#n>9&&(e.#n=0),e.#h=Date.now()+3200,e.#p[t[0]-1]?.length||(e.#p[t[0]-1]=new Uint8Array(256));let i=e.#p[t[0]-1],r=t[1];i.fill(0);let s=t.subarray(2);for(let a=0;a>4-g&1,g++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let n=function(t,i,r){let s=t[0],a=p.cc*i,c=p.rpn*i,h=`GS CH${i+1} `;s<3?t.subarray(1).forEach((l,d)=>{[()=>{e.#e[a+f[0]]=l},()=>{e.#s[i]=l},()=>{let u=e.chRedir(l,r,!0);e.#l[i]=u,i!=u&&(e.buildRchTree(),console.info(`${h}receives from CH${u+1}`))}][s+d]()}):s<19||(s<44?t.subarray(1).forEach((l,d)=>{([()=>{e.#S[i]=+!l},!1,()=>{e.setChType(i,l?l<<1:0,y.gs),console.debug(`${h}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{e.#r[c+3]=l},!1,()=>{e.#e[a+f[7]]=l},!1,!1,()=>{e.#e[a+f[10]]=l||128},!1,!1,()=>{console.debug(`${h}CC 1: cc${l}`)},()=>{console.debug(`${h}CC 2: cc${l}`)},()=>{e.#e[a+f[93]]=l},()=>{e.#e[a+f[91]]=l},!1,!1,()=>{e.#r[c+1]=l},()=>{e.#r[c+2]=l},()=>{e.#e[a+f[94]]=l}][s+d-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},o=function(t,i){let r=t[0],s=`GS CH${i+1} `;r<2?t.subarray(1).forEach((a,c)=>{[()=>{e.#e[p.cc*i+f[32]]=a},()=>{}][r+c]()}):r<32?console.warn(`Unknown GS misc address: ${r}`):r<35?t.subarray(1).forEach((a,c)=>{[()=>{console.debug(`${s}EQ: o${["ff","n"][a]}`)},()=>{},()=>{console.debug(`${s}EFX: o${["ff","n"][a]}`)}][r+c-32]()}):console.warn(`Unknown GS misc address: ${r}`)};this.#P.add([66,18,64,16],(t,i)=>{n(t,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(t,i)=>{n(t,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(t,i)=>{n(t,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(t,i)=>{n(t,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(t,i)=>{n(t,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(t,i)=>{n(t,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(t,i)=>{n(t,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(t,i)=>{n(t,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(t,i)=>{n(t,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(t,i)=>{n(t,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(t,i)=>{n(t,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(t,i)=>{n(t,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(t,i)=>{n(t,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(t,i)=>{n(t,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(t,i)=>{n(t,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(t,i)=>{n(t,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(t,i)=>{o(t,e.chRedir(9,i,!0))}).add([66,18,64,65],(t,i)=>{o(t,e.chRedir(0,i,!0))}).add([66,18,64,66],(t,i)=>{o(t,e.chRedir(1,i,!0))}).add([66,18,64,67],(t,i)=>{o(t,e.chRedir(2,i,!0))}).add([66,18,64,68],(t,i)=>{o(t,e.chRedir(3,i,!0))}).add([66,18,64,69],(t,i)=>{o(t,e.chRedir(4,i,!0))}).add([66,18,64,70],(t,i)=>{o(t,e.chRedir(5,i,!0))}).add([66,18,64,71],(t,i)=>{o(t,e.chRedir(6,i,!0))}).add([66,18,64,72],(t,i)=>{o(t,e.chRedir(7,i,!0))}).add([66,18,64,73],(t,i)=>{o(t,e.chRedir(8,i,!0))}).add([66,18,64,74],(t,i)=>{o(t,e.chRedir(10,i,!0))}).add([66,18,64,75],(t,i)=>{o(t,e.chRedir(11,i,!0))}).add([66,18,64,76],(t,i)=>{o(t,e.chRedir(12,i,!0))}).add([66,18,64,77],(t,i)=>{o(t,e.chRedir(13,i,!0))}).add([66,18,64,78],(t,i)=>{o(t,e.chRedir(14,i,!0))}).add([66,18,64,79],(t,i)=>{o(t,e.chRedir(15,i,!0))}),this.#H.add([54,65],(t,i)=>{e.switchMode("x5d");let r=(t[1]<<7)+t[0],s=(t[3]<<7)+t[2],a=e.chRedir(r&15,i,!0),c=p.cc*a;[()=>{s<1||(s<101?(e.setChType(a,e.CH_MELODIC,y.x5d),e.#s[a]=s-1,e.#e[c+f[0]]=82):s<229?(e.setChType(a,e.CH_MELODIC,y.x5d),e.#s[a]=s-101,e.#e[c+f[0]]=56):(e.setChType(a,e.CH_DRUMS,y.x5d),e.#s[a]=he[s-229]||0,e.#e[c+f[0]]=62))},()=>{e.#e[c+f[7]]=s},()=>{s<31&&(e.#e[c+f[10]]=Math.round((s-15)*4.2+64))},()=>{e.#e[c+f[93]]=P(s)},()=>{e.#e[c+f[91]]=P(s)},()=>{e.#r[a*p.rpn+3]=s>8191?s-16320:64+s},()=>{e.#r[a*p.rpn+1]=s>8191?s-16320:64+s},()=>{s>0&&(e.#r[a*p.rpn]=s)},()=>{}][r>>4]()}).add([54,76,0],(t,i)=>{e.switchMode("x5d",!0);let r="",s=82,a=0,c=0,h="MSB PRG LSB NME";S(t,function(l,d){if(d<16400){let u=d%164;switch(!0){case u<10:{l>31&&(r+=String.fromCharCode(l));break}case u==11:{h+=` +122 006 000 `),this.#y[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#o=!0,this.#a.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#o=!0,this.#a.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#o=!0,this.#a.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#o=!0,this.#a.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#o=!0,this.#a.unshift(`Kara.Ver: ${t.slice(2)}`);break}case"XF":{let i=t.slice(2).split(":");switch(i[0]){case"hd":{i.slice(1).forEach((r,s)=>{r.length&&this.#a.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][s]}: ${r}`)});break}case"ln":{i.slice(1).forEach((r,s)=>{r.length&&this.#a.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][s]}: ${r}`)});break}default:this.#a.unshift(`XGF_Data: ${t}`)}break}default:this.#o?t[0]=="\\"?this.#a.unshift(`@ ${t.slice(1)}`):t[0]=="/"?this.#a.unshift(t.slice(1)):this.#a[0]+=t:(this.#a[0]=t,this.#a.unshift(""))}},this.#y[2]=function(t){this.#a.unshift(`Copyrite: ${t}`)},this.#y[3]=function(t,i){i<1&&this.#C<1&&this.#a.unshift(`TrkTitle: ${t}`)},this.#y[4]=function(t,i){this.#a.unshift(`${de(this.#C,""," ")}Instrmnt: ${t}`)},this.#y[5]=function(t){t.trim()==""?this.#a.unshift(""):this.#a[0]+=`${t}`},this.#y[6]=function(t){this.#a.unshift(`${de(this.#C,""," ")}C.Marker: ${t}`)},this.#y[7]=function(t){this.#a.unshift(`CuePoint: ${t}`)},this.#y[32]=function(t){this.#C=t[0]+1},this.#y[33]=function(t,i){console.debug(`Track ${i} requests to get assigned to output ${t}.`),e.#L[i]=t+1},this.#y[81]=function(t,i){e.#V=t/1e3},this.#y[127]=function(t,i){e.#G.run(t,i)},this.#G.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#G.add([67,0,1],function(t,i){e.#L[i]=t[0]+1}),this.#z=new k,this.#Q=new k,this.#O=new k,this.#P=new k,this.#H=new k,this.#W=new k,this.#q=new k,this.#j=new k,this.#z.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#o=e.#o||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#Q.add([4,1],t=>{e.#v=((t[1]<<7)+t[0])/16383*100}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#O.add([76,0,0],t=>{switch(t[0]){case 126:{e.switchMode("xg",!0),e.#o=!1,console.info("MIDI reset: XG");break}default:{let i=[0,0,0,0],r=(s,a)=>{i[a]=s};if(t.subarray(1).forEach((s,a)=>{let c=a+t[0];([r,r,r,r,h=>{this.#v=h*129/16383*100},h=>{},h=>{}][c]||(()=>{}))(s,a)}),t[0]<4){let s=0;i.forEach(a=>{s=s<<4,s+=a}),s-=1024}}}}).add([76,2,1],t=>{let i="XG ";t[0]<32?(i+="reverb ",t.subarray(1).forEach((r,s)=>{([a=>{e.setEffectTypeRaw(0,!1,a),console.info(`${i}main type: ${C[a]}`)},a=>{e.setEffectTypeRaw(0,!0,a),console.debug(`${i}sub type: ${a+1}`)},a=>{console.debug(`${i}time: ${j(a)}s`)},a=>{console.debug(`${i}diffusion: ${a}`)},a=>{console.debug(`${i}initial delay: ${a}`)},a=>{console.debug(`${i}HPF cutoff: ${O[a]}Hz`)},a=>{console.debug(`${i}LPF cutoff: ${O[a]}Hz`)},a=>{console.debug(`${i}width: ${a}`)},a=>{console.debug(`${i}height: ${a}`)},a=>{console.debug(`${i}depth: ${a}`)},a=>{console.debug(`${i}wall type: ${a}`)},a=>{console.debug(`${i}dry/wet: ${a}`)},a=>{console.debug(`${i}send: ${w(a)}dB`)},a=>{console.debug(`${i}pan: ${a-64}`)},!1,!1,a=>{console.debug(`${i}delay: ${a}`)},a=>{console.debug(`${i}density: ${a}`)},a=>{console.debug(`${i}balance: ${a}`)},a=>{},a=>{console.debug(`${i}feedback: ${a}`)},a=>{}][t[0]+s]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(r)})):t[0]<64?(i+="chorus ",t.subarray(1).forEach((r,s)=>{([a=>{e.setEffectTypeRaw(1,!1,a),console.info(`${i}main type: ${C[a]}`)},a=>{e.setEffectTypeRaw(1,!0,a),console.debug(`${i}sub type: ${a+1}`)},a=>{console.debug(`${i}LFO: ${q[a]}Hz`)},a=>{},a=>{console.debug(`${i}feedback: ${a}`)},a=>{console.debug(`${i}delay offset: ${Y(a)}ms`)},a=>{},a=>{console.debug(`${i}low: ${O[a]}Hz`)},a=>{console.debug(`${i}low: ${a-64}dB`)},a=>{console.debug(`${i}high: ${O[a]}Hz`)},a=>{console.debug(`${i}high: ${a-64}dB`)},a=>{console.debug(`${i}dry/wet: ${a}`)},a=>{console.debug(`${i}send: ${w(a)}dB`)},a=>{console.debug(`${i}pan: ${a-64}`)},a=>{console.debug(`${i}to reverb: ${w(a)}dB`)},!1,a=>{},a=>{},a=>{},a=>{console.debug(`${i}LFO phase diff: ${(a-64)*3}deg`)},a=>{console.debug(`${i}input mode: ${a?"stereo":"mono"}`)},a=>{}][t[0]-32+s]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(r)})):t[0]<86?(i+="variation ",t.subarray(1).forEach((r,s)=>{([a=>{e.setEffectTypeRaw(2,!1,a),console.info(`${i}main type: ${C[a]}`)},a=>{e.setEffectTypeRaw(2,!0,a),console.debug(`${i}sub type: ${a+1}`)}][t[0]-64+s]||function(){})(r)})):t[0]<97?(i+="variation ",t.subarray(1).forEach((r,s)=>{[a=>{console.debug(`${i}send: ${w(a)}dB`)},a=>{console.debug(`${i}pan: ${a-64}`)},a=>{console.debug(`${i}to reverb: ${w(a)}dB`)},a=>{console.debug(`${i}to chorus: ${w(a)}dB`)},a=>{console.debug(`${i}connection: ${a?"system":"insertion"}`)},a=>{console.debug(`${i}channel: CH${a+1}`)},a=>{console.debug(`${i}mod wheel: ${a-64}`)},a=>{console.debug(`${i}bend wheel: ${a-64}`)},a=>{console.debug(`${i}channel after touch: ${a-64}`)},a=>{console.debug(`${i}AC1: ${a-64}`)},a=>{console.debug(`${i}AC2: ${a-64}`)}][t[0]-86+s](r)})):t[0]>111&&t[0]<118?i+="variation ":console.warn(`Unknown XG variation address: ${t[0]}`)}).add([76,2,64],t=>{t.subarray(1).forEach((i,r)=>{let s=r+t[0];if(s==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][i]}`);else{let a=s-1>>2,c=s-1&3,h=`XG EQ ${a} ${["gain","freq","Q","shape"][c]}: `;[()=>{console.debug(`${h}${i-64}dB`)},()=>{console.debug(`${h}${i} (raw)`)},()=>{console.debug(`${h}${i/10}`)},()=>{console.debug(`${h}${["shelf","peak"][+!!i]}`)}][c]()}})}).add([76,3],t=>{let i=t[0],r=t[1],s=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((a,c)=>{([h=>{e.setEffectTypeRaw(3+i,!1,h),console.info(`${s}main type: ${C[h]}`)},h=>{e.setEffectTypeRaw(3+i,!0,h),console.debug(`${s}sub type: ${h+1}`)}][r+c]||function(){})(a)})}).add([76,6,0],t=>{let i=t[0];i<64?e.setLetterDisplay(t.subarray(1),"XG letter display",i):e.#N=Date.now()}).add([76,7,0],t=>{let i=t[0];e.#n=0,e.#h=Date.now()+3200,e.#g.fill(0);let r=t.subarray(1);for(let s=0;s>6-u&1,u++})}).add([76,8],(t,i)=>{let r=e.chRedir(t[0],i,!0),s=t[1],a=p.cc*r,c=`XG CH${r+1} `,h=`Unknown XG part address ${s}.`;t.subarray(2).forEach((l,d)=>{s<1?console.debug(h):s<41?([()=>{e.#e[a+f[0]]=l},()=>{e.#e[a+f[32]]=l},()=>{e.#s[r]=l},()=>{let u=e.chRedir(l,i,!0);e.#l[r]=u,r!=u&&(e.buildRchTree(),console.info(`${c}receives from CH${u+1}`))},()=>{e.#S[r]=+!l},()=>{},()=>{e.setChType(r,l,y.xg),console.debug(`${c}type: ${R[l]||l}`)},()=>{e.#r[p.rpn*r+3]=l},!1,!1,()=>{e.#e[a+f[7]]=l},!1,!1,()=>{e.#e[a+f[10]]=l||128},!1,!1,()=>{e.#e[a+f[11]]=l},()=>{e.#e[a+f[93]]=l},()=>{e.#e[a+f[91]]=l},()=>{e.#e[a+f[94]]=l},()=>{e.#e[a+f[76]]=l},()=>{e.#e[a+f[77]]=l},()=>{e.#e[a+f[78]]=l},()=>{e.#e[a+f[74]]=l},()=>{e.#e[a+f[71]]=l},()=>{e.#e[a+f[73]]=l},()=>{e.#e[a+f[75]]=l},()=>{e.#e[a+f[72]]=l}][s+d-1]||(()=>{}))():s<48?console.debug(h):s<111?s>102&&s<105&&(e.#e[a+f[[5,65][s&1]]]=l):s<114?console.debug(h):s<116?console.debug(`${c}EQ ${["bass","treble"][s&1]} gain: ${l-64}dB`):s<118?console.debug(h):s<120?console.debug(`${c}EQ ${["bass","treble"][s&1]} freq: ${l}`):console.debug(h)})}).add([76,9],(t,i)=>{let r=e.chRedir(t[0],i,!0),s=t[1],a=`PLG-150VL CH${r+1} `;t.subarray(2).forEach((c,h)=>{let l=h+s;switch(l){case 1:{console.info(`${a}breath mode: ${["system","breath","velocity","touch EG"][c]}`);break}case 0:case 27:case 28:break;default:if(l<27){let d=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${a}${d} control source: ${ee(c)}`),c&&c<96&&e.allocateAce(c)):console.debug(`${a}${d} scale break point: ${c}`):console.debug(`${a}${d} depth: ${c-64}`)}}})}).add([76,10],t=>{}).add([76,16],t=>{}).add([76,17,0,0],t=>{}).add([76,112],t=>{console.debug(`XG enable PLG-1${["50VL","00SG","50DX"][t[0]]} for CH${t[2]+1}.`)}).add([73,0,0],(t,i)=>{let r=t[0];t.subarray(1).forEach((s,a)=>{let c=r+a;c==8?console.debug(`MU1000 set LCD contrast to ${s}.`):c>9&&c<16&&[()=>{e.dispatchEvent("channelactive",s)},()=>{s<8?(e.dispatchEvent("channelmin",s<<4),console.info(`Octavia System: Minimum CH${(s<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{s<8?(e.dispatchEvent("channelmax",(s<<4)+15),console.info(`Octavia System: Maximum CH${(s<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#k=!!s,console.info(`Octavia System: RS receiving ${["dis","en"][s]}abled.`)}][c-10]()})}).add([73,10,0],(t,i)=>{let r=t[0],s=`MU1000 RS${e.#k?"":" (ignored)"}: `;if(r<16)switch(r){case 2:{let a=e.chRedir(0,i,!0);e.#k&&(e.dispatchEvent("channelmin",a),e.dispatchEvent("channelmax",a+63)),console.info(`${s}Show CH1~64`);break}case 3:{let a=e.chRedir(t[1]<<5,i,!0);e.#k&&e.dispatchEvent("channelmin",a),e.#k&&e.dispatchEvent("channelmax",a+31),console.info(`${s}Show CH${a+1}~CH${a+32}`);break}default:console.debug(`${s}unknown switch ${r} invoked.`)}else if(r<32){if(e.#k){let a=e.chRedir(r-16+(e.#K<<4),i,!0);e.dispatchEvent("channelactive",a)}}else if(r<36){let a=e.chRedir(r-32<<4,i,!0);e.#k&&(e.dispatchEvent("channelmin",a),e.dispatchEvent("channelmax",a+15),e.#K=r-32),console.info(`${s}Show CH${a+1}~CH${a+16}`)}}).add([93,3],(t,i)=>{let r=e.chRedir(t[0],i,!0),s=`PLG-100SG CH${r+1} `,a=Date.now();if(t[1]==0){let c="",h=0;t.subarray(2).forEach((l,d)=>{d%2==0?c+=Z[l]||l.toString().padStart("0"):h+=l*13}),a>=e.#X&&e.#a.unshift("SG Lyric: "),e.#a[0]+=`${J(c)}`,e.#X=a+Math.ceil(h/2)+e.#V,E()&&console.debug(`${s}vocals: ${c}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}),this.#O.add([76,48],t=>{}).add([76,49],t=>{}).add([76,50],t=>{}).add([76,51],t=>{}),this.#O.add([89,0],(t,i,r)=>{if(e.eprom){let s=t[0],a=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);E()&&console.debug(`MU1000 EPROM trail to 0x${a.toString(16).padStart(6,"0")}, ${s} bytes.`);let c=e.eprom.data;t.subarray(4).forEach((h,l)=>{let d=l>>3,u=l&7;if(u==7)for(let g=0;g<7;g++)c[a+7*d+g]+=(h>>6-g&1)<<7;else c[a+7*d+u]=h})}}).add([89,1],(t,i,r)=>{let s=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];E()&&console.debug(`MU1000 EPROM jump to 0x${s.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=s)}).add([89,2],(t,i,r)=>{if(e.eprom){let s=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);E()&&console.debug(`MU1000 EPROM write to 0x${s.toString(16).padStart(6,"0")}.`);let a=e.eprom.data;t.subarray(4).forEach((c,h)=>{let l=h>>3,d=h&7;if(d==7)for(let u=0;u<7;u++)a[s+7*l+u]+=(c>>6-u&1)<<7;else a[s+7*l+d]=c})}}).add([89,3],(t,i,r)=>{}),this.#O.add([39,48],(t,i,r)=>{}).add([43,0,0],(t,i,r)=>{let s=[0,0,0,0],a=(c,h)=>{s[h]=c};if(t.subarray(1).forEach((c,h)=>{let l=h+t[0];[a,a,a,a,()=>{this.#v=c*129/16383*100},()=>c-64,()=>c||128,()=>c,()=>c,()=>{console.debug(`TG300 variation on cc${c}.`)}][l](c,l)}),t[0]<4){let c=0;s.forEach(h=>{c=c<<4,c+=h}),c-=1024}}).add([43,1,0],(t,i,r)=>{}).add([43,2],(t,i,r)=>{let s=e.chRedir(t[0],i,!0),a=t[1],c=p.cc*s,h=`TG300 CH${s+1} `;t.subarray(2).forEach((l,d)=>{d<5?([()=>{},()=>{e.#e[c+f[0]]=l},()=>{e.#e[c+f[32]]=l},()=>{e.#s[s]=l},()=>{let u=e.chRedir(l,i,!0);e.#l[s]=u,s!=u&&(e.buildRchTree(),console.info(`${h}receives from CH${u+1}`))}][d+a]||(()=>{}))(l,d+a):d<21||(d<47?([()=>{e.#S[s]=+!l},()=>{},()=>{},()=>{e.#r[p.rpn*s+3]=l},()=>{},()=>{e.#e[c+f[7]]=l},!1,!1,()=>{e.#e[c+f[10]]=l||128},!1,!1,()=>{console.debug(`${h} AC1 at cc${l}`)},()=>{console.debug(`${h} AC2 at cc${l}`)},()=>{e.#e[c+f[11]]=l},()=>{e.#e[c+f[93]]=l},()=>{e.#e[c+f[91]]=l},()=>{e.#e[c+f[94]]=l},()=>{e.#e[c+f[76]]=l},()=>{e.#e[c+f[77]]=l},()=>{e.#e[c+f[74]]=l},()=>{e.#e[c+f[71]]=l},()=>{e.#e[c+f[73]]=l},()=>{e.#e[c+f[75]]=l},()=>{e.#e[c+f[72]]=l},()=>{e.#e[c+f[78]]=l}][d+a-21]||(()=>{}))(l,d+a):d<95||([()=>{e.#e[c+f[65]]=l},()=>{e.#e[c+f[5]]=l}][d+a-95]||(()=>{}))(l,d+a))})}).add([43,7,0],(t,i,r)=>{let s=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",s)}).add([43,7,1],(t,i,r)=>{e.#n=0,e.#h=Date.now()+3200,e.#g.fill(0),t.forEach(function(s,a){let c=Math.floor(a/16),h=a%16,l=(h*3+c)*7,d=7,u=0;for(l-=h*5,c==2&&(d=2);u>6-u&1,u++})}),this.#P.add([66,18,0,0,127],(t,i,r)=>{e.switchMode("gs",!0),e.#e[p.cc*9]=120,e.#e[p.cc*25]=120,e.#e[p.cc*41]=120,e.#e[p.cc*57]=120,e.#E=3,e.#o=!1,e.#R.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,i,r)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[p.cc*9]=120,e.#e[p.cc*25]=120,e.#e[p.cc*41]=120,e.#e[p.cc*57]=120,e.#o=!1,e.#R.fill(0),console.info("MIDI reset: GS");break}default:{let s=[0,0,0,0],a=(c,h)=>{s[h]=c};if(t.subarray(1).forEach((c,h)=>{let l=h+t[0];[a,a,a,a,d=>{this.#v=d*129/16383*100},d=>{},d=>{}][l](c,h)}),t[0]<4){let c=0;s.forEach(h=>{c=c<<4,c+=h}),c-=1024}}}}).add([66,18,64,1],t=>{let i=t[0];if(i<16){let r="".padStart(i," ");t.subarray(1).forEach((s,a)=>{r+=String.fromCharCode(Math.max(32,s))}),r=r.padEnd(16," "),console.debug(`GS patch name: ${r}`)}else i<48||(i<65?t.subarray(1).forEach((r,s)=>{let a=`GS ${i+s>55?"chorus":"reverb"} `;([()=>{console.info(`${a}type: ${H[r]}`),e.setEffectType(0,40,r)},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${a}predelay: ${r}ms`)},()=>{console.info(`${a}type: ${te[r]}`),e.setEffectType(1,40,16+r)},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${a}to reverb: ${w(r)}`)},()=>{console.debug(`${a}to delay: ${w(r)}`)}][i+s-48]||(()=>{}))()}):i<80?console.debug(`Unknown GS patch address: ${i}`):i<91?t.subarray(1).forEach((r,s)=>{let a="GS delay ";([()=>{console.info(`${a}type: ${ie[r]}`),e.setEffectType(2,40,32+r)},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${a}to reverb: ${w(r)}`)}][i+s-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${i}`))}).add([66,18,64,2],t=>{let i="GS EQ ";t.subarray(1).forEach((r,s)=>{([()=>{console.debug(`${i}low freq: ${[200,400][r]}Hz`)},()=>{console.debug(`${i}low gain: ${r-64}dB`)},()=>{console.debug(`${i}high freq: ${[3e3,6e3][r]}Hz`)},()=>{console.debug(`${i}high gain: ${r-64}dB`)}][t[0]+s]||function(){console.warn(`Unknown GS EQ address: ${t[0]+s}`)})()})}).add([66,18,64,3],t=>{let i="GS EFX ",r=function(s,a){let c=re(e.#m.subarray(10,12),a,s);c&&console.debug(`${i}${B(e.#m.subarray(10,12))} ${c}`)};t.subarray(1).forEach((s,a)=>{([()=>{e.setEffectTypeRaw(3,!1,32+s)},()=>{e.setEffectTypeRaw(3,!0,s),console.info(`${i}type: ${B(e.#m.subarray(10,12))}`)},!1,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,()=>{console.debug(`${i}to reverb: ${w(s)}dB`)},()=>{console.debug(`${i}to chorus: ${w(s)}dB`)},()=>{console.debug(`${i}to delay: ${w(s)}dB`)},!1,()=>{console.debug(`${i}1 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}1 depth: ${s-64}`)},()=>{console.debug(`${i}2 source: ${s}`),s&&s<96&&e.allocateAce(s)},()=>{console.debug(`${i}2 depth: ${s-64}`)},()=>{console.debug(`${i}to EQ: ${s?"ON":"OFF"}`)}][t[0]+a]||function(c,h){console.warn(`Unknown GS EFX address: ${h}`)})(s,t[0]+a)})}).add([66,18,65],t=>{}).add([69,18,16],t=>{switch(t[0]){case 0:{let i=t[1];e.setLetterDisplay(t.subarray(2),"GS display text",i);break}case 32:{e.#h=Date.now()+3200,t[1]==0&&(e.#n=Math.max(Math.min(t[2]-1,9),0));break}default:if(t[0]<11){e.#n>9&&(e.#n=0),e.#h=Date.now()+3200,e.#p[t[0]-1]?.length||(e.#p[t[0]-1]=new Uint8Array(256));let i=e.#p[t[0]-1],r=t[1];i.fill(0);let s=t.subarray(2);for(let a=0;a>4-g&1,g++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let n=function(t,i,r){let s=t[0],a=p.cc*i,c=p.rpn*i,h=`GS CH${i+1} `;s<3?t.subarray(1).forEach((l,d)=>{[()=>{e.#e[a+f[0]]=l},()=>{e.#s[i]=l},()=>{let u=e.chRedir(l,r,!0);e.#l[i]=u,i!=u&&(e.buildRchTree(),console.info(`${h}receives from CH${u+1}`))}][s+d]()}):s<19||(s<44?t.subarray(1).forEach((l,d)=>{([()=>{e.#S[i]=+!l},!1,()=>{e.setChType(i,l<<1,y.gs),console.debug(`${h}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{e.#r[c+3]=l},!1,()=>{e.#e[a+f[7]]=l},!1,!1,()=>{e.#e[a+f[10]]=l||128},!1,!1,()=>{console.debug(`${h}CC 1: cc${l}`)},()=>{console.debug(`${h}CC 2: cc${l}`)},()=>{e.#e[a+f[93]]=l},()=>{e.#e[a+f[91]]=l},!1,!1,()=>{e.#r[c+1]=l},()=>{e.#r[c+2]=l},()=>{e.#e[a+f[94]]=l}][s+d-19]||(()=>{}))()}):s<76||console.debug(`Unknown GS part address: ${s}`))},o=function(t,i){let r=t[0],s=`GS CH${i+1} `;r<2?t.subarray(1).forEach((a,c)=>{[()=>{e.#e[p.cc*i+f[32]]=a},()=>{}][r+c]()}):r<32?console.warn(`Unknown GS misc address: ${r}`):r<35?t.subarray(1).forEach((a,c)=>{[()=>{console.debug(`${s}EQ: o${["ff","n"][a]}`)},()=>{},()=>{console.debug(`${s}EFX: o${["ff","n"][a]}`)}][r+c-32]()}):console.warn(`Unknown GS misc address: ${r}`)};this.#P.add([66,18,64,16],(t,i)=>{n(t,e.chRedir(9,i,!0),i)}).add([66,18,64,17],(t,i)=>{n(t,e.chRedir(0,i,!0),i)}).add([66,18,64,18],(t,i)=>{n(t,e.chRedir(1,i,!0),i)}).add([66,18,64,19],(t,i)=>{n(t,e.chRedir(2,i,!0),i)}).add([66,18,64,20],(t,i)=>{n(t,e.chRedir(3,i,!0),i)}).add([66,18,64,21],(t,i)=>{n(t,e.chRedir(4,i,!0),i)}).add([66,18,64,22],(t,i)=>{n(t,e.chRedir(5,i,!0),i)}).add([66,18,64,23],(t,i)=>{n(t,e.chRedir(6,i,!0),i)}).add([66,18,64,24],(t,i)=>{n(t,e.chRedir(7,i,!0),i)}).add([66,18,64,25],(t,i)=>{n(t,e.chRedir(8,i,!0),i)}).add([66,18,64,26],(t,i)=>{n(t,e.chRedir(10,i,!0),i)}).add([66,18,64,27],(t,i)=>{n(t,e.chRedir(11,i,!0),i)}).add([66,18,64,28],(t,i)=>{n(t,e.chRedir(12,i,!0),i)}).add([66,18,64,29],(t,i)=>{n(t,e.chRedir(13,i,!0),i)}).add([66,18,64,30],(t,i)=>{n(t,e.chRedir(14,i,!0),i)}).add([66,18,64,31],(t,i)=>{n(t,e.chRedir(15,i,!0),i)}).add([66,18,64,64],(t,i)=>{o(t,e.chRedir(9,i,!0))}).add([66,18,64,65],(t,i)=>{o(t,e.chRedir(0,i,!0))}).add([66,18,64,66],(t,i)=>{o(t,e.chRedir(1,i,!0))}).add([66,18,64,67],(t,i)=>{o(t,e.chRedir(2,i,!0))}).add([66,18,64,68],(t,i)=>{o(t,e.chRedir(3,i,!0))}).add([66,18,64,69],(t,i)=>{o(t,e.chRedir(4,i,!0))}).add([66,18,64,70],(t,i)=>{o(t,e.chRedir(5,i,!0))}).add([66,18,64,71],(t,i)=>{o(t,e.chRedir(6,i,!0))}).add([66,18,64,72],(t,i)=>{o(t,e.chRedir(7,i,!0))}).add([66,18,64,73],(t,i)=>{o(t,e.chRedir(8,i,!0))}).add([66,18,64,74],(t,i)=>{o(t,e.chRedir(10,i,!0))}).add([66,18,64,75],(t,i)=>{o(t,e.chRedir(11,i,!0))}).add([66,18,64,76],(t,i)=>{o(t,e.chRedir(12,i,!0))}).add([66,18,64,77],(t,i)=>{o(t,e.chRedir(13,i,!0))}).add([66,18,64,78],(t,i)=>{o(t,e.chRedir(14,i,!0))}).add([66,18,64,79],(t,i)=>{o(t,e.chRedir(15,i,!0))}),this.#H.add([54,65],(t,i)=>{e.switchMode("x5d");let r=(t[1]<<7)+t[0],s=(t[3]<<7)+t[2],a=e.chRedir(r&15,i,!0),c=p.cc*a;[()=>{s<1||(s<101?(e.setChType(a,e.CH_MELODIC,y.x5d),e.#s[a]=s-1,e.#e[c+f[0]]=82):s<229?(e.setChType(a,e.CH_MELODIC,y.x5d),e.#s[a]=s-101,e.#e[c+f[0]]=56):(e.setChType(a,e.CH_DRUMS,y.x5d),e.#s[a]=he[s-229]||0,e.#e[c+f[0]]=62))},()=>{e.#e[c+f[7]]=s},()=>{s<31&&(e.#e[c+f[10]]=Math.round((s-15)*4.2+64))},()=>{e.#e[c+f[93]]=P(s)},()=>{e.#e[c+f[91]]=P(s)},()=>{e.#r[a*p.rpn+3]=s>8191?s-16320:64+s},()=>{e.#r[a*p.rpn+1]=s>8191?s-16320:64+s},()=>{s>0&&(e.#r[a*p.rpn]=s)},()=>{}][r>>4]()}).add([54,76,0],(t,i)=>{e.switchMode("x5d",!0);let r="",s=82,a=0,c=0,h="MSB PRG LSB NME";S(t,function(l,d){if(d<16400){let u=d%164;switch(!0){case u<10:{l>31&&(r+=String.fromCharCode(l));break}case u==11:{h+=` ${s} ${a} ${c} ${r.trim().replace("Init Voice","")}`,a++,r="";break}}a>99&&(s=90,a=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(h)}).add([54,77,0],(t,i)=>{e.switchMode("x5d",!0);let r="",s=90,a=0,c=0,h="MSB PRG LSB NME";S(t,function(l,d){if(d<13600){let u=d%136;switch(!0){case u<10:{l>31&&(r+=String.fromCharCode(l));break}case u==11:{h+=` ${s} ${a} ${c} ${r.trim().replace("Init Combi","")}`,a++,r="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(h)}).add([54,78],(t,i)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][t[0]]} mode.`)}).add([54,85],(t,i)=>{e.switchMode("x5d",!0),S(t,(r,s)=>{s>0&&s<3&&e.setEffectType(s-1,44,r)})}).add([54,104],(t,i)=>{e.switchMode("x5d",!0),S(t,function(r,s,a,c){if(s<192){let h=e.chRedir(Math.floor(s/12),i,!0),l=h*p.cc;switch(s%12){case 0:{r<128?(e.setChType(h,e.CH_MELODIC,y.x5d),e.#e[l+f[0]]=82,e.#s[h]=r):(e.setChType(h,e.CH_DRUMS,y.x5d),e.#e[l+f[0]]=62,e.#s[h]=he[r-128]),r>0&&(e.#c[h]=1);break}case 1:{e.#e[l+f[7]]=r;break}case 2:{e.#r[h*p.rpn+3]=r>127?r-192:64+r;break}case 3:{e.#r[h*p.rpn+1]=r>127?r-192:64+r;break}case 4:{r<31&&(e.#e[l+f[10]]=Math.round((r-15)*4.2+64));break}case 5:{let d=r>>4,u=r&15;e.#e[l+f[91]]=P(u),e.#e[l+f[93]]=P(d);break}case 10:break;case 11:{let d=e.chRedir(r&15,i,!0),u=r>>4;e.#l[h]=r,(d!=h||u)&&(console.info(`X5D Part CH${h+1} receives from CH${d+1}.`),e.buildRchTree())}}}else{let h=e.chRedir(s-192,i,!0)}})}),this.#P.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#o=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(t,i,r)=>{e.switchMode("mt32");let s=e.chRedir(r,i,!0),a=t[1];t.subarray(2).forEach((c,h)=>{let l=h+a;e.#I[l+(s-1)*16]=c,([!1,()=>{let d=e.#I[s-1<<4];if(d<3)if(e.#T[s]=1,d==2)for(let u=0;u{e.#r[s*p.rpn+3]=c+40},()=>{e.#r[s*p.rpn+1]=c+14},()=>{e.#r[s*p.rpn]=c},!1,()=>{e.#e[p.cc*s+f[91]]=c?127:0},!1,()=>{e.#e[p.cc*s+f[7]]=c},()=>{e.#e[p.cc*s+f[10]]=Math.ceil(c*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(t,i,r)=>{e.switchMode("mt32");let s=e.chRedir(r,i,!0)}).add([22,18,2],(t,i,r)=>{e.switchMode("mt32");let s=e.chRedir(r,i,!0),a=t[1]+(t[0]<<7);a<10&&(e.#T[s]=1),t.subarray(2).forEach((c,h)=>{let l=h+a;l<14&&(e.#w[(s-1)*p.cmt+l]=c)})}).add([22,18,3],(t,i,r)=>{if(e.switchMode("mt32"),t[0]){let s=t[1]-16}else{let s=t[1];t.subarray(2).forEach((a,c)=>{let h=c+s;e.#I[h]=a;let l=e.chRedir(1+h>>4,i,!0),d=h&15;([!1,()=>{let u=e.#I[l-1<<4];if(u<3)if(e.#T[l]=1,u==2)for(let g=0;g{e.#r[l*p.rpn+3]=a+40},()=>{e.#r[l*p.rpn+1]=a+14},()=>{e.#r[l*p.rpn]=a},!1,()=>{e.#e[p.cc*l+f[91]]=a?127:0},!1,()=>{e.#e[p.cc*l+f[7]]=a},()=>{e.#e[p.cc*l+f[10]]=Math.ceil(a*9.05)}][d]||(()=>{}))()})}}).add([22,18,4],(t,i,r)=>{e.switchMode("mt32");let s=t[1]+(t[0]<<7);t.subarray(2).forEach((a,c)=>{let h=c+s,l=e.chRedir(Math.floor(h/246+1),i,!0),d=h%246;d<14&&(e.#w[(l-1)*p.cmt+d]=a),d<10&&(e.#T[l]=1)})}).add([22,18,5],(t,i,r)=>{e.switchMode("mt32");let s=(t[0]<<7)+t[1];t.subarray(2).forEach((a,c)=>{let h=s+c,l=Math.floor(h/8),d=h&7,u=l*8;e.#F[h]=a,([!1,()=>{let g=e.#F[u];if(g<3){let b="";if(g==2){let m=p.cmt*l;b=`MT-m:${a.toString().padStart(3,"0")}`}else b=e.baseBank.get(0,a+(g<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l}),e.userBank.load(`MSB LSB PRG NME 000 127 ${l} ${b}`,!0)}}][d]||(()=>{}))()})}).add([22,18,8],(t,i,r)=>{e.switchMode("mt32");let s=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((a,c)=>{let h=s+c;h>1)*p.cmt+h]=a)})}).add([22,18,16],(t,i,r)=>{e.switchMode("mt32");let s=t[1],a=!1,c=function(h,l){e.#l[l-12]=h,a=!0};t.subarray(2).forEach((h,l)=>{let d=l+s;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,c,c,c,c,c,c,c,c,c,()=>{e.#v=h}][d]||(()=>{}))(h,l)}),a&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let i=t[1],r=" ".repeat(i);t.subarray(2).forEach(s=>{s>31&&(r+=String.fromCharCode(s))}),e.#M=r.padStart(20," "),e.#N=Date.now()+3200}).add([22,18,82],(t,i)=>{let r=e.chRedir(0,i,!0);for(let s=0;s<16;s++)e.#u.ano(r+s),s&&s<10&&(e.#s[r+s]=G[s-1]);console.info("MT-32 alt reset complete.")}),this.#H.add([66,0],(t,i)=>{e.switchMode("ns5r",!0),e.#o=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,i)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#o=!1}).add([66,18,0,0],(t,i)=>{let r=t[0];switch(r){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#o=!1;break}case 125:break;default:if(r<10){let s=[0,0,0,0],a=(c,h)=>{s[h]=c};if(t.subarray(1).forEach((c,h)=>{[a,a,a,a,()=>{e.#v=c*129/16383*100},()=>c-64,()=>c-64,()=>{},()=>{},()=>{}][r+h]()}),t[0]<4){let c=0;s.forEach(h=>{c=c<<4,c+=h}),c-=1024}}}}).add([66,18,0,1],(t,i)=>{}).add([66,18,0,2],(t,i)=>{}).add([66,18,1],(t,i)=>{let r=e.chRedir(t[0],i,!0),s=r*p.cc,a=t[1],c=`NS5R CH${r+1} `;t.subarray(2).forEach((h,l)=>{let d=a+l;d<3?[()=>{e.#e[s+f[0]]=h||121},()=>{e.#e[s+f[32]]=h},()=>{e.#s[r]=h}][d]():d<8||(d<14?[()=>{let u=e.chRedir(h,i,!0);e.#l[r]=u,r!=u&&(e.buildRchTree(),console.info(`${c}receives from CH${u+1}`))},()=>{e.#S[r]=+!h},()=>{e.setChType(r,h,y.ns5r),console.debug(`${c}type: ${R[h]}`)},()=>{e.#r[p.rpn*r+3]=h},()=>{},()=>{}][d-8]():d<16||(d<33?[()=>{e.#e[s+f[7]]=h},()=>{e.#e[s+f[11]]=h},()=>{},()=>{},()=>{e.#e[s+f[10]]=h||128},()=>{},()=>{},()=>{e.#e[s+f[93]]=h},()=>{e.#e[s+f[91]]=h},()=>{e.#e[s+f[76]]=h},()=>{e.#e[s+f[77]]=h},()=>{e.#e[s+f[78]]=h},()=>{e.#e[s+f[74]]=h},()=>{e.#e[s+f[71]]=h},()=>{e.#e[s+f[73]]=h},()=>{e.#e[s+f[75]]=h},()=>{e.#e[s+f[72]]=h}][d-16]():d<112||d<114&&[()=>{e.#e[s+f[5]]=h},()=>{e.#e[s+f[65]]=h}][d-112]()))})}).add([66,18,8,0],(t,i)=>{let r=t[0];if(r<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let s=r-32;e.#h=Date.now()+3200,e.#n=10,e.#g.fill(0);let a=t.subarray(1),c=4;a.forEach(function(h,l){let d=l+s,u=d>>4,g=d&15;if(d<80){let b=u>3,m=0,$=u0;)e.#g[g*32+u*7+($-m)]=b&1,b=b>>1,m++}})}}).add([66,52],(t,i)=>{e.switchMode("ns5r",!0),e.#o=!1;let r="";S(t,(s,a)=>{a<8?(s>31&&(r+=String.fromCharCode(s)),a==7&&(e.aiEfxName=r)):a<10&&e.setEffectType(a-8,44,s)})}).add([66,53],(t,i)=>{e.switchMode("ns5r",!0),e.#o=!1,S(t,function(r,s){switch(!0){case s<2944:{let a=e.chRedir(Math.floor(s/92),i,!0),c=a*p.cc;switch(s%92){case 0:{e.#e[c+f[0]]=r||121;break}case 1:{e.#e[c+f[32]]=r;break}case 2:{e.#s[a]=r,r>0&&(e.#c[a]=1);break}case 3:{let h=e.chRedir(r,i,!0);e.#l[a]=h,a!=h&&(console.info(`NS5R CH${a+1} receives from CH${h+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#r[a*p.rpn+3]=r<40||r>88?r+(r>63?-192:64):r;break}case 9:case 10:{e.#e[c+f[7]]=r;break}case 11:{e.#e[c+f[11]]=r;break}case 14:{e.#e[c+f[10]]=r||128;break}case 19:{e.#e[c+f[93]]=r;break}case 20:{e.#e[c+f[91]]=r;break}case 84:{e.#e[c+f[65]]=r;break}case 85:{e.#e[c+f[5]]=r;break}}break}case s<3096:break;case s<3134:break;case s<8566:break}})}).add([66,54],(t,i)=>{e.switchMode("ns5r",!0);let r="",s=80,a=0,c=0,h="MSB PRG LSB NME";S(t,function(l,d){let u=d%158;switch(!0){case u<10:{l>31&&(r+=String.fromCharCode(l));break}case u==11:{s=l&127;break}case u==12:{c=l&127;break}case u==13:{h+=` diff --git a/dist/state.mjs b/dist/state.mjs index a02ba4b3..7e9ff554 100644 --- a/dist/state.mjs +++ b/dist/state.mjs @@ -136,8 +136,8 @@ o,お ~, ^, _,`.split(` -`).forEach(e=>{let n=e.split(",");A[n[0]]=n[1]});var F=function(e){let n=e;e[0]=="*"&&(n=n.slice(1)),["aa","ii","uu","ee","oo"].forEach(t=>{for(;n.indexOf(t)>-1;)n=n.replace(t,t[0])});for(let t in A)n=n.replaceAll(t,A[t]);n.indexOf("ん")==0&&n.length>1&&(n=n.slice(1));let o=n.indexOf("!");return o>-1&&n.length>1&&(n=n.slice(o+1)),n},K=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var U=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],V=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],z=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var re={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"},ne={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]]},N=function(e){return re[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},Q=function(e,n,o){let t=(e[0]-32<<16)+(e[1]<<8)+n,s=ne[t]||{},r=s[0];if(r?.length)return r+=`: ${(s[1]||function(){})(o)||o}`,r},G=[68,48,95,78,41,3,110,122,0];var y=function(e=64){return Math.round(2e3*Math.log10(e/64))/100};var q=function(e){let n=0;return e.forEach(o=>{n+=o,n=n&127}),~n+1&127},k=function(e,n){let o=0,t=0;for(let s=0;s>r&1)<<7,i=e[s];i+=a,s%8!=0?(n(i,o,e),o++):t=e[s]}},T=function(e){let n=Math.floor(e*14.2);return n<128?n:0};var m=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],Y=[[0,0,0,0,121,0,0,56,82,81,63,0,0],[0,0,4,0,0,127,0,0,0,0,0,0,0]],S=[120,127,120,127,120,127,61,62,62,62,120,122,122],oe=[0,3,81,84,88],W={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},H={0:0,1:1,2:3,5:4},J=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Z=[36,37],te=[20,21,22,23,24,25,26,28,29,30,31,36,37,64,65],v=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,12,13,16,17,18,19],ce=[12,13,16,17,18,19],le=[33,99,100,32,102,8,9,10],j=[0,16,25,40,32,64,26,48],p={};m.forEach((e,n)=>{p[e]=n});var f={length:v.length};v.forEach((e,n)=>{f[e]=n});var E=function(){return!!self.Bun||self.debugMode||!1},he=function(e){let n=[],o=0;return e?.forEach(function(t,s){t==247?n.push(e.subarray(o,s)):t==240&&(o=s+1)}),n.length||n.push(e.subarray(0)),E()&&console.debug(n),n},ee=function(e,n="",o="",t=2){return e?`${n}${e.toString().padStart(t,"0")}${o}`:""},d={ch:128,cc:v.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:te.length,dnc:128,efx:7},Re=class extends P{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#u=0;#k=0;#M=new Array(11);get#b(){return this.#M[this.#u]}set#b(e){this.#M[this.#u]=e}#p=new Uint8Array(d.ch);#f=new Uint8Array(d.ch);#a=new Uint8Array(d.ch);#e=new Uint8Array(d.ch*d.cc);#T=new Uint8Array(d.ace);#r=new Uint8Array(d.ch);#o=new Uint8Array(d.ch*d.nn);#m=new Uint8Array(d.ch);#c=new Uint16Array(d.pl);#h=new Uint8Array(d.pl);#A=new Int16Array(d.ch);#S=new Uint8Array(d.ch);#_=0;#s=new Uint8Array(d.ch*d.rpn);#I=new Int8Array(d.ch*Z.length);#j=new Uint8Array(d.drm*d.dpn*d.dnc);#x=new Uint8Array(d.ch);#U=new Uint8Array(128);#y=new Uint8Array(d.cmt*8);#X=new Uint8Array(1024);#N=new Uint8Array(d.cmt*64);#$=new Uint8Array(d.efx*3);#G=0;#E=0;#g=100;#v=0;#F=500;#K=0;#C="";#H=0;#V=0;#w=!0;#n=!1;#J;#te=new Uint8Array(2);#i=[];#R=new Uint8Array(d.ch);#L=new Uint8Array(d.tr);baseBank=new D("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new D("gm");initOnReset=!1;aiEfxName="";chRedir(e,n,o){if(this.#L[n])return(this.#L[n]-1)*16+e;if([2,3].indexOf(this.#E)>-1){if(o==1)return e;let t=0,s=!0;for(;s;)this.#R[e+t]==0?(this.#R[e+t]=n,console.debug(`Assign track ${n} to channel ${e+t+1}.`),s=!1):this.#R[e+t]==n?s=!1:(t+=16,t>=128&&(t=0,s=!1));return e+t}else return e}#d=[];#B;#l={nOff:(e,n)=>{let o=e*128+n,t=this.#c.lastIndexOf(o);t>-1&&(this.#e[d.cc*e+f[64]]>63?(this.#h[t]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#o[o],state:this.NOTE_HELD})):this.#e[d.cc*e+f[66]]>63&&this.#h[t]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#h[t]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#o[o],state:this.NOTE_SOSTENUTO_HELD})):(this.#c[t]=0,this.#o[o]=0,this.#h[t]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:n,velo:0,state:this.NOTE_IDLE})))},nOn:(e,n,o)=>{let t=e*128+n,s=0;for(this.#m[e]&&this.#l.ano(e);this.#h[s]>0&&this.#c[s]!=t;)s++;s{},cAt:(e,n)=>{},hoOf:e=>{this.#h.forEach((n,o)=>{if(n==this.NOTE_HELD){let t=this.#c[o],s=t>>7;e==s&&(this.#h[o]=this.NOTE_IDLE,this.#c[o]=0,this.#o[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#h.forEach((n,o)=>{let t;switch(n){case this.NOTE_ATTACK:{t=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{t=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{t=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(t){this.#h[o]=t;let s=this.#c[o];this.dispatchEvent("note",{part:e,note:s&127,velo:this.#o[s],state:t})}})},soOf:e=>{this.#h.forEach((n,o)=>{if(n==this.NOTE_SOSTENUTO_HELD){let t=this.#c[o],s=t>>7;e==s&&(this.#h[o]=this.NOTE_IDLE,this.#c[o]=0,this.#o[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#c.forEach((n,o,t)=>{let s=n>>7,r=n&127;n==0&&this.#o[0]==0||s==e&&this.#l.nOff(s,r)})}};#Z={8:function(e){let n=e.channel,o=e.data[0];this.#l.nOff(n,o)},9:function(e){let n=e.channel;this.#p[n]=1;let o=e.data[0],t=e.data[1];t>0?this.#l.nOn(n,o,t):this.#l.nOff(n,o)},10:function(e){let n=e.channel,o=n*128+e.data[0];this.#c.indexOf(o)>-1&&(this.#o[o]=data[1],this.dispatchEvent("note",{part:n,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let n=e.channel;this.#p[n]=1;let o=n*d.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#l.ano(n),this.#A[n]=0;let t=n*d.cc;this.#e[t+f[1]]=0,this.#e[t+f[5]]=0,this.#e[t+f[64]]=0,this.#e[t+f[65]]=0,this.#e[t+f[66]]=0,this.#e[t+f[67]]=0,this.#e[t+f[11]]=127,this.#e[t+f[101]]=127,this.#e[t+f[100]]=127,this.#e[t+f[99]]=127,this.#e[t+f[98]]=127;return}case 123:{this.#l.ano(n);return}case 124:{this.#l.ano(n);return}case 125:{this.#l.ano(n);return}case 126:{this.#m[n]=1,this.#l.ano(n);return}case 127:{this.#m[n]=0,this.#l.ano(n);return}}if(f[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(ce.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{if(E()&&console.debug(`${m[this.#t]}, CH${n+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#a[n]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${n+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg");else if(this.#t==p.gs)e.data[1]<56&&this.#a[n]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${n+1} to stay drums.`));else if(this.#t==p.gm)e.data[1]<48?this.#a[n]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${n+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0);else if(this.#t==p.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let t=0;for(let s=0;s<16;s++){let r=this.#e[d.cc*s];(r==56||r==62)&&t++}t>14&&this.switchMode("ag10",!0)}}switch(this.#t){case p.xg:{[126,127].indexOf(e.data[1])>-1?this.#a[n]==0&&(this.setChType(n,this.CH_DRUM2),console.debug(`CH${n+1} set to drums by MSB.`)):this.#a[n]>0&&(this.setChType(n,this.CH_MELODIC),console.debug(`CH${n+1} set to melodic by MSB.`));break}case p["05rw"]:case p.x5d:case p.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#a[n]==0&&(this.setChType(n,this.CH_DRUM2),console.debug(`CH${n+1} set to drums by MSB.`)):this.#a[n]>0&&(this.setChType(n,this.CH_MELODIC),console.debug(`CH${n+1} set to melodic by MSB.`));break}case p.g2:{e.data[1]==120?this.#a[n]==0&&(this.setChType(n,this.CH_DRUM2),console.debug(`CH${n+1} set to drums by MSB.`)):this.#a[n]>0&&(this.setChType(n,this.CH_MELODIC),console.debug(`CH${n+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:n});break}case 6:{if(this.#_){[p.xg,p.gs,p.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 t=this.#e[o+f[99]],s=this.#e[o+f[98]];if(t==1){let r=le.indexOf(s);if(r>-1)this.#e[o+f[71+r]]=e.data[1],E()&&console.debug(`Redirected NRPN 1 ${s} to cc${71+r}.`),this.dispatchEvent("cc",{part:n,cc:71+r,data:e.data[1]});else{let a=Z.indexOf(s);a>-1?this.#I[n*10+a]=e.data[1]-64:console.warn(`NRPN 0x01${s.toString(16).padStart(2,"0")} is not supported.`),E()&&console.debug(`CH${n+1} voice NRPN ${s} commit`)}}else{if(te.indexOf(t)<0){let a=`NRPN 0x${t.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")} `;t==127?console.warn(`${a}is not necessary. Consider removing it.`):console.warn(`${a}is not supported.`)}else this.#a[n]-2<0&&console.warn(`CH${n+1} cannot accept drum NRPN as type ${C[this.#a[n]]}.`);E()&&console.debug(`CH${n+1} (${C[this.#a[n]]}) drum NRPN ${t} commit`)}}else{let t=H[this.#e[o+f[100]]];this.#e[o+f[101]]==0&&t!=null&&(E()&&console.debug(`CH${n+1} RPN 0 ${this.#e[o+f[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],J[t][0]),J[t][1]),this.#s[n*d.rpn+t]=e.data[1])}break}case 32:{this.dispatchEvent("voice",{part:n});break}case 38:{this.#_||this.#e[o+101]==0&&H[this.#e[o+100]]!=null&&(this.#s[n*d.rpn+H[this.#e[o+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#l.hoOf(n);break}case 66:{e.data[1]>>6?this.#l.soOn(n):this.#l.soOf(n);break}case 98:case 99:{this.#_=1;break}case 100:case 101:{this.#_=0;break}}this.#e[o+f[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:n,cc:e.data[0],data:e.data[1]})}},12:function(e){let n=e.channel;this.#p[n]=1,this.#r[n]=e.data,this.#x[n]=0,E()&&console.debug(`T:${e.track} C:${n} P:${e.data}`),this.dispatchEvent("voice",{part:n})},13:function(e){let n=this,o=e.channel;this.#c.forEach(function(t){let s=t>>7;o==s&&(n.#o[t]=e.data,n.dispatchEvent("note",{part:o,note:t&127,velo:e.data,state:n.NOTE_SUSTAIN}))})},14:function(e){let n=e.channel;this.#A[n]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:n,pitch:this.getPitchShift(n)})},15:function(e){he(e.data).forEach(n=>{let o=n[0],t=n[1];(this.#ee[o]||function(){console.debug(`Unknown manufacturer ${o}.`)})(t,n.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#d[e.meta]||function(o,t,s){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#v=0);let n=oe.indexOf(e.meta)>-1;if(E()&&console.debug(e),n)return e.reply="meta",e}};#ee={64:(e,n,o)=>{this.#q.run(n,o,e)},65:(e,n,o)=>{if(n[0]<16)this.#D.run(n,o,e),console.warn("Unknown device SysEx!");else{let t=n[n.length-1],s=q(n.subarray(2,n.length-1));t==s?this.#D.run(n.subarray(0,n.length-1),o,e):console.warn(`Bad GS checksum ${t}. Should be ${s}.`)}},66:(e,n,o)=>{this.#P.run(n,o,e)},67:(e,n,o)=>{this.#O.run(n,o,e)},68:(e,n,o)=>{this.#W.run(n,o,e)},71:(e,n,o)=>{this.#Y.run(n,o,e)},126:(e,n,o)=>{this.#z.run(n,o,e)},127:(e,n,o)=>{this.switchMode("gm"),this.#Q.run(n,o,e)}};#z;#Q;#O;#D;#P;#q;#Y;#W;buildRchTree(){let e=[];this.#f.forEach((n,o)=>{e[n]?.constructor||(e[n]=[]),e[n].push(o)}),this.#J=e}getActive(){let e=this.#p.slice();return this.#t==p.mt32,e}getCc(e){let n=e*d.cc,o=this.#e.subarray(n,n+d.cc);return o[f[0]]=o[f[0]]||this.#G,o[f[32]]=o[f[32]]||this.#E,o}getCcCh(e,n){if(v.indexOf(n)<0)throw new Error("CC number not accepted");return this.#e[d.cc*e+f[n]]}getCcAll(){let e=this.#e.slice();for(let n=0;n0&&(this.#e[e*d.cc+f[0]]=S[o])}getPitch(){return this.#A}getProgram(){return this.#r}getTexts(){return this.#i.slice()}getVel(e){let n=new Map,o=this;return o.#c.forEach(function(t,s){let r=Math.floor(t/128),a=t%128;e==r&&o.#o[t]>0&&n.set(a,{v:o.#o[t],s:o.#h[s]})}),n}getBitmap(){return{bitmap:this.#b,expire:this.#k}}getLetter(){return{text:this.#C,expire:this.#H}}getMode(){return m[this.#t]}getMaster(){return{volume:this.#g}}getRawStrength(){let e=this;return this.#c.forEach(function(n){let o=Math.floor(n/128);e.#o[n]>e.#S[o]&&(e.#S[o]=e.#o[n])}),this.#S}getStrength(){let e=[],n=this;return this.getRawStrength().forEach(function(o,t){e[t]=Math.floor(o*n.#e[t*d.cc+f[7]]*Math.max(n.#e[t*d.cc+f[11]],Math.floor(n.#e[t*d.cc+f[91]]*.5),Math.floor(n.#e[t*d.cc+f[92]]*.65),Math.floor(n.#e[t*d.cc+f[94]]*.8))*n.#g/803288)}),e}getRpn(){return this.#s}getNrpn(){return this.#I}getVoice(e,n,o,t){let s=e||this.#G,r=n,a=o||this.#E;m[this.#t]=="ns5r"&&s>0&&s<56&&(a=3);let i=this.userBank.get(s,r,a,t);if(m[this.#t]=="mt32"&&i.name.indexOf("MT-m:")==0){let c=parseInt(i.name.slice(5)),h=c*d.cmt,l="";this.#N.subarray(h,h+10).forEach(u=>{u>31&&(l+=String.fromCharCode(u))}),this.userBank.load(`MSB LSB PRG -0 127 ${r} ${l}`,!0),i.name=l,i.ending=" "}return(i.ending!=" "||!i.name.length)&&(i=this.baseBank.get(s,r,a,t)),i}getChVoice(e){let n=this.getVoice(this.#e[e*d.cc+f[0]],this.#r[e],this.#e[e*d.cc+f[32]],m[this.#t]);if(this.#x[e])switch(this.#t){case p.mt32:n.ending="~",n.name="",this.#y.subarray(14*(e-1),14*(e-1)+10).forEach(o=>{o>31&&(n.name+=String.fromCharCode(o))})}return n}getPitchShift(e){let n=e*d.rpn;return this.#A[e]/8192*this.#s[n]+(this.#s[n+3]-64)+((this.#s[n+1]<<7)+this.#s[n+2]-8192)/8192}getEffectType(e=0){let n=3*e+1;return this.#$.subarray(n,n+2)}setEffectTypeRaw(e=0,n,o){let t=3*e;this.#$[t]=1,this.#$[t+1+ +n]=o}setEffectType(e=0,n,o){this.setEffectTypeRaw(e,!1,n),this.setEffectTypeRaw(e,!0,o)}setLetterDisplay(e,n,o=0,t=3200){let s=this,r;s.#C=" ".repeat(o),e.forEach(a=>{s.#C+=String.fromCharCode(a>31?a:32),a<32&&(r=r||new Set,r.add(a))}),s.#H=Date.now()+3200,s.#C=s.#C.padEnd(32," "),r&&(r=Array.from(r),r.forEach((a,i,c)=>{c[i]=a.toString(16).padStart(2,"0")}),console.warn(`${n}${n?" ":""}invalid code point${r.length>1?"s":""}: 0x${r.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let n=!0,o=0;for(;n&&o=d.ace&&console.warn("ACE slots are full.")}getAce(){return this.#T}getChAce(e,n){if(n<0||n>=d.ace)throw new RangeError("No such ACE slot");let o=this.#T[n];if(o){if(v.indexOf(o)>=0)return this.#e[e*d.cc+f[o]];throw new Error(`Invalid ACE source: ${o}`)}else return 0}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#G=0,this.#E=0,this.#v=0,this.#p.fill(0),this.#e.fill(0),this.#T.fill(0),this.#r.fill(0),this.#o.fill(0),this.#c.fill(0),this.#S.fill(0),this.#A.fill(0),this.#I.fill(0),this.#j.fill(0),this.#g=100,this.#i=[],this.#F=500,this.#K=0,this.#H=0,this.#C="",this.#k=0,this.#u=0,this.#b.fill(0),this.#n=!1,this.#V=0,this.#w=!0,this.#f.forEach(function(n,o,t){t[o]=o}),this.buildRchTree(),e==0&&(this.#R.fill(0),this.#L.fill(0)),this.#e[d.cc*9]=S[0],this.#e[d.cc*25]=S[0],this.#e[d.cc*41]=S[0],this.#e[d.cc*57]=S[0],this.#a.fill(this.CH_MELODIC),this.#a[9]=this.CH_DRUM1,this.#a[25]=this.CH_DRUM3,this.#a[41]=this.CH_DRUMS,this.#a[57]=this.CH_DRUMS,this.#a[73]=this.CH_DRUM5,this.#a[89]=this.CH_DRUM7,this.#a[105]=this.CH_DRUMS,this.#a[121]=this.CH_DRUMS,this.#X.fill(0),this.#N.fill(0),this.#U.fill(0),this.#y.fill(0),this.#x.fill(0),this.#$.fill(0),this.aiEfxName="",this.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let n=0;n-1){if(this.#t==0||n){let t=this.#t;this.#t=o,this.#u=0,this.#G=Y[0][o],this.#E=Y[1][o];for(let r=0;r0&&this.#e[r*d.cc+f[0]]==S[t]&&(this.#e[r*d.cc]=S[o]);switch(this.initOnReset,o){case p.mt32:{G.forEach((r,a)=>{let i=a+1;this.#p[i]||(this.#r[i]=r,this.#e[i*d.cc+f[91]]=127)});break}}let s;switch(o){case p.gs:{s=[40,4,40,18,40,32,32,0,0,0,0,0,0,0];break}case p.x5d:case p.ns5r:{s=[44,1,44,19,44,0,44,0,0,0,0,0,0,0];break}default:s=[1,0,65,0,5,0,0,0,0,0,0,0,0,0]}for(let r=0;r14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#Z[e.type].call(this,e);{let n=this.chRedir(e.part,e.track),o=!1;this.#J[n]?.forEach(t=>{e.channel=t,o=!0,this.#Z[e.type].call(this,e)}),o||console.warn(`${W[e.type]?W[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${n+1} without any recipient.`)}this.#i.length>100&&this.#i.splice(100,this.#i.length-99)}runRaw(e){}constructor(){super();let e=this;this.#b=new Uint8Array(256),this.#M[10]=new Uint8Array(512),this.#B=new w,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME +`).forEach(e=>{let n=e.split(",");A[n[0]]=n[1]});var F=function(e){let n=e;e[0]=="*"&&(n=n.slice(1)),["aa","ii","uu","ee","oo"].forEach(t=>{for(;n.indexOf(t)>-1;)n=n.replace(t,t[0])});for(let t in A)n=n.replaceAll(t,A[t]);n.indexOf("ん")==0&&n.length>1&&(n=n.slice(1));let o=n.indexOf("!");return o>-1&&n.length>1&&(n=n.slice(o+1)),n},K=function(e){return e?e<96?`cc${e}`:["aftertouch","velocity","pitch bend"][e-96]:"off"};var U=["room 1","room 2","room 3","hall 1","hall 2","plate","delay","panning delay"],V=["chorus 1","chorus 2","chorus 3","chorus 4","feedback","flanger","short delay","short delay feedback"],z=["delay 1","delay 2","delay 3","delay 4","pan delay 1","pan delay 2","pan delay 3","pan delay 4","delay to reverb","pan repeat"];var re={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"},ne={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]]},N=function(e){return re[(e[0]-32<<8)+e[1]]||`0x${e[0].toString(16).padStart(2,"0")}${e[1].toString(16).padStart(2,"0")}`},Q=function(e,n,o){let t=(e[0]-32<<16)+(e[1]<<8)+n,s=ne[t]||{},r=s[0];if(r?.length)return r+=`: ${(s[1]||function(){})(o)||o}`,r},G=[68,48,95,78,41,3,110,122,0];var y=function(e=64){return Math.round(2e3*Math.log10(e/64))/100};var q=function(e){let n=0;return e.forEach(o=>{n+=o,n=n&127}),~n+1&127},k=function(e,n){let o=0,t=0;for(let s=0;s>r&1)<<7,i=e[s];i+=a,s%8!=0?(n(i,o,e),o++):t=e[s]}},T=function(e){let n=Math.floor(e*14.2);return n<128?n:0};var m=["?","gm","gs","xg","g2","mt32","ns5r","ag10","x5d","05rw","krs","k11","sg"],Y=[[0,0,0,0,121,0,0,56,82,81,63,0,0],[0,0,4,0,0,127,0,0,0,0,0,0,0]],S=[120,127,120,127,120,127,61,62,62,62,120,122,122],oe=[0,3,81,84,88],W={8:"Off",9:"On",10:"Note aftertouch",11:"cc",12:"pc",13:"Channel aftertouch",14:"Pitch"},H={0:0,1:1,2:3,5:4},J=[[0,24],[0,127],[0,127],[40,88],[0,127],[0,127]],Z=[36,37],te=[20,21,22,23,24,25,26,28,29,30,31,36,37,64,65],v=[0,1,2,4,5,6,7,8,10,11,32,38,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,84,91,92,93,94,95,98,99,100,101,12,13,16,17,18,19],ce=[12,13,16,17,18,19],le=[33,99,100,32,102,8,9,10],j=[0,16,25,40,32,64,26,48],p={};m.forEach((e,n)=>{p[e]=n});var f={length:v.length};v.forEach((e,n)=>{f[e]=n});var E=function(){return!!self.Bun||self.debugMode||!1},he=function(e){let n=[],o=0;return e?.forEach(function(t,s){t==247?n.push(e.subarray(o,s)):t==240&&(o=s+1)}),n.length||n.push(e.subarray(0)),E()&&console.debug(n),n},ee=function(e,n="",o="",t=2){return e?`${n}${e.toString().padStart(t,"0")}${o}`:""},d={ch:128,cc:v.length,nn:128,pl:512,tr:256,cmt:14,rpn:6,ace:8,drm:8,dpn:te.length,dnc:128,efx:7},Re=class extends P{NOTE_IDLE=0;NOTE_ATTACK=1;NOTE_DECAY=2;NOTE_SUSTAIN=3;NOTE_HELD=4;NOTE_RELEASE=5;NOTE_SOSTENUTO_ATTACK=8;NOTE_SOSTENUTO_DECAY=9;NOTE_SOSTENUTO_SUSTAIN=10;NOTE_SOSTENUTO_HELD=11;CH_MELODIC=0;CH_DRUMS=1;CH_DRUM1=2;CH_DRUM2=3;CH_DRUM3=4;CH_DRUM4=5;CH_DRUM5=6;CH_DRUM6=7;CH_DRUM7=8;CH_DRUM8=9;#t=0;#u=0;#k=0;#M=new Array(11);get#b(){return this.#M[this.#u]}set#b(e){this.#M[this.#u]=e}#p=new Uint8Array(d.ch);#f=new Uint8Array(d.ch);#a=new Uint8Array(d.ch);#e=new Uint8Array(d.ch*d.cc);#T=new Uint8Array(d.ace);#r=new Uint8Array(d.ch);#o=new Uint8Array(d.ch*d.nn);#m=new Uint8Array(d.ch);#c=new Uint16Array(d.pl);#h=new Uint8Array(d.pl);#A=new Int16Array(d.ch);#S=new Uint8Array(d.ch);#_=0;#s=new Uint8Array(d.ch*d.rpn);#I=new Int8Array(d.ch*Z.length);#J=new Uint8Array(d.drm*d.dpn*d.dnc);#x=new Uint8Array(d.ch);#U=new Uint8Array(128);#y=new Uint8Array(d.cmt*8);#X=new Uint8Array(1024);#N=new Uint8Array(d.cmt*64);#$=new Uint8Array(d.efx*3);#G=0;#E=0;#g=100;#v=0;#F=500;#K=0;#C="";#H=0;#V=0;#w=!0;#n=!1;#Z;#te=new Uint8Array(2);#i=[];#R=new Uint8Array(d.ch);#L=new Uint8Array(d.tr);baseBank=new D("gm","gm2","xg","gs","ns5r","gmega","plg-150vl","plg-150pf","plg-150dx","plg-150an","plg-150dr","plg-100sg","kross");userBank=new D("gm");initOnReset=!1;aiEfxName="";chRedir(e,n,o){if(this.#L[n])return(this.#L[n]-1)*16+e;if([2,3].indexOf(this.#E)>-1){if(o==1)return e;let t=0,s=!0;for(;s;)this.#R[e+t]==0?(this.#R[e+t]=n,console.debug(`Assign track ${n} to channel ${e+t+1}.`),s=!1):this.#R[e+t]==n?s=!1:(t+=16,t>=128&&(t=0,s=!1));return e+t}else return e}#d=[];#B;#l={nOff:(e,n)=>{let o=e*128+n,t=this.#c.lastIndexOf(o);t>-1&&(this.#e[d.cc*e+f[64]]>63?(this.#h[t]=this.NOTE_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#o[o],state:this.NOTE_HELD})):this.#e[d.cc*e+f[66]]>63&&this.#h[t]==this.NOTE_SOSTENUTO_SUSTAIN?(this.#h[t]=this.NOTE_SOSTENUTO_HELD,this.dispatchEvent("note",{part:e,note:n,velo:this.#o[o],state:this.NOTE_SOSTENUTO_HELD})):(this.#c[t]=0,this.#o[o]=0,this.#h[t]=this.NOTE_IDLE,this.dispatchEvent("note",{part:e,note:n,velo:0,state:this.NOTE_IDLE})))},nOn:(e,n,o)=>{let t=e*128+n,s=0;for(this.#m[e]&&this.#l.ano(e);this.#h[s]>0&&this.#c[s]!=t;)s++;s{},cAt:(e,n)=>{},hoOf:e=>{this.#h.forEach((n,o)=>{if(n==this.NOTE_HELD){let t=this.#c[o],s=t>>7;e==s&&(this.#h[o]=this.NOTE_IDLE,this.#c[o]=0,this.#o[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},soOn:e=>{this.#h.forEach((n,o)=>{let t;switch(n){case this.NOTE_ATTACK:{t=this.NOTE_SOSTENUTO_ATTACK;break}case this.NOTE_DECAY:{t=this.NOTE_SOSTENUTO_DECAY;break}case this.NOTE_SUSTAIN:{t=this.NOTE_SOSTENUTO_SUSTAIN;break}}if(t){this.#h[o]=t;let s=this.#c[o];this.dispatchEvent("note",{part:e,note:s&127,velo:this.#o[s],state:t})}})},soOf:e=>{this.#h.forEach((n,o)=>{if(n==this.NOTE_SOSTENUTO_HELD){let t=this.#c[o],s=t>>7;e==s&&(this.#h[o]=this.NOTE_IDLE,this.#c[o]=0,this.#o[t]=0,this.dispatchEvent("note",{part:e,note:t&127,velo:0,state:this.NOTE_IDLE}))}})},ano:e=>{this.#c.forEach((n,o,t)=>{let s=n>>7,r=n&127;n==0&&this.#o[0]==0||s==e&&this.#l.nOff(s,r)})}};#j={8:function(e){let n=e.channel,o=e.data[0];this.#l.nOff(n,o)},9:function(e){let n=e.channel;this.#p[n]=1;let o=e.data[0],t=e.data[1];t>0?this.#l.nOn(n,o,t):this.#l.nOff(n,o)},10:function(e){let n=e.channel,o=n*128+e.data[0];this.#c.indexOf(o)>-1&&(this.#o[o]=data[1],this.dispatchEvent("note",{part:n,note:e.data[0],velo:e.data[1],state:this.NOTE_SUSTAIN}))},11:function(e){let n=e.channel;this.#p[n]=1;let o=n*d.cc;switch(e.data[0]){case 96:return;case 97:return;case 120:return;case 121:{this.#l.ano(n),this.#A[n]=0;let t=n*d.cc;this.#e[t+f[1]]=0,this.#e[t+f[5]]=0,this.#e[t+f[64]]=0,this.#e[t+f[65]]=0,this.#e[t+f[66]]=0,this.#e[t+f[67]]=0,this.#e[t+f[11]]=127,this.#e[t+f[101]]=127,this.#e[t+f[100]]=127,this.#e[t+f[99]]=127,this.#e[t+f[98]]=127;return}case 123:{this.#l.ano(n);return}case 124:{this.#l.ano(n);return}case 125:{this.#l.ano(n);return}case 126:{this.#m[n]=1,this.#l.ano(n);return}case 127:{this.#m[n]=0,this.#l.ano(n);return}}if(f[e.data[0]]==null)console.warn(`cc${e.data[0]} is not accepted.`);else{switch(ce.indexOf(e.data[0])>-1&&this.allocateAce(e.data[0]),e.data[0]){case 0:{if(E()&&console.debug(`${m[this.#t]}, CH${n+1}: ${e.data[1]}`),this.#t==0)e.data[1]<48?(this.#a[n]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${n+1} to stay drums.`)),e.data[1]>0&&(console.debug(`Roland GS detected with MSB: ${e.data[1]}`),this.switchMode("gs"))):e.data[1]==62?this.switchMode("x5d"):e.data[1]==63?this.switchMode("krs"):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg");else if(this.#t==p.gs)e.data[1]<56&&this.#a[n]>0&&(e.data[1]=this.#e[o],e.data[1]=120,console.debug(`Forced channel ${n+1} to stay drums.`));else if(this.#t==p.gm)e.data[1]<48?this.#a[n]>0&&(e.data[1]=120,this.switchMode("gs",!0),console.debug(`Forced channel ${n+1} to stay drums.`)):(e.data[1]==64||e.data[1]==127)&&this.switchMode("xg",!0);else if(this.#t==p.x5d){if(e.data[1]>0&&e.data[1]<8)this.switchMode("05rw",!0);else if(e.data[1]==56){let t=0;for(let s=0;s<16;s++){let r=this.#e[d.cc*s];(r==56||r==62)&&t++}t>14&&this.switchMode("ag10",!0)}}switch(this.#t){case p.xg:{[126,127].indexOf(e.data[1])>-1?this.#a[n]==0&&(this.setChType(n,this.CH_DRUM2),console.debug(`CH${n+1} set to drums by MSB.`)):this.#a[n]>0&&(this.setChType(n,this.CH_MELODIC),console.debug(`CH${n+1} set to melodic by MSB.`));break}case p["05rw"]:case p.x5d:case p.ns5r:{[61,62,126,127].indexOf(e.data[1])>-1?this.#a[n]==0&&(this.setChType(n,this.CH_DRUM2),console.debug(`CH${n+1} set to drums by MSB.`)):this.#a[n]>0&&(this.setChType(n,this.CH_MELODIC),console.debug(`CH${n+1} set to melodic by MSB.`));break}case p.g2:{e.data[1]==120?this.#a[n]==0&&(this.setChType(n,this.CH_DRUMS),console.debug(`CH${n+1} set to drums by MSB.`)):this.#a[n]>0&&(this.setChType(n,this.CH_MELODIC),console.debug(`CH${n+1} set to melodic by MSB.`));break}}this.dispatchEvent("voice",{part:n});break}case 6:{if(this.#_){[p.xg,p.gs,p.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 t=this.#e[o+f[99]],s=this.#e[o+f[98]];if(t==1){let r=le.indexOf(s);if(r>-1)this.#e[o+f[71+r]]=e.data[1],E()&&console.debug(`Redirected NRPN 1 ${s} to cc${71+r}.`),this.dispatchEvent("cc",{part:n,cc:71+r,data:e.data[1]});else{let a=Z.indexOf(s);a>-1?this.#I[n*10+a]=e.data[1]-64:console.warn(`NRPN 0x01${s.toString(16).padStart(2,"0")} is not supported.`),E()&&console.debug(`CH${n+1} voice NRPN ${s} commit`)}}else{if(te.indexOf(t)<0){let a=`NRPN 0x${t.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")} `;t==127?console.warn(`${a}is not necessary. Consider removing it.`):console.warn(`${a}is not supported.`)}else{let a=this.#a[n]-2;a<0?console.warn(`CH${n+1} cannot accept drum NRPN as type ${C[this.#a[n]]}.`):this.#J[(a*d.dpn+t)*d.dnc+s]=e.data[1]-64}E()&&console.debug(`CH${n+1} (${C[this.#a[n]]}) drum NRPN ${t} commit`)}}else{let t=H[this.#e[o+f[100]]];this.#e[o+f[101]]==0&&t!=null&&(E()&&console.debug(`CH${n+1} RPN 0 ${this.#e[o+f[100]]} commit: ${e.data[1]}`),e.data[1]=Math.min(Math.max(e.data[1],J[t][0]),J[t][1]),this.#s[n*d.rpn+t]=e.data[1])}break}case 32:{this.dispatchEvent("voice",{part:n});break}case 38:{this.#_||this.#e[o+101]==0&&H[this.#e[o+100]]!=null&&(this.#s[n*d.rpn+H[this.#e[o+100]]+1]=e.data[1]);break}case 64:{e.data[1]<64&&this.#l.hoOf(n);break}case 66:{e.data[1]>>6?this.#l.soOn(n):this.#l.soOf(n);break}case 98:case 99:{this.#_=1;break}case 100:case 101:{this.#_=0;break}}this.#e[o+f[e.data[0]]]=e.data[1],this.dispatchEvent("cc",{part:n,cc:e.data[0],data:e.data[1]})}},12:function(e){let n=e.channel;this.#p[n]=1,this.#r[n]=e.data,this.#x[n]=0,E()&&console.debug(`T:${e.track} C:${n} P:${e.data}`),this.dispatchEvent("voice",{part:n})},13:function(e){let n=this,o=e.channel;this.#c.forEach(function(t){let s=t>>7;o==s&&(n.#o[t]=e.data,n.dispatchEvent("note",{part:o,note:t&127,velo:e.data,state:n.NOTE_SUSTAIN}))})},14:function(e){let n=e.channel;this.#A[n]=e.data[1]*128+e.data[0]-8192,this.dispatchEvent("pitch",{part:n,pitch:this.getPitchShift(n)})},15:function(e){he(e.data).forEach(n=>{let o=n[0],t=n[1];(this.#ee[o]||function(){console.debug(`Unknown manufacturer ${o}.`)})(t,n.subarray(2),e.track)})},248:function(e){},250:function(e){},251:function(e){},252:function(e){},254:function(e){},255:function(e){(this.#d[e.meta]||function(o,t,s){}).call(this,e.data,e.track,e.meta),e.meta!=32&&(this.#v=0);let n=oe.indexOf(e.meta)>-1;if(E()&&console.debug(e),n)return e.reply="meta",e}};#ee={64:(e,n,o)=>{this.#q.run(n,o,e)},65:(e,n,o)=>{if(n[0]<16)this.#D.run(n,o,e),console.warn("Unknown device SysEx!");else{let t=n[n.length-1],s=q(n.subarray(2,n.length-1));t==s?this.#D.run(n.subarray(0,n.length-1),o,e):console.warn(`Bad GS checksum ${t}. Should be ${s}.`)}},66:(e,n,o)=>{this.#P.run(n,o,e)},67:(e,n,o)=>{this.#O.run(n,o,e)},68:(e,n,o)=>{this.#W.run(n,o,e)},71:(e,n,o)=>{this.#Y.run(n,o,e)},126:(e,n,o)=>{this.#z.run(n,o,e)},127:(e,n,o)=>{this.switchMode("gm"),this.#Q.run(n,o,e)}};#z;#Q;#O;#D;#P;#q;#Y;#W;buildRchTree(){let e=[];this.#f.forEach((n,o)=>{e[n]?.constructor||(e[n]=[]),e[n].push(o)}),this.#Z=e}getActive(){let e=this.#p.slice();return this.#t==p.mt32,e}getCc(e){let n=e*d.cc,o=this.#e.subarray(n,n+d.cc);return o[f[0]]=o[f[0]]||this.#G,o[f[32]]=o[f[32]]||this.#E,o}getCcCh(e,n){if(v.indexOf(n)<0)throw new Error("CC number not accepted");return this.#e[d.cc*e+f[n]]}getCcAll(){let e=this.#e.slice();for(let n=0;n0&&(this.#e[e*d.cc+f[0]]=S[o])}getPitch(){return this.#A}getProgram(){return this.#r}getTexts(){return this.#i.slice()}getVel(e){let n=new Map,o=this;return o.#c.forEach(function(t,s){let r=Math.floor(t/128),a=t%128;e==r&&o.#o[t]>0&&n.set(a,{v:o.#o[t],s:o.#h[s]})}),n}getBitmap(){return{bitmap:this.#b,expire:this.#k}}getLetter(){return{text:this.#C,expire:this.#H}}getMode(){return m[this.#t]}getMaster(){return{volume:this.#g}}getRawStrength(){let e=this;return this.#c.forEach(function(n){let o=Math.floor(n/128);e.#o[n]>e.#S[o]&&(e.#S[o]=e.#o[n])}),this.#S}getStrength(){let e=[],n=this;return this.getRawStrength().forEach(function(o,t){e[t]=Math.floor(o*n.#e[t*d.cc+f[7]]*Math.max(n.#e[t*d.cc+f[11]],Math.floor(n.#e[t*d.cc+f[91]]*.5),Math.floor(n.#e[t*d.cc+f[92]]*.65),Math.floor(n.#e[t*d.cc+f[94]]*.8))*n.#g/803288)}),e}getRpn(){return this.#s}getNrpn(){return this.#I}getVoice(e,n,o,t){let s=e||this.#G,r=n,a=o||this.#E;m[this.#t]=="ns5r"&&s>0&&s<56&&(a=3);let i=this.userBank.get(s,r,a,t);if(m[this.#t]=="mt32"&&i.name.indexOf("MT-m:")==0){let c=parseInt(i.name.slice(5)),h=c*d.cmt,l="";this.#N.subarray(h,h+10).forEach(u=>{u>31&&(l+=String.fromCharCode(u))}),this.userBank.load(`MSB LSB PRG +0 127 ${r} ${l}`,!0),i.name=l,i.ending=" "}return(i.ending!=" "||!i.name.length)&&(i=this.baseBank.get(s,r,a,t)),i}getChVoice(e){let n=this.getVoice(this.#e[e*d.cc+f[0]],this.#r[e],this.#e[e*d.cc+f[32]],m[this.#t]);if(this.#x[e])switch(this.#t){case p.mt32:n.ending="~",n.name="",this.#y.subarray(14*(e-1),14*(e-1)+10).forEach(o=>{o>31&&(n.name+=String.fromCharCode(o))})}return n}getPitchShift(e){let n=e*d.rpn;return this.#A[e]/8192*this.#s[n]+(this.#s[n+3]-64)+((this.#s[n+1]<<7)+this.#s[n+2]-8192)/8192}getEffectType(e=0){let n=3*e+1;return this.#$.subarray(n,n+2)}setEffectTypeRaw(e=0,n,o){let t=3*e;this.#$[t]=1,this.#$[t+1+ +n]=o}setEffectType(e=0,n,o){this.setEffectTypeRaw(e,!1,n),this.setEffectTypeRaw(e,!0,o)}setLetterDisplay(e,n,o=0,t=3200){let s=this,r;s.#C=" ".repeat(o),e.forEach(a=>{s.#C+=String.fromCharCode(a>31?a:32),a<32&&(r=r||new Set,r.add(a))}),s.#H=Date.now()+3200,s.#C=s.#C.padEnd(32," "),r&&(r=Array.from(r),r.forEach((a,i,c)=>{c[i]=a.toString(16).padStart(2,"0")}),console.warn(`${n}${n?" ":""}invalid code point${r.length>1?"s":""}: 0x${r.join(", 0x")}`))}allocateAce(e){if(!e||e>95){console.warn(`cc${e} cannot be allocated as an active custom effect.`);return}let n=!0,o=0;for(;n&&o=d.ace&&console.warn("ACE slots are full.")}getAce(){return this.#T}getChAce(e,n){if(n<0||n>=d.ace)throw new RangeError("No such ACE slot");let o=this.#T[n];if(o){if(v.indexOf(o)>=0)return this.#e[e*d.cc+f[o]];throw new Error(`Invalid ACE source: ${o}`)}else return 0}init(e=0){this.dispatchEvent("mode","?"),this.#t=0,this.#G=0,this.#E=0,this.#v=0,this.#p.fill(0),this.#e.fill(0),this.#T.fill(0),this.#r.fill(0),this.#o.fill(0),this.#c.fill(0),this.#S.fill(0),this.#A.fill(0),this.#I.fill(0),this.#J.fill(0),this.#g=100,this.#i=[],this.#F=500,this.#K=0,this.#H=0,this.#C="",this.#k=0,this.#u=0,this.#b.fill(0),this.#n=!1,this.#V=0,this.#w=!0,this.#f.forEach(function(n,o,t){t[o]=o}),this.buildRchTree(),e==0&&(this.#R.fill(0),this.#L.fill(0)),this.#e[d.cc*9]=S[0],this.#e[d.cc*25]=S[0],this.#e[d.cc*41]=S[0],this.#e[d.cc*57]=S[0],this.#a.fill(this.CH_MELODIC),this.#a[9]=this.CH_DRUM1,this.#a[25]=this.CH_DRUM3,this.#a[41]=this.CH_DRUMS,this.#a[57]=this.CH_DRUMS,this.#a[73]=this.CH_DRUM5,this.#a[89]=this.CH_DRUM7,this.#a[105]=this.CH_DRUMS,this.#a[121]=this.CH_DRUMS,this.#X.fill(0),this.#N.fill(0),this.#U.fill(0),this.#y.fill(0),this.#x.fill(0),this.#$.fill(0),this.aiEfxName="",this.userBank.clearRange({msb:0,lsb:127,prg:[0,127]});for(let n=0;n-1){if(this.#t==0||n){let t=this.#t;this.#t=o,this.#u=0,this.#G=Y[0][o],this.#E=Y[1][o];for(let r=0;r0&&this.#e[r*d.cc+f[0]]==S[t]&&(this.#e[r*d.cc]=S[o]);switch(this.initOnReset,o){case p.mt32:{G.forEach((r,a)=>{let i=a+1;this.#p[i]||(this.#r[i]=r,this.#e[i*d.cc+f[91]]=127)});break}}let s;switch(o){case p.gs:{s=[40,4,40,18,40,32,32,0,0,0,0,0,0,0];break}case p.x5d:case p.ns5r:{s=[44,1,44,19,44,0,44,0,0,0,0,0,0,0];break}default:s=[1,0,65,0,5,0,0,0,0,0,0,0,0,0]}for(let r=0;r14)return e.type==15&&e.data.constructor!=Uint8Array&&(e.data=Uint8Array.from(e.data)),this.#j[e.type].call(this,e);{let n=this.chRedir(e.part,e.track),o=!1;this.#Z[n]?.forEach(t=>{e.channel=t,o=!0,this.#j[e.type].call(this,e)}),o||console.warn(`${W[e.type]?W[e.type]:e.type}${[11,12].includes(e.type)?(e.data[0]!=null?e.data[0]:e.data).toString():""} event sent to CH${n+1} without any recipient.`)}this.#i.length>100&&this.#i.splice(100,this.#i.length-99)}runRaw(e){}constructor(){super();let e=this;this.#b=new Uint8Array(256),this.#M[10]=new Uint8Array(512),this.#B=new w,this.userBank.strictMode=!0,this.userBank.load(`MSB PRG LSB NME 062 000 000 122 000 000 122 001 000 @@ -145,7 +145,7 @@ _,`.split(` 122 003 000 122 004 000 122 005 000 -122 006 000 `),this.#d[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#n=!0,this.#i.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#n=!0,this.#i.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#n=!0,this.#i.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#n=!0,this.#i.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#n=!0,this.#i.unshift(`Kara.Ver: ${t.slice(2)}`);break}case"XF":{let s=t.slice(2).split(":");switch(s[0]){case"hd":{s.slice(1).forEach((r,a)=>{r.length&&this.#i.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][a]}: ${r}`)});break}case"ln":{s.slice(1).forEach((r,a)=>{r.length&&this.#i.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][a]}: ${r}`)});break}default:this.#i.unshift(`XGF_Data: ${t}`)}break}default:this.#n?t[0]=="\\"?this.#i.unshift(`@ ${t.slice(1)}`):t[0]=="/"?this.#i.unshift(t.slice(1)):this.#i[0]+=t:(this.#i[0]=t,this.#i.unshift(""))}},this.#d[2]=function(t){this.#i.unshift(`Copyrite: ${t}`)},this.#d[3]=function(t,s){s<1&&this.#v<1&&this.#i.unshift(`TrkTitle: ${t}`)},this.#d[4]=function(t,s){this.#i.unshift(`${ee(this.#v,""," ")}Instrmnt: ${t}`)},this.#d[5]=function(t){t.trim()==""?this.#i.unshift(""):this.#i[0]+=`${t}`},this.#d[6]=function(t){this.#i.unshift(`${ee(this.#v,""," ")}C.Marker: ${t}`)},this.#d[7]=function(t){this.#i.unshift(`CuePoint: ${t}`)},this.#d[32]=function(t){this.#v=t[0]+1},this.#d[33]=function(t,s){console.debug(`Track ${s} requests to get assigned to output ${t}.`),e.#L[s]=t+1},this.#d[81]=function(t,s){e.#F=t/1e3},this.#d[127]=function(t,s){e.#B.run(t,s)},this.#B.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#B.add([67,0,1],function(t,s){e.#L[s]=t[0]+1}),this.#z=new w,this.#Q=new w,this.#O=new w,this.#D=new w,this.#P=new w,this.#q=new w,this.#Y=new w,this.#W=new w,this.#z.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#n=e.#n||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#Q.add([4,1],t=>{e.#g=((t[1]<<7)+t[0])/16383*100}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#O.add([76,0,0],t=>{switch(t[0]){case 126:{e.switchMode("xg",!0),e.#n=!1,console.info("MIDI reset: XG");break}default:{let s=[0,0,0,0],r=(a,i)=>{s[i]=a};if(t.subarray(1).forEach((a,i)=>{let c=i+t[0];([r,r,r,r,h=>{this.#g=h*129/16383*100},h=>{},h=>{}][c]||(()=>{}))(a,i)}),t[0]<4){let a=0;s.forEach(i=>{a=a<<4,a+=i}),a-=1024}}}}).add([76,2,1],t=>{let s="XG ";t[0]<32?(s+="reverb ",t.subarray(1).forEach((r,a)=>{([i=>{e.setEffectTypeRaw(0,!1,i),console.info(`${s}main type: ${x[i]}`)},i=>{e.setEffectTypeRaw(0,!0,i),console.debug(`${s}sub type: ${i+1}`)},i=>{console.debug(`${s}time: ${B(i)}s`)},i=>{console.debug(`${s}diffusion: ${i}`)},i=>{console.debug(`${s}initial delay: ${i}`)},i=>{console.debug(`${s}HPF cutoff: ${M[i]}Hz`)},i=>{console.debug(`${s}LPF cutoff: ${M[i]}Hz`)},i=>{console.debug(`${s}width: ${i}`)},i=>{console.debug(`${s}height: ${i}`)},i=>{console.debug(`${s}depth: ${i}`)},i=>{console.debug(`${s}wall type: ${i}`)},i=>{console.debug(`${s}dry/wet: ${i}`)},i=>{console.debug(`${s}send: ${y(i)}dB`)},i=>{console.debug(`${s}pan: ${i-64}`)},!1,!1,i=>{console.debug(`${s}delay: ${i}`)},i=>{console.debug(`${s}density: ${i}`)},i=>{console.debug(`${s}balance: ${i}`)},i=>{},i=>{console.debug(`${s}feedback: ${i}`)},i=>{}][t[0]+a]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(r)})):t[0]<64?(s+="chorus ",t.subarray(1).forEach((r,a)=>{([i=>{e.setEffectTypeRaw(1,!1,i),console.info(`${s}main type: ${x[i]}`)},i=>{e.setEffectTypeRaw(1,!0,i),console.debug(`${s}sub type: ${i+1}`)},i=>{console.debug(`${s}LFO: ${_[i]}Hz`)},i=>{},i=>{console.debug(`${s}feedback: ${i}`)},i=>{console.debug(`${s}delay offset: ${I(i)}ms`)},i=>{},i=>{console.debug(`${s}low: ${M[i]}Hz`)},i=>{console.debug(`${s}low: ${i-64}dB`)},i=>{console.debug(`${s}high: ${M[i]}Hz`)},i=>{console.debug(`${s}high: ${i-64}dB`)},i=>{console.debug(`${s}dry/wet: ${i}`)},i=>{console.debug(`${s}send: ${y(i)}dB`)},i=>{console.debug(`${s}pan: ${i-64}`)},i=>{console.debug(`${s}to reverb: ${y(i)}dB`)},!1,i=>{},i=>{},i=>{},i=>{console.debug(`${s}LFO phase diff: ${(i-64)*3}deg`)},i=>{console.debug(`${s}input mode: ${i?"stereo":"mono"}`)},i=>{}][t[0]-32+a]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(r)})):t[0]<86?(s+="variation ",t.subarray(1).forEach((r,a)=>{([i=>{e.setEffectTypeRaw(2,!1,i),console.info(`${s}main type: ${x[i]}`)},i=>{e.setEffectTypeRaw(2,!0,i),console.debug(`${s}sub type: ${i+1}`)}][t[0]-64+a]||function(){})(r)})):t[0]<97?(s+="variation ",t.subarray(1).forEach((r,a)=>{[i=>{console.debug(`${s}send: ${y(i)}dB`)},i=>{console.debug(`${s}pan: ${i-64}`)},i=>{console.debug(`${s}to reverb: ${y(i)}dB`)},i=>{console.debug(`${s}to chorus: ${y(i)}dB`)},i=>{console.debug(`${s}connection: ${i?"system":"insertion"}`)},i=>{console.debug(`${s}channel: CH${i+1}`)},i=>{console.debug(`${s}mod wheel: ${i-64}`)},i=>{console.debug(`${s}bend wheel: ${i-64}`)},i=>{console.debug(`${s}channel after touch: ${i-64}`)},i=>{console.debug(`${s}AC1: ${i-64}`)},i=>{console.debug(`${s}AC2: ${i-64}`)}][t[0]-86+a](r)})):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,r)=>{let a=r+t[0];if(a==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][s]}`);else{let i=a-1>>2,c=a-1&3,h=`XG EQ ${i} ${["gain","freq","Q","shape"][c]}: `;[()=>{console.debug(`${h}${s-64}dB`)},()=>{console.debug(`${h}${s} (raw)`)},()=>{console.debug(`${h}${s/10}`)},()=>{console.debug(`${h}${["shelf","peak"][+!!s]}`)}][c]()}})}).add([76,3],t=>{let s=t[0],r=t[1],a=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((i,c)=>{([h=>{e.setEffectTypeRaw(3+s,!1,h),console.info(`${a}main type: ${x[h]}`)},h=>{e.setEffectTypeRaw(3+s,!0,h),console.debug(`${a}sub type: ${h+1}`)}][r+c]||function(){})(i)})}).add([76,6,0],t=>{let s=t[0];s<64?e.setLetterDisplay(t.subarray(1),"XG letter display",s):e.#H=Date.now()}).add([76,7,0],t=>{let s=t[0];e.#u=0,e.#k=Date.now()+3200,e.#b.fill(0);let r=t.subarray(1);for(let a=0;a>6-b&1,b++})}).add([76,8],(t,s)=>{let r=e.chRedir(t[0],s,!0),a=t[1],i=d.cc*r,c=`XG CH${r+1} `,h=`Unknown XG part address ${a}.`;t.subarray(2).forEach((l,u)=>{a<1?console.debug(h):a<41?([()=>{e.#e[i+f[0]]=l},()=>{e.#e[i+f[32]]=l},()=>{e.#r[r]=l},()=>{let b=e.chRedir(l,s,!0);e.#f[r]=b,r!=b&&(e.buildRchTree(),console.info(`${c}receives from CH${b+1}`))},()=>{e.#m[r]=+!l},()=>{},()=>{e.setChType(r,l,p.xg),console.debug(`${c}type: ${C[l]||l}`)},()=>{e.#s[d.rpn*r+3]=l},!1,!1,()=>{e.#e[i+f[7]]=l},!1,!1,()=>{e.#e[i+f[10]]=l||128},!1,!1,()=>{e.#e[i+f[11]]=l},()=>{e.#e[i+f[93]]=l},()=>{e.#e[i+f[91]]=l},()=>{e.#e[i+f[94]]=l},()=>{e.#e[i+f[76]]=l},()=>{e.#e[i+f[77]]=l},()=>{e.#e[i+f[78]]=l},()=>{e.#e[i+f[74]]=l},()=>{e.#e[i+f[71]]=l},()=>{e.#e[i+f[73]]=l},()=>{e.#e[i+f[75]]=l},()=>{e.#e[i+f[72]]=l}][a+u-1]||(()=>{}))():a<48?console.debug(h):a<111?a>102&&a<105&&(e.#e[i+f[[5,65][a&1]]]=l):a<114?console.debug(h):a<116?console.debug(`${c}EQ ${["bass","treble"][a&1]} gain: ${l-64}dB`):a<118?console.debug(h):a<120?console.debug(`${c}EQ ${["bass","treble"][a&1]} freq: ${l}`):console.debug(h)})}).add([76,9],(t,s)=>{let r=e.chRedir(t[0],s,!0),a=t[1],i=`PLG-150VL CH${r+1} `;t.subarray(2).forEach((c,h)=>{let l=h+a;switch(l){case 1:{console.info(`${i}breath mode: ${["system","breath","velocity","touch EG"][c]}`);break}case 0:case 27:case 28:break;default:if(l<27){let u=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${i}${u} control source: ${K(c)}`),c&&c<96&&e.allocateAce(c)):console.debug(`${i}${u} scale break point: ${c}`):console.debug(`${i}${u} 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 r=t[0];t.subarray(1).forEach((a,i)=>{let c=r+i;c==8?console.debug(`MU1000 set LCD contrast to ${a}.`):c>9&&c<16&&[()=>{e.dispatchEvent("channelactive",a)},()=>{a<8?(e.dispatchEvent("channelmin",a<<4),console.info(`Octavia System: Minimum CH${(a<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{a<8?(e.dispatchEvent("channelmax",(a<<4)+15),console.info(`Octavia System: Maximum CH${(a<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#w=!!a,console.info(`Octavia System: RS receiving ${["dis","en"][a]}abled.`)}][c-10]()})}).add([73,10,0],(t,s)=>{let r=t[0],a=`MU1000 RS${e.#w?"":" (ignored)"}: `;if(r<16)switch(r){case 2:{let i=e.chRedir(0,s,!0);e.#w&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+63)),console.info(`${a}Show CH1~64`);break}case 3:{let i=e.chRedir(t[1]<<5,s,!0);e.#w&&e.dispatchEvent("channelmin",i),e.#w&&e.dispatchEvent("channelmax",i+31),console.info(`${a}Show CH${i+1}~CH${i+32}`);break}default:console.debug(`${a}unknown switch ${r} invoked.`)}else if(r<32){if(e.#w){let i=e.chRedir(r-16+(e.#V<<4),s,!0);e.dispatchEvent("channelactive",i)}}else if(r<36){let i=e.chRedir(r-32<<4,s,!0);e.#w&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+15),e.#V=r-32),console.info(`${a}Show CH${i+1}~CH${i+16}`)}}).add([93,3],(t,s)=>{let r=e.chRedir(t[0],s,!0),a=`PLG-100SG CH${r+1} `,i=Date.now();if(t[1]==0){let c="",h=0;t.subarray(2).forEach((l,u)=>{u%2==0?c+=X[l]||l.toString().padStart("0"):h+=l*13}),i>=e.#K&&e.#i.unshift("SG Lyric: "),e.#i[0]+=`${F(c)}`,e.#K=i+Math.ceil(h/2)+e.#F,E()&&console.debug(`${a}vocals: ${c}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}),this.#O.add([76,48],t=>{}).add([76,49],t=>{}).add([76,50],t=>{}).add([76,51],t=>{}),this.#O.add([89,0],(t,s,r)=>{if(e.eprom){let a=t[0],i=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);E()&&console.debug(`MU1000 EPROM trail to 0x${i.toString(16).padStart(6,"0")}, ${a} bytes.`);let c=e.eprom.data;t.subarray(4).forEach((h,l)=>{let u=l>>3,b=l&7;if(b==7)for(let $=0;$<7;$++)c[i+7*u+$]+=(h>>6-$&1)<<7;else c[i+7*u+b]=h})}}).add([89,1],(t,s,r)=>{let a=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];E()&&console.debug(`MU1000 EPROM jump to 0x${a.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=a)}).add([89,2],(t,s,r)=>{if(e.eprom){let a=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);E()&&console.debug(`MU1000 EPROM write to 0x${a.toString(16).padStart(6,"0")}.`);let i=e.eprom.data;t.subarray(4).forEach((c,h)=>{let l=h>>3,u=h&7;if(u==7)for(let b=0;b<7;b++)i[a+7*l+b]+=(c>>6-b&1)<<7;else i[a+7*l+u]=c})}}).add([89,3],(t,s,r)=>{}),this.#O.add([39,48],(t,s,r)=>{}).add([43,0,0],(t,s,r)=>{let a=[0,0,0,0],i=(c,h)=>{a[h]=c};if(t.subarray(1).forEach((c,h)=>{let l=h+t[0];[i,i,i,i,()=>{this.#g=c*129/16383*100},()=>c-64,()=>c||128,()=>c,()=>c,()=>{console.debug(`TG300 variation on cc${c}.`)}][l](c,l)}),t[0]<4){let c=0;a.forEach(h=>{c=c<<4,c+=h}),c-=1024}}).add([43,1,0],(t,s,r)=>{}).add([43,2],(t,s,r)=>{let a=e.chRedir(t[0],s,!0),i=t[1],c=d.cc*a,h=`TG300 CH${a+1} `;t.subarray(2).forEach((l,u)=>{u<5?([()=>{},()=>{e.#e[c+f[0]]=l},()=>{e.#e[c+f[32]]=l},()=>{e.#r[a]=l},()=>{let b=e.chRedir(l,s,!0);e.#f[a]=b,a!=b&&(e.buildRchTree(),console.info(`${h}receives from CH${b+1}`))}][u+i]||(()=>{}))(l,u+i):u<21||(u<47?([()=>{e.#m[a]=+!l},()=>{},()=>{},()=>{e.#s[d.rpn*a+3]=l},()=>{},()=>{e.#e[c+f[7]]=l},!1,!1,()=>{e.#e[c+f[10]]=l||128},!1,!1,()=>{console.debug(`${h} AC1 at cc${l}`)},()=>{console.debug(`${h} AC2 at cc${l}`)},()=>{e.#e[c+f[11]]=l},()=>{e.#e[c+f[93]]=l},()=>{e.#e[c+f[91]]=l},()=>{e.#e[c+f[94]]=l},()=>{e.#e[c+f[76]]=l},()=>{e.#e[c+f[77]]=l},()=>{e.#e[c+f[74]]=l},()=>{e.#e[c+f[71]]=l},()=>{e.#e[c+f[73]]=l},()=>{e.#e[c+f[75]]=l},()=>{e.#e[c+f[72]]=l},()=>{e.#e[c+f[78]]=l}][u+i-21]||(()=>{}))(l,u+i):u<95||([()=>{e.#e[c+f[65]]=l},()=>{e.#e[c+f[5]]=l}][u+i-95]||(()=>{}))(l,u+i))})}).add([43,7,0],(t,s,r)=>{let a=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",a)}).add([43,7,1],(t,s,r)=>{e.#u=0,e.#k=Date.now()+3200,e.#b.fill(0),t.forEach(function(a,i){let c=Math.floor(i/16),h=i%16,l=(h*3+c)*7,u=7,b=0;for(l-=h*5,c==2&&(u=2);b>6-b&1,b++})}),this.#D.add([66,18,0,0,127],(t,s,r)=>{e.switchMode("gs",!0),e.#e[d.cc*9]=120,e.#e[d.cc*25]=120,e.#e[d.cc*41]=120,e.#e[d.cc*57]=120,e.#E=3,e.#n=!1,e.#R.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,s,r)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[d.cc*9]=120,e.#e[d.cc*25]=120,e.#e[d.cc*41]=120,e.#e[d.cc*57]=120,e.#n=!1,e.#R.fill(0),console.info("MIDI reset: GS");break}default:{let a=[0,0,0,0],i=(c,h)=>{a[h]=c};if(t.subarray(1).forEach((c,h)=>{let l=h+t[0];[i,i,i,i,u=>{this.#g=u*129/16383*100},u=>{},u=>{}][l](c,h)}),t[0]<4){let c=0;a.forEach(h=>{c=c<<4,c+=h}),c-=1024}}}}).add([66,18,64,1],t=>{let s=t[0];if(s<16){let r="".padStart(s," ");t.subarray(1).forEach((a,i)=>{r+=String.fromCharCode(Math.max(32,a))}),r=r.padEnd(16," "),console.debug(`GS patch name: ${r}`)}else s<48||(s<65?t.subarray(1).forEach((r,a)=>{let i=`GS ${s+a>55?"chorus":"reverb"} `;([()=>{console.info(`${i}type: ${U[r]}`),e.setEffectType(0,40,r)},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${i}predelay: ${r}ms`)},()=>{console.info(`${i}type: ${V[r]}`),e.setEffectType(1,40,16+r)},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${i}to reverb: ${y(r)}`)},()=>{console.debug(`${i}to delay: ${y(r)}`)}][s+a-48]||(()=>{}))()}):s<80?console.debug(`Unknown GS patch address: ${s}`):s<91?t.subarray(1).forEach((r,a)=>{let i="GS delay ";([()=>{console.info(`${i}type: ${z[r]}`),e.setEffectType(2,40,32+r)},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${i}to reverb: ${y(r)}`)}][s+a-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${s}`))}).add([66,18,64,2],t=>{let s="GS EQ ";t.subarray(1).forEach((r,a)=>{([()=>{console.debug(`${s}low freq: ${[200,400][r]}Hz`)},()=>{console.debug(`${s}low gain: ${r-64}dB`)},()=>{console.debug(`${s}high freq: ${[3e3,6e3][r]}Hz`)},()=>{console.debug(`${s}high gain: ${r-64}dB`)}][t[0]+a]||function(){console.warn(`Unknown GS EQ address: ${t[0]+a}`)})()})}).add([66,18,64,3],t=>{let s="GS EFX ",r=function(a,i){let c=Q(e.#$.subarray(10,12),i,a);c&&console.debug(`${s}${N(e.#$.subarray(10,12))} ${c}`)};t.subarray(1).forEach((a,i)=>{([()=>{e.setEffectTypeRaw(3,!1,32+a)},()=>{e.setEffectTypeRaw(3,!0,a),console.info(`${s}type: ${N(e.#$.subarray(10,12))}`)},!1,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,()=>{console.debug(`${s}to reverb: ${y(a)}dB`)},()=>{console.debug(`${s}to chorus: ${y(a)}dB`)},()=>{console.debug(`${s}to delay: ${y(a)}dB`)},!1,()=>{console.debug(`${s}1 source: ${a}`),a&&a<96&&e.allocateAce(a)},()=>{console.debug(`${s}1 depth: ${a-64}`)},()=>{console.debug(`${s}2 source: ${a}`),a&&a<96&&e.allocateAce(a)},()=>{console.debug(`${s}2 depth: ${a-64}`)},()=>{console.debug(`${s}to EQ: ${a?"ON":"OFF"}`)}][t[0]+i]||function(c,h){console.warn(`Unknown GS EFX address: ${h}`)})(a,t[0]+i)})}).add([66,18,65],t=>{}).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.#k=Date.now()+3200,t[1]==0&&(e.#u=Math.max(Math.min(t[2]-1,9),0));break}default:if(t[0]<11){e.#u>9&&(e.#u=0),e.#k=Date.now()+3200,e.#M[t[0]-1]?.length||(e.#M[t[0]-1]=new Uint8Array(256));let s=e.#M[t[0]-1],r=t[1];s.fill(0);let a=t.subarray(2);for(let i=0;i>4-$&1,$++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let n=function(t,s,r){let a=t[0],i=d.cc*s,c=d.rpn*s,h=`GS CH${s+1} `;a<3?t.subarray(1).forEach((l,u)=>{[()=>{e.#e[i+f[0]]=l},()=>{e.#r[s]=l},()=>{let b=e.chRedir(l,r,!0);e.#f[s]=b,s!=b&&(e.buildRchTree(),console.info(`${h}receives from CH${b+1}`))}][a+u]()}):a<19||(a<44?t.subarray(1).forEach((l,u)=>{([()=>{e.#m[s]=+!l},!1,()=>{e.setChType(s,l?l<<1:0,p.gs),console.debug(`${h}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{e.#s[c+3]=l},!1,()=>{e.#e[i+f[7]]=l},!1,!1,()=>{e.#e[i+f[10]]=l||128},!1,!1,()=>{console.debug(`${h}CC 1: cc${l}`)},()=>{console.debug(`${h}CC 2: cc${l}`)},()=>{e.#e[i+f[93]]=l},()=>{e.#e[i+f[91]]=l},!1,!1,()=>{e.#s[c+1]=l},()=>{e.#s[c+2]=l},()=>{e.#e[i+f[94]]=l}][a+u-19]||(()=>{}))()}):a<76||console.debug(`Unknown GS part address: ${a}`))},o=function(t,s){let r=t[0],a=`GS CH${s+1} `;r<2?t.subarray(1).forEach((i,c)=>{[()=>{e.#e[d.cc*s+f[32]]=i},()=>{}][r+c]()}):r<32?console.warn(`Unknown GS misc address: ${r}`):r<35?t.subarray(1).forEach((i,c)=>{[()=>{console.debug(`${a}EQ: o${["ff","n"][i]}`)},()=>{},()=>{console.debug(`${a}EFX: o${["ff","n"][i]}`)}][r+c-32]()}):console.warn(`Unknown GS misc address: ${r}`)};this.#D.add([66,18,64,16],(t,s)=>{n(t,e.chRedir(9,s,!0),s)}).add([66,18,64,17],(t,s)=>{n(t,e.chRedir(0,s,!0),s)}).add([66,18,64,18],(t,s)=>{n(t,e.chRedir(1,s,!0),s)}).add([66,18,64,19],(t,s)=>{n(t,e.chRedir(2,s,!0),s)}).add([66,18,64,20],(t,s)=>{n(t,e.chRedir(3,s,!0),s)}).add([66,18,64,21],(t,s)=>{n(t,e.chRedir(4,s,!0),s)}).add([66,18,64,22],(t,s)=>{n(t,e.chRedir(5,s,!0),s)}).add([66,18,64,23],(t,s)=>{n(t,e.chRedir(6,s,!0),s)}).add([66,18,64,24],(t,s)=>{n(t,e.chRedir(7,s,!0),s)}).add([66,18,64,25],(t,s)=>{n(t,e.chRedir(8,s,!0),s)}).add([66,18,64,26],(t,s)=>{n(t,e.chRedir(10,s,!0),s)}).add([66,18,64,27],(t,s)=>{n(t,e.chRedir(11,s,!0),s)}).add([66,18,64,28],(t,s)=>{n(t,e.chRedir(12,s,!0),s)}).add([66,18,64,29],(t,s)=>{n(t,e.chRedir(13,s,!0),s)}).add([66,18,64,30],(t,s)=>{n(t,e.chRedir(14,s,!0),s)}).add([66,18,64,31],(t,s)=>{n(t,e.chRedir(15,s,!0),s)}).add([66,18,64,64],(t,s)=>{o(t,e.chRedir(9,s,!0))}).add([66,18,64,65],(t,s)=>{o(t,e.chRedir(0,s,!0))}).add([66,18,64,66],(t,s)=>{o(t,e.chRedir(1,s,!0))}).add([66,18,64,67],(t,s)=>{o(t,e.chRedir(2,s,!0))}).add([66,18,64,68],(t,s)=>{o(t,e.chRedir(3,s,!0))}).add([66,18,64,69],(t,s)=>{o(t,e.chRedir(4,s,!0))}).add([66,18,64,70],(t,s)=>{o(t,e.chRedir(5,s,!0))}).add([66,18,64,71],(t,s)=>{o(t,e.chRedir(6,s,!0))}).add([66,18,64,72],(t,s)=>{o(t,e.chRedir(7,s,!0))}).add([66,18,64,73],(t,s)=>{o(t,e.chRedir(8,s,!0))}).add([66,18,64,74],(t,s)=>{o(t,e.chRedir(10,s,!0))}).add([66,18,64,75],(t,s)=>{o(t,e.chRedir(11,s,!0))}).add([66,18,64,76],(t,s)=>{o(t,e.chRedir(12,s,!0))}).add([66,18,64,77],(t,s)=>{o(t,e.chRedir(13,s,!0))}).add([66,18,64,78],(t,s)=>{o(t,e.chRedir(14,s,!0))}).add([66,18,64,79],(t,s)=>{o(t,e.chRedir(15,s,!0))}),this.#P.add([54,65],(t,s)=>{e.switchMode("x5d");let r=(t[1]<<7)+t[0],a=(t[3]<<7)+t[2],i=e.chRedir(r&15,s,!0),c=d.cc*i;[()=>{a<1||(a<101?(e.setChType(i,e.CH_MELODIC,p.x5d),e.#r[i]=a-1,e.#e[c+f[0]]=82):a<229?(e.setChType(i,e.CH_MELODIC,p.x5d),e.#r[i]=a-101,e.#e[c+f[0]]=56):(e.setChType(i,e.CH_DRUMS,p.x5d),e.#r[i]=j[a-229]||0,e.#e[c+f[0]]=62))},()=>{e.#e[c+f[7]]=a},()=>{a<31&&(e.#e[c+f[10]]=Math.round((a-15)*4.2+64))},()=>{e.#e[c+f[93]]=T(a)},()=>{e.#e[c+f[91]]=T(a)},()=>{e.#s[i*d.rpn+3]=a>8191?a-16320:64+a},()=>{e.#s[i*d.rpn+1]=a>8191?a-16320:64+a},()=>{a>0&&(e.#s[i*d.rpn]=a)},()=>{}][r>>4]()}).add([54,76,0],(t,s)=>{e.switchMode("x5d",!0);let r="",a=82,i=0,c=0,h="MSB PRG LSB NME";k(t,function(l,u){if(u<16400){let b=u%164;switch(!0){case b<10:{l>31&&(r+=String.fromCharCode(l));break}case b==11:{h+=` +122 006 000 `),this.#d[1]=function(t){switch(t.slice(0,2)){case"@I":{this.#n=!0,this.#i.unshift(`Kar.Info: ${t.slice(2)}`);break}case"@K":{this.#n=!0,this.#i.unshift("Karaoke mode active."),console.debug(`Karaoke mode active: ${t.slice(2)}`);break}case"@L":{this.#n=!0,this.#i.unshift(`Language: ${t.slice(2)}`);break}case"@T":{this.#n=!0,this.#i.unshift(`Ka.Title: ${t.slice(2)}`);break}case"@V":{this.#n=!0,this.#i.unshift(`Kara.Ver: ${t.slice(2)}`);break}case"XF":{let s=t.slice(2).split(":");switch(s[0]){case"hd":{s.slice(1).forEach((r,a)=>{r.length&&this.#i.unshift(`${["SongDate","SnRegion","SongCat.","SongBeat","SongInst","Sn.Vocal","SongCmp.","SongLrc.","SongArr.","SongPerf","SongPrg.","SongTags"][a]}: ${r}`)});break}case"ln":{s.slice(1).forEach((r,a)=>{r.length&&this.#i.unshift(`${["Kar.Lang","Kar.Name","Kar.Cmp.","Kar.Lrc.","kar.Arr.","Kar.Perf","Kar.Prg."][a]}: ${r}`)});break}default:this.#i.unshift(`XGF_Data: ${t}`)}break}default:this.#n?t[0]=="\\"?this.#i.unshift(`@ ${t.slice(1)}`):t[0]=="/"?this.#i.unshift(t.slice(1)):this.#i[0]+=t:(this.#i[0]=t,this.#i.unshift(""))}},this.#d[2]=function(t){this.#i.unshift(`Copyrite: ${t}`)},this.#d[3]=function(t,s){s<1&&this.#v<1&&this.#i.unshift(`TrkTitle: ${t}`)},this.#d[4]=function(t,s){this.#i.unshift(`${ee(this.#v,""," ")}Instrmnt: ${t}`)},this.#d[5]=function(t){t.trim()==""?this.#i.unshift(""):this.#i[0]+=`${t}`},this.#d[6]=function(t){this.#i.unshift(`${ee(this.#v,""," ")}C.Marker: ${t}`)},this.#d[7]=function(t){this.#i.unshift(`CuePoint: ${t}`)},this.#d[32]=function(t){this.#v=t[0]+1},this.#d[33]=function(t,s){console.debug(`Track ${s} requests to get assigned to output ${t}.`),e.#L[s]=t+1},this.#d[81]=function(t,s){e.#F=t/1e3},this.#d[127]=function(t,s){e.#B.run(t,s)},this.#B.default=function(t){console.warn(`Unrecognized sequencer-specific byte sequence: ${t}`)},this.#B.add([67,0,1],function(t,s){e.#L[s]=t[0]+1}),this.#z=new w,this.#Q=new w,this.#O=new w,this.#D=new w,this.#P=new w,this.#q=new w,this.#Y=new w,this.#W=new w,this.#z.add([9],t=>{e.switchMode(["gm","?","g2"][t[0]-1],!0),e.#n=e.#n||!1,console.info(`MIDI reset: ${["GM","Init","GM2"][t[0]-1]}`),t[0]==2&&e.init()}),this.#Q.add([4,1],t=>{e.#g=((t[1]<<7)+t[0])/16383*100}).add([4,3],t=>((t[1]<<7)+t[0]-8192)/8192).add([4,4],t=>t[1]-64),this.#O.add([76,0,0],t=>{switch(t[0]){case 126:{e.switchMode("xg",!0),e.#n=!1,console.info("MIDI reset: XG");break}default:{let s=[0,0,0,0],r=(a,i)=>{s[i]=a};if(t.subarray(1).forEach((a,i)=>{let c=i+t[0];([r,r,r,r,h=>{this.#g=h*129/16383*100},h=>{},h=>{}][c]||(()=>{}))(a,i)}),t[0]<4){let a=0;s.forEach(i=>{a=a<<4,a+=i}),a-=1024}}}}).add([76,2,1],t=>{let s="XG ";t[0]<32?(s+="reverb ",t.subarray(1).forEach((r,a)=>{([i=>{e.setEffectTypeRaw(0,!1,i),console.info(`${s}main type: ${x[i]}`)},i=>{e.setEffectTypeRaw(0,!0,i),console.debug(`${s}sub type: ${i+1}`)},i=>{console.debug(`${s}time: ${B(i)}s`)},i=>{console.debug(`${s}diffusion: ${i}`)},i=>{console.debug(`${s}initial delay: ${i}`)},i=>{console.debug(`${s}HPF cutoff: ${M[i]}Hz`)},i=>{console.debug(`${s}LPF cutoff: ${M[i]}Hz`)},i=>{console.debug(`${s}width: ${i}`)},i=>{console.debug(`${s}height: ${i}`)},i=>{console.debug(`${s}depth: ${i}`)},i=>{console.debug(`${s}wall type: ${i}`)},i=>{console.debug(`${s}dry/wet: ${i}`)},i=>{console.debug(`${s}send: ${y(i)}dB`)},i=>{console.debug(`${s}pan: ${i-64}`)},!1,!1,i=>{console.debug(`${s}delay: ${i}`)},i=>{console.debug(`${s}density: ${i}`)},i=>{console.debug(`${s}balance: ${i}`)},i=>{},i=>{console.debug(`${s}feedback: ${i}`)},i=>{}][t[0]+a]||function(){console.warn(`Unknown XG reverb address: ${t[0]}.`)})(r)})):t[0]<64?(s+="chorus ",t.subarray(1).forEach((r,a)=>{([i=>{e.setEffectTypeRaw(1,!1,i),console.info(`${s}main type: ${x[i]}`)},i=>{e.setEffectTypeRaw(1,!0,i),console.debug(`${s}sub type: ${i+1}`)},i=>{console.debug(`${s}LFO: ${_[i]}Hz`)},i=>{},i=>{console.debug(`${s}feedback: ${i}`)},i=>{console.debug(`${s}delay offset: ${I(i)}ms`)},i=>{},i=>{console.debug(`${s}low: ${M[i]}Hz`)},i=>{console.debug(`${s}low: ${i-64}dB`)},i=>{console.debug(`${s}high: ${M[i]}Hz`)},i=>{console.debug(`${s}high: ${i-64}dB`)},i=>{console.debug(`${s}dry/wet: ${i}`)},i=>{console.debug(`${s}send: ${y(i)}dB`)},i=>{console.debug(`${s}pan: ${i-64}`)},i=>{console.debug(`${s}to reverb: ${y(i)}dB`)},!1,i=>{},i=>{},i=>{},i=>{console.debug(`${s}LFO phase diff: ${(i-64)*3}deg`)},i=>{console.debug(`${s}input mode: ${i?"stereo":"mono"}`)},i=>{}][t[0]-32+a]||function(){console.warn(`Unknown XG chorus address: ${t[0]}.`)})(r)})):t[0]<86?(s+="variation ",t.subarray(1).forEach((r,a)=>{([i=>{e.setEffectTypeRaw(2,!1,i),console.info(`${s}main type: ${x[i]}`)},i=>{e.setEffectTypeRaw(2,!0,i),console.debug(`${s}sub type: ${i+1}`)}][t[0]-64+a]||function(){})(r)})):t[0]<97?(s+="variation ",t.subarray(1).forEach((r,a)=>{[i=>{console.debug(`${s}send: ${y(i)}dB`)},i=>{console.debug(`${s}pan: ${i-64}`)},i=>{console.debug(`${s}to reverb: ${y(i)}dB`)},i=>{console.debug(`${s}to chorus: ${y(i)}dB`)},i=>{console.debug(`${s}connection: ${i?"system":"insertion"}`)},i=>{console.debug(`${s}channel: CH${i+1}`)},i=>{console.debug(`${s}mod wheel: ${i-64}`)},i=>{console.debug(`${s}bend wheel: ${i-64}`)},i=>{console.debug(`${s}channel after touch: ${i-64}`)},i=>{console.debug(`${s}AC1: ${i-64}`)},i=>{console.debug(`${s}AC2: ${i-64}`)}][t[0]-86+a](r)})):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,r)=>{let a=r+t[0];if(a==0)console.debug(`XG EQ preset: ${["flat","jazz","pop","rock","classic"][s]}`);else{let i=a-1>>2,c=a-1&3,h=`XG EQ ${i} ${["gain","freq","Q","shape"][c]}: `;[()=>{console.debug(`${h}${s-64}dB`)},()=>{console.debug(`${h}${s} (raw)`)},()=>{console.debug(`${h}${s/10}`)},()=>{console.debug(`${h}${["shelf","peak"][+!!s]}`)}][c]()}})}).add([76,3],t=>{let s=t[0],r=t[1],a=`XG Insertion ${t[0]+1} `;t.subarray(2).forEach((i,c)=>{([h=>{e.setEffectTypeRaw(3+s,!1,h),console.info(`${a}main type: ${x[h]}`)},h=>{e.setEffectTypeRaw(3+s,!0,h),console.debug(`${a}sub type: ${h+1}`)}][r+c]||function(){})(i)})}).add([76,6,0],t=>{let s=t[0];s<64?e.setLetterDisplay(t.subarray(1),"XG letter display",s):e.#H=Date.now()}).add([76,7,0],t=>{let s=t[0];e.#u=0,e.#k=Date.now()+3200,e.#b.fill(0);let r=t.subarray(1);for(let a=0;a>6-b&1,b++})}).add([76,8],(t,s)=>{let r=e.chRedir(t[0],s,!0),a=t[1],i=d.cc*r,c=`XG CH${r+1} `,h=`Unknown XG part address ${a}.`;t.subarray(2).forEach((l,u)=>{a<1?console.debug(h):a<41?([()=>{e.#e[i+f[0]]=l},()=>{e.#e[i+f[32]]=l},()=>{e.#r[r]=l},()=>{let b=e.chRedir(l,s,!0);e.#f[r]=b,r!=b&&(e.buildRchTree(),console.info(`${c}receives from CH${b+1}`))},()=>{e.#m[r]=+!l},()=>{},()=>{e.setChType(r,l,p.xg),console.debug(`${c}type: ${C[l]||l}`)},()=>{e.#s[d.rpn*r+3]=l},!1,!1,()=>{e.#e[i+f[7]]=l},!1,!1,()=>{e.#e[i+f[10]]=l||128},!1,!1,()=>{e.#e[i+f[11]]=l},()=>{e.#e[i+f[93]]=l},()=>{e.#e[i+f[91]]=l},()=>{e.#e[i+f[94]]=l},()=>{e.#e[i+f[76]]=l},()=>{e.#e[i+f[77]]=l},()=>{e.#e[i+f[78]]=l},()=>{e.#e[i+f[74]]=l},()=>{e.#e[i+f[71]]=l},()=>{e.#e[i+f[73]]=l},()=>{e.#e[i+f[75]]=l},()=>{e.#e[i+f[72]]=l}][a+u-1]||(()=>{}))():a<48?console.debug(h):a<111?a>102&&a<105&&(e.#e[i+f[[5,65][a&1]]]=l):a<114?console.debug(h):a<116?console.debug(`${c}EQ ${["bass","treble"][a&1]} gain: ${l-64}dB`):a<118?console.debug(h):a<120?console.debug(`${c}EQ ${["bass","treble"][a&1]} freq: ${l}`):console.debug(h)})}).add([76,9],(t,s)=>{let r=e.chRedir(t[0],s,!0),a=t[1],i=`PLG-150VL CH${r+1} `;t.subarray(2).forEach((c,h)=>{let l=h+a;switch(l){case 1:{console.info(`${i}breath mode: ${["system","breath","velocity","touch EG"][c]}`);break}case 0:case 27:case 28:break;default:if(l<27){let u=["pressure","embouchure","tonguing","scream","breath noise","growl","throat formant","harmonic enhancer","damping","absorption","amplification","brightness"][l-3>>1];l&1?l<23?(console.debug(`${i}${u} control source: ${K(c)}`),c&&c<96&&e.allocateAce(c)):console.debug(`${i}${u} scale break point: ${c}`):console.debug(`${i}${u} 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 r=t[0];t.subarray(1).forEach((a,i)=>{let c=r+i;c==8?console.debug(`MU1000 set LCD contrast to ${a}.`):c>9&&c<16&&[()=>{e.dispatchEvent("channelactive",a)},()=>{a<8?(e.dispatchEvent("channelmin",a<<4),console.info(`Octavia System: Minimum CH${(a<<4)+1}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{a<8?(e.dispatchEvent("channelmax",(a<<4)+15),console.info(`Octavia System: Maximum CH${(a<<4)+16}`)):(e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges"))},()=>{e.dispatchEvent("channelreset"),console.info("Octavia System: Clear channel ranges")},()=>{e.#w=!!a,console.info(`Octavia System: RS receiving ${["dis","en"][a]}abled.`)}][c-10]()})}).add([73,10,0],(t,s)=>{let r=t[0],a=`MU1000 RS${e.#w?"":" (ignored)"}: `;if(r<16)switch(r){case 2:{let i=e.chRedir(0,s,!0);e.#w&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+63)),console.info(`${a}Show CH1~64`);break}case 3:{let i=e.chRedir(t[1]<<5,s,!0);e.#w&&e.dispatchEvent("channelmin",i),e.#w&&e.dispatchEvent("channelmax",i+31),console.info(`${a}Show CH${i+1}~CH${i+32}`);break}default:console.debug(`${a}unknown switch ${r} invoked.`)}else if(r<32){if(e.#w){let i=e.chRedir(r-16+(e.#V<<4),s,!0);e.dispatchEvent("channelactive",i)}}else if(r<36){let i=e.chRedir(r-32<<4,s,!0);e.#w&&(e.dispatchEvent("channelmin",i),e.dispatchEvent("channelmax",i+15),e.#V=r-32),console.info(`${a}Show CH${i+1}~CH${i+16}`)}}).add([93,3],(t,s)=>{let r=e.chRedir(t[0],s,!0),a=`PLG-100SG CH${r+1} `,i=Date.now();if(t[1]==0){let c="",h=0;t.subarray(2).forEach((l,u)=>{u%2==0?c+=X[l]||l.toString().padStart("0"):h+=l*13}),i>=e.#K&&e.#i.unshift("SG Lyric: "),e.#i[0]+=`${F(c)}`,e.#K=i+Math.ceil(h/2)+e.#F,E()&&console.debug(`${a}vocals: ${c}`)}else console.warn(`Unknown PLG-100SG data: ${t}`)}),this.#O.add([76,48],t=>{}).add([76,49],t=>{}).add([76,50],t=>{}).add([76,51],t=>{}),this.#O.add([89,0],(t,s,r)=>{if(e.eprom){let a=t[0],i=(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);E()&&console.debug(`MU1000 EPROM trail to 0x${i.toString(16).padStart(6,"0")}, ${a} bytes.`);let c=e.eprom.data;t.subarray(4).forEach((h,l)=>{let u=l>>3,b=l&7;if(b==7)for(let $=0;$<7;$++)c[i+7*u+$]+=(h>>6-$&1)<<7;else c[i+7*u+b]=h})}}).add([89,1],(t,s,r)=>{let a=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3];E()&&console.debug(`MU1000 EPROM jump to 0x${a.toString(16).padStart(6,"0")}.`),e.eprom&&(e.eprom.offset=a)}).add([89,2],(t,s,r)=>{if(e.eprom){let a=(t[0]<<21)+(t[1]<<14)+(t[2]<<7)+t[3]+(e.eprom.offset||0);E()&&console.debug(`MU1000 EPROM write to 0x${a.toString(16).padStart(6,"0")}.`);let i=e.eprom.data;t.subarray(4).forEach((c,h)=>{let l=h>>3,u=h&7;if(u==7)for(let b=0;b<7;b++)i[a+7*l+b]+=(c>>6-b&1)<<7;else i[a+7*l+u]=c})}}).add([89,3],(t,s,r)=>{}),this.#O.add([39,48],(t,s,r)=>{}).add([43,0,0],(t,s,r)=>{let a=[0,0,0,0],i=(c,h)=>{a[h]=c};if(t.subarray(1).forEach((c,h)=>{let l=h+t[0];[i,i,i,i,()=>{this.#g=c*129/16383*100},()=>c-64,()=>c||128,()=>c,()=>c,()=>{console.debug(`TG300 variation on cc${c}.`)}][l](c,l)}),t[0]<4){let c=0;a.forEach(h=>{c=c<<4,c+=h}),c-=1024}}).add([43,1,0],(t,s,r)=>{}).add([43,2],(t,s,r)=>{let a=e.chRedir(t[0],s,!0),i=t[1],c=d.cc*a,h=`TG300 CH${a+1} `;t.subarray(2).forEach((l,u)=>{u<5?([()=>{},()=>{e.#e[c+f[0]]=l},()=>{e.#e[c+f[32]]=l},()=>{e.#r[a]=l},()=>{let b=e.chRedir(l,s,!0);e.#f[a]=b,a!=b&&(e.buildRchTree(),console.info(`${h}receives from CH${b+1}`))}][u+i]||(()=>{}))(l,u+i):u<21||(u<47?([()=>{e.#m[a]=+!l},()=>{},()=>{},()=>{e.#s[d.rpn*a+3]=l},()=>{},()=>{e.#e[c+f[7]]=l},!1,!1,()=>{e.#e[c+f[10]]=l||128},!1,!1,()=>{console.debug(`${h} AC1 at cc${l}`)},()=>{console.debug(`${h} AC2 at cc${l}`)},()=>{e.#e[c+f[11]]=l},()=>{e.#e[c+f[93]]=l},()=>{e.#e[c+f[91]]=l},()=>{e.#e[c+f[94]]=l},()=>{e.#e[c+f[76]]=l},()=>{e.#e[c+f[77]]=l},()=>{e.#e[c+f[74]]=l},()=>{e.#e[c+f[71]]=l},()=>{e.#e[c+f[73]]=l},()=>{e.#e[c+f[75]]=l},()=>{e.#e[c+f[72]]=l},()=>{e.#e[c+f[78]]=l}][u+i-21]||(()=>{}))(l,u+i):u<95||([()=>{e.#e[c+f[65]]=l},()=>{e.#e[c+f[5]]=l}][u+i-95]||(()=>{}))(l,u+i))})}).add([43,7,0],(t,s,r)=>{let a=t[0];e.setLetterDisplay(t.subarray(1),"TG300 letter display",a)}).add([43,7,1],(t,s,r)=>{e.#u=0,e.#k=Date.now()+3200,e.#b.fill(0),t.forEach(function(a,i){let c=Math.floor(i/16),h=i%16,l=(h*3+c)*7,u=7,b=0;for(l-=h*5,c==2&&(u=2);b>6-b&1,b++})}),this.#D.add([66,18,0,0,127],(t,s,r)=>{e.switchMode("gs",!0),e.#e[d.cc*9]=120,e.#e[d.cc*25]=120,e.#e[d.cc*41]=120,e.#e[d.cc*57]=120,e.#E=3,e.#n=!1,e.#R.fill(0),console.info(`GS system to ${["single","dual"][t[0]]} mode.`)}).add([66,18,64,0],(t,s,r)=>{switch(t[0]){case 127:{e.switchMode("gs",!0),e.#e[d.cc*9]=120,e.#e[d.cc*25]=120,e.#e[d.cc*41]=120,e.#e[d.cc*57]=120,e.#n=!1,e.#R.fill(0),console.info("MIDI reset: GS");break}default:{let a=[0,0,0,0],i=(c,h)=>{a[h]=c};if(t.subarray(1).forEach((c,h)=>{let l=h+t[0];[i,i,i,i,u=>{this.#g=u*129/16383*100},u=>{},u=>{}][l](c,h)}),t[0]<4){let c=0;a.forEach(h=>{c=c<<4,c+=h}),c-=1024}}}}).add([66,18,64,1],t=>{let s=t[0];if(s<16){let r="".padStart(s," ");t.subarray(1).forEach((a,i)=>{r+=String.fromCharCode(Math.max(32,a))}),r=r.padEnd(16," "),console.debug(`GS patch name: ${r}`)}else s<48||(s<65?t.subarray(1).forEach((r,a)=>{let i=`GS ${s+a>55?"chorus":"reverb"} `;([()=>{console.info(`${i}type: ${U[r]}`),e.setEffectType(0,40,r)},()=>{},()=>{},()=>{},()=>{},()=>{},!1,()=>{console.debug(`${i}predelay: ${r}ms`)},()=>{console.info(`${i}type: ${V[r]}`),e.setEffectType(1,40,16+r)},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${i}to reverb: ${y(r)}`)},()=>{console.debug(`${i}to delay: ${y(r)}`)}][s+a-48]||(()=>{}))()}):s<80?console.debug(`Unknown GS patch address: ${s}`):s<91?t.subarray(1).forEach((r,a)=>{let i="GS delay ";([()=>{console.info(`${i}type: ${z[r]}`),e.setEffectType(2,40,32+r)},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{console.debug(`${i}to reverb: ${y(r)}`)}][s+a-80]||(()=>{}))()}):console.debug(`Unknown GS patch address: ${s}`))}).add([66,18,64,2],t=>{let s="GS EQ ";t.subarray(1).forEach((r,a)=>{([()=>{console.debug(`${s}low freq: ${[200,400][r]}Hz`)},()=>{console.debug(`${s}low gain: ${r-64}dB`)},()=>{console.debug(`${s}high freq: ${[3e3,6e3][r]}Hz`)},()=>{console.debug(`${s}high gain: ${r-64}dB`)}][t[0]+a]||function(){console.warn(`Unknown GS EQ address: ${t[0]+a}`)})()})}).add([66,18,64,3],t=>{let s="GS EFX ",r=function(a,i){let c=Q(e.#$.subarray(10,12),i,a);c&&console.debug(`${s}${N(e.#$.subarray(10,12))} ${c}`)};t.subarray(1).forEach((a,i)=>{([()=>{e.setEffectTypeRaw(3,!1,32+a)},()=>{e.setEffectTypeRaw(3,!0,a),console.info(`${s}type: ${N(e.#$.subarray(10,12))}`)},!1,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,()=>{console.debug(`${s}to reverb: ${y(a)}dB`)},()=>{console.debug(`${s}to chorus: ${y(a)}dB`)},()=>{console.debug(`${s}to delay: ${y(a)}dB`)},!1,()=>{console.debug(`${s}1 source: ${a}`),a&&a<96&&e.allocateAce(a)},()=>{console.debug(`${s}1 depth: ${a-64}`)},()=>{console.debug(`${s}2 source: ${a}`),a&&a<96&&e.allocateAce(a)},()=>{console.debug(`${s}2 depth: ${a-64}`)},()=>{console.debug(`${s}to EQ: ${a?"ON":"OFF"}`)}][t[0]+i]||function(c,h){console.warn(`Unknown GS EFX address: ${h}`)})(a,t[0]+i)})}).add([66,18,65],t=>{}).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.#k=Date.now()+3200,t[1]==0&&(e.#u=Math.max(Math.min(t[2]-1,9),0));break}default:if(t[0]<11){e.#u>9&&(e.#u=0),e.#k=Date.now()+3200,e.#M[t[0]-1]?.length||(e.#M[t[0]-1]=new Uint8Array(256));let s=e.#M[t[0]-1],r=t[1];s.fill(0);let a=t.subarray(2);for(let i=0;i>4-$&1,$++})}else console.warn(`Unknown GS display section: ${t[0]}`)}});let n=function(t,s,r){let a=t[0],i=d.cc*s,c=d.rpn*s,h=`GS CH${s+1} `;a<3?t.subarray(1).forEach((l,u)=>{[()=>{e.#e[i+f[0]]=l},()=>{e.#r[s]=l},()=>{let b=e.chRedir(l,r,!0);e.#f[s]=b,s!=b&&(e.buildRchTree(),console.info(`${h}receives from CH${b+1}`))}][a+u]()}):a<19||(a<44?t.subarray(1).forEach((l,u)=>{([()=>{e.#m[s]=+!l},!1,()=>{e.setChType(s,l<<1,p.gs),console.debug(`${h}type: ${l?"drum ":"melodic"}${l||""}`)},()=>{e.#s[c+3]=l},!1,()=>{e.#e[i+f[7]]=l},!1,!1,()=>{e.#e[i+f[10]]=l||128},!1,!1,()=>{console.debug(`${h}CC 1: cc${l}`)},()=>{console.debug(`${h}CC 2: cc${l}`)},()=>{e.#e[i+f[93]]=l},()=>{e.#e[i+f[91]]=l},!1,!1,()=>{e.#s[c+1]=l},()=>{e.#s[c+2]=l},()=>{e.#e[i+f[94]]=l}][a+u-19]||(()=>{}))()}):a<76||console.debug(`Unknown GS part address: ${a}`))},o=function(t,s){let r=t[0],a=`GS CH${s+1} `;r<2?t.subarray(1).forEach((i,c)=>{[()=>{e.#e[d.cc*s+f[32]]=i},()=>{}][r+c]()}):r<32?console.warn(`Unknown GS misc address: ${r}`):r<35?t.subarray(1).forEach((i,c)=>{[()=>{console.debug(`${a}EQ: o${["ff","n"][i]}`)},()=>{},()=>{console.debug(`${a}EFX: o${["ff","n"][i]}`)}][r+c-32]()}):console.warn(`Unknown GS misc address: ${r}`)};this.#D.add([66,18,64,16],(t,s)=>{n(t,e.chRedir(9,s,!0),s)}).add([66,18,64,17],(t,s)=>{n(t,e.chRedir(0,s,!0),s)}).add([66,18,64,18],(t,s)=>{n(t,e.chRedir(1,s,!0),s)}).add([66,18,64,19],(t,s)=>{n(t,e.chRedir(2,s,!0),s)}).add([66,18,64,20],(t,s)=>{n(t,e.chRedir(3,s,!0),s)}).add([66,18,64,21],(t,s)=>{n(t,e.chRedir(4,s,!0),s)}).add([66,18,64,22],(t,s)=>{n(t,e.chRedir(5,s,!0),s)}).add([66,18,64,23],(t,s)=>{n(t,e.chRedir(6,s,!0),s)}).add([66,18,64,24],(t,s)=>{n(t,e.chRedir(7,s,!0),s)}).add([66,18,64,25],(t,s)=>{n(t,e.chRedir(8,s,!0),s)}).add([66,18,64,26],(t,s)=>{n(t,e.chRedir(10,s,!0),s)}).add([66,18,64,27],(t,s)=>{n(t,e.chRedir(11,s,!0),s)}).add([66,18,64,28],(t,s)=>{n(t,e.chRedir(12,s,!0),s)}).add([66,18,64,29],(t,s)=>{n(t,e.chRedir(13,s,!0),s)}).add([66,18,64,30],(t,s)=>{n(t,e.chRedir(14,s,!0),s)}).add([66,18,64,31],(t,s)=>{n(t,e.chRedir(15,s,!0),s)}).add([66,18,64,64],(t,s)=>{o(t,e.chRedir(9,s,!0))}).add([66,18,64,65],(t,s)=>{o(t,e.chRedir(0,s,!0))}).add([66,18,64,66],(t,s)=>{o(t,e.chRedir(1,s,!0))}).add([66,18,64,67],(t,s)=>{o(t,e.chRedir(2,s,!0))}).add([66,18,64,68],(t,s)=>{o(t,e.chRedir(3,s,!0))}).add([66,18,64,69],(t,s)=>{o(t,e.chRedir(4,s,!0))}).add([66,18,64,70],(t,s)=>{o(t,e.chRedir(5,s,!0))}).add([66,18,64,71],(t,s)=>{o(t,e.chRedir(6,s,!0))}).add([66,18,64,72],(t,s)=>{o(t,e.chRedir(7,s,!0))}).add([66,18,64,73],(t,s)=>{o(t,e.chRedir(8,s,!0))}).add([66,18,64,74],(t,s)=>{o(t,e.chRedir(10,s,!0))}).add([66,18,64,75],(t,s)=>{o(t,e.chRedir(11,s,!0))}).add([66,18,64,76],(t,s)=>{o(t,e.chRedir(12,s,!0))}).add([66,18,64,77],(t,s)=>{o(t,e.chRedir(13,s,!0))}).add([66,18,64,78],(t,s)=>{o(t,e.chRedir(14,s,!0))}).add([66,18,64,79],(t,s)=>{o(t,e.chRedir(15,s,!0))}),this.#P.add([54,65],(t,s)=>{e.switchMode("x5d");let r=(t[1]<<7)+t[0],a=(t[3]<<7)+t[2],i=e.chRedir(r&15,s,!0),c=d.cc*i;[()=>{a<1||(a<101?(e.setChType(i,e.CH_MELODIC,p.x5d),e.#r[i]=a-1,e.#e[c+f[0]]=82):a<229?(e.setChType(i,e.CH_MELODIC,p.x5d),e.#r[i]=a-101,e.#e[c+f[0]]=56):(e.setChType(i,e.CH_DRUMS,p.x5d),e.#r[i]=j[a-229]||0,e.#e[c+f[0]]=62))},()=>{e.#e[c+f[7]]=a},()=>{a<31&&(e.#e[c+f[10]]=Math.round((a-15)*4.2+64))},()=>{e.#e[c+f[93]]=T(a)},()=>{e.#e[c+f[91]]=T(a)},()=>{e.#s[i*d.rpn+3]=a>8191?a-16320:64+a},()=>{e.#s[i*d.rpn+1]=a>8191?a-16320:64+a},()=>{a>0&&(e.#s[i*d.rpn]=a)},()=>{}][r>>4]()}).add([54,76,0],(t,s)=>{e.switchMode("x5d",!0);let r="",a=82,i=0,c=0,h="MSB PRG LSB NME";k(t,function(l,u){if(u<16400){let b=u%164;switch(!0){case b<10:{l>31&&(r+=String.fromCharCode(l));break}case b==11:{h+=` ${a} ${i} ${c} ${r.trim().replace("Init Voice","")}`,i++,r="";break}}i>99&&(a=90,i=0)}}),e.userBank.clearRange({msb:82,prg:[0,99],lsb:0}),e.userBank.load(h)}).add([54,77,0],(t,s)=>{e.switchMode("x5d",!0);let r="",a=90,i=0,c=0,h="MSB PRG LSB NME";k(t,function(l,u){if(u<13600){let b=u%136;switch(!0){case b<10:{l>31&&(r+=String.fromCharCode(l));break}case b==11:{h+=` ${a} ${i} ${c} ${r.trim().replace("Init Combi","")}`,i++,r="";break}}}}),e.userBank.clearRange({msb:90,prg:[0,99],lsb:0}),e.userBank.load(h)}).add([54,78],(t,s)=>{e.switchMode("x5d",!0),console.debug(`X5D mode switch requested: ${["combi","combi edit","prog","prog edit","multi","global"][t[0]]} mode.`)}).add([54,85],(t,s)=>{e.switchMode("x5d",!0),k(t,(r,a)=>{a>0&&a<3&&e.setEffectType(a-1,44,r)})}).add([54,104],(t,s)=>{e.switchMode("x5d",!0),k(t,function(r,a,i,c){if(a<192){let h=e.chRedir(Math.floor(a/12),s,!0),l=h*d.cc;switch(a%12){case 0:{r<128?(e.setChType(h,e.CH_MELODIC,p.x5d),e.#e[l+f[0]]=82,e.#r[h]=r):(e.setChType(h,e.CH_DRUMS,p.x5d),e.#e[l+f[0]]=62,e.#r[h]=j[r-128]),r>0&&(e.#p[h]=1);break}case 1:{e.#e[l+f[7]]=r;break}case 2:{e.#s[h*d.rpn+3]=r>127?r-192:64+r;break}case 3:{e.#s[h*d.rpn+1]=r>127?r-192:64+r;break}case 4:{r<31&&(e.#e[l+f[10]]=Math.round((r-15)*4.2+64));break}case 5:{let u=r>>4,b=r&15;e.#e[l+f[91]]=T(b),e.#e[l+f[93]]=T(u);break}case 10:break;case 11:{let u=e.chRedir(r&15,s,!0),b=r>>4;e.#f[h]=r,(u!=h||b)&&(console.info(`X5D Part CH${h+1} receives from CH${u+1}.`),e.buildRchTree())}}}else{let h=e.chRedir(a-192,s,!0)}})}),this.#D.add([22,18,127],t=>{e.switchMode("mt32",!0),e.#n=!1,e.userBank.clearRange({msb:0,lsb:127,prg:[0,127]}),console.info("MIDI reset: MT-32")}).add([22,18,0],(t,s,r)=>{e.switchMode("mt32");let a=e.chRedir(r,s,!0),i=t[1];t.subarray(2).forEach((c,h)=>{let l=h+i;e.#U[l+(a-1)*16]=c,([!1,()=>{let u=e.#U[a-1<<4];if(u<3)if(e.#x[a]=1,u==2)for(let b=0;b{e.#s[a*d.rpn+3]=c+40},()=>{e.#s[a*d.rpn+1]=c+14},()=>{e.#s[a*d.rpn]=c},!1,()=>{e.#e[d.cc*a+f[91]]=c?127:0},!1,()=>{e.#e[d.cc*a+f[7]]=c},()=>{e.#e[d.cc*a+f[10]]=Math.ceil(c*9.05)}][l]||(()=>{}))()})}).add([22,18,1],(t,s,r)=>{e.switchMode("mt32");let a=e.chRedir(r,s,!0)}).add([22,18,2],(t,s,r)=>{e.switchMode("mt32");let a=e.chRedir(r,s,!0),i=t[1]+(t[0]<<7);i<10&&(e.#x[a]=1),t.subarray(2).forEach((c,h)=>{let l=h+i;l<14&&(e.#y[(a-1)*d.cmt+l]=c)})}).add([22,18,3],(t,s,r)=>{if(e.switchMode("mt32"),t[0]){let a=t[1]-16}else{let a=t[1];t.subarray(2).forEach((i,c)=>{let h=c+a;e.#U[h]=i;let l=e.chRedir(1+h>>4,s,!0),u=h&15;([!1,()=>{let b=e.#U[l-1<<4];if(b<3)if(e.#x[l]=1,b==2)for(let $=0;${e.#s[l*d.rpn+3]=i+40},()=>{e.#s[l*d.rpn+1]=i+14},()=>{e.#s[l*d.rpn]=i},!1,()=>{e.#e[d.cc*l+f[91]]=i?127:0},!1,()=>{e.#e[d.cc*l+f[7]]=i},()=>{e.#e[d.cc*l+f[10]]=Math.ceil(i*9.05)}][u]||(()=>{}))()})}}).add([22,18,4],(t,s,r)=>{e.switchMode("mt32");let a=t[1]+(t[0]<<7);t.subarray(2).forEach((i,c)=>{let h=c+a,l=e.chRedir(Math.floor(h/246+1),s,!0),u=h%246;u<14&&(e.#y[(l-1)*d.cmt+u]=i),u<10&&(e.#x[l]=1)})}).add([22,18,5],(t,s,r)=>{e.switchMode("mt32");let a=(t[0]<<7)+t[1];t.subarray(2).forEach((i,c)=>{let h=a+c,l=Math.floor(h/8),u=h&7,b=l*8;e.#X[h]=i,([!1,()=>{let $=e.#X[b];if($<3){let g="";if($==2){let R=d.cmt*l;g=`MT-m:${i.toString().padStart(3,"0")}`}else g=e.baseBank.get(0,i+($<<6),127,"mt32").name;e.userBank.clearRange({msb:0,lsb:127,prg:l}),e.userBank.load(`MSB LSB PRG NME 000 127 ${l} ${g}`,!0)}}][u]||(()=>{}))()})}).add([22,18,8],(t,s,r)=>{e.switchMode("mt32");let a=((t[0]&1)<<7)+t[1];t.subarray(2).forEach((i,c)=>{let h=a+c;h>1)*d.cmt+h]=i)})}).add([22,18,16],(t,s,r)=>{e.switchMode("mt32");let a=t[1],i=!1,c=function(h,l){e.#f[l-12]=h,i=!0};t.subarray(2).forEach((h,l)=>{let u=l+a;([!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,c,c,c,c,c,c,c,c,c,()=>{e.#g=h}][u]||(()=>{}))(h,l)}),i&&e.buildRchTree()}).add([22,18,32],t=>{e.switchMode("mt32");let s=t[1],r=" ".repeat(s);t.subarray(2).forEach(a=>{a>31&&(r+=String.fromCharCode(a))}),e.#C=r.padStart(20," "),e.#H=Date.now()+3200}).add([22,18,82],(t,s)=>{let r=e.chRedir(0,s,!0);for(let a=0;a<16;a++)e.#l.ano(r+a),a&&a<10&&(e.#r[r+a]=G[a-1]);console.info("MT-32 alt reset complete.")}),this.#P.add([66,0],(t,s)=>{e.switchMode("ns5r",!0),e.#n=!1,console.debug(`NS5R mode switch requested: ${["global","multi","prog edit","comb edit","drum edit","effect edit"][t[0]]} mode.`)}).add([66,1],(t,s)=>{e.switchMode(["ns5r","05rw"][t[0]],!0),e.#n=!1}).add([66,18,0,0],(t,s)=>{let r=t[0];switch(r){case 124:case 126:case 127:{e.switchMode("ns5r",!0),e.#n=!1;break}case 125:break;default:if(r<10){let a=[0,0,0,0],i=(c,h)=>{a[h]=c};if(t.subarray(1).forEach((c,h)=>{[i,i,i,i,()=>{e.#g=c*129/16383*100},()=>c-64,()=>c-64,()=>{},()=>{},()=>{}][r+h]()}),t[0]<4){let c=0;a.forEach(h=>{c=c<<4,c+=h}),c-=1024}}}}).add([66,18,0,1],(t,s)=>{}).add([66,18,0,2],(t,s)=>{}).add([66,18,1],(t,s)=>{let r=e.chRedir(t[0],s,!0),a=r*d.cc,i=t[1],c=`NS5R CH${r+1} `;t.subarray(2).forEach((h,l)=>{let u=i+l;u<3?[()=>{e.#e[a+f[0]]=h||121},()=>{e.#e[a+f[32]]=h},()=>{e.#r[r]=h}][u]():u<8||(u<14?[()=>{let b=e.chRedir(h,s,!0);e.#f[r]=b,r!=b&&(e.buildRchTree(),console.info(`${c}receives from CH${b+1}`))},()=>{e.#m[r]=+!h},()=>{e.setChType(r,h,p.ns5r),console.debug(`${c}type: ${C[h]}`)},()=>{e.#s[d.rpn*r+3]=h},()=>{},()=>{}][u-8]():u<16||(u<33?[()=>{e.#e[a+f[7]]=h},()=>{e.#e[a+f[11]]=h},()=>{},()=>{},()=>{e.#e[a+f[10]]=h||128},()=>{},()=>{},()=>{e.#e[a+f[93]]=h},()=>{e.#e[a+f[91]]=h},()=>{e.#e[a+f[76]]=h},()=>{e.#e[a+f[77]]=h},()=>{e.#e[a+f[78]]=h},()=>{e.#e[a+f[74]]=h},()=>{e.#e[a+f[71]]=h},()=>{e.#e[a+f[73]]=h},()=>{e.#e[a+f[75]]=h},()=>{e.#e[a+f[72]]=h}][u-16]():u<112||u<114&&[()=>{e.#e[a+f[5]]=h},()=>{e.#e[a+f[65]]=h}][u-112]()))})}).add([66,18,8,0],(t,s)=>{let r=t[0];if(r<32)e.setLetterDisplay(t.subarray(1,33),"NS5R letter display");else{let a=r-32;e.#k=Date.now()+3200,e.#u=10,e.#b.fill(0);let i=t.subarray(1),c=4;i.forEach(function(h,l){let u=l+a,b=u>>4,$=u&15;if(u<80){let g=b>3,R=0,se=b0;)e.#b[$*32+b*7+(se-R)]=g&1,g=g>>1,R++}})}}).add([66,52],(t,s)=>{e.switchMode("ns5r",!0),e.#n=!1;let r="";k(t,(a,i)=>{i<8?(a>31&&(r+=String.fromCharCode(a)),i==7&&(e.aiEfxName=r)):i<10&&e.setEffectType(i-8,44,a)})}).add([66,53],(t,s)=>{e.switchMode("ns5r",!0),e.#n=!1,k(t,function(r,a){switch(!0){case a<2944:{let i=e.chRedir(Math.floor(a/92),s,!0),c=i*d.cc;switch(a%92){case 0:{e.#e[c+f[0]]=r||121;break}case 1:{e.#e[c+f[32]]=r;break}case 2:{e.#r[i]=r,r>0&&(e.#p[i]=1);break}case 3:{let h=e.chRedir(r,s,!0);e.#f[i]=h,i!=h&&(console.info(`NS5R CH${i+1} receives from CH${h+1}.`),e.buildRchTree())}case 7:break;case 8:{e.#s[i*d.rpn+3]=r<40||r>88?r+(r>63?-192:64):r;break}case 9:case 10:{e.#e[c+f[7]]=r;break}case 11:{e.#e[c+f[11]]=r;break}case 14:{e.#e[c+f[10]]=r||128;break}case 19:{e.#e[c+f[93]]=r;break}case 20:{e.#e[c+f[91]]=r;break}case 84:{e.#e[c+f[65]]=r;break}case 85:{e.#e[c+f[5]]=r;break}}break}case a<3096:break;case a<3134:break;case a<8566:break}})}).add([66,54],(t,s)=>{e.switchMode("ns5r",!0);let r="",a=80,i=0,c=0,h="MSB PRG LSB NME";k(t,function(l,u){let b=u%158;switch(!0){case b<10:{l>31&&(r+=String.fromCharCode(l));break}case b==11:{a=l&127;break}case b==12:{c=l&127;break}case b==13:{h+=` diff --git a/src/state/index.mjs b/src/state/index.mjs index 432aa2f7..deb26e47 100644 --- a/src/state/index.mjs +++ b/src/state/index.mjs @@ -638,7 +638,7 @@ let OctaviaDevice = class extends CustomEventSource { case modeMap.g2: { if (det.data[1] == 120) { if (this.#chType[part] == 0) { - this.setChType(part, this.CH_DRUM2); + this.setChType(part, this.CH_DRUMS); console.debug(`CH${part + 1} set to drums by MSB.`); }; } else { @@ -696,7 +696,9 @@ let OctaviaDevice = class extends CustomEventSource { let targetSlot = this.#chType[part] - 2; if (targetSlot < 0) { console.warn(`CH${part + 1} cannot accept drum NRPN as type ${xgPartMode[this.#chType[part]]}.`); - } else {}; + } else { + this.#drum[(targetSlot * allocated.dpn + msb) * allocated.dnc + lsb] = det.data[1] - 64; + }; }; getDebugState() && console.debug(`CH${part + 1} (${xgPartMode[this.#chType[part]]}) drum NRPN ${msb} commit`); }; @@ -2519,7 +2521,7 @@ let OctaviaDevice = class extends CustomEventSource { }, false // assign mode , () => { // drum map - upThis.setChType(part, e ? (e << 1) : 0, modeMap.gs); + upThis.setChType(part, e << 1, modeMap.gs); console.debug(`${dPref}type: ${e ? "drum " : "melodic"}${e ? e : ""}`); }, () => { // coarse tune