PlaySoundDialog.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // PlaySoundDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "PlaySoundDialog.h"
  23. #include "Utils.H"
  24. #include "AudibleSound.H"
  25. #include "FileMgr.H"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. // PlaySoundDialogClass dialog
  33. PlaySoundDialogClass::PlaySoundDialogClass(LPCTSTR filename, CWnd* pParent /*=NULL*/)
  34. : m_Filename (filename),
  35. CDialog(PlaySoundDialogClass::IDD, pParent)
  36. {
  37. //{{AFX_DATA_INIT(PlaySoundDialogClass)
  38. // NOTE: the ClassWizard will add member initialization here
  39. //}}AFX_DATA_INIT
  40. }
  41. void PlaySoundDialogClass::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CDialog::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(PlaySoundDialogClass)
  45. // NOTE: the ClassWizard will add DDX and DDV calls here
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(PlaySoundDialogClass, CDialog)
  49. //{{AFX_MSG_MAP(PlaySoundDialogClass)
  50. ON_BN_CLICKED(IDC_PLAY_SOUND_EFFECT, OnPlaySoundEffect)
  51. ON_BN_CLICKED(IDC_STOP_SOUND_EFFECT, OnStopSoundEffect)
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54. /////////////////////////////////////////////////////////////////////////////
  55. //
  56. // OnPlaySoundEffect
  57. //
  58. /////////////////////////////////////////////////////////////////////////////
  59. void
  60. PlaySoundDialogClass::OnPlaySoundEffect (void)
  61. {
  62. ASSERT (m_pSoundObj != NULL);
  63. if (m_pSoundObj != NULL) {
  64. m_pSoundObj->Stop ();
  65. m_pSoundObj->Play ();
  66. }
  67. return ;
  68. }
  69. /////////////////////////////////////////////////////////////////////////////
  70. //
  71. // OnCancel
  72. //
  73. /////////////////////////////////////////////////////////////////////////////
  74. void
  75. PlaySoundDialogClass::OnCancel (void)
  76. {
  77. m_pSoundObj->Stop ();
  78. MEMBER_RELEASE (m_pSoundObj);
  79. CDialog::OnCancel ();
  80. return ;
  81. }
  82. /////////////////////////////////////////////////////////////////////////////
  83. //
  84. // OnInitDialog
  85. //
  86. /////////////////////////////////////////////////////////////////////////////
  87. BOOL
  88. PlaySoundDialogClass::OnInitDialog (void)
  89. {
  90. CDialog::OnInitDialog ();
  91. //
  92. // Put the filename into the dialog
  93. //
  94. CString filename = ::Get_File_Mgr ()->Make_Full_Path (m_Filename);
  95. SetDlgItemText (IDC_FILENAME, filename);
  96. //
  97. // Create the sound effect so we can play it
  98. //
  99. m_pSoundObj = WWAudioClass::Get_Instance ()->Create_Sound_Effect (filename);
  100. if (m_pSoundObj == NULL) {
  101. CString message;
  102. message.Format ("Cannot find sound file: %s!", (LPCTSTR)filename, MB_OK);
  103. MessageBox (message, "File Not Found", MB_ICONEXCLAMATION | MB_OK);
  104. EndDialog (IDCANCEL);
  105. } else {
  106. OnPlaySoundEffect ();
  107. }
  108. return TRUE;
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. //
  112. // OnStopSoundEffect
  113. //
  114. /////////////////////////////////////////////////////////////////////////////
  115. void
  116. PlaySoundDialogClass::OnStopSoundEffect (void)
  117. {
  118. ASSERT (m_pSoundObj != NULL);
  119. if (m_pSoundObj != NULL) {
  120. m_pSoundObj->Stop ();
  121. }
  122. return ;
  123. }