Defining a macro inside another macro

One possible use for defining one
macro
inside another is to make it
act differently depending on how many times it has been called.

Suppose you want to have
pedal
on the first and third count of each
measure, but instead of having that printed for the whole song, you'd rather
just print pedal marks for a couple measures, and then say "simile."
However, for
MIDI,
you would want the pedal to apply to the entire song,
as well as both staffs, not just the one it is printed under.
One way to accomplish that is given below. A PED macro is defined.
Each time it is called, it defines another macro (ONCE, TWICE, and THRICE)
to keep track of how many times it has been called. On the third time,
it prints the "simile." In any case, if it is not doing MIDI and has not yet
reached THRICE, it prints the pedal marks. If it is doing MIDI,
it always applies pedal to both staffs.