Stepmachine.js
A minimal JavaScript library for building a pattern of sequence based on equally spaced steps like step sequencers using Underscore or Lo-Dash.
Functions
Stepmachine.create
// Create an array of `[position, values]` pairs (called `sequence` in
// Stepmachine) from the given array (`input`) that defines a pattern of
// sequence. Rules for defining a pattern of sequence in Stepmachine are
// followings:
//
// [1] Elements of an array are positioned equally spaced. In other words,
// the duration of an array is divided by a length of the array and the
// result is assigned to the duration of its child elements.
//
// Example: [ 'a', 'b' ]
// => [ [0,['a']], [0.5,['b']] ]
//
// [2] Duration of a nested child array equals to the duration of one element
// of its parent array.
//
// Example: [ 'a', [ 'b', 'c' ] ]
// ~~~~~~~~~~~~
// => [ [0,['a']], [0.5,['b']], [0.75,['c']] ]
//
// [3] Elements of an array having a parent array whose length is 1 are
// parallelized.
//
// Example: [ 'a', [[ 'b', [ 'c' , 'd' ] ]] ]
// ~~ ~~
// => [ [0,['a']], [0.5,['b','c']], [0.75,['d']] ]
//
// [4] Falsy elements are skipped.
//
// Example: [ 'a', 'b', , 'c' ]
// ~~
// => [ [0,['a']], [0.25,['b']], [0.75,['c']] ]
//
// If `duration` is given, the duration of the top-level array is set to that
// (1 by default). If `start` is given, start position is set to that (zero by
// default).
Stepmachine.create = function(input, duration, start) { /*...*/ };Stepmachine.reverse
// Reverses the elements of a given nested array excluding parallelized elements.
Stepmachine.reverse = function(input) { /*...*/ };Stepmachine.cycle
// Returns an array built from the contents of a given array repeated
// a certain number of times. If `alternate` is true, reverses the contents
// of odd indexed repetitions.
Stepmachine.cycle = function(input, times, alternate) { /*...*/ }; Stepmachine.create, Stepmachine.reverse and Stepmachine.cycle are also mixed into Underscore or Lo-Dash named _.stepmachine, _.reverse and _.cycle respectively.
License
Copyright (c) 2013 thunder9 licensed under the MIT license.