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.

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