PlaySoundDialog.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 "playsounddialog.h"
  22. #include "utils.h"
  23. #include "audiblesound.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. //
  31. // PlaySoundDialogClass
  32. //
  33. /////////////////////////////////////////////////////////////////////////////
  34. PlaySoundDialogClass::PlaySoundDialogClass(LPCTSTR filename, CWnd* pParent /*=NULL*/)
  35. : Filename (filename),
  36. SoundObj (NULL),
  37. CDialog(PlaySoundDialogClass::IDD, pParent)
  38. {
  39. //{{AFX_DATA_INIT(PlaySoundDialogClass)
  40. // NOTE: the ClassWizard will add member initialization here
  41. //}}AFX_DATA_INIT
  42. return ;
  43. }
  44. /////////////////////////////////////////////////////////////////////////////
  45. //
  46. // DoDataExchange
  47. //
  48. /////////////////////////////////////////////////////////////////////////////
  49. void
  50. PlaySoundDialogClass::DoDataExchange (CDataExchange *pDX)
  51. {
  52. CDialog::DoDataExchange(pDX);
  53. //{{AFX_DATA_MAP(PlaySoundDialogClass)
  54. // NOTE: the ClassWizard will add DDX and DDV calls here
  55. //}}AFX_DATA_MAP
  56. return ;
  57. }
  58. BEGIN_MESSAGE_MAP(PlaySoundDialogClass, CDialog)
  59. //{{AFX_MSG_MAP(PlaySoundDialogClass)
  60. ON_BN_CLICKED(IDC_PLAY_SOUND_EFFECT, OnPlaySoundEffect)
  61. ON_BN_CLICKED(IDC_STOP_SOUND_EFFECT, OnStopSoundEffect)
  62. //}}AFX_MSG_MAP
  63. END_MESSAGE_MAP()
  64. /////////////////////////////////////////////////////////////////////////////
  65. //
  66. // OnPlaySoundEffect
  67. //
  68. /////////////////////////////////////////////////////////////////////////////
  69. void
  70. PlaySoundDialogClass::OnPlaySoundEffect (void)
  71. {
  72. ASSERT (SoundObj != NULL);
  73. if (SoundObj != NULL) {
  74. SoundObj->Stop ();
  75. SoundObj->Play ();
  76. }
  77. return ;
  78. }
  79. /////////////////////////////////////////////////////////////////////////////
  80. //
  81. // OnCancel
  82. //
  83. /////////////////////////////////////////////////////////////////////////////
  84. void
  85. PlaySoundDialogClass::OnCancel (void)
  86. {
  87. SoundObj->Stop ();
  88. MEMBER_RELEASE (SoundObj);
  89. CDialog::OnCancel ();
  90. return ;
  91. }
  92. /////////////////////////////////////////////////////////////////////////////
  93. //
  94. // OnInitDialog
  95. //
  96. /////////////////////////////////////////////////////////////////////////////
  97. BOOL
  98. PlaySoundDialogClass::OnInitDialog (void)
  99. {
  100. CDialog::OnInitDialog ();
  101. //
  102. // Put the filename into the dialog
  103. //
  104. SetDlgItemText (IDC_FILENAME, Filename);
  105. //
  106. // Create the sound effect so we can play it
  107. //
  108. SoundObj = WWAudioClass::Get_Instance ()->Create_Sound_Effect (Filename);
  109. if (SoundObj == NULL) {
  110. CString message;
  111. message.Format ("Cannot find sound file: %s!", (LPCTSTR)Filename, MB_OK);
  112. MessageBox (message, "File Not Found", MB_ICONEXCLAMATION | MB_OK);
  113. EndDialog (IDCANCEL);
  114. } else {
  115. OnPlaySoundEffect ();
  116. }
  117. return TRUE;
  118. }
  119. /////////////////////////////////////////////////////////////////////////////
  120. //
  121. // OnStopSoundEffect
  122. //
  123. /////////////////////////////////////////////////////////////////////////////
  124. void
  125. PlaySoundDialogClass::OnStopSoundEffect (void)
  126. {
  127. ASSERT (SoundObj != NULL);
  128. if (SoundObj != NULL) {
  129. SoundObj->Stop ();
  130. }
  131. return ;
  132. }