Hi Johan,
2008/8/19 Johan Vromans <[EMAIL PROTECTED]>:
> Hi,
>
> I have a piece as follows:
>
> hiMusic = { ... }
> loMusic = { ... }
> \score {
> <<
> \new Voice = "high" { \hiMusic }
> \new Voice = "low" { \loMusic }
> >>
> }
>
> For the MIDI part, I want to add metronome ticks, something similar to
>
> ticktock = \drummode {
> \repeat unfold 94 {
> hiwoodblock 4 lowoodblock lowoodblock lowoodblock
> }
> }
> \score {
> <<
> \new Voice = "high" { \hiMusic }
> \new Voice = "low" { \loMusic }
> \new DrumVoice = "ticktock" { \ticktock }
> >>
> \midi { }
> }
>
> So far, so good. Except that, being a lazy programmer, I don't want to
> count bars, since I'm sure LilyPond knows how many bars a piece has.
> So, instead of the hard-coded 94 (in this example): is there a
> function of property that I can use instead?
Here's a quick music function which should give you a few ideas:
makeUnfold =
#(define-music-function (parser location name mus) (ly:music? ly:music?)
(let ((r (make-repeated-music "unfold")))
(set! (ly:music-property r 'element) mus)
(set! (ly:music-property r 'repeat-count)
(ly:moment-main-numerator (ly:music-length name)))
r))
ticktock = \drummode {
\makeUnfold \hiMusic {
hiwoodblock 4 lowoodblock lowoodblock lowoodblock
}
}
The important function is ly:music-length, which returns the length of
a music expression as a moment. I've cheated by only retrieving the
numerator, which will only represent the number of bars if the music
has a length which is a multiple of a semibreve/whole note. A proper
implementation would naturally work out the exact number of bars based
on the numerator and denominator.
Regards,
Neil
_______________________________________________
lilypond-user mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-user