| 
									
										
										
										
											2019-04-11 14:40:54 +08:00
										 |  |  |  | // Copyright (c) 2016-2018 Kiwano - Nomango
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2019-10-11 21:55:29 +08:00
										 |  |  |  | #include <kiwano-audio/Sound.h>
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | #include <kiwano/core/ObjectBase.h>
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 14:40:54 +08:00
										 |  |  |  | namespace kiwano | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | namespace audio | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | KGE_DECLARE_SMART_PTR(SoundPlayer); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * \addtogroup Audio | 
					
						
							|  |  |  |  |  * @{ | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * \~chinese | 
					
						
							|  |  |  |  |  * @brief <EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | class KGE_API SoundPlayer : public virtual ObjectBase | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | public: | 
					
						
							|  |  |  |  |     SoundPlayer(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     ~SoundPlayer(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief <20><><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ļ<EFBFBD>
 | 
					
						
							|  |  |  |  |     /// @param file_path <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>
 | 
					
						
							|  |  |  |  |     /// @return <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
 | 
					
						
							|  |  |  |  |     size_t Load(String const& file_path); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>Դ
 | 
					
						
							|  |  |  |  |     /// @param res <20><>Ƶ<EFBFBD><C6B5>Դ
 | 
					
						
							|  |  |  |  |     /// @return <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
 | 
					
						
							|  |  |  |  |     size_t Load(Resource const& res); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
 | 
					
						
							|  |  |  |  |     /// @param id <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
 | 
					
						
							|  |  |  |  |     /// @param loop_count <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -1 Ϊѭ<CEAA><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  |     void Play(size_t id, int loop_count = 0); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief <20><>ͣ<EFBFBD><CDA3>Ƶ
 | 
					
						
							|  |  |  |  |     /// @param id <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
 | 
					
						
							|  |  |  |  |     void Pause(size_t id); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
 | 
					
						
							|  |  |  |  |     /// @param id <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
 | 
					
						
							|  |  |  |  |     void Resume(size_t id); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief ֹͣ<CDA3><D6B9>Ƶ
 | 
					
						
							|  |  |  |  |     /// @param id <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
 | 
					
						
							|  |  |  |  |     void Stop(size_t id); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief <20><>ȡ<EFBFBD><C8A1>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>״̬
 | 
					
						
							|  |  |  |  |     /// @param id <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
 | 
					
						
							|  |  |  |  |     bool IsPlaying(size_t id); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  |     float GetVolume() const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  |     /// @param volume <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>1.0 Ϊԭʼ<D4AD><CABC><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> 1 Ϊ<>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD>, 0 Ϊ<><CEAA>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  |     void SetVolume(float volume); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief <20><>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
 | 
					
						
							|  |  |  |  |     void PauseAll(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
 | 
					
						
							|  |  |  |  |     void ResumeAll(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
 | 
					
						
							|  |  |  |  |     void StopAll(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |  |     /// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  |     void ClearCache(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | private: | 
					
						
							|  |  |  |  |     float volume_; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     using SoundMap = Map<size_t, SoundPtr>; | 
					
						
							|  |  |  |  |     SoundMap sound_cache_; | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /** @} */ | 
					
						
							|  |  |  |  | }  // namespace audio
 | 
					
						
							|  |  |  |  | }  // namespace kiwano
 |