\version "2.19.10" #(define (ledger-line-no middle-C-pos p) "Returns the number of ledger-lines a pitch @var{p} will have with middle C position @var{middle-C-pos} expressed as staff-steps from the middle staff line." (let* ((ps (ly:pitch-steps p)) (mid-staff-steps (- middle-C-pos)) (top-line (+ mid-staff-steps 4)) (bottom-line (- mid-staff-steps 4)) (above? (> ps top-line)) (below? (< ps bottom-line)) (steps-outside-staff (cond (below? (- ps bottom-line)) (above? (- ps top-line)) (else 0)))) (truncate (/ steps-outside-staff 2)))) octavate = #(define-music-function (parser location threshold mus) (integer? ly:music?) "Create an ottava for notes which have at least @var{threshold} ledger lines" (let ((elts (ly:music-property mus 'elements))) ; Put an "ottava 1" in front of the first NoteEvent ; such that pitch will result in more than one ledger line ; Put an "ottava 0" in front of the first NoteEvent ; such that one or fewer ledger lines are needed. ; start-loco? and start-ottava? are flags which ensure that ; only the first pitch qualifying for an ottava 0 or 1, respectively, ; receives 'OttavaMusic (define (build-new-elts mus-expr new-expr start-loco? start-ottava?) (if (null? mus-expr) new-expr (let ((p (ly:music-property (car mus-expr) 'pitch))) (cond ((not (ly:pitch? p)) (build-new-elts (cdr mus-expr) (append new-expr (list (car mus-expr))) #t #t)) ((and (ly:pitch? p) start-ottava? (>= (ledger-line-no -6 p) threshold)) (build-new-elts (cdr mus-expr) (append new-expr (list (make-music 'OttavaMusic 'ottava-number 1)) (list (car mus-expr))) #t #f)) ((and (ly:pitch? p) start-loco? (< (ledger-line-no -6 p) threshold)) (build-new-elts (cdr mus-expr) (append new-expr (list (make-music 'OttavaMusic 'ottava-number 0)) (list (car mus-expr))) #f #t)) (else (build-new-elts (cdr mus-expr) (append new-expr (list (car mus-expr))) #t #t)))))) (make-music 'SequentialMusic 'elements (build-new-elts elts '() #t #t)))) %%%%%%%%%%% EXAMPLE %%%%%%%%%%%% music = { a''8 b'' c''' d''' e''' f''' g''' a''' } { \music \bar "||" \octavate #1 \music \bar "||" \octavate #2 \music \bar "||" \octavate #3 \music \bar "||" \octavate #4 \music \bar "||" }