Skip to main content

Concatenation

This page will present you all the functions that can be used to concatenate (e.g. add) things together in various ways. 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.

Many cats

cat

Type: cat :: [Pattern a] -> Pattern a

cat, (also known as slowcat, to match with fastcat defined below) concatenates a list of patterns into a new pattern; each pattern in the list will maintain its original duration. For example:

d1 $ cat [sound "bd*2 sn", sound "arpy jvbass*2"]

d1 $ cat [sound "bd*2 sn", sound "arpy jvbass*2", sound "drum*2"]

d1 $ cat [sound "bd*2 sn", sound "jvbass*3", sound "drum*2", sound "ht mt"]
caution

There is also a slowcat function, perfectly similar to cat. This function exists as a mirror of fastcat.

fastcat

Type: fastcat :: [Pattern a] -> Pattern a

fastcat works like cat above, but squashes all the patterns to fit a single cycle.

d1 $ fastcat [sound "bd*2 sn", sound "arpy jvbass*2"]

d1 $ fastcat [sound "bd*2 sn", sound "arpy jvbass*2", sound "drum*2"]

d1 $ fastcat [sound "bd*2 sn", sound "jvbass*3", sound "drum*2", sound "ht mt"]

timeCat

Type: timeCat :: [(Time, Pattern a)] -> Pattern a

timeCat is like fastcat except that you provide proportionate sizes of the patterns to each other for when they're concatenated into one cycle. The larger the value in the list, the larger relative size the pattern takes in the final loop. If all values are equal then this is equivalent to fastcat (e.g. the following two code fragments are equivalent).

d1 $ fastcat [s "bd*4", s "hh27*8", s "superpiano" # n 0]

d1 $ timeCat [(1, s "bd*4"),
(1, s "hh27*8"),
(1, s "superpiano" # n 0)]

randcat

Type: randcat :: [Pattern a] -> Pattern a

randcat is similar to cat, but rather than playing the given patterns in order, it picks them at random. For example:

d1 $ randcat [sound "bd*2 sn", sound "jvbass*3", sound "drum*2", sound "ht mt"]

Or the more compact, equivalent, version:

d1 $ sound (randcat ["bd*2 sn", "jvbass*3", "drum*2", "ht mt"])

wrandcat

Type: wrandcat :: [(Pattern a, Double)] -> Pattern a

This is a variation of randcat where you can give each pattern in the list a relative probability:

d1 $ sound (
wrandcat [
("bd*2 sn", 5), ("jvbass*3", 2), ("drum*2", 2), ("ht mt", 1)
]
)

Here, the first pattern is the most likely and will play about half the times, and the last pattern is the less likely, with only a 10% probability.

Append family

append

Type: append :: Pattern a -> Pattern a -> Pattern a

append combines two patterns into a new pattern, where cycles alternate between the first and second pattern:

d1 $ append (sound "bd*2 sn") (sound "arpy jvbass*2")

It has the alias slowAppend, in sympathy with fastAppend, described below.

fastAppend

Type: fastAppend :: Pattern a -> Pattern a -> Pattern a

fastAppend works like append described above, but each pair of cycles from the two patterns are squashed to fit a single cycle.

d1 $ fastAppend (sound "bd*2 sn") (sound "arpy jvbass*2")

wedge

Type: wedge :: Time -> Pattern a -> Pattern a -> Pattern a

wedge combines two patterns by squashing them into a single cycle. It takes a ratio as the first argument. The ratio determines what percentage of the pattern cycle is taken up by the first pattern. The second pattern fills in the remainder of the pattern cycle. For example:

d1 $ wedge (1/4) (sound "bd*2 arpy*3 cp sn*2") (sound "odx [feel future]*2 hh hh")

brak

Type: brak :: Pattern a -> Pattern a

brak makes a pattern sound a bit like a breakbeat. It does this by every other cycle, squashing the pattern to fit half a cycle, and offsetting it by a quarter of a cycle.

d1 $ brak $ sound "[feel feel:3, hc:3 hc:2 hc:4 ho:1]"

listToPat

Type: listToPat :: [a] -> Pattern a

listToPat takes a list of things and turns them into a pattern where each item in the list becomes an event all happening in the same cycle, looping upon subsequent cycles. Can also be called as fastFromList

d1 $ n (listToPat [0, 1, 2]) # s "superpiano"

is equivalent to

d1 $ n "[0 1 2]" # s "superpiano"

fromList

fromList takes a list of things and turns them into a pattern where each item in the list has a duration of one cycle, looping back around at the end of the list.

d1 $ n (fromList [0, 1, 2]) # s "superpiano"

is equivalent to

d1 $ n "<0 1 2>" # s "superpiano"

fromMaybes

Type: fromMaybes :: [Maybe a] -> Pattern a

fromMaybes is much like listToPat but when it encounters a Nothing it puts a gap in the pattern and when it encounters Just x puts x in the pattern.

d1 $ n (fromMaybes [Just 0, Nothing, Just 2]) # s "superpiano"

is equivalent to

d1 $ n "0 ~ 2" # s "superpiano"

flatpat

Type: flatpat :: Pattern [a] -> Pattern a

flatpat takes a pattern of lists and flattens it into a pattern where all the events in each list happen simultaneously. For example, the following code uses flatpat in combination with listToPat to create an alternating pattern of chords.

d1 $ n (flatpat $ listToPat [[0,4,7],[(-12),(-8),(-5)]]) # s "superpiano" # sustain 2

This code is equivalent to:

d1 $ n ("[0,4,7] [-12,-8,-5]") # s "superpiano" # sustain 2

run

Type: run :: (Num a, Enum a) => Pattern a -> Pattern a

The run function generates a pattern representing a cycle of numbers from 0 to n-1 inclusive. Notably used to run through a folder of samples in order:

d1 $ n (run 8) # sound "amencutup"

The first parameter to run can be given as a pattern:

d1 $ n (run "<4 8 4 6>") # sound "amencutup"

scan

Type: scan :: (Num a, Enum a) => Pattern a -> Pattern a

scan is similar to run, but starts at 1 for the first cycle, adding an additional number each cycle until it reaches n:

d1 $ n (scan 8) # sound "amencutup"