From 2e37869bdeb7a9a6de2b758eb704320e00aae5c3 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 18 Sep 2013 11:00:02 -0700 Subject: [PATCH] Avoid duplicating notes within note_group_t and score_staff_t Previously, it was possible to have notes "stick" on the staff and not clear off after releasing the note or pedal in some circumstances. We fix a number of these bugs by checking to see if a note is already present in a list before adding a duplicate copy of it. --- scherzo.c | 11 +++++++++++ score.c | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/scherzo.c b/scherzo.c index 0b0a97f..3fcae5c 100644 --- a/scherzo.c +++ b/scherzo.c @@ -585,6 +585,17 @@ note_group_init (void *ctx, note_group_t *group) static void note_group_add_note (note_group_t *group, score_note_t *note) { + int i; + + /* Do nothing if note is already in group. */ + for (i = 0; i < group->num_notes; i++) { + if (group->notes[i]->pitch == note->pitch && + group->notes[i]->octave == note->octave) + { + return; + } + } + group->num_notes++; if (group->num_notes > group->size) { diff --git a/score.c b/score.c index e319af0..ac0d346 100644 --- a/score.c +++ b/score.c @@ -538,6 +538,18 @@ score_add_note (score_staff_t *staff, { score_note_t *note; double line; + int i; + + /* Return existing note if already present. */ + for (i = 0; i < staff->num_notes; i++) { + note = staff->notes[i]; + if (note->pitch == pitch && + note->octave == octave && + note->duration == duration) + { + return note; + } + } note = talloc (staff, score_note_t); if (note == NULL) -- 2.43.0