Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.93 KB | None | 0 0
  1. diff --git a/src/CoreHaptics/Enums.cs b/src/CoreHaptics/Enums.cs
  2. new file mode 100644
  3. index 000000000..ad79f9bb2
  4. --- /dev/null
  5. +++ b/src/CoreHaptics/Enums.cs
  6. @@ -0,0 +1,144 @@
  7. +//
  8. +// CoreHaptics C# bindings
  9. +//
  10. +// Authors:
  11. +// Manuel de la Pena Saenz <mandel@microsoft.com>
  12. +//
  13. +// Copyright 2019 Microsoft Corporation All rights reserved.
  14. +//
  15. +using System;
  16. +using Foundation;
  17. +using ObjCRuntime;
  18. +
  19. +namespace CoreHaptics {
  20. +
  21. + [Mac (10, 15), iOS (13, 0)]
  22. + public enum CHHapticEventParameterId {
  23. + [Field ("CHHapticEventParameterIDHapticIntensity")]
  24. + HapticIntensity,
  25. +
  26. + [Field ("CHHapticEventParameterIDHapticSharpness")]
  27. + HapticSharpness,
  28. +
  29. + [Field ("CHHapticEventParameterIDAttackTime")]
  30. + AttackTime,
  31. +
  32. + [Field ("CHHapticEventParameterIDDecayTime")]
  33. + DecayTime,
  34. +
  35. + [Field ("CHHapticEventParameterIDReleaseTime")]
  36. + ReleaseTime,
  37. +
  38. + [Field ("CHHapticEventParameterIDSustained")]
  39. + Sustained,
  40. +
  41. + [Field ("CHHapticEventParameterIDAudioVolume")]
  42. + AudioVolume,
  43. +
  44. + [Field ("CHHapticEventParameterIDAudioPitch")]
  45. + AudioPitch,
  46. +
  47. + [Field ("CHHapticEventParameterIDAudioPan")]
  48. + AudioPan,
  49. +
  50. + [Field ("CHHapticEventParameterIDAudioBrightness")]
  51. + AudioBrightness,
  52. + }
  53. +
  54. + [Mac (10, 15), iOS (13, 0)]
  55. + public enum CHHapticDynamicParameterId {
  56. + [Field ("CHHapticDynamicParameterIDHapticIntensityControl")]
  57. + HapticDynamicParameterIDHapticIntensityControl,
  58. +
  59. + [Field ("CHHapticDynamicParameterIDHapticSharpnessControl")]
  60. + HapticSharpnessControl,
  61. +
  62. + [Field ("CHHapticDynamicParameterIDHapticAttackTimeControl")]
  63. + HapticAttackTimeControl,
  64. +
  65. + [Field ("CHHapticDynamicParameterIDHapticDecayTimeControl")]
  66. + HapticDecayTimeControl,
  67. +
  68. + [Field ("CHHapticDynamicParameterIDHapticReleaseTimeControl")]
  69. + HapticReleaseTimeControl,
  70. +
  71. + [Field ("CHHapticDynamicParameterIDAudioVolumeControl")]
  72. + AudioVolumeControl,
  73. +
  74. + [Field ("CHHapticDynamicParameterIDAudioPanControl")]
  75. + AudioPanControl,
  76. +
  77. + [Field ("CHHapticDynamicParameterIDAudioBrightnessControl")]
  78. + AudioBrightnessControl,
  79. +
  80. + [Field ("CHHapticDynamicParameterIDAudioPitchControl")]
  81. + AudioPitchControl,
  82. +
  83. + [Field ("CHHapticDynamicParameterIDAudioAttackTimeControl")]
  84. + AudioAttackTimeControl,
  85. +
  86. + [Field ("CHHapticDynamicParameterIDAudioDecayTimeControl")]
  87. + AudioDecayTimeControl,
  88. +
  89. + [Field ("CHHapticDynamicParameterIDAudioReleaseTimeControl")]
  90. + AudioReleaseTimeControl,
  91. + }
  92. +
  93. + [Mac (10, 15), iOS (13, 0)]
  94. + public enum CHHapticEventType {
  95. + [Field ("CHHapticEventTypeHapticTransient")]
  96. + HapticTransient,
  97. +
  98. + [Field ("CHHapticEventTypeHapticContinuous")]
  99. + HapticContinuous,
  100. +
  101. + [Field ("CHHapticEventTypeAudioContinuous")]
  102. + AudioContinuous,
  103. +
  104. + [Field ("CHHapticEventTypeAudioCustom")]
  105. + AudioCustom,
  106. + }
  107. +
  108. + [Mac (10,15), iOS (13,0)]
  109. + [Native]
  110. + public enum CHHapticErrorCode : long {
  111. + EngineNotRunning = -4805,
  112. + OperationNotPermitted = -4806,
  113. + EngineStartTimeout = -4808,
  114. + NotSupported = -4809,
  115. + ServerInitFailed = -4810,
  116. + ServerInterrupted = -4811,
  117. + InvalidPatternPlayer = -4812,
  118. + InvalidPatternData = -4813,
  119. + InvalidPatternDictionary = -4814,
  120. + InvalidAudioSession = -4815,
  121. + InvalidParameterType = -4820,
  122. + InvalidEventType = -4821,
  123. + InvalidEventTime = -4822,
  124. + InvalidEventDuration = -4823,
  125. + InvalidAudioResource = -4824,
  126. + ResourceNotAvailable = -4825,
  127. + BadEventEntry = -4830,
  128. + BadParameterEntry = -4831,
  129. + InvalidTime = -4840,
  130. + UnknownError = -4898,
  131. + MemoryError = -4899,
  132. + }
  133. +
  134. + [Mac (10,15), iOS (13,0)]
  135. + [Native]
  136. + public enum CHHapticEngineFinishedAction : long {
  137. + StopEngine = 1,
  138. + LeaveEngineRunning = 2
  139. + }
  140. +
  141. + [Mac (10,15), iOS (13,0)]
  142. + [Native]
  143. + public enum CHHapticEngineStoppedReason : long {
  144. + AudioSessionInterrupt = 1,
  145. + ApplicationSuspended = 2,
  146. + IdleTimeout = 3,
  147. + NotifyWhenFinished = 4,
  148. + SystemError = -1,
  149. + }
  150. +}
  151. \ No newline at end of file
  152. diff --git a/src/corehaptics.cs b/src/corehaptics.cs
  153. new file mode 100644
  154. index 000000000..cc250153a
  155. --- /dev/null
  156. +++ b/src/corehaptics.cs
  157. @@ -0,0 +1,393 @@
  158. +//
  159. +// CoreHaptics C# bindings
  160. +//
  161. +// Authors:
  162. +// Manuel de la Pena Saenz <mandel@microsoft.com>
  163. +//
  164. +// Copyright 2019 Microsoft Corporation All rights reserved.
  165. +//
  166. +
  167. +using System;
  168. +
  169. +#if !MONOMAC
  170. +using AVFoundation;
  171. +#endif
  172. +using CoreFoundation;
  173. +using Foundation;
  174. +using ObjCRuntime;
  175. +
  176. +namespace CoreHaptics {
  177. +
  178. +#if MONOMAC
  179. + interface AVAudioSession {}
  180. +#endif
  181. +
  182. + [Mac (10,15), iOS (13,0)]
  183. + [BaseType (typeof(NSObject))]
  184. + [DisableDefaultCtor]
  185. + interface CHHapticEventParameter {
  186. + [BindAs (typeof (CHHapticEventParameterId))]
  187. + [Export ("parameterID")]
  188. + NSString ParameterId { get; }
  189. +
  190. + [Export ("value")]
  191. + float Value { get; set; }
  192. +
  193. + [Export ("initWithParameterID:value:")]
  194. + [DesignatedInitializer]
  195. + IntPtr Constructor ([BindAs (typeof (CHHapticEventParameterId))] NSString parameterId, float value);
  196. + }
  197. +
  198. + [Mac (10,15), iOS (13,0)]
  199. + [BaseType (typeof(NSObject))]
  200. + [DisableDefaultCtor]
  201. + interface CHHapticDynamicParameter {
  202. + [BindAs (typeof (CHHapticDynamicParameterId))]
  203. + [Export ("parameterID")]
  204. + NSString ParameterId { get; }
  205. +
  206. + [Export ("value")]
  207. + float Value { get; set; }
  208. +
  209. + [Export ("relativeTime")]
  210. + double RelativeTime { get; set; }
  211. +
  212. + [Export ("initWithParameterID:value:relativeTime:")]
  213. + [DesignatedInitializer]
  214. + IntPtr Constructor ([BindAs (typeof (CHHapticDynamicParameterId))] NSString parameterId, float value, double time);
  215. + }
  216. +
  217. + [Mac (10,15), iOS (13,0)]
  218. + [BaseType (typeof(NSObject))]
  219. + [DisableDefaultCtor]
  220. + interface CHHapticParameterCurveControlPoint {
  221. + [Export ("relativeTime")]
  222. + double RelativeTime { get; set; }
  223. +
  224. + [Export ("value")]
  225. + float Value { get; set; }
  226. +
  227. + [Export ("initWithRelativeTime:value:")]
  228. + [DesignatedInitializer]
  229. + IntPtr Constructor (double time, float value);
  230. + }
  231. +
  232. + [Mac (10,15), iOS (13,0)]
  233. + [BaseType (typeof(NSObject))]
  234. + [DisableDefaultCtor]
  235. + interface CHHapticParameterCurve {
  236. + [BindAs (typeof (CHHapticDynamicParameterId))]
  237. + [Export ("parameterID")]
  238. + NSString ParameterId { get; }
  239. +
  240. + [Export ("relativeTime")]
  241. + double RelativeTime { get; set; }
  242. +
  243. + [Export ("controlPoints")]
  244. + CHHapticParameterCurveControlPoint[] ControlPoints { get; }
  245. +
  246. + [Export ("initWithParameterID:controlPoints:relativeTime:")]
  247. + [DesignatedInitializer]
  248. + IntPtr Constructor ([BindAs (typeof (CHHapticDynamicParameterId))]NSString parameterID, CHHapticParameterCurveControlPoint[] controlPoints, double relativeTime);
  249. + }
  250. +
  251. + [Mac (10,15), iOS (13,0)]
  252. + [BaseType (typeof(NSObject))]
  253. + [DisableDefaultCtor]
  254. + interface CHHapticEvent {
  255. + [BindAs (typeof (CHHapticEventType))]
  256. + [Export ("type")]
  257. + NSString Type { get; }
  258. +
  259. + [Export ("eventParameters")]
  260. + CHHapticEventParameter[] EventParameters { get; }
  261. +
  262. + [Export ("relativeTime")]
  263. + double RelativeTime { get; set; }
  264. +
  265. + [Export ("duration")]
  266. + double Duration { get; set; }
  267. +
  268. + [Export ("initWithEventType:parameters:relativeTime:")]
  269. + IntPtr Constructor ([BindAs (typeof (CHHapticEventType))] NSString type, CHHapticEventParameter[] eventParams, double time);
  270. +
  271. + [Export ("initWithEventType:parameters:relativeTime:duration:")]
  272. + IntPtr Constructor ([BindAs (typeof (CHHapticEventType))] NSString type, CHHapticEventParameter[] eventParams, double time, double duration);
  273. +
  274. + [Export ("initWithAudioResourceID:parameters:relativeTime:")]
  275. + IntPtr Constructor (nuint resourceId, CHHapticEventParameter[] eventParams, double time);
  276. +
  277. + [Export ("initWithAudioResourceID:parameters:relativeTime:duration:")]
  278. + IntPtr Constructor (nuint resourceId, CHHapticEventParameter[] eventParams, double time, double duration);
  279. + }
  280. +
  281. + [Mac (10,15), iOS (13,0)]
  282. + [Protocol]
  283. + [BaseType (typeof(NSObject))]
  284. + interface CHHapticParameterAttributes {
  285. + [Abstract]
  286. + [Export ("minValue")]
  287. + float MinValue { get; }
  288. +
  289. + [Abstract]
  290. + [Export ("maxValue")]
  291. + float MaxValue { get; }
  292. +
  293. + [Abstract]
  294. + [Export ("defaultValue")]
  295. + float DefaultValue { get; }
  296. + }
  297. +
  298. + interface ICHHapticDeviceCapability { }
  299. +
  300. + [iOS (13,0)]
  301. + [Protocol]
  302. + interface CHHapticDeviceCapability {
  303. + [Abstract]
  304. + [Export ("supportsHaptics")]
  305. + bool SupportsHaptics { get; }
  306. +
  307. + [Abstract]
  308. + [Export ("supportsAudio")]
  309. + bool SupportsAudio { get; }
  310. +
  311. + // Protocols do not like BindAs yet we know is the enum CHHapticEventType
  312. + [Abstract]
  313. + [Export ("attributesForEventParameter:eventType:error:")]
  314. + [return: NullAllowed]
  315. + CHHapticParameterAttributes GetAttributes (string eventParameter, string type, [NullAllowed] out NSError outError);
  316. +
  317. + // Protocols do not like BindAs yet we know is the enum CHHapticEventType
  318. + [Abstract]
  319. + [Export ("attributesForDynamicParameter:error:")]
  320. + [return: NullAllowed]
  321. + CHHapticParameterAttributes GetAttributes (string eventParameter, [NullAllowed] out NSError outError);
  322. + }
  323. +
  324. + [Mac (10,15), iOS (13,0)]
  325. + [Protocol]
  326. + [BaseType (typeof(NSObject))]
  327. + interface CHHapticPatternPlayer {
  328. + [Abstract]
  329. + [Export ("startAtTime:error:")]
  330. + bool StartAtTime (double time, [NullAllowed] out NSError outError);
  331. +
  332. + [Abstract]
  333. + [Export ("stopAtTime:error:")]
  334. + bool StopAtTime (double time, [NullAllowed] out NSError outError);
  335. +
  336. + [Abstract]
  337. + [Export ("sendParameters:atTime:error:")]
  338. + bool Send (CHHapticDynamicParameter[] parameters, double time, [NullAllowed] out NSError outError);
  339. +
  340. + [Abstract]
  341. + [Export ("scheduleParameterCurve:atTime:error:")]
  342. + bool Schedule (CHHapticParameterCurve parameterCurve, double time, [NullAllowed] out NSError outError);
  343. +
  344. + [Abstract]
  345. + [Export ("cancelAndReturnError:")]
  346. + bool Cancel ([NullAllowed] out NSError outError);
  347. +
  348. + [Abstract]
  349. + [Export ("isMuted")]
  350. + bool IsMuted { get; set; }
  351. + }
  352. +
  353. + interface ICHHapticAdvancedPatternPlayer {}
  354. +
  355. + [Mac (10,15), iOS (13,0)]
  356. + [Protocol]
  357. + interface CHHapticAdvancedPatternPlayer : CHHapticPatternPlayer {
  358. + [Abstract]
  359. + [Export ("pauseAtTime:error:")]
  360. + bool Pause (double time, [NullAllowed] out NSError outError);
  361. +
  362. + [Abstract]
  363. + [Export ("resumeAtTime:error:")]
  364. + bool Resume (double time, [NullAllowed] out NSError outError);
  365. +
  366. + [Abstract]
  367. + [Export ("seekToOffset:error:")]
  368. + bool Seek (double offsetTime, [NullAllowed] out NSError outError);
  369. +
  370. + [Abstract]
  371. + [Export ("loopEnabled")]
  372. + bool LoopEnabled { get; set; }
  373. +
  374. + [Abstract]
  375. + [Export ("loopEnd")]
  376. + double LoopEnd { get; set; }
  377. +
  378. + [Abstract]
  379. + [Export ("playbackRate")]
  380. + float PlaybackRate { get; set; }
  381. +
  382. + [Abstract]
  383. + [Export ("completionHandler", ArgumentSemantic.Assign)]
  384. + Action<NSError> CompletionHandler { get; set; }
  385. + }
  386. +
  387. + [NoMac, iOS (13,0)]
  388. + [BaseType (typeof(NSObject))]
  389. + [DisableDefaultCtor]
  390. + interface CHHapticEngine
  391. + {
  392. + [Static]
  393. + [Export ("capabilitiesForHardware")]
  394. + ICHHapticDeviceCapability CapabilitiesForHardware { get; }
  395. +
  396. + [Export ("currentTime")]
  397. + double CurrentTime { get; }
  398. +
  399. + [Export ("stoppedHandler", ArgumentSemantic.Assign)]
  400. + Action<CHHapticEngineStoppedReason> StoppedHandler { get; set; }
  401. +
  402. + [Export ("resetHandler", ArgumentSemantic.Assign)]
  403. + Action ResetHandler { get; set; }
  404. +
  405. + [Export ("playsHapticsOnly")]
  406. + bool PlaysHapticsOnly { get; set; }
  407. +
  408. + [Export ("isMutedForAudio")]
  409. + bool IsMutedForAudio { get; set; }
  410. +
  411. + [Export ("isMutedForHaptics")]
  412. + bool IsMutedForHaptics { get; set; }
  413. +
  414. + [Export ("autoShutdownEnabled")]
  415. + bool AutoShutdownEnabled { [Bind ("isAutoShutdownEnabled")] get; set; }
  416. +
  417. + [Export ("initAndReturnError:")]
  418. + [DesignatedInitializer]
  419. + IntPtr Constructor ([NullAllowed] out NSError error);
  420. +/*
  421. + [Export ("initWithAudioSession:error:")]
  422. + [DesignatedInitializer]
  423. + IntPtr Constructor ([NullAllowed] AVAudioSession audioSession, [NullAllowed] out NSError error);
  424. +*/
  425. +
  426. + [Export ("startWithCompletionHandler:")]
  427. + void Start ([NullAllowed] Action<NSError> completionHandler);
  428. +
  429. + [Export ("startAndReturnError:")]
  430. + bool Start ([NullAllowed] out NSError outError);
  431. +
  432. + [Export ("stopWithCompletionHandler:")]
  433. + void Stop ([NullAllowed] Action<NSError> completionHandler);
  434. +
  435. + [Export ("notifyWhenPlayersFinished:")]
  436. + void NotifyWhenPlayersFinished (Action<NSError> finishedHandler);
  437. +
  438. + [Export ("createPlayerWithPattern:error:")]
  439. + [return: NullAllowed]
  440. + CHHapticPatternPlayer CreatePlayer (CHHapticPattern pattern, [NullAllowed] out NSError outError);
  441. +
  442. + [Export ("createAdvancedPlayerWithPattern:error:")]
  443. + [return: NullAllowed]
  444. + ICHHapticAdvancedPatternPlayer CreateAdvancedPlayer (CHHapticPattern pattern, [NullAllowed] out NSError outError);
  445. +
  446. + [Export ("registerAudioResource:options:error:")]
  447. + nuint RegisterAudioResource (NSUrl resourceUrl, NSDictionary options, [NullAllowed] out NSError outError);
  448. +
  449. + [Export ("unregisterAudioResource:error:")]
  450. + bool UnregisterAudioResource (nuint resourceId, [NullAllowed] out NSError outError);
  451. +
  452. + [Export ("playPatternFromURL:error:")]
  453. + bool PlayPattern (NSUrl fileUrl, [NullAllowed] out NSError outError);
  454. +
  455. + [Export ("playPatternFromData:error:")]
  456. + bool PlayPattern (NSData data, [NullAllowed] out NSError outError);
  457. + }
  458. +
  459. + [Static]
  460. + [Internal]
  461. + [Mac (10,15), iOS (13,0)]
  462. + partial interface CHHapticPatternDefinitionKeys {
  463. + [Field ("CHHapticPatternKeyVersion")]
  464. + NSString VersionKey { get; }
  465. +
  466. + [Field ("CHHapticPatternKeyPattern")]
  467. + NSString PatternKey { get; }
  468. +
  469. + [Field ("CHHapticPatternKeyEvent")]
  470. + NSString EventKey { get; }
  471. +
  472. + [Field ("CHHapticPatternKeyEventType")]
  473. + NSString EventTypeKey { get; }
  474. +
  475. + [Field ("CHHapticPatternKeyTime")]
  476. + NSString TimeKey { get; }
  477. +
  478. + [Field ("CHHapticPatternKeyEventDuration")]
  479. + NSString EventDurationKey { get; }
  480. +
  481. + [Field ("CHHapticPatternKeyEventWaveformPath")]
  482. + NSString EventWaveformPathKey { get; }
  483. +
  484. + [Field ("CHHapticPatternKeyEventParameters")]
  485. + NSString EventParametersKey { get; }
  486. +
  487. + [Field ("CHHapticPatternKeyParameter")]
  488. + NSString ParameterKey { get; }
  489. +
  490. + [Field ("CHHapticPatternKeyParameterID")]
  491. + NSString ParameterIdKey { get; }
  492. +
  493. + [Field ("CHHapticPatternKeyParameterValue")]
  494. + NSString ParameterValueKey { get; }
  495. +
  496. + [Field ("CHHapticPatternKeyParameterCurve")]
  497. + NSString ParameterCurveKey { get; }
  498. +
  499. + [Field ("CHHapticPatternKeyParameterCurveControlPoints")]
  500. + NSString ParameterCurveControlPointsKey { get; }
  501. + }
  502. +
  503. + [Mac (10,15), iOS (13,0)]
  504. + [StrongDictionary ("CHHapticPatternDefinitionKeys")]
  505. + partial interface CHHapticPatternDefinition {
  506. + double Version { get; set; }
  507. + NSArray Pattern { get; set; }
  508. + NSDictionary Event { get; set; }
  509. + CHHapticEventType EventType { get; set; }
  510. + double Time { get; set; }
  511. + double EventDuration { get; set; }
  512. + NSString EventWaveformPath { get; set; }
  513. + NSArray EventParameters { get; set; }
  514. + NSDictionary Parameter { get; set; }
  515. + // we need to do a NSString because it can be a CHHapticEventParameterID or a CHHapticDynamicParameterID
  516. + // which are two different enums. User will have to do the conversion
  517. + NSString ParameterId { get; set; }
  518. + double ParameterValue { get; set; }
  519. + // we do not have docs or header information about the exact type
  520. + NSObject ParameterCurve { get; set; }
  521. + NSObject ParameterCurveControlPoints { get; set; }
  522. + }
  523. +
  524. + [Mac (10,15), iOS (13,0)]
  525. + [BaseType (typeof(NSObject))]
  526. + [DisableDefaultCtor]
  527. + interface CHHapticPattern {
  528. + [Export ("duration")]
  529. + double Duration { get; }
  530. +
  531. + [Export ("initWithEvents:parameters:error:")]
  532. + IntPtr Constructor (CHHapticEvent[] events, CHHapticDynamicParameter[] parameters, [NullAllowed] out NSError outError);
  533. +
  534. + [Export ("initWithEvents:parameterCurves:error:")]
  535. + IntPtr Constructor (CHHapticEvent[] events, CHHapticParameterCurve[] parameterCurves, [NullAllowed] out NSError outError);
  536. +
  537. + [Export ("initWithDictionary:error:")]
  538. + IntPtr Constructor (NSDictionary patternDict, [NullAllowed] out NSError outError);
  539. +
  540. + [Wrap ("this (patternDefinition?.Dictionary, out outError)")]
  541. + IntPtr Constructor (CHHapticPatternDefinition patternDefinition, [NullAllowed] out NSError outError);
  542. +
  543. + [Export ("exportDictionaryAndReturnError:")]
  544. + [return: NullAllowed]
  545. + NSDictionary<NSString, NSObject> _ExportDictionary ([NullAllowed] out NSError outError);
  546. +
  547. + [Wrap ("new CHHapticPatternDefinition (_ExportDictionary (out outError))")]
  548. + CHHapticPatternDefinition ExportDictionary ([NullAllowed] out NSError outError);
  549. + }
  550. +}
  551. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement