//------------------------------------------------------------------------ // // VisInterface.cpp // // This class wraps WinAMP Visualization DLL's. See the .H file for // info on this class, or visit http://www.ratajik.com/VisInterface // for more information, including examples. // // ------------------------------------------------------------------- // * COPYRIGHT 2001, Greg Ratajik and Ratajik Software * // * All rights Reserved * // ------------------------------------------------------------------- // // 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. // // More information about this program can be found at: // http://www.ratajik.com/VisInterface // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //------------------------------------------------------------------------ #include "stdafx.h" #include "VisInterface.h" //------------------------------------------------------------------------ // // Method: Create // // Description: Wrapper around the ctor. Will only return a valid pointer // if it's a valid vis. // // Parms: CWnd& - The Parent window. // CString& - Path to the Vis DLL. // // Return: CVisInterface - NULL = Not interface, everything else // = the interface. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-21-01 Ratajik Initial Development //_________________________________________________________________________ CVisInterface * CVisInterface::Create(CWnd& wndParent, const CString& sDLLPath) { CVisInterface *pVis = new CVisInterface(wndParent, sDLLPath); if(pVis) { if(!pVis->isValid()) delete pVis, pVis = NULL; } return(pVis); } //------------------------------------------------------------------------ // // Method: CVisInterface // // Description: Ctor for the class // // Parms: CWnd& - The Parent window. // CString& - Path to the Vis DLL. // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ CVisInterface::CVisInterface(CWnd& wndParent, const CString& sDLLPath) : m_wndParent(wndParent), m_sDLLPath(sDLLPath), m_pVisHeader(NULL), m_hLib(NULL), m_pCurMod(NULL), m_nCurModNbr(0) { m_pMod[0] = NULL; m_pMod[1] = NULL; m_pMod[2] = NULL; try { LoadDLL(); } catch(...) { TRACE0("Unknown error...\n"); } } //------------------------------------------------------------------------ // // Method: ~CVisInterface // // Description: Dtor for the class. Clears up stuff, including unloading // the DLL. // // Parms: N/A // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ CVisInterface:: ~CVisInterface() { if(m_hLib) { FreeLibrary(m_hLib); m_hLib = NULL; } m_pMod[0] = NULL; m_pMod[1] = NULL; m_pMod[2] = NULL; m_pVisHeader = NULL; } //------------------------------------------------------------------------ // // Method: LoadDLL // // Description: Attempt to load the DLL. If that works, get the header. If // that works, get pointers to each Vis Mod and prep it. // // Parms: N/A // // Return: bool = TRUE = At least one mod was loaded // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ bool CVisInterface :: isVis(const CString& sDLLPath) { bool bRet = false; HINSTANCE hLib = LoadLibrary (sDLLPath); if (hLib) { typedef winampVisHeader * (*GetHeader)(void); // Proto to the header GetHeader getHeader; // // Try to get the Proc from the DLL. // getHeader= (GetHeader)GetProcAddress (hLib, "winampVisGetHeader"); if(getHeader != NULL) { winampVisHeader *pVisHeader; // // Call the GetHeader Func to get the // header // pVisHeader = (*getHeader)(); // // If we get the header, then it's a WinAMP Vis DLL. // if(pVisHeader) bRet = true; } FreeLibrary(hLib); } return(bRet); } //------------------------------------------------------------------------ // // Method: LoadDLL // // Description: Attempt to load the DLL. If that works, get the header. If // that works, get pointers to each Vis Mod and prep it. // // Parms: N/A // // Return: bool = TRUE = At least one mod was loaded // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ bool CVisInterface :: LoadDLL(void) { bool bRet = false; m_hLib = LoadLibrary (m_sDLLPath); if (m_hLib) { typedef winampVisHeader * (*GetHeader)(void); // Proto to the header GetHeader getHeader; // // Try to get the Proc from the DLL. // getHeader= (GetHeader)GetProcAddress (m_hLib, "winampVisGetHeader"); if(getHeader != NULL) { // // Call the GetHeader Func to get the // header // m_pVisHeader = (*getHeader)(); // // If we get the header, then it's a WinAMP Vis DLL. Load any Mod's // and init them. // if(m_pVisHeader) { for(int j = 0; j < 3; j++) { m_pMod[j] = m_pVisHeader->getModule(j); if(m_pMod[j]) { LoadModDefaults( m_pMod[j]); bRet = true; } } } } } return(bRet); } //------------------------------------------------------------------------ // // Method: LoadModDefault // // Description: Setup the mod with stuff we will always use. If you want // to do something else, you can extend the class. // // Parms: winAmpVisModule * - The Mod to setup. // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ void CVisInterface :: LoadModDefaults( winampVisModule *pMod) { pMod->hDllInstance = m_hLib; if(m_wndParent) pMod->hwndParent = m_wndParent.m_hWnd; else pMod->hwndParent = NULL; pMod->sRate = 22050; pMod->latencyMs = 25; pMod->delayMs = 25; } //------------------------------------------------------------------------ // // Method: VisName // // Description: Get the Vis name for this DLL. // // Parms: CString& - The returned name. // // Return: TRUE = Got a name. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ bool CVisInterface :: VisName( CString& sVisName ) const { if(m_pVisHeader != NULL) { sVisName = m_pVisHeader->description; return(true); } else { return(false); } } //------------------------------------------------------------------------ // // Method: ModName // // Description: Get the passed mod name // // Parms: int - The mod # to get // CString& - The returned mod name. // // Return: bool - TRUE = Get a mode name. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ bool CVisInterface :: ModName( CString& sModName ) const { bool bRet = false; if(m_pCurMod) { sModName = m_pCurMod->description; bRet = true; } return(bRet); } //------------------------------------------------------------------------ // // Method: ModName // // Description: Get the passed mod name // // Parms: int - The mod # to get // CString& - The returned mod name. // // Return: bool - TRUE = Get a mode name. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ bool CVisInterface :: ModName( int nModNbr, CString& sModName ) const { bool bRet = false; if(nModNbr >= 0 && nModNbr < 3 && m_pMod) { if(m_pMod[nModNbr] != NULL) { sModName = m_pMod[nModNbr]->description; bRet = true; } } return(bRet); } //------------------------------------------------------------------------ // // Method: Config // // Description: Call the Config for the Selected Mod. // // Parms: N/A // // Return: BOOL - TRUE = Was able to call the func. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ bool CVisInterface :: Config( void ) { if(m_pCurMod != NULL) { m_pCurMod->Config(m_pCurMod); return(true); } else return(false); } //------------------------------------------------------------------------ // // Method: Render // // Description: Call the Mod's render function (up to the caller to have // updated the 4 channels (spec/wave left/right) // // Parms: N/A // // Return: BOOL - TRUE = Was able to call the Render func. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ bool CVisInterface :: Render( void ) { if(m_pCurMod != NULL) { m_pCurMod->Render(m_pCurMod); return(true); } else return(false); } //------------------------------------------------------------------------ // // Method: Quit // // Description: Stop the current Vis mod // // Parms: N/A // // Return: BOOL - TRUE = Was able to call the Quit func. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-12-01 Ratajik Initial Development //_________________________________________________________________________ bool CVisInterface :: Quit( void ) { if(m_pCurMod != NULL) { CVisThread :: StopVis(); m_pCurMod->Quit(m_pCurMod); return(true); } else return(false); } //------------------------------------------------------------------------ // // Method: Init // // Description: Call Init on the selected Mod. // // // Parms: void // // Return: bool - TRUE = was able to INIT the mod. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ bool CVisInterface :: Init( void ) { bool bRet = false; if(m_pCurMod) { CVisThread :: StopVis(); CVisThread::StartVis(m_pCurMod, &m_wndParent); bRet = true; } return(bRet); } //------------------------------------------------------------------------ // // Method: SelectModule // // Description: Select the passed Mod as the current one. // NOTE: Lots of these methods require this to be done before // they will do anything. NOTE: This no longer auto-calls // Init() // // Parms: int - The Mod number to select as current. // // Return: bool - TRUE = was able to select the mod. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ bool CVisInterface :: SelectModule( int nModNbr ) { bool bRet = false; if(nModNbr >= 0 && nModNbr < 3) { if(m_pMod[nModNbr] != NULL) { m_pCurMod = m_pMod[nModNbr]; m_nCurModNbr = nModNbr; //m_pCurMod->Init(m_pCurMod); bRet = true; } } return(bRet); } //------------------------------------------------------------------------ // // Method: SetSpectrumNull // // Description: Indicate that the Spectrum data will have no channels // filled out. // // Parms: N/A // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ void CVisInterface :: SetSpectrumNull() { if(m_pCurMod) m_pCurMod->spectrumNch = 0; } //------------------------------------------------------------------------ // // Method: SetSpectrumStero // // Description: Indicate that the Spectrum data will have both channels // filled out. // // Parms: N/A // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ void CVisInterface :: SetSpectrumStereo() { if(m_pCurMod) m_pCurMod->spectrumNch = 2; } //------------------------------------------------------------------------ // // Method: SetSpectrumMono // // Description: Indicate that the Spectrum data will only have the left // channel filled out. // // Parms: N/A // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ void CVisInterface :: SetSpectrumMono() { if(m_pCurMod) m_pCurMod->spectrumNch = 1; } //------------------------------------------------------------------------ // // Method: SetWaveformNull // // Description: Indicate that the Waveform data will no both channels // filled out. // // Parms: N/A // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ void CVisInterface :: SetWaveformNull () { if(m_pCurMod) m_pCurMod->waveformNch = 0; } //------------------------------------------------------------------------ // // Method: SetWaveformStero // // Description: Indicate that the Waveform data will have both channels // filled out. // // Parms: N/A // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ void CVisInterface :: SetWaveformStereo () { if(m_pCurMod) m_pCurMod->waveformNch = 2; } //------------------------------------------------------------------------ // // Method: SetWaveformMono // // Description: Indicate that the Waveform data will only have the left // channel filled out. // // Parms: N/A // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ void CVisInterface :: SetWaveformMono () { if(m_pCurMod) m_pCurMod->waveformNch = 1; } //------------------------------------------------------------------------ // // Method: SetChannelNull // // Description: Indicate that both channels // filled out. // // Parms: N/A // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ void CVisInterface :: SetChannelNull () { if(m_pCurMod) m_pCurMod->nCh = 0; } //------------------------------------------------------------------------ // // Method: SetChannelStero // // Description: // // // Parms: N/A // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ void CVisInterface :: SetChannelStereo () { if(m_pCurMod) m_pCurMod->nCh = 2; } //------------------------------------------------------------------------ // // Method: SetChannelMono // // Description: // // // Parms: N/A // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ void CVisInterface :: SetChannelMono () { if(m_pCurMod) m_pCurMod->nCh = 1; } //------------------------------------------------------------------------ // // Method: GetSpectrumDataLeft // // Description: Get the unsigned char array 576 for this type/channel // // // Parms: void // // Return: unsigned char * - start of the 576 element array. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ unsigned char * CVisInterface :: GetSpectrumDataLeft ( void ) { if(m_pCurMod) return(&m_pCurMod->spectrumData[0][0]); else return(NULL); } //------------------------------------------------------------------------ // // Method: GetSpectrumDataRight // // Description: Get the unsigned char array 576 for this type/channel // // // Parms: void // // Return: unsigned char * - start of the 576 element array. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ unsigned char * CVisInterface :: GetSpectrumDataRight( void ) { if(m_pCurMod) return(&m_pCurMod->spectrumData[1][0]); else return(NULL); } //------------------------------------------------------------------------ // // Method: GetWaveformDataLeft // // Description: Get the unsigned char array 576 for this type/channel // // // Parms: void // // Return: unsigned char * - start of the 576 element array. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ unsigned char * CVisInterface :: GetWaveformDataLeft ( void ) { if(m_pCurMod) return(&m_pCurMod->waveformData[0][0]); else return(NULL); } //------------------------------------------------------------------------ // // Method: GetWaveformDataRight // // Description: Get the unsigned char array 576 for this type/channel // // // Parms: void // // Return: unsigned char * - start of the 576 element array. // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-05-01 Ratajik Initial Development //_________________________________________________________________________ unsigned char * CVisInterface :: GetWaveformDataRight( void ) { if(m_pCurMod) return(&m_pCurMod->waveformData[1][0]); else return(NULL); }