Difference between revisions of "contrast"

From TidalCycles userbase
Jump to: navigation, search
(Created page with "{{DISPLAYTITLE:contrast}} Type: <source inline>contrast :: (ControlPattern -> ControlPattern) -> (ControlPattern -> ControlPattern) -> ControlPattern -> Co...")
 
 
Line 20: Line 20:
 
If you listen to this you'll hear that which instrument is shifted up and which instrument is shifted down alternates between cycles.
 
If you listen to this you'll hear that which instrument is shifted up and which instrument is shifted down alternates between cycles.
  
= fix =
+
'''See also: [[fix]],[[unfix]]'''
[[Type signature|Type]]: <source inline>fix :: (ControlPattern -> ControlPattern) -> ControlPattern -> ControlPattern -> ControlPattern</source>
 
 
 
<source inline> fix </source> is contrast where the ''false'' branch is replaced with the identity function <source inline>id</source>. <source inline>fix</source> will only apply the transformation on a match with the testing pattern.
 
 
 
= unfix =
 
[[Type signature|Type]]: <source inline>unfix :: (ControlPattern -> ControlPattern) -> ControlPattern -> ControlPattern -> ControlPattern</source>
 
 
 
<source inline> unfix </source> is contrast where the ''true'' branch is replaced with the identity function <source inline> id</source>. <source inline>unfix</source> will apply the transformation whenever there is ''not'' a match with the testing pattern.
 
 
 
 
[[Category:Functions]]
 
[[Category:Functions]]

Latest revision as of 23:17, 24 December 2020

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.

See also: fix,unfix