Collection of tools useful for audio production
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.

255 lines
6.6KB

  1. /*
  2. * Caitlib
  3. * Copyright (C) 2007 Nedko Arnaudov <nedko@arnaudov.name>
  4. * Copyright (C) 2012 Filipe Coelho <falktx@falktx.com>
  5. *
  6. * This program 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 2 of the License, or
  9. * any later version.
  10. *
  11. * This program 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. * For a full copy of the GNU General Public License see the COPYING file
  17. */
  18. #ifndef CAITLIB_INCLUDED
  19. #define CAITLIB_INCLUDED
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #else
  23. #include <stdbool.h>
  24. #endif
  25. #include <stdint.h>
  26. #ifdef _WIN32
  27. #define CAITLIB_EXPORT __declspec (dllexport)
  28. #else
  29. #define CAITLIB_EXPORT __attribute__ ((visibility("default")))
  30. #endif
  31. /*!
  32. * @defgroup CaitlibAPI Caitlib API
  33. *
  34. * The Caitlib API
  35. *
  36. * @{
  37. */
  38. /*!
  39. * Native handle for all Caitlib calls.
  40. */
  41. typedef void* CaitlibHandle;
  42. /*!
  43. * @defgroup MidiEventType MidiEvent Type
  44. * @{
  45. */
  46. #define MIDI_EVENT_TYPE_NULL 0x00 //!< Null Event.
  47. #define MIDI_EVENT_TYPE_NOTE_OFF 0x80 //!< Note-Off Event, uses Note data.
  48. #define MIDI_EVENT_TYPE_NOTE_ON 0x90 //!< Note-On Event, uses Note data.
  49. #define MIDI_EVENT_TYPE_AFTER_TOUCH 0xA0 //!< [Key] AfterTouch Event, uses Note data.
  50. #define MIDI_EVENT_TYPE_CONTROL 0xB0 //!< Control Event, uses Control data.
  51. #define MIDI_EVENT_TYPE_PROGRAM 0xC0 //!< Program Event, uses Program data.
  52. #define MIDI_EVENT_TYPE_CHANNEL_PRESSURE 0xD0 //!< Channel Pressure Event, uses Pressure data.
  53. #define MIDI_EVENT_TYPE_PITCH_WHEEL 0xE0 //!< PitchWheel Event, uses PitchWheel data.
  54. /**@}*/
  55. /*!
  56. * MidiEvent in Caitlib
  57. */
  58. typedef struct _MidiEvent
  59. {
  60. /*!
  61. * MidiEvent Type
  62. */
  63. uint16_t type;
  64. /*!
  65. * MidiEvent Channel (0 - 16)
  66. */
  67. uint8_t channel;
  68. /*!
  69. * MidiEvent Data (values depend on type)
  70. */
  71. union MidiEventData {
  72. struct MidiEventControl {
  73. uint8_t controller;
  74. uint8_t value;
  75. } control;
  76. struct MidiEventNote {
  77. uint8_t note;
  78. uint8_t velocity;
  79. } note;
  80. struct MidiEventPressure {
  81. uint8_t value;
  82. } pressure;
  83. struct MidiEventProgram {
  84. uint8_t value;
  85. } program;
  86. struct MidiEventPitchWheel {
  87. int16_t value;
  88. } pitchwheel;
  89. #ifndef DOXYGEN
  90. // padding for future events
  91. struct _MidiEventPadding {
  92. uint8_t pad[32];
  93. } __padding;
  94. #endif
  95. } data;
  96. /*!
  97. * MidiEvent Time (in frames)
  98. */
  99. uint32_t time;
  100. } MidiEvent;
  101. // ------------------------------------------------------------------------------------------
  102. /*!
  103. * @defgroup Initialization
  104. *
  105. * Functions for initialization and destruction of Caitlib instances.
  106. * @{
  107. */
  108. /*!
  109. * Initialize a new Caitlib instance with name \a instanceName.\n
  110. * Must be closed when no longer needed with caitlib_close().
  111. *
  112. * \note MIDI Input is disabled by default, call caitlib_want_events() to enable them.
  113. * \note There are no MIDI Output ports by default, call caitlib_create_port() for that.
  114. */
  115. CAITLIB_EXPORT
  116. CaitlibHandle caitlib_init(const char* instanceName);
  117. /*!
  118. * Close a previously opened Caitlib instance.\n
  119. */
  120. CAITLIB_EXPORT
  121. void caitlib_close(CaitlibHandle handle);
  122. /*!
  123. * Create a new MIDI Output port with name \a portName.\n
  124. * The return value is the ID for the port, which must be passed for any functions in the Output group.\n
  125. * The ID will be >= 0 for a valid port, or -1 if an error occurred.
  126. */
  127. CAITLIB_EXPORT
  128. uint32_t caitlib_create_port(CaitlibHandle handle, const char* portName);
  129. /*!
  130. * Close a previously opened Caitlib instance.\n
  131. * There's no need to call this function before caitlib_close().
  132. */
  133. CAITLIB_EXPORT
  134. void caitlib_destroy_port(CaitlibHandle handle, uint32_t port);
  135. /**@}*/
  136. // ------------------------------------------------------------------------------------------
  137. /*!
  138. * @defgroup Input
  139. *
  140. * Functions for MIDI Input handling.
  141. * @{
  142. */
  143. /*!
  144. * Tell a Caitlib instance wherever if we're interested in MIDI Input.\n
  145. * By default MIDI Input is disabled.\n
  146. * It's safe to call this function multiple times during the lifetime of an instance.
  147. */
  148. CAITLIB_EXPORT
  149. void caitlib_want_events(CaitlibHandle handle, bool yesNo);
  150. /*!
  151. * Get a MidiEvent from a Caitlib instance buffer.\n
  152. * When there are no more messages in the buffer, this function returns NULL.
  153. */
  154. CAITLIB_EXPORT
  155. MidiEvent* caitlib_get_event(CaitlibHandle handle);
  156. /**@}*/
  157. // ------------------------------------------------------------------------------------------
  158. /*!
  159. * @defgroup Output
  160. *
  161. * Functions for putting data into Caitlib instances (MIDI Output).
  162. * @{
  163. */
  164. /*!
  165. * Put a MIDI event into a Caitlib instance port.
  166. */
  167. CAITLIB_EXPORT
  168. void caitlib_put_event(CaitlibHandle handle, uint32_t port, const MidiEvent* event);
  169. /*!
  170. * Put a MIDI Control event into a Caitlib instance port.
  171. */
  172. CAITLIB_EXPORT
  173. void caitlib_put_control(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, uint8_t controller, uint8_t value);
  174. /*!
  175. * Put a MIDI Note On event into a Caitlib instance port.
  176. */
  177. CAITLIB_EXPORT
  178. void caitlib_put_note_on(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, uint8_t note, uint8_t velocity);
  179. /*!
  180. * Put a MIDI Note Off event into a Caitlib instance port.
  181. */
  182. CAITLIB_EXPORT
  183. void caitlib_put_note_off(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, uint8_t note, uint8_t velocity);
  184. /*!
  185. * Put a MIDI AfterTouch event into a Caitlib instance port.
  186. */
  187. CAITLIB_EXPORT
  188. void caitlib_put_aftertouch(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, uint8_t note, uint8_t pressure);
  189. /*!
  190. * Put a MIDI Channel Pressure event into a Caitlib instance port.
  191. */
  192. CAITLIB_EXPORT
  193. void caitlib_put_channel_pressure(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, uint8_t pressure);
  194. /*!
  195. * Put a MIDI Program event into a Caitlib instance port.
  196. */
  197. CAITLIB_EXPORT
  198. void caitlib_put_program(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, uint8_t program);
  199. /*!
  200. * Put a MIDI PitchWheel event into a Caitlib instance port.
  201. */
  202. CAITLIB_EXPORT
  203. void caitlib_put_pitchwheel(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, int16_t value);
  204. /**@}*/
  205. // ------------------------------------------------------------------------------------------
  206. /**@}*/
  207. #ifdef __cplusplus
  208. }
  209. #endif
  210. #endif // CAITLIB_INCLUDED