Merge
This commit is contained in:
68
src/API.ts
68
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,
|
||||
@ -249,12 +250,13 @@ export class UserAPI {
|
||||
public zn(input: string,
|
||||
options: {[key: string]: string|number} = {}): Event {
|
||||
const pattern = cachedPattern(input, options);
|
||||
if(pattern.hasStarted()) {
|
||||
//@ts-ignore
|
||||
if(pattern.hasStarted()) {
|
||||
|
||||
const event = pattern.peek();
|
||||
|
||||
// Check if event is modified
|
||||
const node = event.modifiedEvent ? event.modifiedEvent : event;
|
||||
const node = event!.modifiedEvent ? event!.modifiedEvent : event;
|
||||
const channel = (options.channel ? options.channel : 0) as number;
|
||||
const velocity = (options.velocity ? options.velocity : 100) as number;
|
||||
const sustain = (options.sustain ? options.sustain : 0.5) as number;
|
||||
@ -274,8 +276,9 @@ export class UserAPI {
|
||||
}
|
||||
|
||||
// Remove old modified event
|
||||
if(event.modifiedEvent) event.modifiedEvent = undefined;
|
||||
if(event!.modifiedEvent) event!.modifiedEvent = undefined;
|
||||
}
|
||||
//@ts-ignore
|
||||
return pattern.next();
|
||||
}
|
||||
|
||||
@ -1000,6 +1003,7 @@ export class UserAPI {
|
||||
length: number,
|
||||
rotate: number = 0
|
||||
): boolean[] {
|
||||
if (pulses == length) return Array.from({ length }, () => true);
|
||||
function startsDescent(list: number[], i: number): boolean {
|
||||
const length = list.length;
|
||||
const nextIndex = (i + 1) % length;
|
||||
@ -1033,7 +1037,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.
|
||||
*
|
||||
*/
|
||||
}
|
||||
@ -1077,6 +1081,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.
|
||||
@ -1092,6 +1108,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.
|
||||
@ -1105,6 +1133,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.
|
||||
@ -1118,6 +1158,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.
|
||||
@ -1142,10 +1194,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, this.app);
|
||||
}
|
||||
|
||||
samples = samples;
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ export class Clock {
|
||||
this.time_signature = [4, 4];
|
||||
this.tick = 0;
|
||||
this.bpm = 120;
|
||||
this.ppqn = 48;
|
||||
this.ppqn = 24;
|
||||
this.transportNode = null;
|
||||
this.ctx = ctx;
|
||||
ctx.audioWorklet.addModule(TransportProcessor).then((e) => {
|
||||
|
||||
169
src/Sound.ts
Normal file
169
src/Sound.ts
Normal file
@ -0,0 +1,169 @@
|
||||
import { type Editor } from './main';
|
||||
|
||||
import {
|
||||
superdough,
|
||||
// @ts-ignore
|
||||
} from "superdough";
|
||||
|
||||
export class Sound {
|
||||
|
||||
values: { [key: string]: any }
|
||||
|
||||
constructor(sound: string, public app: Editor) {
|
||||
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, this.app.clock.pulse_duration);
|
||||
}
|
||||
}
|
||||
@ -37,7 +37,7 @@ export class TransportNode extends AudioWorkletNode {
|
||||
setTimeout(() => {
|
||||
const now = performance.now();
|
||||
this.app.clock.time_position = futureTimeStamp;
|
||||
this.$clock.innerHTML = `[${futureTimeStamp.bar}:${futureTimeStamp.beat}:${zeroPad(futureTimeStamp.pulse, '2')}]`;
|
||||
// this.$clock.innerHTML = `[${futureTimeStamp.bar}:${futureTimeStamp.beat}:${zeroPad(futureTimeStamp.pulse, '2')}]`;
|
||||
tryEvaluate(
|
||||
this.app,
|
||||
this.app.global_buffer,
|
||||
@ -66,7 +66,7 @@ export class TransportNode extends AudioWorkletNode {
|
||||
this.startTime = null;
|
||||
this.elapsedTime = null;
|
||||
this.app.clock.tick = 0;
|
||||
this.$clock.innerHTML = `[${1} | ${1} | ${zeroPad(1, '2')}]`;
|
||||
// this.$clock.innerHTML = `[${1} | ${1} | ${zeroPad(1, '2')}]`;
|
||||
this.port.postMessage("stop");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user