On Tue, 2023-12-12 at 14:46 -0800, Stefano Antonelli wrote: > #(define (add-midi-to-score score) > (define (has-midi? score) > (any (lambda (x) (ly:output-def-lookup x 'is-midi)) > (ly:score-output-defs score))) > (if (has-midi? score) score > #{ \score { $score \midi {} } #})) > > toplevel-score-handler = > #(lambda (score) > (collect-scores-for-book (add-midi-to-score score)))
It seems to me, that in order to make this work, two things need to happen: 1. The whole score collection has to be traversed and \midi counted This could be done via toplevel-score-handler and some global variable. 2. If there are no midi blocks, add one. This is tricker. Assuming there is a toplevel-of-everything-handler, it would be necessary to find a score (which one though?) and then add a midi block. I took a shot at the first one: #(define midi-count 0) #(define (has-midi? score) (any (lambda (x) (ly:output-def-lookup x 'is-midi #f)) (ly:score-output-defs score))) #(define (count-midi-in-score score) (if (has-midi? score) (set! midi-count (+ midi-count 1))) score) toplevel-score-handler = #(lambda (score) (collect-scores-for-book (count-midi-in-score score))) midi-count now contains the right number. What can I do with it?