Jump to content

Featured Replies

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)))
   )))
|#

Create an account or sign in to comment


Copyright © 2014-2025 Opusmodus™ Ltd. All rights reserved.
Product features, specifications, system requirements and availability are subject to change without notice.
Opusmodus, the Opusmodus logo, and other Opusmodus trademarks are either registered trademarks or trademarks of Opusmodus Ltd.
All other trademarks contained herein are the property of their respective owners.

Powered by Invision Community

Important Information

Terms of Use Privacy Policy