From 54b27d4e2ab7dab3ff136418b23d12180d1ad609 Mon Sep 17 00:00:00 2001 From: TheNail <43859560+TheNailDev@users.noreply.github.com> Date: Tue, 21 Jan 2025 20:03:02 +0100 Subject: [PATCH 1/5] parse the AUDIO header --- src/base/USong.pas | 55 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/src/base/USong.pas b/src/base/USong.pas index 6e27ea3c3..5c9ce4fa1 100644 --- a/src/base/USong.pas +++ b/src/base/USong.pas @@ -911,6 +911,28 @@ function TSong.ReadTXTHeader(SongFile: TTextFileStream; ReadCustomTags: Boolean) end; end; + {** + * Updates the Audio file of the song (MP3 field) to a file witn given filename. + * Updates the Done flags to identify that the audio resource is set. + * If no file with the given name exists, an error is logged. + *} + procedure CheckAndSetAudioFile(const filename: string); + var + filePath: IPath; + begin + filePath := DecodeFilename(filename); + if (Self.Path.Append(filePath).IsFile) then + begin + self.Mp3 := filePath; + //Add Audio Flag to Done + Done := Done or 4; + end + else + begin + Log.LogError('Can''t find audio file in song: ' + DecodeStringUTF8(FullFileName, Encoding)); + end; + end; + begin Result := true; Done := 0; @@ -1061,20 +1083,35 @@ function TSong.ReadTXTHeader(SongFile: TTextFileStream; ReadCustomTags: Boolean) Done := Done or 2; end; - //MP3 File - if (TagMap.TryGetData('MP3', Value)) then + // Audio File + // The new AUDIO header was introduced in format 1.1.0 and replaces MP3 (deprecated) + // For older format versions the audio file is found in the MP3 header + if self.FormatVersion.MinVersion(1,1,0) then begin - RemoveTagsFromTagMap('MP3'); - EncFile := DecodeFilename(Value); - if (Self.Path.Append(EncFile).IsFile) then + if TagMap.TryGetData('AUDIO', Value) then begin - self.Mp3 := EncFile; - //Add Mp3 Flag to Done - Done := Done or 4; + RemoveTagsFromTagMap('AUDIO'); + // If AUDIO is present MP3 should be ignored + if TagMap.IndexOf('MP3') > -1 then + begin + Log.LogInfo('The AUDIO header overwrites the MP3 header in file ' + FullFileName, 'TSong.ReadTXTHeader'); + RemoveTagsFromTagMap('MP3', false); + end; + CheckAndSetAudioFile(Value); end else begin - Log.LogError('Can''t find audio file in song: ' + DecodeStringUTF8(FullFileName, Encoding)); + Result := false; + Log.LogError('Missing AUDIO header (mandatory for format >= 1.1.0) ' + FullFileName); + Exit; + end; + end + else + begin + if TagMap.TryGetData('MP3', Value) then + begin + RemoveTagsFromTagMap('MP3'); + CheckAndSetAudioFile(Value); end; end; From 058fdb10d8e66d7a112341ceaa02a85b0092d855 Mon Sep 17 00:00:00 2001 From: TheNail <43859560+TheNailDev@users.noreply.github.com> Date: Tue, 21 Jan 2025 20:13:57 +0100 Subject: [PATCH 2/5] write AUDIO header when saving files for format < 1.1.0 only MP3 is written for format in range [1.1.0, 2.0.0) AUDIO and MP3 is written for format >= 2.0.0 only AUDIO is written --- src/base/UFiles.pas | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/base/UFiles.pas b/src/base/UFiles.pas index 5e1ccf5ce..b50352e16 100644 --- a/src/base/UFiles.pas +++ b/src/base/UFiles.pas @@ -149,7 +149,11 @@ function SaveSong(const Song: TSong; const Tracks: array of TLines; const Name: if Song.Year <> 0 then SongFile.WriteLine('#YEAR:' + IntToStr(Song.Year)); if Song.Creator <> '' then SongFile.WriteLine('#CREATOR:' + EncodeToken(Song.Creator)); - SongFile.WriteLine('#MP3:' + EncodeToken(Song.Mp3.ToUTF8)); + if Song.FormatVersion.MinVersion(1,1,0) then + SongFile.WriteLine('#AUDIO:' + EncodeToken(Song.Mp3.ToUTF8)); + if Song.FormatVersion.MaxVersion(2,0,0) then + SongFile.WriteLine('#MP3:' + EncodeToken(Song.Mp3.ToUTF8)); + if Song.Cover.IsSet then SongFile.WriteLine('#COVER:' + EncodeToken(Song.Cover.ToUTF8)); if Song.Background.IsSet then SongFile.WriteLine('#BACKGROUND:' + EncodeToken(Song.Background.ToUTF8)); if Song.Video.IsSet then SongFile.WriteLine('#VIDEO:' + EncodeToken(Song.Video.ToUTF8)); From bbe677cadd649d2ef9fea08672900c9da99b9757 Mon Sep 17 00:00:00 2001 From: TheNail <43859560+TheNailDev@users.noreply.github.com> Date: Wed, 22 Jan 2025 20:42:05 +0100 Subject: [PATCH 3/5] rename TSong.Mp3 to TSong.Audio --- .gitignore | 2 +- src/base/UFiles.pas | 4 ++-- src/base/USong.pas | 16 +++++++------- src/screens/UScreenEditSub.pas | 21 +++++++++---------- src/screens/UScreenJukebox.pas | 17 +-------------- src/screens/UScreenScore.pas | 2 +- src/screens/UScreenSong.pas | 2 +- .../controllers/UScreenSingController.pas | 3 +-- 8 files changed, 25 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index 9e2874531..ae9b019b9 100644 --- a/.gitignore +++ b/.gitignore @@ -48,7 +48,7 @@ ppaslink.sh /src/ultrastardx.res # dev files -/backup/ +**/backup/ /[Tt]o[Dd]o/ /installer/dependencies/dll/*.dll diff --git a/src/base/UFiles.pas b/src/base/UFiles.pas index b50352e16..282f4279b 100644 --- a/src/base/UFiles.pas +++ b/src/base/UFiles.pas @@ -150,9 +150,9 @@ function SaveSong(const Song: TSong; const Tracks: array of TLines; const Name: if Song.Creator <> '' then SongFile.WriteLine('#CREATOR:' + EncodeToken(Song.Creator)); if Song.FormatVersion.MinVersion(1,1,0) then - SongFile.WriteLine('#AUDIO:' + EncodeToken(Song.Mp3.ToUTF8)); + SongFile.WriteLine('#AUDIO:' + EncodeToken(Song.Audio.ToUTF8)); if Song.FormatVersion.MaxVersion(2,0,0) then - SongFile.WriteLine('#MP3:' + EncodeToken(Song.Mp3.ToUTF8)); + SongFile.WriteLine('#MP3:' + EncodeToken(Song.Audio.ToUTF8)); if Song.Cover.IsSet then SongFile.WriteLine('#COVER:' + EncodeToken(Song.Cover.ToUTF8)); if Song.Background.IsSet then SongFile.WriteLine('#BACKGROUND:' + EncodeToken(Song.Background.ToUTF8)); diff --git a/src/base/USong.pas b/src/base/USong.pas index 5c9ce4fa1..add6d896e 100644 --- a/src/base/USong.pas +++ b/src/base/USong.pas @@ -141,7 +141,7 @@ TSong = class // filenames Cover: IPath; - Mp3: IPath; + Audio: IPath; Background: IPath; Video: IPath; @@ -378,7 +378,7 @@ constructor TSong.Create(); Self.Path := PATH_NONE(); Self.FileName := PATH_NONE(); Self.Cover := PATH_NONE(); - Self.Mp3 := PATH_NONE(); + Self.Audio := PATH_NONE(); Self.Background:= PATH_NONE(); Self.Video := PATH_NONE(); end; @@ -912,7 +912,7 @@ function TSong.ReadTXTHeader(SongFile: TTextFileStream; ReadCustomTags: Boolean) end; {** - * Updates the Audio file of the song (MP3 field) to a file witn given filename. + * Updates the Audio file of the song to a file with given filename. * Updates the Done flags to identify that the audio resource is set. * If no file with the given name exists, an error is logged. *} @@ -923,7 +923,7 @@ function TSong.ReadTXTHeader(SongFile: TTextFileStream; ReadCustomTags: Boolean) filePath := DecodeFilename(filename); if (Self.Path.Append(filePath).IsFile) then begin - self.Mp3 := filePath; + self.Audio := filePath; //Add Audio Flag to Done Done := Done or 4; end @@ -1084,7 +1084,7 @@ function TSong.ReadTXTHeader(SongFile: TTextFileStream; ReadCustomTags: Boolean) end; // Audio File - // The new AUDIO header was introduced in format 1.1.0 and replaces MP3 (deprecated) + // The AUDIO header was introduced in format 1.1.0 and replaces MP3 (deprecated) // For older format versions the audio file is found in the MP3 header if self.FormatVersion.MinVersion(1,1,0) then begin @@ -1387,8 +1387,8 @@ function TSong.ReadTXTHeader(SongFile: TTextFileStream; ReadCustomTags: Boolean) Result := false; if (Done and 8) = 0 then //No BPM Flag Log.LogError('File contains empty lines or BPM tag missing: ' + FullFileName) - else if (Done and 4) = 0 then //No MP3 Flag - Log.LogError('MP3 tag/file missing: ' + FullFileName) + else if (Done and 4) = 0 then //No Audio Flag + Log.LogError('Audio/MP3 tag/file missing: ' + FullFileName) else if (Done and 2) = 0 then //No Artist Flag Log.LogError('Artist tag missing: ' + FullFileName) else if (Done and 1) = 0 then //No Title Flag @@ -1766,7 +1766,7 @@ procedure TSong.Clear(); SetLength(CustomTags, 0); //Required Information - Mp3 := PATH_NONE; + Audio := PATH_NONE; SetLength(BPM, 0); GAP := 0; diff --git a/src/screens/UScreenEditSub.pas b/src/screens/UScreenEditSub.pas index bbac2ed08..4c9db7518 100644 --- a/src/screens/UScreenEditSub.pas +++ b/src/screens/UScreenEditSub.pas @@ -2796,18 +2796,18 @@ function TScreenEditSub.ParseMouse(MouseButton: Integer; BtnDown: boolean; X, Y: begin CopyToUndo; SelectsS[Interactions[nBut].Num].SelectedOption := SelectsS[Interactions[nBut].Num].SelectedOption -1; - CurrentSong.Mp3 := Path(SelectsS[Interactions[nBut].Num].TextOptT[SelectsS[Interactions[nBut].Num].SelectedOption]); + CurrentSong.Audio := Path(SelectsS[Interactions[nBut].Num].TextOptT[SelectsS[Interactions[nBut].Num].SelectedOption]); AudioPlayback.Close; - AudioPlayback.Open(CurrentSong.Path.Append(CurrentSong.Mp3)); + AudioPlayback.Open(CurrentSong.Path.Append(CurrentSong.Audio)); end; if ((Mp3SlideId = Interactions[nBut].Num) and (Action = maRight) and (SelectsS[Interactions[nBut].Num].SelectedOption < Length(SelectsS[Interactions[nBut].Num].TextOptT)-1)) then begin CopyToUndo; SelectsS[Interactions[nBut].Num].SelectedOption := SelectsS[Interactions[nBut].Num].SelectedOption +1; - CurrentSong.Mp3 := Path(SelectsS[Interactions[nBut].Num].TextOptT[SelectsS[Interactions[nBut].Num].SelectedOption]); + CurrentSong.Audio := Path(SelectsS[Interactions[nBut].Num].TextOptT[SelectsS[Interactions[nBut].Num].SelectedOption]); AudioPlayback.Close(); - AudioPlayback.Open(CurrentSong.Path.Append(CurrentSong.Mp3)); + AudioPlayback.Open(CurrentSong.Path.Append(CurrentSong.Audio)); end; if (((VolumeAudioSlideId = Interactions[nBut].Num) or (VolumeMidiSlideId = Interactions[nBut].Num) or (VolumeClickSlideId = Interactions[nBut].Num)) @@ -3752,7 +3752,7 @@ procedure TScreenEditSub.CopyToUndo; UndoHeader[CurrentUndoLines].Genre := CurrentSong.Genre; UndoHeader[CurrentUndoLines].Year := CurrentSong.Year; UndoHeader[CurrentUndoLines].Creator := CurrentSong.Creator; - UndoHeader[CurrentUndoLines].Mp3 := CurrentSong.Mp3; + UndoHeader[CurrentUndoLines].Mp3 := CurrentSong.Audio; UndoHeader[CurrentUndoLines].Mp3Id := SelectsS[Mp3SlideId].SelectedOption; UndoHeader[CurrentUndoLines].Cover := CurrentSong.Cover; UndoHeader[CurrentUndoLines].CoverId := SelectsS[CoverSlideId].SelectedOption; @@ -3913,7 +3913,7 @@ procedure TScreenEditSub.CopyFromUndo; CurrentSong.Genre := Undoheader[CurrentUndoLines].Genre; CurrentSong.Year := Undoheader[CurrentUndoLines].Year; CurrentSong.Creator := Undoheader[CurrentUndoLines].Creator; - CurrentSong.Mp3 := Undoheader[CurrentUndoLines].Mp3; + CurrentSong.Audio := Undoheader[CurrentUndoLines].Mp3; SelectsS[Mp3SlideId].SelectedOption := Undoheader[CurrentUndoLines].Mp3Id; CurrentSong.Cover := Undoheader[CurrentUndoLines].Cover; SelectsS[CoverSlideId].SelectedOption := Undoheader[CurrentUndoLines].CoverId; @@ -4703,8 +4703,7 @@ procedure TScreenEditSub.OnShow; SelectsS[CreatorSlideId].TextOpt[0].Align := 0; SelectsS[CreatorSlideId].TextOpt[0].X := SelectsS[CreatorSlideId].TextureSBG.X + 5; - //Text[TextMp3].Text := CurrentSong.Mp3.ToUTF8; - // Header MP3 + // Header MP3 / AUDIO SetLength(MP3Val, 0); SetLength(Files, 0); SlideMP3Index := -1; @@ -4716,7 +4715,7 @@ procedure TScreenEditSub.OnShow; begin SetLength(MP3Val, High(MP3Val) + 2); MP3Val[FileIndex] := filesystem.ExtractFileName(Files[FileIndex]).ToUTF8; - if (UTF8CompareText(MP3Val[FileIndex],CurrentSong.Mp3.ToUTF8) = 0) then + if (UTF8CompareText(MP3Val[FileIndex],CurrentSong.Audio.ToUTF8) = 0) then SlideMP3Index := FileIndex; end; UpdateSelectSlideOptions(Theme.EditSub.SlideMP3,MP3SlideId,MP3Val,SlideMP3Index); @@ -4922,7 +4921,7 @@ procedure TScreenEditSub.OnShow; Tracks[TrackIndex].Lines[0].Notes[0].Color := P1_INVERTED; end; - AudioPlayBack.Open(CurrentSong.Path.Append(CurrentSong.Mp3)); + AudioPlayBack.Open(CurrentSong.Path.Append(CurrentSong.Audio)); //Set Down Music Volume for Better hearability of Midi Sounds //Music.SetVolume(0.4); @@ -5084,7 +5083,7 @@ function TScreenEditSub.Draw: boolean; end; //for NoteIndex} end; //end move cursor - // mp3 music + // music if (PlaySentence or PlayVideo or PlayOne) then begin // stop the music diff --git a/src/screens/UScreenJukebox.pas b/src/screens/UScreenJukebox.pas index 4383605a6..f731bedd1 100644 --- a/src/screens/UScreenJukebox.pas +++ b/src/screens/UScreenJukebox.pas @@ -2174,7 +2174,7 @@ procedure TScreenJukebox.Play(); var I: integer; begin - AudioPlayback.Open(CurrentSong.Path.Append(CurrentSong.Mp3)); + AudioPlayback.Open(CurrentSong.Path.Append(CurrentSong.Audio)); AudioPlayback.SetVolume(1.0); //AudioPlayback.Position := CurrentSong.Start; @@ -2825,21 +2825,6 @@ procedure TScreenJukebox.DrawPlaylist; SongDesc := Title + ' - ' + Artist else SongDesc := Artist + ' - ' + Title; - - { - if (CatSongs.Song[JukeboxVisibleSongs[I + ListMin]].Finish <> 0) then - Time := CatSongs.Song[JukeboxVisibleSongs[I + ListMin]].Finish/1000 - else - begin - AudioPlayback.Open(CatSongs.Song[JukeboxVisibleSongs[I + ListMin]].Mp3); - Time := AudioPlayback.Length; - AudioPlayback.Close(); - // Time := CatSongs.Song[JukeboxVisibleSongs[I + ListMin]].MP3Length; - - end; - - TimeString := IntToStr(Round(Time) div 60) + ':' + Format('%.*d', [2, Round(Time) mod 60]); - } end else begin diff --git a/src/screens/UScreenScore.pas b/src/screens/UScreenScore.pas index 60dce71a1..0a3c6436c 100644 --- a/src/screens/UScreenScore.pas +++ b/src/screens/UScreenScore.pas @@ -1827,7 +1827,7 @@ procedure TScreenSCore.StartPreview; begin AudioPlayback.Close; - if AudioPlayback.Open(CatSongs.Song[select].Path.Append(CatSongs.Song[select].Mp3)) then + if AudioPlayback.Open(CatSongs.Song[select].Path.Append(CatSongs.Song[select].Audio)) then begin if (CatSongs.Song[select].PreviewStart > 0) then AudioPlayback.Position := CatSongs.Song[select].PreviewStart diff --git a/src/screens/UScreenSong.pas b/src/screens/UScreenSong.pas index a0c315c13..9e3c7fe33 100644 --- a/src/screens/UScreenSong.pas +++ b/src/screens/UScreenSong.pas @@ -3710,7 +3710,7 @@ procedure TScreenSong.StartMusicPreview(); Exit; PlayMidi := false; - if AudioPlayback.Open(Song.Path.Append(Song.Mp3)) then + if AudioPlayback.Open(Song.Path.Append(Song.Audio)) then begin PreviewOpened := Interaction; diff --git a/src/screens/controllers/UScreenSingController.pas b/src/screens/controllers/UScreenSingController.pas index b2f479bf8..a4f00eaa6 100644 --- a/src/screens/controllers/UScreenSingController.pas +++ b/src/screens/controllers/UScreenSingController.pas @@ -857,7 +857,7 @@ procedure TScreenSingController.onShowFinish; PlayMidi := false; MidiFadeIn := false; - AudioPlayback.Open(CurrentSong.Path.Append(CurrentSong.Mp3)); + AudioPlayback.Open(CurrentSong.Path.Append(CurrentSong.Audio)); if ScreenSong.Mode = smMedley then AudioPlayback.SetVolume(0.1) else @@ -1018,7 +1018,6 @@ procedure TScreenSingController.LoadNextSong(); if length(PlaylistMedley.Song) >= PlaylistMedley.CurrentMedleySong then begin CatSongs.Selected := PlaylistMedley.Song[PlaylistMedley.CurrentMedleySong-1]; - //Music.Open(CatSongs.Song[CatSongs.Selected].Path + CatSongs.Song[CatSongs.Selected].Mp3); end else begin From 985a293040502af2ec58dbb70f5fe1a8f1b183bb Mon Sep 17 00:00:00 2001 From: TheNail <43859560+TheNailDev@users.noreply.github.com> Date: Wed, 22 Jan 2025 20:44:49 +0100 Subject: [PATCH 4/5] change occurences of MP3 in user interface with Audio I only checked The english and german languages. Most other languages simply use the values from the english localisation. --- game/languages/English.ini | 14 +++++++------- game/languages/German.ini | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/game/languages/English.ini b/game/languages/English.ini index b10ae0f76..a30c1f69e 100644 --- a/game/languages/English.ini +++ b/game/languages/English.ini @@ -616,7 +616,7 @@ EDIT_EDITION=Edition: EDIT_GENRE=Genre: EDIT_YEAR=Year: EDIT_CREATOR=Creator: -EDIT_MP3=MP3: +EDIT_MP3=Audio: EDIT_COVER=Cover: EDIT_BACKGROUND=Background: EDIT_VIDEO=Video: @@ -1994,15 +1994,15 @@ LEFTRIGHT = Go to previous/next note ;-------------------------------------------------------; SEC_030 = Playback PAGEUPDOWN = Adjust song volume -SPACE = Play MP3 for current note +SPACE = Play Audio for current note SHIFT_SPACE = Play MIDI for current note -CTRL_SHIFT_SPACE = Play MP3+MIDI for current note -P = Play MP3+CLICKS for current line +CTRL_SHIFT_SPACE = Play Audio+MIDI for current note +P = Play Audio+CLICKS for current line SHIFT_P = Play MIDI for current line -CTRL_SHIFT_P = Play MIDI+MP3+CLICKS for current line -ALT_P = Play MP3+CLICKS from current line onwards +CTRL_SHIFT_P = Play MIDI+Audio+CLICKS for current line +ALT_P = Play Audio+CLICKS from current line onwards SHIFT_ALT_P = Play MIDI from current line onwards -CTRL_SHIFT_ALT_P = Play MIDI+MP3+CLICKS from current line onwards +CTRL_SHIFT_ALT_P = Play MIDI+Audio+CLICKS from current line onwards V = Play VIDEO from current line onwards SHIFT_V = Play VIDEO+CLICKS from current line onwards ;-------------------------------------------------------; diff --git a/game/languages/German.ini b/game/languages/German.ini index b38f6f7bf..5f4d54486 100644 --- a/game/languages/German.ini +++ b/game/languages/German.ini @@ -616,7 +616,7 @@ EDIT_EDITION=Edition: EDIT_GENRE=Genre: EDIT_YEAR=Jahr: EDIT_CREATOR=Ersteller: -EDIT_MP3=MP3: +EDIT_MP3=Audio: EDIT_COVER=Cover: EDIT_BACKGROUND=Hintergrund: EDIT_VIDEO=Video: From bcf51195bc258c93cca6dcb74280ecae423792cd Mon Sep 17 00:00:00 2001 From: TheNailDev <43859560+TheNailDev@users.noreply.github.com> Date: Thu, 23 Jan 2025 17:57:05 +0000 Subject: [PATCH 5/5] revert changes to gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ae9b019b9..9e2874531 100644 --- a/.gitignore +++ b/.gitignore @@ -48,7 +48,7 @@ ppaslink.sh /src/ultrastardx.res # dev files -**/backup/ +/backup/ /[Tt]o[Dd]o/ /installer/dependencies/dll/*.dll