-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzr.lua
executable file
·313 lines (299 loc) · 10.4 KB
/
zr.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
--- Emulation of the Noise Engineering Zularic Repetitor pattern generator.
-- See the manual: https://www.noiseengineering.us/shop/zularic-repetitor
local ZR = {
new_world = {
motorik_1 = 'motorik_1',
motorik_2 = 'motorik_2',
motorik_3 = 'motorik_3',
pop_1 = 'pop_1',
pop_2 = 'pop_2',
pop_3 = 'pop_3',
pop_4 = 'pop_4',
funk_1 = 'funk_1',
funk_2 = 'funk_2',
funk_3 = 'funk_3',
sequence = 'sequence',
prime_2 = 'prime_2',
prime_322 = 'prime_322',
},
old_world = {
king_1 = 'king_1',
king_2 = 'king_2',
kroboto = 'kroboto',
vodou_1 = 'vodou_1',
vodou_2 = 'vodou_2',
vodou_3 = 'vodou_3',
gahu = 'gahu',
clave = 'clave',
rhumba = 'rhumba',
jhaptal_1 = 'jhaptal_1',
jhaptal_2 = 'jhaptal_2',
chacar = 'chacar',
mata = 'mata',
pashto = 'pashto',
prime_232 = 'prime_232',
}
}
--- See pages 5-8 of the manual: https://www.noiseengineering.us/shop/zularic-repetitor
ZR.banks = {
motorik_1 = {
{1,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0},
{1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,0,1,0,0,1,0,1,0},
{0,0,0,0,1,0,1,1,0,0,0,0,1,0,1,1,0,0,0,0,1,0,1,1,0,0,0,0,1,0,1,1},
{1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0},
},
motorik_2 = {
{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,1},
{1,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0},
{1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0},
},
motorik_3 = {
{1,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0},
{0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0},
{1,0,1,1,1,0,0,1,1,0,1,1,1,0,0,1,1,0,1,1,1,0,0,1,1,0,1,1,1,0,0,1},
{1,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
},
p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opt] string bank, see ZR.new_world, ZR.old_world and ZR.banks, default: 'motorik_1'
-- @tparam[opt] number child which of the 4 rhythms from the bank, 1 is mother rhythm (default)
-- @tparam[opt] number offset number of steps to offset the rhythm, resulting index always wraps
-- @treturn table ZR
function ZR.new(bank, child, offset)
bank, child, offset = bank or 'motorik_1', child or 1, offset or 0
local zr = {
bank=bank,
child=child,
offset=offset,
ix=1,
}
setmetatable(zr, ZR)
return zr
end
--- is v a table that is (hopefully) callable or a function?
-- we could check the metatable for __call but doesn't seem necessary
local function callable(v)
local v_type = type(v)
if v_type == 'table' or v_type == 'function' then
return true
end
return false
end
local function is_table(t) return type(t) == 'table' end
--- Get the next step. Optionally override the world, bank, child, offset from construction.
-- @tparam[opt] table args 'bank', 'child', 'offset' (all optional)
-- @tparam[opt] string args.bank, see ZR.new_world, ZR.old_world and ZR.banks default: self.bank
-- @tparam[opt] number args.child which of the 4 rhythms from the bank, 1 is mother rhythm, default: self.child
-- @tparam[opt] number args.offset number of steps to offset the rhythm, resulting index always wraps, default: self.offset
-- @treturn boolean
function ZR.next(self, args)
args = args or {}
local bank = args.bank or self.bank
local child, offset = args.child or self.child, args.offset or self.offset
if callable(bank) then bank = math.floor(bank()) end
if callable(child) then child = math.floor(child()) end
if callable(offset) then offset = math.floor(offset()) end
local pattern = ZR.banks[bank][child]
local length = #pattern
local offset_ix = (((self.ix + offset) - 1) % length) + 1
self.ix = (self.ix % length) + 1
return pattern[offset_ix] == 1 and true or false
end
-- Get the next step but then decrement the index back.
function ZR.peek(self, args)
local step = self:next(args)
self.ix = self.ix - 1
if self.ix < 1 then
self.ix = 1
end
return step
end
--- Reset the pattern to the first step.
function ZR.reset(self)
self.ix = 1
if is_table(self.bank) then self.bank:reset() end
if is_table(self.child) then self.child:reset() end
if is_table(self.offset) then self.offset:reset() end
end
--- Helper to convert to a pattern to a table.
function ZR.to_table(self, num_steps)
self:reset()
num_steps = num_steps or #ZR.banks[self.bank][self.child]
local pattern = {}
for step=1, num_steps do
table.insert(pattern, self())
end
self:reset()
return pattern
end
--- Helper to print the pattern to the console.
function ZR.print(self)
local pattern = self:to_table(#ZR.banks[self.bank][self.child])
tab.print(pattern)
end
ZR.__call = function(self, ...)
return (self == ZR) and ZR.new(...) or ZR.next(self, ...)
end
ZR.metaix = {reset=ZR.reset, to_table=ZR.to_table, print=ZR.print}
ZR.__index = function(self, ix)
return ZR.metaix[ix]
end
setmetatable(ZR, ZR)
return ZR