mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 03:15:36 +08:00
Move flourish playback to own trigger source
This commit is contained in:
parent
6bfbcca2fd
commit
9bdc80a749
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
|
using osu.Game.Rulesets.Taiko.Objects;
|
||||||
using osu.Game.Rulesets.Taiko.UI;
|
using osu.Game.Rulesets.Taiko.UI;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
@ -11,16 +12,31 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Argon
|
|||||||
{
|
{
|
||||||
internal partial class ArgonDrumSamplePlayer : DrumSamplePlayer
|
internal partial class ArgonDrumSamplePlayer : DrumSamplePlayer
|
||||||
{
|
{
|
||||||
|
private ArgonFlourishTriggerSource argonFlourishTrigger = null!;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(IPooledSampleProvider sampleProvider)
|
private void load(Playfield playfield, IPooledSampleProvider sampleProvider)
|
||||||
{
|
{
|
||||||
|
var hitObjectContainer = playfield.HitObjectContainer;
|
||||||
|
|
||||||
// Warm up pools for non-standard samples.
|
// Warm up pools for non-standard samples.
|
||||||
sampleProvider.GetPooledSample(new VolumeAwareHitSampleInfo(new HitSampleInfo(HitSampleInfo.HIT_NORMAL), true));
|
sampleProvider.GetPooledSample(new VolumeAwareHitSampleInfo(new HitSampleInfo(HitSampleInfo.HIT_NORMAL), true));
|
||||||
sampleProvider.GetPooledSample(new VolumeAwareHitSampleInfo(new HitSampleInfo(HitSampleInfo.HIT_CLAP), true));
|
sampleProvider.GetPooledSample(new VolumeAwareHitSampleInfo(new HitSampleInfo(HitSampleInfo.HIT_CLAP), true));
|
||||||
sampleProvider.GetPooledSample(new VolumeAwareHitSampleInfo(new HitSampleInfo(HitSampleInfo.HIT_FLOURISH), true));
|
sampleProvider.GetPooledSample(new VolumeAwareHitSampleInfo(new HitSampleInfo(HitSampleInfo.HIT_FLOURISH), true));
|
||||||
|
|
||||||
|
// We want to play back flourishes in an isolated source as to not have them cancelled.
|
||||||
|
AddInternal(argonFlourishTrigger = new ArgonFlourishTriggerSource(hitObjectContainer));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DrumSampleTriggerSource CreateTriggerSource(HitObjectContainer hitObjectContainer, SampleBalance balance) =>
|
protected override DrumSampleTriggerSource CreateTriggerSource(HitObjectContainer hitObjectContainer, SampleBalance balance) =>
|
||||||
new ArgonDrumSampleTriggerSource(hitObjectContainer, balance);
|
new ArgonDrumSampleTriggerSource(hitObjectContainer, balance);
|
||||||
|
|
||||||
|
protected override void Play(DrumSampleTriggerSource triggerSource, HitType hitType, bool strong)
|
||||||
|
{
|
||||||
|
base.Play(triggerSource, hitType, strong);
|
||||||
|
|
||||||
|
// This won't always play something, but the logic for flourish playback is contained within.
|
||||||
|
argonFlourishTrigger.Play(hitType, strong);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Rulesets.Taiko.Objects;
|
using osu.Game.Rulesets.Taiko.Objects;
|
||||||
@ -14,20 +13,12 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Argon
|
|||||||
{
|
{
|
||||||
public partial class ArgonDrumSampleTriggerSource : DrumSampleTriggerSource
|
public partial class ArgonDrumSampleTriggerSource : DrumSampleTriggerSource
|
||||||
{
|
{
|
||||||
private readonly HitObjectContainer hitObjectContainer;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private ISkinSource skinSource { get; set; } = null!;
|
private ISkinSource skinSource { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The minimum time to leave between flourishes that are added to strong rim hits.
|
|
||||||
/// </summary>
|
|
||||||
private const double time_between_flourishes = 2000;
|
|
||||||
|
|
||||||
public ArgonDrumSampleTriggerSource(HitObjectContainer hitObjectContainer, SampleBalance balance)
|
public ArgonDrumSampleTriggerSource(HitObjectContainer hitObjectContainer, SampleBalance balance)
|
||||||
: base(hitObjectContainer, balance)
|
: base(hitObjectContainer, balance)
|
||||||
{
|
{
|
||||||
this.hitObjectContainer = hitObjectContainer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Play(HitType hitType, bool strong)
|
public override void Play(HitType hitType, bool strong)
|
||||||
@ -49,37 +40,7 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Argon
|
|||||||
// let the magic begin...
|
// let the magic begin...
|
||||||
var samplesToPlay = new List<ISampleInfo> { new VolumeAwareHitSampleInfo(originalSample, strong) };
|
var samplesToPlay = new List<ISampleInfo> { new VolumeAwareHitSampleInfo(originalSample, strong) };
|
||||||
|
|
||||||
if (strong && hitType == HitType.Rim && canPlayFlourish(hitObject))
|
|
||||||
samplesToPlay.Add(new VolumeAwareHitSampleInfo(hitObject.CreateHitSampleInfo(HitSampleInfo.HIT_FLOURISH), true));
|
|
||||||
|
|
||||||
PlaySamples(samplesToPlay.ToArray());
|
PlaySamples(samplesToPlay.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool canPlayFlourish(TaikoHitObject hitObject)
|
|
||||||
{
|
|
||||||
double? lastFlourish = null;
|
|
||||||
|
|
||||||
var hitObjects = hitObjectContainer.AliveObjects
|
|
||||||
.Reverse()
|
|
||||||
.Select(d => d.HitObject)
|
|
||||||
.OfType<Hit>()
|
|
||||||
.Where(h => h.IsStrong && h.Type == HitType.Rim);
|
|
||||||
|
|
||||||
// Add an additional 'flourish' sample to strong rim hits (that are at least `time_between_flourishes` apart).
|
|
||||||
// This is applied to hitobjects in reverse order, as to sound more musically coherent by biasing towards to
|
|
||||||
// end of groups/combos of strong rim hits instead of the start.
|
|
||||||
foreach (var h in hitObjects)
|
|
||||||
{
|
|
||||||
bool canFlourish = lastFlourish == null || lastFlourish - h.StartTime >= time_between_flourishes;
|
|
||||||
|
|
||||||
if (canFlourish)
|
|
||||||
lastFlourish = h.StartTime;
|
|
||||||
|
|
||||||
if (h == hitObject)
|
|
||||||
return canFlourish;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
// 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 System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Game.Audio;
|
||||||
|
using osu.Game.Rulesets.Taiko.Objects;
|
||||||
|
using osu.Game.Rulesets.Taiko.UI;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Taiko.Skinning.Argon
|
||||||
|
{
|
||||||
|
internal partial class ArgonFlourishTriggerSource : ArgonDrumSampleTriggerSource
|
||||||
|
{
|
||||||
|
private readonly HitObjectContainer hitObjectContainer;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private ISkinSource skinSource { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The minimum time to leave between flourishes that are added to strong rim hits.
|
||||||
|
/// </summary>
|
||||||
|
private const double time_between_flourishes = 2000;
|
||||||
|
|
||||||
|
public ArgonFlourishTriggerSource(HitObjectContainer hitObjectContainer)
|
||||||
|
: base(hitObjectContainer, SampleBalance.Centre)
|
||||||
|
{
|
||||||
|
this.hitObjectContainer = hitObjectContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Play(HitType hitType, bool strong)
|
||||||
|
{
|
||||||
|
TaikoHitObject? hitObject = GetMostValidObject() as TaikoHitObject;
|
||||||
|
|
||||||
|
if (hitObject == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var originalSample = hitObject.CreateHitSampleInfo(hitType == HitType.Rim ? HitSampleInfo.HIT_CLAP : HitSampleInfo.HIT_NORMAL);
|
||||||
|
|
||||||
|
// If the sample is provided by a legacy skin, we should not try and do anything special.
|
||||||
|
if (skinSource.FindProvider(s => s.GetSample(originalSample) != null) is LegacySkinTransformer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (strong && hitType == HitType.Rim && canPlayFlourish(hitObject))
|
||||||
|
PlaySamples(new ISampleInfo[] { new VolumeAwareHitSampleInfo(hitObject.CreateHitSampleInfo(HitSampleInfo.HIT_FLOURISH), true) });
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool canPlayFlourish(TaikoHitObject hitObject)
|
||||||
|
{
|
||||||
|
double? lastFlourish = null;
|
||||||
|
|
||||||
|
var hitObjects = hitObjectContainer.AliveObjects
|
||||||
|
.Reverse()
|
||||||
|
.Select(d => d.HitObject)
|
||||||
|
.OfType<Hit>()
|
||||||
|
.Where(h => h.IsStrong && h.Type == HitType.Rim);
|
||||||
|
|
||||||
|
// Add an additional 'flourish' sample to strong rim hits (that are at least `time_between_flourishes` apart).
|
||||||
|
// This is applied to hitobjects in reverse order, as to sound more musically coherent by biasing towards to
|
||||||
|
// end of groups/combos of strong rim hits instead of the start.
|
||||||
|
foreach (var h in hitObjects)
|
||||||
|
{
|
||||||
|
bool canFlourish = lastFlourish == null || lastFlourish - h.StartTime >= time_between_flourishes;
|
||||||
|
|
||||||
|
if (canFlourish)
|
||||||
|
lastFlourish = h.StartTime;
|
||||||
|
|
||||||
|
if (h == hitObject)
|
||||||
|
return canFlourish;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -93,7 +93,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
triggerSource.Play(hitType, strong);
|
Play(triggerSource, hitType, strong);
|
||||||
|
|
||||||
lastHitTime = Time.Current;
|
lastHitTime = Time.Current;
|
||||||
lastAction = e.Action;
|
lastAction = e.Action;
|
||||||
@ -101,6 +101,9 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void Play(DrumSampleTriggerSource triggerSource, HitType hitType, bool strong) =>
|
||||||
|
triggerSource.Play(hitType, strong);
|
||||||
|
|
||||||
private bool checkStrongValidity(TaikoAction newAction, TaikoAction? lastAction, double timeBetweenActions)
|
private bool checkStrongValidity(TaikoAction newAction, TaikoAction? lastAction, double timeBetweenActions)
|
||||||
{
|
{
|
||||||
if (lastAction == null)
|
if (lastAction == null)
|
||||||
|
Loading…
Reference in New Issue
Block a user