Jump to content

all intervals in chord


Recommended Posts

just tried in 3min. ouput correct or perhaps some BUGs in thinking? 😁

greetings

andré

 

(defun get-all-intervals (alist)
  (let ((alist (sort-asc (flatten (pitch-to-midi (if (chordp alist)
                                            (melodize alist)
                                          alist))))))
    (rest (sort-asc (remove-duplicates
     (loop repeat (length alist)
           for cnt = 0 then (incf cnt)
           append (x-b (filter-last (- (length alist) cnt) alist) (nth cnt alist))))))))


(get-all-intervals '(c4 d4 e4))
=> (2 4)

(get-all-intervals '(c4d4e4f6))
=> (2 4 25 27 29)

 

Link to comment
Share on other sites

Would this be okay, too?

 

For getting the intervals of  notes related to the first note.

 

(defun chordintervals (chord)
(x-b (pitch-to-midi (pitch-melodize chord)) 
     (pitch-to-midi (first (pitch-melodize chord))))
)

 

melodize instead of pitch-melodize works too, but is not listed under functions.

Link to comment
Share on other sites

Is that LISPier?  Does the same as last post.

 

(defun chordintervals (chord)
  (let* ((midimelo (pitch-to-midi (pitch-melodize chord)))
            (chordroot (first midimelo)))
          (x-b midimelo chordroot)))

 

(chordintervals '(c4d4e4g4c5))
(chordintervals '(c4 d4 e4 g4 c5))

both return => (0 2 4 7 12)
Link to comment
Share on other sites

And another way:

(defun chordintervals (chord &key ( named nil))
  (let* ((midimelo (pitch-to-midi (pitch-melodize chord)))
         (chordroot (first midimelo))
         (numbers (x-b midimelo chordroot))
         (names (cons 'base-note (rest (get-interval-name numbers)))))
      (if (equal named t) names numbers) ))

(chordintervals '(c4d4e4g4c5))
=>(0 2 4 7 12)

(chordintervals '(c4d4e4g4c5) :named t )
=>(base-note major-second major-third perfect-fifth perfect-octave)

(chordintervals '(c4 d4 e4 g4 c5))
=>(0 2 4 7 12)

(chordintervals '(c4 d4 e4 g4 c5) :named t)
=>(base-note major-second major-third perfect-fifth perfect-octave)

 

I hope I understood the original post correct.

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.

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