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

Add an "Adjust pitch" switch to DT/HT #24640

Merged
merged 8 commits into from
Oct 18, 2023
26 changes: 25 additions & 1 deletion osu.Game/Rulesets/Mods/ModDaycore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Configuration;

namespace osu.Game.Rulesets.Mods
{
public abstract class ModDaycore : ModHalfTime
public abstract class ModDaycore : ModRateAdjust
{
public override string Name => "Daycore";
public override string Acronym => "DC";
public override IconUsage? Icon => null;
public override ModType Type => ModType.DifficultyReduction;
public override LocalisableString Description => "Whoaaaaa...";

[SettingSource("Speed decrease", "The actual decrease to apply")]
public override BindableNumber<double> SpeedChange { get; } = new BindableDouble(0.75)
{
MinValue = 0.5,
MaxValue = 0.99,
Precision = 0.01,
};

private readonly BindableNumber<double> tempoAdjust = new BindableDouble(1);
private readonly BindableNumber<double> freqAdjust = new BindableDouble(1);

Expand All @@ -33,5 +43,19 @@ public override void ApplyToTrack(IAdjustableAudioComponent track)
track.AddAdjustment(AdjustableProperty.Frequency, freqAdjust);
track.AddAdjustment(AdjustableProperty.Tempo, tempoAdjust);
}

public override double ScoreMultiplier
{
get
{
// Round to the nearest multiple of 0.1.
double value = (int)(SpeedChange.Value * 10) / 10.0;

// Offset back to 0.
value -= 1;

return 1 + value;
}
}
}
}
26 changes: 26 additions & 0 deletions osu.Game/Rulesets/Mods/ModDoubleTime.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
Expand All @@ -25,6 +26,31 @@ public abstract class ModDoubleTime : ModRateAdjust
Precision = 0.01,
};

private IAdjustableAudioComponent? track;

[SettingSource("Adjust pitch", "Should pitch be adjusted with speed")]
public virtual BindableBool AdjustPitch { get; } = new BindableBool(false);
peppy marked this conversation as resolved.
Show resolved Hide resolved

protected ModDoubleTime()
{
AdjustPitch.BindValueChanged(adjustPitchChanged);
}

private void adjustPitchChanged(ValueChangedEvent<bool> adjustPitchSetting)
{
track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), SpeedChange);
track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), SpeedChange);
}

private AdjustableProperty adjustmentForPitchSetting(bool adjustPitchSettingValue)
=> adjustPitchSettingValue ? AdjustableProperty.Frequency : AdjustableProperty.Tempo;

public override void ApplyToTrack(IAdjustableAudioComponent track)
{
this.track = track;
AdjustPitch.TriggerChange();
}

public override double ScoreMultiplier
{
get
Expand Down
26 changes: 26 additions & 0 deletions osu.Game/Rulesets/Mods/ModHalfTime.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
Expand All @@ -25,6 +26,31 @@ public abstract class ModHalfTime : ModRateAdjust
Precision = 0.01,
};

private IAdjustableAudioComponent? track;

[SettingSource("Adjust pitch", "Should pitch be adjusted with speed")]
public virtual BindableBool AdjustPitch { get; } = new BindableBool(false);

protected ModHalfTime()
{
AdjustPitch.BindValueChanged(adjustPitchChanged);
}

private void adjustPitchChanged(ValueChangedEvent<bool> adjustPitchSetting)
{
track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), SpeedChange);
track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), SpeedChange);
}

private AdjustableProperty adjustmentForPitchSetting(bool adjustPitchSettingValue)
=> adjustPitchSettingValue ? AdjustableProperty.Frequency : AdjustableProperty.Tempo;

public override void ApplyToTrack(IAdjustableAudioComponent track)
{
this.track = track;
AdjustPitch.TriggerChange();
}

public override double ScoreMultiplier
{
get
Expand Down
29 changes: 28 additions & 1 deletion osu.Game/Rulesets/Mods/ModNightcore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Game.Audio;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Beatmaps.Timing;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Objects;
Expand All @@ -19,12 +20,38 @@

namespace osu.Game.Rulesets.Mods
{
public abstract class ModNightcore : ModDoubleTime
public abstract class ModNightcore : ModRateAdjust
{
public override string Name => "Nightcore";
public override string Acronym => "NC";
public override IconUsage? Icon => OsuIcon.ModNightcore;
public override ModType Type => ModType.DifficultyIncrease;
public override LocalisableString Description => "Uguuuuuuuu...";

[SettingSource("Speed increase", "The actual increase to apply")]
public override BindableNumber<double> SpeedChange { get; } = new BindableDouble(1.5)
{
MinValue = 1.01,
MaxValue = 2,
Precision = 0.01,
};

public override double ScoreMultiplier
{
get
{
// Round to the nearest multiple of 0.1.
double value = (int)(SpeedChange.Value * 10) / 10.0;

// Offset back to 0.
value -= 1;

// Each 0.1 multiple changes score multiplier by 0.02.
value /= 5;

return 1 + value;
}
}
}

public abstract partial class ModNightcore<TObject> : ModNightcore, IApplicableToDrawableRuleset<TObject>
Expand Down
5 changes: 1 addition & 4 deletions osu.Game/Rulesets/Mods/ModRateAdjust.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ public abstract class ModRateAdjust : Mod, IApplicableToRate

public abstract BindableNumber<double> SpeedChange { get; }

public virtual void ApplyToTrack(IAdjustableAudioComponent track)
{
track.AddAdjustment(AdjustableProperty.Tempo, SpeedChange);
}
public abstract void ApplyToTrack(IAdjustableAudioComponent track);

public virtual void ApplyToSample(IAdjustableAudioComponent sample)
{
Expand Down