]> git.donarmstrong.com Git - lilypond.git/commitdiff
patch::: 1.3.134.jcn2
authorJan Nieuwenhuizen <janneke@gnu.org>
Sun, 4 Mar 2001 12:18:09 +0000 (13:18 +0100)
committerJan Nieuwenhuizen <janneke@gnu.org>
Sun, 4 Mar 2001 12:18:09 +0000 (13:18 +0100)
1.3.134.jcn2
============

* Bugfix: Pitch::transpose ().

CHANGES
VERSION
lily/include/pitch.hh
lily/pitch.cc

diff --git a/CHANGES b/CHANGES
index 9e07294723af4e70b434ab8152d486811c8382f8..840c7d94059ad9be453d53b41eb88e13516d763b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+1.3.134.jcn2
+============
+
+* Bugfix: Pitch::transpose ().
+
 1.3.134.jcn1
 ============
 
diff --git a/VERSION b/VERSION
index 6ae3d034b5a4aa5681653ca7a6e552cb46fff2b4..be95c2efe64055a612306643c450ef1832f7064c 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond
 MAJOR_VERSION=1
 MINOR_VERSION=3
 PATCH_LEVEL=134
-MY_PATCH_LEVEL=jcn1
+MY_PATCH_LEVEL=jcn2
 
 # use the above to send patches: MY_PATCH_LEVEL is always empty for a
 # released version.
index cd478d250f54413143bca96fc55ad12a4b2f98f2..25b576f4c0436fd1109fc3601e29a36544f60248 100644 (file)
@@ -46,6 +46,7 @@ public:
   int notename_i () const;
   int alteration_i () const;
 
+  void normalise ();
   /*
     Pitch is lexicographically ordered by (octave, notename,
     alteration).    
index bbe75c3893b25b7059c989e172b47a6319f1ac5b..17f6b0f5008761a625d2c9634c5f306cdb9af904 100644 (file)
@@ -27,6 +27,7 @@ Pitch::Pitch (int o, int n, int a)
       s += ", notename = " + to_str (n);
       warning (s);
     }
+  normalise ();
 }
 
 Pitch::Pitch ()
@@ -63,44 +64,89 @@ Pitch::steps () const
  */
 static Byte pitch_byte_a[  ] = { 0, 2, 4, 5, 7, 9, 11 };
 
+int
+sign_safe_div (int n, int d)
+{
+  if (n < 0)
+     return - (-n / d) - 1;
+  return n / d;
+}
+
+/* Calculate pitch height in 12th octave steps.  Don't assume
+   normalised pitch as this function is used to normalise the pitch.  */
 int
 Pitch::semitone_pitch () const
 {
-  return  pitch_byte_a[ notename_i_ % 7 ] + alteration_i_ + octave_i_ * 12;
+  return (octave_i_ + sign_safe_div (notename_i_, 7)) * 12
+    + pitch_byte_a[notename_i_ % 7]
+    + alteration_i_;
+}
+
+void
+Pitch::normalise ()
+{
+  int pitch = semitone_pitch ();
+  while (notename_i_ >= 7)
+    {
+      notename_i_ -= 7;
+      octave_i_++;
+      alteration_i_ -= semitone_pitch () - pitch;
+    }
+  while (notename_i_ < 0)
+    {
+      notename_i_ += 7;
+      octave_i_--;
+      alteration_i_ -= semitone_pitch () - pitch;
+    }
+  while (alteration_i_ >= 3)
+    {
+      if (notename_i_ == 6)
+       {
+         notename_i_ = 0;
+         octave_i_++;
+       }
+      else
+       notename_i_++;
+
+      alteration_i_ = 0;
+      alteration_i_ -= semitone_pitch () - pitch;
+    }
+  while (alteration_i_ <= -3)
+    {
+      if (notename_i_ == 0)
+       {
+         notename_i_ = 6;
+         octave_i_--;
+       }
+      else
+       notename_i_--;
+
+      alteration_i_ = 0;
+      alteration_i_ -= semitone_pitch () - pitch;
+    }
 }
 
 /* WHugh, wat een intervaas */
 void
 Pitch::transpose (Pitch delta)
 {
-  int old_pitch = semitone_pitch ();
-  int delta_pitch = delta.semitone_pitch ();
+  int old_semi = semitone_pitch ();
+  int delta_semi = delta.semitone_pitch ();
   octave_i_ += delta.octave_i_;
   notename_i_ += delta.notename_i_;
 
-  
-  while  (notename_i_ >= 7)
-    {
-      notename_i_ -= 7;
-      octave_i_ ++;
-    }
-
-  int new_pitch = semitone_pitch ();
-  int delta_acc = new_pitch - old_pitch - delta_pitch;
+  int new_semi = semitone_pitch ();
+  int delta_acc = new_semi - old_semi - delta_semi;
   alteration_i_ -= delta_acc;
-}
-
 
+  normalise ();
+}
 
 
-/* FIXME */
-#if 0
-// nice test for internationalisation strings
-char const *accname[] = {"double flat", "flat", "natural",
-                        "sharp" , "double sharp"};
-#else
+/* FIXME
+   Merge with *pitch->text* funcs in chord-name.scm
+ */
 char const *accname[] = {"eses", "es", "", "is" , "isis"};
-#endif
 
 String
 Pitch::str () const
@@ -123,7 +169,6 @@ Pitch::str () const
        s += to_str (',');
     }
 
-
   return s;
 }
 
@@ -252,10 +297,7 @@ Pitch::less_p (SCM p1, SCM p2)
 static SCM
 make_pitch (SCM o, SCM n, SCM a)
 {
-  Pitch p;
-  p.octave_i_ = gh_scm2int (o);    
-  p.notename_i_ = gh_scm2int (n);
-  p.alteration_i_ = gh_scm2int (a);
+  Pitch p (gh_scm2int (o), gh_scm2int (n), gh_scm2int (a));
   return p.smobbed_copy ();
 }