]> git.cworth.org Git - scherzo/blobdiff - score.h
Fix high octave numbers (8+) to not be interpreted as 0.
[scherzo] / score.h
diff --git a/score.h b/score.h
index 26b976683cadb23bcfc47870fe7abe7022a00626..d2de1091c5cecdce1bd6cc6d4bb4d5d513c9e3f1 100644 (file)
--- a/score.h
+++ b/score.h
 #ifndef SCORE_H
 #define SCORE_H
 
+#include <talloc.h>
 #include <cairo.h>
 
-typedef struct score
+#include "scherzo-key.h"
+
+typedef enum score_duration
+{
+    SCORE_DURATION_WHOLE = 1,
+    SCORE_DURATION_1 = 1,
+    SCORE_DURATION_HALF = 2,
+    SCORE_DURATION_2 = 2,
+    SCORE_DURATION_QUARTER = 4,
+    SCORE_DURATION_4 = 4,
+    SCORE_DURATION_EIGHTH = 8,
+    SCORE_DURATION_8 = 8,
+    SCORE_DURATION_SIXTEENTH = 16,
+    SCORE_DURATION_16 = 16,
+    SCORE_DURATION_THIRTYSECOND = 32,
+    SCORE_DURATION_32 = 32,
+    SCORE_DURATION_SIXTYFOURTH = 64,
+    SCORE_DURATION_64 = 64,
+    SCORE_DURATION_ONEHUNDREDTWENTYEIGHTH = 128,
+    SCORE_DURATION_128 = 128
+} score_duration_t;
+
+#define SCORE_BUILD_NOTE(pitch, octave, duration) SCORE_PITCH_##pitch, (octave), SCORE_DURATION_##duration
+
+typedef struct score score_t;
+typedef struct score_staff score_staff_t;
+
+typedef struct score_chord
 {
-    /* Height of each space on staff. */
-    int space_height;
+    score_staff_t *staff;
+
+    char *name;
+    double width;
+} score_chord_t;
+
+typedef enum score_clef
+{
+    SCORE_CLEF_G,
+    SCORE_CLEF_TREBLE = SCORE_CLEF_G,
+    SCORE_CLEF_F,
+    SCORE_CLEF_BASS = SCORE_CLEF_F
+} score_clef_t;
+
+/* Allocate a new, empty score object, (with optional ctx as talloc
+ * owner). If ctx is NULL, the caller should call talloc_free on the
+ * score_t* when done with it. Otherwise, the object will be freed
+ * when ctx is freed. */
+score_t *
+score_create (void *ctx);
+
+/* Set an (approximate) staff height. The actual staff height may
+ * differ due to rounding to achieve evenly spaced, sharply rendered
+ * lines. the actual staff height is returned. */
+int
+score_set_staff_height (score_t *score, int height);
+
+/* Set the total width available for drawing the score. */
+void
+score_set_width (score_t *score, int width);
+
+/* Set the key for this score */
+void
+score_set_key (score_t *score, pitch_t key);
+
+/* Add a brace to the score, connecting the given number of staves.
+ *
+ * The staves to be connected are those that will next be added to the
+ * score. */
+void
+score_add_brace (score_t *score, int staves);
 
-    /* Total width available to score. */
-    int width;
-} score_t;
+/* Add a new staff to the score */
+score_staff_t *
+score_add_staff (score_t *score, score_clef_t clef);
 
+/* Add a note to a staff of the given pitch and duration.
+ *
+ * Duration values can be symbolic (SCORE_DURATION_WHOLE, _QUARTER,
+ * _EIGHTH, etc.) or numerical as simply the denominator (WHOLE=1,
+ * QUARTER=4, EIGHTH=8, etc.)
+ */
 void
-score_init (score_t *score);
+score_staff_add_note (score_staff_t *staff,
+                     pitch_t pitch,
+                     score_duration_t duration);
 
+/* Add a note to the score, (automatically selecting the nearest
+ * staff) */
+void
+score_add_note (score_t *score, pitch_t pitch, score_duration_t duration);
+
+/* Add a chord symbol of 'name' to a staff.
+ *
+ * For now, the chord symbols are free-form names.
+ *
+ * The chord name must be a talloc'ed string, which the returned
+ * score_chord_t will talloc_steal.
+ */
+score_chord_t *
+score_add_chord (score_staff_t *staff,
+                const char * name);
+
+/* Remove all chords from the given staff. */
+void
+score_staff_remove_chords (score_staff_t *staff);
+
+/* Remove all chords from the score. */
+void
+score_remove_chords (score_t *score);
+
+/* Remove all notes from the given staff. */
+void
+score_staff_remove_notes (score_staff_t *staff);
+
+/* Remove all notes from the score. */
+void
+score_remove_notes (score_t *score);
+
+/* Draw the given score_t onto the given cairo_t.
+ *
+ * The caller can call cairo_translate before calling score_draw to
+ * position the result as desired, (and can call cairo_clip to clip it
+ * if desired). */
 void
 score_draw (score_t *score, cairo_t *cr);