Step sequencer
A tiny web audio step sequencer:
var sequencer = var ctx = var sequence = // run a sequencestart
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 =
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 = sstart
The sequence object has the following (chainable) methods:
start(when)
: starts the sequence when the audio context currentTime iswhen
stop(when)
: stops the sequence when audio context currentTime is greater thanwhen
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