Hi,

On Mon, Oct 6, 2014 at 3:51 PM, David Bellows <davebell...@gmail.com> wrote:

> I ended up creating my own solution to use in my code that generates
> scores. Unfortunately it doesn't really translate into anything usable by
> anyone else. Likewise I created my own staff switching method as well so
> that rests would be printed in the other staff.
>
> Still, I think the automatic ottava marking would be a good idea and maybe
> even doable. Alas, I am not the one to do it, though.
>
> On Sun, Oct 5, 2014 at 2:14 PM, Gilberto Agostinho <
> gilbertohasn...@gmail.com> wrote:
>
>> Malte Meyn-3 wrote
>> > There is a pitch-dependent staff switching automatism in LilyPond (I
>> > don’t know how it works but you can have a look at piano/harp section in
>> > the notation reference) so I think what you are asking for should at
>> > least not be impossible.
>>
>> You are talking about \autochange (see:
>>
>> http://lilypond.org/doc/v2.18/Documentation/notation/common-notation-for-keyboards#changing-staff-automatically
>> ).
>>
>> And indeed an automatic function to add ottava markings for every pitch
>> higher than a certain threshold (and ottava bassa lower than another
>> defined
>> threshold) would be a fantastic addition to LilyPond.
>>
>>
I think this should be doable.

Here's a preliminary experiment.  It will add an automatic \ottava 1 before
passages where notes have at least a specified number of ledger lines.

Right now this is pretty limited.  It won't handle \relative, for one
thing.  I'll have to get deeper into the music representation for that, but
this should serve as a proof-of-concept.

Another issue is adapting to different clefs.  The function \octavate is
hard-coded for treble clef at the moment.  The problem is that
'clefMiddleCPosition is a context property, and I'm not sure how to get at
context properties through a music function.  Any ideas?  With this
property it's easy to have this work automatically with different clefs.
 (The number -6 in the function represents the value of
'clefMiddleCPosition for treble clef--middle C is 6 staff-steps below the
center line.)

Best,
David
\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 "||"
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to