2021-07-29 14:52:18 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-07-31 07:09:25 +08:00
|
|
|
using osu.Framework.Audio;
|
2021-07-29 14:52:18 +08:00
|
|
|
using osu.Framework.Audio.Track;
|
2021-07-31 07:09:25 +08:00
|
|
|
using osu.Framework.Bindables;
|
2021-07-29 14:52:18 +08:00
|
|
|
using osu.Game.Audio;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mods
|
|
|
|
{
|
2022-05-20 16:12:35 +08:00
|
|
|
public partial class MetronomeBeat : BeatSyncedContainer, IAdjustableAudioComponent
|
2021-07-29 14:52:18 +08:00
|
|
|
{
|
|
|
|
private readonly double firstHitTime;
|
|
|
|
|
2021-07-31 07:09:25 +08:00
|
|
|
private readonly PausableSkinnableSound sample;
|
2021-07-29 14:52:18 +08:00
|
|
|
|
|
|
|
/// <param name="firstHitTime">Start time of the first hit object, used for providing a count down.</param>
|
2022-05-20 16:12:35 +08:00
|
|
|
public MetronomeBeat(double firstHitTime)
|
2021-07-29 14:52:18 +08:00
|
|
|
{
|
|
|
|
this.firstHitTime = firstHitTime;
|
|
|
|
AllowMistimedEventFiring = false;
|
|
|
|
Divisor = 1;
|
|
|
|
|
2021-07-31 07:09:25 +08:00
|
|
|
InternalChild = sample = new PausableSkinnableSound(new SampleInfo("Gameplay/catch-banana"));
|
2021-07-29 14:52:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes)
|
|
|
|
{
|
|
|
|
base.OnNewBeat(beatIndex, timingPoint, effectPoint, amplitudes);
|
|
|
|
|
|
|
|
if (!IsBeatSyncedWithTrack) return;
|
|
|
|
|
2022-01-23 00:27:27 +08:00
|
|
|
int timeSignature = timingPoint.TimeSignature.Numerator;
|
2021-07-29 14:52:18 +08:00
|
|
|
|
|
|
|
// play metronome from one measure before the first object.
|
2022-05-22 21:15:53 +08:00
|
|
|
if (BeatSyncSource.Clock?.CurrentTime < firstHitTime - timingPoint.BeatLength * timeSignature)
|
2021-07-29 14:52:18 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
sample.Frequency.Value = beatIndex % timeSignature == 0 ? 1 : 0.5f;
|
|
|
|
sample.Play();
|
|
|
|
}
|
2021-07-31 07:09:25 +08:00
|
|
|
|
|
|
|
#region IAdjustableAudioComponent
|
|
|
|
|
|
|
|
public IBindable<double> AggregateVolume => sample.AggregateVolume;
|
|
|
|
|
|
|
|
public IBindable<double> AggregateBalance => sample.AggregateBalance;
|
|
|
|
|
|
|
|
public IBindable<double> AggregateFrequency => sample.AggregateFrequency;
|
|
|
|
|
|
|
|
public IBindable<double> AggregateTempo => sample.AggregateTempo;
|
|
|
|
|
|
|
|
public BindableNumber<double> Volume => sample.Volume;
|
|
|
|
|
|
|
|
public BindableNumber<double> Balance => sample.Balance;
|
|
|
|
|
|
|
|
public BindableNumber<double> Frequency => sample.Frequency;
|
|
|
|
|
|
|
|
public BindableNumber<double> Tempo => sample.Tempo;
|
|
|
|
|
|
|
|
public void BindAdjustments(IAggregateAudioAdjustment component)
|
|
|
|
{
|
|
|
|
sample.BindAdjustments(component);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UnbindAdjustments(IAggregateAudioAdjustment component)
|
|
|
|
{
|
|
|
|
sample.UnbindAdjustments(component);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddAdjustment(AdjustableProperty type, IBindable<double> adjustBindable)
|
|
|
|
{
|
|
|
|
sample.AddAdjustment(type, adjustBindable);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RemoveAdjustment(AdjustableProperty type, IBindable<double> adjustBindable)
|
|
|
|
{
|
|
|
|
sample.RemoveAdjustment(type, adjustBindable);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RemoveAllAdjustments(AdjustableProperty type)
|
|
|
|
{
|
|
|
|
sample.RemoveAllAdjustments(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2021-07-29 14:52:18 +08:00
|
|
|
}
|
|
|
|
}
|