ss

step-seq

A tiny step sequencer for web audio

Showing:

Popularity

Downloads/wk

2

GitHub Stars

2

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

0

Size (min+gzip)

0.6KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Step sequencer npm

A tiny web audio step sequencer:

var sequencer = require('step-seq')

var ctx = new AudioContext()
var sequence = sequencer(ctx, function (event, data, time, duration) {
  if (event !== 'data') return
  var osc = ctx.createOscillator()
  osc.connect(ctx.destination)
  osc.frequency.value = data
  osc.start(time)
  osc.stop(time + 0.8 * duration)
})

// run a sequence
sequence([261.63, 293.66, 329.63, 349.23, 392.00, 440.00, 493.88, 523.25]).start()

Install

Via npm: npm i --save step-seq or use the browser based distribution (exports sequencer to the window globals)

Usage

Its just one function:

sequencer(ctx, scheduler)

Create a sequencer with an scheduler:

var sequence = sequencer(ctx, function (event, data, time, duration) {
  if (event === 'start') { ... }
  else if (event === 'stop') { ... }
  else if (event === 'data') {
    // play('something').at(time)
  }
})

The scheduler function receives the following parameters:

  • event: the event type. Can be 'start', 'stop' or 'data'
  • data: the data payload (depends on the sequence data)
  • time: the time in the audio context reference
  • duration: the duration in seconds of each beat

The returned sequence function has the following signature:

sequence(source)

It creates sequence objects. The source can be:

  • An array: iterates over the array
  • A number: iterates from 0 to n-1
  • A string: split it using spaces and iterate its elements
  • A function: a generator-type function
  • Nothing: iterates from 0 to Infinity
var s = sequence('A B C D')
s.tempo(100).start()

The sequence object has the following (chainable) methods:

  • start(when): starts the sequence when the audio context currentTime is when
  • stop(when): stops the sequence when audio context currentTime is greater than when
  • tempo(newTempo): set/get the sequence tempo

Examples

To run the example npm install -g beefy and then beefy example/oscillator.js

License

MIT License

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100