Skip to content

Commit

Permalink
Saving VCED - wrong checksum
Browse files Browse the repository at this point in the history
Filtering the DB StringGrid sometimes triggered OnClick event with a wrong row index
  • Loading branch information
BobanSpasic committed Jan 27, 2023
1 parent 81f8528 commit 8675f22
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 54 deletions.
3 changes: 2 additions & 1 deletion src/prMiniDexedCC.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<UseVersionInfo Value="True"/>
<AutoIncrementBuild Value="True"/>
<MajorVersionNr Value="1"/>
<BuildNr Value="37"/>
<RevisionNr Value="1"/>
<BuildNr Value="41"/>
<StringTable FileDescription="MiniDexed Control Center" LegalCopyright="Boban Spasic" OriginalFilename="MiniDexedCC.exe"/>
</VersionInfo>
<BuildModes>
Expand Down
Binary file modified src/prMiniDexedCC.res
Binary file not shown.
28 changes: 14 additions & 14 deletions src/untMain.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ object frmMain: TfrmMain
Hint = 'Drag&Drop to re-arrange'#13#10'Double-click for sending to Librarian tab'
Top = 0
Width = 1510
ActivePage = tsSDCard
ActivePage = tsLibrarian
Align = alClient
TabIndex = 2
TabIndex = 0
TabOrder = 1
object tsLibrarian: TTabSheet
Caption = 'Librarian'
Expand All @@ -69,9 +69,9 @@ object frmMain: TfrmMain
Height = 835
Top = 0
Width = 680
ActivePage = tsDatabase
ActivePage = tsFiles
Align = alClient
TabIndex = 1
TabIndex = 0
TabOrder = 0
object tsFiles: TTabSheet
Caption = 'Files'
Expand Down Expand Up @@ -205,16 +205,16 @@ object frmMain: TfrmMain
Columns = <
item
Title.Caption = 'Voice'
Width = 200
Width = 206
end
item
ButtonStyle = cbsPickList
Title.Caption = 'Category'
Width = 200
Width = 206
end
item
Title.Caption = 'Origin'
Width = 200
Width = 206
end
item
ReadOnly = True
Expand All @@ -239,9 +239,9 @@ object frmMain: TfrmMain
OnEditingDone = sgDBEditingDone
OnStartDrag = sgDBStartDrag
ColWidths = (
200
200
200
206
206
206
0
50
)
Expand Down Expand Up @@ -13605,7 +13605,7 @@ object frmMain: TfrmMain
item
ReadOnly = True
Title.Caption = 'Title'
Width = 100
Width = 91
end
item
Alignment = taRightJustify
Expand Down Expand Up @@ -13640,7 +13640,7 @@ object frmMain: TfrmMain
Alignment = taRightJustify
ReadOnly = True
Title.Caption = 'Title'
Width = 100
Width = 92
end>
FixedCols = 0
FixedRows = 0
Expand All @@ -13654,12 +13654,12 @@ object frmMain: TfrmMain
TabOrder = 7
OnDrawCell = sgGPIODrawCell
ColWidths = (
100
91
54
20
20
54
100
92
)
Cells = (
40
Expand Down
90 changes: 52 additions & 38 deletions src/untMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,8 @@ function TfrmMain.SanitizeNames(tmp: string): string;
if UTF8pos(UTF8copy(tmp, 1, 1), ('*°/\<>^?~#+-!$%&()[]`.,')) > 0 then
tmp := UTF8copy(tmp, 2, UTF8Length(tmp) - 1);
if cgSanitize.Checked[2] then
if UTF8pos(UTF8copy(tmp, UTF8Length(tmp), 1), ('*°/\<>^?~#+-!$%&()[]`.,')) > 0 then
if UTF8pos(UTF8copy(tmp, UTF8Length(tmp), 1),
('*°/\<>^?~#+-!$%&()[]`.,')) > 0 then
tmp := UTF8copy(tmp, 1, UTF8Length(tmp) - 1);
if cgSanitize.Checked[3] then
begin
Expand Down Expand Up @@ -1903,15 +1904,23 @@ procedure TfrmMain.FormCreate(Sender: TObject);
begin
FMidiIn := cbMidiIn.Text;
FMidiInInt := cbMidiIn.ItemIndex;
MidiInput.Open(FMidiInInt);
try
MidiInput.Open(FMidiInInt);
except
on e: Exception do PopUp('Could not open' + #13#10 + 'MIDI Input', 2);
end;
FMidiIsActive := True;
end;
cbMidiOut.ItemIndex := cbMidiOut.Items.IndexOf(ini.ReadString('MIDIOutput', ''));
if cbMidiOut.ItemIndex <> -1 then
begin
FMidiOut := cbMidiOut.Text;
FMidiOutInt := cbMidiOut.ItemIndex;
MidiOutput.Open(FMidiOutInt);
try
MidiOutput.Open(FMidiOutInt);
except
on e: Exception do PopUp('Could not open' + #13#10 + 'MIDI Output', 2);
end;
FMidiIsActive := True;
end;
LastSysExOpenDir := ini.ReadString('LastSysExOpenDir', '');
Expand Down Expand Up @@ -2197,53 +2206,56 @@ procedure TfrmMain.OpenSysEx(aName: string);
FTmpCCBank.CSetVoice(1, dxv);
lbVoices.Items.Add(FTmpCCBank.CGetVoiceName(1));
dxv.Free;
end;

i := 0; //read from the begining of the stream again
if ContainsDX7BankDump(dmp, i, j) then
begin
lbVoices.Items.Clear;
FTmpCCBank.CLoadVoiceBankFromStream(dmp, j);
for nr := 1 to 32 do
begin
lbVoices.Items.Add(FTmpCCBank.CGetVoiceName(nr));
end;
//k := dmp.Position;
k := 0; // got files where AMEM comes before VMEM
i := k;
if ContainsDX7IISupplBankDump(dmp, i, j) then
FTmpCCBank.CLoadSupplBankFromStream(dmp, j)
else
FTmpCCBank.CInitSuppl;
//i := k;
i := 0; // if PMEM is before VMEM in file
if ContainsTX7FunctBankDump(dmp, i, j) then
FTmpCCBank.CLoadFunctBankFromStream(dmp, j)
else
FTmpCCBank.CInitFunct;
end
else
begin
mmLog.Lines.Add('Not a valid DX SysEx');
feedback := '';
if RepairDX7SysEx(aName, feedback) then

i := 0; //read from the begining of the stream again
if ContainsDX7BankDump(dmp, i, j) then
begin
FillFilesList(edbtSelSysExDir.Text);
mmLog.Lines.Add(feedback);
mmLog.Lines.Add('Reparation: It is maybe a DX7 VMEM file');
Inc(lastClickedFile);
lbVoices.Items.Clear;
FTmpCCBank.CLoadVoiceBankFromStream(dmp, j);
for nr := 1 to 32 do
begin
lbVoices.Items.Add(FTmpCCBank.CGetVoiceName(nr));
end;
//k := dmp.Position;
k := 0; // got files where AMEM comes before VMEM
i := k;
if ContainsDX7IISupplBankDump(dmp, i, j) then
FTmpCCBank.CLoadSupplBankFromStream(dmp, j)
else
FTmpCCBank.CInitSuppl;
//i := k;
i := 0; // if PMEM is before VMEM in file
if ContainsTX7FunctBankDump(dmp, i, j) then
FTmpCCBank.CLoadFunctBankFromStream(dmp, j)
else
FTmpCCBank.CInitFunct;
end
else
begin
mmLog.Lines.Add(feedback);
mmLog.Lines.Add('Could not repair');
mmLog.Lines.Add('Not a valid DX7 Bank SysEx');
feedback := '';
if RepairDX7SysEx(aName, feedback) then
begin
FillFilesList(edbtSelSysExDir.Text);
mmLog.Lines.Add(feedback);
mmLog.Lines.Add('Reparation: It is maybe a DX7 VMEM file');
Inc(lastClickedFile);
end
else
begin
mmLog.Lines.Add(feedback);
mmLog.Lines.Add('Could not repair');
end;
end;
end;
end
else
begin
//mmLog.Lines.Clear;
mmLog.Lines.Add('Not a valid DX SysEx');
mmLog.Lines.Add('Not a valid DX7 SysEx');
feedback := '';
if RepairDX7SysEx(aName, feedback) then
begin
Expand Down Expand Up @@ -2833,7 +2845,9 @@ procedure TfrmMain.sgDBBeforeSelection(Sender: TObject; aCol, aRow: integer);
Unused(aCol);
for c := 0 to 3 do
begin
compArray[c] := sgDB.Cells[c, aRow];
if aRow < sgDB.RowCount then
//sometimes aRow is greater than the row count
compArray[c] := sgDB.Cells[c, aRow];
end;
end;

Expand Down
19 changes: 18 additions & 1 deletion units/untDX7Voice.pas
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ TDX7VoiceContainer = class(TPersistent)
function Add_VCED_ToStream(var aStream: TMemoryStream): boolean;
function GetChecksumPart: integer;
function GetChecksum: integer;
function GetVCEDChecksum: byte;
procedure SysExVoiceToStream(aCh: integer; var aStream: TMemoryStream);
function CalculateHash: string;
end;
Expand Down Expand Up @@ -895,6 +896,22 @@ function TDX7VoiceContainer.GetChecksum: integer;
end;
end;

function TDX7VoiceContainer.GetVCEDChecksum: byte;
var
checksum: integer;
i: integer;
tmpStream: TMemoryStream;
begin
checksum := 0;
tmpStream := TMemoryStream.Create;
Save_VCED_ToStream(tmpStream);
tmpStream.Position := 0;
for i := 0 to 154 do
checksum := checksum + tmpStream.ReadByte;
Result := ((not (checksum and 255)) and 127) + 1;
tmpStream.Free;
end;

procedure TDX7VoiceContainer.SysExVoiceToStream(aCh: integer; var aStream: TMemoryStream);
var
FCh: byte;
Expand All @@ -909,7 +926,7 @@ procedure TDX7VoiceContainer.SysExVoiceToStream(aCh: integer; var aStream: TMemo
aStream.WriteByte($01);
aStream.WriteByte($1B);
Add_VCED_ToStream(aStream);
aStream.WriteByte(GetChecksum);
aStream.WriteByte(GetVCEDChecksum);
aStream.WriteByte($F7);
end;

Expand Down

0 comments on commit 8675f22

Please sign in to comment.