Debian Codegraph @

utils/m-tx/mtx-src/control.pas

raw
1 unit control; { DPL 2004-03-21 }
2 { Controls which M-Tx features are enabled.
3 The interface allows one to interrogate the feature state, to set
4 features according to the M-Tx level, and to override features given
5 the feature name as a character string.
6 }
7
8 interface
9
10 procedure mtxLevel(level: string);
11 function setFeature(which: string; val: boolean): boolean;
12 { return TRUE means OK, return FALSE means there is no such feature }
13 procedure printFeatures(anyway: boolean);
14 { anyway TRUE means print all feature settings, FALSE means only those
15 that were set via setFeature }
16
17 function multiFile: boolean;
18 function splitShortcut: boolean;
19 function newWordShortcut: boolean;
20 function doChords: boolean;
21 function doUptext: boolean;
22 function doLyrics: boolean;
23 function unbeamVocal: boolean;
24 function uptextOnRests: boolean;
25 function solfaNoteNames: boolean;
26 function pedanticWarnings: boolean;
27 function ignoreErrors: boolean;
28 function hideBlindSlurs: boolean;
29 function instrumentNames: boolean;
30 function beVerbose: boolean;
31 function debugMode: boolean;
32 function insertDuration: boolean;
33 function rearrangeNote: boolean;
34 function countMacro: boolean;
35 function expandMacro: boolean;
36 function checkPitch: boolean;
37
38 implementation uses utility;
39
40 type feature = (noSuchFeature,
41 FmultiFile, { enables Include: directive }
42 FsplitShortcut, { one-word shortcut is treated by simply inserting a blank }
43 FnewWordShortcut, { detached form of shortcut allowed }
44 FdoChords, { C: lines are taken into account }
45 FdoUptext, { U: lines are taken into account }
46 FdoLyrics, { L: lines are taken into account }
47 FunbeamVocal, { non-melismatic eighth and shorter notes in vocal lines are unbeamed }
48 FhideBlindSlurs, { blind slurs are hidden }
49 FuptextOnRests, { U: lines synchronize with words and rests }
50 FinsertDuration, { always insert duration into notes }
51 FcountMacro, { include macros in the count }
52 FexpandMacro, { literally expand macros }
53 FcheckPitch, { keep track of pitch and warn if unreal }
54 FrearrangeNote, { transform note words to canical form }
55 FsolfaNoteNames, { use solfa note names }
56 FpedanticWarnings, { issue warnings even when default action is likely to be correct }
57 FignoreErrors, { ignore all errors except fatal errors }
58 FinstrumentNames, { set instrument names }
59 FbeVerbose, { report what is being done }
60 FdebugMode { write all possible infomative messages } );
61
62 Tfeature = record
63 tag: string[30];
64 active, changed: boolean
65 end;
66
67 const
68 firstFeature = FmultiFile;
69 lastFeature = FdebugMode;
70
71 feat: array[feature] of Tfeature = (
72 ( tag: ''; active: false; changed: false),
73 ( tag: 'multiFile'; active: true; changed: false),
74 ( tag: 'splitShortcut'; active: true; changed: false),
75 ( tag: 'newWordShortcut'; active: true; changed: false),
76 ( tag: 'doChords'; active: true; changed: false),
77 ( tag: 'doUptext'; active: true; changed: false),
78 ( tag: 'doLyrics'; active: true; changed: false),
79 ( tag: 'unbeamVocal'; active: true; changed: false),
80 ( tag: 'hideBlindSlurs'; active: true; changed: false),
81 ( tag: 'uptextOnRests'; active: true; changed: false),
82 ( tag: 'insertDuration'; active: true; changed: false),
83 ( tag: 'countMacro'; active: false; changed: false),
84 ( tag: 'expandMacro'; active: false; changed: false),
85 ( tag: 'checkPitch'; active: true; changed: false),
86 ( tag: 'rearrangeNote'; active: true; changed: false),
87 ( tag: 'solfaNoteNames'; active: false; changed: false),
88 ( tag: 'pedanticWarnings'; active: false; changed: false),
89 ( tag: 'ignoreErrors'; active: false; changed: false),
90 ( tag: 'instrumentNames'; active: false; changed: false),
91 ( tag: 'beVerbose'; active: false; changed: false),
92 ( tag: 'debugMode'; active: false; changed: false)
93 );
94
95 procedure printFeatures(anyway: boolean);
96 var i: feature;
97 begin for i:=firstFeature to lastFeature do with feat[i] do
98 if changed or anyway then writeln(tag, ' = ', active)
99 end;
100
101 function featureNamed(s: string): feature;
102 var i: feature;
103 begin for i:=firstFeature to lastFeature do
104 if equalsIgnoreCase(s,feat[i].tag) then begin featureNamed := i; exit end;
105 featureNamed := noSuchFeature
106 end;
107
108 function setFeature(which: string; val: boolean): boolean;
109 var f: feature;
110 begin setFeature := false; f := featureNamed(which);
111 if f <> noSuchFeature then with feat[f] do
112 begin active := val; changed := true; setFeature := true end;
113 if (f=FdebugMode) and val then feat[FbeVerbose].active := true;
114 if (f=FbeVerbose) and not val then feat[FdebugMode].active := false;
115 end;
116
117 procedure mtxLevel(level: string);
118 begin
119 if level<'0.57' then
120 begin
121 setFeature('splitShortcut',false);
122 setFeature('newWordShortcut',false);
123 end
124 end;
125
126 { Feature functions. To add a new feature "newFeature":
127 1. Insert a new value "FnewFeature" in the declaration of type "feature".
128 2. Insert an entry for it in array "feat".
129 3. Copy the template below and change "FEATURE" into "newFeature".
130 4. Copy the function header to the interface section.
131 5. (Optional) Insert code into "mtxLevel" to enable/disable the feature.
132
133 function FEATURE: boolean;
134 begin FEATURE := feat[FFEATURE].active end;
135 }
136
137 function checkPitch: boolean;
138 begin checkPitch := feat[FcheckPitch].active end;
139
140 function countMacro: boolean;
141 begin countMacro := feat[FcountMacro].active end;
142
143 function expandMacro: boolean;
144 begin expandMacro := feat[FexpandMacro].active end;
145
146 function insertDuration: boolean;
147 begin insertDuration := feat[FinsertDuration].active end;
148
149 function rearrangeNote: boolean;
150 begin rearrangeNote := feat[FrearrangeNote].active end;
151
152 function beVerbose: boolean;
153 begin beVerbose := feat[FbeVerbose].active end;
154
155 function debugMode: boolean;
156 begin debugMode := feat[FdebugMode].active end;
157
158 function instrumentNames: boolean;
159 begin instrumentNames := feat[FinstrumentNames].active end;
160
161 function hideBlindSlurs: boolean;
162 begin hideBlindSlurs := feat[FhideBlindSlurs].active end;
163
164 function doLyrics: boolean;
165 begin doLyrics := feat[FdoLyrics].active end;
166
167 function ignoreErrors: boolean;
168 begin ignoreErrors := feat[FignoreErrors].active end;
169
170 function pedanticWarnings: boolean;
171 begin pedanticWarnings := feat[FpedanticWarnings].active end;
172
173 function solfaNoteNames: boolean;
174 begin solfaNoteNames := feat[FsolfaNoteNames].active end;
175
176 function uptextOnRests: boolean;
177 begin uptextOnRests := feat[FuptextOnRests].active end;
178
179 function unbeamVocal: boolean;
180 begin unbeamVocal := feat[FunbeamVocal].active end;
181
182 function doChords: boolean;
183 begin doChords := feat[FdoChords].active end;
184
185 function doUptext: boolean;
186 begin doUptext := feat[FdoUptext].active end;
187
188 function newWordShortcut: boolean;
189 begin newWordShortcut := feat[FnewWordShortcut].active end;
190
191 function splitShortcut: boolean;
192 begin splitShortcut := feat[FsplitShortcut].active end;
193
194 function multiFile: boolean;
195 begin multiFile := feat[FmultiFile].active end;
196
197 end.
198