SHOW:
|
|
- or go back to the newest paste.
| 1 | Hey im trying to easily define recursive music structures and im a little stuck. | |
| 2 | given a beat number that increments every note, a root (say 50), and a pattern (say [0 -2 -4 -2]), and a list of layers (say (4,16)) | |
| 3 | ||
| 4 | i wanna iterate over the pattern every 1 so it completes the cycle every 4: 0, -2, -4, -2, 0 etc... | |
| 5 | and also every four so it completes the cycle every 16: 0 0 0 0 -2 -2 -2 -2 etc.. | |
| 6 | ||
| 7 | so to isolate the question I lets focus on 16: what mathmatically would represent getting 0 0 0 0 1 1 1 1 2 2 2 2 (the indexes) at certain beats. | |
| 8 | ||
| 9 | - | my best guess was floor((beat modulo 16)/4) but dosnt work obviously |
| 9 | + | my best guess was floor((beat modulo 16)/4) but dosnt work obviously: here is the code i had |
| 10 | ||
| 11 | (defn compose [instr beat & {:keys [root pattern timestamp durations recursions]}]
| |
| 12 | (let [;;;;;;;;;;;;;;;;;;;;;;relevant stuff here | |
| 13 | size (count pattern) | |
| 14 | base-beat (map #(mod beat %) recursions) | |
| 15 | indxs (map #(int (/ % size)) base-beat) | |
| 16 | note (+ root (reduce + (map #(nth pattern %) indxs))) | |
| 17 | ;;;;;;;;;;;;;;;;;;;;;;;; | |
| 18 | ts (first timestamp) | |
| 19 | dur (first durations)] | |
| 20 | (play-sample beat instr note 1 dur) | |
| 21 | (apply-by (*metro* (+ beat (* 0.5 ts))) | |
| 22 | #'compose [instr (+ beat ts) | |
| 23 | :root root | |
| 24 | :pattern pattern | |
| 25 | :timestamp (rotate 1 timestamp) | |
| 26 | :durations (rotate 1 durations) | |
| 27 | :recursions recursions]))) | |
| 28 | ||
| 29 | (compose sampled-piano (* 4 (metro-bar *metro*)) | |
| 30 | :root (note :E4) | |
| 31 | :pattern [0 -2 -4 -2] | |
| 32 | :timestamp '(1 1 1 1) | |
| 33 | :durations '(1 1 1 1) | |
| 34 | :recursions '(4)) |