-
Notifications
You must be signed in to change notification settings - Fork 2
/
Sounds.cs
83 lines (71 loc) · 2.87 KB
/
Sounds.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
74
75
76
77
78
79
80
81
82
83
using OpenBveApi.Runtime;
using System.Collections.Generic;
namespace ATCFS {
internal class Sounds {
// --- クラス ---
/// <summary>ループ音を表すクラス</summary>
internal class Sound {
internal readonly int Index;
internal SoundHandle Handle;
internal bool IsToBePlayed;
internal Sound(int index) {
this.Index = index;
this.Handle = null;
}
internal void Play() {
this.IsToBePlayed = true;
}
}
// --- メンバ ---
private readonly PlaySoundDelegate PlaySound;
// --- 繰り返し再生 ---
internal readonly Sound Eb;
private readonly Sound[] LoopingSounds;
// --- 1回再生 ---
internal readonly Sound AtspDing;
internal readonly Sound AtcDing;
internal readonly Sound AtcSwDownSound;
internal readonly Sound AtcSwUpSound;
internal readonly Sound AtcAirSound;
private readonly List<Sound> PlayOnceSounds;
// --- コンストラクタ ---
/// <summary>新しいインスタンスを作成する</summary>
/// <param name="playSound">サウンドを再生する関数のデリゲート。</param>
internal Sounds(PlaySoundDelegate playSound) {
this.PlaySound = playSound;
// --- 繰り返し再生 ---
this.Eb = new Sounds.Sound(13);
this.LoopingSounds = new Sound[] { this.Eb };
// --- 1回再生 ---
this.AtspDing = new Sound(2);
this.AtcDing = new Sound(7);
this.AtcSwDownSound = new Sound(8);
this.AtcSwUpSound = new Sound(9);
this.AtcAirSound = new Sound(10);
this.PlayOnceSounds = new List<Sound> { this.AtspDing, this.AtcDing, this.AtcSwDownSound, this.AtcSwUpSound, this.AtcAirSound };
}
// --- 関数 ---
/// <summary>1フレームごとに呼び出される関数</summary>
/// <param name="data">The data.</param>
internal void Elapse(ElapseData data) {
foreach (Sound sound in this.LoopingSounds) {
if (sound.IsToBePlayed) {
if (sound.Handle == null || sound.Handle.Stopped) {
sound.Handle = PlaySound(sound.Index, 1.0, 1.0, true);
}
} else {
if (sound.Handle != null && sound.Handle.Playing) {
sound.Handle.Stop();
}
}
sound.IsToBePlayed = false;
}
foreach (Sound sound in this.PlayOnceSounds) {
if (sound.IsToBePlayed) {
PlaySound(sound.Index, 1.0, 1.0, false);
sound.IsToBePlayed = false;
}
}
}
}
}