lilypond-user
[Top][All Lists]
Advanced

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

Re: measure numbers with letters


From: Thomas Morley
Subject: Re: measure numbers with letters
Date: Sun, 23 Jul 2017 12:22:27 +0200

2017-07-23 6:49 GMT+02:00 Paul Scott <address@hidden>:
> On Sat, Jul 22, 2017 at 05:25:30PM -0700, madMuze wrote:
>> Simon Albrecht-2 wrote
>> > {
>> >    c'1 \break
>> >    \once\override Score.BarNumber.text = "1A"
>> >    c'
>> > }
>> > does not work
>>
>> In 2.18, I use
>>
>> barNrSffx = #(define-music-function (parser location sffx lastNr) (string?
>> number?)
>>  #{
>>   \override Score.BarNumber.before-line-breaking = #(lambda (grob)
>>    (let*
>>     ( (barNrTxt (caadr (ly:grob-property grob 'text)))
>>      (barNr  (string->number barNrTxt))
>>      (barNrStr (string-append barNrTxt sffx)) )
>>     (ly:grob-set-property! grob 'text (if (or (<= barNr lastNr)
>>                     (= lastNr 0) )
>>                  barNrStr
>>                  barNrTxt )) ) )
>>  #}
>> )
>>
>> in use::
>> % music for mm1-16, for instance, then
>> \set Score.currentBarNumber = 1
>> \barNrSffx "bis"  16 % mm1-16 again with ornaments; bar number will read
>> "2bis", &c.
>> % m17 follows and will be numbered "17" (with no suffix)
>>
>> Perhaps this gives you a start. I think the tricky part is using "caadr" to
>> find the current BarNumber.text so it can be reused. I'm sure many people
>> with better knowledge and skills can improve upon this...
>
> Thank you!
>
> This at least gives me code that works for my purpose!
>
> For me it would seem that your 2nd argument/parameter wouldn't be necessary
> since I always want to modify the text of the previous bar number.
>
> Thank you again,
>
> Paul



Hi Paul,

here my own approach (extending the default 'robust-bar-number-function')

\version "2.19.64"

#(define* ((my-robust-bar-number-function #:optional (fixed #f))
             barnum measure-pos alt-number context)
  (define strg " abcdefghijklmnopqrstuvwxyz")
  (define (get-number-and-power an pow)
    (if (<= an alt-number)
        (get-number-and-power (+ an (expt 26 (1+ pow))) (1+ pow))
        (cons (+ alt-number (- (expt 26 pow) an)) (1- pow))))
  (define (make-letter so-far an pow)
    (if (< pow 0)
        so-far
        (let ((pos (modulo (quotient an (expt 26 pow)) 26)))
          (make-letter (string-append so-far
                                      (substring (string-drop strg 1)
                                                 pos
                                                 (1+ pos)))
                       an
                       (1- pow)))))
  (let* ((number-and-power (get-number-and-power 0 0))
         (begin-measure (= 0 (ly:moment-main-numerator measure-pos)))
         (maybe-open-parenthesis (if begin-measure "" "("))
         (maybe-close-parenthesis (if begin-measure "" ")")))
    (markup
      (string-append
        maybe-open-parenthesis
        (number->string (if (number? fixed) fixed barnum))
        (cond
          ((not (number? fixed))
            "")
          ((and (number? fixed) (< (- barnum fixed) 27))
            (string-capitalize (string (string-ref strg (- barnum fixed)))))
          (else
            (begin
              (ly:warning
                "Requested letter-number exceeds the alphabet: ~a, ignoring."
                (- barnum fixed))
              "")))
        (make-letter ""
                     (car number-and-power)
                     (cdr number-and-power))
        maybe-close-parenthesis))))

keepBarNumberWithLetters =
  \context Score
  \applyContext
  #(lambda (context)
    (let ((static-bar (ly:context-property context 'currentBarNumber)))
      (ly:context-set-property! context
        'barNumberFormatter (my-robust-bar-number-function static-bar))))

defaultBarNumbers =
  \set Score.barNumberFormatter = #robust-bar-number-function

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

\layout {
  \context {
    \Score
    %% For testing. Those settings shouldn't have any impact on the
    %% barNumberFormatter
    \override BarNumber.break-visibility = ##(#f #t #t)
    barNumberVisibility = #first-bar-number-invisible-save-broken-bars
    alternativeNumberingStyle = #'numbers-with-letters
  }
}

{
  c'1  c'
  \keepBarNumberWithLetters
  c' c' c'2 \bar "" \break c'2
  \repeat volta 2 { c'1 } \alternative { { cis'1 } { ces'1 } }
  %% NB
  %% Only the letters of the alphabet plus space are available.
  %% Exceeding those will be ignored and a warning issued.
  %\repeat unfold 25 c'1
  \keepBarNumberWithLetters
  c'1  c'
  \defaultBarNumbers
  c' c' c'
}


HTH,
  Harm



reply via email to

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