The RandomFragmentPatternEngine is a PatternEngine that generates random patterns composed of provided pattern fragments. The generated patterns are allowed to contain notes provided as numbers or wildcard, legato flags and velocity definitions.

This PatternEngine generates a pattern of length patternTicks * list size of patternString. For each distinct element in the patternString, a pattern is generated. The pattern generation works as follows: Pattern fragments are randomly chosen from the provided fragments of the pattern part group character and are concatenated. The pattern is extended until it has exactly the number of ticks provided in the patternTicks variable or until that value is exceeded (in which case this is an error condition).

If a pattern for the same pattern part group has already been generated, a variant of that pattern will be generated (by regenerating a new pattern until the new pattern is unique within the pattern part group), otherwise a new pattern is generated. For example, if you use "A1,A2,A1,B1", A1 will generate a random pattern, A2 will create another one that is different from A1, A1 will use the already generated pattern and B1 will generate a new random pattern.

Please see the description of the RandomPatternEngine for a hint for using the Towers-of-Hanoi method.

The configuration example shows a configuration that can be used to generate a pattern for a snare. Here, the pattern part "A1" can only generate the result ";-,-,-,-,0,-,-,-,-,-,-,-,0,-,-,-" (because the group for "A" only has one pattern fragment, and 16 ticks should be generated). "B1" randomly chooses two of the available two fragments for "B" (either first then first, first then second, second then first or second then second). The second "A1" uses the previous "A1" result, and C1 generates a pattern similar to B1, but from group C.

Currently, all pattern fragments should have the same length in ticks within each group and the patternTicks value must be an integer multiple of that length.

Available since version 0.1.


Tag Attribute Type # Example Description
uniquePatternParts - boolean 0/1 false If true, all generated pattern parts are guaranteed to be unique. Defaults to true. Available since version 0.2.
patternTicks - int 1 16 The number of ticks of the generated pattern parts.
ticksPerBeat - int 0/1 4 Specifies how many ticks in the generated pattern are considered to be a beat. If the actual ticks-per-beat value of the song is different from the one provided here, all note/pause lengths are scaled by the appropriate factor. For example, if the pattern uses 4 and the song uses 12, each pattern note/pause length is multiplied by 3. If this tag is not provided, no length scaling is done. Available since version 0.8.
patternString - string 1 A1,A2,A1,B1 A comma-separated list of pattern parts. Each part consists of two characters or the single character "-". The first character is the pattern part group, the second one defines the group part. "-" will generate an empty pattern.
pattern group string 1 A The group of this list of pattern fragments (must be one character long). The character must be unique within all pattern tags provided.
pattern - string 1 0,-,-,-,0,-,-,-|0,-,-,-,0,-,-,0 The list of pattern fragments (separated by pipe characters). The patterns may contain wildcards, tick lengths, velocities and legato flags.

Configuration example

<patternEngine class="RandomFragmentPatternEngine">
  <pattern group="A">-,-,-,-,0,-,-,-</pattern>
  <pattern group="B">-,-,-,-,0,-,-,-|-,-,-,-,0,-,-,0</pattern>
  <pattern group="C">-,-,-,-,0,-,-,0|-,-,-,0,0,-,0,-</pattern>

Add new comment