October 19Oct 19 Hello,Below is a method I use a lot in generating rhythms in my compositions.It generates a list of pulses of n units, where the pulses are assigned to prime indexes only. I hope you find it useful.All the best,Jawher Matmati;;; ====================================================(defun gen-prime-pulses (nb &key (unit 's)) "Return a list of Nb OMN lengths: index i is UNIT if i is prime, otherwise the corresponding rest (-UNIT). Example: (gen-prime-pulses 10 :unit 's) => (-s -s s s -s s -s s -s -s -s) NB: 0 and 1 are not prime; primes start at 2. UNIT may be an OMN length symbol (s e q h w …) or a rational like 1/16." (labels ((primep (n) (and (> n 1) (loop for d from 2 to (isqrt n) never (zerop (mod n d))))) (rest-of (u) ;; If UNIT is a symbol like 's -> make symbol '-s. ;; If UNIT is a ratio (e.g. 1/16) -> return negative ratio for rest. (typecase u (symbol (intern (format nil "-~a" u))) ; => -S (case-insensitive) (rational (- u)) (integer (- u)) (float (- u))))) (loop for i from 0 to (- nb 1) collect (if (primep i) unit (rest-of unit)))));;; ====================================================
Create an account or sign in to comment