upload
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

sysex_tools.h 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //midi for embedded chips,
  2. //Copyright 2010 Alex Norman
  3. //
  4. //This file is part of avr-midi.
  5. //
  6. //avr-midi is free software: you can redistribute it and/or modify
  7. //it under the terms of the GNU General Public License as published by
  8. //the Free Software Foundation, either version 3 of the License, or
  9. //(at your option) any later version.
  10. //
  11. //avr-midi is distributed in the hope that it will be useful,
  12. //but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. //GNU General Public License for more details.
  15. //
  16. //You should have received a copy of the GNU General Public License
  17. //along with avr-midi. If not, see <http://www.gnu.org/licenses/>.
  18. #ifndef SYSEX_TOOLS_H
  19. #define SYSEX_TOOLS_H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #include <inttypes.h>
  24. /**
  25. * @file
  26. * @brief Sysex utility functions
  27. *
  28. * These functions are for converting data to and from a "midi-safe" format,
  29. * which can be use to send data with sysex messages. Sysex messages may only
  30. * contain data where the to bit is not set.
  31. *
  32. * An "encoded" midi message is one that contains all of the data from its
  33. * original state, but does not have any of the top bits set.
  34. *
  35. * Every 7 bytes of decoded data is converted into 8 bytes of encoded data and
  36. * visa-versa. If you'd like to operate on small segments, make sure that you
  37. * encode in 7 byte increments and decode in 8 byte increments.
  38. *
  39. */
  40. /** @defgroup sysex_tools Sysex utility functions
  41. * @{
  42. */
  43. /**
  44. * @brief Compute the length of a message after it is encoded.
  45. *
  46. * @param decoded_length The length, in bytes, of the message to encode.
  47. *
  48. * @return The length, in bytes, of the message after encodeing.
  49. */
  50. uint16_t sysex_encoded_length(uint16_t decoded_length);
  51. /**
  52. * @brief Compute the length of a message after it is decoded.
  53. *
  54. * @param encoded_length The length, in bytes, of the encoded message.
  55. *
  56. * @return The length, in bytes, of the message after it is decoded.
  57. */
  58. uint16_t sysex_decoded_length(uint16_t encoded_length);
  59. /**
  60. * @brief Encode data so that it can be transmitted safely in a sysex message.
  61. *
  62. * @param encoded The output data buffer, must be at least sysex_encoded_length(length) bytes long.
  63. * @param source The input buffer of data to be encoded.
  64. * @param length The number of bytes from the input buffer to encode.
  65. *
  66. * @return number of bytes encoded.
  67. */
  68. uint16_t sysex_encode(uint8_t *encoded, const uint8_t *source, uint16_t length);
  69. /**
  70. * @brief Decode encoded data.
  71. *
  72. * @param decoded The output data buffer, must be at least sysex_decoded_length(length) bytes long.
  73. * @param source The input buffer of data to be decoded.
  74. * @param length The number of bytes from the input buffer to decode.
  75. *
  76. * @return number of bytes decoded.
  77. */
  78. uint16_t sysex_decode(uint8_t *decoded, const uint8_t *source, uint16_t length);
  79. /**@}*/
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif