# Continuous Signals

Signals are patterns with continuous values, meaning they have theoretically infinite steps. They can provide streams of numbers that can be sampled at discrete points in time.

## saw

A sawtooth signal between 0 and 1.

note("<c3 [eb3,g3] g2 [g3,bb3]>*8") .clip(saw.slow(2))

n(saw.range(0,8).segment(8)) .scale('C major')

## sine

A sine signal between 0 and 1.

n(sine.segment(16).range(0,15)) .scale("C:minor")

## cosine

A cosine signal between 0 and 1.

n(stack(sine,cosine).segment(16).range(0,15)) .scale("C:minor")

## tri

A triangle signal between 0 and 1.

n(tri.segment(8).range(0,7)).scale("C:minor")

## square

A square signal between 0 and 1.

n(square.segment(4).range(0,7)).scale("C:minor")

## Ranges from -1 to 1

There is also `saw2`

, `sine2`

, `cosine2`

, `tri2`

and `square2`

which have a range from -1 to 1!

## rand

A continuous pattern of random numbers, between 0 and 1.

// randomly change the cutoff s("bd*4,hh*8").cutoff(rand.range(500,8000))

## perlin

Generates a continuous pattern of perlin noise, in the range 0..1.

// randomly change the cutoff s("bd*4,hh*8").cutoff(perlin.range(500,8000))

## irand

A continuous pattern of random integers, between 0 and n-1.

- n (number): max value (exclusive)

// randomly select scale notes from 0 - 7 (= C to C) n(irand(8)).struct("x x*2 x x*3").scale("C:minor")

# Random Modifiers

These methods add random behavior to your Patterns.

## chooseCycles

Picks one of the elements at random each cycle.

chooseCycles("bd", "hh", "sd").s().fast(8)

s("bd | hh | sd").fast(8)

## degradeBy

Randomly removes events from the pattern by a given amount. 0 = 0% chance of removal 1 = 100% chance of removal

- amount (number): a number between 0 and 1

s("hh*8").degradeBy(0.2)

s("[hh?0.2]*8")

## degrade

Randomly removes 50% of events from the pattern. Shorthand for `.degradeBy(0.5)`

s("hh*8").degrade()

s("[hh?]*8")

## undegradeBy

Inverse of `degradeBy`

: Randomly removes events from the pattern by a given amount.
0 = 100% chance of removal
1 = 0% chance of removal
Events that would be removed by degradeBy are let through by undegradeBy and vice versa (see second example).

- amount (number): a number between 0 and 1

s("hh*8").undegradeBy(0.2)

## sometimesBy

Randomly applies the given function by the given probability.
Similar to `someCyclesBy`

- probability (number|Pattern): a number between 0 and 1
- function (function): the transformation to apply

s("hh*8").sometimesBy(.4, x=>x.speed("0.5"))

## sometimes

Applies the given function with a 50% chance

- function (function): the transformation to apply

s("hh*8").sometimes(x=>x.speed("0.5"))

## someCyclesBy

Randomly applies the given function by the given probability on a cycle by cycle basis.
Similar to `sometimesBy`

- probability (number|Pattern): a number between 0 and 1
- function (function): the transformation to apply

s("bd,hh*8").someCyclesBy(.3, x=>x.speed("0.5"))

## someCycles

Shorthand for `.someCyclesBy(0.5, fn)`

s("bd,hh*8").someCycles(x=>x.speed("0.5"))

## often

Shorthand for `.sometimesBy(0.75, fn)`

s("hh*8").often(x=>x.speed("0.5"))

## rarely

Shorthand for `.sometimesBy(0.25, fn)`

s("hh*8").rarely(x=>x.speed("0.5"))

## almostNever

Shorthand for `.sometimesBy(0.1, fn)`

s("hh*8").almostNever(x=>x.speed("0.5"))

## almostAlways

Shorthand for `.sometimesBy(0.9, fn)`

s("hh*8").almostAlways(x=>x.speed("0.5"))

## never

Shorthand for `.sometimesBy(0, fn)`

(never calls fn)

s("hh*8").never(x=>x.speed("0.5"))

## always

Shorthand for `.sometimesBy(1, fn)`

(always calls fn)

s("hh*8").always(x=>x.speed("0.5"))

Next up: Conditional Modifiers