1--- 2title: Control Parameters 3layout: ../../layouts/MainLayout.astro 4--- 5 6import { MiniRepl } from '../../docs/MiniRepl'; 7import { JsDoc } from '../../docs/JsDoc'; 8 9# Control Parameters 10 11Besides functions that control time, we saw earlier that functions like `note` and `cutoff` control different parameters (short params) of an event. 12Let's now look more closely at how these `param(eter) functions` work. 13 14# Parameter Functions 15 16A very powerful feature of tidal patterns is that each parameter can be controlled independently: 17 18<MiniRepl 19 client:only="react" 20 tune={`note("c a f e") 21.cutoff("<500 1000 2000 [4000 8000]>") 22.gain(.8) 23.s('sawtooth') 24.log()`} 25/> 26 27In this example, the parameters `note`, `cutoff`, `gain` and `s` are controlled independently by either patterns or plain values (numbers / text). 28After pressing play, we can observe the time and parameter values of each event (hap) in the output created by `.log()`. 29 30## Plain vs Parameterized Values 31 32Patterns that are not wrapped inside a param function will contain unlabeled `plain values`: 33 34<MiniRepl client:only="react" tune={`"<c e g>".log()`} /> 35 36This will not generate any sound output, because Strudel could only guess which param is meant by these letters. 37 38Now compare that to the version wrapped in `note`: 39 40<MiniRepl client:only="react" tune={`note("<c e g>").log()`} /> 41 42Now it is clear that these letters are meant to be played as notes. 43Under the hood, the `note` function (as well as all other param functions) 44will wrap each plain value in an object. If the note function did not exist, we would need to write: 45 46<MiniRepl client:only="react" tune={`cat({note:'c'},{note:'e'},{note:'g'}).log()`} /> 47 48This will have the same output, though it is rather unwieldy to read and write. 49 50## Wrapping Parameter Functions 51 52To avoid too much nesting, param functions can also be chained like this: 53 54<MiniRepl client:only="react" tune={`cat('c', 'e', 'g').note().log()`} /> 55 56This is equivalent to `note(cat('c','e','g')).log()`. 57 58You can use this with any function that declares a type (like `n`, `s`, `note`, `freq` etc), just make sure to leave the parens empty! 59 60## Plain Value Modification 61 62Patterns of plain values can be modified with any of the following operators: 63 64<MiniRepl client:only="react" tune={`"50 60 70".add("<0 1 2>").log()`} /> 65 66Here, the add function modifies the numbers on the left. 67Again, there is no output because these numbers have no meaning without a param. 68 69## Param Value Modification 70 71To modify a parameter value, you can either: 72 73- Use the operator on the plain value pattern, inside the param function: 74 75 <MiniRepl client:only="react" tune={`note("50 60 70".add("<0 1 2>")).room(.1).log()`} /> 76 77- Similarly, use the operator on the plain value pattern and wrap it later: 78 79 <MiniRepl client:only="react" tune={`"50 60 70".add("<0 1 2>").note().room(.1).log()`} /> 80 81- Specify which param should be modified inside the operator function: 82 83 <MiniRepl client:only="react" tune={`note("50 60 70").room(.1).add(note("<0 1 2>")).log()`} /> 84 85Remember the execution of the chained functions goes from left to right. 86 87# Operators 88 89This group of functions allows to modify the value of events. 90 91## add 92 93<JsDoc client:idle name="Pattern.add" h={0} /> 94 95## sub 96 97<JsDoc client:idle name="Pattern.sub" h={0} /> 98 99## mul 100 101<JsDoc client:idle name="Pattern.mul" h={0} /> 102 103## div 104 105<JsDoc client:idle name="Pattern.div" h={0} /> 106 107## round 108 109<JsDoc client:idle name="Pattern.round" h={0} /> 110 111## floor 112 113<JsDoc client:idle name="Pattern.floor" h={0} /> 114 115## ceil 116 117<JsDoc client:idle name="Pattern.ceil" h={0} /> 118 119## range 120 121<JsDoc client:idle name="Pattern.range" h={0} /> 122 123## rangex 124 125<JsDoc client:idle name="Pattern.rangex" h={0} /> 126 127## range2 128 129<JsDoc client:idle name="Pattern.range2" h={0} /> 130 131## ratio 132 133<JsDoc client:idle name="Pattern.ratio" h={0} /> 134 135## as 136 137<JsDoc client:idle name="as" h={0} /> 138 139# Custom Parameters 140 141You can also create your own parameters: 142 143<MiniRepl 144 client:only="react" 145 tune={`let x = createParam('x') 146x(sine.range(0, 200)) 147`} 148/> 149 150Multiple params can also be created in a more consice way, using `createParams`: 151 152<MiniRepl 153 client:only="react" 154 tune={`let { x, y } = createParams('x', 'y'); 155x(sine.range(0, 200)).y(cosine.range(0, 200)); 156`} 157/> 158 159Note that these params will not do anything until you give them meaning in your custom output! 160 161From modifying parameters we transition to the concept of [Signals](/learn/signals).