Parse a few more fields.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 4 Mar 2006 15:35:10 +0000 (16:35 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 4 Mar 2006 15:35:10 +0000 (16:35 +0100)
ChangeLog
ptb.c
ptb.h
ptb2xml.c
ptbinfo.c

index f63fb9df2a73f68a2e4d2129c60ec98797b0ed79..8ef39d31696b4cd16c6827f22aa06f23050a6109 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@ All changes, unless specified otherwise, made by Jelmer Vernooij
 0.5.0:
  * Portability improvements. 
  * Switched VCS to bazaar.
+ * Support a few more fields (based on ptparse released by Brad).
 
 0.4.3:
  * Fix MacOSX shared library build
diff --git a/ptb.c b/ptb.c
index 8b90cbe6c8c9931dafc9fd78a77b3c683acaa625..c4f9686f9eddb7acdcebcb63ff614a7921a939a8 100644 (file)
--- a/ptb.c
+++ b/ptb.c
@@ -154,7 +154,7 @@ static ssize_t ptb_data_constant_string(struct ptbf *f, const char *expected, in
        return ret;
 }
 
-static ssize_t ptb_data_unknown(struct ptbf *f, size_t length) {
+static ssize_t ptb_data_unknown(struct ptbf *f, size_t length, const char *comment) {
        char unknown[255];
        ssize_t ret;
        off_t oldpos = f->curpos;
@@ -233,16 +233,28 @@ static ssize_t ptb_data_string(struct ptbf *bf, char **dest) {
        return 0;
 }
 
-static ssize_t ptb_data_font(struct ptbf *f, struct ptb_font *dest) {
+static ssize_t ptb_data_color(struct ptbf *f, struct ptb_color *dest)
+{
+       int ret = 0;
+
+       ret+=ptb_data_uint8(f, &dest->r);
+       ret+=ptb_data_uint8(f, &dest->g);
+       ret+=ptb_data_uint8(f, &dest->b);
+       ret+=ptb_data_unknown(f, 1, "FIXLA");
+
+       return ret;
+}
+
+static ssize_t ptb_data_font(struct ptbf *f, struct ptb_font *dest) 
+{
        int ret = 0;
        ret+=ptb_data_string(f, &dest->family);
-       ret+=ptb_data_uint8(f, &dest->size);
-       ret+=ptb_data_unknown(f, 5);
-       ret+=ptb_data_uint8(f, &dest->thickness);
-       ret+=ptb_data_unknown(f, 2);
+       ret+=ptb_data_uint32(f, &dest->pointsize);
+       ret+=ptb_data_uint32(f, &dest->weight);
        ret+=ptb_data_uint8(f, &dest->italic);
        ret+=ptb_data_uint8(f, &dest->underlined);
-       ret+=ptb_data_unknown(f, 4);
+       ret+=ptb_data_uint8(f, &dest->strikeout);
+       ret+=ptb_data_color(f, &dest->color);
        return ret;
 }
 
@@ -255,7 +267,7 @@ static ssize_t ptb_data_header(struct ptbf *f, struct ptb_hdr *hdr)
 
        switch(hdr->classification) {
        case CLASSIFICATION_SONG:
-               ptb_data_unknown(f, 1); /* FIXME */
+               ptb_data_unknown(f, 1, "FIXME"); /* FIXME */
                ptb_data_string(f, &hdr->class_info.song.title);
                ptb_data_string(f, &hdr->class_info.song.artist);
 
@@ -545,7 +557,7 @@ static ssize_t ptb_data_file(struct ptbf *bf)
        ptb_data_font(bf, &bf->chord_name_font);
        ptb_data_font(bf, &bf->default_font);
 
-       ptb_data_unknown(bf, 12);
+       ptb_data_unknown(bf, 12, "FIXME");
        return 0;
 }
 
@@ -638,12 +650,11 @@ static int handle_CFloatingText (struct ptbf *bf, const char *section, struct pt
 
        ptb_data_string(bf, &text->text);
        ptb_data_uint8(bf, &text->offset);
-       ptb_data_unknown(bf, 15);
+       ptb_data_unknown(bf, 15, "bounding rectangle for text");
        ptb_data_uint8(bf, &text->alignment);
        ptb_debug("Align: %x", text->alignment);
-       ptb_assert(bf, (text->alignment &~ ALIGN_TIMESTAMP) == ALIGN_LEFT || 
-                                  (text->alignment &~ ALIGN_TIMESTAMP) == ALIGN_CENTER || 
-                                  (text->alignment &~ ALIGN_TIMESTAMP) == ALIGN_RIGHT);
+       ptb_assert(bf, (text->alignment &~ ALIGN_BORDER &~ ALIGN_CENTER 
+                                       &~ ALIGN_LEFT &~ ALIGN_RIGHT)  == 0);
        ptb_data_font(bf, &text->font);
        
        *dest = (struct ptb_list *)text;
@@ -655,17 +666,17 @@ static int handle_CSection (struct ptbf *bf, const char *sectionname, struct ptb
        struct ptb_section *section = GET_ITEM(bf, dest, struct ptb_section);
 
        ptb_data_constant(bf, 0x32);
-       ptb_data_unknown(bf, 11);
+       ptb_data_unknown(bf, 11, "FIXME");
        ptb_data_uint16(bf, &section->properties);
-       ptb_data_unknown(bf, 2);
+       ptb_data_unknown(bf, 2, "FIXME");
        ptb_data_uint8(bf, &section->end_mark);
        ptb_assert(bf, (section->end_mark &~ END_MARK_TYPE_NORMAL 
                           & ~END_MARK_TYPE_DOUBLELINE
                           & ~END_MARK_TYPE_REPEAT) < 24);
        ptb_data_uint8(bf, &section->position_width);
-       ptb_data_unknown(bf, 5);
+       ptb_data_unknown(bf, 5, "FIXME");
        ptb_data_uint8(bf, &section->key_extra);
-       ptb_data_unknown(bf, 1);
+       ptb_data_unknown(bf, 1, "FIXME");
        ptb_data_uint16(bf, &section->meter_type);
        ptb_data_uint8(bf, &section->beat_info);
        ptb_data_uint8(bf, &section->metronome_pulses_per_measure);
@@ -676,6 +687,8 @@ static int handle_CSection (struct ptbf *bf, const char *sectionname, struct ptb
        ptb_data_items(bf, "CChordText", (struct ptb_list **)&section->chordtexts);
        ptb_data_items(bf, "CRhythmSlash", (struct ptb_list **)&section->rhythmslashes);
        ptb_data_items(bf, "CStaff", (struct ptb_list **)&section->staffs);
+       /* FIXME: Barlinearray */
+       /* FIXME: Barline */
        ptb_data_items(bf, "CMusicBar", (struct ptb_list **)&section->musicbars);
 
        *dest = (struct ptb_list *)section;
@@ -702,7 +715,7 @@ static int handle_CChordDiagram (struct ptbf *bf, const char *section, struct pt
        struct ptb_chorddiagram *chorddiagram = GET_ITEM(bf, dest, struct ptb_chorddiagram);
 
        ptb_data(bf, chorddiagram->name, 2);
-       ptb_data_unknown(bf, 3);
+       ptb_data_unknown(bf, 3, "FIXME");
        ptb_data_uint8(bf, &chorddiagram->type);
        ptb_data_uint8(bf, &chorddiagram->frets);
        ptb_data_uint8(bf, &chorddiagram->nr_strings);
@@ -797,15 +810,17 @@ static int handle_CGuitarIn (struct ptbf *bf, const char *section, struct ptb_li
 }
 
 
-static int handle_CStaff (struct ptbf *bf, const char *section, struct ptb_list **dest) { 
+static int handle_CStaff (struct ptbf *bf, const char *section, struct ptb_list **dest)
+{ 
        uint16_t next;
        struct ptb_staff *staff = GET_ITEM(bf, dest, struct ptb_staff);
 
        ptb_data_uint8(bf, &staff->properties);
        ptb_debug("Properties: %02x", staff->properties);
-       ptb_data_uint8(bf, &staff->highest_note);
-       ptb_data_uint8(bf, &staff->lowest_note);
-       ptb_data_unknown(bf, 2);
+       ptb_data_uint8(bf, &staff->highest_note_space);
+       ptb_data_uint8(bf, &staff->lowest_note_space);
+       ptb_data_uint8(bf, &staff->symbol_space);
+       ptb_data_uint8(bf, &staff->tab_staff_space);
 
        /* FIXME! */
        ptb_data_items(bf, "CPosition", (struct ptb_list **)&staff->positions[0]);
@@ -889,7 +904,7 @@ static int handle_CPosition (struct ptbf *bf, const char *section, struct ptb_li
                ptb_data_uint8(bf, &position->additional[i].start_volume);
                ptb_data_uint8(bf, &position->additional[i].end_volume);
                ptb_data_uint8(bf, &position->additional[i].duration);
-               ptb_data_unknown(bf, 1);
+               ptb_data_unknown(bf, 1, "FIXME");
        }
 
        ptb_data_items(bf, "CLineData", (struct ptb_list **)&position->linedatas);
@@ -903,7 +918,7 @@ static int handle_CDynamic (struct ptbf *bf, const char *section, struct ptb_lis
 
        ptb_data_uint8(bf, &dynamic->offset);
        ptb_data_uint8(bf, &dynamic->staff);
-       ptb_data_unknown(bf, 3); /* FIXME */
+       ptb_data_unknown(bf, 3, "FIXME"); /* FIXME */
        ptb_data_uint8(bf, &dynamic->volume);
 
        *dest = (struct ptb_list *)dynamic;
@@ -913,7 +928,7 @@ static int handle_CDynamic (struct ptbf *bf, const char *section, struct ptb_lis
 static int handle_CSectionSymbol (struct ptbf *bf, const char *section, struct ptb_list **dest) {
        struct ptb_sectionsymbol *sectionsymbol = GET_ITEM(bf, dest, struct ptb_sectionsymbol);
 
-       ptb_data_unknown(bf, 5); /* FIXME */
+       ptb_data_unknown(bf, 5, "FIXME"); /* FIXME */
        ptb_data_uint16(bf, &sectionsymbol->repeat_ending);
 
        *dest = (struct ptb_list *)sectionsymbol;
@@ -925,7 +940,7 @@ static int handle_CMusicBar (struct ptbf *bf, const char *section, struct ptb_li
                                                                                         
        ptb_data_uint8(bf, &musicbar->offset);
        ptb_data_uint8(bf, &musicbar->properties);
-       ptb_data_unknown(bf, 6);
+       ptb_data_unknown(bf, 6, "FIXME");
        ptb_data_uint8(bf, &musicbar->letter);
        ptb_data_string(bf, &musicbar->description);
 
@@ -965,9 +980,9 @@ static int handle_CRhythmSlash (struct ptbf *bf, const char *section, struct ptb
 static int handle_CDirection (struct ptbf *bf, const char *section, struct ptb_list **dest) { 
        struct ptb_direction *direction = GET_ITEM(bf, dest, struct ptb_direction);
 
-       ptb_data_unknown(bf, 1);
+       ptb_data_unknown(bf, 1, "FIXME");
        ptb_data_uint8(bf, &direction->nr_items);
-       ptb_data_unknown(bf, 2 * direction->nr_items); /* FIXME */
+       ptb_data_unknown(bf, 2 * direction->nr_items, "FIXME");
 
        *dest = (struct ptb_list *)direction;
        return 1;
diff --git a/ptb.h b/ptb.h
index c519679adbd843b925621f2900f0f6e927d0107b..c3d62b3b2eacf901bb628a9b3d7d4523b7a1c460 100644 (file)
--- a/ptb.h
+++ b/ptb.h
@@ -140,11 +140,30 @@ struct ptb_guitarin {
        uint8_t staff_in;
 };
 
+struct ptb_color { uint8_t r,g,b; };
+
 struct ptb_font {
-       uint8_t size;
-       uint8_t thickness;
+#define WEIGHT_DONT_CARE                0
+#define WEIGHT_THIN              100
+#define WEIGHT_EXTRALIGHT        200
+#define WEIGHT_ULTRALIGHT        200
+#define WEIGHT_LIGHT             300
+#define WEIGHT_NORMAL            400
+#define WEIGHT_REGULAR           400
+#define WEIGHT_MEDIUM            500
+#define WEIGHT_SEMIBOLD          600
+#define WEIGHT_DEMIBOLD          600
+#define WEIGHT_BOLD              700
+#define WEIGHT_EXTRABOLD         800
+#define WEIGHT_ULTRABOLD         800
+#define WEIGHT_BLACK             900
+#define WEIGHT_HEAVY             900
+       uint32_t pointsize;
+       uint32_t weight;
        uint8_t underlined;
+       uint8_t strikeout;
        uint8_t italic;
+       struct ptb_color color;
        char *family;
 };
 
@@ -153,10 +172,11 @@ struct ptb_floatingtext {
 
        char *text;
        uint8_t offset;
-#define ALIGN_LEFT             1
-#define ALIGN_CENTER   2
-#define ALIGN_RIGHT            3
-#define ALIGN_TIMESTAMP        8
+#define ALIGN_LEFT             0x01
+#define ALIGN_CENTER   0x02
+#define ALIGN_RIGHT            0x04
+#define ALIGN_MASK             0x07
+#define ALIGN_BORDER   0x08 /* text surrounded by border */
        uint8_t alignment;
        struct ptb_font font;
 };
@@ -279,15 +299,23 @@ struct ptb_position {
 
 
 
-#define STAFF_TYPE_BASS_KEY    0x10
+#define STAFF_TYPE_BASS_KEY                    0x10
+#define STAFF_CLEF_MASK                                0xf0
+#define STAFF_TAB_STAFF_TYPE_MASK      0x0f
 
 struct ptb_staff {
        struct ptb_staff *prev, *next;
 
        /* Number of strings OR-ed with some settings */
        uint8_t properties;
-       uint8_t highest_note;
-       uint8_t lowest_note;
+       uint8_t highest_note_space;
+       uint8_t lowest_note_space;
+       uint8_t symbol_space;
+       uint8_t tab_staff_space;
+
+       /* first array is for high melody
+        * second is for low melody
+        */
        struct ptb_position *positions[2];
 };
 
index 1121a70b24ace41e9f8c184e3588bcef18fbcef7..5aae579cd833c8664912736d64c4e997b7299b17 100644 (file)
--- a/ptb2xml.c
+++ b/ptb2xml.c
@@ -69,8 +69,8 @@ xmlNodePtr xml_write_font(const char *name, struct ptb_font *font)
 {
        xmlNodePtr xfont = xmlNewNode(NULL, "font");
        xmlSetProp(xfont, "function", name);
-       SMART_ADD_PROP_INT(xfont, "size", font->size);
-       SMART_ADD_PROP_INT(xfont, "thickness", font->thickness);
+       SMART_ADD_PROP_INT(xfont, "pointsize", font->pointsize);
+       SMART_ADD_PROP_INT(xfont, "weight", font->weight);
        SMART_ADD_PROP_INT(xfont, "underlined", font->underlined);
        SMART_ADD_PROP_INT(xfont, "italic", font->italic);
        xmlSetProp(xfont, "family", font->family);
@@ -203,8 +203,10 @@ xmlNodePtr xml_write_staffs(struct ptb_staff *staffs)
                xmlNodePtr xstaff = xmlNewNode(NULL, "staff");
                xmlAddChild(xstaffs, xstaff);
 
-               SMART_ADD_CHILD_INT(xstaff, "highest_note", staff->highest_note);
-               SMART_ADD_CHILD_INT(xstaff, "lowest_note", staff->lowest_note);
+               SMART_ADD_CHILD_INT(xstaff, "highest_note_space", staff->highest_note_space);
+               SMART_ADD_CHILD_INT(xstaff, "lowest_note_space", staff->lowest_note_space);
+               SMART_ADD_CHILD_INT(xstaff, "symbol_space", staff->symbol_space);
+               SMART_ADD_CHILD_INT(xstaff, "tab_staff_space", staff->tab_staff_space);
                SMART_ADD_CHILD_INT(xstaff, "properties", staff->properties);
 
                for(i = 0; i < 2; i++) 
index a5dad6279b780bd23ddb94004e147f36fce53b0f..cdf7c1531dfb5aa5546f447ba45ea41dd783bb74 100644 (file)
--- a/ptbinfo.c
+++ b/ptbinfo.c
@@ -82,7 +82,8 @@ void write_position(struct ptb_position *pos)
 
 void write_staff(struct ptb_staff *staff)
 {
-       printf("\t\tLowest Note: %d, Highest Note: %d\n", staff->lowest_note, staff->highest_note);
+       printf("\t\tLowest Note Space: %d, Highest Note Space: %d\n", staff->lowest_note_space, staff->highest_note_space);
+       printf("\t\tSymbol Space: %d, Tablature Staff Space: %d\n", staff->symbol_space, staff->tab_staff_space);
        printf("\t\tProperties: %d\n", staff->properties);
 
        printf("\t\t    Positions:\n");
@@ -219,7 +220,7 @@ void write_chorddiagram(struct ptb_chorddiagram *chd)
 
 void write_font(struct ptb_font *font)
 {
-       printf("%s, Size: %d, Thickness: %d, Underlined: %d, Italic: %d", font->family, font->size, font->thickness, font->underlined, font->italic);
+       printf("%s, Size: %d, Weight: %d, Underlined: %d, Italic: %d", font->family, font->pointsize, font->weight, font->underlined, font->italic);
 }
 
 void write_floatingtext(struct ptb_floatingtext *ft)
@@ -232,7 +233,7 @@ void write_floatingtext(struct ptb_floatingtext *ft)
        case ALIGN_CENTER: printf("Center"); break;
        case ALIGN_RIGHT: printf("Right"); break;
        }
-       if (ft->alignment & ALIGN_TIMESTAMP) printf(", Print Timestamp");
+       if (ft->alignment & ALIGN_BORDER) printf(", Print Border");
        printf("\n");
        printf("\tFont: "); write_font(&ft->font); printf("\n");
        printf("\n");