js-synthesizer
Advanced tools
Comparing version 1.5.2 to 1.6.0
# Changelog | ||
## v1.6.0 | ||
(This version has no feature updates but the minor version is updated due to updating engine version.) | ||
- Fix required engine version (#4) | ||
- Update packages and build settings | ||
## v1.5.2 | ||
@@ -4,0 +11,0 @@ |
/*! | ||
js-synthesizer version 1.5.2 | ||
js-synthesizer version 1.6.0 | ||
@@ -30,3 +30,3 @@ @license | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["js-synthesizer"]=t():e.JSSynth=t()}(this,(function(){return function(e){var t={};function s(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,s),n.l=!0,n.exports}return s.m=e,s.c=t,s.d=function(e,t,i){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},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 i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)s.d(i,n,function(t){return e[t]}.bind(null,n));return i},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);var i=s(0);class n{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 n))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,S,w,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),i=c(this._seq,e);t.push({clientId:e,name:i})}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 i=A(e);if(null!==i){const e=u._fluid_sequencer_count_clients(this._seq);for(let n=0;n<e;++n){const e=u._fluid_sequencer_get_client_id(this._seq,n);u._fluid_event_set_dest(i,e),u._fluid_sequencer_send_at(this._seq,i,t,s?1:0)}u._delete_fluid_event(i)}}sendEventToClientAt(e,t,s,i){const n=A(t);null!==n&&(u._fluid_event_set_dest(n,-1===e?this._seqId:e),u._fluid_sequencer_send_at(this._seq,n,s,i?1:0),u._delete_fluid_event(n))}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 n))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"]),S=f.cwrap("fluid_synth_sfload","number",["number","string","number"]),w=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)),p(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&&f._fluid_synth_get_active_voice_count(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 i=new Uint8Array(e);g.writeFile(t,i);const n=S(this._synth,t,1);return g.unlink(t),-1===n?Promise.reject(new Error(b(this._synth))):Promise.resolve(n)}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,i=4*t,n=2*i;this._bufferSize<n&&(0!==this._buffer&&C(this._buffer),this._buffer=k(n),this._bufferSize=n);const r=this._buffer,_=this._buffer+i;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,i){f._fluid_synth_program_select(this._synth,e,t,s,i)}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,i){f._fluid_synth_set_reverb(this._synth,e,t,s,i)}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,i,n){f._fluid_synth_set_chorus(this._synth,e,t,s,i,n)}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 i=f._fluid_player_add_mem(this._player,s,t);return C(s),-1!==i?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 i=null!==e?y(function(e,t,s){return(i,n)=>{const r=f._fluid_midi_event_get_type(n);return t(e,r,new h(n,f),s)?0:f._fluid_synth_handle_midi_event(i,n)}}(this,e,t),"iii"):null!==this._fluidSynthCallback?null:y(q,"iii");null!==s&&null!==i?(f._fluid_player_set_playback_callback(this._player,i,this._synth),m(s)):null===i?(f._fluid_player_set_playback_callback(this._player,this._fluidSynthCallback,this._synth),m(s)):f._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){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,i="undefined"!=typeof setTimeout?()=>new Promise(e=>setTimeout(e,0)):()=>Promise.resolve();function n(){return i().then(_)}const r=this;function _(){return r.isPlaying()?(r.renderRaw(t,s,65536),n()):(C(e),Promise.resolve())}return n()}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,i){if(!(e instanceof E))throw new TypeError("Invalid sequencer instance");const r=y((t,i,r,_)=>{const l=new n(i,f),o=f._fluid_event_get_type(i);s(t,o,l,e,_)},"viiii"),_=w(e.getRaw(),t,r,i);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 i=s.data;if(!i)return;if(t&&t(i))return;const n=e[i.id];if(n)delete e[i.id],i.error?n.reject(D(i.error)):n.resolve(i.val);else if(i.error)throw D(i.error)}(s.defers,t,e)),e.start(),s}function D(e){return new o(e.baseName,e.message,e.detail)}function B({port:e},t,s){e.postMessage({id:-1,method:t,args:s})}function j(e,t,s){const i=e.deferId++;(e.deferId===1/0||e.deferId<0)&&(e.deferId=0);const n=new Promise((t,s)=>{e.defers[i]={resolve:t,reject:s}});return e.port.postMessage({id:i,method:t,args:s}),n}class G{constructor(e){this._messaging=N(e)}getRaw(){return j(this._messaging,"getRaw",[])}registerSequencerClientByName(e,t,s){return this.getRaw().then(i=>j(this._messaging,"registerSequencerClientByName",[i,e,t,s]))}close(){B(this._messaging,"close",[])}registerSynthesizer(e){let t;return e instanceof x?(t=e._getRawSynthesizer(),t.then(e=>j(this._messaging,"registerSynthesizer",[e]))):Promise.reject(new TypeError("'synth' is not a compatible type instance"))}unregisterClient(e){B(this._messaging,"unregisterClient",[e])}getAllRegisteredClients(){return j(this._messaging,"getAllRegisteredClients",[])}getClientCount(){return j(this._messaging,"getClientCount",[])}getClientInfo(e){return j(this._messaging,"getClientInfo",[e])}setTimeScale(e){B(this._messaging,"setTimeScale",[e])}getTimeScale(){return j(this._messaging,"getTimeScale",[])}getTick(){return j(this._messaging,"getTick",[])}sendEventAt(e,t,s){B(this._messaging,"sendEventAt",[e,t,s])}sendEventToClientAt(e,t,s,i){B(this._messaging,"sendEventToClientAt",[e,t,s,i])}removeAllEvents(){B(this._messaging,"removeAllEvents",[])}removeAllEventsFromClient(e){B(this._messaging,"removeAllEventsFromClient",[e])}processSequencer(e){B(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=N(s.port,e=>"updateStatus"===e.method&&(this._status=e.val,!0)),s}isInitialized(){return null!==this._messaging}init(e,t){}close(){B(this._messaging,"init",[0])}isPlaying(){return this._status.playing}setInterpolation(e,t){B(this._messaging,"setInterpolation",[e,t])}getGain(){return this._gain}setGain(e){this._gain=e,j(this._messaging,"setGain",[e]).then(()=>j(this._messaging,"getGain",[])).then(e=>{this._gain=e})}setChannelType(e,t){B(this._messaging,"setChannelType",[e,t])}waitForVoicesStopped(){return j(this._messaging,"waitForVoicesStopped",[])}loadSFont(e){return j(this._messaging,"loadSFont",[e])}unloadSFont(e){B(this._messaging,"unloadSFont",[e])}unloadSFontAsync(e){return j(this._messaging,"unloadSFont",[e])}getSFontBankOffset(e){return j(this._messaging,"getSFontBankOffset",[e])}setSFontBankOffset(e,t){B(this._messaging,"setSFontBankOffset",[e,t])}render(){throw new Error("Unexpected call")}midiNoteOn(e,t,s){B(this._messaging,"midiNoteOn",[e,t,s])}midiNoteOff(e,t){B(this._messaging,"midiNoteOff",[e,t])}midiKeyPressure(e,t,s){B(this._messaging,"midiKeyPressure",[e,t,s])}midiControl(e,t,s){B(this._messaging,"midiControl",[e,t,s])}midiProgramChange(e,t){B(this._messaging,"midiProgramChange",[e,t])}midiChannelPressure(e,t){B(this._messaging,"midiChannelPressure",[e,t])}midiPitchBend(e,t){B(this._messaging,"midiPitchBend",[e,t])}midiSysEx(e){B(this._messaging,"midiSysEx",[e])}midiPitchWheelSensitivity(e,t){B(this._messaging,"midiPitchWheelSensitivity",[e,t])}midiBankSelect(e,t){B(this._messaging,"midiBankSelect",[e,t])}midiSFontSelect(e,t){B(this._messaging,"midiSFontSelect",[e,t])}midiProgramSelect(e,t,s,i){B(this._messaging,"midiProgramSelect",[e,t,s,i])}midiUnsetProgram(e){B(this._messaging,"midiUnsetProgram",[e])}midiProgramReset(){B(this._messaging,"midiProgramReset",[])}midiSystemReset(){B(this._messaging,"midiSystemReset",[])}midiAllNotesOff(e){B(this._messaging,"midiAllNotesOff",[e])}midiAllSoundsOff(e){B(this._messaging,"midiAllSoundsOff",[e])}midiSetChannelType(e,t){B(this._messaging,"midiSetChannelType",[e,t])}resetPlayer(){return j(this._messaging,"resetPlayer",[])}isPlayerPlaying(){return this._status.playerPlaying}addSMFDataToPlayer(e){return j(this._messaging,"addSMFDataToPlayer",[e])}playPlayer(){return j(this._messaging,"playPlayer",[])}stopPlayer(){B(this._messaging,"stopPlayer",[])}retrievePlayerCurrentTick(){return j(this._messaging,"retrievePlayerCurrentTick",[])}retrievePlayerTotalTicks(){return j(this._messaging,"retrievePlayerTotalTicks",[])}retrievePlayerBpm(){return j(this._messaging,"retrievePlayerBpm",[])}retrievePlayerMIDITempo(){return j(this._messaging,"retrievePlayerMIDITempo",[])}seekPlayer(e){B(this._messaging,"seekPlayer",[e])}waitForPlayerStopped(){return j(this._messaging,"waitForPlayerStopped",[])}createSequencer(){const e=new MessageChannel;return j(this._messaging,"createSequencer",[e.port2]).then(()=>new G(e.port1))}hookPlayerMIDIEventsByName(e,t){return j(this._messaging,"hookPlayerMIDIEventsByName",[e,t])}registerSequencerClientByName(e,t,s,i){return e instanceof G?e.registerSequencerClientByName(t,s,i):Promise.reject(new TypeError("Invalid sequencer object"))}callFunction(e,t){return j(this._messaging,"callFunction",[e,t])}_getRawSynthesizer(){return j(this._messaging,"getRawSynthesizer",[])}}s.d(t,"Constants",(function(){return i})),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 x}))}])})); | ||
!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(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,s),n.l=!0,n.exports}return s.m=e,s.c=t,s.d=function(e,t,i){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},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 i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)s.d(i,n,function(t){return e[t]}.bind(null,n));return i},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 i})),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 x}));var i=s(0);class n{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 n))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,S,w,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),i=c(this._seq,e);t.push({clientId:e,name:i})}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 i=A(e);if(null!==i){const e=u._fluid_sequencer_count_clients(this._seq);for(let n=0;n<e;++n){const e=u._fluid_sequencer_get_client_id(this._seq,n);u._fluid_event_set_dest(i,e),u._fluid_sequencer_send_at(this._seq,i,t,s?1:0)}u._delete_fluid_event(i)}}sendEventToClientAt(e,t,s,i){const n=A(t);null!==n&&(u._fluid_event_set_dest(n,-1===e?this._seqId:e),u._fluid_sequencer_send_at(this._seq,n,s,i?1:0),u._delete_fluid_event(n))}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 n))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"]),S=f.cwrap("fluid_synth_sfload","number",["number","string","number"]),w=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)),p(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&&f._fluid_synth_get_active_voice_count(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 i=new Uint8Array(e);g.writeFile(t,i);const n=S(this._synth,t,1);return g.unlink(t),-1===n?Promise.reject(new Error(b(this._synth))):Promise.resolve(n)}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,i=4*t,n=2*i;this._bufferSize<n&&(0!==this._buffer&&C(this._buffer),this._buffer=k(n),this._bufferSize=n);const r=this._buffer,_=this._buffer+i;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,i){f._fluid_synth_program_select(this._synth,e,t,s,i)}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,i){f._fluid_synth_set_reverb(this._synth,e,t,s,i)}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,i,n){f._fluid_synth_set_chorus(this._synth,e,t,s,i,n)}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 i=f._fluid_player_add_mem(this._player,s,t);return C(s),-1!==i?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 i=null!==e?y(function(e,t,s){return(i,n)=>{const r=f._fluid_midi_event_get_type(n);return t(e,r,new h(n,f),s)?0:f._fluid_synth_handle_midi_event(i,n)}}(this,e,t),"iii"):null!==this._fluidSynthCallback?null:y(q,"iii");null!==s&&null!==i?(f._fluid_player_set_playback_callback(this._player,i,this._synth),m(s)):null===i?(f._fluid_player_set_playback_callback(this._player,this._fluidSynthCallback,this._synth),m(s)):f._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){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,i="undefined"!=typeof setTimeout?()=>new Promise(e=>setTimeout(e,0)):()=>Promise.resolve();function n(){return i().then(_)}const r=this;function _(){return r.isPlaying()?(r.renderRaw(t,s,65536),n()):(C(e),Promise.resolve())}return n()}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,i){if(!(e instanceof E))throw new TypeError("Invalid sequencer instance");const r=y((t,i,r,_)=>{const l=new n(i,f),o=f._fluid_event_get_type(i);s(t,o,l,e,_)},"viiii"),_=w(e.getRaw(),t,r,i);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 i=s.data;if(!i)return;if(t&&t(i))return;const n=e[i.id];if(n)delete e[i.id],i.error?n.reject(D(i.error)):n.resolve(i.val);else if(i.error)throw D(i.error)}(s.defers,t,e)),e.start(),s}function D(e){return new o(e.baseName,e.message,e.detail)}function B({port:e},t,s){e.postMessage({id:-1,method:t,args:s})}function j(e,t,s){const i=e.deferId++;(e.deferId===1/0||e.deferId<0)&&(e.deferId=0);const n=new Promise((t,s)=>{e.defers[i]={resolve:t,reject:s}});return e.port.postMessage({id:i,method:t,args:s}),n}class G{constructor(e){this._messaging=N(e)}getRaw(){return j(this._messaging,"getRaw",[])}registerSequencerClientByName(e,t,s){return this.getRaw().then(i=>j(this._messaging,"registerSequencerClientByName",[i,e,t,s]))}close(){B(this._messaging,"close",[])}registerSynthesizer(e){let t;return e instanceof x?(t=e._getRawSynthesizer(),t.then(e=>j(this._messaging,"registerSynthesizer",[e]))):Promise.reject(new TypeError("'synth' is not a compatible type instance"))}unregisterClient(e){B(this._messaging,"unregisterClient",[e])}getAllRegisteredClients(){return j(this._messaging,"getAllRegisteredClients",[])}getClientCount(){return j(this._messaging,"getClientCount",[])}getClientInfo(e){return j(this._messaging,"getClientInfo",[e])}setTimeScale(e){B(this._messaging,"setTimeScale",[e])}getTimeScale(){return j(this._messaging,"getTimeScale",[])}getTick(){return j(this._messaging,"getTick",[])}sendEventAt(e,t,s){B(this._messaging,"sendEventAt",[e,t,s])}sendEventToClientAt(e,t,s,i){B(this._messaging,"sendEventToClientAt",[e,t,s,i])}removeAllEvents(){B(this._messaging,"removeAllEvents",[])}removeAllEventsFromClient(e){B(this._messaging,"removeAllEventsFromClient",[e])}processSequencer(e){B(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=N(s.port,e=>"updateStatus"===e.method&&(this._status=e.val,!0)),s}isInitialized(){return null!==this._messaging}init(e,t){}close(){B(this._messaging,"init",[0])}isPlaying(){return this._status.playing}setInterpolation(e,t){B(this._messaging,"setInterpolation",[e,t])}getGain(){return this._gain}setGain(e){this._gain=e,j(this._messaging,"setGain",[e]).then(()=>j(this._messaging,"getGain",[])).then(e=>{this._gain=e})}setChannelType(e,t){B(this._messaging,"setChannelType",[e,t])}waitForVoicesStopped(){return j(this._messaging,"waitForVoicesStopped",[])}loadSFont(e){return j(this._messaging,"loadSFont",[e])}unloadSFont(e){B(this._messaging,"unloadSFont",[e])}unloadSFontAsync(e){return j(this._messaging,"unloadSFont",[e])}getSFontBankOffset(e){return j(this._messaging,"getSFontBankOffset",[e])}setSFontBankOffset(e,t){B(this._messaging,"setSFontBankOffset",[e,t])}render(){throw new Error("Unexpected call")}midiNoteOn(e,t,s){B(this._messaging,"midiNoteOn",[e,t,s])}midiNoteOff(e,t){B(this._messaging,"midiNoteOff",[e,t])}midiKeyPressure(e,t,s){B(this._messaging,"midiKeyPressure",[e,t,s])}midiControl(e,t,s){B(this._messaging,"midiControl",[e,t,s])}midiProgramChange(e,t){B(this._messaging,"midiProgramChange",[e,t])}midiChannelPressure(e,t){B(this._messaging,"midiChannelPressure",[e,t])}midiPitchBend(e,t){B(this._messaging,"midiPitchBend",[e,t])}midiSysEx(e){B(this._messaging,"midiSysEx",[e])}midiPitchWheelSensitivity(e,t){B(this._messaging,"midiPitchWheelSensitivity",[e,t])}midiBankSelect(e,t){B(this._messaging,"midiBankSelect",[e,t])}midiSFontSelect(e,t){B(this._messaging,"midiSFontSelect",[e,t])}midiProgramSelect(e,t,s,i){B(this._messaging,"midiProgramSelect",[e,t,s,i])}midiUnsetProgram(e){B(this._messaging,"midiUnsetProgram",[e])}midiProgramReset(){B(this._messaging,"midiProgramReset",[])}midiSystemReset(){B(this._messaging,"midiSystemReset",[])}midiAllNotesOff(e){B(this._messaging,"midiAllNotesOff",[e])}midiAllSoundsOff(e){B(this._messaging,"midiAllSoundsOff",[e])}midiSetChannelType(e,t){B(this._messaging,"midiSetChannelType",[e,t])}resetPlayer(){return j(this._messaging,"resetPlayer",[])}isPlayerPlaying(){return this._status.playerPlaying}addSMFDataToPlayer(e){return j(this._messaging,"addSMFDataToPlayer",[e])}playPlayer(){return j(this._messaging,"playPlayer",[])}stopPlayer(){B(this._messaging,"stopPlayer",[])}retrievePlayerCurrentTick(){return j(this._messaging,"retrievePlayerCurrentTick",[])}retrievePlayerTotalTicks(){return j(this._messaging,"retrievePlayerTotalTicks",[])}retrievePlayerBpm(){return j(this._messaging,"retrievePlayerBpm",[])}retrievePlayerMIDITempo(){return j(this._messaging,"retrievePlayerMIDITempo",[])}seekPlayer(e){B(this._messaging,"seekPlayer",[e])}waitForPlayerStopped(){return j(this._messaging,"waitForPlayerStopped",[])}createSequencer(){const e=new MessageChannel;return j(this._messaging,"createSequencer",[e.port2]).then(()=>new G(e.port1))}hookPlayerMIDIEventsByName(e,t){return j(this._messaging,"hookPlayerMIDIEventsByName",[e,t])}registerSequencerClientByName(e,t,s,i){return e instanceof G?e.registerSequencerClientByName(t,s,i):Promise.reject(new TypeError("Invalid sequencer object"))}callFunction(e,t){return j(this._messaging,"callFunction",[e,t])}_getRawSynthesizer(){return j(this._messaging,"getRawSynthesizer",[])}}}])})); | ||
//# sourceMappingURL=js-synthesizer.min.js.map |
/*! | ||
js-synthesizer version 1.5.2 | ||
js-synthesizer version 1.6.0 | ||
@@ -29,3 +29,3 @@ @license | ||
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)),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&&u._fluid_synth_get_active_voice_count(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 W=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 N=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 W(this,void 0,void 0,(function*(){yield N,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)}()}]); | ||
*/!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)),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&&u._fluid_synth_get_active_voice_count(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 W=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 N=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 W(this,void 0,void 0,(function*(){yield N,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)}()}]); | ||
//# sourceMappingURL=js-synthesizer.worklet.min.js.map |
{ | ||
"author": "jet", | ||
"betterScripts": { | ||
"build:lib:dev": { | ||
"command": "webpack --config ./build/webpack.config.js" | ||
}, | ||
"build:lib:minified": { | ||
"command": "webpack --config ./build/webpack.config.js", | ||
"env": { | ||
"NODE_ENV": "minified" | ||
} | ||
} | ||
}, | ||
"dependencies": {}, | ||
"description": "Synthesizer library for web-based JS program, using with Web Audio or etc.", | ||
"devDependencies": { | ||
"better-npm-run": "^0.1.1", | ||
"ts-loader": "^6.2.1", | ||
"ts-loader": "^7.0.0", | ||
"typescript": "3.1.4", | ||
"webpack": "4.41.5", | ||
"webpack-cli": "^3.3.10" | ||
"webpack": "~4.42.1", | ||
"webpack-cli": "^3.3.11" | ||
}, | ||
"engines": { | ||
"node": "10", | ||
"node": ">=10", | ||
"npm": ">=6" | ||
@@ -49,4 +37,4 @@ }, | ||
"build": "npm run build:ts && npm run build:lib:dev", | ||
"build:lib:dev": "better-npm-run build:lib:dev", | ||
"build:lib:minified": "better-npm-run build:lib:minified", | ||
"build:lib:dev": "webpack --config ./build/webpack.config.js", | ||
"build:lib:minified": "webpack --config ./build/webpack.config.js --env.minified", | ||
"build:minified": "npm run build:ts && npm run build:lib:minified", | ||
@@ -56,3 +44,3 @@ "build:ts": "tsc -p tsconfig.json" | ||
"types": "./dist/lib/index.d.ts", | ||
"version": "1.5.2" | ||
"version": "1.6.0" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
4
14104
1583686