> For the complete documentation index, see [llms.txt](https://docs.sattern.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sattern.dev/tutorial/patterns.md).

# Patterns

Patterns objects are are the fundamental pieces that make sequences.

> &#x20;If Sattern was a traditional synthesizer then `Pattern` objects can be thought of as its "sounds".

Each Pattern can be mapped across a key/velocity range and respond to input event(s) like MIDI note-on(s), controller messages etc. and return a sequence of `Step` objects.

Let's add some code to our current project to generate a simple sequence. We'll create a new `pattern` object, add it to `sattern`, and assign its `onSequence` property to a custom function that returns a list of `Step` objects.

```javascript
// main.js
// Arpeggiator
//
// Created by Jacob Sologub on 15 Jun 2020.
// Copyright © 2020 Jacob Sologub. All rights reserved.

const sampler = new sattern.Sampler();
sattern.graph.add (sampler);

const sound = new sattern.Sound ("./mcg_mp_064.wav", {
    lowKey: 0, highKey: 127, rootKey: 64
});
sampler.add (sound);

const pattern = new sattern.Pattern();
sattern.add (pattern);
pattern.onSequence = function (context) {
    return [
        new sattern.Step ([sampler, new sattern.Note (64)], 4, 4),
        new sattern.Step ([sampler, new sattern.Note (71)], 4, 4),
        new sattern.Step ([sampler, new sattern.Note (68)], 4, 4),
        new sattern.Step ([sampler, new sattern.Note (76)], 4, 4)
    ];
};
```

Line `#15` creates a new pattern object, line `#16` adds the newly created pattern object to `sattern`, lines `#17-24` assign the pattern object's onSequence property to a custom `function` that returns an `Array` of `Step` objects.

Now hit a key on your midi keyboard or on the virtual (12) "MIDI Keyboard" inside the Sattern UI. You should hear a simple 4 note ("E3", "B3", "G#3", "E4") sequence that will loop as long as you hold down the key on the keyboard.

{% hint style="info" %}
Patterns are polyphonic, and you can have up-to 128 pattern voices playing at the same time. Try holding down multiple keys on your midi keyboard.
{% endhint %}

The above code is a little verbose, and was written that way for example purposes only. Let's take it a step further and try not to repeat ourselves... We know that we want to trigger 4 different notes, but everything else stays the same i.e. the target we want to trigger (sampler) and the duration and gate values (4, 4).&#x20;

Let's improve the code just a bit...

```javascript
// main.js
// Arpeggiator
//
// Created by Jacob Sologub on 15 Jun 2020.
// Copyright © 2020 Jacob Sologub. All rights reserved.

const sampler = new sattern.Sampler();
sattern.graph.add (sampler);

const sound = new sattern.Sound ("./mcg_mp_064.wav", {
    lowKey: 0, highKey: 127, rootKey: 64
});
sampler.add (sound);

const pattern = new sattern.Pattern();
sattern.add (pattern);
pattern.onSequence = function (context) {
    return [64, 71, 68, 76].map (key => {
        return new sattern.Step ([sampler, new sattern.Note (key)], 4, 4)
    });
};
```

Ok, that looks much better. Let's move on to `Step`(s).

{% hint style="info" %}
Try replacing the keys array contents with `["E3", "B3", "G#3", "E4"]`. Keys can be expressed with strings e.g. "C1", "D#1", etc.
{% endhint %}
