More win32 fixes
[jelmer/ptabtools.git] / ptbinfo.c
1 /*
2         (c) 2004: Jelmer Vernooij <jelmer@samba.org>
3
4         This program is free software; you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation; either version 2 of the License, or
7         (at your option) any later version.
8
9         This program is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with this program; if not, write to the Free Software
16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <stdio.h>
20 #include <errno.h>
21 #include <popt.h>
22 #include "dlinklist.h"
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #ifdef HAVE_STDINT_H
29 #  include <stdint.h>
30 #endif
31
32 #include "ptb.h"
33
34 #define COND_PRINTF(desc,field) if(field) printf("%s: %s\n", desc, field);
35
36 #define PRINT_LIST(ls,t,fn) { t l = ls; while(l) { fn(l); l = l->next; } }
37
38 void write_musicbar(struct ptb_musicbar *mb)
39 {
40         printf("\t\tOffset: %d\n", mb->offset);
41         printf("\t\tProperties: %d\n", mb->properties);
42         printf("\t\tLetter: %c\n", mb->letter);
43         if (mb->description) printf("\t\tDescription: %s\n", mb->description);
44         printf("\n");
45 }
46
47 void write_linedata(struct ptb_linedata *ld)
48 {
49         printf("\t\t\t\tFret: %d, String: %d\n", ld->detailed.fret, ld->detailed.string);
50         if (ld->properties & LINEDATA_PROPERTY_TIE) printf("\t\t\t\tTie\n");
51         if (ld->properties & LINEDATA_PROPERTY_MUTED) printf("\t\t\t\tMuted\n");
52         if (ld->properties & LINEDATA_PROPERTY_CONTINUES) printf("\t\t\t\tContinues\n");
53         if (ld->properties & LINEDATA_PROPERTY_HAMMERON_FROM) printf("\t\t\t\tStart of hammer-on\n");
54         if (ld->properties & LINEDATA_PROPERTY_PULLOFF_FROM) printf("\t\t\t\tStart of pull-off\n");
55         if (ld->properties & LINEDATA_PROPERTY_DEST_NOWHERE) printf("\t\t\t\tDest-nowhere(?)\n");
56         if (ld->properties & LINEDATA_PROPERTY_NATURAL_HARMONIC) printf("\t\t\t\tNatural Harmonic\n");
57         if (ld->properties & LINEDATA_PROPERTY_GHOST_NOTE) printf("\t\t\t\tGhost Note\n");
58
59         if (ld->transcribe) {
60                 printf("\t\t\t\tTranscribed: ");
61                 if (ld->transcribe & LINEDATA_TRANSCRIBE_8VA) printf("8va ");
62                 if (ld->transcribe & LINEDATA_TRANSCRIBE_15MA) printf("15ma ");
63                 if (ld->transcribe & LINEDATA_TRANSCRIBE_8VB) printf("8vb ");
64                 if (ld->transcribe & LINEDATA_TRANSCRIBE_15MB) printf("15mb ");
65                 printf("\n");
66         }
67
68         printf("\n");
69 }
70
71 void write_position(struct ptb_position *pos)
72 {
73         printf("\t\t\tOffset: %d\n", pos->offset);
74         printf("\t\t\tLength: %d\n", pos->length);
75         printf("\t\t\t    Attached data:\n");
76         PRINT_LIST(pos->linedatas, struct ptb_linedata *, write_linedata);
77         printf("\n");
78 }
79
80 void write_staff(struct ptb_staff *staff)
81 {
82         printf("\t\tLowest Note: %d, Highest Note: %d\n", staff->lowest_note, staff->highest_note);
83         printf("\t\tProperties: %d\n", staff->properties);
84
85         printf("\t\t    Positions:\n");
86         PRINT_LIST(staff->positions[0], struct ptb_position *, write_position);
87         PRINT_LIST(staff->positions[0], struct ptb_position *, write_position);
88         printf("\n");
89 }
90
91 void write_chordtext(struct ptb_chordtext *ct)
92 {
93         printf("\t\tName: %c%d\n", ct->name[0], ct->name[1]);
94         printf("\t\tOffset: %d\n", ct->offset);
95         printf("\n");
96 }
97
98 void write_rhythmslash(struct ptb_rhythmslash *sl)
99 {
100         printf("\t\tOffset: %d\n", sl->offset);
101         printf("\t\tLength: %d\n", sl->length);
102         printf("\n");
103 }
104
105 void write_direction(struct ptb_direction *dr)
106 {
107         printf("\n");
108 }
109
110 void write_section(struct ptb_section *section)
111 {
112         printf("\tSection(%c): %s\n", section->letter, section->description);
113         printf("\tEnd-Mark: %d\n", section->end_mark);
114         printf("\tMeter Type: %d\n", section->meter_type);
115         printf("\tMetronome Pulses Per Measure: %d\n", section->metronome_pulses_per_measure);
116         printf("\tProperties: %d\n", section->properties);
117         printf("\tKey Extra: %d\n", section->key_extra);
118         printf("\tPosition Width: %d\n", section->position_width);
119
120         if (section->staffs) {
121                 printf("\t    Staffs:\n");
122                 PRINT_LIST(section->staffs, struct ptb_staff *, write_staff);
123         }
124
125         if (section->chordtexts) {
126                 printf("\t    Chordtexts:\n");
127                 PRINT_LIST(section->chordtexts, struct ptb_chordtext *, write_chordtext);
128         }
129
130         if (section->rhythmslashes) {
131                 printf("\t    Rhythmslashes:\n");
132                 PRINT_LIST(section->rhythmslashes, struct ptb_rhythmslash *, write_rhythmslash);
133         }
134
135         if (section->directions) {
136                 printf("\t    Directions:\n");
137                 PRINT_LIST(section->directions, struct ptb_direction *, write_direction);
138         }
139         
140         if (section->musicbars) {
141                 printf("\t    Music Bars:\n");
142                 PRINT_LIST(section->musicbars, struct ptb_musicbar *, write_musicbar);
143         }
144
145         printf("\n");
146 }
147
148 void write_sectionsymbol(struct ptb_sectionsymbol *ssb)
149 {
150         printf("\tRepeat Ending: %d\n", ssb->repeat_ending);
151         printf("\n");
152 }
153
154 void write_tempomarker(struct ptb_tempomarker *tm)
155 {
156         printf("\tDescription: %s\n", tm->description);
157         printf("\tType: %d\n", tm->type);
158         printf("\tBPM: %d\n", tm->bpm);
159         printf("\tSection: %d\n", tm->section);
160         printf("\tOffset: %d\n", tm->offset);
161         printf("\n");
162 }
163
164 void write_dynamic(struct ptb_dynamic *dn)
165 {
166         printf("\tOffset: %d\n", dn->offset);
167         printf("\tStaff: %d\n", dn->staff);
168         printf("\tVolume: %d\n", dn->volume);
169         printf("\n");
170 }
171
172 void write_guitar(struct ptb_guitar *gtr)
173 {
174         int i;
175         printf("\tNumber: %d\n", gtr->index);
176         printf("\tTitle: %s\n", gtr->title);
177         printf("\tType: %s\n", gtr->type);
178         printf("\tStrings(%d):\n", gtr->nr_strings);
179         for (i = 0; i < gtr->nr_strings; i++) 
180                 printf("\t\t%d\n", gtr->strings[i]);
181
182         printf("\tReverb: %d\n", gtr->reverb);
183         printf("\tChorus: %d\n", gtr->chorus);
184         printf("\tTremolo: %d\n", gtr->chorus);
185         printf("\tPan: %d\n", gtr->pan);
186         printf("\tCapo on fret: %d\n", gtr->capo);
187         printf("\tInitial volume: %d\n", gtr->initial_volume);
188         printf("\tMidi Instrument: %d\n", gtr->midi_instrument);
189         printf("\tHalf up(?): %d\n", gtr->half_up);
190         printf("\tSimulate (?): %d\n", gtr->simulate);
191         printf("\n");
192 }
193
194 void write_guitarin(struct ptb_guitarin *gtr)
195 {
196         printf("\tOffset: %d\n", gtr->offset);
197         printf("\tSection: %d\n", gtr->section);
198         printf("\tStaff: %d\n", gtr->staff);
199         printf("\tRhythmslash: %d\n", gtr->rhythm_slash);
200         printf("\tStaff In(?): %d\n", gtr->staff_in);
201         printf("\n");
202 }
203
204 void write_chorddiagram(struct ptb_chorddiagram *chd)
205 {
206         int i;
207         printf("\tName: %c%c\n", chd->name[0], chd->name[1]);
208         printf("\tFret Offset: %d\n", chd->frets);
209         printf("\tType: %d\n", chd->type);
210         printf("\tTones(%d): \n", chd->nr_strings);
211         for (i = 0; i < chd->nr_strings; i++) 
212                 printf("\t\t%d\n", chd->tones[i]);
213         printf("\n");
214 }
215
216 void write_font(struct ptb_font *font)
217 {
218         printf("%s, Size: %d, Thickness: %d, Underlined: %d, Italic: %d", font->family, font->size, font->thickness, font->underlined, font->italic);
219 }
220
221 void write_floatingtext(struct ptb_floatingtext *ft)
222 {
223         printf("\tText: %s\n", ft->text);
224         printf("\tOffset: %d\n", ft->offset);
225         printf("\tAlignment: ");
226         switch (ft->alignment & (ALIGN_LEFT|ALIGN_CENTER|ALIGN_RIGHT)) {
227         case ALIGN_LEFT: printf("Left");break;
228         case ALIGN_CENTER: printf("Center"); break;
229         case ALIGN_RIGHT: printf("Right"); break;
230         }
231         if (ft->alignment & ALIGN_TIMESTAMP) printf(", Print Timestamp");
232         printf("\n");
233         printf("\tFont: "); write_font(&ft->font); printf("\n");
234         printf("\n");
235 }
236
237
238 void write_praudio_info(struct ptb_hdr *hdr)
239 {
240         printf("Audio Type: ");
241         switch(hdr->class_info.song.release_info.pr_audio.type)
242         { 
243         case AUDIO_TYPE_SINGLE: printf("Single\n"); break;
244         case AUDIO_TYPE_EP: printf("EP\n"); break;
245         case AUDIO_TYPE_ALBUM: printf("Album\n"); break;
246         case AUDIO_TYPE_DOUBLE_ALBUM: printf("Double Album\n"); break;
247         case AUDIO_TYPE_TRIPLE_ALBUM: printf("Triple Album\n"); break;
248         case AUDIO_TYPE_BOXSET: printf("Boxset\n"); break;
249         }
250         COND_PRINTF("Album Title", hdr->class_info.song.release_info.pr_audio.album_title);
251         printf("Year: %d\n", hdr->class_info.song.release_info.pr_audio.year);
252         printf("Live recording? %s\n", hdr->class_info.song.release_info.pr_audio.is_live_recording?"Yes":"No");
253 }
254
255 void write_prvideo_info(struct ptb_hdr *hdr)
256 {
257         COND_PRINTF("Video Title", hdr->class_info.song.release_info.pr_video.video_title);
258         printf("Year: %d\n", hdr->class_info.song.release_info.pr_video.year);
259         printf("Live recording? %s\n", hdr->class_info.song.release_info.pr_video.is_live_recording?"Yes":"No");
260 }
261
262 void write_bootleg_info(struct ptb_hdr *hdr)
263 {
264         COND_PRINTF("Bootleg Title", hdr->class_info.song.release_info.bootleg.title);
265         printf("Date: %d-%d-%d\n", 
266                    hdr->class_info.song.release_info.bootleg.day,
267                    hdr->class_info.song.release_info.bootleg.month,
268                    hdr->class_info.song.release_info.bootleg.year);
269 }
270
271 void write_song_info(struct ptb_hdr *hdr)
272 {
273         COND_PRINTF("Title", hdr->class_info.song.title);
274         COND_PRINTF("Artist", hdr->class_info.song.artist);
275         COND_PRINTF("Words By", hdr->class_info.song.words_by);
276         COND_PRINTF("Music By", hdr->class_info.song.music_by);
277         COND_PRINTF("Arranged By", hdr->class_info.song.arranged_by);
278         COND_PRINTF("Guitar Transcribed By", hdr->class_info.song.guitar_transcribed_by);
279         COND_PRINTF("Bass Transcribed By", hdr->class_info.song.bass_transcribed_by);
280         if(hdr->class_info.song.lyrics) 
281                 printf("Lyrics\n----------\n%s\n\n", hdr->class_info.song.lyrics);
282         COND_PRINTF("Copyright", hdr->class_info.song.copyright);
283
284         printf("Release type: ");
285         switch(hdr->class_info.song.release_type) {
286         case RELEASE_TYPE_PR_AUDIO:
287                 printf("Public Release (Audio)\n");
288                 write_praudio_info(hdr);
289                 break;
290         case RELEASE_TYPE_PR_VIDEO:
291                 printf("Public Release (Video)\n");
292                 write_prvideo_info(hdr);
293                 break;
294         case RELEASE_TYPE_BOOTLEG:
295                 printf("Bootleg\n");
296                 write_bootleg_info(hdr);
297                 break;
298         case RELEASE_TYPE_UNRELEASED:
299                 printf("Unreleased\n");
300                 break;
301         }
302 }
303
304 void write_lesson_info(struct ptb_hdr *hdr)
305 {
306         COND_PRINTF("Title", hdr->class_info.lesson.title);
307         COND_PRINTF("Artist", hdr->class_info.lesson.artist);
308         printf("Style: %d\n", hdr->class_info.lesson.style);
309         printf("Level: ");
310         switch(hdr->class_info.lesson.level) {
311         case LEVEL_BEGINNER: printf("Beginner"); break;
312         case LEVEL_INTERMEDIATE: printf("Intermediate"); break;
313         case LEVEL_ADVANCED: printf("Advanced"); break;
314         }
315         COND_PRINTF("Author", hdr->class_info.lesson.author);
316         COND_PRINTF("Copyright", hdr->class_info.lesson.copyright);
317 }
318
319 int main(int argc, const char **argv) 
320 {
321         struct ptbf *ret;
322         int tree = 0;
323         int debugging = 0;
324         int c, tmp1, tmp2;
325         int version = 0;
326         poptContext pc;
327         struct poptOption options[] = {
328                 POPT_AUTOHELP
329                 {"debug", 'd', POPT_ARG_NONE, &debugging, 0, "Turn on debugging output" },
330                 {"tree", 't', POPT_ARG_NONE, &tree, 't', "Print tree of PowerTab file" },
331                 {"version", 'v', POPT_ARG_NONE, &version, 'v', "Show version information" },
332                 POPT_TABLEEND
333         };
334
335         pc = poptGetContext(argv[0], argc, argv, options, 0);
336         poptSetOtherOptionHelp(pc, "file.ptb");
337         while((c = poptGetNextOpt(pc)) >= 0) {
338                 switch(c) {
339                 case 'v':
340                         printf("ptbinfo Version "PACKAGE_VERSION"\n");
341                         printf("(C) 2004 Jelmer Vernooij <jelmer@samba.org>\n");
342                         exit(0);
343                         break;
344                 }
345         }
346                         
347         ptb_set_debug(debugging);
348         ptb_set_asserts_fatal(0);
349         
350         if(!poptPeekArg(pc)) {
351                 poptPrintUsage(pc, stderr, 0);
352                 return -1;
353         }
354         ret = ptb_read_file(poptGetArg(pc));
355         
356         if(!ret) {
357                 perror("Read error: ");
358                 return -1;
359         } 
360
361         printf("File type: ");
362         switch(ret->hdr.classification) {
363         case CLASSIFICATION_SONG: 
364                 printf("Song\n");
365                 write_song_info(&ret->hdr);
366                 break;
367         case CLASSIFICATION_LESSON:
368                 printf("Lesson\n");
369                 write_lesson_info(&ret->hdr);
370                 break;
371         default: 
372                 printf("Unknown\n");
373                 break;
374         }
375
376         DLIST_LEN(ret->instrument[0].sections, tmp1, struct ptb_section *);
377         DLIST_LEN(ret->instrument[1].sections, tmp2, struct ptb_section *);
378         printf("Number of sections: \tRegular: %d Bass: %d\n", tmp1, tmp2);
379
380         DLIST_LEN(ret->instrument[0].guitars, tmp1, struct ptb_guitar *);
381         DLIST_LEN(ret->instrument[1].guitars, tmp2, struct ptb_guitar *);
382
383         printf("Number of guitars: \tRegular: %d Bass: %d\n", tmp1, tmp2);
384
385         if (tree) 
386         {
387                 int i;
388                 printf("\n");
389                 for (i = 0; i < 2; i++) {
390                         printf("\n");
391                         if (i == 0) printf("Guitar\n"); else printf("Bass\n");
392
393                         if (ret->instrument[i].guitars) {
394                                 printf("    Guitars:\n");
395                                 PRINT_LIST(ret->instrument[i].guitars, struct ptb_guitar *, write_guitar);
396                         }
397
398                         if (ret->instrument[i].guitarins) {
399                                 printf("    GuitarIns:\n");
400                                 PRINT_LIST(ret->instrument[i].guitarins, struct ptb_guitarin *, write_guitarin);
401                         }
402
403                         if (ret->instrument[i].chorddiagrams) {
404                                 printf("    Chord Diagrams:\n");
405                                 PRINT_LIST(ret->instrument[i].chorddiagrams, struct ptb_chorddiagram *, write_chorddiagram);
406                         }
407
408                         if (ret->instrument[i].tempomarkers) {
409                                 printf("    Tempo Markers:\n");
410                                 PRINT_LIST(ret->instrument[i].tempomarkers, struct ptb_tempomarker *, write_tempomarker);
411                         }
412
413                         if (ret->instrument[i].dynamics) {
414                                 printf("    Dynamics:\n");
415                                 PRINT_LIST(ret->instrument[i].dynamics, struct ptb_dynamic *, write_dynamic);
416                         }
417
418                         if (ret->instrument[i].floatingtexts) {
419                                 printf("    Floating Texts:\n");
420                                 PRINT_LIST(ret->instrument[i].floatingtexts, struct ptb_floatingtext *, write_floatingtext);
421                         }
422
423                         if (ret->instrument[i].sectionsymbols) {
424                                 printf("    Section Symbols:\n");
425                                 PRINT_LIST(ret->instrument[i].sectionsymbols, struct ptb_sectionsymbol *, write_sectionsymbol);
426                         }
427
428                         if (ret->instrument[i].sections) {
429                                 printf("    Sections:\n");
430                                 PRINT_LIST(ret->instrument[i].sections, struct ptb_section *, write_section);
431                         }
432                 }
433
434                 printf("Default Font: "); write_font(&ret->default_font); printf("\n");
435                 printf("Chord Name Font: "); write_font(&ret->chord_name_font); printf("\n");
436                 printf("Tablature Font: "); write_font(&ret->tablature_font); printf("\n");
437         }
438
439         return (ret?0:1);
440 }