]> git.donarmstrong.com Git - lilypond.git/commitdiff
Add exact inversion
authorBenk Pl <benko.pal@gmail.com>
Tue, 22 Feb 2011 11:26:05 +0000 (11:26 +0000)
committerTrevor Daniels <t.daniels@treda.co.uk>
Tue, 22 Feb 2011 12:43:08 +0000 (12:43 +0000)
Documentation/notation/pitches.itely
input/regression/modal-transforms.ly
ly/music-functions-init.ly
scm/modal-transforms.scm

index 78a222794d195e9ceae5c812971e5f6b2357a824..4ee236cfda8e61d7045598ec2d5a60fa1496f598 100644 (file)
@@ -594,6 +594,7 @@ This section discusses how to modify pitches.
 @menu
 * Octave checks::
 * Transpose::
+* Inversion::
 * Modal transformations::
 @end menu
 
@@ -813,6 +814,22 @@ The relative conversion will not affect @code{\transpose},
 To use relative mode within transposed music, an additional
 @code{\relative} must be placed inside @code{\transpose}.
 
+@node Inversion
+@unnumberedsubsubsec Inversion
+
+@cindex inversion
+
+A music expression can be inverted with @code{\inversion}.
+
+@example
+\inversion @var{frompitch} @var{topitch} @var{musicexpr}
+@end example
+
+@noindent
+This means that @code{@var{musicexpr}} is inverted
+interval-by-interval, and transposition is chosen so that
+@code{@var{frompitch}} is mapped to @code{@var{topitch}}.
+
 @node Modal transformations
 @unnumberedsubsubsec Modal transformations
 
index 907060151073b9e77e147a19b120bfae8350b3ae..7487f2b8bfe34d6cf1752fa8e244f6b50439f704 100644 (file)
@@ -22,12 +22,14 @@ motif = {
         \modalTranspose c' f' \cOctatonicScale \motif
         \retrograde \motif
         \modalInversion aes' b' \cOctatonicScale \motif
+       \inversion aes' b' \motif
       }
       {
         s1-"Octatonic motif" |
         s1-"motif transposed from c to f" |
         s1-"motif in retrograde" |
         s1-"motif inverted around aes to b" |
+       s1-"motif inverted exactly"
       }
     >>
   }
index 34261c114b2d7f3e9606fa50c2d4f95bb0e7d869..ac62bffa9ae67575da8bbce6e60ec12fd8d18595 100644 (file)
@@ -480,6 +480,13 @@ using @var{scale}.")
       (change-pitches music transposer)
       music))
 
+inversion =
+#(define-music-function
+   (parser location around to music) (ly:music? ly:music? ly:music?)
+   (_i "Invert @var{music} about @var{around} and
+transpose from @var{around} to @var{to}.")
+   (music-invert around to music))
+
 musicMap =
 #(define-music-function (parser location proc mus) (procedure? ly:music?)
    (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
index cdaa015ccc08099c251c51304ece2c77a66c61d9..151fb8c3be06edcea7e213291989398428d43fea 100644 (file)
@@ -220,3 +220,20 @@ Typically used to construct a scale for input to transposer-factory
     (map retrograde-music reversed)
 
     music))
+
+(define-public (pitch-invert around to music)
+  "If @var{music} is a single pitch, inverts it about @var{around}
+and transposes from @var{around} to @var{to}."
+  (let ((p (ly:music-property music 'pitch)))
+    (if (ly:pitch? p)
+       (ly:music-set-property!
+        music 'pitch
+        (ly:pitch-transpose to (ly:pitch-diff around p))))
+    music))
+
+(define-public (music-invert around-pitch to-pitch music)
+  "Applies pitch-invert to all pitches in @var{music}."
+  (let ((around (car (extract-pitch-sequence around-pitch)))
+       (to (car (extract-pitch-sequence to-pitch))))
+     (music-map (lambda (x) (pitch-invert around to x)) music)))
+