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.

136 lines
3.3 KiB

  1. #ifndef _TOOL_HELP_
  2. #define _TOOL_HELP_
  3. #include "dmusici.h"
  4. #include "tools.h"
  5. // Global class that provides various useful methods.
  6. class CToolHelper
  7. {
  8. public:
  9. BYTE VolumeToMidi(long lVolume);
  10. long MidiToVolume(BYTE bMidi);
  11. long TimeUnitToTicks(long lTimeUnit,DMUS_TIMESIGNATURE *pTimeSig);
  12. private:
  13. static long m_slMIDIToDB[128]; // Array for converting MIDI to centibel volume.
  14. static long m_slDBToMIDI[97]; // For converting volume to MIDI.
  15. static long m_slResTypes[DMUS_TIME_UNIT_COUNT]; // Array for converting time units into ticks.
  16. };
  17. class CMusicVal
  18. {
  19. public:
  20. CMusicVal(WORD wMusicVal);
  21. WORD GetValue();
  22. void operator+=(CMusicVal Val);
  23. void operator+=(short nScale); // Most common transposition would be by scale.
  24. void operator-=(CMusicVal Val);
  25. CMusicVal operator+(CMusicVal Val) const;
  26. CMusicVal operator-(CMusicVal Val) const;
  27. private:
  28. void CleanUp();
  29. short m_sOctave;
  30. short m_sChord;
  31. short m_sScale;
  32. short m_sAccidental;
  33. };
  34. /*inline void CMusicVal::operator +
  35. inline void CPoint::operator-=(SIZE size)
  36. { x -= size.cx; y -= size.cy; }
  37. _AFXWIN_INLINE void CPoint::operator+=(POINT point)
  38. { x += point.x; y += point.y; }
  39. _AFXWIN_INLINE void CPoint::operator-=(POINT point)
  40. { x -= point.x; y -= point.y; }
  41. _AFXWIN_INLINE CPoint CPoint::operator+(SIZE size) const
  42. { return CPoint(x + size.cx, y + size.cy); }
  43. _AFXWIN_INLINE CPoint CPoint::operator-(SIZE size) const
  44. { return CPoint(x - size.cx, y - size.cy); }
  45. */
  46. inline CMusicVal::CMusicVal(WORD wMusicVal)
  47. {
  48. m_sAccidental = wMusicVal & 0xF;
  49. if (wMusicVal & 0x8) // Negative?
  50. {
  51. m_sAccidental |= 0xFFF0; // Yes, extend sign bit.
  52. }
  53. m_sScale = (wMusicVal & 0xF0) >> 4;
  54. m_sChord = (wMusicVal & 0xF00) >> 8;
  55. m_sOctave = wMusicVal >> 12;
  56. if (m_sOctave > 14) // We count the top two octaves as negative.
  57. {
  58. m_sOctave -= 16;
  59. }
  60. }
  61. inline WORD CMusicVal::GetValue()
  62. {
  63. CleanUp();
  64. return (WORD) ((m_sOctave << 12) | (m_sChord << 8) | (m_sScale << 4) | (m_sAccidental & 0xF));
  65. }
  66. inline void CMusicVal::CleanUp()
  67. {
  68. while (m_sAccidental < -8)
  69. {
  70. // This should never happen, but it does, do approximate math.
  71. m_sAccidental += 2;
  72. m_sScale -= 1;
  73. }
  74. while (m_sAccidental > 7)
  75. {
  76. // Likewise, this should not happen, so resulting math isn't perfect.
  77. m_sAccidental -= 2;
  78. m_sScale += 1;
  79. }
  80. while (m_sScale < 0)
  81. {
  82. m_sScale += 2;
  83. m_sChord -= 1;
  84. }
  85. while (m_sScale > 7)
  86. {
  87. m_sScale -= 2;
  88. m_sChord += 1;
  89. }
  90. while (m_sChord < 0)
  91. {
  92. m_sChord += 4;
  93. m_sOctave -= 1;
  94. }
  95. while (m_sChord > 4)
  96. {
  97. m_sChord -= 4;
  98. m_sOctave += 1;
  99. }
  100. while (m_sOctave < -2)
  101. {
  102. m_sOctave++;
  103. }
  104. while (m_sOctave >= 14)
  105. {
  106. m_sOctave--;
  107. }
  108. }
  109. inline void CMusicVal::operator+=(CMusicVal Val)
  110. {
  111. m_sOctave += Val.m_sOctave;
  112. m_sChord += Val.m_sChord;
  113. m_sScale += Val.m_sScale;
  114. m_sAccidental += Val.m_sAccidental;
  115. }
  116. inline void CMusicVal::operator+=(short nScale)
  117. {
  118. m_sScale += nScale;
  119. }
  120. #endif // _TOOL_HELP_