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/ .
27 typedef struct score score_t;
28 typedef struct score_staff score_staff_t;
29 typedef struct score_note score_note_t;
31 typedef enum score_pitch
76 typedef enum score_duration
78 SCORE_DURATION_WHOLE = 1,
80 SCORE_DURATION_HALF = 2,
82 SCORE_DURATION_QUARTER = 4,
84 SCORE_DURATION_EIGHTH = 8,
86 SCORE_DURATION_SIXTEENTH = 16,
87 SCORE_DURATION_16 = 16,
88 SCORE_DURATION_THIRTYSECOND = 32,
89 SCORE_DURATION_32 = 32,
90 SCORE_DURATION_SIXTYFOURTH = 64,
91 SCORE_DURATION_64 = 64,
92 SCORE_DURATION_ONEHUNDREDTWENTYEIGHTH = 128,
93 SCORE_DURATION_128 = 128
96 #define SCORE_BUILD_NOTE(pitch, octave, duration) SCORE_PITCH_##pitch, (octave), SCORE_DURATION_##duration
98 typedef enum score_clef
104 /* Allocate a new, empty score object, (with optional ctx as talloc
105 * owner). If ctx is NULL, the caller should call talloc_free on the
106 * score_t* when done with it. Otherwise, the object will be freed
107 * when ctx is freed. */
109 score_create (void *ctx);
111 /* Set an (approximate) staff height. The actual staff height may
112 * differ due to rounding to achieve evenly spaced, sharply rendered
113 * lines. the actual staff height is returned. */
115 score_set_staff_height (score_t *score, int height);
117 /* Set the total width available for drawing the score. */
119 score_set_width (score_t *score, int width);
121 /* Add a brace to the score, connecting the given number of staves.
123 * The staves to be connected are those that will next be added to the
126 score_add_brace (score_t *score, int staves);
128 /* Add a new staff to the score */
130 score_add_staff (score_t *score, score_clef_t clef);
132 /* Add a note to a staff of the given pitch, octave, and duration.
134 * Octave numbers are ISO octave numbers [0:8], (so Octave 4 is from
135 * middle C to the B above middle C).
137 * Duration values can be symbolic (SCORE_DURATION_WHOLE, _QUARTER,
138 * _EIGHTH, etc.) or numerical as simply the denominator (WHOLE=1,
139 * QUARTER=4, EIGHTH=8, etc.)
142 score_staff_add_note (score_staff_t *staff,
147 /* Draw the given score_t onto the given cairo_t.
149 * The caller can call cairo_translate before calling score_draw to
150 * position the result as desired, (and can call cairo_clip to clip it
153 score_draw (score_t *score, cairo_t *cr);