+ fprintf (stderr, "Internal error: Cannot adjust a note more than one degree (%d vs. %d).\n", note_degree_zero_based + 1, degree->degree);
+ exit (1);
+ }
+
+ if (degree_delta == -1) {
+ if (name == SCORE_PITCH_NAME_B) {
+ name = SCORE_PITCH_NAME_C;
+ note->octave++;
+ } else {
+ name++;
+ }
+ switch (name) {
+ case SCORE_PITCH_NAME_D:
+ case SCORE_PITCH_NAME_E:
+ case SCORE_PITCH_NAME_G:
+ case SCORE_PITCH_NAME_A:
+ case SCORE_PITCH_NAME_B:
+ accidental -= 2;
+ break;
+ case SCORE_PITCH_NAME_C:
+ case SCORE_PITCH_NAME_F:
+ accidental -= 1;
+ break;
+ }
+ }
+
+ if (degree_delta == +1) {
+ if (name == SCORE_PITCH_NAME_C) {
+ name = SCORE_PITCH_NAME_B;
+ note->octave--;
+ } else {
+ name--;
+ }
+ switch (name) {
+ case SCORE_PITCH_NAME_C:
+ case SCORE_PITCH_NAME_D:
+ case SCORE_PITCH_NAME_F:
+ case SCORE_PITCH_NAME_G:
+ case SCORE_PITCH_NAME_A:
+ accidental += 2;
+ break;
+ case SCORE_PITCH_NAME_E:
+ case SCORE_PITCH_NAME_B:
+ accidental += 1;
+ }
+ }
+
+ if (accidental < 0 || accidental > SCORE_PITCH_ACCIDENTAL_DOUBLE_SHARP) {
+ fprintf (stderr, "Internal error: Trying to adjust an accidental out of range (degree_delta == %d (%d - %d), new accidental == %d).\n", degree_delta, note_degree_zero_based, degree_zero_based, accidental);
+ exit (1);
+ }
+
+ note->pitch = SCORE_PITCH (name, accidental);
+}
+
+static void
+_spell_chord_by_signature (note_group_t *chord,
+ int num_notes,
+ chord_signature_t *signature,
+ score_pitch_t root)
+{
+ int i, degree, note_half_steps, degree_half_steps;
+ int root_midi;
+
+ /* Sanitize root to eliminate things like double-flats,