abbreviate parameters

This commit is contained in:
2023-08-31 13:59:37 +02:00
parent 338dcb26aa
commit 990b129450
2 changed files with 94 additions and 241 deletions

View File

@ -12,6 +12,7 @@ import {
samples, samples,
initAudioOnFirstClick, initAudioOnFirstClick,
registerSynthSounds, registerSynthSounds,
registerZZFXSounds,
soundMap, soundMap,
// @ts-ignore // @ts-ignore
} from "superdough"; } from "superdough";
@ -29,6 +30,7 @@ export async function loadSamples() {
samples("github:tidalcycles/Dirt-Samples/master").then(() => samples("github:tidalcycles/Dirt-Samples/master").then(() =>
registerSynthSounds() registerSynthSounds()
), ),
registerZZFXSounds(),
samples("github:Bubobubobubobubo/Topos-Samples/main"), samples("github:Bubobubobubobubo/Topos-Samples/main"),
]); ]);
} }
@ -1288,12 +1290,17 @@ export class UserAPI {
abs = Math.abs; abs = Math.abs;
// ============================================================= // =============================================================
// Speech synthesis // Speech synthesis
// ============================================================= // =============================================================
speak = (text: string, lang: string = "en-US", voice: number = 0, rate: number = 1, pitch: number = 1): void => { speak = (
text: string,
lang: string = "en-US",
voice: number = 0,
rate: number = 1,
pitch: number = 1
): void => {
/* /*
* Speaks the given text using the browser's speech synthesis API. * Speaks the given text using the browser's speech synthesis API.
* @param text - The text to speak * @param text - The text to speak
@ -1302,10 +1309,19 @@ export class UserAPI {
* @param pitch - The pitch at which to speak the text * @param pitch - The pitch at which to speak the text
* *
*/ */
const speaker = new Speaker({text: text, lang: lang, voice: voice, rate: rate, pitch: pitch}); const speaker = new Speaker({
speaker.speak().then(() => { text: text,
lang: lang,
voice: voice,
rate: rate,
pitch: pitch,
});
speaker
.speak()
.then(() => {
// Done speaking // Done speaking
}).catch((err) => { })
.catch((err) => {
console.log(err); console.log(err);
}); });
}; };

View File

@ -14,76 +14,52 @@ export class SoundEvent extends AudibleEvent {
else this.values = sound; else this.values = sound;
} }
fmenv = (value: "lin" | "exp"): this => { private updateValue<T>(key: string, value: T): this {
this.values["fmenv"] = value; this.values[key] = value;
return this; return this;
}; }
fmattack = (value: number): this => { // ================================================================================
this.values["fmattack"] = value; // ZZFX Sound Parameters
return this; // ================================================================================
};
volume = (value: number) => this.updateValue("volume", value);
vol = this.volume;
zrand = (value: number) => this.updateValue("zrand", value);
// ================================================================================
// Basic Audio Engine Parameters
// ================================================================================
fmi = (value: number) => this.updateValue("fmi", value);
fmh = (value: number) => this.updateValue("fmh", value);
fmenv = (value: "lin" | "exp") => this.updateValue("fmenv", value);
fmattack = (value: number) => this.updateValue("fmattack", value);
fmatk = this.fmattack; fmatk = this.fmattack;
fmdecay = (value: number) => this.updateValue("fmdecay", value);
fmdecay = (value: number): this => {
this.values["fmdecay"] = value;
return this;
};
fmdec = this.fmdecay; fmdec = this.fmdecay;
fmsustain = (value: number) => this.updateValue("fmsustain", value);
fmsustain = (value: number): this => {
this.values["fmsustain"] = value;
return this;
};
fmsus = this.fmsustain; fmsus = this.fmsustain;
fmrelease = (value: number) => this.updateValue("fmrelease", value);
fmrelease = (value: number): this => {
this.values["fmrelease"] = value;
return this;
};
fmrel = this.fmrelease; fmrel = this.fmrelease;
fmvelocity = (value: number) => this.updateValue("fmvelocity", value);
fmvelocity = (value: number): this => {
this.values["fmvelocity"] = value;
return this;
};
fmvel = this.fmvelocity; fmvel = this.fmvelocity;
fmwave = (value: "sine" | "triangle" | "sawtooth" | "square") =>
fmwave = (value: "sine" | "triangle" | "sawtooth" | "square"): this => { this.updateValue("fmwave", value);
this.values["fmwave"] = value;
return this;
};
fmw = this.fmwave; fmw = this.fmwave;
attack = (value: number) => this.updateValue("attack", value);
attack = (value: number): this => {
this.values["attack"] = value;
return this;
};
atk = this.attack; atk = this.attack;
decay = (value: number) => this.updateValue("decay", value);
decay = (value: number): this => {
this.values["decay"] = value;
return this;
};
dec = this.decay; dec = this.decay;
release = (value: number) => this.updateValue("release", value);
release = (value: number): this => {
this.values["release"] = value;
return this;
};
rel = this.release; rel = this.release;
sustain = (value: number) => this.updateValue("sustain", value);
unit = (value: number): this => { sus = this.sustain;
this.values["unit"] = value; unit = (value: number) => this.updateValue("unit", value);
return this; u = this.unit;
}; freq = (value: number) => this.updateValue("freq", value);
f = this.freq;
freq = (value: number): this => { fm = (value: number | string) => {
this.values["freq"] = value;
return this;
};
fm = (value: number | string): this => {
if (typeof value === "number") { if (typeof value === "number") {
this.values["fmi"] = value; this.values["fmi"] = value;
} else { } else {
@ -93,191 +69,52 @@ export class SoundEvent extends AudibleEvent {
} }
return this; return this;
}; };
sound = (value: string) => this.updateValue("s", value);
sound = (value: string): this => { snd = this.sound;
this.values["s"] = value; nudge = (value: number) => this.updateValue("nudge", value);
return this; cut = (value: number) => this.updateValue("cut", value);
}; loop = (value: number) => this.updateValue("loop", value);
clip = (value: number) => this.updateValue("clip", value);
fmi = (value: number): this => { n = (value: number) => this.updateValue("n", value);
this.values["fmi"] = value; note = (value: number) => this.updateValue("note", value);
return this; speed = (value: number) => this.updateValue("speed", value);
}; spd = this.speed;
begin = (value: number) => this.updateValue("begin", value);
fmh = (value: number): this => { end = (value: number) => this.updateValue("end", value);
this.values["fmh"] = value; gain = (value: number) => this.updateValue("gain", value);
return this; cutoff = (value: number) => this.updateValue("cutoff", value);
};
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;
};
lpf = this.cutoff; lpf = this.cutoff;
resonance = (value: number) => this.updateValue("resonance", value);
resonance = (value: number): this => {
this.values["resonance"] = value;
return this;
};
lpq = this.resonance; lpq = this.resonance;
hcutoff = (value: number) => this.updateValue("hcutoff", value);
hcutoff = (value: number): this => {
this.values["hcutoff"] = value;
return this;
};
hpf = this.hcutoff; hpf = this.hcutoff;
hresonance = (value: number) => this.updateValue("hresonance", value);
hresonance = (value: number): this => {
this.values["hresonance"] = value;
return this;
};
hpq = this.hresonance; hpq = this.hresonance;
bandf = (value: number) => this.updateValue("bandf", value);
bandf = (value: number): this => {
this.values["bandf"] = value;
return this;
};
bpf = this.bandf; bpf = this.bandf;
bandq = (value: number) => this.updateValue("bandq", value);
bandq = (value: number): this => {
this.values["bandq"] = value;
return this;
};
bpq = this.bandq; bpq = this.bandq;
coarse = (value: number) => this.updateValue("coarse", value);
coarse = (value: number): this => { crush = (value: number) => this.updateValue("crush", value);
this.values["coarse"] = value; shape = (value: number) => this.updateValue("shape", value);
return this; pan = (value: number) => this.updateValue("pan", value);
}; vowel = (value: number) => this.updateValue("vowel", value);
vow = this.vowel;
crush = (value: number): this => { delay = (value: number) => this.updateValue("delay", value);
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;
};
del = this.delay; del = this.delay;
delayfeedback = (value: number) => this.updateValue("delayfeedback", value);
delayfeedback = (value: number): this => {
this.values["delayfeedback"] = value;
return this;
};
delayfb = this.delayfeedback; delayfb = this.delayfeedback;
delaytime = (value: number) => this.updateValue("delaytime", value);
delaytime = (value: number): this => {
this.values["delaytime"] = value;
return this;
};
delayt = this.delaytime; delayt = this.delaytime;
orbit = (value: number) => this.updateValue("orbit", value);
orbit = (value: number): this => {
this.values["orbit"] = value;
return this;
};
o = this.orbit; o = this.orbit;
room = (value: number) => this.updateValue("room", value);
room = (value: number): this => { rm = this.room;
this.values["room"] = value; size = (value: number) => this.updateValue("size", value);
return this;
};
size = (value: number): this => {
this.values["size"] = value;
return this;
};
sz = this.size; sz = this.size;
velocity = (value: number) => this.updateValue("velocity", value);
velocity = (value: number): this => {
this.values["velocity"] = value;
return this;
};
vel = this.velocity; vel = this.velocity;
modify = (func: Function): this => {
const funcResult = func(this);
if (funcResult instanceof Object) return funcResult;
else {
func(this.values);
this.update();
return this;
}
};
// NOTE: Sustain of the sound. duration() from the superclass Event is used to change the note length.
sustain = (value: number): this => {
this.values["dur"] = value;
return this;
};
sus = this.sustain;
update = (): void => { update = (): void => {
const [note, _] = noteFromPc( const [note, _] = noteFromPc(
this.values.key || "C4", this.values.key || "C4",