-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMDX_PerfConv.lpr
400 lines (357 loc) · 12 KB
/
MDX_PerfConv.lpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
{
*****************************************************************************
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Author: Boban Spasic
Program description:
Convertor for performance files from Yamaha TX7, DX1, DX5, TX802, DX7II to MiniDexed
}
program MDX_PerfConv;
{$mode objfpc}{$H+}
uses
{$DEFINE CMDLINE}
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Classes,
SysUtils,
CustApp,
untDispatcher,
untConverter,
untConvFunct,
untExtract,
untDXUtils, untRenumber;
type
{ TMDX_PerfConv }
TMDX_PerfConv = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure WriteHelp; virtual;
end;
{ TMDX_PerfConv }
procedure TMDX_PerfConv.DoRun;
var
ErrorMsg: string;
fVoiceA1: string;
fVoiceB1: string;
fVoiceA2: string;
fVoiceB2: string;
fOutput: string;
fSettings: string;
fDirectory: string;
iNumbering: integer;
fPerf: string;
slReport: TStringList;
msInputFile: TMemoryStream;
i: integer;
iStartPos: integer;
bVerbose: boolean;
begin
fVoiceA1 := '';
fVoiceB1 := '';
fVoiceA2 := '';
fVoiceB2 := '';
fDirectory := '';
fPerf := '';
bVerbose := False;
// quick check parameters
CaseSensitiveOptions := True;
ErrorMsg := CheckOptions('hica:b:A:B:p:n:vo:s:e:r:',
'help info convert voiceA1: voiceB1: voiceA2: voiceB2: perf: numbering: verbose output: settings: extract: renumber:');
if ErrorMsg <> '' then
begin
WriteHelp;
ShowException(Exception.Create(ErrorMsg));
Terminate;
Exit;
end;
if (ParamCount = 0) or HasOption('h', 'help') then
begin
WriteHelp;
Terminate;
Exit;
end;
if HasOption('v', 'verbose') then bVerbose := True;
if HasOption('o', 'output') then
begin
fOutput := GetOptionValue('o', 'output');
fOutput := IncludeTrailingPathDelimiter(fOutput);
fOutput := ExpandFileName(fOutput);
if bVerbose then WriteLn('Output directory: ' + fOutput);
if not DirectoryExists(fOutput) then CreateDir(fOutput);
end
else
begin
fOutput := GetOptionValue('a', 'voicea1');
fOutput := ExpandFileName(fOutput);
if bVerbose then WriteLn('Output directory: ' + fOutput);
fOutput := IncludeTrailingPathDelimiter(ExtractFileDir(fOutput));
end;
if HasOption('s', 'settings') then
begin
fSettings := GetOptionValue('s', 'settings');
fSettings := ExpandFileName(fSettings);
end;
if HasOption('n', 'numbering') then
iNumbering := (StrToIntDef(GetOptionValue('n', 'numbering'), 1) -1) else iNumbering := 0;
//The convert functions are already adding 1 for the first number
if HasOption('a', 'voicea1') then
begin
fVoiceA1 := GetOptionValue('a', 'voiceA1');
fVoiceA1 := ExpandFileName(fVoiceA1);
end;
if HasOption('b', 'voiceb1') then
begin
fVoiceB1 := GetOptionValue('b', 'voiceB1');
fVoiceB1 := ExpandFileName(fVoiceB1);
end;
if HasOption('A', 'voicea2') then
begin
fVoiceA2 := GetOptionValue('A', 'voiceA2');
fVoiceA2 := ExpandFileName(fVoiceA2);
end;
if HasOption('B', 'voiceb2') then
begin
fVoiceB2 := GetOptionValue('B', 'voiceB2');
fVoiceB2 := ExpandFileName(fVoiceB2);
end;
if HasOption('p', 'perf') then
begin
fPerf := GetOptionValue('p', 'perf');
fPerf := ExpandFileName(fPerf);
end;
if HasOption('i', 'info') then
begin
if (not FileExists(fVoiceA1)) and (not FileExists(fVoiceB1)) and
(not FileExists(fVoiceA2)) and (not FileExists(fVoiceB2)) and
(not FileExists(fPerf)) then
begin
WriteLn('Please specify at least one target file');
Terminate;
Exit;
end
else
begin
if FileExists(fVoiceA1) then
begin
slReport := TStringList.Create;
msInputFile := TMemoryStream.Create;
msInputFile.LoadFromFile(fVoiceA1);
iStartPos := 0;
if ContainsDX_SixOP_Data(msInputFile, iStartPos, slReport) then
begin
for i := 0 to slReport.Count - 1 do
WriteLn(slReport[i]);
end
else
begin
for i := 0 to slReport.Count - 1 do
WriteLn(slReport[i]);
end;
msInputFile.Free;
slReport.Free;
end;
if FileExists(fVoiceB1) then
begin
slReport := TStringList.Create;
msInputFile := TMemoryStream.Create;
msInputFile.LoadFromFile(fVoiceB1);
iStartPos := 0;
if ContainsDX_SixOP_Data(msInputFile, iStartPos, slReport) then
begin
for i := 0 to slReport.Count - 1 do
WriteLn(slReport[i]);
end
else
begin
for i := 0 to slReport.Count - 1 do
WriteLn(slReport[i]);
end;
msInputFile.Free;
slReport.Free;
end;
if FileExists(fVoiceA2) then
begin
slReport := TStringList.Create;
msInputFile := TMemoryStream.Create;
msInputFile.LoadFromFile(fVoiceA2);
iStartPos := 0;
if ContainsDX_SixOP_Data(msInputFile, iStartPos, slReport) then
begin
for i := 0 to slReport.Count - 1 do
WriteLn(slReport[i]);
end
else
begin
for i := 0 to slReport.Count - 1 do
WriteLn(slReport[i]);
end;
msInputFile.Free;
slReport.Free;
end;
if FileExists(fVoiceB2) then
begin
slReport := TStringList.Create;
msInputFile := TMemoryStream.Create;
msInputFile.LoadFromFile(fVoiceB2);
iStartPos := 0;
if ContainsDX_SixOP_Data(msInputFile, iStartPos, slReport) then
begin
for i := 0 to slReport.Count - 1 do
WriteLn(slReport[i]);
end
else
begin
for i := 0 to slReport.Count - 1 do
WriteLn(slReport[i]);
end;
msInputFile.Free;
slReport.Free;
end;
if FileExists(fPerf) then
begin
slReport := TStringList.Create;
msInputFile := TMemoryStream.Create;
msInputFile.LoadFromFile(fPerf);
iStartPos := 0;
if ContainsDX_SixOP_Data(msInputFile, iStartPos, slReport) then
begin
for i := 0 to slReport.Count - 1 do
WriteLn(slReport[i]);
end
else
begin
for i := 0 to slReport.Count - 1 do
WriteLn(slReport[i]);
end;
msInputFile.Free;
slReport.Free;
end;
end;
end;
if HasOption('c', 'convert') then
begin
if (not FileExists(fVoiceA1)) and (not FileExists(fVoiceB1)) and
(not FileExists(fVoiceA2)) and (not FileExists(fVoiceB2)) and
(not FileExists(fPerf)) then
begin
WriteLn('Please specify at least one target file');
Terminate;
Exit;
end
else
begin
if FileExists(fVoiceA1) and FileExists(fVoiceB1) and
FileExists(fVoiceA2) and FileExists(fVoiceB2) and FileExists(fPerf) then
begin
DispatchCheck(fVoiceA1, fVoiceB1, fVoiceA2, fVoiceB2, fPerf, iNumbering, bVerbose, fOutput, fSettings);
end
else
if FileExists(fVoiceA1) and FileExists(fVoiceB1) and FileExists(fPerf) then
begin
DispatchCheck(fVoiceA1, fVoiceB1, fPerf, iNumbering, bVerbose, fOutput, fSettings);
end
else
if FileExists(fVoiceA1) and FileExists(fVoiceB1) then
begin
DispatchCheck(fVoiceA1, fVoiceB1, iNumbering, bVerbose, fOutput, fSettings);
end
else
if FileExists(fVoiceA1) then
begin
DispatchCheck(fVoiceA1, iNumbering, bVerbose, fOutput, fSettings);
end;
end;
end;
if HasOption('r', 'renumber') and HasOption('n', 'numbering') then
begin
fDirectory := GetOptionValue('r', 'renumber');
if DirectoryExists(fDirectory) then
Renumber(fDirectory, iNumbering + 1);
end;
if HasOption('e', 'extract') then
begin
fPerf := GetOptionValue('e', 'extract');
fPerf := ExpandFileName(fPerf);
ExtractDispatch(fPerf, bVerbose);
end;
Terminate;
end;
constructor TMDX_PerfConv.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException := True;
end;
destructor TMDX_PerfConv.Destroy;
begin
inherited Destroy;
end;
procedure TMDX_PerfConv.WriteHelp;
begin
writeln('');
writeln('');
writeln('MDX Performance Converter 1.5 - Performance converter from TX7, DX7II, DX1 and DX5 to MiniDexed');
writeln('Author: Boban Spasic');
writeln('https://github.com/BobanSpasic/MDX_PerfConv');
writeln('');
writeln('Usage: ', ExtractFileName(ExeName), ' -parameters');
writeln(' Parameters (short and long form):');
writeln(' -h --help This help message');
writeln(' -i --info Information');
writeln(' -c --convert Convert to MiniDexed INI file');
writeln(' -v --verbose Detailed info');
writeln('');
writeln(' -a (filename) --voiceA1=(filename) Path to voice bank A1');
writeln(' -b (filename) --voiceB1=(filename) Path to voice bank B1');
writeln(' -A (filename) --voiceA2=(filename) Path to voice bank A2');
writeln(' -B (filename) --voiceB2=(filename) Path to voice bank B2');
writeln(' -p (filename) --perf=(filename) Path to performance file');
writeln(' -n (number) --numbering=(number) First number for filenames');
writeln(' of the output performances');
writeln(' -o (path) --output=(path) Output directory');
writeln(' -s (filename) --settings=(filename) Use settings file (see separate doc.)');
writeLn('');
writeln(' -e (filename) --extract=(filename) Extract data from libraries (see separate doc.)');
writeLn('');
writeln(' -r (path) --renumber=(path) Re-number the performance INI files in a directory');
writeln(' To be used in combination with -n');
writeLn('');
writeLn(' Parameters are CASE-SENSITIVE');
writeLn('');
writeln(' Example usage:');
writeln(' Get info from any kind of supported files:');
writeln(' MDX_PerfConv -i -a VoiceBank.syx');
writeln('');
writeln(' Get info from max. 5 supported files:');
writeln(' MDX_PerfConv -i -a VoiceBankA.syx -b VoiceBankB.syx -p Performance.syx');
writeln('');
writeln(' Convert a TX7 bank (VMEM+PMEM):');
writeln(' MDX_PerfConv -c -a my_TX7_file.syx');
writeln('');
writeln(' Convert a DX7II bank (VMEM+AMEM):');
writeln(' MDX_PerfConv -c -a my_DX7II_file.syx');
writeln('');
writeln(' Convert a DX7II bank set:');
writeln(' MDX_PerfConv -c -a DX7II_BankA(1-32).syx -b DX7II_BankB(33-64).syx -p DX7II_Perf.syx');
writeln('');
writeln(' Convert a DX1/DX5 bank set:');
writeln(' MDX_PerfConv -c -a DX5_BankA1.syx -b DX5_BankB1.syx -A DX5_BankA2.syx -B DX_BankB2.syx -p DX5_Performance.syx');
writeln('');
writeln(' Parameters in long form:');
writeln(' MDX_PerfConv --info --voiceA1=VoiceBank.syx');
writeLn('');
writeLn('');
end;
var
Application: TMDX_PerfConv;
{$R *.res}
begin
Application := TMDX_PerfConv.Create(nil);
Application.Title := 'MDX Performance Converter';
Application.Run;
Application.Free;
end.