/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/src/sgx/audio/logicalchannel.cpp

*/

#include "sgx/core/core.hpp"
#include "sgx/audio/audio.hpp"


CLogicalChannel::CLogicalChannel(tUINT32 idx) {

	m_pSampleData = NULL;
	m_pDeviceChannel = NULL;
	m_pMixChannel = NULL;

	m_vPosition.set(sgxVector3::Null);

	m_fPlayPtr = 0;

	m_bIsPlaying = FALSE;

	m_bReserved = FALSE;

	m_iIndex = idx;
}

void 
CLogicalChannel::update(const tREAL32 time_elapsed)
{
	m_fPlayPtr += time_elapsed;

	if (m_pDeviceChannel) {
		m_pDeviceChannel->update(time_elapsed);
	}
}

tBOOL 
CLogicalChannel::isPlaying() const
{
	if (m_pSampleData) {
		return m_bIsPlaying;
	}
	return FALSE;
}

tBOOL 
CLogicalChannel::hasFinished() const
{
	if (!isPlaying()) {
		return FALSE;
	}
	if (m_pMixChannel == NULL || m_pDeviceChannel == NULL) {
		return TRUE;
	}
	//
	if (m_pMixChannel->m_bLoop) {
		return FALSE;
	}
	//return FALSE;
	return m_pDeviceChannel->hasFinished();
}


void 
CLogicalChannel::pause()
{
	if (m_pDeviceChannel) {
		m_pDeviceChannel->pause();
		m_bIsPlaying = FALSE;
	}
}

void 
CLogicalChannel::resume()
{
	if (m_pDeviceChannel) {
		m_pDeviceChannel->resume();
		m_bIsPlaying = TRUE;
	}
}

void 
CLogicalChannel::stop()
{
	if (m_pDeviceChannel) {
		m_pDeviceChannel->stop();
		m_pSampleData = NULL;
		m_bIsPlaying = FALSE;
	}
}

void 
CLogicalChannel::setVolume(const tREAL32 vol)
{
	if (m_pMixChannel) {
		m_pMixChannel->m_fBaseVolume = vol;
	}
}


void 
CLogicalChannel::setPan(const tREAL32 pan)
{
	if (m_pMixChannel) {
		m_pMixChannel->m_fBasePan = pan;
	}
}




