1.0.0 • Published 10 years ago
beat-scheduler v1.0.0
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 = new window.AudioContext()
, ee = require('nee')()
, opts = { bpm: 135, swing: 0.1, lookahead: 0.2, ee: ee }
, clock = require('beat-scheduler')(ac, opts)
clock.on('next-tick', function (beat) {
// do something notable...
})
clock.play()
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
1.0.0
10 years ago