-
Notifications
You must be signed in to change notification settings - Fork 4
/
megra-generate-sample-category-events.lisp
365 lines (352 loc) · 18.2 KB
/
megra-generate-sample-category-events.lisp
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
(in-package :megra)
;; some helpers
(defun remove-nth (n list)
(nconc (subseq list 0 n) (nthcdr (1+ n) list)))
(defun purge-keyword (keyword seq)
(remove keyword (remove-nth (+ 1 (position keyword seq)) seq)))
(defun purge-all-keywords (keywords seq)
(let ((accum seq))
(mapcar #'(lambda (kw) (setf accum (purge-keyword kw accum))) keywords)
accum))
(defmacro define-category-sampling-event (name dur)
`(progn
(defun ,(read-from-string name) (&rest rest)
(let* ((args (copy-seq rest))
(lvl (find-keyword-val :lvl args :default 0.4))
(dur (find-keyword-val :dur args :default ,dur))
(pos (find-keyword-val :pos args :default 0.0))
(start (find-keyword-val :start args :default 0.0))
(rate (find-keyword-val :rate args :default 1.0))
(atk (find-keyword-val :atk args :default 1))
(rel (find-keyword-val :rel args :default 7))
(hp-freq (find-keyword-val :hp-freq args :default 10))
(hp-q (find-keyword-val :hp-q args :default 0.4))
(lp-q (find-keyword-val :lp-q args :default 0.1))
(lp-freq (find-keyword-val :lp-freq args :default 5000))
(lp-dist (find-keyword-val :lp-dist args :default 1.0))
(lp-freq-lfo-depth (find-keyword-val :lp-freq-lfo-depth args :default 0.0))
(lp-freq-lfo-speed (find-keyword-val :lp-freq-lfo-speed args :default 0.0))
(lp-freq-lfo-phase (find-keyword-val :lp-freq-lfo-phase args :default 0.0))
(pf-q (find-keyword-val :pf-q args :default 10))
(pf-freq (find-keyword-val :pf-freq args :default 1000))
(pf-gain (find-keyword-val :pf-gain args :default 0.0))
(rev (find-keyword-val :rev args :default 0.0))
(echo (find-keyword-val :echo args :default 0.0))
(echorev (find-keyword-val :echorev args :default 0.0))
(tags (find-keyword-val :tags args :default '(,(read-from-string name))))
(cfun (find-keyword-val :cfun args :default #'replace-value))
(param-keywords (loop for key in rest if (typep key 'keyword) collect key))
(search-keywords (purge-all-keywords param-keywords rest)))
(grain (string-downcase ,name)
(get-matching-sample-name ,name search-keywords)
:dur dur
:lvl lvl :rate rate :start start :atk atk :rel rel
:lp-dist lp-dist :lp-freq lp-freq :rev rev :pos pos
:tags tags :echo echo :echorev echorev
:hp-freq hp-freq :hp-q hp-q :lp-q lp-q :pf-q pf-q
:lp-freq-lfo-depth lp-freq-lfo-depth
:lp-freq-lfo-speed lp-freq-lfo-speed
:lp-freq-lfo-phase lp-freq-lfo-phase
:pf-freq pf-freq :pf-gain pf-gain
:cfun cfun)))
(defun ,(read-from-string (concatenate 'string name "-p")) (event)
(member ',(read-from-string name) (event-tags event)))))
(defmacro define-category-sampling-event-4ch (name dur)
(let ((name-proc (concatenate 'string name "-4ch")))
`(progn
(defun ,(read-from-string name-proc) (&rest rest)
(let* ((args (copy-seq rest))
(lvl (find-keyword-val :lvl args :default 0.4))
(dur (find-keyword-val :dur args :default ,dur))
(pos (find-keyword-val :pos args :default 1.0))
(start (find-keyword-val :start args :default 0.0))
(rate (find-keyword-val :rate args :default 1.0))
(atk (find-keyword-val :atk args :default 1))
(rel (find-keyword-val :rel args :default 7))
(hp-freq (find-keyword-val :hp-freq args :default 10))
(hp-q (find-keyword-val :hp-q args :default 0.4))
(lp-q (find-keyword-val :lp-q args :default 0.1))
(lp-freq (find-keyword-val :lp-freq args :default 5000))
(lp-dist (find-keyword-val :lp-dist args :default 1.0))
(lp-freq-lfo-depth (find-keyword-val :lp-freq-lfo-depth args :default 0.0))
(lp-freq-lfo-speed (find-keyword-val :lp-freq-lfo-speed args :default 0.0))
(lp-freq-lfo-phase (find-keyword-val :lp-freq-lfo-phase args :default 0.0))
(pf-q (find-keyword-val :pf-q args :default 10))
(pf-freq (find-keyword-val :pf-freq args :default 1000))
(pf-gain (find-keyword-val :pf-gain args :default 0.0))
(rev (find-keyword-val :rev args :default 0.0))
(tags (find-keyword-val :tags args :default '(,(read-from-string name-proc))))
(cfun (find-keyword-val :cfun args :default #'replace-value))
(param-keywords (loop for key in rest if (typep key 'keyword) collect key))
(search-keywords (purge-all-keywords param-keywords rest)))
(grain-4ch (string-downcase ,name)
(get-matching-sample-name ,name search-keywords)
:dur dur
:lvl lvl :rate rate :start start :atk atk :rel rel
:lp-dist lp-dist :lp-freq lp-freq :rev rev :pos pos
:tags tags
:hp-freq hp-freq
:hp-q hp-q :lp-q lp-q :pf-q pf-q
:lp-freq-lfo-depth lp-freq-lfo-depth
:lp-freq-lfo-speed lp-freq-lfo-speed
:lp-freq-lfo-phase lp-freq-lfo-phase
:pf-freq pf-freq :pf-gain pf-gain
:cfun cfun)))
(defun ,(read-from-string (concatenate 'string name-proc "-p")) (event)
(member ',(read-from-string name) (event-tags event))))))
(defmacro define-category-sampling-event-8ch (name dur)
(let ((name-proc (concatenate 'string name "-8ch")))
`(progn
(defun ,(read-from-string name-proc) (&rest rest)
(let* ((args (copy-seq rest))
(lvl (find-keyword-val :lvl args :default 0.4))
(dur (find-keyword-val :dur args :default ,dur))
(pos (find-keyword-val :pos args :default 1.0))
(start (find-keyword-val :start args :default 0.0))
(rate (find-keyword-val :rate args :default 1.0))
(atk (find-keyword-val :atk args :default 1))
(rel (find-keyword-val :rel args :default 7))
(hp-freq (find-keyword-val :hp-freq args :default 10))
(hp-q (find-keyword-val :hp-q args :default 0.4))
(lp-q (find-keyword-val :lp-q args :default 0.1))
(lp-freq (find-keyword-val :lp-freq args :default 5000))
(lp-dist (find-keyword-val :lp-dist args :default 1.0))
(lp-freq-lfo-depth (find-keyword-val :lp-freq-lfo-depth args :default 0.0))
(lp-freq-lfo-speed (find-keyword-val :lp-freq-lfo-speed args :default 0.0))
(lp-freq-lfo-phase (find-keyword-val :lp-freq-lfo-phase args :default 0.0))
(pf-q (find-keyword-val :pf-q args :default 10))
(pf-freq (find-keyword-val :pf-freq args :default 1000))
(pf-gain (find-keyword-val :pf-gain args :default 0.0))
(rev (find-keyword-val :rev args :default 0.0))
(tags (find-keyword-val :tags args :default '(,(read-from-string name-proc))))
(cfun (find-keyword-val :cfun args :default #'replace-value))
(param-keywords (loop for key in rest if (typep key 'keyword) collect key))
(search-keywords (purge-all-keywords param-keywords rest)))
(grain-8ch (string-downcase ,name)
(get-matching-sample-name ,name search-keywords)
:dur dur
:lvl lvl :rate rate :start start :atk atk :rel rel
:lp-dist lp-dist :lp-freq lp-freq :rev rev :pos pos
:tags tags
:hp-freq hp-freq :hp-q hp-q :lp-q lp-q :pf-q pf-q
:lp-freq-lfo-depth lp-freq-lfo-depth
:lp-freq-lfo-speed lp-freq-lfo-speed
:lp-freq-lfo-phase lp-freq-lfo-phase
:pf-freq pf-freq :pf-gain pf-gain
:cfun cfun)))
(defun ,(read-from-string (concatenate 'string name-proc "-p")) (event)
(member ',(read-from-string name) (event-tags event))))))
(defmacro define-category-sampling-event-16ch (name dur)
(let ((name-proc (concatenate 'string name "-16ch")))
`(progn
(defun ,(read-from-string name-proc) (&rest rest)
(let* ((args (copy-seq rest))
(lvl (find-keyword-val :lvl args :default 0.4))
(dur (find-keyword-val :dur args :default ,dur))
(pos (find-keyword-val :pos args :default 1.0))
(start (find-keyword-val :start args :default 0.0))
(rate (find-keyword-val :rate args :default 1.0))
(atk (find-keyword-val :atk args :default 1))
(rel (find-keyword-val :rel args :default 7))
(hp-freq (find-keyword-val :hp-freq args :default 10))
(hp-q (find-keyword-val :hp-q args :default 0.4))
(lp-q (find-keyword-val :lp-q args :default 0.1))
(lp-freq (find-keyword-val :lp-freq args :default 5000))
(lp-dist (find-keyword-val :lp-dist args :default 1.0))
(lp-freq-lfo-depth (find-keyword-val :lp-freq-lfo-depth args :default 0.0))
(lp-freq-lfo-speed (find-keyword-val :lp-freq-lfo-speed args :default 0.0))
(lp-freq-lfo-phase (find-keyword-val :lp-freq-lfo-phase args :default 0.0))
(pf-q (find-keyword-val :pf-q args :default 10))
(pf-freq (find-keyword-val :pf-freq args :default 1000))
(pf-gain (find-keyword-val :pf-gain args :default 0.0))
(rev (find-keyword-val :rev args :default 0.0))
(tags (find-keyword-val :tags args :default '(,(read-from-string name-proc))))
(cfun (find-keyword-val :cfun args :default #'replace-value))
(param-keywords (loop for key in rest if (typep key 'keyword) collect key))
(search-keywords (purge-all-keywords param-keywords rest)))
(grain-16ch (string-downcase ,name)
(get-matching-sample-name ,name search-keywords)
:dur dur
:lvl lvl :rate rate :start start :atk atk :rel rel
:lp-dist lp-dist :lp-freq lp-freq :rev rev :pos pos
:tags tags
:hp-freq hp-freq :hp-q hp-q :lp-q lp-q :pf-q pf-q
:lp-freq-lfo-depth lp-freq-lfo-depth
:lp-freq-lfo-speed lp-freq-lfo-speed
:lp-freq-lfo-phase lp-freq-lfo-phase
:pf-freq pf-freq :pf-gain pf-gain
:cfun cfun)))
(defun ,(read-from-string (concatenate 'string name-proc "-p")) (event)
(member ',(read-from-string name) (event-tags event))))))
(defmacro define-category-sampling-event-24ch (name dur)
(let ((name-proc (concatenate 'string name "-24ch")))
`(progn
(defun ,(read-from-string name-proc) (&rest rest)
(let* ((args (copy-seq rest))
(lvl (find-keyword-val :lvl args :default 0.4))
(dur (find-keyword-val :dur args :default ,dur))
(pos (find-keyword-val :pos args :default 1.0))
(start (find-keyword-val :start args :default 0.0))
(rate (find-keyword-val :rate args :default 1.0))
(atk (find-keyword-val :atk args :default 1))
(rel (find-keyword-val :rel args :default 7))
(hp-freq (find-keyword-val :hp-freq args :default 10))
(hp-q (find-keyword-val :hp-q args :default 0.4))
(lp-q (find-keyword-val :lp-q args :default 0.1))
(lp-freq (find-keyword-val :lp-freq args :default 5000))
(lp-dist (find-keyword-val :lp-dist args :default 1.0))
(lp-freq-lfo-depth (find-keyword-val :lp-freq-lfo-depth args :default 0.0))
(lp-freq-lfo-speed (find-keyword-val :lp-freq-lfo-speed args :default 0.0))
(lp-freq-lfo-phase (find-keyword-val :lp-freq-lfo-phase args :default 0.0))
(pf-q (find-keyword-val :pf-q args :default 10))
(pf-freq (find-keyword-val :pf-freq args :default 1000))
(pf-gain (find-keyword-val :pf-gain args :default 0.0))
(rev (find-keyword-val :rev args :default 0.0))
(tags (find-keyword-val :tags args :default '(,(read-from-string name-proc))))
(cfun (find-keyword-val :cfun args :default #'replace-value))
(param-keywords (loop for key in rest if (typep key 'keyword) collect key))
(search-keywords (purge-all-keywords param-keywords rest)))
(grain-24ch (string-downcase ,name)
(get-matching-sample-name ,name search-keywords)
:dur dur
:lvl lvl :rate rate :start start :atk atk :rel rel
:lp-dist lp-dist :lp-freq lp-freq :rev rev :pos pos
:tags tags
:hp-freq hp-freq :hp-q hp-q :lp-q lp-q :pf-q pf-q
:lp-freq-lfo-depth lp-freq-lfo-depth
:lp-freq-lfo-speed lp-freq-lfo-speed
:lp-freq-lfo-phase lp-freq-lfo-phase
:pf-freq pf-freq :pf-gain pf-gain
:cfun cfun)))
(defun ,(read-from-string (concatenate 'string name-proc "-p")) (event)
(member ',(read-from-string name) (event-tags event))))))
(defmacro define-category-sampling-event-32ch (name dur)
(let ((name-proc (concatenate 'string name "-32ch")))
`(progn
(defun ,(read-from-string name-proc) (&rest rest)
(let* ((args (copy-seq rest))
(lvl (find-keyword-val :lvl args :default 0.4))
(dur (find-keyword-val :dur args :default ,dur))
(pos (find-keyword-val :pos args :default 1.0))
(start (find-keyword-val :start args :default 0.0))
(rate (find-keyword-val :rate args :default 1.0))
(atk (find-keyword-val :atk args :default 1))
(rel (find-keyword-val :rel args :default 7))
(hp-freq (find-keyword-val :hp-freq args :default 10))
(hp-q (find-keyword-val :hp-q args :default 0.4))
(lp-q (find-keyword-val :lp-q args :default 0.1))
(lp-freq (find-keyword-val :lp-freq args :default 5000))
(lp-dist (find-keyword-val :lp-dist args :default 1.0))
(lp-freq-lfo-depth (find-keyword-val :lp-freq-lfo-depth args :default 0.0))
(lp-freq-lfo-speed (find-keyword-val :lp-freq-lfo-speed args :default 0.0))
(lp-freq-lfo-phase (find-keyword-val :lp-freq-lfo-phase args :default 0.0))
(pf-q (find-keyword-val :pf-q args :default 10))
(pf-freq (find-keyword-val :pf-freq args :default 1000))
(pf-gain (find-keyword-val :pf-gain args :default 0.0))
(rev (find-keyword-val :rev args :default 0.0))
(tags (find-keyword-val :tags args :default '(,(read-from-string name-proc))))
(cfun (find-keyword-val :cfun args :default #'replace-value))
(param-keywords (loop for key in rest if (typep key 'keyword) collect key))
(search-keywords (purge-all-keywords param-keywords rest)))
(grain-32ch (string-downcase ,name)
(get-matching-sample-name ,name search-keywords)
:dur dur
:lvl lvl :rate rate :start start :atk atk :rel rel
:lp-dist lp-dist :lp-freq lp-freq :rev rev :pos pos
:tags tags
:hp-freq hp-freq :hp-q hp-q :lp-q lp-q :pf-q pf-q
:lp-freq-lfo-depth lp-freq-lfo-depth
:lp-freq-lfo-speed lp-freq-lfo-speed
:lp-freq-lfo-phase lp-freq-lfo-phase
:pf-freq pf-freq :pf-gain pf-gain
:cfun cfun)))
(defun ,(read-from-string (concatenate 'string name-proc "-p")) (event)
(member ',(read-from-string name) (event-tags event))))))
(defmacro define-category-sampling-event-ambi (name dur)
(let ((name-proc (concatenate 'string name "-ambi")))
`(progn
(defun ,(read-from-string name-proc) (&rest rest)
(let* ((args (copy-seq rest))
(lvl (find-keyword-val :lvl args :default 0.4))
(dur (find-keyword-val :dur args :default ,dur))
(azi (find-keyword-val :azi args :default 0.0))
(ele (find-keyword-val :ele args :default 1.57))
(start (find-keyword-val :start args :default 0.0))
(rate (find-keyword-val :rate args :default 1.0))
(atk (find-keyword-val :atk args :default 1))
(rel (find-keyword-val :rel args :default 7))
(hp-freq (find-keyword-val :hp-freq args :default 10))
(hp-q (find-keyword-val :hp-q args :default 0.4))
(lp-q (find-keyword-val :lp-q args :default 0.1))
(lp-freq (find-keyword-val :lp-freq args :default 5000))
(lp-dist (find-keyword-val :lp-dist args :default 1.0))
(lp-freq-lfo-depth (find-keyword-val :lp-freq-lfo-depth args :default 0.0))
(lp-freq-lfo-speed (find-keyword-val :lp-freq-lfo-speed args :default 0.0))
(lp-freq-lfo-phase (find-keyword-val :lp-freq-lfo-phase args :default 0.0))
(pf-q (find-keyword-val :pf-q args :default 10))
(pf-freq (find-keyword-val :pf-freq args :default 1000))
(pf-gain (find-keyword-val :pf-gain args :default 0.0))
(rev (find-keyword-val :rev args :default 0.0))
(tags (find-keyword-val :tags args :default '(,(read-from-string name-proc))))
(cfun (find-keyword-val :cfun args :default #'replace-value))
(param-keywords (loop for key in rest if (typep key 'keyword) collect key))
(search-keywords (purge-all-keywords param-keywords rest)))
(grain-ambi (string-downcase ,name)
(get-matching-sample-name ,name search-keywords)
:dur dur
:lvl lvl :rate rate :start start :atk atk :rel rel
:lp-dist lp-dist :lp-freq lp-freq :rev rev
:tags tags
:azi azi :ele ele
:hp-freq hp-freq :hp-q hp-q :lp-q lp-q :pf-q pf-q
:lp-freq-lfo-depth lp-freq-lfo-depth
:lp-freq-lfo-speed lp-freq-lfo-speed
:lp-freq-lfo-phase lp-freq-lfo-phase
:pf-freq pf-freq :pf-gain pf-gain
:cfun cfun)))
(defun ,(read-from-string (concatenate 'string name-proc "-p")) (event)
(member ',(read-from-string name) (event-tags event))))))
(defun average-sample-length-ms (categ)
(let ((accum 0.0)
(count 0)
file)
(loop for path in
(cl-fad::list-directory (concatenate 'string cm::*sample-root*
(string-downcase categ)))
do (cffi::with-foreign-object (sfinfo '(:struct cl-libsndfile::SF_INFO))
(setf file
(cl-libsndfile::sf_open (namestring path)
cl-libsndfile::SFM_READ sfinfo))
(let* ((frames (cffi::foreign-slot-value sfinfo
'(:struct cl-libsndfile::SF_INFO)
'cl-libsndfile::frames))
(sr (cffi::foreign-slot-value sfinfo
'(:struct cl-libsndfile::SF_INFO)
'cl-libsndfile::samplerate))
(length-in-ms (floor (* 1000.0 (/ frames sr)))))
;;(print path)
(incf count)
(setf accum (+ accum length-in-ms)))
(cl-libsndfile::sf_close file)))
(floor (/ accum count))))
(defun is-file (path)
(pathname-name (probe-file path)))
;; create an event constructor for each sample category ...
(loop for path in
(cl-fad::list-directory cm::*sample-root*)
when (not (is-file path))
do (let ((dirname (car (last (pathname-directory path)))))
(when (and (not (equal dirname "IR"))
(not (equal dirname ".git")))
(let* ((avg (average-sample-length-ms dirname))
(dur (cond ((< avg 64) 64)
((> avg 1024) 1024)
(t (float (floor (/ avg 4)))))))
(eval `(define-category-sampling-event ,dirname ,dur))
(eval `(define-category-sampling-event-ambi ,dirname ,dur))
(eval `(define-category-sampling-event-4ch ,dirname ,dur))
(eval `(define-category-sampling-event-8ch ,dirname ,dur))
(eval `(define-category-sampling-event-16ch ,dirname ,dur))
(eval `(define-category-sampling-event-24ch ,dirname ,dur))
(eval `(define-category-sampling-event-32ch ,dirname ,dur))
))))