adding the binrhythm function
This commit is contained in:
15
src/API.ts
15
src/API.ts
@ -1072,7 +1072,7 @@ export class UserAPI {
|
||||
integral_part = integral_part == 0 ? this.nominator() : integral_part;
|
||||
let decimal_part = Math.floor((beat - integral_part) * this.ppqn() + 1);
|
||||
// This was once revelead to me in a dream
|
||||
if (decimal_part <= 0)
|
||||
if (decimal_part <= 0)
|
||||
decimal_part = decimal_part + this.ppqn() * this.nominator();
|
||||
final_pulses.push(
|
||||
integral_part === this.beat() && this.pulse() === decimal_part
|
||||
@ -1219,6 +1219,19 @@ export class UserAPI {
|
||||
return tobin[iterator % tobin.length];
|
||||
};
|
||||
|
||||
public binrhythm = (div: number, n: number): boolean => {
|
||||
/**
|
||||
* Returns a binary cycle of size n, divided by div.
|
||||
*
|
||||
* @param div - The divisor of the binary cycle
|
||||
* @param n - The number to convert to binary
|
||||
* @returns boolean value based on the binary sequence
|
||||
*/
|
||||
let convert: string = n.toString(2);
|
||||
let tobin: boolean[] = convert.split("").map((x: string) => x === "1");
|
||||
return this.mod(div) && tobin.div(div);
|
||||
};
|
||||
|
||||
// =============================================================
|
||||
// Low Frequency Oscillators
|
||||
// =============================================================
|
||||
|
||||
@ -182,6 +182,7 @@ rhythm(speed, 7, 12) :: snd('east').n(9).out()
|
||||
|
||||
|
||||
- <ic>bin(iterator: number, n: number): boolean</ic>: a binary rhythm generator. It transforms the given number into its binary representation (_e.g_ <ic>34</ic> becomes <ic>100010</ic>). It then returns a boolean value based on the iterator in order to generate a rhythm.
|
||||
- <ic>binrhythm(divisor: number, n: number): boolean: boolean</ic>: iterator-less version of the binary rhythm generator.
|
||||
|
||||
${makeExample(
|
||||
"Change the integers for a surprise rhythm!",
|
||||
@ -192,6 +193,15 @@ mod(.5) && bin($(2), 48) && snd('sd').out()
|
||||
true
|
||||
)}
|
||||
|
||||
${makeExample(
|
||||
"binrhythm for fast cool binary rhythms!",
|
||||
`
|
||||
binrhythm(.5, 13) && snd('kick').out()
|
||||
binrhythm(.5, 18) && snd('sd').out()
|
||||
`,
|
||||
true
|
||||
)}
|
||||
|
||||
${makeExample(
|
||||
"Calling 911",
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user