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.

173 lines
6.1KB

  1. #include <stdbool.h>
  2. #include <stddef.h>
  3. #ifndef RTMIDI_C_H
  4. #define RTMIDI_C_H
  5. #if defined(RTMIDI_EXPORT)
  6. #define RTMIDIAPI __declspec(dllexport)
  7. #else
  8. #define RTMIDIAPI //__declspec(dllimport)
  9. #endif
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. //! Wraps an RtMidi object for C function return statuses.
  14. struct RtMidiWrapper {
  15. //! The wrapped RtMidi object.
  16. void* ptr;
  17. void* data;
  18. //! True when the last function call was OK.
  19. bool ok;
  20. //! If an error occured (ok != true), set to an error message.
  21. const char* msg;
  22. };
  23. //! Typedef for a generic RtMidi pointer.
  24. typedef struct RtMidiWrapper* RtMidiPtr;
  25. //! Typedef for a generic RtMidiIn pointer.
  26. typedef struct RtMidiWrapper* RtMidiInPtr;
  27. //! Typedef for a generic RtMidiOut pointer.
  28. typedef struct RtMidiWrapper* RtMidiOutPtr;
  29. enum RtMidiApi {
  30. RT_MIDI_API_UNSPECIFIED, /*!< Search for a working compiled API. */
  31. RT_MIDI_API_MACOSX_CORE, /*!< Macintosh OS-X Core Midi API. */
  32. RT_MIDI_API_LINUX_ALSA, /*!< The Advanced Linux Sound Architecture API. */
  33. RT_MIDI_API_UNIX_JACK, /*!< The Jack Low-Latency MIDI Server API. */
  34. RT_MIDI_API_WINDOWS_MM, /*!< The Microsoft Multimedia MIDI API. */
  35. RT_MIDI_API_RTMIDI_DUMMY /*!< A compilable but non-functional API. */
  36. };
  37. enum RtMidiErrorType {
  38. RT_ERROR_WARNING, RT_ERROR_DEBUG_WARNING, RT_ERROR_UNSPECIFIED, RT_ERROR_NO_DEVICES_FOUND,
  39. RT_ERROR_INVALID_DEVICE, RT_ERROR_MEMORY_ERROR, RT_ERROR_INVALID_PARAMETER, RT_ERROR_INVALID_USE,
  40. RT_ERROR_DRIVER_ERROR, RT_ERROR_SYSTEM_ERROR, RT_ERROR_THREAD_ERROR
  41. };
  42. /*! The type of a RtMidi callback function.
  43. * \param timeStamp The time at which the message has been received.
  44. * \param message The midi message.
  45. * \param userData Additional user data for the callback.
  46. */
  47. typedef void(* RtMidiCCallback) (double timeStamp, const unsigned char* message,
  48. size_t messageSize, void *userData);
  49. /* RtMidi API */
  50. /*! Determine the available compiled MIDI APIs.
  51. * If the given `apis` parameter is null, returns the number of available APIs.
  52. * Otherwise, fill the given apis array with the RtMidi::Api values.
  53. *
  54. * \param apis An array or a null value.
  55. */
  56. RTMIDIAPI int rtmidi_get_compiled_api (enum RtMidiApi *apis); // return length for NULL argument.
  57. //! Report an error.
  58. RTMIDIAPI void rtmidi_error (enum RtMidiErrorType type, const char* errorString);
  59. /*! Open a MIDI port.
  60. *
  61. * \param port Must be greater than 0
  62. * \param portName Name for the application port.
  63. */
  64. RTMIDIAPI void rtmidi_open_port (RtMidiPtr device, unsigned int portNumber, const char *portName);
  65. /*! Creates a virtual MIDI port to which other software applications can
  66. * connect.
  67. *
  68. * \param portName Name for the application port.
  69. */
  70. RTMIDIAPI void rtmidi_open_virtual_port (RtMidiPtr device, const char *portName);
  71. /*! Close a MIDI connection.
  72. */
  73. RTMIDIAPI void rtmidi_close_port (RtMidiPtr device);
  74. /*! Return the number of available MIDI ports.
  75. */
  76. RTMIDIAPI unsigned int rtmidi_get_port_count (RtMidiPtr device);
  77. /*! Return a string identifier for the specified MIDI input port number.
  78. */
  79. RTMIDIAPI const char* rtmidi_get_port_name (RtMidiPtr device, unsigned int portNumber);
  80. /* RtMidiIn API */
  81. //! Create a default RtMidiInPtr value, with no initialization.
  82. RTMIDIAPI RtMidiInPtr rtmidi_in_create_default ();
  83. /*! Create a RtMidiInPtr value, with given api, clientName and queueSizeLimit.
  84. *
  85. * \param api An optional API id can be specified.
  86. * \param clientName An optional client name can be specified. This
  87. * will be used to group the ports that are created
  88. * by the application.
  89. * \param queueSizeLimit An optional size of the MIDI input queue can be
  90. * specified.
  91. */
  92. RTMIDIAPI RtMidiInPtr rtmidi_in_create (enum RtMidiApi api, const char *clientName, unsigned int queueSizeLimit);
  93. //! Deallocate the given pointer.
  94. RTMIDIAPI void rtmidi_in_free (RtMidiInPtr device);
  95. //! Returns the MIDI API specifier for the given instance of RtMidiIn.
  96. RTMIDIAPI enum RtMidiApi rtmidi_in_get_current_api (RtMidiPtr device);
  97. //! Set a callback function to be invoked for incoming MIDI messages.
  98. RTMIDIAPI void rtmidi_in_set_callback (RtMidiInPtr device, RtMidiCCallback callback, void *userData);
  99. //! Cancel use of the current callback function (if one exists).
  100. RTMIDIAPI void rtmidi_in_cancel_callback (RtMidiInPtr device);
  101. //! Specify whether certain MIDI message types should be queued or ignored during input.
  102. RTMIDIAPI void rtmidi_in_ignore_types (RtMidiInPtr device, bool midiSysex, bool midiTime, bool midiSense);
  103. /*! Fill the user-provided array with the data bytes for the next available
  104. * MIDI message in the input queue and return the event delta-time in seconds.
  105. *
  106. * \param message Must point to a char* that is already allocated.
  107. * SYSEX messages maximum size being 1024, a statically
  108. * allocated array could
  109. * be sufficient.
  110. * \param size Is used to return the size of the message obtained.
  111. */
  112. RTMIDIAPI double rtmidi_in_get_message (RtMidiInPtr device, unsigned char *message, size_t *size);
  113. /* RtMidiOut API */
  114. //! Create a default RtMidiInPtr value, with no initialization.
  115. RTMIDIAPI RtMidiOutPtr rtmidi_out_create_default ();
  116. /*! Create a RtMidiOutPtr value, with given and clientName.
  117. *
  118. * \param api An optional API id can be specified.
  119. * \param clientName An optional client name can be specified. This
  120. * will be used to group the ports that are created
  121. * by the application.
  122. */
  123. RTMIDIAPI RtMidiOutPtr rtmidi_out_create (enum RtMidiApi api, const char *clientName);
  124. //! Deallocate the given pointer.
  125. RTMIDIAPI void rtmidi_out_free (RtMidiOutPtr device);
  126. //! Returns the MIDI API specifier for the given instance of RtMidiOut.
  127. RTMIDIAPI enum RtMidiApi rtmidi_out_get_current_api (RtMidiPtr device);
  128. //! Immediately send a single message out an open MIDI output port.
  129. RTMIDIAPI int rtmidi_out_send_message (RtMidiOutPtr device, const unsigned char *message, int length);
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #endif