sources and files for the bombatuino project
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.

123 lines
3.1 KiB

  1. /**
  2. * @file bombatuino_MIDI.h
  3. *
  4. * @author Lukas Haubaum (lukas@haubaum.de)
  5. *
  6. * @date February, 2013
  7. *
  8. * @brief arduino library for sending MIDI messages over serial
  9. *
  10. * library is just for sending MIDI messages over normal Serial (TX), not for receiving.
  11. *
  12. * */
  13. #ifndef bombatuino_MIDI_h
  14. #define bombatuino_MIDI_h
  15. #define MIDI_NOTE_OFF 0x80
  16. #define MIDI_NOTE_ON 0x90
  17. #define MIDI_POLYPHONIC_KEY_PRESSURE 0xA0
  18. #define MIDI_CONTROL_CHANGE 0xB0
  19. #define MIDI_PROGRAMM_CHANGE 0xC0
  20. #define MIDI_CHANNEL_PRESSURE 0xD0
  21. #define MIDI_PITCH_WHEEL_CHANGE 0xE0
  22. #define MIDI_DEFAULT_CHANNEL 0x00
  23. #define MIDI_MAX_STATUS 0xE0
  24. #define MIDI_MAX_CHANNEL 0x0F
  25. #define MIDI_MAX_DATA 0x7F
  26. #define MIDI_NULL_CHANNEL -1
  27. class MIDI {
  28. public:
  29. /**
  30. * initalize the class, should be called in setup() function
  31. *
  32. * !IMPORTANT sets Serial baud rate to the default MIDI baud rate, so do not change baud rate manually
  33. *
  34. * @param optional: default MIDI channel
  35. */
  36. void begin(int channel = MIDI_DEFAULT_CHANNEL);
  37. /**
  38. * send MIDI message over Serial
  39. *
  40. * @param status byte
  41. * @param first data byte
  42. * @param second data byte
  43. * @param optional: MIDI channel
  44. *
  45. * @return false, if an error occurs
  46. */
  47. bool message(int status, int data, int data2, int channel = MIDI_NULL_CHANNEL);
  48. /**
  49. * send Note off MIDI message
  50. *
  51. * @param note number
  52. * @param optional: velocity
  53. * @param optional: MIDI channel
  54. *
  55. * @return false, if an error occurs
  56. */
  57. bool noteOff(int note, int velocity = MIDI_MAX_DATA, int channel = MIDI_NULL_CHANNEL);
  58. /**
  59. * send Note on MIDI message
  60. *
  61. * @param note number
  62. * @param velocity
  63. * @param optional: MIDI channel
  64. *
  65. * @return false, if an error occurs
  66. */
  67. bool noteOn(int note, int velocity, int channel = MIDI_NULL_CHANNEL);
  68. /**
  69. * send polyphinic key pressure MIDI message
  70. *
  71. * @param note number
  72. * @param velocity
  73. * @param optional: MIDI channel
  74. *
  75. * @return false, if an error occurs
  76. */
  77. bool polyphonicKeyPressure(int note, int velocity, int channel = MIDI_NULL_CHANNEL);
  78. /**
  79. * send control change MIDI message
  80. *
  81. * @param controller number
  82. * @param value
  83. * @param optional: MIDI channel
  84. */
  85. bool controlChange(int controller, int value, int channel = MIDI_NULL_CHANNEL);
  86. /**
  87. * send program change MIDI message
  88. *
  89. * @param programm number
  90. * @param optional: MIDI channel
  91. *
  92. * @return false, if an error occurs
  93. */
  94. bool programChange(int programm, int channel = MIDI_NULL_CHANNEL);
  95. /**
  96. * send channel pressure MIDI message
  97. *
  98. * @param pressure value
  99. * @param optional: MIDI channel
  100. *
  101. * @return false, if an error occurs
  102. */
  103. bool channelPressure(int pressure, int channel = MIDI_NULL_CHANNEL);
  104. /**
  105. * send pitch wheel change MIDI message
  106. *
  107. * @param last significant bits
  108. * @param most significant bits
  109. * @param optional: MIDI channel
  110. *
  111. * @return false, if an error occurs
  112. */
  113. bool pitchWheelChange(int last, int most, int channel = MIDI_NULL_CHANNEL);
  114. private:
  115. int _channel; /**> the default MIDI channel */
  116. };
  117. #endif