Extracting unmodified fragments of a music expression

This snippet provides an \extractMusic function that can be used as follows:
\extractMusic music from during
For example, in the second Staff of the score below, the following has been used :
\extractMusic \music s1 s1*2
This has kept the music beginning after the first measure (i.e., at the second measure) for two measures.
All data (notes, scripts, dynamics and various \overrides) outside this range have been deleted.

Note that this function should also work with multiple voices, \repeat structures etc.

A full and updated version of \extractMusic can be found here. There are some additional useful features and other enhancement functions on that page, with a description of each of them in a small document (in pdf format) with multiple voices, \repeat structures etc.