AudioEvents.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWAudio *
  23. * *
  24. * $Archive:: /Commando/Code/WWAudio/AudioEvents.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 11/02/01 11:56a $*
  29. * *
  30. * $Revision:: 4 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __AUDIO_EVENTS_H
  39. #define __AUDIO_EVENTS_H
  40. #include "simplevec.h"
  41. #include "bittype.h"
  42. #include "vector.h"
  43. /////////////////////////////////////////////////////////////////////////////////
  44. // Forward declarations
  45. /////////////////////////////////////////////////////////////////////////////////
  46. class SoundSceneObjClass;
  47. class LogicalListenerClass;
  48. class LogicalSoundClass;
  49. class AudibleSoundClass;
  50. class StringClass;
  51. /////////////////////////////////////////////////////////////////////////////////
  52. //
  53. // Global callbacks (C Style)
  54. //
  55. /////////////////////////////////////////////////////////////////////////////////
  56. //
  57. // Callback declarations. These functions are called when a registered event occurs
  58. // in the sound library/
  59. //
  60. typedef void (_stdcall *LPFNSOSCALLBACK) (SoundSceneObjClass *sound_obj, uint32 user_param);
  61. typedef void (_stdcall *LPFNEOSCALLBACK) (SoundSceneObjClass *sound_obj, uint32 user_param);
  62. typedef void (_stdcall *LPFNHEARDCALLBACK) (LogicalListenerClass *listener, LogicalSoundClass *sound_obj, uint32 user_param);
  63. typedef void (_stdcall *LPFNTEXTCALLBACK) (AudibleSoundClass *sound_obj, const StringClass &text, uint32 user_param);
  64. /////////////////////////////////////////////////////////////////////////////////
  65. //
  66. // Object callbacks (C++ Style)
  67. //
  68. /////////////////////////////////////////////////////////////////////////////////
  69. /////////////////////////////////////////////////////////////////////////////////
  70. //
  71. // AudioCallbackClass
  72. //
  73. // To use this callback mechanism, simply derive from this class and override
  74. // the methods you want notifications of. These methods will be called when
  75. // the event occurs.
  76. //
  77. /////////////////////////////////////////////////////////////////////////////////
  78. class AudioCallbackClass
  79. {
  80. public:
  81. /////////////////////////////////////////////////////////////////////////////////
  82. // Event identifiers
  83. /////////////////////////////////////////////////////////////////////////////////
  84. typedef enum
  85. {
  86. EVENT_NONE = 0x0000,
  87. EVENT_SOUND_STARTED = 0x0001,
  88. EVENT_SOUND_ENDED = 0x0002,
  89. EVENT_LOGICAL_HEARD = 0x0004
  90. } EVENTS;
  91. /////////////////////////////////////////////////////////////////////////////////
  92. // Public constructors/destructors
  93. /////////////////////////////////////////////////////////////////////////////////
  94. AudioCallbackClass (void);
  95. virtual ~AudioCallbackClass (void);
  96. /////////////////////////////////////////////////////////////////////////////////
  97. // Overrideables (callback-methods)
  98. /////////////////////////////////////////////////////////////////////////////////
  99. virtual void On_Sound_Started (SoundSceneObjClass *sound_obj) { }
  100. virtual void On_Sound_Ended (SoundSceneObjClass *sound_obj) { }
  101. virtual void On_Logical_Heard (LogicalListenerClass *listener, LogicalSoundClass *sound_obj) { }
  102. /////////////////////////////////////////////////////////////////////////////////
  103. // Housekeeping
  104. /////////////////////////////////////////////////////////////////////////////////
  105. void On_Registered (SoundSceneObjClass *sound);
  106. void On_UnRegistered (SoundSceneObjClass *sound);
  107. void Remove_All_Callbacks (void);
  108. /////////////////////////////////////////////////////////////////////////////////
  109. // Private member data
  110. /////////////////////////////////////////////////////////////////////////////////
  111. DynamicVectorClass<SoundSceneObjClass *> SoundList;
  112. };
  113. /////////////////////////////////////////////////////////////////////////////////
  114. //
  115. // Internal implementation
  116. //
  117. /////////////////////////////////////////////////////////////////////////////////
  118. /////////////////////////////////////////////////////////////////////////////////
  119. //
  120. // AudioCallbackListClass
  121. //
  122. /////////////////////////////////////////////////////////////////////////////////
  123. /////////////////////////////////////////////////////////////////////////////////
  124. // Protected structures
  125. /////////////////////////////////////////////////////////////////////////////////
  126. template <class T>
  127. struct AUDIO_CALLBACK_STRUCT
  128. {
  129. T callback_ptr;
  130. uint32 user_data;
  131. AUDIO_CALLBACK_STRUCT (void)
  132. : callback_ptr (NULL), user_data (0) {}
  133. AUDIO_CALLBACK_STRUCT (T _ptr, uint32 _data)
  134. : callback_ptr (_ptr), user_data (_data) {}
  135. };
  136. /////////////////////////////////////////////////////////////////////////////////
  137. // Protected structures
  138. /////////////////////////////////////////////////////////////////////////////////
  139. template <class T>
  140. class AudioCallbackListClass : public SimpleDynVecClass< AUDIO_CALLBACK_STRUCT<T> >
  141. {
  142. public:
  143. /////////////////////////////////////////////////////////////////////////////////
  144. // Public constructors/destructors
  145. /////////////////////////////////////////////////////////////////////////////////
  146. AudioCallbackListClass (void) { }
  147. virtual ~AudioCallbackListClass (void) { }
  148. /////////////////////////////////////////////////////////////////////////////////
  149. // Public methods
  150. /////////////////////////////////////////////////////////////////////////////////
  151. void Add_Callback (T pointer, uint32 user_data);
  152. T Get_Callback (int index, uint32 *user_data);
  153. void Remove_Callback (T pointer);
  154. };
  155. /////////////////////////////////////////////////////////////////////////////////
  156. // Add_Callback
  157. /////////////////////////////////////////////////////////////////////////////////
  158. template <class T> void
  159. AudioCallbackListClass<T>::Add_Callback (T pointer, uint32 user_data)
  160. {
  161. Add ( AUDIO_CALLBACK_STRUCT<T> (pointer, user_data));
  162. return ;
  163. }
  164. /////////////////////////////////////////////////////////////////////////////////
  165. // Get_Callback
  166. /////////////////////////////////////////////////////////////////////////////////
  167. template <class T> T
  168. AudioCallbackListClass<T>::Get_Callback (int index, uint32 *user_data)
  169. {
  170. if (user_data != NULL) {
  171. (*user_data) = Vector[index].user_data;
  172. }
  173. return Vector[index].callback_ptr;
  174. }
  175. /////////////////////////////////////////////////////////////////////////////////
  176. // Remove_Callback
  177. /////////////////////////////////////////////////////////////////////////////////
  178. template <class T> void
  179. AudioCallbackListClass<T>::Remove_Callback (T pointer)
  180. {
  181. for (int index = 0; index < ActiveCount; index ++) {
  182. if (Vector[index].callback_ptr == pointer) {
  183. Delete (index);
  184. break;
  185. }
  186. }
  187. return ;
  188. }
  189. #endif //__AUDIO_EVENTS_H