1 /* scherzo - Music notation training
3 * score - Utilities for drawing (simple) musical scores
5 * Copyright © 2010 Carl Worth
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see http://www.gnu.org/licenses/ .
29 typedef enum score_duration
31 SCORE_DURATION_WHOLE = 1,
33 SCORE_DURATION_HALF = 2,
35 SCORE_DURATION_QUARTER = 4,
37 SCORE_DURATION_EIGHTH = 8,
39 SCORE_DURATION_SIXTEENTH = 16,
40 SCORE_DURATION_16 = 16,
41 SCORE_DURATION_THIRTYSECOND = 32,
42 SCORE_DURATION_32 = 32,
43 SCORE_DURATION_SIXTYFOURTH = 64,
44 SCORE_DURATION_64 = 64,
45 SCORE_DURATION_ONEHUNDREDTWENTYEIGHTH = 128,
46 SCORE_DURATION_128 = 128
49 #define SCORE_BUILD_NOTE(pitch, octave, duration) SCORE_PITCH_##pitch, (octave), SCORE_DURATION_##duration
51 typedef struct score score_t;
52 typedef struct score_staff score_staff_t;
54 typedef struct score_note
59 score_duration_t duration;
68 typedef struct score_chord
76 typedef enum score_clef
79 SCORE_CLEF_TREBLE = SCORE_CLEF_G,
81 SCORE_CLEF_BASS = SCORE_CLEF_F
84 /* Allocate a new, empty score object, (with optional ctx as talloc
85 * owner). If ctx is NULL, the caller should call talloc_free on the
86 * score_t* when done with it. Otherwise, the object will be freed
87 * when ctx is freed. */
89 score_create (void *ctx);
91 /* Set an (approximate) staff height. The actual staff height may
92 * differ due to rounding to achieve evenly spaced, sharply rendered
93 * lines. the actual staff height is returned. */
95 score_set_staff_height (score_t *score, int height);
97 /* Set the total width available for drawing the score. */
99 score_set_width (score_t *score, int width);
101 /* Add a brace to the score, connecting the given number of staves.
103 * The staves to be connected are those that will next be added to the
106 score_add_brace (score_t *score, int staves);
108 /* Add a new staff to the score */
110 score_add_staff (score_t *score, score_clef_t clef);
112 /* Add a note to a staff of the given pitch, octave, and duration.
114 * Octave numbers are ISO octave numbers [0:8], (so Octave 4 is from
115 * middle C to the B above middle C).
117 * Duration values can be symbolic (SCORE_DURATION_WHOLE, _QUARTER,
118 * _EIGHTH, etc.) or numerical as simply the denominator (WHOLE=1,
119 * QUARTER=4, EIGHTH=8, etc.)
122 score_add_note (score_staff_t *staff,
127 /* Add a chord symbol of 'name' to a staff.
129 * For now, the chord symbols are free-form names.
131 * The chord name must be a talloc'ed string, which the returned
132 * score_chord_t will talloc_steal.
135 score_add_chord (score_staff_t *staff,
138 /* Remove the given chord from its staff. */
140 score_remove_chord (score_chord_t *chord);
142 /* Remove the given note from its staff. */
144 score_remove_note (score_note_t *note);
147 score_set_note_color_rgb (score_note_t *note,
152 /* Return the first note on the given staff with the given pitch,
153 * octave, and durations. Returns NULL if no match is found. */
155 score_staff_find_note (score_staff_t *staff,
158 score_duration_t duration);
160 /* Draw the given score_t onto the given cairo_t.
162 * The caller can call cairo_translate before calling score_draw to
163 * position the result as desired, (and can call cairo_clip to clip it
166 score_draw (score_t *score, cairo_t *cr);