js-synthesizer
Advanced tools
Comparing version 1.9.0 to 1.10.0
# Changelog | ||
## v1.10.0 | ||
- Add `setPlayerLoop` and `setPlayerTempo` methods to `ISynthesizer` | ||
## v1.9.0 | ||
@@ -4,0 +8,0 @@ |
/*! | ||
js-synthesizer version 1.9.0 | ||
js-synthesizer version 1.10.0 | ||
@@ -30,3 +30,3 @@ @license | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["js-synthesizer"]=t():e.JSSynth=t()}(this,(()=>(()=>{"use strict";var e={d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{AudioWorkletNodeSynthesizer:()=>Y,Constants:()=>s,LogLevel:()=>J,MessageError:()=>o,SequencerEventTypes:()=>n,Synthesizer:()=>B,disableLogging:()=>Q,restoreLogging:()=>X,rewriteEventData:()=>l,waitForReady:()=>L});var s={};e.r(s);var n={};e.r(n);class i{constructor(e,t){this._ptr=e,this._module=t}getRaw(){return this._ptr}dispose(){this._ptr=0}getType(){return 0===this._ptr?-1:this._module._fluid_event_get_type(this._ptr)}getSource(){return 0===this._ptr?-1:this._module._fluid_event_get_source(this._ptr)}getDest(){return 0===this._ptr?-1:this._module._fluid_event_get_dest(this._ptr)}getChannel(){return 0===this._ptr?-1:this._module._fluid_event_get_channel(this._ptr)}getKey(){return 0===this._ptr?-1:this._module._fluid_event_get_key(this._ptr)}getVelocity(){return 0===this._ptr?-1:this._module._fluid_event_get_velocity(this._ptr)}getControl(){return 0===this._ptr?-1:this._module._fluid_event_get_control(this._ptr)}getValue(){return 0===this._ptr?-1:this._module._fluid_event_get_value(this._ptr)}getProgram(){return 0===this._ptr?-1:this._module._fluid_event_get_program(this._ptr)}getData(){return 0===this._ptr?-1:this._module._fluid_event_get_data(this._ptr)}getDuration(){return 0===this._ptr?-1:this._module._fluid_event_get_duration(this._ptr)}getBank(){return 0===this._ptr?-1:this._module._fluid_event_get_bank(this._ptr)}getPitch(){return 0===this._ptr?-1:this._module._fluid_event_get_pitch(this._ptr)}getSFontId(){return 0===this._ptr?-1:this._module._fluid_event_get_sfont_id(this._ptr)}}const r="undefined"!=typeof AudioWorkletGlobalScope?AudioWorkletGlobalScope.wasmModule:Module;function _(e,t){switch(t.type){case 0:case"note":r._fluid_event_note(e,t.channel,t.key,t.vel,t.duration);break;case 1:case"noteon":case"note-on":r._fluid_event_noteon(e,t.channel,t.key,t.vel);break;case 2:case"noteoff":case"note-off":r._fluid_event_noteoff(e,t.channel,t.key);break;case 3:case"allsoundsoff":case"all-sounds-off":r._fluid_event_all_sounds_off(e,t.channel);break;case 4:case"allnotesoff":case"all-notes-off":r._fluid_event_all_notes_off(e,t.channel);break;case 5:case"bankselect":case"bank-select":r._fluid_event_bank_select(e,t.channel,t.bank);break;case 6:case"programchange":case"program-change":r._fluid_event_program_change(e,t.channel,t.preset);break;case 7:case"programselect":case"program-select":r._fluid_event_program_select(e,t.channel,t.sfontId,t.bank,t.preset);break;case 12:case"controlchange":case"control-change":r._fluid_event_control_change(e,t.channel,t.control,t.value);break;case 8:case"pitchbend":case"pitch-bend":r._fluid_event_pitch_bend(e,t.channel,t.value);break;case 9:case"pitchwheelsens":case"pitchwheelsensitivity":case"pitch-wheel-sens":case"pitch-wheel-sensitivity":r._fluid_event_pitch_wheelsens(e,t.channel,t.value);break;case 10:case"modulation":r._fluid_event_modulation(e,t.channel,t.value);break;case 11:case"sustain":r._fluid_event_sustain(e,t.channel,t.value);break;case 13:case"pan":r._fluid_event_pan(e,t.channel,t.value);break;case 14:case"volume":r._fluid_event_volume(e,t.channel,t.value);break;case 15:case"reverb":case"reverbsend":case"reverb-send":r._fluid_event_reverb_send(e,t.channel,t.value);break;case 16:case"chorus":case"chorussend":case"chorus-send":r._fluid_event_chorus_send(e,t.channel,t.value);break;case 20:case"keypressure":case"key-pressure":case"aftertouch":r._fluid_event_key_pressure(e,t.channel,t.key,t.value);break;case 19:case"channelpressure":case"channel-pressure":case"channel-aftertouch":r._fluid_event_channel_pressure(e,t.channel,t.value);break;case 21:case"systemreset":case"system-reset":r._fluid_event_system_reset(e);break;case 17:case"timer":r._fluid_event_timer(e,t.data);break;default:return!1}return!0}function l(e,t){if(!(e&&e instanceof i))return!1;const s=e.getRaw();return 0!==s&&_(s,t)}class o extends Error{constructor(e,t,s){super(t),this.baseName=e,this.detail=s,s&&s.stack&&(this.stack=s.stack)}}class a{constructor(e,t){this._ptr=e,this._module=t}getType(){return this._module._fluid_midi_event_get_type(this._ptr)}setType(e){this._module._fluid_midi_event_set_type(this._ptr,e)}getChannel(){return this._module._fluid_midi_event_get_channel(this._ptr)}setChannel(e){this._module._fluid_midi_event_set_channel(this._ptr,e)}getKey(){return this._module._fluid_midi_event_get_key(this._ptr)}setKey(e){this._module._fluid_midi_event_set_key(this._ptr,e)}getVelocity(){return this._module._fluid_midi_event_get_velocity(this._ptr)}setVelocity(e){this._module._fluid_midi_event_set_velocity(this._ptr,e)}getControl(){return this._module._fluid_midi_event_get_control(this._ptr)}setControl(e){this._module._fluid_midi_event_set_control(this._ptr,e)}getValue(){return this._module._fluid_midi_event_get_value(this._ptr)}setValue(e){this._module._fluid_midi_event_set_value(this._ptr,e)}getProgram(){return this._module._fluid_midi_event_get_program(this._ptr)}setProgram(e){this._module._fluid_midi_event_set_program(this._ptr,e)}getPitch(){return this._module._fluid_midi_event_get_pitch(this._ptr)}setPitch(e){this._module._fluid_midi_event_set_pitch(this._ptr,e)}setSysEx(e){const t=e.byteLength,s=this._module._malloc(t);new Uint8Array(this._module.HEAPU8.buffer,s,t).set(e),this._module._fluid_midi_event_set_sysex(this._ptr,s,t,1)}setText(e){const t=e.byteLength,s=this._module._malloc(t);new Uint8Array(this._module.HEAPU8.buffer,s,t).set(e),this._module._fluid_midi_event_set_text(this._ptr,s,t,1)}setLyrics(e){const t=e.byteLength,s=this._module._malloc(t);new Uint8Array(this._module.HEAPU8.buffer,s,t).set(e),this._module._fluid_midi_event_set_lyrics(this._ptr,s,t,1)}}let h,u,d,c,f,y,g,m,p,v,b,P,w,S,k,C,q,I,A,E,F,T;function z(e){const t=h._new_fluid_event();return _(t,e)?t:(h._delete_fluid_event(t),null)}class R{constructor(){h||("undefined"!=typeof AudioWorkletGlobalScope?(h=AudioWorkletGlobalScope.wasmModule,u=AudioWorkletGlobalScope.wasmRemoveFunction):(h=Module,u=removeFunction),d=h.cwrap("fluid_sequencer_get_client_name","string",["number","number"])),this._seq=0,this._seqId=-1,this._clientFuncMap={}}_initialize(){return this.close(),this._seq=h._new_fluid_sequencer2(0),this._seqId=-1,Promise.resolve()}getRaw(){return this._seq}close(){0!==this._seq&&(Object.keys(this._clientFuncMap).forEach((e=>{this.unregisterClient(Number(e))})),this.unregisterClient(-1),h._delete_fluid_sequencer(this._seq),this._seq=0)}registerSynthesizer(e){let t;if(-1!==this._seqId&&(h._fluid_sequencer_unregister_client(this._seq,this._seqId),this._seqId=-1),"number"==typeof e)t=e;else{if(!(e instanceof B))return Promise.reject(new TypeError("'synth' is not a compatible type instance"));t=e.getRawSynthesizer()}return this._seqId=h._fluid_sequencer_register_fluidsynth(this._seq,t),Promise.resolve(this._seqId)}unregisterClient(e){if(-1===e&&-1===(e=this._seqId))return;const t=h._new_fluid_event();if(h._fluid_event_set_source(t,-1),h._fluid_event_set_dest(t,e),h._fluid_event_unregistering(t),h._fluid_sequencer_send_now(this._seq,t),h._delete_fluid_event(t),h._fluid_sequencer_unregister_client(this._seq,e),this._seqId===e)this._seqId=-1;else{const t=this._clientFuncMap;t[e]&&(u(t[e]),delete t[e])}}getAllRegisteredClients(){const e=h._fluid_sequencer_count_clients(this._seq),t=[];for(let s=0;s<e;++s){const e=h._fluid_sequencer_get_client_id(this._seq,s),n=d(this._seq,e);t.push({clientId:e,name:n})}return Promise.resolve(t)}getClientCount(){return Promise.resolve(h._fluid_sequencer_count_clients(this._seq))}getClientInfo(e){const t=h._fluid_sequencer_get_client_id(this._seq,e),s=d(this._seq,t);return Promise.resolve({clientId:t,name:s})}setTimeScale(e){h._fluid_sequencer_set_time_scale(this._seq,e)}getTimeScale(){return Promise.resolve(h._fluid_sequencer_get_time_scale(this._seq))}getTick(){return Promise.resolve(h._fluid_sequencer_get_tick(this._seq))}sendEventAt(e,t,s){const n=z(e);if(null!==n){const e=h._fluid_sequencer_count_clients(this._seq);for(let i=0;i<e;++i){const e=h._fluid_sequencer_get_client_id(this._seq,i);h._fluid_event_set_dest(n,e),h._fluid_sequencer_send_at(this._seq,n,t,s?1:0)}h._delete_fluid_event(n)}}sendEventToClientAt(e,t,s,n){const i=z(t);null!==i&&(h._fluid_event_set_dest(i,-1===e?this._seqId:e),h._fluid_sequencer_send_at(this._seq,i,s,n?1:0),h._delete_fluid_event(i))}sendEventToClientNow(e,t){const s=z(t);null!==s&&(h._fluid_event_set_dest(s,-1===e?this._seqId:e),h._fluid_sequencer_send_now(this._seq,s),h._delete_fluid_event(s))}sendEventNow(e,t){if(!(t instanceof i))return;const s=t.getRaw();0!==s&&(h._fluid_event_set_dest(s,-1===e?this._seqId:e),h._fluid_sequencer_send_now(this._seq,s))}removeAllEvents(){h._fluid_sequencer_remove_events(this._seq,-1,-1,-1)}removeAllEventsFromClient(e){h._fluid_sequencer_remove_events(this._seq,-1,-1===e?this._seqId:e,-1)}processSequencer(e){0!==this._seq&&h._fluid_sequencer_process(this._seq,e)}setIntervalForSequencer(e){return setInterval((()=>this.processSequencer(e)),e)}}class M{constructor(e){this._ptr=e}static getSoundfontById(e,t){c||(c="undefined"!=typeof AudioWorkletGlobalScope?AudioWorkletGlobalScope.wasmModule:Module,f=c.cwrap("fluid_sfont_get_name","string",["number"]),y=c.cwrap("fluid_preset_get_name","string",["number"]));const s=c._fluid_synth_get_sfont_by_id(e.getRawSynthesizer(),t);return 0===s?null:new M(s)}getName(){return f(this._ptr)}getPreset(e,t){const s=c._fluid_sfont_get_preset(this._ptr,e,t);if(0===s)return null;return{soundfont:this,name:y(s),bankNum:c._fluid_preset_get_banknum(s),num:c._fluid_preset_get_num(s)}}getPresetIterable(){const e=()=>{c._fluid_sfont_iteration_start(this._ptr)},t=()=>{const e=c._fluid_sfont_iteration_next(this._ptr);if(0===e)return{done:!0,value:void 0};return{done:!1,value:{soundfont:this,name:y(e),bankNum:c._fluid_preset_get_banknum(e),num:c._fluid_preset_get_num(e)}}};return{[Symbol.iterator]:()=>(e(),{next:t})}}}function O(){if(!S){if("undefined"!=typeof AudioWorkletGlobalScope)g=AudioWorkletGlobalScope.wasmModule,m=AudioWorkletGlobalScope.wasmAddFunction,p=AudioWorkletGlobalScope.wasmRemoveFunction;else{if("undefined"==typeof Module)throw new Error("wasm module is not available. libfluidsynth-*.js must be loaded.");g=Module,m=addFunction,p=removeFunction}v=g.FS,b=g.cwrap("fluid_settings_setint","number",["number","string","number"]),P=g.cwrap("fluid_settings_setnum","number",["number","string","number"]),w=g.cwrap("fluid_settings_setstr","number",["number","string","string"]),S=g.cwrap("fluid_synth_error","string",["number"]),k=g.cwrap("fluid_synth_sfload","number",["number","string","number"]),C=g.cwrap("fluid_sequencer_register_client","number",["number","string","number","number"]),q=g._malloc.bind(g),I=g._free.bind(g),A=g._fluid_synth_handle_midi_event.bind(g)}}function N(e,t,s){void 0!==s&&b(e,t,s?1:0)}function j(e,t,s){void 0!==s&&b(e,t,s)}function D(e,t,s){void 0!==s&&P(e,t,s)}class B{constructor(){O(),this._settings=0,this._synth=0,this._player=0,this._playerPlaying=!1,this._playerCallbackPtr=null,this._fluidSynthCallback=null,this._buffer=0,this._bufferSize=0,this._numPtr=0,this._gain=.5}static waitForWasmInitialized(){return function(){if(E)return E;let e,t;if("undefined"!=typeof AudioWorkletGlobalScope)e=AudioWorkletGlobalScope.wasmModule,t=AudioWorkletGlobalScope.addOnPostRun;else{if("undefined"==typeof Module)return Promise.reject(new Error("wasm module is not available. libfluidsynth-*.js must be loaded."));e=Module,t="undefined"!=typeof addOnPostRun?addOnPostRun:void 0}return e.calledRun?(E=Promise.resolve(),E):(E=new Promise(void 0===t?e=>{const t=g.onRuntimeInitialized;g.onRuntimeInitialized=()=>{e(),t&&t()}}:e=>{t(e)}),E)}()}isInitialized(){return 0!==this._synth}getRawSynthesizer(){return this._synth}createAudioNode(e,t){const s=e.createScriptProcessor(t,0,2);return s.addEventListener("audioprocess",(e=>{this.render(e.outputBuffer)})),s}init(e,t){this.close();const s=this._settings=g._new_fluid_settings();P(s,"synth.sample-rate",e),t&&(void 0!==t.initialGain&&(this._gain=t.initialGain),N(s,"synth.chorus.active",t.chorusActive),D(s,"synth.chorus.depth",t.chorusDepth),D(s,"synth.chorus.level",t.chorusLevel),j(s,"synth.chorus.nr",t.chorusNr),D(s,"synth.chorus.speed",t.chorusSpeed),j(s,"synth.midi-channels",t.midiChannelCount),function(e,t,s){void 0!==s&&w(e,t,s)}(s,"synth.midi-bank-select",t.midiBankSelect),j(s,"synth.min-note-length",t.minNoteLength),D(s,"synth.overflow.age",t.overflowAge),D(s,"synth.overflow.important",t.overflowImportantValue),void 0!==t.overflowImportantChannels&&w(s,"synth.overflow.important-channels",t.overflowImportantChannels.join(",")),D(s,"synth.overflow.percussion",t.overflowPercussion),D(s,"synth.overflow.released",t.overflowReleased),D(s,"synth.overflow.sustained",t.overflowSustained),D(s,"synth.overflow.volume",t.overflowVolume),j(s,"synth.polyphony",t.polyphony),N(s,"synth.reverb.active",t.reverbActive),D(s,"synth.reverb.damp",t.reverbDamp),D(s,"synth.reverb.level",t.reverbLevel),D(s,"synth.reverb.room-size",t.reverbRoomSize),D(s,"synth.reverb.width",t.reverbWidth)),P(s,"synth.gain",this._gain),this._synth=g._new_fluid_synth(this._settings),this._numPtr=q(8)}close(){0!==this._synth&&(this._closePlayer(),g._delete_fluid_synth(this._synth),this._synth=0,g._delete_fluid_settings(this._settings),this._settings=0,I(this._numPtr),this._numPtr=0)}isPlaying(){return 0!==this._synth&&function(e){const t=g._fluid_synth_get_active_voice_count(e);if(!t)return 0;let s=140,n=e+s+4>>2,i=g.HEAPU32[n];if(i!==t&&(s+=4,n=e+s+4>>2,i=g.HEAPU32[n],i!==t))return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t;const r=g.HEAPU32[e+s>>2];if(!r||r>=g.HEAPU32.byteLength)return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t;const _=g._fluid_synth_get_polyphony(e);let l=!1;for(let e=0;e<_;++e){const t=g.HEAPU32[(r>>2)+e];if(t&&4!==g.HEAPU8[t+4]){l=!0;break}}if(!l)return 0!==i&&console.warn("js-synthesizer: Active voice count is not zero, but all voices are off:",i),g.HEAPU32[n]=0,0;return t}(this._synth)>0}setInterpolation(e,t){this.ensureInitialized(),void 0===t&&(t=-1),g._fluid_synth_set_interp_method(this._synth,t,e)}getGain(){return this._gain}setGain(e){this.ensureInitialized(),g._fluid_synth_set_gain(this._synth,e),this._gain=g._fluid_synth_get_gain(this._synth)}setChannelType(e,t){this.ensureInitialized(),g._fluid_synth_set_channel_type(this._synth,e,t?1:0)}waitForVoicesStopped(){return this.flushFramesAsync()}loadSFont(e){this.ensureInitialized();const t=(s=".sf2",`/${"sfont"}-r${65535*Math.random()}-${65535*Math.random()}${s}`);var s;const n=new Uint8Array(e);v.writeFile(t,n);const i=k(this._synth,t,1);return v.unlink(t),-1===i?Promise.reject(new Error(S(this._synth))):Promise.resolve(i)}unloadSFont(e){this.ensureInitialized(),this.stopPlayer(),this.flushFramesSync(),g._fluid_synth_sfunload(this._synth,e,1)}unloadSFontAsync(e){return this.ensureInitialized(),this.stopPlayer(),this.flushFramesAsync().then((()=>{g._fluid_synth_sfunload(this._synth,e,1)}))}getSFontObject(e){return M.getSoundfontById(this,e)}getSFontBankOffset(e){return this.ensureInitialized(),Promise.resolve(g._fluid_synth_get_bank_offset(this._synth,e))}setSFontBankOffset(e,t){this.ensureInitialized(),g._fluid_synth_set_bank_offset(this._synth,e,t)}render(e){const t="numberOfChannels"in e?e.length:e[0].length,s="numberOfChannels"in e?e.numberOfChannels:e.length,n=4*t,i=2*n;this._bufferSize<i&&(0!==this._buffer&&I(this._buffer),this._buffer=q(i),this._bufferSize=i);const r=this._buffer,_=this._buffer+n;this.renderRaw(r,_,t);const l=new Float32Array(g.HEAPU8.buffer,r,t),o=s>=2?new Float32Array(g.HEAPU8.buffer,_,t):null;if("numberOfChannels"in e)if(e.copyToChannel)e.copyToChannel(l,0,0),o&&e.copyToChannel(o,1,0);else{const t=e.getChannelData(0);if(l.forEach(((e,s)=>t[s]=e)),o){const t=e.getChannelData(1);o.forEach(((e,s)=>t[s]=e))}}else e[0].set(l),o&&e[1].set(o);this.isPlayerPlaying()}midiNoteOn(e,t,s){g._fluid_synth_noteon(this._synth,e,t,s)}midiNoteOff(e,t){g._fluid_synth_noteoff(this._synth,e,t)}midiKeyPressure(e,t,s){g._fluid_synth_key_pressure(this._synth,e,t,s)}midiControl(e,t,s){g._fluid_synth_cc(this._synth,e,t,s)}midiProgramChange(e,t){g._fluid_synth_program_change(this._synth,e,t)}midiChannelPressure(e,t){g._fluid_synth_channel_pressure(this._synth,e,t)}midiPitchBend(e,t){g._fluid_synth_pitch_bend(this._synth,e,t)}midiSysEx(e){const t=e.byteLength,s=q(t);g.HEAPU8.set(e,s),g._fluid_synth_sysex(this._synth,s,t,0,0,0,0),I(s)}midiPitchWheelSensitivity(e,t){g._fluid_synth_pitch_wheel_sens(this._synth,e,t)}midiBankSelect(e,t){g._fluid_synth_bank_select(this._synth,e,t)}midiSFontSelect(e,t){g._fluid_synth_sfont_select(this._synth,e,t)}midiProgramSelect(e,t,s,n){g._fluid_synth_program_select(this._synth,e,t,s,n)}midiUnsetProgram(e){g._fluid_synth_unset_program(this._synth,e)}midiProgramReset(){g._fluid_synth_program_reset(this._synth)}midiSystemReset(){g._fluid_synth_system_reset(this._synth)}midiAllNotesOff(e){g._fluid_synth_all_notes_off(this._synth,void 0===e?-1:e)}midiAllSoundsOff(e){g._fluid_synth_all_sounds_off(this._synth,void 0===e?-1:e)}midiSetChannelType(e,t){g._fluid_synth_set_channel_type(this._synth,e,t?1:0)}setReverb(e,t,s,n){g._fluid_synth_set_reverb(this._synth,e,t,s,n)}setReverbRoomsize(e){g._fluid_synth_set_reverb_roomsize(this._synth,e)}setReverbDamp(e){g._fluid_synth_set_reverb_damp(this._synth,e)}setReverbWidth(e){g._fluid_synth_set_reverb_width(this._synth,e)}setReverbLevel(e){g._fluid_synth_set_reverb_level(this._synth,e)}setReverbOn(e){g._fluid_synth_set_reverb_on(this._synth,e?1:0)}getReverbRoomsize(){return g._fluid_synth_get_reverb_roomsize(this._synth)}getReverbDamp(){return g._fluid_synth_get_reverb_damp(this._synth)}getReverbLevel(){return g._fluid_synth_get_reverb_level(this._synth)}getReverbWidth(){return g._fluid_synth_get_reverb_width(this._synth)}setChorus(e,t,s,n,i){g._fluid_synth_set_chorus(this._synth,e,t,s,n,i)}setChorusVoiceCount(e){g._fluid_synth_set_chorus_nr(this._synth,e)}setChorusLevel(e){g._fluid_synth_set_chorus_level(this._synth,e)}setChorusSpeed(e){g._fluid_synth_set_chorus_speed(this._synth,e)}setChorusDepth(e){g._fluid_synth_set_chorus_depth(this._synth,e)}setChorusType(e){g._fluid_synth_set_chorus_type(this._synth,e)}setChorusOn(e){g._fluid_synth_set_chorus_on(this._synth,e?1:0)}getChorusVoiceCount(){return g._fluid_synth_get_chorus_nr(this._synth)}getChorusLevel(){return g._fluid_synth_get_chorus_level(this._synth)}getChorusSpeed(){return g._fluid_synth_get_chorus_speed(this._synth)}getChorusDepth(){return g._fluid_synth_get_chorus_depth(this._synth)}getChorusType(){return g._fluid_synth_get_chorus_type(this._synth)}getGenerator(e,t){return g._fluid_synth_get_gen(this._synth,e,t)}setGenerator(e,t,s){g._fluid_synth_set_gen(this._synth,e,t,s)}getLegatoMode(e){return g._fluid_synth_get_legato_mode(this._synth,e,this._numPtr),g.HEAP32[this._numPtr>>2]}setLegatoMode(e,t){g._fluid_synth_set_legato_mode(this._synth,e,t)}getPortamentoMode(e){return g._fluid_synth_get_portamento_mode(this._synth,e,this._numPtr),g.HEAP32[this._numPtr>>2]}setPortamentoMode(e,t){g._fluid_synth_set_portamento_mode(this._synth,e,t)}getBreathMode(e){return g._fluid_synth_get_breath_mode(this._synth,e,this._numPtr),g.HEAP32[this._numPtr>>2]}setBreathMode(e,t){g._fluid_synth_set_breath_mode(this._synth,e,t)}resetPlayer(){return new Promise((e=>{this._initPlayer(),e()}))}closePlayer(){this._closePlayer()}_initPlayer(){this._closePlayer();const e=g._new_fluid_player(this._synth);if(this._player=e,0===e)throw new Error("Out of memory");if(null===this._fluidSynthCallback){const t=g.HEAPU32[e+588>>2];g.HEAPU32[e+592>>2]===this._synth&&(this._fluidSynthCallback=t)}}_closePlayer(){const e=this._player;0!==e&&(this.stopPlayer(),g._delete_fluid_player(e),this._player=0,this._playerCallbackPtr=null)}isPlayerPlaying(){if(this._playerPlaying){if(1===g._fluid_player_get_status(this._player))return!0;this.stopPlayer()}return!1}addSMFDataToPlayer(e){this.ensurePlayerInitialized();const t=e.byteLength,s=q(t);g.HEAPU8.set(new Uint8Array(e),s);const n=g._fluid_player_add_mem(this._player,s,t);return I(s),-1!==n?Promise.resolve():Promise.reject(new Error(S(this._synth)))}playPlayer(){if(this.ensurePlayerInitialized(),this._playerPlaying&&this.stopPlayer(),-1===g._fluid_player_play(this._player))return Promise.reject(new Error(S(this._synth)));this._playerPlaying=!0;let e=()=>{};const t=new Promise((t=>{e=t}));return this._playerDefer={promise:t,resolve:e},Promise.resolve()}stopPlayer(){const e=this._player;0!==e&&this._playerPlaying&&(g._fluid_player_stop(e),g._fluid_player_join(e),g._fluid_synth_all_sounds_off(this._synth,-1),this._playerDefer&&(this._playerDefer.resolve(),this._playerDefer=void 0),this._playerPlaying=!1)}retrievePlayerCurrentTick(){return this.ensurePlayerInitialized(),Promise.resolve(g._fluid_player_get_current_tick(this._player))}retrievePlayerTotalTicks(){return this.ensurePlayerInitialized(),Promise.resolve(g._fluid_player_get_total_ticks(this._player))}retrievePlayerBpm(){return this.ensurePlayerInitialized(),Promise.resolve(g._fluid_player_get_bpm(this._player))}retrievePlayerMIDITempo(){return this.ensurePlayerInitialized(),Promise.resolve(g._fluid_player_get_midi_tempo(this._player))}seekPlayer(e){this.ensurePlayerInitialized(),g._fluid_player_seek(this._player,e)}hookPlayerMIDIEvents(e,t){this.ensurePlayerInitialized();const s=this._playerCallbackPtr;if(null===s&&null===e)return;const n=null!==e?m(function(e,t,s){return(n,i)=>{const r=g._fluid_midi_event_get_type(i);return t(e,r,new a(i,g),s)?0:g._fluid_synth_handle_midi_event(n,i)}}(this,e,t),"iii"):null!==this._fluidSynthCallback?null:m(A,"iii");null!==s&&null!==n?(g._fluid_player_set_playback_callback(this._player,n,this._synth),p(s)):null===n?(g._fluid_player_set_playback_callback(this._player,this._fluidSynthCallback,this._synth),p(s)):g._fluid_player_set_playback_callback(this._player,n,this._synth),this._playerCallbackPtr=n}ensureInitialized(){if(0===this._synth)throw new Error("Synthesizer is not initialized")}ensurePlayerInitialized(){this.ensureInitialized(),0===this._player&&this._initPlayer()}renderRaw(e,t,s){g._fluid_synth_write_float(this._synth,s,e,0,1,t,0,1)}flushFramesSync(){const e=262144,t=q(524288),s=t,n=t+e;for(;this.isPlaying();)this.renderRaw(s,n,65536);I(t)}flushFramesAsync(){if(!this.isPlaying())return Promise.resolve();const e=262144,t=q(524288),s=t,n=t+e,i="undefined"!=typeof setTimeout?()=>new Promise((e=>setTimeout(e,0))):()=>Promise.resolve();function r(){return i().then(l)}const _=this;function l(){return _.isPlaying()?(_.renderRaw(s,n,65536),r()):(I(t),Promise.resolve())}return r()}waitForPlayerStopped(){return this._playerDefer?this._playerDefer.promise:Promise.resolve()}static createSequencer(){O();const e=new R;return e._initialize().then((()=>e))}static registerSequencerClient(e,t,s,n){if(!(e instanceof R))throw new TypeError("Invalid sequencer instance");const r=m(((t,n,r,_)=>{const l=new i(n,g),o=g._fluid_event_get_type(n);s(t,o,l,e,_)}),"viiii"),_=C(e.getRaw(),t,r,n);return-1!==_&&(e._clientFuncMap[_]=r),_}static sendEventToClientNow(e,t,s){if(!(e instanceof R))throw new TypeError("Invalid sequencer instance");e.sendEventToClientNow(t,s)}static sendEventNow(e,t,s){if(!(e instanceof R))throw new TypeError("Invalid sequencer instance");e.sendEventNow(t,s)}static setIntervalForSequencer(e,t){if(!(e instanceof R))throw new TypeError("Invalid sequencer instance");return e.setIntervalForSequencer(t)}}function L(){return B.waitForWasmInitialized()}function W(e,t){const s={port:e,defers:{},deferId:0};return e.addEventListener("message",(e=>function(e,t,s){const n=s.data;if(!n)return;if(t&&t(n))return;const i=e[n.id];if(i)delete e[n.id],n.error?i.reject(G(n.error)):i.resolve(n.val);else if(n.error)throw G(n.error)}(s.defers,t,e))),e.start(),s}function G(e){return new o(e.baseName,e.message,e.detail)}function U({port:e},t,s){e.postMessage({id:-1,method:t,args:s})}function H(e,t,s){const n=e.deferId++;(e.deferId===1/0||e.deferId<0)&&(e.deferId=0);const i=new Promise(((t,s)=>{e.defers[n]={resolve:t,reject:s}})),r=[];return s[0]instanceof MessagePort&&r.push(s[0]),e.port.postMessage({id:n,method:t,args:s},r),i}class x{constructor(e,t){this.name=t,this._messaging=W(e)}getName(){return this.name}getPreset(e,t){return H(this._messaging,"getPreset",[e,t])}getPresetIterable(){return H(this._messaging,"getPresetIterable",[])}}class V{constructor(e){this._messaging=W(e)}getRaw(){return H(this._messaging,"getRaw",[])}registerSequencerClientByName(e,t,s){return this.getRaw().then((n=>H(this._messaging,"registerSequencerClientByName",[n,e,t,s])))}close(){U(this._messaging,"close",[])}registerSynthesizer(e){let t;return e instanceof Y?(t=e._getRawSynthesizer(),t.then((e=>H(this._messaging,"registerSynthesizer",[e])))):Promise.reject(new TypeError("'synth' is not a compatible type instance"))}unregisterClient(e){U(this._messaging,"unregisterClient",[e])}getAllRegisteredClients(){return H(this._messaging,"getAllRegisteredClients",[])}getClientCount(){return H(this._messaging,"getClientCount",[])}getClientInfo(e){return H(this._messaging,"getClientInfo",[e])}setTimeScale(e){U(this._messaging,"setTimeScale",[e])}getTimeScale(){return H(this._messaging,"getTimeScale",[])}getTick(){return H(this._messaging,"getTick",[])}sendEventAt(e,t,s){U(this._messaging,"sendEventAt",[e,t,s])}sendEventToClientAt(e,t,s,n){U(this._messaging,"sendEventToClientAt",[e,t,s,n])}removeAllEvents(){U(this._messaging,"removeAllEvents",[])}removeAllEventsFromClient(e){U(this._messaging,"removeAllEventsFromClient",[e])}processSequencer(e){U(this._messaging,"processSequencer",[e])}}let K=null;const $=[],J={Panic:0,Error:1,Warning:2,Info:3,Debug:4};function Q(e=J.Panic){if(K!==e){if(function(){if("undefined"!=typeof AudioWorkletGlobalScope)F=AudioWorkletGlobalScope.wasmModule;else{if("undefined"==typeof Module)throw new Error("wasm module is not available. libfluidsynth-*.js must be loaded.");F=Module}}(),null==e)null!=T&&(F._fluid_set_log_function(0,T,0),F._fluid_set_log_function(1,T,0),F._fluid_set_log_function(2,T,0),F._fluid_set_log_function(3,T,0)),F._fluid_set_log_function(4,0,0);else{let t;for(let s=e;s<5;++s){const e=F._fluid_set_log_function(s,0,0);s!==J.Debug&&(t=e)}null!=t&&null==T&&(T=t)}K=e;for(const t of $)t(e)}}function X(){Q(null)}class Y{constructor(){var e;this._status={playing:!1,playerPlaying:!1},this._messaging=null,this._node=null,this._gain=.5,this.handleLoggingChanged=this._handleLoggingChanged.bind(this),e=this.handleLoggingChanged,$.push(e)}get node(){return this._node}createAudioNode(e,t){const s=new AudioWorkletNode(e,"fluid-js",{numberOfInputs:0,numberOfOutputs:1,channelCount:2,outputChannelCount:[2],processorOptions:{settings:t,disabledLoggingLevel:K}});return this._node=s,this._messaging=W(s.port,(e=>"updateStatus"===e.method&&(this._status=e.val,!0))),s}isInitialized(){return null!==this._messaging}init(e,t){}close(){U(this._messaging,"init",[0])}isPlaying(){return this._status.playing}setInterpolation(e,t){U(this._messaging,"setInterpolation",[e,t])}getGain(){return this._gain}setGain(e){this._gain=e,H(this._messaging,"setGain",[e]).then((()=>H(this._messaging,"getGain",[]))).then((e=>{this._gain=e}))}setChannelType(e,t){U(this._messaging,"setChannelType",[e,t])}waitForVoicesStopped(){return H(this._messaging,"waitForVoicesStopped",[])}loadSFont(e){return H(this._messaging,"loadSFont",[e])}unloadSFont(e){U(this._messaging,"unloadSFont",[e])}unloadSFontAsync(e){return H(this._messaging,"unloadSFont",[e])}getSFontObject(e){const t=new MessageChannel;return H(this._messaging,"getSFontObject",[t.port2,e]).then((e=>new x(t.port1,e)))}getSFontBankOffset(e){return H(this._messaging,"getSFontBankOffset",[e])}setSFontBankOffset(e,t){U(this._messaging,"setSFontBankOffset",[e,t])}render(){throw new Error("Unexpected call")}midiNoteOn(e,t,s){U(this._messaging,"midiNoteOn",[e,t,s])}midiNoteOff(e,t){U(this._messaging,"midiNoteOff",[e,t])}midiKeyPressure(e,t,s){U(this._messaging,"midiKeyPressure",[e,t,s])}midiControl(e,t,s){U(this._messaging,"midiControl",[e,t,s])}midiProgramChange(e,t){U(this._messaging,"midiProgramChange",[e,t])}midiChannelPressure(e,t){U(this._messaging,"midiChannelPressure",[e,t])}midiPitchBend(e,t){U(this._messaging,"midiPitchBend",[e,t])}midiSysEx(e){U(this._messaging,"midiSysEx",[e])}midiPitchWheelSensitivity(e,t){U(this._messaging,"midiPitchWheelSensitivity",[e,t])}midiBankSelect(e,t){U(this._messaging,"midiBankSelect",[e,t])}midiSFontSelect(e,t){U(this._messaging,"midiSFontSelect",[e,t])}midiProgramSelect(e,t,s,n){U(this._messaging,"midiProgramSelect",[e,t,s,n])}midiUnsetProgram(e){U(this._messaging,"midiUnsetProgram",[e])}midiProgramReset(){U(this._messaging,"midiProgramReset",[])}midiSystemReset(){U(this._messaging,"midiSystemReset",[])}midiAllNotesOff(e){U(this._messaging,"midiAllNotesOff",[e])}midiAllSoundsOff(e){U(this._messaging,"midiAllSoundsOff",[e])}midiSetChannelType(e,t){U(this._messaging,"midiSetChannelType",[e,t])}resetPlayer(){return H(this._messaging,"resetPlayer",[])}closePlayer(){U(this._messaging,"closePlayer",[])}isPlayerPlaying(){return this._status.playerPlaying}addSMFDataToPlayer(e){return H(this._messaging,"addSMFDataToPlayer",[e])}playPlayer(){return H(this._messaging,"playPlayer",[])}stopPlayer(){U(this._messaging,"stopPlayer",[])}retrievePlayerCurrentTick(){return H(this._messaging,"retrievePlayerCurrentTick",[])}retrievePlayerTotalTicks(){return H(this._messaging,"retrievePlayerTotalTicks",[])}retrievePlayerBpm(){return H(this._messaging,"retrievePlayerBpm",[])}retrievePlayerMIDITempo(){return H(this._messaging,"retrievePlayerMIDITempo",[])}seekPlayer(e){U(this._messaging,"seekPlayer",[e])}waitForPlayerStopped(){return H(this._messaging,"waitForPlayerStopped",[])}createSequencer(){const e=new MessageChannel;return H(this._messaging,"createSequencer",[e.port2]).then((()=>new V(e.port1)))}hookPlayerMIDIEventsByName(e,t){return H(this._messaging,"hookPlayerMIDIEventsByName",[e,t])}registerSequencerClientByName(e,t,s,n){return e instanceof V?e.registerSequencerClientByName(t,s,n):Promise.reject(new TypeError("Invalid sequencer object"))}callFunction(e,t){return H(this._messaging,"callFunction",[e,t])}_getRawSynthesizer(){return H(this._messaging,"getRawSynthesizer",[])}_handleLoggingChanged(e){null!=this._messaging&&U(this._messaging,"loggingChanged",[e])}}return t})())); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["js-synthesizer"]=t():e.JSSynth=t()}(this,(()=>(()=>{"use strict";var e={d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{AudioWorkletNodeSynthesizer:()=>te,Constants:()=>s,LogLevel:()=>Y,MessageError:()=>h,SequencerEventTypes:()=>n,Synthesizer:()=>W,disableLogging:()=>Z,restoreLogging:()=>ee,rewriteEventData:()=>a,waitForReady:()=>G});var s={};e.r(s),e.d(s,{PlayerSetTempoType:()=>i});var n={};e.r(n);const i={Internal:0,ExternalBpm:1,ExternalMidi:2},r=0;class _{constructor(e,t){this._ptr=e,this._module=t}getRaw(){return this._ptr}dispose(){this._ptr=r}getType(){return this._ptr===r?-1:this._module._fluid_event_get_type(this._ptr)}getSource(){return this._ptr===r?-1:this._module._fluid_event_get_source(this._ptr)}getDest(){return this._ptr===r?-1:this._module._fluid_event_get_dest(this._ptr)}getChannel(){return this._ptr===r?-1:this._module._fluid_event_get_channel(this._ptr)}getKey(){return this._ptr===r?-1:this._module._fluid_event_get_key(this._ptr)}getVelocity(){return this._ptr===r?-1:this._module._fluid_event_get_velocity(this._ptr)}getControl(){return this._ptr===r?-1:this._module._fluid_event_get_control(this._ptr)}getValue(){return this._ptr===r?-1:this._module._fluid_event_get_value(this._ptr)}getProgram(){return this._ptr===r?-1:this._module._fluid_event_get_program(this._ptr)}getData(){return this._ptr===r?-1:this._module._fluid_event_get_data(this._ptr)}getDuration(){return this._ptr===r?-1:this._module._fluid_event_get_duration(this._ptr)}getBank(){return this._ptr===r?-1:this._module._fluid_event_get_bank(this._ptr)}getPitch(){return this._ptr===r?-1:this._module._fluid_event_get_pitch(this._ptr)}getSFontId(){return this._ptr===r?-1:this._module._fluid_event_get_sfont_id(this._ptr)}}const l="undefined"!=typeof AudioWorkletGlobalScope?AudioWorkletGlobalScope.wasmModule:Module;function o(e,t){switch(t.type){case 0:case"note":l._fluid_event_note(e,t.channel,t.key,t.vel,t.duration);break;case 1:case"noteon":case"note-on":l._fluid_event_noteon(e,t.channel,t.key,t.vel);break;case 2:case"noteoff":case"note-off":l._fluid_event_noteoff(e,t.channel,t.key);break;case 3:case"allsoundsoff":case"all-sounds-off":l._fluid_event_all_sounds_off(e,t.channel);break;case 4:case"allnotesoff":case"all-notes-off":l._fluid_event_all_notes_off(e,t.channel);break;case 5:case"bankselect":case"bank-select":l._fluid_event_bank_select(e,t.channel,t.bank);break;case 6:case"programchange":case"program-change":l._fluid_event_program_change(e,t.channel,t.preset);break;case 7:case"programselect":case"program-select":l._fluid_event_program_select(e,t.channel,t.sfontId,t.bank,t.preset);break;case 12:case"controlchange":case"control-change":l._fluid_event_control_change(e,t.channel,t.control,t.value);break;case 8:case"pitchbend":case"pitch-bend":l._fluid_event_pitch_bend(e,t.channel,t.value);break;case 9:case"pitchwheelsens":case"pitchwheelsensitivity":case"pitch-wheel-sens":case"pitch-wheel-sensitivity":l._fluid_event_pitch_wheelsens(e,t.channel,t.value);break;case 10:case"modulation":l._fluid_event_modulation(e,t.channel,t.value);break;case 11:case"sustain":l._fluid_event_sustain(e,t.channel,t.value);break;case 13:case"pan":l._fluid_event_pan(e,t.channel,t.value);break;case 14:case"volume":l._fluid_event_volume(e,t.channel,t.value);break;case 15:case"reverb":case"reverbsend":case"reverb-send":l._fluid_event_reverb_send(e,t.channel,t.value);break;case 16:case"chorus":case"chorussend":case"chorus-send":l._fluid_event_chorus_send(e,t.channel,t.value);break;case 20:case"keypressure":case"key-pressure":case"aftertouch":l._fluid_event_key_pressure(e,t.channel,t.key,t.value);break;case 19:case"channelpressure":case"channel-pressure":case"channel-aftertouch":l._fluid_event_channel_pressure(e,t.channel,t.value);break;case 21:case"systemreset":case"system-reset":l._fluid_event_system_reset(e);break;case 17:case"timer":l._fluid_event_timer(e,t.data);break;default:return!1}return!0}function a(e,t){if(!(e&&e instanceof _))return!1;const s=e.getRaw();return s!==r&&o(s,t)}class h extends Error{constructor(e,t,s){super(t),this.baseName=e,this.detail=s,s&&s.stack&&(this.stack=s.stack)}}class u{constructor(e,t){this._ptr=e,this._module=t}getType(){return this._module._fluid_midi_event_get_type(this._ptr)}setType(e){this._module._fluid_midi_event_set_type(this._ptr,e)}getChannel(){return this._module._fluid_midi_event_get_channel(this._ptr)}setChannel(e){this._module._fluid_midi_event_set_channel(this._ptr,e)}getKey(){return this._module._fluid_midi_event_get_key(this._ptr)}setKey(e){this._module._fluid_midi_event_set_key(this._ptr,e)}getVelocity(){return this._module._fluid_midi_event_get_velocity(this._ptr)}setVelocity(e){this._module._fluid_midi_event_set_velocity(this._ptr,e)}getControl(){return this._module._fluid_midi_event_get_control(this._ptr)}setControl(e){this._module._fluid_midi_event_set_control(this._ptr,e)}getValue(){return this._module._fluid_midi_event_get_value(this._ptr)}setValue(e){this._module._fluid_midi_event_set_value(this._ptr,e)}getProgram(){return this._module._fluid_midi_event_get_program(this._ptr)}setProgram(e){this._module._fluid_midi_event_set_program(this._ptr,e)}getPitch(){return this._module._fluid_midi_event_get_pitch(this._ptr)}setPitch(e){this._module._fluid_midi_event_set_pitch(this._ptr,e)}setSysEx(e){const t=e.byteLength,s=this._module._malloc(t);new Uint8Array(this._module.HEAPU8.buffer,s,t).set(e),this._module._fluid_midi_event_set_sysex(this._ptr,s,t,1)}setText(e){const t=e.byteLength,s=this._module._malloc(t);new Uint8Array(this._module.HEAPU8.buffer,s,t).set(e),this._module._fluid_midi_event_set_text(this._ptr,s,t,1)}setLyrics(e){const t=e.byteLength,s=this._module._malloc(t);new Uint8Array(this._module.HEAPU8.buffer,s,t).set(e),this._module._fluid_midi_event_set_lyrics(this._ptr,s,t,1)}}let d,c,f,y,g,m,p,v,b,P,w,S,k,C,q,I,A,E,T,F,z,R;function M(e){const t=d._new_fluid_event();return o(t,e)?t:(d._delete_fluid_event(t),null)}class O{constructor(){d||("undefined"!=typeof AudioWorkletGlobalScope?(d=AudioWorkletGlobalScope.wasmModule,c=AudioWorkletGlobalScope.wasmRemoveFunction):(d=Module,c=removeFunction),f=d.cwrap("fluid_sequencer_get_client_name","string",["number","number"])),this._seq=r,this._seqId=-1,this._clientFuncMap={}}_initialize(){return this.close(),this._seq=d._new_fluid_sequencer2(0),this._seqId=-1,Promise.resolve()}getRaw(){return this._seq}close(){this._seq!==r&&(Object.keys(this._clientFuncMap).forEach((e=>{this.unregisterClient(Number(e))})),this.unregisterClient(-1),d._delete_fluid_sequencer(this._seq),this._seq=r)}registerSynthesizer(e){let t;if(-1!==this._seqId&&(d._fluid_sequencer_unregister_client(this._seq,this._seqId),this._seqId=-1),"number"==typeof e)t=e;else{if(!(e instanceof W))return Promise.reject(new TypeError("'synth' is not a compatible type instance"));t=e.getRawSynthesizer()}return this._seqId=d._fluid_sequencer_register_fluidsynth(this._seq,t),Promise.resolve(this._seqId)}unregisterClient(e){if(-1===e&&-1===(e=this._seqId))return;const t=d._new_fluid_event();if(d._fluid_event_set_source(t,-1),d._fluid_event_set_dest(t,e),d._fluid_event_unregistering(t),d._fluid_sequencer_send_now(this._seq,t),d._delete_fluid_event(t),d._fluid_sequencer_unregister_client(this._seq,e),this._seqId===e)this._seqId=-1;else{const t=this._clientFuncMap;t[e]&&(c(t[e]),delete t[e])}}getAllRegisteredClients(){const e=d._fluid_sequencer_count_clients(this._seq),t=[];for(let s=0;s<e;++s){const e=d._fluid_sequencer_get_client_id(this._seq,s),n=f(this._seq,e);t.push({clientId:e,name:n})}return Promise.resolve(t)}getClientCount(){return Promise.resolve(d._fluid_sequencer_count_clients(this._seq))}getClientInfo(e){const t=d._fluid_sequencer_get_client_id(this._seq,e),s=f(this._seq,t);return Promise.resolve({clientId:t,name:s})}setTimeScale(e){d._fluid_sequencer_set_time_scale(this._seq,e)}getTimeScale(){return Promise.resolve(d._fluid_sequencer_get_time_scale(this._seq))}getTick(){return Promise.resolve(d._fluid_sequencer_get_tick(this._seq))}sendEventAt(e,t,s){const n=M(e);if(null!==n){const e=d._fluid_sequencer_count_clients(this._seq);for(let i=0;i<e;++i){const e=d._fluid_sequencer_get_client_id(this._seq,i);d._fluid_event_set_dest(n,e),d._fluid_sequencer_send_at(this._seq,n,t,s?1:0)}d._delete_fluid_event(n)}}sendEventToClientAt(e,t,s,n){const i=M(t);null!==i&&(d._fluid_event_set_dest(i,-1===e?this._seqId:e),d._fluid_sequencer_send_at(this._seq,i,s,n?1:0),d._delete_fluid_event(i))}sendEventToClientNow(e,t){const s=M(t);null!==s&&(d._fluid_event_set_dest(s,-1===e?this._seqId:e),d._fluid_sequencer_send_now(this._seq,s),d._delete_fluid_event(s))}sendEventNow(e,t){if(!(t instanceof _))return;const s=t.getRaw();s!==r&&(d._fluid_event_set_dest(s,-1===e?this._seqId:e),d._fluid_sequencer_send_now(this._seq,s))}removeAllEvents(){d._fluid_sequencer_remove_events(this._seq,-1,-1,-1)}removeAllEventsFromClient(e){d._fluid_sequencer_remove_events(this._seq,-1,-1===e?this._seqId:e,-1)}processSequencer(e){this._seq!==r&&d._fluid_sequencer_process(this._seq,e)}setIntervalForSequencer(e){return setInterval((()=>this.processSequencer(e)),e)}}class N{constructor(e){this._ptr=e}static getSoundfontById(e,t){y||(y="undefined"!=typeof AudioWorkletGlobalScope?AudioWorkletGlobalScope.wasmModule:Module,g=y.cwrap("fluid_sfont_get_name","string",["number"]),m=y.cwrap("fluid_preset_get_name","string",["number"]));const s=y._fluid_synth_get_sfont_by_id(e.getRawSynthesizer(),t);return s===r?null:new N(s)}getName(){return g(this._ptr)}getPreset(e,t){const s=y._fluid_sfont_get_preset(this._ptr,e,t);if(s===r)return null;return{soundfont:this,name:m(s),bankNum:y._fluid_preset_get_banknum(s),num:y._fluid_preset_get_num(s)}}getPresetIterable(){const e=()=>{y._fluid_sfont_iteration_start(this._ptr)},t=()=>{const e=y._fluid_sfont_iteration_next(this._ptr);if(0===e)return{done:!0,value:void 0};return{done:!1,value:{soundfont:this,name:m(e),bankNum:y._fluid_preset_get_banknum(e),num:y._fluid_preset_get_num(e)}}};return{[Symbol.iterator]:()=>(e(),{next:t})}}}function j(){if(!C){if("undefined"!=typeof AudioWorkletGlobalScope)p=AudioWorkletGlobalScope.wasmModule,v=AudioWorkletGlobalScope.wasmAddFunction,b=AudioWorkletGlobalScope.wasmRemoveFunction;else{if("undefined"==typeof Module)throw new Error("wasm module is not available. libfluidsynth-*.js must be loaded.");p=Module,v=addFunction,b=removeFunction}P=p.FS,w=p.cwrap("fluid_settings_setint","number",["number","string","number"]),S=p.cwrap("fluid_settings_setnum","number",["number","string","number"]),k=p.cwrap("fluid_settings_setstr","number",["number","string","string"]),C=p.cwrap("fluid_synth_error","string",["number"]),q=p.cwrap("fluid_synth_sfload","number",["number","string","number"]),I=p.cwrap("fluid_sequencer_register_client","number",["number","string","number","number"]),A=p._malloc.bind(p),E=p._free.bind(p),T=p._fluid_synth_handle_midi_event.bind(p)}}function L(e,t,s){void 0!==s&&w(e,t,s?1:0)}function B(e,t,s){void 0!==s&&w(e,t,s)}function D(e,t,s){void 0!==s&&S(e,t,s)}class W{constructor(){j(),this._settings=r,this._synth=r,this._player=r,this._playerPlaying=!1,this._playerCallbackPtr=null,this._fluidSynthCallback=null,this._buffer=r,this._bufferSize=0,this._numPtr=r,this._gain=.5}static waitForWasmInitialized(){return function(){if(F)return F;let e,t;if("undefined"!=typeof AudioWorkletGlobalScope)e=AudioWorkletGlobalScope.wasmModule,t=AudioWorkletGlobalScope.addOnPostRun;else{if("undefined"==typeof Module)return Promise.reject(new Error("wasm module is not available. libfluidsynth-*.js must be loaded."));e=Module,t="undefined"!=typeof addOnPostRun?addOnPostRun:void 0}return e.calledRun?(F=Promise.resolve(),F):(F=new Promise(void 0===t?e=>{const t=p.onRuntimeInitialized;p.onRuntimeInitialized=()=>{e(),t&&t()}}:e=>{t(e)}),F)}()}isInitialized(){return this._synth!==r}getRawSynthesizer(){return this._synth}createAudioNode(e,t){const s=e.createScriptProcessor(t,0,2);return s.addEventListener("audioprocess",(e=>{this.render(e.outputBuffer)})),s}init(e,t){this.close();const s=this._settings=p._new_fluid_settings();S(s,"synth.sample-rate",e),t&&(void 0!==t.initialGain&&(this._gain=t.initialGain),L(s,"synth.chorus.active",t.chorusActive),D(s,"synth.chorus.depth",t.chorusDepth),D(s,"synth.chorus.level",t.chorusLevel),B(s,"synth.chorus.nr",t.chorusNr),D(s,"synth.chorus.speed",t.chorusSpeed),B(s,"synth.midi-channels",t.midiChannelCount),function(e,t,s){void 0!==s&&k(e,t,s)}(s,"synth.midi-bank-select",t.midiBankSelect),B(s,"synth.min-note-length",t.minNoteLength),D(s,"synth.overflow.age",t.overflowAge),D(s,"synth.overflow.important",t.overflowImportantValue),void 0!==t.overflowImportantChannels&&k(s,"synth.overflow.important-channels",t.overflowImportantChannels.join(",")),D(s,"synth.overflow.percussion",t.overflowPercussion),D(s,"synth.overflow.released",t.overflowReleased),D(s,"synth.overflow.sustained",t.overflowSustained),D(s,"synth.overflow.volume",t.overflowVolume),B(s,"synth.polyphony",t.polyphony),L(s,"synth.reverb.active",t.reverbActive),D(s,"synth.reverb.damp",t.reverbDamp),D(s,"synth.reverb.level",t.reverbLevel),D(s,"synth.reverb.room-size",t.reverbRoomSize),D(s,"synth.reverb.width",t.reverbWidth)),S(s,"synth.gain",this._gain),this._synth=p._new_fluid_synth(this._settings),this._numPtr=A(8)}close(){this._synth!==r&&(this._closePlayer(),p._delete_fluid_synth(this._synth),this._synth=r,p._delete_fluid_settings(this._settings),this._settings=r,E(this._numPtr),this._numPtr=r)}isPlaying(){return this._synth!==r&&function(e){const t=p._fluid_synth_get_active_voice_count(e);if(!t)return 0;let s=140,n=e+s+4>>2,i=p.HEAPU32[n];if(i!==t&&(s+=4,n=e+s+4>>2,i=p.HEAPU32[n],i!==t))return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t;const r=p.HEAPU32[e+s>>2];if(!r||r>=p.HEAPU32.byteLength)return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t;const _=p._fluid_synth_get_polyphony(e);let l=!1;for(let e=0;e<_;++e){const t=p.HEAPU32[(r>>2)+e];if(t&&4!==p.HEAPU8[t+4]){l=!0;break}}if(!l)return 0!==i&&console.warn("js-synthesizer: Active voice count is not zero, but all voices are off:",i),p.HEAPU32[n]=0,0;return t}(this._synth)>0}setInterpolation(e,t){this.ensureInitialized(),void 0===t&&(t=-1),p._fluid_synth_set_interp_method(this._synth,t,e)}getGain(){return this._gain}setGain(e){this.ensureInitialized(),p._fluid_synth_set_gain(this._synth,e),this._gain=p._fluid_synth_get_gain(this._synth)}setChannelType(e,t){this.ensureInitialized(),p._fluid_synth_set_channel_type(this._synth,e,t?1:0)}waitForVoicesStopped(){return this.flushFramesAsync()}loadSFont(e){this.ensureInitialized();const t=(s=".sf2",`/${"sfont"}-r${65535*Math.random()}-${65535*Math.random()}${s}`);var s;const n=new Uint8Array(e);P.writeFile(t,n);const i=q(this._synth,t,1);return P.unlink(t),-1===i?Promise.reject(new Error(C(this._synth))):Promise.resolve(i)}unloadSFont(e){this.ensureInitialized(),this.stopPlayer(),this.flushFramesSync(),p._fluid_synth_sfunload(this._synth,e,1)}unloadSFontAsync(e){return this.ensureInitialized(),this.stopPlayer(),this.flushFramesAsync().then((()=>{p._fluid_synth_sfunload(this._synth,e,1)}))}getSFontObject(e){return N.getSoundfontById(this,e)}getSFontBankOffset(e){return this.ensureInitialized(),Promise.resolve(p._fluid_synth_get_bank_offset(this._synth,e))}setSFontBankOffset(e,t){this.ensureInitialized(),p._fluid_synth_set_bank_offset(this._synth,e,t)}render(e){const t="numberOfChannels"in e?e.length:e[0].length,s="numberOfChannels"in e?e.numberOfChannels:e.length,n=4*t,i=2*n;this._bufferSize<i&&(this._buffer!==r&&E(this._buffer),this._buffer=A(i),this._bufferSize=i);const _=this._buffer,l=this._buffer+n;this.renderRaw(_,l,t);const o=new Float32Array(p.HEAPU8.buffer,_,t),a=s>=2?new Float32Array(p.HEAPU8.buffer,l,t):null;if("numberOfChannels"in e)if(e.copyToChannel)e.copyToChannel(o,0,0),a&&e.copyToChannel(a,1,0);else{const t=e.getChannelData(0);if(o.forEach(((e,s)=>t[s]=e)),a){const t=e.getChannelData(1);a.forEach(((e,s)=>t[s]=e))}}else e[0].set(o),a&&e[1].set(a);this.isPlayerPlaying()}midiNoteOn(e,t,s){p._fluid_synth_noteon(this._synth,e,t,s)}midiNoteOff(e,t){p._fluid_synth_noteoff(this._synth,e,t)}midiKeyPressure(e,t,s){p._fluid_synth_key_pressure(this._synth,e,t,s)}midiControl(e,t,s){p._fluid_synth_cc(this._synth,e,t,s)}midiProgramChange(e,t){p._fluid_synth_program_change(this._synth,e,t)}midiChannelPressure(e,t){p._fluid_synth_channel_pressure(this._synth,e,t)}midiPitchBend(e,t){p._fluid_synth_pitch_bend(this._synth,e,t)}midiSysEx(e){const t=e.byteLength,s=A(t);p.HEAPU8.set(e,s),p._fluid_synth_sysex(this._synth,s,t,r,r,r,0),E(s)}midiPitchWheelSensitivity(e,t){p._fluid_synth_pitch_wheel_sens(this._synth,e,t)}midiBankSelect(e,t){p._fluid_synth_bank_select(this._synth,e,t)}midiSFontSelect(e,t){p._fluid_synth_sfont_select(this._synth,e,t)}midiProgramSelect(e,t,s,n){p._fluid_synth_program_select(this._synth,e,t,s,n)}midiUnsetProgram(e){p._fluid_synth_unset_program(this._synth,e)}midiProgramReset(){p._fluid_synth_program_reset(this._synth)}midiSystemReset(){p._fluid_synth_system_reset(this._synth)}midiAllNotesOff(e){p._fluid_synth_all_notes_off(this._synth,void 0===e?-1:e)}midiAllSoundsOff(e){p._fluid_synth_all_sounds_off(this._synth,void 0===e?-1:e)}midiSetChannelType(e,t){p._fluid_synth_set_channel_type(this._synth,e,t?1:0)}setReverb(e,t,s,n){p._fluid_synth_set_reverb(this._synth,e,t,s,n)}setReverbRoomsize(e){p._fluid_synth_set_reverb_roomsize(this._synth,e)}setReverbDamp(e){p._fluid_synth_set_reverb_damp(this._synth,e)}setReverbWidth(e){p._fluid_synth_set_reverb_width(this._synth,e)}setReverbLevel(e){p._fluid_synth_set_reverb_level(this._synth,e)}setReverbOn(e){p._fluid_synth_set_reverb_on(this._synth,e?1:0)}getReverbRoomsize(){return p._fluid_synth_get_reverb_roomsize(this._synth)}getReverbDamp(){return p._fluid_synth_get_reverb_damp(this._synth)}getReverbLevel(){return p._fluid_synth_get_reverb_level(this._synth)}getReverbWidth(){return p._fluid_synth_get_reverb_width(this._synth)}setChorus(e,t,s,n,i){p._fluid_synth_set_chorus(this._synth,e,t,s,n,i)}setChorusVoiceCount(e){p._fluid_synth_set_chorus_nr(this._synth,e)}setChorusLevel(e){p._fluid_synth_set_chorus_level(this._synth,e)}setChorusSpeed(e){p._fluid_synth_set_chorus_speed(this._synth,e)}setChorusDepth(e){p._fluid_synth_set_chorus_depth(this._synth,e)}setChorusType(e){p._fluid_synth_set_chorus_type(this._synth,e)}setChorusOn(e){p._fluid_synth_set_chorus_on(this._synth,e?1:0)}getChorusVoiceCount(){return p._fluid_synth_get_chorus_nr(this._synth)}getChorusLevel(){return p._fluid_synth_get_chorus_level(this._synth)}getChorusSpeed(){return p._fluid_synth_get_chorus_speed(this._synth)}getChorusDepth(){return p._fluid_synth_get_chorus_depth(this._synth)}getChorusType(){return p._fluid_synth_get_chorus_type(this._synth)}getGenerator(e,t){return p._fluid_synth_get_gen(this._synth,e,t)}setGenerator(e,t,s){p._fluid_synth_set_gen(this._synth,e,t,s)}getLegatoMode(e){return p._fluid_synth_get_legato_mode(this._synth,e,this._numPtr),p.HEAP32[this._numPtr>>2]}setLegatoMode(e,t){p._fluid_synth_set_legato_mode(this._synth,e,t)}getPortamentoMode(e){return p._fluid_synth_get_portamento_mode(this._synth,e,this._numPtr),p.HEAP32[this._numPtr>>2]}setPortamentoMode(e,t){p._fluid_synth_set_portamento_mode(this._synth,e,t)}getBreathMode(e){return p._fluid_synth_get_breath_mode(this._synth,e,this._numPtr),p.HEAP32[this._numPtr>>2]}setBreathMode(e,t){p._fluid_synth_set_breath_mode(this._synth,e,t)}resetPlayer(){return new Promise((e=>{this._initPlayer(),e()}))}closePlayer(){this._closePlayer()}_initPlayer(){this._closePlayer();const e=p._new_fluid_player(this._synth);if(this._player=e,e===r)throw new Error("Out of memory");if(null===this._fluidSynthCallback){const t=p.HEAPU32[e+588>>2];p.HEAPU32[e+592>>2]===this._synth&&(this._fluidSynthCallback=t)}}_closePlayer(){const e=this._player;e!==r&&(this.stopPlayer(),p._delete_fluid_player(e),this._player=r,this._playerCallbackPtr=null)}isPlayerPlaying(){if(this._playerPlaying){if(1===p._fluid_player_get_status(this._player))return!0;this.stopPlayer()}return!1}addSMFDataToPlayer(e){this.ensurePlayerInitialized();const t=e.byteLength,s=A(t);p.HEAPU8.set(new Uint8Array(e),s);const n=p._fluid_player_add_mem(this._player,s,t);return E(s),-1!==n?Promise.resolve():Promise.reject(new Error(C(this._synth)))}playPlayer(){if(this.ensurePlayerInitialized(),this._playerPlaying&&this.stopPlayer(),-1===p._fluid_player_play(this._player))return Promise.reject(new Error(C(this._synth)));this._playerPlaying=!0;let e=()=>{};const t=new Promise((t=>{e=t}));return this._playerDefer={promise:t,resolve:e},Promise.resolve()}stopPlayer(){const e=this._player;e!==r&&this._playerPlaying&&(p._fluid_player_stop(e),p._fluid_player_join(e),p._fluid_synth_all_sounds_off(this._synth,-1),this._playerDefer&&(this._playerDefer.resolve(),this._playerDefer=void 0),this._playerPlaying=!1)}retrievePlayerCurrentTick(){return this.ensurePlayerInitialized(),Promise.resolve(p._fluid_player_get_current_tick(this._player))}retrievePlayerTotalTicks(){return this.ensurePlayerInitialized(),Promise.resolve(p._fluid_player_get_total_ticks(this._player))}retrievePlayerBpm(){return this.ensurePlayerInitialized(),Promise.resolve(p._fluid_player_get_bpm(this._player))}retrievePlayerMIDITempo(){return this.ensurePlayerInitialized(),Promise.resolve(p._fluid_player_get_midi_tempo(this._player))}seekPlayer(e){this.ensurePlayerInitialized(),p._fluid_player_seek(this._player,e)}setPlayerLoop(e){this.ensurePlayerInitialized(),p._fluid_player_set_loop(this._player,e)}setPlayerTempo(e,t){this.ensurePlayerInitialized(),p._fluid_player_set_tempo(this._player,e,t)}hookPlayerMIDIEvents(e,t){this.ensurePlayerInitialized();const s=this._playerCallbackPtr;if(null===s&&null===e)return;const n=null!==e?v(function(e,t,s){return(n,i)=>{const r=p._fluid_midi_event_get_type(i);return t(e,r,new u(i,p),s)?0:p._fluid_synth_handle_midi_event(n,i)}}(this,e,t),"iii"):null!==this._fluidSynthCallback?null:v(T,"iii");null!==s&&null!==n?(p._fluid_player_set_playback_callback(this._player,n,this._synth),b(s)):null===n?(p._fluid_player_set_playback_callback(this._player,this._fluidSynthCallback,this._synth),b(s)):p._fluid_player_set_playback_callback(this._player,n,this._synth),this._playerCallbackPtr=n}ensureInitialized(){if(this._synth===r)throw new Error("Synthesizer is not initialized")}ensurePlayerInitialized(){this.ensureInitialized(),this._player===r&&this._initPlayer()}renderRaw(e,t,s){p._fluid_synth_write_float(this._synth,s,e,0,1,t,0,1)}flushFramesSync(){const e=262144,t=A(524288),s=t,n=t+e;for(;this.isPlaying();)this.renderRaw(s,n,65536);E(t)}flushFramesAsync(){if(!this.isPlaying())return Promise.resolve();const e=262144,t=A(524288),s=t,n=t+e,i="undefined"!=typeof setTimeout?()=>new Promise((e=>setTimeout(e,0))):()=>Promise.resolve();function r(){return i().then(l)}const _=this;function l(){return _.isPlaying()?(_.renderRaw(s,n,65536),r()):(E(t),Promise.resolve())}return r()}waitForPlayerStopped(){return this._playerDefer?this._playerDefer.promise:Promise.resolve()}static createSequencer(){j();const e=new O;return e._initialize().then((()=>e))}static registerSequencerClient(e,t,s,n){if(!(e instanceof O))throw new TypeError("Invalid sequencer instance");const i=v(((t,n,i,r)=>{const l=new _(n,p),o=p._fluid_event_get_type(n);s(t,o,l,e,r)}),"viiii"),r=I(e.getRaw(),t,i,n);return-1!==r&&(e._clientFuncMap[r]=i),r}static sendEventToClientNow(e,t,s){if(!(e instanceof O))throw new TypeError("Invalid sequencer instance");e.sendEventToClientNow(t,s)}static sendEventNow(e,t,s){if(!(e instanceof O))throw new TypeError("Invalid sequencer instance");e.sendEventNow(t,s)}static setIntervalForSequencer(e,t){if(!(e instanceof O))throw new TypeError("Invalid sequencer instance");return e.setIntervalForSequencer(t)}}function G(){return W.waitForWasmInitialized()}function U(e,t){const s={port:e,defers:{},deferId:0};return e.addEventListener("message",(e=>function(e,t,s){const n=s.data;if(!n)return;if(t&&t(n))return;const i=e[n.id];if(i)delete e[n.id],n.error?i.reject(H(n.error)):i.resolve(n.val);else if(n.error)throw H(n.error)}(s.defers,t,e))),e.start(),s}function H(e){return new h(e.baseName,e.message,e.detail)}function x({port:e},t,s){e.postMessage({id:-1,method:t,args:s})}function V(e,t,s){const n=e.deferId++;(e.deferId===1/0||e.deferId<0)&&(e.deferId=0);const i=new Promise(((t,s)=>{e.defers[n]={resolve:t,reject:s}})),r=[];return s[0]instanceof MessagePort&&r.push(s[0]),e.port.postMessage({id:n,method:t,args:s},r),i}class K{constructor(e,t){this.name=t,this._messaging=U(e)}getName(){return this.name}getPreset(e,t){return V(this._messaging,"getPreset",[e,t])}getPresetIterable(){return V(this._messaging,"getPresetIterable",[])}}class ${constructor(e){this._messaging=U(e)}getRaw(){return V(this._messaging,"getRaw",[])}registerSequencerClientByName(e,t,s){return this.getRaw().then((n=>V(this._messaging,"registerSequencerClientByName",[n,e,t,s])))}close(){x(this._messaging,"close",[])}registerSynthesizer(e){let t;return e instanceof te?(t=e._getRawSynthesizer(),t.then((e=>V(this._messaging,"registerSynthesizer",[e])))):Promise.reject(new TypeError("'synth' is not a compatible type instance"))}unregisterClient(e){x(this._messaging,"unregisterClient",[e])}getAllRegisteredClients(){return V(this._messaging,"getAllRegisteredClients",[])}getClientCount(){return V(this._messaging,"getClientCount",[])}getClientInfo(e){return V(this._messaging,"getClientInfo",[e])}setTimeScale(e){x(this._messaging,"setTimeScale",[e])}getTimeScale(){return V(this._messaging,"getTimeScale",[])}getTick(){return V(this._messaging,"getTick",[])}sendEventAt(e,t,s){x(this._messaging,"sendEventAt",[e,t,s])}sendEventToClientAt(e,t,s,n){x(this._messaging,"sendEventToClientAt",[e,t,s,n])}removeAllEvents(){x(this._messaging,"removeAllEvents",[])}removeAllEventsFromClient(e){x(this._messaging,"removeAllEventsFromClient",[e])}processSequencer(e){x(this._messaging,"processSequencer",[e])}}let J=null;const Q=[],X=5,Y={Panic:0,Error:1,Warning:2,Info:3,Debug:4};function Z(e=Y.Panic){if(J!==e){if(function(){if("undefined"!=typeof AudioWorkletGlobalScope)z=AudioWorkletGlobalScope.wasmModule;else{if("undefined"==typeof Module)throw new Error("wasm module is not available. libfluidsynth-*.js must be loaded.");z=Module}}(),null==e)null!=R&&(z._fluid_set_log_function(0,R,0),z._fluid_set_log_function(1,R,0),z._fluid_set_log_function(2,R,0),z._fluid_set_log_function(3,R,0)),z._fluid_set_log_function(4,0,0);else{let t;for(let s=e;s<X;++s){const e=z._fluid_set_log_function(s,0,0);s!==Y.Debug&&(t=e)}null!=t&&null==R&&(R=t)}J=e;for(const t of Q)t(e)}}function ee(){Z(null)}class te{constructor(){var e;this._status={playing:!1,playerPlaying:!1},this._messaging=null,this._node=null,this._gain=.5,this.handleLoggingChanged=this._handleLoggingChanged.bind(this),e=this.handleLoggingChanged,Q.push(e)}get node(){return this._node}createAudioNode(e,t){const s=new AudioWorkletNode(e,"fluid-js",{numberOfInputs:0,numberOfOutputs:1,channelCount:2,outputChannelCount:[2],processorOptions:{settings:t,disabledLoggingLevel:J}});return this._node=s,this._messaging=U(s.port,(e=>"updateStatus"===e.method&&(this._status=e.val,!0))),s}isInitialized(){return null!==this._messaging}init(e,t){}close(){x(this._messaging,"init",[0])}isPlaying(){return this._status.playing}setInterpolation(e,t){x(this._messaging,"setInterpolation",[e,t])}getGain(){return this._gain}setGain(e){this._gain=e,V(this._messaging,"setGain",[e]).then((()=>V(this._messaging,"getGain",[]))).then((e=>{this._gain=e}))}setChannelType(e,t){x(this._messaging,"setChannelType",[e,t])}waitForVoicesStopped(){return V(this._messaging,"waitForVoicesStopped",[])}loadSFont(e){return V(this._messaging,"loadSFont",[e])}unloadSFont(e){x(this._messaging,"unloadSFont",[e])}unloadSFontAsync(e){return V(this._messaging,"unloadSFont",[e])}getSFontObject(e){const t=new MessageChannel;return V(this._messaging,"getSFontObject",[t.port2,e]).then((e=>new K(t.port1,e)))}getSFontBankOffset(e){return V(this._messaging,"getSFontBankOffset",[e])}setSFontBankOffset(e,t){x(this._messaging,"setSFontBankOffset",[e,t])}render(){throw new Error("Unexpected call")}midiNoteOn(e,t,s){x(this._messaging,"midiNoteOn",[e,t,s])}midiNoteOff(e,t){x(this._messaging,"midiNoteOff",[e,t])}midiKeyPressure(e,t,s){x(this._messaging,"midiKeyPressure",[e,t,s])}midiControl(e,t,s){x(this._messaging,"midiControl",[e,t,s])}midiProgramChange(e,t){x(this._messaging,"midiProgramChange",[e,t])}midiChannelPressure(e,t){x(this._messaging,"midiChannelPressure",[e,t])}midiPitchBend(e,t){x(this._messaging,"midiPitchBend",[e,t])}midiSysEx(e){x(this._messaging,"midiSysEx",[e])}midiPitchWheelSensitivity(e,t){x(this._messaging,"midiPitchWheelSensitivity",[e,t])}midiBankSelect(e,t){x(this._messaging,"midiBankSelect",[e,t])}midiSFontSelect(e,t){x(this._messaging,"midiSFontSelect",[e,t])}midiProgramSelect(e,t,s,n){x(this._messaging,"midiProgramSelect",[e,t,s,n])}midiUnsetProgram(e){x(this._messaging,"midiUnsetProgram",[e])}midiProgramReset(){x(this._messaging,"midiProgramReset",[])}midiSystemReset(){x(this._messaging,"midiSystemReset",[])}midiAllNotesOff(e){x(this._messaging,"midiAllNotesOff",[e])}midiAllSoundsOff(e){x(this._messaging,"midiAllSoundsOff",[e])}midiSetChannelType(e,t){x(this._messaging,"midiSetChannelType",[e,t])}resetPlayer(){return V(this._messaging,"resetPlayer",[])}closePlayer(){x(this._messaging,"closePlayer",[])}isPlayerPlaying(){return this._status.playerPlaying}addSMFDataToPlayer(e){return V(this._messaging,"addSMFDataToPlayer",[e])}playPlayer(){return V(this._messaging,"playPlayer",[])}stopPlayer(){x(this._messaging,"stopPlayer",[])}retrievePlayerCurrentTick(){return V(this._messaging,"retrievePlayerCurrentTick",[])}retrievePlayerTotalTicks(){return V(this._messaging,"retrievePlayerTotalTicks",[])}retrievePlayerBpm(){return V(this._messaging,"retrievePlayerBpm",[])}retrievePlayerMIDITempo(){return V(this._messaging,"retrievePlayerMIDITempo",[])}seekPlayer(e){x(this._messaging,"seekPlayer",[e])}setPlayerLoop(e){x(this._messaging,"setPlayerLoop",[e])}setPlayerTempo(e,t){x(this._messaging,"setPlayerTempo",[e,t])}waitForPlayerStopped(){return V(this._messaging,"waitForPlayerStopped",[])}createSequencer(){const e=new MessageChannel;return V(this._messaging,"createSequencer",[e.port2]).then((()=>new $(e.port1)))}hookPlayerMIDIEventsByName(e,t){return V(this._messaging,"hookPlayerMIDIEventsByName",[e,t])}registerSequencerClientByName(e,t,s,n){return e instanceof $?e.registerSequencerClientByName(t,s,n):Promise.reject(new TypeError("Invalid sequencer object"))}callFunction(e,t){return V(this._messaging,"callFunction",[e,t])}_getRawSynthesizer(){return V(this._messaging,"getRawSynthesizer",[])}_handleLoggingChanged(e){null!=this._messaging&&x(this._messaging,"loggingChanged",[e])}}return t})())); | ||
//# sourceMappingURL=js-synthesizer.min.js.map |
/*! | ||
js-synthesizer version 1.9.0 | ||
js-synthesizer version 1.10.0 | ||
@@ -29,3 +29,3 @@ @license | ||
OF SUCH DAMAGE. | ||
*/(()=>{"use strict";class e{constructor(e,t){this._ptr=e,this._module=t}getType(){return this._module._fluid_midi_event_get_type(this._ptr)}setType(e){this._module._fluid_midi_event_set_type(this._ptr,e)}getChannel(){return this._module._fluid_midi_event_get_channel(this._ptr)}setChannel(e){this._module._fluid_midi_event_set_channel(this._ptr,e)}getKey(){return this._module._fluid_midi_event_get_key(this._ptr)}setKey(e){this._module._fluid_midi_event_set_key(this._ptr,e)}getVelocity(){return this._module._fluid_midi_event_get_velocity(this._ptr)}setVelocity(e){this._module._fluid_midi_event_set_velocity(this._ptr,e)}getControl(){return this._module._fluid_midi_event_get_control(this._ptr)}setControl(e){this._module._fluid_midi_event_set_control(this._ptr,e)}getValue(){return this._module._fluid_midi_event_get_value(this._ptr)}setValue(e){this._module._fluid_midi_event_set_value(this._ptr,e)}getProgram(){return this._module._fluid_midi_event_get_program(this._ptr)}setProgram(e){this._module._fluid_midi_event_set_program(this._ptr,e)}getPitch(){return this._module._fluid_midi_event_get_pitch(this._ptr)}setPitch(e){this._module._fluid_midi_event_set_pitch(this._ptr,e)}setSysEx(e){const t=e.byteLength,s=this._module._malloc(t);new Uint8Array(this._module.HEAPU8.buffer,s,t).set(e),this._module._fluid_midi_event_set_sysex(this._ptr,s,t,1)}setText(e){const t=e.byteLength,s=this._module._malloc(t);new Uint8Array(this._module.HEAPU8.buffer,s,t).set(e),this._module._fluid_midi_event_set_text(this._ptr,s,t,1)}setLyrics(e){const t=e.byteLength,s=this._module._malloc(t);new Uint8Array(this._module.HEAPU8.buffer,s,t).set(e),this._module._fluid_midi_event_set_lyrics(this._ptr,s,t,1)}}class t{constructor(e,t){this._ptr=e,this._module=t}getRaw(){return this._ptr}dispose(){this._ptr=0}getType(){return 0===this._ptr?-1:this._module._fluid_event_get_type(this._ptr)}getSource(){return 0===this._ptr?-1:this._module._fluid_event_get_source(this._ptr)}getDest(){return 0===this._ptr?-1:this._module._fluid_event_get_dest(this._ptr)}getChannel(){return 0===this._ptr?-1:this._module._fluid_event_get_channel(this._ptr)}getKey(){return 0===this._ptr?-1:this._module._fluid_event_get_key(this._ptr)}getVelocity(){return 0===this._ptr?-1:this._module._fluid_event_get_velocity(this._ptr)}getControl(){return 0===this._ptr?-1:this._module._fluid_event_get_control(this._ptr)}getValue(){return 0===this._ptr?-1:this._module._fluid_event_get_value(this._ptr)}getProgram(){return 0===this._ptr?-1:this._module._fluid_event_get_program(this._ptr)}getData(){return 0===this._ptr?-1:this._module._fluid_event_get_data(this._ptr)}getDuration(){return 0===this._ptr?-1:this._module._fluid_event_get_duration(this._ptr)}getBank(){return 0===this._ptr?-1:this._module._fluid_event_get_bank(this._ptr)}getPitch(){return 0===this._ptr?-1:this._module._fluid_event_get_pitch(this._ptr)}getSFontId(){return 0===this._ptr?-1:this._module._fluid_event_get_sfont_id(this._ptr)}}const s="undefined"!=typeof AudioWorkletGlobalScope?AudioWorkletGlobalScope.wasmModule:Module;function n(e,t){switch(t.type){case 0:case"note":s._fluid_event_note(e,t.channel,t.key,t.vel,t.duration);break;case 1:case"noteon":case"note-on":s._fluid_event_noteon(e,t.channel,t.key,t.vel);break;case 2:case"noteoff":case"note-off":s._fluid_event_noteoff(e,t.channel,t.key);break;case 3:case"allsoundsoff":case"all-sounds-off":s._fluid_event_all_sounds_off(e,t.channel);break;case 4:case"allnotesoff":case"all-notes-off":s._fluid_event_all_notes_off(e,t.channel);break;case 5:case"bankselect":case"bank-select":s._fluid_event_bank_select(e,t.channel,t.bank);break;case 6:case"programchange":case"program-change":s._fluid_event_program_change(e,t.channel,t.preset);break;case 7:case"programselect":case"program-select":s._fluid_event_program_select(e,t.channel,t.sfontId,t.bank,t.preset);break;case 12:case"controlchange":case"control-change":s._fluid_event_control_change(e,t.channel,t.control,t.value);break;case 8:case"pitchbend":case"pitch-bend":s._fluid_event_pitch_bend(e,t.channel,t.value);break;case 9:case"pitchwheelsens":case"pitchwheelsensitivity":case"pitch-wheel-sens":case"pitch-wheel-sensitivity":s._fluid_event_pitch_wheelsens(e,t.channel,t.value);break;case 10:case"modulation":s._fluid_event_modulation(e,t.channel,t.value);break;case 11:case"sustain":s._fluid_event_sustain(e,t.channel,t.value);break;case 13:case"pan":s._fluid_event_pan(e,t.channel,t.value);break;case 14:case"volume":s._fluid_event_volume(e,t.channel,t.value);break;case 15:case"reverb":case"reverbsend":case"reverb-send":s._fluid_event_reverb_send(e,t.channel,t.value);break;case 16:case"chorus":case"chorussend":case"chorus-send":s._fluid_event_chorus_send(e,t.channel,t.value);break;case 20:case"keypressure":case"key-pressure":case"aftertouch":s._fluid_event_key_pressure(e,t.channel,t.key,t.value);break;case 19:case"channelpressure":case"channel-pressure":case"channel-aftertouch":s._fluid_event_channel_pressure(e,t.channel,t.value);break;case 21:case"systemreset":case"system-reset":s._fluid_event_system_reset(e);break;case 17:case"timer":s._fluid_event_timer(e,t.data);break;default:return!1}return!0}let i,r,_,l,o,h,u,a,d,c,f,y,m,p,g,v,b,P,w,k,S,q;function I(e){const t=i._new_fluid_event();return n(t,e)?t:(i._delete_fluid_event(t),null)}class C{constructor(){i||("undefined"!=typeof AudioWorkletGlobalScope?(i=AudioWorkletGlobalScope.wasmModule,r=AudioWorkletGlobalScope.wasmRemoveFunction):(i=Module,r=removeFunction),_=i.cwrap("fluid_sequencer_get_client_name","string",["number","number"])),this._seq=0,this._seqId=-1,this._clientFuncMap={}}_initialize(){return this.close(),this._seq=i._new_fluid_sequencer2(0),this._seqId=-1,Promise.resolve()}getRaw(){return this._seq}close(){0!==this._seq&&(Object.keys(this._clientFuncMap).forEach((e=>{this.unregisterClient(Number(e))})),this.unregisterClient(-1),i._delete_fluid_sequencer(this._seq),this._seq=0)}registerSynthesizer(e){let t;if(-1!==this._seqId&&(i._fluid_sequencer_unregister_client(this._seq,this._seqId),this._seqId=-1),"number"==typeof e)t=e;else{if(!(e instanceof M))return Promise.reject(new TypeError("'synth' is not a compatible type instance"));t=e.getRawSynthesizer()}return this._seqId=i._fluid_sequencer_register_fluidsynth(this._seq,t),Promise.resolve(this._seqId)}unregisterClient(e){if(-1===e&&-1===(e=this._seqId))return;const t=i._new_fluid_event();if(i._fluid_event_set_source(t,-1),i._fluid_event_set_dest(t,e),i._fluid_event_unregistering(t),i._fluid_sequencer_send_now(this._seq,t),i._delete_fluid_event(t),i._fluid_sequencer_unregister_client(this._seq,e),this._seqId===e)this._seqId=-1;else{const t=this._clientFuncMap;t[e]&&(r(t[e]),delete t[e])}}getAllRegisteredClients(){const e=i._fluid_sequencer_count_clients(this._seq),t=[];for(let s=0;s<e;++s){const e=i._fluid_sequencer_get_client_id(this._seq,s),n=_(this._seq,e);t.push({clientId:e,name:n})}return Promise.resolve(t)}getClientCount(){return Promise.resolve(i._fluid_sequencer_count_clients(this._seq))}getClientInfo(e){const t=i._fluid_sequencer_get_client_id(this._seq,e),s=_(this._seq,t);return Promise.resolve({clientId:t,name:s})}setTimeScale(e){i._fluid_sequencer_set_time_scale(this._seq,e)}getTimeScale(){return Promise.resolve(i._fluid_sequencer_get_time_scale(this._seq))}getTick(){return Promise.resolve(i._fluid_sequencer_get_tick(this._seq))}sendEventAt(e,t,s){const n=I(e);if(null!==n){const e=i._fluid_sequencer_count_clients(this._seq);for(let r=0;r<e;++r){const e=i._fluid_sequencer_get_client_id(this._seq,r);i._fluid_event_set_dest(n,e),i._fluid_sequencer_send_at(this._seq,n,t,s?1:0)}i._delete_fluid_event(n)}}sendEventToClientAt(e,t,s,n){const r=I(t);null!==r&&(i._fluid_event_set_dest(r,-1===e?this._seqId:e),i._fluid_sequencer_send_at(this._seq,r,s,n?1:0),i._delete_fluid_event(r))}sendEventToClientNow(e,t){const s=I(t);null!==s&&(i._fluid_event_set_dest(s,-1===e?this._seqId:e),i._fluid_sequencer_send_now(this._seq,s),i._delete_fluid_event(s))}sendEventNow(e,s){if(!(s instanceof t))return;const n=s.getRaw();0!==n&&(i._fluid_event_set_dest(n,-1===e?this._seqId:e),i._fluid_sequencer_send_now(this._seq,n))}removeAllEvents(){i._fluid_sequencer_remove_events(this._seq,-1,-1,-1)}removeAllEventsFromClient(e){i._fluid_sequencer_remove_events(this._seq,-1,-1===e?this._seqId:e,-1)}processSequencer(e){0!==this._seq&&i._fluid_sequencer_process(this._seq,e)}setIntervalForSequencer(e){return setInterval((()=>this.processSequencer(e)),e)}}class E{constructor(e){this._ptr=e}static getSoundfontById(e,t){l||(l="undefined"!=typeof AudioWorkletGlobalScope?AudioWorkletGlobalScope.wasmModule:Module,o=l.cwrap("fluid_sfont_get_name","string",["number"]),h=l.cwrap("fluid_preset_get_name","string",["number"]));const s=l._fluid_synth_get_sfont_by_id(e.getRawSynthesizer(),t);return 0===s?null:new E(s)}getName(){return o(this._ptr)}getPreset(e,t){const s=l._fluid_sfont_get_preset(this._ptr,e,t);if(0===s)return null;return{soundfont:this,name:h(s),bankNum:l._fluid_preset_get_banknum(s),num:l._fluid_preset_get_num(s)}}getPresetIterable(){const e=()=>{l._fluid_sfont_iteration_start(this._ptr)},t=()=>{const e=l._fluid_sfont_iteration_next(this._ptr);if(0===e)return{done:!0,value:void 0};return{done:!1,value:{soundfont:this,name:h(e),bankNum:l._fluid_preset_get_banknum(e),num:l._fluid_preset_get_num(e)}}};return{[Symbol.iterator]:()=>(e(),{next:t})}}}function A(){if(!p){if("undefined"!=typeof AudioWorkletGlobalScope)u=AudioWorkletGlobalScope.wasmModule,a=AudioWorkletGlobalScope.wasmAddFunction,d=AudioWorkletGlobalScope.wasmRemoveFunction;else{if("undefined"==typeof Module)throw new Error("wasm module is not available. libfluidsynth-*.js must be loaded.");u=Module,a=addFunction,d=removeFunction}c=u.FS,f=u.cwrap("fluid_settings_setint","number",["number","string","number"]),y=u.cwrap("fluid_settings_setnum","number",["number","string","number"]),m=u.cwrap("fluid_settings_setstr","number",["number","string","string"]),p=u.cwrap("fluid_synth_error","string",["number"]),g=u.cwrap("fluid_synth_sfload","number",["number","string","number"]),v=u.cwrap("fluid_sequencer_register_client","number",["number","string","number","number"]),b=u._malloc.bind(u),P=u._free.bind(u),w=u._fluid_synth_handle_midi_event.bind(u)}}function z(e,t,s){void 0!==s&&f(e,t,s?1:0)}function F(e,t,s){void 0!==s&&f(e,t,s)}function R(e,t,s){void 0!==s&&y(e,t,s)}class M{constructor(){A(),this._settings=0,this._synth=0,this._player=0,this._playerPlaying=!1,this._playerCallbackPtr=null,this._fluidSynthCallback=null,this._buffer=0,this._bufferSize=0,this._numPtr=0,this._gain=.5}static waitForWasmInitialized(){return function(){if(k)return k;let e,t;if("undefined"!=typeof AudioWorkletGlobalScope)e=AudioWorkletGlobalScope.wasmModule,t=AudioWorkletGlobalScope.addOnPostRun;else{if("undefined"==typeof Module)return Promise.reject(new Error("wasm module is not available. libfluidsynth-*.js must be loaded."));e=Module,t="undefined"!=typeof addOnPostRun?addOnPostRun:void 0}return e.calledRun?(k=Promise.resolve(),k):(k=new Promise(void 0===t?e=>{const t=u.onRuntimeInitialized;u.onRuntimeInitialized=()=>{e(),t&&t()}}:e=>{t(e)}),k)}()}isInitialized(){return 0!==this._synth}getRawSynthesizer(){return this._synth}createAudioNode(e,t){const s=e.createScriptProcessor(t,0,2);return s.addEventListener("audioprocess",(e=>{this.render(e.outputBuffer)})),s}init(e,t){this.close();const s=this._settings=u._new_fluid_settings();y(s,"synth.sample-rate",e),t&&(void 0!==t.initialGain&&(this._gain=t.initialGain),z(s,"synth.chorus.active",t.chorusActive),R(s,"synth.chorus.depth",t.chorusDepth),R(s,"synth.chorus.level",t.chorusLevel),F(s,"synth.chorus.nr",t.chorusNr),R(s,"synth.chorus.speed",t.chorusSpeed),F(s,"synth.midi-channels",t.midiChannelCount),function(e,t,s){void 0!==s&&m(e,t,s)}(s,"synth.midi-bank-select",t.midiBankSelect),F(s,"synth.min-note-length",t.minNoteLength),R(s,"synth.overflow.age",t.overflowAge),R(s,"synth.overflow.important",t.overflowImportantValue),void 0!==t.overflowImportantChannels&&m(s,"synth.overflow.important-channels",t.overflowImportantChannels.join(",")),R(s,"synth.overflow.percussion",t.overflowPercussion),R(s,"synth.overflow.released",t.overflowReleased),R(s,"synth.overflow.sustained",t.overflowSustained),R(s,"synth.overflow.volume",t.overflowVolume),F(s,"synth.polyphony",t.polyphony),z(s,"synth.reverb.active",t.reverbActive),R(s,"synth.reverb.damp",t.reverbDamp),R(s,"synth.reverb.level",t.reverbLevel),R(s,"synth.reverb.room-size",t.reverbRoomSize),R(s,"synth.reverb.width",t.reverbWidth)),y(s,"synth.gain",this._gain),this._synth=u._new_fluid_synth(this._settings),this._numPtr=b(8)}close(){0!==this._synth&&(this._closePlayer(),u._delete_fluid_synth(this._synth),this._synth=0,u._delete_fluid_settings(this._settings),this._settings=0,P(this._numPtr),this._numPtr=0)}isPlaying(){return 0!==this._synth&&function(e){const t=u._fluid_synth_get_active_voice_count(e);if(!t)return 0;let s=140,n=e+s+4>>2,i=u.HEAPU32[n];if(i!==t&&(s+=4,n=e+s+4>>2,i=u.HEAPU32[n],i!==t))return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t;const r=u.HEAPU32[e+s>>2];if(!r||r>=u.HEAPU32.byteLength)return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t;const _=u._fluid_synth_get_polyphony(e);let l=!1;for(let e=0;e<_;++e){const t=u.HEAPU32[(r>>2)+e];if(t&&4!==u.HEAPU8[t+4]){l=!0;break}}if(!l)return 0!==i&&console.warn("js-synthesizer: Active voice count is not zero, but all voices are off:",i),u.HEAPU32[n]=0,0;return t}(this._synth)>0}setInterpolation(e,t){this.ensureInitialized(),void 0===t&&(t=-1),u._fluid_synth_set_interp_method(this._synth,t,e)}getGain(){return this._gain}setGain(e){this.ensureInitialized(),u._fluid_synth_set_gain(this._synth,e),this._gain=u._fluid_synth_get_gain(this._synth)}setChannelType(e,t){this.ensureInitialized(),u._fluid_synth_set_channel_type(this._synth,e,t?1:0)}waitForVoicesStopped(){return this.flushFramesAsync()}loadSFont(e){this.ensureInitialized();const t=(s=".sf2",`/${"sfont"}-r${65535*Math.random()}-${65535*Math.random()}${s}`);var s;const n=new Uint8Array(e);c.writeFile(t,n);const i=g(this._synth,t,1);return c.unlink(t),-1===i?Promise.reject(new Error(p(this._synth))):Promise.resolve(i)}unloadSFont(e){this.ensureInitialized(),this.stopPlayer(),this.flushFramesSync(),u._fluid_synth_sfunload(this._synth,e,1)}unloadSFontAsync(e){return this.ensureInitialized(),this.stopPlayer(),this.flushFramesAsync().then((()=>{u._fluid_synth_sfunload(this._synth,e,1)}))}getSFontObject(e){return E.getSoundfontById(this,e)}getSFontBankOffset(e){return this.ensureInitialized(),Promise.resolve(u._fluid_synth_get_bank_offset(this._synth,e))}setSFontBankOffset(e,t){this.ensureInitialized(),u._fluid_synth_set_bank_offset(this._synth,e,t)}render(e){const t="numberOfChannels"in e?e.length:e[0].length,s="numberOfChannels"in e?e.numberOfChannels:e.length,n=4*t,i=2*n;this._bufferSize<i&&(0!==this._buffer&&P(this._buffer),this._buffer=b(i),this._bufferSize=i);const r=this._buffer,_=this._buffer+n;this.renderRaw(r,_,t);const l=new Float32Array(u.HEAPU8.buffer,r,t),o=s>=2?new Float32Array(u.HEAPU8.buffer,_,t):null;if("numberOfChannels"in e)if(e.copyToChannel)e.copyToChannel(l,0,0),o&&e.copyToChannel(o,1,0);else{const t=e.getChannelData(0);if(l.forEach(((e,s)=>t[s]=e)),o){const t=e.getChannelData(1);o.forEach(((e,s)=>t[s]=e))}}else e[0].set(l),o&&e[1].set(o);this.isPlayerPlaying()}midiNoteOn(e,t,s){u._fluid_synth_noteon(this._synth,e,t,s)}midiNoteOff(e,t){u._fluid_synth_noteoff(this._synth,e,t)}midiKeyPressure(e,t,s){u._fluid_synth_key_pressure(this._synth,e,t,s)}midiControl(e,t,s){u._fluid_synth_cc(this._synth,e,t,s)}midiProgramChange(e,t){u._fluid_synth_program_change(this._synth,e,t)}midiChannelPressure(e,t){u._fluid_synth_channel_pressure(this._synth,e,t)}midiPitchBend(e,t){u._fluid_synth_pitch_bend(this._synth,e,t)}midiSysEx(e){const t=e.byteLength,s=b(t);u.HEAPU8.set(e,s),u._fluid_synth_sysex(this._synth,s,t,0,0,0,0),P(s)}midiPitchWheelSensitivity(e,t){u._fluid_synth_pitch_wheel_sens(this._synth,e,t)}midiBankSelect(e,t){u._fluid_synth_bank_select(this._synth,e,t)}midiSFontSelect(e,t){u._fluid_synth_sfont_select(this._synth,e,t)}midiProgramSelect(e,t,s,n){u._fluid_synth_program_select(this._synth,e,t,s,n)}midiUnsetProgram(e){u._fluid_synth_unset_program(this._synth,e)}midiProgramReset(){u._fluid_synth_program_reset(this._synth)}midiSystemReset(){u._fluid_synth_system_reset(this._synth)}midiAllNotesOff(e){u._fluid_synth_all_notes_off(this._synth,void 0===e?-1:e)}midiAllSoundsOff(e){u._fluid_synth_all_sounds_off(this._synth,void 0===e?-1:e)}midiSetChannelType(e,t){u._fluid_synth_set_channel_type(this._synth,e,t?1:0)}setReverb(e,t,s,n){u._fluid_synth_set_reverb(this._synth,e,t,s,n)}setReverbRoomsize(e){u._fluid_synth_set_reverb_roomsize(this._synth,e)}setReverbDamp(e){u._fluid_synth_set_reverb_damp(this._synth,e)}setReverbWidth(e){u._fluid_synth_set_reverb_width(this._synth,e)}setReverbLevel(e){u._fluid_synth_set_reverb_level(this._synth,e)}setReverbOn(e){u._fluid_synth_set_reverb_on(this._synth,e?1:0)}getReverbRoomsize(){return u._fluid_synth_get_reverb_roomsize(this._synth)}getReverbDamp(){return u._fluid_synth_get_reverb_damp(this._synth)}getReverbLevel(){return u._fluid_synth_get_reverb_level(this._synth)}getReverbWidth(){return u._fluid_synth_get_reverb_width(this._synth)}setChorus(e,t,s,n,i){u._fluid_synth_set_chorus(this._synth,e,t,s,n,i)}setChorusVoiceCount(e){u._fluid_synth_set_chorus_nr(this._synth,e)}setChorusLevel(e){u._fluid_synth_set_chorus_level(this._synth,e)}setChorusSpeed(e){u._fluid_synth_set_chorus_speed(this._synth,e)}setChorusDepth(e){u._fluid_synth_set_chorus_depth(this._synth,e)}setChorusType(e){u._fluid_synth_set_chorus_type(this._synth,e)}setChorusOn(e){u._fluid_synth_set_chorus_on(this._synth,e?1:0)}getChorusVoiceCount(){return u._fluid_synth_get_chorus_nr(this._synth)}getChorusLevel(){return u._fluid_synth_get_chorus_level(this._synth)}getChorusSpeed(){return u._fluid_synth_get_chorus_speed(this._synth)}getChorusDepth(){return u._fluid_synth_get_chorus_depth(this._synth)}getChorusType(){return u._fluid_synth_get_chorus_type(this._synth)}getGenerator(e,t){return u._fluid_synth_get_gen(this._synth,e,t)}setGenerator(e,t,s){u._fluid_synth_set_gen(this._synth,e,t,s)}getLegatoMode(e){return u._fluid_synth_get_legato_mode(this._synth,e,this._numPtr),u.HEAP32[this._numPtr>>2]}setLegatoMode(e,t){u._fluid_synth_set_legato_mode(this._synth,e,t)}getPortamentoMode(e){return u._fluid_synth_get_portamento_mode(this._synth,e,this._numPtr),u.HEAP32[this._numPtr>>2]}setPortamentoMode(e,t){u._fluid_synth_set_portamento_mode(this._synth,e,t)}getBreathMode(e){return u._fluid_synth_get_breath_mode(this._synth,e,this._numPtr),u.HEAP32[this._numPtr>>2]}setBreathMode(e,t){u._fluid_synth_set_breath_mode(this._synth,e,t)}resetPlayer(){return new Promise((e=>{this._initPlayer(),e()}))}closePlayer(){this._closePlayer()}_initPlayer(){this._closePlayer();const e=u._new_fluid_player(this._synth);if(this._player=e,0===e)throw new Error("Out of memory");if(null===this._fluidSynthCallback){const t=u.HEAPU32[e+588>>2];u.HEAPU32[e+592>>2]===this._synth&&(this._fluidSynthCallback=t)}}_closePlayer(){const e=this._player;0!==e&&(this.stopPlayer(),u._delete_fluid_player(e),this._player=0,this._playerCallbackPtr=null)}isPlayerPlaying(){if(this._playerPlaying){if(1===u._fluid_player_get_status(this._player))return!0;this.stopPlayer()}return!1}addSMFDataToPlayer(e){this.ensurePlayerInitialized();const t=e.byteLength,s=b(t);u.HEAPU8.set(new Uint8Array(e),s);const n=u._fluid_player_add_mem(this._player,s,t);return P(s),-1!==n?Promise.resolve():Promise.reject(new Error(p(this._synth)))}playPlayer(){if(this.ensurePlayerInitialized(),this._playerPlaying&&this.stopPlayer(),-1===u._fluid_player_play(this._player))return Promise.reject(new Error(p(this._synth)));this._playerPlaying=!0;let e=()=>{};const t=new Promise((t=>{e=t}));return this._playerDefer={promise:t,resolve:e},Promise.resolve()}stopPlayer(){const e=this._player;0!==e&&this._playerPlaying&&(u._fluid_player_stop(e),u._fluid_player_join(e),u._fluid_synth_all_sounds_off(this._synth,-1),this._playerDefer&&(this._playerDefer.resolve(),this._playerDefer=void 0),this._playerPlaying=!1)}retrievePlayerCurrentTick(){return this.ensurePlayerInitialized(),Promise.resolve(u._fluid_player_get_current_tick(this._player))}retrievePlayerTotalTicks(){return this.ensurePlayerInitialized(),Promise.resolve(u._fluid_player_get_total_ticks(this._player))}retrievePlayerBpm(){return this.ensurePlayerInitialized(),Promise.resolve(u._fluid_player_get_bpm(this._player))}retrievePlayerMIDITempo(){return this.ensurePlayerInitialized(),Promise.resolve(u._fluid_player_get_midi_tempo(this._player))}seekPlayer(e){this.ensurePlayerInitialized(),u._fluid_player_seek(this._player,e)}hookPlayerMIDIEvents(t,s){this.ensurePlayerInitialized();const n=this._playerCallbackPtr;if(null===n&&null===t)return;const i=null!==t?a(function(t,s,n){return(i,r)=>{const _=u._fluid_midi_event_get_type(r);return s(t,_,new e(r,u),n)?0:u._fluid_synth_handle_midi_event(i,r)}}(this,t,s),"iii"):null!==this._fluidSynthCallback?null:a(w,"iii");null!==n&&null!==i?(u._fluid_player_set_playback_callback(this._player,i,this._synth),d(n)):null===i?(u._fluid_player_set_playback_callback(this._player,this._fluidSynthCallback,this._synth),d(n)):u._fluid_player_set_playback_callback(this._player,i,this._synth),this._playerCallbackPtr=i}ensureInitialized(){if(0===this._synth)throw new Error("Synthesizer is not initialized")}ensurePlayerInitialized(){this.ensureInitialized(),0===this._player&&this._initPlayer()}renderRaw(e,t,s){u._fluid_synth_write_float(this._synth,s,e,0,1,t,0,1)}flushFramesSync(){const e=262144,t=b(524288),s=t,n=t+e;for(;this.isPlaying();)this.renderRaw(s,n,65536);P(t)}flushFramesAsync(){if(!this.isPlaying())return Promise.resolve();const e=262144,t=b(524288),s=t,n=t+e,i="undefined"!=typeof setTimeout?()=>new Promise((e=>setTimeout(e,0))):()=>Promise.resolve();function r(){return i().then(l)}const _=this;function l(){return _.isPlaying()?(_.renderRaw(s,n,65536),r()):(P(t),Promise.resolve())}return r()}waitForPlayerStopped(){return this._playerDefer?this._playerDefer.promise:Promise.resolve()}static createSequencer(){A();const e=new C;return e._initialize().then((()=>e))}static registerSequencerClient(e,s,n,i){if(!(e instanceof C))throw new TypeError("Invalid sequencer instance");const r=a(((s,i,r,_)=>{const l=new t(i,u),o=u._fluid_event_get_type(i);n(s,o,l,e,_)}),"viiii"),_=v(e.getRaw(),s,r,i);return-1!==_&&(e._clientFuncMap[_]=r),_}static sendEventToClientNow(e,t,s){if(!(e instanceof C))throw new TypeError("Invalid sequencer instance");e.sendEventToClientNow(t,s)}static sendEventNow(e,t,s){if(!(e instanceof C))throw new TypeError("Invalid sequencer instance");e.sendEventNow(t,s)}static setIntervalForSequencer(e,t){if(!(e instanceof C))throw new TypeError("Invalid sequencer instance");return e.setIntervalForSequencer(t)}}class G extends Error{constructor(e,t,s){super(t),this.baseName=e,this.detail=s,s&&s.stack&&(this.stack=s.stack)}}function T(e){return function(e){const t={},s=[];let n=e;for(;n&&n!==Object.prototype;)s.unshift(n),n=Object.getPrototypeOf(n);return s.forEach((s=>{Object.getOwnPropertyNames(s).forEach((s=>{try{const n=e[s];"function"!=typeof n&&"symbol"!=typeof n&&(t[s]=n)}catch(e){}}))})),{baseName:e.name,message:e.message,detail:t}}(e&&e instanceof Error?e:new Error(`${e}`))}function W(e,t,s,n){const i={port:e};return t?e.addEventListener("message",(e=>{const r=e.data;r&&t.then((()=>O(i.port,r,s,n)))})):e.addEventListener("message",(e=>{const t=e.data;t&&O(i.port,t,s,n)})),e.start(),i}function O(e,t,s,n){if(n&&n(t))return;const i=s();if(i[t.method])try{N(e,t.id,t.method,i[t.method].apply(i,t.args))}catch(s){j(e,t.id,t.method,s)}else j(e,t.id,t.method,new Error("Not implemented"))}function D(e,t,s,n){N(e.port,t,s,n)}function N(e,t,s,n){n instanceof Promise?n.then((n=>{t>=0&&e.postMessage({id:t,method:s,val:n})}),(n=>{e.postMessage({id:t,method:s,error:T(n)})})):e.postMessage({id:t,method:s,val:n})}function L(e,t,s,n){j(e.port,t,s,n)}function j(e,t,s,n){e.postMessage({id:t,method:s,error:T(n)})}let U=null;const H=[],B=0,x=4;function V(e=B){if(U!==e){if(function(){if("undefined"!=typeof AudioWorkletGlobalScope)S=AudioWorkletGlobalScope.wasmModule;else{if("undefined"==typeof Module)throw new Error("wasm module is not available. libfluidsynth-*.js must be loaded.");S=Module}}(),null==e)null!=q&&(S._fluid_set_log_function(0,q,0),S._fluid_set_log_function(1,q,0),S._fluid_set_log_function(2,q,0),S._fluid_set_log_function(3,q,0)),S._fluid_set_log_function(4,0,0);else{let t;for(let s=e;s<5;++s){const e=S._fluid_set_log_function(s,0,0);s!==x&&(t=e)}null!=t&&null==q&&(q=t)}U=e;for(const t of H)t(e)}}var $=function(e,t,s,n){return new(s||(s=Promise))((function(i,r){function _(e){try{o(n.next(e))}catch(e){r(e)}}function l(e){try{o(n.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(_,l)}o((n=n.apply(e,t||[])).next())}))};const K=M.waitForWasmInitialized();AudioWorkletGlobalScope.JSSynth={rewriteEventData:function(e,s){if(!(e&&e instanceof t))return!1;const i=e.getRaw();return 0!==i&&n(i,s)},Synthesizer:M,disableLogging:V,restoreLogging:function(){V(null)}},AudioWorkletGlobalScope.Fluid=AudioWorkletGlobalScope.JSSynth,function(){class e extends AudioWorkletProcessor{constructor(e){super(e);const t=e.processorOptions,s=t&&t.settings;t&&t.disabledLoggingLevel&&V(t.disabledLoggingLevel);const n=this.doInit(s);this._messaging=W(this.port,n,(()=>this.synth),(e=>{switch(e.method){case"init":return this.synth.init(sampleRate,s),!0;case"createSequencer":return this.doCreateSequencer(e.args[0]).then((()=>{D(this._messaging,e.id,e.method,void 0)})),!0;case"hookPlayerMIDIEventsByName":this.doHookPlayerMIDIEvents(e.args[0],e.args[1])?D(this._messaging,e.id,e.method,void 0):L(this._messaging,e.id,e.method,new Error("Name not found"));return!0;case"callFunction":try{this.doCallFunction(e.args[0],e.args[1]),D(this._messaging,e.id,e.method,void 0)}catch(t){L(this._messaging,e.id,e.method,t)}return!0;case"getSFontObject":try{const t=this.doGetSFontObject(e.args[0],e.args[1]);null!==t?D(this._messaging,e.id,e.method,t):L(this._messaging,e.id,e.method,new Error("Invalid sfontId"))}catch(t){L(this._messaging,e.id,e.method,t)}return!0;case"playPlayer":return this.doPlayPlayer(e),!0;case"loggingChanged":return V(e.args[0]),!0}return!1}))}doInit(e){return $(this,void 0,void 0,(function*(){yield K,this.synth=new M,this.synth.init(sampleRate,e)}))}doCreateSequencer(e){return M.createSequencer().then((t=>{const s=W(e,null,(()=>t),(e=>{if("getRaw"===e.method)return D(s,e.id,e.method,t.getRaw()),!0;if("registerSequencerClientByName"===e.method){const n=this.doRegisterSequencerClient(t,e.args[0],e.args[1],e.args[2]);return null!==n?D(s,e.id,e.method,n):L(s,e.id,e.method,new Error("Name not found")),!0}return!1}))}))}doGetSFontObject(e,t){const s=this.synth.getSFontObject(t);if(null===s)return null;const n=W(e,null,(()=>s),(e=>"getPresetIterable"===e.method&&(D(n,e.id,e.method,[...s.getPresetIterable()]),!0)));return s.getName()}doPlayPlayer(e){const t=this.synth;t.playPlayer().then((()=>{D(this._messaging,-1,"updateStatus",{playing:t.isPlaying(),playerPlaying:t.isPlayerPlaying()}),D(this._messaging,e.id,e.method,void 0)}),(t=>{L(this._messaging,e.id,e.method,t)}))}doHookPlayerMIDIEvents(e,t){if(!e)return this.synth.hookPlayerMIDIEvents(null),!0;const s=AudioWorkletGlobalScope[e];return!(!s||"function"!=typeof s)&&(this.synth.hookPlayerMIDIEvents(s,t),!0)}doCallFunction(e,t){const s=AudioWorkletGlobalScope[e];if(!s||"function"!=typeof s)throw new Error("Name not found");s.call(null,this.synth,t)}doRegisterSequencerClient(e,t,s,n){const i=AudioWorkletGlobalScope[s];return i&&"function"==typeof i?M.registerSequencerClient(e,t,i,n):null}process(e,t){if(!this.synth)return!0;const s=this.synth;return s.render(t[0]),D(this._messaging,-1,"updateStatus",{playing:s.isPlaying(),playerPlaying:s.isPlayerPlaying()}),!0}}registerProcessor("fluid-js",e)}()})(); | ||
*/(()=>{"use strict";class e{constructor(e,t){this._ptr=e,this._module=t}getType(){return this._module._fluid_midi_event_get_type(this._ptr)}setType(e){this._module._fluid_midi_event_set_type(this._ptr,e)}getChannel(){return this._module._fluid_midi_event_get_channel(this._ptr)}setChannel(e){this._module._fluid_midi_event_set_channel(this._ptr,e)}getKey(){return this._module._fluid_midi_event_get_key(this._ptr)}setKey(e){this._module._fluid_midi_event_set_key(this._ptr,e)}getVelocity(){return this._module._fluid_midi_event_get_velocity(this._ptr)}setVelocity(e){this._module._fluid_midi_event_set_velocity(this._ptr,e)}getControl(){return this._module._fluid_midi_event_get_control(this._ptr)}setControl(e){this._module._fluid_midi_event_set_control(this._ptr,e)}getValue(){return this._module._fluid_midi_event_get_value(this._ptr)}setValue(e){this._module._fluid_midi_event_set_value(this._ptr,e)}getProgram(){return this._module._fluid_midi_event_get_program(this._ptr)}setProgram(e){this._module._fluid_midi_event_set_program(this._ptr,e)}getPitch(){return this._module._fluid_midi_event_get_pitch(this._ptr)}setPitch(e){this._module._fluid_midi_event_set_pitch(this._ptr,e)}setSysEx(e){const t=e.byteLength,s=this._module._malloc(t);new Uint8Array(this._module.HEAPU8.buffer,s,t).set(e),this._module._fluid_midi_event_set_sysex(this._ptr,s,t,1)}setText(e){const t=e.byteLength,s=this._module._malloc(t);new Uint8Array(this._module.HEAPU8.buffer,s,t).set(e),this._module._fluid_midi_event_set_text(this._ptr,s,t,1)}setLyrics(e){const t=e.byteLength,s=this._module._malloc(t);new Uint8Array(this._module.HEAPU8.buffer,s,t).set(e),this._module._fluid_midi_event_set_lyrics(this._ptr,s,t,1)}}class t{constructor(e,t){this._ptr=e,this._module=t}getRaw(){return this._ptr}dispose(){this._ptr=0}getType(){return 0===this._ptr?-1:this._module._fluid_event_get_type(this._ptr)}getSource(){return 0===this._ptr?-1:this._module._fluid_event_get_source(this._ptr)}getDest(){return 0===this._ptr?-1:this._module._fluid_event_get_dest(this._ptr)}getChannel(){return 0===this._ptr?-1:this._module._fluid_event_get_channel(this._ptr)}getKey(){return 0===this._ptr?-1:this._module._fluid_event_get_key(this._ptr)}getVelocity(){return 0===this._ptr?-1:this._module._fluid_event_get_velocity(this._ptr)}getControl(){return 0===this._ptr?-1:this._module._fluid_event_get_control(this._ptr)}getValue(){return 0===this._ptr?-1:this._module._fluid_event_get_value(this._ptr)}getProgram(){return 0===this._ptr?-1:this._module._fluid_event_get_program(this._ptr)}getData(){return 0===this._ptr?-1:this._module._fluid_event_get_data(this._ptr)}getDuration(){return 0===this._ptr?-1:this._module._fluid_event_get_duration(this._ptr)}getBank(){return 0===this._ptr?-1:this._module._fluid_event_get_bank(this._ptr)}getPitch(){return 0===this._ptr?-1:this._module._fluid_event_get_pitch(this._ptr)}getSFontId(){return 0===this._ptr?-1:this._module._fluid_event_get_sfont_id(this._ptr)}}const s="undefined"!=typeof AudioWorkletGlobalScope?AudioWorkletGlobalScope.wasmModule:Module;function n(e,t){switch(t.type){case 0:case"note":s._fluid_event_note(e,t.channel,t.key,t.vel,t.duration);break;case 1:case"noteon":case"note-on":s._fluid_event_noteon(e,t.channel,t.key,t.vel);break;case 2:case"noteoff":case"note-off":s._fluid_event_noteoff(e,t.channel,t.key);break;case 3:case"allsoundsoff":case"all-sounds-off":s._fluid_event_all_sounds_off(e,t.channel);break;case 4:case"allnotesoff":case"all-notes-off":s._fluid_event_all_notes_off(e,t.channel);break;case 5:case"bankselect":case"bank-select":s._fluid_event_bank_select(e,t.channel,t.bank);break;case 6:case"programchange":case"program-change":s._fluid_event_program_change(e,t.channel,t.preset);break;case 7:case"programselect":case"program-select":s._fluid_event_program_select(e,t.channel,t.sfontId,t.bank,t.preset);break;case 12:case"controlchange":case"control-change":s._fluid_event_control_change(e,t.channel,t.control,t.value);break;case 8:case"pitchbend":case"pitch-bend":s._fluid_event_pitch_bend(e,t.channel,t.value);break;case 9:case"pitchwheelsens":case"pitchwheelsensitivity":case"pitch-wheel-sens":case"pitch-wheel-sensitivity":s._fluid_event_pitch_wheelsens(e,t.channel,t.value);break;case 10:case"modulation":s._fluid_event_modulation(e,t.channel,t.value);break;case 11:case"sustain":s._fluid_event_sustain(e,t.channel,t.value);break;case 13:case"pan":s._fluid_event_pan(e,t.channel,t.value);break;case 14:case"volume":s._fluid_event_volume(e,t.channel,t.value);break;case 15:case"reverb":case"reverbsend":case"reverb-send":s._fluid_event_reverb_send(e,t.channel,t.value);break;case 16:case"chorus":case"chorussend":case"chorus-send":s._fluid_event_chorus_send(e,t.channel,t.value);break;case 20:case"keypressure":case"key-pressure":case"aftertouch":s._fluid_event_key_pressure(e,t.channel,t.key,t.value);break;case 19:case"channelpressure":case"channel-pressure":case"channel-aftertouch":s._fluid_event_channel_pressure(e,t.channel,t.value);break;case 21:case"systemreset":case"system-reset":s._fluid_event_system_reset(e);break;case 17:case"timer":s._fluid_event_timer(e,t.data);break;default:return!1}return!0}let i,r,_,l,o,u,h,a,d,c,f,y,m,p,g,v,b,P,w,k,S,q;function I(e){const t=i._new_fluid_event();return n(t,e)?t:(i._delete_fluid_event(t),null)}class C{constructor(){i||("undefined"!=typeof AudioWorkletGlobalScope?(i=AudioWorkletGlobalScope.wasmModule,r=AudioWorkletGlobalScope.wasmRemoveFunction):(i=Module,r=removeFunction),_=i.cwrap("fluid_sequencer_get_client_name","string",["number","number"])),this._seq=0,this._seqId=-1,this._clientFuncMap={}}_initialize(){return this.close(),this._seq=i._new_fluid_sequencer2(0),this._seqId=-1,Promise.resolve()}getRaw(){return this._seq}close(){0!==this._seq&&(Object.keys(this._clientFuncMap).forEach((e=>{this.unregisterClient(Number(e))})),this.unregisterClient(-1),i._delete_fluid_sequencer(this._seq),this._seq=0)}registerSynthesizer(e){let t;if(-1!==this._seqId&&(i._fluid_sequencer_unregister_client(this._seq,this._seqId),this._seqId=-1),"number"==typeof e)t=e;else{if(!(e instanceof M))return Promise.reject(new TypeError("'synth' is not a compatible type instance"));t=e.getRawSynthesizer()}return this._seqId=i._fluid_sequencer_register_fluidsynth(this._seq,t),Promise.resolve(this._seqId)}unregisterClient(e){if(-1===e&&-1===(e=this._seqId))return;const t=i._new_fluid_event();if(i._fluid_event_set_source(t,-1),i._fluid_event_set_dest(t,e),i._fluid_event_unregistering(t),i._fluid_sequencer_send_now(this._seq,t),i._delete_fluid_event(t),i._fluid_sequencer_unregister_client(this._seq,e),this._seqId===e)this._seqId=-1;else{const t=this._clientFuncMap;t[e]&&(r(t[e]),delete t[e])}}getAllRegisteredClients(){const e=i._fluid_sequencer_count_clients(this._seq),t=[];for(let s=0;s<e;++s){const e=i._fluid_sequencer_get_client_id(this._seq,s),n=_(this._seq,e);t.push({clientId:e,name:n})}return Promise.resolve(t)}getClientCount(){return Promise.resolve(i._fluid_sequencer_count_clients(this._seq))}getClientInfo(e){const t=i._fluid_sequencer_get_client_id(this._seq,e),s=_(this._seq,t);return Promise.resolve({clientId:t,name:s})}setTimeScale(e){i._fluid_sequencer_set_time_scale(this._seq,e)}getTimeScale(){return Promise.resolve(i._fluid_sequencer_get_time_scale(this._seq))}getTick(){return Promise.resolve(i._fluid_sequencer_get_tick(this._seq))}sendEventAt(e,t,s){const n=I(e);if(null!==n){const e=i._fluid_sequencer_count_clients(this._seq);for(let r=0;r<e;++r){const e=i._fluid_sequencer_get_client_id(this._seq,r);i._fluid_event_set_dest(n,e),i._fluid_sequencer_send_at(this._seq,n,t,s?1:0)}i._delete_fluid_event(n)}}sendEventToClientAt(e,t,s,n){const r=I(t);null!==r&&(i._fluid_event_set_dest(r,-1===e?this._seqId:e),i._fluid_sequencer_send_at(this._seq,r,s,n?1:0),i._delete_fluid_event(r))}sendEventToClientNow(e,t){const s=I(t);null!==s&&(i._fluid_event_set_dest(s,-1===e?this._seqId:e),i._fluid_sequencer_send_now(this._seq,s),i._delete_fluid_event(s))}sendEventNow(e,s){if(!(s instanceof t))return;const n=s.getRaw();0!==n&&(i._fluid_event_set_dest(n,-1===e?this._seqId:e),i._fluid_sequencer_send_now(this._seq,n))}removeAllEvents(){i._fluid_sequencer_remove_events(this._seq,-1,-1,-1)}removeAllEventsFromClient(e){i._fluid_sequencer_remove_events(this._seq,-1,-1===e?this._seqId:e,-1)}processSequencer(e){0!==this._seq&&i._fluid_sequencer_process(this._seq,e)}setIntervalForSequencer(e){return setInterval((()=>this.processSequencer(e)),e)}}class E{constructor(e){this._ptr=e}static getSoundfontById(e,t){l||(l="undefined"!=typeof AudioWorkletGlobalScope?AudioWorkletGlobalScope.wasmModule:Module,o=l.cwrap("fluid_sfont_get_name","string",["number"]),u=l.cwrap("fluid_preset_get_name","string",["number"]));const s=l._fluid_synth_get_sfont_by_id(e.getRawSynthesizer(),t);return 0===s?null:new E(s)}getName(){return o(this._ptr)}getPreset(e,t){const s=l._fluid_sfont_get_preset(this._ptr,e,t);if(0===s)return null;return{soundfont:this,name:u(s),bankNum:l._fluid_preset_get_banknum(s),num:l._fluid_preset_get_num(s)}}getPresetIterable(){const e=()=>{l._fluid_sfont_iteration_start(this._ptr)},t=()=>{const e=l._fluid_sfont_iteration_next(this._ptr);if(0===e)return{done:!0,value:void 0};return{done:!1,value:{soundfont:this,name:u(e),bankNum:l._fluid_preset_get_banknum(e),num:l._fluid_preset_get_num(e)}}};return{[Symbol.iterator]:()=>(e(),{next:t})}}}function A(){if(!p){if("undefined"!=typeof AudioWorkletGlobalScope)h=AudioWorkletGlobalScope.wasmModule,a=AudioWorkletGlobalScope.wasmAddFunction,d=AudioWorkletGlobalScope.wasmRemoveFunction;else{if("undefined"==typeof Module)throw new Error("wasm module is not available. libfluidsynth-*.js must be loaded.");h=Module,a=addFunction,d=removeFunction}c=h.FS,f=h.cwrap("fluid_settings_setint","number",["number","string","number"]),y=h.cwrap("fluid_settings_setnum","number",["number","string","number"]),m=h.cwrap("fluid_settings_setstr","number",["number","string","string"]),p=h.cwrap("fluid_synth_error","string",["number"]),g=h.cwrap("fluid_synth_sfload","number",["number","string","number"]),v=h.cwrap("fluid_sequencer_register_client","number",["number","string","number","number"]),b=h._malloc.bind(h),P=h._free.bind(h),w=h._fluid_synth_handle_midi_event.bind(h)}}function z(e,t,s){void 0!==s&&f(e,t,s?1:0)}function F(e,t,s){void 0!==s&&f(e,t,s)}function R(e,t,s){void 0!==s&&y(e,t,s)}class M{constructor(){A(),this._settings=0,this._synth=0,this._player=0,this._playerPlaying=!1,this._playerCallbackPtr=null,this._fluidSynthCallback=null,this._buffer=0,this._bufferSize=0,this._numPtr=0,this._gain=.5}static waitForWasmInitialized(){return function(){if(k)return k;let e,t;if("undefined"!=typeof AudioWorkletGlobalScope)e=AudioWorkletGlobalScope.wasmModule,t=AudioWorkletGlobalScope.addOnPostRun;else{if("undefined"==typeof Module)return Promise.reject(new Error("wasm module is not available. libfluidsynth-*.js must be loaded."));e=Module,t="undefined"!=typeof addOnPostRun?addOnPostRun:void 0}return e.calledRun?(k=Promise.resolve(),k):(k=new Promise(void 0===t?e=>{const t=h.onRuntimeInitialized;h.onRuntimeInitialized=()=>{e(),t&&t()}}:e=>{t(e)}),k)}()}isInitialized(){return 0!==this._synth}getRawSynthesizer(){return this._synth}createAudioNode(e,t){const s=e.createScriptProcessor(t,0,2);return s.addEventListener("audioprocess",(e=>{this.render(e.outputBuffer)})),s}init(e,t){this.close();const s=this._settings=h._new_fluid_settings();y(s,"synth.sample-rate",e),t&&(void 0!==t.initialGain&&(this._gain=t.initialGain),z(s,"synth.chorus.active",t.chorusActive),R(s,"synth.chorus.depth",t.chorusDepth),R(s,"synth.chorus.level",t.chorusLevel),F(s,"synth.chorus.nr",t.chorusNr),R(s,"synth.chorus.speed",t.chorusSpeed),F(s,"synth.midi-channels",t.midiChannelCount),function(e,t,s){void 0!==s&&m(e,t,s)}(s,"synth.midi-bank-select",t.midiBankSelect),F(s,"synth.min-note-length",t.minNoteLength),R(s,"synth.overflow.age",t.overflowAge),R(s,"synth.overflow.important",t.overflowImportantValue),void 0!==t.overflowImportantChannels&&m(s,"synth.overflow.important-channels",t.overflowImportantChannels.join(",")),R(s,"synth.overflow.percussion",t.overflowPercussion),R(s,"synth.overflow.released",t.overflowReleased),R(s,"synth.overflow.sustained",t.overflowSustained),R(s,"synth.overflow.volume",t.overflowVolume),F(s,"synth.polyphony",t.polyphony),z(s,"synth.reverb.active",t.reverbActive),R(s,"synth.reverb.damp",t.reverbDamp),R(s,"synth.reverb.level",t.reverbLevel),R(s,"synth.reverb.room-size",t.reverbRoomSize),R(s,"synth.reverb.width",t.reverbWidth)),y(s,"synth.gain",this._gain),this._synth=h._new_fluid_synth(this._settings),this._numPtr=b(8)}close(){0!==this._synth&&(this._closePlayer(),h._delete_fluid_synth(this._synth),this._synth=0,h._delete_fluid_settings(this._settings),this._settings=0,P(this._numPtr),this._numPtr=0)}isPlaying(){return 0!==this._synth&&function(e){const t=h._fluid_synth_get_active_voice_count(e);if(!t)return 0;let s=140,n=e+s+4>>2,i=h.HEAPU32[n];if(i!==t&&(s+=4,n=e+s+4>>2,i=h.HEAPU32[n],i!==t))return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t;const r=h.HEAPU32[e+s>>2];if(!r||r>=h.HEAPU32.byteLength)return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t;const _=h._fluid_synth_get_polyphony(e);let l=!1;for(let e=0;e<_;++e){const t=h.HEAPU32[(r>>2)+e];if(t&&4!==h.HEAPU8[t+4]){l=!0;break}}if(!l)return 0!==i&&console.warn("js-synthesizer: Active voice count is not zero, but all voices are off:",i),h.HEAPU32[n]=0,0;return t}(this._synth)>0}setInterpolation(e,t){this.ensureInitialized(),void 0===t&&(t=-1),h._fluid_synth_set_interp_method(this._synth,t,e)}getGain(){return this._gain}setGain(e){this.ensureInitialized(),h._fluid_synth_set_gain(this._synth,e),this._gain=h._fluid_synth_get_gain(this._synth)}setChannelType(e,t){this.ensureInitialized(),h._fluid_synth_set_channel_type(this._synth,e,t?1:0)}waitForVoicesStopped(){return this.flushFramesAsync()}loadSFont(e){this.ensureInitialized();const t=(s=".sf2",`/${"sfont"}-r${65535*Math.random()}-${65535*Math.random()}${s}`);var s;const n=new Uint8Array(e);c.writeFile(t,n);const i=g(this._synth,t,1);return c.unlink(t),-1===i?Promise.reject(new Error(p(this._synth))):Promise.resolve(i)}unloadSFont(e){this.ensureInitialized(),this.stopPlayer(),this.flushFramesSync(),h._fluid_synth_sfunload(this._synth,e,1)}unloadSFontAsync(e){return this.ensureInitialized(),this.stopPlayer(),this.flushFramesAsync().then((()=>{h._fluid_synth_sfunload(this._synth,e,1)}))}getSFontObject(e){return E.getSoundfontById(this,e)}getSFontBankOffset(e){return this.ensureInitialized(),Promise.resolve(h._fluid_synth_get_bank_offset(this._synth,e))}setSFontBankOffset(e,t){this.ensureInitialized(),h._fluid_synth_set_bank_offset(this._synth,e,t)}render(e){const t="numberOfChannels"in e?e.length:e[0].length,s="numberOfChannels"in e?e.numberOfChannels:e.length,n=4*t,i=2*n;this._bufferSize<i&&(0!==this._buffer&&P(this._buffer),this._buffer=b(i),this._bufferSize=i);const r=this._buffer,_=this._buffer+n;this.renderRaw(r,_,t);const l=new Float32Array(h.HEAPU8.buffer,r,t),o=s>=2?new Float32Array(h.HEAPU8.buffer,_,t):null;if("numberOfChannels"in e)if(e.copyToChannel)e.copyToChannel(l,0,0),o&&e.copyToChannel(o,1,0);else{const t=e.getChannelData(0);if(l.forEach(((e,s)=>t[s]=e)),o){const t=e.getChannelData(1);o.forEach(((e,s)=>t[s]=e))}}else e[0].set(l),o&&e[1].set(o);this.isPlayerPlaying()}midiNoteOn(e,t,s){h._fluid_synth_noteon(this._synth,e,t,s)}midiNoteOff(e,t){h._fluid_synth_noteoff(this._synth,e,t)}midiKeyPressure(e,t,s){h._fluid_synth_key_pressure(this._synth,e,t,s)}midiControl(e,t,s){h._fluid_synth_cc(this._synth,e,t,s)}midiProgramChange(e,t){h._fluid_synth_program_change(this._synth,e,t)}midiChannelPressure(e,t){h._fluid_synth_channel_pressure(this._synth,e,t)}midiPitchBend(e,t){h._fluid_synth_pitch_bend(this._synth,e,t)}midiSysEx(e){const t=e.byteLength,s=b(t);h.HEAPU8.set(e,s),h._fluid_synth_sysex(this._synth,s,t,0,0,0,0),P(s)}midiPitchWheelSensitivity(e,t){h._fluid_synth_pitch_wheel_sens(this._synth,e,t)}midiBankSelect(e,t){h._fluid_synth_bank_select(this._synth,e,t)}midiSFontSelect(e,t){h._fluid_synth_sfont_select(this._synth,e,t)}midiProgramSelect(e,t,s,n){h._fluid_synth_program_select(this._synth,e,t,s,n)}midiUnsetProgram(e){h._fluid_synth_unset_program(this._synth,e)}midiProgramReset(){h._fluid_synth_program_reset(this._synth)}midiSystemReset(){h._fluid_synth_system_reset(this._synth)}midiAllNotesOff(e){h._fluid_synth_all_notes_off(this._synth,void 0===e?-1:e)}midiAllSoundsOff(e){h._fluid_synth_all_sounds_off(this._synth,void 0===e?-1:e)}midiSetChannelType(e,t){h._fluid_synth_set_channel_type(this._synth,e,t?1:0)}setReverb(e,t,s,n){h._fluid_synth_set_reverb(this._synth,e,t,s,n)}setReverbRoomsize(e){h._fluid_synth_set_reverb_roomsize(this._synth,e)}setReverbDamp(e){h._fluid_synth_set_reverb_damp(this._synth,e)}setReverbWidth(e){h._fluid_synth_set_reverb_width(this._synth,e)}setReverbLevel(e){h._fluid_synth_set_reverb_level(this._synth,e)}setReverbOn(e){h._fluid_synth_set_reverb_on(this._synth,e?1:0)}getReverbRoomsize(){return h._fluid_synth_get_reverb_roomsize(this._synth)}getReverbDamp(){return h._fluid_synth_get_reverb_damp(this._synth)}getReverbLevel(){return h._fluid_synth_get_reverb_level(this._synth)}getReverbWidth(){return h._fluid_synth_get_reverb_width(this._synth)}setChorus(e,t,s,n,i){h._fluid_synth_set_chorus(this._synth,e,t,s,n,i)}setChorusVoiceCount(e){h._fluid_synth_set_chorus_nr(this._synth,e)}setChorusLevel(e){h._fluid_synth_set_chorus_level(this._synth,e)}setChorusSpeed(e){h._fluid_synth_set_chorus_speed(this._synth,e)}setChorusDepth(e){h._fluid_synth_set_chorus_depth(this._synth,e)}setChorusType(e){h._fluid_synth_set_chorus_type(this._synth,e)}setChorusOn(e){h._fluid_synth_set_chorus_on(this._synth,e?1:0)}getChorusVoiceCount(){return h._fluid_synth_get_chorus_nr(this._synth)}getChorusLevel(){return h._fluid_synth_get_chorus_level(this._synth)}getChorusSpeed(){return h._fluid_synth_get_chorus_speed(this._synth)}getChorusDepth(){return h._fluid_synth_get_chorus_depth(this._synth)}getChorusType(){return h._fluid_synth_get_chorus_type(this._synth)}getGenerator(e,t){return h._fluid_synth_get_gen(this._synth,e,t)}setGenerator(e,t,s){h._fluid_synth_set_gen(this._synth,e,t,s)}getLegatoMode(e){return h._fluid_synth_get_legato_mode(this._synth,e,this._numPtr),h.HEAP32[this._numPtr>>2]}setLegatoMode(e,t){h._fluid_synth_set_legato_mode(this._synth,e,t)}getPortamentoMode(e){return h._fluid_synth_get_portamento_mode(this._synth,e,this._numPtr),h.HEAP32[this._numPtr>>2]}setPortamentoMode(e,t){h._fluid_synth_set_portamento_mode(this._synth,e,t)}getBreathMode(e){return h._fluid_synth_get_breath_mode(this._synth,e,this._numPtr),h.HEAP32[this._numPtr>>2]}setBreathMode(e,t){h._fluid_synth_set_breath_mode(this._synth,e,t)}resetPlayer(){return new Promise((e=>{this._initPlayer(),e()}))}closePlayer(){this._closePlayer()}_initPlayer(){this._closePlayer();const e=h._new_fluid_player(this._synth);if(this._player=e,0===e)throw new Error("Out of memory");if(null===this._fluidSynthCallback){const t=h.HEAPU32[e+588>>2];h.HEAPU32[e+592>>2]===this._synth&&(this._fluidSynthCallback=t)}}_closePlayer(){const e=this._player;0!==e&&(this.stopPlayer(),h._delete_fluid_player(e),this._player=0,this._playerCallbackPtr=null)}isPlayerPlaying(){if(this._playerPlaying){if(1===h._fluid_player_get_status(this._player))return!0;this.stopPlayer()}return!1}addSMFDataToPlayer(e){this.ensurePlayerInitialized();const t=e.byteLength,s=b(t);h.HEAPU8.set(new Uint8Array(e),s);const n=h._fluid_player_add_mem(this._player,s,t);return P(s),-1!==n?Promise.resolve():Promise.reject(new Error(p(this._synth)))}playPlayer(){if(this.ensurePlayerInitialized(),this._playerPlaying&&this.stopPlayer(),-1===h._fluid_player_play(this._player))return Promise.reject(new Error(p(this._synth)));this._playerPlaying=!0;let e=()=>{};const t=new Promise((t=>{e=t}));return this._playerDefer={promise:t,resolve:e},Promise.resolve()}stopPlayer(){const e=this._player;0!==e&&this._playerPlaying&&(h._fluid_player_stop(e),h._fluid_player_join(e),h._fluid_synth_all_sounds_off(this._synth,-1),this._playerDefer&&(this._playerDefer.resolve(),this._playerDefer=void 0),this._playerPlaying=!1)}retrievePlayerCurrentTick(){return this.ensurePlayerInitialized(),Promise.resolve(h._fluid_player_get_current_tick(this._player))}retrievePlayerTotalTicks(){return this.ensurePlayerInitialized(),Promise.resolve(h._fluid_player_get_total_ticks(this._player))}retrievePlayerBpm(){return this.ensurePlayerInitialized(),Promise.resolve(h._fluid_player_get_bpm(this._player))}retrievePlayerMIDITempo(){return this.ensurePlayerInitialized(),Promise.resolve(h._fluid_player_get_midi_tempo(this._player))}seekPlayer(e){this.ensurePlayerInitialized(),h._fluid_player_seek(this._player,e)}setPlayerLoop(e){this.ensurePlayerInitialized(),h._fluid_player_set_loop(this._player,e)}setPlayerTempo(e,t){this.ensurePlayerInitialized(),h._fluid_player_set_tempo(this._player,e,t)}hookPlayerMIDIEvents(t,s){this.ensurePlayerInitialized();const n=this._playerCallbackPtr;if(null===n&&null===t)return;const i=null!==t?a(function(t,s,n){return(i,r)=>{const _=h._fluid_midi_event_get_type(r);return s(t,_,new e(r,h),n)?0:h._fluid_synth_handle_midi_event(i,r)}}(this,t,s),"iii"):null!==this._fluidSynthCallback?null:a(w,"iii");null!==n&&null!==i?(h._fluid_player_set_playback_callback(this._player,i,this._synth),d(n)):null===i?(h._fluid_player_set_playback_callback(this._player,this._fluidSynthCallback,this._synth),d(n)):h._fluid_player_set_playback_callback(this._player,i,this._synth),this._playerCallbackPtr=i}ensureInitialized(){if(0===this._synth)throw new Error("Synthesizer is not initialized")}ensurePlayerInitialized(){this.ensureInitialized(),0===this._player&&this._initPlayer()}renderRaw(e,t,s){h._fluid_synth_write_float(this._synth,s,e,0,1,t,0,1)}flushFramesSync(){const e=262144,t=b(524288),s=t,n=t+e;for(;this.isPlaying();)this.renderRaw(s,n,65536);P(t)}flushFramesAsync(){if(!this.isPlaying())return Promise.resolve();const e=262144,t=b(524288),s=t,n=t+e,i="undefined"!=typeof setTimeout?()=>new Promise((e=>setTimeout(e,0))):()=>Promise.resolve();function r(){return i().then(l)}const _=this;function l(){return _.isPlaying()?(_.renderRaw(s,n,65536),r()):(P(t),Promise.resolve())}return r()}waitForPlayerStopped(){return this._playerDefer?this._playerDefer.promise:Promise.resolve()}static createSequencer(){A();const e=new C;return e._initialize().then((()=>e))}static registerSequencerClient(e,s,n,i){if(!(e instanceof C))throw new TypeError("Invalid sequencer instance");const r=a(((s,i,r,_)=>{const l=new t(i,h),o=h._fluid_event_get_type(i);n(s,o,l,e,_)}),"viiii"),_=v(e.getRaw(),s,r,i);return-1!==_&&(e._clientFuncMap[_]=r),_}static sendEventToClientNow(e,t,s){if(!(e instanceof C))throw new TypeError("Invalid sequencer instance");e.sendEventToClientNow(t,s)}static sendEventNow(e,t,s){if(!(e instanceof C))throw new TypeError("Invalid sequencer instance");e.sendEventNow(t,s)}static setIntervalForSequencer(e,t){if(!(e instanceof C))throw new TypeError("Invalid sequencer instance");return e.setIntervalForSequencer(t)}}function T(e){return function(e){const t={},s=[];let n=e;for(;n&&n!==Object.prototype;)s.unshift(n),n=Object.getPrototypeOf(n);return s.forEach((s=>{Object.getOwnPropertyNames(s).forEach((s=>{try{const n=e[s];"function"!=typeof n&&"symbol"!=typeof n&&(t[s]=n)}catch(e){}}))})),{baseName:e.name,message:e.message,detail:t}}(e&&e instanceof Error?e:new Error(`${e}`))}function G(e,t,s,n){const i={port:e};return t?e.addEventListener("message",(e=>{const r=e.data;r&&t.then((()=>W(i.port,r,s,n)))})):e.addEventListener("message",(e=>{const t=e.data;t&&W(i.port,t,s,n)})),e.start(),i}function W(e,t,s,n){if(n&&n(t))return;const i=s();if(i[t.method])try{O(e,t.id,t.method,i[t.method].apply(i,t.args))}catch(s){N(e,t.id,t.method,s)}else N(e,t.id,t.method,new Error("Not implemented"))}function D(e,t,s,n){O(e.port,t,s,n)}function O(e,t,s,n){n instanceof Promise?n.then((n=>{t>=0&&e.postMessage({id:t,method:s,val:n})}),(n=>{e.postMessage({id:t,method:s,error:T(n)})})):e.postMessage({id:t,method:s,val:n})}function L(e,t,s,n){N(e.port,t,s,n)}function N(e,t,s,n){e.postMessage({id:t,method:s,error:T(n)})}let j=null;const U=[],H=5,B={Panic:0,Error:1,Warning:2,Info:3,Debug:4};function x(e=B.Panic){if(j!==e){if(function(){if("undefined"!=typeof AudioWorkletGlobalScope)S=AudioWorkletGlobalScope.wasmModule;else{if("undefined"==typeof Module)throw new Error("wasm module is not available. libfluidsynth-*.js must be loaded.");S=Module}}(),null==e)null!=q&&(S._fluid_set_log_function(0,q,0),S._fluid_set_log_function(1,q,0),S._fluid_set_log_function(2,q,0),S._fluid_set_log_function(3,q,0)),S._fluid_set_log_function(4,0,0);else{let t;for(let s=e;s<H;++s){const e=S._fluid_set_log_function(s,0,0);s!==B.Debug&&(t=e)}null!=t&&null==q&&(q=t)}j=e;for(const t of U)t(e)}}var V=function(e,t,s,n){return new(s||(s=Promise))((function(i,r){function _(e){try{o(n.next(e))}catch(e){r(e)}}function l(e){try{o(n.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(_,l)}o((n=n.apply(e,t||[])).next())}))};const $=M.waitForWasmInitialized();AudioWorkletGlobalScope.JSSynth={rewriteEventData:function(e,s){if(!(e&&e instanceof t))return!1;const i=e.getRaw();return 0!==i&&n(i,s)},Synthesizer:M,disableLogging:x,restoreLogging:function(){x(null)}},AudioWorkletGlobalScope.Fluid=AudioWorkletGlobalScope.JSSynth,function(){class e extends AudioWorkletProcessor{constructor(e){super(e);const t=e.processorOptions,s=t&&t.settings;t&&t.disabledLoggingLevel&&x(t.disabledLoggingLevel);const n=this.doInit(s);this._messaging=G(this.port,n,(()=>this.synth),(e=>{switch(e.method){case"init":return this.synth.init(sampleRate,s),!0;case"createSequencer":return this.doCreateSequencer(e.args[0]).then((()=>{D(this._messaging,e.id,e.method,void 0)})),!0;case"hookPlayerMIDIEventsByName":this.doHookPlayerMIDIEvents(e.args[0],e.args[1])?D(this._messaging,e.id,e.method,void 0):L(this._messaging,e.id,e.method,new Error("Name not found"));return!0;case"callFunction":try{this.doCallFunction(e.args[0],e.args[1]),D(this._messaging,e.id,e.method,void 0)}catch(t){L(this._messaging,e.id,e.method,t)}return!0;case"getSFontObject":try{const t=this.doGetSFontObject(e.args[0],e.args[1]);null!==t?D(this._messaging,e.id,e.method,t):L(this._messaging,e.id,e.method,new Error("Invalid sfontId"))}catch(t){L(this._messaging,e.id,e.method,t)}return!0;case"playPlayer":return this.doPlayPlayer(e),!0;case"loggingChanged":return x(e.args[0]),!0}return!1}))}doInit(e){return V(this,void 0,void 0,(function*(){yield $,this.synth=new M,this.synth.init(sampleRate,e)}))}doCreateSequencer(e){return M.createSequencer().then((t=>{const s=G(e,null,(()=>t),(e=>{if("getRaw"===e.method)return D(s,e.id,e.method,t.getRaw()),!0;if("registerSequencerClientByName"===e.method){const n=this.doRegisterSequencerClient(t,e.args[0],e.args[1],e.args[2]);return null!==n?D(s,e.id,e.method,n):L(s,e.id,e.method,new Error("Name not found")),!0}return!1}))}))}doGetSFontObject(e,t){const s=this.synth.getSFontObject(t);if(null===s)return null;const n=G(e,null,(()=>s),(e=>"getPresetIterable"===e.method&&(D(n,e.id,e.method,[...s.getPresetIterable()]),!0)));return s.getName()}doPlayPlayer(e){const t=this.synth;t.playPlayer().then((()=>{D(this._messaging,-1,"updateStatus",{playing:t.isPlaying(),playerPlaying:t.isPlayerPlaying()}),D(this._messaging,e.id,e.method,void 0)}),(t=>{L(this._messaging,e.id,e.method,t)}))}doHookPlayerMIDIEvents(e,t){if(!e)return this.synth.hookPlayerMIDIEvents(null),!0;const s=AudioWorkletGlobalScope[e];return!(!s||"function"!=typeof s)&&(this.synth.hookPlayerMIDIEvents(s,t),!0)}doCallFunction(e,t){const s=AudioWorkletGlobalScope[e];if(!s||"function"!=typeof s)throw new Error("Name not found");s.call(null,this.synth,t)}doRegisterSequencerClient(e,t,s,n){const i=AudioWorkletGlobalScope[s];return i&&"function"==typeof i?M.registerSequencerClient(e,t,i,n):null}process(e,t){if(!this.synth)return!0;const s=this.synth;return s.render(t[0]),D(this._messaging,-1,"updateStatus",{playing:s.isPlaying(),playerPlaying:s.isPlayerPlaying()}),!0}}registerProcessor("fluid-js",e)}()})(); | ||
//# sourceMappingURL=js-synthesizer.worklet.min.js.map |
@@ -1,2 +0,2 @@ | ||
import { InterpolationValues } from './Constants'; | ||
import { InterpolationValues, PlayerSetTempoType } from './Constants'; | ||
import ISequencer from './ISequencer'; | ||
@@ -65,2 +65,4 @@ import ISynthesizer from './ISynthesizer'; | ||
seekPlayer(ticks: number): void; | ||
setPlayerLoop(loopTimes: number): void; | ||
setPlayerTempo(tempoType: PlayerSetTempoType, tempo: number): void; | ||
waitForPlayerStopped(): Promise<void>; | ||
@@ -67,0 +69,0 @@ /** |
@@ -195,2 +195,8 @@ import WorkletSoundfont from './WorkletSoundfont'; | ||
} | ||
setPlayerLoop(loopTimes) { | ||
MethodMessaging.postCall(this._messaging, 'setPlayerLoop', [loopTimes]); | ||
} | ||
setPlayerTempo(tempoType, tempo) { | ||
MethodMessaging.postCall(this._messaging, 'setPlayerTempo', [tempoType, tempo]); | ||
} | ||
waitForPlayerStopped() { | ||
@@ -197,0 +203,0 @@ return MethodMessaging.postCallWithPromise(this._messaging, 'waitForPlayerStopped', []); |
@@ -103,1 +103,10 @@ /** Default values for synthesizer instances */ | ||
} | ||
/** Tempo type for `Synthesizer.setPlayerTempo` */ | ||
declare const PlayerSetTempoType: { | ||
readonly Internal: 0; | ||
readonly ExternalBpm: 1; | ||
readonly ExternalMidi: 2; | ||
}; | ||
/** Tempo type for `Synthesizer.setPlayerTempo` */ | ||
declare type PlayerSetTempoType = (typeof PlayerSetTempoType)[keyof typeof PlayerSetTempoType]; | ||
export { PlayerSetTempoType }; |
@@ -1,2 +0,8 @@ | ||
export {}; | ||
/** Tempo type for `Synthesizer.setPlayerTempo` */ | ||
const PlayerSetTempoType = { | ||
Internal: 0, | ||
ExternalBpm: 1, | ||
ExternalMidi: 2, | ||
}; | ||
export { PlayerSetTempoType }; | ||
//# sourceMappingURL=Constants.js.map |
@@ -1,2 +0,2 @@ | ||
import { InterpolationValues } from './Constants'; | ||
import { InterpolationValues, PlayerSetTempoType } from './Constants'; | ||
import SynthesizerSettings from './SynthesizerSettings'; | ||
@@ -243,2 +243,13 @@ /** | ||
/** | ||
* Sets the loop for the playlist in the player. | ||
* @param loopTimes loop count (`-1` for infinite loop) | ||
*/ | ||
setPlayerLoop(loopTimes: number): void; | ||
/** | ||
* Sets the tempo for the player. | ||
* @param tempoType tempo value type for `tempo` | ||
* @param tempo tempo value | ||
*/ | ||
setPlayerTempo(tempoType: PlayerSetTempoType, tempo: number): void; | ||
/** | ||
* Wait for finishing player process. | ||
@@ -245,0 +256,0 @@ * Note that even if resolved, some voices may still be playing. |
@@ -1,2 +0,2 @@ | ||
import { InterpolationValues, ChorusModulation, GeneratorTypes, LegatoMode, PortamentoMode } from './Constants'; | ||
import { InterpolationValues, ChorusModulation, GeneratorTypes, LegatoMode, PortamentoMode, PlayerSetTempoType } from './Constants'; | ||
import IMIDIEvent from './IMIDIEvent'; | ||
@@ -229,2 +229,4 @@ import ISequencer from './ISequencer'; | ||
seekPlayer(ticks: number): void; | ||
setPlayerLoop(loopTimes: number): void; | ||
setPlayerTempo(tempoType: PlayerSetTempoType, tempo: number): void; | ||
/** | ||
@@ -231,0 +233,0 @@ * Hooks MIDI events sent by the player. |
@@ -221,3 +221,3 @@ import { INVALID_POINTER } from './PointerType'; | ||
const node = context.createScriptProcessor(frameSize, 0, 2); | ||
node.addEventListener('audioprocess', (ev) => { | ||
node.addEventListener("audioprocess", (ev) => { | ||
this.render(ev.outputBuffer); | ||
@@ -229,33 +229,33 @@ }); | ||
this.close(); | ||
const set = this._settings = _module._new_fluid_settings(); | ||
fluid_settings_setnum(set, 'synth.sample-rate', sampleRate); | ||
const set = (this._settings = _module._new_fluid_settings()); | ||
fluid_settings_setnum(set, "synth.sample-rate", sampleRate); | ||
if (settings) { | ||
if (typeof settings.initialGain !== 'undefined') { | ||
if (typeof settings.initialGain !== "undefined") { | ||
this._gain = settings.initialGain; | ||
} | ||
setBoolValueForSettings(set, 'synth.chorus.active', settings.chorusActive); | ||
setNumValueForSettings(set, 'synth.chorus.depth', settings.chorusDepth); | ||
setNumValueForSettings(set, 'synth.chorus.level', settings.chorusLevel); | ||
setIntValueForSettings(set, 'synth.chorus.nr', settings.chorusNr); | ||
setNumValueForSettings(set, 'synth.chorus.speed', settings.chorusSpeed); | ||
setIntValueForSettings(set, 'synth.midi-channels', settings.midiChannelCount); | ||
setStrValueForSettings(set, 'synth.midi-bank-select', settings.midiBankSelect); | ||
setIntValueForSettings(set, 'synth.min-note-length', settings.minNoteLength); | ||
setNumValueForSettings(set, 'synth.overflow.age', settings.overflowAge); | ||
setNumValueForSettings(set, 'synth.overflow.important', settings.overflowImportantValue); | ||
if (typeof settings.overflowImportantChannels !== 'undefined') { | ||
fluid_settings_setstr(set, 'synth.overflow.important-channels', settings.overflowImportantChannels.join(',')); | ||
setBoolValueForSettings(set, "synth.chorus.active", settings.chorusActive); | ||
setNumValueForSettings(set, "synth.chorus.depth", settings.chorusDepth); | ||
setNumValueForSettings(set, "synth.chorus.level", settings.chorusLevel); | ||
setIntValueForSettings(set, "synth.chorus.nr", settings.chorusNr); | ||
setNumValueForSettings(set, "synth.chorus.speed", settings.chorusSpeed); | ||
setIntValueForSettings(set, "synth.midi-channels", settings.midiChannelCount); | ||
setStrValueForSettings(set, "synth.midi-bank-select", settings.midiBankSelect); | ||
setIntValueForSettings(set, "synth.min-note-length", settings.minNoteLength); | ||
setNumValueForSettings(set, "synth.overflow.age", settings.overflowAge); | ||
setNumValueForSettings(set, "synth.overflow.important", settings.overflowImportantValue); | ||
if (typeof settings.overflowImportantChannels !== "undefined") { | ||
fluid_settings_setstr(set, "synth.overflow.important-channels", settings.overflowImportantChannels.join(",")); | ||
} | ||
setNumValueForSettings(set, 'synth.overflow.percussion', settings.overflowPercussion); | ||
setNumValueForSettings(set, 'synth.overflow.released', settings.overflowReleased); | ||
setNumValueForSettings(set, 'synth.overflow.sustained', settings.overflowSustained); | ||
setNumValueForSettings(set, 'synth.overflow.volume', settings.overflowVolume); | ||
setIntValueForSettings(set, 'synth.polyphony', settings.polyphony); | ||
setBoolValueForSettings(set, 'synth.reverb.active', settings.reverbActive); | ||
setNumValueForSettings(set, 'synth.reverb.damp', settings.reverbDamp); | ||
setNumValueForSettings(set, 'synth.reverb.level', settings.reverbLevel); | ||
setNumValueForSettings(set, 'synth.reverb.room-size', settings.reverbRoomSize); | ||
setNumValueForSettings(set, 'synth.reverb.width', settings.reverbWidth); | ||
setNumValueForSettings(set, "synth.overflow.percussion", settings.overflowPercussion); | ||
setNumValueForSettings(set, "synth.overflow.released", settings.overflowReleased); | ||
setNumValueForSettings(set, "synth.overflow.sustained", settings.overflowSustained); | ||
setNumValueForSettings(set, "synth.overflow.volume", settings.overflowVolume); | ||
setIntValueForSettings(set, "synth.polyphony", settings.polyphony); | ||
setBoolValueForSettings(set, "synth.reverb.active", settings.reverbActive); | ||
setNumValueForSettings(set, "synth.reverb.damp", settings.reverbDamp); | ||
setNumValueForSettings(set, "synth.reverb.level", settings.reverbLevel); | ||
setNumValueForSettings(set, "synth.reverb.room-size", settings.reverbRoomSize); | ||
setNumValueForSettings(set, "synth.reverb.width", settings.reverbWidth); | ||
} | ||
fluid_settings_setnum(set, 'synth.gain', this._gain); | ||
fluid_settings_setnum(set, "synth.gain", this._gain); | ||
this._synth = _module._new_fluid_synth(this._settings); | ||
@@ -277,8 +277,8 @@ this._numPtr = malloc(8); | ||
isPlaying() { | ||
return this._synth !== INVALID_POINTER && | ||
getActiveVoiceCount(this._synth) > 0; | ||
return (this._synth !== INVALID_POINTER && | ||
getActiveVoiceCount(this._synth) > 0); | ||
} | ||
setInterpolation(value, channel) { | ||
this.ensureInitialized(); | ||
if (typeof channel === 'undefined') { | ||
if (typeof channel === "undefined") { | ||
channel = -1; | ||
@@ -306,3 +306,3 @@ } | ||
this.ensureInitialized(); | ||
const name = makeRandomFileName('sfont', '.sf2'); | ||
const name = makeRandomFileName("sfont", ".sf2"); | ||
const ub = new Uint8Array(bin); | ||
@@ -312,5 +312,5 @@ _fs.writeFile(name, ub); | ||
_fs.unlink(name); | ||
return sfont === -1 ? | ||
Promise.reject(new Error(fluid_synth_error(this._synth))) : | ||
Promise.resolve(sfont); | ||
return sfont === -1 | ||
? Promise.reject(new Error(fluid_synth_error(this._synth))) | ||
: Promise.resolve(sfont); | ||
} | ||
@@ -348,4 +348,8 @@ unloadSFont(id) { | ||
render(outBuffer) { | ||
const frameCount = 'numberOfChannels' in outBuffer ? outBuffer.length : outBuffer[0].length; | ||
const channels = 'numberOfChannels' in outBuffer ? outBuffer.numberOfChannels : outBuffer.length; | ||
const frameCount = "numberOfChannels" in outBuffer | ||
? outBuffer.length | ||
: outBuffer[0].length; | ||
const channels = "numberOfChannels" in outBuffer | ||
? outBuffer.numberOfChannels | ||
: outBuffer.length; | ||
const sizePerChannel = 4 * frameCount; | ||
@@ -361,7 +365,10 @@ const totalSize = sizePerChannel * 2; | ||
const memLeft = this._buffer; | ||
const memRight = (this._buffer + sizePerChannel); | ||
const memRight = (this._buffer + | ||
sizePerChannel); | ||
this.renderRaw(memLeft, memRight, frameCount); | ||
const aLeft = new Float32Array(_module.HEAPU8.buffer, memLeft, frameCount); | ||
const aRight = channels >= 2 ? new Float32Array(_module.HEAPU8.buffer, memRight, frameCount) : null; | ||
if ('numberOfChannels' in outBuffer) { | ||
const aRight = channels >= 2 | ||
? new Float32Array(_module.HEAPU8.buffer, memRight, frameCount) | ||
: null; | ||
if ("numberOfChannels" in outBuffer) { | ||
if (outBuffer.copyToChannel) { | ||
@@ -373,8 +380,9 @@ outBuffer.copyToChannel(aLeft, 0, 0); | ||
} | ||
else { // copyToChannel API not exist in Safari AudioBuffer | ||
else { | ||
// copyToChannel API not exist in Safari AudioBuffer | ||
const leftData = outBuffer.getChannelData(0); | ||
aLeft.forEach((val, i) => leftData[i] = val); | ||
aLeft.forEach((val, i) => (leftData[i] = val)); | ||
if (aRight) { | ||
const rightData = outBuffer.getChannelData(1); | ||
aRight.forEach((val, i) => rightData[i] = val); | ||
aRight.forEach((val, i) => (rightData[i] = val)); | ||
} | ||
@@ -442,6 +450,6 @@ } | ||
midiAllNotesOff(chan) { | ||
_module._fluid_synth_all_notes_off(this._synth, typeof chan === 'undefined' ? -1 : chan); | ||
_module._fluid_synth_all_notes_off(this._synth, typeof chan === "undefined" ? -1 : chan); | ||
} | ||
midiAllSoundsOff(chan) { | ||
_module._fluid_synth_all_sounds_off(this._synth, typeof chan === 'undefined' ? -1 : chan); | ||
_module._fluid_synth_all_sounds_off(this._synth, typeof chan === "undefined" ? -1 : chan); | ||
} | ||
@@ -682,3 +690,3 @@ midiSetChannelType(chan, isDrum) { | ||
else { | ||
throw new Error('Out of memory'); | ||
throw new Error("Out of memory"); | ||
} | ||
@@ -714,3 +722,5 @@ } | ||
free(mem); | ||
return r !== -1 ? Promise.resolve() : Promise.reject(new Error(fluid_synth_error(this._synth))); | ||
return r !== -1 | ||
? Promise.resolve() | ||
: Promise.reject(new Error(fluid_synth_error(this._synth))); | ||
} | ||
@@ -732,3 +742,3 @@ playPlayer() { | ||
promise: p, | ||
resolve: resolver | ||
resolve: resolver, | ||
}; | ||
@@ -747,3 +757,3 @@ return Promise.resolve(); | ||
this._playerDefer.resolve(); | ||
this._playerDefer = void (0); | ||
this._playerDefer = void 0; | ||
} | ||
@@ -772,2 +782,10 @@ this._playerPlaying = false; | ||
} | ||
setPlayerLoop(loopTimes) { | ||
this.ensurePlayerInitialized(); | ||
_module._fluid_player_set_loop(this._player, loopTimes); | ||
} | ||
setPlayerTempo(tempoType, tempo) { | ||
this.ensurePlayerInitialized(); | ||
_module._fluid_player_set_tempo(this._player, tempoType, tempo); | ||
} | ||
/** | ||
@@ -785,8 +803,11 @@ * Hooks MIDI events sent by the player. | ||
} | ||
const newPtr = ( | ||
const newPtr = | ||
// if callback is specified, add function | ||
callback !== null ? _addFunction(makeMIDIEventCallback(this, callback, param), 'iii') : ( | ||
// if _fluidSynthCallback is filled, set null to use it for reset callback | ||
// if not, add function defaultMIDIEventCallback for reset | ||
this._fluidSynthCallback !== null ? null : _addFunction(defaultMIDIEventCallback, 'iii'))); | ||
callback !== null | ||
? _addFunction(makeMIDIEventCallback(this, callback, param), "iii") | ||
: // if _fluidSynthCallback is filled, set null to use it for reset callback | ||
// if not, add function defaultMIDIEventCallback for reset | ||
this._fluidSynthCallback !== null | ||
? null | ||
: _addFunction(defaultMIDIEventCallback, "iii"); | ||
// the third parameter of 'fluid_player_set_playback_callback' should be 'fluid_synth_t*' | ||
@@ -813,3 +834,3 @@ if (oldPtr !== null && newPtr !== null) { | ||
if (this._synth === INVALID_POINTER) { | ||
throw new Error('Synthesizer is not initialized'); | ||
throw new Error("Synthesizer is not initialized"); | ||
} | ||
@@ -850,9 +871,9 @@ } | ||
const memRight = (mem + size); | ||
const nextFrame = (typeof setTimeout !== 'undefined' ? | ||
() => { | ||
const nextFrame = typeof setTimeout !== "undefined" | ||
? () => { | ||
return new Promise((resolve) => setTimeout(resolve, 0)); | ||
} : | ||
() => { | ||
} | ||
: () => { | ||
return Promise.resolve(); | ||
}); | ||
}; | ||
function head() { | ||
@@ -873,3 +894,5 @@ return nextFrame().then(tail); | ||
waitForPlayerStopped() { | ||
return this._playerDefer ? this._playerDefer.promise : Promise.resolve(); | ||
return this._playerDefer | ||
? this._playerDefer.promise | ||
: Promise.resolve(); | ||
} | ||
@@ -895,3 +918,3 @@ /** | ||
if (!(seq instanceof Sequencer)) { | ||
throw new TypeError('Invalid sequencer instance'); | ||
throw new TypeError("Invalid sequencer instance"); | ||
} | ||
@@ -902,3 +925,3 @@ const ptr = _addFunction((time, ev, _seq, data) => { | ||
callback(time, type, e, seq, data); | ||
}, 'viiii'); | ||
}, "viiii"); | ||
const r = fluid_sequencer_register_client(seq.getRaw(), name, ptr, param); | ||
@@ -918,3 +941,3 @@ if (r !== -1) { | ||
if (!(seq instanceof Sequencer)) { | ||
throw new TypeError('Invalid sequencer instance'); | ||
throw new TypeError("Invalid sequencer instance"); | ||
} | ||
@@ -931,3 +954,3 @@ seq.sendEventToClientNow(clientId, event); | ||
if (!(seq instanceof Sequencer)) { | ||
throw new TypeError('Invalid sequencer instance'); | ||
throw new TypeError("Invalid sequencer instance"); | ||
} | ||
@@ -945,3 +968,3 @@ seq.sendEventNow(clientId, eventData); | ||
if (!(seq instanceof Sequencer)) { | ||
throw new TypeError('Invalid sequencer instance'); | ||
throw new TypeError("Invalid sequencer instance"); | ||
} | ||
@@ -948,0 +971,0 @@ return seq.setIntervalForSequencer(msec); |
{ | ||
"name": "js-synthesizer", | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"author": "jet", | ||
@@ -35,11 +35,12 @@ "description": "Synthesizer library for web-based JS program, using with Web Audio or etc.", | ||
"build:minified": "npm run build:ts && npm run build:lib:minified", | ||
"build:ts": "tsc -p tsconfig.json" | ||
"build:ts": "tsc -p tsconfig.json", | ||
"build-all": "npm run build:ts && npm run build:lib:dev && npm run build:lib:minified" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"ts-loader": "^9.4.2", | ||
"ts-loader": "^9.4.4", | ||
"typescript": "^4.2.4", | ||
"webpack": "^5.75.0", | ||
"webpack": "^5.88.2", | ||
"webpack-cli": "^4.10.0" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4634445
26852