1.0.0 • Public • Published


An event-based audio clock with variable bpm and swing for use in the browser


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...

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


  • 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 when event is fired; handler will receive a beat object

Beat Objects

  • 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


Beat-scheduler emits only one event type:

  1. 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:

  1. schedule-play will be handled by
  2. schedule.stop will be handled by clock.stop
  3. bpm-change will be handled by clock.changeBpm
  4. swing-change will be handled by clock.changeSwing

Package Sidebar


npm i beat-scheduler

Weekly Downloads






Last publish


  • joelepper