X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=score.h;h=25d558329eb4c05923b924119daac08e8b8041e1;hb=f15abc24d2c9a574d1209922a0d9825df21245f8;hp=26b976683cadb23bcfc47870fe7abe7022a00626;hpb=66812a216aa78f33ddff8753dd62f8450ef3220a;p=scherzo diff --git a/score.h b/score.h index 26b9766..25d5583 100644 --- a/score.h +++ b/score.h @@ -21,20 +21,134 @@ #ifndef SCORE_H #define SCORE_H +#include #include -typedef struct score +typedef struct score score_t; +typedef struct score_staff score_staff_t; +typedef struct score_note score_note_t; + +typedef enum score_pitch +{ + SCORE_PITCH_Aff, + SCORE_PITCH_Af, + SCORE_PITCH_A, + SCORE_PITCH_As, + SCORE_PITCH_Ass, + + SCORE_PITCH_Bff, + SCORE_PITCH_Bf, + SCORE_PITCH_B, + SCORE_PITCH_Bs, + SCORE_PITCH_Bss, + + SCORE_PITCH_Cff, + SCORE_PITCH_Cf, + SCORE_PITCH_C, + SCORE_PITCH_Cs, + SCORE_PITCH_Css, + + SCORE_PITCH_Dff, + SCORE_PITCH_Df, + SCORE_PITCH_D, + SCORE_PITCH_Ds, + SCORE_PITCH_Dss, + + SCORE_PITCH_Eff, + SCORE_PITCH_Ef, + SCORE_PITCH_E, + SCORE_PITCH_Es, + SCORE_PITCH_Ess, + + SCORE_PITCH_Fff, + SCORE_PITCH_Ff, + SCORE_PITCH_F, + SCORE_PITCH_Fs, + SCORE_PITCH_Fss, + + SCORE_PITCH_Gff, + SCORE_PITCH_Gf, + SCORE_PITCH_G, + SCORE_PITCH_Gs, + SCORE_PITCH_Gss +} score_pitch_t; + +typedef enum score_duration +{ + SCORE_DURATION_WHOLE = 1, + SCORE_DURATION_1 = 1, + SCORE_DURATION_HALF = 2, + SCORE_DURATION_2 = 2, + SCORE_DURATION_QUARTER = 4, + SCORE_DURATION_4 = 4, + SCORE_DURATION_EIGHTH = 8, + SCORE_DURATION_8 = 8, + SCORE_DURATION_SIXTEENTH = 16, + SCORE_DURATION_16 = 16, + SCORE_DURATION_THIRTYSECOND = 32, + SCORE_DURATION_32 = 32, + SCORE_DURATION_SIXTYFOURTH = 64, + SCORE_DURATION_64 = 64, + SCORE_DURATION_ONEHUNDREDTWENTYEIGHTH = 128, + SCORE_DURATION_128 = 128 +} score_duration_t; + +#define SCORE_BUILD_NOTE(pitch, octave, duration) SCORE_PITCH_##pitch, (octave), SCORE_DURATION_##duration + +typedef enum score_clef { - /* Height of each space on staff. */ - int space_height; + SCORE_CLEF_G, + SCORE_CLEF_F +} score_clef_t; + +/* Allocate a new, empty score object, (with optional ctx as talloc + * owner). If ctx is NULL, the caller should call talloc_free on the + * score_t* when done with it. Otherwise, the object will be freed + * when ctx is freed. */ +score_t * +score_create (void *ctx); + +/* Set an (approximate) staff height. The actual staff height may + * differ due to rounding to achieve evenly spaced, sharply rendered + * lines. the actual staff height is returned. */ +int +score_set_staff_height (score_t *score, int height); - /* Total width available to score. */ - int width; -} score_t; +/* Set the total width available for drawing the score. */ +void +score_set_width (score_t *score, int width); +/* Add a brace to the score, connecting the given number of staves. + * + * The staves to be connected are those that will next be added to the + * score. */ void -score_init (score_t *score); +score_add_brace (score_t *score, int staves); + +/* Add a new staff to the score */ +score_staff_t * +score_add_staff (score_t *score, score_clef_t clef); +/* Add a note to a staff of the given pitch, octave, and duration. + * + * Octave numbers are ISO octave numbers [0:8], (so Octave 4 is from + * middle C to the B above middle C). + * + * Duration values can be symbolic (SCORE_DURATION_WHOLE, _QUARTER, + * _EIGHTH, etc.) or numerical as simply the denominator (WHOLE=1, + * QUARTER=4, EIGHTH=8, etc.) + */ +score_note_t * +score_staff_add_note (score_staff_t *staff, + score_pitch_t pitch, + int octave, + score_duration_t); + +/* Draw the given score_t onto the given cairo_t. + * + * The caller can call cairo_translate before calling score_draw to + * position the result as desired, (and can call cairo_clip to clip it + * if desired). */ void score_draw (score_t *score, cairo_t *cr);