Skip to content

Commit 6031def

Browse files
committed
use multiple code example blocks in docs, where it fits to ease copying them
1 parent 3c7fce3 commit 6031def

File tree

9 files changed

+187
-74
lines changed

9 files changed

+187
-74
lines changed

docs/book.toml

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ max-level = 3
1616
[output.html]
1717
default-theme = "dark"
1818
preferred-dark-theme = "ayu"
19+
git-repository-url = "https://github.com/emuell/afseq"
20+
git-repository-icon = "fa-github"
21+
edit-url-template = "https://github.com/emuell/afseq/edit/master/docs/{path}"
1922
additional-css = [ "src/styles.css" ]
2023

2124
[output.linkcheck]

docs/src/API/cycle.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020
> ```lua
2121
> --A chord sequence
2222
> cycle("[c4, e4, g4] [e4, g4, b4] [g4, b4, d5] [b4, d5, f#5]")
23+
> ```
24+
> ```lua
2325
> --Arpeggio pattern with variations
2426
> cycle("<c4 e4 g4> <e4 g4> <g4 b4 d5> <b4 f5>")
27+
> ```
28+
> ```lua
2529
> --Euclidean Rhythms
2630
> cycle("c4(3,8) e4(5,8) g4(7,8)")
27-
> --Polyrhythm
28-
> cycle("{c4 e4 g4 b4}%2, {f4 d4 a4}%4")
31+
> ```
32+
> ```lua
2933
> --Map custom identifiers to notes
3034
> cycle("bd(3,8)"):map({ bd = "c4 #1" })
3135
> ```
@@ -84,16 +88,22 @@
8488
> bd = "c4",
8589
> sn = "e4 #1 v0.2"
8690
> })
91+
> ```
92+
> ```lua
8793
> --Using a static map table with targets
8894
> cycle("bd:1 <bd:5, bd:7>"):map({
89-
> -- instrument #1,5,7 will be set as specified
95+
> -- instrument #1,5,7 are set additionally, as specified
9096
> bd = { key = "c4", volume = 0.5 },
9197
> })
98+
> ```
99+
> ```lua
92100
> --Using a dynamic map function
93101
> cycle("4 5 4 <5 [4|6]>"):map(function(context, value)
94102
> -- emit a random note with 'value' as octave
95103
> return math.random(0, 11) + value * 12
96104
> end)
105+
> ```
106+
> ```lua
97107
> --Using a dynamic map function generator
98108
> cycle("4 5 4 <4 [5|7]>"):map(function(init_context)
99109
> local notes = scale("c", "minor").notes
@@ -104,6 +114,8 @@
104114
> return { key = note + octave * 12 }
105115
> end
106116
> end)
117+
> ```
118+
> ```lua
107119
> --Using a dynamic map function to map values to chord degrees
108120
> cycle("1 5 1 [6|7]"):map(function(init_context)
109121
> local cmin = scale("c", "minor")

docs/src/API/pattern.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,28 @@
88
> ```lua
99
> -- using + and * operators to combine patterns
1010
> pattern.from{ 0, 1 } * 3 + { 1, 0 }
11-
>
11+
> ```
12+
> ```lua
1213
> -- repeating, spreading and subsets
1314
> pattern.from{ 0, 1, { 1, 1 } }:repeat_n(4):spread(1.25):take(16)
14-
>
15+
> ```
16+
> ```lua
1517
> -- euclidean patterns
1618
> pattern.euclidean(12, 16)
1719
> pattern.from{ 1, 0.5, 1, 1 }:euclidean(12)
18-
>
20+
> ```
21+
> ```lua
1922
> -- generate/init from functions
2023
> pattern.new(8):init(1) --> 1,1,1,1,1,1,1,1
2124
> pattern.new(12):init(function() return math.random(0.5, 1.0) end )
2225
> pattern.new(16):init(scale("c", "minor").notes_iter())
23-
>
26+
> ```
27+
> ```lua
2428
> -- generate note patterns
2529
> pattern.from{ "c4", "g4", "a4" } * 7 + { "a4", "g4", "c4" }
26-
>
27-
> -- generate chord patterns
30+
> ```
31+
> ```lua
32+
> -- generate chords from degree values
2833
> pattern.from{ 1, 5, 6, 4 }:map(function(index, degree)
2934
> return scale("c", "minor"):chord(degree)
3035
> end)

docs/src/API/rhythm.md

+65-27
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
> pattern = pattern.euclidean(12, 16),
2020
> emit = { "c4", "g4", { "c5 v0.7", "g5 v0.4" }, "a#4" }
2121
> }
22-
>
22+
> ```
23+
> ```lua
2324
> -- trigger a chord sequence every 4 bars after 4 bars
2425
> return rhythm {
2526
> unit = "bars",
@@ -30,7 +31,8 @@
3031
> note("g3'm7"):transpose({ 0, 12, 0, 0 })
3132
> }
3233
> }
33-
>
34+
> ```
35+
> ```lua
3436
> --trigger notes in a seeded, random subdivision pattern
3537
> local seed = 23498
3638
> return rhythm {
@@ -44,7 +46,8 @@
4446
> end,
4547
> emit = { "c4" }
4648
> }
47-
>
49+
> ```
50+
> ```lua
4851
> --trigger random notes in a seeded random pattern from a pentatonic scale
4952
> local cmin = scale("c5", "pentatonic minor").notes
5053
> return rhythm {
@@ -56,13 +59,13 @@
5659
> return { key = cmin[math.random(#cmin)], volume = 0.7 }
5760
> end
5861
> }
59-
>
62+
> ```
63+
> ```lua
6064
> --emit a tidal cycle every new bar
6165
> return rhythm {
6266
> unit = "bars",
6367
> emit = cycle("[c4 [f5 f4]*2]|[c4 [g5 g4]*3]")
6468
> }
65-
> --
6669
> ```
6770
6871
@@ -95,26 +98,39 @@
9598
> create other less common rhythm bases.
9699
> #### examples:
97100
> ```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
100109
> ```
101110
102111
### resolution : [`number`](../API/builtins/number.md)[`?`](../API/builtins/nil.md) {#resolution}
103112
> Factor which is applied on `unit` to specify the final time resolution of the emitter.
104113
> #### examples:
105114
> ```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
108123
> ```
109124
110125
### offset : [`number`](../API/builtins/number.md)[`?`](../API/builtins/nil.md) {#offset}
111126
> Optional offset in `unit * resolution` time units. By default 0.
112127
> When set, the rhythm's event output will be delayed by the given offset value.
113128
> #### examples:
114129
> ```lua
130+
> -- start emitting after 4*4 beats
115131
> unit = "1/4",
116132
> resolution = 4,
117-
> offset = 4 -- start emitting after 4*4 beats
133+
> offset = 4
118134
> ```
119135
120136
### inputs : [`InputParameter`](../API/input.md#InputParameter)[] {#inputs}
@@ -126,18 +142,19 @@
126142
> ```lua
127143
> -- trigger a single note as specified by input parameter 'note'
128144
> -- when input parameter 'enabled' is true, else triggers nothing.
145+
> return rhythm {
129146
> inputs = {
130147
> parameter.boolean("enabled", true),
131148
> parameter.integer("note", 48, { 0, 127 })
132149
> },
133-
> -- [...]
134150
> emit = function(context)
135151
> if context.inputs.enabled then -- boolean value
136152
> return note(context.inputs.note) -- integer value
137153
> else
138154
> return nil
139155
> end
140156
> end
157+
> }
141158
> ```
142159
143160
### 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,27 +175,31 @@
158175
> ```lua
159176
> -- static pattern
160177
> pattern = { 1, 0, 0, 1 }
178+
> ```
179+
> ```lua
161180
> -- "cram" pulses into a single pulse slot via subdivisions
162181
> pattern = { 1, { 1, 1, 1 } }
163-
>
182+
> ```
183+
> ```lua
164184
> -- patterns created via the "patterns" lib
165185
> pattern = pattern.from{ 1, 0 } * 3 + { 1, 1 }
166186
> pattern = pattern.euclidean(7, 16, 2)
167-
>
187+
> ```
188+
> ```lua
168189
> -- stateless pattern function
169190
> pattern = function(context)
170191
> return math.random(0, 1)
171192
> end
172-
>
193+
> ```
194+
> ```lua
173195
> -- stateful generator function
174196
> pattern = function(init_context)
175197
> local triggers = table.new{ 0, 6, 10 }
176198
> return function(context)
177-
> local step = (context.step - 1) % 16
199+
> local step = (context.pulse_step - 1) % 16
178200
> return triggers:contains(step)
179201
> end
180202
> end
181-
>
182203
> ```
183204
184205
### repeats : [`boolean`](../API/builtins/boolean.md) | [`integer`](../API/builtins/integer.md) {#repeats}
@@ -192,10 +213,14 @@
192213
>
193214
> #### examples:
194215
> ```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
199224
> ```
200225
201226
### 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,6 +239,12 @@
214239
> return context.pulse_value > math.random()
215240
> end
216241
> ```
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+
> ```
217248
218249
### 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}
219250
> Specify the melodic pattern of the rhythm. For every pulse in the rhythmical pattern, the event
@@ -231,16 +262,22 @@
231262
> ```lua
232263
> -- a sequence of c4, g4
233264
> emit = {"c4", "g4"}
265+
> ```
266+
> ```lua
234267
> -- a chord of c4, d#4, g4
235268
> emit = {{"c4", "d#4", "g4"}} -- or {"c4'min"}
269+
> ```
270+
> ```lua
236271
> -- a sequence of c4, g4 with volume 0.5
237272
> emit = sequence{"c4", "g4"}:volume(0.5)
238-
>
273+
> ```
274+
> ```lua
239275
> -- stateless generator function
240276
> emit = function(context)
241277
> return 48 + math.random(1, 4) * 5
242278
> end
243-
>
279+
> ```
280+
> ```lua
244281
> -- stateful generator function
245282
> emit = function(init_context)
246283
> local count, step, notes = 1, 2, scale("c5", "minor").notes
@@ -250,16 +287,17 @@
250287
> return { key = key, volume = 0.5 }
251288
> end
252289
> end
253-
>
290+
> ```
291+
> ```lua
254292
> -- a note pattern
255293
> local tritone = scale("c5", "tritone")
256-
> .. -- instrument #1,5,7 will be set as specified.
294+
> --[...]
257295
> emit = pattern.from(tritone:chord(1, 4)):euclidean(6) +
258296
> pattern.from(tritone:chord(5, 4)):euclidean(6)
259-
>
297+
> ```
298+
> ```lua
260299
> -- 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]>"),
263301
> ```
264302
265303

docs/src/API/scale.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
> #### examples:
241241
> ```lua
242242
> local cmin = scale("c4", "minor")
243-
> cmin:fit("c4", "d4", "f4") -> 48, 50, 53 (cmaj -> cmin)
243+
> cmin:fit("c4", "d4", "f4") --> 48, 50, 53 (cmaj -> cmin)
244244
> ```
245245
246246

types/nerdo/library/cycle.lua

+15-3
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,22 @@ local Cycle = {}
4444
--- bd = "c4",
4545
--- sn = "e4 #1 v0.2"
4646
---})
47+
---```
48+
---```lua
4749
-----Using a static map table with targets
4850
---cycle("bd:1 <bd:5, bd:7>"):map({
49-
--- -- instrument #1,5,7 will be set as specified
51+
--- -- instrument #1,5,7 are set additionally, as specified
5052
--- bd = { key = "c4", volume = 0.5 },
5153
---})
54+
---```
55+
---```lua
5256
-----Using a dynamic map function
5357
---cycle("4 5 4 <5 [4|6]>"):map(function(context, value)
5458
--- -- emit a random note with 'value' as octave
5559
--- return math.random(0, 11) + value * 12
5660
---end)
61+
---```
62+
---```lua
5763
-----Using a dynamic map function generator
5864
---cycle("4 5 4 <4 [5|7]>"):map(function(init_context)
5965
--- local notes = scale("c", "minor").notes
@@ -64,6 +70,8 @@ local Cycle = {}
6470
--- return { key = note + octave * 12 }
6571
--- end
6672
---end)
73+
---```
74+
---```lua
6775
-----Using a dynamic map function to map values to chord degrees
6876
---cycle("1 5 1 [6|7]"):map(function(init_context)
6977
--- local cmin = scale("c", "minor")
@@ -91,12 +99,16 @@ function Cycle:map(map) end
9199
--- ```lua
92100
-----A chord sequence
93101
---cycle("[c4, e4, g4] [e4, g4, b4] [g4, b4, d5] [b4, d5, f#5]")
102+
---```
103+
---```lua
94104
-----Arpeggio pattern with variations
95105
---cycle("<c4 e4 g4> <e4 g4> <g4 b4 d5> <b4 f5>")
106+
---```
107+
---```lua
96108
-----Euclidean Rhythms
97109
---cycle("c4(3,8) e4(5,8) g4(7,8)")
98-
-----Polyrhythm
99-
---cycle("{c4 e4 g4 b4}%2, {f4 d4 a4}%4")
110+
---```
111+
---```lua
100112
-----Map custom identifiers to notes
101113
---cycle("bd(3,8)"):map({ bd = "c4 #1" })
102114
--- ```

0 commit comments

Comments
 (0)