supersonic-scsynth 0.20.1 → 0.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- var o={},o=o||{};(function(){"use strict";o.SECS_70YRS=2208988800,o.TWO_32=4294967296,o.defaults={metadata:!1,unpackSingleArgs:!0},o.isCommonJS=!!(typeof module<"u"&&module.exports),o.isNode=o.isCommonJS&&typeof window>"u",o.isElectron=!!(typeof process<"u"&&process.versions&&process.versions.electron),o.isBufferEnv=o.isNode||o.isElectron,o.isArray=function(i){return i&&Object.prototype.toString.call(i)==="[object Array]"},o.isTypedArrayView=function(i){return i.buffer&&i.buffer instanceof ArrayBuffer},o.isBuffer=function(i){return o.isBufferEnv&&i instanceof Buffer},o.Long=typeof Long<"u"?Long:void 0,o.TextDecoder=typeof TextDecoder<"u"?new TextDecoder("utf-8"):typeof util<"u"&&typeof(util.TextDecoder!=="undefined")?new util.TextDecoder("utf-8"):void 0,o.TextEncoder=typeof TextEncoder<"u"?new TextEncoder("utf-8"):typeof util<"u"&&typeof(util.TextEncoder!=="undefined")?new util.TextEncoder("utf-8"):void 0,o.dataView=function(i,e,t){return i.buffer?new DataView(i.buffer,e,t):i instanceof ArrayBuffer?new DataView(i,e,t):new DataView(new Uint8Array(i),e,t)},o.byteArray=function(i){if(i instanceof Uint8Array)return i;var e=i.buffer?i.buffer:i;if(!(e instanceof ArrayBuffer)&&(typeof e.length>"u"||typeof e=="string"))throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: "+JSON.stringify(i,null,2));return new Uint8Array(e)},o.nativeBuffer=function(i){return o.isBufferEnv?o.isBuffer(i)?i:Buffer.from(i.buffer?i:new Uint8Array(i)):o.isTypedArrayView(i)?i:new Uint8Array(i)},o.copyByteArray=function(i,e,t){if(o.isTypedArrayView(i)&&o.isTypedArrayView(e))e.set(i,t);else for(var r=t===void 0?0:t,s=Math.min(e.length-t,i.length),n=0,a=r;n<s;n++,a++)e[a]=i[n];return e},o.readString=function(i,e){for(var t=[],r=e.idx;r<i.byteLength;r++){var s=i.getUint8(r);if(s!==0)t.push(s);else{r++;break}}r=r+3&-4,e.idx=r;var n=o.isBufferEnv?o.readString.withBuffer:o.TextDecoder?o.readString.withTextDecoder:o.readString.raw;return n(t)},o.readString.raw=function(i){for(var e="",t=1e4,r=0;r<i.length;r+=t)e+=String.fromCharCode.apply(null,i.slice(r,r+t));return e},o.readString.withTextDecoder=function(i){var e=new Int8Array(i);return o.TextDecoder.decode(e)},o.readString.withBuffer=function(i){return Buffer.from(i).toString("utf-8")},o.writeString=function(i){var e=o.isBufferEnv?o.writeString.withBuffer:o.TextEncoder?o.writeString.withTextEncoder:null,t=i+"\0",r;e&&(r=e(t));for(var s=e?r.length:t.length,n=s+3&-4,a=new Uint8Array(n),c=0;c<s-1;c++){var l=e?r[c]:t.charCodeAt(c);a[c]=l}return a},o.writeString.withTextEncoder=function(i){return o.TextEncoder.encode(i)},o.writeString.withBuffer=function(i){return Buffer.from(i)},o.readPrimitive=function(i,e,t,r){var s=i[e](r.idx,!1);return r.idx+=t,s},o.writePrimitive=function(i,e,t,r,s){s=s===void 0?0:s;var n;return e?n=new Uint8Array(e.buffer):(n=new Uint8Array(r),e=new DataView(n.buffer)),e[t](s,i,!1),n},o.readInt32=function(i,e){return o.readPrimitive(i,"getInt32",4,e)},o.writeInt32=function(i,e,t){return o.writePrimitive(i,e,"setInt32",4,t)},o.readInt64=function(i,e){var t=o.readPrimitive(i,"getInt32",4,e),r=o.readPrimitive(i,"getInt32",4,e);return o.Long?new o.Long(r,t):{high:t,low:r,unsigned:!1}},o.writeInt64=function(i,e,t){var r=new Uint8Array(8);return r.set(o.writePrimitive(i.high,e,"setInt32",4,t),0),r.set(o.writePrimitive(i.low,e,"setInt32",4,t+4),4),r},o.readFloat32=function(i,e){return o.readPrimitive(i,"getFloat32",4,e)},o.writeFloat32=function(i,e,t){return o.writePrimitive(i,e,"setFloat32",4,t)},o.readFloat64=function(i,e){return o.readPrimitive(i,"getFloat64",8,e)},o.writeFloat64=function(i,e,t){return o.writePrimitive(i,e,"setFloat64",8,t)},o.readChar32=function(i,e){var t=o.readPrimitive(i,"getUint32",4,e);return String.fromCharCode(t)},o.writeChar32=function(i,e,t){var r=i.charCodeAt(0);if(!(r===void 0||r<-1))return o.writePrimitive(r,e,"setUint32",4,t)},o.readBlob=function(i,e){var t=o.readInt32(i,e),r=t+3&-4,s=new Uint8Array(i.buffer,e.idx,t);return e.idx+=r,s},o.writeBlob=function(i){i=o.byteArray(i);var e=i.byteLength,t=e+3&-4,r=4,s=t+r,n=new Uint8Array(s),a=new DataView(n.buffer);return o.writeInt32(e,a),n.set(i,r),n},o.readMIDIBytes=function(i,e){var t=new Uint8Array(i.buffer,e.idx,4);return e.idx+=4,t},o.writeMIDIBytes=function(i){i=o.byteArray(i);var e=new Uint8Array(4);return e.set(i),e},o.readColor=function(i,e){var t=new Uint8Array(i.buffer,e.idx,4),r=t[3]/255;return e.idx+=4,{r:t[0],g:t[1],b:t[2],a:r}},o.writeColor=function(i){var e=Math.round(i.a*255),t=new Uint8Array([i.r,i.g,i.b,e]);return t},o.readTrue=function(){return!0},o.readFalse=function(){return!1},o.readNull=function(){return null},o.readImpulse=function(){return 1},o.readTimeTag=function(i,e){var t=o.readPrimitive(i,"getUint32",4,e),r=o.readPrimitive(i,"getUint32",4,e),s=t===0&&r===1?Date.now():o.ntpToJSTime(t,r);return{raw:[t,r],native:s}},o.writeTimeTag=function(i){var e=i.raw?i.raw:o.jsToNTPTime(i.native),t=new Uint8Array(8),r=new DataView(t.buffer);return o.writeInt32(e[0],r,0),o.writeInt32(e[1],r,4),t},o.timeTag=function(i,e){i=i||0,e=e||Date.now();var t=e/1e3,r=Math.floor(t),s=t-r,n=Math.floor(i),a=i-n,c=s+a;if(c>1){var l=Math.floor(c),u=c-l;n+=l,c=u}var h=r+n+o.SECS_70YRS,f=Math.round(o.TWO_32*c);return{raw:[h,f]}},o.ntpToJSTime=function(i,e){var t=i-o.SECS_70YRS,r=e/o.TWO_32,s=(t+r)*1e3;return s},o.jsToNTPTime=function(i){var e=i/1e3,t=Math.floor(e),r=e-t,s=t+o.SECS_70YRS,n=Math.round(o.TWO_32*r);return[s,n]},o.readArguments=function(i,e,t){var r=o.readString(i,t);if(r.indexOf(",")!==0)throw new Error("A malformed type tag string was found while reading the arguments of an OSC message. String was: "+r," at offset: "+t.idx);var s=r.substring(1).split(""),n=[];return o.readArgumentsIntoArray(n,s,r,i,e,t),n},o.readArgument=function(i,e,t,r,s){var n=o.argumentTypes[i];if(!n)throw new Error("'"+i+"' is not a valid OSC type tag. Type tag string was: "+e);var a=n.reader,c=o[a](t,s);return r.metadata&&(c={type:i,value:c}),c},o.readArgumentsIntoArray=function(i,e,t,r,s,n){for(var a=0;a<e.length;){var c=e[a],l;if(c==="["){var u=e.slice(a+1),h=u.indexOf("]");if(h<0)throw new Error("Invalid argument type tag: an open array type tag ('[') was found without a matching close array tag ('[]'). Type tag was: "+t);var f=u.slice(0,h);l=o.readArgumentsIntoArray([],f,t,r,s,n),a+=h+2}else l=o.readArgument(c,t,r,s,n),a++;i.push(l)}return i},o.writeArguments=function(i,e){var t=o.collectArguments(i,e);return o.joinParts(t)},o.joinParts=function(i){for(var e=new Uint8Array(i.byteLength),t=i.parts,r=0,s=0;s<t.length;s++){var n=t[s];o.copyByteArray(n,e,r),r+=n.length}return e},o.addDataPart=function(i,e){e.parts.push(i),e.byteLength+=i.length},o.writeArrayArguments=function(i,e){for(var t="[",r=0;r<i.length;r++){var s=i[r];t+=o.writeArgument(s,e)}return t+="]",t},o.writeArgument=function(i,e){if(o.isArray(i))return o.writeArrayArguments(i,e);var t=i.type,r=o.argumentTypes[t].writer;if(r){var s=o[r](i.value);o.addDataPart(s,e)}return i.type},o.collectArguments=function(i,e,t){o.isArray(i)||(i=typeof i>"u"?[]:[i]),t=t||{byteLength:0,parts:[]},e.metadata||(i=o.annotateArguments(i));for(var r=",",s=t.parts.length,n=0;n<i.length;n++){var a=i[n];r+=o.writeArgument(a,t)}var c=o.writeString(r);return t.byteLength+=c.byteLength,t.parts.splice(s,0,c),t},o.readMessage=function(i,e,t){e=e||o.defaults;var r=o.dataView(i,i.byteOffset,i.byteLength);t=t||{idx:0};var s=o.readString(r,t);return o.readMessageContents(s,r,e,t)},o.readMessageContents=function(i,e,t,r){if(i.indexOf("/")!==0)throw new Error("A malformed OSC address was found while reading an OSC message. String was: "+i);var s=o.readArguments(e,t,r);return{address:i,args:s.length===1&&t.unpackSingleArgs?s[0]:s}},o.collectMessageParts=function(i,e,t){return t=t||{byteLength:0,parts:[]},o.addDataPart(o.writeString(i.address),t),o.collectArguments(i.args,e,t)},o.writeMessage=function(i,e){if(e=e||o.defaults,!o.isValidMessage(i))throw new Error("An OSC message must contain a valid address. Message was: "+JSON.stringify(i,null,2));var t=o.collectMessageParts(i,e);return o.joinParts(t)},o.isValidMessage=function(i){return i.address&&i.address.indexOf("/")===0},o.readBundle=function(i,e,t){return o.readPacket(i,e,t)},o.collectBundlePackets=function(i,e,t){t=t||{byteLength:0,parts:[]},o.addDataPart(o.writeString("#bundle"),t),o.addDataPart(o.writeTimeTag(i.timeTag),t);for(var r=0;r<i.packets.length;r++){var s=i.packets[r],n=s.address?o.collectMessageParts:o.collectBundlePackets,a=n(s,e);t.byteLength+=a.byteLength,o.addDataPart(o.writeInt32(a.byteLength),t),t.parts=t.parts.concat(a.parts)}return t},o.writeBundle=function(i,e){if(!o.isValidBundle(i))throw new Error("An OSC bundle must contain 'timeTag' and 'packets' properties. Bundle was: "+JSON.stringify(i,null,2));e=e||o.defaults;var t=o.collectBundlePackets(i,e);return o.joinParts(t)},o.isValidBundle=function(i){return i.timeTag!==void 0&&i.packets!==void 0},o.readBundleContents=function(i,e,t,r){for(var s=o.readTimeTag(i,t),n=[];t.idx<r;){var a=o.readInt32(i,t),c=t.idx+a,l=o.readPacket(i,e,t,c);n.push(l)}return{timeTag:s,packets:n}},o.readPacket=function(i,e,t,r){var s=o.dataView(i,i.byteOffset,i.byteLength);r=r===void 0?s.byteLength:r,t=t||{idx:0};var n=o.readString(s,t),a=n[0];if(a==="#")return o.readBundleContents(s,e,t,r);if(a==="/")return o.readMessageContents(n,s,e,t);throw new Error("The header of an OSC packet didn't contain an OSC address or a #bundle string. Header was: "+n)},o.writePacket=function(i,e){if(o.isValidMessage(i))return o.writeMessage(i,e);if(o.isValidBundle(i))return o.writeBundle(i,e);throw new Error("The specified packet was not recognized as a valid OSC message or bundle. Packet was: "+JSON.stringify(i,null,2))},o.argumentTypes={i:{reader:"readInt32",writer:"writeInt32"},h:{reader:"readInt64",writer:"writeInt64"},f:{reader:"readFloat32",writer:"writeFloat32"},s:{reader:"readString",writer:"writeString"},S:{reader:"readString",writer:"writeString"},b:{reader:"readBlob",writer:"writeBlob"},t:{reader:"readTimeTag",writer:"writeTimeTag"},T:{reader:"readTrue"},F:{reader:"readFalse"},N:{reader:"readNull"},I:{reader:"readImpulse"},d:{reader:"readFloat64",writer:"writeFloat64"},c:{reader:"readChar32",writer:"writeChar32"},r:{reader:"readColor",writer:"writeColor"},m:{reader:"readMIDIBytes",writer:"writeMIDIBytes"}},o.inferTypeForArgument=function(i){var e=typeof i;switch(e){case"boolean":return i?"T":"F";case"string":return"s";case"number":return"f";case"undefined":return"N";case"object":if(i===null)return"N";if(i instanceof Uint8Array||i instanceof ArrayBuffer)return"b";if(typeof i.high=="number"&&typeof i.low=="number")return"h";break}throw new Error("Can't infer OSC argument type for value: "+JSON.stringify(i,null,2))},o.annotateArguments=function(i){for(var e=[],t=0;t<i.length;t++){var r=i[t],s;if(typeof r=="object"&&r.type&&r.value!==void 0)s=r;else if(o.isArray(r))s=o.annotateArguments(r);else{var n=o.inferTypeForArgument(r);s={type:n,value:r}}e.push(s)}return e}})();var R=function(){};R.prototype.on=function(){};R.prototype.emit=function(){};R.prototype.removeListener=function(){};(function(){"use strict";o.supportsSerial=!1,o.firePacketEvents=function(e,t,r,s){t.address?e.emit("message",t,r,s):o.fireBundleEvents(e,t,r,s)},o.fireBundleEvents=function(e,t,r,s){e.emit("bundle",t,r,s);for(var n=0;n<t.packets.length;n++){var a=t.packets[n];o.firePacketEvents(e,a,t.timeTag,s)}},o.fireClosedPortSendError=function(e,t){t=t||"Can't send packets on a closed osc.Port object. Please open (or reopen) this Port by calling open().",e.emit("error",t)},o.Port=function(e){this.options=e||{},this.on("data",this.decodeOSC.bind(this))};var i=o.Port.prototype=Object.create(R.prototype);i.constructor=o.Port,i.send=function(e){var t=Array.prototype.slice.call(arguments),r=this.encodeOSC(e),s=o.nativeBuffer(r);t[0]=s,this.sendRaw.apply(this,t)},i.encodeOSC=function(e){e=e.buffer?e.buffer:e;var t;try{t=o.writePacket(e,this.options)}catch(r){this.emit("error",r)}return t},i.decodeOSC=function(e,t){e=o.byteArray(e),this.emit("raw",e,t);try{var r=o.readPacket(e,this.options);this.emit("osc",r,t),o.firePacketEvents(this,r,void 0,t)}catch(s){this.emit("error",s)}},o.SLIPPort=function(e){var t=this,r=this.options=e||{};r.useSLIP=r.useSLIP===void 0?!0:r.useSLIP,this.decoder=new slip.Decoder({onMessage:this.decodeOSC.bind(this),onError:function(n){t.emit("error",n)}});var s=r.useSLIP?this.decodeSLIPData:this.decodeOSC;this.on("data",s.bind(this))},i=o.SLIPPort.prototype=Object.create(o.Port.prototype),i.constructor=o.SLIPPort,i.encodeOSC=function(e){e=e.buffer?e.buffer:e;var t;try{var r=o.writePacket(e,this.options);t=slip.encode(r)}catch(s){this.emit("error",s)}return t},i.decodeSLIPData=function(e,t){this.decoder.decode(e,t)},o.relay=function(e,t,r,s,n,a){r=r||"message",s=s||"send",n=n||function(){},a=a?[null].concat(a):[];var c=function(l){a[0]=l,l=n(l),t[s].apply(t,a)};return e.on(r,c),{eventName:r,listener:c}},o.relayPorts=function(e,t,r){var s=r.raw?"raw":"osc",n=r.raw?"sendRaw":"send";return o.relay(e,t,s,n,r.transform)},o.stopRelaying=function(e,t){e.removeListener(t.eventName,t.listener)},o.Relay=function(e,t,r){var s=this.options=r||{};s.raw=!1,this.port1=e,this.port2=t,this.listen()},i=o.Relay.prototype=Object.create(R.prototype),i.constructor=o.Relay,i.open=function(){this.port1.open(),this.port2.open()},i.listen=function(){this.port1Spec&&this.port2Spec&&this.close(),this.port1Spec=o.relayPorts(this.port1,this.port2,this.options),this.port2Spec=o.relayPorts(this.port2,this.port1,this.options);var e=this.close.bind(this);this.port1.on("close",e),this.port2.on("close",e)},i.close=function(){o.stopRelaying(this.port1,this.port1Spec),o.stopRelaying(this.port2,this.port2Spec),this.emit("close",this.port1,this.port2)}})();(function(){"use strict";o.WebSocket=typeof WebSocket<"u"?WebSocket:void 0,o.WebSocketPort=function(e){o.Port.call(this,e),this.on("open",this.listen.bind(this)),this.socket=e.socket,this.socket&&(this.socket.readyState===1?(o.WebSocketPort.setupSocketForBinary(this.socket),this.emit("open",this.socket)):this.open())};var i=o.WebSocketPort.prototype=Object.create(o.Port.prototype);i.constructor=o.WebSocketPort,i.open=function(){(!this.socket||this.socket.readyState>1)&&(this.socket=new o.WebSocket(this.options.url)),o.WebSocketPort.setupSocketForBinary(this.socket);var e=this;this.socket.onopen=function(){e.emit("open",e.socket)},this.socket.onerror=function(t){e.emit("error",t)}},i.listen=function(){var e=this;this.socket.onmessage=function(t){e.emit("data",t.data,t)},this.socket.onclose=function(t){e.emit("close",t)},e.emit("ready")},i.sendRaw=function(e){if(!this.socket||this.socket.readyState!==1){o.fireClosedPortSendError(this);return}this.socket.send(e)},i.close=function(e,t){this.socket.close(e,t)},o.WebSocketPort.setupSocketForBinary=function(e){e.binaryType=o.isNode?"nodebuffer":"arraybuffer"}})();var O=o,{readPacket:et,writePacket:tt,readMessage:rt,writeMessage:st,readBundle:it,writeBundle:nt}=o;var C=class{constructor(e=null){this.workerBaseURL=e,this.workers={oscOut:null,oscIn:null,debug:null},this.callbacks={onRawOSC:null,onParsedOSC:null,onDebugMessage:null,onError:null,onInitialized:null},this.initialized=!1,this.sharedBuffer=null,this.ringBufferBase=null,this.bufferConstants=null}async init(e,t,r,s={}){if(this.initialized){console.warn("[ScsynthOSC] Already initialized");return}this.sharedBuffer=e,this.ringBufferBase=t,this.bufferConstants=r,this.preschedulerCapacity=s.preschedulerCapacity||65536;try{this.workers.oscOut=new Worker(this.workerBaseURL+"osc_out_prescheduler_worker.js",{type:"module"}),this.workers.oscIn=new Worker(this.workerBaseURL+"osc_in_worker.js",{type:"module"}),this.workers.debug=new Worker(this.workerBaseURL+"debug_worker.js",{type:"module"}),this.setupWorkerHandlers();let n=[this.initWorker(this.workers.oscOut,"OSC SCHEDULER+WRITER",{maxPendingMessages:this.preschedulerCapacity}),this.initWorker(this.workers.oscIn,"OSC IN"),this.initWorker(this.workers.debug,"DEBUG")];await Promise.all(n),this.workers.oscIn.postMessage({type:"start"}),this.workers.debug.postMessage({type:"start"}),this.initialized=!0,this.callbacks.onInitialized&&this.callbacks.onInitialized()}catch(n){throw console.error("[ScsynthOSC] Initialization failed:",n),this.callbacks.onError&&this.callbacks.onError(n),n}}initWorker(e,t,r={}){return new Promise((s,n)=>{let a=setTimeout(()=>{n(new Error(`${t} worker initialization timeout`))},5e3),c=l=>{l.data.type==="initialized"&&(clearTimeout(a),e.removeEventListener("message",c),s())};e.addEventListener("message",c),e.postMessage({type:"init",sharedBuffer:this.sharedBuffer,ringBufferBase:this.ringBufferBase,bufferConstants:this.bufferConstants,...r})})}setupWorkerHandlers(){this.workers.oscIn.onmessage=e=>{let t=e.data;switch(t.type){case"messages":t.messages.forEach(r=>{if(r.oscData&&(this.callbacks.onRawOSC&&this.callbacks.onRawOSC({oscData:r.oscData,sequence:r.sequence}),this.callbacks.onParsedOSC))try{let s={metadata:!1,unpackSingleArgs:!1},n=O.readPacket(r.oscData,s);this.callbacks.onParsedOSC(n)}catch(s){console.error("[ScsynthOSC] Failed to decode OSC message:",s,r)}});break;case"error":console.error("[ScsynthOSC] OSC IN error:",t.error),this.callbacks.onError&&this.callbacks.onError(t.error,"oscIn");break}},this.workers.debug.onmessage=e=>{let t=e.data;switch(t.type){case"debug":this.callbacks.onDebugMessage&&t.messages.forEach(r=>{this.callbacks.onDebugMessage(r)});break;case"error":console.error("[ScsynthOSC] DEBUG error:",t.error),this.callbacks.onError&&this.callbacks.onError(t.error,"debug");break}},this.workers.oscOut.onmessage=e=>{let t=e.data;switch(t.type){case"error":console.error("[ScsynthOSC] OSC OUT error:",t.error),this.callbacks.onError&&this.callbacks.onError(t.error,"oscOut");break}}}send(e,t={}){if(!this.initialized){console.error("[ScsynthOSC] Not initialized");return}let{sessionId:r=0,runTag:s="",audioTimeS:n=null,currentTimeS:a=null}=t;this.workers.oscOut.postMessage({type:"send",oscData:e,sessionId:r,runTag:s,audioTimeS:n,currentTimeS:a})}sendImmediate(e){if(!this.initialized){console.error("[ScsynthOSC] Not initialized");return}this.workers.oscOut.postMessage({type:"sendImmediate",oscData:e})}cancelSessionTag(e,t){this.initialized&&this.workers.oscOut.postMessage({type:"cancelSessionTag",sessionId:e,runTag:t})}cancelSession(e){this.initialized&&this.workers.oscOut.postMessage({type:"cancelSession",sessionId:e})}cancelTag(e){this.initialized&&this.workers.oscOut.postMessage({type:"cancelTag",runTag:e})}cancelAll(){this.initialized&&this.workers.oscOut.postMessage({type:"cancelAll"})}clearDebug(){this.initialized&&this.workers.debug.postMessage({type:"clear"})}onRawOSC(e){this.callbacks.onRawOSC=e}onParsedOSC(e){this.callbacks.onParsedOSC=e}onDebugMessage(e){this.callbacks.onDebugMessage=e}onError(e){this.callbacks.onError=e}onInitialized(e){this.callbacks.onInitialized=e}terminate(){this.workers.oscOut&&(this.workers.oscOut.postMessage({type:"stop"}),this.workers.oscOut.terminate()),this.workers.oscIn&&(this.workers.oscIn.postMessage({type:"stop"}),this.workers.oscIn.terminate()),this.workers.debug&&(this.workers.debug.postMessage({type:"stop"}),this.workers.debug.terminate()),this.workers={oscOut:null,oscIn:null,debug:null},this.initialized=!1}};var ge={5120:"i8",5121:"u8",5122:"i16",5123:"u16",5124:"i32",5125:"u32",5126:"f32"};var q={u8:1,u8c:1,i8:1,u16:2,i16:2,u32:4,i32:4,i64:8,u64:8,f32:4,f64:8};var ye={f32:Float32Array,f64:Float64Array},_e={i8:Int8Array,i16:Int16Array,i32:Int32Array},Ae={u8:Uint8Array,u8c:Uint8ClampedArray,u16:Uint16Array,u32:Uint32Array},be={i64:BigInt64Array,u64:BigUint64Array},Te={...ye,..._e,...Ae},Be=i=>{let e=ge[i];return e!==void 0?e:i};function Y(i,...e){let t=be[i];return new(t||Te[Be(i)])(...e)}var I=(i,e)=>(e--,i+e&~e);var Q=i=>typeof i=="number";var v=(i,e=t=>t!==void 0?": "+t:"")=>class extends Error{origMessage;constructor(t){super(i(t)+e(t)),this.origMessage=t!==void 0?String(t):""}};var Re=v(()=>"Assertion failed"),N=(typeof process<"u"&&process.env!==void 0?process.env.UMBRELLA_ASSERTS:!import.meta.env||import.meta.env.MODE!=="production"||import.meta.env.UMBRELLA_ASSERTS||import.meta.env.VITE_UMBRELLA_ASSERTS)?(i,e)=>{if(typeof i=="function"&&!i()||!i)throw new Re(typeof e=="function"?e():e)}:()=>{};var Oe=v(()=>"illegal argument(s)"),K=i=>{throw new Oe(i)};var j=0,X=1,J=2,ee=3,te=4,B=5,re=6,z=1,$=2,se=7*4,V=0,W=1,b=2*4,U=class{buf;start;u8;u32;state;constructor(e={}){if(this.buf=e.buf?e.buf:new ArrayBuffer(e.size||4096),this.start=e.start!=null?I(Math.max(e.start,0),4):0,this.u8=new Uint8Array(this.buf),this.u32=new Uint32Array(this.buf),this.state=new Uint32Array(this.buf,this.start,se/4),!e.skipInitialization){let t=e.align||8;N(t>=8,`invalid alignment: ${t}, must be a pow2 and >= 8`);let r=this.initialTop(t),s=e.end!=null?Math.min(e.end,this.buf.byteLength):this.buf.byteLength;r>=s&&K(`insufficient address range (0x${this.start.toString(16)} - 0x${s.toString(16)})`),this.align=t,this.doCompact=e.compact!==!1,this.doSplit=e.split!==!1,this.minSplit=e.minSplit||16,this.end=s,this.top=r,this._free=0,this._used=0}}stats(){let e=r=>{let s=0,n=0;for(;r;)s++,n+=this.blockSize(r),r=this.blockNext(r);return{count:s,size:n}},t=e(this._free);return{free:t,used:e(this._used),top:this.top,available:this.end-this.top+t.size,total:this.buf.byteLength}}callocAs(e,t,r=0){let s=this.mallocAs(e,t);return s?.fill(r),s}mallocAs(e,t){let r=this.malloc(t*q[e]);return r?Y(e,this.buf,r,t):void 0}calloc(e,t=0){let r=this.malloc(e);return r&&this.u8.fill(t,r,r+e),r}malloc(e){if(e<=0)return 0;let t=I(e+b,this.align),r=this.end,s=this.top,n=this._free,a=0;for(;n;){let c=this.blockSize(n),l=n+c>=s;if(l||c>=t)return this.mallocTop(n,a,c,t,l);a=n,n=this.blockNext(n)}return n=s,s=n+t,s<=r?(this.initBlock(n,t,this._used),this._used=n,this.top=s,D(n)):0}mallocTop(e,t,r,s,n){if(n&&e+s>this.end)return 0;if(t?this.unlinkBlock(t,e):this._free=this.blockNext(e),this.setBlockNext(e,this._used),this._used=e,n)this.top=e+this.setBlockSize(e,s);else if(this.doSplit){let a=r-s;a>=this.minSplit&&this.splitBlock(e,s,a)}return D(e)}realloc(e,t){if(t<=0)return 0;let r=H(e),s=0,n=this._used,a=0;for(;n;){if(n===r){[s,a]=this.reallocBlock(n,t);break}n=this.blockNext(n)}return s&&s!==r&&this.u8.copyWithin(D(s),D(r),a),D(s)}reallocBlock(e,t){let r=this.blockSize(e),s=e+r,n=s>=this.top,a=I(t+b,this.align);if(a<=r){if(this.doSplit){let c=r-a;c>=this.minSplit?this.splitBlock(e,a,c):n&&(this.top=e+a)}else n&&(this.top=e+a);return[e,s]}return n&&e+a<this.end?(this.top=e+this.setBlockSize(e,a),[e,s]):(this.free(e),[H(this.malloc(t)),s])}reallocArray(e,t){if(e.buffer!==this.buf)return;let r=this.realloc(e.byteOffset,t*e.BYTES_PER_ELEMENT);return r?new e.constructor(this.buf,r,t):void 0}free(e){let t;if(Q(e))t=e;else{if(e.buffer!==this.buf)return!1;t=e.byteOffset}t=H(t);let r=this._used,s=0;for(;r;){if(r===t)return s?this.unlinkBlock(s,r):this._used=this.blockNext(r),this.insert(r),this.doCompact&&this.compact(),!0;s=r,r=this.blockNext(r)}return!1}freeAll(){this._free=0,this._used=0,this.top=this.initialTop()}release(){return delete this.u8,delete this.u32,delete this.state,delete this.buf,!0}get align(){return this.state[te]}set align(e){this.state[te]=e}get end(){return this.state[ee]}set end(e){this.state[ee]=e}get top(){return this.state[J]}set top(e){this.state[J]=e}get _free(){return this.state[j]}set _free(e){this.state[j]=e}get _used(){return this.state[X]}set _used(e){this.state[X]=e}get doCompact(){return!!(this.state[B]&z)}set doCompact(e){e?this.state[B]|=1<<z-1:this.state[B]&=~z}get doSplit(){return!!(this.state[B]&$)}set doSplit(e){e?this.state[B]|=1<<$-1:this.state[B]&=~$}get minSplit(){return this.state[re]}set minSplit(e){N(e>b,`illegal min split threshold: ${e}, require at least ${b+1}`),this.state[re]=e}blockSize(e){return this.u32[(e>>2)+V]}setBlockSize(e,t){return this.u32[(e>>2)+V]=t,t}blockNext(e){return this.u32[(e>>2)+W]}setBlockNext(e,t){this.u32[(e>>2)+W]=t}initBlock(e,t,r){let s=e>>>2;return this.u32[s+V]=t,this.u32[s+W]=r,e}unlinkBlock(e,t){this.setBlockNext(e,this.blockNext(t))}splitBlock(e,t,r){this.insert(this.initBlock(e+this.setBlockSize(e,t),r,0)),this.doCompact&&this.compact()}initialTop(e=this.align){return I(this.start+se+b,e)-b}compact(){let e=this._free,t=0,r=0,s,n=!1;for(;e;){for(s=e,r=this.blockNext(e);r&&s+this.blockSize(s)===r;)s=r,r=this.blockNext(r);if(s!==e){let a=s-e+this.blockSize(s);this.setBlockSize(e,a);let c=this.blockNext(s),l=this.blockNext(e);for(;l&&l!==c;){let u=this.blockNext(l);this.setBlockNext(l,0),l=u}this.setBlockNext(e,c),n=!0}e+this.blockSize(e)>=this.top&&(this.top=e,t?this.unlinkBlock(t,e):this._free=this.blockNext(e)),t=e,e=this.blockNext(e)}return n}insert(e){let t=this._free,r=0;for(;t&&!(e<=t);)r=t,t=this.blockNext(t);r?this.setBlockNext(r,e):this._free=e,this.setBlockNext(e,t)}},D=i=>i>0?i+b:0,H=i=>i>0?i-b:0;var Ce=8,M=class{#t;#n;#d;#o;#a;#s;#r;#e;#c;constructor(e){let{audioContext:t,sharedBuffer:r,bufferPoolConfig:s,sampleBaseURL:n,maxBuffers:a=1024,assetLoader:c=null}=e;if(!t)throw new Error("BufferManager requires audioContext");if(!r||!(r instanceof SharedArrayBuffer))throw new Error("BufferManager requires sharedBuffer (SharedArrayBuffer)");if(!s||typeof s!="object")throw new Error("BufferManager requires bufferPoolConfig (object with start, size, align)");if(!Number.isFinite(s.start)||s.start<0)throw new Error("bufferPoolConfig.start must be a non-negative number");if(!Number.isFinite(s.size)||s.size<=0)throw new Error("bufferPoolConfig.size must be a positive number");if(!Number.isInteger(a)||a<=0)throw new Error("maxBuffers must be a positive integer");this.#d=t,this.#o=r,this.#t=n,this.#n=c,this.#a=new U({buf:r,start:s.start,size:s.size,align:Ce}),this.#s=s.size,this.#r=new Map,this.#e=new Map,this.#c=new Map,this.GUARD_BEFORE=3,this.GUARD_AFTER=1,this.MAX_BUFFERS=a;let l=(s.size/(1024*1024)).toFixed(0),u=(s.start/(1024*1024)).toFixed(0)}#E(e){if(typeof e!="string"||e.length===0)throw new Error("Invalid audio path: must be a non-empty string");if(e.includes(".."))throw new Error(`Invalid audio path: path cannot contain '..' (got: ${e})`);if(e.includes("%2e")||e.includes("%2E"))throw new Error(`Invalid audio path: path cannot contain URL-encoded characters (got: ${e})`);if(e.includes("\\"))throw new Error(`Invalid audio path: use forward slashes only (got: ${e})`);if(e.includes("://")||e.startsWith("/")||e.startsWith("./"))return e;if(!this.#t)throw new Error(`sampleBaseURL not configured. Please set it in SuperSonic constructor options.
1
+ var o={},o=o||{};(function(){"use strict";o.SECS_70YRS=2208988800,o.TWO_32=4294967296,o.defaults={metadata:!1,unpackSingleArgs:!0},o.isCommonJS=!!(typeof module<"u"&&module.exports),o.isNode=o.isCommonJS&&typeof window>"u",o.isElectron=!!(typeof process<"u"&&process.versions&&process.versions.electron),o.isBufferEnv=o.isNode||o.isElectron,o.isArray=function(i){return i&&Object.prototype.toString.call(i)==="[object Array]"},o.isTypedArrayView=function(i){return i.buffer&&i.buffer instanceof ArrayBuffer},o.isBuffer=function(i){return o.isBufferEnv&&i instanceof Buffer},o.Long=typeof Long<"u"?Long:void 0,o.TextDecoder=typeof TextDecoder<"u"?new TextDecoder("utf-8"):typeof util<"u"&&typeof(util.TextDecoder!=="undefined")?new util.TextDecoder("utf-8"):void 0,o.TextEncoder=typeof TextEncoder<"u"?new TextEncoder("utf-8"):typeof util<"u"&&typeof(util.TextEncoder!=="undefined")?new util.TextEncoder("utf-8"):void 0,o.dataView=function(i,e,t){return i.buffer?new DataView(i.buffer,e,t):i instanceof ArrayBuffer?new DataView(i,e,t):new DataView(new Uint8Array(i),e,t)},o.byteArray=function(i){if(i instanceof Uint8Array)return i;var e=i.buffer?i.buffer:i;if(!(e instanceof ArrayBuffer)&&(typeof e.length>"u"||typeof e=="string"))throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: "+JSON.stringify(i,null,2));return new Uint8Array(e)},o.nativeBuffer=function(i){return o.isBufferEnv?o.isBuffer(i)?i:Buffer.from(i.buffer?i:new Uint8Array(i)):o.isTypedArrayView(i)?i:new Uint8Array(i)},o.copyByteArray=function(i,e,t){if(o.isTypedArrayView(i)&&o.isTypedArrayView(e))e.set(i,t);else for(var r=t===void 0?0:t,s=Math.min(e.length-t,i.length),n=0,a=r;n<s;n++,a++)e[a]=i[n];return e},o.readString=function(i,e){for(var t=[],r=e.idx;r<i.byteLength;r++){var s=i.getUint8(r);if(s!==0)t.push(s);else{r++;break}}r=r+3&-4,e.idx=r;var n=o.isBufferEnv?o.readString.withBuffer:o.TextDecoder?o.readString.withTextDecoder:o.readString.raw;return n(t)},o.readString.raw=function(i){for(var e="",t=1e4,r=0;r<i.length;r+=t)e+=String.fromCharCode.apply(null,i.slice(r,r+t));return e},o.readString.withTextDecoder=function(i){var e=new Int8Array(i);return o.TextDecoder.decode(e)},o.readString.withBuffer=function(i){return Buffer.from(i).toString("utf-8")},o.writeString=function(i){var e=o.isBufferEnv?o.writeString.withBuffer:o.TextEncoder?o.writeString.withTextEncoder:null,t=i+"\0",r;e&&(r=e(t));for(var s=e?r.length:t.length,n=s+3&-4,a=new Uint8Array(n),c=0;c<s-1;c++){var l=e?r[c]:t.charCodeAt(c);a[c]=l}return a},o.writeString.withTextEncoder=function(i){return o.TextEncoder.encode(i)},o.writeString.withBuffer=function(i){return Buffer.from(i)},o.readPrimitive=function(i,e,t,r){var s=i[e](r.idx,!1);return r.idx+=t,s},o.writePrimitive=function(i,e,t,r,s){s=s===void 0?0:s;var n;return e?n=new Uint8Array(e.buffer):(n=new Uint8Array(r),e=new DataView(n.buffer)),e[t](s,i,!1),n},o.readInt32=function(i,e){return o.readPrimitive(i,"getInt32",4,e)},o.writeInt32=function(i,e,t){return o.writePrimitive(i,e,"setInt32",4,t)},o.readInt64=function(i,e){var t=o.readPrimitive(i,"getInt32",4,e),r=o.readPrimitive(i,"getInt32",4,e);return o.Long?new o.Long(r,t):{high:t,low:r,unsigned:!1}},o.writeInt64=function(i,e,t){var r=new Uint8Array(8);return r.set(o.writePrimitive(i.high,e,"setInt32",4,t),0),r.set(o.writePrimitive(i.low,e,"setInt32",4,t+4),4),r},o.readFloat32=function(i,e){return o.readPrimitive(i,"getFloat32",4,e)},o.writeFloat32=function(i,e,t){return o.writePrimitive(i,e,"setFloat32",4,t)},o.readFloat64=function(i,e){return o.readPrimitive(i,"getFloat64",8,e)},o.writeFloat64=function(i,e,t){return o.writePrimitive(i,e,"setFloat64",8,t)},o.readChar32=function(i,e){var t=o.readPrimitive(i,"getUint32",4,e);return String.fromCharCode(t)},o.writeChar32=function(i,e,t){var r=i.charCodeAt(0);if(!(r===void 0||r<-1))return o.writePrimitive(r,e,"setUint32",4,t)},o.readBlob=function(i,e){var t=o.readInt32(i,e),r=t+3&-4,s=new Uint8Array(i.buffer,e.idx,t);return e.idx+=r,s},o.writeBlob=function(i){i=o.byteArray(i);var e=i.byteLength,t=e+3&-4,r=4,s=t+r,n=new Uint8Array(s),a=new DataView(n.buffer);return o.writeInt32(e,a),n.set(i,r),n},o.readMIDIBytes=function(i,e){var t=new Uint8Array(i.buffer,e.idx,4);return e.idx+=4,t},o.writeMIDIBytes=function(i){i=o.byteArray(i);var e=new Uint8Array(4);return e.set(i),e},o.readColor=function(i,e){var t=new Uint8Array(i.buffer,e.idx,4),r=t[3]/255;return e.idx+=4,{r:t[0],g:t[1],b:t[2],a:r}},o.writeColor=function(i){var e=Math.round(i.a*255),t=new Uint8Array([i.r,i.g,i.b,e]);return t},o.readTrue=function(){return!0},o.readFalse=function(){return!1},o.readNull=function(){return null},o.readImpulse=function(){return 1},o.readTimeTag=function(i,e){var t=o.readPrimitive(i,"getUint32",4,e),r=o.readPrimitive(i,"getUint32",4,e),s=t===0&&r===1?Date.now():o.ntpToJSTime(t,r);return{raw:[t,r],native:s}},o.writeTimeTag=function(i){var e=i.raw?i.raw:o.jsToNTPTime(i.native),t=new Uint8Array(8),r=new DataView(t.buffer);return o.writeInt32(e[0],r,0),o.writeInt32(e[1],r,4),t},o.timeTag=function(i,e){i=i||0,e=e||Date.now();var t=e/1e3,r=Math.floor(t),s=t-r,n=Math.floor(i),a=i-n,c=s+a;if(c>1){var l=Math.floor(c),u=c-l;n+=l,c=u}var h=r+n+o.SECS_70YRS,f=Math.round(o.TWO_32*c);return{raw:[h,f]}},o.ntpToJSTime=function(i,e){var t=i-o.SECS_70YRS,r=e/o.TWO_32,s=(t+r)*1e3;return s},o.jsToNTPTime=function(i){var e=i/1e3,t=Math.floor(e),r=e-t,s=t+o.SECS_70YRS,n=Math.round(o.TWO_32*r);return[s,n]},o.readArguments=function(i,e,t){var r=o.readString(i,t);if(r.indexOf(",")!==0)throw new Error("A malformed type tag string was found while reading the arguments of an OSC message. String was: "+r," at offset: "+t.idx);var s=r.substring(1).split(""),n=[];return o.readArgumentsIntoArray(n,s,r,i,e,t),n},o.readArgument=function(i,e,t,r,s){var n=o.argumentTypes[i];if(!n)throw new Error("'"+i+"' is not a valid OSC type tag. Type tag string was: "+e);var a=n.reader,c=o[a](t,s);return r.metadata&&(c={type:i,value:c}),c},o.readArgumentsIntoArray=function(i,e,t,r,s,n){for(var a=0;a<e.length;){var c=e[a],l;if(c==="["){var u=e.slice(a+1),h=u.indexOf("]");if(h<0)throw new Error("Invalid argument type tag: an open array type tag ('[') was found without a matching close array tag ('[]'). Type tag was: "+t);var f=u.slice(0,h);l=o.readArgumentsIntoArray([],f,t,r,s,n),a+=h+2}else l=o.readArgument(c,t,r,s,n),a++;i.push(l)}return i},o.writeArguments=function(i,e){var t=o.collectArguments(i,e);return o.joinParts(t)},o.joinParts=function(i){for(var e=new Uint8Array(i.byteLength),t=i.parts,r=0,s=0;s<t.length;s++){var n=t[s];o.copyByteArray(n,e,r),r+=n.length}return e},o.addDataPart=function(i,e){e.parts.push(i),e.byteLength+=i.length},o.writeArrayArguments=function(i,e){for(var t="[",r=0;r<i.length;r++){var s=i[r];t+=o.writeArgument(s,e)}return t+="]",t},o.writeArgument=function(i,e){if(o.isArray(i))return o.writeArrayArguments(i,e);var t=i.type,r=o.argumentTypes[t].writer;if(r){var s=o[r](i.value);o.addDataPart(s,e)}return i.type},o.collectArguments=function(i,e,t){o.isArray(i)||(i=typeof i>"u"?[]:[i]),t=t||{byteLength:0,parts:[]},e.metadata||(i=o.annotateArguments(i));for(var r=",",s=t.parts.length,n=0;n<i.length;n++){var a=i[n];r+=o.writeArgument(a,t)}var c=o.writeString(r);return t.byteLength+=c.byteLength,t.parts.splice(s,0,c),t},o.readMessage=function(i,e,t){e=e||o.defaults;var r=o.dataView(i,i.byteOffset,i.byteLength);t=t||{idx:0};var s=o.readString(r,t);return o.readMessageContents(s,r,e,t)},o.readMessageContents=function(i,e,t,r){if(i.indexOf("/")!==0)throw new Error("A malformed OSC address was found while reading an OSC message. String was: "+i);var s=o.readArguments(e,t,r);return{address:i,args:s.length===1&&t.unpackSingleArgs?s[0]:s}},o.collectMessageParts=function(i,e,t){return t=t||{byteLength:0,parts:[]},o.addDataPart(o.writeString(i.address),t),o.collectArguments(i.args,e,t)},o.writeMessage=function(i,e){if(e=e||o.defaults,!o.isValidMessage(i))throw new Error("An OSC message must contain a valid address. Message was: "+JSON.stringify(i,null,2));var t=o.collectMessageParts(i,e);return o.joinParts(t)},o.isValidMessage=function(i){return i.address&&i.address.indexOf("/")===0},o.readBundle=function(i,e,t){return o.readPacket(i,e,t)},o.collectBundlePackets=function(i,e,t){t=t||{byteLength:0,parts:[]},o.addDataPart(o.writeString("#bundle"),t),o.addDataPart(o.writeTimeTag(i.timeTag),t);for(var r=0;r<i.packets.length;r++){var s=i.packets[r],n=s.address?o.collectMessageParts:o.collectBundlePackets,a=n(s,e);t.byteLength+=a.byteLength,o.addDataPart(o.writeInt32(a.byteLength),t),t.parts=t.parts.concat(a.parts)}return t},o.writeBundle=function(i,e){if(!o.isValidBundle(i))throw new Error("An OSC bundle must contain 'timeTag' and 'packets' properties. Bundle was: "+JSON.stringify(i,null,2));e=e||o.defaults;var t=o.collectBundlePackets(i,e);return o.joinParts(t)},o.isValidBundle=function(i){return i.timeTag!==void 0&&i.packets!==void 0},o.readBundleContents=function(i,e,t,r){for(var s=o.readTimeTag(i,t),n=[];t.idx<r;){var a=o.readInt32(i,t),c=t.idx+a,l=o.readPacket(i,e,t,c);n.push(l)}return{timeTag:s,packets:n}},o.readPacket=function(i,e,t,r){var s=o.dataView(i,i.byteOffset,i.byteLength);r=r===void 0?s.byteLength:r,t=t||{idx:0};var n=o.readString(s,t),a=n[0];if(a==="#")return o.readBundleContents(s,e,t,r);if(a==="/")return o.readMessageContents(n,s,e,t);throw new Error("The header of an OSC packet didn't contain an OSC address or a #bundle string. Header was: "+n)},o.writePacket=function(i,e){if(o.isValidMessage(i))return o.writeMessage(i,e);if(o.isValidBundle(i))return o.writeBundle(i,e);throw new Error("The specified packet was not recognized as a valid OSC message or bundle. Packet was: "+JSON.stringify(i,null,2))},o.argumentTypes={i:{reader:"readInt32",writer:"writeInt32"},h:{reader:"readInt64",writer:"writeInt64"},f:{reader:"readFloat32",writer:"writeFloat32"},s:{reader:"readString",writer:"writeString"},S:{reader:"readString",writer:"writeString"},b:{reader:"readBlob",writer:"writeBlob"},t:{reader:"readTimeTag",writer:"writeTimeTag"},T:{reader:"readTrue"},F:{reader:"readFalse"},N:{reader:"readNull"},I:{reader:"readImpulse"},d:{reader:"readFloat64",writer:"writeFloat64"},c:{reader:"readChar32",writer:"writeChar32"},r:{reader:"readColor",writer:"writeColor"},m:{reader:"readMIDIBytes",writer:"writeMIDIBytes"}},o.inferTypeForArgument=function(i){var e=typeof i;switch(e){case"boolean":return i?"T":"F";case"string":return"s";case"number":return"f";case"undefined":return"N";case"object":if(i===null)return"N";if(i instanceof Uint8Array||i instanceof ArrayBuffer)return"b";if(typeof i.high=="number"&&typeof i.low=="number")return"h";break}throw new Error("Can't infer OSC argument type for value: "+JSON.stringify(i,null,2))},o.annotateArguments=function(i){for(var e=[],t=0;t<i.length;t++){var r=i[t],s;if(typeof r=="object"&&r.type&&r.value!==void 0)s=r;else if(o.isArray(r))s=o.annotateArguments(r);else{var n=o.inferTypeForArgument(r);s={type:n,value:r}}e.push(s)}return e}})();var R=function(){};R.prototype.on=function(){};R.prototype.emit=function(){};R.prototype.removeListener=function(){};(function(){"use strict";o.supportsSerial=!1,o.firePacketEvents=function(e,t,r,s){t.address?e.emit("message",t,r,s):o.fireBundleEvents(e,t,r,s)},o.fireBundleEvents=function(e,t,r,s){e.emit("bundle",t,r,s);for(var n=0;n<t.packets.length;n++){var a=t.packets[n];o.firePacketEvents(e,a,t.timeTag,s)}},o.fireClosedPortSendError=function(e,t){t=t||"Can't send packets on a closed osc.Port object. Please open (or reopen) this Port by calling open().",e.emit("error",t)},o.Port=function(e){this.options=e||{},this.on("data",this.decodeOSC.bind(this))};var i=o.Port.prototype=Object.create(R.prototype);i.constructor=o.Port,i.send=function(e){var t=Array.prototype.slice.call(arguments),r=this.encodeOSC(e),s=o.nativeBuffer(r);t[0]=s,this.sendRaw.apply(this,t)},i.encodeOSC=function(e){e=e.buffer?e.buffer:e;var t;try{t=o.writePacket(e,this.options)}catch(r){this.emit("error",r)}return t},i.decodeOSC=function(e,t){e=o.byteArray(e),this.emit("raw",e,t);try{var r=o.readPacket(e,this.options);this.emit("osc",r,t),o.firePacketEvents(this,r,void 0,t)}catch(s){this.emit("error",s)}},o.SLIPPort=function(e){var t=this,r=this.options=e||{};r.useSLIP=r.useSLIP===void 0?!0:r.useSLIP,this.decoder=new slip.Decoder({onMessage:this.decodeOSC.bind(this),onError:function(n){t.emit("error",n)}});var s=r.useSLIP?this.decodeSLIPData:this.decodeOSC;this.on("data",s.bind(this))},i=o.SLIPPort.prototype=Object.create(o.Port.prototype),i.constructor=o.SLIPPort,i.encodeOSC=function(e){e=e.buffer?e.buffer:e;var t;try{var r=o.writePacket(e,this.options);t=slip.encode(r)}catch(s){this.emit("error",s)}return t},i.decodeSLIPData=function(e,t){this.decoder.decode(e,t)},o.relay=function(e,t,r,s,n,a){r=r||"message",s=s||"send",n=n||function(){},a=a?[null].concat(a):[];var c=function(l){a[0]=l,l=n(l),t[s].apply(t,a)};return e.on(r,c),{eventName:r,listener:c}},o.relayPorts=function(e,t,r){var s=r.raw?"raw":"osc",n=r.raw?"sendRaw":"send";return o.relay(e,t,s,n,r.transform)},o.stopRelaying=function(e,t){e.removeListener(t.eventName,t.listener)},o.Relay=function(e,t,r){var s=this.options=r||{};s.raw=!1,this.port1=e,this.port2=t,this.listen()},i=o.Relay.prototype=Object.create(R.prototype),i.constructor=o.Relay,i.open=function(){this.port1.open(),this.port2.open()},i.listen=function(){this.port1Spec&&this.port2Spec&&this.close(),this.port1Spec=o.relayPorts(this.port1,this.port2,this.options),this.port2Spec=o.relayPorts(this.port2,this.port1,this.options);var e=this.close.bind(this);this.port1.on("close",e),this.port2.on("close",e)},i.close=function(){o.stopRelaying(this.port1,this.port1Spec),o.stopRelaying(this.port2,this.port2Spec),this.emit("close",this.port1,this.port2)}})();(function(){"use strict";o.WebSocket=typeof WebSocket<"u"?WebSocket:void 0,o.WebSocketPort=function(e){o.Port.call(this,e),this.on("open",this.listen.bind(this)),this.socket=e.socket,this.socket&&(this.socket.readyState===1?(o.WebSocketPort.setupSocketForBinary(this.socket),this.emit("open",this.socket)):this.open())};var i=o.WebSocketPort.prototype=Object.create(o.Port.prototype);i.constructor=o.WebSocketPort,i.open=function(){(!this.socket||this.socket.readyState>1)&&(this.socket=new o.WebSocket(this.options.url)),o.WebSocketPort.setupSocketForBinary(this.socket);var e=this;this.socket.onopen=function(){e.emit("open",e.socket)},this.socket.onerror=function(t){e.emit("error",t)}},i.listen=function(){var e=this;this.socket.onmessage=function(t){e.emit("data",t.data,t)},this.socket.onclose=function(t){e.emit("close",t)},e.emit("ready")},i.sendRaw=function(e){if(!this.socket||this.socket.readyState!==1){o.fireClosedPortSendError(this);return}this.socket.send(e)},i.close=function(e,t){this.socket.close(e,t)},o.WebSocketPort.setupSocketForBinary=function(e){e.binaryType=o.isNode?"nodebuffer":"arraybuffer"}})();var O=o,{readPacket:et,writePacket:tt,readMessage:rt,writeMessage:st,readBundle:it,writeBundle:nt}=o;var D=class{constructor(e=null){this.workerBaseURL=e,this.workers={oscOut:null,oscIn:null,debug:null},this.callbacks={onRawOSC:null,onParsedOSC:null,onDebugMessage:null,onError:null,onInitialized:null},this.initialized=!1,this.sharedBuffer=null,this.ringBufferBase=null,this.bufferConstants=null}async init(e,t,r,s={}){if(this.initialized){console.warn("[ScsynthOSC] Already initialized");return}this.sharedBuffer=e,this.ringBufferBase=t,this.bufferConstants=r,this.preschedulerCapacity=s.preschedulerCapacity||65536;try{this.workers.oscOut=new Worker(this.workerBaseURL+"osc_out_prescheduler_worker.js",{type:"module"}),this.workers.oscIn=new Worker(this.workerBaseURL+"osc_in_worker.js",{type:"module"}),this.workers.debug=new Worker(this.workerBaseURL+"debug_worker.js",{type:"module"}),this.setupWorkerHandlers();let n=[this.initWorker(this.workers.oscOut,"OSC SCHEDULER+WRITER",{maxPendingMessages:this.preschedulerCapacity}),this.initWorker(this.workers.oscIn,"OSC IN"),this.initWorker(this.workers.debug,"DEBUG")];await Promise.all(n),this.workers.oscIn.postMessage({type:"start"}),this.workers.debug.postMessage({type:"start"}),this.initialized=!0,this.callbacks.onInitialized&&this.callbacks.onInitialized()}catch(n){throw console.error("[ScsynthOSC] Initialization failed:",n),this.callbacks.onError&&this.callbacks.onError(n),n}}initWorker(e,t,r={}){return new Promise((s,n)=>{let a=setTimeout(()=>{n(new Error(`${t} worker initialization timeout`))},5e3),c=l=>{l.data.type==="initialized"&&(clearTimeout(a),e.removeEventListener("message",c),s())};e.addEventListener("message",c),e.postMessage({type:"init",sharedBuffer:this.sharedBuffer,ringBufferBase:this.ringBufferBase,bufferConstants:this.bufferConstants,...r})})}setupWorkerHandlers(){this.workers.oscIn.onmessage=e=>{let t=e.data;switch(t.type){case"messages":t.messages.forEach(r=>{if(r.oscData&&(this.callbacks.onRawOSC&&this.callbacks.onRawOSC({oscData:r.oscData,sequence:r.sequence}),this.callbacks.onParsedOSC))try{let s={metadata:!1,unpackSingleArgs:!1},n=O.readPacket(r.oscData,s);this.callbacks.onParsedOSC(n)}catch(s){console.error("[ScsynthOSC] Failed to decode OSC message:",s,r)}});break;case"error":console.error("[ScsynthOSC] OSC IN error:",t.error),this.callbacks.onError&&this.callbacks.onError(t.error,"oscIn");break}},this.workers.debug.onmessage=e=>{let t=e.data;switch(t.type){case"debug":this.callbacks.onDebugMessage&&t.messages.forEach(r=>{this.callbacks.onDebugMessage(r)});break;case"error":console.error("[ScsynthOSC] DEBUG error:",t.error),this.callbacks.onError&&this.callbacks.onError(t.error,"debug");break}},this.workers.oscOut.onmessage=e=>{let t=e.data;switch(t.type){case"error":console.error("[ScsynthOSC] OSC OUT error:",t.error),this.callbacks.onError&&this.callbacks.onError(t.error,"oscOut");break}}}send(e,t={}){if(!this.initialized){console.error("[ScsynthOSC] Not initialized");return}let{sessionId:r=0,runTag:s="",audioTimeS:n=null,currentTimeS:a=null}=t;this.workers.oscOut.postMessage({type:"send",oscData:e,sessionId:r,runTag:s,audioTimeS:n,currentTimeS:a})}sendImmediate(e){if(!this.initialized){console.error("[ScsynthOSC] Not initialized");return}this.workers.oscOut.postMessage({type:"sendImmediate",oscData:e})}cancelSessionTag(e,t){this.initialized&&this.workers.oscOut.postMessage({type:"cancelSessionTag",sessionId:e,runTag:t})}cancelSession(e){this.initialized&&this.workers.oscOut.postMessage({type:"cancelSession",sessionId:e})}cancelTag(e){this.initialized&&this.workers.oscOut.postMessage({type:"cancelTag",runTag:e})}cancelAll(){this.initialized&&this.workers.oscOut.postMessage({type:"cancelAll"})}clearDebug(){this.initialized&&this.workers.debug.postMessage({type:"clear"})}onRawOSC(e){this.callbacks.onRawOSC=e}onParsedOSC(e){this.callbacks.onParsedOSC=e}onDebugMessage(e){this.callbacks.onDebugMessage=e}onError(e){this.callbacks.onError=e}onInitialized(e){this.callbacks.onInitialized=e}terminate(){this.workers.oscOut&&(this.workers.oscOut.postMessage({type:"stop"}),this.workers.oscOut.terminate()),this.workers.oscIn&&(this.workers.oscIn.postMessage({type:"stop"}),this.workers.oscIn.terminate()),this.workers.debug&&(this.workers.debug.postMessage({type:"stop"}),this.workers.debug.terminate()),this.workers={oscOut:null,oscIn:null,debug:null},this.initialized=!1}};var Ee={5120:"i8",5121:"u8",5122:"i16",5123:"u16",5124:"i32",5125:"u32",5126:"f32"};var q={u8:1,u8c:1,i8:1,u16:2,i16:2,u32:4,i32:4,i64:8,u64:8,f32:4,f64:8};var ye={f32:Float32Array,f64:Float64Array},_e={i8:Int8Array,i16:Int16Array,i32:Int32Array},be={u8:Uint8Array,u8c:Uint8ClampedArray,u16:Uint16Array,u32:Uint32Array},Ae={i64:BigInt64Array,u64:BigUint64Array},Te={...ye,..._e,...be},Be=i=>{let e=Ee[i];return e!==void 0?e:i};function Y(i,...e){let t=Ae[i];return new(t||Te[Be(i)])(...e)}var C=(i,e)=>(e--,i+e&~e);var Q=i=>typeof i=="number";var v=(i,e=t=>t!==void 0?": "+t:"")=>class extends Error{origMessage;constructor(t){super(i(t)+e(t)),this.origMessage=t!==void 0?String(t):""}};var Re=v(()=>"Assertion failed"),N=(typeof process<"u"&&process.env!==void 0?process.env.UMBRELLA_ASSERTS:!import.meta.env||import.meta.env.MODE!=="production"||import.meta.env.UMBRELLA_ASSERTS||import.meta.env.VITE_UMBRELLA_ASSERTS)?(i,e)=>{if(typeof i=="function"&&!i()||!i)throw new Re(typeof e=="function"?e():e)}:()=>{};var Oe=v(()=>"illegal argument(s)"),K=i=>{throw new Oe(i)};var j=0,X=1,J=2,ee=3,te=4,B=5,re=6,z=1,$=2,se=7*4,V=0,W=1,A=2*4,U=class{buf;start;u8;u32;state;constructor(e={}){if(this.buf=e.buf?e.buf:new ArrayBuffer(e.size||4096),this.start=e.start!=null?C(Math.max(e.start,0),4):0,this.u8=new Uint8Array(this.buf),this.u32=new Uint32Array(this.buf),this.state=new Uint32Array(this.buf,this.start,se/4),!e.skipInitialization){let t=e.align||8;N(t>=8,`invalid alignment: ${t}, must be a pow2 and >= 8`);let r=this.initialTop(t),s=e.end!=null?Math.min(e.end,this.buf.byteLength):this.buf.byteLength;r>=s&&K(`insufficient address range (0x${this.start.toString(16)} - 0x${s.toString(16)})`),this.align=t,this.doCompact=e.compact!==!1,this.doSplit=e.split!==!1,this.minSplit=e.minSplit||16,this.end=s,this.top=r,this._free=0,this._used=0}}stats(){let e=r=>{let s=0,n=0;for(;r;)s++,n+=this.blockSize(r),r=this.blockNext(r);return{count:s,size:n}},t=e(this._free);return{free:t,used:e(this._used),top:this.top,available:this.end-this.top+t.size,total:this.buf.byteLength}}callocAs(e,t,r=0){let s=this.mallocAs(e,t);return s?.fill(r),s}mallocAs(e,t){let r=this.malloc(t*q[e]);return r?Y(e,this.buf,r,t):void 0}calloc(e,t=0){let r=this.malloc(e);return r&&this.u8.fill(t,r,r+e),r}malloc(e){if(e<=0)return 0;let t=C(e+A,this.align),r=this.end,s=this.top,n=this._free,a=0;for(;n;){let c=this.blockSize(n),l=n+c>=s;if(l||c>=t)return this.mallocTop(n,a,c,t,l);a=n,n=this.blockNext(n)}return n=s,s=n+t,s<=r?(this.initBlock(n,t,this._used),this._used=n,this.top=s,I(n)):0}mallocTop(e,t,r,s,n){if(n&&e+s>this.end)return 0;if(t?this.unlinkBlock(t,e):this._free=this.blockNext(e),this.setBlockNext(e,this._used),this._used=e,n)this.top=e+this.setBlockSize(e,s);else if(this.doSplit){let a=r-s;a>=this.minSplit&&this.splitBlock(e,s,a)}return I(e)}realloc(e,t){if(t<=0)return 0;let r=H(e),s=0,n=this._used,a=0;for(;n;){if(n===r){[s,a]=this.reallocBlock(n,t);break}n=this.blockNext(n)}return s&&s!==r&&this.u8.copyWithin(I(s),I(r),a),I(s)}reallocBlock(e,t){let r=this.blockSize(e),s=e+r,n=s>=this.top,a=C(t+A,this.align);if(a<=r){if(this.doSplit){let c=r-a;c>=this.minSplit?this.splitBlock(e,a,c):n&&(this.top=e+a)}else n&&(this.top=e+a);return[e,s]}return n&&e+a<this.end?(this.top=e+this.setBlockSize(e,a),[e,s]):(this.free(e),[H(this.malloc(t)),s])}reallocArray(e,t){if(e.buffer!==this.buf)return;let r=this.realloc(e.byteOffset,t*e.BYTES_PER_ELEMENT);return r?new e.constructor(this.buf,r,t):void 0}free(e){let t;if(Q(e))t=e;else{if(e.buffer!==this.buf)return!1;t=e.byteOffset}t=H(t);let r=this._used,s=0;for(;r;){if(r===t)return s?this.unlinkBlock(s,r):this._used=this.blockNext(r),this.insert(r),this.doCompact&&this.compact(),!0;s=r,r=this.blockNext(r)}return!1}freeAll(){this._free=0,this._used=0,this.top=this.initialTop()}release(){return delete this.u8,delete this.u32,delete this.state,delete this.buf,!0}get align(){return this.state[te]}set align(e){this.state[te]=e}get end(){return this.state[ee]}set end(e){this.state[ee]=e}get top(){return this.state[J]}set top(e){this.state[J]=e}get _free(){return this.state[j]}set _free(e){this.state[j]=e}get _used(){return this.state[X]}set _used(e){this.state[X]=e}get doCompact(){return!!(this.state[B]&z)}set doCompact(e){e?this.state[B]|=1<<z-1:this.state[B]&=~z}get doSplit(){return!!(this.state[B]&$)}set doSplit(e){e?this.state[B]|=1<<$-1:this.state[B]&=~$}get minSplit(){return this.state[re]}set minSplit(e){N(e>A,`illegal min split threshold: ${e}, require at least ${A+1}`),this.state[re]=e}blockSize(e){return this.u32[(e>>2)+V]}setBlockSize(e,t){return this.u32[(e>>2)+V]=t,t}blockNext(e){return this.u32[(e>>2)+W]}setBlockNext(e,t){this.u32[(e>>2)+W]=t}initBlock(e,t,r){let s=e>>>2;return this.u32[s+V]=t,this.u32[s+W]=r,e}unlinkBlock(e,t){this.setBlockNext(e,this.blockNext(t))}splitBlock(e,t,r){this.insert(this.initBlock(e+this.setBlockSize(e,t),r,0)),this.doCompact&&this.compact()}initialTop(e=this.align){return C(this.start+se+A,e)-A}compact(){let e=this._free,t=0,r=0,s,n=!1;for(;e;){for(s=e,r=this.blockNext(e);r&&s+this.blockSize(s)===r;)s=r,r=this.blockNext(r);if(s!==e){let a=s-e+this.blockSize(s);this.setBlockSize(e,a);let c=this.blockNext(s),l=this.blockNext(e);for(;l&&l!==c;){let u=this.blockNext(l);this.setBlockNext(l,0),l=u}this.setBlockNext(e,c),n=!0}e+this.blockSize(e)>=this.top&&(this.top=e,t?this.unlinkBlock(t,e):this._free=this.blockNext(e)),t=e,e=this.blockNext(e)}return n}insert(e){let t=this._free,r=0;for(;t&&!(e<=t);)r=t,t=this.blockNext(t);r?this.setBlockNext(r,e):this._free=e,this.setBlockNext(e,t)}},I=i=>i>0?i+A:0,H=i=>i>0?i-A:0;var De=8,M=class{#t;#n;#d;#o;#a;#s;#r;#e;#c;constructor(e){let{audioContext:t,sharedBuffer:r,bufferPoolConfig:s,sampleBaseURL:n,maxBuffers:a=1024,assetLoader:c=null}=e;if(!t)throw new Error("BufferManager requires audioContext");if(!r||!(r instanceof SharedArrayBuffer))throw new Error("BufferManager requires sharedBuffer (SharedArrayBuffer)");if(!s||typeof s!="object")throw new Error("BufferManager requires bufferPoolConfig (object with start, size, align)");if(!Number.isFinite(s.start)||s.start<0)throw new Error("bufferPoolConfig.start must be a non-negative number");if(!Number.isFinite(s.size)||s.size<=0)throw new Error("bufferPoolConfig.size must be a positive number");if(!Number.isInteger(a)||a<=0)throw new Error("maxBuffers must be a positive integer");this.#d=t,this.#o=r,this.#t=n,this.#n=c,this.#a=new U({buf:r,start:s.start,size:s.size,align:De}),this.#s=s.size,this.#r=new Map,this.#e=new Map,this.#c=new Map,this.GUARD_BEFORE=3,this.GUARD_AFTER=1,this.MAX_BUFFERS=a;let l=(s.size/(1024*1024)).toFixed(0),u=(s.start/(1024*1024)).toFixed(0)}#g(e){if(typeof e!="string"||e.length===0)throw new Error("Invalid audio path: must be a non-empty string");if(e.includes(".."))throw new Error(`Invalid audio path: path cannot contain '..' (got: ${e})`);if(e.includes("%2e")||e.includes("%2E"))throw new Error(`Invalid audio path: path cannot contain URL-encoded characters (got: ${e})`);if(e.includes("\\"))throw new Error(`Invalid audio path: use forward slashes only (got: ${e})`);if(e.includes("://")||e.startsWith("/")||e.startsWith("./"))return e;if(!this.#t)throw new Error(`sampleBaseURL not configured. Please set it in SuperSonic constructor options.
2
2
  Example: new SuperSonic({ sampleBaseURL: "./dist/samples/" })
3
3
  Or use CDN: new SuperSonic({ sampleBaseURL: "https://unpkg.com/supersonic-scsynth-samples@latest/samples/" })
4
- Or install: npm install supersonic-scsynth-samples`);return this.#t+e}#g(e){if(!Number.isInteger(e)||e<0||e>=this.MAX_BUFFERS)throw new Error(`Invalid buffer number ${e} (must be 0-${this.MAX_BUFFERS-1})`)}async#h(e,t,r){let s=null,n=null,a=!1,c=await this.#l(e),l=!1;try{await this.#p(e);let{ptr:u,sizeBytes:h,numFrames:f,numChannels:w,sampleRate:m,...S}=await r();s=u;let{uuid:p,allocationComplete:d}=this.#T(e,t);n=p,this.#S(e,s,h,p,d,{numFrames:f,numChannels:w,sampleRate:m}),a=!0;let E=this.#_(e,p,d);return c(),l=!0,{ptr:s,uuid:p,allocationComplete:E,numFrames:f,numChannels:w,sampleRate:m,...S}}catch(u){throw a&&n?this.#B(e,n,!1):s&&this.#a.free(s),u}finally{l||c()}}async prepareFromBlob(e){let{bufnum:t,blob:r,startFrame:s=0,numFrames:n=0,channels:a=null}=e;if(this.#g(t),!r||!(r instanceof ArrayBuffer||ArrayBuffer.isView(r)))throw new Error("/b_allocFile requires audio data as ArrayBuffer or typed array");let c=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);return this.#h(t,3e4,async()=>{let l=await this.#d.decodeAudioData(c),u=Math.max(0,Math.floor(s||0)),h=l.length-u,f=n&&n>0?Math.min(Math.floor(n),h):h;if(f<=0)throw new Error(`No audio frames available for buffer ${t}`);let w=this.#f(a,l.numberOfChannels),m=w.length,S=f*m+(this.GUARD_BEFORE+this.GUARD_AFTER)*m,p=this.#m(S),d=new Float32Array(S),E=this.GUARD_BEFORE*m;for(let y=0;y<f;y++)for(let g=0;g<m;g++){let A=w[g],T=l.getChannelData(A);d[E+y*m+g]=T[u+y]}this.#w(p,d);let _=d.length*4;return{ptr:p,sizeBytes:_,numFrames:f,numChannels:m,sampleRate:l.sampleRate}})}async prepareFromFile(e){let{bufnum:t,path:r,startFrame:s=0,numFrames:n=0,channels:a=null}=e;return this.#g(t),this.#h(t,6e4,async()=>{let c=this.#E(r),l=r.split("/").pop(),u=await this.#n.fetch(c,{type:"sample",name:l}),h=await this.#d.decodeAudioData(u),f=Math.max(0,Math.floor(s||0)),w=h.length-f,m=n&&n>0?Math.min(Math.floor(n),w):w;if(m<=0)throw new Error(`No audio frames available for buffer ${t} from ${r}`);let S=this.#f(a,h.numberOfChannels),p=S.length,d=m*p+(this.GUARD_BEFORE+this.GUARD_AFTER)*p,E=this.#m(d),_=new Float32Array(d),y=this.GUARD_BEFORE*p;for(let A=0;A<m;A++)for(let T=0;T<p;T++){let we=S[T],Ee=h.getChannelData(we);_[y+A*p+T]=Ee[f+A]}this.#w(E,_);let g=_.length*4;return{ptr:E,sizeBytes:g,numFrames:m,numChannels:p,sampleRate:h.sampleRate}})}async prepareEmpty(e){let{bufnum:t,numFrames:r,numChannels:s=1,sampleRate:n=null}=e;if(this.#g(t),!Number.isFinite(r)||r<=0)throw new Error(`/b_alloc requires a positive number of frames (got ${r})`);if(!Number.isFinite(s)||s<=0)throw new Error(`/b_alloc requires a positive channel count (got ${s})`);let a=Math.floor(r),c=Math.floor(s);return this.#h(t,5e3,async()=>{let l=a*c+(this.GUARD_BEFORE+this.GUARD_AFTER)*c,u=this.#m(l),h=new Float32Array(l);this.#w(u,h);let f=h.length*4;return{ptr:u,sizeBytes:f,numFrames:a,numChannels:c,sampleRate:n||this.#d.sampleRate}})}#f(e,t){return!e||e.length===0?Array.from({length:t},(r,s)=>s):(e.forEach(r=>{if(!Number.isInteger(r)||r<0||r>=t)throw new Error(`Channel ${r} is out of range (file has ${t} channels)`)}),e)}#m(e){let t=e*4,r=this.#a.malloc(t);if(r===0){let s=this.#a.stats(),n=((s.available||0)/(1024*1024)).toFixed(2),a=((s.total||0)/(1024*1024)).toFixed(2),c=(t/(1024*1024)).toFixed(2);throw new Error(`Buffer pool allocation failed: requested ${c}MB, available ${n}MB of ${a}MB total`)}return r}#w(e,t){new Float32Array(this.#o,e,t.length).set(t)}#y(e,t,r){return new Promise((s,n)=>{let a=setTimeout(()=>{this.#e.delete(e),n(new Error(`Buffer ${t} allocation timeout (${r}ms)`))},r);this.#e.set(e,{resolve:s,reject:n,timeout:a})})}#T(e,t){let r=crypto.randomUUID(),s=this.#y(r,e,t);return{uuid:r,allocationComplete:s}}async#l(e){let t=this.#c.get(e)||Promise.resolve(),r,s=new Promise(n=>{r=n});return this.#c.set(e,t.then(()=>s)),await t,()=>{r&&(r(),r=null),this.#c.get(e)===s&&this.#c.delete(e)}}#S(e,t,r,s,n,a={}){let c=this.#r.get(e),l={ptr:t,size:r,numFrames:a.numFrames||0,numChannels:a.numChannels||1,sampleRate:a.sampleRate||48e3,pendingToken:s,pendingPromise:n,previousAllocation:c?{ptr:c.ptr,size:c.size}:null};return this.#r.set(e,l),l}async#p(e){let t=this.#r.get(e);if(t&&t.pendingToken&&t.pendingPromise)try{await t.pendingPromise}catch{}}#_(e,t,r){return!r||typeof r.then!="function"?(this.#B(e,t,!0),Promise.resolve()):r.then(s=>(this.#B(e,t,!0),s)).catch(s=>{throw this.#B(e,t,!1),s})}#B(e,t,r){let s=this.#r.get(e);if(!s||s.pendingToken!==t)return;let n=s.previousAllocation;if(r){s.pendingToken=null,s.pendingPromise=null,s.previousAllocation=null,n?.ptr&&this.#a.free(n.ptr);return}s.ptr&&this.#a.free(s.ptr),s.pendingPromise=null,n?.ptr?this.#r.set(e,{ptr:n.ptr,size:n.size,pendingToken:null,previousAllocation:null}):this.#r.delete(e)}handleBufferFreed(e){let t=e[0],r=e[1],s=this.#r.get(t);if(!s){typeof r=="number"&&r!==0&&this.#a.free(r);return}if(typeof r=="number"&&r===s.ptr){this.#a.free(s.ptr),this.#r.delete(t);return}if(typeof r=="number"&&s.previousAllocation&&s.previousAllocation.ptr===r){this.#a.free(r),s.previousAllocation=null;return}this.#a.free(s.ptr),this.#r.delete(t)}handleBufferAllocated(e){let t=e[0],r=e[1],s=this.#e.get(t);s&&(clearTimeout(s.timeout),s.resolve({bufnum:r}),this.#e.delete(t))}allocate(e){let t=e*4,r=this.#a.malloc(t);if(r===0){let s=this.#a.stats(),n=((s.available||0)/(1024*1024)).toFixed(2),a=((s.total||0)/(1024*1024)).toFixed(2),c=(t/(1024*1024)).toFixed(2);console.error(`[BufferManager] Allocation failed: requested ${c}MB, available ${n}MB of ${a}MB total`)}return r}free(e){return this.#a.free(e)}getView(e,t){return new Float32Array(this.#o,e,t)}getStats(){return this.#a.stats()}getAllocatedBuffers(){let e=[];for(let[t,r]of this.#r.entries())!r||!r.ptr||e.push({bufnum:t,ptr:r.ptr,numFrames:r.numFrames,numChannels:r.numChannels,sampleRate:r.sampleRate});return e}updateAudioContext(e){if(!e)throw new Error("BufferManager.updateAudioContext requires audioContext");this.#d=e}getDiagnostics(){let e=this.#a.stats(),t=0,r=0;for(let s of this.#r.values())s&&(t+=s.size||0,s.pendingToken&&r++);return{active:this.#r.size,pending:r,bytesActive:t,pool:{total:this.#s,available:e.available||0,freeBytes:e.free?.size||0,freeBlocks:e.free?.count||0,usedBytes:e.used?.size||0,usedBlocks:e.used?.count||0}}}destroy(){for(let[e,t]of this.#e.entries())clearTimeout(t.timeout),t.reject(new Error("BufferManager destroyed"));this.#e.clear();for(let[e,t]of this.#r.entries())t.ptr&&this.#a.free(t.ptr);this.#r.clear(),this.#c.clear()}};var P=class{#t;#n;#d;constructor(e={}){let{onLoadingEvent:t=null,maxRetries:r=3,baseDelay:s=1e3}=e;this.#t=t,this.#n=r,this.#d=s}async fetch(e,{type:t,name:r}){let s=this.#o(e),n=this.#a(e),a=await s;this.#t?.("loading:start",{type:t,name:r,...a!=null&&{size:a}});let l=await(await n).arrayBuffer();return this.#t?.("loading:complete",{type:t,name:r,size:l.byteLength}),l}async#o(e){try{let t=await fetch(e,{method:"HEAD"});if(t.ok){let r=t.headers.get("Content-Length");return r?parseInt(r,10):null}return null}catch{return null}}async#a(e){let t;for(let r=0;r<=this.#n;r++)try{let s=await fetch(e);if(s.status>=400&&s.status<500)throw new Error(`Failed to fetch ${e}: ${s.status} ${s.statusText}`);if(!s.ok)throw new Error(`Server error fetching ${e}: ${s.status} ${s.statusText}`);return s}catch(s){if(t=s,s.message.includes("Failed to fetch")&&s.message.includes("4"))throw s;if(r<this.#n){let n=this.#d*Math.pow(2,r);await this.#s(n)}}throw t}#s(e){return new Promise(t=>setTimeout(t,e))}};var x=class{#t;#n;constructor({bufferManager:e,getDefaultSampleRate:t}){if(!e)throw new Error("OSCRewriter requires bufferManager");if(typeof t!="function")throw new Error("OSCRewriter requires getDefaultSampleRate callback");this.#t=e,this.#n=t}async rewritePacket(e){if(e&&e.address){let{message:t,changed:r}=await this.#d(e);return{packet:t,changed:r}}if(this.#c(e)){let t=await Promise.all(e.packets.map(n=>this.rewritePacket(n)));if(!t.some(n=>n.changed))return{packet:e,changed:!1};let s=t.map(n=>n.packet);return{packet:{timeTag:e.timeTag,packets:s},changed:!0}}return{packet:e,changed:!1}}async#d(e){switch(e.address){case"/b_alloc":return{message:await this.#o(e),changed:!0};case"/b_allocRead":return{message:await this.#a(e),changed:!0};case"/b_allocReadChannel":return{message:await this.#s(e),changed:!0};case"/b_allocFile":return{message:await this.#r(e),changed:!0};default:return{message:e,changed:!1}}}async#o(e){let t=this.#w(e.args,0,"/b_alloc requires a buffer number"),r=this.#w(e.args,1,"/b_alloc requires a frame count"),s=2,n=1,a=this.#n();this.#S(this.#f(e.args,s))&&(n=Math.max(1,this.#y(e.args,s,1)),s++),this.#f(e.args,s)?.type==="b"&&s++,this.#S(this.#f(e.args,s))&&(a=this.#m(this.#f(e.args,s)));let c=await this.#t.prepareEmpty({bufnum:t,numFrames:r,numChannels:n,sampleRate:a});return this.#p(c.allocationComplete,`/b_alloc ${t}`),this.#e(t,c)}async#a(e){let t=this.#w(e.args,0,"/b_allocRead requires a buffer number"),r=this.#T(e.args,1,"/b_allocRead requires a file path"),s=this.#y(e.args,2,0),n=this.#y(e.args,3,0),a=await this.#t.prepareFromFile({bufnum:t,path:r,startFrame:s,numFrames:n});return this.#p(a.allocationComplete,`/b_allocRead ${t}`),this.#e(t,a)}async#s(e){let t=this.#w(e.args,0,"/b_allocReadChannel requires a buffer number"),r=this.#T(e.args,1,"/b_allocReadChannel requires a file path"),s=this.#y(e.args,2,0),n=this.#y(e.args,3,0),a=[];for(let l=4;l<(e.args?.length||0)&&this.#S(e.args[l]);l++)a.push(Math.floor(this.#m(e.args[l])));let c=await this.#t.prepareFromFile({bufnum:t,path:r,startFrame:s,numFrames:n,channels:a.length>0?a:null});return this.#p(c.allocationComplete,`/b_allocReadChannel ${t}`),this.#e(t,c)}async#r(e){let t=this.#w(e.args,0,"/b_allocFile requires a buffer number"),r=this.#l(e.args,1,"/b_allocFile requires audio file data as blob"),s=await this.#t.prepareFromBlob({bufnum:t,blob:r});return this.#p(s.allocationComplete,`/b_allocFile ${t}`),this.#e(t,s)}#e(e,t){return{address:"/b_allocPtr",args:[this.#E(e),this.#E(t.ptr),this.#E(t.numFrames),this.#E(t.numChannels),this.#g(t.sampleRate),this.#h(t.uuid)]}}#c(e){return e&&e.timeTag!==void 0&&Array.isArray(e.packets)}#E(e){return{type:"i",value:Math.floor(e)}}#g(e){return{type:"f",value:e}}#h(e){return{type:"s",value:String(e)}}#f(e,t){if(Array.isArray(e))return e[t]}#m(e){if(e!=null)return typeof e=="object"&&Object.prototype.hasOwnProperty.call(e,"value")?e.value:e}#w(e,t,r){let s=this.#m(this.#f(e,t));if(!Number.isFinite(s))throw new Error(r);return Math.floor(s)}#y(e,t,r=0){let s=this.#m(this.#f(e,t));return Number.isFinite(s)?Math.floor(s):r}#T(e,t,r){let s=this.#m(this.#f(e,t));if(typeof s!="string")throw new Error(r);return s}#l(e,t,r){let s=this.#f(e,t);if(!s||s.type!=="b")throw new Error(r);let n=this.#m(s);if(!(n instanceof Uint8Array||n instanceof ArrayBuffer))throw new Error(r);return n}#S(e){if(!e)return!1;let t=this.#m(e);return Number.isFinite(t)}#p(e,t){!e||typeof e.catch!="function"||e.catch(r=>{console.error(`[OSCRewriter] ${t} allocation failed:`,r)})}};function Ie(i,e,t=0){for(let r=0;r<=t;r++)if(Atomics.compareExchange(i,e,0,1)===0)return!0;return!1}function De(i,e){Atomics.store(i,e,0)}function ie({atomicView:i,dataView:e,uint8View:t,bufferConstants:r,ringBufferBase:s,controlIndices:n,oscMessage:a,maxSpins:c=0}){let l=a.length,u=r.MESSAGE_HEADER_SIZE+l;if(u>r.IN_BUFFER_SIZE-r.MESSAGE_HEADER_SIZE||!Ie(i,n.IN_WRITE_LOCK,c))return!1;try{let h=Atomics.load(i,n.IN_HEAD),f=Atomics.load(i,n.IN_TAIL);if((r.IN_BUFFER_SIZE-1-h+f)%r.IN_BUFFER_SIZE<u)return!1;let m=Atomics.add(i,n.IN_SEQUENCE,1),S=r.IN_BUFFER_SIZE-h;if(u>S){let d=new Uint8Array(r.MESSAGE_HEADER_SIZE),E=new DataView(d.buffer);E.setUint32(0,r.MESSAGE_MAGIC,!0),E.setUint32(4,u,!0),E.setUint32(8,m,!0),E.setUint32(12,0,!0);let _=s+r.IN_BUFFER_START+h,y=s+r.IN_BUFFER_START;if(S>=r.MESSAGE_HEADER_SIZE){t.set(d,_);let g=S-r.MESSAGE_HEADER_SIZE;t.set(a.subarray(0,g),_+r.MESSAGE_HEADER_SIZE),t.set(a.subarray(g),y)}else{t.set(d.subarray(0,S),_),t.set(d.subarray(S),y);let g=r.MESSAGE_HEADER_SIZE-S;t.set(a,y+g)}}else{let d=s+r.IN_BUFFER_START+h;e.setUint32(d,r.MESSAGE_MAGIC,!0),e.setUint32(d+4,u,!0),e.setUint32(d+8,m,!0),e.setUint32(d+12,0,!0),t.set(a,d+r.MESSAGE_HEADER_SIZE)}Atomics.load(i,n.IN_HEAD);let p=(h+u)%r.IN_BUFFER_SIZE;return Atomics.store(i,n.IN_HEAD,p),!0}finally{De(i,n.IN_WRITE_LOCK)}}var ve=.2,k=class{#t;#n;#d;#o;#a;#s;#r;#e;#c;constructor({sharedBuffer:e,ringBufferBase:t,bufferConstants:r,getAudioContextTime:s,getNTPStartTime:n}){if(!e||!r)throw new Error("DirectWriter requires sharedBuffer and bufferConstants");if(typeof s!="function")throw new Error("DirectWriter requires getAudioContextTime callback");if(typeof n!="function")throw new Error("DirectWriter requires getNTPStartTime callback");this.#t=e,this.#n=t,this.#d=r,this.#o=s,this.#a=n,this.#E()}tryWrite(e){return!this.#s||!this.#c||!this.#g(e)?!1:ie({atomicView:this.#s,dataView:this.#r,uint8View:this.#e,bufferConstants:this.#d,ringBufferBase:this.#n,controlIndices:this.#c,oscMessage:e})}isBundle(e){return e.length>=8&&e[0]===35}#E(){this.#s=new Int32Array(this.#t),this.#r=new DataView(this.#t),this.#e=new Uint8Array(this.#t);let e=this.#d.CONTROL_START;this.#c={IN_HEAD:(this.#n+e+0)/4,IN_TAIL:(this.#n+e+4)/4,IN_SEQUENCE:(this.#n+e+24)/4,IN_WRITE_LOCK:(this.#n+e+40)/4}}#g(e){if(!this.isBundle(e)||e.length<16)return!0;let t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=t.getUint32(8,!1),s=t.getUint32(12,!1);if(r===0&&(s===0||s===1))return!0;let n=this.#o(),a=this.#a();if(n===null||a===0)return!0;let c=n+a;return r+s/4294967296-c<ve}};function G(i){if(!i)return null;if(typeof i=="string")return(i.split("/").filter(Boolean).pop()||i).replace(/\.scsyndef$/i,"");let e=i instanceof ArrayBuffer?new Uint8Array(i):i;if(!(e instanceof Uint8Array)||e.length<11||e[0]!==83||e[1]!==67||e[2]!==103||e[3]!==102)return null;let t=e[10];if(t===0||11+t>e.length)return null;try{return new TextDecoder().decode(e.slice(11,11+t))}catch{return null}}function F(i){return i/1e3+2208988800}function Z(i,e){return i-e}function ne(i,e){let t=i-e;return Math.round(t*1e3)}var oe={totalPages:1280,ringBufferReserved:3145728,bufferPoolOffset:19922944,bufferPoolSize:63963136,get totalMemory(){return this.bufferPoolOffset+this.bufferPoolSize},get wasmHeapSize(){return this.bufferPoolOffset-this.ringBufferReserved}};var ae={numBuffers:1024,maxNodes:1024,maxGraphDefs:1024,maxWireBufs:64,numAudioBusChannels:128,numInputBusChannels:0,numOutputBusChannels:2,numControlBusChannels:4096,bufLength:128,realTimeMemorySize:8192,numRGens:64,realTime:!1,memoryLocking:!1,loadGraphDefs:0,preferredSampleRate:0,verbosity:0};var Se=class i{static osc={encode:e=>O.writePacket(e),decode:(e,t={metadata:!1})=>O.readPacket(e,t)};static inspect(e){let t,r,s;if(e instanceof i)t=e.sharedBuffer,r=e.ringBufferBase,s=e.bufferConstants;else if(e&&e.sab)t=e.sab,r=e.ringBufferBase??0,s=e.layout;else throw new Error("SuperSonic.inspect() requires an instance or {sab, ringBufferBase, layout}");if(!t||!s)return{error:"Not initialized - sab or layout missing"};let n=new Int32Array(t),a=r+s.CONTROL_START,c={inHead:Atomics.load(n,(a+0)/4),inTail:Atomics.load(n,(a+4)/4),outHead:Atomics.load(n,(a+8)/4),outTail:Atomics.load(n,(a+12)/4),debugHead:Atomics.load(n,(a+16)/4),debugTail:Atomics.load(n,(a+20)/4),inSequence:Atomics.load(n,(a+24)/4),outSequence:Atomics.load(n,(a+28)/4),debugSequence:Atomics.load(n,(a+32)/4),statusFlags:Atomics.load(n,(a+36)/4),inWriteLock:Atomics.load(n,(a+40)/4)},l=new Float64Array(t,r+s.NTP_START_TIME_START,1),u=new Int32Array(t,r+s.DRIFT_OFFSET_START,1),h=new Int32Array(t,r+s.GLOBAL_OFFSET_START,1),f={ntpStartTime:l[0],driftOffsetMs:Atomics.load(u,0),globalOffsetMs:Atomics.load(h,0)},w=(c.inHead-c.inTail+s.IN_BUFFER_SIZE)%s.IN_BUFFER_SIZE,m=(c.outHead-c.outTail+s.OUT_BUFFER_SIZE)%s.OUT_BUFFER_SIZE,S=(c.debugHead-c.debugTail+s.DEBUG_BUFFER_SIZE)%s.DEBUG_BUFFER_SIZE,p={in:{bytes:w,percent:w/s.IN_BUFFER_SIZE*100},out:{bytes:m,percent:m/s.OUT_BUFFER_SIZE*100},debug:{bytes:S,percent:S/s.DEBUG_BUFFER_SIZE*100}},d=new Uint32Array(t,r+s.METRICS_START,s.METRICS_SIZE/4),E={processCount:d[0],messagesProcessed:d[1],messagesDropped:d[2],schedulerQueueDepth:d[3],schedulerQueueMax:d[4],schedulerQueueDropped:d[5]};return{layout:s,ringBufferBase:r,control:c,timing:f,bufferUsage:p,metrics:E,sabByteLength:t.byteLength}}#t;#n;#d=null;#o;#a;#s;#r;#e;#c;#E;#g;#h;#f;#m;#w;#y;#T;#l;#S;#p;#_;#B;#i;#D;#I;#A;#R;#O;#v;#U=null;#x=!1;#N=100;#b=new Map;#z=null;#M=null;constructor(e={}){this.#l=!1,this.#S=!1,this.#p=null,this.#_={},this.#B=null,this.#s=null,this.#r=null,this.#e=null,this.#t=null,this.#n=null,this.#o=null,this.#c=null,this.loadedSynthDefs=new Map;let t=e.baseURL,r=e.workerBaseURL||(t?`${t}workers/`:null),s=e.wasmBaseURL||(t?`${t}wasm/`:null);if(!r||!s)throw new Error(`SuperSonic requires baseURL or explicit workerBaseURL and wasmBaseURL options. Example:
4
+ Or install: npm install supersonic-scsynth-samples`);return this.#t+e}#E(e){if(!Number.isInteger(e)||e<0||e>=this.MAX_BUFFERS)throw new Error(`Invalid buffer number ${e} (must be 0-${this.MAX_BUFFERS-1})`)}async#h(e,t,r){let s=null,n=null,a=!1,c=await this.#l(e),l=!1;try{await this.#p(e);let{ptr:u,sizeBytes:h,numFrames:f,numChannels:w,sampleRate:m,...S}=await r();s=u;let{uuid:p,allocationComplete:d}=this.#T(e,t);n=p,this.#S(e,s,h,p,d,{numFrames:f,numChannels:w,sampleRate:m}),a=!0;let g=this.#_(e,p,d);return c(),l=!0,{ptr:s,uuid:p,allocationComplete:g,numFrames:f,numChannels:w,sampleRate:m,...S}}catch(u){throw a&&n?this.#B(e,n,!1):s&&this.#a.free(s),u}finally{l||c()}}async prepareFromBlob(e){let{bufnum:t,blob:r,startFrame:s=0,numFrames:n=0,channels:a=null}=e;if(this.#E(t),!r||!(r instanceof ArrayBuffer||ArrayBuffer.isView(r)))throw new Error("/b_allocFile requires audio data as ArrayBuffer or typed array");let c=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);return this.#h(t,3e4,async()=>{let l=await this.#d.decodeAudioData(c),u=Math.max(0,Math.floor(s||0)),h=l.length-u,f=n&&n>0?Math.min(Math.floor(n),h):h;if(f<=0)throw new Error(`No audio frames available for buffer ${t}`);let w=this.#f(a,l.numberOfChannels),m=w.length,S=f*m+(this.GUARD_BEFORE+this.GUARD_AFTER)*m,p=this.#m(S),d=new Float32Array(S),g=this.GUARD_BEFORE*m;for(let y=0;y<f;y++)for(let E=0;E<m;E++){let b=w[E],T=l.getChannelData(b);d[g+y*m+E]=T[u+y]}this.#w(p,d);let _=d.length*4;return{ptr:p,sizeBytes:_,numFrames:f,numChannels:m,sampleRate:l.sampleRate}})}async prepareFromFile(e){let{bufnum:t,path:r,startFrame:s=0,numFrames:n=0,channels:a=null}=e;return this.#E(t),this.#h(t,6e4,async()=>{let c=this.#g(r),l=r.split("/").pop(),u=await this.#n.fetch(c,{type:"sample",name:l}),h=await this.#d.decodeAudioData(u),f=Math.max(0,Math.floor(s||0)),w=h.length-f,m=n&&n>0?Math.min(Math.floor(n),w):w;if(m<=0)throw new Error(`No audio frames available for buffer ${t} from ${r}`);let S=this.#f(a,h.numberOfChannels),p=S.length,d=m*p+(this.GUARD_BEFORE+this.GUARD_AFTER)*p,g=this.#m(d),_=new Float32Array(d),y=this.GUARD_BEFORE*p;for(let b=0;b<m;b++)for(let T=0;T<p;T++){let we=S[T],ge=h.getChannelData(we);_[y+b*p+T]=ge[f+b]}this.#w(g,_);let E=_.length*4;return{ptr:g,sizeBytes:E,numFrames:m,numChannels:p,sampleRate:h.sampleRate}})}async prepareEmpty(e){let{bufnum:t,numFrames:r,numChannels:s=1,sampleRate:n=null}=e;if(this.#E(t),!Number.isFinite(r)||r<=0)throw new Error(`/b_alloc requires a positive number of frames (got ${r})`);if(!Number.isFinite(s)||s<=0)throw new Error(`/b_alloc requires a positive channel count (got ${s})`);let a=Math.floor(r),c=Math.floor(s);return this.#h(t,5e3,async()=>{let l=a*c+(this.GUARD_BEFORE+this.GUARD_AFTER)*c,u=this.#m(l),h=new Float32Array(l);this.#w(u,h);let f=h.length*4;return{ptr:u,sizeBytes:f,numFrames:a,numChannels:c,sampleRate:n||this.#d.sampleRate}})}#f(e,t){return!e||e.length===0?Array.from({length:t},(r,s)=>s):(e.forEach(r=>{if(!Number.isInteger(r)||r<0||r>=t)throw new Error(`Channel ${r} is out of range (file has ${t} channels)`)}),e)}#m(e){let t=e*4,r=this.#a.malloc(t);if(r===0){let s=this.#a.stats(),n=((s.available||0)/(1024*1024)).toFixed(2),a=((s.total||0)/(1024*1024)).toFixed(2),c=(t/(1024*1024)).toFixed(2);throw new Error(`Buffer pool allocation failed: requested ${c}MB, available ${n}MB of ${a}MB total`)}return r}#w(e,t){new Float32Array(this.#o,e,t.length).set(t)}#y(e,t,r){return new Promise((s,n)=>{let a=setTimeout(()=>{this.#e.delete(e),n(new Error(`Buffer ${t} allocation timeout (${r}ms)`))},r);this.#e.set(e,{resolve:s,reject:n,timeout:a})})}#T(e,t){let r=crypto.randomUUID(),s=this.#y(r,e,t);return{uuid:r,allocationComplete:s}}async#l(e){let t=this.#c.get(e)||Promise.resolve(),r,s=new Promise(n=>{r=n});return this.#c.set(e,t.then(()=>s)),await t,()=>{r&&(r(),r=null),this.#c.get(e)===s&&this.#c.delete(e)}}#S(e,t,r,s,n,a={}){let c=this.#r.get(e),l={ptr:t,size:r,numFrames:a.numFrames||0,numChannels:a.numChannels||1,sampleRate:a.sampleRate||48e3,pendingToken:s,pendingPromise:n,previousAllocation:c?{ptr:c.ptr,size:c.size}:null};return this.#r.set(e,l),l}async#p(e){let t=this.#r.get(e);if(t&&t.pendingToken&&t.pendingPromise)try{await t.pendingPromise}catch{}}#_(e,t,r){return!r||typeof r.then!="function"?(this.#B(e,t,!0),Promise.resolve()):r.then(s=>(this.#B(e,t,!0),s)).catch(s=>{throw this.#B(e,t,!1),s})}#B(e,t,r){let s=this.#r.get(e);if(!s||s.pendingToken!==t)return;let n=s.previousAllocation;if(r){s.pendingToken=null,s.pendingPromise=null,s.previousAllocation=null,n?.ptr&&this.#a.free(n.ptr);return}s.ptr&&this.#a.free(s.ptr),s.pendingPromise=null,n?.ptr?this.#r.set(e,{ptr:n.ptr,size:n.size,pendingToken:null,previousAllocation:null}):this.#r.delete(e)}handleBufferFreed(e){let t=e[0],r=e[1],s=this.#r.get(t);if(!s){typeof r=="number"&&r!==0&&this.#a.free(r);return}if(typeof r=="number"&&r===s.ptr){this.#a.free(s.ptr),this.#r.delete(t);return}if(typeof r=="number"&&s.previousAllocation&&s.previousAllocation.ptr===r){this.#a.free(r),s.previousAllocation=null;return}this.#a.free(s.ptr),this.#r.delete(t)}handleBufferAllocated(e){let t=e[0],r=e[1],s=this.#e.get(t);s&&(clearTimeout(s.timeout),s.resolve({bufnum:r}),this.#e.delete(t))}allocate(e){let t=e*4,r=this.#a.malloc(t);if(r===0){let s=this.#a.stats(),n=((s.available||0)/(1024*1024)).toFixed(2),a=((s.total||0)/(1024*1024)).toFixed(2),c=(t/(1024*1024)).toFixed(2);console.error(`[BufferManager] Allocation failed: requested ${c}MB, available ${n}MB of ${a}MB total`)}return r}free(e){return this.#a.free(e)}getView(e,t){return new Float32Array(this.#o,e,t)}getStats(){return this.#a.stats()}getAllocatedBuffers(){let e=[];for(let[t,r]of this.#r.entries())!r||!r.ptr||e.push({bufnum:t,ptr:r.ptr,numFrames:r.numFrames,numChannels:r.numChannels,sampleRate:r.sampleRate});return e}updateAudioContext(e){if(!e)throw new Error("BufferManager.updateAudioContext requires audioContext");this.#d=e}getDiagnostics(){let e=this.#a.stats(),t=0,r=0;for(let s of this.#r.values())s&&(t+=s.size||0,s.pendingToken&&r++);return{active:this.#r.size,pending:r,bytesActive:t,pool:{total:this.#s,available:e.available||0,freeBytes:e.free?.size||0,freeBlocks:e.free?.count||0,usedBytes:e.used?.size||0,usedBlocks:e.used?.count||0}}}destroy(){for(let[e,t]of this.#e.entries())clearTimeout(t.timeout),t.reject(new Error("BufferManager destroyed"));this.#e.clear();for(let[e,t]of this.#r.entries())t.ptr&&this.#a.free(t.ptr);this.#r.clear(),this.#c.clear()}};var P=class{#t;#n;#d;constructor(e={}){let{onLoadingEvent:t=null,maxRetries:r=3,baseDelay:s=1e3}=e;this.#t=t,this.#n=r,this.#d=s}async fetch(e,{type:t,name:r}){let s=this.#o(e),n=this.#a(e),a=await s;this.#t?.("loading:start",{type:t,name:r,...a!=null&&{size:a}});let l=await(await n).arrayBuffer();return this.#t?.("loading:complete",{type:t,name:r,size:l.byteLength}),l}async#o(e){try{let t=await fetch(e,{method:"HEAD"});if(t.ok){let r=t.headers.get("Content-Length");return r?parseInt(r,10):null}return null}catch{return null}}async#a(e){let t;for(let r=0;r<=this.#n;r++)try{let s=await fetch(e);if(s.status>=400&&s.status<500)throw new Error(`Failed to fetch ${e}: ${s.status} ${s.statusText}`);if(!s.ok)throw new Error(`Server error fetching ${e}: ${s.status} ${s.statusText}`);return s}catch(s){if(t=s,s.message.includes("Failed to fetch")&&s.message.includes("4"))throw s;if(r<this.#n){let n=this.#d*Math.pow(2,r);await this.#s(n)}}throw t}#s(e){return new Promise(t=>setTimeout(t,e))}};var x=class{#t;#n;constructor({bufferManager:e,getDefaultSampleRate:t}){if(!e)throw new Error("OSCRewriter requires bufferManager");if(typeof t!="function")throw new Error("OSCRewriter requires getDefaultSampleRate callback");this.#t=e,this.#n=t}async rewritePacket(e){if(e&&e.address){let{message:t,changed:r}=await this.#d(e);return{packet:t,changed:r}}if(this.#c(e)){let t=await Promise.all(e.packets.map(n=>this.rewritePacket(n)));if(!t.some(n=>n.changed))return{packet:e,changed:!1};let s=t.map(n=>n.packet);return{packet:{timeTag:e.timeTag,packets:s},changed:!0}}return{packet:e,changed:!1}}async#d(e){switch(e.address){case"/b_alloc":return{message:await this.#o(e),changed:!0};case"/b_allocRead":return{message:await this.#a(e),changed:!0};case"/b_allocReadChannel":return{message:await this.#s(e),changed:!0};case"/b_allocFile":return{message:await this.#r(e),changed:!0};default:return{message:e,changed:!1}}}async#o(e){let t=this.#w(e.args,0,"/b_alloc requires a buffer number"),r=this.#w(e.args,1,"/b_alloc requires a frame count"),s=2,n=1,a=this.#n();this.#S(this.#f(e.args,s))&&(n=Math.max(1,this.#y(e.args,s,1)),s++),this.#f(e.args,s)?.type==="b"&&s++,this.#S(this.#f(e.args,s))&&(a=this.#m(this.#f(e.args,s)));let c=await this.#t.prepareEmpty({bufnum:t,numFrames:r,numChannels:n,sampleRate:a});return this.#p(c.allocationComplete,`/b_alloc ${t}`),this.#e(t,c)}async#a(e){let t=this.#w(e.args,0,"/b_allocRead requires a buffer number"),r=this.#T(e.args,1,"/b_allocRead requires a file path"),s=this.#y(e.args,2,0),n=this.#y(e.args,3,0),a=await this.#t.prepareFromFile({bufnum:t,path:r,startFrame:s,numFrames:n});return this.#p(a.allocationComplete,`/b_allocRead ${t}`),this.#e(t,a)}async#s(e){let t=this.#w(e.args,0,"/b_allocReadChannel requires a buffer number"),r=this.#T(e.args,1,"/b_allocReadChannel requires a file path"),s=this.#y(e.args,2,0),n=this.#y(e.args,3,0),a=[];for(let l=4;l<(e.args?.length||0)&&this.#S(e.args[l]);l++)a.push(Math.floor(this.#m(e.args[l])));let c=await this.#t.prepareFromFile({bufnum:t,path:r,startFrame:s,numFrames:n,channels:a.length>0?a:null});return this.#p(c.allocationComplete,`/b_allocReadChannel ${t}`),this.#e(t,c)}async#r(e){let t=this.#w(e.args,0,"/b_allocFile requires a buffer number"),r=this.#l(e.args,1,"/b_allocFile requires audio file data as blob"),s=await this.#t.prepareFromBlob({bufnum:t,blob:r});return this.#p(s.allocationComplete,`/b_allocFile ${t}`),this.#e(t,s)}#e(e,t){return{address:"/b_allocPtr",args:[this.#g(e),this.#g(t.ptr),this.#g(t.numFrames),this.#g(t.numChannels),this.#E(t.sampleRate),this.#h(t.uuid)]}}#c(e){return e&&e.timeTag!==void 0&&Array.isArray(e.packets)}#g(e){return{type:"i",value:Math.floor(e)}}#E(e){return{type:"f",value:e}}#h(e){return{type:"s",value:String(e)}}#f(e,t){if(Array.isArray(e))return e[t]}#m(e){if(e!=null)return typeof e=="object"&&Object.prototype.hasOwnProperty.call(e,"value")?e.value:e}#w(e,t,r){let s=this.#m(this.#f(e,t));if(!Number.isFinite(s))throw new Error(r);return Math.floor(s)}#y(e,t,r=0){let s=this.#m(this.#f(e,t));return Number.isFinite(s)?Math.floor(s):r}#T(e,t,r){let s=this.#m(this.#f(e,t));if(typeof s!="string")throw new Error(r);return s}#l(e,t,r){let s=this.#f(e,t);if(!s||s.type!=="b")throw new Error(r);let n=this.#m(s);if(!(n instanceof Uint8Array||n instanceof ArrayBuffer))throw new Error(r);return n}#S(e){if(!e)return!1;let t=this.#m(e);return Number.isFinite(t)}#p(e,t){!e||typeof e.catch!="function"||e.catch(r=>{console.error(`[OSCRewriter] ${t} allocation failed:`,r)})}};function Ce(i,e,t=0){for(let r=0;r<=t;r++)if(Atomics.compareExchange(i,e,0,1)===0)return!0;return!1}function Ie(i,e){Atomics.store(i,e,0)}function ie({atomicView:i,dataView:e,uint8View:t,bufferConstants:r,ringBufferBase:s,controlIndices:n,oscMessage:a,maxSpins:c=0}){let l=a.length,u=r.MESSAGE_HEADER_SIZE+l;if(u>r.IN_BUFFER_SIZE-r.MESSAGE_HEADER_SIZE||!Ce(i,n.IN_WRITE_LOCK,c))return!1;try{let h=Atomics.load(i,n.IN_HEAD),f=Atomics.load(i,n.IN_TAIL);if((r.IN_BUFFER_SIZE-1-h+f)%r.IN_BUFFER_SIZE<u)return!1;let m=Atomics.add(i,n.IN_SEQUENCE,1),S=r.IN_BUFFER_SIZE-h;if(u>S){let d=new Uint8Array(r.MESSAGE_HEADER_SIZE),g=new DataView(d.buffer);g.setUint32(0,r.MESSAGE_MAGIC,!0),g.setUint32(4,u,!0),g.setUint32(8,m,!0),g.setUint32(12,0,!0);let _=s+r.IN_BUFFER_START+h,y=s+r.IN_BUFFER_START;if(S>=r.MESSAGE_HEADER_SIZE){t.set(d,_);let E=S-r.MESSAGE_HEADER_SIZE;t.set(a.subarray(0,E),_+r.MESSAGE_HEADER_SIZE),t.set(a.subarray(E),y)}else{t.set(d.subarray(0,S),_),t.set(d.subarray(S),y);let E=r.MESSAGE_HEADER_SIZE-S;t.set(a,y+E)}}else{let d=s+r.IN_BUFFER_START+h;e.setUint32(d,r.MESSAGE_MAGIC,!0),e.setUint32(d+4,u,!0),e.setUint32(d+8,m,!0),e.setUint32(d+12,0,!0),t.set(a,d+r.MESSAGE_HEADER_SIZE)}Atomics.load(i,n.IN_HEAD);let p=(h+u)%r.IN_BUFFER_SIZE;return Atomics.store(i,n.IN_HEAD,p),!0}finally{Ie(i,n.IN_WRITE_LOCK)}}var ve=.2,k=class{#t;#n;#d;#o;#a;#s;#r;#e;#c;constructor({sharedBuffer:e,ringBufferBase:t,bufferConstants:r,getAudioContextTime:s,getNTPStartTime:n}){if(!e||!r)throw new Error("DirectWriter requires sharedBuffer and bufferConstants");if(typeof s!="function")throw new Error("DirectWriter requires getAudioContextTime callback");if(typeof n!="function")throw new Error("DirectWriter requires getNTPStartTime callback");this.#t=e,this.#n=t,this.#d=r,this.#o=s,this.#a=n,this.#g()}tryWrite(e){return!this.#s||!this.#c||!this.#E(e)?!1:ie({atomicView:this.#s,dataView:this.#r,uint8View:this.#e,bufferConstants:this.#d,ringBufferBase:this.#n,controlIndices:this.#c,oscMessage:e})}isBundle(e){return e.length>=8&&e[0]===35}#g(){this.#s=new Int32Array(this.#t),this.#r=new DataView(this.#t),this.#e=new Uint8Array(this.#t);let e=this.#d.CONTROL_START;this.#c={IN_HEAD:(this.#n+e+0)/4,IN_TAIL:(this.#n+e+4)/4,IN_SEQUENCE:(this.#n+e+24)/4,IN_WRITE_LOCK:(this.#n+e+40)/4}}#E(e){if(!this.isBundle(e)||e.length<16)return!0;let t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=t.getUint32(8,!1),s=t.getUint32(12,!1);if(r===0&&(s===0||s===1))return!0;let n=this.#o(),a=this.#a();if(n===null||a===0)return!0;let c=n+a;return r+s/4294967296-c<ve}};function G(i){if(!i)return null;if(typeof i=="string")return(i.split("/").filter(Boolean).pop()||i).replace(/\.scsyndef$/i,"");let e=i instanceof ArrayBuffer?new Uint8Array(i):i;if(!(e instanceof Uint8Array)||e.length<11||e[0]!==83||e[1]!==67||e[2]!==103||e[3]!==102)return null;let t=e[10];if(t===0||11+t>e.length)return null;try{return new TextDecoder().decode(e.slice(11,11+t))}catch{return null}}function F(i){return i/1e3+2208988800}function Z(i,e){return i-e}function ne(i,e){let t=i-e;return Math.round(t*1e3)}var oe={totalPages:1280,ringBufferReserved:3145728,bufferPoolOffset:19922944,bufferPoolSize:63963136,get totalMemory(){return this.bufferPoolOffset+this.bufferPoolSize},get wasmHeapSize(){return this.bufferPoolOffset-this.ringBufferReserved}};var ae={numBuffers:1024,maxNodes:1024,maxGraphDefs:1024,maxWireBufs:64,numAudioBusChannels:128,numInputBusChannels:0,numOutputBusChannels:2,numControlBusChannels:4096,bufLength:128,realTimeMemorySize:8192,numRGens:64,realTime:!1,memoryLocking:!1,loadGraphDefs:0,preferredSampleRate:0,verbosity:0};var Se=class i{static osc={encode:e=>O.writePacket(e),decode:(e,t={metadata:!1})=>O.readPacket(e,t)};static inspect(e){let t,r,s;if(e instanceof i)t=e.sharedBuffer,r=e.ringBufferBase,s=e.bufferConstants;else if(e&&e.sab)t=e.sab,r=e.ringBufferBase??0,s=e.layout;else throw new Error("SuperSonic.inspect() requires an instance or {sab, ringBufferBase, layout}");if(!t||!s)return{error:"Not initialized - sab or layout missing"};let n=new Int32Array(t),a=r+s.CONTROL_START,c={inHead:Atomics.load(n,(a+0)/4),inTail:Atomics.load(n,(a+4)/4),outHead:Atomics.load(n,(a+8)/4),outTail:Atomics.load(n,(a+12)/4),debugHead:Atomics.load(n,(a+16)/4),debugTail:Atomics.load(n,(a+20)/4),inSequence:Atomics.load(n,(a+24)/4),outSequence:Atomics.load(n,(a+28)/4),debugSequence:Atomics.load(n,(a+32)/4),statusFlags:Atomics.load(n,(a+36)/4),inWriteLock:Atomics.load(n,(a+40)/4)},l=new Float64Array(t,r+s.NTP_START_TIME_START,1),u=new Int32Array(t,r+s.DRIFT_OFFSET_START,1),h=new Int32Array(t,r+s.GLOBAL_OFFSET_START,1),f={ntpStartTime:l[0],driftOffsetMs:Atomics.load(u,0),globalOffsetMs:Atomics.load(h,0)},w=(c.inHead-c.inTail+s.IN_BUFFER_SIZE)%s.IN_BUFFER_SIZE,m=(c.outHead-c.outTail+s.OUT_BUFFER_SIZE)%s.OUT_BUFFER_SIZE,S=(c.debugHead-c.debugTail+s.DEBUG_BUFFER_SIZE)%s.DEBUG_BUFFER_SIZE,p={in:{bytes:w,percent:w/s.IN_BUFFER_SIZE*100},out:{bytes:m,percent:m/s.OUT_BUFFER_SIZE*100},debug:{bytes:S,percent:S/s.DEBUG_BUFFER_SIZE*100}},d=new Uint32Array(t,r+s.METRICS_START,s.METRICS_SIZE/4),g={processCount:d[0],messagesProcessed:d[1],messagesDropped:d[2],schedulerQueueDepth:d[3],schedulerQueueMax:d[4],schedulerQueueDropped:d[5]};return{layout:s,ringBufferBase:r,control:c,timing:f,bufferUsage:p,metrics:g,sabByteLength:t.byteLength}}#t;#n;#d=null;#o;#a;#s;#r;#e;#c;#g;#E;#h;#f;#m;#w;#y;#T;#l;#S;#p;#_;#B;#i;#I;#C;#b;#R;#O;#v;#U=null;#x=!1;#N=100;#A=new Map;#z=null;#M=null;constructor(e={}){this.#l=!1,this.#S=!1,this.#p=null,this.#_={},this.#B=null,this.#s=null,this.#r=null,this.#e=null,this.#t=null,this.#n=null,this.#o=null,this.#c=null,this.loadedSynthDefs=new Map;let t=e.baseURL,r=e.workerBaseURL||(t?`${t}workers/`:null),s=e.wasmBaseURL||(t?`${t}wasm/`:null);if(!r||!s)throw new Error(`SuperSonic requires baseURL or explicit workerBaseURL and wasmBaseURL options. Example:
5
5
  new SuperSonic({
6
6
  baseURL: "/supersonic/"
7
7
  })
@@ -9,7 +9,7 @@ new SuperSonic({
9
9
  new SuperSonic({
10
10
  workerBaseURL: "/supersonic/workers/",
11
11
  wasmBaseURL: "/supersonic/wasm/"
12
- })`);let n={...ae,...e.scsynthOptions};this.#i={wasmUrl:e.wasmUrl||s+"scsynth-nrt.wasm",wasmBaseURL:s,workletUrl:e.workletUrl||r+"scsynth_audio_worklet.js",workerBaseURL:r,audioContext:e.audioContext||null,autoConnect:e.autoConnect!==!1,audioContextOptions:{latencyHint:"interactive",sampleRate:48e3},memory:oe,worldOptions:n,preschedulerCapacity:e.preschedulerCapacity||65536,activityEvent:{maxLineLength:e.activityEvent?.maxLineLength??200,scsynth:e.activityEvent?.scsynth??null,oscIn:e.activityEvent?.oscIn??null,oscOut:e.activityEvent?.oscOut??null},debug:e.debug??!1,debugScsynth:e.debugScsynth??!1,debugOscIn:e.debugOscIn??!1,debugOscOut:e.debugOscOut??!1,activityConsoleLog:{maxLineLength:e.activityConsoleLog?.maxLineLength??200,scsynth:e.activityConsoleLog?.scsynth??null,oscIn:e.activityConsoleLog?.oscIn??null,oscOut:e.activityConsoleLog?.oscOut??null}},this.#m=e.sampleBaseURL||(t?`${t}samples/`:null),this.#w=e.synthdefBaseURL||(t?`${t}synthdefs/`:null),this.#y={maxRetries:e.fetchMaxRetries??3,baseDelay:e.fetchRetryDelay??1e3},this.#T=new P({onLoadingEvent:(a,c)=>this.#u(a,c),maxRetries:this.#y.maxRetries,baseDelay:this.#y.baseDelay}),this.bootStats={initStartTime:null,initDuration:null}}get initialized(){return this.#l}get initializing(){return this.#S}on(e,t){if(typeof t!="function")throw new Error("Callback must be a function");return this.#b.has(e)||this.#b.set(e,new Set),this.#b.get(e).add(t),()=>this.off(e,t)}off(e,t){let r=this.#b.get(e);return r&&r.delete(t),this}once(e,t){let r=(...s)=>{this.off(e,r),t(...s)};return this.on(e,r)}removeAllListeners(e){return e===void 0?this.#b.clear():this.#b.delete(e),this}#u(e,...t){let r=this.#b.get(e);if(r)for(let s of r)try{s(...t)}catch(n){console.error(`[SuperSonic] Error in ${e} listener:`,n)}}async init(e={}){if(!this.#l)return this.#p?this.#p:(this.#p=this.#j(e),this.#p)}async#j(e){this.#i={...this.#i,...e,audioContextOptions:{...this.#i.audioContextOptions,...e.audioContextOptions||{}}},this.#S=!0,this.bootStats.initStartTime=performance.now();try{this.#re(),this.#se(),this.#$(),this.#ie(),this.#V();let t=await this.#W();await this.#H(t),await this.#G(),this.#q(),this.#F(),this.#Z()}catch(t){throw this.#S=!1,this.#p=null,console.error("[SuperSonic] Initialization failed:",t),this.#u("error",t),t}}getMetrics(){return this.#Y()}setMetricsInterval(e){this.#N=e,this.#F()}stopMetricsPolling(){this.#P()}async#X(){if(!this.#t||!this.#A)return!1;try{await this.#t.resume()}catch{}let e=this.#A[0];await new Promise(s=>setTimeout(s,200));let r=this.#A[0]>e;return r&&this.#K(),r}async recover(){if(!this.#l)return!1;if(await this.#X())return!0;this.#u("recover:start");let e=await this.#J();return this.#u("recover:complete",{success:e}),e}async#J(){if(!this.#l)return!1;let e=new Map(this.loadedSynthDefs),t=this.#c?.getAllocatedBuffers()||[];await this.#ee(),await this.#te();for(let[r,s]of e)try{await this.send("/d_recv",s)}catch(n){console.error(`[SuperSonic] Failed to restore synthdef ${r}:`,n)}for(let r of t)try{let s=crypto.randomUUID();await this.send("/b_allocPtr",r.bufnum,r.ptr,r.numFrames,r.numChannels,r.sampleRate,s)}catch(s){console.error(`[SuperSonic] Failed to restore buffer ${r.bufnum}:`,s)}return!0}async#ee(){this.#L(),this.#P(),this.#h?.clear(),this.#h=null,this.#o&&(this.#o.cancelAll(),this.#o.terminate(),this.#o=null),this.#n&&(this.#n.disconnect(),this.#n=null),this.#t&&(await this.#t.close(),this.#t=null),this.#l=!1,this.loadedSynthDefs.clear(),this.#p=null,this.#r=null,this.#e=null,this.#D=null,this.#I=null,this.#A=null,this.#R=null,this.#O=null,this.#v=null,this.#f=void 0}async#te(){this.#S=!0,this.bootStats.initStartTime=performance.now();try{this.#$(),this.#c&&this.#c.updateAudioContext(this.#t),this.#V();let e=await this.#W();await this.#H(e),await this.#G(),this.#q(),this.#F(),this.#Z()}catch(e){throw this.#S=!1,this.#p=null,console.error("[SuperSonic] Partial init failed:",e),this.#u("error",e),e}}getTree(){if(!this.#l||!this.#s||!this.#e)return{nodeCount:0,version:0,nodes:[]};let e=this.#e,t=this.#r+e.NODE_TREE_START,r=new Uint32Array(this.#s,t,2),s=r[0],n=r[1],a=t+e.NODE_TREE_HEADER_SIZE,c=e.NODE_TREE_MAX_NODES,l=e.NODE_TREE_ENTRY_SIZE,u=e.NODE_TREE_DEF_NAME_SIZE,h=new DataView(this.#s,a,c*l),f=new TextDecoder("utf-8"),w=[],m=0;for(let S=0;S<c&&m<s;S++){let p=S*l,d=h.getInt32(p,!0);if(d===-1)continue;m++;let E=a+p+24,_=new Uint8Array(this.#s,E,u),y=new Uint8Array(u);y.set(_);let g=y.indexOf(0);g===-1&&(g=u);let A=f.decode(y.subarray(0,g));w.push({id:d,parentId:h.getInt32(p+4,!0),isGroup:h.getInt32(p+8,!0)===1,prevId:h.getInt32(p+12,!0),nextId:h.getInt32(p+16,!0),headId:h.getInt32(p+20,!0),defName:A})}return{nodeCount:s,version:n,nodes:w}}get bufferConstants(){return this.#e}get ringBufferBase(){return this.#r}get sharedBuffer(){return this.#s}startCapture(){if(!this.#l||!this.#s||!this.#e)throw new Error("SuperSonic not initialized");let e=this.#e,t=this.#r+e.AUDIO_CAPTURE_START,r=new Uint32Array(this.#s,t,4);Atomics.store(r,1,0),Atomics.store(r,0,1)}stopCapture(){if(!this.#l||!this.#s||!this.#e)throw new Error("SuperSonic not initialized");let e=this.#e,t=this.#r+e.AUDIO_CAPTURE_START,r=new Uint32Array(this.#s,t,4);Atomics.store(r,0,0);let s=Atomics.load(r,1),n=r[2],a=r[3],c=t+e.AUDIO_CAPTURE_HEADER_SIZE,l=new Float32Array(this.#s,c,s*a),u=new Float32Array(s),h=a>1?new Float32Array(s):null;for(let f=0;f<s;f++)u[f]=l[f*a],h&&(h[f]=l[f*a+1]);return{sampleRate:n,channels:a,frames:s,left:u,right:h}}isCaptureEnabled(){if(!this.#l||!this.#s||!this.#e)return!1;let e=this.#e,t=this.#r+e.AUDIO_CAPTURE_START,r=new Uint32Array(this.#s,t,1);return Atomics.load(r,0)===1}getCaptureFrames(){if(!this.#l||!this.#s||!this.#e)return 0;let e=this.#e,t=this.#r+e.AUDIO_CAPTURE_START,r=new Uint32Array(this.#s,t,2);return Atomics.load(r,1)}getMaxCaptureDuration(){if(!this.#e)return 0;let e=this.#e;return e.AUDIO_CAPTURE_FRAMES/(e.AUDIO_CAPTURE_SAMPLE_RATE||48e3)}async send(e,...t){if(this.#C("send OSC messages"),e==="/d_load"||e==="/d_loadDir")throw new Error(`${e} is not supported in SuperSonic (no filesystem). Use loadSynthDef() or send /d_recv with synthdef bytes instead.`);if(e==="/b_read"||e==="/b_readChannel")throw new Error(`${e} is not supported in SuperSonic (no filesystem). Use loadSample() to load audio into a buffer.`);if(e==="/b_write"||e==="/b_close")throw new Error(`${e} is not supported in SuperSonic (no filesystem). Writing audio files is not available in the browser.`);if(e==="/clearSched")throw new Error("/clearSched is not supported in SuperSonic. Bundle scheduling works differently in the browser AudioWorklet environment.");if(e==="/dumpOSC")throw new Error("/dumpOSC is not supported in SuperSonic. Use browser developer tools to inspect OSC messages.");if(e==="/error")throw new Error("/error is not supported in SuperSonic. Error notifications are always enabled.");if(e==="/d_recv"){let a=t[0];if(a instanceof Uint8Array||a instanceof ArrayBuffer){let c=a instanceof ArrayBuffer?new Uint8Array(a):a,l=G(c)||"unknown";this.loadedSynthDefs.set(l,c)}}if(e==="/d_free")for(let a of t)typeof a=="string"&&this.loadedSynthDefs.delete(a);else e==="/d_freeAll"&&this.loadedSynthDefs.clear();let r=t.map(a=>{if(typeof a=="string")return{type:"s",value:a};if(typeof a=="number")return{type:Number.isInteger(a)?"i":"f",value:a};if(a instanceof Uint8Array||a instanceof ArrayBuffer)return{type:"b",value:a instanceof ArrayBuffer?new Uint8Array(a):a};throw new Error(`Unsupported argument type: ${typeof a}`)}),s={address:e,args:r},n=i.osc.encode(s);if(this.#i.debug||this.#i.debugOscOut){let a=this.#i.activityConsoleLog.oscOut??this.#i.activityConsoleLog.maxLineLength,c=t.map(l=>{if(l instanceof Uint8Array||l instanceof ArrayBuffer)return`<${l.byteLength||l.length} bytes>`;let u=JSON.stringify(l);return u.length>a?u.slice(0,a)+"...":u}).join(", ");console.log(`[OSC \u2192] ${e}${c?" "+c:""}`)}return this.sendOSC(n)}async sendOSC(e,t={}){this.#C("send OSC data");let r=this.#me(e),s=await this.#Se(r);if(this.#k("mainMessagesSent"),this.#k("mainBytesSent",s.length),this.#u("message:sent",s),this.#D?.tryWrite(s)){this.#k("preschedulerBypassed");return}let n=this.#e?.scheduler_slot_size;if(n&&s.length>n)throw new Error(`OSC bundle too large to schedule (${s.length} > ${n} bytes). Use immediate timestamp (0 or 1) for large messages, or reduce bundle size.`);let a=this.#we(s),c={...t};a&&(c.audioTimeS=a.audioTimeS,c.currentTimeS=a.currentTimeS),this.#o.send(s,c)}cancelTag(e){this.#C("cancel by tag"),this.#o.cancelTag(e)}cancelSession(e){this.#C("cancel by session"),this.#o.cancelSession(e)}cancelSessionTag(e,t){this.#C("cancel by session and tag"),this.#o.cancelSessionTag(e,t)}cancelAllScheduled(){this.#C("cancel all scheduled"),this.#o.cancelAll()}get node(){return this.#d}get osc(){return this.#o}async loadSynthDef(e){if(!this.#l)throw new Error("SuperSonic not initialized. Call init() first.");let t;if(this.#he(e))t=e;else{if(!this.#w)throw new Error("synthdefBaseURL not configured. Either provide a full path or set synthdefBaseURL in constructor options.");t=`${this.#w}${e}.scsyndef`}let r=G(t);try{let s=await this.#T.fetch(t,{type:"synthdef",name:r}),n=new Uint8Array(s);return await this.send("/d_recv",n),{name:r,size:n.length}}catch(s){throw console.error("[SuperSonic] Failed to load synthdef:",s),s}}async loadSynthDefs(e){if(!this.#l)throw new Error("SuperSonic not initialized. Call init() first.");let t={};await Promise.all(e.map(async s=>{try{await this.loadSynthDef(s),t[s]={success:!0}}catch(n){console.error(`[SuperSonic] Failed to load ${s}:`,n),t[s]={success:!1,error:n.message}}}));let r=Object.values(t).filter(s=>s.success).length;return t}async loadSample(e,t,r=0,s=0){this.#C("load samples");let n=await this.#c.prepareFromFile({bufnum:e,path:t,startFrame:r,numFrames:s});return await this.send("/b_allocPtr",e,n.ptr,n.numFrames,n.numChannels,n.sampleRate,n.uuid),n.allocationComplete}async sync(e=Math.floor(Math.random()*2147483647)){if(!this.#l)throw new Error("SuperSonic not initialized. Call init() first.");let t=new Promise((r,s)=>{let n=setTimeout(()=>{this.#h&&this.#h.delete(e),s(new Error("Timeout waiting for /synced response"))},1e4),a=c=>{clearTimeout(n),this.#h.delete(e),r()};this.#h||(this.#h=new Map),this.#h.set(e,a)});await this.send("/sync",e),await t}getInfo(){return this.#C("get info"),{sampleRate:this.#t.sampleRate,numBuffers:this.#i.worldOptions.numBuffers,totalMemory:this.#i.memory.totalMemory,wasmHeapSize:this.#i.memory.wasmHeapSize,bufferPoolSize:this.#i.memory.bufferPoolSize,bootTimeMs:this.bootStats.initDuration,capabilities:{...this.#_},version:this.#B}}async shutdown(){!this.#l&&!this.#S||(this.#u("shutdown"),this.#L(),this.#P(),this.#h?.clear(),this.#h=null,this.#o&&(this.#o.cancelAll(),this.#o.terminate(),this.#o=null),this.#n&&(this.#n.disconnect(),this.#n=null),this.#t&&(await this.#t.close(),this.#t=null),this.#c&&(this.#c.destroy(),this.#c=null),this.#E=null,this.#D=null,this.#s=null,this.#l=!1,this.loadedSynthDefs.clear(),this.#p=null,this.#a=null,this.#r=null,this.#e=null,this.#I=null,this.#A=null,this.#R=null,this.#O=null,this.#v=null,this.#f=void 0,this.bootStats={initStartTime:null,initDuration:null})}async destroy(){this.#u("destroy"),await this.shutdown(),this.#M=null,this.#b.clear()}async reset(e={}){await this.shutdown(),await this.init(e)}#re(){this.#_={audioWorklet:typeof AudioWorklet<"u",sharedArrayBuffer:typeof SharedArrayBuffer<"u",crossOriginIsolated:window.crossOriginIsolated===!0,atomics:typeof Atomics<"u",webWorker:typeof Worker<"u"};let t=["audioWorklet","sharedArrayBuffer","crossOriginIsolated","atomics","webWorker"].filter(r=>!this.#_[r]);if(t.length>0){let r=new Error(`Missing required features: ${t.join(", ")}`);throw this.#_.crossOriginIsolated||(this.#_.sharedArrayBuffer?r.message+=`
12
+ })`);let n={...ae,...e.scsynthOptions};this.#i={wasmUrl:e.wasmUrl||s+"scsynth-nrt.wasm",wasmBaseURL:s,workletUrl:e.workletUrl||r+"scsynth_audio_worklet.js",workerBaseURL:r,audioContext:e.audioContext||null,autoConnect:e.autoConnect!==!1,audioContextOptions:{latencyHint:"interactive",sampleRate:48e3},memory:oe,worldOptions:n,preschedulerCapacity:e.preschedulerCapacity||65536,activityEvent:{maxLineLength:e.activityEvent?.maxLineLength??200,scsynth:e.activityEvent?.scsynth??null,oscIn:e.activityEvent?.oscIn??null,oscOut:e.activityEvent?.oscOut??null},debug:e.debug??!1,debugScsynth:e.debugScsynth??!1,debugOscIn:e.debugOscIn??!1,debugOscOut:e.debugOscOut??!1,activityConsoleLog:{maxLineLength:e.activityConsoleLog?.maxLineLength??200,scsynth:e.activityConsoleLog?.scsynth??null,oscIn:e.activityConsoleLog?.oscIn??null,oscOut:e.activityConsoleLog?.oscOut??null}},this.#m=e.sampleBaseURL||(t?`${t}samples/`:null),this.#w=e.synthdefBaseURL||(t?`${t}synthdefs/`:null),this.#y={maxRetries:e.fetchMaxRetries??3,baseDelay:e.fetchRetryDelay??1e3},this.#T=new P({onLoadingEvent:(a,c)=>this.#u(a,c),maxRetries:this.#y.maxRetries,baseDelay:this.#y.baseDelay}),this.bootStats={initStartTime:null,initDuration:null}}get initialized(){return this.#l}get initializing(){return this.#S}on(e,t){if(typeof t!="function")throw new Error("Callback must be a function");return this.#A.has(e)||this.#A.set(e,new Set),this.#A.get(e).add(t),()=>this.off(e,t)}off(e,t){let r=this.#A.get(e);return r&&r.delete(t),this}once(e,t){let r=(...s)=>{this.off(e,r),t(...s)};return this.on(e,r)}removeAllListeners(e){return e===void 0?this.#A.clear():this.#A.delete(e),this}#u(e,...t){let r=this.#A.get(e);if(r)for(let s of r)try{s(...t)}catch(n){console.error(`[SuperSonic] Error in ${e} listener:`,n)}}async init(e={}){if(!this.#l)return this.#p?this.#p:(this.#p=this.#j(e),this.#p)}async#j(e){this.#i={...this.#i,...e,audioContextOptions:{...this.#i.audioContextOptions,...e.audioContextOptions||{}}},this.#S=!0,this.bootStats.initStartTime=performance.now();try{this.#re(),this.#se(),this.#$(),this.#ie(),this.#V();let t=await this.#W();await this.#H(t),await this.#G(),this.#q(),this.#F(),this.#Z()}catch(t){throw this.#S=!1,this.#p=null,console.error("[SuperSonic] Initialization failed:",t),this.#u("error",t),t}}getMetrics(){return this.#Y()}setMetricsInterval(e){this.#N=e,this.#F()}stopMetricsPolling(){this.#P()}async#X(){if(!this.#t||!this.#b)return!1;try{await this.#t.resume()}catch{}let e=this.#b[0];await new Promise(s=>setTimeout(s,200));let r=this.#b[0]>e;return r&&this.#K(),r}async recover(){if(!this.#l)return!1;if(await this.#X())return!0;this.#u("recover:start");let e=await this.#J();return this.#u("recover:complete",{success:e}),e}async#J(){if(!this.#l)return!1;let e=new Map(this.loadedSynthDefs),t=this.#c?.getAllocatedBuffers()||[];await this.#ee(),await this.#te();for(let[r,s]of e)try{await this.send("/d_recv",s)}catch(n){console.error(`[SuperSonic] Failed to restore synthdef ${r}:`,n)}for(let r of t)try{let s=crypto.randomUUID();await this.send("/b_allocPtr",r.bufnum,r.ptr,r.numFrames,r.numChannels,r.sampleRate,s)}catch(s){console.error(`[SuperSonic] Failed to restore buffer ${r.bufnum}:`,s)}return!0}async#ee(){this.#L(),this.#P(),this.#h?.clear(),this.#h=null,this.#o&&(this.#o.cancelAll(),this.#o.terminate(),this.#o=null),this.#n&&(this.#n.disconnect(),this.#n=null),this.#t&&(await this.#t.close(),this.#t=null),this.#l=!1,this.loadedSynthDefs.clear(),this.#p=null,this.#r=null,this.#e=null,this.#I=null,this.#C=null,this.#b=null,this.#R=null,this.#O=null,this.#v=null,this.#f=void 0}async#te(){this.#S=!0,this.bootStats.initStartTime=performance.now();try{this.#$(),this.#c&&this.#c.updateAudioContext(this.#t),this.#V();let e=await this.#W();await this.#H(e),await this.#G(),this.#q(),this.#F(),this.#Z()}catch(e){throw this.#S=!1,this.#p=null,console.error("[SuperSonic] Partial init failed:",e),this.#u("error",e),e}}getTree(){if(!this.#l||!this.#s||!this.#e)return{nodeCount:0,version:0,nodes:[]};let e=this.#e,t=this.#r+e.NODE_TREE_START,r=new Uint32Array(this.#s,t,2),s=r[0],n=r[1],a=t+e.NODE_TREE_HEADER_SIZE,c=e.NODE_TREE_MAX_NODES,l=e.NODE_TREE_ENTRY_SIZE,u=e.NODE_TREE_DEF_NAME_SIZE,h=new DataView(this.#s,a,c*l),f=new TextDecoder("utf-8"),w=[],m=0;for(let S=0;S<c&&m<s;S++){let p=S*l,d=h.getInt32(p,!0);if(d===-1)continue;m++;let g=a+p+24,_=new Uint8Array(this.#s,g,u),y=new Uint8Array(u);y.set(_);let E=y.indexOf(0);E===-1&&(E=u);let b=f.decode(y.subarray(0,E));w.push({id:d,parentId:h.getInt32(p+4,!0),isGroup:h.getInt32(p+8,!0)===1,prevId:h.getInt32(p+12,!0),nextId:h.getInt32(p+16,!0),headId:h.getInt32(p+20,!0),defName:b})}return{nodeCount:s,version:n,nodes:w}}get bufferConstants(){return this.#e}get ringBufferBase(){return this.#r}get sharedBuffer(){return this.#s}startCapture(){if(!this.#l||!this.#s||!this.#e)throw new Error("SuperSonic not initialized");let e=this.#e,t=this.#r+e.AUDIO_CAPTURE_START,r=new Uint32Array(this.#s,t,4);Atomics.store(r,1,0),Atomics.store(r,0,1)}stopCapture(){if(!this.#l||!this.#s||!this.#e)throw new Error("SuperSonic not initialized");let e=this.#e,t=this.#r+e.AUDIO_CAPTURE_START,r=new Uint32Array(this.#s,t,4);Atomics.store(r,0,0);let s=Atomics.load(r,1),n=r[2],a=r[3],c=t+e.AUDIO_CAPTURE_HEADER_SIZE,l=new Float32Array(this.#s,c,s*a),u=new Float32Array(s),h=a>1?new Float32Array(s):null;for(let f=0;f<s;f++)u[f]=l[f*a],h&&(h[f]=l[f*a+1]);return{sampleRate:n,channels:a,frames:s,left:u,right:h}}isCaptureEnabled(){if(!this.#l||!this.#s||!this.#e)return!1;let e=this.#e,t=this.#r+e.AUDIO_CAPTURE_START,r=new Uint32Array(this.#s,t,1);return Atomics.load(r,0)===1}getCaptureFrames(){if(!this.#l||!this.#s||!this.#e)return 0;let e=this.#e,t=this.#r+e.AUDIO_CAPTURE_START,r=new Uint32Array(this.#s,t,2);return Atomics.load(r,1)}getMaxCaptureDuration(){if(!this.#e)return 0;let e=this.#e;return e.AUDIO_CAPTURE_FRAMES/(e.AUDIO_CAPTURE_SAMPLE_RATE||48e3)}async send(e,...t){if(this.#D("send OSC messages"),e==="/d_load"||e==="/d_loadDir")throw new Error(`${e} is not supported in SuperSonic (no filesystem). Use loadSynthDef() or send /d_recv with synthdef bytes instead.`);if(e==="/b_read"||e==="/b_readChannel")throw new Error(`${e} is not supported in SuperSonic (no filesystem). Use loadSample() to load audio into a buffer.`);if(e==="/b_write"||e==="/b_close")throw new Error(`${e} is not supported in SuperSonic (no filesystem). Writing audio files is not available in the browser.`);if(e==="/clearSched")throw new Error("/clearSched is not supported in SuperSonic. Bundle scheduling works differently in the browser AudioWorklet environment.");if(e==="/dumpOSC")throw new Error("/dumpOSC is not supported in SuperSonic. Use browser developer tools to inspect OSC messages.");if(e==="/error")throw new Error("/error is not supported in SuperSonic. Error notifications are always enabled.");if(e==="/d_recv"){let a=t[0];if(a instanceof Uint8Array||a instanceof ArrayBuffer){let c=a instanceof ArrayBuffer?new Uint8Array(a):a,l=G(c)||"unknown";this.loadedSynthDefs.set(l,c)}}if(e==="/d_free")for(let a of t)typeof a=="string"&&this.loadedSynthDefs.delete(a);else e==="/d_freeAll"&&this.loadedSynthDefs.clear();let r=t.map(a=>{if(typeof a=="string")return{type:"s",value:a};if(typeof a=="number")return{type:Number.isInteger(a)?"i":"f",value:a};if(a instanceof Uint8Array||a instanceof ArrayBuffer)return{type:"b",value:a instanceof ArrayBuffer?new Uint8Array(a):a};throw new Error(`Unsupported argument type: ${typeof a}`)}),s={address:e,args:r},n=i.osc.encode(s);if(this.#i.debug||this.#i.debugOscOut){let a=this.#i.activityConsoleLog.oscOut??this.#i.activityConsoleLog.maxLineLength,c=t.map(l=>{if(l instanceof Uint8Array||l instanceof ArrayBuffer)return`<${l.byteLength||l.length} bytes>`;let u=JSON.stringify(l);return u.length>a?u.slice(0,a)+"...":u}).join(", ");console.log(`[OSC \u2192] ${e}${c?" "+c:""}`)}return this.sendOSC(n)}async sendOSC(e,t={}){this.#D("send OSC data");let r=this.#me(e),s=await this.#Se(r);if(this.#k("mainMessagesSent"),this.#k("mainBytesSent",s.length),this.#u("message:sent",s),this.#I?.tryWrite(s)){this.#k("preschedulerBypassed");return}let n=this.#e?.scheduler_slot_size;if(n&&s.length>n)throw new Error(`OSC bundle too large to schedule (${s.length} > ${n} bytes). Use immediate timestamp (0 or 1) for large messages, or reduce bundle size.`);let a=this.#we(s),c={...t};a&&(c.audioTimeS=a.audioTimeS,c.currentTimeS=a.currentTimeS),this.#o.send(s,c)}cancelTag(e){this.#D("cancel by tag"),this.#o.cancelTag(e)}cancelSession(e){this.#D("cancel by session"),this.#o.cancelSession(e)}cancelSessionTag(e,t){this.#D("cancel by session and tag"),this.#o.cancelSessionTag(e,t)}cancelAllScheduled(){this.#D("cancel all scheduled"),this.#o.cancelAll()}get node(){return this.#d}get osc(){return this.#o}async loadSynthDef(e){if(!this.#l)throw new Error("SuperSonic not initialized. Call init() first.");let t;if(this.#he(e))t=e;else{if(!this.#w)throw new Error("synthdefBaseURL not configured. Either provide a full path or set synthdefBaseURL in constructor options.");t=`${this.#w}${e}.scsyndef`}let r=G(t);try{let s=await this.#T.fetch(t,{type:"synthdef",name:r}),n=new Uint8Array(s);return await this.send("/d_recv",n),{name:r,size:n.length}}catch(s){throw console.error("[SuperSonic] Failed to load synthdef:",s),s}}async loadSynthDefs(e){if(!this.#l)throw new Error("SuperSonic not initialized. Call init() first.");let t={};await Promise.all(e.map(async s=>{try{await this.loadSynthDef(s),t[s]={success:!0}}catch(n){console.error(`[SuperSonic] Failed to load ${s}:`,n),t[s]={success:!1,error:n.message}}}));let r=Object.values(t).filter(s=>s.success).length;return t}async loadSample(e,t,r=0,s=0){this.#D("load samples");let n=await this.#c.prepareFromFile({bufnum:e,path:t,startFrame:r,numFrames:s});return await this.send("/b_allocPtr",e,n.ptr,n.numFrames,n.numChannels,n.sampleRate,n.uuid),n.allocationComplete}async sync(e=Math.floor(Math.random()*2147483647)){if(!this.#l)throw new Error("SuperSonic not initialized. Call init() first.");let t=new Promise((r,s)=>{let n=setTimeout(()=>{this.#h&&this.#h.delete(e),s(new Error("Timeout waiting for /synced response"))},1e4),a=c=>{clearTimeout(n),this.#h.delete(e),r()};this.#h||(this.#h=new Map),this.#h.set(e,a)});await this.send("/sync",e),await t}getInfo(){return this.#D("get info"),{sampleRate:this.#t.sampleRate,numBuffers:this.#i.worldOptions.numBuffers,totalMemory:this.#i.memory.totalMemory,wasmHeapSize:this.#i.memory.wasmHeapSize,bufferPoolSize:this.#i.memory.bufferPoolSize,bootTimeMs:this.bootStats.initDuration,capabilities:{...this.#_},version:this.#B}}async shutdown(){!this.#l&&!this.#S||(this.#u("shutdown"),this.#L(),this.#P(),this.#h?.clear(),this.#h=null,this.#o&&(this.#o.cancelAll(),this.#o.terminate(),this.#o=null),this.#n&&(this.#n.disconnect(),this.#n=null),this.#t&&(await this.#t.close(),this.#t=null),this.#c&&(this.#c.destroy(),this.#c=null),this.#g=null,this.#I=null,this.#s=null,this.#l=!1,this.loadedSynthDefs.clear(),this.#p=null,this.#a=null,this.#r=null,this.#e=null,this.#C=null,this.#b=null,this.#R=null,this.#O=null,this.#v=null,this.#f=void 0,this.bootStats={initStartTime:null,initDuration:null})}async destroy(){this.#u("destroy"),await this.shutdown(),this.#M=null,this.#A.clear()}async reset(e={}){await this.shutdown(),await this.init(e)}#re(){this.#_={audioWorklet:typeof AudioWorklet<"u",sharedArrayBuffer:typeof SharedArrayBuffer<"u",crossOriginIsolated:window.crossOriginIsolated===!0,atomics:typeof Atomics<"u",webWorker:typeof Worker<"u"};let t=["audioWorklet","sharedArrayBuffer","crossOriginIsolated","atomics","webWorker"].filter(r=>!this.#_[r]);if(t.length>0){let r=new Error(`Missing required features: ${t.join(", ")}`);throw this.#_.crossOriginIsolated||(this.#_.sharedArrayBuffer?r.message+=`
13
13
 
14
14
  SharedArrayBuffer is available but cross-origin isolation is not enabled. Please ensure COOP and COEP headers are set correctly:
15
15
  Cross-Origin-Opener-Policy: same-origin
@@ -18,5 +18,5 @@ SharedArrayBuffer is available but cross-origin isolation is not enabled. Please
18
18
  SharedArrayBuffer is not available. This may be due to:
19
19
  1. Missing COOP/COEP headers
20
20
  2. Browser doesn't support SharedArrayBuffer
21
- 3. Browser security settings`),r}return this.#_}#se(){let e=this.#i.memory;this.#a=new WebAssembly.Memory({initial:e.totalPages,maximum:e.totalPages,shared:!0}),this.#s=this.#a.buffer}#$(){return this.#i.audioContext?this.#t=this.#i.audioContext:this.#t=new AudioContext(this.#i.audioContextOptions),this.#t.addEventListener("statechange",()=>{let e=this.#t?.state;if(!e)return;let t=this.#z;this.#z=e,e==="running"&&(t==="suspended"||t==="interrupted")&&this.#K(),this.#u("audiocontext:statechange",{state:e}),e==="suspended"?this.#u("audiocontext:suspended"):e==="running"?this.#u("audiocontext:resumed"):e==="interrupted"&&this.#u("audiocontext:interrupted")}),this.#t}#ie(){this.#c=new M({audioContext:this.#t,sharedBuffer:this.#s,bufferPoolConfig:{start:this.#i.memory.bufferPoolOffset,size:this.#i.memory.bufferPoolSize},sampleBaseURL:this.#m,maxBuffers:this.#i.worldOptions.numBuffers,assetLoader:this.#T})}#V(){this.#E=new x({bufferManager:this.#c,getDefaultSampleRate:()=>this.#t?.sampleRate||44100})}async#W(){if(this.#M)return this.#M;let e=this.#i.wasmUrl.split("/").pop();this.#u("loading:start",{type:"wasm",name:e});let t;try{t=await fetch(this.#i.wasmUrl)}catch(s){throw new Error(`Failed to fetch WASM from ${this.#i.wasmUrl}: ${s.message}`)}if(!t.ok)throw new Error(`Failed to load WASM: ${t.status} ${t.statusText}`);let r=await t.arrayBuffer();return this.#u("loading:complete",{type:"wasm",name:e,size:r.byteLength}),this.#M=r,r}async#H(e){await this.#t.audioWorklet.addModule(this.#i.workletUrl),this.#n=new AudioWorkletNode(this.#t,"scsynth-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2]}),this.#i.autoConnect&&this.#n.connect(this.#t.destination),this.#d=this.#ne(),this.#n.port.postMessage({type:"init",sharedBuffer:this.#s}),this.#n.port.postMessage({type:"loadWasm",wasmBytes:e,wasmMemory:this.#a,worldOptions:this.#i.worldOptions,sampleRate:this.#t.sampleRate}),await this.#oe()}#ne(){let e=this.#n;return Object.freeze({connect:(t,r,s)=>e.connect(t,r,s),disconnect:(t,r,s)=>e.disconnect(t,r,s),get context(){return e.context},get numberOfOutputs(){return e.numberOfOutputs},get channelCount(){return e.channelCount}})}async#G(){this.#o=new C(this.#i.workerBaseURL),this.#o.onRawOSC(e=>{this.#u("message:raw",e)}),this.#o.onParsedOSC(e=>{if(e.address==="/supersonic/buffer/freed")this.#c?.handleBufferFreed(e.args);else if(e.address==="/supersonic/buffer/allocated")this.#c?.handleBufferAllocated(e.args);else if(e.address==="/supersonic/synthdef/loaded"){let t=e.args[0]}else if(e.address==="/synced"&&e.args.length>0){let t=e.args[0];this.#h&&this.#h.has(t)&&this.#h.get(t)(e)}if(this.#u("message",e),this.#i.debug||this.#i.debugOscIn){let t=this.#i.activityConsoleLog.oscIn??this.#i.activityConsoleLog.maxLineLength,r=e.args?.map(s=>{let n=JSON.stringify(s);return n.length>t?n.slice(0,t)+"...":n}).join(", ")||"";console.log(`[\u2190 OSC] ${e.address}${r?" "+r:""}`)}}),this.#o.onDebugMessage(e=>{let t=this.#i.activityEvent.scsynth??this.#i.activityEvent.maxLineLength;if(t>0&&e.text&&e.text.length>t&&(e={...e,text:e.text.slice(0,t)+"..."}),this.#u("debug",e),this.#i.debug||this.#i.debugScsynth){let r=this.#i.activityConsoleLog.scsynth??this.#i.activityConsoleLog.maxLineLength,s=e.text.length>r?e.text.slice(0,r)+"...":e.text;console.log(`[synth] ${s}`)}}),this.#o.onError((e,t)=>{console.error(`[SuperSonic] ${t} error:`,e),this.#u("error",new Error(`${t}: ${e}`))}),await this.#o.init(this.#s,this.#r,this.#e,{preschedulerCapacity:this.#i.preschedulerCapacity})}#Z(){this.#l=!0,this.#S=!1,this.bootStats.initDuration=performance.now()-this.bootStats.initStartTime,this.#u("ready",{capabilities:this.#_,bootStats:this.bootStats})}#oe(){return new Promise((e,t)=>{let r=setTimeout(()=>{t(new Error("AudioWorklet initialization timeout"))},5e3),s=async n=>{if(n.data.type!=="debug"){if(n.data.type==="error"){console.error("[AudioWorklet] Error:",n.data.error),clearTimeout(r),this.#n.port.removeEventListener("message",s),t(new Error(n.data.error||"AudioWorklet error"));return}n.data.type==="initialized"&&(clearTimeout(r),this.#n.port.removeEventListener("message",s),n.data.success?(n.data.ringBufferBase!==void 0?this.#r=n.data.ringBufferBase:console.warn("[SuperSonic] Warning: ringBufferBase not provided by worklet"),n.data.bufferConstants!==void 0?(this.#e=n.data.bufferConstants,this.#le(),this.#ue(),await this.#fe(),this.#pe()):console.warn("[SuperSonic] Warning: bufferConstants not provided by worklet"),e()):t(new Error(n.data.error||"AudioWorklet initialization failed")))}};this.#n.port.addEventListener("message",s),this.#n.port.start()})}#q(){this.#n.port.onmessage=e=>{let{data:t}=e;switch(t.type){case"error":console.error("[Worklet] Error:",t.error),t.diagnostics&&(console.error("[Worklet] Diagnostics:",t.diagnostics),console.table(t.diagnostics)),this.#u("error",new Error(t.error));break;case"process_debug":break;case"debug":break;case"version":this.#B=t.version;break}}}#ae(){if(!this.#A)return null;let e=this.#A;return{workletProcessCount:e[0],workletMessagesProcessed:e[1],workletMessagesDropped:e[2],workletSchedulerDepth:e[3],workletSchedulerMax:e[4],workletSchedulerDropped:e[5],workletSequenceGaps:e[24],preschedulerPending:e[6],preschedulerPeak:e[7],preschedulerSent:e[8],preschedulerRetriesSucceeded:e[9],preschedulerRetriesFailed:e[10],preschedulerBundlesScheduled:e[11],preschedulerEventsCancelled:e[12],preschedulerTotalDispatches:e[13],preschedulerMessagesRetried:e[14],preschedulerRetryQueueSize:e[15],preschedulerRetryQueueMax:e[16],preschedulerBypassed:e[25],oscInMessagesReceived:e[17],oscInMessagesDropped:e[18],oscInBytesReceived:e[19],debugMessagesReceived:e[20],debugBytesReceived:e[21],mainMessagesSent:e[22],mainBytesSent:e[23]}}#ce(){if(!this.#I||!this.#e||!this.#r)return null;let e=this.#r+this.#e.CONTROL_START,t=this.#I,r=Atomics.load(t,(e+0)/4),s=Atomics.load(t,(e+4)/4),n=Atomics.load(t,(e+8)/4),a=Atomics.load(t,(e+12)/4),c=Atomics.load(t,(e+16)/4),l=Atomics.load(t,(e+20)/4),u=(r-s+this.#e.IN_BUFFER_SIZE)%this.#e.IN_BUFFER_SIZE,h=(n-a+this.#e.OUT_BUFFER_SIZE)%this.#e.OUT_BUFFER_SIZE,f=(c-l+this.#e.DEBUG_BUFFER_SIZE)%this.#e.DEBUG_BUFFER_SIZE;return{inBufferUsed:{bytes:u,percentage:u/this.#e.IN_BUFFER_SIZE*100},outBufferUsed:{bytes:h,percentage:h/this.#e.OUT_BUFFER_SIZE*100},debugBufferUsed:{bytes:f,percentage:f/this.#e.DEBUG_BUFFER_SIZE*100}}}#k(e,t=1){if(!this.#A)return;let r={mainMessagesSent:22,mainBytesSent:23,preschedulerBypassed:25};Atomics.add(this.#A,r[e],t)}#Y(){let e=performance.now(),t=this.#ae()||{},r=this.#ce();if(r&&Object.assign(t,r),t.driftOffsetMs=this.#de(),t.audioContextState=this.#t?.state||"unknown",this.#c){let n=this.#c.getStats();t.bufferPoolUsedBytes=n.used.size,t.bufferPoolAvailableBytes=n.available,t.bufferPoolAllocations=n.used.count}t.loadedSynthDefs=this.loadedSynthDefs?.size||0;let s=performance.now()-e;return s>1&&console.warn(`[SuperSonic] Slow metrics gathering: ${s.toFixed(2)}ms`),t}#F(){this.#P();let e=this.#N;this.#U=setInterval(()=>{if(!(!this.#b.has("metrics")||this.#b.get("metrics").size===0)){if(this.#x){console.warn(`[SuperSonic] Metrics gathering took >${e}ms, skipping this interval`);return}this.#x=!0;try{let t=this.#Y();this.#u("metrics",t)}catch(t){console.error("[SuperSonic] Metrics gathering failed:",t)}finally{this.#x=!1}}},e)}#P(){this.#U&&(clearInterval(this.#U),this.#U=null)}#C(e="perform this operation"){if(!this.#l)throw new Error(`SuperSonic not initialized. Call init() before attempting to ${e}.`)}#le(){if(!this.#s||!this.#r||!this.#e){console.warn("[SuperSonic] Cannot initialize shared views - missing buffer info");return}this.#I=new Int32Array(this.#s);let e=this.#r+this.#e.METRICS_START;this.#A=new Uint32Array(this.#s,e,this.#e.METRICS_SIZE/4),this.#R=new Float64Array(this.#s,this.#r+this.#e.NTP_START_TIME_START,1),this.#O=new Int32Array(this.#s,this.#r+this.#e.DRIFT_OFFSET_START,1),this.#v=new Int32Array(this.#s,this.#r+this.#e.GLOBAL_OFFSET_START,1)}#ue(){this.#D=new k({sharedBuffer:this.#s,ringBufferBase:this.#r,bufferConstants:this.#e,getAudioContextTime:()=>this.#t?.currentTime??null,getNTPStartTime:()=>this.#R?.[0]??0})}#he(e){return e.includes("/")||e.includes("://")}#Ee(){return this.#c?.getStats()}async#fe(){if(!this.#e||!this.#t)return;let e;for(;e=this.#t.getOutputTimestamp(),!(e.contextTime>0);)await new Promise(n=>setTimeout(n,50));let t=performance.timeOrigin+e.performanceTime,r=F(t),s=Z(r,e.contextTime);this.#R[0]=s,this.#f=s}#Q(){if(!this.#e||!this.#t||this.#f===void 0)return;let e=this.#t.getOutputTimestamp(),t=performance.timeOrigin+e.performanceTime,s=F(t)-this.#f,n=ne(s,e.contextTime);Atomics.store(this.#O,0,n)}#de(){return this.#O?Atomics.load(this.#O,0):0}#K(){if(!this.#t||!this.#R||!this.#O)return;let e=this.#t.getOutputTimestamp();if(!e||e.contextTime<=0)return;let t=performance.timeOrigin+e.performanceTime,r=F(t),s=Z(r,e.contextTime);this.#R[0]=s,this.#f=s,this.#Q()}#pe(){this.#L(),this.#g=setInterval(()=>{this.#Q()},15e3)}#L(){this.#g&&(clearInterval(this.#g),this.#g=null)}#me(e){if(e instanceof Uint8Array)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);throw new Error("oscData must be ArrayBuffer or Uint8Array")}async#Se(e){let t={metadata:!0,unpackSingleArgs:!1};try{let r=i.osc.decode(e,t),{packet:s,changed:n}=await this.#E.rewritePacket(r);return n?i.osc.encode(s):e}catch(r){throw console.error("[SuperSonic] Failed to prepare OSC packet:",r),r}}#we(e){if(e.length<16||String.fromCharCode.apply(null,e.slice(0,8))!=="#bundle\0")return null;let r=this.#R[0];if(r===0)return console.warn("[SuperSonic] NTP start time not yet initialized"),null;let n=Atomics.load(this.#O,0)/1e3,c=Atomics.load(this.#v,0)/1e3,l=r+n+c,u=new DataView(e.buffer,e.byteOffset),h=u.getUint32(8,!1),f=u.getUint32(12,!1);if(h===0&&(f===0||f===1))return null;let m=h+f/4294967296-l,S=this.#t.currentTime;return{audioTimeS:m,currentTimeS:S}}};export{Se as SuperSonic};
21
+ 3. Browser security settings`),r}return this.#_}#se(){let e=this.#i.memory;this.#a=new WebAssembly.Memory({initial:e.totalPages,maximum:e.totalPages,shared:!0}),this.#s=this.#a.buffer}#$(){return this.#i.audioContext?this.#t=this.#i.audioContext:this.#t=new AudioContext(this.#i.audioContextOptions),this.#t.addEventListener("statechange",()=>{let e=this.#t?.state;if(!e)return;let t=this.#z;this.#z=e,e==="running"&&(t==="suspended"||t==="interrupted")&&this.#K(),this.#u("audiocontext:statechange",{state:e}),e==="suspended"?this.#u("audiocontext:suspended"):e==="running"?this.#u("audiocontext:resumed"):e==="interrupted"&&this.#u("audiocontext:interrupted")}),this.#t}#ie(){this.#c=new M({audioContext:this.#t,sharedBuffer:this.#s,bufferPoolConfig:{start:this.#i.memory.bufferPoolOffset,size:this.#i.memory.bufferPoolSize},sampleBaseURL:this.#m,maxBuffers:this.#i.worldOptions.numBuffers,assetLoader:this.#T})}#V(){this.#g=new x({bufferManager:this.#c,getDefaultSampleRate:()=>this.#t?.sampleRate||44100})}async#W(){if(this.#M)return this.#M;let e=this.#i.wasmUrl.split("/").pop();this.#u("loading:start",{type:"wasm",name:e});let t;try{t=await fetch(this.#i.wasmUrl)}catch(s){throw new Error(`Failed to fetch WASM from ${this.#i.wasmUrl}: ${s.message}`)}if(!t.ok)throw new Error(`Failed to load WASM: ${t.status} ${t.statusText}`);let r=await t.arrayBuffer();return this.#u("loading:complete",{type:"wasm",name:e,size:r.byteLength}),this.#M=r,r}async#H(e){await this.#t.audioWorklet.addModule(this.#i.workletUrl),this.#n=new AudioWorkletNode(this.#t,"scsynth-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2]}),this.#i.autoConnect&&this.#n.connect(this.#t.destination),this.#d=this.#ne(),this.#n.port.postMessage({type:"init",sharedBuffer:this.#s}),this.#n.port.postMessage({type:"loadWasm",wasmBytes:e,wasmMemory:this.#a,worldOptions:this.#i.worldOptions,sampleRate:this.#t.sampleRate}),await this.#oe()}#ne(){let e=this.#n;return Object.freeze({connect:(t,r,s)=>e.connect(t,r,s),disconnect:(t,r,s)=>e.disconnect(t,r,s),get context(){return e.context},get numberOfOutputs(){return e.numberOfOutputs},get channelCount(){return e.channelCount}})}async#G(){this.#o=new D(this.#i.workerBaseURL),this.#o.onRawOSC(e=>{this.#u("message:raw",e)}),this.#o.onParsedOSC(e=>{if(e.address==="/supersonic/buffer/freed")this.#c?.handleBufferFreed(e.args);else if(e.address==="/supersonic/buffer/allocated")this.#c?.handleBufferAllocated(e.args);else if(e.address==="/supersonic/synthdef/loaded"){let t=e.args[0]}else if(e.address==="/synced"&&e.args.length>0){let t=e.args[0];this.#h&&this.#h.has(t)&&this.#h.get(t)(e)}if(this.#u("message",e),this.#i.debug||this.#i.debugOscIn){let t=this.#i.activityConsoleLog.oscIn??this.#i.activityConsoleLog.maxLineLength,r=e.args?.map(s=>{let n=JSON.stringify(s);return n.length>t?n.slice(0,t)+"...":n}).join(", ")||"";console.log(`[\u2190 OSC] ${e.address}${r?" "+r:""}`)}}),this.#o.onDebugMessage(e=>{let t=this.#i.activityEvent.scsynth??this.#i.activityEvent.maxLineLength;if(t>0&&e.text&&e.text.length>t&&(e={...e,text:e.text.slice(0,t)+"..."}),this.#u("debug",e),this.#i.debug||this.#i.debugScsynth){let r=this.#i.activityConsoleLog.scsynth??this.#i.activityConsoleLog.maxLineLength,s=e.text.length>r?e.text.slice(0,r)+"...":e.text;console.log(`[synth] ${s}`)}}),this.#o.onError((e,t)=>{console.error(`[SuperSonic] ${t} error:`,e),this.#u("error",new Error(`${t}: ${e}`))}),await this.#o.init(this.#s,this.#r,this.#e,{preschedulerCapacity:this.#i.preschedulerCapacity})}#Z(){this.#l=!0,this.#S=!1,this.bootStats.initDuration=performance.now()-this.bootStats.initStartTime,this.#u("ready",{capabilities:this.#_,bootStats:this.bootStats})}#oe(){return new Promise((e,t)=>{let r=setTimeout(()=>{t(new Error("AudioWorklet initialization timeout"))},5e3),s=async n=>{if(n.data.type!=="debug"){if(n.data.type==="error"){console.error("[AudioWorklet] Error:",n.data.error),clearTimeout(r),this.#n.port.removeEventListener("message",s),t(new Error(n.data.error||"AudioWorklet error"));return}n.data.type==="initialized"&&(clearTimeout(r),this.#n.port.removeEventListener("message",s),n.data.success?(n.data.ringBufferBase!==void 0?this.#r=n.data.ringBufferBase:console.warn("[SuperSonic] Warning: ringBufferBase not provided by worklet"),n.data.bufferConstants!==void 0?(this.#e=n.data.bufferConstants,this.#le(),this.#ue(),await this.#fe(),this.#pe()):console.warn("[SuperSonic] Warning: bufferConstants not provided by worklet"),e()):t(new Error(n.data.error||"AudioWorklet initialization failed")))}};this.#n.port.addEventListener("message",s),this.#n.port.start()})}#q(){this.#n.port.onmessage=e=>{let{data:t}=e;switch(t.type){case"error":console.error("[Worklet] Error:",t.error),t.diagnostics&&(console.error("[Worklet] Diagnostics:",t.diagnostics),console.table(t.diagnostics)),this.#u("error",new Error(t.error));break;case"process_debug":break;case"debug":break;case"version":this.#B=t.version;break}}}#ae(){if(!this.#b)return null;let e=this.#b;return{workletProcessCount:e[0],workletMessagesProcessed:e[1],workletMessagesDropped:e[2],workletSchedulerDepth:e[3],workletSchedulerMax:e[4],workletSchedulerDropped:e[5],workletSequenceGaps:e[24],preschedulerPending:e[6],preschedulerPeak:e[7],preschedulerSent:e[8],preschedulerRetriesSucceeded:e[9],preschedulerRetriesFailed:e[10],preschedulerBundlesScheduled:e[11],preschedulerEventsCancelled:e[12],preschedulerTotalDispatches:e[13],preschedulerMessagesRetried:e[14],preschedulerRetryQueueSize:e[15],preschedulerRetryQueueMax:e[16],preschedulerBypassed:e[25],oscInMessagesReceived:e[17],oscInMessagesDropped:e[18],oscInBytesReceived:e[19],debugMessagesReceived:e[20],debugBytesReceived:e[21],mainMessagesSent:e[22],mainBytesSent:e[23]}}#ce(){if(!this.#C||!this.#e||!this.#r)return null;let e=this.#r+this.#e.CONTROL_START,t=this.#C,r=Atomics.load(t,(e+0)/4),s=Atomics.load(t,(e+4)/4),n=Atomics.load(t,(e+8)/4),a=Atomics.load(t,(e+12)/4),c=Atomics.load(t,(e+16)/4),l=Atomics.load(t,(e+20)/4),u=(r-s+this.#e.IN_BUFFER_SIZE)%this.#e.IN_BUFFER_SIZE,h=(n-a+this.#e.OUT_BUFFER_SIZE)%this.#e.OUT_BUFFER_SIZE,f=(c-l+this.#e.DEBUG_BUFFER_SIZE)%this.#e.DEBUG_BUFFER_SIZE;return{inBufferUsed:{bytes:u,percentage:u/this.#e.IN_BUFFER_SIZE*100},outBufferUsed:{bytes:h,percentage:h/this.#e.OUT_BUFFER_SIZE*100},debugBufferUsed:{bytes:f,percentage:f/this.#e.DEBUG_BUFFER_SIZE*100}}}#k(e,t=1){if(!this.#b)return;let r={mainMessagesSent:22,mainBytesSent:23,preschedulerBypassed:25};Atomics.add(this.#b,r[e],t)}#Y(){let e=performance.now(),t=this.#ae()||{},r=this.#ce();if(r&&Object.assign(t,r),t.driftOffsetMs=this.#de(),t.audioContextState=this.#t?.state||"unknown",this.#c){let n=this.#c.getStats();t.bufferPoolUsedBytes=n.used.size,t.bufferPoolAvailableBytes=n.available,t.bufferPoolAllocations=n.used.count}t.loadedSynthDefs=this.loadedSynthDefs?.size||0;let s=performance.now()-e;return s>1&&console.warn(`[SuperSonic] Slow metrics gathering: ${s.toFixed(2)}ms`),t}#F(){this.#P();let e=this.#N;this.#U=setInterval(()=>{if(!(!this.#A.has("metrics")||this.#A.get("metrics").size===0)){if(this.#x){console.warn(`[SuperSonic] Metrics gathering took >${e}ms, skipping this interval`);return}this.#x=!0;try{let t=this.#Y();this.#u("metrics",t)}catch(t){console.error("[SuperSonic] Metrics gathering failed:",t)}finally{this.#x=!1}}},e)}#P(){this.#U&&(clearInterval(this.#U),this.#U=null)}#D(e="perform this operation"){if(!this.#l)throw new Error(`SuperSonic not initialized. Call init() before attempting to ${e}.`)}#le(){if(!this.#s||!this.#r||!this.#e){console.warn("[SuperSonic] Cannot initialize shared views - missing buffer info");return}this.#C=new Int32Array(this.#s);let e=this.#r+this.#e.METRICS_START;this.#b=new Uint32Array(this.#s,e,this.#e.METRICS_SIZE/4),this.#R=new Float64Array(this.#s,this.#r+this.#e.NTP_START_TIME_START,1),this.#O=new Int32Array(this.#s,this.#r+this.#e.DRIFT_OFFSET_START,1),this.#v=new Int32Array(this.#s,this.#r+this.#e.GLOBAL_OFFSET_START,1)}#ue(){this.#I=new k({sharedBuffer:this.#s,ringBufferBase:this.#r,bufferConstants:this.#e,getAudioContextTime:()=>this.#t?.currentTime??null,getNTPStartTime:()=>this.#R?.[0]??0})}#he(e){return e.includes("/")||e.includes("://")}#ge(){return this.#c?.getStats()}async#fe(){if(!this.#e||!this.#t)return;let e;for(;e=this.#t.getOutputTimestamp(),!(e.contextTime>0);)await new Promise(n=>setTimeout(n,50));let t=performance.timeOrigin+e.performanceTime,r=F(t),s=Z(r,e.contextTime);this.#R[0]=s,this.#f=s}#Q(){if(!this.#e||!this.#t||this.#f===void 0)return;let e=this.#t.getOutputTimestamp(),t=performance.timeOrigin+e.performanceTime,s=F(t)-this.#f,n=ne(s,e.contextTime);Atomics.store(this.#O,0,n)}#de(){return this.#O?Atomics.load(this.#O,0):0}#K(){if(!this.#t||!this.#R||!this.#O)return;let e=this.#t.getOutputTimestamp();if(!e||e.contextTime<=0)return;let t=performance.timeOrigin+e.performanceTime,r=F(t),s=Z(r,e.contextTime);this.#R[0]=s,this.#f=s,this.#Q()}#pe(){this.#L(),this.#E=setInterval(()=>{this.#Q()},15e3)}#L(){this.#E&&(clearInterval(this.#E),this.#E=null)}#me(e){if(e instanceof Uint8Array)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);throw new Error("oscData must be ArrayBuffer or Uint8Array")}async#Se(e){let t={metadata:!0,unpackSingleArgs:!1};try{let r=i.osc.decode(e,t),{packet:s,changed:n}=await this.#g.rewritePacket(r);return n?i.osc.encode(s):e}catch(r){throw console.error("[SuperSonic] Failed to prepare OSC packet:",r),r}}#we(e){if(e.length<16||String.fromCharCode.apply(null,e.slice(0,8))!=="#bundle\0")return null;let r=this.#R[0];if(r===0)return console.warn("[SuperSonic] NTP start time not yet initialized"),null;let n=Atomics.load(this.#O,0)/1e3,c=Atomics.load(this.#v,0)/1e3,l=r+n+c,u=new DataView(e.buffer,e.byteOffset),h=u.getUint32(8,!1),f=u.getUint32(12,!1);if(h===0&&(f===0||f===1))return null;let m=h+f/4294967296-l,S=this.#t.currentTime;return{audioTimeS:m,currentTimeS:S}}};export{Se as SuperSonic};
22
22
  /*! osc.js 2.4.5, Copyright 2024 Colin Clark | github.com/colinbdclark/osc.js */
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supersonic-scsynth",
3
- "version": "0.20.1",
3
+ "version": "0.20.2",
4
4
  "description": "SuperCollider scsynth WebAssembly port for AudioWorklet - Run SuperCollider synthesis in the browser",
5
5
  "main": "dist/supersonic.js",
6
6
  "unpkg": "dist/supersonic.js",