Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

639 lines
18 KiB

  1. //@doc
  2. /******************************************************
  3. **
  4. ** @module EFFECT.H | Definition file for InternalEffect structure
  5. **
  6. ** Description:
  7. ** The Data Packager allows virtualization of the
  8. ** commands into the different firmware versions packet format
  9. ** DataPackager - Base class that defines the functionality of all DataPackagers
  10. ** DataPackager100 - DataPackager for Firmware 1.**
  11. ** DataPackager200 - DataPackager for Firmware 2.**
  12. **
  13. ** Classes:
  14. ** DataPackager
  15. ** DataPackager100 - DataPackager for Firmware 1.**
  16. ** DataPackager200 - DataPackager for Firmware 2.**
  17. ** DataPacket
  18. **
  19. ** History:
  20. ** Created 1/05/98 Matthew L. Coill (mlc)
  21. **
  22. ** (c) 1986-1998 Microsoft Corporation. All Rights Reserved.
  23. ******************************************************/
  24. #ifndef __EFFECT_H__
  25. #define __EFFECT_H__
  26. #include "SW_Error.hpp"
  27. #include "Hau_Midi.hpp"
  28. #include "DX_Map.hpp"
  29. #include "DPack.h" // For ASSUME Macros
  30. #ifndef override
  31. #define override
  32. #endif
  33. #define ET_CUSTOMFORCE_200 0x01
  34. #define ET_SINE_200 0x02
  35. #define ET_SQUARE_200 0x03
  36. #define ET_TRIANGLE_200 0x04
  37. #define ET_SAWTOOTH_200 0x05
  38. #define ET_CONSTANTFORCE_200 0x06
  39. #define ET_DELAY_200 0x08 // - Not defined
  40. #define ET_SPRING_200 0x08
  41. #define ET_DAMPER_200 0x09
  42. #define ET_INERTIA_200 0x0A
  43. #define ET_FRICTION_200 0x0B
  44. #define ET_WALL_200 0x0C
  45. #define ET_RAWFORCE_200 0x0D // Needed for mapping
  46. #define ID_RTCSPRING_200 1
  47. class DataPacket;
  48. class Envelope
  49. {
  50. protected: // Cannot create the generic envelope
  51. Envelope() {};
  52. };
  53. class Envelope1XX : public Envelope
  54. {
  55. public:
  56. Envelope1XX(DIENVELOPE* pDIEnvelope, DWORD baseLine, DWORD duration);
  57. DWORD m_AttackTime; // Time from attack to sustain
  58. DWORD m_SustainTime; // Time from sustain to fade
  59. DWORD m_FadeTime; // Time from fade to end
  60. DWORD m_StartPercent; // Percentage of max that is start
  61. DWORD m_SustainPercent; // Percentage of max that is sustained
  62. DWORD m_EndPercent; // Percentage of max during fade
  63. };
  64. class Envelope200 : public Envelope
  65. {
  66. public:
  67. Envelope200(DIENVELOPE* pDIEnvelope, DWORD sustain, DWORD duration, HRESULT& hr);
  68. WORD m_AttackTime; // Time from attack to sustain
  69. WORD m_FadeStart; // Time from start to fade (attack + sustain)
  70. BYTE m_StartPercent; // Percentage of max that is start
  71. BYTE m_SustainPercent; // Percentage of max that is sustained
  72. BYTE m_EndPercent; // Percentage of max at end of fade
  73. };
  74. //
  75. // @class InternalEffect class
  76. //
  77. class InternalEffect
  78. {
  79. //@access Constructor
  80. public:
  81. //@cmember constructor
  82. InternalEffect();
  83. virtual ~InternalEffect();
  84. // Ugly! but quick and simple
  85. static InternalEffect* CreateSpring();
  86. static InternalEffect* CreateDamper();
  87. static InternalEffect* CreateInertia();
  88. static InternalEffect* CreateFriction();
  89. static InternalEffect* CreateRTCSpring();
  90. static InternalEffect* CreateSystemEffect();
  91. static InternalEffect* CreateCustomForce();
  92. static InternalEffect* CreateSine();
  93. static InternalEffect* CreateSquare();
  94. static InternalEffect* CreateTriangle();
  95. static InternalEffect* CreateSawtoothUp();
  96. static InternalEffect* CreateSawtoothDown();
  97. static InternalEffect* CreateConstantForce();
  98. static InternalEffect* CreateRamp();
  99. static InternalEffect* CreateWall();
  100. static InternalEffect* CreateDelay() { return NULL; }
  101. static InternalEffect* CreateFromVFX(const DIEFFECT& diOringinal, EFFECT effect, ENVELOPE envelope, BYTE* pEffectParms, DWORD paramSize, HRESULT& hr);
  102. virtual HRESULT Create(const DIEFFECT& diEffect);
  103. virtual HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  104. virtual UINT GetModifyOnlyNeeded() const { return 0; }
  105. virtual HRESULT FillModifyOnlyParms() const { return SUCCESS; }
  106. virtual HRESULT FillCreatePacket(DataPacket& packet) const { return SFERR_NO_SUPPORT; }
  107. static BYTE ComputeChecksum(const DataPacket& packet, short int numFields);
  108. void FillSysExHeader(DataPacket& packet) const;
  109. void FillHeader1XX(DataPacket& packet, BYTE effectType, BYTE effectID) const;
  110. void FillHeader200(DataPacket& packet, BYTE effectType, BYTE effectID) const;
  111. BYTE GetGlobalID() const { return m_EffectID; }
  112. BYTE GetDeviceID() const { return m_DeviceEffectID; }
  113. void SetGlobalID(BYTE id) { m_EffectID = id; }
  114. void SetDeviceID(BYTE id) { m_DeviceEffectID = id; }
  115. // For special modfication of play reapeat
  116. HRESULT FillModifyPacket200(BYTE packetIndex, BYTE paramIndex, DWORD value) const;
  117. virtual BYTE GetRepeatIndex() const { return 0xFF; }
  118. void SetPlaying(BOOL playState) { m_IsPossiblyPlaying = playState; }
  119. BOOL IsPossiblyPlaying() const { return m_IsPossiblyPlaying; }
  120. BOOL IsReallyPlaying(BOOL& multiCheckStop);
  121. protected:
  122. HRESULT FillModifyPacket1XX(BYTE packetIndex, BYTE paramIndex, DWORD value) const;
  123. HRESULT FillModifyPacket200(BYTE packetIndex, BYTE paramIndex, BYTE low, BYTE high) const;
  124. BYTE m_EffectID;
  125. BYTE m_DeviceEffectID;
  126. DWORD m_Duration;
  127. DWORD m_Gain;
  128. DWORD m_SamplePeriod;
  129. DWORD m_TriggerPlayButton;
  130. DWORD m_TriggerRepeat;
  131. DWORD m_AxisMask;
  132. DWORD m_EffectAngle;
  133. DWORD m_PercentX; // Percent force X
  134. DWORD m_PercentY; // Percent force Y
  135. DWORD m_PercentAdjustment; // Y-Force mapping combination of above
  136. BOOL m_AxesReversed;
  137. BOOL m_IsPossiblyPlaying;
  138. };
  139. // ********************** Behavioural Based Effects *****************************/
  140. //
  141. // @class BehaviouralEffect class
  142. // Spring, Damper, Intertia, Friction, and Wall (till wall gets its own type)
  143. //
  144. class BehaviouralEffect : public InternalEffect
  145. {
  146. //@access Constructor
  147. public:
  148. //@cmember constructor
  149. BehaviouralEffect() : InternalEffect() {};
  150. virtual override HRESULT Create(const DIEFFECT& diEffect);
  151. // Accessors
  152. long int ConstantX() const { return m_ConditionData[0].lPositiveCoefficient; }
  153. long int ConstantY() const { return m_ConditionData[1].lPositiveCoefficient; }
  154. long int CenterX() const { return m_ConditionData[0].lOffset; }
  155. long int CenterY() const { return m_ConditionData[1].lOffset; }
  156. protected:
  157. DICONDITION m_ConditionData[2]; // We are just dealing with two axis currently
  158. BYTE m_TypeID;
  159. };
  160. //
  161. // @class BehaviouralEffect1XX class
  162. // Spring, Damper, and Inertia
  163. //
  164. class BehaviouralEffect1XX : public BehaviouralEffect
  165. {
  166. //@access Constructor
  167. public:
  168. //@cmember constructor
  169. BehaviouralEffect1XX(BYTE typeID) : BehaviouralEffect() { m_TypeID = typeID; m_HasCenter = TRUE; }
  170. virtual override HRESULT FillCreatePacket(DataPacket& packet) const;
  171. override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  172. protected:
  173. void AdjustModifyParams(InternalEffect& newEffect, DWORD& modFlags) const;
  174. BOOL m_HasCenter; // Friction has no center
  175. };
  176. //
  177. // @class RTCSpring1XX class
  178. //
  179. class RTCSpring1XX : public BehaviouralEffect
  180. {
  181. //@access Constructor
  182. public:
  183. //@cmember constructor
  184. RTCSpring1XX();
  185. override HRESULT Create(const DIEFFECT& diEffect);
  186. override HRESULT FillCreatePacket(DataPacket& packet) const;
  187. override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  188. long int SaturationX() const { return m_ConditionData[0].dwPositiveSaturation; }
  189. long int SaturationY() const { return m_ConditionData[1].dwPositiveSaturation; }
  190. long int DeadBandX() const { return m_ConditionData[0].lDeadBand; }
  191. long int DeadBandY() const { return m_ConditionData[1].lDeadBand; }
  192. protected:
  193. void AdjustModifyParams(InternalEffect& newEffect, DWORD& modFlags) const;
  194. };
  195. //
  196. // @class BehaviouralEffect200 class
  197. // Spring, Damper, and Inertia
  198. //
  199. class BehaviouralEffect200 : public BehaviouralEffect
  200. {
  201. //@access Constructor
  202. public:
  203. //@cmember constructor
  204. BehaviouralEffect200(BYTE typeID) : BehaviouralEffect() { m_TypeID = typeID; }
  205. override HRESULT Create(const DIEFFECT& diEffect);
  206. virtual override UINT GetModifyOnlyNeeded() const;
  207. virtual override HRESULT FillModifyOnlyParms() const;
  208. override HRESULT FillCreatePacket(DataPacket& packet) const;
  209. override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  210. override BYTE GetRepeatIndex() const;
  211. protected:
  212. HRESULT AdjustModifyParams(InternalEffect& newEffect, DWORD& modFlags);
  213. // Distances and Forces spec'd for the firmware
  214. void ComputeDsAndFs();
  215. BYTE m_Ds[4];
  216. BYTE m_Fs[4];
  217. };
  218. //
  219. // @class RTCSpring200 class
  220. //
  221. class RTCSpring200 : public BehaviouralEffect200
  222. {
  223. //@access Constructor
  224. public:
  225. //@cmember constructor
  226. RTCSpring200();
  227. override HRESULT Create(const DIEFFECT& diEffect);
  228. override HRESULT FillCreatePacket(DataPacket& packet) const;
  229. override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  230. override UINT GetModifyOnlyNeeded() const;
  231. override HRESULT FillModifyOnlyParms() const;
  232. long int SaturationX() const { return m_ConditionData[0].dwPositiveSaturation; }
  233. long int SaturationY() const { return m_ConditionData[1].dwPositiveSaturation; }
  234. long int DeadBandX() const { return m_ConditionData[0].lDeadBand; }
  235. long int DeadBandY() const { return m_ConditionData[1].lDeadBand; }
  236. protected:
  237. void AdjustModifyParams(InternalEffect& newEffect, DWORD& modFlags) const;
  238. };
  239. //
  240. // @class FrictionEffect1XX class
  241. //
  242. class FrictionEffect1XX : public BehaviouralEffect1XX
  243. {
  244. //@access Constructor
  245. public:
  246. //@cmember constructor
  247. FrictionEffect1XX() : BehaviouralEffect1XX(ET_BE_FRICTION) { m_HasCenter = FALSE; }
  248. override HRESULT FillCreatePacket(DataPacket& packet) const;
  249. };
  250. //
  251. // @class FrictionEffect200 class
  252. //
  253. class FrictionEffect200 : public BehaviouralEffect
  254. {
  255. //@access Constructor
  256. public:
  257. //@cmember constructor
  258. FrictionEffect200() : BehaviouralEffect() { m_TypeID = ET_FRICTION_200; }
  259. override UINT GetModifyOnlyNeeded() const;
  260. override HRESULT FillModifyOnlyParms() const;
  261. override HRESULT FillCreatePacket(DataPacket& packet) const;
  262. override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  263. override BYTE GetRepeatIndex() const;
  264. protected:
  265. HRESULT AdjustModifyParams(InternalEffect& newEffect, DWORD& modFlags);
  266. };
  267. /*
  268. //
  269. // @class WallEffect1XX class
  270. //
  271. class WallEffect1XX : public BehaviouralEffect
  272. {
  273. //@access Constructor
  274. public:
  275. //@cmember constructor
  276. WallEffect1XX() : BehaviouralEffect() {};
  277. override HRESULT FillCreatePacket(DataPacket& packet) const;
  278. override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags) const;
  279. protected:
  280. void AdjustModifyParams(InternalEffect& newEffect, DWORD& modFlags) const;
  281. };
  282. */
  283. // ********************* Periodic based Effects *****************************/
  284. //
  285. // @class PeriodicEffect class
  286. // Sine, Square, Triangle
  287. //
  288. class PeriodicEffect : public InternalEffect
  289. {
  290. //@access Constructor
  291. public:
  292. //@cmember constructor
  293. PeriodicEffect();
  294. override ~PeriodicEffect();
  295. virtual override HRESULT Create(const DIEFFECT& diEffect);
  296. // Accessors
  297. long int Magnitude() const { return m_PeriodicData.dwMagnitude; }
  298. long int Offset() const { return m_PeriodicData.lOffset; }
  299. virtual long int Phase() const { return m_PeriodicData.dwPhase; }
  300. long int Period() const { return m_PeriodicData.dwPeriod; }
  301. protected:
  302. DIPERIODIC m_PeriodicData; // We are just dealing with two axis currently
  303. Envelope* m_pEnvelope;
  304. BYTE m_TypeID;
  305. };
  306. //
  307. // @class PeriodicEffect1XX class
  308. //
  309. class PeriodicEffect1XX : public PeriodicEffect
  310. {
  311. //@access Constructor
  312. public:
  313. //@cmember constructor
  314. PeriodicEffect1XX(BYTE typeID) : PeriodicEffect() { m_TypeID = typeID; }
  315. override HRESULT Create(const DIEFFECT& diEffect);
  316. override HRESULT FillCreatePacket(DataPacket& packet) const;
  317. override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  318. protected:
  319. void DIToJolt(DWORD mag, DWORD off, DWORD gain, DWORD& max, DWORD& min) const;
  320. static DWORD DIPeriodToJoltFreq(DWORD period);
  321. HRESULT AdjustModifyParams(InternalEffect& newEffect, DWORD& modFlags) const;
  322. };
  323. //
  324. // @class PeriodicEffect200 class
  325. //
  326. class PeriodicEffect200 : public PeriodicEffect
  327. {
  328. //@access Constructor
  329. public:
  330. //@cmember constructor
  331. PeriodicEffect200(BYTE typeID) : PeriodicEffect() { m_TypeID = typeID; }
  332. virtual override HRESULT Create(const DIEFFECT& diEffect);
  333. override UINT GetModifyOnlyNeeded() const;
  334. override HRESULT FillModifyOnlyParms() const;
  335. override HRESULT FillCreatePacket(DataPacket& packet) const;
  336. virtual override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  337. override BYTE GetRepeatIndex() const;
  338. virtual override long int Phase() const;
  339. protected:
  340. HRESULT AdjustModifyParams(InternalEffect& newEffect, DWORD& modFlags);
  341. };
  342. //
  343. // @class SawtoothEffect200 class
  344. //
  345. class SawtoothEffect200 : public PeriodicEffect200
  346. {
  347. //@access Constructor
  348. public:
  349. //@cmember constructor
  350. SawtoothEffect200(BOOL isUp) : PeriodicEffect200(ET_SAWTOOTH_200), m_IsUp(isUp) {};
  351. virtual override HRESULT Create(const DIEFFECT& diEffect);
  352. override long int Phase() const;
  353. protected:
  354. BOOL m_IsUp;
  355. };
  356. //
  357. // @class RampEffect200 class
  358. //
  359. class RampEffect200 : public SawtoothEffect200
  360. {
  361. //@access Constructor
  362. public:
  363. //@cmember constructor
  364. RampEffect200() : SawtoothEffect200(TRUE) {};
  365. override HRESULT Create(const DIEFFECT& diEffect);
  366. override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  367. };
  368. // ************************ Miscellaneuous (CustomForce, RampForce, ConstantForce, SystemEffect) *********************//
  369. //
  370. // @class CustomForceEffect class
  371. //
  372. class CustomForceEffect : public InternalEffect
  373. {
  374. //@access Constructor
  375. public:
  376. //@cmember constructor
  377. CustomForceEffect();
  378. virtual override ~CustomForceEffect();
  379. virtual override HRESULT Create(const DIEFFECT& diEffect);
  380. protected:
  381. DICUSTOMFORCE m_CustomForceData;
  382. };
  383. //
  384. // @class CustomForceEffect200 class
  385. //
  386. class CustomForceEffect200 : public CustomForceEffect
  387. {
  388. //@access Constructor
  389. public:
  390. //@cmember constructor
  391. CustomForceEffect200();
  392. ~CustomForceEffect200();
  393. override HRESULT Create(const DIEFFECT& diEffect);
  394. override UINT GetModifyOnlyNeeded() const;
  395. override HRESULT FillModifyOnlyParms() const;
  396. override HRESULT FillCreatePacket(DataPacket& packet) const;
  397. override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  398. override BYTE GetRepeatIndex() const;
  399. private:
  400. HRESULT AdjustModifyParams(InternalEffect& newEffect, DWORD& modFlags);
  401. Envelope200* m_pEnvelope;
  402. };
  403. /*
  404. //
  405. // @class RampForceEffect class
  406. //
  407. class RampForceEffect : public InternalEffect
  408. {
  409. //@access Constructor
  410. public:
  411. //@cmember constructor
  412. RampForceEffect();
  413. virtual override HRESULT Create(const DIEFFECT& diEffect);
  414. // Accessors
  415. long int StartForce() const { return m_RampForceData.lStart; }
  416. long int EndForce() const { return m_RampForceData.lEnd; }
  417. protected:
  418. DIRAMPFORCE m_RampForceData;
  419. };
  420. */
  421. //
  422. // @class ConstantForceEffect class
  423. //
  424. class ConstantForceEffect : public InternalEffect
  425. {
  426. //@access Constructor
  427. public:
  428. //@cmember constructor
  429. ConstantForceEffect();
  430. override ~ConstantForceEffect();
  431. virtual override HRESULT Create(const DIEFFECT& diEffect);
  432. // Accessors
  433. long int Magnitude() const { return m_ConstantForceData.lMagnitude; }
  434. protected:
  435. DICONSTANTFORCE m_ConstantForceData;
  436. Envelope* m_pEnvelope;
  437. };
  438. //
  439. // @class ConstantForceEffect200 class
  440. //
  441. class ConstantForceEffect200 : public ConstantForceEffect
  442. {
  443. //@access Constructor
  444. public:
  445. //@cmember constructor
  446. ConstantForceEffect200() : ConstantForceEffect() {};
  447. override HRESULT Create(const DIEFFECT& diEffect);
  448. override UINT GetModifyOnlyNeeded() const;
  449. override HRESULT FillModifyOnlyParms() const;
  450. override HRESULT FillCreatePacket(DataPacket& packet) const;
  451. override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  452. override BYTE GetRepeatIndex() const;
  453. protected:
  454. HRESULT AdjustModifyParams(InternalEffect& newEffect, DWORD& modFlags);
  455. };
  456. //
  457. // @class WallEffect class
  458. //
  459. class WallEffect : public InternalEffect
  460. {
  461. //@access Constructor
  462. public:
  463. //@cmember constructor
  464. WallEffect() : InternalEffect() {};
  465. virtual override HRESULT Create(const DIEFFECT& diEffect);
  466. protected:
  467. BE_WALL_PARAM m_WallData;
  468. };
  469. //
  470. // @class WallEffect200 class
  471. //
  472. class WallEffect200 : public WallEffect
  473. {
  474. //@access Constructor
  475. public:
  476. //@cmember constructor
  477. WallEffect200() : WallEffect() {};
  478. override HRESULT Create(const DIEFFECT& diEffect);
  479. override UINT GetModifyOnlyNeeded() const;
  480. override HRESULT FillModifyOnlyParms() const;
  481. override HRESULT FillCreatePacket(DataPacket& packet) const;
  482. override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  483. override BYTE GetRepeatIndex() const;
  484. private:
  485. HRESULT AdjustModifyParams(InternalEffect& newEffect, DWORD& modFlags);
  486. // Distances and Forces spec'd for the firmware
  487. void ComputeDsAndFs();
  488. BYTE m_Ds[4];
  489. BYTE m_Fs[4];
  490. };
  491. //
  492. // @class SystemEffect class
  493. //
  494. class SystemEffect : public InternalEffect
  495. {
  496. //@access Constructor
  497. public:
  498. //@cmember constructor
  499. SystemEffect() {};
  500. };
  501. class SystemStickData1XX
  502. {
  503. public:
  504. SystemStickData1XX();
  505. void SetFromRegistry(DWORD dwDeviceID);
  506. DWORD dwXYConst;
  507. DWORD dwRotConst;
  508. DWORD dwSldrConst;
  509. DWORD dwAJPos;
  510. DWORD dwAJRot;
  511. DWORD dwAJSldr;
  512. DWORD dwSprScl;
  513. DWORD dwBmpScl;
  514. DWORD dwDmpScl;
  515. DWORD dwInertScl;
  516. DWORD dwVelOffScl;
  517. DWORD dwAccOffScl;
  518. DWORD dwYMotBoost;
  519. DWORD dwXMotSat;
  520. DWORD dwReserved;
  521. DWORD dwMasterGain;
  522. };
  523. class SystemEffect1XX : public SystemEffect
  524. {
  525. //@access Constructor
  526. public:
  527. //@cmember constructor
  528. SystemEffect1XX();
  529. override HRESULT Create(const DIEFFECT& diEffect);
  530. override HRESULT FillCreatePacket(DataPacket& packet) const;
  531. override HRESULT Modify(InternalEffect& newEffect, DWORD modFlags);
  532. protected:
  533. SystemStickData1XX m_SystemStickData;
  534. };
  535. #endif __EFFECT_H__