From 42d65a1df16c61238ff2aad335baf5833ce814aa Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sun, 13 Aug 2023 11:21:29 +0200 Subject: [PATCH] new methods --- src/API.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/API.ts b/src/API.ts index 551810b..499abc2 100644 --- a/src/API.ts +++ b/src/API.ts @@ -10,6 +10,19 @@ import { registerSynthSounds } from 'superdough'; +/** + * We are overriding the includes method which is rather + * useful to check the position of an event on a specific beat. + */ +declare global { + interface Array { + in(value: T): boolean; + } +} +Array.prototype.in = function(this: T[], value: T): boolean { + return this.includes(value); +}; + const init = Promise.all([ initAudioOnFirstClick(), @@ -829,6 +842,28 @@ export class UserAPI { // Low Frequency Oscillators // ============================================================= + line(start: number, end: number, step: number = 1): number[] { + /** + * Returns an array of values between start and end, with a given step. + * + * @param start - The start value of the array + * @param end - The end value of the array + * @param step - The step value of the array + * @returns An array of values between start and end, with a given step + */ + const result: number[] = []; + + if ((end > start && step > 0) || (end < start && step < 0)) { + for (let value = start; value <= end; value += step) { + result.push(value); + } + } else { + console.error("Invalid range or step provided."); + } + + return result; + } + sine(freq: number = 1, offset: number=0): number { /** * Returns a sine wave between -1 and 1.