<< \music \repeat unfold #(floor (/ (/ (car (moment->fraction (ly:music-length music))) (cdr (moment->fraction (ly:music-length musmusic)))) 1/16)) s16 >>
EDIT: To achieve something like your example you can also do something like this:
#(define (Beat_counter_engraver context)
(let ((measpos #f) (grouping #f) (basemom #f) (beatmom #f))
(define (mom->dur mom)
(let ((pair (moment->fraction mom)))
(/ (car pair) (cdr pair))))
(define (is-beat-moment? count gping beatcount)
(if (= (* count (mom->dur basemom)) (mom->dur measpos))
(+ 1 beatcount)
(if (> (* count (mom->dur basemom)) (mom->dur measpos))
#f
(if (null? gping)
#f
(is-beat-moment? (+ count (car gping)) (cdr gping) (+ 1 beatcount))))))
(make-engraver
((process-music engraver)
(set! measpos (ly:context-property context 'measurePosition 'noof))
(set! grouping (ly:context-property context 'beatStructure 'noof))
(set! basemom (ly:context-property context 'baseMoment 'noof))
(set! beatmom (is-beat-moment? 0 grouping 0))
(if beatmom
(let ((grob (ly:engraver-make-grob engraver 'TextScript '())))
(ly:grob-set-property! grob 'text (number->string beatmom))
(ly:grob-set-property! grob 'direction DOWN)))))))
\layout {
\context {
\Dynamics
\consists #Beat_counter_engraver
\override TextScript.font-shape = ##f
\override TextScript.Y-offset = #-0.8
\consists Instrument_name_engraver
}
}
sixteenth-grid-during =
#(define-music-function (m) (ly:music?)
#{
\repeat unfold #(floor (/ (/ (car (moment->fraction (ly:music-length m))) (cdr (moment->fraction (ly:music-length m)))) 1/16)) s16
#})
\paper {
ragged-last = ##f
}
musI = {
\mark "In 3"
\time 3/8
8 8 16 r |
8 16 16 8 |
16[ 16 8 r16 16] |
4. \bar "|."
}
>
musII = {
\mark "In 4"
\time 4/8
\set Score.beatStructure = 1,1,1,1
8 16 16~ 8 r8 |
r16 16[ r16 16] r16 8.~ |
4 ~ 16 8 16 |
16 r16 4 r8 \bar "|."
}
>