Hi Erik,

On Sun, Oct 12, 2014 at 2:35 AM, erik flister <erik.flis...@gmail.com>
wrote:

> hi-
>
> i'm writing some software that generates .ly files and want to offer
> the option to automatically add (woodwind) fingering chart annotations
> to the engraving.  the project is in haskell and i'd rather not learn
> scheme or lilypond internals.  the problem is determining the octave
> -- i want to support relative octave entry
> (
> http://lilypond.org/doc/v2.18/Documentation/notation/writing-pitches#relative-octave-entry
> ),
> but i don't want to reimplement relative octave detection (not because
> it's hard, but i in principle don't want to duplicate logic).
>
> i would think automatic fingering annotation would be a desirable
> feature in lilypond itself -- perhaps a markup flag where i request
> the standard fingering for the note, maybe some way of selecting a
> predefined alternate fingering (nice to have would be rules for
> determining prefered fingerings from the previous note, a way to
> define fingering libraries to choose from, etc).
>
> i assume that wouldn't be anyone's priority to implement, so either i
> could try to myself from within lilypond, or (my preference) i need
> some way to ask lilypond for the octave -- either an API or
> command-line program or something where i give an .ly snippet and
> lilypond gives me back the absolute pitches.
>

I can't offer any suggestions about manipulating the text file, but I hope
the following will be useful to you.

It is possible to create markups in the score through a Scheme engraver.
The one I've attached looks for a NoteHead that has had its
'display-property property set to #t.

(Aside 1:This is an invented property, and there is currently no good way
to add a property except by adding it to the codebase.  This method will
probably cause problems if you try to process a batch of files--though
removing the "symbol redefined" error will likely "fix" that.)

(Aside 2: I've thought for a long time that adding a generic marker
property to grobs would be very useful: store whatever you want in it to
act as an ID.)

This engraver prints the octave of notes in the score by way of a markup
command \placeholder, where you could substitute whatever logic goes into
making woodwind diagrams.   You'll want other info about the pitch, of
course, and there are Scheme functions for that.  See
http://lilypond.org/doc/v2.18/Documentation/internals/scheme-functions.

Best,

David
\version "2.19.10"


#(define (define-grob-custom-property symbol type? description)
   (if (not (equal? (object-property symbol 'backend-doc) #f))
       (ly:error (_ "symbol ~S redefined") symbol))

   (set-object-property! symbol 'backend-type? type?)
   (set-object-property! symbol 'backend-doc description)
   symbol)

#(define all-user-grob-custom-properties
   (map
    (lambda (x)
      (apply define-grob-custom-property x))

    `((display-fingering ,boolean? "Display woodwind fingering"))))

#(define-markup-command (placeholder layout props arg) (number?)
  (interpret-markup layout props (number->string arg)))

textToMarkedEngraver=
#(lambda (context)
   (make-engraver
    (acknowledgers
     ((note-head-interface trans grob source)
      (let* ((cause (event-cause grob))
             (p (ly:event-property cause 'pitch))
             (marked? (ly:grob-property grob 'display-fingering))
             (marked? (and (boolean? marked?) marked?)))
        (if marked?
            (let* ((t (ly:engraver-make-grob trans 'TextScript cause)))
              (ly:grob-set-property! t 'text
                #{ \markup \placeholder #(ly:pitch-octave p) #}))))))))

markAll = \override NoteHead.display-fingering = ##t
markOne = \once \markAll

%%% EXAMPLE

\relative c {
  \clef bass 
  c, \markOne c' c'
  \clef treble
  c' \markAll c' c'
}

\layout {
  \context {
    \Staff
    \consists #textToMarkedEngraver
  }
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to