Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new method TALSSound.FadeOutThenPause() #57

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions source/alsound.pas
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ TALSSound = class( TALSErrorHandling )
procedure SetBuffersFrameCapacity(aFrameCapacity: longword);
procedure FreeBuffers;
protected
FFadeOutEnabled, FKillAfterFadeOut, FKillAfterPlay, FKill: boolean;
FFadeOutEnabled, FKillAfterFadeOut, FPauseAfterFadeOut, FKillAfterPlay, FKill: boolean;
private
procedure SetLoop(AValue: boolean);
procedure SetALVolume;
Expand Down Expand Up @@ -444,6 +444,9 @@ TALSSound = class( TALSErrorHandling )
// Decrease the volume of the sound and when its volume reach 0 kill it.
procedure FadeOutThenKill(aDuration: single; aCurveID: TALSCurveID = ALS_Linear);

// Decrease the volume of the sound and when its volume reach 0 pause it.
procedure FadeOutThenPause(aDuration: single; aCurveID: TALSCurveID = ALS_Linear);

// kill the sound (stop it and free all ressources for this sound).
procedure Kill;

Expand Down Expand Up @@ -5738,8 +5741,13 @@ procedure TALSSound.Update(const aElapsedTime: single);
if (Volume.State = alspsNO_CHANGE) and FFadeOutEnabled then
begin
FFadeOutEnabled := False;
Stop;
FKill := FKill or FKillAfterFadeOut;
if FPauseAfterFadeOut then begin
FPauseAfterFadeOut := False;
alSourcePause(FSource);
end else if FKillAfterFadeOut then begin
Stop;
FKill := True;
end;
end;

flagDoOnStopped := (State = ALS_STOPPED) and
Expand Down Expand Up @@ -6155,6 +6163,20 @@ procedure TALSSound.FadeOutThenKill(aDuration: single; aCurveID: TALSCurveID);
Kill;
end;

procedure TALSSound.FadeOutThenPause(aDuration: single; aCurveID: TALSCurveID);
begin
if not Error then
begin
case State of
ALS_STOPPED, ALS_PAUSED: Volume.Value := 0;
ALS_PLAYING: begin
FPauseAfterFadeOut := True;
FadeOut(aDuration, aCurveID);
end;
end;
end;
end;

procedure TALSSound.Kill;
begin
FKill := True;
Expand Down