]> git.cworth.org Git - scherzo/commitdiff
Avoid duplicating notes within note_group_t and score_staff_t
authorCarl Worth <cworth@cworth.org>
Wed, 18 Sep 2013 18:00:02 +0000 (11:00 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 18 Sep 2013 18:00:02 +0000 (11:00 -0700)
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
score.c

index 0b0a97f77e9ed2049f82422d1069300525e0fa39..3fcae5cfb9e3e291f367b9cac94726ad6c7f4b7a 100644 (file)
--- 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 e319af0c238abaf594afee0088bc8c580de6f59e..ac0d346522715896fc3c2e478a3a215a2b32619e 100644 (file)
--- 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)