X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=score.c;h=0c9d5f37cb37e20d9913e0601ef4b66246ccf777;hb=05c28164f342656bd02bb4c6607b938bb8d3f2b1;hp=7a1c231a4b82cfdcef0d972dcf88ac6c1168e645;hpb=f6b8f7f23bb8a4a5b30bfde8242578cca90ddacf;p=scherzo diff --git a/score.c b/score.c index 7a1c231..0c9d5f3 100644 --- a/score.c +++ b/score.c @@ -18,6 +18,8 @@ * along with this program. If not, see http://www.gnu.org/licenses/ . */ +#include + #include "score.h" struct score_staff @@ -56,13 +58,6 @@ struct score int num_staves; }; -typedef struct score_note -{ - score_pitch_t pitch; - int octave; - score_duration_t duration; -} score_note_t; - score_t * score_create (void *ctx) { @@ -222,7 +217,6 @@ _draw_staff (score_t *score, cairo_t *cr, { int i; cairo_glyph_t clef_glyph; - cairo_text_extents_t clef_extents; cairo_save (cr); @@ -249,8 +243,6 @@ _draw_staff (score_t *score, cairo_t *cr, cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */ cairo_show_glyphs (cr, &clef_glyph, 1); - cairo_glyph_extents (cr, &clef_glyph, 1, &clef_extents); - /* Draw staff lines */ for (i = 0; i < 5; i++) { cairo_move_to (cr, 0, i * score->space_height + score->line_width / 2.0); @@ -263,12 +255,14 @@ _draw_staff (score_t *score, cairo_t *cr, cairo_stroke (cr); /* Make space for clef before drawing notes */ - cairo_translate (cr, (int) (1.5 * clef_extents.width), 0); + cairo_translate (cr, (int) (4 * score->space_height), 0); /* Draw notes */ for (i = 0; i < staff->num_notes; i++) { _draw_note (score, cr, staff, staff->notes[i]); + /* Draw all notes concurrent for now (as a chord) cairo_translate (cr, score->space_height * 2.0, 0); + */ } cairo_restore (cr); @@ -372,10 +366,10 @@ score_add_staff (score_t *score, score_clef_t clef) } score_note_t * -score_staff_add_note (score_staff_t *staff, - score_pitch_t pitch, - int octave, - score_duration_t duration) +score_add_note (score_staff_t *staff, + score_pitch_t pitch, + int octave, + score_duration_t duration) { score_note_t *note; @@ -383,6 +377,7 @@ score_staff_add_note (score_staff_t *staff, if (note == NULL) return NULL; + note->staff = staff; note->pitch = pitch; note->octave = octave; note->duration = duration; @@ -402,3 +397,48 @@ score_staff_add_note (score_staff_t *staff, return note; } +void +score_remove_note (score_note_t *note) +{ + score_staff_t *staff = note->staff; + int i; + + for (i = 0; i < staff->num_notes; i++) + if (staff->notes[i] == note) + break; + + if (i == staff->num_notes) + return; + + if (i < staff->num_notes - 1) + { + memmove (staff->notes + i, + staff->notes + i + 1, + (staff->num_notes - 1 - i) * sizeof (score_note_t *)); + } + + staff->num_notes -= 1; +} + +score_note_t * +score_staff_find_note (score_staff_t *staff, + score_pitch_t pitch, + int octave, + score_duration_t duration) +{ + int i; + score_note_t *note; + + for (i = 0; i < staff->num_notes; i++) { + note = staff->notes[i]; + if (note->pitch == pitch && + note->octave == octave && + note->duration == duration) + { + return note; + } + } + + return NULL; +} +