AudioBeam.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. using RootSystem = System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace Windows.Kinect
  5. {
  6. //
  7. // Windows.Kinect.AudioBeam
  8. //
  9. public sealed partial class AudioBeam : Helper.INativeWrapper
  10. {
  11. internal RootSystem.IntPtr _pNative;
  12. RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
  13. // Constructors and Finalizers
  14. internal AudioBeam(RootSystem.IntPtr pNative)
  15. {
  16. _pNative = pNative;
  17. Windows_Kinect_AudioBeam_AddRefObject(ref _pNative);
  18. }
  19. ~AudioBeam()
  20. {
  21. Dispose(false);
  22. }
  23. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  24. private static extern void Windows_Kinect_AudioBeam_ReleaseObject(ref RootSystem.IntPtr pNative);
  25. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  26. private static extern void Windows_Kinect_AudioBeam_AddRefObject(ref RootSystem.IntPtr pNative);
  27. private void Dispose(bool disposing)
  28. {
  29. if (_pNative == RootSystem.IntPtr.Zero)
  30. {
  31. return;
  32. }
  33. __EventCleanup();
  34. Helper.NativeObjectCache.RemoveObject<AudioBeam>(_pNative);
  35. Windows_Kinect_AudioBeam_ReleaseObject(ref _pNative);
  36. _pNative = RootSystem.IntPtr.Zero;
  37. }
  38. // Public Properties
  39. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  40. private static extern Windows.Kinect.AudioBeamMode Windows_Kinect_AudioBeam_get_AudioBeamMode(RootSystem.IntPtr pNative);
  41. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  42. private static extern void Windows_Kinect_AudioBeam_put_AudioBeamMode(RootSystem.IntPtr pNative, Windows.Kinect.AudioBeamMode audioBeamMode);
  43. public Windows.Kinect.AudioBeamMode AudioBeamMode
  44. {
  45. get
  46. {
  47. if (_pNative == RootSystem.IntPtr.Zero)
  48. {
  49. throw new RootSystem.ObjectDisposedException("AudioBeam");
  50. }
  51. return Windows_Kinect_AudioBeam_get_AudioBeamMode(_pNative);
  52. }
  53. set
  54. {
  55. if (_pNative == RootSystem.IntPtr.Zero)
  56. {
  57. throw new RootSystem.ObjectDisposedException("AudioBeam");
  58. }
  59. Windows_Kinect_AudioBeam_put_AudioBeamMode(_pNative, value);
  60. Helper.ExceptionHelper.CheckLastError();
  61. }
  62. }
  63. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  64. private static extern RootSystem.IntPtr Windows_Kinect_AudioBeam_get_AudioSource(RootSystem.IntPtr pNative);
  65. public Windows.Kinect.AudioSource AudioSource
  66. {
  67. get
  68. {
  69. if (_pNative == RootSystem.IntPtr.Zero)
  70. {
  71. throw new RootSystem.ObjectDisposedException("AudioBeam");
  72. }
  73. RootSystem.IntPtr objectPointer = Windows_Kinect_AudioBeam_get_AudioSource(_pNative);
  74. Helper.ExceptionHelper.CheckLastError();
  75. if (objectPointer == RootSystem.IntPtr.Zero)
  76. {
  77. return null;
  78. }
  79. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.AudioSource>(objectPointer, n => new Windows.Kinect.AudioSource(n));
  80. }
  81. }
  82. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  83. private static extern float Windows_Kinect_AudioBeam_get_BeamAngle(RootSystem.IntPtr pNative);
  84. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  85. private static extern void Windows_Kinect_AudioBeam_put_BeamAngle(RootSystem.IntPtr pNative, float beamAngle);
  86. public float BeamAngle
  87. {
  88. get
  89. {
  90. if (_pNative == RootSystem.IntPtr.Zero)
  91. {
  92. throw new RootSystem.ObjectDisposedException("AudioBeam");
  93. }
  94. return Windows_Kinect_AudioBeam_get_BeamAngle(_pNative);
  95. }
  96. set
  97. {
  98. if (_pNative == RootSystem.IntPtr.Zero)
  99. {
  100. throw new RootSystem.ObjectDisposedException("AudioBeam");
  101. }
  102. Windows_Kinect_AudioBeam_put_BeamAngle(_pNative, value);
  103. Helper.ExceptionHelper.CheckLastError();
  104. }
  105. }
  106. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  107. private static extern float Windows_Kinect_AudioBeam_get_BeamAngleConfidence(RootSystem.IntPtr pNative);
  108. public float BeamAngleConfidence
  109. {
  110. get
  111. {
  112. if (_pNative == RootSystem.IntPtr.Zero)
  113. {
  114. throw new RootSystem.ObjectDisposedException("AudioBeam");
  115. }
  116. return Windows_Kinect_AudioBeam_get_BeamAngleConfidence(_pNative);
  117. }
  118. }
  119. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  120. private static extern long Windows_Kinect_AudioBeam_get_RelativeTime(RootSystem.IntPtr pNative);
  121. public RootSystem.TimeSpan RelativeTime
  122. {
  123. get
  124. {
  125. if (_pNative == RootSystem.IntPtr.Zero)
  126. {
  127. throw new RootSystem.ObjectDisposedException("AudioBeam");
  128. }
  129. return RootSystem.TimeSpan.FromMilliseconds(Windows_Kinect_AudioBeam_get_RelativeTime(_pNative));
  130. }
  131. }
  132. // Events
  133. private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Data_PropertyChangedEventArgs_Delegate_Handle;
  134. [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
  135. private delegate void _Windows_Data_PropertyChangedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
  136. private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>>> Windows_Data_PropertyChangedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>>>();
  137. [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Data_PropertyChangedEventArgs_Delegate))]
  138. private static void Windows_Data_PropertyChangedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
  139. {
  140. List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>> callbackList = null;
  141. Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
  142. lock(callbackList)
  143. {
  144. var objThis = Helper.NativeObjectCache.GetObject<AudioBeam>(pNative);
  145. var args = new Windows.Data.PropertyChangedEventArgs(result);
  146. foreach(var func in callbackList)
  147. {
  148. Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
  149. }
  150. }
  151. }
  152. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  153. private static extern void Windows_Kinect_AudioBeam_add_PropertyChanged(RootSystem.IntPtr pNative, _Windows_Data_PropertyChangedEventArgs_Delegate eventCallback, bool unsubscribe);
  154. public event RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs> PropertyChanged
  155. {
  156. add
  157. {
  158. Helper.EventPump.EnsureInitialized();
  159. Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  160. var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
  161. lock (callbackList)
  162. {
  163. callbackList.Add(value);
  164. if(callbackList.Count == 1)
  165. {
  166. var del = new _Windows_Data_PropertyChangedEventArgs_Delegate(Windows_Data_PropertyChangedEventArgs_Delegate_Handler);
  167. _Windows_Data_PropertyChangedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
  168. Windows_Kinect_AudioBeam_add_PropertyChanged(_pNative, del, false);
  169. }
  170. }
  171. }
  172. remove
  173. {
  174. if (_pNative == RootSystem.IntPtr.Zero)
  175. {
  176. return;
  177. }
  178. Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  179. var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
  180. lock (callbackList)
  181. {
  182. callbackList.Remove(value);
  183. if(callbackList.Count == 0)
  184. {
  185. Windows_Kinect_AudioBeam_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
  186. _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
  187. }
  188. }
  189. }
  190. }
  191. // Public Methods
  192. private void __EventCleanup()
  193. {
  194. {
  195. Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  196. var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
  197. lock (callbackList)
  198. {
  199. if (callbackList.Count > 0)
  200. {
  201. callbackList.Clear();
  202. if (_pNative != RootSystem.IntPtr.Zero)
  203. {
  204. Windows_Kinect_AudioBeam_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
  205. }
  206. _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
  207. }
  208. }
  209. }
  210. }
  211. }
  212. }