home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////////////////
- //
- // $$root$$.cpp : Implementation of C$$Safe_root$$
- //
- /////////////////////////////////////////////////////////////////////////////
-
- #include "stdafx.h"
- #include "i$$root$$.h"
- #include "$$root$$.h"
-
-
- /////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::C$$Safe_root$$
- // Constructor
-
- C$$Safe_root$$::C$$Safe_root$$() :
- m_clrForeground(0x0000FF),
- m_nPreset(0)
- {
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::~C$$Safe_root$$
- // Destructor
-
- C$$Safe_root$$::~C$$Safe_root$$()
- {
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$:::FinalConstruct
- // Called when an effect is first loaded. Use this function to do one-time
- // intializations that could fail (i.e. creating offscreen buffers) instead
- // of doing this in the constructor, which cannot return an error.
-
- HRESULT C$$Safe_root$$::FinalConstruct()
- {
- return S_OK;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$:::FinalRelease
- // Called when an effect is unloaded. Use this function to free any
- // resources allocated in FinalConstruct.
-
- void C$$Safe_root$$::FinalRelease()
- {
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::Render
- // Called when an effect should render itself to the screen.
- //////////////////////////////////////////////////////////////////////////////
- STDMETHODIMP C$$Safe_root$$::Render(TimedLevel *pLevels, HDC hdc, RECT *prc)
- {
- // Fill background with black
- HBRUSH hNewBrush = ::CreateSolidBrush( 0 );
- HPEN hNewPen = ::CreatePen( PS_SOLID, 0, m_clrForeground );
- HPEN hOldPen= static_cast<HPEN>(::SelectObject( hdc, hNewPen ));
-
- ::FillRect( hdc, prc, hNewBrush );
-
- // draw using the current preset
- switch (m_nPreset)
- {
- case PRESET_BARS:
- {
- // Walk through the frequencies until we run out of levels or drawing surface.
- for (int x = prc->left; x < prc->right && x < (SA_BUFFER_SIZE-1); ++x)
- {
- int y = static_cast<int>(((prc->bottom - prc->top)/256.0f) * pLevels->frequency[0][x - (prc->left - 1)]);
- ::MoveToEx( hdc, x, prc->bottom, NULL );
- ::LineTo(hdc, x, prc->bottom - y);
- }
- }
- break;
-
- case PRESET_SCOPE:
- {
- // Walk through the waveform data until we run out of samples or drawing surface.
- int y = static_cast<int>(((prc->bottom - prc->top)/256.0f) * pLevels->waveform[0][0]);
- ::MoveToEx( hdc, prc->left, y, NULL );
- for (int x = prc->left; x < prc->right && x < (SA_BUFFER_SIZE-1); ++x)
- {
- y = static_cast<int>(((prc->bottom - prc->top)/256.0f) * pLevels->waveform[0][x - (prc->left - 1)]);
- ::LineTo(hdc, x, y);
- }
- }
- break;
- }
-
- if (hNewBrush)
- {
- ::DeleteObject( hNewBrush );
- }
-
- if (hNewPen)
- {
- ::SelectObject( hdc, hOldPen );
- ::DeleteObject( hNewPen );
- }
-
- return S_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::MediaInfo
- // Everytime new media is loaded, this method is called to pass the
- // number of channels (mono/stereo), the sample rate of the media, and the
- // title of the media
- //////////////////////////////////////////////////////////////////////////////
- STDMETHODIMP C$$Safe_root$$::MediaInfo(LONG lChannelCount, LONG lSampleRate, BSTR bstrTitle )
- {
- return S_OK;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::GetCapabilities
- // Returns the capabilities of this effect. Flags that can be returned are:
- // EFFECT_CANGOFULLSCREEN -- effect supports full-screen rendering
- // EFFECT_HASPROPERTYPAGE -- effect supports a property page
- //////////////////////////////////////////////////////////////////////////////
- STDMETHODIMP C$$Safe_root$$::GetCapabilities(DWORD * pdwCapabilities)
- {
- if (NULL == pdwCapabilities)
- {
- return E_POINTER;
- }
-
- *pdwCapabilities = 0;
- return S_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::GetTitle
- // Invoked when a host wants to obtain the title of the effect
- //////////////////////////////////////////////////////////////////////////////
- STDMETHODIMP C$$Safe_root$$::GetTitle(BSTR* bstrTitle)
- {
- USES_CONVERSION;
-
- if (NULL == bstrTitle)
- {
- return E_POINTER;
- }
-
- CComBSTR bstrTemp;
- bstrTemp.LoadString(IDS_EFFECTNAME);
-
- if ((!bstrTemp) || (0 == bstrTemp.Length))
- {
- return E_FAIL;
- }
-
- *bstrTitle = bstrTemp.Detach();
-
- return S_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::GetPresetTitle
- // Invoked when a host wants to obtain the title of the given preset
- //////////////////////////////////////////////////////////////////////////////
- STDMETHODIMP C$$Safe_root$$::GetPresetTitle(LONG nPreset, BSTR *bstrPresetTitle)
- {
- USES_CONVERSION;
-
- if (NULL == bstrPresetTitle)
- {
- return E_POINTER;
- }
-
- if ((nPreset < 0) || (nPreset >= PRESET_COUNT))
- {
- return E_INVALIDARG;
- }
-
- CComBSTR bstrTemp;
-
- switch (nPreset)
- {
- case PRESET_BARS:
- bstrTemp.LoadString(IDS_BARSPRESETNAME);
- break;
-
- case PRESET_SCOPE:
- bstrTemp.LoadString(IDS_SCOPEPRESETNAME);
- break;
- }
-
- if ((!bstrTemp) || (0 == bstrTemp.Length))
- {
- return E_FAIL;
- }
-
- *bstrPresetTitle = bstrTemp.Detach();
-
- return S_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::GetPresetCount
- // Invoked when a host wants to obtain the number of supported presets
- //////////////////////////////////////////////////////////////////////////////
- STDMETHODIMP C$$Safe_root$$::GetPresetCount(LONG *pnPresetCount)
- {
- if (NULL == pnPresetCount)
- {
- return E_POINTER;
- }
-
- *pnPresetCount = PRESET_COUNT;
-
- return (S_OK);
- }
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::SetCurrentPreset
- // Invoked when a host wants to change the index of the current preset
- //////////////////////////////////////////////////////////////////////////////
- STDMETHODIMP C$$Safe_root$$::SetCurrentPreset(LONG nPreset)
- {
- if ((nPreset < 0) || (nPreset >= PRESET_COUNT))
- {
- return E_INVALIDARG;
- }
-
- m_nPreset = nPreset;
-
- return (S_OK);
- }
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::GetCurrentPreset
- // Invoked when a host wants to obtain the index of the current preset
- //////////////////////////////////////////////////////////////////////////////
- STDMETHODIMP C$$Safe_root$$::GetCurrentPreset(LONG *pnPreset)
- {
- if (NULL == pnPreset)
- {
- return E_POINTER;
- }
-
- *pnPreset = m_nPreset;
-
- return (S_OK);
- }
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::get_foregroundColor
- // Property get to retrieve the foregroundColor prop via the public interface.
- //////////////////////////////////////////////////////////////////////////////
- STDMETHODIMP C$$Safe_root$$::get_foregroundColor(BSTR *pVal)
- {
- return ColorToWz( pVal, m_clrForeground);
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::put_foregroundColor
- // Property put to set the foregroundColor prop via the public interface.
- //////////////////////////////////////////////////////////////////////////////
- STDMETHODIMP C$$Safe_root$$::put_foregroundColor(BSTR newVal)
- {
- return WzToColor(newVal, &m_clrForeground);
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::WzToColor
- // Helper function used to convert a string into a COLORREF.
- //////////////////////////////////////////////////////////////////////////////
- HRESULT C$$Safe_root$$::WzToColor(const WCHAR *pwszColor, COLORREF *pcrColor)
- {
- if (NULL == pwszColor)
- {
- //NULL color string passed in
- return E_POINTER;
- }
-
- if (0 == lstrlenW(pwszColor))
- {
- //Empty color string passed in
- return E_INVALIDARG;
- }
-
- if (NULL == pcrColor)
- {
- //NULL output color DWORD passed in
- return E_POINTER;
- }
-
- if (lstrlenW(pwszColor) != 7)
- {
- //hex color string is not of the correct length
- return E_INVALIDARG;
- }
-
- DWORD dwRet = 0;
- for (int i = 1; i < 7; i++)
- {
- // shift dwRet by 4
- dwRet <<= 4;
- // and add in the value of this string
-
- if ((pwszColor[i] >= L'0') && (pwszColor[i] <= L'9'))
- {
- dwRet += pwszColor[i] - '0';
- }
- else if ((pwszColor[i] >= L'A') && (pwszColor[i] <= L'F'))
- {
- dwRet += 10 + (pwszColor[i] - L'A');
- }
- else if ((pwszColor[i] >= L'a') && (pwszColor[i] <= L'f'))
- {
- dwRet += 10 + (pwszColor[i] - L'a');
- }
- else
- {
- //Invalid hex digit in color string
- return E_INVALIDARG;
- }
- }
-
- *pcrColor = SwapBytes(dwRet);
-
- return S_OK;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::ColorToWz
- // Helper function used to convert a COLORREF to a BSTR.
- //////////////////////////////////////////////////////////////////////////////
- HRESULT C$$Safe_root$$::ColorToWz( BSTR* pbstrColor, COLORREF crColor)
- {
- _ASSERT( NULL != pbstrColor );
- _ASSERT( (crColor & 0x00FFFFFF) == crColor );
-
- *pbstrColor = NULL;
-
- WCHAR wsz[8];
- HRESULT hr = S_OK;
-
- wsprintfW( wsz, L"#%06X", SwapBytes(crColor) );
-
- *pbstrColor = ::SysAllocString( wsz );
-
- if (!pbstrColor)
- {
- hr = E_FAIL;
- }
-
- return hr;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- // C$$Safe_root$$::SwapBytes
- // Used to convert between a DWORD and COLORREF. Simply swaps the lowest
- // and 3rd order bytes.
- //////////////////////////////////////////////////////////////////////////////
- inline DWORD C$$Safe_root$$::SwapBytes(DWORD dwRet)
- {
- return ((dwRet & 0x0000FF00) | ((dwRet & 0x00FF0000) >> 16) | ((dwRet & 0x000000FF) << 16));
- }
-
-