+ /* Nothing to do if we have no staff, (there's no place to add a note) . */
+ if (score->num_staves == 0)
+ return;
+
+ /* Find the staff where the note will be closest to the center of
+ * the staff. */
+ for (i = 0; i < score->num_staves; i++) {
+ staff = score->staves[i];
+ distance = fabs (_score_staff_pitch_to_line (staff, pitch) - 2.0);
+ if (nearest_staff == NULL || distance < nearest_distance) {
+ nearest_staff = staff;
+ nearest_distance = distance;
+ }
+ }
+
+ score_staff_add_note (nearest_staff, pitch, duration);