diff --git a/src/API.ts b/src/API.ts
index 504738b..a83cb15 100644
--- a/src/API.ts
+++ b/src/API.ts
@@ -882,12 +882,10 @@ export class UserAPI {
return current_chunk % 2 === 0;
};
- onbar = (n: number, ...bar: number[]): boolean => {
- // n is acting as a modulo on the bar number
- const bar_list = [...Array(n).keys()].map((i) => i + 1);
- console.log(bar.some((b) => bar_list.includes(b % n)));
- return bar.some((b) => bar_list.includes(b % n));
- };
+ public onbar = (n: number, ...bar: number[]): boolean => {
+ return bar.some(b => ((b - 1) % n) < n);
+ };
+
onbeat = (...beat: number[]): boolean => {
/**
diff --git a/src/Documentation.ts b/src/Documentation.ts
index c9db61b..70ae0a8 100644
--- a/src/Documentation.ts
+++ b/src/Documentation.ts
@@ -485,7 +485,17 @@ if (onbar(4, 1, 3)) {
`,
true
)}
-
+
+
+- divbar(bar: number): return true or false alternatively every _n_ bars.
+${makeExample(
+ "Alternating over four bars",
+`
+divbar(2)
+ ? mod(.5) && snd(['kick', 'hh'].div(1)).out()
+ : mod(.5) && snd(['east', 'snare'].div(1)).out()
+`, true)};
+
## What are pulses?
To make a beat, you need a certain number of time grains or **pulses**. The **pulse** is also known as the [PPQN](https://en.wikipedia.org/wiki/Pulses_per_quarter_note). By default, Topos is using a _pulses per quarter note_ of 48. You can change it by using the ppqn(number) function. It means that the lowest possible rhythmic value is 1/48 of a quarter note. That's plenty of time already.