/*
*/

#include <gst/gst.h>
#include <gst-phonon/gst-phonon.h>
#include "volumefadereffect.h"

namespace Phonon
{
namespace Gst
{
VolumeFaderEffect::VolumeFaderEffect( QObject* parent )
	: AudioEffect( -1, parent )
	, m_fadeTime( 0 )
{
	//object = gpho_volume_fader_effect_new();
}

VolumeFaderEffect::~VolumeFaderEffect()
{
	//gst_object_unref(object);
}

float VolumeFaderEffect::volume() const
{
	if( m_fadeTime > 0 )
	{
		float v = m_volume + ( m_endvolume - m_volume ) / m_fadeTime * m_fadeStart.elapsed();
		if( ( m_volume < m_endvolume && v > m_endvolume ) || ( m_volume > m_endvolume && v < m_endvolume ) )
		{
			VolumeFaderEffect* t = const_cast<VolumeFaderEffect*>( this );
			t->m_volume = m_endvolume;
			t->m_fadeTime = 0;
		}
		else
			return v;
	}
	return m_volume;
}

void VolumeFaderEffect::setVolume( float volume )
{
	m_volume = volume;
}

Phonon::VolumeFaderEffect::FadeCurve VolumeFaderEffect::fadeCurve() const
{
	return m_fadeCurve;
}

void VolumeFaderEffect::setFadeCurve( Phonon::VolumeFaderEffect::FadeCurve curve )
{
	m_fadeCurve = curve;
}

void VolumeFaderEffect::fadeTo( float volume, int fadeTime )
{
	if( m_fadeTime > 0 )
		m_volume = this->volume();
	m_fadeStart.start();
	m_fadeTime = fadeTime;
	m_endvolume = volume;
}

}} //namespace Phonon::Gst

#include "volumefadereffect.moc"
// vim: sw=4 ts=4
