2014-12-28 4:09 GMT+01:00 Jon Arnold <jonarnoldsem...@gmail.com>:
> Hi-
>
> I have finally achieved a solution to the question I asked here:
> http://lists.gnu.org/archive/html/lilypond-user/2014-10/msg00851.html
>
> I'm doing this:
>
> measureFixer_One = {
>   \set Score.barNumberVisibility = #all-bar-numbers-visible
>   \bar ""
>   \override Score.BarNumber.stencil
>   = #(lambda (grob)(grob-interpret-markup grob
>                      #{ \markup {"1 (7)"}
>                      #}))
>   s1
> %etc.... etc...
>   \override Score.BarNumber.stencil
>   = #(lambda (grob)(grob-interpret-markup grob
>                      #{ \markup {"6 (12)"}
>                      #}))
>   \revert Score.BarNumber.stencil
>   \set Score.currentBarNumber = #13
>
>
> }
>
> The above works OK, especially because I am only doing this for <15 or so
> bars each time, but I would really like a smarter function that takes the
> currentBarNumber, adds a the difference as a parameter (in this case 6) and
> prints "n (n+x)"
>
> Part of the need is due to multiple editions (multimovement with contiguous
> bar numbers vs. single movements)
>
> Help?



Hi Jon,

a compilable example would have increased your chance to get an answer
earlier. ;)

Nevertheless, maybe the code below will work for you.
It works with different 'alternativeNumberingStyle' and line-breaks
mid-measure as well.


\version "2.19.15"
% works with 2.18. as well

#(define (add-parenthesized-alternative-bar-numbers number)
  (lambda (grob)
    (let* ((text (ly:grob-property grob 'text))
           ;; If the internals change this may fail.
           ;; Same, if custom overrides are applied before.
           (txt-arg (car (last text)))
           (current-bar-number
             (if (string->number txt-arg)
                 (string->number txt-arg)
                 ;; If BarNumber is not a single number, get a list where
                 ;; first sublist accumulates the numbers, second other stuff.
                 ;; Clear second list from brackets and transform the lists
                 ;; into strings.
                 ;; Maybe overkill ;)
                 (call-with-values
                   (lambda ()
                    (partition
                      string->number
                      (map string (string->list txt-arg))))
                   (lambda (a b)
                     (if (member "(" b)
                         (set! b
                           (filter
                             (lambda (s)
                               (and (not (string=? ")" s))
                                    (not (string=? "(" s))))
                             b)))
                     (map string-concatenate (list a b))))))
           (added-bar-number
             (if (number? current-bar-number)
                 (number->string (+ number current-bar-number))
                 (if (and (list? current-bar-number)
                          (string->number (car current-bar-number)))
                     (string-append
                       (number->string
                         (+ number (string->number (car current-bar-number))))
                       (cadr current-bar-number))
                     (begin
                       (ly:warning
                         (_ "\n\tnot smart enough to handle this BarNumber: ~a"
                            current-bar-number))
                       "?")))))
    (ly:grob-set-property! grob 'text
       #{
         \markup {
           $text
           \override #'(padding . 0.1)
           \parenthesize $added-bar-number
         }
       #}))))

newBarNumber =
#(define-music-function (parser location nmbr)(number?)
#{
  \override Score.BarNumber.before-line-breaking =
    #(add-parenthesized-alternative-bar-numbers nmbr)
#})

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\layout {
  \context {
    \Score
    \override BarNumber.self-alignment-X = #CENTER
    barNumberVisibility = #all-bar-numbers-visible
  }
}

music =
\relative c'' {
  \bar ""
  \repeat volta 3 {
    c1 \break
    <>^"Testing line-break mid-measure"
    c2 \bar "" \break c2 \break
  }
  \alternative {
    {
      <>^"Testing line-break mid-measure in an alternative ending"
      d2 \bar "" \break d2 \break
    }
    { e1 \break }
    { f1 \break }
  }
  g1
  \bar "|."
}

\header {
    title =
    \markup
      \column {
        \rounded-box
          \fill-line { "Add a parenthesized number to default BarNumber" }
        \vspace #1
      }
}

\score {
  \new Staff \music
  \layout {
    \newBarNumber #4
  }
  \header {
    piece =
    \markup
     \rounded-box
     \bold
    "Adding alternative BarNumbers, 'alternativeNumberingStyle' is not set"
  }
}

\score {
  \new Staff \music
  \layout {
    \newBarNumber #5
    \context {
      \Score
      alternativeNumberingStyle = #'numbers
    }
  }
  \header {
    piece =
    \markup
     \rounded-box
     \bold
    "Adding alternative BarNumbers, 'alternativeNumberingStyle' is set 'numbers"
  }
}

\score {
  \new Staff \music
  \layout {
    \newBarNumber #6
    \context {
      \Score
      alternativeNumberingStyle = #'numbers-with-letters
    }
  }
  \header {
    piece =
    \markup
     \rounded-box
     \bold
    "Adding alternative BarNumbers, 'alternativeNumberingStyle' is set
'numbers-with-letters"
  }
}



HTH,
  Harm

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to