Merge pull request #1 from Bubobubobubobubo/two-clocks

Two clocks
This commit is contained in:
Raphaël Forment
2023-08-02 19:39:54 +02:00
committed by GitHub
6 changed files with 104 additions and 42 deletions

View File

@ -164,9 +164,14 @@ export class UserAPI {
// Transport functions
// =============================================================
bpm(bpm: number): void {
bpm(bpm?: number): number {
if (bpm === undefined)
return this.app.clock.bpm
this.app.clock.bpm = bpm
return bpm
}
tempo = this.bpm
time_signature(numerator: number, denominator: number): void {
this.app.clock.time_signature = [numerator, denominator]
@ -210,12 +215,16 @@ export class UserAPI {
get bar(): number { return this.app.clock.time_position.bar }
get pulse(): number { return this.app.clock.time_position.pulse }
get beat(): number { return this.app.clock.time_position.beat }
get beats_since_origin(): number { return this.app.clock.beats_since_origin }
onbar(...bar: number[]): boolean {
return bar.some(b => b === this.app.clock.time_position.bar)
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_list)
console.log(bar.some(b => bar_list.includes(b % n)))
return bar.some(b => bar_list.includes(b % n))
}
// TODO: bugfix here
onbeat(...beat: number[]): boolean {
let final_pulses: boolean[] = []
beat.forEach(b => {
@ -235,7 +244,6 @@ export class UserAPI {
}
mod(...pulse: number[]): boolean { return pulse.some(p => this.app.clock.time_position.pulse % p === 0) }
modbar(...bar: number[]): boolean { return bar.some(b => this.app.clock.time_position.bar % b === 0) }
euclid(pulses: number, length: number, rotate: number=0): boolean {
@ -266,9 +274,8 @@ export class UserAPI {
// Small ZZFX interface for playing with this synth
zzfx = (...thing: number[]) => zzfx(...thing);
playSound = async (values: object) => {
sound = async (values: object) => {
await this.load;
webaudioOutput(sound(values), 0.01)
webaudioOutput(sound(values), 0.00)
}
}