X-Git-Url: https://git.cworth.org/git?p=scherzo;a=blobdiff_plain;f=score.h;h=d2de1091c5cecdce1bd6cc6d4bb4d5d513c9e3f1;hp=03add0353aa71b07070c97f4b60e68ca2ac04144;hb=HEAD;hpb=73ba6a9e9a9308747fd0fa301e1a349746eaf47c diff --git a/score.h b/score.h index 03add03..d2de109 100644 --- a/score.h +++ b/score.h @@ -24,87 +24,7 @@ #include #include -typedef struct score score_t; -typedef struct score_staff score_staff_t; - -#define SCORE_PITCH_ACCIDENTAL_MASK 0x07 -#define SCORE_PITCH_ACCIDENTAL_SHIFT 0 - -typedef enum score_pitch_accidental -{ - SCORE_PITCH_ACCIDENTAL_DOUBLE_FLAT, - SCORE_PITCH_ACCIDENTAL_FLAT, - SCORE_PITCH_ACCIDENTAL_NATURAL, - SCORE_PITCH_ACCIDENTAL_SHARP, - SCORE_PITCH_ACCIDENTAL_DOUBLE_SHARP -} score_pitch_accidental_t; - -#define SCORE_PITCH_ACCIDENTAL(pitch) (((pitch) & SCORE_PITCH_ACCIDENTAL_MASK) >> SCORE_PITCH_ACCIDENTAL_SHIFT) - -#define SCORE_PITCH_NAME_MASK 0x38 -#define SCORE_PITCH_NAME_SHIFT 3 - -typedef enum score_pitch_name -{ - SCORE_PITCH_NAME_C, - SCORE_PITCH_NAME_D, - SCORE_PITCH_NAME_E, - SCORE_PITCH_NAME_F, - SCORE_PITCH_NAME_G, - SCORE_PITCH_NAME_A, - SCORE_PITCH_NAME_B, -} score_pitch_name_t; - -#define SCORE_PITCH_NAME(pitch) (((pitch) & SCORE_PITCH_NAME_MASK) >> SCORE_PITCH_NAME_SHIFT) - -#define SCORE_PITCH(name, accidental) (((name) << SCORE_PITCH_NAME_SHIFT) | (accidental)) - -#define SCORE_PITCH_LITERAL(literal_name, literal_accidental) SCORE_PITCH(SCORE_PITCH_NAME_##literal_name, SCORE_PITCH_ACCIDENTAL_##literal_accidental) - -typedef enum score_pitch -{ - SCORE_PITCH_Cff = SCORE_PITCH_LITERAL (C, DOUBLE_FLAT), - SCORE_PITCH_Cf = SCORE_PITCH_LITERAL (C, FLAT), - SCORE_PITCH_C = SCORE_PITCH_LITERAL (C, NATURAL), - SCORE_PITCH_Cs = SCORE_PITCH_LITERAL (C, SHARP), - SCORE_PITCH_Css = SCORE_PITCH_LITERAL (C, DOUBLE_SHARP), - - SCORE_PITCH_Dff = SCORE_PITCH_LITERAL (D, DOUBLE_FLAT), - SCORE_PITCH_Df = SCORE_PITCH_LITERAL (D, FLAT), - SCORE_PITCH_D = SCORE_PITCH_LITERAL (D, NATURAL), - SCORE_PITCH_Ds = SCORE_PITCH_LITERAL (D, SHARP), - SCORE_PITCH_Dss = SCORE_PITCH_LITERAL (D, DOUBLE_SHARP), - - SCORE_PITCH_Eff = SCORE_PITCH_LITERAL (E, DOUBLE_FLAT), - SCORE_PITCH_Ef = SCORE_PITCH_LITERAL (E, FLAT), - SCORE_PITCH_E = SCORE_PITCH_LITERAL (E, NATURAL), - SCORE_PITCH_Es = SCORE_PITCH_LITERAL (E, SHARP), - SCORE_PITCH_Ess = SCORE_PITCH_LITERAL (E, DOUBLE_SHARP), - - SCORE_PITCH_Fff = SCORE_PITCH_LITERAL (F, DOUBLE_FLAT), - SCORE_PITCH_Ff = SCORE_PITCH_LITERAL (F, FLAT), - SCORE_PITCH_F = SCORE_PITCH_LITERAL (F, NATURAL), - SCORE_PITCH_Fs = SCORE_PITCH_LITERAL (F, SHARP), - SCORE_PITCH_Fss = SCORE_PITCH_LITERAL (F, DOUBLE_SHARP), - - SCORE_PITCH_Gff = SCORE_PITCH_LITERAL (G, DOUBLE_FLAT), - SCORE_PITCH_Gf = SCORE_PITCH_LITERAL (G, FLAT), - SCORE_PITCH_G = SCORE_PITCH_LITERAL (G, NATURAL), - SCORE_PITCH_Gs = SCORE_PITCH_LITERAL (G, SHARP), - SCORE_PITCH_Gss = SCORE_PITCH_LITERAL (G, DOUBLE_SHARP), - - SCORE_PITCH_Aff = SCORE_PITCH_LITERAL (A, DOUBLE_FLAT), - SCORE_PITCH_Af = SCORE_PITCH_LITERAL (A, FLAT), - SCORE_PITCH_A = SCORE_PITCH_LITERAL (A, NATURAL), - SCORE_PITCH_As = SCORE_PITCH_LITERAL (A, SHARP), - SCORE_PITCH_Ass = SCORE_PITCH_LITERAL (A, DOUBLE_SHARP), - - SCORE_PITCH_Bff = SCORE_PITCH_LITERAL (B, DOUBLE_FLAT), - SCORE_PITCH_Bf = SCORE_PITCH_LITERAL (B, FLAT), - SCORE_PITCH_B = SCORE_PITCH_LITERAL (B, NATURAL), - SCORE_PITCH_Bs = SCORE_PITCH_LITERAL (B, SHARP), - SCORE_PITCH_Bss = SCORE_PITCH_LITERAL (B, DOUBLE_SHARP) -} score_pitch_t; +#include "scherzo-key.h" typedef enum score_duration { @@ -128,19 +48,8 @@ typedef enum score_duration #define SCORE_BUILD_NOTE(pitch, octave, duration) SCORE_PITCH_##pitch, (octave), SCORE_DURATION_##duration -typedef struct score_note -{ - score_staff_t *staff; - score_pitch_t pitch; - int octave; - score_duration_t duration; - - struct { - double r; - double g; - double b; - } color; -} score_note_t; +typedef struct score score_t; +typedef struct score_staff score_staff_t; typedef struct score_chord { @@ -175,6 +84,10 @@ score_set_staff_height (score_t *score, int height); void score_set_width (score_t *score, int width); +/* Set the key for this score */ +void +score_set_key (score_t *score, pitch_t key); + /* 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 @@ -186,20 +99,21 @@ score_add_brace (score_t *score, int staves); 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). +/* Add a note to a staff of the given pitch and duration. * * 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_add_note (score_staff_t *staff, - score_pitch_t pitch, - int octave, - score_duration_t); +void +score_staff_add_note (score_staff_t *staff, + pitch_t pitch, + score_duration_t duration); + +/* Add a note to the score, (automatically selecting the nearest + * staff) */ +void +score_add_note (score_t *score, pitch_t pitch, score_duration_t duration); /* Add a chord symbol of 'name' to a staff. * @@ -212,27 +126,21 @@ score_chord_t * score_add_chord (score_staff_t *staff, const char * name); -/* Remove the given chord from its staff. */ +/* Remove all chords from the given staff. */ +void +score_staff_remove_chords (score_staff_t *staff); + +/* Remove all chords from the score. */ void -score_remove_chord (score_chord_t *chord); +score_remove_chords (score_t *score); -/* Remove the given note from its staff. */ +/* Remove all notes from the given staff. */ void -score_remove_note (score_note_t *note); +score_staff_remove_notes (score_staff_t *staff); +/* Remove all notes from the score. */ void -score_set_note_color_rgb (score_note_t *note, - double r, - double g, - double b); - -/* Return the first note on the given staff with the given pitch, - * octave, and durations. Returns NULL if no match is found. */ -score_note_t * -score_staff_find_note (score_staff_t *staff, - score_pitch_t pitch, - int octave, - score_duration_t duration); +score_remove_notes (score_t *score); /* Draw the given score_t onto the given cairo_t. *