Skip to content

Commit

Permalink
new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubobubobubobubo committed Aug 13, 2023
1 parent fb652e6 commit 42d65a1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
in(value: T): boolean;
}
}
Array.prototype.in = function<T>(this: T[], value: T): boolean {
return this.includes(value);
};


const init = Promise.all([
initAudioOnFirstClick(),
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 42d65a1

Please sign in to comment.