Magic_Game/core/utils/Music.h

98 lines
2.2 KiB
C
Raw Normal View History

2018-10-03 22:02:46 +08:00
// Copyright (c) 2016-2018 Easy2D - 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 "../base/base.h"
#include "../base/RefCounter.h"
#include "../base/Resource.h"
#include <xaudio2.h>
2018-03-01 00:19:09 +08:00
2018-11-08 00:21:59 +08:00
namespace easy2d
2018-03-01 00:19:09 +08:00
{
// <20><><EFBFBD><EFBFBD>
class Music
: public RefCounter
2018-11-08 00:21:59 +08:00
{
public:
Music();
2018-03-01 00:19:09 +08:00
Music(
const String& file_path /* <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7> */
);
2018-03-01 00:19:09 +08:00
Music(
Resource& res /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ */
);
2018-05-22 23:36:46 +08:00
virtual ~Music();
2018-03-01 00:19:09 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
bool Load(
const String& file_path /* <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7> */
);
2018-03-01 00:19:09 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
bool Load(
Resource& res /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ */
);
2018-03-01 00:19:09 +08:00
// <20><><EFBFBD><EFBFBD>
bool Play(
int loop_count = 0 /* <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (-1 Ϊѭ<CEAA><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) */
);
2018-03-01 00:19:09 +08:00
// <20><>ͣ
void Pause();
// <20><><EFBFBD><EFBFBD>
void Resume();
// ֹͣ
void Stop();
// <20>رղ<D8B1><D5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
void Close();
// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>
bool IsPlaying() const;
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
float GetVolume() const;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool SetVolume(
float volume /* 1 Ϊԭʼ<D4AD><CABC><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> 1 Ϊ<>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD>, 0 Ϊ<><CEAA>С<EFBFBD><D0A1><EFBFBD><EFBFBD> */
2018-11-08 00:21:59 +08:00
);
// <20><>ȡ IXAudio2SourceVoice <20><><EFBFBD><EFBFBD>
IXAudio2SourceVoice * GetSourceVoice() const;
2018-05-22 22:55:06 +08:00
protected:
E2D_DISABLE_COPY(Music);
protected:
bool opened_;
bool playing_;
UINT32 size_;
BYTE* wave_data_;
IXAudio2SourceVoice* voice_;
};
}