<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.lilypond.community/index.php?action=history&amp;feed=atom&amp;title=Extracting_unmodified_fragments_of_a_music_expression</id>
	<title>Extracting unmodified fragments of a music expression - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.lilypond.community/index.php?action=history&amp;feed=atom&amp;title=Extracting_unmodified_fragments_of_a_music_expression"/>
	<link rel="alternate" type="text/html" href="https://wiki.lilypond.community/index.php?title=Extracting_unmodified_fragments_of_a_music_expression&amp;action=history"/>
	<updated>2026-06-19T16:37:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.lilypond.community/index.php?title=Extracting_unmodified_fragments_of_a_music_expression&amp;diff=4844&amp;oldid=prev</id>
		<title>Lemzwerg: New category</title>
		<link rel="alternate" type="text/html" href="https://wiki.lilypond.community/index.php?title=Extracting_unmodified_fragments_of_a_music_expression&amp;diff=4844&amp;oldid=prev"/>
		<updated>2025-11-21T23:33:51Z</updated>

		<summary type="html">&lt;p&gt;New category&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 23:33, 21 November 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l165&quot;&gt;Line 165:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 165:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Scheme]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Scheme]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Preparing parts]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Preparing parts]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Really cool]][[Category:Snippet]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Really cool]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Snippet]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Lemzwerg</name></author>
	</entry>
	<entry>
		<id>https://wiki.lilypond.community/index.php?title=Extracting_unmodified_fragments_of_a_music_expression&amp;diff=3473&amp;oldid=prev</id>
		<title>Lemzwerg at 22:52, 21 November 2025</title>
		<link rel="alternate" type="text/html" href="https://wiki.lilypond.community/index.php?title=Extracting_unmodified_fragments_of_a_music_expression&amp;diff=3473&amp;oldid=prev"/>
		<updated>2025-11-21T22:52:43Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 22:52, 21 November 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l165&quot;&gt;Line 165:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 165:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Scheme]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Scheme]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Preparing parts]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Preparing parts]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Really cool]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Really cool&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;]][[Category:Snippet&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Lemzwerg</name></author>
	</entry>
	<entry>
		<id>https://wiki.lilypond.community/index.php?title=Extracting_unmodified_fragments_of_a_music_expression&amp;diff=2592&amp;oldid=prev</id>
		<title>Jean Abou Samra: Replace version=&quot;2.24.0&quot; with version=&quot;2.24&quot; now that the LilyWiki extension supports auto-selecting the latest release in a stable series</title>
		<link rel="alternate" type="text/html" href="https://wiki.lilypond.community/index.php?title=Extracting_unmodified_fragments_of_a_music_expression&amp;diff=2592&amp;oldid=prev"/>
		<updated>2025-11-16T18:53:03Z</updated>

		<summary type="html">&lt;p&gt;Replace version=&amp;quot;2.24.0&amp;quot; with version=&amp;quot;2.24&amp;quot; now that the LilyWiki extension supports auto-selecting the latest release in a stable series&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 18:53, 16 November 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l12&quot;&gt;Line 12:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 12:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A full and updated version of &amp;lt;code&amp;gt;\extractMusic&amp;lt;/code&amp;gt; can be found [http://gillesth.free.fr/Lilypond/extractMusic/ 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, &amp;lt;code&amp;gt;\repeat&amp;lt;/code&amp;gt; structures etc.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A full and updated version of &amp;lt;code&amp;gt;\extractMusic&amp;lt;/code&amp;gt; can be found [http://gillesth.free.fr/Lilypond/extractMusic/ 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, &amp;lt;code&amp;gt;\repeat&amp;lt;/code&amp;gt; structures etc.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;lilypond version=&quot;2.24&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.0&lt;/del&gt;&quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;lilypond version=&quot;2.24&quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;%% http://lsr.di.unimi.it/LSR/Item?id=542&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;%% http://lsr.di.unimi.it/LSR/Item?id=542&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Jean Abou Samra</name></author>
	</entry>
	<entry>
		<id>https://wiki.lilypond.community/index.php?title=Extracting_unmodified_fragments_of_a_music_expression&amp;diff=288&amp;oldid=prev</id>
		<title>Jean Abou Samra: Import snippet from LSR</title>
		<link rel="alternate" type="text/html" href="https://wiki.lilypond.community/index.php?title=Extracting_unmodified_fragments_of_a_music_expression&amp;diff=288&amp;oldid=prev"/>
		<updated>2025-10-26T22:39:31Z</updated>

		<summary type="html">&lt;p&gt;Import snippet from LSR&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This snippet provides an &amp;lt;code&amp;gt;\extractMusic&amp;lt;/code&amp;gt; function that can be used as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;code&amp;gt;\extractMusic music from during&amp;lt;/code&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
For example, in the second Staff of the score below, the following has been used :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;code&amp;gt;\extractMusic \music s1 s1*2&amp;lt;/code&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
This has kept the music beginning after the first measure (i.e., at the second measure) for two measures.&amp;lt;br /&amp;gt;&lt;br /&gt;
All data (notes, scripts, dynamics and various &amp;lt;code&amp;gt;\override&amp;lt;/code&amp;gt;s) outside this range have been deleted.&lt;br /&gt;
&lt;br /&gt;
Note that this function should also work with multiple voices, &amp;lt;code&amp;gt;\repeat&amp;lt;/code&amp;gt; structures etc.&lt;br /&gt;
&lt;br /&gt;
A full and updated version of &amp;lt;code&amp;gt;\extractMusic&amp;lt;/code&amp;gt; can be found [http://gillesth.free.fr/Lilypond/extractMusic/ 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, &amp;lt;code&amp;gt;\repeat&amp;lt;/code&amp;gt; structures etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;lilypond version=&amp;quot;2.24.0&amp;quot;&amp;gt;&lt;br /&gt;
%% http://lsr.di.unimi.it/LSR/Item?id=542&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#(use-modules (srfi srfi-39))&lt;br /&gt;
&lt;br /&gt;
#(define *current-moment* (make-parameter (ly:make-moment 0/1 0/1)))&lt;br /&gt;
&lt;br /&gt;
#(define moment-null (ly:make-moment 0/1 0/1))&lt;br /&gt;
&lt;br /&gt;
#(define (music-has-no-length? music)&lt;br /&gt;
  &amp;quot;Is music empty of notes, rests or skips?&amp;quot;&lt;br /&gt;
  (equal? (ly:music-length music) moment-null))&lt;br /&gt;
&lt;br /&gt;
#(define (simultaneous? music)&lt;br /&gt;
  (memq (ly:music-property music &amp;#039;name)&lt;br /&gt;
    (list &amp;#039;SimultaneousMusic &amp;#039;EventChord)))&lt;br /&gt;
&lt;br /&gt;
#(define (defined-music? music)&lt;br /&gt;
  (not (eq? &amp;#039;Music (ly:music-property music &amp;#039;name))))&lt;br /&gt;
&lt;br /&gt;
#(define (chord-event? music)&lt;br /&gt;
  (eq? &amp;#039;EventChord (ly:music-property music &amp;#039;name)))&lt;br /&gt;
&lt;br /&gt;
#(define (get-duration music)&lt;br /&gt;
  (ly:music-property music &amp;#039;duration))&lt;br /&gt;
&lt;br /&gt;
#(define (moment&amp;gt;=? momentA momentB)&lt;br /&gt;
  (not (ly:moment&amp;lt;? momentA momentB)))&lt;br /&gt;
&lt;br /&gt;
#(define (moment-inside? moment from-moment to-moment)&lt;br /&gt;
  (and&lt;br /&gt;
    (moment&amp;gt;=? moment from-moment)&lt;br /&gt;
    (ly:moment&amp;lt;? moment to-moment)))&lt;br /&gt;
&lt;br /&gt;
#(define (whole-music-inside? begin-music end-music left-range right-range)&lt;br /&gt;
  (and&lt;br /&gt;
    (moment&amp;gt;=? begin-music left-range)&lt;br /&gt;
    (moment&amp;gt;=? right-range end-music )&lt;br /&gt;
    (not (equal? begin-music right-range))))&lt;br /&gt;
&lt;br /&gt;
#(define (whole-music-outside? begin-music end-music left-range right-range)&lt;br /&gt;
  (or&lt;br /&gt;
    (moment&amp;gt;=? left-range end-music)&lt;br /&gt;
    (moment&amp;gt;=? begin-music right-range)))&lt;br /&gt;
&lt;br /&gt;
#(define (moment-&amp;gt;duration moment)&lt;br /&gt;
  ;see duration.cc in Lilypond sources (Duration::Duration)&lt;br /&gt;
  (let* ((p (ly:moment-main-numerator moment))&lt;br /&gt;
         (q (ly:moment-main-denominator moment))&lt;br /&gt;
         (k (- (ly:intlog2 q) (ly:intlog2 p)))&lt;br /&gt;
         (dots 0))&lt;br /&gt;
   ;(ash p k) = p * 2^k&lt;br /&gt;
   (if (&amp;lt; (ash p k) q) (set! k (1+ k)))&lt;br /&gt;
   (set! p (- (ash p k) q))&lt;br /&gt;
   (while (begin (set! p (ash p 1))(&amp;gt;= p q))&lt;br /&gt;
    (set! p (- p q))&lt;br /&gt;
    (set! dots (1+ dots)))&lt;br /&gt;
   (if (&amp;gt; k 6)&lt;br /&gt;
    (ly:make-duration 6 0)&lt;br /&gt;
    (ly:make-duration k dots))&lt;br /&gt;
))&lt;br /&gt;
&lt;br /&gt;
#(define (extract-music music from to)&lt;br /&gt;
  &amp;quot;Keeps only music between `from&amp;#039; and `to&amp;#039;, `from&amp;#039; and `to&amp;#039; as moment&amp;quot;&lt;br /&gt;
  (let ((begin-pos (*current-moment*))&lt;br /&gt;
        (end-pos (ly:moment-add&lt;br /&gt;
                   (*current-moment*)&lt;br /&gt;
                   (ly:music-length music))))&lt;br /&gt;
   (cond&lt;br /&gt;
    ((whole-music-inside? begin-pos end-pos from to)&lt;br /&gt;
      (*current-moment* end-pos)&lt;br /&gt;
      music)&lt;br /&gt;
    ((whole-music-outside? begin-pos end-pos from to)&lt;br /&gt;
      (*current-moment* end-pos)&lt;br /&gt;
      (make-music &amp;#039;Music))&lt;br /&gt;
    ; the intervals [begin-pos end-pos] [from to] overlap&lt;br /&gt;
    (else&lt;br /&gt;
    (cond&lt;br /&gt;
    ; inside a chords or for multiRest events&lt;br /&gt;
    ((ly:duration? (get-duration music))&lt;br /&gt;
      (if (moment-inside? begin-pos from to)&lt;br /&gt;
        (set! end-pos to)&lt;br /&gt;
        (begin&lt;br /&gt;
          (set! begin-pos from)&lt;br /&gt;
          (if (not (moment-inside? end-pos from to))(set! end-pos to))))&lt;br /&gt;
      (ly:music-set-property! music &amp;#039;duration &lt;br /&gt;
          (moment-&amp;gt;duration  (ly:moment-sub end-pos begin-pos)))&lt;br /&gt;
      (*current-moment* end-pos)&lt;br /&gt;
      music)&lt;br /&gt;
    (else     ; for containers of chords&lt;br /&gt;
      (let ((elts (ly:music-property music &amp;#039;elements))&lt;br /&gt;
          (elt  (ly:music-property music &amp;#039;element)))&lt;br /&gt;
        (if (ly:music? elt)&lt;br /&gt;
        (ly:music-set-property! music &amp;#039;element (extract-music elt from to)))&lt;br /&gt;
        (if (pair? elts) &lt;br /&gt;
        (cond  &lt;br /&gt;
          ((simultaneous? music)    ; simultaneous music OR EventChords&lt;br /&gt;
          (ly:music-set-property! music &amp;#039;elements (filter&lt;br /&gt;
            (lambda (evt)&lt;br /&gt;
              (or (music-has-no-length? evt) ; i.e for &amp;#039;VoiceSeparator&lt;br /&gt;
                (begin&lt;br /&gt;
                  (*current-moment* begin-pos)  ; restore *current-moment*&lt;br /&gt;
                  (set! evt (extract-music evt from to))&lt;br /&gt;
                  (defined-music? evt)))) ; keeps if not (make-music &amp;#039;Music)&lt;br /&gt;
            elts))&lt;br /&gt;
          (*current-moment* end-pos))&lt;br /&gt;
         (else              ; sequential music&lt;br /&gt;
          (ly:music-set-property! music &amp;#039;elements (filter&lt;br /&gt;
            (lambda (evt)&lt;br /&gt;
              (set! evt (extract-music evt from to))&lt;br /&gt;
              (defined-music? evt))&lt;br /&gt;
            elts)))))&lt;br /&gt;
        music)))))))&lt;br /&gt;
&lt;br /&gt;
%%%%%%%%%%%%%%%%%%%%%% the main function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
extractMusic =&lt;br /&gt;
#(define-music-function (music from during) (ly:music? ly:music? ly:music?)&lt;br /&gt;
  (let* ((from-length (ly:music-length from))&lt;br /&gt;
         (during-length (ly:music-length during))&lt;br /&gt;
         (to-length (ly:moment-add during-length from-length)))&lt;br /&gt;
    (parameterize ((*current-moment* (ly:make-moment 0/1 0/1)))&lt;br /&gt;
                  (extract-music music from-length to-length))))&lt;br /&gt;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
&lt;br /&gt;
music = \relative c&amp;#039; {&lt;br /&gt;
  \override Staff.NoteHead.color = #blue&lt;br /&gt;
  &amp;lt;c e&amp;gt;4-- d\&amp;lt; \tuplet 3/2 { e8 f g } a8^&amp;quot;a text&amp;quot; c\!&lt;br /&gt;
  b8 c b a^&amp;quot;another text&amp;quot; &amp;lt;&amp;lt; { g4 f8 e } \\ { e4 d8 c } &amp;gt;&amp;gt;&lt;br /&gt;
  \override Voice.NoteHead.color = #green&lt;br /&gt;
  d2 g&lt;br /&gt;
  \override Voice.NoteHead.color = #red&lt;br /&gt;
  g16 a g f e8 d c2&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
\score {&lt;br /&gt;
  &amp;lt;&amp;lt;&lt;br /&gt;
    \new Staff \new Voice {&lt;br /&gt;
      \music&lt;br /&gt;
      c&amp;#039;1&lt;br /&gt;
    } &lt;br /&gt;
    \new Staff \new Voice {&lt;br /&gt;
      s1&lt;br /&gt;
      \extractMusic \music  s1 s1*2&lt;br /&gt;
      s1&lt;br /&gt;
      c&amp;#039;1&lt;br /&gt;
    }&lt;br /&gt;
  &amp;gt;&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/lilypond&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Scheme]]&lt;br /&gt;
[[Category:Preparing parts]]&lt;br /&gt;
[[Category:Really cool]]&lt;/div&gt;</summary>
		<author><name>Jean Abou Samra</name></author>
	</entry>
</feed>