From bd5272c6000d6e2a5fb61677b8caf4058b3160d7 Mon Sep 17 00:00:00 2001 From: Miika Alonen Date: Mon, 28 Aug 2023 22:38:57 +0300 Subject: [PATCH] Document chaining --- src/Documentation.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Documentation.ts b/src/Documentation.ts index c6a32fe..6ab4668 100644 --- a/src/Documentation.ts +++ b/src/Documentation.ts @@ -1735,6 +1735,38 @@ Topos is made to be controlled entirely with a keyboard. It is recommanded to st const chaining: string = ` # Chaining +Method chaining can be used to manipulate object returned by both sound() and midi() functions. Probability functions are chained to apply different functions randomly. Probability functions are named as global probability functions (see Probabilities), but take a function as an input. + +## Chaining sound events + +All functions from the sound object can be used to modify the event, for example: + +${makeExample( + "Modifying sound events with probabilities",  +`mod(.5) && sound('hh') + .odds(1/4, s => s.speed(irand(1,4))) + .rarely(s => s.crush(3)) + .out()`, true)}; + +${makeExample( + "Modifying sound events with probabilities",  + `mod(.5) && sound('tink').note(60) + .often(s => s.note(62)) + .sometimes(s => s.note(64).n(irand(1,4))) + .out()`, true)}; + +## Chaining midi events + +All functions from the midi object can be used to modify the event with the probabilities. Values can also be incremented using += notation. + + ${makeExample( + "Modifying midi events with probabilities",  + `mod(.5) && midi(60).channel(1) + .odds(1/4, n => n.channel(2)) + .often(n => n.note+=4) + .sometimes(s => s.velocity(irand(50,100)) + .out()`, true)}; + `; return {