Magically import images and more into Gamecraft as blocks
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.

106 lines
3.0KB

  1. using System.Collections.Generic;
  2. using System.Runtime.CompilerServices;
  3. using GamecraftModdingAPI.Utility;
  4. using Melanchall.DryWetMidi.Common;
  5. namespace Pixi.Audio
  6. {
  7. public static class AudioTools
  8. {
  9. private static Dictionary<byte, byte> programMap = null;
  10. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  11. public static byte TrackType(FourBitNumber channel)
  12. {
  13. return TrackType((byte) channel);
  14. }
  15. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  16. public static byte TrackType(byte channel)
  17. {
  18. if (programMap.ContainsKey(channel)) return programMap[channel];
  19. #if DEBUG
  20. Logging.MetaLog($"Using default value (piano) for channel number {channel}");
  21. #endif
  22. return 5; // Piano
  23. }
  24. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  25. public static float VelocityToVolume(SevenBitNumber velocity)
  26. {
  27. // faster key hit means louder note
  28. return 100f * velocity / ((float) SevenBitNumber.MaxValue + 1f);
  29. }
  30. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  31. internal static void GenerateProgramMap()
  32. {
  33. programMap = new Dictionary<byte, byte>
  34. {
  35. {0, 5 /* Piano */},
  36. {1, 5},
  37. {2, 5},
  38. {3, 5},
  39. {4, 5},
  40. {5, 5},
  41. {6, 5},
  42. {7, 5},
  43. {8, 0 /* Kick Drum */},
  44. {9, 0},
  45. {10, 0},
  46. {11, 0},
  47. {12, 0},
  48. {13, 0},
  49. {14, 0},
  50. {15, 0},
  51. {24, 6 /* Guitar 1 (Acoustic) */},
  52. {25, 6},
  53. {26, 6},
  54. {27, 6},
  55. {28, 6},
  56. {29, 7 /* Guitar 2 (Dirty Electric) */},
  57. {30, 7},
  58. {32, 6},
  59. {33, 6},
  60. {34, 6},
  61. {35, 6},
  62. {36, 6},
  63. {37, 6},
  64. {38, 6},
  65. {39, 6},
  66. {56, 8 /* Trumpet */}, // basically all brass & reeds are trumpets... that's how music works right?
  67. {57, 8},
  68. {58, 8},
  69. {59, 8},
  70. {60, 8},
  71. {61, 8},
  72. {62, 8},
  73. {63, 8},
  74. {64, 8},
  75. {65, 8},
  76. {66, 8},
  77. {67, 8},
  78. {68, 8},
  79. {69, 8}, // Nice
  80. {70, 8},
  81. {71, 8},
  82. {72, 8},
  83. {73, 8},
  84. {74, 8},
  85. {75, 8},
  86. {76, 8},
  87. {77, 8},
  88. {78, 8},
  89. {79, 8},
  90. {112, 0},
  91. {113, 0},
  92. {114, 0},
  93. {115, 0},
  94. {116, 0},
  95. {117, 4 /* Tom Drum */},
  96. {118, 4},
  97. {119, 3 /* Open High Hat */},
  98. };
  99. }
  100. }
  101. }