163 lines
4.9 KiB
C
163 lines
4.9 KiB
C
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
|||
|
|
//
|
|||
|
|
// 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
|
|||
|
|
#include <kiwano-audio/Sound.h>
|
|||
|
|
#include <kiwano/base/ObjectBase.h>
|
|||
|
|
|
|||
|
|
namespace kiwano
|
|||
|
|
{
|
|||
|
|
namespace audio
|
|||
|
|
{
|
|||
|
|
KGE_DECLARE_SMART_PTR(SoundManager);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* \addtogroup Audio
|
|||
|
|
* @{
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* \~chinese
|
|||
|
|
* @brief <EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*/
|
|||
|
|
class KGE_API SoundManager : public ObjectBase
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
SoundManager();
|
|||
|
|
|
|||
|
|
~SoundManager();
|
|||
|
|
|
|||
|
|
/// \~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(const String& file_path);
|
|||
|
|
|
|||
|
|
/// \~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 Save_Load(const String& 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(const Resource& 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><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
float GetVolumeRate() 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 SetVolumeRate(float volume);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ļ<EFBFBD>id
|
|||
|
|
/// @param file_path <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>
|
|||
|
|
/// @return <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
|
|||
|
|
size_t GetId(const String& file_path) const;
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1>Ƶ<EFBFBD><C6B5>Դid
|
|||
|
|
/// @param res <20><>Ƶ<EFBFBD><C6B5>Դ
|
|||
|
|
/// @return <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
|
|||
|
|
size_t GetId(const Resource& res) const;
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
|
|||
|
|
/// @param id <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
|
|||
|
|
SoundPtr GetSound(size_t id) const;
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
|
|||
|
|
/// @param id <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
|
|||
|
|
SoundPtr GetSaveSound(size_t id) const;
|
|||
|
|
|
|||
|
|
/// \~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();
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
|
|||
|
|
/// @param id <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
|
|||
|
|
void ReleaseSoundByIndex(const size_t Id);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
|
|||
|
|
/// @param id <20><>Ƶ<EFBFBD><C6B5>ʶ<EFBFBD><CAB6>
|
|||
|
|
void ReleaseSaveSoundByIndex(const size_t Id);
|
|||
|
|
|
|||
|
|
/// \~chinese
|
|||
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
|
|||
|
|
Map<size_t, SoundPtr> GetAllSound();
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
float volume_rate;
|
|||
|
|
|
|||
|
|
using SoundMap = Map<size_t, SoundPtr>;
|
|||
|
|
SoundMap sound_cache_;
|
|||
|
|
SoundMap sound_save_;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/** @} */
|
|||
|
|
} // namespace audio
|
|||
|
|
} // namespace kiwano
|