]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4702/1: Implement `music-pitches' function
authorDavid Kastrup <dak@gnu.org>
Fri, 4 Dec 2015 15:09:00 +0000 (16:09 +0100)
committerDavid Kastrup <dak@gnu.org>
Mon, 28 Dec 2015 08:53:08 +0000 (09:53 +0100)
scm/music-functions.scm

index d5a4b2478a00acce7fa6b18ca72c7dcee2a64f97..325da29dd575a147e82998a0547d9b3a5fd723c8 100644 (file)
@@ -2073,6 +2073,21 @@ are expanded using the default settings of the parser."
   (map (lambda (x) (ly:music-property x 'pitch))
        (event-chord-notes event-chord)))
 
+(define-public (music-pitches music)
+  "Return a list of all pitches from @var{music}."
+  ;; Opencoded for efficiency.
+  (reverse!
+   (let loop ((music music) (pitches '()))
+     (let ((p (ly:music-property music 'pitch)))
+       (if (ly:pitch? p)
+           (cons p pitches)
+           (let ((elt (ly:music-property music 'element)))
+             (fold loop
+                   (if (ly:music? elt)
+                       (loop elt pitches)
+                       pitches)
+                   (ly:music-property music 'elements))))))))
+
 (define-public (event-chord-reduce music)
   "Reduces event chords in @var{music} to their first note event,
 retaining only the chord articulations.  Returns the modified music."