({ wasmDataURI, withPlugins })
| 229 | } |
| 230 | |
| 231 | async initialize({ wasmDataURI, withPlugins }) { |
| 232 | if (withPlugins && !isEmpty(withPlugins)) { |
| 233 | withPlugins = await fetchPlugins(withPlugins); |
| 234 | } |
| 235 | |
| 236 | log(`initialization: instantiate the SABWorker Thread`)(); |
| 237 | // clearFsLastmods(); |
| 238 | const csoundWorker = new Worker(SABWorker()); |
| 239 | this.csoundWorker = csoundWorker; |
| 240 | const audioStateBuffer = this.audioStateBuffer; |
| 241 | const audioStatePointer = this.audioStatePointer; |
| 242 | const audioStreamIn = this.audioStreamIn; |
| 243 | const audioStreamOut = this.audioStreamOut; |
| 244 | const midiBuffer = this.midiBuffer; |
| 245 | |
| 246 | log(`providing the audioWorker a pointer to SABMain's instance`)(); |
| 247 | this.audioWorker.csoundWorkerMain = this; |
| 248 | |
| 249 | // both audio worker and csound worker use 1 handler |
| 250 | // simplifies flow of data (csound main.worker is always first to receive) |
| 251 | log(`adding message eventListeners for mainMessagePort and mainMessagePortAudio`)(); |
| 252 | this.ipcMessagePorts.mainMessagePort.addEventListener("message", messageEventHandler(this)); |
| 253 | this.ipcMessagePorts.mainMessagePort.start(); |
| 254 | this.ipcMessagePorts.mainMessagePortAudio.addEventListener( |
| 255 | "message", |
| 256 | messageEventHandler(this), |
| 257 | ); |
| 258 | this.ipcMessagePorts.mainMessagePortAudio.start(); |
| 259 | log(`(postMessage) making a message channel from SABMain to SABWorker via workerMessagePort`)(); |
| 260 | |
| 261 | this.ipcMessagePorts.sabMainCallbackReply.addEventListener("message", (event) => { |
| 262 | switch (event.data) { |
| 263 | case "poll": { |
| 264 | this.ipcMessagePorts && |
| 265 | this.ipcMessagePorts.sabMainCallbackReply.postMessage( |
| 266 | Object.keys(this.callbackBuffer).map((id) => ({ |
| 267 | id, |
| 268 | apiKey: this.callbackBuffer[id].apiKey, |
| 269 | argumentz: this.callbackBuffer[id].argumentz, |
| 270 | })), |
| 271 | ); |
| 272 | break; |
| 273 | } |
| 274 | case "releaseStop": { |
| 275 | this.onPlayStateChange( |
| 276 | this.currentPlayState === "renderStarted" ? "renderEnded" : "realtimePerformanceEnded", |
| 277 | ); |
| 278 | this.publicEvents && this.publicEvents.triggerRealtimePerformanceEnded(this); |
| 279 | this.eventPromises && this.eventPromises.releaseStopPromise(); |
| 280 | break; |
| 281 | } |
| 282 | case "releasePause": { |
| 283 | this.publicEvents.triggerRealtimePerformancePaused(this); |
| 284 | this.eventPromises.releasePausePromise(); |
| 285 | break; |
| 286 | } |
| 287 | case "releaseResumed": { |
| 288 | this.publicEvents.triggerRealtimePerformanceResumed(this); |
nothing calls this directly
no test coverage detected