beet.js

Beet.js is a polyrhythmic sequencer library for Web Audio API.
The sequencer can have multiple layers where each layer can have an independent tempo and step count.
This feature allows you to create complex rhythmic sequences such as polyrhythms and euclidean rhythms using a simple API.


Simple Euclidean Rhythm - 5/9


var Beet = require('beet.js');
var context = new AudioContext();
var beet = new Beet({
  context: context
});
var pattern = beet.pattern(5, 9); // returns 101110111
var layer = beet.layer(pattern, callback);
beet.add(layer).start();

Euclidean Rhythm - 9/13


var Beet = require('beet.js');
var context = new AudioContext();
var beet = new Beet({
  context: context
});
var pattern = beet.pattern(9, 13); // returns 1011011011011
var layer = beet.layer(pattern, callback);
beet.add(layer).start();

Polyrhythm - 5 over 4 - Two Layers


var Beet = require('beet.js');
var context = new AudioContext();
var beet = new Beet({
  context: context
});
var fours = beet.pattern(4); // returns 1111
var layer1 = beet.layer(fours, foursCallback);
var fives = beet.pattern(5); // returns 11111
var layer2 = beet.layer(fives, fivesCallback);
beet.add(layer1);
beet.add(layer2);
beet..start();

Multiple Layers With Different Tempos


each layer can have an independent speed. the tempo can also be changed in real-time


var Beet = require('beet.js');
var context = new AudioContext();
var beet = new Beet({
  context: context
});
var pattern1 = beet.pattern(4, 8); // returns 10101010
var layer1 = beet.layer(pattern1, callback1);
layer1.tempo = 120;
var pattern2 = beet.pattern(3, 8); // returns 10100100
var layer2 = beet.layer(pattern2, callback2);
layer2.tempo = 60;
var pattern3 = beet.pattern(3, 4); // returns 1111
var laye3 = beet.layer(pattern3, callback3);
layer2.tempo = 40;
beet.add(layer1);
beet.add(layer2);
beet.add(layer3);
beet.start();

On/Off Callbacks


each layer takes two callbacks. one for 'on' steps and one for 'off' steps.


var Beet = require('beet.js');
var context = new AudioContext();
var beet = new Beet({
  context: context
});
var pattern = beet.pattern(4, 9);
// callbackOn will be called on the green slots
// callbackOff will be called on the grey slots
var layer = beet.layer(pattern, callbackOn, callbackOff);
beet.add(layer).start();

Custom String Patterns


a pattern can be genrated by passing a custom string instead of numbers


var Beet = require('beet.js');
var context = new AudioContext();
var beet = new Beet({
  context: context
});
var pattern = beet.pattern('1000101010');
var layer = beet.layer(pattern, callbackOn);
beet.add(layer).start();