Skip to content

Commit

Permalink
Merge pull request #951 from TheNailDev/audio-header
Browse files Browse the repository at this point in the history
Implement AUDIO header
  • Loading branch information
barbeque-squared authored Jan 26, 2025
2 parents 6470caf + bcf5119 commit 28feced
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 54 deletions.
14 changes: 7 additions & 7 deletions game/languages/English.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
;-------------------------------------------------------;
Expand Down
2 changes: 1 addition & 1 deletion game/languages/German.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion src/base/UFiles.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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.Audio.ToUTF8));
if Song.FormatVersion.MaxVersion(2,0,0) then
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));
if Song.Video.IsSet then SongFile.WriteLine('#VIDEO:' + EncodeToken(Song.Video.ToUTF8));
Expand Down
65 changes: 51 additions & 14 deletions src/base/USong.pas
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ TSong = class

// filenames
Cover: IPath;
Mp3: IPath;
Audio: IPath;
Background: IPath;
Video: IPath;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -911,6 +911,28 @@ function TSong.ReadTXTHeader(SongFile: TTextFileStream; ReadCustomTags: Boolean)
end;
end;

{**
* 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.
*}
procedure CheckAndSetAudioFile(const filename: string);
var
filePath: IPath;
begin
filePath := DecodeFilename(filename);
if (Self.Path.Append(filePath).IsFile) then
begin
self.Audio := 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;
Expand Down Expand Up @@ -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 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;

Expand Down Expand Up @@ -1350,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
Expand Down Expand Up @@ -1729,7 +1766,7 @@ procedure TSong.Clear();
SetLength(CustomTags, 0);

//Required Information
Mp3 := PATH_NONE;
Audio := PATH_NONE;
SetLength(BPM, 0);

GAP := 0;
Expand Down
21 changes: 10 additions & 11 deletions src/screens/UScreenEditSub.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
17 changes: 1 addition & 16 deletions src/screens/UScreenJukebox.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/screens/UScreenScore.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/screens/UScreenSong.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/screens/controllers/UScreenSingController.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 28feced

Please sign in to comment.