Adding more corrections

This commit also adds the possibility to pick a sample using the
`kick:5` syntax used by Tidal and Strudel.
This commit is contained in:
2023-09-17 13:38:22 +02:00
parent f10a0f00d5
commit 70b8b78ea4
2 changed files with 45 additions and 20 deletions

View File

@ -10,8 +10,19 @@ import {
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") {
else this.values = sound; if (sound.includes(":")) {
this.values = {
s: sound.split(":")[0],
n: sound.split(":")[1],
dur: 0.5,
};
} else {
this.values = { s: sound, dur: 0.5 };
}
} else {
this.values = sound;
}
} }
private updateValue<T>(key: string, value: T): this { private updateValue<T>(key: string, value: T): this {
@ -103,11 +114,13 @@ export class SoundEvent extends AudibleEvent {
public begin = (value: number) => this.updateValue("begin", value); public begin = (value: number) => this.updateValue("begin", value);
public end = (value: number) => this.updateValue("end", value); public end = (value: number) => this.updateValue("end", value);
public gain = (value: number) => this.updateValue("gain", value); public gain = (value: number) => this.updateValue("gain", value);
public dbgain = (value: number) => this.updateValue("gain", Math.min(Math.pow(10, value / 20), 10)); public dbgain = (value: number) =>
this.updateValue("gain", Math.min(Math.pow(10, value / 20), 10));
public db = this.dbgain; public db = this.dbgain;
public cutoff = (value: number) => this.updateValue("cutoff", value); public cutoff = (value: number) => this.updateValue("cutoff", value);
public lpf = this.cutoff; public lpf = this.cutoff;
public resonance = (value: number) => this.updateValue("resonance", Math.min(Math.max(value, 0), 50)); public resonance = (value: number) =>
this.updateValue("resonance", Math.min(Math.max(value, 0), 50));
public lpq = this.resonance; public lpq = this.resonance;
public hcutoff = (value: number) => this.updateValue("hcutoff", value); public hcutoff = (value: number) => this.updateValue("hcutoff", value);
public hpf = this.hcutoff; public hpf = this.hcutoff;
@ -164,9 +177,9 @@ export class SoundEvent extends AudibleEvent {
}; };
out = (): void => { out = (): void => {
if(this.values.chord) { if (this.values.chord) {
this.values.chord.forEach((freq: number) => { this.values.chord.forEach((freq: number) => {
const copy = {...this.values}; const copy = { ...this.values };
copy.freq = freq; copy.freq = freq;
superdough(copy, 1 / 4, this.values.dur || 0.5); superdough(copy, 1 / 4, this.values.dur || 0.5);
}); });

View File

@ -369,7 +369,7 @@ ${makeExample(
` `
flipbar(2) flipbar(2)
? beat(.5) && snd(['kick', 'hh'].beat(1)).out() ? beat(.5) && snd(['kick', 'hh'].beat(1)).out()
: beat(.5) && snd(['east', 'snare'].beat(1)).out() : beat(.5) && snd(['east', 'east:2'].beat(1)).out()
`, `,
false false
)}; )};
@ -380,16 +380,21 @@ flipbar(2)
${makeExample( ${makeExample(
"Using onbar for filler drums", "Using onbar for filler drums",
` `
// Only play on the fourth bar of a four bar cycle. bpm(150);
onbar(4, 4)::beat(.5)::snd('hh').out(); // Only play on the third and fourth bar of the cycle.
onbar([3,4], 4)::beat(.25)::snd('hh').out();
// Here comes a longer version using JavaScript normal control flow // Using JavaScript regular control flow
if (onbar([4, 1], 3)) { if (onbar([1,2], 4)) {
beat(1)::snd('kick').out(); beat(.5) :: sometimes() :: sound('east').out()
rhythm(.5, 3, 7) :: snd('kick').out();
rhythm(.5, 1, 7) :: snd('jvbass').out();
rhythm(.5, 2, 7) :: snd('snare').n(5).out();
} else { } else {
beat(.5)::snd('sd').out(); beat(.5) :: rarely() :: sound('east').n($(1)).out()
} rhythm(.5, 3, 7) :: snd('kick').n(4).out();
`, rhythm(.5, 1, 7) :: snd('jvbass').n(2).out();
rhythm(.5, 2, 7) :: snd('snare').n(3).out();
}`,
true true
)} )}
@ -422,15 +427,22 @@ These values are **extremely useful** to craft more complex syntax or to write m
${makeExample( ${makeExample(
"Manual mode: using time primitives!", "Manual mode: using time primitives!",
` `
// Manual time condition
if((cbar() % 4) > 1) { if((cbar() % 4) > 1) {
beat(1) && sound('kick').out() beat(2) && sound('kick').out()
rarely() && beat(.5) && sound('sd').out() rarely() && beat(.5) && sound('sd').out()
beat(.5) && sound('jvbass').freq(500).out() beat([.5, .25].beat()) && sound('jvbass')
.freq(100 * [2, 1].pick()).dec(2)
.room(0.9).size(0.9).orbit(2).out()
} else { } else {
beat(.5) && sound('hh').out() beat(.5) && sound('hh').out()
beat(.75) && sound('cp').out() beat(2) && sound('cp').out()
beat(.5) && sound('jvbass').freq(250).out() beat([.5, .5, .25].beat(.5)) && sound('jvbass')
.freq(100 * [3, 1].pick()).dec(2)
.room(0.9).size(0.9).orbit(2).out()
} }
// This is always playing no matter what happens
beat([.5, .5, 1, .25].beat(0.5)) :: sound('shaker').out()
`, `,
true true
)} )}