| 1 |
/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ |
| 2 |
/* From input file "analyze.pas" */ |
| 3 |
|
| 4 |
|
| 5 |
#include "p2c.h" |
| 6 |
|
| 7 |
|
| 8 |
#define ANALYZE_G |
| 9 |
#include "analyze.h" |
| 10 |
|
| 11 |
|
| 12 |
#ifndef MTX_H |
| 13 |
#include "mtx.h" |
| 14 |
#endif |
| 15 |
|
| 16 |
#ifndef STRINGS_H |
| 17 |
#include "strings.h" |
| 18 |
#endif |
| 19 |
|
| 20 |
#ifndef LYRICS_H |
| 21 |
#include "lyrics.h" |
| 22 |
#endif |
| 23 |
|
| 24 |
#ifndef MTXLINE_H |
| 25 |
#include "mtxline.h" |
| 26 |
#endif |
| 27 |
|
| 28 |
#ifndef UPTEXT_H |
| 29 |
#include "uptext.h" |
| 30 |
#endif |
| 31 |
|
| 32 |
#ifndef PREAMBLE_H |
| 33 |
#include "preamble.h" |
| 34 |
#endif |
| 35 |
|
| 36 |
#ifndef UTILITY_H |
| 37 |
#include "utility.h" |
| 38 |
#endif |
| 39 |
|
| 40 |
|
| 41 |
void includeStartString(void) |
| 42 |
{ |
| 43 |
voice_index voice; |
| 44 |
paragraph_index0 mus; |
| 45 |
voice_index FORLIM; |
| 46 |
Char STR1[256]; |
| 47 |
Char STR2[256]; |
| 48 |
|
| 49 |
FORLIM = nvoices; |
| 50 |
for (voice = 1; voice <= FORLIM; voice++) { |
| 51 |
mus = musicLineNo(voice); |
| 52 |
if (mus > 0) { |
| 53 |
sprintf(STR2, "%s%s", startString(STR1, voice), P[mus-1]); |
| 54 |
strcpy(P[mus-1], STR2); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
Static Char *describe(Char *Result, short nbar, short extra) |
| 61 |
{ |
| 62 |
Char STR1[256]; |
| 63 |
Char STR3[256]; |
| 64 |
Char STR4[256]; |
| 65 |
|
| 66 |
sprintf(Result, "%s bar%s + %s/64 notes", |
| 67 |
toString(STR1, nbar), plural(STR3, nbar), toString(STR4, extra)); |
| 68 |
return Result; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
void testParagraph(void) |
| 73 |
{ |
| 74 |
voice_index0 voice; |
| 75 |
voice_index0 leader = 0, nv = 0; |
| 76 |
paragraph_index0 mus; |
| 77 |
short extra, l, nbar; |
| 78 |
voice_index0 FORLIM; |
| 79 |
Char STR2[256]; |
| 80 |
Char STR4[256]; |
| 81 |
|
| 82 |
nbars = 0; |
| 83 |
pickup = 0; |
| 84 |
nleft = 0; |
| 85 |
if (top > bottom) |
| 86 |
return; |
| 87 |
pickup = 0; |
| 88 |
*multi_bar_rest = '\0'; |
| 89 |
FORLIM = bottom; |
| 90 |
for (voice = top; voice <= FORLIM; voice++) { |
| 91 |
mus = musicLineNo(voice); |
| 92 |
if (mus > 0) { /** -------------- Voice is present ---- */ |
| 93 |
nv++; |
| 94 |
line_no = orig_line_no[mus-1]; |
| 95 |
scanMusic(voice, &l); |
| 96 |
if (*multi_bar_rest != '\0' && nv > 1) |
| 97 |
error("Multi-bar rest allows only one voice", print); |
| 98 |
if (!pmx_preamble_done) { |
| 99 |
if (voice == top) |
| 100 |
pickup = l; |
| 101 |
else if (pickup != l) |
| 102 |
error3(voice, "The same pickup must appear in all voices"); |
| 103 |
} |
| 104 |
nbar = numberOfBars(voice); |
| 105 |
extra = ExtraLength(voice); |
| 106 |
if (*multi_bar_rest != '\0' && (nbar > 0 || extra > 0)) |
| 107 |
error3(voice, "Multi-bar rest allows no other rests or notes"); |
| 108 |
if (nbar > nbars || nbar == nbars && extra > nleft) { |
| 109 |
nbars = nbar; |
| 110 |
nleft = extra; |
| 111 |
leader = voice; |
| 112 |
} |
| 113 |
if (!final_paragraph && meternum > 0 && extra > 0) { |
| 114 |
printf("Line has %s\n", describe(STR2, nbar, extra)); |
| 115 |
error(" Line does not end at complete bar", print); |
| 116 |
} |
| 117 |
if (pmx_preamble_done && l > 0 && meternum > 0) { |
| 118 |
printf("l=%d meternum=%d\n", l, meternum); |
| 119 |
error3(voice, "Short bar with no meter change"); |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
if (!pmx_preamble_done) { |
| 124 |
xmtrnum0 = (double)pickup / one_beat; /* Don't want an integer result */ |
| 125 |
if (beVerbose()) |
| 126 |
printf("Pickup = %d/64\n", pickup); |
| 127 |
} |
| 128 |
if (leader <= 0) |
| 129 |
return; |
| 130 |
FORLIM = bottom; |
| 131 |
for (voice = top; voice <= FORLIM; voice++) { |
| 132 |
if (musicLineNo(voice) > 0) { |
| 133 |
if (voice != leader) { |
| 134 |
mus = musicLineNo(voice); |
| 135 |
line_no = orig_line_no[mus-1]; |
| 136 |
if (numberOfBars(voice) != numberOfBars(leader) || |
| 137 |
ExtraLength(voice) != ExtraLength(leader)) { |
| 138 |
printf("Following line has %s\n", |
| 139 |
describe(STR4, numberOfBars(voice), ExtraLength(voice))); |
| 140 |
puts(musicLine(STR4, voice)); |
| 141 |
printf("Longest line has %s\n", |
| 142 |
describe(STR2, numberOfBars(leader), ExtraLength(leader))); |
| 143 |
puts(musicLine(STR2, leader)); |
| 144 |
error("Line duration anomaly", print); |
| 145 |
} |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
void describeParagraph(void) |
| 153 |
{ |
| 154 |
voice_index0 voice; |
| 155 |
Char STR2[256]; |
| 156 |
voice_index0 FORLIM; |
| 157 |
|
| 158 |
printf("---- Paragraph %d starting at line %d bar %d\n", |
| 159 |
paragraph_no, orig_line_no[0], bar_no); |
| 160 |
FORLIM = bottom; |
| 161 |
for (voice = top; voice <= FORLIM; voice++) |
| 162 |
describeVoice(voice, lyricsReport(STR2, voice)); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
/* Local variables for paragraphSetup: */ |
| 167 |
struct LOC_paragraphSetup { |
| 168 |
voice_index0 *voice; |
| 169 |
short l; |
| 170 |
voice_index0 k; |
| 171 |
Char P_keep[256], w[256]; |
| 172 |
boolean is_labelled; |
| 173 |
} ; |
| 174 |
|
| 175 |
Local void maybeUptext(short i, struct LOC_paragraphSetup *LINK) |
| 176 |
{ |
| 177 |
if (!doUptext()) |
| 178 |
return; |
| 179 |
if (strlen(LINK->w) == 1) { |
| 180 |
if (*LINK->voice == nvoices) |
| 181 |
warning("Uptext line below bottom voice should be labelled", print); |
| 182 |
} |
| 183 |
if (strlen(LINK->w) == 1) { /** Standard chord line ------ */ |
| 184 |
LINK->k = *LINK->voice + 1; |
| 185 |
if (LINK->k > nvoices) |
| 186 |
LINK->k--; |
| 187 |
setUptextLineNo(LINK->k, i); |
| 188 |
/** Labelled chord line ---- */ |
| 189 |
return; |
| 190 |
} |
| 191 |
predelete(LINK->w, 1); |
| 192 |
LINK->k = findVoice(LINK->w); |
| 193 |
if (LINK->k == 0) |
| 194 |
error("Uptext line belongs to unknown voice", print); |
| 195 |
else |
| 196 |
setUptextLineNo(LINK->k, i); |
| 197 |
} |
| 198 |
|
| 199 |
Local void maybeChords(short i, struct LOC_paragraphSetup *LINK) |
| 200 |
{ |
| 201 |
if (!doChords()) |
| 202 |
return; |
| 203 |
if (strlen(LINK->w) == 1 && *LINK->voice == 0 && pedanticWarnings()) |
| 204 |
warning("Chord line above top voice should be labelled", print); |
| 205 |
if (strlen(LINK->w) == 1) { /** Standard chord line ------ */ |
| 206 |
LINK->k = *LINK->voice; |
| 207 |
if (LINK->k == 0) |
| 208 |
LINK->k = 1; |
| 209 |
setChordLineNo(LINK->k, i); |
| 210 |
/** Labelled chord line ---- */ |
| 211 |
return; |
| 212 |
} |
| 213 |
predelete(LINK->w, 1); |
| 214 |
LINK->k = findVoice(LINK->w); |
| 215 |
if (LINK->k == 0) |
| 216 |
error("Chord line belongs to unknown voice", print); |
| 217 |
else |
| 218 |
setChordLineNo(LINK->k, i); |
| 219 |
} |
| 220 |
|
| 221 |
Local void analyzeParagraph(struct LOC_paragraphSetup *LINK) |
| 222 |
{ |
| 223 |
paragraph_index i, FORLIM; |
| 224 |
|
| 225 |
*LINK->voice = 0; |
| 226 |
bottom = 0; |
| 227 |
top = nvoices + 1; |
| 228 |
clearLabels(); |
| 229 |
clearTags(); |
| 230 |
clearUptext(); |
| 231 |
FORLIM = para_len; |
| 232 |
for (i = 1; i <= FORLIM; i++) |
| 233 |
{ /* ----- Paragraph analysis main loop ----- */ |
| 234 |
if (*P[i-1] != '\0' && P[i-1][0] != comment) { |
| 235 |
NextWord(LINK->w, P[i-1], blank, colon); |
| 236 |
line_no = orig_line_no[i-1]; |
| 237 |
LINK->l = strlen(LINK->w); |
| 238 |
LINK->is_labelled = (LINK->w[LINK->l-1] == colon && |
| 239 |
LINK->w[LINK->l-2] != barsym); |
| 240 |
if (LINK->is_labelled) { |
| 241 |
strcpy(LINK->P_keep, P[i-1]); |
| 242 |
predelete(P[i-1], LINK->l); |
| 243 |
shorten(LINK->w, LINK->l - 1); |
| 244 |
LINK->k = findVoice(LINK->w); /* First look for a voice label */ |
| 245 |
if (LINK->k > 0) { |
| 246 |
*LINK->voice = LINK->k; |
| 247 |
setMusicLineNo(*LINK->voice, i); |
| 248 |
} else if (LINK->w[0] == 'L') |
| 249 |
maybeLyrics(*LINK->voice, i, LINK->w); |
| 250 |
else if (LINK->w[0] == 'C') |
| 251 |
maybeChords(i, LINK); |
| 252 |
else if (LINK->w[0] == 'U') |
| 253 |
maybeUptext(i, LINK); |
| 254 |
else { |
| 255 |
if (startsWithIgnoreCase(LINK->w, "SPACE")) { |
| 256 |
setSpace(P[i-1]); |
| 257 |
must_respace = true; |
| 258 |
} else { |
| 259 |
if (startsWithIgnoreCase(LINK->w, "VOICES")) { |
| 260 |
selectVoices(P[i-1]); |
| 261 |
must_restyle = true; |
| 262 |
} else { |
| 263 |
strcpy(P[i-1], LINK->P_keep); |
| 264 |
LINK->is_labelled = false; |
| 265 |
if (!isNoteOrRest(LINK->w)) { |
| 266 |
error("Unknown line label", print); |
| 267 |
/** ------------ Maybe Space command ------------ */ |
| 268 |
/** ------------ Maybe Voices command ------------ */ |
| 269 |
/** Could be sticky attribute **/ |
| 270 |
} |
| 271 |
} |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
if (!LINK->is_labelled) { |
| 276 |
(*LINK->voice)++; |
| 277 |
setMusicLineNo(*LINK->voice, i); |
| 278 |
} |
| 279 |
if (*LINK->voice > bottom) |
| 280 |
bottom = *LINK->voice; |
| 281 |
if (*LINK->voice > 0 && *LINK->voice < top) |
| 282 |
top = *LINK->voice; |
| 283 |
} |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
Local void obliterate(struct LOC_paragraphSetup *LINK) |
| 288 |
{ |
| 289 |
paragraph_index i; |
| 290 |
Char new_only[256]; |
| 291 |
paragraph_index FORLIM; |
| 292 |
|
| 293 |
*new_only = '\0'; |
| 294 |
FORLIM = para_len; |
| 295 |
for (i = 0; i <= FORLIM - 1; i++) { |
| 296 |
if (startsWithIgnoreCase(P[i], "only:")) { |
| 297 |
strcpy(new_only, P[i]); |
| 298 |
strcpy(P[i], "%"); |
| 299 |
} |
| 300 |
} |
| 301 |
if (*new_only != '\0') { |
| 302 |
setOnly(new_only); |
| 303 |
return; |
| 304 |
} |
| 305 |
FORLIM = para_len; |
| 306 |
for (i = 1; i <= FORLIM; i++) { |
| 307 |
if (omitLine(i)) |
| 308 |
strcpy(P[i-1], "%"); |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
void paragraphSetup(voice_index0 *voice_) |
| 314 |
{ |
| 315 |
struct LOC_paragraphSetup V; |
| 316 |
|
| 317 |
V.voice = voice_; |
| 318 |
obliterate(&V); |
| 319 |
analyzeParagraph(&V); |
| 320 |
reviseLyrics(); |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
/* End. */ |