Jump to content

Featured Replies

Posted

OMers,

I wrote this function and use it in my composition work. Please feel free to steal use it. It returns the "polarity" of a sequence, defined as the ratio of consecutive uneven and even interval classes (IC) in a sequence. I use this as a way of testing if a generated sequence contains a balanced mix of even or uneven ICs.

 

(defun polarity (in-seq)
    (when (equal (length in-seq) 0)
      return 0
      )
    (let((accum 0) (int-pairs (interval-class in-seq)))
      (mapcar (lambda (x) (when (evenp x) (incf accum) )) int-pairs)
      (/ (* accum 1.0) (- (length in-seq) 1))
      )
    )

 

Some examples:

;; The polarity of a chromatic scale is 0.0, as there are no even interval classes.

OM 9 > (polarity '(0 1 2 3 4 5 6 7 8 9 10))
0.0

 

;; The polarity of a whole-tone scale is 1.0, as there are no uneven interval classes.

OM 10 > (polarity '(0 4 8 2 6 10))
1.0

 

;; The polarity of a chromatic scale is 0.0, as there are no even interval classes.

OM 9 > (polarity '(0 1 2 3 4 5 6 7 8 9 10))
0.0

 

;; The polarity of a sequence of alternating even and uneven ICs is 0.5.

OM 14 > (polarity `(0 6 11 5 10 4 9 3 8 2 7 1 6))
interval-class

 

Right now it only works on sequences of numbers and there's no error handling. I would appreciate very much any advice on a concise and OM-ian way to extend it to accepts either integers or pitch symbols like '(c4 fs4 b4 f5 bb5).
 

Thanks!
Paul Marquardt

 

Is this what you are looking for:
 

(defun polarity (seq &key sum)
  (do-verbose ("polarity")
    (flet ((polarity-i (in-seq)
             (let ((integers (if (omn-pitchp (car in-seq)) (pitch-to-midi in-seq) in-seq)))
               (when (equal (length integers) 0)
                 return 0
                 )
               (let ((accum 0) (int-pairs (interval-class integers)))
                 (mapcar (lambda (x) (when (evenp x) (incf accum) )) int-pairs)
                 (/ (* accum 1.0) (- (length integers) 1))
                 ))))
      (let ((result (loop for i in (lists! seq)
                          collect (polarity-i i))))
        (if sum (/ (find-sum (flatten result)) (length result)) result)))))

(polarity '(1 3 6 4 2))
=> (0.75)
(polarity '((c4 e4 c3 ds4 b5) (c4 cs4 d4 ds4 f4)))
=> (0.75 0.25)
(polarity '((c4 e4 c3 ds4 b5) (c4 cs4 d4 ds4 f4)) :sum t)
=> 0.5

 

  • Author

This is excellent -- and the feature to accept lists of lists is very helpful -- thank you 😀

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