+ *pitch = PITCH (name, accidental, octave);
+}
+
+static void
+_spell_chord_by_signature (pitch_group_t *chord,
+ chord_signature_t *signature,
+ pitch_t root)
+{
+ int i, degree, note_half_steps, degree_half_steps;
+ int root_midi;
+
+ /* Sanitize root to eliminate things like double-flats,
+ * double-sharps, Cb, E#, etc. */
+ root_midi = _pitch_to_midi (root);
+ root = _midi_to_pitch (root_midi);
+
+ for (i = 0; i < chord->num_pitches; i++) {
+ note_half_steps = _pitch_from_root_in_half_steps (chord->pitches[i],
+ root);
+ for (degree = 0; degree < signature->num_degrees; degree++) {
+ degree_half_steps = _modified_degree_to_half_steps (&signature->degrees[degree]);
+ if (note_half_steps == degree_half_steps) {
+ scherzo_adjust_pitch_to_match_modified_degree (&chord->pitches[i],
+ root,
+ &signature->degrees[degree]);
+ break;
+ }
+ }
+ if (note_half_steps != degree_half_steps) {
+ fprintf (stderr, "Internal error: Chord and degree mis-match\n");
+ exit (1);
+ }
+ }
+}
+
+static void
+_analyze_chord (pitch_group_t *chord,
+ chord_signature_t **signature_ret,
+ pitch_t **root_ret)
+{
+ void *local = talloc_new (NULL);
+ analyzed_pitch_t *pitches;
+ int i, j, num_pitches;
+ int bass_pitch, inversion;
+ pitch_t root;
+ chord_signature_t *match = NULL;
+
+ /* Default to no-match for any early return */
+ *signature_ret = NULL;
+ *root_ret = NULL;
+
+ num_pitches = chord->num_pitches;
+
+ if (chord->num_pitches <= 1)