Skip to content
View in the app

A better way to browse. Learn more.

Learn more

all intervals in chord

Featured Replies

Is there a function that returns all intervals from a chord?

Thanks, Achim

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)

 

(pitch-to-interval '(c4d4e4f6))

 

different approach...

 

(pitch-to-interval '(c4d4e4f6)) => intervals between neighbours

(get-all-intervals '(c4d4e4f6)) => all intervals INSIDE the chord (between all pitches)

 

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.

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)

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.

Create an account or sign in to comment

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.