Skip to content

Commit

Permalink
Implementing -o --overwrite parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
BobanSpasic committed May 4, 2023
1 parent 82e9ced commit d4c5339
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 77 deletions.
14 changes: 7 additions & 7 deletions MDX_Hash_Test.lps
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@
<Unit>
<Filename Value="MDX_Hash_Test.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<CursorPos X="24" Y="92"/>
<UsageCount Value="129"/>
<Loaded Value="True"/>
</Unit>
<Unit>
<Filename Value="untDXObjInterface.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="4"/>
<TopLine Value="708"/>
<CursorPos X="29" Y="727"/>
Expand Down Expand Up @@ -117,8 +117,8 @@
<Unit>
<Filename Value="units\untDX7Voice.pas"/>
<EditorIndex Value="5"/>
<TopLine Value="862"/>
<CursorPos X="38" Y="865"/>
<TopLine Value="759"/>
<CursorPos X="36" Y="779"/>
<UsageCount Value="43"/>
<Loaded Value="True"/>
</Unit>
Expand Down Expand Up @@ -255,10 +255,6 @@
<Filename Value="untDXObjInterface.pas"/>
<Caret Line="29" Column="19"/>
</Position>
<Position>
<Filename Value="untDXObjInterface.pas"/>
<Caret Line="143" Column="15" TopLine="158"/>
</Position>
<Position>
<Filename Value="untDXObjInterface.pas"/>
<Caret Line="190" Column="52" TopLine="159"/>
Expand Down Expand Up @@ -303,6 +299,10 @@
<Filename Value="untDXObjInterface.pas"/>
<Caret Line="131" Column="5" TopLine="111"/>
</Position>
<Position>
<Filename Value="MDX_Hash_Test.lpr"/>
<Caret Line="92" Column="24"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
Expand Down
21 changes: 14 additions & 7 deletions MDX_Tool.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
{$ENDIF}
Classes,
SysUtils,
CustApp,
Expand Down Expand Up @@ -54,12 +54,14 @@ TMDX_Tool = class(TCustomApplication)
iDmpPos: integer;
bNullVoice: boolean;
iErrCode: integer;
bOverwrite: boolean;
begin
bNullVoice := False;
fInput := '';
bOverwrite := False;
// quick check parameters
ErrorMsg := CheckOptions('himnzywrvcsxjqf:d:',
'help info hname vname normalize markcorr marknull repair voices crop split xsplit join quest file: dir:');
ErrorMsg := CheckOptions('hiomnzywrvcsxjqf:d:',
'help info overwrite hname vname normalize markcorr marknull repair voices crop split xsplit join quest file: dir:');

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

if HasOption('o', 'overwrite') then
bOverwrite := True;

if HasOption('r', 'repair') then
begin
if not FileExists(fInput) then
Expand All @@ -93,13 +98,13 @@ TMDX_Tool = class(TCustomApplication)
WriteLn('Repairing file ' + ExtractFileName(fInput));
if trim(ExtractFileDir(fInput)) = '' then
fInput := IncludeTrailingPathDelimiter(GetCurrentDir) + fInput;
if RepairDX7SysEx(fInput, slReport) then
if RepairDX7SysEx(fInput, slReport, bOverwrite) then
begin
for i := 0 to slReport.Count - 1 do
WriteLn(slReport[i]);
end
else
if MultiVCED2VMEM(fInput, slReport) then
if MultiVCED2VMEM(fInput, slReport, bOverwrite) then
begin
for i := 0 to slReport.Count - 1 do
WriteLn(slReport[i]);
Expand Down Expand Up @@ -298,7 +303,7 @@ TMDX_Tool = class(TCustomApplication)
end
else
begin
NormalizeVMEM(msInputFile, iDmpPos, fInput);
NormalizeVMEM(msInputFile, iDmpPos, fInput, bOverwrite);
WriteLn('VMEM data integrity is normalized');
end;
end;
Expand All @@ -311,7 +316,7 @@ TMDX_Tool = class(TCustomApplication)
end
else
begin
NormalizeVCED(msInputFile, iDmpPos, fInput);
NormalizeVCED(msInputFile, iDmpPos, fInput, bOverwrite);
WriteLn('VCED data integrity is normalized');
end;
end;
Expand Down Expand Up @@ -583,6 +588,8 @@ TMDX_Tool = class(TCustomApplication)
writeln(' If it does not contain a drive letter, a sub-directory in');
writeln(' the current directory will be created.');
writeLn('');
writeln(' -o --overwrite Overwrite source file at repairing or normalizing');
writeLn('');
writeln(' Example usage:');
writeln(' MDX_Tool -i -f my_dx_file.syx');
writeln(' MDX_Tool -r -f my_dx_file.syx');
Expand Down
86 changes: 43 additions & 43 deletions MDX_Tool.lps
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,36 @@
<Unit>
<Filename Value="MDX_Tool.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="72"/>
<CursorPos X="33" Y="105"/>
<UsageCount Value="145"/>
<TopLine Value="567"/>
<CursorPos X="108" Y="591"/>
<UsageCount Value="146"/>
<Loaded Value="True"/>
</Unit>
<Unit>
<Filename Value="untDXObjInterface.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="4"/>
<TopLine Value="860"/>
<CursorPos X="84" Y="896"/>
<UsageCount Value="113"/>
<TopLine Value="694"/>
<CursorPos X="36" Y="732"/>
<UsageCount Value="114"/>
<Loaded Value="True"/>
</Unit>
<Unit>
<Filename Value="units\untUtils.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="2"/>
<CursorPos Y="225"/>
<UsageCount Value="107"/>
<UsageCount Value="108"/>
<Loaded Value="True"/>
</Unit>
<Unit>
<Filename Value="units\untDXUtils.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="502"/>
<CursorPos X="5" Y="532"/>
<UsageCount Value="105"/>
<TopLine Value="426"/>
<CursorPos X="52" Y="474"/>
<UsageCount Value="106"/>
<Loaded Value="True"/>
</Unit>
<Unit>
Expand Down Expand Up @@ -183,38 +183,6 @@
</Unit>
</Units>
<JumpHistory HistoryIndex="29">
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="137" TopLine="112"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="138" TopLine="112"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="135" TopLine="112"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="137" TopLine="112"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="138" TopLine="112"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="135" TopLine="112"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="137" TopLine="112"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="138" TopLine="112"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="140" TopLine="114"/>
Expand Down Expand Up @@ -303,6 +271,38 @@
<Filename Value="untDXObjInterface.pas"/>
<Caret Line="883" Column="17" TopLine="857"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="104" Column="18" TopLine="83"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="329" Column="41" TopLine="306"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="345" Column="45" TopLine="311"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="347" Column="72" TopLine="313"/>
</Position>
<Position>
<Filename Value="units\untDXUtils.pas"/>
<Caret Line="352" Column="36" TopLine="318"/>
</Position>
<Position>
<Filename Value="untDXObjInterface.pas"/>
<Caret Line="870" TopLine="840"/>
</Position>
<Position>
<Filename Value="untDXObjInterface.pas"/>
<Caret Line="40" Column="18" TopLine="19"/>
</Position>
<Position>
<Filename Value="untDXObjInterface.pas"/>
<Caret Line="38" Column="19" TopLine="8"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
Expand Down
16 changes: 11 additions & 5 deletions units/untDXUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ function ContainsDX7VoiceDump(dmp: TMemoryStream;
var StartPos, StartDmp: integer): boolean;
function ContainsDX7BankDump(dmp: TMemoryStream;
var StartPos, StartDmp: integer): boolean;
function RepairDX7SysEx(aFileName: string; const Report: TStrings): boolean;
function RepairDX7SysEx(aFileName: string; const Report: TStrings;
aOverwrite: boolean = False): boolean;
function CropHeaders(aFileName: string): boolean;
function CheckSum(dmp: TMemoryStream; StartPos, DumpLen: integer): boolean;

Expand Down Expand Up @@ -323,7 +324,8 @@ function ContainsDX7BankDump(dmp: TMemoryStream;
end;
end;

function RepairDX7SysEx(aFileName: string; const Report: TStrings): boolean;
function RepairDX7SysEx(aFileName: string; const Report: TStrings;
aOverwrite: boolean = False): boolean;
var
sDirRepaired: string;
sNameRepaired: string;
Expand Down Expand Up @@ -441,7 +443,9 @@ function RepairDX7SysEx(aFileName: string; const Report: TStrings): boolean;
iCalcChk := ((not (iCalcChk and 255)) and 127) + 1;
msRepaired.WriteByte(iCalcChk);
msRepaired.WriteByte($F7);
sNameRepaired := sDirRepaired + sNameRepaired + '_DX7_repaired.syx';
if aOverwrite then sNameRepaired := aFileName
else
sNameRepaired := sDirRepaired + sNameRepaired + '_DX7_repaired.syx';
msRepaired.SaveToFile(sNameRepaired);
Report.Add('File is just 4096 bytes long. Writting headers.');
Result := True;
Expand All @@ -467,8 +471,10 @@ function RepairDX7SysEx(aFileName: string; const Report: TStrings): boolean;
iCalcChk := ((not (iCalcChk and 255)) and 127) + 1;
msRepaired.WriteByte(iCalcChk);
msRepaired.WriteByte($F7);
sNameRepaired := sDirRepaired + sNameRepaired + '_' +
IntToStr(iDumpStart) + '_DX7_repaired.syx';
if aOverwrite then sNameRepaired := aFileName
else
sNameRepaired := sDirRepaired + sNameRepaired + '_' +
IntToStr(iDumpStart) + '_DX7_repaired.syx';
msRepaired.SaveToFile(sNameRepaired);
Result := True;
end;
Expand Down
46 changes: 31 additions & 15 deletions untDXObjInterface.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ function CheckVMEMIntegrity(aStream: TMemoryStream; aPos: integer;
var aNullVoice: boolean): integer;
function CheckVCEDIntegrity(aStream: TMemoryStream; aPos: integer;
var aNullVoice: boolean): integer;
procedure NormalizeVMEM(aStream: TMemoryStream; aPos: integer; aFile: string);
procedure NormalizeVCED(aStream: TMemoryStream; aPos: integer; aFile: string);
function MultiVCED2VMEM(aFileName: string; const Report: TStrings): boolean;
procedure NormalizeVMEM(aStream: TMemoryStream; aPos: integer;
aFile: string; aOverwrite: boolean = False);
procedure NormalizeVCED(aStream: TMemoryStream; aPos: integer;
aFile: string; aOverwrite: boolean = False);
function MultiVCED2VMEM(aFileName: string; const Report: TStrings;
aOverwrite: boolean = False): boolean;

implementation

Expand Down Expand Up @@ -674,18 +677,23 @@ function CheckVCEDIntegrity(aStream: TMemoryStream; aPos: integer;
slReport.Free;
end;

procedure NormalizeVMEM(aStream: TMemoryStream; aPos: integer; aFile: string);
procedure NormalizeVMEM(aStream: TMemoryStream; aPos: integer;
aFile: string; aOverwrite: boolean = False);
var
fBank: TDX7BankContainer;
fVoice: TDX7VoiceContainer;
sOutName: string;
msOutFile: TMemoryStream;
i: integer;
begin
sOutName := ExtractFileName(aFile);
sOutName := ExtractFileNameWithoutExt(sOutName);
sOutName := IncludeTrailingPathDelimiter(ExtractFileDir(aFile)) +
sOutName + '.normalized.syx';
if aOverwrite then sOutName := aFile
else
begin
sOutName := ExtractFileName(aFile);
sOutName := ExtractFileNameWithoutExt(sOutName);
sOutName := IncludeTrailingPathDelimiter(ExtractFileDir(aFile)) +
sOutName + '.normalized.syx';
end;

msOutFile := TMemoryStream.Create;

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

procedure NormalizeVCED(aStream: TMemoryStream; aPos: integer; aFile: string);
procedure NormalizeVCED(aStream: TMemoryStream; aPos: integer;
aFile: string; aOverwrite: boolean = False);
var
fVoice: TDX7VoiceContainer;
sOutName: string;
msOutFile: TMemoryStream;
begin
sOutName := ExtractFileName(aFile);
sOutName := ExtractFileNameWithoutExt(sOutName);
sOutName := IncludeTrailingPathDelimiter(ExtractFileDir(aFile)) +
sOutName + '.normalized.syx';
if aOverwrite then sOutName := aFile
else
begin
sOutName := ExtractFileName(aFile);
sOutName := ExtractFileNameWithoutExt(sOutName);
sOutName := IncludeTrailingPathDelimiter(ExtractFileDir(aFile)) +
sOutName + '.normalized.syx';
end;

msOutFile := TMemoryStream.Create;

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

function MultiVCED2VMEM(aFileName: string; const Report: TStrings): boolean;
function MultiVCED2VMEM(aFileName: string; const Report: TStrings;
aOverwrite: boolean = False): boolean;
var
fBank: TDX7BankContainer;
fVoice: TDX7VoiceContainer;
Expand All @@ -893,7 +907,9 @@ function MultiVCED2VMEM(aFileName: string; const Report: TStrings): boolean;
Inc(iVoiceNr);
end;
Result := True;
fBank.SaveBankToSysExFile(ExtractFileNameWithoutExt(aFileName) + '.vmem.syx');
if not aOverwrite then
aFileName := ExtractFileNameWithoutExt(aFileName) + '.vmem.syx';
fBank.SaveBankToSysExFile(aFileName);
end
else
Report.Add('Not a Multi-VCED');
Expand Down

0 comments on commit d4c5339

Please sign in to comment.