Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
reindernijhoff committed Apr 30, 2024
2 parents c55c645 + 37dfed3 commit 7a90281
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 79 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ full [Dittytoy API Reference here](https://dittytoy.net/syntax).

### Installing

Add `dittytoy` to your project:
Add [dittytoy](https://www.npmjs.com/package/dittytoy) to your project:

```sh
npm i dittytoy
Expand Down Expand Up @@ -111,7 +111,7 @@ dittytoy.addListener(MSG_INIT, (data:any) => {
During playback, the `MSG_UPDATE` event is emitted each time the ditty is updated. This will be ~60 times per second.

```ts
dittytoy.addEventListener(MSG_UPDATE, (data:any) => {
dittytoy.addListener(MSG_UPDATE, (data:any) => {
// data.amp contains information about the volume of the ditty and the separate loops
const state = data.state;
if (state) {
Expand Down
118 changes: 118 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
export const LOOP_OPERATOR_SYNTH: 0;
export const LOOP_OPERATOR_OPTION: 1;
export const BUFFER_LENGTH: number;
export const NUM_BUFFERS: 4;
export const RUN_AS_WORKER: 0;
export const RUN_AS_INLINE: 1;
export const NODE_TYPE_LOOP: 0;
export const NODE_TYPE_INLINE: 1;
export const NODE_TYPE_FILTER: 2;
export const NODE_TYPE_OUT: 3;
export const MSG_INIT: 0;
export const MSG_RESET: 1;
export const MSG_LOG: 2;
export const MSG_ERROR: 3;
export const MSG_ANALYZE_STRUCTURE: 4;
export const MSG_WORKLET_READY: 5;
export const MSG_UPDATE: 6;
export const MSG_NOTE_PLAYED: 7;
export const MSG_SET_AMP: 8;
export const MSG_SET_VARS: 9;
export const MSG_PLAY: 10;
export const MSG_STOP: 11;
export const MSG_PAUSE: 12;
export const MSG_RESUME: 13;

export type VolumeType = {
master?: {
amp: number;
},
loops?: {
name: string;
amp: number;
}
};

export type InputParameterType = {
key: string;
value: number;
}

/**
* The Dittytoy class represents a Dittytoy synthesizer.
*/
export class Dittytoy {
/**
* Indicates whether the synthesizer is paused.
*/
paused: boolean;

/**
* Indicates whether the synthesizer is stopped.
*/
stopped: boolean;

/**
* Adds a listener for a specific event.
* @param event - The event to listen for.
* @param callback - The function to call when the event occurs.
*/
addListener(event: any, callback: any): void;

/**
* Removes a listener for a specific event.
* @param event - The event to stop listening for.
* @param callback - The function to remove from the event's listeners.
*/
removeListener(event: any, callback: any): void;

/**
* Sets the volume for the synthesizer.
* @param volume - The volume settings to apply.
*/
setVolume(volume: VolumeType): void;

/**
* Sets the input parameters for the synthesizer.
* @param inputParameters - The input parameters to set.
*/
setInputParameters(inputParameters: InputParameterType[]): void;

/**
* Compiles the provided code.
* @param code - The code to compile.
* @returns A promise that resolves when the code has been compiled.
*/
compile(code: string): Promise<any>;

/**
* Stops the synthesizer.
* @returns A promise that resolves when the synthesizer has been stopped.
*/
stop(): Promise<void>;

/**
* Pauses the synthesizer.
* @returns A promise that resolves when the synthesizer has been paused.
*/
pause(): Promise<void>;

/**
* Resumes the synthesizer.
* @param inputParameters - The input parameters to set (optional).
* @param volume - The volume settings to apply (optional).
* @param releaseMode - Whether to enable release mode (optional).
* @returns A promise that resolves when the synthesizer has been resumed.
*/
resume(inputParameters?: InputParameterType[], volume?: VolumeType, releaseMode?: boolean): Promise<void>;

/**
* Starts playing the synthesizer.
* @param inputParameters - The input parameters to set (optional).
* @param volume - The volume settings to apply (optional).
* @param releaseMode - Whether to enable release mode (optional).
* @returns A promise that resolves when the synthesizer has started playing.
*/
play(inputParameters?: InputParameterType[], volume?: VolumeType, releaseMode?: boolean): Promise<void>;
}
export {};
72 changes: 36 additions & 36 deletions package-lock.json

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

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
{
"name": "dittytoy",
"version": "0.1.8",
"version": "1.0.5",
"description": "",
"keywords": [
"Web Audio",
"Web Audio API",
"Synthesis",
"Audio Synthesis",
"Algorithmic Composition",
"Algorave",
"Playback",
"Instrument",
"Music",
"DSP",
"Signal Processing",
"Generative Music",
"Dittytoy",
"Sonic Pi"
"Sonic Pi",
"Supercollider"
],
"repository": "[email protected]:reindernijhoff/dittytoy-package.git",
"author": "Reinder Nijhoff <[email protected]>",
Expand All @@ -25,10 +28,12 @@
],
"main": "./dist/dittytoy.umd.cjs",
"module": "./dist/dittytoy.js",
"types": "./index.d.ts",
"exports": {
".": {
"import": "./dist/dittytoy.js",
"require": "./dist/dittytoy.umd.cjs"
"require": "./dist/dittytoy.umd.cjs",
"types": "./index.d.ts"
}
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/preparePublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const distFolder = join(projectFolder, 'dist');

// include all paths (files or folders) that should be copied over to the dist folder on publish
// this should likely be in sync with the 'files' field in the package.json
const filesToPublish = ['package.json', 'README.md', 'LICENSE'];
const filesToPublish = ['package.json', 'README.md', 'LICENSE', 'index.d.ts'];

for (const file of filesToPublish) {
shell.cp('-R', join(projectFolder, file), join(distFolder, file));
Expand Down
Loading

0 comments on commit 7a90281

Please sign in to comment.