Skip to content

Commit

Permalink
merge dev into main
Browse files Browse the repository at this point in the history
  • Loading branch information
terryzfeng committed Apr 8, 2024
2 parents 02321c4 + 18ac87d commit c4de3f6
Show file tree
Hide file tree
Showing 12 changed files with 3,484 additions and 1,302 deletions.
18 changes: 12 additions & 6 deletions dist/Chuck.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default class Chuck extends window.AudioWorkletNode {
/** @internal */
static chuckID: number;
/** @internal */
static chugins: Filename[];
static chuginsToLoad: Filename[];
private chugins;
/**
* Private internal constructor for a ChucK AudioWorklet Web Audio Node. Use public **{@link init| Init}** to create a ChucK instance.
* @param preloadedFiles Array of Files to preload into ChucK's filesystem
Expand Down Expand Up @@ -84,15 +85,20 @@ export default class Chuck extends window.AudioWorkletNode {
*/
loadFile(url: string): Promise<void>;
/**
* Load a WebChugin (.chug.wasm) via url into WebChucK.
* The list of WebChugins to load can be found in the {@link https://chuck.stanford.edu/chugins/ | webchugins} folder.
* Load a single WebChugin (.chug.wasm) via url into WebChucK.
* A list of publicly available WebChugins to load can be found in the {@link https://chuck.stanford.edu/chugins/ | webchugins} folder.
* **Note:** WebChugins must be loaded before `theChuck` is initialized.
* @param url url to webchugin to load
* @example
* ```ts
* Chuck.loadChugin("https://url/to/myChugin.chug.wasm");
* theChuck = await Chuck.init([]);
* ```
*/
loadChugin(url: string): void;
static loadChugin(url: string): void;
/**
* Return a list of loaded WebChugins.
* @returns Array string of loaded WebChugins
* @returns String array of loaded WebChugin names
*/
loadedChugins(): string[];
/**
Expand Down Expand Up @@ -464,7 +470,7 @@ export default class Chuck extends window.AudioWorkletNode {
*
* // Output: "ChucK says: Hello World!"
* ```
* @param message Message that ChucK wil print to console
* @param message Message that ChucK will print to console
*/
chuckPrint(message: string): void;
/**
Expand Down
33 changes: 19 additions & 14 deletions dist/Chuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default class Chuck extends window.AudioWorkletNode {
this.eventCallbacks = {};
this.eventCallbackCounter = 0;
this.isReady = defer();
this.chugins = [];
this.port.onmessage = this.receiveMessage.bind(this);
this.onprocessorerror = (e) => console.error(e);
Chuck.chuckID++;
Expand Down Expand Up @@ -97,10 +98,13 @@ export default class Chuck extends window.AudioWorkletNode {
}
await audioContext.audioWorklet.addModule(whereIsChuck + "webchuck.js");
// Add Chugins to filenamesToPreload
filenamesToPreload = filenamesToPreload.concat(Chuck.chugins);
filenamesToPreload = filenamesToPreload.concat(Chuck.chuginsToLoad);
const preloadedFiles = await preloadFiles(filenamesToPreload);
const chuck = new Chuck(preloadedFiles, audioContext, wasm, numOutChannels);
// connect node to default destination if using default audio context
// Remember the chugins that were loaded
chuck.chugins = Chuck.chuginsToLoad.map((chugin) => chugin.virtualFilename.split("/").pop());
Chuck.chuginsToLoad = []; // clear
// Connect node to default destination if using default audio context
if (defaultAudioContext) {
chuck.connect(audioContext.destination); // default connection source
}
Expand Down Expand Up @@ -168,27 +172,28 @@ export default class Chuck extends window.AudioWorkletNode {
}
// ================== WebChugins ================== //
/**
* Load a WebChugin (.chug.wasm) via url into WebChucK.
* The list of WebChugins to load can be found in the {@link https://chuck.stanford.edu/chugins/ | webchugins} folder.
* Load a single WebChugin (.chug.wasm) via url into WebChucK.
* A list of publicly available WebChugins to load can be found in the {@link https://chuck.stanford.edu/chugins/ | webchugins} folder.
* **Note:** WebChugins must be loaded before `theChuck` is initialized.
* @param url url to webchugin to load
* @example
* ```ts
* Chuck.loadChugin("https://url/to/myChugin.chug.wasm");
* theChuck = await Chuck.init([]);
* ```
*/
loadChugin(url) {
Chuck.chugins.concat({
static loadChugin(url) {
Chuck.chuginsToLoad.push({
serverFilename: url,
virtualFilename: "/chugins/" + url.split("/").pop(),
});
}
/**
* Return a list of loaded WebChugins.
* @returns Array string of loaded WebChugins
* @returns String array of loaded WebChugin names
*/
loadedChugins() {
let chugins = [];
Chuck.chugins.map((chugin) => {
chugins.push(chugin.serverFilename.split("/").pop());
});
return chugins;
return this.chugins;
}
// ================== Run/Replace Code ================== //
/**
Expand Down Expand Up @@ -821,7 +826,7 @@ export default class Chuck extends window.AudioWorkletNode {
*
* // Output: "ChucK says: Hello World!"
* ```
* @param message Message that ChucK wil print to console
* @param message Message that ChucK will print to console
*/
chuckPrint(message) {
// Default ChucK output destination
Expand Down Expand Up @@ -928,4 +933,4 @@ export default class Chuck extends window.AudioWorkletNode {
/** @internal */
Chuck.chuckID = 1;
/** @internal */
Chuck.chugins = [];
Chuck.chuginsToLoad = [];
1 change: 1 addition & 0 deletions docs/assets/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c4de3f6

Please sign in to comment.