]> git.cworth.org Git - scherzo/commitdiff
Fix the broken SCORE_PITCH_NAME macro to work correctly
authorCarl Worth <cworth@cworth.org>
Tue, 17 Sep 2013 20:31:04 +0000 (13:31 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 17 Sep 2013 20:31:04 +0000 (13:31 -0700)
For no good reason, the score_pitch_name_t enum had previously been
defined with pre-shifted values. That could have worked, but the
SCORE_PITCH_NAME macro was shiftin the masked value down as if the
enum values were not pre-shifted. So SCORE_PITCH_NAME was yielding
unexpected values, (that did not correspond to score_pitch_name_t
enum values).

We fix this by making the enum sane, (with unshifted values), leaving
the shifting in place in SCORE_PIATCH_NAME and tracking the new style
of the enum by adding shifting to the SCORE_PITCH_VALUE macro.

That is, the macro that is changed by this commit reamins working, and
the macro that is left unchaged by this commit is now fixed.

score.h

diff --git a/score.h b/score.h
index d1f0406725944e2c66e3132b169bc3541bf8e1a9..fe627b8ad401ab489bd073ee47adcd530b6c8bd5 100644 (file)
--- a/score.h
+++ b/score.h
@@ -46,18 +46,18 @@ typedef enum score_pitch_accidental
 
 typedef enum score_pitch_name
 {
-    SCORE_PITCH_NAME_C = 0 << SCORE_PITCH_NAME_SHIFT,
-    SCORE_PITCH_NAME_D = 1 << SCORE_PITCH_NAME_SHIFT,
-    SCORE_PITCH_NAME_E = 2 << SCORE_PITCH_NAME_SHIFT,
-    SCORE_PITCH_NAME_F = 3 << SCORE_PITCH_NAME_SHIFT,
-    SCORE_PITCH_NAME_G = 4 << SCORE_PITCH_NAME_SHIFT,
-    SCORE_PITCH_NAME_A = 5 << SCORE_PITCH_NAME_SHIFT,
-    SCORE_PITCH_NAME_B = 6 << SCORE_PITCH_NAME_SHIFT
+    SCORE_PITCH_NAME_C,
+    SCORE_PITCH_NAME_D,
+    SCORE_PITCH_NAME_E,
+    SCORE_PITCH_NAME_F,
+    SCORE_PITCH_NAME_G,
+    SCORE_PITCH_NAME_A,
+    SCORE_PITCH_NAME_B,
 } score_pitch_name_t;
 
 #define SCORE_PITCH_NAME(pitch) (((pitch) & SCORE_PITCH_NAME_MASK) >> SCORE_PITCH_NAME_SHIFT)
 
-#define SCORE_PITCH_VALUE(name, accidental) ((SCORE_PITCH_NAME_##name) + (SCORE_PITCH_ACCIDENTAL_##accidental))
+#define SCORE_PITCH_VALUE(name, accidental) ((SCORE_PITCH_NAME_##name << SCORE_PITCH_NAME_SHIFT) + (SCORE_PITCH_ACCIDENTAL_##accidental))
 
 typedef enum score_pitch
 {