[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Order of 'label-page-table
From: |
Thomas Morley |
Subject: |
Order of 'label-page-table |
Date: |
Thu, 25 Oct 2012 13:10:45 +0200 |
Hi,
I tried to define a markup-command which should allow to print some
markups in the page-header/footer depending on labeled pages.
It tooks me some time to identify, why it doesn't work as expected:
The 'label-page-table changes its order, if more than one label is on one page.
Heavily simplified example:
%%%%%%%%%%%%%%%%%%%%%%%%%%
\version "2.17.4"
#(define-markup-command (print-on-labeled-page layout props strg-label)
(string?)
(let* ((label (string->symbol (car (string-split strg-label #\_))))
(arg (cadr (string-split strg-label #\_))))
(ly:make-stencil
`(delay-stencil-evaluation
,(delay (ly:stencil-expr
(let* ((table (ly:output-def-lookup layout 'label-page-table)))
(newline)(display "table ")(write table)
(interpret-markup layout props arg)))))
'(0 . 9)
'(0 . 2))))
%----- test --------
\paper {
oddHeaderMarkup =
\markup \fill-line {
\box \print-on-labeled-page #"a_Adagio"
\box \print-on-labeled-page #"b_Allegro"
\box \print-on-labeled-page #"c_Andante"
}
evenHeaderMarkup =
\markup \fill-line {
\box \print-on-labeled-page #"a_Adagio"
\box \print-on-labeled-page #"b_Allegro"
\box \print-on-labeled-page #"c_Andante"
}
}
\relative c' {
\label #'a
\repeat unfold 6 { c1 \break }
\bar "|."
\pageBreak %<===================
}
\relative c' {
\label #'b
\repeat unfold 6 { d1 \break }
\bar "|."
}
\relative c' {
\label #'c
\repeat unfold 6 { e1 \break }
\bar "|."
}
%%%%%%%%%%%%%%%%%%%%%%%%%%
With the pageBreak the terminal returns:
table: ((b . 2) (c . 2) (a . 1))
I.e. the list-elements-cars doesn't match with the occurrence of the
labels, nor the reversed list.
Without pageBreak:
table: ((a . 1) (b . 1) (c . 1))
Well, I managed to order the list with some scheme-code:
%%%%%%%%%%%%%%%%%%%%%%%%%%
#(define l '((f . 4)(g . 4)(d . 3)(e . 3)(c . 2) (a . 1) (b . 1)))
#(define (split-at-equal-cdr alist)
"After `split-at-predicateĀ“ from lily-library.scm
BTW, why is it not public?
"
(if (null? alist)
(list alist)
(let ((i (list-index
(lambda (x y) (not (= (cdr x) (cdr y))))
alist
(cdr alist))))
(if i
(cons (take alist (1+ i)) (drop alist (1+ i)))
(list alist)))))
#(define (order-alist l)
(define (helper l1 l2)
(if (null? l1)
l2
(helper
(cdr (split-at-equal-cdr l1))
(append (car (split-at-equal-cdr l1)) l2))))
(helper l '()))
#(write (order-alist l))
%%%%%%%%%%%%%%%%%%%%%%%%%%
Returns: ((a . 1) (b . 1) (c . 2) (d . 3) (e . 3) (f . 4) (g . 4))
and would be ok.
Is there any reason for the default-behaviour of 'label-page-table?
If not, could it be changed easily?
Or must I postprocess the 'label-page-table with my `order-alistĀ“?
I found
// By reversing the table, we ensure that duplicated labels (eg. those
// straddling a page turn) will appear in the table with their last
// occurence first.
in page-breaking.cc, but because of my lack of C++ - knowledge, I
can't read, understand or appraise the coding.
-Harm
- Order of 'label-page-table,
Thomas Morley <=