forked from ppy/osu-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleChannel.cs
73 lines (53 loc) · 1.77 KB
/
SampleChannel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// 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;
using System.Threading.Tasks;
using osu.Framework.Audio.Mixing;
using osu.Framework.Statistics;
using osu.Framework.Audio.Track;
namespace osu.Framework.Audio.Sample
{
public abstract class SampleChannel : AdjustableAudioComponent, ISampleChannel, IAudioChannel
{
internal Action<SampleChannel>? OnPlay;
public string Name { get; }
protected SampleChannel(string name)
{
Name = name;
}
public virtual void Play()
{
ObjectDisposedException.ThrowIf(IsDisposed, this);
Played = true;
OnPlay?.Invoke(this);
}
public virtual void Stop()
{
}
protected override void UpdateState()
{
FrameStatistics.Increment(StatisticsCounterType.SChannels);
base.UpdateState();
}
public bool Played { get; private set; }
public abstract bool Playing { get; }
public virtual bool Looping { get; set; }
public override bool IsAlive => base.IsAlive && Playing;
public virtual ChannelAmplitudes CurrentAmplitudes { get; } = ChannelAmplitudes.Empty;
#region Mixing
protected virtual AudioMixer? Mixer { get; set; }
AudioMixer? IAudioChannel.Mixer
{
get => Mixer;
set => Mixer = value;
}
Task IAudioChannel.EnqueueAction(Action action) => EnqueueAction(action);
#endregion
protected override void Dispose(bool disposing)
{
if (!IsDisposed)
Stop();
base.Dispose(disposing);
}
}
}