Skip to content

joeLepper/beat-scheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  • __opts.ee-- event emitter - an event emitter with on and emit methods for use communicating with the scheduler; beat-scheduler uses nee internally

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

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

About

A clock to use scheduling beats and audio

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published