# Alteration

This page will present you all the functions that can be used to manipulate and alter your patterns. Each function will be presented following the same model:

**Type signature**: how the function is declared on the**Haskell**side.**Description**: verbal description of the function.**Examples**: a small list of examples that you can copy/paste in your editor.

## #

Scaling### #

range`range`

will take a pattern which goes from `0`

to `1`

(such as `sine`

), and scale it to a different range - between the first and second arguments. In the below example, `range 1 1.5`

shifts the range of sine from `0 - 1`

to `1 - 1.5`

.

The above is equivalent to the following:

### #

rangex`rangex`

is an exponential version of `range`

described above, good to use for frequencies. For example, `range 20 2000 "0.5"`

will give `1010`

- halfway between `20`

and `2000`

. But `rangex 20 2000 0.5`

will give `200`

- halfway between on a logarithmic scale. This usually sounds better if youâ€™re using the numbers as pitch frequencies. Since rangex uses logarithms, donâ€™t try to scale things to zero or less!

### #

quantise`quantise`

is useful for rounding a collection of numbers to some particular base fraction. For example,

It will round all the values to the nearest `(1/5)=0.2`

and thus will output the list `[0.0,1.2,2.6,3.2,4.8,5.0]`

. You can use this function to force a continuous pattern like sine into specific values. In the following example:

all the releases selected be rounded to the nearest `0.1`

and the notes selected to the nearest `1`

.

`quantise`

with fractional inputs does the consistent thing: `quantise 0.5`

rounds values to the nearest `2`

, `quantise 0.25`

rounds the nearest `4`

, etc...

## #

Degrade### #

degrade`degrade`

randomly removes events from a pattern, `50%`

of the time. Example usage:

### #

degradeBySimilarly to `degrade`

, `degradeBy`

allows you to control the percentage of events that are removed. For example, to remove events `90%`

of the time:

### #

unDegradeBy`unDegradeBy`

is `degradeBy`

but with the percentage describing how many events to keep on average not remove.

## #

Repetitions### #

plyThe `ply`

function repeats each event the given number of times. For example:

... is equivalent to ...

The first parameter may be given as a pattern, so that:

... is equivalent to ...

Here is an example of it being used conditionally:

### #

stutter`stutter`

is like `stut`

that doesn't reduce the volume or `ply`

if you controlled the timing. `stutter n t`

repeats each event in the pattern `n`

times, separated by `t`

time (in fractions of a cycle).

should be functionally equivalent to

Specific conveniences functions that use stutter are:

### #

stripeThe `stripe`

function repeats a pattern at random speeds. The first parameter gives the number of cycles to operate over, for example `stripe 2`

will repeat a pattern twice, over two cycles. Each cycle will be played at a random speed, but in such a way that the total duration will be the same.

For example in the following example, the start of every third repetition of the `d1`

pattern will match with the clap on the d2 pattern.

### #

slowstripeThe `slowstripe`

function is the same as `stripe`

but the result is also slowed down by `n`

time (where `n`

is the first parameter of the function. This means that the mean average duration of the stripes is exactly one cycle, and every nth stripe starts on a cycle boundary (in indian classical terms, the sam). Usage:

### #

palindromeThe `palindrome`

function applies `rev`

to a pattern every other cycle, so that the pattern alternates between forwards and backwards. For example this:

... is the same as this:

... and indeed this:

## #

Truncation### #

trunc`trunc`

truncates a pattern so that only a fraction of the pattern is played. The following example plays only the first three quarters of the pattern:

You can also pattern the first parameter, for example to cycle through three values, one per cycle:

### #

linger`linger`

is similar to `trunc`

, in that it truncates a pattern so that only the first fraction of the pattern is played. However unlike trunc, `linger`

repeats that part to fill the remainder of the cycle.

For example this repeats the first quarter, so you only hear a single repeating note:

or slightly more interesting, applied only every fourth cycle:

or to a chopped-up sample:

You can also pattern the first parameter, for example to cycle through three values, one per cycle:

### #

chunk`chunk`

divides a pattern into a given number of parts, then cycles through those parts in turn, applying the given function to each part in turn (one part per cycle). Example:

The below highlights in uppercase which part of the above pattern has the (# speed 2) function applied to it over four cycles:

Another example:

### #

chunk'`chunk'`

does the same as chunk but cycles through the parts in the reverse direction.

### #

loopFirst`loopFirst`

is a function that takes a pattern and loops only the first cycle of the pattern. For example, in the following code will only play the bass drum sample.

This function combines with sometimes to insert events from the first cycle randomly into subsequent cycles of the pattern:

### #

runWithOld name for `chunk`

.

### #

runWith'Old name for `chunk'`

?

## #

Shuffling and scrambling### #

biteThe `bite`

function allows you to slice each cycle into a given number of equal sized bits, and then pattern those bits by number. It's similar to `slice`

, but is for slicing up patterns, rather than samples. The following slices the pattern into four bits, and then plays those bits in turn.

Of course that doesn't actually change anything, but then you can reorder those bits:

The slices bits of pattern will be squeezed or contracted to fit:

### #

shuffle`shuffle`

takes a number and a pattern as input, divides the pattern into the given number of parts, and returns a new pattern as a random permutation of the parts, picking one of each per cycle. This could also be called "sampling without replacement". For example:

... will sometimes play `"sn bd hh"`

or `"hh sn bd"`

, but will never play `"bd sn bd"`

or `"hh hh hh"`

, because that isn't a permutation of the three parts.

### #

scramble`scramble`

takes a number and a pattern as input, divides the pattern into the given number of parts, and returns a new pattern by randomly selecting from the parts. This could also be called "sampling with replacement". For example:

... will sometimes play `"sn bd hh"`

or `"hh sn bd"`

, but can also play `"bd sn bd"`

or `"hh hh hh"`

, because it can make any random combination of the three parts.

### #

rotThe `rot`

function 'rotates' the values in a pattern, while preserving its structure. For example in the following, each value will shift to its neighbour's position one step to the left, so that `b`

takes the place of `a`

, `a`

of `c`

, and `c`

of `b`

:

The result is equivalent of:

The first parameter is the number of steps, and may be given as a pattern, for example:

The above will not rotate the pattern for the first two cycles, will rotate it by one the third cycle, and by three the fourth cycle.

## #

Step sequencers### #

step`step`

acts as a kind of simple step-sequencer using strings. For example, `step "sn" "x x 12 "`

is equivalent to the pattern of strings given by `"sn ~ sn ~ sn:1 sn:2 ~"`

. `step`

substitutes the given string for each x, for each number it substitutes the string followed by a colon and the number, and for everything else it puts in a rest.

In other words, `step`

generates a pattern of strings in exactly the syntax you'd want for selecting samples and that can be fed directly into the s function.

### #

step'`step' `

is like `step`

but more general, using the numbers in the step-sequencing string as indexes into the list of strings you give it.

is equivalent to

##### tip

There is also `steps`

. You can take a look at this function in the `Accumulation`

section

### #

lindenmayer`lindenmayer`

takes an integer `b`

, a Lindenmayer system rule set and an initiating string as input in order to generate an L-system tree string of `b`

iterations. It can be used in conjunction with a step function to convert the generated string into a playable pattern. For example:

... generates an L-system with initiating string "0" and maps it onto a list of samples.

Complex L-system trees with many rules and iterations can sometimes result in unwieldy strings. Using `take n`

to only use the first `n`

elements of the string, along with a `slow`

function, can make the generated values more manageable.

## #

Higher-order### #

spreadThe `spread`

function allows you to take a pattern transformation which takes a parameter, such as `slow`

, and provide several parameters which are switched between. In other words it 'spreads' a function across several values. Taking a simple high hat loop as an example:

We can speed it up by different amounts, such as by 2x:

Or by 3x:

But if we use `spread`

, we can make a pattern which alternates between the two speeds:

Note that many functions now allow pattern input. This is equivalent to the above:

Note that if you pass (`$`

) as the function to spread values over, you can put different functions as the list of values. For example:

Above, the pattern will have these transforms applied to it, one at a time, per cycle:

After `(# speed "0.8")`

, the transforms will repeat and start at `density 2`

again.

(This is the same as `slowspread`

in earlier versions of TidalCycles.)

### #

spreadfA convenient shorthand for spread (`$`

).

### #

fastspread`fastspread`

works the same as `spread`

, but the result is squashed into a single cycle. If you gave four values to `spread`

, then the result would seem to speed up by a factor of four. Compare these two:

### #

spreadChoose`spreadChoose`

(alias `spreadr`

) works the same as spread, but the values are selected at random, one cycle at a time. For example: