Sorry, it is not working correctly yet (it does not count)....

2009/2/26 Marek Klein <ma...@gregoriana.sk>

> 2009/2/26 Reinhold Kainhofer <reinh...@kainhofer.com>
>
>>
>> It would actually be quite simple to implement: In scm/lily-library.scm in
>> the
>> print- book-with function, instead of storing the file count as a number
>> in
>> 'output-count, store it in an alist (which is set as the 'output-count
>> parser
>> variable), with the suffix as key. This way, the counting is per suffix
>> and
>> we'll automatically not append the number for the first file with a given
>> suffix...
>>
>> I think this would be quite a nice task or a frog, so I'm not coding it
>> myself, just giving a few pointers... The way to work with the alist
>> (that's
>> Scheme's idea of a Hash) can be seen e.g. in my counter snippet on LSR:
>> http://lsr.dsi.unimi.it/LSR/Item?id=543
>>
>> All you need to do is to use assoc-ref instead of count and
>> ly:parser-define!
>> (instead of the set! in the counter example) with assoc-set! to set one
>> entry
>> of the hash / alist. The key for the alist would be the suffix. The rest
>> of
>> the function doesn't even need to be changed...
>>
>> Here is my solution:
>
> (define counter-alist '())
>
> (define (print-book-with parser book process-procedure)
>   (let*
>       ((paper (ly:parser-lookup parser '$defaultpaper))
>        (layout (ly:parser-lookup parser '$defaultlayout))
>        (output-count (assoc-ref counter-alist 'output-suffix))
>        (base (ly:parser-output-name parser))
>        (output-suffix (ly:parser-lookup parser 'output-suffix)) )
>
>     (if (string? output-suffix)
>     (set! base (format "~a-~a" base (string-regexp-substitute
>                        "[^a-zA-Z0-9-]" "_" output-suffix))))
>
>     ;; must be careful: output-count is under user control.
>     (if (not (integer? output-count))
>     (set! output-count 0))
>
>     (if (> output-count 0)
>     (set! base (format #f "~a-~a" base output-count)))
>     (set! counter-alist (assoc-set! counter-alist output-suffix (1+
> output-count)))
>     (process-procedure book paper layout base)
>     ))
>
> I didn't use ly:parser-define! instead of the set! (I couldn't make it to
> work).
> The output-count variable is no more under user control this way.
>
> Please do comment.
>
> --
> Marek Klein
> http://gregoriana.sk
>



-- 
Marek Klein
http://gregoriana.sk
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to