1 /* -- general macros -- */
2 
3 #include <stdio.h>
4 #include <time.h>
5 
6 #include "config.h"
7 
8 #define MAXVOICE 32	/* max number of voices */
9 
10 #define MAXHD	8	/* max heads in a chord */
11 #define MAXDC	32	/* max decorations per symbol */
12 #define MAXMICRO 32	/* max microtone values (5 bits in accs[]) */
13 #define DC_NAME_SZ 128	/* size of the decoration name table */
14 
15 #define BASE_LEN 1536	/* basic note length (semibreve or whole note - same as MIDI) */
16 
17 #define VOICE_ID_SZ 16	/* max size of the voice identifiers */
18 
19 /* accidentals */
20 enum accidentals {
21 	A_NULL,		/* none */
22 	A_SH,		/* sharp */
23 	A_NT,		/* natural */
24 	A_FT,		/* flat */
25 	A_DS,		/* double sharp */
26 	A_DF		/* double flat */
27 };
28 
29 /* bar types - 4 bits per symbol */
30 #define B_BAR 1		/* | */
31 #define B_OBRA 2	/* [ */
32 #define B_CBRA 3	/* ] */
33 #define B_COL 4		/* : */
34 
35 #define B_SINGLE 0x01		/* |	single bar */
36 #define B_DOUBLE 0x11		/* ||	thin double bar */
37 #define B_THIN_THICK 0x13	/* |]	thick at section end  */
38 #define B_THICK_THIN 0x21	/* [|	thick at section start */
39 #define B_LREP 0x14		/* |:	left repeat bar */
40 #define B_RREP 0x41		/* :|	right repeat bar */
41 #define B_DREP 0x44		/* ::	double repeat bar */
42 #define B_DASH 0x04		/* :	dashed bar */
43 
44 /* slur/tie types (4 bits) */
45 #define SL_ABOVE 0x01
46 #define SL_BELOW 0x02
47 #define SL_HIDDEN 0x03		/* also opposite for gstemdir */
48 #define SL_AUTO 0x04
49 #define SL_DOTTED 0x08		/* (modifier bit) */
50 
51 #define OUTPUTFILE "Out.ps"	/* standard output file */
52 
53 #ifndef WIN32
54 #define DIRSEP '/'
55 #else
56 #define DIRSEP '\\'
57 #define strcasecmp stricmp
58 #define strncasecmp _strnicmp
59 #define strdup _strdup
60 #define snprintf _snprintf
61 #ifdef _MSC_VER
62 #define fileno _fileno
63 #endif
64 #endif
65 
66 #define CM		* 37.8	/* factor to transform cm to pt */
67 #define PT			/* factor to transform pt to pt */
68 #define IN		* 96.0	/* factor to transform inch to pt */
69 
70 /* basic page dimensions */
71 #ifdef A4_FORMAT
72 #define PAGEHEIGHT	(29.7 CM)
73 #define PAGEWIDTH	(21.0 CM)
74 #define MARGIN		(1.8 CM)
75 #else
76 #define PAGEHEIGHT	(11.0 IN)
77 #define PAGEWIDTH	(8.5 IN)
78 #define MARGIN		(0.7 IN)
79 #endif
80 
81 /* -- macros controlling music typesetting -- */
82 
83 #define STEM_YOFF	1.0	/* offset stem from note center */
84 #define STEM_XOFF	3.5
85 #define STEM		21	/* default stem height = one octave */
86 #define STEM_MIN	16	/* min stem height under beams */
87 #define STEM_MIN2	14	/* ... for notes with two beams */
88 #define STEM_MIN3	12	/* ... for notes with three beams */
89 #define STEM_MIN4	10	/* ... for notes with four beams */
90 #define STEM_CH_MIN	14	/* min stem height for chords under beams */
91 #define STEM_CH_MIN2	10	/* ... for notes with two beams */
92 #define STEM_CH_MIN3	 9	/* ... for notes with three beams */
93 #define STEM_CH_MIN4	 9	/* ... for notes with four beams */
94 #define BEAM_DEPTH	3.2	/* width of a beam stroke */
95 #define BEAM_OFFSET	0.25	/* pos of flat beam relative to staff line */
96 #define BEAM_SHIFT	5.0	/* shift of second and third beams */
97 /*  To align the 4th beam as the 1st: shift=6-(depth-2*offset)/3  */
98 #define BEAM_FLATFAC	0.6	/* factor to decrease slope of long beams */
99 #define BEAM_THRESH	0.06	/* flat beam if slope below this threshold */
100 #define BEAM_SLOPE	0.5	/* max slope of a beam */
101 #define BEAM_STUB	7.0	/* length of stub for flag under beam */
102 #define SLUR_SLOPE	1.0	/* max slope of a slur */
103 #define GSTEM		15	/* grace note stem length */
104 #define GSTEM_XOFF	2.3	/* x offset for grace note stem */
105 
106 #define BETA_C		0.1	/* max expansion for flag -c */
107 #define BETA_X		1.0	/* max expansion before complaining */
108 
109 #define VOCPRE		0.4	/* portion of vocals word before note */
110 #define GCHPRE		0.4	/* portion of guitar chord before note */
111 
112 /* -- Parameters for note spacing -- */
113 /* fnn multiplies the spacing under a beam, to compress the notes a bit */
114 
115 #define fnnp 0.9
116 
117 /* -- macros for program internals -- */
118 
119 #define STRL1		256	/* string length for file names */
120 #define MAXSTAFF	32	/* max staves */
121 #define BSIZE		512	/* buffer size for one input string */
122 
123 #define BREVE		(BASE_LEN * 2)	/* double note (square note) */
124 #define SEMIBREVE	BASE_LEN	/* whole note */
125 #define MINIM		(BASE_LEN / 2)	/* half note (white note) */
126 #define CROTCHET 	(BASE_LEN / 4)	/* quarter note (black note) */
127 #define QUAVER		(BASE_LEN / 8)	/* 1/8 note */
128 #define SEMIQUAVER	(BASE_LEN / 16)	/* 1/16 note */
129 
130 #define MAXFONTS	30	/* max number of fonts */
131 
132 #define T_LEFT		0
133 #define T_JUSTIFY	1
134 #define T_FILL		2
135 #define T_CENTER	3
136 #define T_SKIP		4
137 #define T_RIGHT		5
138 
139 #define YSTEP	128		/* number of steps for y offsets */
140 
141 struct decos {		/* decorations */
142 	char n;			/* whole number of decorations */
143 	struct {
144 		unsigned char t;	/* decoration index */
145 		signed char m;		/* index in chord when note / -1 */
146 	} tm[MAXDC];
147 };
148 
149 struct note_map {	/* note mapping */
150 	struct note_map *next;	/* note linkage */
151 	char type;		/* map type */
152 #define MAP_ONE 0
153 #define MAP_OCT 1
154 #define MAP_KEY 2
155 #define MAP_ALL 3
156 	signed char pit;	/* note pitch and accidental */
157 	unsigned char acc;
158 	char *heads;		/* comma separated list of note heads */
159 	int color;		/* color */
160 	signed char print_pit;	/* print pitch */
161 	unsigned char print_acc; /* print acc */
162 };
163 struct map {		/* voice mapping */
164 	struct map *next;	/* name linkage */
165 	char *name;
166 	struct note_map *notes;	/* mapping of the notes */
167 };
168 extern struct map *maps; /* note mappings */
169 
170 struct note {		/* note head */
171 	short len;		/* note duration (# pts in [1] if space) */
172 	signed char pit;	/* absolute pitch from source - used for ties and map */
173 	unsigned char acc;	/* code for accidental & index in micro_tb */
174 	unsigned char sl1;	/* slur start */
175 	char sl2;		/* number of slur ends */
176 	char ti1;		/* flag to start tie here */
177 	char hlen;		/* length of the head string */
178 	char invisible;		/* alternate note head */
179 	float shhd;		/* horizontal head shift (#pts if space) */
180 	float shac;		/* horizontal accidental shift */
181 	char *head;		/* head */
182 	int color;		/* heads when note mapping */
183 };
184 
185 struct notes {		/* note chord or rest */
186 	struct note notes[MAXHD]; /* note heads */
187 	unsigned char slur_st;	/* slurs starting here (2 bits array) */
188 	char slur_end;		/* number of slurs ending here */
189 	signed char brhythm;	/* broken rhythm */
190 	unsigned char microscale; /* microtone denominator - 1 */
191 	float sdx;		/* x offset of the stem */
192 	struct decos dc;	/* decorations */
193 };
194 
195 extern int severity;
196 
197 extern char *deco[256];
198 
199 struct FONTSPEC {
200 	int fnum;		/* index to font tables in format.c */
201 	float size;
202 	float swfac;
203 };
204 extern char *fontnames[MAXFONTS];	/* list of font names */
205 
206 /* lyrics */
207 #define LY_HYPH	0x10	/* replacement character for hyphen */
208 #define LY_UNDER 0x11	/* replacement character for underscore */
209 #define MAXLY	16	/* max number of lyrics */
210 struct lyl {
211 	struct FONTSPEC *f;	/* font */
212 	float w;		/* width */
213 	float s;		/* shift / note */
214 	char t[256];		/* word (dummy size) */
215 };
216 struct lyrics {
217 	struct lyl *lyl[MAXLY];	/* ptr to lyric lines */
218 };
219 
220 /* guitar chord / annotations */
221 #define MAXGCH 8		/* max number of guitar chords / annotations */
222 struct gch {
223 	char type;		/* ann. char, 'g' gchord, 'r' repeat, '\0' end */
224 	unsigned char idx;	/* index in as.text */
225 	unsigned char font;	/* font */
226 	char box;		/* 1 if in box */
227 	float x, y;		/* x y offset / note + (top or bottom) of staff */
228 	float w;		/* width */
229 };
230 
231 /* positions / directions - see SL_xxx */
232 struct posit_s {
233 	unsigned short dyn:4;	/* %%dynamic */
234 	unsigned short gch:4;	/* %%gchord */
235 	unsigned short orn:4;	/* %%ornament */
236 	unsigned short voc:4;	/* %%vocal */
237 	unsigned short vol:4;	/* %%volume */
238 	unsigned short std:4;	/* %%stemdir */
239 	unsigned short gsd:4;	/* %%gstemdir */
240 };
241 
242 /* music element */
243 struct SYMBOL { 		/* struct for a drawable symbol */
244 	struct SYMBOL *abc_next, *abc_prev; /* source linkage */
245 	struct SYMBOL *next, *prev;	/* voice linkage */
246 	struct SYMBOL *ts_next, *ts_prev; /* time linkage */
247 	struct SYMBOL *extra;	/* extra symbols (grace notes, tempo... */
248 	char abc_type;		/* ABC symbol type */
249 #define ABC_T_NULL	0
250 #define ABC_T_INFO 	1		/* (text[0] gives the info type) */
251 #define ABC_T_PSCOM	2
252 #define ABC_T_CLEF	3
253 #define ABC_T_NOTE	4
254 #define ABC_T_REST	5
255 #define ABC_T_BAR	6
256 #define ABC_T_EOLN	7
257 #define ABC_T_MREST	8		/* multi-measure rest */
258 #define ABC_T_MREP	9		/* measure repeat */
259 #define ABC_T_V_OVER	10		/* voice overlay */
260 #define ABC_T_TUPLET	11
261 	unsigned char type;	/* symbol type */
262 #define NO_TYPE		0	/* invalid type */
263 #define NOTEREST	1	/* valid symbol types */
264 #define SPACE		2
265 #define BAR		3
266 #define CLEF		4
267 #define TIMESIG 	5
268 #define KEYSIG		6
269 #define TEMPO		7
270 #define STAVES		8
271 #define MREST		9
272 #define PART		10
273 #define GRACE		11
274 #define FMTCHG		12
275 #define TUPLET		13
276 #define STBRK		14
277 #define CUSTOS		15
278 #define NSYMTYPES	16
279 	unsigned char voice;	/* voice (0..nvoice) */
280 	unsigned char staff;	/* staff (0..nstaff) */
281 	unsigned char nhd;	/* number of notes in chord - 1 */
282 	signed char pits[MAXHD]; /* pitches / clef */
283 	int dur;		/* main note duration */
284 	int time;		/* starting time */
285 	unsigned int sflags;	/* symbol flags */
286 #define S_EOLN		0x0001		/* end of line */
287 #define S_BEAM_ST	0x0002		/* beam starts here */
288 #define S_BEAM_BR1	0x0004		/* 2nd beam must restart here */
289 #define S_BEAM_BR2	0x0008		/* 3rd beam must restart here */
290 #define S_BEAM_END	0x0010		/* beam ends here */
291 #define S_CLEF_AUTO	0x0020		/* auto clef (when clef) */
292 #define S_IN_TUPLET	0x0040		/* in a tuplet */
293 #define S_TREM2		0x0080		/* tremolo on 2 notes */
294 #define S_RRBAR		0x0100		/* right repeat bar (when bar) */
295 #define S_XSTEM		0x0200		/* cross-staff stem (when note) */
296 #define S_BEAM_ON	0x0400		/* continue beaming */
297 #define S_SL1		0x0800		/* some chord slur start */
298 #define S_SL2		0x1000		/* some chord slur end */
299 #define S_TI1		0x2000		/* some chord tie start */
300 #define S_PERC		0x4000		/* percussion */
301 #define S_RBSTOP	0x8000		// end of repeat bracket
302 #define S_FEATHERED_BEAM 0x00010000	/* feathered beam */
303 #define S_REPEAT	0x00020000	/* sequence / measure repeat */
304 #define S_NL		0x00040000	/* start of new music line */
305 #define S_SEQST		0x00080000	/* start of vertical sequence */
306 #define S_SECOND	0x00100000	/* symbol on a secondary voice */
307 #define S_FLOATING	0x00200000	/* symbol on a floating voice */
308 #define S_NOREPBRA	0x00400000	/* don't print the repeat bracket */
309 #define S_TREM1		0x00800000	/* tremolo on 1 note */
310 #define S_TEMP		0x01000000	/* temporary symbol */
311 #define S_SHIFTUNISON_1	0x02000000	/* %%shiftunison 1 */
312 #define S_SHIFTUNISON_2	0x04000000	/* %%shiftunison 2 */
313 #define S_NEW_SY	0x08000000	/* staff system change (%%staves) */
314 #define S_RBSTART	0x10000000	// start of repeat bracket
315 	struct posit_s posit;	/* positions / directions */
316 	signed char stem;	/* 1 / -1 for stem up / down */
317 	signed char combine;	/* voice combine */
318 	signed char nflags;	/* number of note flags when > 0 */
319 	char dots;		/* number of dots */
320 	unsigned char head;	/* head type */
321 #define H_FULL		0
322 #define H_EMPTY 	1
323 #define H_OVAL		2
324 #define H_SQUARE	3
325 	signed char multi;	/* multi voice in the staff (+1, 0, -1) */
326 	signed char nohdi1;	/* no head index (for unison) / nb of repeat */
327 	signed char nohdi2;
328 	signed char doty;	/* NOTEREST: y pos of dot when voices overlap
329 				 * STBRK: forced
330 				 * FMTCHG REPEAT: infos */
331 	short aux;		/* auxillary information:
332 				 *	- CLEF: small clef
333 				 *	- KEYSIG: old key signature
334 				 *	- BAR: new bar number
335 				 *	- TUPLET: tuplet format
336 				 *	- NOTE: tremolo number / feathered beam
337 				 *	- FMTCHG (format change): subtype */
338 #define PSSEQ 0				/* postscript sequence */
339 #define SVGSEQ 1			/* SVG sequence */
340 #define REPEAT 2			/* repeat sequence or measure
341 					 *	doty: # measures if > 0
342 					 *	      # notes/rests if < 0
343 					 *	nohdi1: # repeat */
344 	int color;
345 	float x;		/* x offset */
346 	signed char y;		/* y offset of note head */
347 	signed char ymn, ymx;	/* min, max, note head y offset */
348 	signed char mid;	// y offset of the staff middle line
349 	float xmx;		/* max h-pos of a head rel to top
350 				 * width when STBRK */
351 	float xs, ys;		/* coord of stem end / bar height */
352 	float wl, wr;		/* left, right min width */
353 	float space;		/* natural space before symbol */
354 	float shrink;		/* minimum space before symbol */
355 	float xmax;		/* max x offset */
356 	struct gch *gch;	/* guitar chords / annotations */
357 	struct lyrics *ly;	/* lyrics */
358 
359 	char state;		/* symbol state in file/tune */
360 #define ABC_S_GLOBAL 0			/* global */
361 #define ABC_S_HEAD 1			/* in header (after X:) */
362 #define ABC_S_TUNE 2			/* in tune (after K:) */
363 	unsigned short flags;
364 #define ABC_F_ERROR	0x0001		/* error around this symbol */
365 #define ABC_F_INVIS	0x0002		/* invisible symbol */
366 #define ABC_F_SPACE	0x0004		/* space before a note */
367 #define ABC_F_STEMLESS	0x0008		/* note with no stem */
368 #define ABC_F_LYRIC_START 0x0010	/* may start a lyric here */
369 #define ABC_F_GRACE	0x0020		/* grace note */
370 #define ABC_F_GR_END	0x0040		/* end of grace note sequence */
371 #define ABC_F_SAPPO	0x0080		/* short appoggiatura */
372 #define ABC_F_RBSTART	0x0100		// start of repeat bracket and mark
373 #define ABC_F_RBSTOP	0x0200		// end of repeat bracket and mark
374 	unsigned short colnum;	/* ABC source column number */
375 	int linenum;		/* ABC source line number */
376 	char *fn;		/* ABC source file name */
377 	char *text;		/* main text (INFO, PSCOM),
378 				 * guitar chord (NOTE, REST, BAR) */
379 	union {			/* type dependent part */
380 		struct key_s {		/* K: info */
381 			signed char sf;		/* sharp (> 0) flats (< 0) */
382 			char empty;		/* clef alone if 1, 'none' if 2 */
383 			char exp;		/* exp (1) or mod (0) */
384 //			char mode;		/* mode */
385 //					/* 0: Ionian, 1: Dorian, 2: Phrygian, 3: Lydian,
386 //					 * 4: Mixolydian, 5: Aeolian, 6: Locrian */
387 			char instr;		/* specific instrument */
388 #define K_HP 1				/* bagpipe */
389 #define K_Hp 2
390 #define K_DRUM 3			/* percussion */
391 			signed char nacc;	/* number of explicit accidentals */
392 			signed char cue;	/* cue voice (scale 0.7) */
393 			signed char octave;	/* 'octave=' */
394 #define NO_OCTAVE 10				/* no 'octave=' */
395 			unsigned char microscale; /* microtone denominator - 1 */
396 			char clef_delta;	/* clef delta */
397 			char key_delta;		// tonic base
398 			char *stafflines;
399 			float staffscale;
400 			signed char pits[8];
401 			unsigned char accs[8];
402 		} key;
403 		struct {		/* L: info */
404 			int base_length;	/* basic note length */
405 		} length;
406 		struct meter_s {	/* M: info */
407 			short wmeasure;		/* duration of a measure */
408 			unsigned char nmeter;	/* number of meter elements */
409 			char expdur;		/* explicit measure duration */
410 #define MAX_MEASURE 16
411 			struct {
412 				char top[8];	/* top value */
413 				char bot[2];	/* bottom value */
414 			} meter[MAX_MEASURE];
415 		} meter;
416 		struct {		/* Q: info */
417 			char *str1;		/* string before */
418 			short beats[4];		/* up to 4 beats */
419 			short circa;		/* "ca. " */
420 			short tempo;		/* number of beats per mn or */
421 			short new_beat;		/* old beat */
422 			char *str2;		/* string after */
423 		} tempo;
424 		struct {		/* V: info */
425 			char id[VOICE_ID_SZ];	/* voice ID */
426 			char *fname;		/* full name */
427 			char *nname;		/* nick name */
428 			float scale;		/* != 0 when change */
429 			unsigned char voice;	/* voice number */
430 			signed char octave;	/* 'octave=' - same as in K: */
431 			char merge;		/* merge with previous voice */
432 			signed char stem;	/* have stems up or down (2 = auto) */
433 			signed char gstem;	/* have grace stems up or down (2 = auto) */
434 			signed char dyn;	/* have dynamic marks above or below the staff */
435 			signed char lyrics;	/* have lyrics above or below the staff */
436 			signed char gchord;	/* have gchord above or below the staff */
437 			signed char cue;	/* cue voice (scale 0.7) */
438 			char *stafflines;
439 			float staffscale;
440 		} voice;
441 		struct {		/* bar, mrest or mrep */
442 			int type;
443 			char repeat_bar;
444 			char len;		/* len if mrest or mrep */
445 			char dotted;
446 			struct decos dc;	/* decorations */
447 		} bar;
448 		struct clef_s {		/* clef */
449 			char *name;		/* PS drawing function */
450 			signed char type;
451 #define TREBLE 0
452 #define ALTO 1
453 #define BASS 2
454 #define PERC 3
455 #define AUTOCLEF 4
456 			char line;
457 			signed char octave;	/* '+8' / '-8' */
458 			signed char transpose;	/* if '^8' / '_8' */
459 			char invis;		/* clef 'none' */
460 			char check_pitch;	/* check if old abc2ps transposition */
461 		} clef;
462 		struct notes note;	/* note, rest */
463 		struct {		/* user defined accent */
464 			unsigned char symbol;
465 			unsigned char value;
466 		} user;
467 		struct {
468 			char type;	/* 0: end of line
469 					 * 1: continuation ('\')
470 					 * 2: line break ('!') */
471 		} eoln;
472 		struct {		/* voice overlay */
473 			char type;
474 #define V_OVER_V 0				/* & */
475 #define V_OVER_S 1				/* (& */
476 #define V_OVER_E 2				/* &) */
477 			unsigned char voice;
478 		} v_over;
479 		struct {		/* tuplet */
480 			char p_plet, q_plet, r_plet;
481 		} tuplet;
482 	} u;
483 };
484 
485 /* parse definition */
486 struct parse {
487 	struct SYMBOL *first_sym; /* first symbol */
488 	struct SYMBOL *last_sym; /* last symbol */
489 	int abc_vers;		/* ABC version = (H << 16) + (M << 8) + L */
490 	char *deco_tb[DC_NAME_SZ]; /* decoration names */
491 	unsigned short micro_tb[MAXMICRO]; /* microtone values [ (n-1) | (d-1) ] */
492 	int abc_state;		/* parser state */
493 };
494 extern struct parse parse;
495 
496 #define	FONT_UMAX 10		/* max number of user fonts 0..9 */
497 enum e_fonts {
498 	ANNOTATIONFONT = FONT_UMAX,
499 	COMPOSERFONT,
500 	FOOTERFONT,
501 	GCHORDFONT,
502 	HEADERFONT,
503 	HISTORYFONT,
504 	INFOFONT,
505 	MEASUREFONT,
506 	PARTSFONT,
507 	REPEATFONT,
508 	SUBTITLEFONT,
509 	TEMPOFONT,
510 	TEXTFONT,
511 	TITLEFONT,
512 	VOCALFONT,
513 	VOICEFONT,
514 	WORDSFONT,
515 	FONT_DYN		/* index of dynamic fonts (gch, an, ly) */
516 };
517 #define	FONT_DYNX 12				/* number of dynamic fonts */
518 #define	FONT_MAX (FONT_DYN + FONT_DYNX)		/* whole number of fonts */
519 
520 struct FORMAT { 		/* struct for page layout */
521 	float pageheight, pagewidth;
522 	float topmargin, botmargin, leftmargin, rightmargin;
523 	float topspace, wordsspace, titlespace, subtitlespace, partsspace;
524 	float composerspace, musicspace, vocalspace, textspace;
525 	float breaklimit, maxshrink, lineskipfac, parskipfac, stemheight;
526 	float gutter, indent, infospace, slurheight, notespacingfactor, scale;
527 	float staffsep, sysstaffsep, maxstaffsep, maxsysstaffsep, stretchlast;
528 	int abc2pscompat, alignbars, aligncomposer, autoclef;
529 	int barsperstaff, breakoneoln, bstemdown, cancelkey, capo;
530 	int combinevoices, contbarnb, continueall, custos;
531 	int dblrepbar, decoerr, dynalign, flatbeams, infoline;
532 	int gchordbox, graceslurs, graceword,gracespace, hyphencont;
533 	int keywarn, landscape, linewarn;
534 	int measurebox, measurefirst, measurenb, micronewps;
535 	int oneperpage;
536 #ifdef HAVE_PANGO
537 	int pango;
538 #endif
539 	int partsbox, pdfmark;
540 	int rbdbstop, rbmax, rbmin;
541 	int setdefl, shiftunison, splittune, squarebreve;
542 	int staffnonote, straightflags, stretchstaff;
543 	int textoption, titlecaps, titleleft, titletrim;
544 	int timewarn, transpose, tuplets;
545 	char *bgcolor, *dateformat, *header, *footer, *titleformat;
546 	char *musicfont;
547 	struct FONTSPEC font_tb[FONT_MAX];
548 	char ndfont;		/* current index of dynamic fonts */
549 	unsigned char gcf, anf, vof;	/* fonts for guitar chords,
550 					 * annotations and lyrics */
551 	unsigned int fields[2];	/* info fields to print
552 				 *[0] is 'A'..'Z', [1] is 'a'..'z' */
553 	struct posit_s posit;
554 };
555 
556 extern struct FORMAT cfmt;	/* current format */
557 extern struct FORMAT dfmt;	/* global format */
558 
559 typedef struct SYMBOL *INFO[26]; /* information fields ('A' .. 'Z') */
560 extern INFO info;
561 
562 extern char *outbuf;		/* output buffer.. should hold one tune */
563 extern int outbufsz;		/* size of outbuf */
564 extern char *mbf;		/* where to PUTx() */
565 extern int use_buffer;		/* 1 if lines are being accumulated */
566 
567 extern int outft;		/* last font in the output file */
568 extern int tunenum;		/* number of current tune */
569 extern int pagenum;		/* current page number */
570 extern int nbar;		/* current measure number */
571 extern int in_page;
572 extern int defl;		/* decoration flags */
573 #define DEF_NOST 0x01		/* long deco with no start */
574 #define DEF_NOEN 0x02		/* long deco with no end */
575 #define DEF_STEMUP 0x04		/* stem up (1) or down (0) */
576 
577 		/* switches modified by flags: */
578 extern int quiet;		/* quiet mode */
579 extern int secure;		/* secure mode */
580 extern int annotate;		/* output source references */
581 extern int pagenumbers; 	/* write page numbers */
582 extern int epsf;		/* 1: EPSF, 2: SVG, 3: embedded ABC */
583 extern int svg;			/* 1: SVG, 2: XHTML */
584 extern int showerror;		/* show the errors */
585 extern int pipeformat;		/* format for bagpipes */
586 
587 extern char outfn[FILENAME_MAX]; /* output file name */
588 extern char *in_fname;		/* current input file name */
589 extern time_t mtime;		/* last modification time of the input file */
590 
591 extern int file_initialized;	/* for output file */
592 extern FILE *fout;		/* output file */
593 
594 #define MAXTBLT 8
595 struct tblt_s {
596 	char *head;		/* PS head function */
597 	char *note;		/* PS note function */
598 	char *bar;		/* PS bar function */
599 	float wh;		/* width of head */
600 	float ha;		/* height above the staff */
601 	float hu;		/* height under the staff */
602 	short pitch;		/* pitch when no associated 'w:' / 0 */
603 	char instr[2];		/* instrument pitch */
604 };
605 extern struct tblt_s *tblts[MAXTBLT];
606 
607 #define MAXCMDTBLT	4	/* max number of -T in command line */
608 struct cmdtblt_s {
609 	short index;		/* tablature number */
610 	short active;		/* activate or not */
611 	char *vn;		/* voice name */
612 };
613 extern struct cmdtblt_s cmdtblts[MAXCMDTBLT];
614 extern int ncmdtblt;
615 
616 extern int s_argc;		/* command line arguments */
617 extern char **s_argv;
618 
619 struct STAFF_S {
620 	struct SYMBOL *s_clef;	/* clef at start of music line */
621 	char empty;		/* no symbol on this staff */
622 	char *stafflines;
623 	float staffscale;
624 	short botbar, topbar;	/* bottom and top of bar */
625 	float y;		/* y position */
626 	float top[YSTEP], bot[YSTEP];	/* top/bottom y offsets */
627 };
628 extern struct STAFF_S staff_tb[MAXSTAFF];
629 extern int nstaff;		/* (0..MAXSTAFF-1) */
630 
631 struct VOICE_S {
632 	char id[VOICE_ID_SZ];	/* voice id */
633 							/* generation */
634 	struct VOICE_S *next;	/* link */
635 	struct SYMBOL *sym;	/* associated symbols */
636 	struct SYMBOL *last_sym; /* last symbol while scanning */
637 	struct SYMBOL *lyric_start;	/* start of lyrics while scanning */
638 	char *nm;		/* voice name */
639 	char *snm;		/* voice subname */
640 	char *bar_text;		/* bar text at start of staff when bar_start */
641 	struct gch *bar_gch;	/* bar text */
642 	struct SYMBOL *tie;	/* note with ties of previous line */
643 	struct SYMBOL *rtie;	/* note with ties before 1st repeat bar */
644 	struct tblt_s *tblts[2]; /* tablatures */
645 	float scale;		/* scale */
646 	int time;		/* current time (parsing) */
647 	struct SYMBOL *s_clef;	/* clef at end of music line */
648 	struct key_s key;	/* current key signature */
649 	struct meter_s meter;	/* current time signature */
650 	struct key_s ckey;	/* key signature while parsing */
651 	struct key_s okey;	/* original key signature (parsing) */
652 	unsigned hy_st;		/* lyrics hyphens at start of line (bit array) */
653 	unsigned ignore:1;	/* ignore this voice (%%staves) */
654 	unsigned second:1;	/* secondary voice in a brace/parenthesis */
655 	unsigned floating:1;	/* floating voice in a brace system */
656 	unsigned bar_repeat:1;	/* bar at start of staff is a repeat bar */
657 	unsigned norepbra:1;	/* don't display the repeat brackets */
658 	unsigned have_ly:1;	/* some lyrics in this voice */
659 	unsigned new_name:1;	/* redisplay the voice name */
660 	unsigned space:1;	/* have a space before the next note (parsing) */
661 	unsigned perc:1;	/* percussion */
662 	unsigned auto_len:1;	/* auto L: (parsing) */
663 	short wmeasure;		/* measure duration (parsing) */
664 	short transpose;	/* transposition (parsing) */
665 	short bar_start;	/* bar type at start of staff / 0 */
666 	struct posit_s posit;	/* positions / directions */
667 	signed char octave;	/* octave (parsing) */
668 	signed char ottava;	/* !8va(! ... (parsing) */
669 	signed char clone;	/* duplicate from this voice number */
670 	signed char over;	/* overlay of this voice number */
671 	unsigned char staff;	/* staff (0..n-1) */
672 	unsigned char cstaff;	/* staff (parsing) */
673 	unsigned char slur_st;	/* slurs at start of staff */
674 	signed char combine;	/* voice combine */
675 	int color;
676 	char *stafflines;
677 	float staffscale;
678 							/* parsing */
679 	struct SYMBOL *last_note;	/* last note or rest */
680 	char *map_name;
681 	short ulen;			/* unit note length */
682 	unsigned char microscale;	/* microtone scale */
683 	unsigned char mvoice;		/* main voice when voice overlay */
684 };
685 extern struct VOICE_S *curvoice;	/* current voice while parsing */
686 extern struct VOICE_S voice_tb[MAXVOICE]; /* voice table */
687 extern struct VOICE_S *first_voice; /* first_voice */
688 
689 extern struct SYMBOL *tsfirst;	/* first symbol in the time linked list */
690 extern struct SYMBOL *tsnext;	/* next line when cut */
691 extern float realwidth;		/* real staff width while generating */
692 
693 #define NFLAGS_SZ 10		/* size of note flags tables */
694 #define C_XFLAGS 5		/* index of crotchet in flags tables */
695 extern float space_tb[NFLAGS_SZ]; /* note spacing */
696 extern float hw_tb[];		// width of note heads
697 
698 struct SYSTEM {			/* staff system */
699 	struct SYSTEM *next;
700 	short top_voice;	/* first voice in the staff system */
701 	short nstaff;
702 	struct {
703 		short flags;
704 #define OPEN_BRACE 0x01
705 #define CLOSE_BRACE 0x02
706 #define OPEN_BRACKET 0x04
707 #define CLOSE_BRACKET 0x08
708 #define OPEN_PARENTH 0x10
709 #define CLOSE_PARENTH 0x20
710 #define STOP_BAR 0x40
711 #define FL_VOICE 0x80
712 #define OPEN_BRACE2 0x0100
713 #define CLOSE_BRACE2 0x0200
714 #define OPEN_BRACKET2 0x0400
715 #define CLOSE_BRACKET2 0x0800
716 #define MASTER_VOICE 0x1000
717 		char empty;
718 		char *stafflines;
719 		float staffscale;
720 //		struct clef_s clef;
721 		float sep, maxsep;
722 	} staff[MAXSTAFF];
723 	struct {
724 		signed char range;
725 		unsigned char staff;
726 		char second;
727 		char dum;
728 		float sep, maxsep;
729 //		struct clef_s clef;
730 	} voice[MAXVOICE];
731 };
732 extern struct SYSTEM *cursys;		/* current staff system */
733 
734 /* -- external routines -- */
735 /* abcm2ps.c */
736 void include_file(unsigned char *fn);
737 void clrarena(int level);
738 int lvlarena(int level);
739 void *getarena(int len);
740 void strext(char *fid, char *ext);
741 /* abcparse.c */
742 void abc_parse(char *p, char *fname, int linenum);
743 void abc_eof(void);
744 char *get_str(char *d,
745 	      char *s,
746 	      int maxlen);
747 char *parse_acc_pit(char *p,
748 		int *pit,
749 		int *acc);
750 /* buffer.c */
751 void a2b(char *fmt, ...)
752 #ifdef __GNUC__
753 	__attribute__ ((format (printf, 1, 2)))
754 #endif
755 	;
756 void block_put(void);
757 void buffer_eob(int eot);
758 void marg_init(void);
759 void bskip(float h);
760 void check_buffer(void);
761 void init_outbuf(int kbsz);
762 void close_output_file(void);
763 void close_page(void);
764 float get_bposy(void);
765 void open_fout(void);
766 void write_buffer(void);
767 extern int (*output)(FILE *out, const char *fmt, ...)
768 #ifdef __GNUC__
769 	__attribute__ ((format (printf, 2, 3)))
770 #endif
771 	;
772 void write_eps(void);
773 /* deco.c */
774 void deco_add(char *text);
775 void deco_cnv(struct decos *dc, struct SYMBOL *s, struct SYMBOL *prev);
776 void deco_update(struct SYMBOL *s, float dx);
777 float deco_width(struct SYMBOL *s);
778 void draw_all_deco(void);
779 //int draw_deco_head(int deco, float x, float y, int stem);
780 void draw_deco_near(void);
781 void draw_deco_note(void);
782 void draw_deco_staff(void);
783 float draw_partempo(int staff, float top);
784 void draw_measnb(void);
785 void init_deco(void);
786 void reset_deco(void);
787 void set_defl(int new_defl);
788 float tempo_width(struct SYMBOL *s);
789 void write_tempo(struct SYMBOL *s,
790 		int beat,
791 		float sc);
792 float y_get(int staff,
793 		int up,
794 		float x,
795 		float w);
796 void y_set(int staff,
797 		int up,
798 		float x,
799 		float w,
800 		float y);
801 /* draw.c */
802 void draw_sym_near(void);
803 void draw_all_symb(void);
804 float draw_systems(float indent);
805 void output_ps(struct SYMBOL *s, int color);
806 struct SYMBOL *prev_scut(struct SYMBOL *s);
807 void putf(float f);
808 void putx(float x);
809 void puty(float y);
810 void putxy(float x, float y);
811 void set_scale(struct SYMBOL *s);
812 void set_sscale(int staff);
813 void set_color(int color);
814 /* format.c */
815 void define_fonts(void);
816 int get_textopt(char *p);
817 int get_font_encoding(int ft);
818 int get_bool(char *p);
819 void interpret_fmt_line(char *w, char *p, int lock);
820 void lock_fmt(void *fmt);
821 void make_font_list(void);
822 FILE *open_file(char *fn,
823 		char *ext,
824 		char *rfn);
825 void print_format(void);
826 void set_font(int ft);
827 void set_format(void);
828 void set_voice_param(struct VOICE_S *p_voice, int state, char *w, char *p);
829 struct tblt_s *tblt_parse(char *p);
830 /* front.c */
831 #define FE_ABC 0
832 #define FE_FMT 1
833 #define FE_PS 2
834 void frontend(unsigned char *s,
835 		int ftype,
836 		char *fname,
837 		int linenum);
838 /* glyph.c */
839 char *glyph_out(char *p);
840 void glyph_add(char *p);
841 /* music.c */
842 void output_music(void);
843 void reset_gen(void);
844 void unlksym(struct SYMBOL *s);
845 /* parse.c */
846 extern float multicol_start;
847 void do_tune(void);
848 void identify_note(struct SYMBOL *s,
849 		int len,
850 		int *p_head,
851 		int *p_dots,
852 		int *p_flags);
853 void sort_pitch(struct SYMBOL *s);
854 struct SYMBOL *sym_add(struct VOICE_S *p_voice,
855 			int type);
856 /* subs.c */
857 void bug(char *msg, int fatal);
858 void error(int sev, struct SYMBOL *s, char *fmt, ...);
859 float scan_u(char *str, int type);
860 float cwid(unsigned char c);
861 void get_str_font(int *cft, int *dft);
862 void set_str_font(int cft, int dft);
863 #ifdef HAVE_PANGO
864 void pg_init(void);
865 void pg_reset_font(void);
866 #endif
867 void put_history(void);
868 void put_words(struct SYMBOL *words);
869 void str_font(int ft);
870 #define A_LEFT 0
871 #define A_CENTER 1
872 #define A_RIGHT 2
873 #define A_LYRIC 3
874 #define A_GCHORD 4
875 #define A_ANNOT 5
876 #define A_GCHEXP 6
877 void str_out(char *p, int action);
878 void put_str(char *str, int action);
879 float tex_str(char *s);
880 extern char tex_buf[];	/* result of tex_str() */
881 #define TEX_BUF_SZ 512
882 char *trim_title(char *p, struct SYMBOL *title);
883 void user_ps_add(char *s, char use);
884 void user_ps_write(void);
885 void write_title(struct SYMBOL *s);
886 void write_heading(void);
887 void write_user_ps(void);
888 void write_text(char *cmd, char *s, int job);
889 /* svg.c */
890 void define_svg_symbols(char *title, int num, float w, float h);
891 void svg_def_id(char *id, int idsz);
892 void svg_font_switch(void);
893 int svg_output(FILE *out, const char *fmt, ...)
894 #ifdef __GNUC__
895 	__attribute__ ((format (printf, 2, 3)))
896 #endif
897 	;
898 void svg_write(char *buf, int len);
899 void svg_close();
900 /* syms.c */
901 void define_font(char *name, int num, int enc);
902 void define_symbols(void);
903