From d0e6dfad33f94e2f4e6cae8806dd005d1fc83b0d Mon Sep 17 00:00:00 2001 From: spessasus Date: Thu, 12 Sep 2024 22:17:01 +0200 Subject: [PATCH] remove console log --- src/website/js/renderer/channel_analysers.js | 1 - src/website/minified/demo_main.min.js | 2 +- src/website/minified/local_main.min.js | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/website/js/renderer/channel_analysers.js b/src/website/js/renderer/channel_analysers.js index 47b58f21..85a00bb3 100644 --- a/src/website/js/renderer/channel_analysers.js +++ b/src/website/js/renderer/channel_analysers.js @@ -54,7 +54,6 @@ export function updateFftSize() else { this.delayNode.delayTime.value = 0; - console.log('no') } } } diff --git a/src/website/minified/demo_main.min.js b/src/website/minified/demo_main.min.js index 161a267c..e1d1e5f4 100644 --- a/src/website/minified/demo_main.min.js +++ b/src/website/minified/demo_main.min.js @@ -1,5 +1,5 @@ var hm=(A=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(A,{get:(r,l)=>(typeof require<"u"?require:r)[l]}):A)(function(A){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+A+'" is not supported')});var l6=class extends Uint8Array{constructor(r){super(r),this.currentIndex=0}currentIndex};function bs(A){let r=A.reduce((d,b)=>d+b.length,0),l=new l6(r),g=0;for(let d of A)l.set(d,g),g+=d.length;return l}function f$(A){A=Math.floor(A);let r=Math.floor(A/60),l=Math.round(A-r*60);return{minutes:r,seconds:l,time:`${r.toString().padStart(2,"0")}:${l.toString().padStart(2,"0")}`}}function wB(A){return A.trim().replaceAll(".mid","").replaceAll(".rmi","").replaceAll("_"," ")}var D1={warn:"color: orange;",unrecognized:"color: red;",info:"color: aqua;",recognized:"color: lime",value:"color: yellow; background-color: black;"};var ui=class{constructor(r,l,g){this.ticks=r,this.messageStatusByte=l,this.messageData=g}};var J3={noteOff:128,noteOn:144,polyPressure:160,controllerChange:176,programChange:192,channelPressure:208,pitchBend:224,systemExclusive:240,timecode:241,songPosition:242,songSelect:243,tuneRequest:246,clock:248,start:250,continue:251,stop:252,activeSensing:254,reset:255,sequenceNumber:0,text:1,copyright:2,trackName:3,instrumentName:4,lyric:5,marker:6,cuePoint:7,midiChannelPrefix:32,midiPort:33,endOfTrack:47,setTempo:81,smpteOffset:84,timeSignature:88,keySignature:89,sequenceSpecific:127};function KQ(A){let r=A&240,l=A&15,g=-1,d=A;return r>=128&&r<=224&&(g=l,d=r),{status:d,channel:g}}var A6={bankSelect:0,modulationWheel:1,breathController:2,footController:4,portamentoTime:5,dataEntryMsb:6,mainVolume:7,balance:8,pan:10,expressionController:11,effectControl1:12,effectControl2:13,generalPurposeController1:16,generalPurposeController2:17,generalPurposeController3:18,generalPurposeController4:19,lsbForControl0BankSelect:32,lsbForControl1ModulationWheel:33,lsbForControl2BreathController:34,lsbForControl4FootController:36,lsbForControl5PortamentoTime:37,lsbForControl6DataEntry:38,lsbForControl7MainVolume:39,lsbForControl8Balance:40,lsbForControl10Pan:42,lsbForControl11ExpressionController:43,lsbForControl12EffectControl1:44,lsbForControl13EffectControl2:45,sustainPedal:64,portamentoOnOff:65,sostenutoPedal:66,softPedal:67,legatoFootswitch:68,hold2Pedal:69,soundVariation:70,timbreHarmonicContent:71,releaseTime:72,attackTime:73,brightness:74,soundController6:75,soundController7:76,soundController8:77,soundController9:78,soundController10:79,generalPurposeController5:80,generalPurposeController6:81,generalPurposeController7:82,generalPurposeController8:83,portamentoControl:84,effects1Depth:91,effects2Depth:92,effects3Depth:93,effects4Depth:94,effects5Depth:95,dataIncrement:96,dataDecrement:97,NRPNLsb:98,NRPNMsb:99,RPNLsb:100,RPNMsb:101,allSoundOff:120,resetAllControllers:121,localControlOnOff:122,allNotesOff:123,omniModeOff:124,omniModeOn:125,monoModeOn:126,polyModeOn:127};var fm=class{constructor(){this.events={noteoff:{},noteon:{},pitchwheel:{},controllerchange:{},programchange:{},channelpressure:{},polypressure:{},drumchange:{},stopall:{},newchannel:{},mutechannel:{},presetlistchange:{},allcontrollerreset:{},soundfonterror:{}}}addEvent(r,l,g){this.events[r][l]=g}removeEvent(r,l){delete this.events[r][l]}callEvent(r,l){this.events[r]&&Object.values(this.events[r]).forEach(g=>g(l))}};var kB={nodesAmount:4,defaultDelay:.03,delayVariation:.01,stereoDifference:.02,oscillatorFrequency:.3,oscillatorFrequencyVariation:.05,oscillatorGain:.003},um=class{constructor(r,l=kB){let g=r.context;this.input=new ChannelSplitterNode(g,{numberOfOutputs:2});let d=new ChannelMergerNode(g,{numberOfInputs:2}),b=[],h0=[],b0=l.oscillatorFrequency,p0=l.defaultDelay;for(let R0=0;R0{let b=await d.arrayBuffer();l.buffer=await A.decodeAudioData(b)})}return l}var B8={noteOff:0,noteOn:1,ccChange:2,programChange:3,channelPressure:4,polyPressure:5,killNote:6,ccReset:7,setChannelVibrato:8,soundFontManager:9,stopAll:10,killNotes:11,muteChannel:12,addNewChannel:13,customcCcChange:14,debugMessage:15,systemExclusive:16,setMasterParameter:17,setDrums:18,pitchWheel:19,transpose:20,highPerformanceMode:21,lockController:22,sequencerSpecific:23,requestSynthesizerSnapshot:24,setLogLevel:25},mC={mainVolume:0,masterPan:1,voicesCap:2,interpolationType:3},Hi=-1,u$={channelProperties:0,eventCall:1,reportedCurrentTime:2,sequencerSpecific:3,synthesizerSnapshot:4,ready:5,soundfontError:6,identify:7};var BD=!0,pD=!0,vB=!0;function Y5(...A){BD&&console.info(...A)}function _4(...A){pD&&console.warn(...A)}function ar(...A){vB&&console.group(...A)}function ei(...A){vB&&console.groupCollapsed(...A)}function t4(){vB&&console.groupEnd()}var zQ={chorusEnabled:!0,chorusConfig:kB,reverbEnabled:!0,reverbImpulseResponse:void 0};var BC={reloadSoundFont:0,addNewSoundFont:2,deleteSoundFont:3,rearrangeSoundFonts:4};var dm=class{constructor(r){this.soundfontList=[{id:"main",bankOffset:0}],this._port=r.worklet.port,this.synth=r}_sendToWorklet(r,l){this._port.postMessage({messageType:B8.soundFontManager,messageData:[r,l]})}async addNewSoundFont(r,l,g=0){if(this.soundfontList.find(d=>d.id===l)!==void 0)throw new Error("Cannot overwrite the existing soundfont. Use soundfontManager.delete(id) instead.");this._sendToWorklet(BC.addNewSoundFont,[r,l,g]),await new Promise(d=>this.synth.resolveWhenReady=d),this.soundfontList.push({id:l,bankOffset:g})}deleteSoundFont(r){if(this.soundfontList.length===0){_4("1 soundfont left. Aborting!");return}if(this.soundfontList.findIndex(l=>l.id===r)===-1){_4(`No soundfont with id of "${r}" found. Aborting!`);return}this._sendToWorklet(BC.deleteSoundFont,r)}rearrangeSoundFonts(r){this._sendToWorklet(BC.rearrangeSoundFonts,r),this.soundfontList.sort((l,g)=>r.indexOf(l.id)-r.indexOf(g.id))}async reloadManager(r){this._sendToWorklet(BC.reloadSoundFont,r),await new Promise(l=>this.synth.resolveWhenReady=l)}};var QD="spessasynth-worklet-system",SB=450,ki=9,yD=16;var ah=class{constructor(r,l,g=!0,d=void 0,b=zQ){Y5("%cInitializing SpessaSynth synthesizer...",D1.info),this.context=r.context;let h0=d?.oneOutput===!0;this.eventHandler=new fm,this._voiceCap=SB,this._outputsAmount=yD,this.channelsAmount=this._outputsAmount,this.resolveWhenReady=void 0,this.isReady=new Promise(R0=>this.resolveWhenReady=R0),this.channelProperties=[];for(let R0=0;R0this.handleMessage(R0.data),this.soundfontManager=new dm(this),this._snapshotCallback=void 0,this.sequencerCallbackFunction=void 0,b.reverbEnabled&&!h0&&(this.reverbProcessor=VQ(this.context,b.reverbImpulseResponse),this.reverbProcessor.connect(r),this.worklet.connect(this.reverbProcessor,0)),b.chorusEnabled&&!h0&&(this.chorusProcessor=new um(r,b.chorusConfig),this.worklet.connect(this.chorusProcessor.input,1)),h0)this.worklet.connect(r,0);else for(let R0=2;R0{this.channelsAmount++})}get voiceCap(){return this._voiceCap}set voiceCap(r){this._setMasterParam(mC.voicesCap,r),this._voiceCap=r}set highPerformanceMode(r){this._highPerformanceMode=r}get highPerformanceMode(){return this._highPerformanceMode}setLogLevel(r,l,g,d){this.post({channelNumber:Hi,messageType:B8.setLogLevel,messageData:[r,l,g,d]})}_setMasterParam(r,l){this.post({channelNumber:Hi,messageType:B8.setMasterParameter,messageData:[r,l]})}setInterpolationType(r){this._setMasterParam(mC.interpolationType,r)}handleMessage(r){let l=r.messageData;switch(r.messageType){case u$.channelProperties:this.channelProperties=l,this._voicesAmount=this.channelProperties.reduce((g,d)=>g+d.voicesAmount,0);break;case u$.eventCall:this.eventHandler.callEvent(l.eventName,l.eventData);break;case u$.sequencerSpecific:this.sequencerCallbackFunction&&this.sequencerCallbackFunction(l.messageType,l.messageData);break;case u$.synthesizerSnapshot:this._snapshotCallback&&this._snapshotCallback(l);break;case u$.ready:this.resolveWhenReady();break;case u$.soundfontError:_4(new Error(l)),this.eventHandler.callEvent("soundfonterror",l);break}}async getSynthesizerSnapshot(){return new Promise(r=>{this._snapshotCallback=l=>{this._snapshotCallback=void 0,r(l)},this.post({messageType:B8.requestSynthesizerSnapshot,messageData:void 0,channelNumber:Hi})})}addNewChannel(r=!0){this.channelProperties.push({voicesAmount:0,pitchBend:0,pitchBendRangeSemitones:0,isMuted:!1,isDrum:!1}),r&&this.post({channelNumber:0,messageType:B8.addNewChannel,messageData:null})}setVibrato(r,l){this.post({channelNumber:r,messageType:B8.setChannelVibrato,messageData:l})}connectIndividualOutputs(r){if(r.length!==this._outputsAmount)throw new Error(`input nodes amount differs from the system's outputs amount! - Expected ${this._outputsAmount} got ${r.length}`);for(let l=0;l0?this.noteOn(l.channel,r[1],g):this.noteOff(l.channel,r[1]);break;case J3.noteOff:this.noteOff(l.channel,r[1]);break;case J3.pitchBend:this.pitchWheel(l.channel,r[2],r[1]);break;case J3.controllerChange:this.controllerChange(l.channel,r[1],r[2]);break;case J3.programChange:this.programChange(l.channel,r[1]);break;case J3.polyPressure:this.polyPressure(l.channel,r[0],r[1]);break;case J3.channelPressure:this.channelPressure(l.channel,r[1]);break;case J3.systemExclusive:this.systemExclusive(new l6(r.slice(1)));break;case J3.reset:this.stopAll(!0),this.resetControllers();break;default:break}}get currentTime(){return this.context.currentTime}get voicesAmount(){return this._voicesAmount}reverbateEverythingBecauseWhyNot(){for(let r=0;r{this.pressedKeys.delete(g),this.releaseNote(g,this.channel),this.synth.noteOff(this.channel,g)},r=(g,d)=>{let b;if(Bn)b=127;else{let b0=this.keys[0].getBoundingClientRect();if(this.keyboard.classList.contains("sideways")){let p0=d.clientX-b0.left,R0=b0.width;b=Math.floor((R0-p0)/R0*127)}else{let p0=d.clientY-b0.top,R0=b0.height;b=Math.floor(p0/R0*127)}}this.synth.noteOn(this.channel,g,b,this.enableDebugging)},l=g=>{let d=g.touches?Array.from(g.touches):[g],b=new Set;d.forEach(h0=>{let b0=document.elementFromPoint(h0.clientX,h0.clientY),p0=parseInt(b0.id.replace("note",""));b.add(p0),!(isNaN(p0)||p0<0||this.pressedKeys.has(p0))&&(this.pressedKeys.add(p0),r(p0,h0))}),this.pressedKeys.forEach(h0=>{b.has(h0)||A(h0)})};Bn||(document.addEventListener("mousedown",g=>{this.mouseHeld=!0,l(g)}),document.addEventListener("mouseup",()=>{this.mouseHeld=!1,this.pressedKeys.forEach(g=>{A(g)})}),this.keyboard.onmousemove=g=>{this.mouseHeld&&l(g)},this.keyboard.onmouseleave=()=>{this.pressedKeys.forEach(g=>{A(g)})}),this.keyboard.ontouchstart=l.bind(this),this.keyboard.ontouchend=l.bind(this),this.keyboard.ontouchmove=l.bind(this)}var WQ=20,pC=class{constructor(r,l){this.mouseHeld=!1,this.pressedKeys=new Set,this.mode="light",this.enableDebugging=!1,this.sizeChangeAnimationId=-1,this.modeChangeAnimationId=-1,this._keyRange={min:0,max:127},document.addEventListener("keydown",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,A6.sustainPedal,127),this.keyboard.style.filter="brightness(0.5)")}),document.addEventListener("keyup",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,A6.sustainPedal,0),this.keyboard.style.filter="")}),this.synth=l,this.channel=0,this.channelColors=r,this._shown=!0,this._createKeyboard(),this.synth.eventHandler.addEvent("noteon","keyboard-note-on",g=>{this.pressNote(g.midiNote,g.channel,g.velocity)}),this.synth.eventHandler.addEvent("noteoff","keyboard-note-off",g=>{this.releaseNote(g.midiNote,g.channel)}),this.synth.eventHandler.addEvent("stopall","keyboard-stop-all",()=>{this.clearNotes()}),this.synth.eventHandler.addEvent("mutechannel","keyboard-mute-channel",g=>{if(g.isMuted)for(let d=0;d<128;d++)this.releaseNote(d,g.channel)})}set shown(r){r===!0?this.keyboard.style.display="":this.keyboard.style.display="none",this._shown=r}get shown(){return this._shown}_createKeyboard(){this.keyboard=document.getElementById("keyboard"),this.keyboard.innerHTML="",this.keys=[],this.keyColors=[];for(let r=this._keyRange.min;r=0&&(b=l(r-1)),r<127&&(h0=l(r+1)),h0&&b?g.classList.add("between_sharps"):b?g.classList.add("left_sharp"):h0&&g.classList.add("right_sharp")}return g}toggleMode(r=!0){if(this.mode==="light"?this.mode="dark":this.mode="light",!r){this.keys.forEach(g=>{g.classList.contains("flat_key")&&g.classList.toggle("flat_dark_key")});return}this.modeChangeAnimationId&&clearTimeout(this.modeChangeAnimationId),this.keyboard.classList.add("mode_transform"),document.body.scrollHeight<=window.innerHeight&&document.body.classList.add("no_scroll"),this.modeChangeAnimationId=setTimeout(()=>{this.keys.forEach(g=>{g.classList.contains("flat_key")&&g.classList.toggle("flat_dark_key")}),this.keyboard.classList.remove("mode_transform"),setTimeout(()=>document.body.classList.remove("no_scroll"),500)},500)}get keyRange(){return this._keyRange}set keyRange(r){if(r.max===void 0||r.min===void 0)throw new TypeError("No min or max property!");if(r.min>r.max){let l=r.min;r.min=r.max,r.max=l}r.min=Math.max(0,r.min),r.max=Math.min(127,r.max),this.setKeyRange(r,!0)}setKeyRange(r,l=!0){Math.abs(r.max-r.min)<12&&(r.min-=6,r.max=r.min+12);let d=900/(r.max-r.min+5),b=document.styleSheets[0].cssRules,h0;for(let b0 of b)if(b0.selectorText==="#keyboard .key"){h0=b0;break}if(h0.style.setProperty("--pressed-transform-skew",`${8e-4/(d/7)}`),l){this.sizeChangeAnimationId&&clearTimeout(this.sizeChangeAnimationId);let b0=getComputedStyle(this.keyboard),p0=parseFloat(b0.getPropertyValue("--current-min-height").replace(/[^\d.]+/g,"")),R0=this.keyboard.getBoundingClientRect().height,E1=d/p0,M=R0*E1-R0,K0=(this._keyRange.min+this._keyRange.max)/2,_0=(r.min+r.max)/2;this._keyRange=r;let k1=this.keys.find(_5=>_5.classList.contains("sharp_key")).getBoundingClientRect().width,h2=(K0-_0)*k1,R1=parseFloat(b0.getPropertyValue("--key-border-radius").replace(/[^\d.]+/g,""));this.keyboard.style.marginTop=`${M}px`,this.keyboard.style.transition="",this.keyboard.style.transform=`scale(${E1}) translateX(${h2}px)`,this.keyboard.style.setProperty("--key-border-radius",`${R1/E1}vmin`),this.sizeChangeAnimationId=setTimeout(()=>{this.keyboard.style.setProperty("--current-min-height",`${d}`),this.keyboard.style.transition="none",this.keyboard.style.transform="",this.keyboard.style.marginTop="",this.keyboard.style.setProperty("--key-border-radius",""),this._createKeyboard(),setTimeout(()=>this.keyboard.style.transition="",75)},500)}else this.keyboard.style.setProperty("--current-min-height",`${d}`),this._keyRange=r,this._createKeyboard()}selectChannel(r){this.channel=r}pressNote(r,l,g){let d=this.keys[r-this._keyRange.min];if(d===void 0)return;d.classList.add("pressed");let b=d.classList.contains("sharp_key"),h0=g/127,b0=this.channelColors[l%16].match(/\d+(\.\d+)?/g).map(parseFloat),p0;if(!b&&this.mode==="light"?p0=`rgba(${b0.slice(0,3).map(E1=>255-(255-E1)*h0).join(", ")}, ${b0[3]})`:p0=`rgba(${b0.slice(0,3).map(E1=>E1*h0).join(", ")}, ${b0[3]})`,d.style.background=p0,this.mode==="dark"){let R0=WQ*h0;d.style.boxShadow=`${p0} 0px 0px ${R0}px ${R0/5}px`}this.keyColors[r-this._keyRange.min].push(this.channelColors[l%16])}releaseNote(r,l){let g=this.keys[r-this._keyRange.min];if(g===void 0)return;l%=this.channelColors.length;let d=this.keyColors[r-this._keyRange.min];if(!d)return;let b=d.findLastIndex(h0=>h0===this.channelColors[l]);b!==-1&&(d.splice(b,1),g.style.background=d[d.length-1],this.mode==="dark"&&(g.style.boxShadow=`0px 0px ${WQ}px ${d[d.length-1]}`),d.length<1&&(g.classList.remove("pressed"),g.style.background="",g.style.boxShadow=""))}clearNotes(){this.keys.forEach((r,l)=>{r.classList.remove("pressed"),r.style.background="",r.style.boxShadow="",this.keyColors[l]=[]})}};pC.prototype._handlePointers=ZQ;function d$(A,r){let l=A.replace(/[^\d,]/g,"").split(",");return`rgb(${r(parseInt(l[0]))}, ${r(parseInt(l[1]))}, ${r(parseInt(l[2]))})`}var kD="#000";function jQ(A,r,l){A.forEach(g=>{if(g.pressedProgress===0)return;r.fillStyle=g.color;let d=g.pressedProgress*g.velocity;if(r.globalAlpha=.5*d,l){r.fillRect(g.xPos,g.yPos-g.height*d,g.width,g.height*(d*2+1)),r.globalAlpha=1;return}r.fillRect(g.xPos-g.width*d,g.yPos,g.width*(d*2+1),g.height),r.globalAlpha=1}),A.forEach(g=>{r.fillStyle=g.color,r.save(),r.translate(g.xPos,g.yPos),r.fillRect(0,0,g.width,g.height),r.restore(),r.strokeStyle=kD,r.lineWidth=g.stroke,r.strokeRect(g.xPos,g.yPos,g.width,g.height)})}var DB=!1;function XQ(A=!0,r=!1){let l=(this.seq===void 0||this?.seq?.paused===!0)&&this.synth.voicesAmount===0&&!r;if(!this.renderBool||l)if(DB){A&&requestAnimationFrame(this.render.bind(this));return}else DB=!0;else DB=!1;if(A&&this.drawingContext.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderAnalysers&&!this.synth.highPerformanceMode&&this.renderWaveforms(),this.renderNotes&&this.noteTimes){let b=this.computeNotePositions(this.synth.highPerformanceMode);this.synth.highPerformanceMode||jQ(b,this.drawingContext,this.sideways)}let g=performance.now()-this.frameTimeStart;this.frameTimeStart=performance.now();let d=1e3/g;this.drawingContext.textBaseline="hanging",this.drawingContext.textAlign="end",this.drawingContext.font=`${bB}px Verdana`,this.drawingContext.fillStyle="white",this.drawingContext.strokeStyle="white",this.drawingContext.fillText(`${this.notesOnScreen} notes`,this.canvas.width,bB+5),this.drawingContext.fillText(Math.round(d).toString()+" FPS",this.canvas.width,5),this.onRender&&this.onRender(),A&&requestAnimationFrame(this.render.bind(this))}function ey(A=!1){this.notesOnScreen=0;let r=this.sideways?this.canvas.height:this.canvas.width,l=this.sideways?this.canvas.width:this.canvas.height,g=this.keyRange.max-this.keyRange.min,d=r/(g+1),b=d-E$*2,h0=this.noteFallingTimeMs/1e3,b0=this.noteAfterTriggerTimeMs/1e3,p0=this.seq.currentHighResolutionTime,R0=p0-b0,E1=h0+b0,M=R0+E1,K0=iy/E1,_0=[];this.synth.channelProperties.forEach(h2=>{if(this.showVisualPitch){let R1=h2.pitchBend-8192+this.visualPitchBendOffset;_0.push(h2.pitchBendRangeSemitones*(R1/8192*d))}else _0.push(0)});let k1=[];return this.noteTimes.forEach((h2,R1)=>{if(h2.renderStartIndex>=h2.notes.length||!this.renderChannels[R1])return;let _5=h2.renderStartIndex,v2=h2.notes,J2=v2[_5],n3=-1;for(;J2.start<=M&&(_5++,!(this.notesOnScreen>ry));){let U5=J2.start+J2.length;if(U5>R0&&J2.length>0){let a0=J2.length/E1*l-E$*2;if(this.notesOnScreen<1e3||a0>K0){n3===-1&&(n3=_5-1);let J5=(J2.start-R0)/E1*l,n6;if(this._notesFall?n6=l-a0-J5+E$:n6=J5+E$,J2.midiNotethis.keyRange.max){if(_5>=v2.length)break;J2=v2[_5];continue}let c6=J2.midiNote-this.keyRange.min,O6=d*c6+E$,g6,u4,Ke,J4;if(this.sideways?(g6=n6,u4=O6,J4=b,Ke=a0):(u4=n6,g6=O6,Ke=b,J4=a0),this.notesOnScreen++,A)this.drawingContext.fillStyle=this.plainColors[R1],this.drawingContext.fillRect(g6+I$+E$,u4+I$,Ke-I$*2,J4-I$*2);else{let p9;if(J2.start>p0||U5=v2.length)break;J2=v2[_5]}n3>-1&&(h2.renderStartIndex=n3)}),k1.sort((h2,R1)=>R1.height-h2.height),k1}function ny(){let A=this.canvas.width/4,r=this.canvas.height/4;this.channelAnalysers.forEach((l,g)=>{let d=g%4,b=Math.floor(g/4),h0=!1;for(let M=g;M0){h0=!0;break}if(!h0){let M=this.canvas.width/4,K0=this.canvas.height/4,_0=M*d,k1=K0*b+K0/2;this.drawingContext.lineWidth=this.lineThickness,this.drawingContext.strokeStyle=this.channelColors[g],this.drawingContext.beginPath(),this.drawingContext.moveTo(_0,k1),this.drawingContext.lineTo(_0+M,k1),this.drawingContext.stroke();return}let b0=new Float32Array(l.frequencyBinCount);l.getFloatTimeDomainData(b0);let p0=A*d,R0=r*b+r/2,E1=this.waveMultiplier*r;if(this.drawingContext.lineWidth=this.lineThickness,this.drawingContext.strokeStyle=this.channelColors[g],this.drawingContext.beginPath(),this._stabilizeWaveforms){let M=b0.length/4,K0=A/M,_0=Math.floor(M/2),k1=b0.length-_0;for(let v2=k1;v2>=1;v2--)if(b0[v2-1]<0&&b0[v2]>=0){k1=v2;break}let h2=p0,R1=k1-_0,_5=k1+_0;for(let v2=R1;v2<_5;v2++)this.drawingContext.lineTo(h2,R0+b0[v2]*E1),h2+=K0}else{let M=A/b0.length,K0=p0;for(let _0=0;_0{this.renderChannels[r.channel]=!r.isMuted}),this.updateFftSize()}function oy(){for(let A=0;A4096?this.delayNode.delayTime.value=d/this.synth.context.sampleRate/2:(this.delayNode.delayTime.value=0,console.log("no")))}}function ay(A){A.connectIndividualOutputs(this.channelAnalysers),A.eventHandler.addEvent("drumchange","renderer-drum-change",()=>{this.updateFftSize()})}function $y(){for(let A of this.channelAnalysers)A.disconnect();Y5("%cAnalysers disconnected!",D1.recognized)}function ly(A){this.seq=A,this.seq.addOnTimeChangeEvent(()=>this.resetIndexes(),"renderer-time-change"),this.seq.addOnSongChangeEvent(async r=>{if(this.calculateNoteTimes(await this.seq.getMIDI()),this.resetIndexes(),r.RMIDInfo?.IPIC!==void 0){let l=new Blob([r.RMIDInfo?.IPIC.buffer]),g=URL.createObjectURL(l),d=this.canvas.classList.contains("light_mode")?0:.9;this.canvas.style.background=`linear-gradient(rgba(0, 0, 0, ${d}), rgba(0, 0, 0, ${d})), center center / cover url("${g}")`}else this.canvas.style.background=""},"renderer-song-change")}function cy(){this.noteTimes&&this.noteTimes.forEach(A=>A.renderStartIndex=0)}function _B(A,r){let l=0;for(let g=8*(r-1);g>=0;g-=8)l|=A[A.currentIndex++]<>>0}function QC(A,r){let l=new Array(r).fill(0);for(let g=r-1;g>=0;g--)l[g]=A&255,A>>=8;return l}var $h=.02;function gy(A){function r(R0){return R0.messageData=new l6(R0.messageData.buffer),R0.messageData.currentIndex=0,6e7/_B(R0.messageData,3)}let l=[],d=A.tracks.flat();d.sort((R0,E1)=>R0.ticks-E1.ticks);for(let R0=0;R0<16;R0++)l.push({renderStartIndex:0,notes:[]});let b=0,h0=60/(120*A.timeDivision),b0=0,p0=0;for(;b0>4,M=R0.messageStatusByte&15;if(E1===8){let K0=l[M].notes.findLast(_0=>_0.midiNote===R0.messageData[0]&&_0.length===-1);if(K0){let _0=b-K0.start;K0.length=_0<$h&&M===ki?$h:_0}p0--}else if(E1===9)if(R0.messageData[1]===0){let K0=l[M].notes.findLast(_0=>_0.midiNote===R0.messageData[0]&&_0.length===-1);if(K0){let _0=b-K0.start;K0.length=_0<$h&&M===ki?$h:_0}p0--}else l[R0.messageStatusByte&15].notes.push({midiNote:R0.messageData[0],start:b,length:-1,velocity:R0.messageData[1]/127}),p0++;else R0.messageStatusByte===81&&(h0=60/(r(R0)*A.timeDivision));if(++b0>=d.length)break;b+=h0*(d[b0].ticks-R0.ticks)}p0>0&&l.forEach((R0,E1)=>R0.notes.filter(M=>M.length===-1).forEach(M=>{let K0=b-M.start;M.length=K0<$h&&E1===ki?$h:K0})),this.noteTimes=l,Y5("%cFinished loading note times and ready to render the sequence!",D1.info)}var vD=1024,SD=4096,DD=2,bD=2,Im=.6,Em=.5,I$=1,E$=1,bB=16,ty=.6,iy=2,ry=81572,vi=class{constructor(r,l,g,d){this.noteFallingTimeMs=1e3,this.noteAfterTriggerTimeMs=0,this._keyRange={min:0,max:127},this.visualPitchBendOffset=0,this.lineThickness=bD,this._normalAnalyserFft=vD,this._drumAnalyserFft=SD,this.waveMultiplier=DD,this._notesFall=!0,this.sideways=!1,this._renderBool=!0,this.renderAnalysers=!0,this.renderNotes=!0,this.drawActiveNotes=!0,this.showVisualPitch=!0,this._stabilizeWaveforms=!0,this.renderChannels=Array(16).fill(!0),this.canvas=g,this.drawingContext=this.canvas.getContext("2d"),this.plainColors=r,this.computeColors(),this.synth=l,this.delayNode=d,this.notesOnScreen=0,this.channelAnalysers=[],this.createChannelAnalysers(l),this.connectChannelAnalysers(l)}get stabilizeWaveforms(){return this._stabilizeWaveforms}set stabilizeWaveforms(r){this._stabilizeWaveforms=r,this.updateFftSize()}set direction(r){this._notesFall=r==="down"}get direction(){return this._notesFall?"down":"up"}computeColors(){this.channelColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,this.canvas.width/128,0);return l.addColorStop(0,d$(r,g=>g*Em)),l.addColorStop(1,r),l}),this.darkerColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,this.canvas.width/128,0);return l.addColorStop(0,d$(r,g=>g*Em*Im)),l.addColorStop(1,d$(r,g=>g*Im)),l}),this.sidewaysChannelColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,d$(r,g=>g*Em)),l.addColorStop(1,r),l}),this.sidewaysDarkerColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,d$(r,g=>g*Em*Im)),l.addColorStop(1,d$(r,g=>g*Im)),l})}toggleDarkMode(){this.canvas.classList.toggle("light_mode")}onRender;get normalAnalyserFft(){return this._normalAnalyserFft}set normalAnalyserFft(r){this._normalAnalyserFft=r,this.updateFftSize()}get drumAnalyserFft(){return this._drumAnalyserFft}set drumAnalyserFft(r){this._drumAnalyserFft=r,this.updateFftSize()}get renderBool(){return this._renderBool}set renderBool(r){this._renderBool=r,r===!0?this.connectChannelAnalysers(this.synth):this.disconnectChannelAnalysers()}get keyRange(){return this._keyRange}set keyRange(r){if(r.max===void 0||r.min===void 0)throw new TypeError("No min or max property!");if(r.min>r.max){let l=r.min;r.min=r.max,r.max=l}r.min=Math.max(0,r.min),r.max=Math.min(127,r.max),this._keyRange=r}};vi.prototype.render=XQ;vi.prototype.computeNotePositions=ey;vi.prototype.createChannelAnalysers=Ay;vi.prototype.updateFftSize=oy;vi.prototype.connectChannelAnalysers=ay;vi.prototype.disconnectChannelAnalysers=$y;vi.prototype.connectSequencer=ly;vi.prototype.calculateNoteTimes=gy;vi.prototype.resetIndexes=cy;vi.prototype.renderWaveforms=ny;function r3(A,r){let l=0;for(let g=0;g>>0}function C$(A,r,l){for(let g=0;g>g*8&255}function B9(A,r){A[A.currentIndex++]=r&255,A[A.currentIndex++]=r>>8}function at(A,r){C$(A,r,4)}function lh(A,r){let l=r<<8|A;return l>32767?l-65536:l}function hy(A){return A>127?A-256:A}function Fe(A,r,l=void 0,g=!0){if(l){let d=A.slice(A.currentIndex,A.currentIndex+r);return A.currentIndex+=r,new TextDecoder(l.replace(/[^\x20-\x7E]/g,"")).decode(d.buffer)}else{let d=!1,b="";for(let h0=0;h0127){if(g){d=!0;continue}else if(b0===0){d=!0;continue}}b+=String.fromCharCode(b0)}}return b}}function So(A,r=0){let l=A.length;r>0&&(l=r);let g=new l6(l);return di(g,A,r),g}function di(A,r,l=0){l>0&&r.length>l&&(r=r.slice(0,l));for(let g=0;gr.length)for(let g=0;gl.header!=="LIST"?!1:(l.chunkData.currentIndex=0,Fe(l.chunkData,4)===r))}function Cm(A){let r=[A&127];for(A>>=7;A>0;)r.unshift(A&127|128),A>>=7;return r}function mm(A){let r=[];for(let d of A.tracks){let b=[],h0=0,b0;for(let p0 of d){let R0=p0.ticks-h0,E1;p0.messageStatusByte<=J3.keySignature||p0.messageStatusByte===J3.sequenceSpecific?E1=[255,p0.messageStatusByte,...Cm(p0.messageData.length),...p0.messageData]:p0.messageStatusByte===J3.systemExclusive?E1=[240,...Cm(p0.messageData.length),...p0.messageData]:(E1=[],b0!==p0.messageStatusByte&&(b0=p0.messageStatusByte,E1.push(p0.messageStatusByte)),E1.push(...p0.messageData)),b.push(...Cm(R0)),b.push(...E1),h0+=R0}r.push(new Uint8Array(b))}function l(d,b){for(let h0=0;h0A.chunkData.currentIndex;)r.push(new RB(A.chunkData));return r.length>1&&r.pop(),r}var x7={noController:0,noteOnVelocity:2,noteOnKeyNum:3,polyPressure:10,channelPressure:13,pitchWheel:14,pitchWheelRange:16,link:127},Qn={linear:0,concave:1,convex:2,switch:3},_D=[];for(let A=0;A<4;A++)_D.push([[],[]]);var o7=class A{constructor(r){r.srcEnum?(this.modulatorSource=r.srcEnum,this.modulatorDestination=r.dest,this.modulationSecondarySrc=r.secSrcEnum,this.transformAmount=r.amt,this.transformType=r.transform):(this.modulatorSource=r3(r,2),this.modulatorDestination=r3(r,2),this.transformAmount=lh(r[r.currentIndex++],r[r.currentIndex++]),this.modulationSecondarySrc=r3(r,2),this.transformType=r3(r,2)),this.modulatorDestination>58&&(this.modulatorDestination=b1.INVALID),this.sourcePolarity=this.modulatorSource>>9&1,this.sourceDirection=this.modulatorSource>>8&1,this.sourceUsesCC=this.modulatorSource>>7&1,this.sourceIndex=this.modulatorSource&127,this.sourceCurveType=this.modulatorSource>>10&3,this.secSrcPolarity=this.modulationSecondarySrc>>9&1,this.secSrcDirection=this.modulationSecondarySrc>>8&1,this.secSrcUsesCC=this.modulationSecondarySrc>>7&1,this.secSrcIndex=this.modulationSecondarySrc&127,this.secSrcCurveType=this.modulationSecondarySrc>>10&3}sumTransform(r){return new A({srcEnum:this.modulatorSource,secSrcEnum:this.modulationSecondarySrc,dest:this.modulatorDestination,transform:this.transformType,amt:this.transformAmount+r.transformAmount})}debugString(){function r(d,b){return Object.keys(d).find(h0=>d[h0]===b)}let l=r(Qn,this.sourceCurveType);l+=this.sourcePolarity===0?" unipolar ":" bipolar ",l+=this.sourceDirection===0?"forwards ":"backwards ",this.sourceUsesCC?l+=r(A6,this.sourceIndex):l+=r(x7,this.sourceIndex);let g=r(Qn,this.secSrcCurveType);return g+=this.secSrcPolarity===0?" unipolar ":" bipolar ",g+=this.secSrcCurveType===0?"forwards ":"backwards ",this.secSrcUsesCC?g+=r(A6,this.secSrcIndex):g+=r(x7,this.secSrcIndex),`Modulator: + Expected ${this._outputsAmount} got ${r.length}`);for(let l=0;l0?this.noteOn(l.channel,r[1],g):this.noteOff(l.channel,r[1]);break;case J3.noteOff:this.noteOff(l.channel,r[1]);break;case J3.pitchBend:this.pitchWheel(l.channel,r[2],r[1]);break;case J3.controllerChange:this.controllerChange(l.channel,r[1],r[2]);break;case J3.programChange:this.programChange(l.channel,r[1]);break;case J3.polyPressure:this.polyPressure(l.channel,r[0],r[1]);break;case J3.channelPressure:this.channelPressure(l.channel,r[1]);break;case J3.systemExclusive:this.systemExclusive(new l6(r.slice(1)));break;case J3.reset:this.stopAll(!0),this.resetControllers();break;default:break}}get currentTime(){return this.context.currentTime}get voicesAmount(){return this._voicesAmount}reverbateEverythingBecauseWhyNot(){for(let r=0;r{this.pressedKeys.delete(g),this.releaseNote(g,this.channel),this.synth.noteOff(this.channel,g)},r=(g,d)=>{let b;if(Bn)b=127;else{let b0=this.keys[0].getBoundingClientRect();if(this.keyboard.classList.contains("sideways")){let p0=d.clientX-b0.left,R0=b0.width;b=Math.floor((R0-p0)/R0*127)}else{let p0=d.clientY-b0.top,R0=b0.height;b=Math.floor(p0/R0*127)}}this.synth.noteOn(this.channel,g,b,this.enableDebugging)},l=g=>{let d=g.touches?Array.from(g.touches):[g],b=new Set;d.forEach(h0=>{let b0=document.elementFromPoint(h0.clientX,h0.clientY),p0=parseInt(b0.id.replace("note",""));b.add(p0),!(isNaN(p0)||p0<0||this.pressedKeys.has(p0))&&(this.pressedKeys.add(p0),r(p0,h0))}),this.pressedKeys.forEach(h0=>{b.has(h0)||A(h0)})};Bn||(document.addEventListener("mousedown",g=>{this.mouseHeld=!0,l(g)}),document.addEventListener("mouseup",()=>{this.mouseHeld=!1,this.pressedKeys.forEach(g=>{A(g)})}),this.keyboard.onmousemove=g=>{this.mouseHeld&&l(g)},this.keyboard.onmouseleave=()=>{this.pressedKeys.forEach(g=>{A(g)})}),this.keyboard.ontouchstart=l.bind(this),this.keyboard.ontouchend=l.bind(this),this.keyboard.ontouchmove=l.bind(this)}var WQ=20,pC=class{constructor(r,l){this.mouseHeld=!1,this.pressedKeys=new Set,this.mode="light",this.enableDebugging=!1,this.sizeChangeAnimationId=-1,this.modeChangeAnimationId=-1,this._keyRange={min:0,max:127},document.addEventListener("keydown",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,A6.sustainPedal,127),this.keyboard.style.filter="brightness(0.5)")}),document.addEventListener("keyup",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,A6.sustainPedal,0),this.keyboard.style.filter="")}),this.synth=l,this.channel=0,this.channelColors=r,this._shown=!0,this._createKeyboard(),this.synth.eventHandler.addEvent("noteon","keyboard-note-on",g=>{this.pressNote(g.midiNote,g.channel,g.velocity)}),this.synth.eventHandler.addEvent("noteoff","keyboard-note-off",g=>{this.releaseNote(g.midiNote,g.channel)}),this.synth.eventHandler.addEvent("stopall","keyboard-stop-all",()=>{this.clearNotes()}),this.synth.eventHandler.addEvent("mutechannel","keyboard-mute-channel",g=>{if(g.isMuted)for(let d=0;d<128;d++)this.releaseNote(d,g.channel)})}set shown(r){r===!0?this.keyboard.style.display="":this.keyboard.style.display="none",this._shown=r}get shown(){return this._shown}_createKeyboard(){this.keyboard=document.getElementById("keyboard"),this.keyboard.innerHTML="",this.keys=[],this.keyColors=[];for(let r=this._keyRange.min;r=0&&(b=l(r-1)),r<127&&(h0=l(r+1)),h0&&b?g.classList.add("between_sharps"):b?g.classList.add("left_sharp"):h0&&g.classList.add("right_sharp")}return g}toggleMode(r=!0){if(this.mode==="light"?this.mode="dark":this.mode="light",!r){this.keys.forEach(g=>{g.classList.contains("flat_key")&&g.classList.toggle("flat_dark_key")});return}this.modeChangeAnimationId&&clearTimeout(this.modeChangeAnimationId),this.keyboard.classList.add("mode_transform"),document.body.scrollHeight<=window.innerHeight&&document.body.classList.add("no_scroll"),this.modeChangeAnimationId=setTimeout(()=>{this.keys.forEach(g=>{g.classList.contains("flat_key")&&g.classList.toggle("flat_dark_key")}),this.keyboard.classList.remove("mode_transform"),setTimeout(()=>document.body.classList.remove("no_scroll"),500)},500)}get keyRange(){return this._keyRange}set keyRange(r){if(r.max===void 0||r.min===void 0)throw new TypeError("No min or max property!");if(r.min>r.max){let l=r.min;r.min=r.max,r.max=l}r.min=Math.max(0,r.min),r.max=Math.min(127,r.max),this.setKeyRange(r,!0)}setKeyRange(r,l=!0){Math.abs(r.max-r.min)<12&&(r.min-=6,r.max=r.min+12);let d=900/(r.max-r.min+5),b=document.styleSheets[0].cssRules,h0;for(let b0 of b)if(b0.selectorText==="#keyboard .key"){h0=b0;break}if(h0.style.setProperty("--pressed-transform-skew",`${8e-4/(d/7)}`),l){this.sizeChangeAnimationId&&clearTimeout(this.sizeChangeAnimationId);let b0=getComputedStyle(this.keyboard),p0=parseFloat(b0.getPropertyValue("--current-min-height").replace(/[^\d.]+/g,"")),R0=this.keyboard.getBoundingClientRect().height,E1=d/p0,M=R0*E1-R0,K0=(this._keyRange.min+this._keyRange.max)/2,_0=(r.min+r.max)/2;this._keyRange=r;let k1=this.keys.find(_5=>_5.classList.contains("sharp_key")).getBoundingClientRect().width,h2=(K0-_0)*k1,R1=parseFloat(b0.getPropertyValue("--key-border-radius").replace(/[^\d.]+/g,""));this.keyboard.style.marginTop=`${M}px`,this.keyboard.style.transition="",this.keyboard.style.transform=`scale(${E1}) translateX(${h2}px)`,this.keyboard.style.setProperty("--key-border-radius",`${R1/E1}vmin`),this.sizeChangeAnimationId=setTimeout(()=>{this.keyboard.style.setProperty("--current-min-height",`${d}`),this.keyboard.style.transition="none",this.keyboard.style.transform="",this.keyboard.style.marginTop="",this.keyboard.style.setProperty("--key-border-radius",""),this._createKeyboard(),setTimeout(()=>this.keyboard.style.transition="",75)},500)}else this.keyboard.style.setProperty("--current-min-height",`${d}`),this._keyRange=r,this._createKeyboard()}selectChannel(r){this.channel=r}pressNote(r,l,g){let d=this.keys[r-this._keyRange.min];if(d===void 0)return;d.classList.add("pressed");let b=d.classList.contains("sharp_key"),h0=g/127,b0=this.channelColors[l%16].match(/\d+(\.\d+)?/g).map(parseFloat),p0;if(!b&&this.mode==="light"?p0=`rgba(${b0.slice(0,3).map(E1=>255-(255-E1)*h0).join(", ")}, ${b0[3]})`:p0=`rgba(${b0.slice(0,3).map(E1=>E1*h0).join(", ")}, ${b0[3]})`,d.style.background=p0,this.mode==="dark"){let R0=WQ*h0;d.style.boxShadow=`${p0} 0px 0px ${R0}px ${R0/5}px`}this.keyColors[r-this._keyRange.min].push(this.channelColors[l%16])}releaseNote(r,l){let g=this.keys[r-this._keyRange.min];if(g===void 0)return;l%=this.channelColors.length;let d=this.keyColors[r-this._keyRange.min];if(!d)return;let b=d.findLastIndex(h0=>h0===this.channelColors[l]);b!==-1&&(d.splice(b,1),g.style.background=d[d.length-1],this.mode==="dark"&&(g.style.boxShadow=`0px 0px ${WQ}px ${d[d.length-1]}`),d.length<1&&(g.classList.remove("pressed"),g.style.background="",g.style.boxShadow=""))}clearNotes(){this.keys.forEach((r,l)=>{r.classList.remove("pressed"),r.style.background="",r.style.boxShadow="",this.keyColors[l]=[]})}};pC.prototype._handlePointers=ZQ;function d$(A,r){let l=A.replace(/[^\d,]/g,"").split(",");return`rgb(${r(parseInt(l[0]))}, ${r(parseInt(l[1]))}, ${r(parseInt(l[2]))})`}var kD="#000";function jQ(A,r,l){A.forEach(g=>{if(g.pressedProgress===0)return;r.fillStyle=g.color;let d=g.pressedProgress*g.velocity;if(r.globalAlpha=.5*d,l){r.fillRect(g.xPos,g.yPos-g.height*d,g.width,g.height*(d*2+1)),r.globalAlpha=1;return}r.fillRect(g.xPos-g.width*d,g.yPos,g.width*(d*2+1),g.height),r.globalAlpha=1}),A.forEach(g=>{r.fillStyle=g.color,r.save(),r.translate(g.xPos,g.yPos),r.fillRect(0,0,g.width,g.height),r.restore(),r.strokeStyle=kD,r.lineWidth=g.stroke,r.strokeRect(g.xPos,g.yPos,g.width,g.height)})}var DB=!1;function XQ(A=!0,r=!1){let l=(this.seq===void 0||this?.seq?.paused===!0)&&this.synth.voicesAmount===0&&!r;if(!this.renderBool||l)if(DB){A&&requestAnimationFrame(this.render.bind(this));return}else DB=!0;else DB=!1;if(A&&this.drawingContext.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderAnalysers&&!this.synth.highPerformanceMode&&this.renderWaveforms(),this.renderNotes&&this.noteTimes){let b=this.computeNotePositions(this.synth.highPerformanceMode);this.synth.highPerformanceMode||jQ(b,this.drawingContext,this.sideways)}let g=performance.now()-this.frameTimeStart;this.frameTimeStart=performance.now();let d=1e3/g;this.drawingContext.textBaseline="hanging",this.drawingContext.textAlign="end",this.drawingContext.font=`${bB}px Verdana`,this.drawingContext.fillStyle="white",this.drawingContext.strokeStyle="white",this.drawingContext.fillText(`${this.notesOnScreen} notes`,this.canvas.width,bB+5),this.drawingContext.fillText(Math.round(d).toString()+" FPS",this.canvas.width,5),this.onRender&&this.onRender(),A&&requestAnimationFrame(this.render.bind(this))}function ey(A=!1){this.notesOnScreen=0;let r=this.sideways?this.canvas.height:this.canvas.width,l=this.sideways?this.canvas.width:this.canvas.height,g=this.keyRange.max-this.keyRange.min,d=r/(g+1),b=d-E$*2,h0=this.noteFallingTimeMs/1e3,b0=this.noteAfterTriggerTimeMs/1e3,p0=this.seq.currentHighResolutionTime,R0=p0-b0,E1=h0+b0,M=R0+E1,K0=iy/E1,_0=[];this.synth.channelProperties.forEach(h2=>{if(this.showVisualPitch){let R1=h2.pitchBend-8192+this.visualPitchBendOffset;_0.push(h2.pitchBendRangeSemitones*(R1/8192*d))}else _0.push(0)});let k1=[];return this.noteTimes.forEach((h2,R1)=>{if(h2.renderStartIndex>=h2.notes.length||!this.renderChannels[R1])return;let _5=h2.renderStartIndex,v2=h2.notes,J2=v2[_5],n3=-1;for(;J2.start<=M&&(_5++,!(this.notesOnScreen>ry));){let U5=J2.start+J2.length;if(U5>R0&&J2.length>0){let a0=J2.length/E1*l-E$*2;if(this.notesOnScreen<1e3||a0>K0){n3===-1&&(n3=_5-1);let J5=(J2.start-R0)/E1*l,n6;if(this._notesFall?n6=l-a0-J5+E$:n6=J5+E$,J2.midiNotethis.keyRange.max){if(_5>=v2.length)break;J2=v2[_5];continue}let c6=J2.midiNote-this.keyRange.min,O6=d*c6+E$,g6,u4,Ke,J4;if(this.sideways?(g6=n6,u4=O6,J4=b,Ke=a0):(u4=n6,g6=O6,Ke=b,J4=a0),this.notesOnScreen++,A)this.drawingContext.fillStyle=this.plainColors[R1],this.drawingContext.fillRect(g6+I$+E$,u4+I$,Ke-I$*2,J4-I$*2);else{let p9;if(J2.start>p0||U5=v2.length)break;J2=v2[_5]}n3>-1&&(h2.renderStartIndex=n3)}),k1.sort((h2,R1)=>R1.height-h2.height),k1}function ny(){let A=this.canvas.width/4,r=this.canvas.height/4;this.channelAnalysers.forEach((l,g)=>{let d=g%4,b=Math.floor(g/4),h0=!1;for(let M=g;M0){h0=!0;break}if(!h0){let M=this.canvas.width/4,K0=this.canvas.height/4,_0=M*d,k1=K0*b+K0/2;this.drawingContext.lineWidth=this.lineThickness,this.drawingContext.strokeStyle=this.channelColors[g],this.drawingContext.beginPath(),this.drawingContext.moveTo(_0,k1),this.drawingContext.lineTo(_0+M,k1),this.drawingContext.stroke();return}let b0=new Float32Array(l.frequencyBinCount);l.getFloatTimeDomainData(b0);let p0=A*d,R0=r*b+r/2,E1=this.waveMultiplier*r;if(this.drawingContext.lineWidth=this.lineThickness,this.drawingContext.strokeStyle=this.channelColors[g],this.drawingContext.beginPath(),this._stabilizeWaveforms){let M=b0.length/4,K0=A/M,_0=Math.floor(M/2),k1=b0.length-_0;for(let v2=k1;v2>=1;v2--)if(b0[v2-1]<0&&b0[v2]>=0){k1=v2;break}let h2=p0,R1=k1-_0,_5=k1+_0;for(let v2=R1;v2<_5;v2++)this.drawingContext.lineTo(h2,R0+b0[v2]*E1),h2+=K0}else{let M=A/b0.length,K0=p0;for(let _0=0;_0{this.renderChannels[r.channel]=!r.isMuted}),this.updateFftSize()}function oy(){for(let A=0;A4096?this.delayNode.delayTime.value=d/this.synth.context.sampleRate/2:this.delayNode.delayTime.value=0)}}function ay(A){A.connectIndividualOutputs(this.channelAnalysers),A.eventHandler.addEvent("drumchange","renderer-drum-change",()=>{this.updateFftSize()})}function $y(){for(let A of this.channelAnalysers)A.disconnect();Y5("%cAnalysers disconnected!",D1.recognized)}function ly(A){this.seq=A,this.seq.addOnTimeChangeEvent(()=>this.resetIndexes(),"renderer-time-change"),this.seq.addOnSongChangeEvent(async r=>{if(this.calculateNoteTimes(await this.seq.getMIDI()),this.resetIndexes(),r.RMIDInfo?.IPIC!==void 0){let l=new Blob([r.RMIDInfo?.IPIC.buffer]),g=URL.createObjectURL(l),d=this.canvas.classList.contains("light_mode")?0:.9;this.canvas.style.background=`linear-gradient(rgba(0, 0, 0, ${d}), rgba(0, 0, 0, ${d})), center center / cover url("${g}")`}else this.canvas.style.background=""},"renderer-song-change")}function cy(){this.noteTimes&&this.noteTimes.forEach(A=>A.renderStartIndex=0)}function _B(A,r){let l=0;for(let g=8*(r-1);g>=0;g-=8)l|=A[A.currentIndex++]<>>0}function QC(A,r){let l=new Array(r).fill(0);for(let g=r-1;g>=0;g--)l[g]=A&255,A>>=8;return l}var $h=.02;function gy(A){function r(R0){return R0.messageData=new l6(R0.messageData.buffer),R0.messageData.currentIndex=0,6e7/_B(R0.messageData,3)}let l=[],d=A.tracks.flat();d.sort((R0,E1)=>R0.ticks-E1.ticks);for(let R0=0;R0<16;R0++)l.push({renderStartIndex:0,notes:[]});let b=0,h0=60/(120*A.timeDivision),b0=0,p0=0;for(;b0>4,M=R0.messageStatusByte&15;if(E1===8){let K0=l[M].notes.findLast(_0=>_0.midiNote===R0.messageData[0]&&_0.length===-1);if(K0){let _0=b-K0.start;K0.length=_0<$h&&M===ki?$h:_0}p0--}else if(E1===9)if(R0.messageData[1]===0){let K0=l[M].notes.findLast(_0=>_0.midiNote===R0.messageData[0]&&_0.length===-1);if(K0){let _0=b-K0.start;K0.length=_0<$h&&M===ki?$h:_0}p0--}else l[R0.messageStatusByte&15].notes.push({midiNote:R0.messageData[0],start:b,length:-1,velocity:R0.messageData[1]/127}),p0++;else R0.messageStatusByte===81&&(h0=60/(r(R0)*A.timeDivision));if(++b0>=d.length)break;b+=h0*(d[b0].ticks-R0.ticks)}p0>0&&l.forEach((R0,E1)=>R0.notes.filter(M=>M.length===-1).forEach(M=>{let K0=b-M.start;M.length=K0<$h&&E1===ki?$h:K0})),this.noteTimes=l,Y5("%cFinished loading note times and ready to render the sequence!",D1.info)}var vD=1024,SD=4096,DD=2,bD=2,Im=.6,Em=.5,I$=1,E$=1,bB=16,ty=.6,iy=2,ry=81572,vi=class{constructor(r,l,g,d){this.noteFallingTimeMs=1e3,this.noteAfterTriggerTimeMs=0,this._keyRange={min:0,max:127},this.visualPitchBendOffset=0,this.lineThickness=bD,this._normalAnalyserFft=vD,this._drumAnalyserFft=SD,this.waveMultiplier=DD,this._notesFall=!0,this.sideways=!1,this._renderBool=!0,this.renderAnalysers=!0,this.renderNotes=!0,this.drawActiveNotes=!0,this.showVisualPitch=!0,this._stabilizeWaveforms=!0,this.renderChannels=Array(16).fill(!0),this.canvas=g,this.drawingContext=this.canvas.getContext("2d"),this.plainColors=r,this.computeColors(),this.synth=l,this.delayNode=d,this.notesOnScreen=0,this.channelAnalysers=[],this.createChannelAnalysers(l),this.connectChannelAnalysers(l)}get stabilizeWaveforms(){return this._stabilizeWaveforms}set stabilizeWaveforms(r){this._stabilizeWaveforms=r,this.updateFftSize()}set direction(r){this._notesFall=r==="down"}get direction(){return this._notesFall?"down":"up"}computeColors(){this.channelColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,this.canvas.width/128,0);return l.addColorStop(0,d$(r,g=>g*Em)),l.addColorStop(1,r),l}),this.darkerColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,this.canvas.width/128,0);return l.addColorStop(0,d$(r,g=>g*Em*Im)),l.addColorStop(1,d$(r,g=>g*Im)),l}),this.sidewaysChannelColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,d$(r,g=>g*Em)),l.addColorStop(1,r),l}),this.sidewaysDarkerColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,d$(r,g=>g*Em*Im)),l.addColorStop(1,d$(r,g=>g*Im)),l})}toggleDarkMode(){this.canvas.classList.toggle("light_mode")}onRender;get normalAnalyserFft(){return this._normalAnalyserFft}set normalAnalyserFft(r){this._normalAnalyserFft=r,this.updateFftSize()}get drumAnalyserFft(){return this._drumAnalyserFft}set drumAnalyserFft(r){this._drumAnalyserFft=r,this.updateFftSize()}get renderBool(){return this._renderBool}set renderBool(r){this._renderBool=r,r===!0?this.connectChannelAnalysers(this.synth):this.disconnectChannelAnalysers()}get keyRange(){return this._keyRange}set keyRange(r){if(r.max===void 0||r.min===void 0)throw new TypeError("No min or max property!");if(r.min>r.max){let l=r.min;r.min=r.max,r.max=l}r.min=Math.max(0,r.min),r.max=Math.min(127,r.max),this._keyRange=r}};vi.prototype.render=XQ;vi.prototype.computeNotePositions=ey;vi.prototype.createChannelAnalysers=Ay;vi.prototype.updateFftSize=oy;vi.prototype.connectChannelAnalysers=ay;vi.prototype.disconnectChannelAnalysers=$y;vi.prototype.connectSequencer=ly;vi.prototype.calculateNoteTimes=gy;vi.prototype.resetIndexes=cy;vi.prototype.renderWaveforms=ny;function r3(A,r){let l=0;for(let g=0;g>>0}function C$(A,r,l){for(let g=0;g>g*8&255}function B9(A,r){A[A.currentIndex++]=r&255,A[A.currentIndex++]=r>>8}function at(A,r){C$(A,r,4)}function lh(A,r){let l=r<<8|A;return l>32767?l-65536:l}function hy(A){return A>127?A-256:A}function Fe(A,r,l=void 0,g=!0){if(l){let d=A.slice(A.currentIndex,A.currentIndex+r);return A.currentIndex+=r,new TextDecoder(l.replace(/[^\x20-\x7E]/g,"")).decode(d.buffer)}else{let d=!1,b="";for(let h0=0;h0127){if(g){d=!0;continue}else if(b0===0){d=!0;continue}}b+=String.fromCharCode(b0)}}return b}}function So(A,r=0){let l=A.length;r>0&&(l=r);let g=new l6(l);return di(g,A,r),g}function di(A,r,l=0){l>0&&r.length>l&&(r=r.slice(0,l));for(let g=0;gr.length)for(let g=0;gl.header!=="LIST"?!1:(l.chunkData.currentIndex=0,Fe(l.chunkData,4)===r))}function Cm(A){let r=[A&127];for(A>>=7;A>0;)r.unshift(A&127|128),A>>=7;return r}function mm(A){let r=[];for(let d of A.tracks){let b=[],h0=0,b0;for(let p0 of d){let R0=p0.ticks-h0,E1;p0.messageStatusByte<=J3.keySignature||p0.messageStatusByte===J3.sequenceSpecific?E1=[255,p0.messageStatusByte,...Cm(p0.messageData.length),...p0.messageData]:p0.messageStatusByte===J3.systemExclusive?E1=[240,...Cm(p0.messageData.length),...p0.messageData]:(E1=[],b0!==p0.messageStatusByte&&(b0=p0.messageStatusByte,E1.push(p0.messageStatusByte)),E1.push(...p0.messageData)),b.push(...Cm(R0)),b.push(...E1),h0+=R0}r.push(new Uint8Array(b))}function l(d,b){for(let h0=0;h0A.chunkData.currentIndex;)r.push(new RB(A.chunkData));return r.length>1&&r.pop(),r}var x7={noController:0,noteOnVelocity:2,noteOnKeyNum:3,polyPressure:10,channelPressure:13,pitchWheel:14,pitchWheelRange:16,link:127},Qn={linear:0,concave:1,convex:2,switch:3},_D=[];for(let A=0;A<4;A++)_D.push([[],[]]);var o7=class A{constructor(r){r.srcEnum?(this.modulatorSource=r.srcEnum,this.modulatorDestination=r.dest,this.modulationSecondarySrc=r.secSrcEnum,this.transformAmount=r.amt,this.transformType=r.transform):(this.modulatorSource=r3(r,2),this.modulatorDestination=r3(r,2),this.transformAmount=lh(r[r.currentIndex++],r[r.currentIndex++]),this.modulationSecondarySrc=r3(r,2),this.transformType=r3(r,2)),this.modulatorDestination>58&&(this.modulatorDestination=b1.INVALID),this.sourcePolarity=this.modulatorSource>>9&1,this.sourceDirection=this.modulatorSource>>8&1,this.sourceUsesCC=this.modulatorSource>>7&1,this.sourceIndex=this.modulatorSource&127,this.sourceCurveType=this.modulatorSource>>10&3,this.secSrcPolarity=this.modulationSecondarySrc>>9&1,this.secSrcDirection=this.modulationSecondarySrc>>8&1,this.secSrcUsesCC=this.modulationSecondarySrc>>7&1,this.secSrcIndex=this.modulationSecondarySrc&127,this.secSrcCurveType=this.modulationSecondarySrc>>10&3}sumTransform(r){return new A({srcEnum:this.modulatorSource,secSrcEnum:this.modulationSecondarySrc,dest:this.modulatorDestination,transform:this.transformType,amt:this.transformAmount+r.transformAmount})}debugString(){function r(d,b){return Object.keys(d).find(h0=>d[h0]===b)}let l=r(Qn,this.sourceCurveType);l+=this.sourcePolarity===0?" unipolar ":" bipolar ",l+=this.sourceDirection===0?"forwards ":"backwards ",this.sourceUsesCC?l+=r(A6,this.sourceIndex):l+=r(x7,this.sourceIndex);let g=r(Qn,this.secSrcCurveType);return g+=this.secSrcPolarity===0?" unipolar ":" bipolar ",g+=this.secSrcCurveType===0?"forwards ":"backwards ",this.secSrcUsesCC?g+=r(A6,this.secSrcIndex):g+=r(x7,this.secSrcIndex),`Modulator: Source: ${l} Secondary source: ${g} Destination: ${r(b1,this.modulatorDestination)} diff --git a/src/website/minified/local_main.min.js b/src/website/minified/local_main.min.js index 0ec93c20..2b21c369 100644 --- a/src/website/minified/local_main.min.js +++ b/src/website/minified/local_main.min.js @@ -1,5 +1,5 @@ var am=(o=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(o,{get:(r,l)=>(typeof require<"u"?require:r)[l]}):o)(function(o){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+o+'" is not supported')});var l6=class extends Uint8Array{constructor(r){super(r),this.currentIndex=0}currentIndex};function Ds(o){let r=o.reduce((E,x)=>E+x.length,0),l=new l6(r),g=0;for(let E of o)l.set(E,g),g+=E.length;return l}function h$(o){o=Math.floor(o);let r=Math.floor(o/60),l=Math.round(o-r*60);return{minutes:r,seconds:l,time:`${r.toString().padStart(2,"0")}:${l.toString().padStart(2,"0")}`}}function CB(o){return o.trim().replaceAll(".mid","").replaceAll(".rmi","").replaceAll("_"," ")}var D1={warn:"color: orange;",unrecognized:"color: red;",info:"color: aqua;",recognized:"color: lime",value:"color: yellow; background-color: black;"};var fi=class{constructor(r,l,g){this.ticks=r,this.messageStatusByte=l,this.messageData=g}};var J3={noteOff:128,noteOn:144,polyPressure:160,controllerChange:176,programChange:192,channelPressure:208,pitchBend:224,systemExclusive:240,timecode:241,songPosition:242,songSelect:243,tuneRequest:246,clock:248,start:250,continue:251,stop:252,activeSensing:254,reset:255,sequenceNumber:0,text:1,copyright:2,trackName:3,instrumentName:4,lyric:5,marker:6,cuePoint:7,midiChannelPrefix:32,midiPort:33,endOfTrack:47,setTempo:81,smpteOffset:84,timeSignature:88,keySignature:89,sequenceSpecific:127};function UQ(o){let r=o&240,l=o&15,g=-1,E=o;return r>=128&&r<=224&&(g=l,E=r),{status:E,channel:g}}var A6={bankSelect:0,modulationWheel:1,breathController:2,footController:4,portamentoTime:5,dataEntryMsb:6,mainVolume:7,balance:8,pan:10,expressionController:11,effectControl1:12,effectControl2:13,generalPurposeController1:16,generalPurposeController2:17,generalPurposeController3:18,generalPurposeController4:19,lsbForControl0BankSelect:32,lsbForControl1ModulationWheel:33,lsbForControl2BreathController:34,lsbForControl4FootController:36,lsbForControl5PortamentoTime:37,lsbForControl6DataEntry:38,lsbForControl7MainVolume:39,lsbForControl8Balance:40,lsbForControl10Pan:42,lsbForControl11ExpressionController:43,lsbForControl12EffectControl1:44,lsbForControl13EffectControl2:45,sustainPedal:64,portamentoOnOff:65,sostenutoPedal:66,softPedal:67,legatoFootswitch:68,hold2Pedal:69,soundVariation:70,timbreHarmonicContent:71,releaseTime:72,attackTime:73,brightness:74,soundController6:75,soundController7:76,soundController8:77,soundController9:78,soundController10:79,generalPurposeController5:80,generalPurposeController6:81,generalPurposeController7:82,generalPurposeController8:83,portamentoControl:84,effects1Depth:91,effects2Depth:92,effects3Depth:93,effects4Depth:94,effects5Depth:95,dataIncrement:96,dataDecrement:97,NRPNLsb:98,NRPNMsb:99,RPNLsb:100,RPNMsb:101,allSoundOff:120,resetAllControllers:121,localControlOnOff:122,allNotesOff:123,omniModeOff:124,omniModeOn:125,monoModeOn:126,polyModeOn:127};var $m=class{constructor(){this.events={noteoff:{},noteon:{},pitchwheel:{},controllerchange:{},programchange:{},channelpressure:{},polypressure:{},drumchange:{},stopall:{},newchannel:{},mutechannel:{},presetlistchange:{},allcontrollerreset:{},soundfonterror:{}}}addEvent(r,l,g){this.events[r][l]=g}removeEvent(r,l){delete this.events[r][l]}callEvent(r,l){this.events[r]&&Object.values(this.events[r]).forEach(g=>g(l))}};var mB={nodesAmount:4,defaultDelay:.03,delayVariation:.01,stereoDifference:.02,oscillatorFrequency:.3,oscillatorFrequencyVariation:.05,oscillatorGain:.003},lm=class{constructor(r,l=mB){let g=r.context;this.input=new ChannelSplitterNode(g,{numberOfOutputs:2});let E=new ChannelMergerNode(g,{numberOfInputs:2}),x=[],u0=[],R0=l.oscillatorFrequency,p0=l.defaultDelay;for(let D0=0;D0{let x=await E.arrayBuffer();l.buffer=await o.decodeAudioData(x)})}return l}var B8={noteOff:0,noteOn:1,ccChange:2,programChange:3,channelPressure:4,polyPressure:5,killNote:6,ccReset:7,setChannelVibrato:8,soundFontManager:9,stopAll:10,killNotes:11,muteChannel:12,addNewChannel:13,customcCcChange:14,debugMessage:15,systemExclusive:16,setMasterParameter:17,setDrums:18,pitchWheel:19,transpose:20,highPerformanceMode:21,lockController:22,sequencerSpecific:23,requestSynthesizerSnapshot:24,setLogLevel:25},dC={mainVolume:0,masterPan:1,voicesCap:2,interpolationType:3},Pi=-1,f$={channelProperties:0,eventCall:1,reportedCurrentTime:2,sequencerSpecific:3,synthesizerSnapshot:4,ready:5,soundfontError:6,identify:7};var fD=!0,uD=!0,BB=!0;function j5(...o){fD&&console.info(...o)}function fe(...o){uD&&console.warn(...o)}function or(...o){BB&&console.group(...o)}function Xt(...o){BB&&console.groupCollapsed(...o)}function t4(){BB&&console.groupEnd()}var PQ={chorusEnabled:!0,chorusConfig:mB,reverbEnabled:!0,reverbImpulseResponse:void 0};var EC={reloadSoundFont:0,addNewSoundFont:2,deleteSoundFont:3,rearrangeSoundFonts:4};var cm=class{constructor(r){this.soundfontList=[{id:"main",bankOffset:0}],this._port=r.worklet.port,this.synth=r}_sendToWorklet(r,l){this._port.postMessage({messageType:B8.soundFontManager,messageData:[r,l]})}async addNewSoundFont(r,l,g=0){if(this.soundfontList.find(E=>E.id===l)!==void 0)throw new Error("Cannot overwrite the existing soundfont. Use soundfontManager.delete(id) instead.");this._sendToWorklet(EC.addNewSoundFont,[r,l,g]),await new Promise(E=>this.synth.resolveWhenReady=E),this.soundfontList.push({id:l,bankOffset:g})}deleteSoundFont(r){if(this.soundfontList.length===0){fe("1 soundfont left. Aborting!");return}if(this.soundfontList.findIndex(l=>l.id===r)===-1){fe(`No soundfont with id of "${r}" found. Aborting!`);return}this._sendToWorklet(EC.deleteSoundFont,r)}rearrangeSoundFonts(r){this._sendToWorklet(EC.rearrangeSoundFonts,r),this.soundfontList.sort((l,g)=>r.indexOf(l.id)-r.indexOf(g.id))}async reloadManager(r){this._sendToWorklet(EC.reloadSoundFont,r),await new Promise(l=>this.synth.resolveWhenReady=l)}};var ID="spessasynth-worklet-system",pB=450,ki=9,dD=16;var sh=class{constructor(r,l,g=!0,E=void 0,x=PQ){j5("%cInitializing SpessaSynth synthesizer...",D1.info),this.context=r.context;let u0=E?.oneOutput===!0;this.eventHandler=new $m,this._voiceCap=pB,this._outputsAmount=dD,this.channelsAmount=this._outputsAmount,this.resolveWhenReady=void 0,this.isReady=new Promise(D0=>this.resolveWhenReady=D0),this.channelProperties=[];for(let D0=0;D0this.handleMessage(D0.data),this.soundfontManager=new cm(this),this._snapshotCallback=void 0,this.sequencerCallbackFunction=void 0,x.reverbEnabled&&!u0&&(this.reverbProcessor=OQ(this.context,x.reverbImpulseResponse),this.reverbProcessor.connect(r),this.worklet.connect(this.reverbProcessor,0)),x.chorusEnabled&&!u0&&(this.chorusProcessor=new lm(r,x.chorusConfig),this.worklet.connect(this.chorusProcessor.input,1)),u0)this.worklet.connect(r,0);else for(let D0=2;D0{this.channelsAmount++})}get voiceCap(){return this._voiceCap}set voiceCap(r){this._setMasterParam(dC.voicesCap,r),this._voiceCap=r}set highPerformanceMode(r){this._highPerformanceMode=r}get highPerformanceMode(){return this._highPerformanceMode}setLogLevel(r,l,g,E){this.post({channelNumber:Pi,messageType:B8.setLogLevel,messageData:[r,l,g,E]})}_setMasterParam(r,l){this.post({channelNumber:Pi,messageType:B8.setMasterParameter,messageData:[r,l]})}setInterpolationType(r){this._setMasterParam(dC.interpolationType,r)}handleMessage(r){let l=r.messageData;switch(r.messageType){case f$.channelProperties:this.channelProperties=l,this._voicesAmount=this.channelProperties.reduce((g,E)=>g+E.voicesAmount,0);break;case f$.eventCall:this.eventHandler.callEvent(l.eventName,l.eventData);break;case f$.sequencerSpecific:this.sequencerCallbackFunction&&this.sequencerCallbackFunction(l.messageType,l.messageData);break;case f$.synthesizerSnapshot:this._snapshotCallback&&this._snapshotCallback(l);break;case f$.ready:this.resolveWhenReady();break;case f$.soundfontError:fe(new Error(l)),this.eventHandler.callEvent("soundfonterror",l);break}}async getSynthesizerSnapshot(){return new Promise(r=>{this._snapshotCallback=l=>{this._snapshotCallback=void 0,r(l)},this.post({messageType:B8.requestSynthesizerSnapshot,messageData:void 0,channelNumber:Pi})})}addNewChannel(r=!0){this.channelProperties.push({voicesAmount:0,pitchBend:0,pitchBendRangeSemitones:0,isMuted:!1,isDrum:!1}),r&&this.post({channelNumber:0,messageType:B8.addNewChannel,messageData:null})}setVibrato(r,l){this.post({channelNumber:r,messageType:B8.setChannelVibrato,messageData:l})}connectIndividualOutputs(r){if(r.length!==this._outputsAmount)throw new Error(`input nodes amount differs from the system's outputs amount! - Expected ${this._outputsAmount} got ${r.length}`);for(let l=0;l0?this.noteOn(l.channel,r[1],g):this.noteOff(l.channel,r[1]);break;case J3.noteOff:this.noteOff(l.channel,r[1]);break;case J3.pitchBend:this.pitchWheel(l.channel,r[2],r[1]);break;case J3.controllerChange:this.controllerChange(l.channel,r[1],r[2]);break;case J3.programChange:this.programChange(l.channel,r[1]);break;case J3.polyPressure:this.polyPressure(l.channel,r[0],r[1]);break;case J3.channelPressure:this.channelPressure(l.channel,r[1]);break;case J3.systemExclusive:this.systemExclusive(new l6(r.slice(1)));break;case J3.reset:this.stopAll(!0),this.resetControllers();break;default:break}}get currentTime(){return this.context.currentTime}get voicesAmount(){return this._voicesAmount}reverbateEverythingBecauseWhyNot(){for(let r=0;r{this.pressedKeys.delete(g),this.releaseNote(g,this.channel),this.synth.noteOff(this.channel,g)},r=(g,E)=>{let x;if(vo)x=127;else{let R0=this.keys[0].getBoundingClientRect();if(this.keyboard.classList.contains("sideways")){let p0=E.clientX-R0.left,D0=R0.width;x=Math.floor((D0-p0)/D0*127)}else{let p0=E.clientY-R0.top,D0=R0.height;x=Math.floor(p0/D0*127)}}this.synth.noteOn(this.channel,g,x,this.enableDebugging)},l=g=>{let E=g.touches?Array.from(g.touches):[g],x=new Set;E.forEach(u0=>{let R0=document.elementFromPoint(u0.clientX,u0.clientY),p0=parseInt(R0.id.replace("note",""));x.add(p0),!(isNaN(p0)||p0<0||this.pressedKeys.has(p0))&&(this.pressedKeys.add(p0),r(p0,u0))}),this.pressedKeys.forEach(u0=>{x.has(u0)||o(u0)})};vo||(document.addEventListener("mousedown",g=>{this.mouseHeld=!0,l(g)}),document.addEventListener("mouseup",()=>{this.mouseHeld=!1,this.pressedKeys.forEach(g=>{o(g)})}),this.keyboard.onmousemove=g=>{this.mouseHeld&&l(g)},this.keyboard.onmouseleave=()=>{this.pressedKeys.forEach(g=>{o(g)})}),this.keyboard.ontouchstart=l.bind(this),this.keyboard.ontouchend=l.bind(this),this.keyboard.ontouchmove=l.bind(this)}var qQ=20,CC=class{constructor(r,l){this.mouseHeld=!1,this.pressedKeys=new Set,this.mode="light",this.enableDebugging=!1,this.sizeChangeAnimationId=-1,this.modeChangeAnimationId=-1,this._keyRange={min:0,max:127},document.addEventListener("keydown",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,A6.sustainPedal,127),this.keyboard.style.filter="brightness(0.5)")}),document.addEventListener("keyup",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,A6.sustainPedal,0),this.keyboard.style.filter="")}),this.synth=l,this.channel=0,this.channelColors=r,this._shown=!0,this._createKeyboard(),this.synth.eventHandler.addEvent("noteon","keyboard-note-on",g=>{this.pressNote(g.midiNote,g.channel,g.velocity)}),this.synth.eventHandler.addEvent("noteoff","keyboard-note-off",g=>{this.releaseNote(g.midiNote,g.channel)}),this.synth.eventHandler.addEvent("stopall","keyboard-stop-all",()=>{this.clearNotes()}),this.synth.eventHandler.addEvent("mutechannel","keyboard-mute-channel",g=>{if(g.isMuted)for(let E=0;E<128;E++)this.releaseNote(E,g.channel)})}set shown(r){r===!0?this.keyboard.style.display="":this.keyboard.style.display="none",this._shown=r}get shown(){return this._shown}_createKeyboard(){this.keyboard=document.getElementById("keyboard"),this.keyboard.innerHTML="",this.keys=[],this.keyColors=[];for(let r=this._keyRange.min;r=0&&(x=l(r-1)),r<127&&(u0=l(r+1)),u0&&x?g.classList.add("between_sharps"):x?g.classList.add("left_sharp"):u0&&g.classList.add("right_sharp")}return g}toggleMode(r=!0){if(this.mode==="light"?this.mode="dark":this.mode="light",!r){this.keys.forEach(g=>{g.classList.contains("flat_key")&&g.classList.toggle("flat_dark_key")});return}this.modeChangeAnimationId&&clearTimeout(this.modeChangeAnimationId),this.keyboard.classList.add("mode_transform"),document.body.scrollHeight<=window.innerHeight&&document.body.classList.add("no_scroll"),this.modeChangeAnimationId=setTimeout(()=>{this.keys.forEach(g=>{g.classList.contains("flat_key")&&g.classList.toggle("flat_dark_key")}),this.keyboard.classList.remove("mode_transform"),setTimeout(()=>document.body.classList.remove("no_scroll"),500)},500)}get keyRange(){return this._keyRange}set keyRange(r){if(r.max===void 0||r.min===void 0)throw new TypeError("No min or max property!");if(r.min>r.max){let l=r.min;r.min=r.max,r.max=l}r.min=Math.max(0,r.min),r.max=Math.min(127,r.max),this.setKeyRange(r,!0)}setKeyRange(r,l=!0){Math.abs(r.max-r.min)<12&&(r.min-=6,r.max=r.min+12);let E=900/(r.max-r.min+5),x=document.styleSheets[0].cssRules,u0;for(let R0 of x)if(R0.selectorText==="#keyboard .key"){u0=R0;break}if(u0.style.setProperty("--pressed-transform-skew",`${8e-4/(E/7)}`),l){this.sizeChangeAnimationId&&clearTimeout(this.sizeChangeAnimationId);let R0=getComputedStyle(this.keyboard),p0=parseFloat(R0.getPropertyValue("--current-min-height").replace(/[^\d.]+/g,"")),D0=this.keyboard.getBoundingClientRect().height,E1=E/p0,M=D0*E1-D0,K0=(this._keyRange.min+this._keyRange.max)/2,_0=(r.min+r.max)/2;this._keyRange=r;let k1=this.keys.find(_5=>_5.classList.contains("sharp_key")).getBoundingClientRect().width,h2=(K0-_0)*k1,R1=parseFloat(R0.getPropertyValue("--key-border-radius").replace(/[^\d.]+/g,""));this.keyboard.style.marginTop=`${M}px`,this.keyboard.style.transition="",this.keyboard.style.transform=`scale(${E1}) translateX(${h2}px)`,this.keyboard.style.setProperty("--key-border-radius",`${R1/E1}vmin`),this.sizeChangeAnimationId=setTimeout(()=>{this.keyboard.style.setProperty("--current-min-height",`${E}`),this.keyboard.style.transition="none",this.keyboard.style.transform="",this.keyboard.style.marginTop="",this.keyboard.style.setProperty("--key-border-radius",""),this._createKeyboard(),setTimeout(()=>this.keyboard.style.transition="",75)},500)}else this.keyboard.style.setProperty("--current-min-height",`${E}`),this._keyRange=r,this._createKeyboard()}selectChannel(r){this.channel=r}pressNote(r,l,g){let E=this.keys[r-this._keyRange.min];if(E===void 0)return;E.classList.add("pressed");let x=E.classList.contains("sharp_key"),u0=g/127,R0=this.channelColors[l%16].match(/\d+(\.\d+)?/g).map(parseFloat),p0;if(!x&&this.mode==="light"?p0=`rgba(${R0.slice(0,3).map(E1=>255-(255-E1)*u0).join(", ")}, ${R0[3]})`:p0=`rgba(${R0.slice(0,3).map(E1=>E1*u0).join(", ")}, ${R0[3]})`,E.style.background=p0,this.mode==="dark"){let D0=qQ*u0;E.style.boxShadow=`${p0} 0px 0px ${D0}px ${D0/5}px`}this.keyColors[r-this._keyRange.min].push(this.channelColors[l%16])}releaseNote(r,l){let g=this.keys[r-this._keyRange.min];if(g===void 0)return;l%=this.channelColors.length;let E=this.keyColors[r-this._keyRange.min];if(!E)return;let x=E.findLastIndex(u0=>u0===this.channelColors[l]);x!==-1&&(E.splice(x,1),g.style.background=E[E.length-1],this.mode==="dark"&&(g.style.boxShadow=`0px 0px ${qQ}px ${E[E.length-1]}`),E.length<1&&(g.classList.remove("pressed"),g.style.background="",g.style.boxShadow=""))}clearNotes(){this.keys.forEach((r,l)=>{r.classList.remove("pressed"),r.style.background="",r.style.boxShadow="",this.keyColors[l]=[]})}};CC.prototype._handlePointers=HQ;function u$(o,r){let l=o.replace(/[^\d,]/g,"").split(",");return`rgb(${r(parseInt(l[0]))}, ${r(parseInt(l[1]))}, ${r(parseInt(l[2]))})`}var CD="#000";function YQ(o,r,l){o.forEach(g=>{if(g.pressedProgress===0)return;r.fillStyle=g.color;let E=g.pressedProgress*g.velocity;if(r.globalAlpha=.5*E,l){r.fillRect(g.xPos,g.yPos-g.height*E,g.width,g.height*(E*2+1)),r.globalAlpha=1;return}r.fillRect(g.xPos-g.width*E,g.yPos,g.width*(E*2+1),g.height),r.globalAlpha=1}),o.forEach(g=>{r.fillStyle=g.color,r.save(),r.translate(g.xPos,g.yPos),r.fillRect(0,0,g.width,g.height),r.restore(),r.strokeStyle=CD,r.lineWidth=g.stroke,r.strokeRect(g.xPos,g.yPos,g.width,g.height)})}var QB=!1;function JQ(o=!0,r=!1){let l=(this.seq===void 0||this?.seq?.paused===!0)&&this.synth.voicesAmount===0&&!r;if(!this.renderBool||l)if(QB){o&&requestAnimationFrame(this.render.bind(this));return}else QB=!0;else QB=!1;if(o&&this.drawingContext.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderAnalysers&&!this.synth.highPerformanceMode&&this.renderWaveforms(),this.renderNotes&&this.noteTimes){let x=this.computeNotePositions(this.synth.highPerformanceMode);this.synth.highPerformanceMode||YQ(x,this.drawingContext,this.sideways)}let g=performance.now()-this.frameTimeStart;this.frameTimeStart=performance.now();let E=1e3/g;this.drawingContext.textBaseline="hanging",this.drawingContext.textAlign="end",this.drawingContext.font=`${yB}px Verdana`,this.drawingContext.fillStyle="white",this.drawingContext.strokeStyle="white",this.drawingContext.fillText(`${this.notesOnScreen} notes`,this.canvas.width,yB+5),this.drawingContext.fillText(Math.round(E).toString()+" FPS",this.canvas.width,5),this.onRender&&this.onRender(),o&&requestAnimationFrame(this.render.bind(this))}function KQ(o=!1){this.notesOnScreen=0;let r=this.sideways?this.canvas.height:this.canvas.width,l=this.sideways?this.canvas.width:this.canvas.height,g=this.keyRange.max-this.keyRange.min,E=r/(g+1),x=E-d$*2,u0=this.noteFallingTimeMs/1e3,R0=this.noteAfterTriggerTimeMs/1e3,p0=this.seq.currentHighResolutionTime,D0=p0-R0,E1=u0+R0,M=D0+E1,K0=zQ/E1,_0=[];this.synth.channelProperties.forEach(h2=>{if(this.showVisualPitch){let R1=h2.pitchBend-8192+this.visualPitchBendOffset;_0.push(h2.pitchBendRangeSemitones*(R1/8192*E))}else _0.push(0)});let k1=[];return this.noteTimes.forEach((h2,R1)=>{if(h2.renderStartIndex>=h2.notes.length||!this.renderChannels[R1])return;let _5=h2.renderStartIndex,v2=h2.notes,J2=v2[_5],n3=-1;for(;J2.start<=M&&(_5++,!(this.notesOnScreen>ZQ));){let U5=J2.start+J2.length;if(U5>D0&&J2.length>0){let a0=J2.length/E1*l-d$*2;if(this.notesOnScreen<1e3||a0>K0){n3===-1&&(n3=_5-1);let Y5=(J2.start-D0)/E1*l,n6;if(this._notesFall?n6=l-a0-Y5+d$:n6=Y5+d$,J2.midiNotethis.keyRange.max){if(_5>=v2.length)break;J2=v2[_5];continue}let c6=J2.midiNote-this.keyRange.min,O6=E*c6+d$,g6,u4,Ke,Y4;if(this.sideways?(g6=n6,u4=O6,Y4=x,Ke=a0):(u4=n6,g6=O6,Ke=x,Y4=a0),this.notesOnScreen++,o)this.drawingContext.fillStyle=this.plainColors[R1],this.drawingContext.fillRect(g6+I$+d$,u4+I$,Ke-I$*2,Y4-I$*2);else{let p9;if(J2.start>p0||U5=v2.length)break;J2=v2[_5]}n3>-1&&(h2.renderStartIndex=n3)}),k1.sort((h2,R1)=>R1.height-h2.height),k1}function WQ(){let o=this.canvas.width/4,r=this.canvas.height/4;this.channelAnalysers.forEach((l,g)=>{let E=g%4,x=Math.floor(g/4),u0=!1;for(let M=g;M0){u0=!0;break}if(!u0){let M=this.canvas.width/4,K0=this.canvas.height/4,_0=M*E,k1=K0*x+K0/2;this.drawingContext.lineWidth=this.lineThickness,this.drawingContext.strokeStyle=this.channelColors[g],this.drawingContext.beginPath(),this.drawingContext.moveTo(_0,k1),this.drawingContext.lineTo(_0+M,k1),this.drawingContext.stroke();return}let R0=new Float32Array(l.frequencyBinCount);l.getFloatTimeDomainData(R0);let p0=o*E,D0=r*x+r/2,E1=this.waveMultiplier*r;if(this.drawingContext.lineWidth=this.lineThickness,this.drawingContext.strokeStyle=this.channelColors[g],this.drawingContext.beginPath(),this._stabilizeWaveforms){let M=R0.length/4,K0=o/M,_0=Math.floor(M/2),k1=R0.length-_0;for(let v2=k1;v2>=1;v2--)if(R0[v2-1]<0&&R0[v2]>=0){k1=v2;break}let h2=p0,R1=k1-_0,_5=k1+_0;for(let v2=R1;v2<_5;v2++)this.drawingContext.lineTo(h2,D0+R0[v2]*E1),h2+=K0}else{let M=o/R0.length,K0=p0;for(let _0=0;_0{this.renderChannels[r.channel]=!r.isMuted}),this.updateFftSize()}function ey(){for(let o=0;o4096?this.delayNode.delayTime.value=E/this.synth.context.sampleRate/2:(this.delayNode.delayTime.value=0,console.log("no")))}}function ty(o){o.connectIndividualOutputs(this.channelAnalysers),o.eventHandler.addEvent("drumchange","renderer-drum-change",()=>{this.updateFftSize()})}function iy(){for(let o of this.channelAnalysers)o.disconnect();j5("%cAnalysers disconnected!",D1.recognized)}function ry(o){this.seq=o,this.seq.addOnTimeChangeEvent(()=>this.resetIndexes(),"renderer-time-change"),this.seq.addOnSongChangeEvent(async r=>{if(this.calculateNoteTimes(await this.seq.getMIDI()),this.resetIndexes(),r.RMIDInfo?.IPIC!==void 0){let l=new Blob([r.RMIDInfo?.IPIC.buffer]),g=URL.createObjectURL(l),E=this.canvas.classList.contains("light_mode")?0:.9;this.canvas.style.background=`linear-gradient(rgba(0, 0, 0, ${E}), rgba(0, 0, 0, ${E})), center center / cover url("${g}")`}else this.canvas.style.background=""},"renderer-song-change")}function ny(){this.noteTimes&&this.noteTimes.forEach(o=>o.renderStartIndex=0)}function wB(o,r){let l=0;for(let g=8*(r-1);g>=0;g-=8)l|=o[o.currentIndex++]<>>0}function mC(o,r){let l=new Array(r).fill(0);for(let g=r-1;g>=0;g--)l[g]=o&255,o>>=8;return l}var Ah=.02;function sy(o){function r(D0){return D0.messageData=new l6(D0.messageData.buffer),D0.messageData.currentIndex=0,6e7/wB(D0.messageData,3)}let l=[],E=o.tracks.flat();E.sort((D0,E1)=>D0.ticks-E1.ticks);for(let D0=0;D0<16;D0++)l.push({renderStartIndex:0,notes:[]});let x=0,u0=60/(120*o.timeDivision),R0=0,p0=0;for(;R0>4,M=D0.messageStatusByte&15;if(E1===8){let K0=l[M].notes.findLast(_0=>_0.midiNote===D0.messageData[0]&&_0.length===-1);if(K0){let _0=x-K0.start;K0.length=_0_0.midiNote===D0.messageData[0]&&_0.length===-1);if(K0){let _0=x-K0.start;K0.length=_0=E.length)break;x+=u0*(E[R0].ticks-D0.ticks)}p0>0&&l.forEach((D0,E1)=>D0.notes.filter(M=>M.length===-1).forEach(M=>{let K0=x-M.start;M.length=K0{let l=this.drawingContext.createLinearGradient(0,0,this.canvas.width/128,0);return l.addColorStop(0,u$(r,g=>g*hm)),l.addColorStop(1,r),l}),this.darkerColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,this.canvas.width/128,0);return l.addColorStop(0,u$(r,g=>g*hm*gm)),l.addColorStop(1,u$(r,g=>g*gm)),l}),this.sidewaysChannelColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,u$(r,g=>g*hm)),l.addColorStop(1,r),l}),this.sidewaysDarkerColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,u$(r,g=>g*hm*gm)),l.addColorStop(1,u$(r,g=>g*gm)),l})}toggleDarkMode(){this.canvas.classList.toggle("light_mode")}onRender;get normalAnalyserFft(){return this._normalAnalyserFft}set normalAnalyserFft(r){this._normalAnalyserFft=r,this.updateFftSize()}get drumAnalyserFft(){return this._drumAnalyserFft}set drumAnalyserFft(r){this._drumAnalyserFft=r,this.updateFftSize()}get renderBool(){return this._renderBool}set renderBool(r){this._renderBool=r,r===!0?this.connectChannelAnalysers(this.synth):this.disconnectChannelAnalysers()}get keyRange(){return this._keyRange}set keyRange(r){if(r.max===void 0||r.min===void 0)throw new TypeError("No min or max property!");if(r.min>r.max){let l=r.min;r.min=r.max,r.max=l}r.min=Math.max(0,r.min),r.max=Math.min(127,r.max),this._keyRange=r}};vi.prototype.render=JQ;vi.prototype.computeNotePositions=KQ;vi.prototype.createChannelAnalysers=XQ;vi.prototype.updateFftSize=ey;vi.prototype.connectChannelAnalysers=ty;vi.prototype.disconnectChannelAnalysers=iy;vi.prototype.connectSequencer=ry;vi.prototype.calculateNoteTimes=sy;vi.prototype.resetIndexes=ny;vi.prototype.renderWaveforms=WQ;function r3(o,r){let l=0;for(let g=0;g>>0}function E$(o,r,l){for(let g=0;g>g*8&255}function B9(o,r){o[o.currentIndex++]=r&255,o[o.currentIndex++]=r>>8}function ot(o,r){E$(o,r,4)}function oh(o,r){let l=r<<8|o;return l>32767?l-65536:l}function Ay(o){return o>127?o-256:o}function Fe(o,r,l=void 0,g=!0){if(l){let E=o.slice(o.currentIndex,o.currentIndex+r);return o.currentIndex+=r,new TextDecoder(l.replace(/[^\x20-\x7E]/g,"")).decode(E.buffer)}else{let E=!1,x="";for(let u0=0;u0127){if(g){E=!0;continue}else if(R0===0){E=!0;continue}}x+=String.fromCharCode(R0)}}return x}}function So(o,r=0){let l=o.length;r>0&&(l=r);let g=new l6(l);return ui(g,o,r),g}function ui(o,r,l=0){l>0&&r.length>l&&(r=r.slice(0,l));for(let g=0;gr.length)for(let g=0;gl.header!=="LIST"?!1:(l.chunkData.currentIndex=0,Fe(l.chunkData,4)===r))}function fm(o){let r=[o&127];for(o>>=7;o>0;)r.unshift(o&127|128),o>>=7;return r}function um(o){let r=[];for(let E of o.tracks){let x=[],u0=0,R0;for(let p0 of E){let D0=p0.ticks-u0,E1;p0.messageStatusByte<=J3.keySignature||p0.messageStatusByte===J3.sequenceSpecific?E1=[255,p0.messageStatusByte,...fm(p0.messageData.length),...p0.messageData]:p0.messageStatusByte===J3.systemExclusive?E1=[240,...fm(p0.messageData.length),...p0.messageData]:(E1=[],R0!==p0.messageStatusByte&&(R0=p0.messageStatusByte,E1.push(p0.messageStatusByte)),E1.push(...p0.messageData)),x.push(...fm(D0)),x.push(...E1),u0+=D0}r.push(new Uint8Array(x))}function l(E,x){for(let u0=0;u0o.chunkData.currentIndex;)r.push(new kB(o.chunkData));return r.length>1&&r.pop(),r}var R7={noController:0,noteOnVelocity:2,noteOnKeyNum:3,polyPressure:10,channelPressure:13,pitchWheel:14,pitchWheelRange:16,link:127},Qn={linear:0,concave:1,convex:2,switch:3},yD=[];for(let o=0;o<4;o++)yD.push([[],[]]);var o7=class o{constructor(r){r.srcEnum?(this.modulatorSource=r.srcEnum,this.modulatorDestination=r.dest,this.modulationSecondarySrc=r.secSrcEnum,this.transformAmount=r.amt,this.transformType=r.transform):(this.modulatorSource=r3(r,2),this.modulatorDestination=r3(r,2),this.transformAmount=oh(r[r.currentIndex++],r[r.currentIndex++]),this.modulationSecondarySrc=r3(r,2),this.transformType=r3(r,2)),this.modulatorDestination>58&&(this.modulatorDestination=b1.INVALID),this.sourcePolarity=this.modulatorSource>>9&1,this.sourceDirection=this.modulatorSource>>8&1,this.sourceUsesCC=this.modulatorSource>>7&1,this.sourceIndex=this.modulatorSource&127,this.sourceCurveType=this.modulatorSource>>10&3,this.secSrcPolarity=this.modulationSecondarySrc>>9&1,this.secSrcDirection=this.modulationSecondarySrc>>8&1,this.secSrcUsesCC=this.modulationSecondarySrc>>7&1,this.secSrcIndex=this.modulationSecondarySrc&127,this.secSrcCurveType=this.modulationSecondarySrc>>10&3}sumTransform(r){return new o({srcEnum:this.modulatorSource,secSrcEnum:this.modulationSecondarySrc,dest:this.modulatorDestination,transform:this.transformType,amt:this.transformAmount+r.transformAmount})}debugString(){function r(E,x){return Object.keys(E).find(u0=>E[u0]===x)}let l=r(Qn,this.sourceCurveType);l+=this.sourcePolarity===0?" unipolar ":" bipolar ",l+=this.sourceDirection===0?"forwards ":"backwards ",this.sourceUsesCC?l+=r(A6,this.sourceIndex):l+=r(R7,this.sourceIndex);let g=r(Qn,this.secSrcCurveType);return g+=this.secSrcPolarity===0?" unipolar ":" bipolar ",g+=this.secSrcCurveType===0?"forwards ":"backwards ",this.secSrcUsesCC?g+=r(A6,this.secSrcIndex):g+=r(R7,this.secSrcIndex),`Modulator: + Expected ${this._outputsAmount} got ${r.length}`);for(let l=0;l0?this.noteOn(l.channel,r[1],g):this.noteOff(l.channel,r[1]);break;case J3.noteOff:this.noteOff(l.channel,r[1]);break;case J3.pitchBend:this.pitchWheel(l.channel,r[2],r[1]);break;case J3.controllerChange:this.controllerChange(l.channel,r[1],r[2]);break;case J3.programChange:this.programChange(l.channel,r[1]);break;case J3.polyPressure:this.polyPressure(l.channel,r[0],r[1]);break;case J3.channelPressure:this.channelPressure(l.channel,r[1]);break;case J3.systemExclusive:this.systemExclusive(new l6(r.slice(1)));break;case J3.reset:this.stopAll(!0),this.resetControllers();break;default:break}}get currentTime(){return this.context.currentTime}get voicesAmount(){return this._voicesAmount}reverbateEverythingBecauseWhyNot(){for(let r=0;r{this.pressedKeys.delete(g),this.releaseNote(g,this.channel),this.synth.noteOff(this.channel,g)},r=(g,E)=>{let x;if(vo)x=127;else{let R0=this.keys[0].getBoundingClientRect();if(this.keyboard.classList.contains("sideways")){let p0=E.clientX-R0.left,D0=R0.width;x=Math.floor((D0-p0)/D0*127)}else{let p0=E.clientY-R0.top,D0=R0.height;x=Math.floor(p0/D0*127)}}this.synth.noteOn(this.channel,g,x,this.enableDebugging)},l=g=>{let E=g.touches?Array.from(g.touches):[g],x=new Set;E.forEach(u0=>{let R0=document.elementFromPoint(u0.clientX,u0.clientY),p0=parseInt(R0.id.replace("note",""));x.add(p0),!(isNaN(p0)||p0<0||this.pressedKeys.has(p0))&&(this.pressedKeys.add(p0),r(p0,u0))}),this.pressedKeys.forEach(u0=>{x.has(u0)||o(u0)})};vo||(document.addEventListener("mousedown",g=>{this.mouseHeld=!0,l(g)}),document.addEventListener("mouseup",()=>{this.mouseHeld=!1,this.pressedKeys.forEach(g=>{o(g)})}),this.keyboard.onmousemove=g=>{this.mouseHeld&&l(g)},this.keyboard.onmouseleave=()=>{this.pressedKeys.forEach(g=>{o(g)})}),this.keyboard.ontouchstart=l.bind(this),this.keyboard.ontouchend=l.bind(this),this.keyboard.ontouchmove=l.bind(this)}var qQ=20,CC=class{constructor(r,l){this.mouseHeld=!1,this.pressedKeys=new Set,this.mode="light",this.enableDebugging=!1,this.sizeChangeAnimationId=-1,this.modeChangeAnimationId=-1,this._keyRange={min:0,max:127},document.addEventListener("keydown",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,A6.sustainPedal,127),this.keyboard.style.filter="brightness(0.5)")}),document.addEventListener("keyup",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,A6.sustainPedal,0),this.keyboard.style.filter="")}),this.synth=l,this.channel=0,this.channelColors=r,this._shown=!0,this._createKeyboard(),this.synth.eventHandler.addEvent("noteon","keyboard-note-on",g=>{this.pressNote(g.midiNote,g.channel,g.velocity)}),this.synth.eventHandler.addEvent("noteoff","keyboard-note-off",g=>{this.releaseNote(g.midiNote,g.channel)}),this.synth.eventHandler.addEvent("stopall","keyboard-stop-all",()=>{this.clearNotes()}),this.synth.eventHandler.addEvent("mutechannel","keyboard-mute-channel",g=>{if(g.isMuted)for(let E=0;E<128;E++)this.releaseNote(E,g.channel)})}set shown(r){r===!0?this.keyboard.style.display="":this.keyboard.style.display="none",this._shown=r}get shown(){return this._shown}_createKeyboard(){this.keyboard=document.getElementById("keyboard"),this.keyboard.innerHTML="",this.keys=[],this.keyColors=[];for(let r=this._keyRange.min;r=0&&(x=l(r-1)),r<127&&(u0=l(r+1)),u0&&x?g.classList.add("between_sharps"):x?g.classList.add("left_sharp"):u0&&g.classList.add("right_sharp")}return g}toggleMode(r=!0){if(this.mode==="light"?this.mode="dark":this.mode="light",!r){this.keys.forEach(g=>{g.classList.contains("flat_key")&&g.classList.toggle("flat_dark_key")});return}this.modeChangeAnimationId&&clearTimeout(this.modeChangeAnimationId),this.keyboard.classList.add("mode_transform"),document.body.scrollHeight<=window.innerHeight&&document.body.classList.add("no_scroll"),this.modeChangeAnimationId=setTimeout(()=>{this.keys.forEach(g=>{g.classList.contains("flat_key")&&g.classList.toggle("flat_dark_key")}),this.keyboard.classList.remove("mode_transform"),setTimeout(()=>document.body.classList.remove("no_scroll"),500)},500)}get keyRange(){return this._keyRange}set keyRange(r){if(r.max===void 0||r.min===void 0)throw new TypeError("No min or max property!");if(r.min>r.max){let l=r.min;r.min=r.max,r.max=l}r.min=Math.max(0,r.min),r.max=Math.min(127,r.max),this.setKeyRange(r,!0)}setKeyRange(r,l=!0){Math.abs(r.max-r.min)<12&&(r.min-=6,r.max=r.min+12);let E=900/(r.max-r.min+5),x=document.styleSheets[0].cssRules,u0;for(let R0 of x)if(R0.selectorText==="#keyboard .key"){u0=R0;break}if(u0.style.setProperty("--pressed-transform-skew",`${8e-4/(E/7)}`),l){this.sizeChangeAnimationId&&clearTimeout(this.sizeChangeAnimationId);let R0=getComputedStyle(this.keyboard),p0=parseFloat(R0.getPropertyValue("--current-min-height").replace(/[^\d.]+/g,"")),D0=this.keyboard.getBoundingClientRect().height,E1=E/p0,M=D0*E1-D0,K0=(this._keyRange.min+this._keyRange.max)/2,_0=(r.min+r.max)/2;this._keyRange=r;let k1=this.keys.find(_5=>_5.classList.contains("sharp_key")).getBoundingClientRect().width,h2=(K0-_0)*k1,R1=parseFloat(R0.getPropertyValue("--key-border-radius").replace(/[^\d.]+/g,""));this.keyboard.style.marginTop=`${M}px`,this.keyboard.style.transition="",this.keyboard.style.transform=`scale(${E1}) translateX(${h2}px)`,this.keyboard.style.setProperty("--key-border-radius",`${R1/E1}vmin`),this.sizeChangeAnimationId=setTimeout(()=>{this.keyboard.style.setProperty("--current-min-height",`${E}`),this.keyboard.style.transition="none",this.keyboard.style.transform="",this.keyboard.style.marginTop="",this.keyboard.style.setProperty("--key-border-radius",""),this._createKeyboard(),setTimeout(()=>this.keyboard.style.transition="",75)},500)}else this.keyboard.style.setProperty("--current-min-height",`${E}`),this._keyRange=r,this._createKeyboard()}selectChannel(r){this.channel=r}pressNote(r,l,g){let E=this.keys[r-this._keyRange.min];if(E===void 0)return;E.classList.add("pressed");let x=E.classList.contains("sharp_key"),u0=g/127,R0=this.channelColors[l%16].match(/\d+(\.\d+)?/g).map(parseFloat),p0;if(!x&&this.mode==="light"?p0=`rgba(${R0.slice(0,3).map(E1=>255-(255-E1)*u0).join(", ")}, ${R0[3]})`:p0=`rgba(${R0.slice(0,3).map(E1=>E1*u0).join(", ")}, ${R0[3]})`,E.style.background=p0,this.mode==="dark"){let D0=qQ*u0;E.style.boxShadow=`${p0} 0px 0px ${D0}px ${D0/5}px`}this.keyColors[r-this._keyRange.min].push(this.channelColors[l%16])}releaseNote(r,l){let g=this.keys[r-this._keyRange.min];if(g===void 0)return;l%=this.channelColors.length;let E=this.keyColors[r-this._keyRange.min];if(!E)return;let x=E.findLastIndex(u0=>u0===this.channelColors[l]);x!==-1&&(E.splice(x,1),g.style.background=E[E.length-1],this.mode==="dark"&&(g.style.boxShadow=`0px 0px ${qQ}px ${E[E.length-1]}`),E.length<1&&(g.classList.remove("pressed"),g.style.background="",g.style.boxShadow=""))}clearNotes(){this.keys.forEach((r,l)=>{r.classList.remove("pressed"),r.style.background="",r.style.boxShadow="",this.keyColors[l]=[]})}};CC.prototype._handlePointers=HQ;function u$(o,r){let l=o.replace(/[^\d,]/g,"").split(",");return`rgb(${r(parseInt(l[0]))}, ${r(parseInt(l[1]))}, ${r(parseInt(l[2]))})`}var CD="#000";function YQ(o,r,l){o.forEach(g=>{if(g.pressedProgress===0)return;r.fillStyle=g.color;let E=g.pressedProgress*g.velocity;if(r.globalAlpha=.5*E,l){r.fillRect(g.xPos,g.yPos-g.height*E,g.width,g.height*(E*2+1)),r.globalAlpha=1;return}r.fillRect(g.xPos-g.width*E,g.yPos,g.width*(E*2+1),g.height),r.globalAlpha=1}),o.forEach(g=>{r.fillStyle=g.color,r.save(),r.translate(g.xPos,g.yPos),r.fillRect(0,0,g.width,g.height),r.restore(),r.strokeStyle=CD,r.lineWidth=g.stroke,r.strokeRect(g.xPos,g.yPos,g.width,g.height)})}var QB=!1;function JQ(o=!0,r=!1){let l=(this.seq===void 0||this?.seq?.paused===!0)&&this.synth.voicesAmount===0&&!r;if(!this.renderBool||l)if(QB){o&&requestAnimationFrame(this.render.bind(this));return}else QB=!0;else QB=!1;if(o&&this.drawingContext.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderAnalysers&&!this.synth.highPerformanceMode&&this.renderWaveforms(),this.renderNotes&&this.noteTimes){let x=this.computeNotePositions(this.synth.highPerformanceMode);this.synth.highPerformanceMode||YQ(x,this.drawingContext,this.sideways)}let g=performance.now()-this.frameTimeStart;this.frameTimeStart=performance.now();let E=1e3/g;this.drawingContext.textBaseline="hanging",this.drawingContext.textAlign="end",this.drawingContext.font=`${yB}px Verdana`,this.drawingContext.fillStyle="white",this.drawingContext.strokeStyle="white",this.drawingContext.fillText(`${this.notesOnScreen} notes`,this.canvas.width,yB+5),this.drawingContext.fillText(Math.round(E).toString()+" FPS",this.canvas.width,5),this.onRender&&this.onRender(),o&&requestAnimationFrame(this.render.bind(this))}function KQ(o=!1){this.notesOnScreen=0;let r=this.sideways?this.canvas.height:this.canvas.width,l=this.sideways?this.canvas.width:this.canvas.height,g=this.keyRange.max-this.keyRange.min,E=r/(g+1),x=E-d$*2,u0=this.noteFallingTimeMs/1e3,R0=this.noteAfterTriggerTimeMs/1e3,p0=this.seq.currentHighResolutionTime,D0=p0-R0,E1=u0+R0,M=D0+E1,K0=zQ/E1,_0=[];this.synth.channelProperties.forEach(h2=>{if(this.showVisualPitch){let R1=h2.pitchBend-8192+this.visualPitchBendOffset;_0.push(h2.pitchBendRangeSemitones*(R1/8192*E))}else _0.push(0)});let k1=[];return this.noteTimes.forEach((h2,R1)=>{if(h2.renderStartIndex>=h2.notes.length||!this.renderChannels[R1])return;let _5=h2.renderStartIndex,v2=h2.notes,J2=v2[_5],n3=-1;for(;J2.start<=M&&(_5++,!(this.notesOnScreen>ZQ));){let U5=J2.start+J2.length;if(U5>D0&&J2.length>0){let a0=J2.length/E1*l-d$*2;if(this.notesOnScreen<1e3||a0>K0){n3===-1&&(n3=_5-1);let Y5=(J2.start-D0)/E1*l,n6;if(this._notesFall?n6=l-a0-Y5+d$:n6=Y5+d$,J2.midiNotethis.keyRange.max){if(_5>=v2.length)break;J2=v2[_5];continue}let c6=J2.midiNote-this.keyRange.min,O6=E*c6+d$,g6,u4,Ke,Y4;if(this.sideways?(g6=n6,u4=O6,Y4=x,Ke=a0):(u4=n6,g6=O6,Ke=x,Y4=a0),this.notesOnScreen++,o)this.drawingContext.fillStyle=this.plainColors[R1],this.drawingContext.fillRect(g6+I$+d$,u4+I$,Ke-I$*2,Y4-I$*2);else{let p9;if(J2.start>p0||U5=v2.length)break;J2=v2[_5]}n3>-1&&(h2.renderStartIndex=n3)}),k1.sort((h2,R1)=>R1.height-h2.height),k1}function WQ(){let o=this.canvas.width/4,r=this.canvas.height/4;this.channelAnalysers.forEach((l,g)=>{let E=g%4,x=Math.floor(g/4),u0=!1;for(let M=g;M0){u0=!0;break}if(!u0){let M=this.canvas.width/4,K0=this.canvas.height/4,_0=M*E,k1=K0*x+K0/2;this.drawingContext.lineWidth=this.lineThickness,this.drawingContext.strokeStyle=this.channelColors[g],this.drawingContext.beginPath(),this.drawingContext.moveTo(_0,k1),this.drawingContext.lineTo(_0+M,k1),this.drawingContext.stroke();return}let R0=new Float32Array(l.frequencyBinCount);l.getFloatTimeDomainData(R0);let p0=o*E,D0=r*x+r/2,E1=this.waveMultiplier*r;if(this.drawingContext.lineWidth=this.lineThickness,this.drawingContext.strokeStyle=this.channelColors[g],this.drawingContext.beginPath(),this._stabilizeWaveforms){let M=R0.length/4,K0=o/M,_0=Math.floor(M/2),k1=R0.length-_0;for(let v2=k1;v2>=1;v2--)if(R0[v2-1]<0&&R0[v2]>=0){k1=v2;break}let h2=p0,R1=k1-_0,_5=k1+_0;for(let v2=R1;v2<_5;v2++)this.drawingContext.lineTo(h2,D0+R0[v2]*E1),h2+=K0}else{let M=o/R0.length,K0=p0;for(let _0=0;_0{this.renderChannels[r.channel]=!r.isMuted}),this.updateFftSize()}function ey(){for(let o=0;o4096?this.delayNode.delayTime.value=E/this.synth.context.sampleRate/2:this.delayNode.delayTime.value=0)}}function ty(o){o.connectIndividualOutputs(this.channelAnalysers),o.eventHandler.addEvent("drumchange","renderer-drum-change",()=>{this.updateFftSize()})}function iy(){for(let o of this.channelAnalysers)o.disconnect();j5("%cAnalysers disconnected!",D1.recognized)}function ry(o){this.seq=o,this.seq.addOnTimeChangeEvent(()=>this.resetIndexes(),"renderer-time-change"),this.seq.addOnSongChangeEvent(async r=>{if(this.calculateNoteTimes(await this.seq.getMIDI()),this.resetIndexes(),r.RMIDInfo?.IPIC!==void 0){let l=new Blob([r.RMIDInfo?.IPIC.buffer]),g=URL.createObjectURL(l),E=this.canvas.classList.contains("light_mode")?0:.9;this.canvas.style.background=`linear-gradient(rgba(0, 0, 0, ${E}), rgba(0, 0, 0, ${E})), center center / cover url("${g}")`}else this.canvas.style.background=""},"renderer-song-change")}function ny(){this.noteTimes&&this.noteTimes.forEach(o=>o.renderStartIndex=0)}function wB(o,r){let l=0;for(let g=8*(r-1);g>=0;g-=8)l|=o[o.currentIndex++]<>>0}function mC(o,r){let l=new Array(r).fill(0);for(let g=r-1;g>=0;g--)l[g]=o&255,o>>=8;return l}var Ah=.02;function sy(o){function r(D0){return D0.messageData=new l6(D0.messageData.buffer),D0.messageData.currentIndex=0,6e7/wB(D0.messageData,3)}let l=[],E=o.tracks.flat();E.sort((D0,E1)=>D0.ticks-E1.ticks);for(let D0=0;D0<16;D0++)l.push({renderStartIndex:0,notes:[]});let x=0,u0=60/(120*o.timeDivision),R0=0,p0=0;for(;R0>4,M=D0.messageStatusByte&15;if(E1===8){let K0=l[M].notes.findLast(_0=>_0.midiNote===D0.messageData[0]&&_0.length===-1);if(K0){let _0=x-K0.start;K0.length=_0_0.midiNote===D0.messageData[0]&&_0.length===-1);if(K0){let _0=x-K0.start;K0.length=_0=E.length)break;x+=u0*(E[R0].ticks-D0.ticks)}p0>0&&l.forEach((D0,E1)=>D0.notes.filter(M=>M.length===-1).forEach(M=>{let K0=x-M.start;M.length=K0{let l=this.drawingContext.createLinearGradient(0,0,this.canvas.width/128,0);return l.addColorStop(0,u$(r,g=>g*hm)),l.addColorStop(1,r),l}),this.darkerColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,this.canvas.width/128,0);return l.addColorStop(0,u$(r,g=>g*hm*gm)),l.addColorStop(1,u$(r,g=>g*gm)),l}),this.sidewaysChannelColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,u$(r,g=>g*hm)),l.addColorStop(1,r),l}),this.sidewaysDarkerColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,u$(r,g=>g*hm*gm)),l.addColorStop(1,u$(r,g=>g*gm)),l})}toggleDarkMode(){this.canvas.classList.toggle("light_mode")}onRender;get normalAnalyserFft(){return this._normalAnalyserFft}set normalAnalyserFft(r){this._normalAnalyserFft=r,this.updateFftSize()}get drumAnalyserFft(){return this._drumAnalyserFft}set drumAnalyserFft(r){this._drumAnalyserFft=r,this.updateFftSize()}get renderBool(){return this._renderBool}set renderBool(r){this._renderBool=r,r===!0?this.connectChannelAnalysers(this.synth):this.disconnectChannelAnalysers()}get keyRange(){return this._keyRange}set keyRange(r){if(r.max===void 0||r.min===void 0)throw new TypeError("No min or max property!");if(r.min>r.max){let l=r.min;r.min=r.max,r.max=l}r.min=Math.max(0,r.min),r.max=Math.min(127,r.max),this._keyRange=r}};vi.prototype.render=JQ;vi.prototype.computeNotePositions=KQ;vi.prototype.createChannelAnalysers=XQ;vi.prototype.updateFftSize=ey;vi.prototype.connectChannelAnalysers=ty;vi.prototype.disconnectChannelAnalysers=iy;vi.prototype.connectSequencer=ry;vi.prototype.calculateNoteTimes=sy;vi.prototype.resetIndexes=ny;vi.prototype.renderWaveforms=WQ;function r3(o,r){let l=0;for(let g=0;g>>0}function E$(o,r,l){for(let g=0;g>g*8&255}function B9(o,r){o[o.currentIndex++]=r&255,o[o.currentIndex++]=r>>8}function ot(o,r){E$(o,r,4)}function oh(o,r){let l=r<<8|o;return l>32767?l-65536:l}function Ay(o){return o>127?o-256:o}function Fe(o,r,l=void 0,g=!0){if(l){let E=o.slice(o.currentIndex,o.currentIndex+r);return o.currentIndex+=r,new TextDecoder(l.replace(/[^\x20-\x7E]/g,"")).decode(E.buffer)}else{let E=!1,x="";for(let u0=0;u0127){if(g){E=!0;continue}else if(R0===0){E=!0;continue}}x+=String.fromCharCode(R0)}}return x}}function So(o,r=0){let l=o.length;r>0&&(l=r);let g=new l6(l);return ui(g,o,r),g}function ui(o,r,l=0){l>0&&r.length>l&&(r=r.slice(0,l));for(let g=0;gr.length)for(let g=0;gl.header!=="LIST"?!1:(l.chunkData.currentIndex=0,Fe(l.chunkData,4)===r))}function fm(o){let r=[o&127];for(o>>=7;o>0;)r.unshift(o&127|128),o>>=7;return r}function um(o){let r=[];for(let E of o.tracks){let x=[],u0=0,R0;for(let p0 of E){let D0=p0.ticks-u0,E1;p0.messageStatusByte<=J3.keySignature||p0.messageStatusByte===J3.sequenceSpecific?E1=[255,p0.messageStatusByte,...fm(p0.messageData.length),...p0.messageData]:p0.messageStatusByte===J3.systemExclusive?E1=[240,...fm(p0.messageData.length),...p0.messageData]:(E1=[],R0!==p0.messageStatusByte&&(R0=p0.messageStatusByte,E1.push(p0.messageStatusByte)),E1.push(...p0.messageData)),x.push(...fm(D0)),x.push(...E1),u0+=D0}r.push(new Uint8Array(x))}function l(E,x){for(let u0=0;u0o.chunkData.currentIndex;)r.push(new kB(o.chunkData));return r.length>1&&r.pop(),r}var R7={noController:0,noteOnVelocity:2,noteOnKeyNum:3,polyPressure:10,channelPressure:13,pitchWheel:14,pitchWheelRange:16,link:127},Qn={linear:0,concave:1,convex:2,switch:3},yD=[];for(let o=0;o<4;o++)yD.push([[],[]]);var o7=class o{constructor(r){r.srcEnum?(this.modulatorSource=r.srcEnum,this.modulatorDestination=r.dest,this.modulationSecondarySrc=r.secSrcEnum,this.transformAmount=r.amt,this.transformType=r.transform):(this.modulatorSource=r3(r,2),this.modulatorDestination=r3(r,2),this.transformAmount=oh(r[r.currentIndex++],r[r.currentIndex++]),this.modulationSecondarySrc=r3(r,2),this.transformType=r3(r,2)),this.modulatorDestination>58&&(this.modulatorDestination=b1.INVALID),this.sourcePolarity=this.modulatorSource>>9&1,this.sourceDirection=this.modulatorSource>>8&1,this.sourceUsesCC=this.modulatorSource>>7&1,this.sourceIndex=this.modulatorSource&127,this.sourceCurveType=this.modulatorSource>>10&3,this.secSrcPolarity=this.modulationSecondarySrc>>9&1,this.secSrcDirection=this.modulationSecondarySrc>>8&1,this.secSrcUsesCC=this.modulationSecondarySrc>>7&1,this.secSrcIndex=this.modulationSecondarySrc&127,this.secSrcCurveType=this.modulationSecondarySrc>>10&3}sumTransform(r){return new o({srcEnum:this.modulatorSource,secSrcEnum:this.modulationSecondarySrc,dest:this.modulatorDestination,transform:this.transformType,amt:this.transformAmount+r.transformAmount})}debugString(){function r(E,x){return Object.keys(E).find(u0=>E[u0]===x)}let l=r(Qn,this.sourceCurveType);l+=this.sourcePolarity===0?" unipolar ":" bipolar ",l+=this.sourceDirection===0?"forwards ":"backwards ",this.sourceUsesCC?l+=r(A6,this.sourceIndex):l+=r(R7,this.sourceIndex);let g=r(Qn,this.secSrcCurveType);return g+=this.secSrcPolarity===0?" unipolar ":" bipolar ",g+=this.secSrcCurveType===0?"forwards ":"backwards ",this.secSrcUsesCC?g+=r(A6,this.secSrcIndex):g+=r(R7,this.secSrcIndex),`Modulator: Source: ${l} Secondary source: ${g} Destination: ${r(b1,this.modulatorDestination)}