Nerd Corner: Edit Custom Patterns in a Text Editor
Nerd Corner: Edit Custom Patterns in a Text Editor

Nerd Corner: Edit Custom Patterns in a Text Editor

Rhythm Lab provides a Custom screen for creating and editing patterns. You can edit existing patterns and add them to a new pattern set, or keep them on an existing custom pattern set. You can also export your custom pattern set in JSON format. Since Rhythm Lab can import custom pattern sets in JSON format, this means it is easy to create or edit a custom pattern set using only a text editor. As easy as it is to create and edit using the Custom screen, you might find it useful to use a text editor instead. In this article, I will outline the basic format and structure of the JSON file, and give some examples of how to edit it.

JSON Format and Structure

A Rhythm Lab Custom Pattern Set has the following structure:

  • Top Level: the data structure is a dictionary with the following keys:
    • title – the title of the pattern set = text string
    • type – one of four types: single, double, drumline, or drumkit = text string
    • category – all custom pattern sets are “custom” = text string
    • sequence – if you want to group more than one custom pattern in a certain order = number
    • exercises – an array (list) of all of the patterns in the set = array
  • Secondary Level: the data structure is an array of Patterns that belong to the Pattern Set. Each member of the array is a unique pattern defined by a dictionary with the following keys:
    • title – the title of the pattern = text string.
    • type – one of four types: single, double, drumline, or drumkit = text string.
    • category – all custom patterns are “custom” = text string.
    • sequence – the ordinal position of the pattern in the pattern set = number.
    • timeSig – the initial time signature of the pattern = text string.
    • points – the number of points for this pattern. This value is actually ignored by Rhythm Lab; points are calculated within the program itself, but the key is still within the data structure for legacy code reasons. =. number.
    • measure count – the number of measures in this pattern = number.
    • bpm – the initial metronome beats per minute for this pattern = number.
    • voices – an array of individual voices for this pattern. Single patterns and Drumline patterns have one voice, Double patterns have two voices, and Drumkit patterns have three voices = array.
  • Tertiary Level: the data structure is an array of voice objects that belong to the Pattern. Each member of the array is a dictionary defined by the following keys:
    • type – includes voice one, voice two, drumline, hihat, snare, or kick types = text string.
    • pattern – a text string with a very specific format that indicates all of the elements in the pattern for each measure. Rhythm Lab parses the pattern to create the actual rhythmic elements (notes, rest, barlines, time signatures, beamed groups, tuplet groups, etc.) = text string.
    • sequence – the ordinal position of the voice within the pattern = number.

Example

{
  "title" : "Rests Level A - Example",
  "type" : "single",
  "category" : "custom",
  "sequence" : 0,
  "exercises" : [
    {
      "category" : "custom",
      "timeSig" : "2\/4",
      "sequence" : 0,
      "points" : 0,
      "measureCount" : 4,
      "title" : "Rests 1",
      "bpm" : 85,
      "voices" : [
        {
          "type" : "v1pattern",
          "pattern" : " q  qr bs  q  qr bs  q  qr bs  h bf",
          "sequence" : 0
        }
      ],
      "type" : "single"
    },
{
      "category" : "custom",
      "timeSig" : "2\/4",
      "sequence" : 1,
      "points" : 0,
      "measureCount" : 4,
      "title" : "Rests 2",
      "bpm" : 85,
      "voices" : [
        {
          "type" : "v1pattern",
          "pattern" : " q  qr bs  h bs  q  qr bs  h bf",
          "sequence" : 0
        }
      ],
      "type" : "single"
    },
    {
      "category" : "custom",
      "timeSig" : "2\/4",
      "sequence" : 2,
      "points" : 0,
      "measureCount" : 4,
      "title" : "Rests 3",
      "bpm" : 85,
      "voices" : [
        {
          "type" : "v1pattern",
          "pattern" : " h bs  q  qr bs  h bs  h bf",
          "sequence" : 0
        }
      ],
      "type" : "single"
    }    
  ]
}

Notes

Rhythm Lab stores custom pattern sets as objects, and within each object, references to individual patterns are held in a Set rather than an Array. If you examine the JSON files generated by Rhythm Lab (export custom pattern set), you will notice that patterns, and voices within patterns, are not necessarily listed in the order of the sequence number.

The “pattern” strings inside the “voices” dictionary follow a very specific format that Rhythm Lab parses to create the pattern inside the app. I will explore these strings in a later post. For now, you can probably figure out the basic syntax on your own by examining this and other examples.