diff --git a/orchestrallily.ily b/orchestrallily.ily index 5804d28b3dbe3d0163dc6014db6f1c5d06cd890d..b7faa07be74da50060c5ad668f9823e85724edf4 100644 --- a/orchestrallily.ily +++ b/orchestrallily.ily @@ -830,12 +830,17 @@ keepcuefilter = #(define-music-function (parser location music) (ly:music?) removecuefilter = #(define-music-function (parser location music) (ly:music?) ((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music))) - +%% The page numbers are pages counts in the pdf file, not visible page number! +%% So we have to offset them if the first page is not page #1 +%% unfortunately this means we have to store the first-page-number of the first +%% bookpart in a global variable, because in later layouts we don't have that +%% information available any more (first-page-number will be the first page +%% number of the currently processed bookpart!) +#(define oly:first-page-offset #f) #(define (oly:create-toc-file layout pages) - (let* ((label-table (ly:output-def-lookup layout 'label-page-table)) - ;; The page numbers are pages counts in the pdf file, not visible page number! - ;; So we have to offset them if the first page is not page #1 - (first-page-offset (1- (ly:output-def-lookup layout 'first-page-number)))) + (if (not oly:first-page-offset) + (set! oly:first-page-offset (1- (ly:output-def-lookup layout 'first-page-number)))) + (let* ((label-table (ly:output-def-lookup layout 'label-page-table))) (if (not (null? label-table)) (let* ((format-line (lambda (toc-item) (let* ((label (car toc-item)) @@ -843,9 +848,12 @@ removecuefilter = #(define-music-function (parser location music) (ly:music?) (label-page (and (list? label-table) (assoc label label-table))) (page (and label-page (cdr label-page)))) - (format #f "~a, section, 1, {~a}, ~a" (- page first-page-offset) text label)))) + (if page + (format #f "~a, section, 1, {~a}, ~a" (- page oly:first-page-offset) text label) + ;; label came from a different bookpart, so ignore it! + #f)))) (formatted-toc-items (map format-line (toc-items))) - (whole-string (string-join formatted-toc-items ",\n")) + (whole-string (string-join (filter (lambda (i) i) formatted-toc-items) ",\n")) (output-name (ly:parser-output-name parser)) (outfilename (format "~a.toc" output-name)) (outfile (open-output-file outfilename)))