chiark / gitweb /
Merge branch 'arkkra' into shiny
[mup] / mup / mup / globals.c
1 /* Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2006
2  * by Arkkra Enterprises */
3 /* All rights reserved */
4 /*
5  *      globals.c
6  *
7  *      This files defines all the global variables used in more than one
8  *      file, except for ones that are used only by yacc and lex.
9  */
10
11 #include "structs.h"
12 #include "rational.h"
13 #include "globals.h"
14
15 /*
16  * Define the fixed SSV structures, which accumulate attributes of the
17  * score, staffs, and voices.
18  */
19 struct SSV Score;
20 struct SSV Staff[MAXSTAFFS];
21 struct SSV Voice[MAXSTAFFS][MAXVOICES];
22
23 /*
24  * Define command line requested staff and voice visibilities.  Each value is
25  * YES or NO.
26  */
27 short Staff_vis[MAXSTAFFS + 1];
28 short Voice_vis[MAXSTAFFS + 1][MAXVOICES + 1];
29
30 /*
31  * Define head and tail cells of the main linked list set up by the parser.
32  */
33 struct MAINLL *Mainllhc_p;
34 struct MAINLL *Mainlltc_p;
35
36 int Optch = OPTION_MARKER;      /* character for command line options */
37 int Mupmate = NO;               /* was Mup called from Mupmate? */
38 int Errorcount;         /* number of errors found so far */
39 int Maxverses;          /* maximum number of verse numbers used in the song */
40 short Meas_num = 1;     /* count measure numbers */
41 int Preproc = NO;       /* was -E specified on command line? */
42 int Ppcomments = NO;    /* was -C specified on command line? */
43
44 int Context = C_MUSIC;
45 int Curr_family = BASE_TIMES;
46 int Curr_font = FONT_TR;
47 int Curr_size = DFLT_SIZE;
48 int Got_some_data = NO;
49 int Doing_tab_staff;    /* YES while parsing a line for a tab staff, else NO */
50 int Doing_MIDI = NO;
51 char *Curr_filename;
52 char *Outfilename = "";
53 int Vflag = NO;
54 int Vcombused = NO;     /* was the voicecombine parameter ever used? */
55 int CSBused = NO;       /* was cross staff beaming used in this song? */
56 int CSSused = NO;       /* was cross staff stemming used in this song? */
57 int CSSpass = NO;       /* YES while doing a special pass for cross staff stem*/
58
59 /*
60  * Due to read ahead, we may already be on the following line when generating
61  * an error message, so need to know when to compensate by subtracting
62  * 1 from the current line number.
63  */
64 int Last_was_newline = NO;
65
66 /*
67  * The following table lets you conveniently find the character name of any
68  * note head type of form GF_NORMAL.  It is to be indexed like this:
69  *      headchar = Hctab [ basictime > 2 ? 3 : basictime ];
70  */
71 unsigned char Hctab [] = {
72         C_DBLWHOLE,     C_1N,   C_2N,   C_4N
73 };
74
75 /*
76  * This table is like Hctab, but for X notes.  Note that for half notes and
77  * longer, we actually draw the note as a diamond instead of an X.
78  */
79 unsigned char Xhctab[] = {
80         C_DWHDIAMOND,   C_DIAMOND,      C_DIAMOND,       C_XNOTE
81 };
82
83 /*
84  * This table is like Hctab, but for diamond shaped notes.
85  */
86 unsigned char Dhctab[] = {
87         C_DWHDIAMOND,   C_DIAMOND,      C_DIAMOND,       C_FILLDIAMOND
88 };
89
90 /*
91  * The following table lets you conveniently find the character name of any
92  * rest type, whole or shorter.  It is to be indexed by log2(basictime).
93  */
94 unsigned char Resttab[] = {
95         C_LL1REST, C_LL2REST, C_4REST, C_8REST, C_16REST, C_32REST, C_64REST,
96         C_128REST, C_256REST,
97 };
98
99 /*
100  * The following table tells how many letters up from C each note is.  It is
101  * to be indexed by (noteletter - 'a').
102  */
103 int Letshift[] = { 5, 6, 0, 1, 2, 3, 4, };
104                 /* a  b  c  d  e  f  g */
105
106 /* the note letters in the order of the circle of fifths */
107 char Circle[] = "fcgdaeb";
108
109 /* internal accidental letters */
110 char Acclets[] = "B&n#x";
111
112 /* external accidental symbols */
113 char *Acctostr[] = { "&&", "&", "", "#", "x" };
114
115 /*
116  * Define strings for pedstyle = pedstar ("Ped." and the star).
117  */
118 char Ped_start[] = { FONT_ZI, 18, 'P', 'e', 'd', '.', '\0' };
119 char Ped_stop[] =  { FONT_ZD, 14, 'j', '\0' };
120
121 /*
122  * Define the string info for standard guitar tuning.  Note that the octaves
123  * are for how it should be printed; the actual sound is an octave lower.
124  * When outputting MIDI, we check whether the tablature staff is using this
125  * default array, and if so, automatically transpose down by 12 halfsteps.
126  */
127 struct STRINGINFO Guitar[DEFTABLINES] = {
128         { 'e', '\0', 0, 5 },
129         { 'b', '\0', 0, 4 },
130         { 'g', '\0', 0, 4 },
131         { 'd', '\0', 0, 4 },
132         { 'a', '\0', 0, 3 },
133         { 'e', '\0', 1, 3 },
134 };
135
136 /*
137  * These arrays are used to keep track of things while adjusting the pitches
138  * of notes to account for octave marks. They are indexed by staff number,
139  * so element 0 of each array is unused. Octave mark related transposition
140  * is done both in MIDI code and trantab code.
141  */
142 int Octave_adjust[MAXSTAFFS+1]; /* how many octaves to adjust due to
143                                  * user-specified octave marks */
144 int Octave_bars[MAXSTAFFS+1];   /* how many bar lines to cross with
145                                  * current Octave_adjust (if Octave_adjust is
146                                  * zero, this variable is meaningless) */
147 float Octave_count[MAXSTAFFS+1];/* number of counts into measure that
148                                  * Octave_adjust applies in measure after
149                                  * Octave_bars have gone by. (if Octave_adjust
150                                  * is zero, this variable is meaningless */
151 /*
152  * Define fixed location variables.  For all of these, only the absolute
153  * coordinates are used.
154  */
155 float _Page     [NUMCTYPE];     /* whole page */
156 float _Win      [NUMCTYPE];     /* middle (music) window */
157 float _Cur      [NUMCTYPE];     /* current position */
158
159 /*
160  * Define the structures for headers and footers.
161  */
162 struct BLOCKHEAD Header;        /* first page header */
163 struct BLOCKHEAD Footer;        /* first page footer */
164 struct BLOCKHEAD Header2;       /* later page header */
165 struct BLOCKHEAD Footer2;       /* later page footer */
166
167 /*
168  * used by print phase to keep track of current staff locations
169  */
170 float *Score_location_p;        /* score coord from FEED struct */
171 float Staffs_y[MAXSTAFFS + 1];  /* absolute Y of the staffs of a score */
172
173 /*
174  * While constructing a GRPSYL list of groups or lyrics, or a list of STUFF,
175  * any of which could be being defining for multiple staffs at once and/or more
176  * than one vno, keep a pointer to the list of staffs and vnos being defined.
177  * Once we gather an entire line of input, the GRPSYL list or STUFF list is
178  * cloned for each staff being defined, and the information is moved to be
179  * associated with the appropriate STAFF structs.
180  */
181 struct RANGELIST *Staffrange_p;
182 struct RANGELIST *Vnorange_p;
183
184 /*
185  * During parse phase, this keeps track of the place (PL_ABOVE, PL_BELOW,
186  * or PL_BETWEEN) of the current thing being collected (groups, lyrics,
187  * or stuff).
188  */
189 short Place;
190
191 /*
192  * Snapshot of the state of pedals at the beginning of endings.
193  * The zeroth element of the array is used as a flag. If it is YES,
194  * the rest of the array contains the pedal state for each staff,
195  * YES for pedal on, NO for off. If the zeroth element is NO,
196  * the rest of the array is meaningless.
197  */
198 short Ped_snapshot[MAXSTAFFS + 1];
199
200 /* table to give a quick mapping from staff number to STAFF struct */
201 struct MAINLL *Staffmap_p[MAXSTAFFS + 1];
202
203 /* pointer to beginning of all the STAFF structs in current measure */
204 struct MAINLL *List_of_staffs_p;
205
206 struct SVRANGELIST *Svrangelist_p;
207
208 /* beginning of the list of GRPSYL structs currently being built */
209 struct GRPSYL *Curr_gs_list_p;
210
211 /* If 0, no multirest in current measure yet.
212  * If 1, got a multirest.
213  * If 2, got both a multirest and music data */
214 short Got_multirest;
215
216 /* YES if input contained at least one group in the current measure */
217 short Got_group;
218
219 short Pagenum;                  /* which page we are currently printing */
220 int Last_pagenum;               /* page number of the final page */
221
222 /* set to YES if given font is used somewhere */
223 short Font_used[MAXFONTS];
224
225 /* items used when chord grids are to be printed at the end of the song */
226 struct ATEND_INFO Atend_info;
227
228 /*
229  * Define a variable for a staff's staffscale, and other variables which are
230  * staffscale times the corresponding macro symbol in all caps.  This is to
231  * avoid recalculating these all the time.  These variables are for use in
232  * files where a main function loops over staffs, and calls a tree of
233  * subroutines for each staff.  The main function should set these variables
234  * for the current staff, and from there on the code can use them.  Early in
235  * Mup they are initialized to their default values by doing initstructs()
236  * and set_staffscale(0), so that everywhere before the point where staff
237  * scaling begins (in restsyl.c) they are set to these default values, and
238  * code before there can call utilities that use these symbols and no scaling
239  * will result.
240  */
241 float Staffscale;       /* for this staff */
242 float Stdpad;           /* STDPAD on this staff */
243 float Stepsize;         /* STEPSIZE on this staff */
244 float Flagsep;          /* FLAGSEP on this staff */
245 float Smflagsep;        /* SMFLAGSEP on this staff */
246 float Tupheight;        /* TUPHEIGHT on this staff */
247
248 /* define rational number constants that may be useful in multiple files */
249 RATIONAL Zero = {0,1};
250 RATIONAL One_fourth = {1,4};
251 RATIONAL One_third = {1,3};
252 RATIONAL One_half = {1,2};
253 RATIONAL Two_thirds = {2,3};
254 RATIONAL Three_fourths = {3,4};
255 RATIONAL One = {1,1};
256 RATIONAL Two = {2,1};
257 RATIONAL Three = {3,1};
258 RATIONAL Four = {4,1};
259
260 /*
261  * Define something longer than the longest possible measure.  See the comment
262  * by the #define for MAXTSLEN.
263  */
264 RATIONAL Maxtime = {(MAXTSLEN - 3) * 99 + 1, 1};
265
266 int Debuglevel;                 /* bitmap of what message classes to print */