Source code of Windows XP (NT5)
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.

109 lines
3.4 KiB

  1. // ToolHelp.cpp : Global functions.
  2. //
  3. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved
  4. //
  5. #include "toolhelp.h"
  6. long CToolHelper::m_slMIDIToDB[128] = { // Global array used to convert MIDI to dB.
  7. -9600, -8415, -7211, -6506, -6006, -5619, -5302, -5034,
  8. -4802, -4598, -4415, -4249, -4098, -3959, -3830, -3710,
  9. -3598, -3493, -3394, -3300, -3211, -3126, -3045, -2968,
  10. -2894, -2823, -2755, -2689, -2626, -2565, -2506, -2449,
  11. -2394, -2341, -2289, -2238, -2190, -2142, -2096, -2050,
  12. -2006, -1964, -1922, -1881, -1841, -1802, -1764, -1726,
  13. -1690, -1654, -1619, -1584, -1551, -1518, -1485, -1453,
  14. -1422, -1391, -1361, -1331, -1302, -1273, -1245, -1217,
  15. -1190, -1163, -1137, -1110, -1085, -1059, -1034, -1010,
  16. -985, -961, -938, -914, -891, -869, -846, -824,
  17. -802, -781, -759, -738, -718, -697, -677, -657,
  18. -637, -617, -598, -579, -560, -541, -522, -504,
  19. -486, -468, -450, -432, -415, -397, -380, -363,
  20. -347, -330, -313, -297, -281, -265, -249, -233,
  21. -218, -202, -187, -172, -157, -142, -127, -113,
  22. -98, -84, -69, -55, -41, -27, -13, 0
  23. };
  24. long CToolHelper::m_slDBToMIDI[97] = { // Global array used to convert db to MIDI.
  25. 127, 119, 113, 106, 100, 95, 89, 84, 80, 75,
  26. 71, 67, 63, 60, 56, 53, 50, 47, 45, 42,
  27. 40, 37, 35, 33, 31, 30, 28, 26, 25, 23,
  28. 22, 21, 20, 19, 17, 16, 15, 15, 14, 13,
  29. 12, 11, 11, 10, 10, 9, 8, 8, 8, 7,
  30. 7, 6, 6, 6, 5, 5, 5, 4, 4, 4,
  31. 4, 3, 3, 3, 3, 3, 2, 2, 2, 2,
  32. 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
  33. 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
  34. 0, 0, 0, 0, 0, 0, 0
  35. };
  36. long CToolHelper::m_slResTypes[DMUS_TIME_UNIT_COUNT] =
  37. { 1, // DMUS_TIME_UNIT_MS
  38. 1, // DMUS_TIME_UNIT_MTIME
  39. 384, // DMUS_TIME_UNIT_GRID
  40. 768, // DMUS_TIME_UNIT_BEAT
  41. 3072, // DMUS_TIME_UNIT_BAR
  42. 32, // DMUS_TIME_UNIT_64T
  43. 48, // DMUS_TIME_UNIT_64
  44. 64, // DMUS_TIME_UNIT_32T
  45. 96, // DMUS_TIME_UNIT_32
  46. 128, // DMUS_TIME_UNIT_16T
  47. 192, // DMUS_TIME_UNIT_16
  48. 256, // DMUS_TIME_UNIT_8T
  49. 384, // DMUS_TIME_UNIT_8
  50. 512, // DMUS_TIME_UNIT_4T
  51. 768, // DMUS_TIME_UNIT_4
  52. 1024, // DMUS_TIME_UNIT_2T
  53. 1536, // DMUS_TIME_UNIT_2
  54. 2048, // DMUS_TIME_UNIT_1T
  55. 3072 // DMUS_TIME_UNIT_1
  56. };
  57. BYTE CToolHelper::VolumeToMidi(long lVolume)
  58. {
  59. if (lVolume < -9600) lVolume = -9600;
  60. if (lVolume > 0) lVolume = 0;
  61. lVolume = -lVolume;
  62. long lFraction = lVolume % 100;
  63. lVolume = lVolume / 100;
  64. long lResult = m_slDBToMIDI[lVolume];
  65. lResult += ((m_slDBToMIDI[lVolume + 1] - lResult) * lFraction) / 100;
  66. return (BYTE) lResult;
  67. }
  68. long CToolHelper::MidiToVolume(BYTE bMidi)
  69. {
  70. if (bMidi > 127) bMidi = 127;
  71. return m_slMIDIToDB[bMidi];
  72. }
  73. long CToolHelper::TimeUnitToTicks(long lTimeUnit,DMUS_TIMESIGNATURE *pTimeSig)
  74. {
  75. long lTicks;
  76. if (lTimeUnit > DMUS_TIME_UNIT_BAR)
  77. {
  78. lTicks = m_slResTypes[lTimeUnit];
  79. }
  80. else if ((lTimeUnit >= DMUS_TIME_UNIT_GRID) && pTimeSig)
  81. {
  82. DWORD dwBeat = (4 * 768) / pTimeSig->bBeat;
  83. if (lTimeUnit == DMUS_TIME_UNIT_BEAT)
  84. {
  85. lTicks = dwBeat;
  86. }
  87. else if (lTimeUnit == DMUS_TIME_UNIT_GRID)
  88. {
  89. lTicks = (dwBeat / pTimeSig->wGridsPerBeat);
  90. }
  91. else
  92. {
  93. lTicks = (dwBeat * pTimeSig->bBeatsPerMeasure);
  94. }
  95. }
  96. else lTicks = 0;
  97. return lTicks;
  98. }