//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
SoundVoice* SoundVoiceContainer::GetVoice()
{
	if (m_voiceList.empty()) {
		return NULL;
	}

	// 停止ボイスを探す
	std::list<SoundVoice*>::iterator it;
	for (it = m_voiceList.begin(); it != m_voiceList.end(); it++) {
		SoundVoice* voice = *it;
		if (!voice->CheckPlaying()) {
			m_voiceList.erase(it);
			m_voiceList.push_back(voice);
			return voice;
		}
	}

	// 停止ボイスがないときは最前ボイスを使用
	SoundVoice* voice = m_voiceList.front();
	m_voiceList.pop_front();
	m_voiceList.push_back(voice);
	voice->Stop();

	return voice;
}
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void SoundPlayer::Pause( ::Effekseer::SoundHandle handle, ::Effekseer::SoundTag tag, bool pause  )
{
	SoundVoice* voice = (SoundVoice*)handle;
	if (tag == voice->GetTag()) {
		voice->Pause(pause);
	}
}
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void SoundPlayer::Stop( ::Effekseer::SoundHandle handle, ::Effekseer::SoundTag tag )
{
	SoundVoice* voice = (SoundVoice*)handle;
	if (tag == voice->GetTag()) {
		voice->Stop();
	}
}
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void SoundVoiceContainer::StopAll()
{
	std::list<SoundVoice*>::iterator it;
	for (it = m_voiceList.begin(); it != m_voiceList.end(); it++) {
		SoundVoice* voice = *it;
		voice->Stop();
	}
}
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
bool SoundPlayer::CheckPlaying( ::Effekseer::SoundHandle handle, ::Effekseer::SoundTag tag )
{
	SoundVoice* voice = (SoundVoice*)handle;
	if (tag == voice->GetTag()) {
		return voice->CheckPlaying();
	}
	return false;
}
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void SoundVoiceContainer::PauseTag( ::Effekseer::SoundTag tag, bool pause )
{
	std::list<SoundVoice*>::iterator it;
	for (it = m_voiceList.begin(); it != m_voiceList.end(); it++) {
		SoundVoice* voice = *it;
		if (tag == voice->GetTag()) {
			voice->Pause(pause);
		}
	}
}
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void SoundVoiceContainer::StopData( SoundData* soundData )
{
	std::list<SoundVoice*>::iterator it;
	for (it = m_voiceList.begin(); it != m_voiceList.end(); it++) {
		SoundVoice* voice = *it;
		if (soundData == voice->GetData()) {
			voice->Stop();
		}
	}
}
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
bool SoundVoiceContainer::CheckPlayingTag( ::Effekseer::SoundTag tag )
{
	std::list<SoundVoice*>::iterator it;
	for (it = m_voiceList.begin(); it != m_voiceList.end(); it++) {
		SoundVoice* voice = *it;
		if (tag == voice->GetTag() && voice->CheckPlaying()) {
			return true;
		}
	}
	return false;
}
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
::Effekseer::SoundHandle SoundPlayer::Play( ::Effekseer::SoundTag tag, 
		const ::Effekseer::SoundPlayer::InstanceParameter& parameter )
{
	if (m_sound->GetMute()) {
		return NULL;
	}
	SoundData* soundData = (SoundData*)parameter.Data;
	if (soundData) {
		SoundVoice* voice = m_sound->GetVoice();
		if (voice) {
			voice->Play(tag, parameter);
			return (::Effekseer::SoundHandle)voice;
		}
	}
	return NULL;
}