2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
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.
 
 
 
 
 
 

63 lines
1.3 KiB

  1. #include "IZ_midi.h"
  2. char* IZ_MIDIGetNoteName(u8 midi_note) {
  3. static const char* pitch_names[] = {
  4. "C",
  5. "C#",
  6. "D",
  7. "D#",
  8. "E",
  9. "F",
  10. "F#",
  11. "G",
  12. "G#",
  13. "A",
  14. "A#",
  15. "B"
  16. };
  17. const u8 pitch_class = midi_note % 12;
  18. const u8 octave = midi_note / 12;
  19. static char note_name[8];
  20. sprintf_s(note_name, 8, "%s%u", pitch_names[pitch_class], octave);
  21. return note_name;
  22. }
  23. u8 IZ_MIDIGetNoteFromName(const char* name) {
  24. char name_copy[8];
  25. memcpy_s(name_copy, 8, name, 8);
  26. _strlwr_s(name_copy, 8);
  27. u8 octave;
  28. const char base_pitch_name[] = "c d ef g a b";
  29. if (strlen(name_copy) == 2) {
  30. octave = name_copy[1] - '0';
  31. u8 pitch_index;
  32. for (pitch_index = 0; pitch_index < 12; pitch_index += 1) {
  33. if (base_pitch_name[pitch_index] == name_copy[0]) {
  34. return (octave * 12) + pitch_index;
  35. }
  36. }
  37. return 255u;
  38. }
  39. u8 pitch_class;
  40. octave = name_copy[2] - '0';
  41. if (strstr(name_copy, "c#") || strstr(name_copy, "db")) {
  42. pitch_class = 1;
  43. } else if (strstr(name_copy, "d#") || strstr(name_copy, "eb")) {
  44. pitch_class = 3;
  45. } else if (strstr(name_copy, "f#") || strstr(name_copy, "gb")) {
  46. pitch_class = 6;
  47. } else if (strstr(name_copy, "g#") || strstr(name_copy, "ab")) {
  48. pitch_class = 8;
  49. } else if (strstr(name_copy, "a#") || strstr(name_copy, "bb")) {
  50. pitch_class = 10;
  51. } else {
  52. return 255u;
  53. }
  54. return (octave * 12) + pitch_class;
  55. }