From 8541d0c3ef101c5afbb6ed3e4f3d9de5c8e2670f Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Thu, 17 Aug 2023 01:02:37 +0200 Subject: [PATCH] adding unipolar LFOs and new method chaining --- src/API.ts | 59 +++++++++++++++++- src/Sound.ts | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+), 3 deletions(-) create mode 100644 src/Sound.ts diff --git a/src/API.ts b/src/API.ts index 5fd1764..05ac71d 100644 --- a/src/API.ts +++ b/src/API.ts @@ -5,6 +5,7 @@ import { DrunkWalk } from "./Utils/Drunk"; import { LRUCache } from 'lru-cache'; import { scale } from "./Scales"; import { Editor } from "./main"; +import { Sound } from './Sound'; import { superdough, samples, @@ -1035,7 +1036,7 @@ export class UserAPI { gold() { /** * Essayer de générer des séquences tirées du truc de Puckette - * Faire ça avec des lazy lists, ça ne devrait pas être trop difficle. + * Faire ça avec des lazy lists, ça ne devrait pas être trop difficile. * */ } @@ -1079,6 +1080,18 @@ export class UserAPI { ); } + usine(freq: number = 1, offset: number = 0): number { + /** + * Returns a sine wave between 0 and 1. + * + * @param freq - The frequency of the sine wave + * @param offset - The offset of the sine wave + * @returns A sine wave between 0 and 1 + * @see sine + */ + return (this.sine(freq, offset) + 1) / 2; + } + saw(freq: number = 1, offset: number = 0): number { /** * Returns a saw wave between -1 and 1. @@ -1094,6 +1107,18 @@ export class UserAPI { return ((this.app.clock.ctx.currentTime * freq) % 1) * 2 - 1 + offset; } + usaw(freq: number = 1, offset: number = 0): number { + /** + * Returns a saw wave between 0 and 1. + * + * @param freq - The frequency of the saw wave + * @param offset - The offset of the saw wave + * @returns A saw wave between 0 and 1 + * @see saw + */ + return (this.saw(freq, offset) + 1) / 2; + } + triangle(freq: number = 1, offset: number = 0): number { /** * Returns a triangle wave between -1 and 1. @@ -1107,6 +1132,18 @@ export class UserAPI { return Math.abs(this.saw(freq, offset)) * 2 - 1; } + utriangle(freq: number = 1, offset: number = 0): number { + /** + * Returns a triangle wave between 0 and 1. + * + * @param freq - The frequency of the triangle wave + * @param offset - The offset of the triangle wave + * @returns A triangle wave between 0 and 1 + * @see triangle + */ + return (this.triangle(freq, offset) + 1) / 2; + } + square(freq: number = 1, offset: number = 0): number { /** * Returns a square wave between -1 and 1. @@ -1120,6 +1157,18 @@ export class UserAPI { return this.saw(freq, offset) > 0 ? 1 : -1; } + usquare(freq: number = 1, offset: number = 0): number { + /** + * Returns a square wave between 0 and 1. + * + * @param freq - The frequency of the square wave + * @param offset - The offset of the square wave + * @returns A square wave between 0 and 1 + * @see square + */ + return (this.square(freq, offset) + 1) / 2; + } + noise(): number { /** * Returns a random value between -1 and 1. @@ -1144,10 +1193,14 @@ export class UserAPI { // Trivial functions // ============================================================= - sound = async (values: object, delay: number = 0.0) => { + d = async (values: object, delay: number = 0.0) => { superdough(values, delay); }; - d = this.sound; + + + sound = (sound: string) => { + return new Sound(sound); + } samples = samples; diff --git a/src/Sound.ts b/src/Sound.ts new file mode 100644 index 0000000..e802a60 --- /dev/null +++ b/src/Sound.ts @@ -0,0 +1,167 @@ +import { + superdough, + // @ts-ignore +} from "superdough"; + +export class Sound { + + values: { [key: string]: any } + + constructor(sound: string) { + this.values = { 's': sound } + } + + unit = (value: number): this => { + this.values['unit'] = value + return this; + } + + frequency = (value: number): this => { + this.values['frequency'] = value + return this; + } + + nudge = (value: number): this => { + this.values['nudge'] = value + return this; + } + + cut = (value: number): this => { + this.values['cut'] = value + return this; + } + + loop = (value: number): this => { + this.values['loop'] = value + return this; + } + + clip = (value: number): this => { + this.values['clip'] = value + return this; + } + + n = (value: number): this => { + this.values['n'] = value + return this; + } + + note = (value: number): this => { + this.values['note'] = value + return this; + } + + speed = (value: number): this => { + this.values['speed'] = value + return this; + } + + begin = (value: number): this => { + this.values['begin'] = value + return this; + } + + end = (value: number): this => { + this.values['end'] = value + return this; + } + + gain = (value: number): this => { + this.values['gain'] = value + return this; + } + + cutoff = (value: number): this => { + this.values['cutoff'] = value + return this; + } + + resonance = (value: number): this => { + this.values['resonance'] = value + return this; + } + + hcutoff = (value: number): this => { + this.values['hcutoff'] = value + return this; + } + + hresonance = (value: number): this => { + this.values['hresonance'] = value + return this; + } + + bandf = (value: number): this => { + this.values['bandf'] = value + return this; + } + + bandq = (value: number): this => { + this.values['bandq'] = value + return this; + } + + coarse = (value: number): this => { + this.values['coarse'] = value + return this; + } + + crush = (value: number): this => { + this.values['crush'] = value + return this; + } + + shape = (value: number): this => { + this.values['shape'] = value + return this; + } + + pan = (value: number): this => { + this.values['pan'] = value + return this; + } + + vowel = (value: number): this => { + this.values['vowel'] = value + return this; + } + + delay = (value: number): this => { + this.values['delay'] = value + return this; + } + + delayfeedback = (value: number): this => { + this.values['delayfeedback'] = value + return this; + } + + delaytime = (value: number): this => { + this.values['delaytime'] = value + return this; + } + + orbit = (value: number): this => { + this.values['orbit'] = value + return this; + } + + room = (value: number): this => { + this.values['room'] = value + return this; + } + + size = (value: number): this => { + this.values['size'] = value + return this; + } + + velocity = (value: number): this => { + this.values['velocity'] = value + return this; + } + + out = (): object => { + return superdough(this.values, 0.0); + } +} \ No newline at end of file