aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code
diff options
context:
space:
mode:
authorbrunzelchen <brunzelchen@b956fd51-792f-4845-bead-9b4dfca2ff2c>2010-02-27 20:53:57 +0000
committerbrunzelchen <brunzelchen@b956fd51-792f-4845-bead-9b4dfca2ff2c>2010-02-27 20:53:57 +0000
commit16859ce865acb002696435dd8fb7b224fe4f4525 (patch)
tree8954347853739c67bf5cfaeb33e9e3d42c9e7d91 /Game/Code
parent0c62037cf72f7f12bf5f4563b36af7f81146e51a (diff)
downloadusdx-16859ce865acb002696435dd8fb7b224fe4f4525.tar.gz
usdx-16859ce865acb002696435dd8fb7b224fe4f4525.tar.xz
usdx-16859ce865acb002696435dd8fb7b224fe4f4525.zip
added check for corrupted song txts
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/1.0.1 Challenge MOD@2159 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code')
-rw-r--r--Game/Code/Classes/UFiles.pas104
-rw-r--r--Game/Code/Classes/USongs.pas2
2 files changed, 103 insertions, 3 deletions
diff --git a/Game/Code/Classes/UFiles.pas b/Game/Code/Classes/UFiles.pas
index 0d22fec5..666bbd88 100644
--- a/Game/Code/Classes/UFiles.pas
+++ b/Game/Code/Classes/UFiles.pas
@@ -21,6 +21,7 @@ procedure ResetSingTemp;
procedure ParseNote(NrCzesci: integer; TypeP: char; StartP, DurationP, NoteP: integer; LyricS: string);
procedure NewSentence(NrCzesciP: integer; Param1, Param2: integer; LoadFullFile: boolean);
function LoadSong(Name: string; LoadFullFile: boolean): boolean;
+function CheckSong: boolean;
function SaveSong(Song: TSong; Czesc: TCzesci; Name: string; Relative: boolean): boolean;
procedure FindRefrainStart(var Song: TSong);
procedure SetMedleyMode;
@@ -633,6 +634,104 @@ begin
Base[NrCzesciP] := 100; // high number
end;
+function CheckSong: boolean;
+var
+ p, line, note: integer;
+ numLines, numNotes: integer;
+ bt: integer;
+ nextBeat: integer;
+ foundMedleyStart: boolean;
+ foundMedleyEnd: boolean;
+ medley: boolean;
+
+begin
+ Result := false;
+ bt := -32000;
+
+ if(AktSong.Medley.Source = msTag) then
+ begin
+ medley := true;
+ foundMedleyStart := false;
+ foundMedleyEnd := false;
+ end else
+ medley := false;
+
+ for p := 0 to {Length(Czesci)}1 - 1 do //TODO: why doesn't it work?
+ begin
+ numLines := Length(Czesci[p].Czesc);
+
+ if(numLines=0) then
+ begin
+ Log.LogError('Song ' + AktSong.Path + AktSong.Filename + ' has no lines?');
+ Exit;
+ end;
+
+ for line := 0 to numLines - 1 do
+ begin
+ numNotes := Length(Czesci[p].Czesc[line].Nuta);
+
+ if(numNotes=0) then
+ begin
+ Log.LogError('Line ' + IntToStr(line+1) + ' in song ' + AktSong.Path + AktSong.Filename + ' has no notes?');
+ Exit;
+ end;
+
+ if(bt>Czesci[p].Czesc[line].Start) then
+ begin
+ Log.LogError('Beat error line ' + IntToStr(line+1) + ', beat ' + IntToStr(Czesci[p].Czesc[line].Start) +
+ ' in song ' + AktSong.Path + AktSong.Filename);
+ Exit;
+ end;
+ bt := Czesci[p].Czesc[line].Start;
+
+ for note := 0 to numNotes - 1 do
+ begin
+ if(bt>Czesci[p].Czesc[line].Nuta[note].Start) then
+ begin
+ Log.LogError('Beat error line ' + IntToStr(line+1) + ', beat ' + IntToStr(Czesci[p].Czesc[line].Nuta[note].Start) +
+ ' in song ' + AktSong.Path + AktSong.Filename);
+ Exit;
+ end;
+ bt := Czesci[p].Czesc[line].Nuta[note].Start;
+
+ if (note<numNotes-1) then
+ nextBeat := Czesci[p].Czesc[line].Nuta[note+1].Start
+ else if (line<numLines-1) then
+ nextBeat := Czesci[p].Czesc[line+1].Start
+ else
+ nextBeat := Czesci[p].Czesc[line].Koniec;
+
+ if (bt+Czesci[p].Czesc[line].Nuta[note].Dlugosc>nextBeat) then
+ begin
+ Log.LogError('Note length error line ' + IntToStr(line+1) + ', beat ' + IntToStr(Czesci[p].Czesc[line].Nuta[note].Start) +
+ ' in song ' + AktSong.Path + AktSong.Filename);
+ Exit;
+ end;
+
+ if(medley) then
+ begin
+ if(bt = AktSong.Medley.StartBeat) then
+ foundMedleyStart := true;
+ if(bt+Czesci[p].Czesc[line].Nuta[note].Dlugosc = AktSong.Medley.EndBeat) then
+ foundMedleyEnd := true;
+ end;
+ end;
+ end;
+ end;
+
+ if(medley and not foundMedleyStart) then
+ begin
+ Log.LogError('Error MedleyStartBeat: no corresponding note start (beat) in song ' + AktSong.Path + AktSong.Filename);
+ Exit;
+ end else if(medley and not foundMedleyEnd) then
+ begin
+ Log.LogError('Error MedleyEndBeat: no corresponding note start+length in song ' + AktSong.Path + AktSong.Filename);
+ Exit;
+ end;
+ Result := true;
+end;
+
+
//--------------------
// Load a Song
//--------------------
@@ -719,6 +818,7 @@ begin
Read(SongFile, TempC);
until ((TempC = ':') or (TempC = 'F') or (TempC = '*'));
+ SetLength(Czesci, 0);
SetLength(Czesci, 2);
for Pet := 0 to High(Czesci) do begin
SetLength(Czesci[Pet].Czesc, 1);
@@ -831,7 +931,7 @@ begin
exit;
end;
- Result := true;
+ Result := CheckSong;
end;
//--------------------
@@ -964,7 +1064,7 @@ var
len_lines, len_notes: integer;
found_end: boolean;
begin
- if AktSong.Medley.Source = msTag then //will be deleted soon
+ if AktSong.Medley.Source = msTag then
Exit;
//relative is not supported for medley by now!
diff --git a/Game/Code/Classes/USongs.pas b/Game/Code/Classes/USongs.pas
index 39aeba31..c605703d 100644
--- a/Game/Code/Classes/USongs.pas
+++ b/Game/Code/Classes/USongs.pas
@@ -174,7 +174,7 @@ begin
res := AnalyseFile(Song[SLen]); //TODO Hash?
- if res and (Song[SLen].Medley.Source=msNone) then
+ if res then
begin
SetLength(Czesci, 1);
AktSong := Song[SLen];