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.

269 lines
7.0KB

  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. #define MIDI_EVENT_TYPE_TIME 0xF1 //!< Time Event, uses Time Data.
  55. /**@}*/
  56. /*!
  57. * MidiEvent in Caitlib
  58. */
  59. typedef struct _MidiEvent
  60. {
  61. /*!
  62. * MidiEvent Type
  63. */
  64. uint16_t type;
  65. /*!
  66. * MidiEvent Channel (0 - 16)
  67. */
  68. uint8_t channel;
  69. /*!
  70. * MidiEvent Data (values depend on type).
  71. * \note Time event types ignore channel value.
  72. */
  73. union MidiEventData {
  74. struct MidiEventControl {
  75. uint8_t controller;
  76. uint8_t value;
  77. } control;
  78. struct MidiEventNote {
  79. uint8_t note;
  80. uint8_t velocity;
  81. } note;
  82. struct MidiEventPressure {
  83. uint8_t value;
  84. } pressure;
  85. struct MidiEventProgram {
  86. uint8_t value;
  87. } program;
  88. struct MidiEventPitchWheel {
  89. int16_t value;
  90. } pitchwheel;
  91. struct MidiEventTime {
  92. double bpm;
  93. uint8_t sigNum;
  94. uint8_t sigDenum;
  95. } time;
  96. #ifndef DOXYGEN
  97. // padding for future events
  98. struct _MidiEventPadding {
  99. uint8_t pad[128];
  100. } __padding;
  101. #endif
  102. } data;
  103. /*!
  104. * MidiEvent Time (in frames)
  105. */
  106. uint32_t time;
  107. } MidiEvent;
  108. // ------------------------------------------------------------------------------------------
  109. /*!
  110. * @defgroup Initialization
  111. *
  112. * Functions for initialization and destruction of Caitlib instances.
  113. * @{
  114. */
  115. /*!
  116. * Initialize a new Caitlib instance with name \a instanceName.\n
  117. * Must be closed when no longer needed with caitlib_close().
  118. *
  119. * \note MIDI Input is disabled by default, call caitlib_want_events() to enable them.
  120. * \note There are no MIDI Output ports by default, call caitlib_create_port() for that.
  121. */
  122. CAITLIB_EXPORT
  123. CaitlibHandle caitlib_init(const char* instanceName);
  124. /*!
  125. * Close a previously opened Caitlib instance.\n
  126. */
  127. CAITLIB_EXPORT
  128. void caitlib_close(CaitlibHandle handle);
  129. /*!
  130. * Create a new MIDI Output port with name \a portName.\n
  131. * The return value is the ID for the port, which must be passed for any functions in the Output group.\n
  132. * The ID will be >= 0 for a valid port, or -1 if an error occurred.
  133. */
  134. CAITLIB_EXPORT
  135. uint32_t caitlib_create_port(CaitlibHandle handle, const char* portName);
  136. /*!
  137. * Close a previously opened Caitlib instance.\n
  138. * There's no need to call this function before caitlib_close().
  139. */
  140. CAITLIB_EXPORT
  141. void caitlib_destroy_port(CaitlibHandle handle, uint32_t port);
  142. /**@}*/
  143. // ------------------------------------------------------------------------------------------
  144. /*!
  145. * @defgroup Input
  146. *
  147. * Functions for MIDI Input handling.
  148. * @{
  149. */
  150. /*!
  151. * Tell a Caitlib instance wherever if we're interested in MIDI Input.\n
  152. * By default MIDI Input is disabled.\n
  153. * It's safe to call this function multiple times during the lifetime of an instance.
  154. */
  155. CAITLIB_EXPORT
  156. void caitlib_want_events(CaitlibHandle handle, bool yesNo);
  157. /*!
  158. * Get a MidiEvent from a Caitlib instance buffer.\n
  159. * When there are no more messages in the buffer, this function returns NULL.
  160. */
  161. CAITLIB_EXPORT
  162. MidiEvent* caitlib_get_event(CaitlibHandle handle);
  163. /**@}*/
  164. // ------------------------------------------------------------------------------------------
  165. /*!
  166. * @defgroup Output
  167. *
  168. * Functions for putting data into Caitlib instances (MIDI Output).
  169. * @{
  170. */
  171. /*!
  172. * Put a MIDI event into a Caitlib instance port.
  173. */
  174. CAITLIB_EXPORT
  175. void caitlib_put_event(CaitlibHandle handle, uint32_t port, const MidiEvent* event);
  176. /*!
  177. * Put a MIDI Control event into a Caitlib instance port.
  178. */
  179. CAITLIB_EXPORT
  180. void caitlib_put_control(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, uint8_t controller, uint8_t value);
  181. /*!
  182. * Put a MIDI Note On event into a Caitlib instance port.
  183. */
  184. CAITLIB_EXPORT
  185. void caitlib_put_note_on(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, uint8_t note, uint8_t velocity);
  186. /*!
  187. * Put a MIDI Note Off event into a Caitlib instance port.
  188. */
  189. CAITLIB_EXPORT
  190. void caitlib_put_note_off(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, uint8_t note, uint8_t velocity);
  191. /*!
  192. * Put a MIDI AfterTouch event into a Caitlib instance port.
  193. */
  194. CAITLIB_EXPORT
  195. void caitlib_put_aftertouch(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, uint8_t note, uint8_t pressure);
  196. /*!
  197. * Put a MIDI Channel Pressure event into a Caitlib instance port.
  198. */
  199. CAITLIB_EXPORT
  200. void caitlib_put_channel_pressure(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, uint8_t pressure);
  201. /*!
  202. * Put a MIDI Program event into a Caitlib instance port.
  203. */
  204. CAITLIB_EXPORT
  205. void caitlib_put_program(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, uint8_t program);
  206. /*!
  207. * Put a MIDI PitchWheel event into a Caitlib instance port.
  208. */
  209. CAITLIB_EXPORT
  210. void caitlib_put_pitchwheel(CaitlibHandle handle, uint32_t port, uint32_t time, uint8_t channel, int16_t value);
  211. /*!
  212. * Put a MIDI Time event into a Caitlib instance.
  213. */
  214. CAITLIB_EXPORT
  215. void caitlib_put_time(CaitlibHandle handle, uint32_t time, double bpm, uint8_t sigNum, uint8_t sigDenum);
  216. /**@}*/
  217. // ------------------------------------------------------------------------------------------
  218. /**@}*/
  219. #ifdef __cplusplus
  220. }
  221. #endif
  222. #endif // CAITLIB_INCLUDED