From 0842c10fca3cd8105800e51e01dedf4974979761 Mon Sep 17 00:00:00 2001 From: spessasus Date: Mon, 9 Sep 2024 10:24:44 +0200 Subject: [PATCH] no negative attenuation --- src/spessasynth_lib/soundfont/read_sf2/generators.js | 2 +- src/spessasynth_lib/synthetizer/worklet_processor.min.js | 2 +- src/website/js/renderer/compute_note_positions.js | 4 ++-- src/website/minified/demo_main.min.js | 2 +- src/website/minified/local_main.min.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/spessasynth_lib/soundfont/read_sf2/generators.js b/src/spessasynth_lib/soundfont/read_sf2/generators.js index eed30bd3..3d91feca 100644 --- a/src/spessasynth_lib/soundfont/read_sf2/generators.js +++ b/src/spessasynth_lib/soundfont/read_sf2/generators.js @@ -138,7 +138,7 @@ generatorLimits[generatorTypes.startloopAddrsCoarseOffset] = {min: -32768, max: generatorLimits[generatorTypes.keyNum] = {min: -1, max: 127, def: -1}; generatorLimits[generatorTypes.velocity] = {min: -1, max: 127, def: -1}; -generatorLimits[generatorTypes.initialAttenuation] = {min: -250, max: 1440, def: 0}; // soundblaster allows 10dB of gain (divide by 0.4) +generatorLimits[generatorTypes.initialAttenuation] = {min: 0, max: 1440, def: 0}; // soundblaster allows 10dB of gain (divide by 0.4) generatorLimits[generatorTypes.endloopAddrsCoarseOffset] = {min: -32768, max: 32768, def: 0}; diff --git a/src/spessasynth_lib/synthetizer/worklet_processor.min.js b/src/spessasynth_lib/synthetizer/worklet_processor.min.js index fdd54442..6d1ec377 100644 --- a/src/spessasynth_lib/synthetizer/worklet_processor.min.js +++ b/src/spessasynth_lib/synthetizer/worklet_processor.min.js @@ -1,4 +1,4 @@ -var rs=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(A,t)=>(typeof require<"u"?require:A)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var Y=class extends Uint8Array{constructor(A){super(A),this.currentIndex=0}currentIndex};function pe(e){let A=e.reduce((n,o)=>n+o.length,0),t=new Y(A),s=0;for(let n of e)t.set(n,s),s+=n.length;return t}function ct(e){e=Math.floor(e);let A=Math.floor(e/60),t=Math.round(e-A*60);return{minutes:A,seconds:t,time:`${A.toString().padStart(2,"0")}:${t.toString().padStart(2,"0")}`}}function is(e){return e.trim().replaceAll(".mid","").replaceAll(".rmi","").replaceAll("_"," ")}function hA(e){let A="";for(let t=0;t=128&&A<=224&&(s=t,n=A),{status:n,channel:s}}var S={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},as={8:2,9:2,10:2,11:2,12:1,13:1,14:2};var AA={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},re={mainVolume:0,masterPan:1,voicesCap:2,interpolationType:3},bA=-1,mA={channelProperties:0,eventCall:1,reportedCurrentTime:2,sequencerSpecific:3,synthesizerSnapshot:4,ready:5,soundfontError:6,identify:7};var gs=!0,Cs=!0,Te=!0,Es=!0;function Bs(e,A,t,s){gs=e,Cs=A,Te=t,Es=s}function p(...e){gs&&console.info(...e)}function b(...e){Cs&&console.warn(...e)}function hs(...e){Es&&console.table(...e)}function Ae(...e){Te&&console.group(...e)}function DA(...e){Te&&console.groupCollapsed(...e)}function X(){Te&&console.groupEnd()}var ie={reloadSoundFont:0,addNewSoundFont:2,deleteSoundFont:3,rearrangeSoundFonts:4};var Qs="spessasynth-worklet-system",cs=450,pA=9,He=16,Ye="gs";var MA={loadNewSongList:0,pause:1,stop:2,play:3,setTime:4,changeMIDIMessageSending:5,setPlaybackRate:6,setLoop:7,changeSong:8,getMIDI:9,setSkipToFirstNote:10},kA={midiEvent:0,songChange:1,textEvent:2,timeChange:3,pause:4,getMIDI:5,midiError:6};function WA(e,A){let t=0;for(let s=8*(A-1);s>=0;s-=8)t|=e[e.currentIndex++]<>>0}function ls(e,A){if(this.ignoreEvents)return;if(this.sendMIDIMessages&&e.messageStatusByte>=128){this.sendMIDIMessage([e.messageStatusByte,...e.messageData]);return}let t=Se(e.messageStatusByte),s=this.midiPortChannelOffsets[this.midiPorts[A]]||0;switch(t.channel+=s,t.status){case w.noteOn:let n=e.messageData[1];if(n>0)this.synth.noteOn(t.channel,e.messageData[0],n),this.playingNotes.push({midiNote:e.messageData[0],channel:t.channel,velocity:n});else{this.synth.noteOff(t.channel,e.messageData[0]);let E=this.playingNotes.findIndex(g=>g.midiNote===e.messageData[0]&&g.channel===t.channel);E!==-1&&this.playingNotes.splice(E,1)}break;case w.noteOff:this.synth.noteOff(t.channel,e.messageData[0]);let o=this.playingNotes.findIndex(E=>E.midiNote===e.messageData[0]&&E.channel===t.channel);o!==-1&&this.playingNotes.splice(o,1);break;case w.pitchBend:this.synth.pitchWheel(t.channel,e.messageData[1],e.messageData[0]);break;case w.controllerChange:this.synth.controllerChange(t.channel,e.messageData[0],e.messageData[1]);break;case w.programChange:this.synth.programChange(t.channel,e.messageData[0]);break;case w.polyPressure:this.synth.polyPressure(t.channel,e.messageData[0],e.messageData[1]);break;case w.channelPressure:this.synth.channelPressure(t.channel,e.messageData[0]);break;case w.systemExclusive:this.synth.systemExclusive(e.messageData,s);break;case w.setTempo:this.oneTickToSeconds=60/(Fo(e)*this.midiData.timeDivision),this.oneTickToSeconds===0&&(this.oneTickToSeconds=60/(120*this.midiData.timeDivision),b("invalid tempo! falling back to 120 BPM"));break;case w.timeSignature:case w.endOfTrack:case w.midiChannelPrefix:case w.songPosition:case w.activeSensing:case w.keySignature:break;case w.text:case w.lyric:case w.copyright:case w.trackName:case w.marker:case w.cuePoint:case w.instrumentName:this.post(kA.textEvent,[e.messageData,t.status]);break;case w.midiPort:this.assignMIDIPort(A,e.messageData[0]);break;case w.reset:this.synth.stopAllChannels(),this.synth.resetAllControllers();break;default:b(`%cUnrecognized Event: %c${e.messageStatusByte}%c status byte: %c${Object.keys(w).find(E=>w[E]===t.status)}`,I.warn,I.unrecognized,I.warn,I.value);break}}function us(){for(let e=0;e<16;e++)this.synth.createWorkletChannel(!0),e===pA&&this.synth.setDrums(this.synth.workletProcessorChannels.length-1,!0)}function Fo(e){return e.messageData.currentIndex=0,6e7/WA(e.messageData,3)}function fs(){let e=this.currentTime;for(;this.playedTime1&&this.nextSong();return}let s=this.tracks[A][this.eventIndex[A]];if(this.playedTime+=this.oneTickToSeconds*(s.ticks-t.ticks),this.midiData.loop.end<=t.ticks&&this.loop){this.setTimeTicks(this.midiData.loop.start);return}else if(e>=this.duration){if(this.loop){this.setTimeTicks(this.midiData.loop.start);return}this.eventIndex[A]--,this.pause(!0),this.songs.length>1&&this.nextSong();return}}}function ds(){let e=0,A=1/0;return this.tracks.forEach((t,s)=>{this.eventIndex[s]>=t.length||t[this.eventIndex[s]].ticksg===S.dataDecrement||g===S.dataIncrement||g===S.dataEntryMsb||g===S.dataDecrement||g===S.lsbForControl6DataEntry||g===S.RPNLsb||g===S.RPNMsb||g===S.NRPNLsb||g===S.NRPNMsb||g===S.bankSelect||g===S.lsbForControl0BankSelect||g===S.resetAllControllers,E=[];for(let g=0;g=A)break}else if(this.playedTime>=e)break;let c=Se(h.messageStatusByte),d=c.channel+(this.midiPortChannelOffsets[this.midiPorts[g]]||0);switch(c.status){case w.noteOn:case w.noteOff:case w.keySignature:break;case w.pitchBend:s[d]=h.messageData[1]<<7|h.messageData[0];break;case w.programChange:let Q=n[d];Q.program=h.messageData[0],Q.actualBank=Q.bank;break;case w.controllerChange:let l=h.messageData[0];if(o(l))if(this.sendMIDIMessages)this.sendMIDIMessage([w.controllerChange|d%16,l,h.messageData[1]]);else{let m=h.messageData[1];if(l===S.bankSelect){n[d].bank=m;break}this.synth.controllerChange(d,l,m)}else E[d]===void 0&&(E[d]=Array.from(qA)),E[d][l]=h.messageData[1];break;default:this._processEvent(h,g);break}this.eventIndex[g]++,g=this._findFirstEventIndex();let u=this.tracks[g][this.eventIndex[g]];if(u===void 0)return this.stop(),!1;this.playedTime+=this.oneTickToSeconds*(u.ticks-h.ticks)}if(this.sendMIDIMessages){for(let g=0;g>7]),E[g].forEach((h,c)=>{h!==qA[c]&&!o(c)&&this.sendMIDIMessage([w.controllerChange|g%16,c,h])}),n[g].program>=0&&n[g].actualBank>=0){let h=n[g].actualBank;this.sendMIDIMessage([w.controllerChange|g%16,S.bankSelect,h]),this.sendMIDIMessage([w.programChange|g%16,n[g].program])}}else for(let g=0;g>7,s[g]&127),E[g]!==void 0&&E[g].forEach((h,c)=>{h!==qA[c]&&!o(c)&&this.synth.controllerChange(g,c,h)}),n[g].program>=0&&n[g].actualBank>=0){let h=n[g].actualBank;this.synth.controllerChange(g,S.bankSelect,h),this.synth.programChange(g,n[g].program)}return!0}function ps(e=!1){if(this.midiData!==void 0){if(e){this.currentTime=0;return}if(this.currentTime>=this.duration){this.currentTime=0;return}this.paused&&(this._recalculateStartTime(this.pausedTime),this.pausedTime=void 0),this.sendMIDIMessages||this.playingNotes.forEach(A=>{this.synth.noteOn(A.channel,A.midiNote,A.velocity,!1,!0)}),this.setProcessHandler()}}function Je(e,A,t){if(A<=0)return 0;let s=e.find(o=>o.ticks>>0}function Ie(e,A,t){for(let s=0;s>s*8&255}function J(e,A){e[e.currentIndex++]=A&255,e[e.currentIndex++]=A>>8}function cA(e,A){Ie(e,A,4)}function ae(e,A){let t=A<<8|e;return t>32767?t-65536:t}function Ds(e){return e>127?e-256:e}function V(e,A,t=void 0,s=!0){if(t){let n=e.slice(e.currentIndex,e.currentIndex+A);return e.currentIndex+=A,new TextDecoder(t.replace(/[^\x20-\x7E]/g,"")).decode(n.buffer)}else{let n=!1,o="";for(let E=0;E127){if(s){n=!0;continue}else if(g===0){n=!0;continue}}o+=String.fromCharCode(g)}}return o}}function wA(e,A,t=0){t>0&&A.length>t&&(A=A.slice(0,t));for(let s=0;sA.length)for(let s=0;st.header!=="LIST"?!1:(t.chunkData.currentIndex=0,V(t.chunkData,4)===A))}function Ke(e){let A=0;for(;e;){let t=e[e.currentIndex++];if(A=A<<7|t&127,t>>7!==1)break}return A}var a={INVALID:-1,startAddrsOffset:0,endAddrOffset:1,startloopAddrsOffset:2,endloopAddrsOffset:3,startAddrsCoarseOffset:4,modLfoToPitch:5,vibLfoToPitch:6,modEnvToPitch:7,initialFilterFc:8,initialFilterQ:9,modLfoToFilterFc:10,modEnvToFilterFc:11,endAddrsCoarseOffset:12,modLfoToVolume:13,unused1:14,chorusEffectsSend:15,reverbEffectsSend:16,pan:17,unused2:18,unused3:19,unused4:20,delayModLFO:21,freqModLFO:22,delayVibLFO:23,freqVibLFO:24,delayModEnv:25,attackModEnv:26,holdModEnv:27,decayModEnv:28,sustainModEnv:29,releaseModEnv:30,keyNumToModEnvHold:31,keyNumToModEnvDecay:32,delayVolEnv:33,attackVolEnv:34,holdVolEnv:35,decayVolEnv:36,sustainVolEnv:37,releaseVolEnv:38,keyNumToVolEnvHold:39,keyNumToVolEnvDecay:40,instrument:41,reserved1:42,keyRange:43,velRange:44,startloopAddrsCoarseOffset:45,keyNum:46,velocity:47,initialAttenuation:48,reserved2:49,endloopAddrsCoarseOffset:50,coarseTune:51,fineTune:52,sampleID:53,sampleModes:54,reserved3:55,scaleTuning:56,exclusiveClass:57,overridingRootKey:58,unused5:59,endOper:60},T=[];T[a.startAddrsOffset]={min:0,max:32768,def:0};T[a.endAddrOffset]={min:-32768,max:32768,def:0};T[a.startloopAddrsOffset]={min:-32768,max:32768,def:0};T[a.endloopAddrsOffset]={min:-32768,max:32768,def:0};T[a.startAddrsCoarseOffset]={min:0,max:32768,def:0};T[a.modLfoToPitch]={min:-12e3,max:12e3,def:0};T[a.vibLfoToPitch]={min:-12e3,max:12e3,def:0};T[a.modEnvToPitch]={min:-12e3,max:12e3,def:0};T[a.initialFilterFc]={min:1500,max:13500,def:13500};T[a.initialFilterQ]={min:0,max:960,def:0};T[a.modLfoToFilterFc]={min:-12e3,max:12e3,def:0};T[a.modEnvToFilterFc]={min:-12e3,max:12e3,def:0};T[a.endAddrsCoarseOffset]={min:-32768,max:32768,def:0};T[a.modLfoToVolume]={min:-960,max:960,def:0};T[a.chorusEffectsSend]={min:0,max:1e3,def:0};T[a.reverbEffectsSend]={min:0,max:1e3,def:0};T[a.pan]={min:-500,max:500,def:0};T[a.delayModLFO]={min:-12e3,max:5e3,def:-12e3};T[a.freqModLFO]={min:-16e3,max:4500,def:0};T[a.delayVibLFO]={min:-12e3,max:5e3,def:-12e3};T[a.freqVibLFO]={min:-16e3,max:4500,def:0};T[a.delayModEnv]={min:-12e3,max:5e3,def:-12e3};T[a.attackModEnv]={min:-12e3,max:8e3,def:-12e3};T[a.holdModEnv]={min:-12e3,max:5e3,def:-12e3};T[a.decayModEnv]={min:-12e3,max:8e3,def:-12e3};T[a.sustainModEnv]={min:0,max:1e3,def:0};T[a.releaseModEnv]={min:-12e3,max:8e3,def:-12e3};T[a.keyNumToModEnvHold]={min:-1200,max:1200,def:0};T[a.keyNumToModEnvDecay]={min:-1200,max:1200,def:0};T[a.delayVolEnv]={min:-12e3,max:5e3,def:-12e3};T[a.attackVolEnv]={min:-12e3,max:8e3,def:-12e3};T[a.holdVolEnv]={min:-12e3,max:5e3,def:-12e3};T[a.decayVolEnv]={min:-12e3,max:8e3,def:-12e3};T[a.sustainVolEnv]={min:0,max:1440,def:0};T[a.releaseVolEnv]={min:-7200,max:8e3,def:-12e3};T[a.keyNumToVolEnvHold]={min:-1200,max:1200,def:0};T[a.keyNumToVolEnvDecay]={min:-1200,max:1200,def:0};T[a.startloopAddrsCoarseOffset]={min:-32768,max:32768,def:0};T[a.keyNum]={min:-1,max:127,def:-1};T[a.velocity]={min:-1,max:127,def:-1};T[a.initialAttenuation]={min:-250,max:1440,def:0};T[a.endloopAddrsCoarseOffset]={min:-32768,max:32768,def:0};T[a.coarseTune]={min:-120,max:120,def:0};T[a.fineTune]={min:-99,max:99,def:0};T[a.scaleTuning]={min:0,max:1200,def:100};T[a.exclusiveClass]={min:0,max:99999,def:0};T[a.overridingRootKey]={min:-1,max:127,def:-1};var U=class{constructor(A=a.INVALID,t=0){if(this.generatorType=A,t===void 0)throw new Error("No value provided.");let s=T[A];this.generatorValue=Math.round(t),s!==void 0&&(this.generatorValue=Math.max(s.min,Math.min(s.max,this.generatorValue)))}generatorType=a.INVALID;generatorValue=0};function ks(e,A,t){let s=T[e]||{min:0,max:32768,def:0},n=A.find(h=>h.generatorType===e),o=0;n&&(o=n.generatorValue);let E=t.find(h=>h.generatorType===e),g=s.def;return E&&(g=E.generatorValue),Math.max(s.min,Math.min(s.max,g+o))}var lt=class extends U{constructor(A){super();let t=A.currentIndex;this.generatorType=A[t+1]<<8|A[t],this.generatorValue=ae(A[t+2],A[t+3]),A.currentIndex+=4}};function ut(e){let A=[];for(;e.chunkData.length>e.chunkData.currentIndex;)A.push(new lt(e.chunkData));return A.length>1&&A.pop(),A}var v={noController:0,noteOnVelocity:2,noteOnKeyNum:3,polyPressure:10,channelPressure:13,pitchWheel:14,pitchWheelRange:16,link:127},lA={linear:0,concave:1,convex:2,switch:3},Ro=[];for(let e=0;e<4;e++)Ro.push([[],[]]);var rA=class e{constructor(A){A.srcEnum?(this.modulatorSource=A.srcEnum,this.modulatorDestination=A.dest,this.modulationSecondarySrc=A.secSrcEnum,this.transformAmount=A.amt,this.transformType=A.transform):(this.modulatorSource=D(A,2),this.modulatorDestination=D(A,2),this.transformAmount=ae(A[A.currentIndex++],A[A.currentIndex++]),this.modulationSecondarySrc=D(A,2),this.transformType=D(A,2)),this.modulatorDestination>58&&(this.modulatorDestination=a.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(A){return new e({srcEnum:this.modulatorSource,secSrcEnum:this.modulationSecondarySrc,dest:this.modulatorDestination,transform:this.transformType,amt:this.transformAmount+A.transformAmount})}debugString(){function A(n,o){return Object.keys(n).find(E=>n[E]===o)}let t=A(lA,this.sourceCurveType);t+=this.sourcePolarity===0?" unipolar ":" bipolar ",t+=this.sourceDirection===0?"forwards ":"backwards ",this.sourceUsesCC?t+=A(S,this.sourceIndex):t+=A(v,this.sourceIndex);let s=A(lA,this.secSrcCurveType);return s+=this.secSrcPolarity===0?" unipolar ":" bipolar ",s+=this.secSrcCurveType===0?"forwards ":"backwards ",this.secSrcUsesCC?s+=A(S,this.secSrcIndex):s+=A(v,this.secSrcIndex),`Modulator: +var rs=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(A,t)=>(typeof require<"u"?require:A)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var Y=class extends Uint8Array{constructor(A){super(A),this.currentIndex=0}currentIndex};function pe(e){let A=e.reduce((n,o)=>n+o.length,0),t=new Y(A),s=0;for(let n of e)t.set(n,s),s+=n.length;return t}function ct(e){e=Math.floor(e);let A=Math.floor(e/60),t=Math.round(e-A*60);return{minutes:A,seconds:t,time:`${A.toString().padStart(2,"0")}:${t.toString().padStart(2,"0")}`}}function is(e){return e.trim().replaceAll(".mid","").replaceAll(".rmi","").replaceAll("_"," ")}function hA(e){let A="";for(let t=0;t=128&&A<=224&&(s=t,n=A),{status:n,channel:s}}var S={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},as={8:2,9:2,10:2,11:2,12:1,13:1,14:2};var AA={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},re={mainVolume:0,masterPan:1,voicesCap:2,interpolationType:3},bA=-1,mA={channelProperties:0,eventCall:1,reportedCurrentTime:2,sequencerSpecific:3,synthesizerSnapshot:4,ready:5,soundfontError:6,identify:7};var gs=!0,Cs=!0,Te=!0,Es=!0;function Bs(e,A,t,s){gs=e,Cs=A,Te=t,Es=s}function p(...e){gs&&console.info(...e)}function b(...e){Cs&&console.warn(...e)}function hs(...e){Es&&console.table(...e)}function Ae(...e){Te&&console.group(...e)}function DA(...e){Te&&console.groupCollapsed(...e)}function X(){Te&&console.groupEnd()}var ie={reloadSoundFont:0,addNewSoundFont:2,deleteSoundFont:3,rearrangeSoundFonts:4};var Qs="spessasynth-worklet-system",cs=450,pA=9,He=16,Ye="gs";var MA={loadNewSongList:0,pause:1,stop:2,play:3,setTime:4,changeMIDIMessageSending:5,setPlaybackRate:6,setLoop:7,changeSong:8,getMIDI:9,setSkipToFirstNote:10},kA={midiEvent:0,songChange:1,textEvent:2,timeChange:3,pause:4,getMIDI:5,midiError:6};function WA(e,A){let t=0;for(let s=8*(A-1);s>=0;s-=8)t|=e[e.currentIndex++]<>>0}function ls(e,A){if(this.ignoreEvents)return;if(this.sendMIDIMessages&&e.messageStatusByte>=128){this.sendMIDIMessage([e.messageStatusByte,...e.messageData]);return}let t=Se(e.messageStatusByte),s=this.midiPortChannelOffsets[this.midiPorts[A]]||0;switch(t.channel+=s,t.status){case w.noteOn:let n=e.messageData[1];if(n>0)this.synth.noteOn(t.channel,e.messageData[0],n),this.playingNotes.push({midiNote:e.messageData[0],channel:t.channel,velocity:n});else{this.synth.noteOff(t.channel,e.messageData[0]);let E=this.playingNotes.findIndex(g=>g.midiNote===e.messageData[0]&&g.channel===t.channel);E!==-1&&this.playingNotes.splice(E,1)}break;case w.noteOff:this.synth.noteOff(t.channel,e.messageData[0]);let o=this.playingNotes.findIndex(E=>E.midiNote===e.messageData[0]&&E.channel===t.channel);o!==-1&&this.playingNotes.splice(o,1);break;case w.pitchBend:this.synth.pitchWheel(t.channel,e.messageData[1],e.messageData[0]);break;case w.controllerChange:this.synth.controllerChange(t.channel,e.messageData[0],e.messageData[1]);break;case w.programChange:this.synth.programChange(t.channel,e.messageData[0]);break;case w.polyPressure:this.synth.polyPressure(t.channel,e.messageData[0],e.messageData[1]);break;case w.channelPressure:this.synth.channelPressure(t.channel,e.messageData[0]);break;case w.systemExclusive:this.synth.systemExclusive(e.messageData,s);break;case w.setTempo:this.oneTickToSeconds=60/(Fo(e)*this.midiData.timeDivision),this.oneTickToSeconds===0&&(this.oneTickToSeconds=60/(120*this.midiData.timeDivision),b("invalid tempo! falling back to 120 BPM"));break;case w.timeSignature:case w.endOfTrack:case w.midiChannelPrefix:case w.songPosition:case w.activeSensing:case w.keySignature:break;case w.text:case w.lyric:case w.copyright:case w.trackName:case w.marker:case w.cuePoint:case w.instrumentName:this.post(kA.textEvent,[e.messageData,t.status]);break;case w.midiPort:this.assignMIDIPort(A,e.messageData[0]);break;case w.reset:this.synth.stopAllChannels(),this.synth.resetAllControllers();break;default:b(`%cUnrecognized Event: %c${e.messageStatusByte}%c status byte: %c${Object.keys(w).find(E=>w[E]===t.status)}`,I.warn,I.unrecognized,I.warn,I.value);break}}function us(){for(let e=0;e<16;e++)this.synth.createWorkletChannel(!0),e===pA&&this.synth.setDrums(this.synth.workletProcessorChannels.length-1,!0)}function Fo(e){return e.messageData.currentIndex=0,6e7/WA(e.messageData,3)}function fs(){let e=this.currentTime;for(;this.playedTime1&&this.nextSong();return}let s=this.tracks[A][this.eventIndex[A]];if(this.playedTime+=this.oneTickToSeconds*(s.ticks-t.ticks),this.midiData.loop.end<=t.ticks&&this.loop){this.setTimeTicks(this.midiData.loop.start);return}else if(e>=this.duration){if(this.loop){this.setTimeTicks(this.midiData.loop.start);return}this.eventIndex[A]--,this.pause(!0),this.songs.length>1&&this.nextSong();return}}}function ds(){let e=0,A=1/0;return this.tracks.forEach((t,s)=>{this.eventIndex[s]>=t.length||t[this.eventIndex[s]].ticksg===S.dataDecrement||g===S.dataIncrement||g===S.dataEntryMsb||g===S.dataDecrement||g===S.lsbForControl6DataEntry||g===S.RPNLsb||g===S.RPNMsb||g===S.NRPNLsb||g===S.NRPNMsb||g===S.bankSelect||g===S.lsbForControl0BankSelect||g===S.resetAllControllers,E=[];for(let g=0;g=A)break}else if(this.playedTime>=e)break;let c=Se(h.messageStatusByte),d=c.channel+(this.midiPortChannelOffsets[this.midiPorts[g]]||0);switch(c.status){case w.noteOn:case w.noteOff:case w.keySignature:break;case w.pitchBend:s[d]=h.messageData[1]<<7|h.messageData[0];break;case w.programChange:let Q=n[d];Q.program=h.messageData[0],Q.actualBank=Q.bank;break;case w.controllerChange:let l=h.messageData[0];if(o(l))if(this.sendMIDIMessages)this.sendMIDIMessage([w.controllerChange|d%16,l,h.messageData[1]]);else{let m=h.messageData[1];if(l===S.bankSelect){n[d].bank=m;break}this.synth.controllerChange(d,l,m)}else E[d]===void 0&&(E[d]=Array.from(qA)),E[d][l]=h.messageData[1];break;default:this._processEvent(h,g);break}this.eventIndex[g]++,g=this._findFirstEventIndex();let u=this.tracks[g][this.eventIndex[g]];if(u===void 0)return this.stop(),!1;this.playedTime+=this.oneTickToSeconds*(u.ticks-h.ticks)}if(this.sendMIDIMessages){for(let g=0;g>7]),E[g].forEach((h,c)=>{h!==qA[c]&&!o(c)&&this.sendMIDIMessage([w.controllerChange|g%16,c,h])}),n[g].program>=0&&n[g].actualBank>=0){let h=n[g].actualBank;this.sendMIDIMessage([w.controllerChange|g%16,S.bankSelect,h]),this.sendMIDIMessage([w.programChange|g%16,n[g].program])}}else for(let g=0;g>7,s[g]&127),E[g]!==void 0&&E[g].forEach((h,c)=>{h!==qA[c]&&!o(c)&&this.synth.controllerChange(g,c,h)}),n[g].program>=0&&n[g].actualBank>=0){let h=n[g].actualBank;this.synth.controllerChange(g,S.bankSelect,h),this.synth.programChange(g,n[g].program)}return!0}function ps(e=!1){if(this.midiData!==void 0){if(e){this.currentTime=0;return}if(this.currentTime>=this.duration){this.currentTime=0;return}this.paused&&(this._recalculateStartTime(this.pausedTime),this.pausedTime=void 0),this.sendMIDIMessages||this.playingNotes.forEach(A=>{this.synth.noteOn(A.channel,A.midiNote,A.velocity,!1,!0)}),this.setProcessHandler()}}function Je(e,A,t){if(A<=0)return 0;let s=e.find(o=>o.ticks>>0}function Ie(e,A,t){for(let s=0;s>s*8&255}function J(e,A){e[e.currentIndex++]=A&255,e[e.currentIndex++]=A>>8}function cA(e,A){Ie(e,A,4)}function ae(e,A){let t=A<<8|e;return t>32767?t-65536:t}function Ds(e){return e>127?e-256:e}function V(e,A,t=void 0,s=!0){if(t){let n=e.slice(e.currentIndex,e.currentIndex+A);return e.currentIndex+=A,new TextDecoder(t.replace(/[^\x20-\x7E]/g,"")).decode(n.buffer)}else{let n=!1,o="";for(let E=0;E127){if(s){n=!0;continue}else if(g===0){n=!0;continue}}o+=String.fromCharCode(g)}}return o}}function wA(e,A,t=0){t>0&&A.length>t&&(A=A.slice(0,t));for(let s=0;sA.length)for(let s=0;st.header!=="LIST"?!1:(t.chunkData.currentIndex=0,V(t.chunkData,4)===A))}function Ke(e){let A=0;for(;e;){let t=e[e.currentIndex++];if(A=A<<7|t&127,t>>7!==1)break}return A}var a={INVALID:-1,startAddrsOffset:0,endAddrOffset:1,startloopAddrsOffset:2,endloopAddrsOffset:3,startAddrsCoarseOffset:4,modLfoToPitch:5,vibLfoToPitch:6,modEnvToPitch:7,initialFilterFc:8,initialFilterQ:9,modLfoToFilterFc:10,modEnvToFilterFc:11,endAddrsCoarseOffset:12,modLfoToVolume:13,unused1:14,chorusEffectsSend:15,reverbEffectsSend:16,pan:17,unused2:18,unused3:19,unused4:20,delayModLFO:21,freqModLFO:22,delayVibLFO:23,freqVibLFO:24,delayModEnv:25,attackModEnv:26,holdModEnv:27,decayModEnv:28,sustainModEnv:29,releaseModEnv:30,keyNumToModEnvHold:31,keyNumToModEnvDecay:32,delayVolEnv:33,attackVolEnv:34,holdVolEnv:35,decayVolEnv:36,sustainVolEnv:37,releaseVolEnv:38,keyNumToVolEnvHold:39,keyNumToVolEnvDecay:40,instrument:41,reserved1:42,keyRange:43,velRange:44,startloopAddrsCoarseOffset:45,keyNum:46,velocity:47,initialAttenuation:48,reserved2:49,endloopAddrsCoarseOffset:50,coarseTune:51,fineTune:52,sampleID:53,sampleModes:54,reserved3:55,scaleTuning:56,exclusiveClass:57,overridingRootKey:58,unused5:59,endOper:60},T=[];T[a.startAddrsOffset]={min:0,max:32768,def:0};T[a.endAddrOffset]={min:-32768,max:32768,def:0};T[a.startloopAddrsOffset]={min:-32768,max:32768,def:0};T[a.endloopAddrsOffset]={min:-32768,max:32768,def:0};T[a.startAddrsCoarseOffset]={min:0,max:32768,def:0};T[a.modLfoToPitch]={min:-12e3,max:12e3,def:0};T[a.vibLfoToPitch]={min:-12e3,max:12e3,def:0};T[a.modEnvToPitch]={min:-12e3,max:12e3,def:0};T[a.initialFilterFc]={min:1500,max:13500,def:13500};T[a.initialFilterQ]={min:0,max:960,def:0};T[a.modLfoToFilterFc]={min:-12e3,max:12e3,def:0};T[a.modEnvToFilterFc]={min:-12e3,max:12e3,def:0};T[a.endAddrsCoarseOffset]={min:-32768,max:32768,def:0};T[a.modLfoToVolume]={min:-960,max:960,def:0};T[a.chorusEffectsSend]={min:0,max:1e3,def:0};T[a.reverbEffectsSend]={min:0,max:1e3,def:0};T[a.pan]={min:-500,max:500,def:0};T[a.delayModLFO]={min:-12e3,max:5e3,def:-12e3};T[a.freqModLFO]={min:-16e3,max:4500,def:0};T[a.delayVibLFO]={min:-12e3,max:5e3,def:-12e3};T[a.freqVibLFO]={min:-16e3,max:4500,def:0};T[a.delayModEnv]={min:-12e3,max:5e3,def:-12e3};T[a.attackModEnv]={min:-12e3,max:8e3,def:-12e3};T[a.holdModEnv]={min:-12e3,max:5e3,def:-12e3};T[a.decayModEnv]={min:-12e3,max:8e3,def:-12e3};T[a.sustainModEnv]={min:0,max:1e3,def:0};T[a.releaseModEnv]={min:-12e3,max:8e3,def:-12e3};T[a.keyNumToModEnvHold]={min:-1200,max:1200,def:0};T[a.keyNumToModEnvDecay]={min:-1200,max:1200,def:0};T[a.delayVolEnv]={min:-12e3,max:5e3,def:-12e3};T[a.attackVolEnv]={min:-12e3,max:8e3,def:-12e3};T[a.holdVolEnv]={min:-12e3,max:5e3,def:-12e3};T[a.decayVolEnv]={min:-12e3,max:8e3,def:-12e3};T[a.sustainVolEnv]={min:0,max:1440,def:0};T[a.releaseVolEnv]={min:-7200,max:8e3,def:-12e3};T[a.keyNumToVolEnvHold]={min:-1200,max:1200,def:0};T[a.keyNumToVolEnvDecay]={min:-1200,max:1200,def:0};T[a.startloopAddrsCoarseOffset]={min:-32768,max:32768,def:0};T[a.keyNum]={min:-1,max:127,def:-1};T[a.velocity]={min:-1,max:127,def:-1};T[a.initialAttenuation]={min:0,max:1440,def:0};T[a.endloopAddrsCoarseOffset]={min:-32768,max:32768,def:0};T[a.coarseTune]={min:-120,max:120,def:0};T[a.fineTune]={min:-99,max:99,def:0};T[a.scaleTuning]={min:0,max:1200,def:100};T[a.exclusiveClass]={min:0,max:99999,def:0};T[a.overridingRootKey]={min:-1,max:127,def:-1};var U=class{constructor(A=a.INVALID,t=0){if(this.generatorType=A,t===void 0)throw new Error("No value provided.");let s=T[A];this.generatorValue=Math.round(t),s!==void 0&&(this.generatorValue=Math.max(s.min,Math.min(s.max,this.generatorValue)))}generatorType=a.INVALID;generatorValue=0};function ks(e,A,t){let s=T[e]||{min:0,max:32768,def:0},n=A.find(h=>h.generatorType===e),o=0;n&&(o=n.generatorValue);let E=t.find(h=>h.generatorType===e),g=s.def;return E&&(g=E.generatorValue),Math.max(s.min,Math.min(s.max,g+o))}var lt=class extends U{constructor(A){super();let t=A.currentIndex;this.generatorType=A[t+1]<<8|A[t],this.generatorValue=ae(A[t+2],A[t+3]),A.currentIndex+=4}};function ut(e){let A=[];for(;e.chunkData.length>e.chunkData.currentIndex;)A.push(new lt(e.chunkData));return A.length>1&&A.pop(),A}var v={noController:0,noteOnVelocity:2,noteOnKeyNum:3,polyPressure:10,channelPressure:13,pitchWheel:14,pitchWheelRange:16,link:127},lA={linear:0,concave:1,convex:2,switch:3},Ro=[];for(let e=0;e<4;e++)Ro.push([[],[]]);var rA=class e{constructor(A){A.srcEnum?(this.modulatorSource=A.srcEnum,this.modulatorDestination=A.dest,this.modulationSecondarySrc=A.secSrcEnum,this.transformAmount=A.amt,this.transformType=A.transform):(this.modulatorSource=D(A,2),this.modulatorDestination=D(A,2),this.transformAmount=ae(A[A.currentIndex++],A[A.currentIndex++]),this.modulationSecondarySrc=D(A,2),this.transformType=D(A,2)),this.modulatorDestination>58&&(this.modulatorDestination=a.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(A){return new e({srcEnum:this.modulatorSource,secSrcEnum:this.modulationSecondarySrc,dest:this.modulatorDestination,transform:this.transformType,amt:this.transformAmount+A.transformAmount})}debugString(){function A(n,o){return Object.keys(n).find(E=>n[E]===o)}let t=A(lA,this.sourceCurveType);t+=this.sourcePolarity===0?" unipolar ":" bipolar ",t+=this.sourceDirection===0?"forwards ":"backwards ",this.sourceUsesCC?t+=A(S,this.sourceIndex):t+=A(v,this.sourceIndex);let s=A(lA,this.secSrcCurveType);return s+=this.secSrcPolarity===0?" unipolar ":" bipolar ",s+=this.secSrcCurveType===0?"forwards ":"backwards ",this.secSrcUsesCC?s+=A(S,this.secSrcIndex):s+=A(v,this.secSrcIndex),`Modulator: Source: ${t} Secondary source: ${s} Destination: ${A(a,this.modulatorDestination)} diff --git a/src/website/js/renderer/compute_note_positions.js b/src/website/js/renderer/compute_note_positions.js index 4d1de66c..6e9909a7 100644 --- a/src/website/js/renderer/compute_note_positions.js +++ b/src/website/js/renderer/compute_note_positions.js @@ -5,7 +5,7 @@ import { MAX_NOTES, MIN_NOTE_HEIGHT_PX, NOTE_MARGIN, PRESSED_EFFECT_TIME, STROKE * @returns {NoteToRender[]} * @this {Renderer} */ -export function computeNotePositions(renderImmediately=false) +export function computeNotePositions(renderImmediately = false) { // math this.notesOnScreen = 0; @@ -16,7 +16,7 @@ export function computeNotePositions(renderImmediately=false) const keyStep = canvasWidth / (keysAmount + 1); // add one because it works const noteWidth = keyStep - (NOTE_MARGIN * 2); - const fallingTime = this.noteFallingTimeMs / 1000 + const fallingTime = this.noteFallingTimeMs / 1000; const afterTime = this.noteAfterTriggerTimeMs / 1000; const currentSeqTime = this.seq.currentHighResolutionTime; diff --git a/src/website/minified/demo_main.min.js b/src/website/minified/demo_main.min.js index 290faa7c..7b91c6ca 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((I,b)=>I+b.length,0),l=new l6(r),g=0;for(let I of A)l.set(I,g),g+=I.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,I=A;return r>=128&&r<=224&&(g=l,I=r),{status:I,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 I=new ChannelMergerNode(g,{numberOfInputs:2}),b=[],h0=[],b0=l.oscillatorFrequency,p0=l.defaultDelay;for(let R0=0;R0{let b=await I.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 Im=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(I=>I.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(I=>this.synth.resolveWhenReady=I),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,I=void 0,b=zQ){Y5("%cInitializing SpessaSynth synthesizer...",D1.info),this.context=r.context;let h0=I?.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 Im(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,I){this.post({channelNumber:Hi,messageType:B8.setLogLevel,messageData:[r,l,g,I]})}_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,I)=>g+I.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,I)=>{let b;if(Bn)b=127;else{let b0=this.keys[0].getBoundingClientRect();if(this.keyboard.classList.contains("sideways")){let p0=I.clientX-b0.left,R0=b0.width;b=Math.floor((R0-p0)/R0*127)}else{let p0=I.clientY-b0.top,R0=b0.height;b=Math.floor(p0/R0*127)}}this.synth.noteOn(this.channel,g,b,this.enableDebugging)},l=g=>{let I=g.touches?Array.from(g.touches):[g],b=new Set;I.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 I=0;I<128;I++)this.releaseNote(I,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 I=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/(I/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=I/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",`${I}`),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",`${I}`),this._keyRange=r,this._createKeyboard()}selectChannel(r){this.channel=r}pressNote(r,l,g){let I=this.keys[r-this._keyRange.min];if(I===void 0)return;I.classList.add("pressed");let b=I.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]})`,I.style.background=p0,this.mode==="dark"){let R0=WQ*h0;I.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 I=this.keyColors[r-this._keyRange.min];if(!I)return;let b=I.findLastIndex(h0=>h0===this.channelColors[l]);b!==-1&&(I.splice(b,1),g.style.background=I[I.length-1],this.mode==="dark"&&(g.style.boxShadow=`0px 0px ${WQ}px ${I[I.length-1]}`),I.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 I$(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 I=g.pressedProgress*g.velocity;if(r.globalAlpha=.5*I,l){r.fillRect(g.xPos,g.yPos-g.height*I,g.width,g.height*(I*2+1)),r.globalAlpha=1;return}r.fillRect(g.xPos-g.width*I,g.yPos,g.width*(I*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 I=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(I).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,I=r/(g+1),b=I-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*I))}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=I*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+d$+E$,u4+d$,Ke-d$*2,J4-d$*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 I=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*I,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*I,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;A{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),I=this.canvas.classList.contains("light_mode")?0:.9;this.canvas.style.background=`linear-gradient(rgba(0, 0, 0, ${I}), rgba(0, 0, 0, ${I})), 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=[],I=A.tracks.flat();I.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>=I.length)break;b+=h0*(I[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,dm=.6,Em=.5,d$=1,E$=1,bB=16,ty=.6,iy=2,ry=81572,vi=class{constructor(r,l,g,I){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=I,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,I$(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,I$(r,g=>g*Em*dm)),l.addColorStop(1,I$(r,g=>g*dm)),l}),this.sidewaysChannelColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,I$(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,I$(r,g=>g*Em*dm)),l.addColorStop(1,I$(r,g=>g*dm)),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 I=A.slice(A.currentIndex,A.currentIndex+r);return A.currentIndex+=r,new TextDecoder(l.replace(/[^\x20-\x7E]/g,"")).decode(I.buffer)}else{let I=!1,b="";for(let h0=0;h0127){if(g){I=!0;continue}else if(b0===0){I=!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 Ii(g,A,r),g}function Ii(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 I of A.tracks){let b=[],h0=0,b0;for(let p0 of I){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(I,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(I,b){return Object.keys(I).find(h0=>I[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,I)=>{let b;if(Bn)b=127;else{let b0=this.keys[0].getBoundingClientRect();if(this.keyboard.classList.contains("sideways")){let p0=I.clientX-b0.left,R0=b0.width;b=Math.floor((R0-p0)/R0*127)}else{let p0=I.clientY-b0.top,R0=b0.height;b=Math.floor(p0/R0*127)}}this.synth.noteOn(this.channel,g,b,this.enableDebugging)},l=g=>{let I=g.touches?Array.from(g.touches):[g],b=new Set;I.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 I=0;I<128;I++)this.releaseNote(I,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 I=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/(I/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=I/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",`${I}`),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",`${I}`),this._keyRange=r,this._createKeyboard()}selectChannel(r){this.channel=r}pressNote(r,l,g){let I=this.keys[r-this._keyRange.min];if(I===void 0)return;I.classList.add("pressed");let b=I.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]})`,I.style.background=p0,this.mode==="dark"){let R0=WQ*h0;I.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 I=this.keyColors[r-this._keyRange.min];if(!I)return;let b=I.findLastIndex(h0=>h0===this.channelColors[l]);b!==-1&&(I.splice(b,1),g.style.background=I[I.length-1],this.mode==="dark"&&(g.style.boxShadow=`0px 0px ${WQ}px ${I[I.length-1]}`),I.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 I$(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 I=g.pressedProgress*g.velocity;if(r.globalAlpha=.5*I,l){r.fillRect(g.xPos,g.yPos-g.height*I,g.width,g.height*(I*2+1)),r.globalAlpha=1;return}r.fillRect(g.xPos-g.width*I,g.yPos,g.width*(I*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 I=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(I).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,I=r/(g+1),b=I-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*I))}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=I*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+d$+E$,u4+d$,Ke-d$*2,J4-d$*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 I=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*I,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*I,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;A{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),I=this.canvas.classList.contains("light_mode")?0:.9;this.canvas.style.background=`linear-gradient(rgba(0, 0, 0, ${I}), rgba(0, 0, 0, ${I})), 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=[],I=A.tracks.flat();I.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>=I.length)break;b+=h0*(I[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,dm=.6,Em=.5,d$=1,E$=1,bB=16,ty=.6,iy=2,ry=81572,vi=class{constructor(r,l,g,I){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=I,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,I$(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,I$(r,g=>g*Em*dm)),l.addColorStop(1,I$(r,g=>g*dm)),l}),this.sidewaysChannelColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,I$(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,I$(r,g=>g*Em*dm)),l.addColorStop(1,I$(r,g=>g*dm)),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 I=A.slice(A.currentIndex,A.currentIndex+r);return A.currentIndex+=r,new TextDecoder(l.replace(/[^\x20-\x7E]/g,"")).decode(I.buffer)}else{let I=!1,b="";for(let h0=0;h0127){if(g){I=!0;continue}else if(b0===0){I=!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 Ii(g,A,r),g}function Ii(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 I of A.tracks){let b=[],h0=0,b0;for(let p0 of I){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(I,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(I,b){return Object.keys(I).find(h0=>I[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 b5f7c6ac..0ca18f14 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 DA(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 s6={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 Ah=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,s6.sustainPedal,127),this.keyboard.style.filter="brightness(0.5)")}),document.addEventListener("keyup",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,s6.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;o{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 sh=.02;function Ay(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=Ay;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 sy(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(s6,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(s6,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,s6.sustainPedal,127),this.keyboard.style.filter="brightness(0.5)")}),document.addEventListener("keyup",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,s6.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;o{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 sh=.02;function Ay(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=Ay;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 sy(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(s6,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(s6,this.secSrcIndex):g+=r(R7,this.secSrcIndex),`Modulator: Source: ${l} Secondary source: ${g} Destination: ${r(b1,this.modulatorDestination)}