MCPcopy Create free account
hub / github.com/csound/csound / initialize

Method initialize

wasm/browser/src/mains/sab.main.js:231–538  ·  view source on GitHub ↗
({ wasmDataURI, withPlugins })

Source from the content-addressed store, hash-verified

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);

Callers

nothing calls this directly

Calls 15

onPlayStateChangeMethod · 0.95
fetchPluginsFunction · 0.90
messageEventHandlerFunction · 0.90
makeProxyCallbackFunction · 0.90
csoundApiRenameFunction · 0.90
logFunction · 0.85
releaseStopPromiseMethod · 0.80
releasePausePromiseMethod · 0.80
releaseResumePromiseMethod · 0.80

Tested by

no test coverage detected