From 70b8b78ea4d8c664602832601efa640e24ab66c3 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sun, 17 Sep 2023 13:38:22 +0200 Subject: [PATCH] Adding more corrections This commit also adds the possibility to pick a sample using the `kick:5` syntax used by Tidal and Strudel. --- src/classes/SoundEvent.ts | 25 ++++++++++++++++++------ src/documentation/time.ts | 40 +++++++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/classes/SoundEvent.ts b/src/classes/SoundEvent.ts index cd36250..748df3e 100644 --- a/src/classes/SoundEvent.ts +++ b/src/classes/SoundEvent.ts @@ -10,8 +10,19 @@ import { export class SoundEvent extends AudibleEvent { constructor(sound: string | object, public app: Editor) { super(app); - if (typeof sound === "string") this.values = { s: sound, dur: 0.5 }; - else this.values = sound; + if (typeof sound === "string") { + 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(key: string, value: T): this { @@ -103,11 +114,13 @@ export class SoundEvent extends AudibleEvent { public begin = (value: number) => this.updateValue("begin", value); public end = (value: number) => this.updateValue("end", 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 cutoff = (value: number) => this.updateValue("cutoff", value); 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 hcutoff = (value: number) => this.updateValue("hcutoff", value); public hpf = this.hcutoff; @@ -164,9 +177,9 @@ export class SoundEvent extends AudibleEvent { }; out = (): void => { - if(this.values.chord) { + if (this.values.chord) { this.values.chord.forEach((freq: number) => { - const copy = {...this.values}; + const copy = { ...this.values }; copy.freq = freq; superdough(copy, 1 / 4, this.values.dur || 0.5); }); diff --git a/src/documentation/time.ts b/src/documentation/time.ts index 98a3883..5a8ce7e 100644 --- a/src/documentation/time.ts +++ b/src/documentation/time.ts @@ -369,7 +369,7 @@ ${makeExample( ` flipbar(2) ? 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 )}; @@ -380,16 +380,21 @@ flipbar(2) ${makeExample( "Using onbar for filler drums", ` -// Only play on the fourth bar of a four bar cycle. -onbar(4, 4)::beat(.5)::snd('hh').out(); - -// Here comes a longer version using JavaScript normal control flow -if (onbar([4, 1], 3)) { - beat(1)::snd('kick').out(); +bpm(150); +// Only play on the third and fourth bar of the cycle. +onbar([3,4], 4)::beat(.25)::snd('hh').out(); +// Using JavaScript regular control flow +if (onbar([1,2], 4)) { + 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 { - 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 )} @@ -422,15 +427,22 @@ These values are **extremely useful** to craft more complex syntax or to write m ${makeExample( "Manual mode: using time primitives!", ` +// Manual time condition if((cbar() % 4) > 1) { - beat(1) && sound('kick').out() + beat(2) && sound('kick').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 { beat(.5) && sound('hh').out() - beat(.75) && sound('cp').out() - beat(.5) && sound('jvbass').freq(250).out() + beat(2) && sound('cp').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 )}