js-synthesizer
Advanced tools
Comparing version 1.7.0 to 1.8.0
# Changelog | ||
## v1.8.0 | ||
- Add `waitForWasmInitialized` to wait for WebAssembly initialization (#13) | ||
- Add Soundfont object to read loaded soundfont information (including presets defined in the soundfont) (#14) | ||
- Fix AudioWorkletNodeSynthesizer playPlayer to wait for internal playPlayer done (related: #16) | ||
- Fix messaging usage on Sequence for AudioWorklet | ||
- Add support for libfluidsynth 2.2.x | ||
- Bundle libfluidsynth-2.1.9.js | ||
## v1.7.0 | ||
@@ -4,0 +13,0 @@ |
/*! | ||
js-synthesizer version 1.7.0 | ||
js-synthesizer version 1.8.0 | ||
@license | ||
Copyright (C) 2020 jet | ||
Copyright (C) 2021 jet | ||
All rights reserved. | ||
@@ -30,3 +30,3 @@ | ||
*/ | ||
!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,(function(){return function(e){var t={};function s(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=e,s.c=t,s.d=function(e,t,n){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(s.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)s.d(n,i,function(t){return e[t]}.bind(null,i));return n},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=2)}([function(e,t){},function(e,t){},function(e,t,s){"use strict";s.r(t),s.d(t,"Constants",(function(){return n})),s.d(t,"MessageError",(function(){return o})),s.d(t,"rewriteEventData",(function(){return l})),s.d(t,"SequencerEventTypes",(function(){return a})),s.d(t,"Synthesizer",(function(){return M})),s.d(t,"waitForReady",(function(){return O})),s.d(t,"AudioWorkletNodeSynthesizer",(function(){return G}));var n=s(0);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)}}var a=s(1);class h{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 u,d,c,f,y,m,g,p,v,P,b,w,S,k,C,q,I;function A(e){const t=u._new_fluid_event();return _(t,e)?t:(u._delete_fluid_event(t),null)}class E{constructor(){u||("undefined"!=typeof AudioWorkletGlobalScope?(u=AudioWorkletGlobalScope.wasmModule,d=AudioWorkletGlobalScope.wasmRemoveFunction):(u=Module,d=removeFunction),c=u.cwrap("fluid_sequencer_get_client_name","string",["number","number"])),this._seq=0,this._seqId=-1,this._clientFuncMap={}}_initialize(){return this.close(),this._seq=u._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),u._delete_fluid_sequencer(this._seq),this._seq=0)}registerSynthesizer(e){let t;if(-1!==this._seqId&&(u._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=u._fluid_sequencer_register_fluidsynth(this._seq,t),Promise.resolve(this._seqId)}unregisterClient(e){if(-1===e&&-1===(e=this._seqId))return;const t=u._new_fluid_event();if(u._fluid_event_set_source(t,-1),u._fluid_event_set_dest(t,e),u._fluid_event_unregistering(t),u._fluid_sequencer_send_now(this._seq,t),u._delete_fluid_event(t),u._fluid_sequencer_unregister_client(this._seq,e),this._seqId===e)this._seqId=-1;else{const t=this._clientFuncMap;t[e]&&(d(t[e]),delete t[e])}}getAllRegisteredClients(){const e=u._fluid_sequencer_count_clients(this._seq),t=[];for(let s=0;s<e;++s){const e=u._fluid_sequencer_get_client_id(this._seq,s),n=c(this._seq,e);t.push({clientId:e,name:n})}return Promise.resolve(t)}getClientCount(){return Promise.resolve(u._fluid_sequencer_count_clients(this._seq))}getClientInfo(e){const t=u._fluid_sequencer_get_client_id(this._seq,e),s=c(this._seq,t);return Promise.resolve({clientId:t,name:s})}setTimeScale(e){u._fluid_sequencer_set_time_scale(this._seq,e)}getTimeScale(){return Promise.resolve(u._fluid_sequencer_get_time_scale(this._seq))}getTick(){return Promise.resolve(u._fluid_sequencer_get_tick(this._seq))}sendEventAt(e,t,s){const n=A(e);if(null!==n){const e=u._fluid_sequencer_count_clients(this._seq);for(let i=0;i<e;++i){const e=u._fluid_sequencer_get_client_id(this._seq,i);u._fluid_event_set_dest(n,e),u._fluid_sequencer_send_at(this._seq,n,t,s?1:0)}u._delete_fluid_event(n)}}sendEventToClientAt(e,t,s,n){const i=A(t);null!==i&&(u._fluid_event_set_dest(i,-1===e?this._seqId:e),u._fluid_sequencer_send_at(this._seq,i,s,n?1:0),u._delete_fluid_event(i))}sendEventToClientNow(e,t){const s=A(t);null!==s&&(u._fluid_event_set_dest(s,-1===e?this._seqId:e),u._fluid_sequencer_send_now(this._seq,s),u._delete_fluid_event(s))}sendEventNow(e,t){if(!(t instanceof i))return;const s=t.getRaw();0!==s&&(u._fluid_event_set_dest(s,-1===e?this._seqId:e),u._fluid_sequencer_send_now(this._seq,s))}removeAllEvents(){u._fluid_sequencer_remove_events(this._seq,-1,-1,-1)}removeAllEventsFromClient(e){u._fluid_sequencer_remove_events(this._seq,-1,-1===e?this._seqId:e,-1)}processSequencer(e){0!==this._seq&&u._fluid_sequencer_process(this._seq,e)}setIntervalForSequencer(e){return setInterval(()=>this.processSequencer(e),e)}}function T(){b||("undefined"!=typeof AudioWorkletGlobalScope?(f=AudioWorkletGlobalScope.wasmModule,y=AudioWorkletGlobalScope.wasmAddFunction,m=AudioWorkletGlobalScope.wasmRemoveFunction):(f=Module,y=addFunction,m=removeFunction),g=f.FS,p=f.cwrap("fluid_settings_setint","number",["number","string","number"]),v=f.cwrap("fluid_settings_setnum","number",["number","string","number"]),P=f.cwrap("fluid_settings_setstr","number",["number","string","string"]),b=f.cwrap("fluid_synth_error","string",["number"]),w=f.cwrap("fluid_synth_sfload","number",["number","string","number"]),S=f.cwrap("fluid_sequencer_register_client","number",["number","string","number","number"]),k=f._malloc.bind(f),C=f._free.bind(f),q=f._fluid_synth_handle_midi_event.bind(f))}function F(e,t,s){void 0!==s&&p(e,t,s?1:0)}function z(e,t,s){void 0!==s&&p(e,t,s)}function R(e,t,s){void 0!==s&&v(e,t,s)}class M{constructor(){T(),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}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=f._new_fluid_settings();v(s,"synth.sample-rate",e),t&&(void 0!==t.initialGain&&(this._gain=t.initialGain),F(s,"synth.chorus.active",t.chorusActive),R(s,"synth.chorus.depth",t.chorusDepth),R(s,"synth.chorus.level",t.chorusLevel),z(s,"synth.chorus.nr",t.chorusNr),R(s,"synth.chorus.speed",t.chorusSpeed),z(s,"synth.midi-channels",t.midiChannelCount),function(e,t,s){void 0!==s&&P(e,t,s)}(s,"synth.midi-bank-select",t.midiBankSelect),z(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&&P(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),z(s,"synth.polyphony",t.polyphony),F(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)),v(s,"synth.gain",this._gain),this._synth=f._new_fluid_synth(this._settings),this._numPtr=k(8),this._initPlayer()}close(){0!==this._synth&&(this._closePlayer(),f._delete_fluid_synth(this._synth),this._synth=0,f._delete_fluid_settings(this._settings),this._settings=0,C(this._numPtr),this._numPtr=0)}isPlaying(){return 0!==this._synth&&function(e){const t=f._fluid_synth_get_active_voice_count(e);if(!t)return 0;const s=e+144>>2,n=f.HEAPU32[s];if(n!==t){return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t}const i=f.HEAPU32[e+140>>2];if(!i||i>=f.HEAPU32.byteLength){return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t}const r=f._fluid_synth_get_polyphony(e);let _=!1;for(let e=0;e<r;++e){const t=f.HEAPU32[(i>>2)+e];if(!t)continue;if(4!==f.HEAPU8[t+4]){_=!0;break}}if(!_){if(0!==n){console.warn("js-synthesizer: Active voice count is not zero, but all voices are off:",n)}return f.HEAPU32[s]=0,0}return t}(this._synth)>0}setInterpolation(e,t){this.ensureInitialized(),void 0===t&&(t=-1),f._fluid_synth_set_interp_method(this._synth,t,e)}getGain(){return this._gain}setGain(e){this.ensureInitialized(),f._fluid_synth_set_gain(this._synth,e),this._gain=f._fluid_synth_get_gain(this._synth)}setChannelType(e,t){this.ensureInitialized(),f._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);g.writeFile(t,n);const i=w(this._synth,t,1);return g.unlink(t),-1===i?Promise.reject(new Error(b(this._synth))):Promise.resolve(i)}unloadSFont(e){this.ensureInitialized(),this.stopPlayer(),this.flushFramesSync(),f._fluid_synth_sfunload(this._synth,e,1)}unloadSFontAsync(e){return this.ensureInitialized(),this.stopPlayer(),this.flushFramesAsync().then(()=>{f._fluid_synth_sfunload(this._synth,e,1)})}getSFontBankOffset(e){return this.ensureInitialized(),Promise.resolve(f._fluid_synth_get_bank_offset(this._synth,e))}setSFontBankOffset(e,t){this.ensureInitialized(),f._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&&C(this._buffer),this._buffer=k(i),this._bufferSize=i);const r=this._buffer,_=this._buffer+n;this.renderRaw(r,_,t);const l=new Float32Array(f.HEAPU8.buffer,r,t),o=s>=2?new Float32Array(f.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){f._fluid_synth_noteon(this._synth,e,t,s)}midiNoteOff(e,t){f._fluid_synth_noteoff(this._synth,e,t)}midiKeyPressure(e,t,s){f._fluid_synth_key_pressure(this._synth,e,t,s)}midiControl(e,t,s){f._fluid_synth_cc(this._synth,e,t,s)}midiProgramChange(e,t){f._fluid_synth_program_change(this._synth,e,t)}midiChannelPressure(e,t){f._fluid_synth_channel_pressure(this._synth,e,t)}midiPitchBend(e,t){f._fluid_synth_pitch_bend(this._synth,e,t)}midiSysEx(e){const t=e.byteLength,s=k(t);f.HEAPU8.set(e,s),f._fluid_synth_sysex(this._synth,s,t,0,0,0,0),C(s)}midiPitchWheelSensitivity(e,t){f._fluid_synth_pitch_wheel_sens(this._synth,e,t)}midiBankSelect(e,t){f._fluid_synth_bank_select(this._synth,e,t)}midiSFontSelect(e,t){f._fluid_synth_sfont_select(this._synth,e,t)}midiProgramSelect(e,t,s,n){f._fluid_synth_program_select(this._synth,e,t,s,n)}midiUnsetProgram(e){f._fluid_synth_unset_program(this._synth,e)}midiProgramReset(){f._fluid_synth_program_reset(this._synth)}midiSystemReset(){f._fluid_synth_system_reset(this._synth)}midiAllNotesOff(e){f._fluid_synth_all_notes_off(this._synth,void 0===e?-1:e)}midiAllSoundsOff(e){f._fluid_synth_all_sounds_off(this._synth,void 0===e?-1:e)}midiSetChannelType(e,t){f._fluid_synth_set_channel_type(this._synth,e,t?1:0)}setReverb(e,t,s,n){f._fluid_synth_set_reverb(this._synth,e,t,s,n)}setReverbRoomsize(e){f._fluid_synth_set_reverb_roomsize(this._synth,e)}setReverbDamp(e){f._fluid_synth_set_reverb_damp(this._synth,e)}setReverbWidth(e){f._fluid_synth_set_reverb_width(this._synth,e)}setReverbLevel(e){f._fluid_synth_set_reverb_level(this._synth,e)}setReverbOn(e){f._fluid_synth_set_reverb_on(this._synth,e?1:0)}getReverbRoomsize(){return f._fluid_synth_get_reverb_roomsize(this._synth)}getReverbDamp(){return f._fluid_synth_get_reverb_damp(this._synth)}getReverbLevel(){return f._fluid_synth_get_reverb_level(this._synth)}getReverbWidth(){return f._fluid_synth_get_reverb_width(this._synth)}setChorus(e,t,s,n,i){f._fluid_synth_set_chorus(this._synth,e,t,s,n,i)}setChorusVoiceCount(e){f._fluid_synth_set_chorus_nr(this._synth,e)}setChorusLevel(e){f._fluid_synth_set_chorus_level(this._synth,e)}setChorusSpeed(e){f._fluid_synth_set_chorus_speed(this._synth,e)}setChorusDepth(e){f._fluid_synth_set_chorus_depth(this._synth,e)}setChorusType(e){f._fluid_synth_set_chorus_type(this._synth,e)}setChorusOn(e){f._fluid_synth_set_chorus_on(this._synth,e?1:0)}getChorusVoiceCount(){return f._fluid_synth_get_chorus_nr(this._synth)}getChorusLevel(){return f._fluid_synth_get_chorus_level(this._synth)}getChorusSpeed(){return f._fluid_synth_get_chorus_speed(this._synth)}getChorusDepth(){return f._fluid_synth_get_chorus_depth(this._synth)}getChorusType(){return f._fluid_synth_get_chorus_type(this._synth)}getGenerator(e,t){return f._fluid_synth_get_gen(this._synth,e,t)}setGenerator(e,t,s){f._fluid_synth_set_gen(this._synth,e,t,s)}getLegatoMode(e){return f._fluid_synth_get_legato_mode(this._synth,e,this._numPtr),f.HEAP32[this._numPtr>>2]}setLegatoMode(e,t){f._fluid_synth_set_legato_mode(this._synth,e,t)}getPortamentoMode(e){return f._fluid_synth_get_portamento_mode(this._synth,e,this._numPtr),f.HEAP32[this._numPtr>>2]}setPortamentoMode(e,t){f._fluid_synth_set_portamento_mode(this._synth,e,t)}getBreathMode(e){return f._fluid_synth_get_breath_mode(this._synth,e,this._numPtr),f.HEAP32[this._numPtr>>2]}setBreathMode(e,t){f._fluid_synth_set_breath_mode(this._synth,e,t)}resetPlayer(){return this._initPlayer()}_initPlayer(){this._closePlayer();const e=f._new_fluid_player(this._synth);if(this._player=e,0!==e&&null===this._fluidSynthCallback){const t=f.HEAPU32[e+588>>2];f.HEAPU32[e+592>>2]===this._synth&&(this._fluidSynthCallback=t)}return 0!==e?Promise.resolve():Promise.reject(new Error("Out of memory"))}_closePlayer(){const e=this._player;0!==e&&(this.stopPlayer(),f._delete_fluid_player(e),this._player=0,this._playerCallbackPtr=null)}isPlayerPlaying(){if(this._playerPlaying){if(1===f._fluid_player_get_status(this._player))return!0;this.stopPlayer()}return!1}addSMFDataToPlayer(e){this.ensurePlayerInitialized();const t=e.byteLength,s=k(t);f.HEAPU8.set(new Uint8Array(e),s);const n=f._fluid_player_add_mem(this._player,s,t);return C(s),-1!==n?Promise.resolve():Promise.reject(new Error(b(this._synth)))}playPlayer(){if(this.ensurePlayerInitialized(),this._playerPlaying&&this.stopPlayer(),-1===f._fluid_player_play(this._player))return Promise.reject(new Error(b(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&&(f._fluid_player_stop(e),f._fluid_player_join(e),f._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(f._fluid_player_get_current_tick(this._player))}retrievePlayerTotalTicks(){return this.ensurePlayerInitialized(),Promise.resolve(f._fluid_player_get_total_ticks(this._player))}retrievePlayerBpm(){return this.ensurePlayerInitialized(),Promise.resolve(f._fluid_player_get_bpm(this._player))}retrievePlayerMIDITempo(){return this.ensurePlayerInitialized(),Promise.resolve(f._fluid_player_get_midi_tempo(this._player))}seekPlayer(e){this.ensurePlayerInitialized(),f._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?y(function(e,t,s){return(n,i)=>{const r=f._fluid_midi_event_get_type(i);return t(e,r,new h(i,f),s)?0:f._fluid_synth_handle_midi_event(n,i)}}(this,e,t),"iii"):null!==this._fluidSynthCallback?null:y(q,"iii");null!==s&&null!==n?(f._fluid_player_set_playback_callback(this._player,n,this._synth),m(s)):null===n?(f._fluid_player_set_playback_callback(this._player,this._fluidSynthCallback,this._synth),m(s)):f._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(){if(this.ensureInitialized(),0===this._player)throw new Error("Player is not initialized")}renderRaw(e,t,s){f._fluid_synth_write_float(this._synth,s,e,0,1,t,0,1)}flushFramesSync(){const e=k(524288),t=e,s=e+262144;for(;this.isPlaying();)this.renderRaw(t,s,65536);C(e)}flushFramesAsync(){if(!this.isPlaying())return Promise.resolve();const e=k(524288),t=e,s=e+262144,n="undefined"!=typeof setTimeout?()=>new Promise(e=>setTimeout(e,0)):()=>Promise.resolve();function i(){return n().then(_)}const r=this;function _(){return r.isPlaying()?(r.renderRaw(t,s,65536),i()):(C(e),Promise.resolve())}return i()}waitForPlayerStopped(){return this._playerDefer?this._playerDefer.promise:Promise.resolve()}static createSequencer(){T();const e=new E;return e._initialize().then(()=>e)}static registerSequencerClient(e,t,s,n){if(!(e instanceof E))throw new TypeError("Invalid sequencer instance");const r=y((t,n,r,_)=>{const l=new i(n,f),o=f._fluid_event_get_type(n);s(t,o,l,e,_)},"viiii"),_=S(e.getRaw(),t,r,n);return-1!==_&&(e._clientFuncMap[_]=r),_}static sendEventToClientNow(e,t,s){if(!(e instanceof E))throw new TypeError("Invalid sequencer instance");e.sendEventToClientNow(t,s)}static sendEventNow(e,t,s){if(!(e instanceof E))throw new TypeError("Invalid sequencer instance");e.sendEventNow(t,s)}static setIntervalForSequencer(e,t){if(!(e instanceof E))throw new TypeError("Invalid sequencer instance");return e.setIntervalForSequencer(t)}}function O(){if(!I){const e="undefined"!=typeof AudioWorkletGlobalScope?AudioWorkletGlobalScope.wasmModule:Module;I=new Promise(t=>{if(e.calledRun)t();else{const s=e.onRuntimeInitialized;e.onRuntimeInitialized=()=>{t(),s&&s()}}})}return I}function N(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(j(n.error)):i.resolve(n.val);else if(n.error)throw j(n.error)}(s.defers,t,e)),e.start(),s}function j(e){return new o(e.baseName,e.message,e.detail)}function D({port:e},t,s){e.postMessage({id:-1,method:t,args:s})}function B(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}});return e.port.postMessage({id:n,method:t,args:s}),i}class U{constructor(e){this._messaging=N(e)}getRaw(){return B(this._messaging,"getRaw",[])}registerSequencerClientByName(e,t,s){return this.getRaw().then(n=>B(this._messaging,"registerSequencerClientByName",[n,e,t,s]))}close(){D(this._messaging,"close",[])}registerSynthesizer(e){let t;return e instanceof G?(t=e._getRawSynthesizer(),t.then(e=>B(this._messaging,"registerSynthesizer",[e]))):Promise.reject(new TypeError("'synth' is not a compatible type instance"))}unregisterClient(e){D(this._messaging,"unregisterClient",[e])}getAllRegisteredClients(){return B(this._messaging,"getAllRegisteredClients",[])}getClientCount(){return B(this._messaging,"getClientCount",[])}getClientInfo(e){return B(this._messaging,"getClientInfo",[e])}setTimeScale(e){D(this._messaging,"setTimeScale",[e])}getTimeScale(){return B(this._messaging,"getTimeScale",[])}getTick(){return B(this._messaging,"getTick",[])}sendEventAt(e,t,s){D(this._messaging,"sendEventAt",[e,t,s])}sendEventToClientAt(e,t,s,n){D(this._messaging,"sendEventToClientAt",[e,t,s,n])}removeAllEvents(){D(this._messaging,"removeAllEvents",[])}removeAllEventsFromClient(e){D(this._messaging,"removeAllEventsFromClient",[e])}processSequencer(e){D(this._messaging,"processSequencer",[e])}}class G{constructor(){this._status={playing:!1,playerPlaying:!1},this._messaging=null,this._node=null,this._gain=.5}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}});return this._node=s,this._messaging=N(s.port,e=>"updateStatus"===e.method&&(this._status=e.val,!0)),s}isInitialized(){return null!==this._messaging}init(e,t){}close(){D(this._messaging,"init",[0])}isPlaying(){return this._status.playing}setInterpolation(e,t){D(this._messaging,"setInterpolation",[e,t])}getGain(){return this._gain}setGain(e){this._gain=e,B(this._messaging,"setGain",[e]).then(()=>B(this._messaging,"getGain",[])).then(e=>{this._gain=e})}setChannelType(e,t){D(this._messaging,"setChannelType",[e,t])}waitForVoicesStopped(){return B(this._messaging,"waitForVoicesStopped",[])}loadSFont(e){return B(this._messaging,"loadSFont",[e])}unloadSFont(e){D(this._messaging,"unloadSFont",[e])}unloadSFontAsync(e){return B(this._messaging,"unloadSFont",[e])}getSFontBankOffset(e){return B(this._messaging,"getSFontBankOffset",[e])}setSFontBankOffset(e,t){D(this._messaging,"setSFontBankOffset",[e,t])}render(){throw new Error("Unexpected call")}midiNoteOn(e,t,s){D(this._messaging,"midiNoteOn",[e,t,s])}midiNoteOff(e,t){D(this._messaging,"midiNoteOff",[e,t])}midiKeyPressure(e,t,s){D(this._messaging,"midiKeyPressure",[e,t,s])}midiControl(e,t,s){D(this._messaging,"midiControl",[e,t,s])}midiProgramChange(e,t){D(this._messaging,"midiProgramChange",[e,t])}midiChannelPressure(e,t){D(this._messaging,"midiChannelPressure",[e,t])}midiPitchBend(e,t){D(this._messaging,"midiPitchBend",[e,t])}midiSysEx(e){D(this._messaging,"midiSysEx",[e])}midiPitchWheelSensitivity(e,t){D(this._messaging,"midiPitchWheelSensitivity",[e,t])}midiBankSelect(e,t){D(this._messaging,"midiBankSelect",[e,t])}midiSFontSelect(e,t){D(this._messaging,"midiSFontSelect",[e,t])}midiProgramSelect(e,t,s,n){D(this._messaging,"midiProgramSelect",[e,t,s,n])}midiUnsetProgram(e){D(this._messaging,"midiUnsetProgram",[e])}midiProgramReset(){D(this._messaging,"midiProgramReset",[])}midiSystemReset(){D(this._messaging,"midiSystemReset",[])}midiAllNotesOff(e){D(this._messaging,"midiAllNotesOff",[e])}midiAllSoundsOff(e){D(this._messaging,"midiAllSoundsOff",[e])}midiSetChannelType(e,t){D(this._messaging,"midiSetChannelType",[e,t])}resetPlayer(){return B(this._messaging,"resetPlayer",[])}isPlayerPlaying(){return this._status.playerPlaying}addSMFDataToPlayer(e){return B(this._messaging,"addSMFDataToPlayer",[e])}playPlayer(){return B(this._messaging,"playPlayer",[])}stopPlayer(){D(this._messaging,"stopPlayer",[])}retrievePlayerCurrentTick(){return B(this._messaging,"retrievePlayerCurrentTick",[])}retrievePlayerTotalTicks(){return B(this._messaging,"retrievePlayerTotalTicks",[])}retrievePlayerBpm(){return B(this._messaging,"retrievePlayerBpm",[])}retrievePlayerMIDITempo(){return B(this._messaging,"retrievePlayerMIDITempo",[])}seekPlayer(e){D(this._messaging,"seekPlayer",[e])}waitForPlayerStopped(){return B(this._messaging,"waitForPlayerStopped",[])}createSequencer(){const e=new MessageChannel;return B(this._messaging,"createSequencer",[e.port2]).then(()=>new U(e.port1))}hookPlayerMIDIEventsByName(e,t){return B(this._messaging,"hookPlayerMIDIEventsByName",[e,t])}registerSequencerClientByName(e,t,s,n){return e instanceof U?e.registerSequencerClientByName(t,s,n):Promise.reject(new TypeError("Invalid sequencer object"))}callFunction(e,t){return B(this._messaging,"callFunction",[e,t])}_getRawSynthesizer(){return B(this._messaging,"getRawSynthesizer",[])}}}])})); | ||
!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,(function(){return(()=>{"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:()=>x,Constants:()=>s,MessageError:()=>o,SequencerEventTypes:()=>n,Synthesizer:()=>j,rewriteEventData:()=>l,waitForReady:()=>B});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,y,f,m,g,p,v,P,b,w,S,k,C,q,I,A,E;function F(e){const t=h._new_fluid_event();return _(t,e)?t:(h._delete_fluid_event(t),null)}class z{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 j))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=F(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=F(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=F(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 T{constructor(e){this._ptr=e}static getSoundfontById(e,t){c||(c="undefined"!=typeof AudioWorkletGlobalScope?AudioWorkletGlobalScope.wasmModule:Module,y=c.cwrap("fluid_sfont_get_name","string",["number"]),f=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 T(s)}getName(){return y(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:f(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:f(e),bankNum:c._fluid_preset_get_banknum(e),num:c._fluid_preset_get_num(e)}}};return{[Symbol.iterator]:()=>(e(),{next:t})}}}function R(){S||("undefined"!=typeof AudioWorkletGlobalScope?(m=AudioWorkletGlobalScope.wasmModule,g=AudioWorkletGlobalScope.wasmAddFunction,p=AudioWorkletGlobalScope.wasmRemoveFunction):(m=Module,g=addFunction,p=removeFunction),v=m.FS,P=m.cwrap("fluid_settings_setint","number",["number","string","number"]),b=m.cwrap("fluid_settings_setnum","number",["number","string","number"]),w=m.cwrap("fluid_settings_setstr","number",["number","string","string"]),S=m.cwrap("fluid_synth_error","string",["number"]),k=m.cwrap("fluid_synth_sfload","number",["number","string","number"]),C=m.cwrap("fluid_sequencer_register_client","number",["number","string","number","number"]),q=m._malloc.bind(m),I=m._free.bind(m),A=m._fluid_synth_handle_midi_event.bind(m))}function O(e,t,s){void 0!==s&&P(e,t,s?1:0)}function M(e,t,s){void 0!==s&&P(e,t,s)}function N(e,t,s){void 0!==s&&b(e,t,s)}class j{constructor(){R(),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;return"undefined"!=typeof AudioWorkletGlobalScope?(e=AudioWorkletGlobalScope.wasmModule,t=AudioWorkletGlobalScope.addOnPostRun):(e=Module,t="undefined"!=typeof addOnPostRun?addOnPostRun:void 0),e.calledRun?(E=Promise.resolve(),E):(E=new Promise(void 0===t?e=>{const t=m.onRuntimeInitialized;m.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=m._new_fluid_settings();b(s,"synth.sample-rate",e),t&&(void 0!==t.initialGain&&(this._gain=t.initialGain),O(s,"synth.chorus.active",t.chorusActive),N(s,"synth.chorus.depth",t.chorusDepth),N(s,"synth.chorus.level",t.chorusLevel),M(s,"synth.chorus.nr",t.chorusNr),N(s,"synth.chorus.speed",t.chorusSpeed),M(s,"synth.midi-channels",t.midiChannelCount),function(e,t,s){void 0!==s&&w(e,t,s)}(s,"synth.midi-bank-select",t.midiBankSelect),M(s,"synth.min-note-length",t.minNoteLength),N(s,"synth.overflow.age",t.overflowAge),N(s,"synth.overflow.important",t.overflowImportantValue),void 0!==t.overflowImportantChannels&&w(s,"synth.overflow.important-channels",t.overflowImportantChannels.join(",")),N(s,"synth.overflow.percussion",t.overflowPercussion),N(s,"synth.overflow.released",t.overflowReleased),N(s,"synth.overflow.sustained",t.overflowSustained),N(s,"synth.overflow.volume",t.overflowVolume),M(s,"synth.polyphony",t.polyphony),O(s,"synth.reverb.active",t.reverbActive),N(s,"synth.reverb.damp",t.reverbDamp),N(s,"synth.reverb.level",t.reverbLevel),N(s,"synth.reverb.room-size",t.reverbRoomSize),N(s,"synth.reverb.width",t.reverbWidth)),b(s,"synth.gain",this._gain),this._synth=m._new_fluid_synth(this._settings),this._numPtr=q(8),this._initPlayer()}close(){0!==this._synth&&(this._closePlayer(),m._delete_fluid_synth(this._synth),this._synth=0,m._delete_fluid_settings(this._settings),this._settings=0,I(this._numPtr),this._numPtr=0)}isPlaying(){return 0!==this._synth&&function(e){const t=m._fluid_synth_get_active_voice_count(e);if(!t)return 0;let s=140,n=e+s+4>>2,i=m.HEAPU32[n];if(i!==t&&(s+=4,n=e+s+4>>2,i=m.HEAPU32[n],i!==t))return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t;const r=m.HEAPU32[e+s>>2];if(!r||r>=m.HEAPU32.byteLength)return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t;const _=m._fluid_synth_get_polyphony(e);let l=!1;for(let e=0;e<_;++e){const t=m.HEAPU32[(r>>2)+e];if(t&&4!==m.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),m.HEAPU32[n]=0,0;return t}(this._synth)>0}setInterpolation(e,t){this.ensureInitialized(),void 0===t&&(t=-1),m._fluid_synth_set_interp_method(this._synth,t,e)}getGain(){return this._gain}setGain(e){this.ensureInitialized(),m._fluid_synth_set_gain(this._synth,e),this._gain=m._fluid_synth_get_gain(this._synth)}setChannelType(e,t){this.ensureInitialized(),m._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(),m._fluid_synth_sfunload(this._synth,e,1)}unloadSFontAsync(e){return this.ensureInitialized(),this.stopPlayer(),this.flushFramesAsync().then((()=>{m._fluid_synth_sfunload(this._synth,e,1)}))}getSFontObject(e){return T.getSoundfontById(this,e)}getSFontBankOffset(e){return this.ensureInitialized(),Promise.resolve(m._fluid_synth_get_bank_offset(this._synth,e))}setSFontBankOffset(e,t){this.ensureInitialized(),m._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(m.HEAPU8.buffer,r,t),o=s>=2?new Float32Array(m.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){m._fluid_synth_noteon(this._synth,e,t,s)}midiNoteOff(e,t){m._fluid_synth_noteoff(this._synth,e,t)}midiKeyPressure(e,t,s){m._fluid_synth_key_pressure(this._synth,e,t,s)}midiControl(e,t,s){m._fluid_synth_cc(this._synth,e,t,s)}midiProgramChange(e,t){m._fluid_synth_program_change(this._synth,e,t)}midiChannelPressure(e,t){m._fluid_synth_channel_pressure(this._synth,e,t)}midiPitchBend(e,t){m._fluid_synth_pitch_bend(this._synth,e,t)}midiSysEx(e){const t=e.byteLength,s=q(t);m.HEAPU8.set(e,s),m._fluid_synth_sysex(this._synth,s,t,0,0,0,0),I(s)}midiPitchWheelSensitivity(e,t){m._fluid_synth_pitch_wheel_sens(this._synth,e,t)}midiBankSelect(e,t){m._fluid_synth_bank_select(this._synth,e,t)}midiSFontSelect(e,t){m._fluid_synth_sfont_select(this._synth,e,t)}midiProgramSelect(e,t,s,n){m._fluid_synth_program_select(this._synth,e,t,s,n)}midiUnsetProgram(e){m._fluid_synth_unset_program(this._synth,e)}midiProgramReset(){m._fluid_synth_program_reset(this._synth)}midiSystemReset(){m._fluid_synth_system_reset(this._synth)}midiAllNotesOff(e){m._fluid_synth_all_notes_off(this._synth,void 0===e?-1:e)}midiAllSoundsOff(e){m._fluid_synth_all_sounds_off(this._synth,void 0===e?-1:e)}midiSetChannelType(e,t){m._fluid_synth_set_channel_type(this._synth,e,t?1:0)}setReverb(e,t,s,n){m._fluid_synth_set_reverb(this._synth,e,t,s,n)}setReverbRoomsize(e){m._fluid_synth_set_reverb_roomsize(this._synth,e)}setReverbDamp(e){m._fluid_synth_set_reverb_damp(this._synth,e)}setReverbWidth(e){m._fluid_synth_set_reverb_width(this._synth,e)}setReverbLevel(e){m._fluid_synth_set_reverb_level(this._synth,e)}setReverbOn(e){m._fluid_synth_set_reverb_on(this._synth,e?1:0)}getReverbRoomsize(){return m._fluid_synth_get_reverb_roomsize(this._synth)}getReverbDamp(){return m._fluid_synth_get_reverb_damp(this._synth)}getReverbLevel(){return m._fluid_synth_get_reverb_level(this._synth)}getReverbWidth(){return m._fluid_synth_get_reverb_width(this._synth)}setChorus(e,t,s,n,i){m._fluid_synth_set_chorus(this._synth,e,t,s,n,i)}setChorusVoiceCount(e){m._fluid_synth_set_chorus_nr(this._synth,e)}setChorusLevel(e){m._fluid_synth_set_chorus_level(this._synth,e)}setChorusSpeed(e){m._fluid_synth_set_chorus_speed(this._synth,e)}setChorusDepth(e){m._fluid_synth_set_chorus_depth(this._synth,e)}setChorusType(e){m._fluid_synth_set_chorus_type(this._synth,e)}setChorusOn(e){m._fluid_synth_set_chorus_on(this._synth,e?1:0)}getChorusVoiceCount(){return m._fluid_synth_get_chorus_nr(this._synth)}getChorusLevel(){return m._fluid_synth_get_chorus_level(this._synth)}getChorusSpeed(){return m._fluid_synth_get_chorus_speed(this._synth)}getChorusDepth(){return m._fluid_synth_get_chorus_depth(this._synth)}getChorusType(){return m._fluid_synth_get_chorus_type(this._synth)}getGenerator(e,t){return m._fluid_synth_get_gen(this._synth,e,t)}setGenerator(e,t,s){m._fluid_synth_set_gen(this._synth,e,t,s)}getLegatoMode(e){return m._fluid_synth_get_legato_mode(this._synth,e,this._numPtr),m.HEAP32[this._numPtr>>2]}setLegatoMode(e,t){m._fluid_synth_set_legato_mode(this._synth,e,t)}getPortamentoMode(e){return m._fluid_synth_get_portamento_mode(this._synth,e,this._numPtr),m.HEAP32[this._numPtr>>2]}setPortamentoMode(e,t){m._fluid_synth_set_portamento_mode(this._synth,e,t)}getBreathMode(e){return m._fluid_synth_get_breath_mode(this._synth,e,this._numPtr),m.HEAP32[this._numPtr>>2]}setBreathMode(e,t){m._fluid_synth_set_breath_mode(this._synth,e,t)}resetPlayer(){return this._initPlayer()}_initPlayer(){this._closePlayer();const e=m._new_fluid_player(this._synth);if(this._player=e,0!==e&&null===this._fluidSynthCallback){const t=m.HEAPU32[e+588>>2];m.HEAPU32[e+592>>2]===this._synth&&(this._fluidSynthCallback=t)}return 0!==e?Promise.resolve():Promise.reject(new Error("Out of memory"))}_closePlayer(){const e=this._player;0!==e&&(this.stopPlayer(),m._delete_fluid_player(e),this._player=0,this._playerCallbackPtr=null)}isPlayerPlaying(){if(this._playerPlaying){if(1===m._fluid_player_get_status(this._player))return!0;this.stopPlayer()}return!1}addSMFDataToPlayer(e){this.ensurePlayerInitialized();const t=e.byteLength,s=q(t);m.HEAPU8.set(new Uint8Array(e),s);const n=m._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===m._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&&(m._fluid_player_stop(e),m._fluid_player_join(e),m._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(m._fluid_player_get_current_tick(this._player))}retrievePlayerTotalTicks(){return this.ensurePlayerInitialized(),Promise.resolve(m._fluid_player_get_total_ticks(this._player))}retrievePlayerBpm(){return this.ensurePlayerInitialized(),Promise.resolve(m._fluid_player_get_bpm(this._player))}retrievePlayerMIDITempo(){return this.ensurePlayerInitialized(),Promise.resolve(m._fluid_player_get_midi_tempo(this._player))}seekPlayer(e){this.ensurePlayerInitialized(),m._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?g(function(e,t,s){return(n,i)=>{const r=m._fluid_midi_event_get_type(i);return t(e,r,new a(i,m),s)?0:m._fluid_synth_handle_midi_event(n,i)}}(this,e,t),"iii"):null!==this._fluidSynthCallback?null:g(A,"iii");null!==s&&null!==n?(m._fluid_player_set_playback_callback(this._player,n,this._synth),p(s)):null===n?(m._fluid_player_set_playback_callback(this._player,this._fluidSynthCallback,this._synth),p(s)):m._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(){if(this.ensureInitialized(),0===this._player)throw new Error("Player is not initialized")}renderRaw(e,t,s){m._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(){R();const e=new z;return e._initialize().then((()=>e))}static registerSequencerClient(e,t,s,n){if(!(e instanceof z))throw new TypeError("Invalid sequencer instance");const r=g(((t,n,r,_)=>{const l=new i(n,m),o=m._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 z))throw new TypeError("Invalid sequencer instance");e.sendEventToClientNow(t,s)}static sendEventNow(e,t,s){if(!(e instanceof z))throw new TypeError("Invalid sequencer instance");e.sendEventNow(t,s)}static setIntervalForSequencer(e,t){if(!(e instanceof z))throw new TypeError("Invalid sequencer instance");return e.setIntervalForSequencer(t)}}function B(){return j.waitForWasmInitialized()}function D(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(U(n.error)):i.resolve(n.val);else if(n.error)throw U(n.error)}(s.defers,t,e))),e.start(),s}function U(e){return new o(e.baseName,e.message,e.detail)}function G({port:e},t,s){e.postMessage({id:-1,method:t,args:s})}function W(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 H{constructor(e,t){this.name=t,this._messaging=D(e)}getName(){return this.name}getPreset(e,t){return W(this._messaging,"getPreset",[e,t])}getPresetIterable(){return W(this._messaging,"getPresetIterable",[])}}class L{constructor(e){this._messaging=D(e)}getRaw(){return W(this._messaging,"getRaw",[])}registerSequencerClientByName(e,t,s){return this.getRaw().then((n=>W(this._messaging,"registerSequencerClientByName",[n,e,t,s])))}close(){G(this._messaging,"close",[])}registerSynthesizer(e){let t;return e instanceof x?(t=e._getRawSynthesizer(),t.then((e=>W(this._messaging,"registerSynthesizer",[e])))):Promise.reject(new TypeError("'synth' is not a compatible type instance"))}unregisterClient(e){G(this._messaging,"unregisterClient",[e])}getAllRegisteredClients(){return W(this._messaging,"getAllRegisteredClients",[])}getClientCount(){return W(this._messaging,"getClientCount",[])}getClientInfo(e){return W(this._messaging,"getClientInfo",[e])}setTimeScale(e){G(this._messaging,"setTimeScale",[e])}getTimeScale(){return W(this._messaging,"getTimeScale",[])}getTick(){return W(this._messaging,"getTick",[])}sendEventAt(e,t,s){G(this._messaging,"sendEventAt",[e,t,s])}sendEventToClientAt(e,t,s,n){G(this._messaging,"sendEventToClientAt",[e,t,s,n])}removeAllEvents(){G(this._messaging,"removeAllEvents",[])}removeAllEventsFromClient(e){G(this._messaging,"removeAllEventsFromClient",[e])}processSequencer(e){G(this._messaging,"processSequencer",[e])}}class x{constructor(){this._status={playing:!1,playerPlaying:!1},this._messaging=null,this._node=null,this._gain=.5}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}});return this._node=s,this._messaging=D(s.port,(e=>"updateStatus"===e.method&&(this._status=e.val,!0))),s}isInitialized(){return null!==this._messaging}init(e,t){}close(){G(this._messaging,"init",[0])}isPlaying(){return this._status.playing}setInterpolation(e,t){G(this._messaging,"setInterpolation",[e,t])}getGain(){return this._gain}setGain(e){this._gain=e,W(this._messaging,"setGain",[e]).then((()=>W(this._messaging,"getGain",[]))).then((e=>{this._gain=e}))}setChannelType(e,t){G(this._messaging,"setChannelType",[e,t])}waitForVoicesStopped(){return W(this._messaging,"waitForVoicesStopped",[])}loadSFont(e){return W(this._messaging,"loadSFont",[e])}unloadSFont(e){G(this._messaging,"unloadSFont",[e])}unloadSFontAsync(e){return W(this._messaging,"unloadSFont",[e])}getSFontObject(e){const t=new MessageChannel;return W(this._messaging,"getSFontObject",[t.port2,e]).then((e=>new H(t.port1,e)))}getSFontBankOffset(e){return W(this._messaging,"getSFontBankOffset",[e])}setSFontBankOffset(e,t){G(this._messaging,"setSFontBankOffset",[e,t])}render(){throw new Error("Unexpected call")}midiNoteOn(e,t,s){G(this._messaging,"midiNoteOn",[e,t,s])}midiNoteOff(e,t){G(this._messaging,"midiNoteOff",[e,t])}midiKeyPressure(e,t,s){G(this._messaging,"midiKeyPressure",[e,t,s])}midiControl(e,t,s){G(this._messaging,"midiControl",[e,t,s])}midiProgramChange(e,t){G(this._messaging,"midiProgramChange",[e,t])}midiChannelPressure(e,t){G(this._messaging,"midiChannelPressure",[e,t])}midiPitchBend(e,t){G(this._messaging,"midiPitchBend",[e,t])}midiSysEx(e){G(this._messaging,"midiSysEx",[e])}midiPitchWheelSensitivity(e,t){G(this._messaging,"midiPitchWheelSensitivity",[e,t])}midiBankSelect(e,t){G(this._messaging,"midiBankSelect",[e,t])}midiSFontSelect(e,t){G(this._messaging,"midiSFontSelect",[e,t])}midiProgramSelect(e,t,s,n){G(this._messaging,"midiProgramSelect",[e,t,s,n])}midiUnsetProgram(e){G(this._messaging,"midiUnsetProgram",[e])}midiProgramReset(){G(this._messaging,"midiProgramReset",[])}midiSystemReset(){G(this._messaging,"midiSystemReset",[])}midiAllNotesOff(e){G(this._messaging,"midiAllNotesOff",[e])}midiAllSoundsOff(e){G(this._messaging,"midiAllSoundsOff",[e])}midiSetChannelType(e,t){G(this._messaging,"midiSetChannelType",[e,t])}resetPlayer(){return W(this._messaging,"resetPlayer",[])}isPlayerPlaying(){return this._status.playerPlaying}addSMFDataToPlayer(e){return W(this._messaging,"addSMFDataToPlayer",[e])}playPlayer(){return W(this._messaging,"playPlayer",[])}stopPlayer(){G(this._messaging,"stopPlayer",[])}retrievePlayerCurrentTick(){return W(this._messaging,"retrievePlayerCurrentTick",[])}retrievePlayerTotalTicks(){return W(this._messaging,"retrievePlayerTotalTicks",[])}retrievePlayerBpm(){return W(this._messaging,"retrievePlayerBpm",[])}retrievePlayerMIDITempo(){return W(this._messaging,"retrievePlayerMIDITempo",[])}seekPlayer(e){G(this._messaging,"seekPlayer",[e])}waitForPlayerStopped(){return W(this._messaging,"waitForPlayerStopped",[])}createSequencer(){const e=new MessageChannel;return W(this._messaging,"createSequencer",[e.port2]).then((()=>new L(e.port1)))}hookPlayerMIDIEventsByName(e,t){return W(this._messaging,"hookPlayerMIDIEventsByName",[e,t])}registerSequencerClientByName(e,t,s,n){return e instanceof L?e.registerSequencerClientByName(t,s,n):Promise.reject(new TypeError("Invalid sequencer object"))}callFunction(e,t){return W(this._messaging,"callFunction",[e,t])}_getRawSynthesizer(){return W(this._messaging,"getRawSynthesizer",[])}}return t})()})); | ||
//# sourceMappingURL=js-synthesizer.min.js.map |
/*! | ||
js-synthesizer version 1.7.0 | ||
js-synthesizer version 1.8.0 | ||
@license | ||
Copyright (C) 2020 jet | ||
Copyright (C) 2021 jet | ||
All rights reserved. | ||
@@ -29,3 +29,3 @@ | ||
OF SUCH DAMAGE. | ||
*/!function(e){var t={};function s(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,s),i.l=!0,i.exports}s.m=e,s.c=t,s.d=function(e,t,n){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(s.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)s.d(n,i,function(t){return e[t]}.bind(null,i));return n},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=0)}([function(e,t,s){"use strict";s.r(t);class n{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 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}let l,o,h,u,a,d,c,f,y,m,p,v,g,b,P,w,k;function S(e){const t=l._new_fluid_event();return _(t,e)?t:(l._delete_fluid_event(t),null)}class q{constructor(){l||("undefined"!=typeof AudioWorkletGlobalScope?(l=AudioWorkletGlobalScope.wasmModule,o=AudioWorkletGlobalScope.wasmRemoveFunction):(l=Module,o=removeFunction),h=l.cwrap("fluid_sequencer_get_client_name","string",["number","number"])),this._seq=0,this._seqId=-1,this._clientFuncMap={}}_initialize(){return this.close(),this._seq=l._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),l._delete_fluid_sequencer(this._seq),this._seq=0)}registerSynthesizer(e){let t;if(-1!==this._seqId&&(l._fluid_sequencer_unregister_client(this._seq,this._seqId),this._seqId=-1),"number"==typeof e)t=e;else{if(!(e instanceof z))return Promise.reject(new TypeError("'synth' is not a compatible type instance"));t=e.getRawSynthesizer()}return this._seqId=l._fluid_sequencer_register_fluidsynth(this._seq,t),Promise.resolve(this._seqId)}unregisterClient(e){if(-1===e&&-1===(e=this._seqId))return;const t=l._new_fluid_event();if(l._fluid_event_set_source(t,-1),l._fluid_event_set_dest(t,e),l._fluid_event_unregistering(t),l._fluid_sequencer_send_now(this._seq,t),l._delete_fluid_event(t),l._fluid_sequencer_unregister_client(this._seq,e),this._seqId===e)this._seqId=-1;else{const t=this._clientFuncMap;t[e]&&(o(t[e]),delete t[e])}}getAllRegisteredClients(){const e=l._fluid_sequencer_count_clients(this._seq),t=[];for(let s=0;s<e;++s){const e=l._fluid_sequencer_get_client_id(this._seq,s),n=h(this._seq,e);t.push({clientId:e,name:n})}return Promise.resolve(t)}getClientCount(){return Promise.resolve(l._fluid_sequencer_count_clients(this._seq))}getClientInfo(e){const t=l._fluid_sequencer_get_client_id(this._seq,e),s=h(this._seq,t);return Promise.resolve({clientId:t,name:s})}setTimeScale(e){l._fluid_sequencer_set_time_scale(this._seq,e)}getTimeScale(){return Promise.resolve(l._fluid_sequencer_get_time_scale(this._seq))}getTick(){return Promise.resolve(l._fluid_sequencer_get_tick(this._seq))}sendEventAt(e,t,s){const n=S(e);if(null!==n){const e=l._fluid_sequencer_count_clients(this._seq);for(let i=0;i<e;++i){const e=l._fluid_sequencer_get_client_id(this._seq,i);l._fluid_event_set_dest(n,e),l._fluid_sequencer_send_at(this._seq,n,t,s?1:0)}l._delete_fluid_event(n)}}sendEventToClientAt(e,t,s,n){const i=S(t);null!==i&&(l._fluid_event_set_dest(i,-1===e?this._seqId:e),l._fluid_sequencer_send_at(this._seq,i,s,n?1:0),l._delete_fluid_event(i))}sendEventToClientNow(e,t){const s=S(t);null!==s&&(l._fluid_event_set_dest(s,-1===e?this._seqId:e),l._fluid_sequencer_send_now(this._seq,s),l._delete_fluid_event(s))}sendEventNow(e,t){if(!(t instanceof i))return;const s=t.getRaw();0!==s&&(l._fluid_event_set_dest(s,-1===e?this._seqId:e),l._fluid_sequencer_send_now(this._seq,s))}removeAllEvents(){l._fluid_sequencer_remove_events(this._seq,-1,-1,-1)}removeAllEventsFromClient(e){l._fluid_sequencer_remove_events(this._seq,-1,-1===e?this._seqId:e,-1)}processSequencer(e){0!==this._seq&&l._fluid_sequencer_process(this._seq,e)}setIntervalForSequencer(e){return setInterval(()=>this.processSequencer(e),e)}}function C(){p||("undefined"!=typeof AudioWorkletGlobalScope?(u=AudioWorkletGlobalScope.wasmModule,a=AudioWorkletGlobalScope.wasmAddFunction,d=AudioWorkletGlobalScope.wasmRemoveFunction):(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"]),v=u.cwrap("fluid_synth_sfload","number",["number","string","number"]),g=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 I(e,t,s){void 0!==s&&f(e,t,s?1:0)}function E(e,t,s){void 0!==s&&f(e,t,s)}function A(e,t,s){void 0!==s&&y(e,t,s)}class z{constructor(){C(),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}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),I(s,"synth.chorus.active",t.chorusActive),A(s,"synth.chorus.depth",t.chorusDepth),A(s,"synth.chorus.level",t.chorusLevel),E(s,"synth.chorus.nr",t.chorusNr),A(s,"synth.chorus.speed",t.chorusSpeed),E(s,"synth.midi-channels",t.midiChannelCount),function(e,t,s){void 0!==s&&m(e,t,s)}(s,"synth.midi-bank-select",t.midiBankSelect),E(s,"synth.min-note-length",t.minNoteLength),A(s,"synth.overflow.age",t.overflowAge),A(s,"synth.overflow.important",t.overflowImportantValue),void 0!==t.overflowImportantChannels&&m(s,"synth.overflow.important-channels",t.overflowImportantChannels.join(",")),A(s,"synth.overflow.percussion",t.overflowPercussion),A(s,"synth.overflow.released",t.overflowReleased),A(s,"synth.overflow.sustained",t.overflowSustained),A(s,"synth.overflow.volume",t.overflowVolume),E(s,"synth.polyphony",t.polyphony),I(s,"synth.reverb.active",t.reverbActive),A(s,"synth.reverb.damp",t.reverbDamp),A(s,"synth.reverb.level",t.reverbLevel),A(s,"synth.reverb.room-size",t.reverbRoomSize),A(s,"synth.reverb.width",t.reverbWidth)),y(s,"synth.gain",this._gain),this._synth=u._new_fluid_synth(this._settings),this._numPtr=b(8),this._initPlayer()}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;const s=e+144>>2,n=u.HEAPU32[s];if(n!==t){return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t}const i=u.HEAPU32[e+140>>2];if(!i||i>=u.HEAPU32.byteLength){return console.warn("js-synthesizer: cannot check synthesizer internal data (may be changed)"),t}const r=u._fluid_synth_get_polyphony(e);let _=!1;for(let e=0;e<r;++e){const t=u.HEAPU32[(i>>2)+e];if(!t)continue;if(4!==u.HEAPU8[t+4]){_=!0;break}}if(!_){if(0!==n){console.warn("js-synthesizer: Active voice count is not zero, but all voices are off:",n)}return u.HEAPU32[s]=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=v(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)})}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 this._initPlayer()}_initPlayer(){this._closePlayer();const e=u._new_fluid_player(this._synth);if(this._player=e,0!==e&&null===this._fluidSynthCallback){const t=u.HEAPU32[e+588>>2];u.HEAPU32[e+592>>2]===this._synth&&(this._fluidSynthCallback=t)}return 0!==e?Promise.resolve():Promise.reject(new Error("Out of memory"))}_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(e,t){this.ensurePlayerInitialized();const s=this._playerCallbackPtr;if(null===s&&null===e)return;const i=null!==e?a(function(e,t,s){return(i,r)=>{const _=u._fluid_midi_event_get_type(r);return t(e,_,new n(r,u),s)?0:u._fluid_synth_handle_midi_event(i,r)}}(this,e,t),"iii"):null!==this._fluidSynthCallback?null:a(w,"iii");null!==s&&null!==i?(u._fluid_player_set_playback_callback(this._player,i,this._synth),d(s)):null===i?(u._fluid_player_set_playback_callback(this._player,this._fluidSynthCallback,this._synth),d(s)):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(){if(this.ensureInitialized(),0===this._player)throw new Error("Player is not initialized")}renderRaw(e,t,s){u._fluid_synth_write_float(this._synth,s,e,0,1,t,0,1)}flushFramesSync(){const e=b(524288),t=e,s=e+262144;for(;this.isPlaying();)this.renderRaw(t,s,65536);P(e)}flushFramesAsync(){if(!this.isPlaying())return Promise.resolve();const e=b(524288),t=e,s=e+262144,n="undefined"!=typeof setTimeout?()=>new Promise(e=>setTimeout(e,0)):()=>Promise.resolve();function i(){return n().then(_)}const r=this;function _(){return r.isPlaying()?(r.renderRaw(t,s,65536),i()):(P(e),Promise.resolve())}return i()}waitForPlayerStopped(){return this._playerDefer?this._playerDefer.promise:Promise.resolve()}static createSequencer(){C();const e=new q;return e._initialize().then(()=>e)}static registerSequencerClient(e,t,s,n){if(!(e instanceof q))throw new TypeError("Invalid sequencer instance");const r=a((t,n,r,_)=>{const l=new i(n,u),o=u._fluid_event_get_type(n);s(t,o,l,e,_)},"viiii"),_=g(e.getRaw(),t,r,n);return-1!==_&&(e._clientFuncMap[_]=r),_}static sendEventToClientNow(e,t,s){if(!(e instanceof q))throw new TypeError("Invalid sequencer instance");e.sendEventToClientNow(t,s)}static sendEventNow(e,t,s){if(!(e instanceof q))throw new TypeError("Invalid sequencer instance");e.sendEventNow(t,s)}static setIntervalForSequencer(e,t){if(!(e instanceof q))throw new TypeError("Invalid sequencer instance");return e.setIntervalForSequencer(t)}}Error;function R(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 F(e,t,s,n){const i={port:e};return t?e.addEventListener("message",e=>{const r=e.data;r&&t.then(()=>M(i.port,r,s,n))}):e.addEventListener("message",e=>{const t=e.data;t&&M(i.port,t,s,n)}),e.start(),i}function M(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){G(e,t.id,t.method,s)}else G(e,t.id,t.method,new Error("Not implemented"))}function T(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:R(n)})}):e.postMessage({id:t,method:s,val:n})}function D(e,t,s,n){G(e.port,t,s,n)}function G(e,t,s,n){e.postMessage({id:t,method:s,error:R(n)})}var j=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){e.done?i(e.value):new s((function(t){t(e.value)})).then(_,l)}o((n=n.apply(e,t||[])).next())}))};const W=function(){if(!k){const e="undefined"!=typeof AudioWorkletGlobalScope?AudioWorkletGlobalScope.wasmModule:Module;k=new Promise(t=>{if(e.calledRun)t();else{const s=e.onRuntimeInitialized;e.onRuntimeInitialized=()=>{t(),s&&s()}}})}return k}();AudioWorkletGlobalScope.JSSynth={rewriteEventData:function(e,t){if(!(e&&e instanceof i))return!1;const s=e.getRaw();return 0!==s&&_(s,t)},Synthesizer:z},AudioWorkletGlobalScope.Fluid=AudioWorkletGlobalScope.JSSynth,function(){class e extends AudioWorkletProcessor{constructor(e){super(e);const t=e.processorOptions&&e.processorOptions.settings,s=this.doInit(t);this._messaging=F(this.port,s,()=>this.synth,e=>{switch(e.method){case"init":return this.synth.init(sampleRate,t),!0;case"createSequencer":return this.doCreateSequencer(e.args[0]).then(()=>{T(this._messaging,e.id,e.method,void 0)}),!0;case"hookPlayerMIDIEventsByName":this.doHookPlayerMIDIEvents(e.args[0],e.args[1])?T(this._messaging,e.id,e.method,void 0):D(this._messaging,e.id,e.method,new Error("Name not found"));return!0;case"callFunction":try{this.doCallFunction(e.args[0],e.args[1]),T(this._messaging,e.id,e.method,void 0)}catch(t){D(this._messaging,e.id,e.method,t)}return!0}return!1})}doInit(e){return j(this,void 0,void 0,(function*(){yield W,this.synth=new z,this.synth.init(sampleRate,e)}))}doCreateSequencer(e){return z.createSequencer().then(t=>{F(e,null,()=>t,e=>{if("getRaw"===e.method)return T(this._messaging,e.id,e.method,t.getRaw()),!0;if("registerSequencerClientByName"===e.method){const s=this.doRegisterSequencerClient(t,e.args[0],e.args[1],e.args[2]);return null!==s?T(this._messaging,e.id,e.method,s):D(this._messaging,e.id,e.method,new Error("Name not found")),!0}return!1})})}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?z.registerSequencerClient(e,t,i,n):null}process(e,t){if(!this.synth)return!0;const s=this.synth;return s.render(t[0]),T(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,h,u,a,d,c,y,f,m,p,g,v,b,P,w,k;function S(e){const t=i._new_fluid_event();return n(t,e)?t:(i._delete_fluid_event(t),null)}class q{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 F))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=S(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=S(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=S(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 I{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 I(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 C(){p||("undefined"!=typeof AudioWorkletGlobalScope?(u=AudioWorkletGlobalScope.wasmModule,a=AudioWorkletGlobalScope.wasmAddFunction,d=AudioWorkletGlobalScope.wasmRemoveFunction):(u=Module,a=addFunction,d=removeFunction),c=u.FS,y=u.cwrap("fluid_settings_setint","number",["number","string","number"]),f=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 E(e,t,s){void 0!==s&&y(e,t,s?1:0)}function A(e,t,s){void 0!==s&&y(e,t,s)}function z(e,t,s){void 0!==s&&f(e,t,s)}class F{constructor(){C(),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;return"undefined"!=typeof AudioWorkletGlobalScope?(e=AudioWorkletGlobalScope.wasmModule,t=AudioWorkletGlobalScope.addOnPostRun):(e=Module,t="undefined"!=typeof addOnPostRun?addOnPostRun:void 0),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();f(s,"synth.sample-rate",e),t&&(void 0!==t.initialGain&&(this._gain=t.initialGain),E(s,"synth.chorus.active",t.chorusActive),z(s,"synth.chorus.depth",t.chorusDepth),z(s,"synth.chorus.level",t.chorusLevel),A(s,"synth.chorus.nr",t.chorusNr),z(s,"synth.chorus.speed",t.chorusSpeed),A(s,"synth.midi-channels",t.midiChannelCount),function(e,t,s){void 0!==s&&m(e,t,s)}(s,"synth.midi-bank-select",t.midiBankSelect),A(s,"synth.min-note-length",t.minNoteLength),z(s,"synth.overflow.age",t.overflowAge),z(s,"synth.overflow.important",t.overflowImportantValue),void 0!==t.overflowImportantChannels&&m(s,"synth.overflow.important-channels",t.overflowImportantChannels.join(",")),z(s,"synth.overflow.percussion",t.overflowPercussion),z(s,"synth.overflow.released",t.overflowReleased),z(s,"synth.overflow.sustained",t.overflowSustained),z(s,"synth.overflow.volume",t.overflowVolume),A(s,"synth.polyphony",t.polyphony),E(s,"synth.reverb.active",t.reverbActive),z(s,"synth.reverb.damp",t.reverbDamp),z(s,"synth.reverb.level",t.reverbLevel),z(s,"synth.reverb.room-size",t.reverbRoomSize),z(s,"synth.reverb.width",t.reverbWidth)),f(s,"synth.gain",this._gain),this._synth=u._new_fluid_synth(this._settings),this._numPtr=b(8),this._initPlayer()}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 I.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 this._initPlayer()}_initPlayer(){this._closePlayer();const e=u._new_fluid_player(this._synth);if(this._player=e,0!==e&&null===this._fluidSynthCallback){const t=u.HEAPU32[e+588>>2];u.HEAPU32[e+592>>2]===this._synth&&(this._fluidSynthCallback=t)}return 0!==e?Promise.resolve():Promise.reject(new Error("Out of memory"))}_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(){if(this.ensureInitialized(),0===this._player)throw new Error("Player is not initialized")}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(){C();const e=new q;return e._initialize().then((()=>e))}static registerSequencerClient(e,s,n,i){if(!(e instanceof q))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 q))throw new TypeError("Invalid sequencer instance");e.sendEventToClientNow(t,s)}static sendEventNow(e,t,s){if(!(e instanceof q))throw new TypeError("Invalid sequencer instance");e.sendEventNow(t,s)}static setIntervalForSequencer(e,t){if(!(e instanceof q))throw new TypeError("Invalid sequencer instance");return e.setIntervalForSequencer(t)}}Error;function R(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 M(e,t,s,n){const i={port:e};return t?e.addEventListener("message",(e=>{const r=e.data;r&&t.then((()=>T(i.port,r,s,n)))})):e.addEventListener("message",(e=>{const t=e.data;t&&T(i.port,t,s,n)})),e.start(),i}function T(e,t,s,n){if(n&&n(t))return;const i=s();if(i[t.method])try{G(e,t.id,t.method,i[t.method].apply(i,t.args))}catch(s){D(e,t.id,t.method,s)}else D(e,t.id,t.method,new Error("Not implemented"))}function O(e,t,s,n){G(e.port,t,s,n)}function G(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:R(n)})})):e.postMessage({id:t,method:s,val:n})}function W(e,t,s,n){D(e.port,t,s,n)}function D(e,t,s,n){e.postMessage({id:t,method:s,error:R(n)})}var N=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 U=F.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:F},AudioWorkletGlobalScope.Fluid=AudioWorkletGlobalScope.JSSynth,function(){class e extends AudioWorkletProcessor{constructor(e){super(e);const t=e.processorOptions&&e.processorOptions.settings,s=this.doInit(t);this._messaging=M(this.port,s,(()=>this.synth),(e=>{switch(e.method){case"init":return this.synth.init(sampleRate,t),!0;case"createSequencer":return this.doCreateSequencer(e.args[0]).then((()=>{O(this._messaging,e.id,e.method,void 0)})),!0;case"hookPlayerMIDIEventsByName":this.doHookPlayerMIDIEvents(e.args[0],e.args[1])?O(this._messaging,e.id,e.method,void 0):W(this._messaging,e.id,e.method,new Error("Name not found"));return!0;case"callFunction":try{this.doCallFunction(e.args[0],e.args[1]),O(this._messaging,e.id,e.method,void 0)}catch(t){W(this._messaging,e.id,e.method,t)}return!0;case"getSFontObject":try{const t=this.doGetSFontObject(e.args[0],e.args[1]);null!==t?O(this._messaging,e.id,e.method,t):W(this._messaging,e.id,e.method,new Error("Invalid sfontId"))}catch(t){W(this._messaging,e.id,e.method,t)}return!0;case"playPlayer":return this.doPlayPlayer(e),!0}return!1}))}doInit(e){return N(this,void 0,void 0,(function*(){yield U,this.synth=new F,this.synth.init(sampleRate,e)}))}doCreateSequencer(e){return F.createSequencer().then((t=>{const s=M(e,null,(()=>t),(e=>{if("getRaw"===e.method)return O(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?O(s,e.id,e.method,n):W(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=M(e,null,(()=>s),(e=>"getPresetIterable"===e.method&&(O(n,e.id,e.method,[...s.getPresetIterable()]),!0)));return s.getName()}doPlayPlayer(e){const t=this.synth;t.playPlayer().then((()=>{O(this._messaging,-1,"updateStatus",{playing:t.isPlaying(),playerPlaying:t.isPlayerPlaying()}),O(this._messaging,e.id,e.method,void 0)}),(t=>{W(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?F.registerSequencerClient(e,t,i,n):null}process(e,t){if(!this.synth)return!0;const s=this.synth;return s.render(t[0]),O(this._messaging,-1,"updateStatus",{playing:s.isPlaying(),playerPlaying:s.isPlayerPlaying()}),!0}}registerProcessor("fluid-js",e)}()})(); | ||
//# sourceMappingURL=js-synthesizer.worklet.min.js.map |
@@ -5,2 +5,3 @@ import { InterpolationValues } from './Constants'; | ||
import SynthesizerSettings from './SynthesizerSettings'; | ||
import WorkletSoundfont from './WorkletSoundfont'; | ||
/** An synthesizer object with AudioWorkletNode */ | ||
@@ -10,3 +11,3 @@ export default class AudioWorkletNodeSynthesizer implements ISynthesizer { | ||
/** Audio node for this synthesizer */ | ||
readonly node: AudioWorkletNode | null; | ||
get node(): AudioWorkletNode | null; | ||
/** | ||
@@ -28,2 +29,8 @@ * Create AudiWorkletNode instance | ||
unloadSFontAsync(id: number): Promise<void>; | ||
/** | ||
* Returns the `Soundfont` instance for specified SoundFont. | ||
* @param sfontId loaded SoundFont id ({@link loadSFont} returns this) | ||
* @return resolve with `Soundfont` instance (rejected if `sfontId` is not valid or loaded) | ||
*/ | ||
getSFontObject(sfontId: number): Promise<WorkletSoundfont>; | ||
getSFontBankOffset(id: number): Promise<number>; | ||
@@ -30,0 +37,0 @@ setSFontBankOffset(id: number, offset: number): void; |
@@ -0,1 +1,2 @@ | ||
import WorkletSoundfont from './WorkletSoundfont'; | ||
import WorkletSequencer from './WorkletSequencer'; | ||
@@ -82,2 +83,13 @@ import * as MethodMessaging from './MethodMessaging'; | ||
} | ||
/** | ||
* Returns the `Soundfont` instance for specified SoundFont. | ||
* @param sfontId loaded SoundFont id ({@link loadSFont} returns this) | ||
* @return resolve with `Soundfont` instance (rejected if `sfontId` is not valid or loaded) | ||
*/ | ||
getSFontObject(sfontId) { | ||
const channel = new MessageChannel(); | ||
return MethodMessaging.postCallWithPromise(this._messaging, 'getSFontObject', [channel.port2, sfontId]).then((name) => { | ||
return new WorkletSoundfont(channel.port1, name); | ||
}); | ||
} | ||
getSFontBankOffset(id) { | ||
@@ -84,0 +96,0 @@ return MethodMessaging.postCallWithPromise(this._messaging, 'getSFontBankOffset', [id]); |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=Constants.js.map |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=IMIDIEvent.js.map |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=ISequencer.js.map |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=ISynthesizer.js.map |
@@ -1,1 +0,16 @@ | ||
export {}; | ||
export interface MethodCallEventData { | ||
id: number; | ||
method: string; | ||
args: any[]; | ||
} | ||
export interface MethodReturnEventData { | ||
id: number; | ||
method: string; | ||
val: any; | ||
error?: MessageErrorData; | ||
} | ||
export interface MessageErrorData { | ||
baseName: string; | ||
message: string; | ||
detail: any; | ||
} |
@@ -83,5 +83,9 @@ import MessageError from './MessageError'; | ||
}); | ||
const transfers = []; | ||
if (args[0] instanceof MessagePort) { | ||
transfers.push(args[0]); | ||
} | ||
instance.port.postMessage({ | ||
id, method, args | ||
}); | ||
}, transfers); | ||
return promise; | ||
@@ -88,0 +92,0 @@ } |
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -53,2 +54,19 @@ }); | ||
return true; | ||
case 'getSFontObject': | ||
try { | ||
const name = this.doGetSFontObject(data.args[0], data.args[1]); | ||
if (name !== null) { | ||
postReturn(this._messaging, data.id, data.method, name); | ||
} | ||
else { | ||
postReturnError(this._messaging, data.id, data.method, new Error('Invalid sfontId')); | ||
} | ||
} | ||
catch (e) { | ||
postReturnError(this._messaging, data.id, data.method, e); | ||
} | ||
return true; | ||
case 'playPlayer': | ||
this.doPlayPlayer(data); | ||
return true; | ||
} | ||
@@ -67,6 +85,6 @@ return false; | ||
return Synthesizer.createSequencer().then((seq) => { | ||
initializeReturnPort(port, null, () => seq, (data) => { | ||
const messaging = initializeReturnPort(port, null, () => seq, (data) => { | ||
// special handle for Sequencer | ||
if (data.method === 'getRaw') { | ||
postReturn(this._messaging, data.id, data.method, seq.getRaw()); | ||
postReturn(messaging, data.id, data.method, seq.getRaw()); | ||
return true; | ||
@@ -77,6 +95,6 @@ } | ||
if (r !== null) { | ||
postReturn(this._messaging, data.id, data.method, r); | ||
postReturn(messaging, data.id, data.method, r); | ||
} | ||
else { | ||
postReturnError(this._messaging, data.id, data.method, new Error('Name not found')); | ||
postReturnError(messaging, data.id, data.method, new Error('Name not found')); | ||
} | ||
@@ -89,2 +107,28 @@ return true; | ||
} | ||
doGetSFontObject(port, sfontId) { | ||
const sfont = this.synth.getSFontObject(sfontId); | ||
if (sfont === null) { | ||
return null; | ||
} | ||
const messaging = initializeReturnPort(port, null, () => sfont, (data) => { | ||
if (data.method === 'getPresetIterable') { | ||
postReturn(messaging, data.id, data.method, [...sfont.getPresetIterable()]); | ||
return true; | ||
} | ||
return false; | ||
}); | ||
return sfont.getName(); | ||
} | ||
doPlayPlayer(data) { | ||
const syn = this.synth; | ||
syn.playPlayer().then(() => { | ||
postReturn(this._messaging, -1, "updateStatus" /* UpdateStatus */, { | ||
playing: syn.isPlaying(), | ||
playerPlaying: syn.isPlayerPlaying() | ||
}); | ||
postReturn(this._messaging, data.id, data.method, void (0)); | ||
}, (e) => { | ||
postReturnError(this._messaging, data.id, data.method, e); | ||
}); | ||
} | ||
doHookPlayerMIDIEvents(name, param) { | ||
@@ -91,0 +135,0 @@ if (!name) { |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=SequencerEvent.js.map |
@@ -8,2 +8,3 @@ import { InterpolationValues, ChorusModulation, GeneratorTypes, LegatoMode, PortamentoMode } from './Constants'; | ||
import SequencerEvent, { EventType as SequencerEventType } from './SequencerEvent'; | ||
import Soundfont from './Soundfont'; | ||
/** Hook callback function type */ | ||
@@ -36,2 +37,4 @@ export interface HookMIDIEventCallback { | ||
constructor(); | ||
/** Return the promise object that resolves when WebAssembly has been initialized */ | ||
static waitForWasmInitialized(): Promise<void>; | ||
isInitialized(): boolean; | ||
@@ -52,2 +55,8 @@ /** Return the raw synthesizer instance value (pointer for libfluidsynth). */ | ||
unloadSFontAsync(id: number): Promise<void>; | ||
/** | ||
* Returns the `Soundfont` instance for specified SoundFont. | ||
* @param sfontId loaded SoundFont id ({@link loadSFont} returns this) | ||
* @return `Soundfont` instance or `null` if `sfontId` is not valid or loaded | ||
*/ | ||
getSFontObject(sfontId: number): Soundfont | null; | ||
getSFontBankOffset(id: number): Promise<number>; | ||
@@ -54,0 +63,0 @@ setSFontBankOffset(id: number, offset: number): void; |
@@ -5,2 +5,3 @@ import { INVALID_POINTER } from './PointerType'; | ||
import SequencerEventData from './SequencerEventData'; | ||
import Soundfont from './Soundfont'; | ||
let _module; | ||
@@ -53,2 +54,39 @@ let _addFunction; | ||
} | ||
let promiseWaitForInitialized; | ||
function waitForInitialized() { | ||
if (promiseWaitForInitialized) { | ||
return promiseWaitForInitialized; | ||
} | ||
let mod; | ||
let addOnPostRunFn; | ||
if (typeof AudioWorkletGlobalScope !== 'undefined') { | ||
mod = AudioWorkletGlobalScope.wasmModule; | ||
addOnPostRunFn = AudioWorkletGlobalScope.addOnPostRun; | ||
} | ||
else { | ||
mod = Module; | ||
addOnPostRunFn = typeof addOnPostRun !== 'undefined' ? addOnPostRun : undefined; | ||
} | ||
if (mod.calledRun) { | ||
promiseWaitForInitialized = Promise.resolve(); | ||
return promiseWaitForInitialized; | ||
} | ||
if (typeof addOnPostRunFn === 'undefined') { | ||
promiseWaitForInitialized = new Promise((resolve) => { | ||
const fn = _module.onRuntimeInitialized; | ||
_module.onRuntimeInitialized = () => { | ||
resolve(); | ||
if (fn) { | ||
fn(); | ||
} | ||
}; | ||
}); | ||
} | ||
else { | ||
promiseWaitForInitialized = new Promise((resolve) => { | ||
addOnPostRunFn(resolve); | ||
}); | ||
} | ||
return promiseWaitForInitialized; | ||
} | ||
function setBoolValueForSettings(settings, name, value) { | ||
@@ -82,13 +120,25 @@ if (typeof value !== 'undefined') { | ||
// check if the structure is not changed | ||
// 144 === offset [synth->active_voice_count] | ||
const offsetOfActiveVoiceCount = (synth + 144) >> 2; | ||
const structActiveVoiceCount = _module.HEAPU32[offsetOfActiveVoiceCount]; | ||
// for fluidsynth 2.0.x-2.1.x: | ||
// 140 === offset [synth->voice] | ||
// 144 === offset [synth->active_voice_count] for | ||
// for fluidsynth 2.2.x: | ||
// 144 === offset [synth->voice] | ||
// 148 === offset [synth->active_voice_count] | ||
// first check 2.1.x structure | ||
let baseOffsetOfVoice = 140; | ||
let offsetOfActiveVoiceCount = (synth + baseOffsetOfVoice + 4) >> 2; | ||
let structActiveVoiceCount = _module.HEAPU32[offsetOfActiveVoiceCount]; | ||
if (structActiveVoiceCount !== actualCount) { | ||
// unknown structure | ||
const c = console; | ||
c.warn('js-synthesizer: cannot check synthesizer internal data (may be changed)'); | ||
return actualCount; | ||
// add 4 for 2.2.x | ||
baseOffsetOfVoice += 4; | ||
offsetOfActiveVoiceCount = (synth + baseOffsetOfVoice + 4) >> 2; | ||
structActiveVoiceCount = _module.HEAPU32[offsetOfActiveVoiceCount]; | ||
if (structActiveVoiceCount !== actualCount) { | ||
// unknown structure | ||
const c = console; | ||
c.warn('js-synthesizer: cannot check synthesizer internal data (may be changed)'); | ||
return actualCount; | ||
} | ||
} | ||
// 140 === offset [synth->voice] | ||
const voiceList = _module.HEAPU32[(synth + 140) >> 2]; | ||
const voiceList = _module.HEAPU32[(synth + baseOffsetOfVoice) >> 2]; | ||
// (voice should not be NULL) | ||
@@ -155,2 +205,6 @@ if (!voiceList || voiceList >= _module.HEAPU32.byteLength) { | ||
} | ||
/** Return the promise object that resolves when WebAssembly has been initialized */ | ||
static waitForWasmInitialized() { | ||
return waitForInitialized(); | ||
} | ||
isInitialized() { | ||
@@ -271,2 +325,10 @@ return this._synth !== INVALID_POINTER; | ||
} | ||
/** | ||
* Returns the `Soundfont` instance for specified SoundFont. | ||
* @param sfontId loaded SoundFont id ({@link loadSFont} returns this) | ||
* @return `Soundfont` instance or `null` if `sfontId` is not valid or loaded | ||
*/ | ||
getSFontObject(sfontId) { | ||
return Soundfont.getSoundfontById(this, sfontId); | ||
} | ||
getSFontBankOffset(id) { | ||
@@ -273,0 +335,0 @@ this.ensureInitialized(); |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=SynthesizerSettings.js.map |
@@ -1,2 +0,2 @@ | ||
let promiseWasmInitialized; | ||
import Synthesizer from "./Synthesizer"; | ||
/** | ||
@@ -6,22 +6,4 @@ * Returns the Promise object which resolves when the synthesizer engine is ready. | ||
export default function waitForReady() { | ||
if (!promiseWasmInitialized) { | ||
const _module = typeof AudioWorkletGlobalScope !== 'undefined' ? | ||
AudioWorkletGlobalScope.wasmModule : Module; | ||
promiseWasmInitialized = new Promise((resolve) => { | ||
if (_module.calledRun) { | ||
resolve(); | ||
} | ||
else { | ||
const fn = _module.onRuntimeInitialized; | ||
_module.onRuntimeInitialized = () => { | ||
resolve(); | ||
if (fn) { | ||
fn(); | ||
} | ||
}; | ||
} | ||
}); | ||
} | ||
return promiseWasmInitialized; | ||
return Synthesizer.waitForWasmInitialized(); | ||
} | ||
//# sourceMappingURL=waitForReady.js.map |
@@ -6,9 +6,9 @@ { | ||
"devDependencies": { | ||
"ts-loader": "^7.0.0", | ||
"typescript": "3.1.4", | ||
"webpack": "~4.42.1", | ||
"webpack-cli": "^3.3.11" | ||
"ts-loader": "^9.2.2", | ||
"typescript": "^4.2.4", | ||
"webpack": "^5.37.1", | ||
"webpack-cli": "^4.7.0" | ||
}, | ||
"engines": { | ||
"node": ">=10", | ||
"node": ">=14", | ||
"npm": ">=6" | ||
@@ -39,3 +39,3 @@ }, | ||
"build:lib:dev": "webpack --config ./build/webpack.config.js", | ||
"build:lib:minified": "webpack --config ./build/webpack.config.js --env.minified", | ||
"build:lib:minified": "webpack --config ./build/webpack.config.js --env minified", | ||
"build:minified": "npm run build:ts && npm run build:lib:minified", | ||
@@ -45,3 +45,3 @@ "build:ts": "tsc -p tsconfig.json" | ||
"types": "./dist/lib/index.d.ts", | ||
"version": "1.7.0" | ||
"version": "1.8.0" | ||
} |
@@ -18,12 +18,22 @@ [![NPM version](https://badge.fury.io/js/js-synthesizer.svg)](https://www.npmjs.com/package/js-synthesizer) | ||
Copies `dist/js-synthesizer.js` (or `dist/js-synthesizer.min.js`) and `externals/libfluidsynth-2.1.3.js` (libfluidsynth JS file) to your project, and writes `<script>` tags as following order: | ||
Copies `dist/js-synthesizer.js` (or `dist/js-synthesizer.min.js`) and `externals/libfluidsynth-2.1.9.js` (libfluidsynth JS file) to your project, and writes `<script>` tags as following order: | ||
```html | ||
<script src="libfluidsynth-2.1.3.js"></script> | ||
<script src="libfluidsynth-2.1.9.js"></script> | ||
<script src="js-synthesizer.js"></script> | ||
``` | ||
When scripts are available, you can use APIs via `JSSynth` namespace object. | ||
When scripts are available, please check whether `waitForReady` resolves. | ||
```js | ||
JSSynth.waitForReady().then(loadSynthesizer); | ||
function loadSynthesizer() { | ||
// process with JSSynth... | ||
} | ||
``` | ||
When initialized, you can use APIs via `JSSynth` namespace object. | ||
```js | ||
// Prepare the AudioContext instance | ||
@@ -77,3 +87,3 @@ var context = new AudioContext(); | ||
var context = new AudioContext(); | ||
context.audioWorklet.addModule('libfluidsynth-2.1.3.js') | ||
context.audioWorklet.addModule('libfluidsynth-2.1.9.js') | ||
.then(function () { | ||
@@ -80,0 +90,0 @@ return context.audioWorklet.addModule('js-synthesizer.worklet.js'); |
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
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
2929368
89
28732
226
12