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 /* Some compatibility naming until the code changes to use pitch_t and
30 * firedns in place of score_pitch_t and friends. */
31 typedef pitch_accidental_t score_pitch_accidental_t;
32 typedef pitch_name_t score_pitch_name_t;
33 typedef pitch_t score_pitch_t;
35 #define SCORE_PITCH_ACCIDENTAL(pitch) PITCH_ACCIDENTAL(pitch)
36 #define SCORE_PITCH_NAME(pitch) PITCH_NAME(pitch)
37 #define SCORE_PITCH(pitch, octave) PITCH(pitch, octave)
39 #define SCORE_PITCH_ACCIDENTAL_DOUBLE_FLAT PITCH_ACCIDENTAL_DOUBLE_FLAT
40 #define SCORE_PITCH_ACCIDENTAL_FLAT PITCH_ACCIDENTAL_FLAT
41 #define SCORE_PITCH_ACCIDENTAL_NATURAL PITCH_ACCIDENTAL_NATURAL
42 #define SCORE_PITCH_ACCIDENTAL_SHARP PITCH_ACCIDENTAL_SHARP
43 #define SCORE_PITCH_ACCIDENTAL_DOUBLE_SHARP PITCH_ACCIDENTAL_DOUBLE_SHARP
45 #define SCORE_PITCH_NAME_C PITCH_NAME_C
46 #define SCORE_PITCH_NAME_D PITCH_NAME_D
47 #define SCORE_PITCH_NAME_E PITCH_NAME_E
48 #define SCORE_PITCH_NAME_F PITCH_NAME_F
49 #define SCORE_PITCH_NAME_G PITCH_NAME_G
50 #define SCORE_PITCH_NAME_A PITCH_NAME_A
51 #define SCORE_PITCH_NAME_B PITCH_NAME_B
53 #define SCORE_PITCH_Cff PITCH_Cff
54 #define SCORE_PITCH_Cf PITCH_Cf
55 #define SCORE_PITCH_C PITCH_C
56 #define SCORE_PITCH_Cs PITCH_Cs
57 #define SCORE_PITCH_Css PITCH_Css
58 #define SCORE_PITCH_Dff PITCH_Dff
59 #define SCORE_PITCH_Df PITCH_Df
60 #define SCORE_PITCH_D PITCH_D
61 #define SCORE_PITCH_Ds PITCH_Ds
62 #define SCORE_PITCH_Dss PITCH_Dss
63 #define SCORE_PITCH_Eff PITCH_Eff
64 #define SCORE_PITCH_Ef PITCH_Ef
65 #define SCORE_PITCH_E PITCH_E
66 #define SCORE_PITCH_Es PITCH_Es
67 #define SCORE_PITCH_Ess PITCH_Ess
68 #define SCORE_PITCH_Fff PITCH_Fff
69 #define SCORE_PITCH_Ff PITCH_Ff
70 #define SCORE_PITCH_F PITCH_F
71 #define SCORE_PITCH_Fs PITCH_Fs
72 #define SCORE_PITCH_Fss PITCH_Fss
73 #define SCORE_PITCH_Gff PITCH_Gff
74 #define SCORE_PITCH_Gf PITCH_Gf
75 #define SCORE_PITCH_G PITCH_G
76 #define SCORE_PITCH_Gs PITCH_Gs
77 #define SCORE_PITCH_Gss PITCH_Gss
78 #define SCORE_PITCH_Aff PITCH_Aff
79 #define SCORE_PITCH_Af PITCH_Af
80 #define SCORE_PITCH_A PITCH_A
81 #define SCORE_PITCH_As PITCH_As
82 #define SCORE_PITCH_Ass PITCH_Ass
83 #define SCORE_PITCH_Bff PITCH_Bff
84 #define SCORE_PITCH_Bf PITCH_Bf
85 #define SCORE_PITCH_B PITCH_B
86 #define SCORE_PITCH_Bs PITCH_Bs
87 #define SCORE_PITCH_Bss PITCH_Bss
89 typedef enum score_duration
91 SCORE_DURATION_WHOLE = 1,
93 SCORE_DURATION_HALF = 2,
95 SCORE_DURATION_QUARTER = 4,
97 SCORE_DURATION_EIGHTH = 8,
99 SCORE_DURATION_SIXTEENTH = 16,
100 SCORE_DURATION_16 = 16,
101 SCORE_DURATION_THIRTYSECOND = 32,
102 SCORE_DURATION_32 = 32,
103 SCORE_DURATION_SIXTYFOURTH = 64,
104 SCORE_DURATION_64 = 64,
105 SCORE_DURATION_ONEHUNDREDTWENTYEIGHTH = 128,
106 SCORE_DURATION_128 = 128
109 #define SCORE_BUILD_NOTE(pitch, octave, duration) SCORE_PITCH_##pitch, (octave), SCORE_DURATION_##duration
111 typedef struct score score_t;
112 typedef struct score_staff score_staff_t;
114 typedef struct score_note
116 score_staff_t *staff;
119 score_duration_t duration;
128 typedef struct score_chord
130 score_staff_t *staff;
136 typedef enum score_clef
139 SCORE_CLEF_TREBLE = SCORE_CLEF_G,
141 SCORE_CLEF_BASS = SCORE_CLEF_F
144 /* Allocate a new, empty score object, (with optional ctx as talloc
145 * owner). If ctx is NULL, the caller should call talloc_free on the
146 * score_t* when done with it. Otherwise, the object will be freed
147 * when ctx is freed. */
149 score_create (void *ctx);
151 /* Set an (approximate) staff height. The actual staff height may
152 * differ due to rounding to achieve evenly spaced, sharply rendered
153 * lines. the actual staff height is returned. */
155 score_set_staff_height (score_t *score, int height);
157 /* Set the total width available for drawing the score. */
159 score_set_width (score_t *score, int width);
161 /* Add a brace to the score, connecting the given number of staves.
163 * The staves to be connected are those that will next be added to the
166 score_add_brace (score_t *score, int staves);
168 /* Add a new staff to the score */
170 score_add_staff (score_t *score, score_clef_t clef);
172 /* Add a note to a staff of the given pitch, octave, and duration.
174 * Octave numbers are ISO octave numbers [0:8], (so Octave 4 is from
175 * middle C to the B above middle C).
177 * Duration values can be symbolic (SCORE_DURATION_WHOLE, _QUARTER,
178 * _EIGHTH, etc.) or numerical as simply the denominator (WHOLE=1,
179 * QUARTER=4, EIGHTH=8, etc.)
182 score_add_note (score_staff_t *staff,
187 /* Add a chord symbol of 'name' to a staff.
189 * For now, the chord symbols are free-form names.
191 * The chord name must be a talloc'ed string, which the returned
192 * score_chord_t will talloc_steal.
195 score_add_chord (score_staff_t *staff,
198 /* Remove the given chord from its staff. */
200 score_remove_chord (score_chord_t *chord);
202 /* Remove the given note from its staff. */
204 score_remove_note (score_note_t *note);
207 score_set_note_color_rgb (score_note_t *note,
212 /* Return the first note on the given staff with the given pitch,
213 * octave, and durations. Returns NULL if no match is found. */
215 score_staff_find_note (score_staff_t *staff,
218 score_duration_t duration);
220 /* Draw the given score_t onto the given cairo_t.
222 * The caller can call cairo_translate before calling score_draw to
223 * position the result as desired, (and can call cairo_clip to clip it
226 score_draw (score_t *score, cairo_t *cr);