# Euclidean rhythm

> Spread pulses as evenly as possible over a cycle of steps, locked to the transport, and play each as a note, with rotation, swing and accent.

Source: https://docs.tune.toys/nodes/midi.euclid/

Euclidean rhythm spreads a number of pulses as evenly as possible over a cycle of steps and plays each pulse as a note. Three pulses over eight steps is the tresillo; five over eight the cinquillo. A few of these on different notes make a drum pattern.

## What it does

Pulses are placed with Bjorklund's construction, the method Godfried Toussaint showed generates many traditional rhythms: E(3,8) is `x..x..x.`, E(5,8) is `x.xx.xx.` and E(7,16) is `x..x.x.x..x.x.x.`. Rotation starts the same pattern later in its cycle. More pulses than steps plays every step; no pulses plays nothing.

Steps are locked to the transport's beat, so every replay and offline render plays the same notes on the same samples, and the cycle starts on beat 0. A step sounds only while the transport rolls; stopping or jumping the transport releases the sounding note. A rising edge on `reset` releases it too and starts a new cycle on the next step.

Every pulse plays Note at Velocity; the first pulse of each cycle, as played after rotation, adds Accent. The `hit` outlet is 1 for one block whenever a pulse plays. The `position` outlet holds the current step index divided by Steps, including rests.

The rhythm wheel shows one cycle clockwise from the top: filled dots play notes, small dots are rests, and the polygon joins the pulses. Steps, Pulses and Rotation redraw it immediately; its bottom handle rotates the pattern. During playback, the playhead follows the engine, including swing and resets. The same wheel is available as a Frame face.

## When to use it

Use it for kick, snare and hat patterns, or for an off-kilter pulse on a synth. Merge several with [MIDI merge](https://docs.tune.toys/nodes/midi.merge/) into one drum voice. For melodies, use [Step sequencer](https://docs.tune.toys/nodes/midi.step/).

## Ports

<!-- ports:start -->

| Port       | Direction | Signal  | Lanes            |
| ---------- | --------- | ------- | ---------------- |
| `reset`    | Input     | Control | 1                |
| `midi`     | Output    | MIDI    | 16 MIDI channels |
| `hit`      | Output    | Control | 1                |
| `position` | Output    | Control | 1                |

<!-- ports:end -->

## Parameters

<!-- parameters:start -->

| Parameter     | Label       | Range     | Default | Unit | Scale  | Notes                                                                                                                                                                                               |
| ------------- | ----------- | --------- | ------- | ---- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `steps`       | Steps       | 1 to 32   | 8       |      | linear | Steps in one cycle.                                                                                                                                                                                 |
| `pulses`      | Pulses      | 0 to 32   | 3       |      | linear | Notes in one cycle, spread as evenly as the steps allow; more pulses than steps plays every step.                                                                                                   |
| `rotation`    | Rotation    | 0 to 31   | 0       |      | linear | Shifts the pattern this many steps later in the cycle.                                                                                                                                              |
| `division`    | Division    | 0 to 11   | 2       |      | linear | Length of one step, locked to the transport's beat. Choices: 0 1/32, 1 1/16 triplet, 2 1/16, 3 1/16 dotted, 4 1/8 triplet, 5 1/8, 6 1/8 dotted, 7 1/4 triplet, 8 1/4, 9 1/4 dotted, 10 1/2, 11 1/1. |
| `swing`       | Swing       | 0 to 0.75 | 0       |      | linear | Delay of every second step, as a fraction of a step: 0 is straight, about 0.33 a triplet feel, 0.5 dotted.                                                                                          |
| `note`        | Note        | 0 to 127  | 60      |      | linear | MIDI note every pulse plays.                                                                                                                                                                        |
| `velocity`    | Velocity    | 0 to 1    | 0.8     |      | linear | Velocity of each pulse.                                                                                                                                                                             |
| `accent`      | Accent      | 0 to 1    | 0.2     |      | linear | Velocity added to the first pulse of each cycle.                                                                                                                                                    |
| `gate_length` | Gate length | 0.05 to 1 | 0.5     |      | linear | How long each note sounds, as a fraction of its step.                                                                                                                                               |
| `channel`     | Channel     | 1 to 16   | 1       |      | linear | MIDI channel of the notes.                                                                                                                                                                          |

<!-- parameters:end -->

### Steps (`steps`)

Steps in one cycle, 1 to 32.

### Pulses (`pulses`)

Notes in one cycle, 0 to 32, spread as evenly as the steps allow.

### Rotation (`rotation`)

Shifts the pattern this many steps later in its cycle, 0 to 31; values past Steps wrap around.

### Division (`division`)

The length of one step, from 1/32 to a whole note, with triplet and dotted choices.

### Swing (`swing`)

Delays every second step by a fraction of a step, 0 to 0.75.

### Note (`note`)

The MIDI note every pulse plays, 0 to 127.

### Velocity (`velocity`)

The velocity of each pulse, 0 to 1.

### Accent (`accent`)

Velocity added to the first pulse of each cycle, 0 to 1, so the cycle has a downbeat.

### Gate length (`gate_length`)

How much of its step a note holds, 0.05 to 1.

### Channel (`channel`)

The MIDI channel the notes are sent on, 1 to 16.

## Tips

- Try E(3,8), E(5,8), E(7,12) and E(9,16), then rotate them against each other.
- Two Euclidean rhythms with steps 3 and 4 make a polyrhythm that lines up every twelve steps.
- Short gates (0.1 to 0.2) sound percussive on a sustained voice.

## See also

[Step sequencer](https://docs.tune.toys/nodes/midi.step/), [Clock](https://docs.tune.toys/nodes/ctl.clock/), [MIDI merge](https://docs.tune.toys/nodes/midi.merge/), [Polyphonic instrument](https://docs.tune.toys/nodes/std.poly/).
