From f1a9072c2c9f45b591a115b9aa134d7dbbcc19fd Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 4 Mar 2001 13:18:09 +0100 Subject: [PATCH] patch::: 1.3.134.jcn2 1.3.134.jcn2 ============ * Bugfix: Pitch::transpose (). --- CHANGES | 5 +++ VERSION | 2 +- lily/include/pitch.hh | 1 + lily/pitch.cc | 94 +++++++++++++++++++++++++++++++------------ 4 files changed, 75 insertions(+), 27 deletions(-) diff --git a/CHANGES b/CHANGES index 9e07294723..840c7d9405 100644 --- 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 6ae3d034b5..be95c2efe6 100644 --- 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. diff --git a/lily/include/pitch.hh b/lily/include/pitch.hh index cd478d250f..25b576f4c0 100644 --- a/lily/include/pitch.hh +++ b/lily/include/pitch.hh @@ -46,6 +46,7 @@ public: int notename_i () const; int alteration_i () const; + void normalise (); /* Pitch is lexicographically ordered by (octave, notename, alteration). diff --git a/lily/pitch.cc b/lily/pitch.cc index bbe75c3893..17f6b0f500 100644 --- a/lily/pitch.cc +++ b/lily/pitch.cc @@ -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 (); } -- 2.39.2