commit b4dea9cfd642340bc38ba4ddd71bfe3f8ce41394
parent 9693a8c486944835b8eb8a6ba52b41b1d5ef32e7
Author: nibo <nibo@relim.de>
Date: Wed, 7 Aug 2024 22:20:03 +0200
Fix chord parsing issues
Diffstat:
| M | chordpro.c | | | 60 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- |
| M | todo | | | 1 | - |
2 files changed, 57 insertions(+), 4 deletions(-)
diff --git a/chordpro.c b/chordpro.c
@@ -39,7 +39,7 @@ static const char *font_directives[] = {
"gridfont", "gridsize", "gridcolour",
"tabfont", "tabsize", "tabcolour",
"textfont", "tf", "textsize", "ts", "textcolour",
- "titlefont", "titlesize", "titlecolour"
+ "titlefont", "titlesize", "titlecolour", NULL
/* "footerfont", "footersize", "footercolour",
"tocfont", "tocsize", "toccolour", */
};
@@ -101,10 +101,12 @@ static const char *chord_extensions_major[] = {
"sus2", "sus4", "sus9",
"6sus2", "6sus4",
"7sus2", "7sus4",
- "13sus2", "13sus4"
+ "13sus2", "13sus4",
+ NULL
};
static const char *chord_extensions_minor[] = {
+ // https://www.chordpro.org/beta/chordpro-chords/#extensions-for-minor-chords
"#5",
"#5",
"m11",
@@ -134,9 +136,58 @@ static const char *chord_extensions_minor[] = {
"msus4", "msus9",
"-sus4", "-sus9",
"m7sus4",
- "-7sus4"
+ "-7sus4",
+ // custom
+ "m7",
+ "m9",
+ "m",
+ NULL
};
+#ifdef DEBUG
+
+static const char *cho_debug_chord_qualifier_to_string(enum ChordQualifier qual)
+{
+ switch (qual) {
+ case CQ_MIN:
+ return "CQ_MIN";
+ case CQ_MAJ:
+ return "CQ_MAJ";
+ case CQ_AUG:
+ return "CQ_AUG";
+ case CQ_DIM:
+ return "CQ_DIM";
+ default:
+ return "CQ_EMPTY";
+ }
+}
+
+static void cho_debug_chord_print(struct ChoChord *chord)
+{
+ printf("---- BEGIN CHORD ----\n");
+ printf("is_canonical: %d\n", chord->is_canonical);
+ printf("name: '%s'\n", chord->name);
+ if (chord->root) {
+ printf("root: '%s'\n", chord->root);
+ } else {
+ printf("root: 'NULL'\n");
+ }
+ printf("qual: '%s'\n", cho_debug_chord_qualifier_to_string(chord->qual));
+ if (chord->ext) {
+ printf("ext: '%s'\n", chord->ext);
+ } else {
+ printf("ext: 'NULL'\n");
+ }
+ if (chord->bass) {
+ printf("bass: '%s'\n", chord->bass);
+ } else {
+ printf("bass: 'NULL'\n");
+ }
+ printf("---- END CHORD ------\n");
+}
+
+#endif /* DEBUG */
+
static enum SongFragmentType g_current_ftype = SF_TEXT;
static enum SongFragmentType g_prev_ftype = SF_TEXT;
static struct Config *g_config = NULL;
@@ -1395,6 +1446,7 @@ static struct ChoChord *cho_chord_parse(const char *str)
if (ret == 0) {
return chord;
}
+ chord->qual = CQ_MAJ;
bytes_parsed += ret;
if (bytes_parsed == str_len) {
chord->is_canonical = true;
@@ -2244,6 +2296,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
}
cho_chord_free(tmp_chord);
is_chord_already_initialized = false;
+ // cho_debug_chord_print(songs[so]->sections[se]->lines[li]->text_above[c]->u.chord);
} else {
songs[so]->sections[se]->lines[li]->text_above = realloc(songs[so]->sections[se]->lines[li]->text_above, (c+1) * sizeof(struct ChoLineItemAbove *));
songs[so]->sections[se]->lines[li]->text_above[c] = malloc(sizeof(struct ChoLineItemAbove));
@@ -2251,6 +2304,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config)
chord_pos = cho_line_compute_chord_position(songs[so]->sections[se]->lines[li], ly, te);
songs[so]->sections[se]->lines[li]->text_above[c]->position = chord_pos;
songs[so]->sections[se]->lines[li]->text_above[c]->u.chord = cho_chord_parse(chord);
+ // cho_debug_chord_print(songs[so]->sections[se]->lines[li]->text_above[c]->u.chord);
}
memset(chord, 0, strlen(chord));
c++;
diff --git a/todo b/todo
@@ -1,4 +1,3 @@
-apply all config in cho_songs_parse() instead of out_pdf_new()
'chorus' directive
decide how to implement
'image' directive