var assert =var motif =assert
$ npm install motif
$ bower install motif-js
// => [['a'], ['b']]
Compiles the given
lookup object is given, the value of each symbol given in the lookup object will replace the symbol's occurences in the pattern.
// => [, ]
compilation result (buckets)
All motif patterns produce an array of 'bucket' arrays, where a bucket represents things that occur simultaneously. In the context of music, this would mean a series of notes played at the same time. In the example below,
'c' are in the same bucket, so they would be played at the same time.
// => [['a', 'c'], ['b']]
// => []
Strings are another primitive type in the language. Strings can be any series of alphanumeric characters apart from cases containing only numbers.
// => [['l3mon']]
If a corresponding symbol exists for the string in a lookup object given to
motif, the string representation is replaced by the symbol.
// => [, , ['c']]
A rest produces an empty bucket.
~ is the symbol used for a rest. In the context of music, this would mean a time interval where no notes are played.
// => [['a'], , ['b']]
A repitition is an operation used to duplicate a pattern a number of times. Repititions can be any primitive, rest or group literal followed by a
*, then an integer.
// => [['a'], ['b'], ['a'], ['b'], ['a'], ['b']]
Groups define pattern segments of the same 'length'. In the context of music, this would mean groups of things which should be played one after the other, each at an equivalent amount of time.
A group can be any combination of whitespace separated primitives, rests, operations, or group literals, where a group literal is a nested motif pattern enclosed inside square brackets (
Group literals and whitespace allow one to form multiple groups. In the example below, the following patterns are equivalent, where
[c d] and
[e f g] are the groups in each pattern.
In the example below,
[a] has a rest added to it (it essentially becomes
[a ~]) so that has the same length as
// this simplifies to: '[a ~] [b c]'// then simplifies to: '[a]  [b] [c]'// then compiles to: [['a'], , ['b'], ['c']])
Layers define pattern segments which should overlap. In the context of music, this would mean two different rhythms, possibly of different lengths, that are played simultaneously.
A layer is recognised as one or more groups. Multiple layers are recognised as layers separated by
, characters (with any number of whitespace characters before and after).
In the example below,
b would occur simulataneously.
// => [['a', 'b']])
As is the case with groups, layers are simplified to be of the same 'length'. In the example below,
a has a rest added to it to give it the same length as
[b c]. From there, buckets are formed from the two layers, so
b get played together, and
c gets played alone (
[a] is concatenated with
 is concatenated with
// this simplifies to: '[a ~], [b c]'// then simplifies to: '[a] , [b] [c]'// then compiles to: [['a', 'b'], ['c']]
You can use this library as the npm package
npm i motif # or yarn add motif
It can be used in both es-module-aware and commonjs bundlers/environments.
// es module// commonjsconst motif =
It can also be used a