[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Manual bar number visibility
From: |
Dan Eble |
Subject: |
Re: Manual bar number visibility |
Date: |
Mon, 7 Jul 2014 19:54:51 -0400 |
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
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.16.1
% \overrideProperty Timing.NonMusicalPaperColumn.line-break-penalty #-1 %
2.18.2
\bar ""
\barNumber
}
% 2.12.3 prints bar numbers 5, 8, and 12 without complaint.
%
% 2.16.1 prints bar numbers 5, 8, and 12 and complains
% warning: cannot find property type-check for `visibleBarNumbers'
% (translation-type?). perhaps a typing error?
% warning: doing assignment anyway
%
% 2.18.2 does not print any bar numbers and complains
% warning: cannot find property type-check for `visibleBarNumbers'
% (translation-type?). perhaps a typing error?
% warning: skipping assignment
\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
d4 | d2 b4 | g2 d4 | e2 g4 | d2 \meterBreak
d4 | g2 b4 | b2 a4 | g2 \bar "|."
}
}