lilypond-devel
[Top][All Lists]
Advanced

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

exact inversion (issue4173065)


From: benko . pal
Subject: exact inversion (issue4173065)
Date: Sat, 19 Feb 2011 12:03:22 +0000

Reviewers: ,

Message:
following up on modal transformation

Description:
exact inversion

Please review this at http://codereview.appspot.com/4173065/

Affected files:
  M Documentation/notation/pitches.itely
  M input/regression/modal-transforms.ly
  M ly/music-functions-init.ly
  M scm/modal-transforms.scm


Index: Documentation/notation/pitches.itely
diff --git a/Documentation/notation/pitches.itely b/Documentation/notation/pitches.itely index 78a222794d195e9ceae5c812971e5f6b2357a824..63c0ccce39465edcb1896eaa7e2940782e6fc002 100644
--- a/Documentation/notation/pitches.itely
+++ b/Documentation/notation/pitches.itely
@@ -594,6 +594,7 @@ This section discusses how to modify pitches.
 @menu
 * Octave checks::
 * Transpose::
+* Inversion::
 * Modal transformations::
 @end menu

@@ -813,6 +814,23 @@ 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}.

address@hidden Inversion
address@hidden Inversion
+
address@hidden inversion
+
+A music expression can be inverted with @code{\inversion}.
+The syntax is
+
address@hidden
+\inversion @var{frompitch} @var{topitch} @var{musicexpr}
address@hidden example
+
address@hidden
+This means that @address@hidden is inverted interval by
+interval, and transposition is chosen so that @address@hidden
+is mapped to @address@hidden
+
 @node Modal transformations
 @unnumberedsubsubsec Modal transformations

Index: input/regression/modal-transforms.ly
diff --git a/input/regression/modal-transforms.ly b/input/regression/modal-transforms.ly index 907060151073b9e77e147a19b120bfae8350b3ae..7487f2b8bfe34d6cf1752fa8e244f6b50439f704 100644
--- a/input/regression/modal-transforms.ly
+++ b/input/regression/modal-transforms.ly
@@ -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: ly/music-functions-init.ly
diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly
index 34261c114b2d7f3e9606fa50c2d4f95bb0e7d869..ac62bffa9ae67575da8bbce6e60ec12fd8d18595 100644
--- a/ly/music-functions-init.ly
+++ b/ly/music-functions-init.ly
@@ -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: scm/modal-transforms.scm
diff --git a/scm/modal-transforms.scm b/scm/modal-transforms.scm
index cdaa015ccc08099c251c51304ece2c77a66c61d9..151fb8c3be06edcea7e213291989398428d43fea 100644
--- a/scm/modal-transforms.scm
+++ b/scm/modal-transforms.scm
@@ -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)))
+





reply via email to

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