- int found = 0;
- int target_midi = _pitch_and_octave_to_midi (pitch, octave);
- int note_midi;
-
- for (i = scherzo->notes_pressed.num_notes - 1; i >=0; i--) {
- note = scherzo->notes_pressed.notes[i];
- note_midi = _pitch_and_octave_to_midi (note->pitch, note->octave);
- if (note_midi == target_midi) {
- found = 1;
- if (! scherzo->pedal_pressed)
- score_remove_note (note);
- note_group_remove_note_at (&scherzo->notes_pressed, i);
+
+ /* Do nothing if this note is already pressed. */
+ for (i = 0; i < scherzo->notes_pressed.num_pitches; i++)
+ if (scherzo->notes_pressed.pitches[i] == pitch)
+ return;
+
+ pitch_group_add_pitch (&scherzo->notes_pressed, pitch);
+
+ if (scherzo->pedal_pressed)
+ pitch_group_add_pitch (&scherzo->notes_pedaled, pitch);
+
+ /* Remove all notes/chords from score, then add current notes. */
+ score_remove_notes (scherzo->score);
+ score_remove_chords (scherzo->score);
+
+ if (scherzo->pedal_pressed)
+ chord = &scherzo->notes_pedaled;
+ else
+ chord = &scherzo->notes_pressed;
+
+ _analyze_chord (chord, &signature, &root);
+
+ if (signature) {
+ /* Don't print root pitch for octaves and inversions,
+ * (since a pitch name alone looks like a major triad) */
+ if (signature->num_degrees < 3) {
+ chord_name = talloc_strdup (local, signature->name);
+ } else {
+ _spell_chord_by_signature (&scherzo->notes_pressed,
+ signature, *root);
+ _spell_chord_by_signature (&scherzo->notes_pedaled,
+ signature, *root);
+
+ chord_name = talloc_asprintf (local, "%s%s",
+ _pitch_str (*root),
+ signature->name);