Jump to content

respell/enharmonic change

Recommended Posts

is there an RESPELL-function which would change sharps into flats and flats into sharps for single pitch-values? enharmonic changes....




(enharmonic 'cs4)
=> db4

(enharmonic 'db4)
=> cs4


but there is an other solution for an EQUALP* whicht is "independent" from pitch-name (enharmonic)... but a function like ENHARMONIC or EQUALP* could be useful (for pattern-match etc)...


(defun equalp* (a b)
  (equal (pitch-to-midi a) (pitch-to-midi b)))

(equalp* 'cs4 'db4)
=> t


there is an EQUALP in the system (but not documented), and works like that

(equalp 'cs4 'db4)
=> nil

(equalp 'cs4 'cs4)
=> t




Link to comment
Share on other sites

  • 3 weeks later...

EQUALP is part of the Common Lisp standard. You can find its documentation at  



Note that Common Lisp has a whole zoo of equality comparison functions, see eq, eql, equal, =, string=, string-equal, char=, char-equal in that documentation




Link to comment
Share on other sites




here is a solution for that (i hope i got all cases) - could be usefull in OPMO - it was/is a explode/compress-thing of the pitch-symbols and to think about all cases. please check it!!




(defun enharmonic* (pitches)
  (let ((liste '((cs db)
                 (ds eb)
                 (e fb)
                 (es f)
                 (fs gb)
                 (gs ab)
                 (as bb)
                 (b cb)
                 (bs c))))

    (loop for n in pitches
      collect (let ((octave (car (last (explode n))))
                    (pitchname (compress (butlast  (explode n)))))
                (append (compress (list (car (set-difference 
                                              (loop for i in liste
                                                ;; cases with octave-change
                                                when (or (and (equal i '(bs c))
                                                              (equal pitchname 'bs))
                                                         (and (equal i '(b cb))
                                                              (equal pitchname 'b)))
                                                do (setf octave (1+ octave))
                                                when (or (and (equal i '(bs c))
                                                              (equal pitchname 'c))
                                                         (and (equal i '(b cb))
                                                              (equal pitchname 'cb)))
                                                do (setf octave (1- octave))
                                              ;; ordinary cases
                                              when (member pitchname i)
                                              append i) 
                                            (list pitchname)))


(enharmonic* '(fb4 fb4 cb5))
=> (e4 e4 b4)

(enharmonic* '(f4 b7))
=> (es4 cb8)

(enharmonic* '(bs4 cs5 cb5))
=> (c5 db5 b4)

(enharmonic* '(c6 gs7 gb4))
=> (bs5 ab7 fs4)


Link to comment
Share on other sites

Maybe a Kind of Substitute map function could be useful

something like

I did it to interval substitution, to transform interval ( 0 - 11) to interval classes (0 - 6)

(replace-map '((-11 1) (-10 2) (-9 3) (-8 4) (-7 5) (7 -5) (8 -4) (9 -3)(10 -2)(11 -1)) '(1 2 3 4 5 6 7 8 9 10 11 12 13))

Maybe a kind of mapping to tonalities could be useful.

Respell to tonality function


respell-to-collection '( pitch list)

Link to comment
Share on other sites

Join the conversation

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

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