lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Customizing ottava text


From: Thomas Morley
Subject: Re: Customizing ottava text
Date: Thu, 16 Feb 2017 21:51:49 +0100

2017-02-15 21:06 GMT+01:00 Urs Liska <address@hidden>:
> Hi all,
>
> is it really true that the text of the OttavaBracket can't be
> customized? All I could find was the doc snippet
> http://lilypond.org/doc/v2.19/Documentation/snippets/text#text-ottava-text
> which suggests to manually set Staff.ottavation after the \ottava command.
>
> With this I created a function (overwriting the built-in function)
>
> #(define ottava
>    (let ((orig-ottava ottava)
>          (numbers '("15" "8" "" "8" "15")))
>      (define-music-function (oct)(integer?)
>        #{
>          #(orig-ottava oct)
>          #(if (not (= oct 0))
>               #{
>                 \set Staff.ottavation = #(list-ref numbers (+ oct 2))
>               #})
>        #})))
>
>
> which actually does what I want (change "8va" to "8"), but I can't
> believe that it is really necessary to go that long way for a seemingly
> simple task.
>
> Any comments?
> Urs



Hi Urs,

best I can currently think of:

\version "2.19.52"

%% Define new context-property 'ottavaText'

#(define (define-translator-property symbol type? description)
  (if (not (and (symbol? symbol)
                (procedure? type?)
                (string? description)))
      (ly:error "error in call of define-translator-property"))
  (if (not (equal? (object-property symbol 'translation-doc) #f))
      (ly:error (_ "symbol ~S redefined") symbol))

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

#(for-each
  (lambda (x)
    (apply define-translator-property x))
    `((ottavaText
       ,list?
       "An alist of pairs with ottavation-number and markup.")))

%% Redefine 'make-ottava-set'
#(define (make-ottava-set music)
  "Set context properties for an ottava bracket."
  (let ((octavation (ly:music-property music 'ottava-number))
        (labels
          '((2 . "15ma")
            (1 . "8va")
            (0 . #f)
            (-1 . "8vb")
            (-2 . "15mb"))))

    (list (context-spec-music
           (make-apply-context
            (lambda (context)
              (let* ((offset (* -7 octavation))
                     (ctx-label-list
                       (ly:context-property context 'ottavaText))
                     (string
                       (assoc-get octavation
                                  (if (null? ctx-label-list)
                                      labels
                                      ctx-label-list))))
                (set! (ly:context-property context 'middleCOffset) offset)
                (set! (ly:context-property context 'ottavation) string)
                (ly:set-middle-C! context))))
           'Staff))))

%% Redefine 'ottava'
ottava =
#(define-music-function (octave) (integer?)
   (_i "Set the octavation.")
   (make-music 'OttavaMusic
               'elements-callback make-ottava-set
               'ottava-number octave))

%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLE
%%%%%%%%%%%%%%%%%%%%%

\layout {
  \context {
    \Staff
    ottavaText =
      #`((2 . ,(markup #:rounded-box "16.0"))
         (1 . "8.0")
         (0 . #f)
         (-1 . "8.0")
         (-2 . ,#{ \markup \rotate #90 "16.0" #}))
  }
}

{
    \ottava #2 c''
    \ottava #1 c''
    \ottava #0 c''
    \ottava #-1 c''
    \ottava #-2 c''
}


HTH,
  Harm



reply via email to

[Prev in Thread] Current Thread [Next in Thread]