lilypond-user
[Top][All Lists]
Advanced

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

Re: Metronome ticks


From: Neil Puttock
Subject: Re: Metronome ticks
Date: Tue, 19 Aug 2008 23:44:55 +0100

Hi Johan,

2008/8/19 Johan Vromans <address@hidden>:
> 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




reply via email to

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