lilypond-user
[Top][All Lists]
Advanced

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

Re: Creating metronome staff?


From: Ferenc Wágner
Subject: Re: Creating metronome staff?
Date: Mon, 27 Sep 2010 17:41:38 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Bajnok Kristóf <address@hidden> writes:

> I'm looking for a way to create metronome beats to a melody which has 
> variable times (4/4, 6/8, etc). Is there a function to make it 
> automatically? 

Here's what I've come up with.  Comments welcome, I'm interested how it could be
done better.

Include in your file:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#(define metronome-patterns
  '(
    ((2 . 4) . "sn4 ss")
    ((3 . 4) . "sn4 ss ss")
    ((4 . 4) . "sn4 ss ss ss")
    ((5 . 4) . "sn4 ss ss ss ss")
    ((6 . 4) . "sn4 ss ss ss ss ss")
    ((3 . 8) . "sn8 ss ss")
    ((6 . 8) . "sn8 ss ss sn ss ss")
  ))

barMapperElement = {
  \applyContext #(lambda (x)
                  (let*
                   ((pos (ly:moment-main-numerator (ly:context-property x
'measurePosition)))
                    (sig (ly:context-property x 'timeSignatureFraction)))
                   (if (= pos 0)
                    (simple-format #t "~A |\n" (assoc-ref metronome-patterns 
sig))
                  )))
  s8
}

barMapper = {
  \applyContext #(lambda (x) (set-current-output-port (open-output-file
"metronome.inc")))
  s1*0 \repeat unfold 1000 \barMapperElement
}

metronome = \drums { \include "metronome.inc" }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The s8 in barMapperElement is the granularity of the mapping, it should be small
enough to "hit" the first moment of every bar. The repeat count 1000 in
barMapper should be big enough to span the piece, the length of the generated
metronome "music" is this count times the length of barMapperElement.

Use this by making barMapper and metronome parallel to your music, for example
if you have

\score {
  \unfoldRepeats
  \music
  \midi { }
}

then change it to

\score {
  \unfoldRepeats
  << \music \barMapper \metronome >>
  \midi { }
}

barMapper will create an empty staff and at the same time write out a file
called "metronome.inc", which is included by metronome on the next Lilypond run.
(You'll get an error about "metronome.inc" missing on the first run.)
You can get rid of barMapper in the end, but it's mostly useful for midi output,
where an empty staff does not matter.

I'd be interested to learn how this could be done in a single Lilypond run,
without generating an intermediate file.
-- 
Regards,
Feri.




reply via email to

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