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/ .
25 /* Height of a single staff */
28 /* Height of one space within a staff */
31 /* Full width of staff */
36 score_create (void *ctx)
40 score = talloc (ctx, score_t);
41 score_set_staff_height (score, 24);
47 score_set_staff_height (score_t *score, int height)
49 score->space_height = (int) height / 4;
50 score->staff_height = score->space_height * 4;
51 return score->staff_height;
55 score_set_width (score_t *score, int width)
60 typedef enum score_clef
67 _draw_staff (score_t *score, cairo_t *cr, score_clef_t clef)
74 cairo_select_font_face (cr, "Gonville-26", 0, 0);
76 /* XXX: This font size is a rough guess at best. We should figure
77 * out to correctly measure, size, and place clefs. */
78 cairo_set_font_size (cr, 24);
80 /* XXX: The hard-coded glyph indices here are very ugly. We should
81 * figure out how to lookup glyphs by name from this font. */
86 glyph.y = 3 * score->space_height;
90 glyph.y = 1 * score->space_height;
95 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
96 cairo_show_glyphs (cr, &glyph, 1);
100 score->width - 1.0, score->space_height * 4);
102 for (i = 1; i < 4; i++) {
103 cairo_move_to (cr, 0, i * score->space_height + 0.5);
104 cairo_rel_line_to (cr, score->width, 0);
107 cairo_set_line_width (cr, 1.0);
109 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
116 _draw_grand_staff (score_t *score, cairo_t *cr)
118 #define BRACE_GLYPHS 1
123 cairo_select_font_face (cr, "Gonville-Brace", 0, 0);
125 /* XXX: This font size (in conjunction with the glyph selection)
126 * is a rough guess at best. We should figure out how the brace
127 * font is intended to be used and actually measure to find the
128 * correctly sized glyph. */
129 cairo_set_font_size (cr, 40);
131 cairo_translate (cr, 5, 0);
134 /* XXX: This hard-coded glyph index is pretty ugly. We should
135 * figure out how to lookup the glyph we want, (though, as it
136 * turns out, this brace font pretty much just has numbered glyph
137 * names for different sizes, so it wouldn't be all that different
138 * than just the bare index here). */
141 brace.y = score->staff_height * 1.5;
143 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
144 cairo_show_glyphs (cr, &brace, 1);
146 cairo_translate (cr, 2, 0);
149 /* Vertical lines at each end */
153 score->staff_height * 3);
154 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
155 cairo_set_line_width (cr, 1.0);
159 _draw_staff (score, cr, SCORE_CLEF_G);
162 cairo_translate (cr, 0, score->staff_height * 2);
163 _draw_staff (score, cr, SCORE_CLEF_F);
169 score_draw (score_t *score, cairo_t *cr)
171 _draw_grand_staff (score, cr);