I am a composer usually working with Max-MSP and OpenMusic. For porting some work from OM to Max, I have just started to learn LISP.
My problem is rather simple: I want to make chord inversions from a given chord.
From (C E G)
it needs to return ((C E G) (E G C) (G C E))
. It means that for a 3 notes chord I'll get 3 inversions and for n notes chord n inversions.
I've already built the basic functions:
(defun if-x-under-y-raise-x (x y)
(if (<= x y) (if-x-under-y-raise-x (+ x 12) y) x))
(defun transp (chord)
(append (cdr chord)
(cons (if-x-under-y-raise-x (first chord) (list-max chord 0)) nil)))
transp
function takes the lowest note of a sorted chord and transpose it by one octave until it is higher than the highest note of the chord recursively.
So expressed in MIDI it means that (60 64 67)
becomes (64 67 72)
. This is very easy to do.
Problems come when I want to get the n
inversions recursively as explained before.
I can do it once with transp
but the function below doesn't work:
(defun renverse (chords)
(if (< (length (first chords)) (length chords))
chords
(cons chords (renverse (list (transp (last chords)))))))
chords
is the starting list.
(renverse '(60 64 67))
should return 3 chord inversions.
Any help will be very welcome. :-)