KisaragiLibrary
 
読み取り中…
検索中…
一致する文字列を見つけられません
Sound.hpp
[詳解]
1#pragma once
2#include <DxLib.h>
3#include <unordered_map>
4#include <unordered_set>
5#include <string>
6#include <memory>
11#include <mutex>
12#include "../Accessor.hpp"
13
14
15namespace Kisaragi_Lib
16{
18 {
19 int handle;
20
21 public:
22 SoundHandle(int _handle) : handle{_handle}
23 {
24
25 }
26
27
29 {
30 DeleteSoundMem(handle);
31 }
32
33 operator const int&() const
34 {
35 return handle;
36 }
37 };
38
39 class SoundClip;
40
42 {
43 public:
44 static void Load(std::string _key, std::string _pass);
45 static void UnLoad(std::string _key);
46 static std::unique_ptr<SoundClip> CreateClip(std::string _key);
47
48 private:
49 static void Init();
50
51 static std::once_flag once;
52
54 static std::weak_ptr<SoundResourceFacade_Impl> ptr;
55 };
56
58 {
59 ASYNC = DX_PLAYTYPE_BACK , //: 非同期再生
60 LOOP = DX_PLAYTYPE_LOOP , //: ループ再生
61 SYNC = DX_PLAYTYPE_NORMAL, //: 同期再生
62 };
63
65 {
67 bool isPlayTop = 1;
68
70
71 public:
72
73 SoundClip(int _handle) : handle{ _handle }
74 {
75 Vol(128);
76 }
77
78
80
81 template<typename Num>
82 const int& Vol(Num _in)
83 {
84 vol = _in;
85 ChangeVolumeSoundMem(vol,handle);
86 return vol;
87 }
88
89
90 void Play()
91 {
92 if (IsPlay())
93 {
94 Debug::PrintWarningStatic("既に再生中です");
95 return;
96 }
97
98 PlaySoundMem(handle, playType, isPlayTop);
99
100 }
101
102 void Pause()
103 {
104 if (IsPlay())
105 {
106 isPlayTop = 0;
107 StopSoundMem(handle);
108 return;
109 }
110
111 Debug::PrintWarningStatic("再生されていない音声を停止しようとしました");
112 }
113
114
115 void Stop()
116 {
117 if (IsPlay())
118 {
119 isPlayTop = 1;
120 StopSoundMem(handle);
121 return;
122 }
123
124 Debug::PrintWarningStatic("再生されていない音声を停止しようとしました");
125 }
126
127
128 bool IsPlay()
129 {
130 return CheckSoundMem(handle) == 1;
131 }
132 };
133
134 class DeleteWaitSoundClips;
135
137 {
138 static std::once_flag once;
139
140 static std::weak_ptr<DeleteWaitSoundClips> deleteWaitClips;
141
142 public:
143
144 static void Init();
145
146 static void Push(std::unique_ptr<SoundClip> _clip);
147
148 static void Delete();
149
150 static void Clear();
151
152 };
153
154
155
156 /// <summary>
157 /// Facadeクラスのcontainerに対するインターフェースとなるクラス
158 /// </summary>
160 {
161 std::unordered_map<std::string,std::unique_ptr<SoundClip>> vec;
162
163 public:
164
166
167 SoundClip& operator[](std::string _key)
168 {
169 if (!vec.count(_key))
170 {
171 Debug::PrintAssertStatic("keyの要素が存在しません");
172 }
173 return *vec[_key];
174 }
175
176 void Add(std::string _key, std::string _soundFile, std::string _clipName);
177
178 void Add(std::string _key, std::string _clipName);
179
180 void Pop(std::string _clipName);
181
182
184 {
185 while (vec.size()!=0)
186 {
187 Pop(vec.begin()->first);
188 }
189 }
190 };
191}
DebugConsole操作クラス
範囲指定の値型を提供します。
Definition ComponentBase.hpp:24
static void PrintAssertStatic(const std::string _in)
エラー出力用コンソール出力(文字色しか変わらない)
Definition Debug.cpp:152
static void PrintWarningStatic(const std::string _in)
警告用コンソール出力(文字色しか変わらない)
Definition Debug.cpp:147
static std::once_flag once
Definition Sound.hpp:138
static std::weak_ptr< DeleteWaitSoundClips > deleteWaitClips
Definition Sound.hpp:140
static void Push(std::unique_ptr< SoundClip > _clip)
Definition Sound.cpp:46
static void Init()
Definition Sound.cpp:41
static void Delete()
Definition Sound.cpp:51
static void Clear()
Definition Sound.cpp:56
特定範囲の値を管理するための数値型
Definition RangeNum.hpp:123
Definition Sound.hpp:65
SoundHandle handle
Definition Sound.hpp:66
bool isPlayTop
Definition Sound.hpp:67
void Stop()
Definition Sound.hpp:115
void Play()
Definition Sound.hpp:90
void Pause()
Definition Sound.hpp:102
const int & Vol(Num _in)
Definition Sound.hpp:82
bool IsPlay()
Definition Sound.hpp:128
SoundClip(int _handle)
Definition Sound.hpp:73
SoundPlayType playType
Definition Sound.hpp:79
RangeNum< int, ClampOnOutOfRange > vol
Definition Sound.hpp:69
Definition Sound.hpp:18
int handle
Definition Sound.hpp:19
SoundHandle(int _handle)
Definition Sound.hpp:22
~SoundHandle()
Definition Sound.hpp:28
~SoundPlayerComponent()
Definition Sound.hpp:183
SoundClip & operator[](std::string _key)
Definition Sound.hpp:167
void Add(std::string _key, std::string _soundFile, std::string _clipName)
Definition Sound.cpp:162
std::unordered_map< std::string, std::unique_ptr< SoundClip > > vec
Definition Sound.hpp:161
SoundPlayerComponent()
Definition Sound.cpp:157
void Pop(std::string _clipName)
Definition Sound.cpp:173
SoundFacadeの本体
Definition Sound.cpp:68
Definition Sound.hpp:42
static void Init()
Definition Sound.cpp:133
static std::unique_ptr< SoundClip > CreateClip(std::string _key)
Definition Sound.cpp:150
static std::weak_ptr< SoundResourceFacade_Impl > ptr
Definition Sound.hpp:54
static void Load(std::string _key, std::string _pass)
Definition Sound.cpp:138
static void UnLoad(std::string _key)
Definition Sound.cpp:144
static std::once_flag once
Definition Sound.hpp:51
Definition Accessor.hpp:110
SoundPlayType
Definition Sound.hpp:58
@ ASYNC
Definition Sound.hpp:59
@ LOOP
Definition Sound.hpp:60
@ SYNC
Definition Sound.hpp:61
纏めるのが思いつかなかった汎用関数