From TidalCycles userbase
Revision as of 00:15, 25 December 2020 by Left adjoint (talk | contribs) (Created page with "{{DISPLAYTITLE:contrast}} Type: <source inline>contrast :: (ControlPattern -> ControlPattern) -> (ControlPattern -> ControlPattern) -> ControlPattern -> Co...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Type: contrast :: (ControlPattern -> ControlPattern) -> (ControlPattern -> ControlPattern) -> ControlPattern -> ControlPattern -> ControlPattern

contrast is like a if-else-statement over patterns. For contrast f g p you can think of f as the true-branch, g as the false branch, and p as the test.

For contrast, you can use any control pattern as a test of equality: n "<0 1>", speed "0.5", or things like that. This lets you choose specific properties of the pattern you're transforming for testing, like in the following example

  d1 $ contrast (|+ n 12) (|- n 12) (n "c") $ n (run 4) # s "superpiano"

where every note that isn't middle-c will be shifted down an octave but middle-c will be shifted up to c5.

Since the test given to contrast is also a pattern, you can do things like have it alternate between options

d1 $ contrast (|+ n 12) (|- n 12) (s "<superpiano superchip>") $ s "superpiano superchip" # n 0

If you listen to this you'll hear that which instrument is shifted up and which instrument is shifted down alternates between cycles.


Type: fix :: (ControlPattern -> ControlPattern) -> ControlPattern -> ControlPattern -> ControlPattern

fix is contrast where the false branch is replaced with the identity function id. fix will only apply the transformation on a match with the testing pattern.


Type: unfix :: (ControlPattern -> ControlPattern) -> ControlPattern -> ControlPattern -> ControlPattern

unfix is contrast where the true branch is replaced with the identity function id. unfix will apply the transformation whenever there is not a match with the testing pattern.