I want to find the interval size of a two-note chord in a music
function, and I came up with the following solution.
```tex
showInterval =
#(define-music-function (ev-chord)
   (ly:music?)

   (define (interval-string a b)
     (number->string (1+ (ly:pitch-steps (- b a)))))

   (let* ((notes (extract-named-music ev-chord 'NoteEvent))
          (bottom (ly:music-property (first notes) 'pitch))
          (top (ly:music-property (second notes) 'pitch))
          (dur (ly:music-property (first notes) 'duration)))
     (make-relative (bottom top)
                    #{ < #bottom #top > #}
                    #{ < $bottom $top > $dur
                         ^ #(interval-string bottom top) #})))

\relative c' {
  \showInterval <d a'>4 \showInterval <d d'>4
}
```

Is there a better, less convoluted way to do that?  Any advice is
highly appreciated.


    Werner

Reply via email to