 /*	
	HotKey plugin for Sonique 2.0
    Copyright (C) 2004  Jerome Kuptz

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
#ifndef _MEDIAFILTER_HOT_H_
#define _MEDIAFILTER_HOT_H_

#include "sq2_audiosys.h"
#include "ioutils.h"
#include "mia.h"


class PCMMediaFormat : public MPCMMediaFormat
{
public:
	PCMMediaFormat() { m_RefCount; MediaType = MID_MEDIATYPE_PCM; }

	PCMMediaFormat& operator =(const MPCMMediaFormat& Other) { nSampleRate = Other.nSampleRate; nNumChannels = Other.nNumChannels; nBitsPerSample = Other.nBitsPerSample; bIsReal = Other.bIsReal; bIsSigned = Other.bIsSigned; return *this; }
	bool operator !=(const MPCMMediaFormat& Other) { return nSampleRate != Other.nSampleRate || nNumChannels != Other.nNumChannels || nBitsPerSample != Other.nBitsPerSample || bIsReal != Other.bIsReal || bIsSigned != Other.bIsSigned; }

    virtual void	__stdcall Release( ) { if( !AtomicDecrement(&m_RefCount) ) delete this; }
	virtual void    __stdcall AddRef() { AtomicIncrement(&m_RefCount); }
	int32 m_RefCount;
};


class SQ2_Audio_HotKey_dll;

class HotKeyFilter: 
	public MMediaFilter, 
	public MMediaInput, 
	public MMediaOutput, 
	public MMediaSettings
{
public:
	HotKeyFilter(SQ2_Audio_HotKey_dll *parMainDLL);
	~HotKeyFilter();

	//MMediaFilter
	virtual MRESULT __stdcall GetNumInputs( ) const;
	virtual MRESULT __stdcall GetNumOutputs( ) const;
	virtual MRESULT __stdcall GetInput(  MMediaInput** ppToHere, int32 nWhich ) const ;
	virtual MRESULT __stdcall GetInput(  MMediaInput** ppToHere, const wchar_t* wsWhich ) const;
	virtual MRESULT __stdcall GetOutput( MMediaOutput** ppToHere, int32 nWhich ) const;
	virtual MRESULT __stdcall GetOutput( MMediaOutput** ppToHere, const wchar_t* wsWhich ) const;
	virtual MRESULT __stdcall AddedToChain( MMediaChain* pChain );
	virtual MRESULT __stdcall ChangeState( MediaState State );
	virtual MRESULT __stdcall GatherFilterInformation( InformationHint Hint );
	virtual MRESULT __stdcall SeekFilter( double tTime, bool bAccurately, bool bFlush );
	virtual MRESULT __stdcall FlushFilter();

	//MMediaInput
	virtual WString __stdcall GetInputName( ) const;
	virtual MRESULT __stdcall CanHandle( MMediaOutput* pOutput, uint32 *plConfidence, uint32 *plMerit );
	virtual MRESULT __stdcall AttachInput( MMediaOutput* pOutput );
	virtual MRESULT __stdcall GetFilter( MMediaFilter** ppToHere );
	

	//MMediaOutput
	virtual WString __stdcall GetOutputName( ) const;
	virtual MRESULT __stdcall GetPacket( RefPtr<MPacket>& pToHere );
	virtual MRESULT __stdcall GetFormats( Array<RefPtr<MMediaFormat> >& Formats );
	virtual MRESULT __stdcall SelectFormat( MMediaFormat* pFormat );
	virtual MRESULT __stdcall AttachOutput( MMediaInput* pInput );
	
	//MMediaInformation
	virtual MRESULT __stdcall GetStringInfo( const wchar_t* wsWhich, WString& wsToHere );
	virtual MRESULT __stdcall GetIntegerInfo( const wchar_t* wsWhich, int32& lToHere );
	virtual MRESULT __stdcall GetRealInfo( const wchar_t* wsWhich, double& lToHere );
	virtual MRESULT __stdcall EnumerateInformation( Array<MediaInfo>& Info );

	//MMediaSettings
	virtual MRESULT __stdcall SetStringInfo( const wchar_t* wsWhich, const WString& Info );
	virtual MRESULT __stdcall SetIntegerInfo( const wchar_t* wsWhich, int32 Info );
	virtual MRESULT __stdcall SetRealInfo( const wchar_t* wsWhich, double Info );
	virtual MRESULT __stdcall LoadSettings( MPreferences* pPrefs );
	virtual MRESULT __stdcall SaveSettings( MPreferences* pPrefs );
	virtual MRESULT	__stdcall FilterMessage( const wchar_t* wsMessageName, void* pData );

	virtual MRESULT __stdcall QueryModule(const MID& mid, void** ppv, bool bAddReference = true, const MGeneric* pPrev = NULL);
	IMPLEMENT_REFERENCECOUNT();

protected:
	MRESULT GetCompatibleFormats( MMediaOutput* pOutput, Array<RefPtr<MMediaFormat> >& CompatibleFormats );
	bool						m_bEnabled;

	uint32 m_lPlayKey;
	uint32 m_lStopKey;
	uint32 m_lNextKey;
	uint32 m_lPrevKey;
	uint32 m_lMuteKey;
	uint32 m_lVolDKey;
	uint32 m_lVolUKey;

	uint32 m_lPlayMod;
	uint32 m_lStopMod;
	uint32 m_lNextMod;
	uint32 m_lPrevMod;
	uint32 m_lMuteMod;
	uint32 m_lVolUMod;
	uint32 m_lVolDMod;

/*
	WString m_wsPlayKey;
	WString m_wsStopKey;
	WString m_wsNextKey;
	WString m_wsPrevKey;
	WString m_wsMuteKey;
	WString m_wsVolDKey;
	WString m_wsVolUKey;

	WString m_wsPlayMod;
	WString m_wsStopMod;
	WString m_wsNextMod;
	WString m_wsPrevMod;
	WString m_wsMuteMod;
	WString m_wsVolUMod;
	WString m_wsVolDMod;
*/

	RefPtr<PCMMediaFormat>		m_pAudioFormat;
	CriticalSectionObject       m_HotCs;
	PreferencesPtr				m_pPrefs;	
	ErrorSystemPtr				m_ErrorSys;

	MediaState					m_State;
	MMediaInput*                m_pMyDest;
	MMediaOutput*               m_pMySource;
	MMediaChain*				m_pChain;

private:
	SQ2_Audio_HotKey_dll *m_MainDLL;
};

#endif