:: Pattern a -> Pattern a package:tidal

Splits queries that span cycles. For example `query p (0.5, 1.5)` would be turned into two queries, `(0.5,1)` and `(1,1.5)`, and the results combined. Being able to assume queries don't span cycles often makes transformations easier to specify.
rev p returns p with the event positions in each cycle reversed (or mirrored). For example rev "1 [~ 2] ~ 3" is equivalent to rev "3 ~ [2 ~] 1". Note that rev reverses on a cycle-by-cycle basis. This means that rev (slow 2 "1 2 3 4") would actually result in (slow 2 "2 1 4 3"). This is because the slow 2 makes the repeating pattern last two cycles, each of which is reversed independently. In practice rev is generally used with conditionals, for example with every:
d1 $ every 3 rev $ n "0 1 [~ 2] 3" # sound "arpy"
or jux:
d1 $ jux rev $ n (iter 4 "0 1 [~ 2] 3") # sound "arpy"
Serialises a pattern so there's only one event playing at any one time, making it monophonic. Events which start/end earlier are given priority.
degrade randomly removes events from a pattern 50% of the time:
d1 $ slow 2 $ degrade $ sound "[[[feel:5*8,feel*3] feel:3*8], feel*4]"
# accelerate "-6"
# speed "2"
The shorthand syntax for degrade is a question mark: ?. Using ? will allow you to randomly remove events from a portion of a pattern:
d1 $ slow 2 $ sound "bd ~ sn bd ~ bd? [sn bd?] ~"
You can also use ? to randomly remove events from entire sub-patterns:
d1 $ slow 2 $ sound "[[[feel:5*8,feel*3] feel:3*8]?, feel*4]"
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 $ sound (brak "bd sn kurt")
d1 $ brak $ sound "[feel feel:3, hc:3 hc:2 hc:4 ho:1]"
palindrome p applies rev to p every other cycle, so that the pattern alternates between forwards and backwards. For example, these are equivalent:
d1 $ palindrome $ sound "arpy:0 arpy:1 arpy:2 arpy:3"
d1 $ slow 2 $ sound "arpy:0 arpy:1 arpy:2 arpy:3 arpy:3 arpy:2 arpy:1 arpy:0"
d1 $ every 2 rev $ sound "arpy:0 arpy:1 arpy:2 arpy:3"
stretch takes a pattern, and if there’s silences at the start or end of the current cycle, it will zoom in to avoid them. The following are equivalent:
d1 $ note (stretch "~ 0 1 5 8*4 ~") # s "superpiano"
d1 $ note "0 1 5 8*4" # s "superpiano"
You can pattern silences on the extremes of a cycle to make changes to the rhythm:
d1 $ note (stretch "~ <0 ~> 1 5 8*4 ~") # s "superpiano"
Takes a pattern and loops only the first cycle of the pattern. For example, the following code will only play the bass drum sample:
d1 $ loopFirst $ s "<<bd*4 ht*8> cp*4>"
This function combines with sometimes to insert events from the first cycle randomly into subsequent cycles of the pattern:
d1 $ sometimes loopFirst $ s "<<bd*4 ht*8> cp*4>"
arpeggiate finds events that share the same timespan, and spreads them out during that timespan, so for example arpeggiate "[bd,sn]" gets turned into "bd sn". Useful for creating arpeggios/broken chords.
Shorthand alias for arpeggiate
rolled plays each note of a chord quickly in order, as opposed to simultaneously; to give a chord a harp-like or strum effect. Notes are played low to high, and are evenly distributed within (14) of the chord event length, as opposed to arparpeggiate that spread the notes over the whole event.
rolled $ n "cmaj4" # s "superpiano"
rolled = rolledBy (1/4)
Syncopates a rhythm, shifting (delaying) each event halfway into its arc (timespan). In mini-notation terms, it basically turns every instance of a into [~ a], e.g., "a b [c d] e" becomes the equivalent of "[~ a] [~ b] [[~ c] [~ d]] [~ e]". Every beat then becomes an offbeat, and so the overall effect is to syncopate a pattern. In the following example, you can hear that the piano chords play between the snare and the bass drum. In 4/4 time, they are playing in the 2 and a half, and 4 and a half beats:
do
resetCycles
d1 $ stack [
press $ n "~ c'maj ~ c'maj" # s "superpiano" # gain 0.9 # pan 0.6,
s "[bd,clap sd bd sd]" # pan 0.4
] # cps (90/60/4)
In the next example, the C major chord plays before the G major. As the slot that occupies the C chord is that of one eighth note, it is displaced by press only a sixteenth note:
do
resetCycles
d1 $ stack [
press $ n "~ [c'maj ~] ~ ~" # s "superpiano" # gain 0.9 # pan 0.6,
press $ n "~ g'maj ~ ~" # s "superpiano" # gain 0.9 # pan 0.4,
s "[bd,clap sd bd sd]"
] # cps (90/60/4)
Align the start of a pattern with the time a pattern is evaluated, rather than the global start time. Because of this, the pattern will probably not be aligned to the pattern grid.
(Alias qt) Quantise trigger. Aligns the start of the pattern with the next cycle boundary. For example, this pattern will fade in starting with the next cycle after the pattern is evaluated:
d1 $ qtrigger $ s "hh(5, 8)" # amp envL
Note that the pattern will start playing immediately. The start of the pattern aligns with the next cycle boundary, but events will play before if the pattern has events at negative timestamps (which most loops do). These events can be filtered out, for example:
d1 $ qtrigger $ filterWhen (>= 0) $ s "hh(5, 8)"
Alternatively, you can use wait to achieve the same result:
wait 1 1 $ s "bd hh hh hh"
Alias for qtrigger.
Ceiling trigger. Aligns the start of a pattern to the next cycle boundary, just like qtrigger.
Rounded trigger. Aligns the start of a pattern to the nearest cycle boundary, either next or previous.
Floor trigger. Aligns the start of a pattern to the previous cycle boundary.
Turns a pattern of seconds into a pattern of (rational) cycle durations
smooth receives a pattern of numbers and linearly goes from one to the next, passing through all of them. As time is cycle-based, after reaching the last number in the pattern, it will smoothly go to the first one again.
d1 $ sound "bd*4" # pan (slow 4 $ smooth "0 1 0.5 1")
This sound will pan gradually from left to right, then to the center, then to the right again, and finally comes back to the left.
Turns a pattern of milliseconds into a pattern of (rational) cycle durations, according to the current cps.
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"