| 
									
										
										
										
											2019-04-11 14:40:54 +08:00
										 |  |  |  | // Copyright (c) 2016-2018 Kiwano - Nomango
 | 
					
						
							| 
									
										
										
										
											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:
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // 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-11-13 14:33:15 +08:00
										 |  |  |  | #include <kiwano/core/ObjectBase.h>
 | 
					
						
							| 
									
										
										
										
											2019-10-11 21:55:29 +08:00
										 |  |  |  | #include <kiwano-audio/Sound.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
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-07-30 10:46:01 +08:00
										 |  |  |  | 	namespace audio | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-08-19 09:28:59 +08:00
										 |  |  |  | 		KGE_DECLARE_SMART_PTR(SoundPlayer); | 
					
						
							| 
									
										
										
										
											2019-07-30 10:46:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-31 10:37:29 +08:00
										 |  |  |  | 		/**
 | 
					
						
							|  |  |  |  | 		* \addtogroup Audio | 
					
						
							|  |  |  |  | 		* @{ | 
					
						
							|  |  |  |  | 		*/ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		/**
 | 
					
						
							|  |  |  |  | 		* \~chinese | 
					
						
							|  |  |  |  | 		* @brief <EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | 
					
						
							|  |  |  |  | 		*/ | 
					
						
							| 
									
										
										
										
											2019-08-19 09:28:59 +08:00
										 |  |  |  | 		class KGE_API SoundPlayer | 
					
						
							| 
									
										
										
										
											2020-01-09 08:45:00 +08:00
										 |  |  |  | 			: public virtual ObjectBase | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-07-30 10:46:01 +08:00
										 |  |  |  | 		public: | 
					
						
							| 
									
										
										
										
											2019-08-19 09:28:59 +08:00
										 |  |  |  | 			SoundPlayer(); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-19 09:28:59 +08:00
										 |  |  |  | 			~SoundPlayer(); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-31 10:37:29 +08:00
										 |  |  |  | 			/// \~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>
 | 
					
						
							| 
									
										
										
										
											2019-09-29 22:23:13 +08:00
										 |  |  |  | 			float GetVolume() const; | 
					
						
							| 
									
										
										
										
											2019-07-30 10:46:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-31 10:37:29 +08:00
										 |  |  |  | 			/// \~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); | 
					
						
							| 
									
										
										
										
											2019-07-30 10:46:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-31 10:37:29 +08:00
										 |  |  |  | 			/// \~chinese
 | 
					
						
							|  |  |  |  | 			/// @brief <20><>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
 | 
					
						
							| 
									
										
										
										
											2019-07-30 10:46:01 +08:00
										 |  |  |  | 			void PauseAll(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-31 10:37:29 +08:00
										 |  |  |  | 			/// \~chinese
 | 
					
						
							|  |  |  |  | 			/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
 | 
					
						
							| 
									
										
										
										
											2019-07-30 10:46:01 +08:00
										 |  |  |  | 			void ResumeAll(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-31 10:37:29 +08:00
										 |  |  |  | 			/// \~chinese
 | 
					
						
							|  |  |  |  | 			/// @brief ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
 | 
					
						
							| 
									
										
										
										
											2019-07-30 10:46:01 +08:00
										 |  |  |  | 			void StopAll(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-31 10:37:29 +08:00
										 |  |  |  | 			/// \~chinese
 | 
					
						
							|  |  |  |  | 			/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2019-07-30 10:46:01 +08:00
										 |  |  |  | 			void ClearCache(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-23 18:05:08 +08:00
										 |  |  |  | 		private: | 
					
						
							| 
									
										
										
										
											2019-09-29 22:23:13 +08:00
										 |  |  |  | 			float volume_; | 
					
						
							| 
									
										
										
										
											2019-08-18 17:49:13 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-12 11:26:41 +08:00
										 |  |  |  | 			using SoundMap = Map<size_t, SoundPtr>; | 
					
						
							| 
									
										
										
										
											2019-09-10 11:50:19 +08:00
										 |  |  |  | 			SoundMap sound_cache_; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2019-12-31 10:37:29 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		/** @} */ | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } |