MusiFrog 2D

The MusiFrog 2D (© algoritmarte) is a variant of the MusiFrog algorithm described in this post.

The MusiFrog algorithm is a deterministic algorithm for generating a sequence of notes using a “frog” (no animals were harmed in the creation of this algorithm). In this variant the frog plays on a two dimensional MxN grid.

splash

The grid and initial setup

In our first example we picked a 5×5 squares grid.

Each cell of the grid contains:

  • a note
  • a jump value and
  • a direction.

One cell is the current cell, and the frog is positioned over it.

The notes could be random, but for more musical result, you can create a sequence and repeat it all over the grid. The length of the sequence does not have to correspond to one of the sides of the grid. For example, use 11 notes from the C major diatonic scale over two octaves:

C, D, E, F, G, A, B, C2, D2, E2, G2

Note that picking different starting points on the grid can lead to completely different melodies. In our example we started from the G (upper-left corner).

The jump value of a cell is a positive integer; in our example we used the range from 1 to the side length minus one, but we could use also greater numbers (opposite borders are treated as if they are connected).

The initial jump values of the cells can be assigned in different ways:

  • the same value; in our example each cell at the beginning has a jump value of 1
  • increasing values
  • random values
  • values from a simple math formula
  • and so on …

The direction can be Right, Down, Left, Up represented with the integers 0,1,2,3.

As for the jumps, the initial direction of each cell can be assigned in different ways, the suggestion is to use a fixed direction; in our example each cell at the beginning has direction Right (0).

The Frog jumps

After the grid is built, the frog start its jumps using these simple rules:

  • it jumps along the cell’s direction and the jump length is the jump value of the cell; if the jump crosses the border it re-enters from the opposite border;
  • the note of the landing cell is played;
  • both the jump value and the direction are increased by one (if the increment exceeds the maximum, the value is set to the minimum)

In this example the frog is on cell (4,4) which has jump value 2, and direction Down (1)

fig2

  • it jumps Down , and crossing the border it re-enters from the top border and lands on cell (4,1) that contains the note C2
  • the note C2 is played
  • the old cell at (4,4) now contains a jump value of 2+1=3, and the direction is Left (1+1=2)

fig3

To make the melody more interesting, you can store the sequence of the notes; then after T steps, every K steps you can decide to replay a previous note of the sequence (and lower it by one octave). For example:

Jump: 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
Note: C  D  A  F  G  E  F  G  C  A  C  E  D  F  B
Bass: -  -  -  -  -  C  -  -  D  -  -  A  -  -  F
                     ^after 6 jumps we start to replay the sequence,
                      but "slowly", every 3 jumps

This is a video that demonstrates the execution of the algorithm; the notes are sent to a synth (ASM Hydrasynth Explorer) using the MIDI interface. The Soma Lab Cosmos is used to add some post effects.

Ideas for further improvements experiments:

  • associate each cell with an interval instead of a note
  • make some “holes” in the grid (if the frog jumps on a hole, no note is played)
  • use different grid shapes

 

Leave a Reply

Your email address will not be published. Required fields are marked *