|
19 | 19 | > pattern = pattern.euclidean(12, 16), |
20 | 20 | > emit = { "c4", "g4", { "c5 v0.7", "g5 v0.4" }, "a#4" } |
21 | 21 | > } |
22 | | -> |
| 22 | +> ``` |
| 23 | +> ```lua |
23 | 24 | > -- trigger a chord sequence every 4 bars after 4 bars |
24 | 25 | > return rhythm { |
25 | 26 | > unit = "bars", |
|
30 | 31 | > note("g3'm7"):transpose({ 0, 12, 0, 0 }) |
31 | 32 | > } |
32 | 33 | > } |
33 | | -> |
| 34 | +> ``` |
| 35 | +> ```lua |
34 | 36 | > --trigger notes in a seeded, random subdivision pattern |
35 | 37 | > local seed = 23498 |
36 | 38 | > return rhythm { |
|
44 | 46 | > end, |
45 | 47 | > emit = { "c4" } |
46 | 48 | > } |
47 | | -> |
| 49 | +> ``` |
| 50 | +> ```lua |
48 | 51 | > --trigger random notes in a seeded random pattern from a pentatonic scale |
49 | 52 | > local cmin = scale("c5", "pentatonic minor").notes |
50 | 53 | > return rhythm { |
|
56 | 59 | > return { key = cmin[math.random(#cmin)], volume = 0.7 } |
57 | 60 | > end |
58 | 61 | > } |
59 | | -> |
| 62 | +> ``` |
| 63 | +> ```lua |
60 | 64 | > --emit a tidal cycle every new bar |
61 | 65 | > return rhythm { |
62 | 66 | > unit = "bars", |
63 | 67 | > emit = cycle("[c4 [f5 f4]*2]|[c4 [g5 g4]*3]") |
64 | 68 | > } |
65 | | -> -- |
66 | 69 | > ``` |
67 | 70 |
|
68 | 71 |
|
|
95 | 98 | > create other less common rhythm bases. |
96 | 99 | > #### examples: |
97 | 100 | > ```lua |
98 | | -> unit = "beats", resolution = 1.01 --> slightly off beat pulse |
99 | | -> unit = "1/16", resolution = 4/3 --> triplet |
| 101 | +> -- slightly off beat pulse |
| 102 | +> unit = "beats", |
| 103 | +> resolution = 1.01 |
| 104 | +> ``` |
| 105 | +> ```lua |
| 106 | +> -- triplet |
| 107 | +> unit = "1/16", |
| 108 | +> resolution = 4/3 |
100 | 109 | > ``` |
101 | 110 |
|
102 | 111 | ### resolution : [`number`](../API/builtins/number.md)[`?`](../API/builtins/nil.md) {#resolution} |
103 | 112 | > Factor which is applied on `unit` to specify the final time resolution of the emitter. |
104 | 113 | > #### examples: |
105 | 114 | > ```lua |
106 | | -> unit = "beats", resolution = 1.01 --> slightly off beat pulse |
107 | | -> unit = "1/16", resolution = 4/3 --> triplet |
| 115 | +> -- slightly off beat pulse |
| 116 | +> unit = "beats", |
| 117 | +> resolution = 1.01 |
| 118 | +> ``` |
| 119 | +> ```lua |
| 120 | +> -- triplet |
| 121 | +> unit = "1/16", |
| 122 | +> resolution = 4/3 |
108 | 123 | > ``` |
109 | 124 |
|
110 | 125 | ### offset : [`number`](../API/builtins/number.md)[`?`](../API/builtins/nil.md) {#offset} |
111 | 126 | > Optional offset in `unit * resolution` time units. By default 0. |
112 | 127 | > When set, the rhythm's event output will be delayed by the given offset value. |
113 | 128 | > #### examples: |
114 | 129 | > ```lua |
| 130 | +> -- start emitting after 4*4 beats |
115 | 131 | > unit = "1/4", |
116 | 132 | > resolution = 4, |
117 | | -> offset = 4 -- start emitting after 4*4 beats |
| 133 | +> offset = 4 |
118 | 134 | > ``` |
119 | 135 |
|
120 | 136 | ### inputs : [`InputParameter`](../API/input.md#InputParameter)[] {#inputs} |
|
126 | 142 | > ```lua |
127 | 143 | > -- trigger a single note as specified by input parameter 'note' |
128 | 144 | > -- when input parameter 'enabled' is true, else triggers nothing. |
| 145 | +> return rhythm { |
129 | 146 | > inputs = { |
130 | 147 | > parameter.boolean("enabled", true), |
131 | 148 | > parameter.integer("note", 48, { 0, 127 }) |
132 | 149 | > }, |
133 | | -> -- [...] |
134 | 150 | > emit = function(context) |
135 | 151 | > if context.inputs.enabled then -- boolean value |
136 | 152 | > return note(context.inputs.note) -- integer value |
137 | 153 | > else |
138 | 154 | > return nil |
139 | 155 | > end |
140 | 156 | > end |
| 157 | +> } |
141 | 158 | > ``` |
142 | 159 |
|
143 | 160 | ### pattern : [`boolean`](../API/builtins/boolean.md) | [`number`](../API/builtins/number.md) | `0` | `1` | [`Pulse`](#Pulse) | [`nil`](../API/builtins/nil.md)[] | (context : [`PatternContext`](../API/rhythm.md#PatternContext)) `->` [`boolean`](../API/builtins/boolean.md) | [`number`](../API/builtins/number.md) | `0` | `1` | [`Pulse`](#Pulse) | [`nil`](../API/builtins/nil.md) | (context : [`PatternContext`](../API/rhythm.md#PatternContext)) `->` (context : [`PatternContext`](../API/rhythm.md#PatternContext)) `->` [`boolean`](../API/builtins/boolean.md) | [`number`](../API/builtins/number.md) | `0` | `1` | [`Pulse`](#Pulse) | [`nil`](../API/builtins/nil.md) {#pattern} |
|
158 | 175 | > ```lua |
159 | 176 | > -- static pattern |
160 | 177 | > pattern = { 1, 0, 0, 1 } |
| 178 | +> ``` |
| 179 | +> ```lua |
161 | 180 | > -- "cram" pulses into a single pulse slot via subdivisions |
162 | 181 | > pattern = { 1, { 1, 1, 1 } } |
163 | | -> |
| 182 | +> ``` |
| 183 | +> ```lua |
164 | 184 | > -- patterns created via the "patterns" lib |
165 | 185 | > pattern = pattern.from{ 1, 0 } * 3 + { 1, 1 } |
166 | 186 | > pattern = pattern.euclidean(7, 16, 2) |
167 | | -> |
| 187 | +> ``` |
| 188 | +> ```lua |
168 | 189 | > -- stateless pattern function |
169 | 190 | > pattern = function(context) |
170 | 191 | > return math.random(0, 1) |
171 | 192 | > end |
172 | | -> |
| 193 | +> ``` |
| 194 | +> ```lua |
173 | 195 | > -- stateful generator function |
174 | 196 | > pattern = function(init_context) |
175 | 197 | > local triggers = table.new{ 0, 6, 10 } |
176 | 198 | > return function(context) |
177 | | -> local step = (context.step - 1) % 16 |
| 199 | +> local step = (context.pulse_step - 1) % 16 |
178 | 200 | > return triggers:contains(step) |
179 | 201 | > end |
180 | 202 | > end |
181 | | -> |
182 | 203 | > ``` |
183 | 204 |
|
184 | 205 | ### repeats : [`boolean`](../API/builtins/boolean.md) | [`integer`](../API/builtins/integer.md) {#repeats} |
|
192 | 213 | > |
193 | 214 | > #### examples: |
194 | 215 | > ```lua |
195 | | -> repeat = 0 -- one-shot |
196 | | -> repeat = false -- also a one-shot |
197 | | -> repeat = 3 -- play the pattern 4 times |
198 | | -> repeat = true -- play & repeat forever |
| 216 | +> -- one-shot |
| 217 | +> repeat = 0 |
| 218 | +> -- also a one-shot |
| 219 | +> repeat = false |
| 220 | +> -- play the pattern 4 times |
| 221 | +> repeat = 3 |
| 222 | +> -- play & repeat forever (default) |
| 223 | +> repeat = true |
199 | 224 | > ``` |
200 | 225 |
|
201 | 226 | ### gate : (context : [`GateContext`](../API/rhythm.md#GateContext)) `->` [`boolean`](../API/builtins/boolean.md) | (context : [`GateContext`](../API/rhythm.md#GateContext)) `->` (context : [`GateContext`](../API/rhythm.md#GateContext)) `->` [`boolean`](../API/builtins/boolean.md) {#gate} |
|
214 | 239 | > return context.pulse_value > math.random() |
215 | 240 | > end |
216 | 241 | > ``` |
| 242 | +> ```lua |
| 243 | +> -- threshold gate: skips all pulse values below a given threshold value |
| 244 | +> gate = function(context) |
| 245 | +> return context.pulse_value > 0.5 |
| 246 | +> end |
| 247 | +> ``` |
217 | 248 |
|
218 | 249 | ### emit : [`Cycle`](../API/cycle.md#Cycle) | [`Sequence`](../API/sequence.md#Sequence) | [`Note`](../API/note.md#Note) | [`NoteValue`](#NoteValue) | [`Note`](../API/note.md#Note) | [`NoteValue`](#NoteValue)[] | (context : [`EmitterContext`](../API/rhythm.md#EmitterContext)) `->` [`NoteValue`](#NoteValue) | (context : [`EmitterContext`](../API/rhythm.md#EmitterContext)) `->` (context : [`EmitterContext`](../API/rhythm.md#EmitterContext)) `->` [`NoteValue`](#NoteValue) {#emit} |
219 | 250 | > Specify the melodic pattern of the rhythm. For every pulse in the rhythmical pattern, the event |
|
231 | 262 | > ```lua |
232 | 263 | > -- a sequence of c4, g4 |
233 | 264 | > emit = {"c4", "g4"} |
| 265 | +> ``` |
| 266 | +> ```lua |
234 | 267 | > -- a chord of c4, d#4, g4 |
235 | 268 | > emit = {{"c4", "d#4", "g4"}} -- or {"c4'min"} |
| 269 | +> ``` |
| 270 | +> ```lua |
236 | 271 | > -- a sequence of c4, g4 with volume 0.5 |
237 | 272 | > emit = sequence{"c4", "g4"}:volume(0.5) |
238 | | -> |
| 273 | +> ``` |
| 274 | +> ```lua |
239 | 275 | > -- stateless generator function |
240 | 276 | > emit = function(context) |
241 | 277 | > return 48 + math.random(1, 4) * 5 |
242 | 278 | > end |
243 | | -> |
| 279 | +> ``` |
| 280 | +> ```lua |
244 | 281 | > -- stateful generator function |
245 | 282 | > emit = function(init_context) |
246 | 283 | > local count, step, notes = 1, 2, scale("c5", "minor").notes |
|
250 | 287 | > return { key = key, volume = 0.5 } |
251 | 288 | > end |
252 | 289 | > end |
253 | | -> |
| 290 | +> ``` |
| 291 | +> ```lua |
254 | 292 | > -- a note pattern |
255 | 293 | > local tritone = scale("c5", "tritone") |
256 | | -> .. -- instrument #1,5,7 will be set as specified. |
| 294 | +> --[...] |
257 | 295 | > emit = pattern.from(tritone:chord(1, 4)):euclidean(6) + |
258 | 296 | > pattern.from(tritone:chord(5, 4)):euclidean(6) |
259 | | -> |
| 297 | +> ``` |
| 298 | +> ```lua |
260 | 299 | > -- a tidal cycle |
261 | | -> emit = cycle("<[a3 c4 e4 a4]*3 [d4 g3 g4 c4]>") |
262 | | -> -- |
| 300 | +> emit = cycle("<[a3 c4 e4 a4]*3 [d4 g3 g4 c4]>"), |
263 | 301 | > ``` |
264 | 302 |
|
265 | 303 | |
|
0 commit comments