From 33d4ac7e0e86cd7f740aca2d7a1d715e030f0643 Mon Sep 17 00:00:00 2001 From: barbeque-squared Date: Sun, 14 Jul 2024 16:12:26 +0200 Subject: [PATCH 1/2] ignore invalid #RESOLUTION. fixes #859 --- src/base/UFiles.pas | 1 + src/base/USong.pas | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/base/UFiles.pas b/src/base/UFiles.pas index 55ea526e5..d257fecd5 100644 --- a/src/base/UFiles.pas +++ b/src/base/UFiles.pas @@ -150,6 +150,7 @@ function SaveSong(const Song: TSong; const Tracks: array of TLines; const Name: if Song.Video.IsSet then SongFile.WriteLine('#VIDEO:' + EncodeToken(Song.Video.ToUTF8)); if Song.VideoGAP <> 0.0 then SongFile.WriteLine('#VIDEOGAP:' + FloatToStr(Song.VideoGAP)); + // TODO: this default also appears in USong.ReadTXTHeader and USong.Clear if Song.Resolution <> 4 then SongFile.WriteLine('#RESOLUTION:' + IntToStr(Song.Resolution)); if Song.NotesGAP <> 0 then SongFile.WriteLine('#NOTESGAP:' + IntToStr(Song.NotesGAP)); if Song.Start <> 0.0 then SongFile.WriteLine('#START:' + FloatToStr(Song.Start)); diff --git a/src/base/USong.pas b/src/base/USong.pas index fc91d3c1c..82b6dbe75 100644 --- a/src/base/USong.pas +++ b/src/base/USong.pas @@ -971,7 +971,12 @@ function TSong.ReadTXTHeader(SongFile: TTextFileStream; ReadCustomTags: Boolean) // Resolution else if (Identifier = 'RESOLUTION') then begin - TryStrtoInt(Value, self.Resolution) + TryStrtoInt(Value, self.Resolution); + if (self.Resolution < 1) then begin + // TODO: this hardcoded default also appears in Clear and UFiles.SaveSong + Log.LogError('Ignoring invalid resolution in song: ' + FullFileName); + self.Resolution := 4; + end end // Notes Gap @@ -1472,6 +1477,7 @@ procedure TSong.Clear(); Video := PATH_NONE; VideoGAP := 0; NotesGAP := 0; + // TODO: this default also appears in ReadTXTHeader and UFiles.SaveSong Resolution := 4; Creator := ''; PreviewStart := 0; From a7b136be61d98b86dd510425f0edad62f50b0a75 Mon Sep 17 00:00:00 2001 From: barbeque-squared Date: Sun, 14 Jul 2024 16:17:59 +0200 Subject: [PATCH 2/2] less hardcoding of default #RESOLUTION value --- src/base/UFiles.pas | 3 +-- src/base/USong.pas | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/base/UFiles.pas b/src/base/UFiles.pas index d257fecd5..dfa3b8fa7 100644 --- a/src/base/UFiles.pas +++ b/src/base/UFiles.pas @@ -150,8 +150,7 @@ function SaveSong(const Song: TSong; const Tracks: array of TLines; const Name: if Song.Video.IsSet then SongFile.WriteLine('#VIDEO:' + EncodeToken(Song.Video.ToUTF8)); if Song.VideoGAP <> 0.0 then SongFile.WriteLine('#VIDEOGAP:' + FloatToStr(Song.VideoGAP)); - // TODO: this default also appears in USong.ReadTXTHeader and USong.Clear - if Song.Resolution <> 4 then SongFile.WriteLine('#RESOLUTION:' + IntToStr(Song.Resolution)); + if Song.Resolution <> USong.DEFAULT_RESOLUTION then SongFile.WriteLine('#RESOLUTION:' + IntToStr(Song.Resolution)); if Song.NotesGAP <> 0 then SongFile.WriteLine('#NOTESGAP:' + IntToStr(Song.NotesGAP)); if Song.Start <> 0.0 then SongFile.WriteLine('#START:' + FloatToStr(Song.Start)); if Song.Finish <> 0 then SongFile.WriteLine('#END:' + IntToStr(Song.Finish)); diff --git a/src/base/USong.pas b/src/base/USong.pas index 82b6dbe75..d68669c8a 100644 --- a/src/base/USong.pas +++ b/src/base/USong.pas @@ -61,6 +61,9 @@ interface UUnicodeStringHelper, UUnicodeUtils; +const + DEFAULT_RESOLUTION = 4; // default #RESOLUTION + type TSingMode = ( smNormal, smPartyClassic, smPartyFree, smPartyChallenge, smPartyTournament, smJukebox, smPlaylistRandom , smMedley ); @@ -973,9 +976,8 @@ function TSong.ReadTXTHeader(SongFile: TTextFileStream; ReadCustomTags: Boolean) begin TryStrtoInt(Value, self.Resolution); if (self.Resolution < 1) then begin - // TODO: this hardcoded default also appears in Clear and UFiles.SaveSong Log.LogError('Ignoring invalid resolution in song: ' + FullFileName); - self.Resolution := 4; + self.Resolution := DEFAULT_RESOLUTION; end end @@ -1477,8 +1479,7 @@ procedure TSong.Clear(); Video := PATH_NONE; VideoGAP := 0; NotesGAP := 0; - // TODO: this default also appears in ReadTXTHeader and UFiles.SaveSong - Resolution := 4; + Resolution := DEFAULT_RESOLUTION; Creator := ''; PreviewStart := 0; CalcMedley := true;