Skip to content

Commit d4c5339

Browse files
committed
Implementing -o --overwrite parameter
1 parent 82e9ced commit d4c5339

5 files changed

+106
-77
lines changed

MDX_Hash_Test.lps

+7-7
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@
6868
<Unit>
6969
<Filename Value="MDX_Hash_Test.lpr"/>
7070
<IsPartOfProject Value="True"/>
71+
<IsVisibleTab Value="True"/>
7172
<CursorPos X="24" Y="92"/>
7273
<UsageCount Value="129"/>
7374
<Loaded Value="True"/>
7475
</Unit>
7576
<Unit>
7677
<Filename Value="untDXObjInterface.pas"/>
7778
<IsPartOfProject Value="True"/>
78-
<IsVisibleTab Value="True"/>
7979
<EditorIndex Value="4"/>
8080
<TopLine Value="708"/>
8181
<CursorPos X="29" Y="727"/>
@@ -117,8 +117,8 @@
117117
<Unit>
118118
<Filename Value="units\untDX7Voice.pas"/>
119119
<EditorIndex Value="5"/>
120-
<TopLine Value="862"/>
121-
<CursorPos X="38" Y="865"/>
120+
<TopLine Value="759"/>
121+
<CursorPos X="36" Y="779"/>
122122
<UsageCount Value="43"/>
123123
<Loaded Value="True"/>
124124
</Unit>
@@ -255,10 +255,6 @@
255255
<Filename Value="untDXObjInterface.pas"/>
256256
<Caret Line="29" Column="19"/>
257257
</Position>
258-
<Position>
259-
<Filename Value="untDXObjInterface.pas"/>
260-
<Caret Line="143" Column="15" TopLine="158"/>
261-
</Position>
262258
<Position>
263259
<Filename Value="untDXObjInterface.pas"/>
264260
<Caret Line="190" Column="52" TopLine="159"/>
@@ -303,6 +299,10 @@
303299
<Filename Value="untDXObjInterface.pas"/>
304300
<Caret Line="131" Column="5" TopLine="111"/>
305301
</Position>
302+
<Position>
303+
<Filename Value="MDX_Hash_Test.lpr"/>
304+
<Caret Line="92" Column="24"/>
305+
</Position>
306306
</JumpHistory>
307307
<RunParams>
308308
<FormatVersion Value="2"/>

MDX_Tool.lpr

+14-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
uses
2020
{$IFDEF UNIX}
2121
cthreads,
22-
{$ENDIF}
22+
{$ENDIF}
2323
Classes,
2424
SysUtils,
2525
CustApp,
@@ -54,12 +54,14 @@ TMDX_Tool = class(TCustomApplication)
5454
iDmpPos: integer;
5555
bNullVoice: boolean;
5656
iErrCode: integer;
57+
bOverwrite: boolean;
5758
begin
5859
bNullVoice := False;
5960
fInput := '';
61+
bOverwrite := False;
6062
// quick check parameters
61-
ErrorMsg := CheckOptions('himnzywrvcsxjqf:d:',
62-
'help info hname vname normalize markcorr marknull repair voices crop split xsplit join quest file: dir:');
63+
ErrorMsg := CheckOptions('hiomnzywrvcsxjqf:d:',
64+
'help info overwrite hname vname normalize markcorr marknull repair voices crop split xsplit join quest file: dir:');
6365

6466
if ErrorMsg <> '' then
6567
begin
@@ -79,6 +81,9 @@ TMDX_Tool = class(TCustomApplication)
7981
if HasOption('f', 'file') then
8082
fInput := GetOptionValue('f', 'file');
8183

84+
if HasOption('o', 'overwrite') then
85+
bOverwrite := True;
86+
8287
if HasOption('r', 'repair') then
8388
begin
8489
if not FileExists(fInput) then
@@ -93,13 +98,13 @@ TMDX_Tool = class(TCustomApplication)
9398
WriteLn('Repairing file ' + ExtractFileName(fInput));
9499
if trim(ExtractFileDir(fInput)) = '' then
95100
fInput := IncludeTrailingPathDelimiter(GetCurrentDir) + fInput;
96-
if RepairDX7SysEx(fInput, slReport) then
101+
if RepairDX7SysEx(fInput, slReport, bOverwrite) then
97102
begin
98103
for i := 0 to slReport.Count - 1 do
99104
WriteLn(slReport[i]);
100105
end
101106
else
102-
if MultiVCED2VMEM(fInput, slReport) then
107+
if MultiVCED2VMEM(fInput, slReport, bOverwrite) then
103108
begin
104109
for i := 0 to slReport.Count - 1 do
105110
WriteLn(slReport[i]);
@@ -298,7 +303,7 @@ TMDX_Tool = class(TCustomApplication)
298303
end
299304
else
300305
begin
301-
NormalizeVMEM(msInputFile, iDmpPos, fInput);
306+
NormalizeVMEM(msInputFile, iDmpPos, fInput, bOverwrite);
302307
WriteLn('VMEM data integrity is normalized');
303308
end;
304309
end;
@@ -311,7 +316,7 @@ TMDX_Tool = class(TCustomApplication)
311316
end
312317
else
313318
begin
314-
NormalizeVCED(msInputFile, iDmpPos, fInput);
319+
NormalizeVCED(msInputFile, iDmpPos, fInput, bOverwrite);
315320
WriteLn('VCED data integrity is normalized');
316321
end;
317322
end;
@@ -583,6 +588,8 @@ TMDX_Tool = class(TCustomApplication)
583588
writeln(' If it does not contain a drive letter, a sub-directory in');
584589
writeln(' the current directory will be created.');
585590
writeLn('');
591+
writeln(' -o --overwrite Overwrite source file at repairing or normalizing');
592+
writeLn('');
586593
writeln(' Example usage:');
587594
writeln(' MDX_Tool -i -f my_dx_file.syx');
588595
writeln(' MDX_Tool -r -f my_dx_file.syx');

MDX_Tool.lps

+43-43
Original file line numberDiff line numberDiff line change
@@ -68,36 +68,36 @@
6868
<Unit>
6969
<Filename Value="MDX_Tool.lpr"/>
7070
<IsPartOfProject Value="True"/>
71-
<IsVisibleTab Value="True"/>
72-
<TopLine Value="72"/>
73-
<CursorPos X="33" Y="105"/>
74-
<UsageCount Value="145"/>
71+
<TopLine Value="567"/>
72+
<CursorPos X="108" Y="591"/>
73+
<UsageCount Value="146"/>
7574
<Loaded Value="True"/>
7675
</Unit>
7776
<Unit>
7877
<Filename Value="untDXObjInterface.pas"/>
7978
<IsPartOfProject Value="True"/>
79+
<IsVisibleTab Value="True"/>
8080
<EditorIndex Value="4"/>
81-
<TopLine Value="860"/>
82-
<CursorPos X="84" Y="896"/>
83-
<UsageCount Value="113"/>
81+
<TopLine Value="694"/>
82+
<CursorPos X="36" Y="732"/>
83+
<UsageCount Value="114"/>
8484
<Loaded Value="True"/>
8585
</Unit>
8686
<Unit>
8787
<Filename Value="units\untUtils.pas"/>
8888
<IsPartOfProject Value="True"/>
8989
<EditorIndex Value="2"/>
9090
<CursorPos Y="225"/>
91-
<UsageCount Value="107"/>
91+
<UsageCount Value="108"/>
9292
<Loaded Value="True"/>
9393
</Unit>
9494
<Unit>
9595
<Filename Value="units\untDXUtils.pas"/>
9696
<IsPartOfProject Value="True"/>
9797
<EditorIndex Value="1"/>
98-
<TopLine Value="502"/>
99-
<CursorPos X="5" Y="532"/>
100-
<UsageCount Value="105"/>
98+
<TopLine Value="426"/>
99+
<CursorPos X="52" Y="474"/>
100+
<UsageCount Value="106"/>
101101
<Loaded Value="True"/>
102102
</Unit>
103103
<Unit>
@@ -183,38 +183,6 @@
183183
</Unit>
184184
</Units>
185185
<JumpHistory HistoryIndex="29">
186-
<Position>
187-
<Filename Value="units\untDXUtils.pas"/>
188-
<Caret Line="137" TopLine="112"/>
189-
</Position>
190-
<Position>
191-
<Filename Value="units\untDXUtils.pas"/>
192-
<Caret Line="138" TopLine="112"/>
193-
</Position>
194-
<Position>
195-
<Filename Value="units\untDXUtils.pas"/>
196-
<Caret Line="135" TopLine="112"/>
197-
</Position>
198-
<Position>
199-
<Filename Value="units\untDXUtils.pas"/>
200-
<Caret Line="137" TopLine="112"/>
201-
</Position>
202-
<Position>
203-
<Filename Value="units\untDXUtils.pas"/>
204-
<Caret Line="138" TopLine="112"/>
205-
</Position>
206-
<Position>
207-
<Filename Value="units\untDXUtils.pas"/>
208-
<Caret Line="135" TopLine="112"/>
209-
</Position>
210-
<Position>
211-
<Filename Value="units\untDXUtils.pas"/>
212-
<Caret Line="137" TopLine="112"/>
213-
</Position>
214-
<Position>
215-
<Filename Value="units\untDXUtils.pas"/>
216-
<Caret Line="138" TopLine="112"/>
217-
</Position>
218186
<Position>
219187
<Filename Value="units\untDXUtils.pas"/>
220188
<Caret Line="140" TopLine="114"/>
@@ -303,6 +271,38 @@
303271
<Filename Value="untDXObjInterface.pas"/>
304272
<Caret Line="883" Column="17" TopLine="857"/>
305273
</Position>
274+
<Position>
275+
<Filename Value="units\untDXUtils.pas"/>
276+
<Caret Line="104" Column="18" TopLine="83"/>
277+
</Position>
278+
<Position>
279+
<Filename Value="units\untDXUtils.pas"/>
280+
<Caret Line="329" Column="41" TopLine="306"/>
281+
</Position>
282+
<Position>
283+
<Filename Value="units\untDXUtils.pas"/>
284+
<Caret Line="345" Column="45" TopLine="311"/>
285+
</Position>
286+
<Position>
287+
<Filename Value="units\untDXUtils.pas"/>
288+
<Caret Line="347" Column="72" TopLine="313"/>
289+
</Position>
290+
<Position>
291+
<Filename Value="units\untDXUtils.pas"/>
292+
<Caret Line="352" Column="36" TopLine="318"/>
293+
</Position>
294+
<Position>
295+
<Filename Value="untDXObjInterface.pas"/>
296+
<Caret Line="870" TopLine="840"/>
297+
</Position>
298+
<Position>
299+
<Filename Value="untDXObjInterface.pas"/>
300+
<Caret Line="40" Column="18" TopLine="19"/>
301+
</Position>
302+
<Position>
303+
<Filename Value="untDXObjInterface.pas"/>
304+
<Caret Line="38" Column="19" TopLine="8"/>
305+
</Position>
306306
</JumpHistory>
307307
<RunParams>
308308
<FormatVersion Value="2"/>

units/untDXUtils.pas

+11-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ function ContainsDX7VoiceDump(dmp: TMemoryStream;
101101
var StartPos, StartDmp: integer): boolean;
102102
function ContainsDX7BankDump(dmp: TMemoryStream;
103103
var StartPos, StartDmp: integer): boolean;
104-
function RepairDX7SysEx(aFileName: string; const Report: TStrings): boolean;
104+
function RepairDX7SysEx(aFileName: string; const Report: TStrings;
105+
aOverwrite: boolean = False): boolean;
105106
function CropHeaders(aFileName: string): boolean;
106107
function CheckSum(dmp: TMemoryStream; StartPos, DumpLen: integer): boolean;
107108

@@ -323,7 +324,8 @@ function ContainsDX7BankDump(dmp: TMemoryStream;
323324
end;
324325
end;
325326

326-
function RepairDX7SysEx(aFileName: string; const Report: TStrings): boolean;
327+
function RepairDX7SysEx(aFileName: string; const Report: TStrings;
328+
aOverwrite: boolean = False): boolean;
327329
var
328330
sDirRepaired: string;
329331
sNameRepaired: string;
@@ -441,7 +443,9 @@ function RepairDX7SysEx(aFileName: string; const Report: TStrings): boolean;
441443
iCalcChk := ((not (iCalcChk and 255)) and 127) + 1;
442444
msRepaired.WriteByte(iCalcChk);
443445
msRepaired.WriteByte($F7);
444-
sNameRepaired := sDirRepaired + sNameRepaired + '_DX7_repaired.syx';
446+
if aOverwrite then sNameRepaired := aFileName
447+
else
448+
sNameRepaired := sDirRepaired + sNameRepaired + '_DX7_repaired.syx';
445449
msRepaired.SaveToFile(sNameRepaired);
446450
Report.Add('File is just 4096 bytes long. Writting headers.');
447451
Result := True;
@@ -467,8 +471,10 @@ function RepairDX7SysEx(aFileName: string; const Report: TStrings): boolean;
467471
iCalcChk := ((not (iCalcChk and 255)) and 127) + 1;
468472
msRepaired.WriteByte(iCalcChk);
469473
msRepaired.WriteByte($F7);
470-
sNameRepaired := sDirRepaired + sNameRepaired + '_' +
471-
IntToStr(iDumpStart) + '_DX7_repaired.syx';
474+
if aOverwrite then sNameRepaired := aFileName
475+
else
476+
sNameRepaired := sDirRepaired + sNameRepaired + '_' +
477+
IntToStr(iDumpStart) + '_DX7_repaired.syx';
472478
msRepaired.SaveToFile(sNameRepaired);
473479
Result := True;
474480
end;

untDXObjInterface.pas

+31-15
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ function CheckVMEMIntegrity(aStream: TMemoryStream; aPos: integer;
3535
var aNullVoice: boolean): integer;
3636
function CheckVCEDIntegrity(aStream: TMemoryStream; aPos: integer;
3737
var aNullVoice: boolean): integer;
38-
procedure NormalizeVMEM(aStream: TMemoryStream; aPos: integer; aFile: string);
39-
procedure NormalizeVCED(aStream: TMemoryStream; aPos: integer; aFile: string);
40-
function MultiVCED2VMEM(aFileName: string; const Report: TStrings): boolean;
38+
procedure NormalizeVMEM(aStream: TMemoryStream; aPos: integer;
39+
aFile: string; aOverwrite: boolean = False);
40+
procedure NormalizeVCED(aStream: TMemoryStream; aPos: integer;
41+
aFile: string; aOverwrite: boolean = False);
42+
function MultiVCED2VMEM(aFileName: string; const Report: TStrings;
43+
aOverwrite: boolean = False): boolean;
4144

4245
implementation
4346

@@ -674,18 +677,23 @@ function CheckVCEDIntegrity(aStream: TMemoryStream; aPos: integer;
674677
slReport.Free;
675678
end;
676679

677-
procedure NormalizeVMEM(aStream: TMemoryStream; aPos: integer; aFile: string);
680+
procedure NormalizeVMEM(aStream: TMemoryStream; aPos: integer;
681+
aFile: string; aOverwrite: boolean = False);
678682
var
679683
fBank: TDX7BankContainer;
680684
fVoice: TDX7VoiceContainer;
681685
sOutName: string;
682686
msOutFile: TMemoryStream;
683687
i: integer;
684688
begin
685-
sOutName := ExtractFileName(aFile);
686-
sOutName := ExtractFileNameWithoutExt(sOutName);
687-
sOutName := IncludeTrailingPathDelimiter(ExtractFileDir(aFile)) +
688-
sOutName + '.normalized.syx';
689+
if aOverwrite then sOutName := aFile
690+
else
691+
begin
692+
sOutName := ExtractFileName(aFile);
693+
sOutName := ExtractFileNameWithoutExt(sOutName);
694+
sOutName := IncludeTrailingPathDelimiter(ExtractFileDir(aFile)) +
695+
sOutName + '.normalized.syx';
696+
end;
689697

690698
msOutFile := TMemoryStream.Create;
691699

@@ -708,16 +716,21 @@ procedure NormalizeVMEM(aStream: TMemoryStream; aPos: integer; aFile: string);
708716
fVoice.Free;
709717
end;
710718

711-
procedure NormalizeVCED(aStream: TMemoryStream; aPos: integer; aFile: string);
719+
procedure NormalizeVCED(aStream: TMemoryStream; aPos: integer;
720+
aFile: string; aOverwrite: boolean = False);
712721
var
713722
fVoice: TDX7VoiceContainer;
714723
sOutName: string;
715724
msOutFile: TMemoryStream;
716725
begin
717-
sOutName := ExtractFileName(aFile);
718-
sOutName := ExtractFileNameWithoutExt(sOutName);
719-
sOutName := IncludeTrailingPathDelimiter(ExtractFileDir(aFile)) +
720-
sOutName + '.normalized.syx';
726+
if aOverwrite then sOutName := aFile
727+
else
728+
begin
729+
sOutName := ExtractFileName(aFile);
730+
sOutName := ExtractFileNameWithoutExt(sOutName);
731+
sOutName := IncludeTrailingPathDelimiter(ExtractFileDir(aFile)) +
732+
sOutName + '.normalized.syx';
733+
end;
721734

722735
msOutFile := TMemoryStream.Create;
723736

@@ -867,7 +880,8 @@ function Test_VMEMHash(aFile: string; aVoiceNr: integer = 1): string;
867880
fStream.Free;
868881
end;
869882

870-
function MultiVCED2VMEM(aFileName: string; const Report: TStrings): boolean;
883+
function MultiVCED2VMEM(aFileName: string; const Report: TStrings;
884+
aOverwrite: boolean = False): boolean;
871885
var
872886
fBank: TDX7BankContainer;
873887
fVoice: TDX7VoiceContainer;
@@ -893,7 +907,9 @@ function MultiVCED2VMEM(aFileName: string; const Report: TStrings): boolean;
893907
Inc(iVoiceNr);
894908
end;
895909
Result := True;
896-
fBank.SaveBankToSysExFile(ExtractFileNameWithoutExt(aFileName) + '.vmem.syx');
910+
if not aOverwrite then
911+
aFileName := ExtractFileNameWithoutExt(aFileName) + '.vmem.syx';
912+
fBank.SaveBankToSysExFile(aFileName);
897913
end
898914
else
899915
Report.Add('Not a Multi-VCED');

0 commit comments

Comments
 (0)