Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hey im trying to easily define recursive music structures and im a little stuck.
- 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))
- i wanna iterate over the pattern every 1 so it completes the cycle every 4: 0, -2, -4, -2, 0 etc...
- and also every four so it completes the cycle every 16: 0 0 0 0 -2 -2 -2 -2 etc..
- 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.
- my best guess was floor((beat modulo 16)/4) but dosnt work obviously: here is the code i had
- (defn compose [instr beat & {:keys [root pattern timestamp durations recursions]}]
- (let [;;;;;;;;;;;;;;;;;;;;;;relevant stuff here
- size (count pattern)
- base-beat (map #(mod beat %) recursions)
- indxs (map #(int (/ % size)) base-beat)
- note (+ root (reduce + (map #(nth pattern %) indxs)))
- ;;;;;;;;;;;;;;;;;;;;;;;;
- ts (first timestamp)
- dur (first durations)]
- (play-sample beat instr note 1 dur)
- (apply-by (*metro* (+ beat (* 0.5 ts)))
- #'compose [instr (+ beat ts)
- :root root
- :pattern pattern
- :timestamp (rotate 1 timestamp)
- :durations (rotate 1 durations)
- :recursions recursions])))
- (compose sampled-piano (* 4 (metro-bar *metro*))
- :root (note :E4)
- :pattern [0 -2 -4 -2]
- :timestamp '(1 1 1 1)
- :durations '(1 1 1 1)
- :recursions '(4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement