lilypond-user
[Top][All Lists]
Advanced

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

Re: Multiple place number skip ranges


From: Thomas Morley
Subject: Re: Multiple place number skip ranges
Date: Thu, 5 May 2016 16:30:26 +0200

2016-05-05 16:18 GMT+02:00 David Nalesnik <address@hidden>:
> Hi,
>
> On Thu, May 5, 2016 at 8:53 AM, Thomas Morley <address@hidden> wrote:
>> Hi Andrew,
>>
>> 2016-05-05 5:57 GMT+02:00 Andrew Bernard <address@hidden>:
>>> David Nalesnik and various others I think have written scheme to allow you
>>> to skip a range of numbers when page numbering, or to give a direct list of
>>> page numbers to be used.
>>
>> Right now I don't remember such code. Just to refresh my memory,
>> please provide a link.
>>
>>> I want to be able to specify something like this
>>> list to only have the specified ranges printed, all in one continous score
>>> (yes, there is a use case for this!).
>>>
>>> ((1 24) (52 64) (70 80) (100 110))
>>>
>>> Of course, alternatively you could have list of ranges to skip rather than
>>> include.
>>
>>
>> How about:
>>
>> \version "2.19.36"
>>
>> #(define-markup-command
>>   (page-range-fromproperty layout props page-ranges symbol)
>>   (list? symbol?)
>>
>>   (define (my-nmbrs rngs)
>>     (append-map (lambda (e) (iota (- (last e) (- (car e) 1)) (car e) 1)) 
>> rngs))
>>
>>   (let ((m (chain-assoc-get symbol props))
>>         (page-nmbr (chain-assoc-get 'page:page-number props -1)))
>>     (if (markup? m)
>>         ;; prevent infinite loops by clearing the interpreted property:
>>         (interpret-markup
>>           layout
>>           (cons
>>             (list (cons symbol `(,property-recursive-markup ,symbol)))
>>             props)
>>           (if (and (string? m)
>>                    (number? (string->number m))
>>                    (= (string->number m) page-nmbr))
>>               (format #f "~a"
>>                 (let ((my-ranges (my-nmbrs page-ranges)))
>>                   ;; if entries from `page-ranges' are done, fall back to
>>                   ;; usual page-numbering
>>                   (if (> (length my-ranges) (1- page-nmbr))
>>                       (list-ref my-ranges (1- page-nmbr))
>>                       page-nmbr)))
>>                m))
>>         empty-stencil)))
>>
>> #(define ranges '((1 24) (52 64) (70 80) (100 110)))
>>
>> \paper {
>>   oddHeaderMarkup = \markup
>>   \fill-line {
>>     ""
>>     \on-the-fly #not-part-first-page \fromproperty #'header:instrument
>>     \on-the-fly #print-page-number-check-first
>>       \page-range-fromproperty #ranges #'page:page-number-string
>>   }
>>
>>   %% evenHeaderMarkup would inherit the value of
>>   %% oddHeaderMarkup if it were not defined here
>>   evenHeaderMarkup = \markup
>>   \fill-line {
>>     \on-the-fly #print-page-number-check-first
>>       \page-range-fromproperty #ranges #'page:page-number-string
>>     \on-the-fly #not-part-first-page \fromproperty #'header:instrument
>>     ""
>>   }
>> }
>>
>>
>> \new Staff \repeat unfold 70 { c''1 \pageBreak }
>>
>
> The reference is to
> http://www.mail-archive.com/lilypond-user%40gnu.org/msg85967.html,
> which I've adapted below to number the given ranges rather than what's
> excluded.
>
> Harm, your mail just came through, so I borrowed your my-nmbrs :)

:)

> For what it's worth::
>
> \version "2.19.30"
>
>
> #(define (my-nmbrs rngs)
>    (append-map (lambda (e) (iota (- (last e) (- (car e) 1)) (car e) 1)) rngs))

Bolied down to whats _really_ needed. Far better!

> #(define-markup-command (use-page-number-ranges layout props arg)
>    (number-list?)
>    (let ((page-number (chain-assoc-get 'page:page-number props -1)))
>      (interpret-markup layout props
>        (if (< page-number (length arg))
>            (number->string (list-ref arg (1- page-number)))
>            (chain-assoc-get 'page:page-number-string props -1)))))
>
> \paper {
>   print-first-page-number = ##t
>   print-page-number = ##t
>   oddHeaderMarkup = \markup
>   \fill-line {
>     " "
>     \on-the-fly #not-first-page \fromproperty #'header:instrument
>     \on-the-fly #print-page-number-check-first \use-page-number-ranges
>     #(my-nmbrs '((1) (3 5) (7 10)))
>   }
>   evenHeaderMarkup = \markup
>   \fill-line {
>     \on-the-fly #print-page-number-check-first \use-page-number-ranges
>     #(my-nmbrs '((1) (3 5) (7 10)))
>     \on-the-fly #not-first-page \fromproperty #'header:instrument
>     " "
>   }
> }
>
> \score {
>   \new Staff {
>     \repeat unfold 15 {
>       s1
>       \pageBreak
>     }
>   }
> }

Cheers,
  Harm



reply via email to

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