tidal-1.9.5: Pattern language for improvised music
Safe HaskellSafe-Inferred
LanguageHaskell2010

Sound.Tidal.Core

Synopsis

Elemental patterns

sig :: (Time -> a) -> Pattern a Source #

Takes a function of time to values, and turns it into a Pattern. Useful for creating continuous patterns such as sine or perlin.

For example, saw is defined as

saw = sig $ \t -> mod' (fromRational t) 1

sine :: Fractional a => Pattern a Source #

sine - unipolar sinewave. A pattern of continuous values following a sinewave with frequency of one cycle, and amplitude from 0 to 1.

sine2 :: Fractional a => Pattern a Source #

sine2 - bipolar sinewave. A pattern of continuous values following a sinewave with frequency of one cycle, and amplitude from -1 to 1.

cosine :: Fractional a => Pattern a Source #

cosine - unipolar cosine wave. A pattern of continuous values following a cosine with frequency of one cycle, and amplitude from 0 to 1. Equivalent to 0.25 ~> sine.

cosine2 :: Fractional a => Pattern a Source #

cosine2 - bipolar cosine wave. A pattern of continuous values following a cosine with frequency of one cycle, and amplitude from -1 to 1. Equivalent to 0.25 ~> sine2.

saw :: (Fractional a, Real a) => Pattern a Source #

saw - unipolar ascending sawtooth wave. A pattern of continuous values following a sawtooth with frequency of one cycle, and amplitude from 0 to 1.

saw2 :: (Fractional a, Real a) => Pattern a Source #

saw2 - bipolar ascending sawtooth wave. A pattern of continuous values following a sawtooth with frequency of one cycle, and amplitude from -1 to 1.

isaw :: (Fractional a, Real a) => Pattern a Source #

isaw like saw, but a descending (inverse) sawtooth.

isaw2 :: (Fractional a, Real a) => Pattern a Source #

isaw2 like saw2, but a descending (inverse) sawtooth.

tri :: (Fractional a, Real a) => Pattern a Source #

tri - unipolar triangle wave. A pattern of continuous values following a triangle wave with frequency of one cycle, and amplitude from 0 to 1.

tri2 :: (Fractional a, Real a) => Pattern a Source #

tri2 - bipolar triangle wave. A pattern of continuous values following a triangle wave with frequency of one cycle, and amplitude from -1 to 1.

square :: Fractional a => Pattern a Source #

square - unipolar square wave. A pattern of continuous values following a square wave with frequency of one cycle, and amplitude from 0 to 1. | square is like sine, for square waves.

square2 :: Fractional a => Pattern a Source #

square2 - bipolar square wave. A pattern of continuous values following a square wave with frequency of one cycle, and amplitude from -1 to 1.

envL :: Pattern Double Source #

envL is a Pattern of continuous Double values, representing a linear interpolation between 0 and 1 during the first cycle, then staying constant at 1 for all following cycles. Possibly only useful if you're using something like the retrig function defined in tidal.el.

envLR :: Pattern Double Source #

like envL but reversed.

envEq :: Pattern Double Source #

'Equal power' version of env, for gain-based transitions

envEqR :: Pattern Double Source #

Equal power reversed

Pattern algebra

class Unionable a where Source #

Methods

union :: a -> a -> a Source #

Instances

Instances details
Unionable ValueMap Source # 
Instance details

Defined in Sound.Tidal.Core

Unionable a Source # 
Instance details

Defined in Sound.Tidal.Core

Methods

union :: a -> a -> a Source #

(|+|) :: (Applicative a, Num b) => a b -> a b -> a b Source #

(|+) :: Num a => Pattern a -> Pattern a -> Pattern a Source #

(+|) :: Num a => Pattern a -> Pattern a -> Pattern a Source #

(||+) :: Num a => Pattern a -> Pattern a -> Pattern a Source #

(|/|) :: (Applicative a, Fractional b) => a b -> a b -> a b Source #

(|*|) :: (Applicative a, Num b) => a b -> a b -> a b Source #

(|*) :: Num a => Pattern a -> Pattern a -> Pattern a Source #

(*|) :: Num a => Pattern a -> Pattern a -> Pattern a Source #

(||*) :: Num a => Pattern a -> Pattern a -> Pattern a Source #

(|-|) :: (Applicative a, Num b) => a b -> a b -> a b Source #

(|-) :: Num a => Pattern a -> Pattern a -> Pattern a Source #

(-|) :: Num a => Pattern a -> Pattern a -> Pattern a Source #

(||-) :: Num a => Pattern a -> Pattern a -> Pattern a Source #

(|%|) :: (Applicative a, Moddable b) => a b -> a b -> a b Source #

(|**|) :: (Applicative a, Floating b) => a b -> a b -> a b Source #

(|>|) :: (Applicative a, Unionable b) => a b -> a b -> a b Source #

(|<|) :: (Applicative a, Unionable b) => a b -> a b -> a b Source #

Constructing patterns

fromList :: [a] -> Pattern a Source #

Turns a list of values into a pattern, playing one of them per cycle. The following are equivalent:

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

fastFromList :: [a] -> Pattern a Source #

Turns a list of values into a pattern, playing all of them per cycle. The following are equivalent:

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

listToPat :: [a] -> Pattern a Source #

A synonym for fastFromList

fromMaybes :: [Maybe a] -> Pattern a Source #

'fromMaybes; is similar to fromList, but allows values to be optional using the Maybe type, so that Nothing results in gaps in the pattern. The following are equivalent: > d1 $ n (fromMaybes [Just 0, Nothing, Just 2]) # s "superpiano" > d1 $ n "0 ~ 2" # s "superpiano"

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

A pattern of whole numbers from 0 to the given number, in a single cycle. Can be used 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"

_run :: (Enum a, Num a) => a -> Pattern a Source #

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

Similar to run, but starts from 1 for the first cycle, successively adds a number until it gets up to n. > d1 $ n (scan 8) # sound "amencutup"

_scan :: (Enum a, Num a) => a -> Pattern a Source #

Combining patterns

append :: Pattern a -> Pattern a -> Pattern a Source #

Alternate between cycles of the two given patterns > d1 $ append (sound "bd*2 sn") (sound "arpy jvbass*2")

cat :: [Pattern a] -> Pattern a Source #

Like append, but for a list of patterns. Interlaces them, playing the first cycle from each in turn, then the second cycle from each, and so on. It 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"]

slowCat :: [Pattern a] -> Pattern a Source #

Alias for cat

slowAppend :: Pattern a -> Pattern a -> Pattern a Source #

Alias for append

fastAppend :: Pattern a -> Pattern a -> Pattern a Source #

Like append, but twice as fast > d1 $ fastAppend (sound "bd*2 sn") (sound "arpy jvbass*2")

fastCat :: [Pattern a] -> Pattern a Source #

The same as cat, but speeds up the result by the number of patterns there are, so the cycles from each are squashed 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"]

fastcat :: [Pattern a] -> Pattern a Source #

Alias for fastCat

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

Similar to fastCat, but each pattern is given a relative duration. 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)
             ]

timecat :: [(Time, Pattern a)] -> Pattern a Source #

Alias for timeCat

overlay :: Pattern a -> Pattern a -> Pattern a Source #

overlay combines two Patterns into a new pattern, so that their events are combined over time. For example, the following two lines are equivalent:

d1 $ sound (overlay "bd sn:2" "cp*3")
d1 $ sound "[bd sn:2, cp*3]"

overlay is equal to <>,

(<>) :: Semigroup a => a -> a -> a

which can thus be used as an infix operator equivalent of overlay:

d1 $ sound ("bd sn:2" <> "cp*3")

stack :: [Pattern a] -> Pattern a Source #

stack combines a list of Patterns into a new pattern, so that their events are combined over time, i.e., all of the patterns in the list are played simultaneously.

d1 $ stack [
 sound "bd bd*2",
 sound "hh*2 [sn cp] cp future*4",
 sound "arpy" +| n "0 .. 15"
]

This is particularly useful if you want to apply a function or synth control pattern to multiple patterns at once:

d1 $ whenmod 5 3 (striate 3) $ stack [
 sound "bd bd*2",
 sound "hh*2 [sn cp] cp future*4",
 sound "arpy" +| n "0 .. 15"
] # speed "[[1 0.8], [1.5 2]*2]/3"

Manipulating time

(<~) :: Pattern Time -> Pattern a -> Pattern a Source #

Shifts a pattern back in time by the given amount, expressed in cycles

(~>) :: Pattern Time -> Pattern a -> Pattern a Source #

Shifts a pattern forward in time by the given amount, expressed in cycles

slowSqueeze :: Pattern Time -> Pattern a -> Pattern a Source #

Slow down a pattern by the factors in the given time pattern, "squeezing" the pattern to fit the slot given in the time pattern. It is the slow analogue to fastSqueeze.

If the time pattern only has a single value in a cycle, slowSqueeze becomes equivalent to slow. These are equivalent:

d1 $ slow "<2 4>" $ s "bd*8"
d1 $ slowSqueeze "<2 4>" $ s "bd*8"

When the time pattern has multiple values, however, the behavior is a little different. Instead, a slowed version of the pattern will be made for each value in the time pattern, and they’re all combined together in a cycle according to the structure of the time pattern. For example, these are equivalent:

d1 $ slowSqueeze "2 4 8 16" $ s "bd*8"
d1 $ s "bd*4 bd*2 bd bd/2"

as are these:

d1 $ slowSqueeze "2 4 [8 16]" $ s "bd*8"
d1 $ s "bd*4 bd*2 [bd bd/2]"

sparsity :: Pattern Time -> Pattern a -> Pattern a Source #

An alias for slow

zoom :: (Time, Time) -> Pattern a -> Pattern a Source #

Plays a portion of a pattern, specified by a time arc (start and end time). The new resulting pattern is played over the time period of the original pattern.

d1 $ zoom (0.25, 0.75) $ sound "bd*2 hh*3 [sn bd]*2 drum"

In the pattern above, zoom is used with an arc from 25% to 75%. It is equivalent to:

d1 $ sound "hh*3 [sn bd]*2"

Here’s an example of it being used with a conditional:

d1 $ every 4 (zoom (0.25, 0.75)) $ sound "bd*2 hh*3 [sn bd]*2 drum"

fastGap :: Pattern Time -> Pattern a -> Pattern a Source #

fastGap is similar to fast but maintains its cyclic alignment, i.e., rather than playing the pattern multiple times, it instead leaves a gap in the remaining space of the cycle. For example, fastGap 2 p would squash the events in pattern p into the first half of each cycle (and the second halves would be empty). The factor should be at least 1.

densityGap :: Pattern Time -> Pattern a -> Pattern a Source #

An alias for fastGap

compress :: (Time, Time) -> Pattern a -> Pattern a Source #

compress takes a pattern and squeezes it within the specified time span (i.e. the ‘arc’). The new resulting pattern is a sped up version of the original.

d1 $ compress (1/4, 3/4) $ s "[bd sn]!"

In the above example, the pattern will play in an arc spanning from 25% to 75% of the duration of a cycle. It is equivalent to:

d1 $ s "~ [bd sn]! ~"

Another example, where all events are different:

d1 $ compress (1/4, 3/4) $ n (run 4) # s "arpy"

It differs from zoom in that it preserves the original pattern but it speeds up its events so to match with the new time period.

every :: Pattern Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a Source #

  • Higher order functions

Functions which work on other functions (higher order functions)

every n f p applies the function f to p, but only affects every n cycles.

It takes three inputs: how often the function should be applied (e.g. 3 to apply it every 3 cycles), the function to be applied, and the pattern you are applying it to. For example: to reverse a pattern every three cycles (and for the other two play it normally)

d1 $ every 3 rev $ n "0 1 [~ 2] 3" # sound "arpy"

Note that if the function you’re applying requires additional parameters itself (such as fast 2 to make a pattern twice as fast), then you’ll need to wrap it in parenthesis, like so:

d1 $ every 3 (fast 2) $ n "0 1 [~ 2] 3" # sound "arpy"

Otherwise, the every function will think it is being passed too many parameters.

_every :: Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a Source #

every' :: Pattern Int -> Pattern Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a Source #

every' n o f p is like every n f p but with an offset of o cycles.

For example, every' 3 0 (fast 2) will speed up the cycle on cycles 0,3,6,… whereas every' 3 1 (fast 2) will transform the pattern on cycles 1,4,7,….

With this in mind, setting the second argument of every' to 0 gives the equivalent every function. For example, every 3 is equivalent to every' 3 0.

The every functions can be used to silence a full cycle or part of a cycle by using silent or mask "~". Mask provides additional flexibility to turn on/off individual steps.

d1 $ every 3 silent $ n "2 9 11 2" # s "hh27"
d1 $ every 3 (mask "~") $ n "2 9 10 2" # s "hh27"
d1 $ every 3 (mask "0 0 0 0") $ n "2 9 11 2" # s "hh27"

_every' :: Int -> Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a Source #

foldEvery :: [Int] -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a Source #

foldEvery ns f p applies the function f to p, and is applied for each cycle in ns.

It is similar to chaining multiple every functions together. It transforms a pattern with a function, once per any of the given number of cycles. If a particular cycle is the start of more than one of the given cycle periods, then it it applied more than once.

d1 $ foldEvery [5,3] (|+ n 1) $ s "moog" # legato 1

The first moog samples are tuned to C2, C3 and C4. Note how on cycles that are multiples of 3 or 5 the pitch is an octave higher, and on multiples of 15 the pitch is two octaves higher, as the transformation is applied twice.

when :: (Int -> Bool) -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a Source #

The given pattern transformation is applied only when the given test function returns True. The test function will be called with the current cycle as a number.

d1 $ when (elem '4' . show)
          (striate 4)
   $ sound "hh hc"

The above will only apply striate 4 to the pattern if the current cycle number contains the number 4. So the fourth cycle will be striated and the fourteenth and so on. Expect lots of striates after cycle number 399.

whenT :: (Time -> Bool) -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a Source #

Like when, but works on continuous time values rather than cycle numbers. The following will apply # speed 2 only when the remainder of the current Time divided by 2 is less than 0.5:

d1 $ whenT ((< 0.5) . (flip Data.Fixed.mod' 2))
           (# speed 2)
   $ sound "hh(4,8) hc(3,8)"

_getP :: a -> (Value -> Maybe a) -> Pattern Value -> Pattern a Source #

_cX :: a -> (Value -> Maybe a) -> String -> Pattern a Source #

_cX_ :: (Value -> Maybe a) -> String -> Pattern a Source #