Jump to content

Recommended Posts

Posted

Hi folks,

 

here's a function I find useful for my work and sharing it here.

This is an anti oscillation function to remove aba type patterns when working on algorithmically generated material.

 

(defun anti-oscil (lst)
  "Supprime les éléments formant des oscillations de type x _ x dans LST.
   Exemple : (anti-oscil '(a b a a c)) => (a b c)"
  (labels
      ((rec (remaining result)
         (if (null remaining)
             ;; Plus rien à traiter, on renvoie le résultat tel quel
             result
           (let ((x (car remaining)))
             (if (and (>= (length result) 2)
                      (equal x (nth (- (length result) 2) result)))
                 ;; x forme une oscillation x _ x : on l'ignore
                 (rec (cdr remaining) result)
               ;; Sinon, on l'ajoute à la fin du résultat
               (rec (cdr remaining) (append result (list x))))))))
    ;; On démarre la récursion avec la liste complète et un résultat vide
    (rec lst '())))

#| Usage examples
 (filter-repeat
  1
  (anti-oscil
   (vector-to-pitch
    '(c3 c5)
    (vector-smooth 0.2 (gen-noise 128 :seed 42)))
   ))


(tonality-map
 '(messiaen-mode2 :map 'step)
 (filter-repeat
  1
  (anti-oscil
   (vector-to-pitch
    '(0 20)
    (vector-smooth 0.2 (gen-noise 128)))
   )))


|#

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy