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 #include "scherzo-key.h"
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_chord
62 typedef enum score_clef
65 SCORE_CLEF_TREBLE = SCORE_CLEF_G,
67 SCORE_CLEF_BASS = SCORE_CLEF_F
70 /* Allocate a new, empty score object, (with optional ctx as talloc
71 * owner). If ctx is NULL, the caller should call talloc_free on the
72 * score_t* when done with it. Otherwise, the object will be freed
73 * when ctx is freed. */
75 score_create (void *ctx);
77 /* Set an (approximate) staff height. The actual staff height may
78 * differ due to rounding to achieve evenly spaced, sharply rendered
79 * lines. the actual staff height is returned. */
81 score_set_staff_height (score_t *score, int height);
83 /* Set the total width available for drawing the score. */
85 score_set_width (score_t *score, int width);
87 /* Set the key for this score */
89 score_set_key (score_t *score, pitch_t key);
91 /* Add a brace to the score, connecting the given number of staves.
93 * The staves to be connected are those that will next be added to the
96 score_add_brace (score_t *score, int staves);
98 /* Add a new staff to the score */
100 score_add_staff (score_t *score, score_clef_t clef);
102 /* Add a note to a staff of the given pitch and duration.
104 * Duration values can be symbolic (SCORE_DURATION_WHOLE, _QUARTER,
105 * _EIGHTH, etc.) or numerical as simply the denominator (WHOLE=1,
106 * QUARTER=4, EIGHTH=8, etc.)
109 score_staff_add_note (score_staff_t *staff,
111 score_duration_t duration);
113 /* Add a note to the score, (automatically selecting the nearest
116 score_add_note (score_t *score, pitch_t pitch, score_duration_t duration);
118 /* Add a chord symbol of 'name' to a staff.
120 * For now, the chord symbols are free-form names.
122 * The chord name must be a talloc'ed string, which the returned
123 * score_chord_t will talloc_steal.
126 score_add_chord (score_staff_t *staff,
129 /* Remove all chords from the given staff. */
131 score_staff_remove_chords (score_staff_t *staff);
133 /* Remove all chords from the score. */
135 score_remove_chords (score_t *score);
137 /* Remove all notes from the given staff. */
139 score_staff_remove_notes (score_staff_t *staff);
141 /* Remove all notes from the score. */
143 score_remove_notes (score_t *score);
145 /* Draw the given score_t onto the given cairo_t.
147 * The caller can call cairo_translate before calling score_draw to
148 * position the result as desired, (and can call cairo_clip to clip it
151 score_draw (score_t *score, cairo_t *cr);