| 1 |
unit analyze; |
| 2 |
|
| 3 |
{ Decide which lines of paragraphs go where; test total duration of lines. } |
| 4 |
|
| 5 |
interface uses control, globals; |
| 6 |
|
| 7 |
procedure testParagraph; |
| 8 |
procedure describeParagraph; |
| 9 |
procedure paragraphSetup (var voice: voice_index0); |
| 10 |
procedure includeStartString; |
| 11 |
|
| 12 |
implementation uses mtx, strings, lyrics, mtxline, uptext, |
| 13 |
preamble, utility; |
| 14 |
|
| 15 |
procedure includeStartString; |
| 16 |
var voice: voice_index; |
| 17 |
mus: paragraph_index0; |
| 18 |
begin for voice:=1 to nvoices do |
| 19 |
begin mus:=musicLineNo(voice); if mus>0 then |
| 20 |
P[mus]:=startString(voice)+P[mus]; |
| 21 |
end; |
| 22 |
end; |
| 23 |
|
| 24 |
function describe(nbar,extra: integer): string; |
| 25 |
begin describe:=toString(nbar)+' bar'+plural(nbar)+' + '+ |
| 26 |
toString(extra)+'/64 notes'; |
| 27 |
end; |
| 28 |
|
| 29 |
procedure testParagraph; |
| 30 |
var voice, leader, nv: voice_index0; |
| 31 |
mus: paragraph_index0; |
| 32 |
extra, l, nbar: integer; |
| 33 |
begin |
| 34 |
nbars:=0; pickup:=0; nleft:=0; if top>bottom then exit; |
| 35 |
pickup:=0; nv:=0; leader:=0; multi_bar_rest := ''; |
| 36 |
for voice:=top to bottom do |
| 37 |
begin mus:=musicLineNo(voice); |
| 38 |
if mus>0 then {* -------------- Voice is present ---- } |
| 39 |
begin inc(nv); line_no:=orig_line_no[mus]; |
| 40 |
scanMusic(voice,l); |
| 41 |
if (multi_bar_rest<>'') and (nv>1) then error( |
| 42 |
'Multi-bar rest allows only one voice',print); |
| 43 |
if not pmx_preamble_done then |
| 44 |
if voice=top then pickup:=l |
| 45 |
else if pickup<>l then |
| 46 |
error3(voice,'The same pickup must appear in all voices'); |
| 47 |
nbar := numberOfBars(voice); extra := extraLength(voice); |
| 48 |
if (multi_bar_rest<>'') and ((nbar>0) or (extra>0)) then error3(voice, |
| 49 |
'Multi-bar rest allows no other rests or notes'); |
| 50 |
if (nbar>nbars) or (nbar=nbars) and (extra>nleft) then |
| 51 |
begin nbars:=nbar; nleft:=extra; leader:=voice; end; |
| 52 |
if not final_paragraph and (meternum>0) and (extra>0) then |
| 53 |
begin writeln('Line has ', describe(nbar,extra)); |
| 54 |
error(' Line does not end at complete bar',print); |
| 55 |
end; |
| 56 |
if pmx_preamble_done and (l>0) and (meternum>0) then |
| 57 |
begin |
| 58 |
writeln('l=',l,' meternum=',meternum); |
| 59 |
error3(voice,'Short bar with no meter change'); |
| 60 |
end |
| 61 |
end |
| 62 |
end; |
| 63 |
if not pmx_preamble_done then |
| 64 |
begin |
| 65 |
xmtrnum0 := pickup/one_beat; { Don't want an integer result } |
| 66 |
if beVerbose then writeln ('Pickup = ', pickup, '/64'); |
| 67 |
end; |
| 68 |
if leader>0 then |
| 69 |
for voice:=top to bottom do if musicLineNo(voice)>0 then |
| 70 |
if voice<>leader then |
| 71 |
begin mus:=musicLineNo(voice); |
| 72 |
line_no:=orig_line_no[mus]; |
| 73 |
if (numberOfBars(voice)<>numberOfBars(leader)) |
| 74 |
or (extraLength(voice)<>extraLength(leader)) then |
| 75 |
begin |
| 76 |
writeln('Following line has ', |
| 77 |
describe(numberOfBars(voice), extraLength(voice))); |
| 78 |
writeln(musicLine(voice)); |
| 79 |
writeln('Longest line has ', |
| 80 |
describe(numberOfBars(leader), extraLength(leader))); |
| 81 |
writeln(musicLine(leader)); |
| 82 |
error('Line duration anomaly',print); |
| 83 |
end; |
| 84 |
end; |
| 85 |
end; |
| 86 |
|
| 87 |
procedure describeParagraph; |
| 88 |
var voice: voice_index0; |
| 89 |
begin writeln('---- Paragraph ',paragraph_no, |
| 90 |
' starting at line ', orig_line_no[1], ' bar ', bar_no); |
| 91 |
for voice:=top to bottom do describeVoice(voice,lyricsReport(voice)); |
| 92 |
end; |
| 93 |
|
| 94 |
procedure paragraphSetup (var voice: voice_index0); |
| 95 |
var l: integer; |
| 96 |
k: voice_index0; |
| 97 |
P_keep, w: string; |
| 98 |
is_labelled: boolean; |
| 99 |
|
| 100 |
procedure maybeUptext(i: integer); |
| 101 |
begin if not doUptext then exit; |
| 102 |
if (length(w)=1) then if (voice=nvoices) then |
| 103 |
warning('Uptext line below bottom voice should be labelled',print); |
| 104 |
if length(w)=1 then {* Standard chord line ------ } |
| 105 |
begin k:=voice+1; if k>nvoices then dec(k); |
| 106 |
setUptextLineNo(k,i); |
| 107 |
end |
| 108 |
else {* Labelled chord line ---- } |
| 109 |
begin predelete(w,1); k:=findVoice(w); |
| 110 |
if k=0 then error('Uptext line belongs to unknown voice',print) |
| 111 |
else setUptextLineNo(k,i); |
| 112 |
end |
| 113 |
end; |
| 114 |
|
| 115 |
procedure maybeChords(i: integer); |
| 116 |
begin if not doChords then exit; |
| 117 |
if (length(w)=1) and (voice=0) and pedanticWarnings then |
| 118 |
warning('Chord line above top voice should be labelled',print); |
| 119 |
if length(w)=1 then {* Standard chord line ------ } |
| 120 |
begin k:=voice; if k=0 then k:=1; |
| 121 |
setChordLineNo(k,i); |
| 122 |
end |
| 123 |
else {* Labelled chord line ---- } |
| 124 |
begin predelete(w,1); k:=findVoice(w); |
| 125 |
if k=0 then error('Chord line belongs to unknown voice',print) |
| 126 |
else setChordLineNo(k,i); |
| 127 |
end |
| 128 |
end; |
| 129 |
|
| 130 |
procedure analyzeParagraph; |
| 131 |
var i: paragraph_index; |
| 132 |
begin voice:=0; bottom:=0; top:=nvoices+1; |
| 133 |
clearLabels; clearTags; clearUptext; |
| 134 |
for i:=1 to para_len do { ----- Paragraph analysis main loop ----- } |
| 135 |
if (P[i]<>'') and (P[i,1]<>comment) then |
| 136 |
begin |
| 137 |
w:=NextWord(P[i],blank,colon); line_no := orig_line_no[i]; |
| 138 |
l:=length(w); |
| 139 |
is_labelled := (w[l]=colon) and (w[l-1]<>barsym); |
| 140 |
if is_labelled then |
| 141 |
begin P_keep := P[i]; predelete(P[i],l); shorten(w,l-1); |
| 142 |
k:=findVoice(w); { First look for a voice label } |
| 143 |
if k>0 then |
| 144 |
begin voice:=k; setMusicLineNo(voice,i); |
| 145 |
end |
| 146 |
else if w[1]='L' then maybeLyrics(voice,i,w) |
| 147 |
else if w[1]='C' then maybeChords(i) |
| 148 |
else if w[1]='U' then maybeUptext(i) |
| 149 |
else begin {* ------------ Maybe Space command ------------ } |
| 150 |
if startsWithIgnoreCase(w,'SPACE') then |
| 151 |
begin setSpace(P[i]); must_respace:=true; |
| 152 |
end |
| 153 |
else {* ------------ Maybe Voices command ------------ } |
| 154 |
if startsWithIgnoreCase(w,'VOICES') then |
| 155 |
begin selectVoices(P[i]); must_restyle:=true; |
| 156 |
end |
| 157 |
else begin {* Could be sticky attribute *} |
| 158 |
P[i] := P_keep; is_labelled := false; |
| 159 |
if not isNoteOrRest(w) then error('Unknown line label',print); |
| 160 |
end |
| 161 |
end |
| 162 |
end; |
| 163 |
if not is_labelled then |
| 164 |
begin inc(voice); setMusicLineNo(voice,i); |
| 165 |
end; |
| 166 |
if voice>bottom then bottom:=voice; |
| 167 |
if (voice>0) and (voice<top) then top:=voice; |
| 168 |
end; |
| 169 |
end; |
| 170 |
|
| 171 |
procedure obliterate; |
| 172 |
var i: paragraph_index; |
| 173 |
new_only: string; |
| 174 |
begin new_only:=''; |
| 175 |
for i:=1 to para_len do if startsWithIgnoreCase(P[i],'only:') |
| 176 |
then begin new_only:=P[i]; P[i]:='%'; end; |
| 177 |
if new_only<>'' then setOnly(new_only) |
| 178 |
else for i:=1 to para_len do if omitLine(i) then P[i]:='%'; |
| 179 |
end; |
| 180 |
|
| 181 |
begin obliterate; analyzeParagraph; reviseLyrics; |
| 182 |
end; |
| 183 |
|
| 184 |
end. |