lorid

convert chordpro to pdf
git clone git://git.relim.de/lorid.git
Log | Files | Refs | README | LICENSE

commit b9bdabaf1aeb7a59dcabfc617b8db5b42e1cdb79
parent 7163891bf4947d27a9ad4891f204bd889992fc91
Author: nibo <nibo@relim.de>
Date:   Mon,  3 Feb 2025 17:54:58 +0100

Outsource shared types into types.h and parse 'diagram' define directive option

Diffstat:
MMakefile | 2+-
Mchord_diagram.c | 26++++++++++++++++----------
Mchord_diagram.h | 28+++++++---------------------
Mchordpro.c | 153+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Mchordpro.h | 221++-----------------------------------------------------------------------------
Mconfig.c | 3++-
Mconfig.h | 82++-----------------------------------------------------------------------------
Mlorid.c | 1+
Mout_pdf.c | 3++-
Mout_pdf.h | 1+
Atypes.h | 333+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mutil.c | 1+
Mutil.h | 14++------------
13 files changed, 482 insertions(+), 386 deletions(-)

diff --git a/Makefile b/Makefile @@ -38,7 +38,7 @@ uninstall: rm ${PREFIX}/share/lorid/ChordProSymbols.ttf dist: mkdir -p lorid-v${VERSION}/ - cp -r *.c *.h misc/ Makefile README lorid.1 lorid_config.5 lorid-v${VERSION}/ + cp -r *.c *.h misc/ Makefile DEVELOPMENT_NOTES README.md lorid.1 lorid_config.5 lorid-v${VERSION}/ tar czf lorid-v${VERSION}.tar.gz lorid-v${VERSION}/* rm -rf lorid-v${VERSION}/ html: diff --git a/chord_diagram.c b/chord_diagram.c @@ -1,6 +1,8 @@ #include <string.h> +#include <ctype.h> #include <pdfio.h> #include <pdfio-content.h> +#include "types.h" #include "out_pdf.h" #include "util.h" #include "config.h" @@ -292,7 +294,7 @@ draw_circle_with_char_inside( return true; } -static struct StringDiagram * +struct StringDiagram * string_diagram_new(void) { struct StringDiagram *d = emalloc(sizeof(struct StringDiagram)); @@ -511,7 +513,7 @@ string_diagram_draw( return true; } -static struct KeyboardDiagram * +struct KeyboardDiagram * keyboard_diagram_new(void) { struct KeyboardDiagram *d = emalloc(sizeof(struct KeyboardDiagram)); @@ -540,22 +542,18 @@ keyboard_diagram_copy(struct KeyboardDiagram *diagram) } */ struct ChordDiagram * -chord_diagram_new(bool is_string_instrument) +chord_diagram_new() { struct ChordDiagram *d = emalloc(sizeof(struct ChordDiagram)); - if (is_string_instrument) { - d->is_string_instrument = true; - d->u.sd = string_diagram_new(); - } else { - d->is_string_instrument = false; - d->u.kd = keyboard_diagram_new(); - } + d->show = true; + d->color = cho_rgbcolor_new(20, 20, 20); return d; } void chord_diagram_free(struct ChordDiagram *d) { + free(d->color); if (d->is_string_instrument) { string_diagram_free(d->u.sd); } else { @@ -597,6 +595,14 @@ debug_chord_diagram_print(struct ChordDiagram *diagram) { int i; printf("---- CHORD DIAGRAM BEGIN ----\n"); + printf("show: %s\n", diagram->show ? "true" : "false"); + + char str[8]; + str[7] = 0; + sprintf((char *)&str, "#%02X%02X%02X", diagram->color->red, diagram->color->green, diagram->color->blue); + + printf("color: %s\n", str); + if (diagram->is_string_instrument) { printf("name: %s\n", diagram->u.sd->name); printf("base-fret: %d\n", diagram->u.sd->base_fret); diff --git a/chord_diagram.h b/chord_diagram.h @@ -1,4 +1,5 @@ #include <pdfio.h> +#include "types.h" enum TextRendering { FILL, @@ -11,29 +12,14 @@ enum Direction { VERTICAL }; -struct StringDiagram { - char *name; - int8_t base_fret; - int8_t frets[12]; - int8_t fingers[12]; -}; +struct ChordDiagram *chord_diagram_new(); +void chord_diagram_free(struct ChordDiagram *d); +bool chord_diagram_draw(pdfio_stream_t *stream, struct ChordDiagram *diagram, double x, double y, double width); -struct KeyboardDiagram { - char *name; - int8_t keys[24]; -}; +struct StringDiagram *string_diagram_new(void); +struct KeyboardDiagram *keyboard_diagram_new(void); -struct ChordDiagram { - bool is_string_instrument; - union { - struct StringDiagram *sd; - struct KeyboardDiagram *kd; - } u; -}; - -struct ChordDiagram *chord_diagram_new(bool is_string_instrument); -void chord_diagram_free(struct ChordDiagram *d); void chord_diagrams_free(struct ChordDiagram **diagrams); -bool chord_diagram_draw(pdfio_stream_t *stream, struct ChordDiagram *diagram, double x, double y, double width); struct ChordDiagram **chord_diagrams_create(struct Config *config, struct ChoChord ***chords, struct ChordDiagram **custom_diagram); + void debug_chord_diagram_print(struct ChordDiagram *diagram); diff --git a/chordpro.c b/chordpro.c @@ -8,10 +8,11 @@ #include <ctype.h> #include <errno.h> #include <limits.h> +#include "types.h" #include "chordpro.h" -// #include "config.h" #include "util.h" #include "chord_diagram.h" +#include "config.h" static const char *font_families[] = { "normal", "sans", "serif", "monospace" }; static const char *font_styles[] = { "normal", "oblique", "italic" }; @@ -359,7 +360,7 @@ is_whitespace(char c) return false; } -static struct RGBColor * +struct RGBColor * cho_rgbcolor_new(uint8_t red, uint8_t green, uint8_t blue) { struct RGBColor *color = emalloc(sizeof(struct RGBColor)); @@ -2766,32 +2767,32 @@ finger_to_int(char c) static struct ChordDiagram * cho_chord_diagram_parse(const char *str) { - struct ChordDiagram *diagram = NULL; + struct ChordDiagram *diagram = chord_diagram_new(); enum ChordDiagramState state = CDS_NAME; enum ChordDiagramContent current_content = -1; enum ChordDiagramContent future_content = -1; bool is_maybe_minus_one = false; - char c; char name[20]; char option[10]; char key[3]; char base_fret[3]; + char diagram_value[7+1]; int n = 0; int o = 0; int k = 0; int b = 0; + int d = 0; int f = 0; - int i; int fret_count = 0; int finger_count = 0; int8_t number = -2; long l; - for (i = 0; str[i]; i++) { - c = str[i]; + const char *c; + for (c = str; *c; c++) { // printf("c '%c' state '%d'\n", c, state); switch (state) { - case CDS_NAME: - if (is_whitespace(c)) { + case CDS_NAME: { + if (is_whitespace(*c)) { if (n == 0) { break; } @@ -2803,16 +2804,17 @@ cho_chord_diagram_parse(const char *str) cho_log(LOG_ERR, "Chord name in chord diagram is too long."); return NULL; } - name[n] = c; + name[n] = *c; n++; break; - case CDS_OPTION_NAME: - CDS_OPTION_NAME_LABEL: - if (is_whitespace(c)) { + } + case CDS_OPTION_NAME: { + if (is_whitespace(*c)) { if (o == 0) { break; } option[o] = 0; + future_content = -1; if (!strcmp(option, "base-fret")) { state = CDS_BASE_FRET; future_content = CDC_STRING; @@ -2828,21 +2830,26 @@ cho_chord_diagram_parse(const char *str) if (!strcmp(option, "keys")) { state = CDS_KEYS; future_content = CDC_KEYBOARD; + } else + if (!strcmp(option, "diagram")) { + state = CDS_DIAGRAM; } else { cho_log(LOG_ERR, "Invalid option '%s' in define directive.", option); return NULL; } memset(option, 0, o); o = 0; - if (current_content == -1) { + if (current_content == -1 && future_content != -1) { current_content = future_content; switch (future_content) { case CDC_STRING: - diagram = chord_diagram_new(true); + diagram->is_string_instrument = true; + diagram->u.sd = string_diagram_new(); diagram->u.sd->name = strdup(name); break; case CDC_KEYBOARD: - diagram = chord_diagram_new(false); + diagram->is_string_instrument = false; + diagram->u.kd = keyboard_diagram_new(); diagram->u.kd->name = strdup(name); break; default: @@ -2855,11 +2862,12 @@ cho_chord_diagram_parse(const char *str) cho_log(LOG_ERR, "Option in chord diagram is too long."); return NULL; } - option[o] = c; + option[o] = *c; o++; break; - case CDS_BASE_FRET: - if (is_whitespace(c)) { + } + case CDS_BASE_FRET: { + if (is_whitespace(*c)) { if (b == 0) { break; } @@ -2871,7 +2879,7 @@ cho_chord_diagram_parse(const char *str) return NULL; } if (l == 0) { - cho_log(LOG_ERR, "Invalid base-fret value '%c' in chord diagram.", c); + cho_log(LOG_ERR, "Invalid base-fret value '%c' in chord diagram.", *c); return NULL; } diagram->u.sd->base_fret = (int8_t)l; @@ -2880,43 +2888,45 @@ cho_chord_diagram_parse(const char *str) } if (b > 1) { cho_log(LOG_ERR, "base-fret value is too long."); - printf("c: %c\n", c); + printf("c: %c\n", *c); return NULL; } - base_fret[b] = c; + base_fret[b] = *c; b++; break; - case CDS_FRETS: + } + case CDS_FRETS: { number = -2; - if (is_whitespace(c)) { + if (is_whitespace(*c)) { break; } - if (c == '-') { + if (*c == '-') { is_maybe_minus_one = true; break; } if (is_maybe_minus_one) { - if (c == '1') { + if (*c == '1') { number = -1; is_maybe_minus_one = false; } else { - cho_log(LOG_ERR, "Invalid frets value '-%c' in chord diagram.", c); + cho_log(LOG_ERR, "Invalid frets value '-%c' in chord diagram.", *c); return NULL; } } - if (c == 'N' || c == 'x') { + if (*c == 'N' || *c == 'x') { number = -1; } else - if (isalpha(c)) { + if (isalpha(*c)) { f = 0; state = CDS_OPTION_NAME; - goto CDS_OPTION_NAME_LABEL; + c--; + break; } if (number == -2) { - number = char_to_positive_int(c); + number = char_to_positive_int(*c); if (number == -1) { LOG_DEBUG("char_to_positive_int failed."); - cho_log(LOG_ERR, "Invalid frets value '%c' in chord diagram.", c); + cho_log(LOG_ERR, "Invalid frets value '%c' in chord diagram.", *c); return NULL; } } @@ -2928,18 +2938,20 @@ cho_chord_diagram_parse(const char *str) f++; fret_count++; break; - case CDS_FINGERS: - if (is_whitespace(c)) { + } + case CDS_FINGERS: { + if (is_whitespace(*c)) { break; } - if (c == 'b' || c == 'f') { + if (*c == 'b' || *c == 'f') { f = 0; state = CDS_OPTION_NAME; - goto CDS_OPTION_NAME_LABEL; + c--; + break; } - number = finger_to_int(c); + number = finger_to_int(*c); if (number == -2) { - cho_log(LOG_ERR, "Invalid fingers value '%c' in chord diagram.", c); + cho_log(LOG_ERR, "Invalid fingers value '%c' in chord diagram.", *c); return NULL; } if (f > 11) { @@ -2950,8 +2962,9 @@ cho_chord_diagram_parse(const char *str) f++; finger_count++; break; - case CDS_KEYS: - if (is_whitespace(c)) { + } + case CDS_KEYS: { + if (is_whitespace(*c)) { if (k == 0) { break; } @@ -2971,17 +2984,51 @@ cho_chord_diagram_parse(const char *str) f++; break; } + if (isalpha(*c)) { + state = CDS_OPTION_NAME; + c--; + break; + } if (k > 1) { cho_log(LOG_ERR, "Too high key value in chord diagram. '%d'", k); printf("key '%s'\n", key); return NULL; } - key[k] = c; + key[k] = *c; k++; break; } + case CDS_DIAGRAM: { + if (is_whitespace(*c)) { + if (d == 0) { + break; + } + diagram_value[d] = 0; + d = 0; + if (!strcmp(diagram_value, "off")) { + diagram->show = false; + } else + if (!strcmp(diagram_value, "on")) { + // INFO: but this is already the default + diagram->show = true; + } else { + diagram->color = cho_color_parse(diagram_value); + if (!diagram->color) { + LOG_DEBUG("cho_color_parse failed."); + return NULL; + } + } + state = CDS_OPTION_NAME; + break; + } + diagram_value[d] = *c; + d++; + break; + } + } } - if (current_content == CDC_KEYBOARD) { + switch (state) { + case CDS_KEYS: { key[k] = 0; if (strlen(key) > 0) { l = str_to_number(key); @@ -2996,6 +3043,27 @@ cho_chord_diagram_parse(const char *str) } diagram->u.kd->keys[f] = (int8_t)l; } + break; + } + case CDS_DIAGRAM: { + diagram_value[d] = 0; + if (!strcmp(diagram_value, "off")) { + diagram->show = false; + } else + if (!strcmp(diagram_value, "on")) { + // INFO: but this is already the default + diagram->show = true; + } else { + free(diagram->color); + diagram->color = cho_color_parse(diagram_value); + if (!diagram->color) { + LOG_DEBUG("cho_color_parse failed."); + return NULL; + } + } + break; + default: + } } if ( current_content == CDC_STRING && @@ -4589,7 +4657,6 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) songs[so]->diagrams[dia] = diagram; dia++; // debug_chord_diagram_print(diagram); - // chord_diagram_free(diagram); break; } break; diff --git a/chordpro.h b/chordpro.h @@ -1,60 +1,9 @@ #include <stdint.h> +#include "types.h" #ifndef _CHORDPRO_H_ #define _CHORDPRO_H_ -enum TextType : int8_t { - TT_CHORD, - TT_ANNOT, - TT_CHORUS, - TT_FOOTER, - TT_GRID, - TT_TAB, - TT_TOC, - TT_TOC_TITLE, - TT_TEXT, - TT_TITLE, - TT_SUBTITLE, - TT_LABEL, - TT_COMMENT, - TT_COMMENT_ITALIC, - TT_COMMENT_BOX, - TT_LENGTH -}; - -enum Alignment : int8_t { - A_LEFT, - A_CENTER, - A_RIGHT -}; - -struct FontPresence { - bool name; - bool family; - bool style; - bool weight; - bool size; -}; - -struct ChoStylePresence { - struct FontPresence font; - bool foreground_color; - bool background_color; - bool underline_style; - bool underline_color; - bool overline_style; - bool overline_color; - bool strikethrough; - bool strikethrough_color; - bool boxed; - bool boxed_color; - bool rise; - bool href; -}; - -#include "config.h" - - #define ERROR -1.0 #define EMPTY_DOUBLE -1.0 #define EMPTY_INT -1 @@ -64,26 +13,12 @@ struct ChoStylePresence { #define URL_MAX_LEN 2000 #define FONT_NAME_MAX 100 -enum Anchor { - AN_PAPER, - AN_PAGE, - AN_COLUMN, - AN_LINE, - AN_FLOAT -}; - enum AttrValueSyntax : int8_t { AVS_QUOTATION_MARK, AVS_APOSTROPHE, AVS_UNQUOTED }; -enum BreakType : int8_t { - BT_LINE, - BT_PAGE, - BT_COLUMN -}; - enum ChordDiagramContent : int8_t { CDC_STRING, CDC_KEYBOARD @@ -95,20 +30,14 @@ enum ChordDiagramState { CDS_BASE_FRET, CDS_FRETS, CDS_FINGERS, - CDS_KEYS + CDS_KEYS, + CDS_DIAGRAM }; enum ChordDirective { TRANSPOSE, DEFINE /* , CHORD */ }; -enum ChordQualifier { - CQ_MIN, - CQ_MAJ, - CQ_AUG, - CQ_DIM -}; - enum DirectiveType { DT_ENVIRONMENT, DT_METADATA, @@ -122,30 +51,6 @@ enum DirectiveType { DT_CUSTOM }; -enum FontFamily : int8_t { - FF_NORMAL, - FF_SANS, - FF_SERIF, - FF_MONOSPACE -}; - -enum FontStyle : int8_t { - FS_ROMAN, - FS_OBLIQUE, - FS_ITALIC -}; - -enum FontWeight : int8_t { - FW_REGULAR, - FW_BOLD -}; - -enum LineStyle : int8_t { - LS_SINGLE, - LS_DOUBLE, - LS_NONE -}; - enum MetadataDirective { TITLE, SUBTITLE @@ -162,16 +67,6 @@ enum Position { POS_NO }; -enum SectionType { - ST_NEWSONG, - ST_CHORUS, - ST_VERSE, - ST_BRIDGE, - ST_TAB, - ST_GRID, - ST_CUSTOM -}; - enum State { STATE_LYRICS, STATE_BACKSLASH, @@ -199,46 +94,6 @@ struct Attr { char *value; }; -struct Font { - char *name; - enum FontFamily family; - enum FontStyle style; - enum FontWeight weight; - double size; -}; - -struct RGBColor { - uint8_t red; - uint8_t green; - uint8_t blue; -}; - -struct ChoStyle { - struct Font *font; - struct RGBColor *foreground_color; - struct RGBColor *background_color; - enum LineStyle underline_style; - struct RGBColor *underline_color; - enum LineStyle overline_style; - struct RGBColor *overline_color; - bool strikethrough; - struct RGBColor *strikethrough_color; - bool boxed; - struct RGBColor *boxed_color; - double rise; - char *href; -}; - -struct ChoChord { - struct ChoStyle *style; - bool is_canonical; - char *name; - char *root; - enum ChordQualifier qual; - char *ext; - char *bass; -}; - /* INFO: Depending on the 'dtype' the other fields have a meaningful value or not. @@ -256,75 +111,6 @@ struct ChoDirective { struct ChoStyle *style; }; -struct ChoImage { - bool is_asset; - char *id; - char *src; - struct Size *width; - struct Size *height; - struct Size *width_scale; - struct Size *height_scale; - enum Alignment align; - double border; - struct Size *spread_space; - char *href; - struct Size *x; - struct Size *y; - enum Anchor anchor; - struct Size *dx; - struct Size *dy; - struct Size *w; - struct Size *h; - bool bbox; -}; - -struct ChoText { - struct ChoStyle *style; - char *text; -}; - -struct ChoLineItem { - bool is_text; - union { - struct ChoImage *image; - struct ChoText *text; - } u; -}; - -struct ChoLineItemAbove { - int position; - bool is_chord; - union { - struct ChoChord *chord; - struct ChoText *annot; - } u; -}; - -struct ChoLine { - struct ChoLineItemAbove **text_above; - struct ChoLineItem **items; - enum BreakType btype; -}; - -struct ChoMetadata { - char *name; - char *value; - struct ChoStyle *style; -}; - -struct ChoSection { - enum SectionType type; - struct ChoText *label; - struct ChoLine **lines; -}; - -struct ChoSong { - struct ChoMetadata **metadata; - struct ChoSection **sections; - struct ChordDiagram **diagrams; - bool present_text_types[TT_LENGTH]; -}; - union StylePropertyValue { char *font_name; double font_size; @@ -368,6 +154,7 @@ void cho_style_free(struct ChoStyle *style); struct ChoStyle *cho_style_copy(struct ChoStyle *style); void cho_style_print_as_toml(struct ChoStyle *style, const char *section); +struct RGBColor *cho_rgbcolor_new(uint8_t red, uint8_t green, uint8_t blue); struct RGBColor *cho_color_parse(const char *str); struct RGBColor *cho_color_copy(struct RGBColor *color); enum LineStyle cho_linestyle_parse(const char *str); diff --git a/config.c b/config.c @@ -2,8 +2,9 @@ #include <stdlib.h> #include <string.h> #include <toml.h> -#include "chordpro.h" +#include "types.h" #include "config.h" +#include "chordpro.h" #include "util.h" #include "chord_diagram.h" diff --git a/config.h b/config.h @@ -1,3 +1,5 @@ +#include "types.h" + #ifndef _CONFIG_H_ #define _CONFIG_H_ @@ -8,86 +10,6 @@ #endif /* DEBUG */ #define DEFAULT_FONT_FAMILY "Open Sans" -enum NotationSystem { - NS_COMMON, - NS_GERMAN, - NS_SCANDINAVIAN, - NS_LATIN, - NS_ROMAN, - NS_NASHVILLE, - NS_CUSTOM -}; - -enum ParseMode { - PM_STRICT, - PM_RELAXED -}; - -enum NoteType { - NT_NOTE, - NT_SHARP, - NT_FLAT -}; - -enum Instrument : int8_t { - INS_GUITAR, - INS_KEYBOARD, - INS_MANDOLIN, - INS_UKULELE -}; - -struct Note { - char *note; - char *sharp; - char *flat; -}; - -struct ConfigChords { - enum NotationSystem notation_system; - enum ParseMode mode; -}; - -struct ConfigChorus { - char *label; - bool quote; -}; - -struct ConfigParser { - struct ConfigChords *chords; - struct Note **notes; -}; - -struct ConfigChordDiagram { - bool show; - enum Instrument instrument; -}; - -struct ConfigToc { - bool show; - char *title; -}; - -struct ConfigPageNo { - bool show; - enum Alignment align; -}; - -struct ConfigOutput { - struct ConfigChorus *chorus; - struct ConfigToc *toc; - struct ConfigChordDiagram *diagram; - struct ConfigPageNo *page_no; - struct ChoStyle **styles; // TODO: Make array of size 7 - struct Note **notes; - enum NotationSystem notation_system; - bool start_song_on_new_page; -}; - -struct Config { - struct ConfigOutput *output; - struct ConfigParser *parser; -}; - struct Config *config_load(const char *filepath); void config_free(struct Config *config); void config_print_default(void); diff --git a/lorid.c b/lorid.c @@ -3,6 +3,7 @@ #include <stdbool.h> #include <string.h> #include <getopt.h> +#include "types.h" #include "chordpro.h" #include "config.h" #include "out_pdf.h" diff --git a/out_pdf.c b/out_pdf.c @@ -8,9 +8,10 @@ #include <fontconfig/fontconfig.h> #include <grapheme.h> #include <math.h> +#include "types.h" +#include "out_pdf.h" #include "chordpro.h" #include "config.h" -#include "out_pdf.h" #include "util.h" #include "chord_diagram.h" diff --git a/out_pdf.h b/out_pdf.h @@ -1,4 +1,5 @@ #include <pdfio.h> +#include "types.h" #include "chordpro.h" #define MEDIABOX_HEIGHT 841.995 diff --git a/types.h b/types.h @@ -0,0 +1,333 @@ +#include <stdint.h> + +#ifndef _TYPES_H_ +#define _TYPES_H_ + +enum TextType : int8_t { + TT_CHORD, + TT_ANNOT, + TT_CHORUS, + TT_FOOTER, + TT_GRID, + TT_TAB, + TT_TOC, + TT_TOC_TITLE, + TT_TEXT, + TT_TITLE, + TT_SUBTITLE, + TT_LABEL, + TT_COMMENT, + TT_COMMENT_ITALIC, + TT_COMMENT_BOX, + TT_LENGTH +}; + +enum Alignment : int8_t { + A_LEFT, + A_CENTER, + A_RIGHT +}; + +enum Anchor { + AN_PAPER, + AN_PAGE, + AN_COLUMN, + AN_LINE, + AN_FLOAT +}; + +enum BreakType : int8_t { + BT_LINE, + BT_PAGE, + BT_COLUMN +}; + +enum ChordQualifier { + CQ_MIN, + CQ_MAJ, + CQ_AUG, + CQ_DIM +}; + +enum SectionType { + ST_NEWSONG, + ST_CHORUS, + ST_VERSE, + ST_BRIDGE, + ST_TAB, + ST_GRID, + ST_CUSTOM +}; + +enum SizeType { + ST_POINT, + ST_PERCENT, + ST_EM, + ST_EX +}; + +enum FontFamily : int8_t { + FF_NORMAL, + FF_SANS, + FF_SERIF, + FF_MONOSPACE +}; + +enum FontStyle : int8_t { + FS_ROMAN, + FS_OBLIQUE, + FS_ITALIC +}; + +enum FontWeight : int8_t { + FW_REGULAR, + FW_BOLD +}; + +enum LineStyle : int8_t { + LS_SINGLE, + LS_DOUBLE, + LS_NONE +}; + +enum NoteType { + NT_NOTE, + NT_SHARP, + NT_FLAT +}; + +struct FontPresence { + bool name; + bool family; + bool style; + bool weight; + bool size; +}; + +struct ChoStylePresence { + struct FontPresence font; + bool foreground_color; + bool background_color; + bool underline_style; + bool underline_color; + bool overline_style; + bool overline_color; + bool strikethrough; + bool strikethrough_color; + bool boxed; + bool boxed_color; + bool rise; + bool href; +}; + +struct Font { + char *name; + enum FontFamily family; + enum FontStyle style; + enum FontWeight weight; + double size; +}; + +struct RGBColor { + uint8_t red; + uint8_t green; + uint8_t blue; +}; + +struct ChoStyle { + struct Font *font; + struct RGBColor *foreground_color; + struct RGBColor *background_color; + enum LineStyle underline_style; + struct RGBColor *underline_color; + enum LineStyle overline_style; + struct RGBColor *overline_color; + bool strikethrough; + struct RGBColor *strikethrough_color; + bool boxed; + struct RGBColor *boxed_color; + double rise; + char *href; +}; + +struct ChoChord { + struct ChoStyle *style; + bool is_canonical; + char *name; + char *root; + enum ChordQualifier qual; + char *ext; + char *bass; +}; + +struct ChoText { + struct ChoStyle *style; + char *text; +}; + +struct ChoLineItem { + bool is_text; + union { + struct ChoImage *image; + struct ChoText *text; + } u; +}; + +struct ChoLineItemAbove { + int position; + bool is_chord; + union { + struct ChoChord *chord; + struct ChoText *annot; + } u; +}; + +struct ChoLine { + struct ChoLineItemAbove **text_above; + struct ChoLineItem **items; + enum BreakType btype; +}; + +struct ChoMetadata { + char *name; + char *value; + struct ChoStyle *style; +}; + +struct ChoSection { + enum SectionType type; + struct ChoText *label; + struct ChoLine **lines; +}; + +struct ChoSong { + struct ChoMetadata **metadata; + struct ChoSection **sections; + struct ChordDiagram **diagrams; + bool present_text_types[TT_LENGTH]; +}; + +struct ChoImage { + bool is_asset; + char *id; + char *src; + struct Size *width; + struct Size *height; + struct Size *width_scale; + struct Size *height_scale; + enum Alignment align; + double border; + struct Size *spread_space; + char *href; + struct Size *x; + struct Size *y; + enum Anchor anchor; + struct Size *dx; + struct Size *dy; + struct Size *w; + struct Size *h; + bool bbox; +}; + +struct Size { + enum SizeType type; + double d; +}; + +struct StringDiagram { + char *name; + int8_t base_fret; + int8_t frets[12]; + int8_t fingers[12]; +}; + +struct KeyboardDiagram { + char *name; + int8_t keys[24]; +}; + +struct ChordDiagram { + bool show; + struct RGBColor *color; + bool is_string_instrument; + union { + struct StringDiagram *sd; + struct KeyboardDiagram *kd; + } u; +}; + +enum NotationSystem { + NS_COMMON, + NS_GERMAN, + NS_SCANDINAVIAN, + NS_LATIN, + NS_ROMAN, + NS_NASHVILLE, + NS_CUSTOM +}; + +enum ParseMode { + PM_STRICT, + PM_RELAXED +}; + +enum Instrument : int8_t { + INS_GUITAR, + INS_KEYBOARD, + INS_MANDOLIN, + INS_UKULELE +}; + +struct Note { + char *note; + char *sharp; + char *flat; +}; + +struct ConfigChords { + enum NotationSystem notation_system; + enum ParseMode mode; +}; + +struct ConfigChorus { + char *label; + bool quote; +}; + +struct ConfigParser { + struct ConfigChords *chords; + struct Note **notes; +}; + +struct ConfigChordDiagram { + bool show; + enum Instrument instrument; +}; + +struct ConfigToc { + bool show; + char *title; +}; + +struct ConfigPageNo { + bool show; + enum Alignment align; +}; + +struct ConfigOutput { + struct ConfigChorus *chorus; + struct ConfigToc *toc; + struct ConfigChordDiagram *diagram; + struct ConfigPageNo *page_no; + struct ChoStyle **styles; // TODO: Make array of size 7 + struct Note **notes; + enum NotationSystem notation_system; + bool start_song_on_new_page; +}; + +struct Config { + struct ConfigOutput *output; + struct ConfigParser *parser; +}; + +#endif /* _TYPES_H_ */ diff --git a/util.c b/util.c @@ -8,6 +8,7 @@ #include <errno.h> #include <assert.h> #include <limits.h> +#include "types.h" #include "util.h" static bool g_show_info_logs = false; diff --git a/util.h b/util.h @@ -1,3 +1,5 @@ +#include "types.h" + #ifdef DEBUG #define LOG_DEBUG(msg) fprintf(stderr, msg"\n") #else @@ -26,18 +28,6 @@ enum FileType { F_OTHER }; -enum SizeType { - ST_POINT, - ST_PERCENT, - ST_EM, - ST_EX -}; - -struct Size { - enum SizeType type; - double d; -}; - void util_log_enable_info_logs(void); void *emalloc(size_t size);