Navigation Menu

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

Fix being able to seek TrackVirtual to negative time values #1464

Merged
merged 2 commits into from Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion osu.Framework/Audio/Track/Track.cs
Expand Up @@ -64,10 +64,21 @@ public virtual void ResetSpeedAdjustments()
/// </summary>
public abstract double CurrentTime { get; }

private double length;

/// <summary>
/// Length of the track in milliseconds.
/// </summary>
public double Length { get; protected set; }
public double Length
{
get => length;
set
{
if (value < 0)
throw new ArgumentException("Track length must be >= 0.", nameof(value));
length = value;
}
}

public virtual int? Bitrate => null;

Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Audio/Track/TrackVirtual.cs
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using osu.Framework.Timing;
using OpenTK;

namespace osu.Framework.Audio.Track
{
Expand Down Expand Up @@ -30,8 +31,7 @@ public override bool Seek(double seek)
clock.Reset();
}

if (Length > 0 && seekOffset > Length)
seekOffset = Length;
seekOffset = MathHelper.Clamp(seekOffset, 0, Length);

return current != seekOffset;
}
Expand Down