0001: //-----------------------------------------------------------------------------
0002: // File: DMUtil.h
0003: //
0004: // Desc: DirectMusic framework classes for playing DirectMusic segments and
0005: //       DirectMusic scripts. Feel free to use this class as a starting point 
0006: //       for adding extra functionality.
0007: //-----------------------------------------------------------------------------
0008: #ifndef DMUTIL_H
0009: #define DMUTIL_H
0010: 
0011: #include <dmusicc.h>
0012: #include <dmusici.h>
0013: #include <dsound.h>
0014: 
0015: 
0016: //-----------------------------------------------------------------------------
0017: // Classes used by this header
0018: //-----------------------------------------------------------------------------
0019: class CMusicManager;
0020: class CMusicSegment;
0021: class C3DMusicSegment;
0022: class CMusicScript;
0023: 
0024: 
0025: 
0026: 
0027: //-----------------------------------------------------------------------------
0028: // Name: class CMusicManager
0029: // Desc: 
0030: //-----------------------------------------------------------------------------
0031: class CMusicManager
0032: {
0033: protected:
0034:     BOOL                      m_bCleanupCOM;
0035:     IDirectMusicLoader8*      m_pLoader;
0036:     IDirectMusicPerformance8* m_pPerformance;
0037:     IDirectSound3DListener*   m_pDSListener;
0038:     DS3DLISTENER              m_dsListenerParams;                // Listener properties
0039: 
0040: public:
0041:     CMusicManager();
0042:     ~CMusicManager();
0043: 
0044:     inline IDirectMusicLoader8*      GetLoader()      { return m_pLoader; }
0045:     inline IDirectMusicPerformance8* GetPerformance() { return m_pPerformance; }
0046:     inline IDirectSound3DListener*   GetListener()    { return m_pDSListener; }
0047: 
0048:     IDirectMusicAudioPath8* GetDefaultAudioPath();
0049: 
0050:     HRESULT Initialize( HWND hWnd, DWORD dwPChannels = 128, DWORD dwDefaultPathType = DMUS_APATH_DYNAMIC_STEREO, LPDIRECTSOUND pDS = NULL  );
0051: 
0052:     HRESULT SetSearchDirectory( const TCHAR* strMediaPath );
0053:     VOID    CollectGarbage();
0054:     VOID    StopAll();
0055: 
0056:     HRESULT CreateSegmentFromFile( CMusicSegment** ppSegment, TCHAR* strFileName, 
0057:                                    BOOL bDownloadNow = TRUE, BOOL bIsMidiFile = FALSE );
0058:     HRESULT Create3DSegmentFromFile( C3DMusicSegment** ppSegment, TCHAR* strFileName, 
0059:                                    BOOL bDownloadNow = TRUE, BOOL bIsMidiFile = FALSE, 
0060:                                    IDirectMusicAudioPath8* p3DAudioPath = NULL );
0061:     HRESULT CreateScriptFromFile( CMusicScript** ppScript, TCHAR* strFileName );
0062: 
0063:     HRESULT CreateChordMapFromFile( IDirectMusicChordMap8** ppChordMap, TCHAR* strFileName );
0064:     HRESULT CreateStyleFromFile( IDirectMusicStyle8** ppStyle, TCHAR* strFileName );
0065:     HRESULT GetMotifFromStyle( IDirectMusicSegment8** ppMotif, TCHAR* strStyle, TCHAR* wstrMotif );
0066: 
0067:     HRESULT CreateSegmentFromResource( CMusicSegment** ppSegment, TCHAR* strResource, TCHAR* strResourceType, 
0068:                                    BOOL bDownloadNow = TRUE, BOOL bIsMidiFile = FALSE );
0069: 
0070:     VOID Set3DParameters( FLOAT fDistanceFactor, FLOAT fDopplerFactor, FLOAT fRolloffFactor );
0071: };
0072: 
0073: 
0074: 
0075: 
0076: //-----------------------------------------------------------------------------
0077: // Name: class CMusicSegment
0078: // Desc: Encapsulates functionality of an IDirectMusicSegment
0079: //-----------------------------------------------------------------------------
0080: class CMusicSegment
0081: {
0082: protected:
0083:     IDirectMusicSegment8*     m_pSegment;
0084:     IDirectMusicLoader8*      m_pLoader;
0085:     IDirectMusicPerformance8* m_pPerformance;
0086:     IDirectMusicAudioPath8*   m_pEmbeddedAudioPath;
0087:     BOOL                      m_bDownloaded;
0088: 
0089: public:
0090:     CMusicSegment( IDirectMusicPerformance8* pPerformance, 
0091:                    IDirectMusicLoader8* pLoader,
0092:                    IDirectMusicSegment8* pSegment );
0093:     virtual ~CMusicSegment();
0094: 
0095:     inline  IDirectMusicSegment8* GetSegment() { return m_pSegment; }
0096:     HRESULT GetStyle( IDirectMusicStyle8** ppStyle, DWORD dwStyleIndex = 0 );
0097: 
0098:     HRESULT SetRepeats( DWORD dwRepeats );
0099:     virtual HRESULT Play( DWORD dwFlags = DMUS_SEGF_SECONDARY, IDirectMusicAudioPath8* pAudioPath = NULL );
0100:     HRESULT Stop( DWORD dwFlags = 0 );
0101:     HRESULT Download( IDirectMusicAudioPath8* pAudioPath = NULL );
0102:     HRESULT Unload( IDirectMusicAudioPath8* pAudioPath = NULL );
0103: 
0104:     BOOL    IsPlaying();
0105: };
0106: 
0107: 
0108: 
0109: 
0110: //-----------------------------------------------------------------------------
0111: // Name: class CMusicSegment
0112: // Desc: Encapsulates functionality of an IDirectMusicSegment
0113: //-----------------------------------------------------------------------------
0114: class C3DMusicSegment : public CMusicSegment
0115: {
0116: protected:
0117:     IDirectMusicAudioPath8* m_p3DAudioPath;
0118:     IDirectSound3DBuffer*   m_pDS3DBuffer;
0119: 
0120:     DS3DBUFFER              m_dsBufferParams;                  // 3D buffer properties
0121:     BOOL                    m_bDeferSettings;
0122:     BOOL                    m_bCleanupAudioPath;
0123: 
0124: public:
0125:     C3DMusicSegment( IDirectMusicPerformance8* pPerformance, 
0126:                    IDirectMusicLoader8* pLoader,
0127:                    IDirectMusicSegment8* pSegment,
0128:                    IDirectMusicAudioPath8* pAudioPath );
0129:     virtual ~C3DMusicSegment();
0130: 
0131:     HRESULT Init();
0132:     IDirectMusicAudioPath8* GetAudioPath() { return m_p3DAudioPath; }
0133:     HRESULT Play( DWORD dwFlags = DMUS_SEGF_SECONDARY, IDirectMusicAudioPath8* pAudioPath = NULL );
0134: 
0135:     VOID Set3DParameters( FLOAT fMinDistance,   FLOAT fMaxDistance );
0136:     VOID SetObjectProperties( D3DVECTOR* pvPosition, D3DVECTOR* pvVelocity );
0137: };
0138: 
0139: 
0140: 
0141: 
0142: //-----------------------------------------------------------------------------
0143: // Name: class CMusicScript
0144: // Desc: Encapsulates functionality of an IDirectMusicScript
0145: //-----------------------------------------------------------------------------
0146: class CMusicScript
0147: {
0148: protected:
0149:     IDirectMusicScript8*      m_pScript;
0150:     IDirectMusicLoader8*      m_pLoader;
0151:     IDirectMusicPerformance8* m_pPerformance;
0152: 
0153: public:
0154:     CMusicScript( IDirectMusicPerformance8* pPerformance, 
0155:                   IDirectMusicLoader8* pLoader,
0156:                   IDirectMusicScript8* pScript );
0157:     virtual ~CMusicScript();
0158: 
0159:     inline  IDirectMusicScript8* GetScript() { return m_pScript; }
0160: 
0161:     HRESULT CallRoutine( TCHAR* strRoutine );
0162:     HRESULT SetVariableNumber( TCHAR* strVariable, LONG lValue );
0163:     HRESULT GetVariableNumber( TCHAR* strVariable, LONG* plValue );
0164:     HRESULT SetVariableObject( TCHAR* strVariable, IUnknown *punkValue);
0165:     HRESULT GetVariableObject( TCHAR* strVariable, REFIID riid, LPVOID FAR *ppv);
0166: };
0167: 
0168: 
0169: 
0170: 
0171: #endif // DMUTIL_H
0172: