AudioEvents.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. ** Command & Conquer Generals(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:: 5/24/00 5:40p $*
  29. * *
  30. * $Revision:: 3 $*
  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. /////////////////////////////////////////////////////////////////////////////////
  43. // Forward declarations
  44. /////////////////////////////////////////////////////////////////////////////////
  45. class SoundSceneObjClass;
  46. class LogicalListenerClass;
  47. class LogicalSoundClass;
  48. class AudibleSoundClass;
  49. class StringClass;
  50. /////////////////////////////////////////////////////////////////////////////////
  51. //
  52. // Global callbacks (C Style)
  53. //
  54. /////////////////////////////////////////////////////////////////////////////////
  55. //
  56. // Callback declarations. These functions are called when a registered event occurs
  57. // in the sound library/
  58. //
  59. typedef void (_stdcall *LPFNSOSCALLBACK) (SoundSceneObjClass *sound_obj, uint32 user_param);
  60. typedef void (_stdcall *LPFNEOSCALLBACK) (SoundSceneObjClass *sound_obj, uint32 user_param);
  61. typedef void (_stdcall *LPFNHEARDCALLBACK) (LogicalListenerClass *listener, LogicalSoundClass *sound_obj, uint32 user_param);
  62. typedef void (_stdcall *LPFNTEXTCALLBACK) (AudibleSoundClass *sound_obj, const StringClass &text, uint32 user_param);
  63. /////////////////////////////////////////////////////////////////////////////////
  64. //
  65. // Object callbacks (C++ Style)
  66. //
  67. /////////////////////////////////////////////////////////////////////////////////
  68. /////////////////////////////////////////////////////////////////////////////////
  69. //
  70. // AudioCallbackClass
  71. //
  72. // To use this callback mechanism, simply derive from this class and override
  73. // the methods you want notifications of. These methods will be called when
  74. // the event occurs.
  75. //
  76. /////////////////////////////////////////////////////////////////////////////////
  77. class AudioCallbackClass
  78. {
  79. public:
  80. /////////////////////////////////////////////////////////////////////////////////
  81. // Event identifiers
  82. /////////////////////////////////////////////////////////////////////////////////
  83. typedef enum
  84. {
  85. EVENT_NONE = 0x0000,
  86. EVENT_SOUND_STARTED = 0x0001,
  87. EVENT_SOUND_ENDED = 0x0002,
  88. EVENT_LOGICAL_HEARD = 0x0004
  89. } EVENTS;
  90. /////////////////////////////////////////////////////////////////////////////////
  91. // Overrideables (callback-methods)
  92. /////////////////////////////////////////////////////////////////////////////////
  93. virtual void On_Sound_Started (SoundSceneObjClass *sound_obj) { }
  94. virtual void On_Sound_Ended (SoundSceneObjClass *sound_obj) { }
  95. virtual void On_Logical_Heard (LogicalListenerClass *listener, LogicalSoundClass *sound_obj) { }
  96. };
  97. /////////////////////////////////////////////////////////////////////////////////
  98. //
  99. // Internal implementation
  100. //
  101. /////////////////////////////////////////////////////////////////////////////////
  102. /////////////////////////////////////////////////////////////////////////////////
  103. //
  104. // AudioCallbackListClass
  105. //
  106. /////////////////////////////////////////////////////////////////////////////////
  107. /////////////////////////////////////////////////////////////////////////////////
  108. // Protected structures
  109. /////////////////////////////////////////////////////////////////////////////////
  110. template <class T>
  111. struct AUDIO_CALLBACK_STRUCT
  112. {
  113. T callback_ptr;
  114. uint32 user_data;
  115. AUDIO_CALLBACK_STRUCT (void)
  116. : callback_ptr (NULL), user_data (0) {}
  117. AUDIO_CALLBACK_STRUCT (T _ptr, uint32 _data)
  118. : callback_ptr (_ptr), user_data (_data) {}
  119. };
  120. /////////////////////////////////////////////////////////////////////////////////
  121. // Protected structures
  122. /////////////////////////////////////////////////////////////////////////////////
  123. template <class T>
  124. class AudioCallbackListClass : public SimpleDynVecClass< AUDIO_CALLBACK_STRUCT<T> >
  125. {
  126. public:
  127. /////////////////////////////////////////////////////////////////////////////////
  128. // Public constructors/destructors
  129. /////////////////////////////////////////////////////////////////////////////////
  130. AudioCallbackListClass (void) { }
  131. virtual ~AudioCallbackListClass (void) { }
  132. /////////////////////////////////////////////////////////////////////////////////
  133. // Public methods
  134. /////////////////////////////////////////////////////////////////////////////////
  135. void Add_Callback (T pointer, uint32 user_data);
  136. T Get_Callback (int index, uint32 *user_data);
  137. void Remove_Callback (T pointer);
  138. };
  139. /////////////////////////////////////////////////////////////////////////////////
  140. // Add_Callback
  141. /////////////////////////////////////////////////////////////////////////////////
  142. template <class T> void
  143. AudioCallbackListClass<T>::Add_Callback (T pointer, uint32 user_data)
  144. {
  145. Add ( AUDIO_CALLBACK_STRUCT<T> (pointer, user_data));
  146. return ;
  147. }
  148. /////////////////////////////////////////////////////////////////////////////////
  149. // Get_Callback
  150. /////////////////////////////////////////////////////////////////////////////////
  151. template <class T> T
  152. AudioCallbackListClass<T>::Get_Callback (int index, uint32 *user_data)
  153. {
  154. if (user_data != NULL) {
  155. (*user_data) = Vector[index].user_data;
  156. }
  157. return Vector[index].callback_ptr;
  158. }
  159. /////////////////////////////////////////////////////////////////////////////////
  160. // Remove_Callback
  161. /////////////////////////////////////////////////////////////////////////////////
  162. template <class T> void
  163. AudioCallbackListClass<T>::Remove_Callback (T pointer)
  164. {
  165. for (int index = 0; index < ActiveCount; index ++) {
  166. if (Vector[index].callback_ptr == pointer) {
  167. Delete (index);
  168. break;
  169. }
  170. }
  171. return ;
  172. }
  173. #endif //__AUDIO_EVENTS_H