libcm is a C development framework with an emphasis on audio signal processing applications.
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.

cmMidiPort.h 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //| Copyright: (C) 2009-2020 Kevin Larke <contact AT larke DOT org>
  2. //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
  3. #ifndef cmMidiPort_h
  4. #define cmMidiPort_h
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. //( { file_desc:"Device independent MIDI port related code." kw:[midi devices]}
  9. typedef unsigned cmMpRC_t;
  10. // Flags used to identify input and output ports on MIDI devices
  11. enum
  12. {
  13. kInMpFl = 0x01,
  14. kOutMpFl = 0x02
  15. };
  16. enum
  17. {
  18. kOkMpRC = cmOkRC,
  19. kCfStringErrMpRC,
  20. kLHeapErrMpRC,
  21. kThreadErrMpRC,
  22. kSysErrMpRC,
  23. kInvalidArgMpRC,
  24. kMemAllocFailMpRC,
  25. kNotImplMpRC,
  26. kCbNotFoundMpRC
  27. };
  28. typedef void (*cmMpCallback_t)( const cmMidiPacket_t* pktArray, unsigned pktCnt );
  29. //)
  30. //( { label:cmMpParser file_desc:"MIDI event parser converts raw MIDI events into cmMidiPacket_t messages." kw:[midi]}
  31. //===============================================================================================
  32. // MIDI Parser
  33. //
  34. typedef cmHandle_t cmMpParserH_t;
  35. // 'cbFunc' and 'cbDataPtr' are optional. If 'cbFunc' is not supplied in the call to
  36. // cmMpParserCreate() it may be supplied later by cmMpParserInstallCallback().
  37. // 'bufByteCnt' defines is the largest complete system-exclusive message the parser will
  38. // by able to transmit. System-exclusive messages larger than this will be broken into
  39. // multiple sequential callbacks.
  40. cmMpParserH_t cmMpParserCreate( unsigned devIdx, unsigned portIdx, cmMpCallback_t cbFunc, void* cbDataPtr, unsigned bufByteCnt, cmRpt_t* rpt );
  41. void cmMpParserDestroy( cmMpParserH_t* hp );
  42. unsigned cmMpParserErrorCount( cmMpParserH_t h );
  43. void cmMpParseMidiData( cmMpParserH_t h, const cmTimeSpec_t* timestamp, const cmMidiByte_t* buf, unsigned bufByteCnt );
  44. // The following two functions are intended to be used togetther.
  45. // Use cmMpParserMidiTriple() to insert pre-parsed msg's to the output buffer,
  46. // and then use cmMpParserTransmit() to send the buffer via the parsers callback function.
  47. // Set the data bytes to 0xff if they are not used by the message.
  48. cmMpRC_t cmMpParserMidiTriple( cmMpParserH_t h, const cmTimeSpec_t* timestamp, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1 );
  49. cmMpRC_t cmMpParserTransmit( cmMpParserH_t h );
  50. // Install/Remove additional callbacks.
  51. cmMpRC_t cmMpParserInstallCallback( cmMpParserH_t h, cmMpCallback_t cbFunc, void* cbDataPtr );
  52. cmMpRC_t cmMpParserRemoveCallback( cmMpParserH_t h, cmMpCallback_t cbFunc, void* cbDataPtr );
  53. // Returns true if the parser uses the given callback.
  54. bool cmMpParserHasCallback( cmMpParserH_t h, cmMpCallback_t cbFunc, void* cbDataPtr );
  55. //)
  56. //( { label:cmMidiPort file_desc:"Device independent MIDI port." kw:[midi]}
  57. //===============================================================================================
  58. // MIDI Device Interface
  59. //
  60. // 'cbFunc' and 'cbDataPtr' are optional (they may be set to NULL). In this case
  61. // 'cbFunc' and 'cbDataPtr' may be set in a later call to cmMpInstallCallback().
  62. cmMpRC_t cmMpInitialize( cmCtx_t* ctx, cmMpCallback_t cbFunc, void* cbDataPtr, unsigned parserBufByteCnt, const char* appNameStr );
  63. cmMpRC_t cmMpFinalize();
  64. bool cmMpIsInitialized();
  65. unsigned cmMpDeviceCount();
  66. const char* cmMpDeviceName( unsigned devIdx );
  67. unsigned cmMpDeviceNameToIndex(const cmChar_t* name);
  68. unsigned cmMpDevicePortCount( unsigned devIdx, unsigned flags );
  69. const char* cmMpDevicePortName( unsigned devIdx, unsigned flags, unsigned portIdx );
  70. unsigned cmMpDevicePortNameToIndex( unsigned devIdx, unsigned flags, const cmChar_t* name );
  71. cmMpRC_t cmMpDeviceSend( unsigned devIdx, unsigned portIdx, cmMidiByte_t st, cmMidiByte_t d0, cmMidiByte_t d1 );
  72. cmMpRC_t cmMpDeviceSendData( unsigned devIdx, unsigned portIdx, const cmMidiByte_t* dataPtr, unsigned byteCnt );
  73. // Set devIdx to -1 to assign the callback to all devices.
  74. // Set portIdx to -1 to assign the callback to all ports on the specified devices.
  75. //
  76. cmMpRC_t cmMpInstallCallback( unsigned devIdx, unsigned portIdx, cmMpCallback_t cbFunc, void* cbDataPtr );
  77. cmMpRC_t cmMpRemoveCallback( unsigned devIdx, unsigned portIdx, cmMpCallback_t cbFunc, void* cbDataPtr );
  78. bool cmMpUsesCallback( unsigned devIdx, unsigned portIdx, cmMpCallback_t cbFunc, void* cbDataPtr );
  79. void cmMpReport( cmRpt_t* rpt );
  80. void cmMpTest( cmCtx_t* ctx );
  81. //)
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif