\version "2.18" #(define (get-pitch elt) (ly:music-property elt 'pitch)) #(define (extract-pitches lst result) (cond ((null? lst) result) ((ly:pitch? (get-pitch (car lst))) (set! result (append result (list (get-pitch (car lst))))) (extract-pitches (cdr lst) result)) ((ly:music-property (car lst) 'elements) (append (extract-pitches (ly:music-property (car lst) 'elements) result) (extract-pitches (cdr lst) '()))) (else (extract-pitches (cdr lst) result)))) extractPitches = #(define-scheme-function (parser location lst) (ly:music?) (extract-pitches (extract-named-music lst '(EventChord NoteEvent)) '())) %% quoted/adapted from http://lsr.di.unimi.it/LSR/Snippet?id=122 #(define (make-note-req p d) (make-music 'NoteEvent 'duration d 'pitch p)) #(define (make-note elts) (make-music 'EventChord 'elements elts)) #(define (seq-music-list elts) (make-music 'SequentialMusic 'elements elts)) notesFromPitchList = #(define-scheme-function (parser location lst) (list?) (seq-music-list (map (lambda (pitch) (make-note (list (make-note-req pitch (ly:make-duration 2 0))))) (sort (delete-duplicates lst) (lambda (a b) (ly:pitch8 r r 4 d2 } partIII = \relative c' { \voiceOne r2 r8 d ees g, fis4 g r8 a16 bes c8 bes16 a bes2 ~ 8 b16 a g8 a16 b c4 r r2 R1 r8 d ees g, fis4 g r8 a16 bes c8 bes16 a b2 } partIV = \relative c { \voiceTwo d4 r r2 r8 d ees g, fis4 a d,8 d'16 c bes8 c16 d ees2 ~ 8 ees16 d c8 d16 ees fis,8 a16 g fis8 g16 a d,8 d'16 c bes8 c16 d ees8 c a fis' g f ees d c bes a g c a d d, g2\fermata } %% \score and \layout must be stripped when assigning music expression to variable? Bach = << \set Score.currentBarNumber = #28 \bar "" \new PianoStaff << \new Staff = "RH" << \global \new Voice = "voiceI" { \partI } \new Voice = "voiceII" { \partII } >> \new Staff = "LH" << \clef "bass" \global \new Voice = "voiceIII" { \partIII } \new Voice = "voiceIV" { \partIV } >> >> >> %% full score \score { \Bach \layout { \context { \Staff \remove "Time_signature_engraver" } \context { \PianoStaff \override StaffGrouper.staff-staff-spacing.padding = #1 } } } % How many notes? \markup { \line { "There are" #(number->string (length (delete-duplicates #{ \extractPitches \Bach #}))) "different pitches in this excerpt." } } %% pitches used in example, in ascending order \markup \vspace #1 \markup { Notes used: } notesUsed = \notesFromPitchList \extractPitches \Bach \score { \new StaffGroup << \new Staff = "up" { \global #(skip-of-length #{ \notesUsed #}) } \new Staff = "down" { \clef bass \global \autochange { \notesUsed } } >> }