[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Manual bar number visibility
From: |
Thomas Morley |
Subject: |
Re: Manual bar number visibility |
Date: |
Tue, 8 Jul 2014 03:58:32 +0200 |
2014-07-08 1:54 GMT+02:00 Dan Eble <address@hidden>:
> On Jul 7, 2014, at 06:10 , Thomas Morley <address@hidden> wrote:
>
>> I've still 2.12.3 installed and could do some testing.
>> All I can say right now is, that 'visibleBarNumbers is not a valid
>> context-property and it wasn't in 2.12.3 as well.
>
> Valid or not, it solved a problem and worked for years. Is there a way to
> make 2.18 let me set this property, or is there another way that I can store
> and retrieve my own score-level information? I have other functions that are
> producing similar warnings. A full example follows.
>
> Thanks,
> —
> Dan
[...]
The following seems to work (though, it's in the middle of the night
here, can't think anymore ..)
\version "2.19.8"
#(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))
`((visibleBarNumbers
,hash-table?
"what-ever-description")
))
barNumber =
#(define-music-function (parser location) ()
(let ((m (make-music 'ApplyContext)))
(define (force-bar-number ctx)
(let* ((barnum-table (ly:context-property ctx 'visibleBarNumbers)))
(if (not (hash-table? barnum-table)) ; first use in this score?
(begin
; create the set of visible bar numbers
(set! barnum-table (make-hash-table 16))
(ly:context-set-property! ctx 'visibleBarNumbers barnum-table)))
(let* ((barnum (ly:context-property ctx 'currentBarNumber))
(measurePos (ly:context-property ctx 'measurePosition))
(measureLen (ly:context-property ctx 'measureLength))
(mid-measure (and (ly:moment<? ZERO-MOMENT measurePos)
(ly:moment<? measurePos measureLen))))
(if mid-measure
(set! barnum (1+ barnum)))
(hash-set! barnum-table barnum #t)
)))
(set! (ly:music-property m 'procedure) force-bar-number)
(context-spec-music m 'Score)))
manualBarNumbersOn =
#(define-music-function (parser location) ()
(define (set-properties ctx)
(let ()
; this special formatter is necessary for string->number to
; work in the visibility callback below
(define (bar-number-formatter barnum measure-pos alt-number ctx)
(number->string barnum))
(define (bar-number-break-visibility-callback grob)
(let ((barnum-table (ly:context-property ctx 'visibleBarNumbers))
(barnum (string->number (ly:grob-property grob 'text))))
(if (and (hash-table? barnum-table)
(hash-ref barnum-table barnum))
end-of-line-invisible
begin-of-line-visible
)))
(ly:context-set-property! ctx 'barNumberFormatter bar-number-formatter)
(ly:context-pushpop-property ctx 'BarNumber 'break-visibility
bar-number-break-visibility-callback)
))
(context-spec-music (make-apply-context set-properties) 'Score))
% Encourage a line break in the music.
% This is intended to mark the end of a line of lyrics.
meterBreak =
{
\overrideProperty Timing.NonMusicalPaperColumn.line-break-penalty #-1 % 2.18.2
\bar ""
\barNumber
}
\new Staff {
\manualBarNumbersOn
\relative d' {
\time 3/4
\partial 4
d4 | g2 b4 | b2 a4 | g2 e4 | d2 \meterBreak
d4 | g2 b4 | b2 a4 | d2 \meterBreak \break % N.B.
d4 | d2 b4 | g2 d4 | e2 g4 | d2 \meterBreak
d4 | g2 b4 | b2 a4 | g2 \bar "|."
}
}
HTH,
Harm