home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8a_sdk.exe / samples / multimedia / common / src / dmutil.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-04  |  22.4 KB  |  680 lines

  1. //-----------------------------------------------------------------------------
  2. // File: DMUtil.cpp
  3. //
  4. // Desc: DirectMusic framework classes for playing DirectMusic segments and
  5. //       DirectMusic scripts. Feel free to use this class as a starting point 
  6. //       for adding extra functionality.
  7. //
  8. // Copyright (c) 1999-2000 Microsoft Corp. All rights reserved.
  9. //-----------------------------------------------------------------------------
  10. #define STRICT
  11. #include <dmusicc.h>
  12. #include <dmusici.h>
  13. #include <dsound.h>
  14. #include <dxerr8.h>
  15. #include "DMUtil.h"
  16. #include "DXUtil.h"
  17.  
  18.  
  19.  
  20.  
  21. //-----------------------------------------------------------------------------
  22. // Name: CMusicManager::CMusicManager()
  23. // Desc: Constructs the class
  24. //-----------------------------------------------------------------------------
  25. CMusicManager::CMusicManager()
  26. {
  27.     m_pLoader       = NULL;
  28.     m_pPerformance  = NULL;
  29.     
  30.     // Initialize COM
  31.     CoInitialize(NULL);
  32. }
  33.  
  34.  
  35.  
  36.  
  37. //-----------------------------------------------------------------------------
  38. // Name: CMusicManager::~CMusicManager()
  39. // Desc: Destroys the class
  40. //-----------------------------------------------------------------------------
  41. CMusicManager::~CMusicManager()
  42. {
  43.     SAFE_RELEASE( m_pLoader ); 
  44.  
  45.     if( m_pPerformance )
  46.     {
  47.         // If there is any music playing, stop it.
  48.         m_pPerformance->Stop( NULL, NULL, 0, 0 );
  49.         m_pPerformance->CloseDown();
  50.  
  51.         SAFE_RELEASE( m_pPerformance );
  52.     }
  53.  
  54.     CoUninitialize();
  55. }
  56.  
  57.  
  58.  
  59.  
  60. //-----------------------------------------------------------------------------
  61. // Name: CMusicManager::Initialize()
  62. // Desc: Inits DirectMusic using a standard audio path
  63. //-----------------------------------------------------------------------------
  64. HRESULT CMusicManager::Initialize( HWND hWnd, DWORD dwPChannels, DWORD dwDefaultPathType )
  65. {
  66.     HRESULT hr;
  67.  
  68.     // Create loader object
  69.     if( FAILED( hr = CoCreateInstance( CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC, 
  70.                                        IID_IDirectMusicLoader8, (void**)&m_pLoader ) ) )
  71.         return DXTRACE_ERR( TEXT("CoCreateInstance"), hr );
  72.  
  73.     // Create performance object
  74.     if( FAILED( hr = CoCreateInstance( CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC, 
  75.                                        IID_IDirectMusicPerformance8, (void**)&m_pPerformance ) ) )
  76.         return DXTRACE_ERR( TEXT("CoCreateInstance"), hr );
  77.  
  78.     // Initialize the performance with the standard audio path.
  79.     // This initializes both DirectMusic and DirectSound and 
  80.     // sets up the synthesizer. Typcially its easist to use an 
  81.     // audio path for playing music and sound effects.
  82.     if( FAILED( hr = m_pPerformance->InitAudio( NULL, NULL, hWnd, dwDefaultPathType, 
  83.                                                 dwPChannels, DMUS_AUDIOF_ALL, NULL ) ) )
  84.         return DXTRACE_ERR( TEXT("InitAudio"), hr );
  85.  
  86.     return S_OK;
  87. }
  88.  
  89.  
  90.  
  91.  
  92. //-----------------------------------------------------------------------------
  93. // Name: CMusicManager::SetSearchDirectory()
  94. // Desc: Sets the search directory.  If not called, the current working
  95. //       directory is used to load content.
  96. //-----------------------------------------------------------------------------
  97. HRESULT CMusicManager::SetSearchDirectory( const TCHAR* strMediaPath )
  98. {
  99.     if( NULL == m_pLoader )
  100.         return E_UNEXPECTED;
  101.  
  102.     // DMusic only takes wide strings
  103.     WCHAR wstrMediaPath[MAX_PATH];
  104.     DXUtil_ConvertGenericStringToWide( wstrMediaPath, strMediaPath );
  105.  
  106.     return m_pLoader->SetSearchDirectory( GUID_DirectMusicAllTypes, 
  107.                                           wstrMediaPath, FALSE );
  108. }
  109.  
  110.  
  111.  
  112.  
  113. //-----------------------------------------------------------------------------
  114. // Name: CMusicManager::GetDefaultAudioPath()
  115. // Desc: 
  116. //-----------------------------------------------------------------------------
  117. IDirectMusicAudioPath8* CMusicManager::GetDefaultAudioPath()
  118. {
  119.     IDirectMusicAudioPath8* pAudioPath = NULL;
  120.     if( NULL == m_pPerformance )
  121.         return NULL;
  122.  
  123.     m_pPerformance->GetDefaultAudioPath( &pAudioPath );
  124.     return pAudioPath;
  125. }
  126.  
  127.  
  128.  
  129.  
  130. //-----------------------------------------------------------------------------
  131. // Name: CMusicManager::CollectGarbage()
  132. // Desc: Tells the loader to cleanup any garbage from previously 
  133. //       released objects.
  134. //-----------------------------------------------------------------------------
  135. VOID CMusicManager::CollectGarbage()
  136. {
  137.     if( m_pLoader )
  138.         m_pLoader->CollectGarbage();
  139. }
  140.  
  141.  
  142.  
  143.  
  144. //-----------------------------------------------------------------------------
  145. // Name: CMusicManager::CreateSegmentFromFile()
  146. // Desc: 
  147. //-----------------------------------------------------------------------------
  148. HRESULT CMusicManager::CreateSegmentFromFile( CMusicSegment** ppSegment, 
  149.                                               TCHAR* strFileName, 
  150.                                               BOOL bDownloadNow,
  151.                                               BOOL bIsMidiFile )
  152. {
  153.     HRESULT               hr;
  154.     IDirectMusicSegment8* pSegment = NULL;
  155.  
  156.     // DMusic only takes wide strings
  157.     WCHAR wstrFileName[MAX_PATH];
  158.     DXUtil_ConvertGenericStringToWide( wstrFileName, strFileName );
  159.  
  160.     if ( FAILED( hr = m_pLoader->LoadObjectFromFile( CLSID_DirectMusicSegment,
  161.                                                      IID_IDirectMusicSegment8,
  162.                                                      wstrFileName,
  163.                                                      (LPVOID*) &pSegment ) ) )
  164.     {
  165.         if( hr == DMUS_E_LOADER_FAILEDOPEN )
  166.             return hr;
  167.         return DXTRACE_ERR( TEXT("LoadObjectFromFile"), hr );
  168.     }
  169.  
  170.     *ppSegment = new CMusicSegment( m_pPerformance, m_pLoader, pSegment );
  171.     if (!*ppSegment)
  172.         return E_OUTOFMEMORY;
  173.  
  174.     if( bIsMidiFile )
  175.     {
  176.         if( FAILED( hr = pSegment->SetParam( GUID_StandardMIDIFile, 
  177.                                              0xFFFFFFFF, 0, 0, NULL ) ) )
  178.             return DXTRACE_ERR( TEXT("SetParam"), hr );
  179.     }
  180.  
  181.     if( bDownloadNow )
  182.     {
  183.         if( FAILED( hr = (*ppSegment)->Download() ) )
  184.             return DXTRACE_ERR( TEXT("Download"), hr );
  185.     }
  186.  
  187.     return S_OK;
  188. }
  189.  
  190.  
  191.  
  192.  
  193. //-----------------------------------------------------------------------------
  194. // Name: CMusicManager::CreateSegmentFromResource()
  195. // Desc: 
  196. //-----------------------------------------------------------------------------
  197. HRESULT CMusicManager::CreateSegmentFromResource( CMusicSegment** ppSegment, 
  198.                                                   TCHAR* strResource,
  199.                                                   TCHAR* strResourceType,
  200.                                                   BOOL bDownloadNow,
  201.                                                   BOOL bIsMidiFile )
  202. {
  203.     HRESULT               hr;
  204.     IDirectMusicSegment8* pSegment      = NULL;
  205.     HRSRC                 hres          = NULL;
  206.     void*                 pMem          = NULL;
  207.     DWORD                 dwSize        = 0;
  208.     DMUS_OBJECTDESC       objdesc;
  209.  
  210.     // Find the resource
  211.     hres = FindResource( NULL,strResource,strResourceType );
  212.     if( NULL == hres ) 
  213.         return E_FAIL;
  214.  
  215.     // Load the resource
  216.     pMem = (void*)LoadResource( NULL, hres );
  217.     if( NULL == pMem ) 
  218.         return E_FAIL;
  219.  
  220.     // Store the size of the resource
  221.     dwSize = SizeofResource( NULL, hres ); 
  222.     
  223.     // Set up our object description 
  224.     ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  225.     objdesc.dwSize = sizeof(DMUS_OBJECTDESC);
  226.     objdesc.dwValidData = DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS;
  227.     objdesc.guidClass = CLSID_DirectMusicSegment;
  228.     objdesc.llMemLength =(LONGLONG)dwSize;
  229.     objdesc.pbMemData = (BYTE*)pMem;
  230.     
  231.     if (FAILED ( hr = m_pLoader->GetObject( &objdesc,
  232.                                             IID_IDirectMusicSegment8,
  233.                                             (void**)&pSegment ) ) )
  234.     {
  235.         if( hr == DMUS_E_LOADER_FAILEDOPEN )
  236.             return hr;
  237.         return DXTRACE_ERR( TEXT("LoadObjectFromFile"), hr );
  238.     }
  239.  
  240.     *ppSegment = new CMusicSegment( m_pPerformance, m_pLoader, pSegment );
  241.     if( NULL == *ppSegment )
  242.         return E_OUTOFMEMORY;
  243.  
  244.     if( bIsMidiFile )
  245.     {
  246.         // Do this to make sure that the default General MIDI set 
  247.         // is connected appropriately to the MIDI file and 
  248.         // all instruments sound correct.                  
  249.         if( FAILED( hr = pSegment->SetParam( GUID_StandardMIDIFile, 
  250.                                              0xFFFFFFFF, 0, 0, NULL ) ) )
  251.             return DXTRACE_ERR( TEXT("SetParam"), hr );
  252.     }
  253.  
  254.     if( bDownloadNow )
  255.     {
  256.         // The segment needs to be download first before playing.  
  257.         // However, some apps may want to wait before calling this 
  258.         // to because the download allocates memory for the 
  259.         // instruments. The more instruments currently downloaded, 
  260.         // the more memory is in use by the synthesizer.
  261.         if( FAILED( hr = (*ppSegment)->Download() ) )
  262.             return DXTRACE_ERR( TEXT("Download"), hr );
  263.     }
  264.  
  265.     return S_OK;
  266. }
  267.  
  268.  
  269.  
  270.  
  271. //-----------------------------------------------------------------------------
  272. // Name: CMusicManager::CreateScriptFromFile()
  273. // Desc: 
  274. //-----------------------------------------------------------------------------
  275. HRESULT CMusicManager::CreateScriptFromFile( CMusicScript** ppScript, 
  276.                                              TCHAR* strFileName )
  277. {
  278.     HRESULT               hr;
  279.     IDirectMusicScript* pScript = NULL;
  280.  
  281.     // DMusic only takes wide strings
  282.     WCHAR wstrFileName[MAX_PATH];
  283.     DXUtil_ConvertGenericStringToWide( wstrFileName, strFileName );
  284.     
  285.     if ( FAILED( hr = m_pLoader->LoadObjectFromFile( CLSID_DirectMusicScript,
  286.                                                      IID_IDirectMusicScript8,
  287.                                                      wstrFileName,
  288.                                                      (LPVOID*) &pScript ) ) )
  289.         return DXTRACE_ERR( TEXT("LoadObjectFromFile"), hr );
  290.  
  291.     if ( FAILED( hr = pScript->Init( m_pPerformance, NULL ) ) )
  292.         return DXTRACE_ERR( TEXT("Init"), hr );
  293.  
  294.     *ppScript = new CMusicScript( m_pPerformance, m_pLoader, pScript );
  295.     if (!*ppScript)
  296.         return E_OUTOFMEMORY;
  297.  
  298.     return hr;
  299. }
  300.  
  301.  
  302.  
  303.  
  304. //-----------------------------------------------------------------------------
  305. // Name: CMusicManager::CreateChordMapFromFile()
  306. // Desc: 
  307. //-----------------------------------------------------------------------------
  308. HRESULT CMusicManager::CreateChordMapFromFile( IDirectMusicChordMap8** ppChordMap, 
  309.                                                TCHAR* strFileName )
  310. {
  311.     // DMusic only takes wide strings
  312.     WCHAR wstrFileName[MAX_PATH];
  313.     DXUtil_ConvertGenericStringToWide( wstrFileName, strFileName );
  314.  
  315.     return m_pLoader->LoadObjectFromFile( CLSID_DirectMusicChordMap,
  316.                                           IID_IDirectMusicChordMap8,
  317.                                           wstrFileName, (LPVOID*) ppChordMap );
  318. }
  319.  
  320.  
  321.  
  322.  
  323. //-----------------------------------------------------------------------------
  324. // Name: CMusicManager::CreateChordMapFromFile()
  325. // Desc: 
  326. //-----------------------------------------------------------------------------
  327. HRESULT CMusicManager::CreateStyleFromFile( IDirectMusicStyle8** ppStyle, 
  328.                                             TCHAR* strFileName )
  329. {
  330.     // DMusic only takes wide strings
  331.     WCHAR wstrFileName[MAX_PATH];
  332.     DXUtil_ConvertGenericStringToWide( wstrFileName, strFileName );
  333.  
  334.     return m_pLoader->LoadObjectFromFile( CLSID_DirectMusicStyle,
  335.                                           IID_IDirectMusicStyle8,
  336.                                           wstrFileName, (LPVOID*) ppStyle );
  337. }
  338.  
  339.  
  340.  
  341.  
  342. //-----------------------------------------------------------------------------
  343. // Name: CMusicManager::GetMotifFromStyle()
  344. // Desc: 
  345. //-----------------------------------------------------------------------------
  346. HRESULT CMusicManager::GetMotifFromStyle( IDirectMusicSegment8** ppMotif8, 
  347.                                           TCHAR* strStyle, TCHAR* strMotif )
  348. {       
  349.     HRESULT              hr;
  350.     IDirectMusicStyle8*  pStyle = NULL;
  351.     IDirectMusicSegment* pMotif = NULL;
  352.  
  353.     if( FAILED( hr = CreateStyleFromFile( &pStyle, strStyle ) ) )
  354.         return DXTRACE_ERR( TEXT("CreateStyleFromFile"), hr );
  355.  
  356.     if( pStyle )
  357.     {
  358.         // DMusic only takes wide strings
  359.         WCHAR wstrMotif[MAX_PATH];
  360.         DXUtil_ConvertGenericStringToWide( wstrMotif, strMotif );
  361.  
  362.         hr = pStyle->GetMotif( wstrMotif, &pMotif );
  363.         SAFE_RELEASE( pStyle );
  364.  
  365.         if( FAILED( hr ) )
  366.             return DXTRACE_ERR( TEXT("GetMotif"), hr );
  367.  
  368.         pMotif->QueryInterface( IID_IDirectMusicSegment8, (LPVOID*) ppMotif8 );
  369.     }
  370.  
  371.     return S_OK;
  372. }
  373.  
  374.  
  375.  
  376.  
  377. //-----------------------------------------------------------------------------
  378. // Name: CMusicSegment::CMusicSegment()
  379. // Desc: Constructs the class
  380. //-----------------------------------------------------------------------------
  381. CMusicSegment::CMusicSegment( IDirectMusicPerformance8* pPerformance, 
  382.                               IDirectMusicLoader8*      pLoader,
  383.                               IDirectMusicSegment8*     pSegment )
  384. {
  385.     m_pPerformance          = pPerformance;
  386.     m_pLoader               = pLoader;
  387.     m_pSegment              = pSegment;
  388.     m_pEmbeddedAudioPath    = NULL;
  389.     m_bDownloaded           = FALSE;
  390.     
  391.     // Try to pull out an audio path from the segment itself if there is one.
  392.     // This embedded audio path will be used instead of the default
  393.     // audio path if the app doesn't wish to use an overriding audio path.
  394.     IUnknown* pConfig = NULL;
  395.     if( SUCCEEDED( m_pSegment->GetAudioPathConfig( &pConfig ) ) )
  396.     {
  397.         m_pPerformance->CreateAudioPath( pConfig, TRUE, &m_pEmbeddedAudioPath );
  398.         SAFE_RELEASE( pConfig );
  399.     } 
  400.  
  401. }
  402.  
  403.  
  404.  
  405.  
  406. //-----------------------------------------------------------------------------
  407. // Name: CMusicSegment::~CMusicSegment()
  408. // Desc: Destroys the class
  409. //-----------------------------------------------------------------------------
  410. CMusicSegment::~CMusicSegment()
  411. {
  412.     if( m_pSegment )
  413.     {
  414.         // Tell the loader that this object should now be released
  415.         if( m_pLoader )
  416.             m_pLoader->ReleaseObjectByUnknown( m_pSegment );
  417.  
  418.         if( m_bDownloaded )
  419.         {
  420.             if( m_pEmbeddedAudioPath )
  421.                 m_pSegment->Unload( m_pEmbeddedAudioPath );
  422.             else
  423.                 m_pSegment->Unload( m_pPerformance );
  424.         }
  425.  
  426.         SAFE_RELEASE( m_pEmbeddedAudioPath ); 
  427.         SAFE_RELEASE( m_pSegment ); 
  428.     }
  429.  
  430.     m_pPerformance = NULL;
  431. }
  432.  
  433.  
  434.  
  435.  
  436. //-----------------------------------------------------------------------------
  437. // Name: CMusicSegment::Play()
  438. // Desc: Plays the sound using voice management flags.  Pass in DSBPLAY_LOOPING
  439. //       in the dwFlags to loop the sound
  440. //-----------------------------------------------------------------------------
  441. HRESULT CMusicSegment::Play( DWORD dwFlags, IDirectMusicAudioPath8* pAudioPath )
  442. {
  443.     if( m_pSegment == NULL || m_pPerformance == NULL )
  444.         return CO_E_NOTINITIALIZED;
  445.  
  446.     if( !m_bDownloaded )
  447.         return E_FAIL;
  448.  
  449.     // If an audio path was passed in then use it, otherwise
  450.     // use the embedded audio path if there was one.
  451.     if( pAudioPath == NULL && m_pEmbeddedAudioPath != NULL )
  452.         pAudioPath = m_pEmbeddedAudioPath;
  453.         
  454.     // If pAudioPath is NULL then this plays on the default audio path.
  455.     return m_pPerformance->PlaySegmentEx( m_pSegment, 0, NULL, dwFlags, 
  456.                                           0, 0, NULL, pAudioPath );
  457. }
  458.  
  459.  
  460.  
  461.  
  462.  
  463. //-----------------------------------------------------------------------------
  464. // Name: CMusicSegment::Download()
  465. // Desc: 
  466. //-----------------------------------------------------------------------------
  467. HRESULT CMusicSegment::Download( IDirectMusicAudioPath8* pAudioPath )
  468. {
  469.     HRESULT hr;
  470.     
  471.     if( m_pSegment == NULL )
  472.         return CO_E_NOTINITIALIZED;
  473.  
  474.     // If no audio path was passed in, then download
  475.     // to the embedded audio path if it exists 
  476.     // else download to the performance
  477.     if( pAudioPath == NULL )
  478.     {
  479.         if( m_pEmbeddedAudioPath )
  480.             hr = m_pSegment->Download( m_pEmbeddedAudioPath );
  481.         else    
  482.             hr = m_pSegment->Download( m_pPerformance );
  483.     }
  484.     else
  485.     {
  486.         hr = m_pSegment->Download( pAudioPath );
  487.     }
  488.     
  489.     if ( SUCCEEDED( hr ) )
  490.         m_bDownloaded = TRUE;
  491.         
  492.     return hr;
  493. }
  494.  
  495.  
  496.  
  497.  
  498. //-----------------------------------------------------------------------------
  499. // Name: CMusicSegment::Unload()
  500. // Desc: 
  501. //-----------------------------------------------------------------------------
  502. HRESULT CMusicSegment::Unload( IDirectMusicAudioPath8* pAudioPath )
  503. {
  504.     HRESULT hr;
  505.     
  506.     if( m_pSegment == NULL )
  507.         return CO_E_NOTINITIALIZED;
  508.  
  509.     // If no audio path was passed in, then unload 
  510.     // from the embedded audio path if it exists 
  511.     // else unload from the performance
  512.     if( pAudioPath == NULL )
  513.     {
  514.         if( m_pEmbeddedAudioPath )
  515.             hr = m_pSegment->Unload( m_pEmbeddedAudioPath );
  516.         else    
  517.             hr = m_pSegment->Unload( m_pPerformance );
  518.     }
  519.     else
  520.     {
  521.         hr = m_pSegment->Unload( pAudioPath );
  522.     }
  523.         
  524.     if ( SUCCEEDED( hr ) )
  525.         m_bDownloaded = FALSE;
  526.  
  527.     return hr;
  528. }
  529.  
  530.  
  531.  
  532.  
  533. //-----------------------------------------------------------------------------
  534. // Name: CMusicSegment::IsPlaying()
  535. // Desc: 
  536. //-----------------------------------------------------------------------------
  537. BOOL CMusicSegment::IsPlaying()
  538. {
  539.     if( m_pSegment == NULL || m_pPerformance == NULL )
  540.         return CO_E_NOTINITIALIZED;
  541.  
  542.     return ( m_pPerformance->IsPlaying( m_pSegment, NULL ) == S_OK );
  543. }
  544.  
  545.  
  546.  
  547.  
  548. //-----------------------------------------------------------------------------
  549. // Name: CMusicSegment::Stop()
  550. // Desc: Stops the sound from playing
  551. //-----------------------------------------------------------------------------
  552. HRESULT CMusicSegment::Stop( DWORD dwFlags )
  553. {
  554.     if( m_pSegment == NULL || m_pPerformance == NULL )
  555.         return CO_E_NOTINITIALIZED;
  556.  
  557.     return m_pPerformance->Stop( m_pSegment, NULL, 0, dwFlags );;
  558. }
  559.  
  560.  
  561.  
  562.  
  563. //-----------------------------------------------------------------------------
  564. // Name: CMusicSegment::SetRepeats()
  565. // Desc: 
  566. //-----------------------------------------------------------------------------
  567. HRESULT CMusicSegment::SetRepeats( DWORD dwRepeats )
  568. {
  569.     if( m_pSegment == NULL )
  570.         return CO_E_NOTINITIALIZED;
  571.  
  572.     return m_pSegment->SetRepeats( dwRepeats );
  573. }
  574.  
  575.  
  576.  
  577.  
  578. //-----------------------------------------------------------------------------
  579. // Name: CMusicSegment::GetStyle()
  580. // Desc: 
  581. //-----------------------------------------------------------------------------
  582. HRESULT CMusicSegment::GetStyle( IDirectMusicStyle8** ppStyle, DWORD dwStyleIndex )
  583. {
  584.     // Get the Style from the Segment by calling the Segment's GetData() with
  585.     // the data type GUID_StyleTrackStyle. 0xffffffff indicates to look at
  586.     // tracks in all TrackGroups in the segment. The first 0 indicates to
  587.     // retrieve the Style from the first Track  in the indicated TrackGroup.
  588.     // The second 0 indicates to retrieve the Style from the beginning of the
  589.     // segment, i.e. time 0 in Segment time. If this Segment was loaded from a
  590.     // section file, there is only one Style and it is at time 0.
  591.     return m_pSegment->GetParam( GUID_IDirectMusicStyle, 0xffffffff, dwStyleIndex, 
  592.                                  0, NULL, (VOID*)ppStyle );
  593. }
  594.  
  595.  
  596.  
  597. //-----------------------------------------------------------------------------
  598. // Name: CMusicScript::CMusicScript()
  599. // Desc: Constructs the class
  600. //-----------------------------------------------------------------------------
  601. CMusicScript::CMusicScript( IDirectMusicPerformance8* pPerformance, 
  602.                             IDirectMusicLoader8* pLoader,                   
  603.                             IDirectMusicScript8* pScript )
  604. {
  605.     m_pPerformance = pPerformance;
  606.     m_pLoader      = pLoader;
  607.     m_pScript      = pScript;
  608. }
  609.  
  610.  
  611.  
  612.  
  613. //-----------------------------------------------------------------------------
  614. // Name: CMusicScript::~CMusicScript()
  615. // Desc: Destroys the class
  616. //-----------------------------------------------------------------------------
  617. CMusicScript::~CMusicScript()
  618. {
  619.     if( m_pLoader )
  620.     {
  621.         // Tell the loader that this object should now be released
  622.         m_pLoader->ReleaseObjectByUnknown( m_pScript );
  623.         m_pLoader = NULL;
  624.     }
  625.  
  626.     SAFE_RELEASE( m_pScript ); 
  627.     m_pPerformance = NULL;
  628. }
  629.  
  630.  
  631.  
  632.  
  633. //-----------------------------------------------------------------------------
  634. // Name: CMusicScript::Play()
  635. // Desc: Calls a routine in the script
  636. //-----------------------------------------------------------------------------
  637. HRESULT CMusicScript::CallRoutine( TCHAR* strRoutine )
  638. {
  639.     // DMusic only takes wide strings
  640.     WCHAR wstrRoutine[MAX_PATH];
  641.     DXUtil_ConvertGenericStringToWide( wstrRoutine, strRoutine );
  642.  
  643.     return m_pScript->CallRoutine( wstrRoutine, NULL );
  644. }
  645.  
  646.  
  647.  
  648.  
  649. //-----------------------------------------------------------------------------
  650. // Name: CMusicScript::SetVariableNumber()
  651. // Desc: Sets the value of a variable in the script
  652. //-----------------------------------------------------------------------------
  653. HRESULT CMusicScript::SetVariableNumber( TCHAR* strVariable, LONG lValue )
  654. {
  655.     // DMusic only takes wide strings
  656.     WCHAR wstrVariable[MAX_PATH];
  657.     DXUtil_ConvertGenericStringToWide( wstrVariable, strVariable );
  658.  
  659.     return m_pScript->SetVariableNumber( wstrVariable, lValue, NULL );
  660. }
  661.  
  662.  
  663.  
  664.  
  665. //-----------------------------------------------------------------------------
  666. // Name: CMusicScript::GetVariableNumber()
  667. // Desc: Gets the value of a variable in the script
  668. //-----------------------------------------------------------------------------
  669. HRESULT CMusicScript::GetVariableNumber( TCHAR* strVariable, LONG* plValue )
  670. {
  671.     // DMusic only takes wide strings
  672.     WCHAR wstrVariable[MAX_PATH];
  673.     DXUtil_ConvertGenericStringToWide( wstrVariable, strVariable );
  674.  
  675.     return m_pScript->GetVariableNumber( wstrVariable, plValue, NULL );
  676. }
  677.  
  678.  
  679.  
  680.