stuff
This commit is contained in:
50
src/API.ts
50
src/API.ts
@ -32,23 +32,28 @@ declare global {
|
|||||||
repeatPair(amount: number): T;
|
repeatPair(amount: number): T;
|
||||||
repeatOdd(amount: number): T;
|
repeatOdd(amount: number): T;
|
||||||
loop(index: number): T;
|
loop(index: number): T;
|
||||||
|
div(division: number): T;
|
||||||
shuffle(): this;
|
shuffle(): this;
|
||||||
rotate(steps: number): this;
|
rotate(steps: number): this;
|
||||||
unique(): this;
|
unique(): this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Array.prototype.shuffle = function() {
|
Array.prototype.shuffle = function () {
|
||||||
let currentIndex = this.length, randomIndex;
|
let currentIndex = this.length,
|
||||||
|
randomIndex;
|
||||||
while (currentIndex !== 0) {
|
while (currentIndex !== 0) {
|
||||||
randomIndex = Math.floor(Math.random() * currentIndex);
|
randomIndex = Math.floor(Math.random() * currentIndex);
|
||||||
currentIndex--;
|
currentIndex--;
|
||||||
[this[currentIndex], this[randomIndex]] = [this[randomIndex], this[currentIndex]];
|
[this[currentIndex], this[randomIndex]] = [
|
||||||
|
this[randomIndex],
|
||||||
|
this[currentIndex],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.rotate = function(steps: number) {
|
Array.prototype.rotate = function (steps: number) {
|
||||||
const length = this.length;
|
const length = this.length;
|
||||||
if (steps < 0) {
|
if (steps < 0) {
|
||||||
steps = length + (steps % length);
|
steps = length + (steps % length);
|
||||||
@ -62,7 +67,7 @@ Array.prototype.rotate = function(steps: number) {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.unique = function() {
|
Array.prototype.unique = function () {
|
||||||
const seen = new Set();
|
const seen = new Set();
|
||||||
let writeIndex = 0;
|
let writeIndex = 0;
|
||||||
for (let readIndex = 0; readIndex < this.length; readIndex++) {
|
for (let readIndex = 0; readIndex < this.length; readIndex++) {
|
||||||
@ -92,25 +97,25 @@ Array.prototype.degrade = function <T>(this: T[], amount: number) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.repeatAll = function <T>(this: T[], amount: number) {
|
Array.prototype.repeatAll = function <T>(this: T[], amount: number) {
|
||||||
if (amount < 1) {
|
if (amount < 1) {
|
||||||
throw new Error("Amount should be at least 1");
|
throw new Error("Amount should be at least 1");
|
||||||
|
}
|
||||||
|
let result = [];
|
||||||
|
for (let i = 0; i < this.length; i++) {
|
||||||
|
for (let j = 0; j < amount; j++) {
|
||||||
|
result.push(this[i]);
|
||||||
}
|
}
|
||||||
let result = [];
|
}
|
||||||
for (let i = 0; i < this.length; i++) {
|
this.length = 0;
|
||||||
for (let j = 0; j < amount; j++) {
|
this.push(...result);
|
||||||
result.push(this[i]);
|
return this;
|
||||||
}
|
|
||||||
}
|
|
||||||
this.length = 0;
|
|
||||||
this.push(...result);
|
|
||||||
return this;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.repeatPair = function <T>(this: T[], amount: number) {
|
Array.prototype.repeatPair = function <T>(this: T[], amount: number) {
|
||||||
@ -119,7 +124,7 @@ Array.prototype.repeatPair = function <T>(this: T[], amount: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let result = [];
|
let result = [];
|
||||||
|
|
||||||
for (let i = 0; i < this.length; i++) {
|
for (let i = 0; i < this.length; i++) {
|
||||||
// If the index is even, repeat the element
|
// If the index is even, repeat the element
|
||||||
if (i % 2 === 0) {
|
if (i % 2 === 0) {
|
||||||
@ -135,7 +140,7 @@ Array.prototype.repeatPair = function <T>(this: T[], amount: number) {
|
|||||||
this.length = 0;
|
this.length = 0;
|
||||||
this.push(...result);
|
this.push(...result);
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.repeatOdd = function <T>(this: T[], amount: number) {
|
Array.prototype.repeatOdd = function <T>(this: T[], amount: number) {
|
||||||
if (amount < 1) {
|
if (amount < 1) {
|
||||||
@ -159,9 +164,7 @@ Array.prototype.repeatOdd = function <T>(this: T[], amount: number) {
|
|||||||
this.length = 0;
|
this.length = 0;
|
||||||
this.push(...result);
|
this.push(...result);
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Array.prototype.palindrome = function <T>() {
|
Array.prototype.palindrome = function <T>() {
|
||||||
let left_to_right = Array.from(this);
|
let left_to_right = Array.from(this);
|
||||||
@ -200,13 +203,12 @@ Array.prototype.in = function <T>(this: T[], value: T): boolean {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function loadSamples() {
|
export async function loadSamples() {
|
||||||
// const ds = "https://raw.githubusercontent.com/felixroos/dough-samples/main/";
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
initAudioOnFirstClick(),
|
initAudioOnFirstClick(),
|
||||||
samples("github:Bubobubobubobubo/Topos-Samples/main"),
|
|
||||||
samples("github:tidalcycles/Dirt-Samples/master").then(() =>
|
samples("github:tidalcycles/Dirt-Samples/master").then(() =>
|
||||||
registerSynthSounds()
|
registerSynthSounds()
|
||||||
),
|
),
|
||||||
|
samples("github:Bubobubobubobubo/Topos-Samples/main"),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -523,7 +523,7 @@ There are three basic filters: a _lowpass_, _highpass_ and _bandpass_ filters wi
|
|||||||
|
|
||||||
\`\`\`javascript
|
\`\`\`javascript
|
||||||
mod(.5) && snd('sawtooth')
|
mod(.5) && snd('sawtooth')
|
||||||
.cutoff(pick(2000,500)) + usine(.5) * 4000)
|
.cutoff(pick(2000,500) + usine(.5) * 4000)
|
||||||
.resonance(0.9).freq(pick(100,150))
|
.resonance(0.9).freq(pick(100,150))
|
||||||
.out()
|
.out()
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { type Editor } from '../main';
|
import { type Editor } from "../main";
|
||||||
import { AudibleEvent } from './AbstractEvents';
|
import { AudibleEvent } from "./AbstractEvents";
|
||||||
import { midiToFreq, noteFromPc } from 'zifferjs';
|
import { midiToFreq, noteFromPc } from "zifferjs";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
superdough,
|
superdough,
|
||||||
@ -8,7 +8,6 @@ import {
|
|||||||
} from "superdough";
|
} from "superdough";
|
||||||
|
|
||||||
export class SoundEvent extends AudibleEvent {
|
export class SoundEvent extends AudibleEvent {
|
||||||
|
|
||||||
constructor(sound: string | object, public app: Editor) {
|
constructor(sound: string | object, public app: Editor) {
|
||||||
super(app);
|
super(app);
|
||||||
if (typeof sound === "string") this.values = { s: sound, dur: 0.5 };
|
if (typeof sound === "string") this.values = { s: sound, dur: 0.5 };
|
||||||
|
|||||||
Reference in New Issue
Block a user