Beat-scheduler
An event-based audio clock with variable bpm and swing for use in the browser
Install
npm install beat-scheduler --save
Basic Use
var ac = ee = opts = bpm: 135 swing: 01 lookahead: 02 ee: ee clock = ac opts clock clock
Configuration Options
- opts.bpm integer - beats per minute
- opts.swing float - a value between 0 and 1 representing the amount of "swing" in the beat
- opts.lookahead float - number of seconds (typically a fraction thereof) to look ahead for not events
Methods
- clock.play() start the clock
- clock.stop() stop the clock
- clock.changeBpm(bpm) set the
bpm
to a number - clock.changeSwing(swing) change the
swing
to a float between 0 and 1 - clock.on(event, handler) register
handler
as a callback whenevent
is fired;handler
will receive abeat
object
Beat Objects
- beat.now float - audio context time at which the tick was published
- beat.beatLength float - the total length of this beat (adjusted for swing)
- beat.lookahead float - audio context time to look ahead to; users will typically use this to schedule events for the future
- beat.lastBeat float - audio context time at which the previous beat occurred
- beat.nextBeat float - audio context time at which the next beat will occur
Events
Beat-scheduler emits only one event type:
- next-tick events fire on a request animation frame loop, passing a
beat
object
If you hand in an event emitter with on
and emit
methods, beat-scheduler can also respond to events:
- schedule-play will be handled by
clock.play
- schedule.stop will be handled by
clock.stop
- bpm-change will be handled by
clock.changeBpm
- swing-change will be handled by
clock.changeSwing