commit f0d20c50522d925f96b013d63c1d5e67bfbf6988
parent b589ffd2a01350f88c5676b737b0da0280978838
Author: nibo <nibo@relim.de>
Date: Wed, 12 Jun 2024 20:42:33 +0200
Set chord position correctly
Diffstat:
4 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/chordpro.c b/chordpro.c
@@ -725,7 +725,6 @@ struct Style *cho_tag_style_inherit(struct Tag **tags, int prev_index)
If no style can be inherited the
default style should be used.
*/
- printf("cho_tag_style_inherit: Return NULL\n");
return NULL;
}
@@ -786,7 +785,7 @@ struct ChoMetadata *cho_metadata_split(const char *directive_value)
struct ChoChord *cho_chord_new(void)
{
struct ChoChord *chord = malloc(sizeof(struct ChoChord));
- chord->index_in_lyrics = -1;
+ chord->position = -1;
chord->chord = NULL;
return chord;
}
@@ -799,6 +798,19 @@ struct ChoLine *cho_line_new(void)
return line;
}
+int cho_line_compute_chord_position(struct ChoLine *line, int ly, int te)
+{
+ if (ly == 0)
+ return te;
+ ly--;
+ size_t lyrics_len = 0;
+ while (ly >= 0) {
+ lyrics_len += strlen(line->lyrics[ly]->text);
+ ly--;
+ }
+ return lyrics_len + te;
+}
+
struct ChoLineItem *cho_line_item_new(void)
{
struct ChoLineItem *item = malloc(sizeof(struct ChoLineItem));
@@ -1052,6 +1064,7 @@ struct ChoSong **cho_parse(FILE *fp)
int at = 0;
int atn = 0;
int atv = 0;
+ int chord_pos;
size_t read;
enum AttrValueSyntax avs = AVS_NO;
struct ChoDirective *directive = NULL;
@@ -1298,7 +1311,6 @@ struct ChoSong **cho_parse(FILE *fp)
char *trimmed_directive_value = string_remove_leading_whitespace(directive_value);
songs[so]->sections[se]->lines[li]->lyrics[ly]->text = trimmed_directive_value;
te += strlen(trimmed_directive_value);
- // te = 0;
break;
case DT_PREAMBLE:
fprintf(stderr, "INFO: Preamble directive '%s' can't have a value.\n", directive_name);
@@ -1321,7 +1333,8 @@ struct ChoSong **cho_parse(FILE *fp)
ch = 0;
songs[so]->sections[se]->lines[li]->chords = realloc(songs[so]->sections[se]->lines[li]->chords, (c+1) * sizeof(struct ChoChord *));
songs[so]->sections[se]->lines[li]->chords[c] = cho_chord_new();
- songs[so]->sections[se]->lines[li]->chords[c]->index_in_lyrics = ly;
+ chord_pos = cho_line_compute_chord_position(songs[so]->sections[se]->lines[li], ly, te);
+ songs[so]->sections[se]->lines[li]->chords[c]->position = chord_pos;
songs[so]->sections[se]->lines[li]->chords[c]->chord = strdup(chord);
memset(chord, 0, strlen(chord));
c++;
diff --git a/chordpro.h b/chordpro.h
@@ -122,7 +122,7 @@ struct ChoMetadata {
struct ChoChord {
// struct Style *style;
- int index_in_lyrics;
+ int position;
char *chord;
};
diff --git a/lorid.c b/lorid.c
@@ -46,12 +46,12 @@ int main(int argc, char *argv[])
/* m++;*/
/*}*/
/*printf("---- END METADATA ------\n");*/
- // struct ChoChord **chords;
+ /* struct ChoChord **chords;
enum SectionType stype;
struct ChoLineItem *line_item;
int s = 0;
int li = 0;
- // int c = 0;
+ int c = 0;
int ly = 0;
struct ChoSong *song = songs[0];
while (song->sections[s] != NULL) {
@@ -63,18 +63,18 @@ int main(int argc, char *argv[])
}
while (song->sections[s]->lines[li] != NULL) {
printf("---- BEGIN LINE ----\n");
- /* chords = song->sections[s]->lines[li]->chords;
+ chords = song->sections[s]->lines[li]->chords;
while (chords[c] != NULL) {
- printf("index: %d, chord: %s | ", chords[c]->index_in_lyrics, chords[c]->chord);
+ printf("index: %d, chord: %s | ", chords[c]->position, chords[c]->chord);
c++;
}
printf("\n");
- c = 0; */
+ c = 0;
while (song->sections[s]->lines[li]->lyrics[ly] != NULL) {
line_item = song->sections[s]->lines[li]->lyrics[ly];
if (strlen(line_item->text) > 0) {
printf("text: %s\n", line_item->text);
- cho_style_print(line_item->style);
+ // cho_style_print(line_item->style);
}
ly++;
}
@@ -85,7 +85,7 @@ int main(int argc, char *argv[])
li = 0;
s++;
printf("---- END SECTION ------\n");
- }
+ } */
cho_songs_free(songs);
fclose(fp);
return 0;
diff --git a/todo b/todo
@@ -3,4 +3,4 @@
'image' directive
decide if implement
chordpro markup
- https://chordpro.org/chordpro/chordpro_markup/
+ implement inside chords