Add missing bar function + documentation

This commit is contained in:
2023-10-13 16:42:13 +02:00
parent ad9962848c
commit 2edbb577d0
2 changed files with 158 additions and 137 deletions

View File

@ -1269,6 +1269,17 @@ export class UserAPI {
}; };
b = this.beat; b = this.beat;
public bar = (...n: number[]): boolean => {
const results: boolean[] = n.map(
(value) =>
this.app.clock.pulses_since_origin % Math.floor((value * this.ppqn()) * this.app.clock.time_signature[1]) ===
0
);
return results.some((value) => value === true);
};
B = this.bar;
public pulse = (...n: number[]): boolean => { public pulse = (...n: number[]): boolean => {
const results: boolean[] = n.map( const results: boolean[] = n.map(
(value) => this.app.clock.pulses_since_origin % value === 0 (value) => this.app.clock.pulses_since_origin % value === 0

View File

@ -20,7 +20,7 @@ To change the tempo, use the <ic>bpm(number)</ic> function. The transport is con
Let's study two very simple rhythmic functions, <ic>mod(n: ...number[])</ic> and <ic>onbeat(...n:number[])</ic>. They are both easy to understand and powerful enough to get you to play your first rhythms. Let's study two very simple rhythmic functions, <ic>mod(n: ...number[])</ic> and <ic>onbeat(...n:number[])</ic>. They are both easy to understand and powerful enough to get you to play your first rhythms.
- <ic>beat(...n: number[])</ic>: this function will return true every _n_ beats. The value <ic>1</ic> will return <ic>true</ic> at the beginning of each beat. Floating point numbers like <ic>0.5</ic> or <ic>0.25</ic> are also accepted. Multiple values can be passed to <ic>beat</ic> to generate more complex rhythms. - <ic>beat(...n: number[])</ic>: return true every _n_ beats. The value <ic>1</ic> will return <ic>true</ic> at the beginning of each beat. Floating point numbers like <ic>0.5</ic> or <ic>0.25</ic> are also accepted. Multiple values can be passed to <ic>beat</ic> to generate more complex rhythms.
${makeExample( ${makeExample(
"Using different mod values", "Using different mod values",
@ -51,7 +51,6 @@ beat([1,0.75].beat(2)) :: blip([50, 100].beat(2)).pan(r(0,1)).out();
false false
)} )}
- <ic>pulse(...n: number[])</ic>: faster version of the <ic>beat</ic> function. Instead of returning true for every beat, this function is returning true every _n_ clock ticks! It can be used to generate very unexpected rhythms. - <ic>pulse(...n: number[])</ic>: faster version of the <ic>beat</ic> function. Instead of returning true for every beat, this function is returning true every _n_ clock ticks! It can be used to generate very unexpected rhythms.
${makeExample( ${makeExample(
@ -74,6 +73,17 @@ beat(1)::snd(['bd', '808oh'].beat(1)).out()
false false
)}; )};
- <ic>bar(...n: number[])</ic>: return true every _n_ bars.
${makeExample(
"Four beats per bar: proof",
`
bar(1)::sound('kick').out()
beat(1)::sound('hat').speed(2).out()
`, true
)}
- <ic>onbeat(...n: number[])</ic>: The <ic>onbeat</ic> function allows you to lock on to a specific beat from the clock to execute code. It can accept multiple arguments. It's usage is very straightforward and not hard to understand. You can pass either integers or floating point numbers. By default, topos is using a <ic>4/4</ic> bar meaning that you can target any of these beats (or in-between) with this function. - <ic>onbeat(...n: number[])</ic>: The <ic>onbeat</ic> function allows you to lock on to a specific beat from the clock to execute code. It can accept multiple arguments. It's usage is very straightforward and not hard to understand. You can pass either integers or floating point numbers. By default, topos is using a <ic>4/4</ic> bar meaning that you can target any of these beats (or in-between) with this function.
${makeExample( ${makeExample(